-
Notifications
You must be signed in to change notification settings - Fork 0
/
ccsds-epp.pk
151 lines (134 loc) · 4.76 KB
/
ccsds-epp.pk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**
* @file ccsds-epp.pk
* @author Conlan Wesson
* Poke support for CCSDS Encapsulation Packet Protocol (CCSDS 133.1-B-3).
*
* @ingroup ccsds
* @defgroup epp CCSDS Encapsulation Packet
* @{
*/
/// Encapsulation Packet Protocol Version 8
var ENCAPSULATION_PACKET_VERSION_8 = 0b111;
/// Encapsulation Packet Idle Protocol ID (4.1.2.3.3 1)
var ENCAPSULATION_PACKET_IDLE = 0b000;
/// LTP over Encapsulation Packet Protocol ID
var ENCAPSULATION_PACKET_LTP = 0b001;
/// Encapsulation Packet Internet Protocol Extension Protocol ID
var ENCAPSULATION_PACKET_IPE = 0b010;
/// Encapsulation Packet CFDP Protocol ID
var ENCAPSULATION_PACKET_CFDP = 0b011;
/// Encapsulation Packet Bundle Protocol Protocol ID
var ENCAPSULATION_PACKET_BP = 0b100;
/// Encapsulation Packet Protocol ID Extension Protocol ID (4.1.2.3.3 2)
var ENCAPSULATION_PACKET_USE_PROTOCOL_EXTENSION = 0b110;
/// Encapsulation Packet Mission-specific Protocol ID (4.1.2.3.3 3)
var ENCAPSULATION_PACKET_MISSION_SPECIFIC = 0b111;
/**
* Encapsulation Packet Primary Header
*/
type Encapsulation_Packet_Header =
struct
{
uint<3> version = ENCAPSULATION_PACKET_VERSION_8;
uint<3> protocol_id;
uint<2> length_of_length : (length_of_length != 0) || (protocol_id == ENCAPSULATION_PACKET_IDLE); // (4.1.2.4.4)
if (length_of_length == 0b01)
offset<uint<8>,B> length8;
if (length_of_length >= 0b10)
uint<4> user_defined;
if (length_of_length >= 0b10)
uint<4> protocol_id_extension : (protocol_id_extension == 0) || (protocol_id == ENCAPSULATION_PACKET_USE_PROTOCOL_EXTENSION); // (4.1.2.6.3)
if (length_of_length == 0b10)
offset<uint<16>,B> length16;
if (length_of_length == 0b11)
uint<16> ccsds_defined = 0; // (4.1.2.7.2)
if (length_of_length == 0b11)
offset<uint<32>,B> length32;
computed offset<uint<32>,B> length;
method get_length = offset<uint<32>,B>:
{
if (length_of_length == 0b00)
return 0#B;
if (length_of_length == 0b01)
return length8;
if (length_of_length == 0b10)
return length16;
if (length_of_length == 0b11)
return length32;
}
method set_length = (offset<uint<32>,B> len) void:
{
if (length_of_length == 0b00)
return;
if (length_of_length == 0b01)
length8 = len;
if (length_of_length == 0b10)
length16 = len;
if (length_of_length == 0b11)
length32 = len;
}
/**
* Pretty printer.
*/
method _print = void:
{
print ("#<\n");
printf (" %<struct-field-name:Primary Header%>:\n");
printf (" %<struct-field-name:Version%>: %<integer:%u4d%>\n", version+1);
// Protocol ID
printf (" %<struct-field-name:Protocol ID%>: ");
if (protocol_id == ENCAPSULATION_PACKET_IDLE)
print ("Idle\n");
else if (protocol_id == ENCAPSULATION_PACKET_LTP)
print ("LTP\n");
else if (protocol_id == ENCAPSULATION_PACKET_IPE)
print ("IPE\n");
else if (protocol_id == ENCAPSULATION_PACKET_CFDP)
print ("CFDP\n");
else if (protocol_id == ENCAPSULATION_PACKET_BP)
print ("BP\n");
else if (protocol_id == ENCAPSULATION_PACKET_USE_PROTOCOL_EXTENSION)
print ("Use protocol extension\n");
else if (protocol_id == ENCAPSULATION_PACKET_MISSION_SPECIFIC)
print ("Mission specific\n");
else
printf ("%<integer:0b%u3b%>\n", protocol_id);
// Legnth-of-Length
printf (" %<struct-field-name:Length-of-Length%>: ");
if (length_of_length == 0b11)
printf ("%<integer:4%>");
else
printf ("%<integer:%u2d%>", length_of_length);
printf (" Bytes\n");
if (length_of_length >= 0b10) {
printf (" %<struct-field-name:User Defined%>: 0x%<integer:%u4x%>\n", user_defined);
printf (" %<struct-field-name:Protocol ID Extension%>: 0x%<integer:%u4x%>\n", protocol_id_extension);
}
printf (" %<struct-field-name:Length%>: %v\n", get_length);
print (">\n");
}
};
assert(Encapsulation_Packet_Header{length_of_length=0}'size == 1#B);
assert(Encapsulation_Packet_Header{length_of_length=1}'size == 2#B);
assert(Encapsulation_Packet_Header{length_of_length=2}'size == 4#B);
assert(Encapsulation_Packet_Header{length_of_length=3}'size == 8#B);
/**
* Encapsulation Packet
*/
type Encapsulation_Packet =
struct
{
Encapsulation_Packet_Header header;
var encapsulated_data_offset = OFFSET;
if (header.length_of_length > 0)
byte[0] @ OFFSET + header.length;
/**
* Get the encapsulated data.
* @return Array containing the encapsulated data field.
*/
method get_encapsulated_data = byte[]:
{
return byte[header.length] @ encapsulated_data_offset;
}
};
/** @} */ // defgroup epp