![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Repo for COM_MNG_TMTC_SIMPLE for integration with adf
Fork of COM_MNG_TMTC_SIMPLE by
Diff: ThreadsAndFunctions.h
- Revision:
- 4:104dd82c99b8
- Parent:
- 3:6c81fc8834e2
- Child:
- 5:ab276a17ca07
diff -r 6c81fc8834e2 -r 104dd82c99b8 ThreadsAndFunctions.h --- a/ThreadsAndFunctions.h Wed Dec 23 05:37:55 2015 +0000 +++ b/ThreadsAndFunctions.h Tue Dec 29 06:50:19 2015 +0000 @@ -58,6 +58,11 @@ } void COM_MNG_TMTC_FUN(void const *args){ + if( !(gFLAGS & COM_SESSION_FLAG) ){ + gPC.puts("com session is flase\r\n"); + gLEDR = 1; + gLEDG = 1; + } while(true){ Thread::signal_wait( COM_MNG_TMTC_SIGNAL_UART_INT ); if( gFLAGS & UART_INT_FLAG ){ @@ -69,82 +74,128 @@ gFLAGS = gFLAGS | COM_RX_FLAG; PUT_RAW_BYTE; // PENDING : MEASURE RSSI + if( gFLAGS & COM_SESSION_FLAG ){ + gLEDR = 0; + gLEDG = 0; + } } else if( gFLAGS & COM_RX_FLAG ){ + gLEDR = 0; + gLEDG = 1; PUT_RAW_BYTE; } else{ + gLEDR = 1; + gLEDG = 0; gFLAGS = gFLAGS | COM_RX_FLAG; PUT_RAW_BYTE; } } - else if( (gFLAGS & NEW_TC_RECEIVED) && (gFLAGS & COM_MNG_TMTC_RUNNING_FLAG) ){ + else if( gFLAGS & NEW_TC_RECEIVED ){ + gPC.puts("NEW TC RECEIVED\r\n"); gFLAGS = gFLAGS & (~NEW_TC_RECEIVED); gFLAGS = gFLAGS & (~COM_RX_FLAG); + gFLAGS = gFLAGS | COM_MNG_TMTC_RUNNING_FLAG; // DISABLE THE RX1M INTERRUPT RX1M.attach(NULL); + // VERIFY CRC, REPEATED PSC AND UPDATE TOTAL_VALID_TC, INCORRECT SIZE TC, CRC FAIL TC while(gRX_COUNT < (RX_BUFFER_LENGTH)){ gRX_CURRENT_DATA_NODE->values[gRX_COUNT] = 0x00; ++gRX_COUNT; } gRX_COUNT = 0; + raw_data_to_tc(); - // VERIFY CRC, REPEATED PSC AND UPDATE TOTAL_VALID_TC, INCORRECT SIZE TC, CRC FAIL TC - raw_data_to_tc(); if( gTOTAL_VALID_TC > 0 ){ - // CHECK WEATHER TC LIST HAS MISSING TC OR WEATHER LAST FRAME BIT IS HIGH IN THE LAST PSC-TC - uint8_t tempContinue = 0xFF; - continueToExecute(tempContinue); - if(tempContinue == 0x00){ - // CHECK WEATHER GS VERIFICATION CODE MATCHES - uint8_t tempGSver = 0x00; - GScodeVerification(tempGSver); - if( tempGSver ){ - gFLAGS = gFLAGS | COM_SESSION_VALIDITY; - // PENDING : COM_POWER_ON_TX - EXECUTE_OBOSC_ONLY; - EXECUTE_TC; + gPC.printf("valid TC rx: %u\r\n", gTOTAL_VALID_TC); + if( gTOTAL_VALID_TC < COM_MAX_TC_LIMIT ){ + // CHECK WEATHER TC LIST HAS MISSING TC OR WEATHER LAST FRAME BIT IS HIGH IN THE LAST PSC-TC + gPC.puts("checking for tc list complete\r\n"); + uint8_t tempContinue = 0xFF; + continueToExecute(tempContinue); + if(tempContinue == 0x00){ + gPC.puts("tc list is complete\r\n"); + // CHECK WEATHER GS VERIFICATION CODE MATCHES + uint8_t tempGSver = 0x00; + GScodeVerification(tempGSver); + if( tempGSver ){ + gPC.puts("GC code match !!\r\n"); + gFLAGS = gFLAGS | COM_SESSION_VALIDITY; + COM_POWER_ON_TX; + // PENDING: PA HOT HANDLED IN EXECUTE_XXX FUNCTIONS + uint8_t tempPAHot = 0x00; + isPAhot(tempPAHot); + if( tempPAHot == 0xFF ){ + gPC.puts("EXECUTING TELECOMMANDS\r\n"); + EXECUTE_OBOSC_ONLY; + EXECUTE_TC; + gPC.puts("COMPLETED EXECUTION\r\n"); + } + else{ + gFLAGS = gFLAGS | COM_PA_HOT_FLAG; + COM_POWER_OFF_TX; + RX1M.attach(&rx_read, Serial::RxIrq); + gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG); + } + } + else{ + gPC.puts("GS code mismatch !!\r\n"); + reset_all; + gFLAGS = gFLAGS & (~COM_SESSION_VALIDITY); + // PENDING : ENABLE THREADS + gSESSION_TIMEOUT.detach(); + gFLAGS = gFLAGS & (~COM_SESSION_FLAG); + // WARNING: clear COM_MNG_TMTC ? + } } else{ - gFLAGS = gFLAGS & (~COM_SESSION_VALIDITY); - // PENDING : ENABLE THREADS - gSESSION_TIMEOUT.detach(); - gFLAGS = gFLAGS & (~COM_SESSION_FLAG); + COM_POWER_ON_TX; + // PENDING : POWER OFF TX + RX1M.attach(&rx_read, Serial::RxIrq); + gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG); } } else{ - // PENDING : COM_POWER_ON_TX - // PENDING : POWER OFF TX + COM_POWER_ON_TX; + // POWER OFF TX + // WARNING: reset_all ? clear com_session ? RX1M.attach(&rx_read, Serial::RxIrq); + gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG); } } - else if( !(gFLAGS & COM_TX_FLAG) ){ + else{ + gPC.puts("No valid TC recweived\r\n"); RX1M.attach(&rx_read, Serial::RxIrq); - // PENDING : ENABLE THREADS - gSESSION_TIMEOUT.detach(); - gFLAGS = gFLAGS & (~COM_SESSION_FLAG); + gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG); + + if( !(gFLAGS & COM_TX_FLAG) ){ + reset_all; + // PENDING : ENABLE THREADS + gSESSION_TIMEOUT.detach(); + gFLAGS = gFLAGS & (~COM_SESSION_FLAG); + } + // else wait } } else if( gFLAGS & COM_PA_HOT_FLAG ){ uint8_t tempPA = 0xFF; isPAhot(tempPA); if( tempPA == 0x00 ){ - gCOM_PA_COOLING_TIMER.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT); + gCOM_PA_COOLING_TIMEOUT.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT); } else{ gFLAGS = gFLAGS & (~COM_PA_HOT_FLAG); - gCOM_PA_COOLING_TIMER.detach(); - // PENDING : COM POWER ON TX + gCOM_PA_COOLING_TIMEOUT.detach(); + COM_POWER_ON_TX; EXECUTE_OBOSC_ONLY; EXECUTE_TC; } } else{ // SOME INVALID SIGNAL RECEIVED - - // PENDING : COM_POWER_OFF_TX + COM_POWER_OFF_TX; reset_all; // PENDING : ENABLE THREADS gSESSION_TIMEOUT.detach(); @@ -153,46 +204,41 @@ } } -void SCIENCE_FUN(void const *args){ -// SPIpayload.format(8,0); -// SPIpayload.frequency(1000000); - for ( int i = 0 ; i < PAYLOAD_BUFFER_LENGTH ; i++ ){ - gPAYLOAD_BUFFER[i] = 1; - } - - // initialise the buffer for dma - // SPIpayload.bulkRead_init(VAR_SPACE::payload_dma_buffer, PAYLOAD_DMA_SIZE, &payload_interrupt_fun); - // start dma read - // SPIpayload.bulkRead_start(); - - // attach DMA interrupt - while(true){ - gSCIENCE_THREAD->signal_wait(0x01); - -//*********************************************************THE TEST - - //read rtc time later - uint64_t RTC_time = 0; - Science_Data_Compression::complete_compression( gPAYLOAD_BUFFER , RTC_time); -// SPI_mutex.lock(); -// disk_write(SDcard_lastWritten , 5); -// SPI_mutex.unlock(); - -//**********************************************THE TEST - - - -// counter_for_payload++; -// if(counter_for_payload == 10){ -// payload_ticker.detach(); -// ledg = 0; -// PC.puts("its over\r\n"); -// } - - - - -// SPIpayload.bulkRead_start(); - - } -} \ No newline at end of file +//void SCIENCE_FUN(void const *args){ +//// SPIpayload.format(8,0); +//// SPIpayload.frequency(1000000); +// for ( int i = 0 ; i < PAYLOAD_BUFFER_LENGTH ; i++ ){ +// gPAYLOAD_BUFFER[i] = 1; +// } +// +// // initialise the buffer for dma +// // SPIpayload.bulkRead_init(VAR_SPACE::payload_dma_buffer, PAYLOAD_DMA_SIZE, &payload_interrupt_fun); +// // start dma read +// // SPIpayload.bulkRead_start(); +// +// // attach DMA interrupt +// while(true){ +// gSCIENCE_THREAD->signal_wait(0x01); +// +////*********************************************************THE TEST +// +// //read rtc time later +// uint64_t RTC_time = 0; +// Science_Data_Compression::complete_compression( gPAYLOAD_BUFFER , RTC_time); +//// SPI_mutex.lock(); +//// disk_write(SDcard_lastWritten , 5); +//// SPI_mutex.unlock(); +// +////**********************************************THE TEST +// +//// counter_for_payload++; +//// if(counter_for_payload == 10){ +//// payload_ticker.detach(); +//// ledg = 0; +//// PC.puts("its over\r\n"); +//// } +// +//// SPIpayload.bulkRead_start(); +// +// } +//} \ No newline at end of file