Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FreescaleIAP SimpleDMA mbed-rtos mbed
Fork of CDMS_CODE by
COM_RCV_TC.h
00001 #define flushData_appendTC(bytes, outState) {\ 00002 uint16_t tc_type = 2;\ 00003 if( (bytes == TC_SHORT_SIZE) && (outState == 7) ){\ 00004 tc_type = SHORT_TC_CODE;\ 00005 }\ 00006 else if( (bytes == TC_LONG_SIZE) && (outState == 7) ){\ 00007 tc_type = LONG_TC_CODE;\ 00008 }\ 00009 else{\ 00010 /*gPC.puts("incorrect size\r\n");*/\ 00011 /*gPC.printf("%u, %u\r\n", bytes, outState);*/\ 00012 ++gTOTAL_INCORRECT_SIZE_TC;\ 00013 }\ 00014 if( tc_type == SHORT_TC_CODE ){\ 00015 uint16_t crc_checksum = crc16_gen(rx_tempString, TC_SHORT_SIZE-2);\ 00016 if( ( (crc_checksum & 0xFF) == rx_tempString[TC_SHORT_SIZE-1]) && ( ((crc_checksum >> 8) & 0xFF) == rx_tempString[TC_SHORT_SIZE-2] ) ){\ 00017 uint16_t temp16;\ 00018 Base_tc *temp_ptr = gHEAD_NODE_TCL;\ 00019 bool repeat_flag = false;\ 00020 uint8_t testPSC = rx_tempString[0];\ 00021 while(temp_ptr != NULL){\ 00022 if( GETpacket_seq_count(temp_ptr) == testPSC ){\ 00023 repeat_flag = true;\ 00024 break;\ 00025 }\ 00026 temp_ptr = temp_ptr->next_TC;\ 00027 }\ 00028 if( repeat_flag == false ){\ 00029 if( gTOTAL_VALID_TC == 0 ){\ 00030 gHEAD_NODE_TCL = new Short_tc;\ 00031 gHEAD_NODE_TCL->next_TC = NULL;\ 00032 gLAST_NODE_TCL = gHEAD_NODE_TCL;\ 00033 }\ 00034 else{\ 00035 gLAST_NODE_TCL->next_TC = new Short_tc;\ 00036 gLAST_NODE_TCL = gLAST_NODE_TCL->next_TC;\ 00037 gLAST_NODE_TCL->next_TC = NULL;\ 00038 }\ 00039 /*gPC.puts("printing tx string\r\n");*/\ 00040 for(int i = 0 ; i < TC_SHORT_SIZE ; ++i){\ 00041 gLAST_NODE_TCL->TC_string[i] = rx_tempString[i];\ 00042 }\ 00043 PUTshort_or_long(gLAST_NODE_TCL, tc_type);\ 00044 temp16 = 1;\ 00045 PUTcrc_pass(gLAST_NODE_TCL, temp16);\ 00046 temp16 = 0;\ 00047 PUTexec_status(gLAST_NODE_TCL, temp16);\ 00048 ++gTOTAL_VALID_TC;\ 00049 }\ 00050 else{\ 00051 /*gPC.puts("repeated psc short\r\n");*/\ 00052 ++gTOTAL_REPEATED_TC;\ 00053 }\ 00054 }\ 00055 else{\ 00056 /*gPC.puts("crc fail tc short\r\n");*/\ 00057 ++gTOTAL_CRC_FAIL_TC;\ 00058 }\ 00059 }\ 00060 else if( tc_type == LONG_TC_CODE ){\ 00061 uint16_t crc_checksum = crc16_gen(rx_tempString, TC_LONG_SIZE-2);\ 00062 if( ( (crc_checksum & 0xFF) == rx_tempString[TC_LONG_SIZE-1]) && ( ((crc_checksum >> 8) & 0xFF) == rx_tempString[TC_LONG_SIZE-2] ) ){\ 00063 uint16_t temp16;\ 00064 Base_tc *temp_ptr = gHEAD_NODE_TCL;\ 00065 bool repeat_flag = false;\ 00066 uint8_t testPSC = rx_tempString[0];\ 00067 while(temp_ptr != NULL){\ 00068 if( GETpacket_seq_count(temp_ptr) == testPSC ){\ 00069 repeat_flag = true;\ 00070 break;\ 00071 }\ 00072 temp_ptr = temp_ptr->next_TC;\ 00073 }\ 00074 if( repeat_flag == false ){\ 00075 if( gTOTAL_VALID_TC == 0 ){\ 00076 gHEAD_NODE_TCL = new Long_tc;\ 00077 gHEAD_NODE_TCL->next_TC = NULL;\ 00078 gLAST_NODE_TCL = gHEAD_NODE_TCL;\ 00079 }\ 00080 else{\ 00081 gLAST_NODE_TCL->next_TC = new Long_tc;\ 00082 gLAST_NODE_TCL = gLAST_NODE_TCL->next_TC;\ 00083 gLAST_NODE_TCL->next_TC = NULL;\ 00084 }\ 00085 /*gPC.puts("printing tx string\r\n");*/\ 00086 for(int i = 0 ; i < TC_LONG_SIZE ; ++i){\ 00087 gLAST_NODE_TCL->TC_string[i] = rx_tempString[i];\ 00088 }\ 00089 PUTshort_or_long(gLAST_NODE_TCL, tc_type);\ 00090 temp16 = 1;\ 00091 PUTcrc_pass(gLAST_NODE_TCL, temp16);\ 00092 temp16 = 0;\ 00093 PUTexec_status(gLAST_NODE_TCL, temp16);\ 00094 ++gTOTAL_VALID_TC;\ 00095 }\ 00096 else{\ 00097 /*gPC.puts("repeated psc long\r\n");*/\ 00098 ++gTOTAL_REPEATED_TC;\ 00099 }\ 00100 }\ 00101 else{\ 00102 /*gPC.puts("crc fail tc long\r\n");*/\ 00103 ++gTOTAL_CRC_FAIL_TC;\ 00104 }\ 00105 }\ 00106 } 00107 00108 unsigned char rx_tempString[TC_LONG_SIZE+1]; 00109 00110 void raw_data_to_tc(void){ 00111 /*gPC.puts("inside raw_data_to_tc\r\n")*/; 00112 bool frame_started = false; 00113 bool chain_started = false; 00114 bool flush_called = false; 00115 00116 uint32_t bytes_read = 0; 00117 uint8_t state7e = 0; 00118 uint8_t outState = 0; 00119 uint32_t outByte = 0; 00120 uint32_t byteCount = 0; 00121 00122 COM_RX_DATA_NODE *data_node = gRX_HEAD_DATA_NODE; 00123 // read byte by byte 00124 00125 //gPC.puts("received data : \n"); 00126 00127 while( data_node != NULL ){ 00128 for(int iBuf = 0 ; iBuf < RX_BUFFER_LENGTH ; ++iBuf ){ 00129 uint8_t test_this = data_node->values[iBuf]; 00130 //gPC.printf("0x%02X ",test_this); 00131 ++bytes_read; 00132 00133 // read bit by bit 00134 for(int i = 7 ; i >= 0 ; --i){ 00135 unsigned char tempBit = (test_this >> i) & 1; 00136 bool skipIteration = false; 00137 00138 if( tempBit == 1 ){ 00139 switch( state7e ){ 00140 case 0: 00141 state7e = 0; 00142 break; 00143 case 1: 00144 state7e = 2; 00145 break; 00146 case 2: 00147 state7e = 3; 00148 break; 00149 case 3: 00150 state7e = 4; 00151 break; 00152 case 4: 00153 state7e = 5; 00154 break; 00155 case 5: 00156 state7e = 6; 00157 break; 00158 case 6: 00159 state7e = 7; 00160 break; 00161 case 7: 00162 // error reset 00163 state7e = 0; 00164 chain_started = false; 00165 frame_started = false; 00166 byteCount = 0; 00167 outByte = 0; 00168 outState = 0; 00169 skipIteration = true; 00170 break; 00171 } 00172 } 00173 else{ 00174 switch( state7e ){ 00175 case 0: 00176 case 1: 00177 case 2: 00178 case 3: 00179 case 4: 00180 case 5: 00181 state7e = 1; 00182 break; 00183 case 6: 00184 state7e = 1; 00185 skipIteration = true; 00186 break; 00187 case 7: 00188 state7e = 0; 00189 // detected 7e 00190 if( !chain_started ){ 00191 chain_started = true; 00192 frame_started = true; 00193 byteCount = 0; 00194 outByte = 0; 00195 outState = 0; 00196 skipIteration = true; 00197 } 00198 else{ 00199 flush_called = true; 00200 flushData_appendTC(byteCount, outState); 00201 byteCount = 0; 00202 outState = 0; 00203 outByte = 0; 00204 skipIteration = true; 00205 } 00206 break; 00207 } 00208 } 00209 if( (!skipIteration) && (frame_started) ){ 00210 // write bit to output 00211 switch( outState ){ 00212 case 0: 00213 outState = 1; 00214 rx_tempString[outByte] = tempBit << 7; 00215 break; 00216 case 1: 00217 outState = 2; 00218 rx_tempString[outByte] += tempBit << 6; 00219 break; 00220 case 2: 00221 outState = 3; 00222 rx_tempString[outByte] += tempBit << 5; 00223 break; 00224 case 3: 00225 outState = 4; 00226 rx_tempString[outByte] += tempBit << 4; 00227 break; 00228 case 4: 00229 outState = 5; 00230 rx_tempString[outByte] += tempBit << 3; 00231 break; 00232 case 5: 00233 outState = 6; 00234 rx_tempString[outByte] += tempBit << 2; 00235 break; 00236 case 6: 00237 outState = 7; 00238 rx_tempString[outByte] += tempBit << 1; 00239 break; 00240 case 7: 00241 outState = 0; 00242 rx_tempString[outByte] += tempBit; 00243 ++outByte; 00244 // exceeded tc length discard 00245 if(outByte > 135){ 00246 ++gTOTAL_INCORRECT_SIZE_TC; 00247 outByte = 0; 00248 } 00249 ++byteCount; 00250 break; 00251 } 00252 } 00253 } 00254 } 00255 COM_RX_DATA_NODE *temp = data_node->next_node; 00256 delete data_node; 00257 data_node = temp; 00258 } 00259 if( (!flush_called) && (gTOTAL_INCORRECT_SIZE_TC == 0) ){ 00260 ++gTOTAL_INCORRECT_SIZE_TC; 00261 } 00262 gRX_HEAD_DATA_NODE = new COM_RX_DATA_NODE; 00263 gRX_HEAD_DATA_NODE->next_node = NULL; 00264 gRX_CURRENT_DATA_NODE = gRX_HEAD_DATA_NODE; 00265 gRX_COUNT = 0; 00266 00267 /*gPC.puts("Completed conversion of raw_data\r\n")*/; 00268 }
Generated on Tue Jul 26 2022 00:15:16 by
 1.7.2
 1.7.2 
    