for frequency correction testing
Dependencies: FreescaleIAP SimpleDMA mbed-rtos mbed
Fork of CDMS_CODE by
COM_POWER_ON_TX.h
00001 #define STANDBY_PRCS(tm_ptr){\ 00002 Base_tc *stdby_tc = new Long_tc;\ 00003 stdby_tc->next_TC = NULL;\ 00004 PUTshort_or_long(stdby_tc,LONG_TC_CODE);\ 00005 PUTcrc_pass(stdby_tc,0x1);\ 00006 PUTexec_status(stdby_tc,0);\ 00007 stdby_tc->TC_string[0] = 0x01;\ 00008 stdby_tc->TC_string[1] = 0x41;\ 00009 stdby_tc->TC_string[2] = 0x81;\ 00010 stdby_tc->TC_string[3] = 0x40;\ 00011 stdby_tc->TC_string[4] = 0;\ 00012 stdby_tc->TC_string[5] = 0;\ 00013 stdby_tc->TC_string[6] = 0;\ 00014 stdby_tc->TC_string[7] = 0;\ 00015 stdby_tc->TC_string[8] = 0;\ 00016 uint16_t crc16 = crc16_gen(stdby_tc->TC_string, 9);\ 00017 stdby_tc->TC_string[9] = (crc16 & 0xFF00)>>8;\ 00018 stdby_tc->TC_string[10] = (crc16 & 0x00FF);\ 00019 for(int i = 11; i < 135; i++){\ 00020 stdby_tc->TC_string[i] = 0;\ 00021 }\ 00022 tm_ptr = FCTN_CDMS_RLY_TMTC(stdby_tc);\ 00023 delete stdby_tc;\ 00024 } 00025 00026 #define SET_BCN_STANDBY(tm_ptr){\ 00027 Base_tc *beacon_tc = new Long_tc;\ 00028 beacon_tc->next_TC = NULL;\ 00029 PUTshort_or_long(beacon_tc,LONG_TC_CODE);\ 00030 PUTcrc_pass(beacon_tc,0x1);\ 00031 PUTexec_status(beacon_tc,0);\ 00032 beacon_tc->TC_string[0] = 0x01;\ 00033 beacon_tc->TC_string[1] = BCN_APID_SOURCE;\ 00034 beacon_tc->TC_string[2] = BCN_SERVICE;\ 00035 beacon_tc->TC_string[3] = 0xE2;\ 00036 beacon_tc->TC_string[4] = 0x01;\ 00037 beacon_tc->TC_string[5] = 0;\ 00038 beacon_tc->TC_string[6] = 0;\ 00039 beacon_tc->TC_string[7] = 0;\ 00040 beacon_tc->TC_string[8] = 0;\ 00041 uint16_t crc16 = crc16_gen(beacon_tc->TC_string, 9);\ 00042 beacon_tc->TC_string[9] = (crc16 & 0xFF00)>>8;\ 00043 beacon_tc->TC_string[10] = (crc16 & 0x00FF);\ 00044 for(int i = 11; i < 135; i++){\ 00045 beacon_tc->TC_string[i] = 0;\ 00046 }\ 00047 tm_ptr = FCTN_CDMS_RLY_TMTC(beacon_tc);\ 00048 delete beacon_tc;\ 00049 } 00050 00051 #define P_CDMS_HK_MAIN {\ 00052 Base_tc *hk_main_ptr = new Short_tc;\ 00053 hk_main_ptr->next_TC = NULL;\ 00054 PUTshort_or_long(hk_main_ptr,SHORT_TC_CODE);\ 00055 PUTcrc_pass(hk_main_ptr,0x1);\ 00056 PUTexec_status(hk_main_ptr,0);\ 00057 hk_main_ptr->TC_string[0] = 0x01;\ 00058 hk_main_ptr->TC_string[1] = 0x81;\ 00059 hk_main_ptr->TC_string[2] = 0x81;\ 00060 hk_main_ptr->TC_string[3] = 0x04;\ 00061 hk_main_ptr->TC_string[4] = 0;\ 00062 hk_main_ptr->TC_string[5] = 0;\ 00063 hk_main_ptr->TC_string[6] = 0;\ 00064 hk_main_ptr->TC_string[7] = 0;\ 00065 hk_main_ptr->TC_string[8] = 0;\ 00066 uint16_t crc16 = crc16_gen(hk_main_ptr->TC_string, 9);\ 00067 hk_main_ptr->TC_string[9] = (crc16 & 0xFF00)>>8;\ 00068 hk_main_ptr->TC_string[10] = (crc16 & 0x00FF);\ 00069 Base_tm *tm_ptr = NULL;\ 00070 tm_ptr = FCTN_CDMS_RLY_TMTC(hk_main_ptr);\ 00071 delete hk_main_ptr;\ 00072 /*DELETE THE TM AFTER USE*/\ 00073 Base_tm *del_tm = tm_ptr;\ 00074 int overCount = 0;\ 00075 while( del_tm != NULL ){\ 00076 if( (overCount < TM_OVERFLOW_CONSTANT) ){\ 00077 Base_tm *temp = del_tm->next_TM;\ 00078 delete del_tm;\ 00079 del_tm = temp;\ 00080 ++overCount;\ 00081 }\ 00082 else{\ 00083 RESET_CDMS;\ 00084 break;\ 00085 }\ 00086 }\ 00087 } 00088 00089 #define P_BCN_TX_MAIN(tm_ptr) {\ 00090 Base_tc *bcn_tx_main_ptr = new Long_tc;\ 00091 bcn_tx_main_ptr->next_TC = NULL;\ 00092 PUTshort_or_long(bcn_tx_main_ptr,LONG_TC_CODE);\ 00093 PUTcrc_pass(bcn_tx_main_ptr,0x1);\ 00094 PUTexec_status(bcn_tx_main_ptr,0);\ 00095 bcn_tx_main_ptr->TC_string[0] = 0x01;\ 00096 bcn_tx_main_ptr->TC_string[1] = 0x41;\ 00097 bcn_tx_main_ptr->TC_string[2] = 0x81;\ 00098 bcn_tx_main_ptr->TC_string[3] = 0x07;\ 00099 bcn_tx_main_ptr->TC_string[4] = 0;\ 00100 bcn_tx_main_ptr->TC_string[5] = 0;\ 00101 bcn_tx_main_ptr->TC_string[6] = 0;\ 00102 bcn_tx_main_ptr->TC_string[7] = 0;\ 00103 bcn_tx_main_ptr->TC_string[8] = 0;\ 00104 uint16_t crc16 = crc16_gen(bcn_tx_main_ptr->TC_string, 9);\ 00105 bcn_tx_main_ptr->TC_string[9] = (crc16 & 0xFF00)>>8;\ 00106 bcn_tx_main_ptr->TC_string[10] = (crc16 & 0x00FF);\ 00107 for(int i = 11; i < 135; i++){\ 00108 bcn_tx_main_ptr->TC_string[i] = 0;\ 00109 }\ 00110 tm_ptr = FCTN_CDMS_RLY_TMTC(bcn_tx_main_ptr);\ 00111 delete bcn_tx_main_ptr;\ 00112 } 00113 00114 void COM_POWER_ON_TX() { 00115 //gPC.puts("Inside COM_POWER_ON_TX\r\n"); 00116 if( !(gFLAGS & COM_TX_FLAG) ){ 00117 gFLAGS = gFLAGS | COM_TX_FLAG; 00118 //gPC.puts("Inside COM_TX_FLAG\r\n"); 00119 gFLAGS = gFLAGS | BAE_SW_EN_FLAG ; 00120 if( gFLAGS & BAE_SW_EN_FLAG ){ 00121 /*WARNING: INFINITE WHILE LOOP POSSIBLE: if standby ack received and bcn tx main status = 0*/ 00122 bool retryFlag = true; 00123 while( retryFlag == true ){ 00124 Base_tm *tm_ptr = NULL; 00125 gPC.puts("setting Bcn off\r\n"); 00126 wait(1); 00127 SET_BCN_STANDBY(tm_ptr); 00128 //gPC.puts("set Bcn off\r\n"); 00129 uint8_t bcn_main_status = (tm_ptr->TM_string[2] & 0xEF); 00130 gPC.printf("bcn_main_status = 0x%02X\r\n",bcn_main_status); 00131 if(( bcn_main_status == 0xC0 )||( bcn_main_status ==0xA0 )){ 00132 /*ACK RECCEIVED*/ 00133 if( bcn_main_status == 0xA0 ){ 00134 gPC.puts("A0\r\n"); 00135 retryFlag = false; 00136 RF_SW_CNTRL_TX = 1; 00137 Thread::wait(25); 00138 RF_SW_CNTRL_TX = 0; 00139 gFLAGS = gFLAGS & (~RF_SW_STATUS_FLAG);/*RF_SW_STATUS_FLAG set to RF_COM_TX*/ 00140 } 00141 else{ 00142 gPC.puts("waiting for bcn off\r\n"); 00143 Thread::wait(5000); 00144 } 00145 } 00146 else{ 00147 gPC.puts("not A0\r\n"); 00148 SW_RST_BAE(); 00149 Base_tm *tm_ptr2 = NULL; 00150 gPC.puts("settin bcn off\r\n"); 00151 SET_BCN_STANDBY(tm_ptr2); 00152 //gPC.puts("bcn off\r\n"); 00153 uint8_t standbyAck2 = 0; 00154 uint8_t bcn_main_status2 = (tm_ptr2->TM_string[2] & 0xEF); 00155 if( ( bcn_main_status2 == 0xC0 )||( bcn_main_status2 == 0xA0 ) ){ 00156 if( bcn_main_status2 == 0xA0 ){ 00157 gPC.puts("ack = A0\r\n"); 00158 retryFlag = false; 00159 RF_SW_CNTRL_TX = 1; 00160 Thread::wait(25); 00161 RF_SW_CNTRL_TX = 0; 00162 gFLAGS = gFLAGS & (~RF_SW_STATUS_FLAG); 00163 } 00164 else{ 00165 gPC.puts("ack = C0\r\n"); 00166 Thread::wait(5000); 00167 } 00168 } 00169 else{ 00170 gPC.puts("sw off BAE\r\n"); 00171 retryFlag = false; 00172 SW_OFF_BAE(); 00173 gPC.puts("swd off BAE\r\n"); 00174 gFLAGS = gFLAGS | COM_AUTO_POWER_OFF_BAE_FLAG; 00175 RF_SW_CNTRL_TX = 1; 00176 Thread::wait(25); 00177 RF_SW_CNTRL_TX = 0; 00178 gFLAGS = gFLAGS & (~RF_SW_STATUS_FLAG);/*RF_SW_STATUS_FLAG set to RF_COM_TX*/ 00179 } 00180 /*DELETE THE TM AFTER USE*/ 00181 Base_tm *del_tm = tm_ptr2; 00182 int overCount = 0; 00183 while( del_tm != NULL ){ 00184 if( (overCount < TM_OVERFLOW_CONSTANT) ){ 00185 Base_tm *temp = del_tm->next_TM; 00186 delete del_tm; 00187 del_tm = temp; 00188 ++overCount; 00189 } 00190 else{ 00191 RESET_CDMS; 00192 break; 00193 } 00194 } 00195 } 00196 /*DELETE THE TM AFTER USE*/ 00197 Base_tm *del_tm = tm_ptr; 00198 int overCount = 0; 00199 while( del_tm != NULL ){ 00200 if( (overCount < TM_OVERFLOW_CONSTANT) ){ 00201 Base_tm *temp = del_tm->next_TM; 00202 delete del_tm; 00203 del_tm = temp; 00204 ++overCount; 00205 } 00206 else{ 00207 RESET_CDMS; 00208 break; 00209 } 00210 } 00211 } 00212 } 00213 else{ 00214 gPC.puts("RF_SW_CNTRL_TX\r\n"); 00215 RF_SW_CNTRL_TX = 1; 00216 Thread::wait(25); 00217 RF_SW_CNTRL_TX = 0; 00218 gFLAGS = gFLAGS & (~RF_SW_STATUS_FLAG);/*RF_SW_STATUS_FLAG set to RF_COM_TX*/ 00219 } 00220 } 00221 gPC.puts("swd off BAE\r\n"); 00222 COM_TX_CNTRL = 1; 00223 uint8_t adfConfigPass = 0xFF; 00224 for( int i = 0 ; i < COM_TX_CONFIG_LIMIT ; ++i ){ 00225 /*PENDING: CONFIGURE ADF and set adfConfigPass*/ 00226 if( adfConfigPass == 0xFF ){ 00227 break; 00228 } 00229 } 00230 if( adfConfigPass == 0xFF ){ 00231 /*adf successfully configured*/ 00232 gFLAGS = gFLAGS | COM_TX_STATUS_FLAG; 00233 /*CALL SIGN*/ 00234 Base_tm *power_on_tm = NULL; 00235 Base_tm *power_on_tm_head = NULL; 00236 get_call_sign( power_on_tm_head ); 00237 power_on_tm = power_on_tm_head; 00238 /*ACK L1*/ 00239 get_ack_l1(power_on_tm->next_TM); 00240 int overFlowCountADF = 0; 00241 while( power_on_tm->next_TM != NULL ){ 00242 if( overFlowCountADF < TM_OVERFLOW_CONSTANT ){ 00243 power_on_tm = power_on_tm->next_TM; 00244 ++overFlowCountADF; 00245 } 00246 else{ 00247 RESET_CDMS; 00248 break; 00249 } 00250 } 00251 get_tc_list(power_on_tm->next_TM, 0x00); 00252 /*Call Sign, ACK_L1, TC_LIST*/ 00253 /*snd_tm.head_pointer(power_on_tm_head);*/ 00254 /*transmit_adf;*/ 00255 uint8_t transmissionPass = 0xFF; 00256 /*PENDING: get acknowledgement of transmission*/ 00257 /*deleting the telemetry*/ 00258 power_on_tm = power_on_tm_head; 00259 overFlowCountADF = 0; 00260 while( power_on_tm != NULL ){ 00261 if( overFlowCountADF < TM_OVERFLOW_CONSTANT ){ 00262 Base_tm *temp = power_on_tm->next_TM; 00263 delete power_on_tm; 00264 power_on_tm = temp; 00265 ++overFlowCountADF; 00266 } 00267 else{ 00268 RESET_CDMS; 00269 break; 00270 } 00271 } 00272 if( transmissionPass == 0 ){ 00273 /*NOT Transmitted succesfully*/ 00274 COM_POWER_OFF_TX; 00275 P_CDMS_HK_MAIN; 00276 Base_tm *ptr_tm = NULL; 00277 STANDBY_PRCS(ptr_tm); 00278 uint8_t standbyACK = 0x00; 00279 uint8_t bcn_main_status = (ptr_tm->TM_string[2] & 0xEF); 00280 if(( bcn_main_status == 0xC0 )||( bcn_main_status ==0xA0 )){ 00281 standbyACK = 1; 00282 } 00283 if(standbyACK == 1){ 00284 uint8_t ackReceived = 0x00; 00285 Base_tm *tm_ptr = NULL; 00286 P_BCN_TX_MAIN(tm_ptr); 00287 uint8_t ackcode = tm_ptr->TM_string[2] & 0xEF; 00288 if( (ackcode == 0xA0) || (ackcode == 0xC0)) 00289 ackReceived = 0xFF; 00290 /*DELETE THE TM AFTER USE*/ 00291 Base_tm *del_tm = tm_ptr; 00292 int overCount = 0; 00293 while( del_tm != NULL ){ 00294 if( (overCount < TM_OVERFLOW_CONSTANT) ){ 00295 Base_tm *temp = del_tm->next_TM; 00296 delete del_tm; 00297 del_tm = temp; 00298 ++overCount; 00299 } 00300 else{ 00301 RESET_CDMS; 00302 break; 00303 } 00304 } 00305 if( ackReceived == 0xFF ){ 00306 Thread::wait(5000); 00307 } 00308 } 00309 /*DELETE THE TM AFTER USE*/ 00310 Base_tm *del_tm = ptr_tm; 00311 int overCount = 0; 00312 while( del_tm != NULL ){ 00313 if( (overCount < TM_OVERFLOW_CONSTANT) ){ 00314 Base_tm *temp = del_tm->next_TM; 00315 delete del_tm; 00316 del_tm = temp; 00317 ++overCount; 00318 } 00319 else{ 00320 RESET_CDMS; 00321 break; 00322 } 00323 } 00324 RESET_CDMS_TC; 00325 } 00326 } 00327 else{ 00328 /*ADF not configured*/ 00329 gFLAGS = gFLAGS & (~COM_TX_STATUS_FLAG); 00330 COM_POWER_OFF_TX; 00331 P_CDMS_HK_MAIN; 00332 Base_tm *ptr_tm = NULL; 00333 STANDBY_PRCS(ptr_tm); 00334 uint8_t standbyACK = 0x00; 00335 uint8_t bcn_main_status = (ptr_tm->TM_string[2] & 0xEF); 00336 if(( bcn_main_status == 0xC0 )||( bcn_main_status ==0xA0 )){ 00337 standbyACK = 1; 00338 } 00339 if(standbyACK == 1){ 00340 uint8_t ackReceived = 0x00; 00341 Base_tm *tm_ptr = NULL; 00342 P_BCN_TX_MAIN(tm_ptr); 00343 uint8_t ackcode = tm_ptr->TM_string[2] & 0xEF; 00344 if( (ackcode == 0xA0) || (ackcode == 0xC0)) 00345 ackReceived = 0xFF; 00346 /*DELETE THE TM AFTER USE*/ 00347 Base_tm *del_tm = tm_ptr; 00348 int overCount = 0; 00349 while( del_tm != NULL ){ 00350 if( (overCount < TM_OVERFLOW_CONSTANT) ){ 00351 Base_tm *temp = del_tm->next_TM; 00352 delete del_tm; 00353 del_tm = temp; 00354 ++overCount; 00355 } 00356 else{ 00357 RESET_CDMS; 00358 break; 00359 } 00360 } 00361 if( ackReceived == 0xFF ){ 00362 Thread::wait(5000); 00363 } 00364 } 00365 /*DELETE THE TM AFTER USE*/ 00366 Base_tm *del_tm = ptr_tm; 00367 int overCount = 0; 00368 while( del_tm != NULL ){ 00369 if( (overCount < TM_OVERFLOW_CONSTANT) ){ 00370 Base_tm *temp = del_tm->next_TM; 00371 delete del_tm; 00372 del_tm = temp; 00373 ++overCount; 00374 } 00375 else{ 00376 RESET_CDMS; 00377 break; 00378 } 00379 } 00380 RESET_CDMS_TC; 00381 } 00382 gPC.puts("COMPLETED COM_POWER_ON_TX\r\n"); 00383 }
Generated on Sat Jul 16 2022 01:27:53 by 1.7.2