pl ack in tmtc

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of COM_MNG_TMTC_SIMPLE_pl123 by shubham c

Committer:
aniruddhv
Date:
Thu Dec 31 11:49:42 2015 +0000
Revision:
12:ffdb29353058
Parent:
5:ab276a17ca07
Removed Print statements

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shreeshas95 0:f016e9e8d48b 1 #define flushData_appendTC(bytes, outState) {\
shreeshas95 0:f016e9e8d48b 2 uint16_t tc_type = 2;\
shreeshas95 0:f016e9e8d48b 3 if( (bytes == TC_SHORT_SIZE) && (outState == 7) ){\
shreeshas95 4:104dd82c99b8 4 tc_type = SHORT_TC_CODE;\
shreeshas95 0:f016e9e8d48b 5 }\
shreeshas95 0:f016e9e8d48b 6 else if( (bytes == TC_LONG_SIZE) && (outState == 7) ){\
shreeshas95 4:104dd82c99b8 7 tc_type = LONG_TC_CODE;\
shreeshas95 0:f016e9e8d48b 8 }\
shreeshas95 0:f016e9e8d48b 9 else{\
shreeshas95 5:ab276a17ca07 10 /*gPC.puts("incorrect size\r\n");*/\
shreeshas95 5:ab276a17ca07 11 /*gPC.printf("%u, %u\r\n", bytes, outState);*/\
shreeshas95 2:2caf2a9a13aa 12 ++gTOTAL_INCORRECT_SIZE_TC;\
shreeshas95 0:f016e9e8d48b 13 }\
shreeshas95 4:104dd82c99b8 14 if( tc_type == SHORT_TC_CODE ){\
shreeshas95 0:f016e9e8d48b 15 uint16_t crc_checksum = crc16_gen(rx_tempString, TC_SHORT_SIZE-2);\
shreeshas95 0:f016e9e8d48b 16 if( ( (crc_checksum & 0xFF) == rx_tempString[TC_SHORT_SIZE-1]) && ( ((crc_checksum >> 8) & 0xFF) == rx_tempString[TC_SHORT_SIZE-2] ) ){\
shreeshas95 0:f016e9e8d48b 17 uint16_t temp16;\
shreeshas95 0:f016e9e8d48b 18 Base_tc *temp_ptr = gHEAD_NODE_TCL;\
shreeshas95 0:f016e9e8d48b 19 bool repeat_flag = false;\
shreeshas95 0:f016e9e8d48b 20 uint8_t testPSC = rx_tempString[0];\
shreeshas95 0:f016e9e8d48b 21 while(temp_ptr != NULL){\
shreeshas95 0:f016e9e8d48b 22 if( GETpacket_seq_count(temp_ptr) == testPSC ){\
shreeshas95 0:f016e9e8d48b 23 repeat_flag = true;\
shreeshas95 0:f016e9e8d48b 24 break;\
shreeshas95 0:f016e9e8d48b 25 }\
shreeshas95 0:f016e9e8d48b 26 temp_ptr = temp_ptr->next_TC;\
shreeshas95 0:f016e9e8d48b 27 }\
shreeshas95 0:f016e9e8d48b 28 if( repeat_flag == false ){\
shreeshas95 5:ab276a17ca07 29 if( gTOTAL_VALID_TC == 0 ){\
shreeshas95 0:f016e9e8d48b 30 gHEAD_NODE_TCL = new Short_tc;\
shreeshas95 0:f016e9e8d48b 31 gHEAD_NODE_TCL->next_TC = NULL;\
shreeshas95 0:f016e9e8d48b 32 gLAST_NODE_TCL = gHEAD_NODE_TCL;\
shreeshas95 0:f016e9e8d48b 33 }\
shreeshas95 0:f016e9e8d48b 34 else{\
shreeshas95 0:f016e9e8d48b 35 gLAST_NODE_TCL->next_TC = new Short_tc;\
shreeshas95 4:104dd82c99b8 36 gLAST_NODE_TCL = gLAST_NODE_TCL->next_TC;\
shreeshas95 0:f016e9e8d48b 37 gLAST_NODE_TCL->next_TC = NULL;\
shreeshas95 0:f016e9e8d48b 38 }\
shreeshas95 5:ab276a17ca07 39 /*gPC.puts("printing tx string\r\n");*/\
shreeshas95 0:f016e9e8d48b 40 for(int i = 0 ; i < TC_SHORT_SIZE ; ++i){\
shreeshas95 0:f016e9e8d48b 41 gLAST_NODE_TCL->TC_string[i] = rx_tempString[i];\
shreeshas95 0:f016e9e8d48b 42 }\
shreeshas95 0:f016e9e8d48b 43 PUTshort_or_long(gLAST_NODE_TCL, tc_type);\
shreeshas95 0:f016e9e8d48b 44 temp16 = 1;\
shreeshas95 0:f016e9e8d48b 45 PUTcrc_pass(gLAST_NODE_TCL, temp16);\
shreeshas95 0:f016e9e8d48b 46 temp16 = 0;\
shreeshas95 0:f016e9e8d48b 47 PUTexec_status(gLAST_NODE_TCL, temp16);\
shreeshas95 0:f016e9e8d48b 48 ++gTOTAL_VALID_TC;\
shreeshas95 0:f016e9e8d48b 49 }\
shreeshas95 2:2caf2a9a13aa 50 else{\
aniruddhv 12:ffdb29353058 51 /*gPC.puts("repeated psc short\r\n");*/\
shreeshas95 2:2caf2a9a13aa 52 ++gTOTAL_REPEATED_TC;\
shreeshas95 2:2caf2a9a13aa 53 }\
shreeshas95 0:f016e9e8d48b 54 }\
shreeshas95 0:f016e9e8d48b 55 else{\
aniruddhv 12:ffdb29353058 56 /*gPC.puts("crc fail tc short\r\n");*/\
shreeshas95 0:f016e9e8d48b 57 ++gTOTAL_CRC_FAIL_TC;\
shreeshas95 0:f016e9e8d48b 58 }\
shreeshas95 0:f016e9e8d48b 59 }\
shreeshas95 4:104dd82c99b8 60 else if( tc_type == LONG_TC_CODE ){\
shreeshas95 0:f016e9e8d48b 61 uint16_t crc_checksum = crc16_gen(rx_tempString, TC_LONG_SIZE-2);\
shreeshas95 0:f016e9e8d48b 62 if( ( (crc_checksum & 0xFF) == rx_tempString[TC_LONG_SIZE-1]) && ( ((crc_checksum >> 8) & 0xFF) == rx_tempString[TC_LONG_SIZE-2] ) ){\
shreeshas95 0:f016e9e8d48b 63 uint16_t temp16;\
shreeshas95 0:f016e9e8d48b 64 Base_tc *temp_ptr = gHEAD_NODE_TCL;\
shreeshas95 0:f016e9e8d48b 65 bool repeat_flag = false;\
shreeshas95 0:f016e9e8d48b 66 uint8_t testPSC = rx_tempString[0];\
shreeshas95 0:f016e9e8d48b 67 while(temp_ptr != NULL){\
shreeshas95 0:f016e9e8d48b 68 if( GETpacket_seq_count(temp_ptr) == testPSC ){\
shreeshas95 0:f016e9e8d48b 69 repeat_flag = true;\
shreeshas95 0:f016e9e8d48b 70 break;\
shreeshas95 0:f016e9e8d48b 71 }\
shreeshas95 0:f016e9e8d48b 72 temp_ptr = temp_ptr->next_TC;\
shreeshas95 0:f016e9e8d48b 73 }\
shreeshas95 0:f016e9e8d48b 74 if( repeat_flag == false ){\
shreeshas95 5:ab276a17ca07 75 if( gTOTAL_VALID_TC == 0 ){\
shreeshas95 0:f016e9e8d48b 76 gHEAD_NODE_TCL = new Long_tc;\
shreeshas95 0:f016e9e8d48b 77 gHEAD_NODE_TCL->next_TC = NULL;\
shreeshas95 0:f016e9e8d48b 78 gLAST_NODE_TCL = gHEAD_NODE_TCL;\
shreeshas95 0:f016e9e8d48b 79 }\
shreeshas95 0:f016e9e8d48b 80 else{\
shreeshas95 0:f016e9e8d48b 81 gLAST_NODE_TCL->next_TC = new Long_tc;\
shreeshas95 0:f016e9e8d48b 82 gLAST_NODE_TCL = gLAST_NODE_TCL->next_TC;\
shreeshas95 0:f016e9e8d48b 83 gLAST_NODE_TCL->next_TC = NULL;\
shreeshas95 0:f016e9e8d48b 84 }\
shreeshas95 5:ab276a17ca07 85 /*gPC.puts("printing tx string\r\n");*/\
shreeshas95 0:f016e9e8d48b 86 for(int i = 0 ; i < TC_LONG_SIZE ; ++i){\
shreeshas95 0:f016e9e8d48b 87 gLAST_NODE_TCL->TC_string[i] = rx_tempString[i];\
shreeshas95 0:f016e9e8d48b 88 }\
shreeshas95 0:f016e9e8d48b 89 PUTshort_or_long(gLAST_NODE_TCL, tc_type);\
shreeshas95 0:f016e9e8d48b 90 temp16 = 1;\
shreeshas95 0:f016e9e8d48b 91 PUTcrc_pass(gLAST_NODE_TCL, temp16);\
shreeshas95 0:f016e9e8d48b 92 temp16 = 0;\
shreeshas95 0:f016e9e8d48b 93 PUTexec_status(gLAST_NODE_TCL, temp16);\
shreeshas95 0:f016e9e8d48b 94 ++gTOTAL_VALID_TC;\
shreeshas95 0:f016e9e8d48b 95 }\
shreeshas95 2:2caf2a9a13aa 96 else{\
aniruddhv 12:ffdb29353058 97 /*gPC.puts("repeated psc long\r\n");*/\
shreeshas95 2:2caf2a9a13aa 98 ++gTOTAL_REPEATED_TC;\
shreeshas95 2:2caf2a9a13aa 99 }\
shreeshas95 0:f016e9e8d48b 100 }\
shreeshas95 0:f016e9e8d48b 101 else{\
aniruddhv 12:ffdb29353058 102 /*gPC.puts("crc fail tc long\r\n");*/\
shreeshas95 0:f016e9e8d48b 103 ++gTOTAL_CRC_FAIL_TC;\
shreeshas95 0:f016e9e8d48b 104 }\
shreeshas95 0:f016e9e8d48b 105 }\
shreeshas95 0:f016e9e8d48b 106 }
shreeshas95 0:f016e9e8d48b 107
shreeshas95 0:f016e9e8d48b 108 unsigned char rx_tempString[TC_LONG_SIZE+1];
shreeshas95 0:f016e9e8d48b 109
shreeshas95 0:f016e9e8d48b 110 void raw_data_to_tc(void){
aniruddhv 12:ffdb29353058 111 /*gPC.puts("inside raw_data_to_tc\r\n")*/;
shreeshas95 0:f016e9e8d48b 112 bool frame_started = false;
shreeshas95 0:f016e9e8d48b 113 bool chain_started = false;
shreeshas95 0:f016e9e8d48b 114 bool flush_called = false;
shreeshas95 0:f016e9e8d48b 115
shreeshas95 0:f016e9e8d48b 116 uint32_t bytes_read = 0;
shreeshas95 0:f016e9e8d48b 117 uint8_t state7e = 0;
shreeshas95 0:f016e9e8d48b 118 uint8_t outState = 0;
shreeshas95 0:f016e9e8d48b 119 uint32_t outByte = 0;
shreeshas95 0:f016e9e8d48b 120 uint32_t byteCount = 0;
shreeshas95 2:2caf2a9a13aa 121
shreeshas95 0:f016e9e8d48b 122 COM_RX_DATA_NODE *data_node = gRX_HEAD_DATA_NODE;
shreeshas95 0:f016e9e8d48b 123 // read byte by byte
shreeshas95 0:f016e9e8d48b 124 while( data_node != NULL ){
shreeshas95 0:f016e9e8d48b 125 for(int iBuf = 0 ; iBuf < RX_BUFFER_LENGTH ; ++iBuf ){
shreeshas95 0:f016e9e8d48b 126 uint8_t test_this = data_node->values[iBuf];
shreeshas95 0:f016e9e8d48b 127 ++bytes_read;
shreeshas95 0:f016e9e8d48b 128
shreeshas95 0:f016e9e8d48b 129 // read bit by bit
shreeshas95 0:f016e9e8d48b 130 for(int i = 7 ; i >= 0 ; --i){
shreeshas95 0:f016e9e8d48b 131 unsigned char tempBit = (test_this >> i) & 1;
shreeshas95 0:f016e9e8d48b 132 bool skipIteration = false;
shreeshas95 0:f016e9e8d48b 133
shreeshas95 0:f016e9e8d48b 134 if( tempBit == 1 ){
shreeshas95 0:f016e9e8d48b 135 switch( state7e ){
shreeshas95 0:f016e9e8d48b 136 case 0:
shreeshas95 0:f016e9e8d48b 137 state7e = 0;
shreeshas95 0:f016e9e8d48b 138 break;
shreeshas95 0:f016e9e8d48b 139 case 1:
shreeshas95 0:f016e9e8d48b 140 state7e = 2;
shreeshas95 0:f016e9e8d48b 141 break;
shreeshas95 0:f016e9e8d48b 142 case 2:
shreeshas95 0:f016e9e8d48b 143 state7e = 3;
shreeshas95 0:f016e9e8d48b 144 break;
shreeshas95 0:f016e9e8d48b 145 case 3:
shreeshas95 0:f016e9e8d48b 146 state7e = 4;
shreeshas95 0:f016e9e8d48b 147 break;
shreeshas95 0:f016e9e8d48b 148 case 4:
shreeshas95 0:f016e9e8d48b 149 state7e = 5;
shreeshas95 0:f016e9e8d48b 150 break;
shreeshas95 0:f016e9e8d48b 151 case 5:
shreeshas95 0:f016e9e8d48b 152 state7e = 6;
shreeshas95 0:f016e9e8d48b 153 break;
shreeshas95 0:f016e9e8d48b 154 case 6:
shreeshas95 0:f016e9e8d48b 155 state7e = 7;
shreeshas95 0:f016e9e8d48b 156 break;
shreeshas95 0:f016e9e8d48b 157 case 7:
shreeshas95 0:f016e9e8d48b 158 // error reset
shreeshas95 0:f016e9e8d48b 159 state7e = 0;
shreeshas95 0:f016e9e8d48b 160 chain_started = false;
shreeshas95 0:f016e9e8d48b 161 frame_started = false;
shreeshas95 0:f016e9e8d48b 162 byteCount = 0;
shreeshas95 0:f016e9e8d48b 163 outByte = 0;
shreeshas95 0:f016e9e8d48b 164 outState = 0;
shreeshas95 0:f016e9e8d48b 165 skipIteration = true;
shreeshas95 0:f016e9e8d48b 166 break;
shreeshas95 0:f016e9e8d48b 167 }
shreeshas95 0:f016e9e8d48b 168 }
shreeshas95 0:f016e9e8d48b 169 else{
shreeshas95 0:f016e9e8d48b 170 switch( state7e ){
shreeshas95 0:f016e9e8d48b 171 case 0:
shreeshas95 0:f016e9e8d48b 172 case 1:
shreeshas95 0:f016e9e8d48b 173 case 2:
shreeshas95 0:f016e9e8d48b 174 case 3:
shreeshas95 0:f016e9e8d48b 175 case 4:
shreeshas95 0:f016e9e8d48b 176 case 5:
shreeshas95 0:f016e9e8d48b 177 state7e = 1;
shreeshas95 0:f016e9e8d48b 178 break;
shreeshas95 0:f016e9e8d48b 179 case 6:
shreeshas95 0:f016e9e8d48b 180 state7e = 1;
shreeshas95 0:f016e9e8d48b 181 skipIteration = true;
shreeshas95 0:f016e9e8d48b 182 break;
shreeshas95 0:f016e9e8d48b 183 case 7:
shreeshas95 0:f016e9e8d48b 184 state7e = 0;
shreeshas95 0:f016e9e8d48b 185 // detected 7e
shreeshas95 0:f016e9e8d48b 186 if( !chain_started ){
shreeshas95 0:f016e9e8d48b 187 chain_started = true;
shreeshas95 0:f016e9e8d48b 188 frame_started = true;
shreeshas95 0:f016e9e8d48b 189 byteCount = 0;
shreeshas95 0:f016e9e8d48b 190 outByte = 0;
shreeshas95 0:f016e9e8d48b 191 outState = 0;
shreeshas95 0:f016e9e8d48b 192 skipIteration = true;
shreeshas95 0:f016e9e8d48b 193 }
shreeshas95 0:f016e9e8d48b 194 else{
shreeshas95 0:f016e9e8d48b 195 flush_called = true;
shreeshas95 0:f016e9e8d48b 196 flushData_appendTC(byteCount, outState);
shreeshas95 0:f016e9e8d48b 197 byteCount = 0;
shreeshas95 0:f016e9e8d48b 198 outState = 0;
shreeshas95 0:f016e9e8d48b 199 outByte = 0;
shreeshas95 0:f016e9e8d48b 200 skipIteration = true;
shreeshas95 0:f016e9e8d48b 201 }
shreeshas95 0:f016e9e8d48b 202 break;
shreeshas95 0:f016e9e8d48b 203 }
shreeshas95 0:f016e9e8d48b 204 }
shreeshas95 0:f016e9e8d48b 205 if( (!skipIteration) && (frame_started) ){
shreeshas95 0:f016e9e8d48b 206 // write bit to output
shreeshas95 0:f016e9e8d48b 207 switch( outState ){
shreeshas95 0:f016e9e8d48b 208 case 0:
shreeshas95 0:f016e9e8d48b 209 outState = 1;
shreeshas95 0:f016e9e8d48b 210 rx_tempString[outByte] = tempBit << 7;
shreeshas95 0:f016e9e8d48b 211 break;
shreeshas95 0:f016e9e8d48b 212 case 1:
shreeshas95 0:f016e9e8d48b 213 outState = 2;
shreeshas95 0:f016e9e8d48b 214 rx_tempString[outByte] += tempBit << 6;
shreeshas95 0:f016e9e8d48b 215 break;
shreeshas95 0:f016e9e8d48b 216 case 2:
shreeshas95 0:f016e9e8d48b 217 outState = 3;
shreeshas95 0:f016e9e8d48b 218 rx_tempString[outByte] += tempBit << 5;
shreeshas95 0:f016e9e8d48b 219 break;
shreeshas95 0:f016e9e8d48b 220 case 3:
shreeshas95 0:f016e9e8d48b 221 outState = 4;
shreeshas95 0:f016e9e8d48b 222 rx_tempString[outByte] += tempBit << 4;
shreeshas95 0:f016e9e8d48b 223 break;
shreeshas95 0:f016e9e8d48b 224 case 4:
shreeshas95 0:f016e9e8d48b 225 outState = 5;
shreeshas95 0:f016e9e8d48b 226 rx_tempString[outByte] += tempBit << 3;
shreeshas95 0:f016e9e8d48b 227 break;
shreeshas95 0:f016e9e8d48b 228 case 5:
shreeshas95 0:f016e9e8d48b 229 outState = 6;
shreeshas95 0:f016e9e8d48b 230 rx_tempString[outByte] += tempBit << 2;
shreeshas95 0:f016e9e8d48b 231 break;
shreeshas95 0:f016e9e8d48b 232 case 6:
shreeshas95 0:f016e9e8d48b 233 outState = 7;
shreeshas95 0:f016e9e8d48b 234 rx_tempString[outByte] += tempBit << 1;
shreeshas95 0:f016e9e8d48b 235 break;
shreeshas95 0:f016e9e8d48b 236 case 7:
shreeshas95 0:f016e9e8d48b 237 outState = 0;
shreeshas95 0:f016e9e8d48b 238 rx_tempString[outByte] += tempBit;
shreeshas95 0:f016e9e8d48b 239 ++outByte;
shreeshas95 0:f016e9e8d48b 240 // exceeded tc length discard
shreeshas95 0:f016e9e8d48b 241 if(outByte > 135){
shreeshas95 2:2caf2a9a13aa 242 ++gTOTAL_INCORRECT_SIZE_TC;
shreeshas95 0:f016e9e8d48b 243 outByte = 0;
shreeshas95 0:f016e9e8d48b 244 }
shreeshas95 0:f016e9e8d48b 245 ++byteCount;
shreeshas95 0:f016e9e8d48b 246 break;
shreeshas95 0:f016e9e8d48b 247 }
shreeshas95 0:f016e9e8d48b 248 }
shreeshas95 0:f016e9e8d48b 249 }
shreeshas95 0:f016e9e8d48b 250 }
shreeshas95 0:f016e9e8d48b 251 COM_RX_DATA_NODE *temp = data_node->next_node;
shreeshas95 0:f016e9e8d48b 252 delete data_node;
shreeshas95 0:f016e9e8d48b 253 data_node = temp;
shreeshas95 0:f016e9e8d48b 254 }
shreeshas95 0:f016e9e8d48b 255 if( (!flush_called) && (gTOTAL_INCORRECT_SIZE_TC == 0) ){
shreeshas95 0:f016e9e8d48b 256 ++gTOTAL_INCORRECT_SIZE_TC;
shreeshas95 0:f016e9e8d48b 257 }
shreeshas95 0:f016e9e8d48b 258 gRX_HEAD_DATA_NODE = new COM_RX_DATA_NODE;
shreeshas95 0:f016e9e8d48b 259 gRX_HEAD_DATA_NODE->next_node = NULL;
shreeshas95 0:f016e9e8d48b 260 gRX_CURRENT_DATA_NODE = gRX_HEAD_DATA_NODE;
shreeshas95 2:2caf2a9a13aa 261 gRX_COUNT = 0;
shreeshas95 0:f016e9e8d48b 262
aniruddhv 12:ffdb29353058 263 /*gPC.puts("Completed conversion of raw_data\r\n")*/;
shreeshas95 0:f016e9e8d48b 264 // PENDING: SORT THE LINKED LIST ACCORDING TO PSC VALUE
shreeshas95 0:f016e9e8d48b 265 }