|
@@
-1,463
+1,465
|
|
1
|
/** Functions related to TeleCommand acceptance.
|
|
1
|
/** Functions related to TeleCommand acceptance.
|
|
2
|
*
|
|
2
|
*
|
|
3
|
* @file
|
|
3
|
* @file
|
|
4
|
* @author P. LEROY
|
|
4
|
* @author P. LEROY
|
|
5
|
*
|
|
5
|
*
|
|
6
|
* A group of functions to handle TeleCommands parsing.\n
|
|
6
|
* A group of functions to handle TeleCommands parsing.\n
|
|
7
|
*
|
|
7
|
*
|
|
8
|
*/
|
|
8
|
*/
|
|
9
|
|
|
9
|
|
|
10
|
#include "tc_acceptance.h"
|
|
10
|
#include "tc_acceptance.h"
|
|
|
|
|
11
|
#include <stdio.h>
|
|
11
|
|
|
12
|
|
|
12
|
unsigned int lookUpTableForCRC[256];
|
|
13
|
unsigned int lookUpTableForCRC[256];
|
|
13
|
|
|
14
|
|
|
14
|
//**********************
|
|
15
|
//**********************
|
|
15
|
// GENERAL USE FUNCTIONS
|
|
16
|
// GENERAL USE FUNCTIONS
|
|
16
|
unsigned int Crc_opt( unsigned char D, unsigned int Chk)
|
|
17
|
unsigned int Crc_opt( unsigned char D, unsigned int Chk)
|
|
17
|
{
|
|
18
|
{
|
|
18
|
/** This function generate the CRC for one byte and returns the value of the new syndrome.
|
|
19
|
/** This function generate the CRC for one byte and returns the value of the new syndrome.
|
|
19
|
*
|
|
20
|
*
|
|
20
|
* @param D is the current byte of data.
|
|
21
|
* @param D is the current byte of data.
|
|
21
|
* @param Chk is the current syndrom value.
|
|
22
|
* @param Chk is the current syndrom value.
|
|
22
|
*
|
|
23
|
*
|
|
23
|
* @return the value of the new syndrome on two bytes.
|
|
24
|
* @return the value of the new syndrome on two bytes.
|
|
24
|
*
|
|
25
|
*
|
|
25
|
*/
|
|
26
|
*/
|
|
26
|
|
|
27
|
|
|
27
|
return(((Chk << 8) & 0xff00)^lookUpTableForCRC [(((Chk >> 8)^D) & 0x00ff)]);
|
|
28
|
return(((Chk << 8) & 0xff00)^lookUpTableForCRC [(((Chk >> 8)^D) & 0x00ff)]);
|
|
28
|
}
|
|
29
|
}
|
|
29
|
|
|
30
|
|
|
30
|
void initLookUpTableForCRC( void )
|
|
31
|
void initLookUpTableForCRC( void )
|
|
31
|
{
|
|
32
|
{
|
|
32
|
/** This function is used to initiates the look-up table for fast CRC computation.
|
|
33
|
/** This function is used to initiates the look-up table for fast CRC computation.
|
|
33
|
*
|
|
34
|
*
|
|
34
|
* The global table lookUpTableForCRC[256] is initiated.
|
|
35
|
* The global table lookUpTableForCRC[256] is initiated.
|
|
35
|
*
|
|
36
|
*
|
|
36
|
*/
|
|
37
|
*/
|
|
37
|
|
|
38
|
|
|
38
|
unsigned int i;
|
|
39
|
unsigned int i;
|
|
39
|
unsigned int tmp;
|
|
40
|
unsigned int tmp;
|
|
40
|
|
|
41
|
|
|
41
|
for (i=0; i<256; i++)
|
|
42
|
for (i=0; i<256; i++)
|
|
42
|
{
|
|
43
|
{
|
|
43
|
tmp = 0;
|
|
44
|
tmp = 0;
|
|
44
|
if((i & 1) != 0) {
|
|
45
|
if((i & 1) != 0) {
|
|
45
|
tmp = tmp ^ 0x1021;
|
|
46
|
tmp = tmp ^ 0x1021;
|
|
46
|
}
|
|
47
|
}
|
|
47
|
if((i & 2) != 0) {
|
|
48
|
if((i & 2) != 0) {
|
|
48
|
tmp = tmp ^ 0x2042;
|
|
49
|
tmp = tmp ^ 0x2042;
|
|
49
|
}
|
|
50
|
}
|
|
50
|
if((i & 4) != 0) {
|
|
51
|
if((i & 4) != 0) {
|
|
51
|
tmp = tmp ^ 0x4084;
|
|
52
|
tmp = tmp ^ 0x4084;
|
|
52
|
}
|
|
53
|
}
|
|
53
|
if((i & 8) != 0) {
|
|
54
|
if((i & 8) != 0) {
|
|
54
|
tmp = tmp ^ 0x8108;
|
|
55
|
tmp = tmp ^ 0x8108;
|
|
55
|
}
|
|
56
|
}
|
|
56
|
if((i & 16) != 0) {
|
|
57
|
if((i & 16) != 0) {
|
|
57
|
tmp = tmp ^ 0x1231;
|
|
58
|
tmp = tmp ^ 0x1231;
|
|
58
|
}
|
|
59
|
}
|
|
59
|
if((i & 32) != 0) {
|
|
60
|
if((i & 32) != 0) {
|
|
60
|
tmp = tmp ^ 0x2462;
|
|
61
|
tmp = tmp ^ 0x2462;
|
|
61
|
}
|
|
62
|
}
|
|
62
|
if((i & 64) != 0) {
|
|
63
|
if((i & 64) != 0) {
|
|
63
|
tmp = tmp ^ 0x48c4;
|
|
64
|
tmp = tmp ^ 0x48c4;
|
|
64
|
}
|
|
65
|
}
|
|
65
|
if((i & 128) != 0) {
|
|
66
|
if((i & 128) != 0) {
|
|
66
|
tmp = tmp ^ 0x9188;
|
|
67
|
tmp = tmp ^ 0x9188;
|
|
67
|
}
|
|
68
|
}
|
|
68
|
lookUpTableForCRC[i] = tmp;
|
|
69
|
lookUpTableForCRC[i] = tmp;
|
|
69
|
}
|
|
70
|
}
|
|
70
|
}
|
|
71
|
}
|
|
71
|
|
|
72
|
|
|
72
|
void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData)
|
|
73
|
void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData)
|
|
73
|
{
|
|
74
|
{
|
|
74
|
/** This function calculates a two bytes Cyclic Redundancy Code.
|
|
75
|
/** This function calculates a two bytes Cyclic Redundancy Code.
|
|
75
|
*
|
|
76
|
*
|
|
76
|
* @param data points to a buffer containing the data on which to compute the CRC.
|
|
77
|
* @param data points to a buffer containing the data on which to compute the CRC.
|
|
77
|
* @param crcAsTwoBytes points points to a two bytes buffer in which the CRC is stored.
|
|
78
|
* @param crcAsTwoBytes points points to a two bytes buffer in which the CRC is stored.
|
|
78
|
* @param sizeOfData is the number of bytes of *data* used to compute the CRC.
|
|
79
|
* @param sizeOfData is the number of bytes of *data* used to compute the CRC.
|
|
79
|
*
|
|
80
|
*
|
|
80
|
* The specification of the Cyclic Redundancy Code is described in the following document: ECSS-E-70-41-A.
|
|
81
|
* The specification of the Cyclic Redundancy Code is described in the following document: ECSS-E-70-41-A.
|
|
81
|
*
|
|
82
|
*
|
|
82
|
*/
|
|
83
|
*/
|
|
83
|
|
|
84
|
|
|
84
|
unsigned int Chk;
|
|
85
|
unsigned int Chk;
|
|
85
|
int j;
|
|
86
|
int j;
|
|
86
|
Chk = 0xffff; // reset the syndrom to all ones
|
|
87
|
Chk = 0xffff; // reset the syndrom to all ones
|
|
87
|
for (j=0; j<sizeOfData; j++) {
|
|
88
|
for (j=0; j<sizeOfData; j++) {
|
|
88
|
Chk = Crc_opt(data[j], Chk);
|
|
89
|
Chk = Crc_opt(data[j], Chk);
|
|
89
|
}
|
|
90
|
}
|
|
90
|
crcAsTwoBytes[0] = (unsigned char) (Chk >> 8);
|
|
91
|
crcAsTwoBytes[0] = (unsigned char) (Chk >> 8);
|
|
91
|
crcAsTwoBytes[1] = (unsigned char) (Chk & 0x00ff);
|
|
92
|
crcAsTwoBytes[1] = (unsigned char) (Chk & 0x00ff);
|
|
92
|
}
|
|
93
|
}
|
|
93
|
|
|
94
|
|
|
94
|
//*********************
|
|
95
|
//*********************
|
|
95
|
// ACCEPTANCE FUNCTIONS
|
|
96
|
// ACCEPTANCE FUNCTIONS
|
|
96
|
int tc_parser(ccsdsTelecommandPacket_t * TCPacket, unsigned int estimatedPacketLength, unsigned char *computed_CRC)
|
|
97
|
int tc_parser(ccsdsTelecommandPacket_t * TCPacket, unsigned int estimatedPacketLength, unsigned char *computed_CRC)
|
|
97
|
{
|
|
98
|
{
|
|
98
|
/** This function parses TeleCommands.
|
|
99
|
/** This function parses TeleCommands.
|
|
99
|
*
|
|
100
|
*
|
|
100
|
* @param TC points to the TeleCommand that will be parsed.
|
|
101
|
* @param TC points to the TeleCommand that will be parsed.
|
|
101
|
* @param estimatedPacketLength is the PACKET_LENGTH field calculated from the effective length of the received packet.
|
|
102
|
* @param estimatedPacketLength is the PACKET_LENGTH field calculated from the effective length of the received packet.
|
|
102
|
*
|
|
103
|
*
|
|
103
|
* @return Status code of the parsing.
|
|
104
|
* @return Status code of the parsing.
|
|
104
|
*
|
|
105
|
*
|
|
105
|
* The parsing checks:
|
|
106
|
* The parsing checks:
|
|
106
|
* - process id
|
|
107
|
* - process id
|
|
107
|
* - category
|
|
108
|
* - category
|
|
108
|
* - length: a global check is performed and a per subtype check also
|
|
109
|
* - length: a global check is performed and a per subtype check also
|
|
109
|
* - type
|
|
110
|
* - type
|
|
110
|
* - subtype
|
|
111
|
* - subtype
|
|
111
|
* - crc
|
|
112
|
* - crc
|
|
112
|
*
|
|
113
|
*
|
|
113
|
*/
|
|
114
|
*/
|
|
114
|
|
|
115
|
|
|
115
|
int status;
|
|
116
|
int status;
|
|
116
|
int status_crc;
|
|
117
|
int status_crc;
|
|
117
|
unsigned char pid;
|
|
118
|
unsigned char pid;
|
|
118
|
unsigned char category;
|
|
119
|
unsigned char category;
|
|
119
|
unsigned int packetLength;
|
|
120
|
unsigned int packetLength;
|
|
120
|
unsigned char packetType;
|
|
121
|
unsigned char packetType;
|
|
121
|
unsigned char packetSubtype;
|
|
122
|
unsigned char packetSubtype;
|
|
122
|
unsigned char sid;
|
|
123
|
unsigned char sid;
|
|
123
|
|
|
124
|
|
|
124
|
status = CCSDS_TM_VALID;
|
|
125
|
status = CCSDS_TM_VALID;
|
|
125
|
|
|
126
|
|
|
126
|
// APID check *** APID on 2 bytes
|
|
127
|
// APID check *** APID on 2 bytes
|
|
127
|
pid = ((TCPacket->packetID[0] & 0x07)<<4) + ( (TCPacket->packetID[1]>>4) & 0x0f ); // PID = 11 *** 7 bits xxxxx210 7654xxxx
|
|
128
|
pid = ((TCPacket->packetID[0] & 0x07)<<4) + ( (TCPacket->packetID[1]>>4) & 0x0f ); // PID = 11 *** 7 bits xxxxx210 7654xxxx
|
|
128
|
category = (TCPacket->packetID[1] & 0x0f); // PACKET_CATEGORY = 12 *** 4 bits xxxxxxxx xxxx3210
|
|
129
|
category = (TCPacket->packetID[1] & 0x0f); // PACKET_CATEGORY = 12 *** 4 bits xxxxxxxx xxxx3210
|
|
129
|
packetLength = (TCPacket->packetLength[0] * 256) + TCPacket->packetLength[1];
|
|
130
|
packetLength = (TCPacket->packetLength[0] * 256) + TCPacket->packetLength[1];
|
|
130
|
packetType = TCPacket->serviceType;
|
|
131
|
packetType = TCPacket->serviceType;
|
|
131
|
packetSubtype = TCPacket->serviceSubType;
|
|
132
|
packetSubtype = TCPacket->serviceSubType;
|
|
132
|
sid = TCPacket->sourceID;
|
|
133
|
sid = TCPacket->sourceID;
|
|
133
|
|
|
134
|
|
|
134
|
if ( pid != CCSDS_PROCESS_ID ) // CHECK THE PROCESS ID
|
|
135
|
if ( pid != CCSDS_PROCESS_ID ) // CHECK THE PROCESS ID
|
|
135
|
{
|
|
136
|
{
|
|
136
|
status = ILLEGAL_APID;
|
|
137
|
status = ILLEGAL_APID;
|
|
137
|
}
|
|
138
|
}
|
|
138
|
if (status == CCSDS_TM_VALID) // CHECK THE CATEGORY
|
|
139
|
if (status == CCSDS_TM_VALID) // CHECK THE CATEGORY
|
|
139
|
{
|
|
140
|
{
|
|
140
|
if ( category != CCSDS_PACKET_CATEGORY )
|
|
141
|
if ( category != CCSDS_PACKET_CATEGORY )
|
|
141
|
{
|
|
142
|
{
|
|
142
|
status = ILLEGAL_APID;
|
|
143
|
status = ILLEGAL_APID;
|
|
143
|
}
|
|
144
|
}
|
|
144
|
}
|
|
145
|
}
|
|
145
|
if (status == CCSDS_TM_VALID) // CHECK THE PACKET_LENGTH FIELD AND THE ESTIMATED PACKET_LENGTH COMPLIANCE
|
|
146
|
if (status == CCSDS_TM_VALID) // CHECK THE PACKET_LENGTH FIELD AND THE ESTIMATED PACKET_LENGTH COMPLIANCE
|
|
146
|
{
|
|
147
|
{
|
|
147
|
if (packetLength != estimatedPacketLength ) {
|
|
148
|
if (packetLength != estimatedPacketLength ) {
|
|
148
|
status = WRONG_LEN_PKT;
|
|
149
|
status = WRONG_LEN_PKT;
|
|
149
|
}
|
|
150
|
}
|
|
150
|
}
|
|
151
|
}
|
|
151
|
if (status == CCSDS_TM_VALID) // CHECK THAT THE PACKET DOES NOT EXCEED THE MAX SIZE
|
|
152
|
if (status == CCSDS_TM_VALID) // CHECK THAT THE PACKET DOES NOT EXCEED THE MAX SIZE
|
|
152
|
{
|
|
153
|
{
|
|
153
|
if ( packetLength >= CCSDS_TC_PKT_MAX_SIZE ) {
|
|
154
|
if ( packetLength >= CCSDS_TC_PKT_MAX_SIZE ) {
|
|
154
|
status = WRONG_LEN_PKT;
|
|
155
|
status = WRONG_LEN_PKT;
|
|
155
|
}
|
|
156
|
}
|
|
156
|
}
|
|
157
|
}
|
|
157
|
if (status == CCSDS_TM_VALID) // CHECK THE TYPE
|
|
158
|
if (status == CCSDS_TM_VALID) // CHECK THE TYPE
|
|
158
|
{
|
|
159
|
{
|
|
159
|
status = tc_check_type( packetType );
|
|
160
|
status = tc_check_type( packetType );
|
|
160
|
}
|
|
161
|
}
|
|
161
|
if (status == CCSDS_TM_VALID) // CHECK THE SUBTYPE
|
|
162
|
if (status == CCSDS_TM_VALID) // CHECK THE SUBTYPE
|
|
162
|
{
|
|
163
|
{
|
|
163
|
status = tc_check_type_subtype( packetType, packetSubtype );
|
|
164
|
status = tc_check_type_subtype( packetType, packetSubtype );
|
|
164
|
}
|
|
165
|
}
|
|
165
|
if (status == CCSDS_TM_VALID) // CHECK THE SID
|
|
166
|
if (status == CCSDS_TM_VALID) // CHECK THE SID
|
|
166
|
{
|
|
167
|
{
|
|
167
|
status = tc_check_sid( sid );
|
|
168
|
status = tc_check_sid( sid );
|
|
168
|
}
|
|
169
|
}
|
|
169
|
if (status == CCSDS_TM_VALID) // CHECK THE SUBTYPE AND LENGTH COMPLIANCE
|
|
170
|
if (status == CCSDS_TM_VALID) // CHECK THE SUBTYPE AND LENGTH COMPLIANCE
|
|
170
|
{
|
|
171
|
{
|
|
171
|
status = tc_check_length( packetSubtype, packetLength );
|
|
172
|
status = tc_check_length( packetSubtype, packetLength );
|
|
172
|
}
|
|
173
|
}
|
|
173
|
status_crc = tc_check_crc( TCPacket, estimatedPacketLength, computed_CRC );
|
|
174
|
status_crc = tc_check_crc( TCPacket, estimatedPacketLength, computed_CRC );
|
|
174
|
if (status == CCSDS_TM_VALID ) // CHECK CRC
|
|
175
|
if (status == CCSDS_TM_VALID ) // CHECK CRC
|
|
175
|
{
|
|
176
|
{
|
|
176
|
status = status_crc;
|
|
177
|
status = status_crc;
|
|
177
|
}
|
|
178
|
}
|
|
178
|
|
|
179
|
|
|
179
|
return status;
|
|
180
|
return status;
|
|
180
|
}
|
|
181
|
}
|
|
181
|
|
|
182
|
|
|
182
|
int tc_check_type( unsigned char packetType )
|
|
183
|
int tc_check_type( unsigned char packetType )
|
|
183
|
{
|
|
184
|
{
|
|
184
|
/** This function checks that the type of a TeleCommand is valid.
|
|
185
|
/** This function checks that the type of a TeleCommand is valid.
|
|
185
|
*
|
|
186
|
*
|
|
186
|
* @param packetType is the type to check.
|
|
187
|
* @param packetType is the type to check.
|
|
187
|
*
|
|
188
|
*
|
|
188
|
* @return Status code CCSDS_TM_VALID or ILL_TYPE.
|
|
189
|
* @return Status code CCSDS_TM_VALID or ILL_TYPE.
|
|
189
|
*
|
|
190
|
*
|
|
190
|
*/
|
|
191
|
*/
|
|
191
|
|
|
192
|
|
|
192
|
int status;
|
|
193
|
int status;
|
|
193
|
|
|
194
|
|
|
194
|
if ( (packetType == TC_TYPE_GEN) || (packetType == TC_TYPE_TIME))
|
|
195
|
if ( (packetType == TC_TYPE_GEN) || (packetType == TC_TYPE_TIME))
|
|
195
|
{
|
|
196
|
{
|
|
196
|
status = CCSDS_TM_VALID;
|
|
197
|
status = CCSDS_TM_VALID;
|
|
197
|
}
|
|
198
|
}
|
|
198
|
else
|
|
199
|
else
|
|
199
|
{
|
|
200
|
{
|
|
200
|
status = ILL_TYPE;
|
|
201
|
status = ILL_TYPE;
|
|
201
|
}
|
|
202
|
}
|
|
202
|
|
|
203
|
|
|
203
|
return status;
|
|
204
|
return status;
|
|
204
|
}
|
|
205
|
}
|
|
205
|
|
|
206
|
|
|
206
|
int tc_check_type_subtype( unsigned char packetType, unsigned char packetSubType )
|
|
207
|
int tc_check_type_subtype( unsigned char packetType, unsigned char packetSubType )
|
|
207
|
{
|
|
208
|
{
|
|
208
|
/** This function checks that the subtype of a TeleCommand is valid and coherent with the type.
|
|
209
|
/** This function checks that the subtype of a TeleCommand is valid and coherent with the type.
|
|
209
|
*
|
|
210
|
*
|
|
210
|
* @param packetType is the type of the TC.
|
|
211
|
* @param packetType is the type of the TC.
|
|
211
|
* @param packetSubType is the subtype to check.
|
|
212
|
* @param packetSubType is the subtype to check.
|
|
212
|
*
|
|
213
|
*
|
|
213
|
* @return Status code CCSDS_TM_VALID or ILL_SUBTYPE.
|
|
214
|
* @return Status code CCSDS_TM_VALID or ILL_SUBTYPE.
|
|
214
|
*
|
|
215
|
*
|
|
215
|
*/
|
|
216
|
*/
|
|
216
|
|
|
217
|
|
|
217
|
int status;
|
|
218
|
int status;
|
|
218
|
|
|
219
|
|
|
219
|
switch(packetType)
|
|
220
|
switch(packetType)
|
|
220
|
{
|
|
221
|
{
|
|
221
|
case TC_TYPE_GEN:
|
|
222
|
case TC_TYPE_GEN:
|
|
222
|
if ( (packetSubType == TC_SUBTYPE_RESET)
|
|
223
|
if ( (packetSubType == TC_SUBTYPE_RESET)
|
|
223
|
|| (packetSubType == TC_SUBTYPE_LOAD_COMM)
|
|
224
|
|| (packetSubType == TC_SUBTYPE_LOAD_COMM)
|
|
224
|
|| (packetSubType == TC_SUBTYPE_LOAD_NORM) || (packetSubType == TC_SUBTYPE_LOAD_BURST)
|
|
225
|
|| (packetSubType == TC_SUBTYPE_LOAD_NORM) || (packetSubType == TC_SUBTYPE_LOAD_BURST)
|
|
225
|
|| (packetSubType == TC_SUBTYPE_LOAD_SBM1) || (packetSubType == TC_SUBTYPE_LOAD_SBM2)
|
|
226
|
|| (packetSubType == TC_SUBTYPE_LOAD_SBM1) || (packetSubType == TC_SUBTYPE_LOAD_SBM2)
|
|
226
|
|| (packetSubType == TC_SUBTYPE_DUMP)
|
|
227
|
|| (packetSubType == TC_SUBTYPE_DUMP)
|
|
227
|
|| (packetSubType == TC_SUBTYPE_ENTER)
|
|
228
|
|| (packetSubType == TC_SUBTYPE_ENTER)
|
|
228
|
|| (packetSubType == TC_SUBTYPE_UPDT_INFO)
|
|
229
|
|| (packetSubType == TC_SUBTYPE_UPDT_INFO)
|
|
229
|
|| (packetSubType == TC_SUBTYPE_EN_CAL) || (packetSubType == TC_SUBTYPE_DIS_CAL)
|
|
230
|
|| (packetSubType == TC_SUBTYPE_EN_CAL) || (packetSubType == TC_SUBTYPE_DIS_CAL)
|
|
230
|
|| (packetSubType == TC_SUBTYPE_LOAD_K) || (packetSubType == TC_SUBTYPE_DUMP_K)
|
|
231
|
|| (packetSubType == TC_SUBTYPE_LOAD_K) || (packetSubType == TC_SUBTYPE_DUMP_K)
|
|
231
|
|| (packetSubType == TC_SUBTYPE_LOAD_FBINS) )
|
|
232
|
|| (packetSubType == TC_SUBTYPE_LOAD_FBINS) )
|
|
232
|
{
|
|
233
|
{
|
|
233
|
status = CCSDS_TM_VALID;
|
|
234
|
status = CCSDS_TM_VALID;
|
|
234
|
}
|
|
235
|
}
|
|
235
|
else
|
|
236
|
else
|
|
236
|
{
|
|
237
|
{
|
|
237
|
status = ILL_SUBTYPE;
|
|
238
|
status = ILL_SUBTYPE;
|
|
238
|
}
|
|
239
|
}
|
|
239
|
break;
|
|
240
|
break;
|
|
240
|
|
|
241
|
|
|
241
|
case TC_TYPE_TIME:
|
|
242
|
case TC_TYPE_TIME:
|
|
242
|
if (packetSubType == TC_SUBTYPE_UPDT_TIME)
|
|
243
|
if (packetSubType == TC_SUBTYPE_UPDT_TIME)
|
|
243
|
{
|
|
244
|
{
|
|
244
|
status = CCSDS_TM_VALID;
|
|
245
|
status = CCSDS_TM_VALID;
|
|
245
|
}
|
|
246
|
}
|
|
246
|
else
|
|
247
|
else
|
|
247
|
{
|
|
248
|
{
|
|
248
|
status = ILL_SUBTYPE;
|
|
249
|
status = ILL_SUBTYPE;
|
|
249
|
}
|
|
250
|
}
|
|
250
|
break;
|
|
251
|
break;
|
|
251
|
|
|
252
|
|
|
252
|
default:
|
|
253
|
default:
|
|
253
|
status = ILL_SUBTYPE;
|
|
254
|
status = ILL_SUBTYPE;
|
|
254
|
break;
|
|
255
|
break;
|
|
255
|
}
|
|
256
|
}
|
|
256
|
|
|
257
|
|
|
257
|
return status;
|
|
258
|
return status;
|
|
258
|
}
|
|
259
|
}
|
|
259
|
|
|
260
|
|
|
260
|
int tc_check_sid( unsigned char sid )
|
|
261
|
int tc_check_sid( unsigned char sid )
|
|
261
|
{
|
|
262
|
{
|
|
262
|
/** This function checks that the sid of a TeleCommand is valid.
|
|
263
|
/** This function checks that the sid of a TeleCommand is valid.
|
|
263
|
*
|
|
264
|
*
|
|
264
|
* @param sid is the sid to check.
|
|
265
|
* @param sid is the sid to check.
|
|
265
|
*
|
|
266
|
*
|
|
266
|
* @return Status code CCSDS_TM_VALID or CORRUPTED.
|
|
267
|
* @return Status code CCSDS_TM_VALID or CORRUPTED.
|
|
267
|
*
|
|
268
|
*
|
|
268
|
*/
|
|
269
|
*/
|
|
269
|
|
|
270
|
|
|
270
|
int status;
|
|
271
|
int status;
|
|
271
|
|
|
272
|
|
|
272
|
if ( (sid == SID_TC_MISSION_TIMELINE) || (sid == SID_TC_TC_SEQUENCES) || (sid == SID_TC_RECOVERY_ACTION_CMD)
|
|
273
|
if ( (sid == SID_TC_MISSION_TIMELINE) || (sid == SID_TC_TC_SEQUENCES) || (sid == SID_TC_RECOVERY_ACTION_CMD)
|
|
273
|
|| (sid == SID_TC_BACKUP_MISSION_TIMELINE)
|
|
274
|
|| (sid == SID_TC_BACKUP_MISSION_TIMELINE)
|
|
274
|
|| (sid == SID_TC_DIRECT_CMD) || (sid == SID_TC_SPARE_GRD_SRC1) || (sid == SID_TC_SPARE_GRD_SRC2)
|
|
275
|
|| (sid == SID_TC_DIRECT_CMD) || (sid == SID_TC_SPARE_GRD_SRC1) || (sid == SID_TC_SPARE_GRD_SRC2)
|
|
275
|
|| (sid == SID_TC_OBCP) || (sid == SID_TC_SYSTEM_CONTROL) || (sid == SID_TC_AOCS)
|
|
276
|
|| (sid == SID_TC_OBCP) || (sid == SID_TC_SYSTEM_CONTROL) || (sid == SID_TC_AOCS)
|
|
276
|
|| (sid == SID_TC_RPW_INTERNAL))
|
|
277
|
|| (sid == SID_TC_RPW_INTERNAL))
|
|
277
|
{
|
|
278
|
{
|
|
278
|
status = CCSDS_TM_VALID;
|
|
279
|
status = CCSDS_TM_VALID;
|
|
279
|
}
|
|
280
|
}
|
|
280
|
else
|
|
281
|
else
|
|
281
|
{
|
|
282
|
{
|
|
282
|
status = WRONG_SRC_ID;
|
|
283
|
status = WRONG_SRC_ID;
|
|
283
|
}
|
|
284
|
}
|
|
284
|
|
|
285
|
|
|
285
|
return status;
|
|
286
|
return status;
|
|
286
|
}
|
|
287
|
}
|
|
287
|
|
|
288
|
|
|
288
|
int tc_check_length( unsigned char packetSubType, unsigned int length )
|
|
289
|
int tc_check_length( unsigned char packetSubType, unsigned int length )
|
|
289
|
{
|
|
290
|
{
|
|
290
|
/** This function checks that the subtype and the length are compliant.
|
|
291
|
/** This function checks that the subtype and the length are compliant.
|
|
291
|
*
|
|
292
|
*
|
|
292
|
* @param packetSubType is the subtype to check.
|
|
293
|
* @param packetSubType is the subtype to check.
|
|
293
|
* @param length is the length to check.
|
|
294
|
* @param length is the length to check.
|
|
294
|
*
|
|
295
|
*
|
|
295
|
* @return Status code CCSDS_TM_VALID or ILL_TYPE.
|
|
296
|
* @return Status code CCSDS_TM_VALID or ILL_TYPE.
|
|
296
|
*
|
|
297
|
*
|
|
297
|
*/
|
|
298
|
*/
|
|
298
|
|
|
299
|
|
|
299
|
int status;
|
|
300
|
int status;
|
|
300
|
|
|
301
|
|
|
301
|
status = LFR_SUCCESSFUL;
|
|
302
|
status = LFR_SUCCESSFUL;
|
|
302
|
|
|
303
|
|
|
303
|
switch(packetSubType)
|
|
304
|
switch(packetSubType)
|
|
304
|
{
|
|
305
|
{
|
|
305
|
case TC_SUBTYPE_RESET:
|
|
306
|
case TC_SUBTYPE_RESET:
|
|
306
|
if (length!=(TC_LEN_RESET-CCSDS_TC_TM_PACKET_OFFSET)) {
|
|
307
|
if (length!=(TC_LEN_RESET-CCSDS_TC_TM_PACKET_OFFSET)) {
|
|
307
|
status = WRONG_LEN_PKT;
|
|
308
|
status = WRONG_LEN_PKT;
|
|
308
|
}
|
|
309
|
}
|
|
309
|
else {
|
|
310
|
else {
|
|
310
|
status = CCSDS_TM_VALID;
|
|
311
|
status = CCSDS_TM_VALID;
|
|
311
|
}
|
|
312
|
}
|
|
312
|
break;
|
|
313
|
break;
|
|
313
|
case TC_SUBTYPE_LOAD_COMM:
|
|
314
|
case TC_SUBTYPE_LOAD_COMM:
|
|
314
|
if (length!=(TC_LEN_LOAD_COMM-CCSDS_TC_TM_PACKET_OFFSET)) {
|
|
315
|
if (length!=(TC_LEN_LOAD_COMM-CCSDS_TC_TM_PACKET_OFFSET)) {
|
|
315
|
status = WRONG_LEN_PKT;
|
|
316
|
status = WRONG_LEN_PKT;
|
|
316
|
}
|
|
317
|
}
|
|
317
|
else {
|
|
318
|
else {
|
|
318
|
status = CCSDS_TM_VALID;
|
|
319
|
status = CCSDS_TM_VALID;
|
|
319
|
}
|
|
320
|
}
|
|
320
|
break;
|
|
321
|
break;
|
|
321
|
case TC_SUBTYPE_LOAD_NORM:
|
|
322
|
case TC_SUBTYPE_LOAD_NORM:
|
|
322
|
if (length!=(TC_LEN_LOAD_NORM-CCSDS_TC_TM_PACKET_OFFSET)) {
|
|
323
|
if (length!=(TC_LEN_LOAD_NORM-CCSDS_TC_TM_PACKET_OFFSET)) {
|
|
323
|
status = WRONG_LEN_PKT;
|
|
324
|
status = WRONG_LEN_PKT;
|
|
324
|
}
|
|
325
|
}
|
|
325
|
else {
|
|
326
|
else {
|
|
326
|
status = CCSDS_TM_VALID;
|
|
327
|
status = CCSDS_TM_VALID;
|
|
327
|
}
|
|
328
|
}
|
|
328
|
break;
|
|
329
|
break;
|
|
329
|
case TC_SUBTYPE_LOAD_BURST:
|
|
330
|
case TC_SUBTYPE_LOAD_BURST:
|
|
330
|
if (length!=(TC_LEN_LOAD_BURST-CCSDS_TC_TM_PACKET_OFFSET)) {
|
|
331
|
if (length!=(TC_LEN_LOAD_BURST-CCSDS_TC_TM_PACKET_OFFSET)) {
|
|
331
|
status = WRONG_LEN_PKT;
|
|
332
|
status = WRONG_LEN_PKT;
|
|
332
|
}
|
|
333
|
}
|
|
333
|
else {
|
|
334
|
else {
|
|
334
|
status = CCSDS_TM_VALID;
|
|
335
|
status = CCSDS_TM_VALID;
|
|
335
|
}
|
|
336
|
}
|
|
336
|
break;
|
|
337
|
break;
|
|
337
|
case TC_SUBTYPE_LOAD_SBM1:
|
|
338
|
case TC_SUBTYPE_LOAD_SBM1:
|
|
338
|
if (length!=(TC_LEN_LOAD_SBM1-CCSDS_TC_TM_PACKET_OFFSET)) {
|
|
339
|
if (length!=(TC_LEN_LOAD_SBM1-CCSDS_TC_TM_PACKET_OFFSET)) {
|
|
339
|
status = WRONG_LEN_PKT;
|
|
340
|
status = WRONG_LEN_PKT;
|
|
340
|
}
|
|
341
|
}
|
|
341
|
else {
|
|
342
|
else {
|
|
342
|
status = CCSDS_TM_VALID;
|
|
343
|
status = CCSDS_TM_VALID;
|
|
343
|
}
|
|
344
|
}
|
|
344
|
break;
|
|
345
|
break;
|
|
345
|
case TC_SUBTYPE_LOAD_SBM2:
|
|
346
|
case TC_SUBTYPE_LOAD_SBM2:
|
|
346
|
if (length!=(TC_LEN_LOAD_SBM2-CCSDS_TC_TM_PACKET_OFFSET)) {
|
|
347
|
if (length!=(TC_LEN_LOAD_SBM2-CCSDS_TC_TM_PACKET_OFFSET)) {
|
|
347
|
status = WRONG_LEN_PKT;
|
|
348
|
status = WRONG_LEN_PKT;
|
|
348
|
}
|
|
349
|
}
|
|
349
|
else {
|
|
350
|
else {
|
|
350
|
status = CCSDS_TM_VALID;
|
|
351
|
status = CCSDS_TM_VALID;
|
|
351
|
}
|
|
352
|
}
|
|
352
|
break;
|
|
353
|
break;
|
|
353
|
case TC_SUBTYPE_DUMP:
|
|
354
|
case TC_SUBTYPE_DUMP:
|
|
354
|
if (length!=(TC_LEN_DUMP-CCSDS_TC_TM_PACKET_OFFSET)) {
|
|
355
|
if (length!=(TC_LEN_DUMP-CCSDS_TC_TM_PACKET_OFFSET)) {
|
|
355
|
status = WRONG_LEN_PKT;
|
|
356
|
status = WRONG_LEN_PKT;
|
|
356
|
}
|
|
357
|
}
|
|
357
|
else {
|
|
358
|
else {
|
|
358
|
status = CCSDS_TM_VALID;
|
|
359
|
status = CCSDS_TM_VALID;
|
|
359
|
}
|
|
360
|
}
|
|
360
|
break;
|
|
361
|
break;
|
|
361
|
case TC_SUBTYPE_ENTER:
|
|
362
|
case TC_SUBTYPE_ENTER:
|
|
362
|
if (length!=(TC_LEN_ENTER-CCSDS_TC_TM_PACKET_OFFSET)) {
|
|
363
|
if (length!=(TC_LEN_ENTER-CCSDS_TC_TM_PACKET_OFFSET)) {
|
|
363
|
status = WRONG_LEN_PKT;
|
|
364
|
status = WRONG_LEN_PKT;
|
|
364
|
}
|
|
365
|
}
|
|
365
|
else {
|
|
366
|
else {
|
|
366
|
status = CCSDS_TM_VALID;
|
|
367
|
status = CCSDS_TM_VALID;
|
|
367
|
}
|
|
368
|
}
|
|
368
|
break;
|
|
369
|
break;
|
|
369
|
case TC_SUBTYPE_UPDT_INFO:
|
|
370
|
case TC_SUBTYPE_UPDT_INFO:
|
|
370
|
if (length!=(TC_LEN_UPDT_INFO-CCSDS_TC_TM_PACKET_OFFSET)) {
|
|
371
|
if (length!=(TC_LEN_UPDT_INFO-CCSDS_TC_TM_PACKET_OFFSET)) {
|
|
371
|
status = WRONG_LEN_PKT;
|
|
372
|
status = WRONG_LEN_PKT;
|
|
372
|
}
|
|
373
|
}
|
|
373
|
else {
|
|
374
|
else {
|
|
374
|
status = CCSDS_TM_VALID;
|
|
375
|
status = CCSDS_TM_VALID;
|
|
375
|
}
|
|
376
|
}
|
|
376
|
break;
|
|
377
|
break;
|
|
377
|
case TC_SUBTYPE_EN_CAL:
|
|
378
|
case TC_SUBTYPE_EN_CAL:
|
|
378
|
if (length!=(TC_LEN_EN_CAL-CCSDS_TC_TM_PACKET_OFFSET)) {
|
|
379
|
if (length!=(TC_LEN_EN_CAL-CCSDS_TC_TM_PACKET_OFFSET)) {
|
|
379
|
status = WRONG_LEN_PKT;
|
|
380
|
status = WRONG_LEN_PKT;
|
|
380
|
}
|
|
381
|
}
|
|
381
|
else {
|
|
382
|
else {
|
|
382
|
status = CCSDS_TM_VALID;
|
|
383
|
status = CCSDS_TM_VALID;
|
|
383
|
}
|
|
384
|
}
|
|
384
|
break;
|
|
385
|
break;
|
|
385
|
case TC_SUBTYPE_DIS_CAL:
|
|
386
|
case TC_SUBTYPE_DIS_CAL:
|
|
386
|
if (length!=(TC_LEN_DIS_CAL-CCSDS_TC_TM_PACKET_OFFSET)) {
|
|
387
|
if (length!=(TC_LEN_DIS_CAL-CCSDS_TC_TM_PACKET_OFFSET)) {
|
|
387
|
status = WRONG_LEN_PKT;
|
|
388
|
status = WRONG_LEN_PKT;
|
|
388
|
}
|
|
389
|
}
|
|
389
|
else {
|
|
390
|
else {
|
|
390
|
status = CCSDS_TM_VALID;
|
|
391
|
status = CCSDS_TM_VALID;
|
|
391
|
}
|
|
392
|
}
|
|
392
|
break;
|
|
393
|
break;
|
|
393
|
case TC_SUBTYPE_LOAD_K:
|
|
394
|
case TC_SUBTYPE_LOAD_K:
|
|
394
|
if (length!=(TC_LEN_LOAD_K-CCSDS_TC_TM_PACKET_OFFSET)) {
|
|
395
|
if (length!=(TC_LEN_LOAD_K-CCSDS_TC_TM_PACKET_OFFSET)) {
|
|
395
|
status = WRONG_LEN_PKT;
|
|
396
|
status = WRONG_LEN_PKT;
|
|
396
|
}
|
|
397
|
}
|
|
397
|
else {
|
|
398
|
else {
|
|
398
|
status = CCSDS_TM_VALID;
|
|
399
|
status = CCSDS_TM_VALID;
|
|
399
|
}
|
|
400
|
}
|
|
400
|
break;
|
|
401
|
break;
|
|
401
|
case TC_SUBTYPE_DUMP_K:
|
|
402
|
case TC_SUBTYPE_DUMP_K:
|
|
402
|
if (length!=(TC_LEN_DUMP_K-CCSDS_TC_TM_PACKET_OFFSET)) {
|
|
403
|
if (length!=(TC_LEN_DUMP_K-CCSDS_TC_TM_PACKET_OFFSET)) {
|
|
403
|
status = WRONG_LEN_PKT;
|
|
404
|
status = WRONG_LEN_PKT;
|
|
404
|
}
|
|
405
|
}
|
|
405
|
else {
|
|
406
|
else {
|
|
406
|
status = CCSDS_TM_VALID;
|
|
407
|
status = CCSDS_TM_VALID;
|
|
407
|
}
|
|
408
|
}
|
|
408
|
break;
|
|
409
|
break;
|
|
409
|
case TC_SUBTYPE_LOAD_FBINS:
|
|
410
|
case TC_SUBTYPE_LOAD_FBINS:
|
|
410
|
if (length!=(TC_LEN_LOAD_FBINS-CCSDS_TC_TM_PACKET_OFFSET)) {
|
|
411
|
if (length!=(TC_LEN_LOAD_FBINS-CCSDS_TC_TM_PACKET_OFFSET)) {
|
|
411
|
status = WRONG_LEN_PKT;
|
|
412
|
status = WRONG_LEN_PKT;
|
|
412
|
}
|
|
413
|
}
|
|
413
|
else {
|
|
414
|
else {
|
|
414
|
status = CCSDS_TM_VALID;
|
|
415
|
status = CCSDS_TM_VALID;
|
|
415
|
}
|
|
416
|
}
|
|
416
|
break;
|
|
417
|
break;
|
|
417
|
case TC_SUBTYPE_UPDT_TIME:
|
|
418
|
case TC_SUBTYPE_UPDT_TIME:
|
|
418
|
if (length!=(TC_LEN_UPDT_TIME-CCSDS_TC_TM_PACKET_OFFSET)) {
|
|
419
|
if (length!=(TC_LEN_UPDT_TIME-CCSDS_TC_TM_PACKET_OFFSET)) {
|
|
419
|
status = WRONG_LEN_PKT;
|
|
420
|
status = WRONG_LEN_PKT;
|
|
420
|
}
|
|
421
|
}
|
|
421
|
else {
|
|
422
|
else {
|
|
422
|
status = CCSDS_TM_VALID;
|
|
423
|
status = CCSDS_TM_VALID;
|
|
423
|
}
|
|
424
|
}
|
|
424
|
break;
|
|
425
|
break;
|
|
425
|
default: // if the subtype is not a legal value, return ILL_SUBTYPE
|
|
426
|
default: // if the subtype is not a legal value, return ILL_SUBTYPE
|
|
426
|
status = ILL_SUBTYPE;
|
|
427
|
status = ILL_SUBTYPE;
|
|
427
|
break ;
|
|
428
|
break ;
|
|
428
|
}
|
|
429
|
}
|
|
429
|
|
|
430
|
|
|
430
|
return status;
|
|
431
|
return status;
|
|
431
|
}
|
|
432
|
}
|
|
432
|
|
|
433
|
|
|
433
|
int tc_check_crc( ccsdsTelecommandPacket_t * TCPacket, unsigned int length, unsigned char *computed_CRC )
|
|
434
|
int tc_check_crc( ccsdsTelecommandPacket_t * TCPacket, unsigned int length, unsigned char *computed_CRC )
|
|
434
|
{
|
|
435
|
{
|
|
435
|
/** This function checks the CRC validity of the corresponding TeleCommand packet.
|
|
436
|
/** This function checks the CRC validity of the corresponding TeleCommand packet.
|
|
436
|
*
|
|
437
|
*
|
|
437
|
* @param TCPacket points to the TeleCommand packet to check.
|
|
438
|
* @param TCPacket points to the TeleCommand packet to check.
|
|
438
|
* @param length is the length of the TC packet.
|
|
439
|
* @param length is the length of the TC packet.
|
|
439
|
*
|
|
440
|
*
|
|
440
|
* @return Status code CCSDS_TM_VALID or INCOR_CHECKSUM.
|
|
441
|
* @return Status code CCSDS_TM_VALID or INCOR_CHECKSUM.
|
|
441
|
*
|
|
442
|
*
|
|
442
|
*/
|
|
443
|
*/
|
|
443
|
|
|
444
|
|
|
444
|
int status;
|
|
445
|
int status;
|
|
445
|
unsigned char * CCSDSContent;
|
|
446
|
unsigned char * CCSDSContent;
|
|
446
|
|
|
447
|
|
|
447
|
CCSDSContent = (unsigned char*) TCPacket->packetID;
|
|
448
|
CCSDSContent = (unsigned char*) TCPacket->packetID;
|
|
448
|
GetCRCAsTwoBytes(CCSDSContent, computed_CRC, length + CCSDS_TC_TM_PACKET_OFFSET - 2); // 2 CRC bytes removed from the calculation of the CRC
|
|
449
|
GetCRCAsTwoBytes(CCSDSContent, computed_CRC, length + CCSDS_TC_TM_PACKET_OFFSET - 2); // 2 CRC bytes removed from the calculation of the CRC
|
|
|
|
|
450
|
|
|
449
|
if (computed_CRC[0] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -2]) {
|
|
451
|
if (computed_CRC[0] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -2]) {
|
|
450
|
status = INCOR_CHECKSUM;
|
|
452
|
status = INCOR_CHECKSUM;
|
|
451
|
}
|
|
453
|
}
|
|
452
|
else if (computed_CRC[1] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -1]) {
|
|
454
|
else if (computed_CRC[1] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -1]) {
|
|
453
|
status = INCOR_CHECKSUM;
|
|
455
|
status = INCOR_CHECKSUM;
|
|
454
|
}
|
|
456
|
}
|
|
455
|
else {
|
|
457
|
else {
|
|
456
|
status = CCSDS_TM_VALID;
|
|
458
|
status = CCSDS_TM_VALID;
|
|
457
|
}
|
|
459
|
}
|
|
458
|
|
|
460
|
|
|
459
|
return status;
|
|
461
|
return status;
|
|
460
|
}
|
|
462
|
}
|
|
461
|
|
|
463
|
|
|
462
|
|
|
464
|
|
|
463
|
|
|
465
|
|