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: mbed
Revision 2:155d07b145c6, committed 2022-08-01
- Comitter:
- paologiorgio
- Date:
- Mon Aug 01 17:31:30 2022 +0000
- Parent:
- 1:00cee5df0f76
- Commit message:
- Dora, 01/08/2022. Versione finale
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
tlc_tlm_list.h | Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Jul 15 14:00:59 2022 +0000 +++ b/main.cpp Mon Aug 01 17:31:30 2022 +0000 @@ -1,7 +1,3 @@ - -// in data 13/07/2022 abbiamo testato spacecraft-mima avendo come spacecraft -// la seriale che parla su STM, mentre mima l'usb del pc - // Librerie #include "mbed.h" #include <math.h> @@ -10,71 +6,101 @@ #include <stdbool.h> // Macros -#define PACKETDIM 15 // temperature -#define word 1 -#define packet 2 // 2 bytes -#define hsk_buf 113 -#define hsk_rx 114 // 114 bytes - 57 telemetry words(housekeeping) -#define hsk_sd_buf 11211 -#define hsk_sd 11212 // 11212 bytes - 5606 interferogram data words +#define config 2 // 0: spacecraft, 1: mima, 2: no diagnostic +#define PACKETDIM 15 // temperature +#define word 1 +#define packet 2 // 2 bytes #define channel_size 10 // temeprature channel from sen30202 +#define CMD05_1 40 +#define CMD05_2 41 +#define TLMODE_HSK 0 +#define TLMODE_HSKSD 127 +#define CMD00 0 +#define CMD02 16 +#define TEMP_QUERY 32 +#define CMD15_R 121 +#define CMD15 120 +#define ALL_RELAY_OFF 42 +#define ALL_RELAY_ON 85 +#define ENABLE_12V 1 +#define DISABLE_12V 0 +#define ENABLE_5V 3 +#define DISABLE_5V 2 +#define ENABLE_15V 7 +#define DISABLE_15V 6 +#define ENABLE_24V 15 +#define DISABLE_24V 8 +#define CMD31 241 +#define RESET_GLOBAL_VARS 127 -// Serial e periferiche -Serial spacecraft(USBTX, USBRX); // switchare questo e le print con mima +// Definizione periferiche +Serial spacecraft(PC_1, PC_0); +//Serial spacecraft(USBTX, USBRX); // se pc connesso direttamente all'stm32 Serial mima(PC_4, PC_5); +/* se si desidera utilizzare il pc come mima +Serial mima(PC_1, PC_0); +Serial spacecraft(PC_4, PC_5); +*/ Serial max31865(PA_0, PA_1); // L16 Actuonix: -PwmOut actuonix (PB_3); +AnalogOut actuonix(PA_4); +PwmOut actuonix_dig(PB_3); float offset; -// Relay: configurazione pull-up -DigitalOut Relay5V (PA_7); -DigitalOut Relay12V (PB_4); -DigitalOut Relay24V (PB_5); -DigitalOut Relay15_15_5V (PB_10); +float offset_dig; +// Relay +DigitalOut Relay5V(PA_7); +DigitalOut Relay12V(PB_4); +DigitalOut Relay24V(PB_5); +DigitalOut Relay15_15_5V(PB_10); // Buffer: telecommand -volatile int rxTlcPtr; // telecommand receiving buffer -int rxTlcDataCounter = 0; -char rx_TLC[word+1]; // buffer -char data_TLC[word+1]; // telecommand +volatile int rxTlcPtr; +int rxTlcDataCounter = 0; +char rx_TLC[word+1]; +char data_TLC[word+1]; -// Buffer: standard telemetry -volatile int rxTlmPtr; +// Buffer: standard telemetry (1 frame da 16 bit o 2 frame da 16 bit ciascuno) +volatile int rxTlmPtr; int rxTlmDataCounter = 0; -char rx_TLM[word+1]; // buffer -char data_TLM[word+1]; // standard telemetry +char rx_TLM[word+1]; +char data_TLM[word+1]; -// Buffer: TLMODE telemetry option 1 -volatile int rxTlmOpt1Ptr; +// Buffer: TLMODE telemetry option 1 (tutte le housekeeping telemetries) +volatile int rxTlmOpt1Ptr; int rxTlmOpt1DataCounter = 0; -char rx_TLMOpt1[hsk_buf+1]; -char data_TLMOpt1[hsk_buf+1]; +char rx_TLMOpt1[word+1]; +char data_TLMOpt1[word+1]; -// Buffer: TLMODE telemetry option 1 -volatile int rxTlmOpt2Ptr; +// Buffer: TLMODE telemetry option 2 (housekeeping + data dall'interferometro) +volatile int rxTlmOpt2Ptr; int rxTlmOpt2DataCounter = 0; -char rx_TLMOpt2[hsk_sd_buf+1]; -char data_TLMOpt2[hsk_sd_buf+1]; +char rx_TLMOpt2[word+1]; +char data_TLMOpt2[word+1]; -// Timer -Timer timer; // telecommand -Timer rx; // rx window -float rxWindow = 300 /* seconds */, rxTimeStart, rxTimeStop, rxTimeRead; -float TIMEOUT = 10 /* seconds */, tTimeStart, tTimeStop, tTimeRead; +// Timer: 3 contatori differenti a seconda del numero di bytes da ricevere +Timer timer; +Timer rx; +Timer rx_wide; +float rxWindow = 6 /*seconds, TBA */, rxTimeStart, rxTimeStop, rxTimeRead; // standard teleemtry + hsk +float rx_wideWindow = 300 /*seconds, TBA */, rx_wideTimeStart, rx_wideTimeStop, rx_wideTimeRead; // full hsk+scientific data +float TIMEOUT = 3 /*seconds */, tTimeStart, tTimeStop, tTimeRead; // telecommand -// TLMODE +// TLMODE: definizione dei vari flag, assegnazioni di variabili volatile int tlmode_option_1, tlmode_option_2, tlmode_tlm; +volatile char payload; volatile bool TlcSend; +volatile bool Spare; +volatile char dataIn; // SC-MIMA communication: TX/RX -void RxTelecommand(); -void TxTelecommand(); -void RxTelemetry(); -void TxTelemetry(); +void RxTelecommand(void); +void TxTelecommand(void); +void RxTelemetry(void); +void TxTelemetry(void); // System utility void clearBuffer(char *arr, int arrLen); -// Temperature settings +// Richiesta temperatura char tempCH1[channel_size]; char tempCH2[channel_size]; volatile int j; // first channel index @@ -85,15 +111,15 @@ // Routines dedicate alla ricezione di dati della temperatura (Pt100) void SerialeRxInterrupt(void) { - char cReadChar; - while((max31865.readable())) + char cReadChar; + while ((max31865.readable())) { - cReadChar = max31865.getc(); - nRxCharCount++; + cReadChar = max31865.getc(); + nRxCharCount++; caRxPacket[nRxCharCount] = cReadChar; - } - - if (nRxCharCount == PACKETDIM) // if it reaches max -> reset + } + + if (nRxCharCount == PACKETDIM) { nRxCharCount = 0; } @@ -102,111 +128,172 @@ // Main int main() { + // config 0: il mio pc come spacecraft + // config 1: il mio pc come mima + // Baudrate - spacecraft.baud(115200); - //spacecraft.baud(9600); + spacecraft.baud(9600); mima.baud(9600); - //mima.baud(115200); max31865.baud(115200); // Diagnostica - spacecraft.printf(" Avvio Spacecraft... \n\r"); - //mima.printf(" Avvio MIMA... \n\r"); - + if (config == 0) + { + spacecraft.printf(" Avvio Spacecraft... \n\r"); + } + else if (config == 1) + { + mima.printf(" Avvio MIMA... \n\r"); + } + // Setup per temperatura int nIndex; nRxCharCount = 0; - for(nIndex = 0; nIndex < PACKETDIM; nIndex++) + for (nIndex = 0; nIndex < PACKETDIM; nIndex++) { caRxPacket[nIndex] = 0; - } - - // Setup per Actuonix L16 - actuonix.period_us(1000); + } + + // Setup per Actuonix L16->PWM + actuonix_dig.period_us(1000); + offset_dig = actuonix_dig.read(); offset = actuonix.read(); - + // Setup per Relay: 1 = OFF (1->OFF, 0->ON) - Relay5V = 1; - Relay12V = 1; - Relay15_15_5V = 1; - Relay24V = 1; - + Relay5V = 1; + Relay12V = 1; + Relay15_15_5V = 1; + Relay24V = 1; + // Bool flags TlcSend = false; - - // Interrupt routine + + // Interrupts max31865.attach(&SerialeRxInterrupt, Serial::RxIrq); spacecraft.attach(&RxTelecommand, Serial::RxIrq); mima.attach(&RxTelemetry, Serial::RxIrq); + + // Diagnostica + if (config == 0) + { + spacecraft.printf(" ... Ready to send... \n\r"); + } + else if (config == 1) + { + mima.printf(" ... Ready to send... \n\r"); + } // Main loop while (true) - { - // Telecommand + { + // Inizializza contatore caratteri in arrivo e flag di ricezione comando Spare + rxTlcPtr = 0; + Spare = false; + + // Setup per RX (uno dei flag verrà attivato solo via invio di un telecomando) + // se tutti i flag sono su "1", dora non trasmetterà nulla verso spacecraft + tlmode_option_1 = 1; + tlmode_option_2 = 1; + tlmode_tlm = 1; + + // Timer timer.start(); - tTimeStart = timer.read(); // in secondi + tTimeStart = timer.read(); tTimeRead = tTimeStart; - + + // Finché non raggiungo la dimensione richiesta (16 bit, 2 byte), + // resto in attesa di dati da spacecraft, all'interno della finestra di ricezione while ((rxTlcPtr < packet) && ((tTimeRead - tTimeStart) < TIMEOUT)) { tTimeRead = timer.read(); } - + timer.stop(); - + + // Se ho ricevuto 2 byte nella finestra di ricezione, preparo un array di data + // per ricomporre il frame da 16 bit e inviarlo a mima tramite dora if ((rxTlcPtr == packet) && ((tTimeRead - tTimeStart) < TIMEOUT)) - { - __disable_irq(); // disable interrupts so data doesn't arrive while we are doing this - memcpy(data_TLC, rx_TLC, rxTlcPtr); + { + __disable_irq(); + memcpy(data_TLC, rx_TLC, rxTlcPtr); rxTlcDataCounter = rxTlcPtr; - rxTlcPtr = 0; - //__enable_irq(); // re-enable interrupts - - data_TLC[1] = data_TLC[1] >> 1; // read payload data ignoring the LSB + + // Legge il contenuto del payload ignorando il LSB + payload = data_TLC[1] >> 1; + + // Diagnostica + if (config == 0) + { + spacecraft.printf("\n\r .... Telecomando ricevuto su DORA! \n\r"); + } + else if (config == 1) + { + mima.printf("\n\r .... Telecomando ricevuto su DORA! \n\r"); + } - spacecraft.printf("\n\r .... Telecomando ricevuto su DORA! \n\r"); - - for (int i = 0; i < sizeof(data_TLC)/sizeof(char); i++) + // Visualizza i byte inviati + for (int i = 0; i < sizeof(data_TLC) / sizeof(char); i++) { - spacecraft.printf("> Carattere: %f \n\r", (float)data_TLC[i]); - } - - data_TLC[rxTlcDataCounter] = 0; // add a null just in case the received data didn't have one at the end - + if (config == 0) + { + spacecraft.printf("> Carattere: %i \n\r", (int) data_TLC[i]); + } + else if (config == 1) + { + mima.printf("> Carattere: %i \n\r", (int) data_TLC[i]); + } + } + + // add a null just in case the received data didn't have one at the end + data_TLC[rxTlcDataCounter] = 0; + // hw control: set-point init - offset = 0; - + offset = actuonix.read(); // legge il valore attuale dell'attuatore + offset_dig = actuonix_dig.read(); + // RX settings - if (((float)data_TLC[0] != 40) || ((float)data_TLC[0] != 41)) + // Si prepara alla ricezione di telemetrie standard in caso di invio di telecomandi + // differenti dal CMD05 (TLMODE) + if (((int) data_TLC[0] != CMD05_1) || ((int) data_TLC[0] != CMD05_2)) { tlmode_option_1 = 1; tlmode_option_2 = 1; tlmode_tlm = 0; } - - // L16 setpoint - if ((float)data_TLC[0] == 0) + + // Controllo dell'attuatore lineare L16 (comando Spare) + if ((int) data_TLC[0] == CMD00) { - offset = (float)data_TLC[1]; - offset = offset/100; + offset = (int) payload; + offset = offset / 100; + + offset_dig = (int) payload; + offset_dig = offset_dig / 100; + + actuonix_dig.write(offset_dig); actuonix.write(offset); + + Spare = true; } - // Temperature request - else if (((float)data_TLC[0] == 16) && ((float)data_TLC[1] == 32)) + + // Richiesta delle temperature. Data: SXXX.XX;YYY.YYP > START/CH1;CH2/END + // Controllo del flusso di dati proveniente dalla Seriale + else if (((int) data_TLC[0] == CMD02) && ((int) payload == TEMP_QUERY)) { // Cleaning buffers - clearBuffer(tempCH1, sizeof(tempCH1)/sizeof(char)); - clearBuffer(tempCH2, sizeof(tempCH2)/sizeof(char)); + clearBuffer(tempCH1, sizeof(tempCH1) / sizeof(char)); + clearBuffer(tempCH2, sizeof(tempCH2) / sizeof(char)); // Index setup nRxCharCount = 0; int y = 0, u = 0; - t = 0; j = 0; + t = 0; j = 0; // global for (int i = 0; i < PACKETDIM; i++) { if (caRxPacket[i] == 'S') { + // Indice sul quale cade la prima cifra del canale 1 j = i + 1; while (j < PACKETDIM) @@ -223,6 +310,7 @@ j++; } + // Indice sul quale cade la prima cifra del canale 2 t = j + 1; while (t < PACKETDIM) @@ -235,69 +323,90 @@ { tempCH2[u++] = caRxPacket[t]; } + t++; } + break; } } - // Send + + // Invia i dati a Spacecraft spacecraft.puts(tempCH1); - spacecraft.puts(";"); + spacecraft.puts(";"); // split ch1-ch2 data spacecraft.puts(tempCH2); + + Spare = true; } - else if (((float)data_TLC[0] == 121) && ((float)data_TLC[1] == 42)) + else if (((int) data_TLC[0] == CMD15_R) && ((int) payload == ALL_RELAY_OFF)) { Relay5V = 1; Relay12V = 1; Relay15_15_5V = 1; Relay24V = 1; + + Spare = true; } - else if (((float)data_TLC[0] == 120) && ((float)data_TLC[1] == 85)) + else if (((int) data_TLC[0] == CMD15) && ((int) payload == ALL_RELAY_ON)) { Relay5V = 0; Relay12V = 0; Relay15_15_5V = 0; - Relay24V = 0; + Relay24V = 0; + + Spare = true; } - else if (((float)data_TLC[0] == 120)) // Relay + else if (((int) data_TLC[0] == CMD15)) { - if (((float)data_TLC[1] == 0)) + if (((int) payload == DISABLE_12V)) { Relay12V = 1; + Spare = true; } - else if (((float)data_TLC[1] == 1)) + else if (((int) payload == ENABLE_12V)) { Relay12V = 0; // since the linear actuator is driven by 12V power offset = actuonix.read(); + offset_dig = actuonix_dig.read(); + actuonix.write(offset); - } - else if (((float)data_TLC[1] == 2)) - { - Relay5V = 1; + actuonix.write(offset_dig); + + Spare = true; } - else if (((float)data_TLC[1] == 3)) + else if (((int) payload == DISABLE_5V)) { - Relay5V = 0; + Relay5V = 1; + Spare = true; } - else if (((float)data_TLC[1] == 6)) + else if (((int) payload == ENABLE_5V)) + { + Relay5V = 0; + Spare = true; + } + else if (((int) payload == DISABLE_15V)) { Relay15_15_5V = 1; + Spare = true; } - else if (((float)data_TLC[1] == 7)) + else if (((int) payload == ENABLE_15V)) { Relay15_15_5V = 0; + Spare = true; } - else if (((float)data_TLC[1] == 8)) + else if (((int) payload == DISABLE_24V)) { Relay24V = 1; + Spare = true; } - else if (((float)data_TLC[1] == 15)) + else if (((int) payload == ENABLE_24V)) { Relay24V = 0; + Spare = true; } } - else if (((float)data_TLC[0] == 40) && ((float)data_TLC[1] == 24)) + else if (((int) data_TLC[0] == CMD05_1) && ((int) payload == TLMODE_HSK)) { tlmode_option_1 = 0; tlmode_option_2 = 1; @@ -305,9 +414,17 @@ rxTlmPtr = 0; rxTlmOpt1Ptr = 0; rxTlmOpt2Ptr = 0; - spacecraft.printf("> Sono entrato in TLMODE 1 \n\r"); + + if (config == 0) + { + spacecraft.printf("\n\r ... Sono entrato in TLMODE 1 ... \n\r"); + } + else if (config == 1) + { + mima.printf("\n\r ... Sono entrato in TLMODE 1 ... \n\r"); + } } - else if (((float)data_TLC[0] == 41) && ((float)data_TLC[1] == 127)) + else if (((int) data_TLC[0] == CMD05_2) && ((int) payload == TLMODE_HSKSD)) { tlmode_option_2 = 0; tlmode_option_1 = 1; @@ -315,10 +432,19 @@ rxTlmPtr = 0; rxTlmOpt1Ptr = 0; rxTlmOpt2Ptr = 0; - spacecraft.printf("> Sono entrato in TLMODE 2 \n\r"); + + if (config == 0) + { + spacecraft.printf("\n\r ... Sono entrato in TLMODE 2 ... \n\r"); + } + else if (config == 1) + { + mima.printf("\n\r ... Sono entrato in TLMODE 2 ... \n\r"); + } } + // Reset global vars - else if (((float)data_TLC[0] == 241) && ((float)data_TLC[1] == 127)) + else if (((int) data_TLC[0] == CMD31) && ((int) payload == RESET_GLOBAL_VARS)) { nRxCharCount = 0; rxTlcPtr = 0; @@ -330,203 +456,294 @@ tlmode_tlm = 1; tlmode_option_1 = 1; tlmode_option_2 = 1; - - for(nIndex = 0; nIndex < PACKETDIM; nIndex++) + + for (nIndex = 0; nIndex < PACKETDIM; nIndex++) { caRxPacket[nIndex] = 0; - } + } + + clearBuffer(data_TLC, sizeof(data_TLC) / sizeof(char)); + clearBuffer(data_TLM, sizeof(data_TLM) / sizeof(char)); + clearBuffer(data_TLMOpt1, sizeof(data_TLMOpt1) / sizeof(char)); + clearBuffer(data_TLMOpt2, sizeof(data_TLMOpt2) / sizeof(char)); - clearBuffer(data_TLC, sizeof(data_TLC)/sizeof(char)); - clearBuffer(data_TLM, sizeof(data_TLM)/sizeof(char)); - clearBuffer(data_TLMOpt1, sizeof(data_TLMOpt1)/sizeof(char)); - clearBuffer(data_TLMOpt2, sizeof(data_TLMOpt2)/sizeof(char)); - - spacecraft.printf(".... Reset variabili effettuato! \n\r"); + Spare = true; + + if (config == 0) + { + spacecraft.printf("\n\r ... Reset variabili effettuato! ... \n\r"); + } + else if (config == 1) + { + mima.printf("\n\r ... Reset variabili effettuato! ... \n\r"); + } + } + + // Invia il telecomando a MIMA se non è Spare + if (!Spare) + { + TxTelecommand(); + } + // Telecommand sent, flags set + + if (config == 0) + { + spacecraft.printf("\n\r ... Telecomando inviato a MIMA ... \n\r"); + } + else if (config == 1) + { + mima.printf("\n\r ... Telecomando inviato a MIMA ... \n\r"); + } + + // Ripulisci il buffer di ricezione telecomando + clearBuffer(rx_TLC, sizeof(rx_TLC) / sizeof(char)); + clearBuffer(data_TLC, sizeof(data_TLC) / sizeof(char)); + + if (config == 0) + { + spacecraft.printf("\n\r ... Ho ripulito i buffer di ricezione TLC .... \n\r"); + } + else + { + mima.printf("\n\r ... Ho ripulito i buffer di ricezione TLC .... \n\r"); } - - // Send after setting flags and clear - TxTelecommand(); - spacecraft.printf(".... Telecomando inviato a MIMA ...."); - __enable_irq(); // ********************************************************************* - clearBuffer(rx_TLC, sizeof(rx_TLC)/sizeof(char)); - clearBuffer(data_TLC, sizeof(data_TLC)/sizeof(char)); - - spacecraft.printf(".... Ho ripulito i buffer di ricezione TLC .... \n\r"); - - /* *********************************************************** */ - - //__disable_irq(); // da lavorare su queste chiamate perché se da un lato prevengono - // blocco del telecomando durante ricezione, dall'altro impediscono al comando di telemetria di ricevere - - if ((TlcSend) && (tlmode_option_1 == 1) && (tlmode_option_2 == 1) && (tlmode_tlm == 0)) - { - clearBuffer(data_TLM, sizeof(data_TLM)/sizeof(char)); + + __enable_irq(); // now he's ready to receive new data + + } // end-if:telecommand + else if ((tTimeRead - tTimeStart) >= TIMEOUT) + { + rxTlcPtr = 0; + for (int i = 0; i < packet; i++) + { + rx_TLC[i] = '\0'; + data_TLC[i] = '\0'; + } + + if (config == 0) + { + spacecraft.printf(" n\r ... Telecommand RX timeout ... \n\r"); + } + else if (config == 1) + { + mima.printf("\n\r ... Telecommand RX timeout ... \n\r"); + } + } // end-else-if:telecommand+timeout - // Standard telemetry frame + // Telemetry + /* DORA si predispone a ricevere lato mima solo se un comando che non sia + Spare è stato inviato, onde evitare ritardi (sul prossimo telecomando) + dovuti a Timeout indesiderati. Sostanzialmente attende due byte + (ricompone il frame) e li invia a spacecraft all'interno della finestra + di trasmissione. */ + if ((!Spare) && (TlcSend)) + { + if ((tlmode_option_1 == 1) && (tlmode_option_2 == 1) && (tlmode_tlm == 0)) // standard telemetry + { + clearBuffer(data_TLM, sizeof(data_TLM) / sizeof(char)); + rx.start(); - rxTimeStart = rx.read(); + rxTimeStart = rx.read(); rxTimeRead = rxTimeStart; - - while ((rxTlmPtr < packet) && ((rxTimeRead - rxTimeStart) < rxWindow)) + + while (((rxTimeRead - rxTimeStart) < rxWindow)) { + if (rxTlmPtr == packet) + { + __disable_irq(); + memcpy(data_TLM, rx_TLM, rxTlmPtr); + rxTlmDataCounter = rxTlmPtr; + rxTlmPtr = 0; + + data_TLM[rxTlmDataCounter] = 0; + + TxTelemetry(); + __enable_irq(); + + // Diagnostic + if (config == 0) + { + spacecraft.printf("\n\r ... Ricevuto Telemetry Standard ... \n\r"); + } + else if (config == 1) + { + mima.printf("\n\r ... Ricevuto Telemetry Standard ... \n\r"); + } + } + // update rxTimeRead = rx.read(); } - + rx.stop(); - - if ((rxTlmPtr == packet) && ((rxTimeRead - rxTimeStart) < rxWindow)) - { - __disable_irq(); - memcpy(data_TLM, rx_TLM, rxTlmPtr); - rxTlmDataCounter = rxTlmPtr; - rxTlmPtr = 0; - //__enable_irq(); - - data_TLM[rxTlmDataCounter] = 0; - - TxTelemetry(); - __enable_irq(); // *************************************************** - spacecraft.printf("\n\r Ricevuto Telemetry Standard \n\r"); - } - else if ((rxTimeRead - rxTimeStart) >= rxWindow) + if ((rxTimeRead - rxTimeStart) >= rxWindow) { - spacecraft.printf("\n\r !!! Scattato il timeout in Telemetry !!! \n\r"); + if (config == 0) + { + spacecraft.printf("\n\r ... Scattato il timeout in Telemetry ... \n\r"); + } + else if (config == 1) + { + mima.printf("\n\r ... Scattato il timeout in Telemetry ... \n\r"); + } + rxTlmPtr = 0; + for (int i = 0; i < packet; i++) { rx_TLM[i] = '\0'; data_TLM[i] = '\0'; } - } // end-else-if:telecommand-send+timeout - + } // end-else-if:telecommand-send+timeout + TlcSend = false; - } // end-if-send-telecommand - else if ((TlcSend) && (tlmode_option_1 == 0) && (tlmode_option_2 == 1) && (tlmode_tlm == 1)) - { - spacecraft.printf("\n\r > Sono entrato in TLMODE 1 - TX Telemetry \n\r"); - clearBuffer(data_TLMOpt1, sizeof(data_TLMOpt1)/sizeof(char)); - + } // end-if-send-telecommand + else if ((tlmode_option_1 == 0) && (tlmode_option_2 == 1) && (tlmode_tlm == 1)) // all housekeeping teemetries + { + clearBuffer(data_TLMOpt1, sizeof(data_TLMOpt1)/sizeof(char)); + rx.start(); - rxTimeStart = rx.read(); + rxTimeStart = rx.read(); rxTimeRead = rxTimeStart; - - while ((rxTlmOpt1Ptr < hsk_rx) && ((rxTimeRead - rxTimeStart) < rxWindow)) + + while (((rxTimeRead - rxTimeStart) < rxWindow)) { + if (rxTlmOpt1Ptr == packet) + { + __disable_irq(); + memcpy(data_TLMOpt1, rx_TLMOpt1, rxTlmOpt1Ptr); + rxTlmOpt1DataCounter = rxTlmOpt1Ptr; + rxTlmOpt1Ptr = 0; + + data_TLMOpt1[rxTlmOpt1DataCounter] = 0; + + TxTelemetry(); + __enable_irq(); + + // Diagnostic + if (config == 0) + { + spacecraft.printf("\n\r ... Ricevuto Telemetry Opt 1 ... \n\r"); + } + else if (config == 1) + { + mima.printf("\n\r ... Ricevuto Telemetry Opt 1 ... \n\r"); + } + + } + // update rxTimeRead = rx.read(); } - + rx.stop(); - - if ((rxTlmOpt1Ptr == hsk_rx) && ((rxTimeRead - rxTimeStart) < rxWindow)) - { - __disable_irq(); - memcpy(data_TLMOpt1, rx_TLMOpt1, rxTlmOpt1Ptr); - rxTlmOpt1DataCounter = rxTlmOpt1Ptr; - rxTlmOpt1Ptr = 0; - //__enable_irq(); - - data_TLMOpt1[rxTlmOpt1DataCounter] = 0; + + if ((rxTimeRead - rxTimeStart) >= rxWindow) + { + if (config == 0) + { + spacecraft.printf("\n\r ... Scattato il timeout in Telemetry Opt 1 ... \n\r"); + } + else if (config == 1) + { + mima.printf("\n\r ... Scattato il timeout in Telemetry Opt 1 ... \n\r"); + } - TxTelemetry(); - __enable_irq(); // *************************************************** - spacecraft.printf("\n\r > Ricevuto Telemetry Opt 1 \n\r"); - - } - else if ((rxTimeRead - rxTimeStart) >= rxWindow) - { - mima.printf("\n\r !!! Scattato il timeout in Telemetry Opt 1 !!! \n\r"); rxTlmOpt1Ptr = 0; for (int i = 0; i < packet; i++) { rx_TLMOpt1[i] = '\0'; data_TLMOpt1[i] = '\0'; } - } + } // end-else-if:telecommand-send+timeout + TlcSend = false; - } // end-else-if-send-telecommand - else if ((TlcSend) && (tlmode_option_1 == 1) && (tlmode_option_2 == 0) && (tlmode_tlm == 1)) - { - spacecraft.printf("\n\r > Sono entrato in TLMODE 2 - TX Telemetry \n\r"); - clearBuffer(data_TLMOpt2, sizeof(data_TLMOpt2)/sizeof(char)); - - rx.start(); - rxTimeStart = rx.read(); - rxTimeRead = rxTimeStart; - - while ((rxTlmOpt2Ptr < hsk_sd) && ((rxTimeRead - rxTimeStart) < rxWindow)) + } // end-else-if-send-telecommand + else if ((tlmode_option_1 == 1) && (tlmode_option_2 == 0) && (tlmode_tlm == 1)) // all hsk + inteferogram data + { + clearBuffer(data_TLMOpt2, sizeof(data_TLMOpt2)/sizeof(char)); + + rx_wide.start(); + rx_wideTimeStart = rx_wide.read(); + rx_wideTimeRead = rx_wideTimeStart; + + while (((rx_wideTimeRead - rx_wideTimeStart) < rx_wideWindow)) { - rxTimeRead = rx.read(); + if (rxTlmOpt2Ptr == packet) + { + __disable_irq(); + memcpy(data_TLMOpt2, rx_TLMOpt2, rxTlmOpt2Ptr); + rxTlmOpt2DataCounter = rxTlmOpt2Ptr; + rxTlmOpt2Ptr = 0; + + data_TLMOpt2[rxTlmOpt2DataCounter] = 0; + + TxTelemetry(); + __enable_irq(); + + // Diagnostic + if (config == 0) + { + spacecraft.printf("\n\r ... Ricevuto Telemetry Opt 2 ... \n\r"); + } + else if (config == 1) + { + mima.printf("\n\r ... Ricevuto Telemetry Opt 2 ... \n\r"); + } + + } + // update + rx_wideTimeRead = rx_wide.read(); } - + rx.stop(); - - if ((rxTlmOpt2Ptr == hsk_sd) && ((rxTimeRead - rxTimeStart) < rxWindow)) - { - __disable_irq(); - memcpy(data_TLMOpt2, rx_TLMOpt2, rxTlmOpt2Ptr); - rxTlmOpt2DataCounter = rxTlmOpt2Ptr; - rxTlmOpt2Ptr = 0; - //__enable_irq(); - - data_TLMOpt2[rxTlmOpt2DataCounter] = 0; + + if ((rx_wideTimeRead - rx_wideTimeStart) >= rx_wideWindow) + { + if (config == 0) + { + spacecraft.printf("\n\r ... Scattato il timeout in Telemetry Opt 2 ... \n\r"); + } + else if (config == 1) + { + mima.printf("\n\r ... Scattato il timeout in Telemetry Opt 2 ... \n\r"); + } - TxTelemetry(); - __enable_irq(); // *************************************************** - spacecraft.printf("\n\r Ricevuto Telemetry Opt 2 \n\r"); - - } - else if ((rxTimeRead - rxTimeStart) >= rxWindow) - { - spacecraft.printf("\n\r !!! Scattato il timeout in Telemetry Opt 2 !!! \n\r"); rxTlmOpt2Ptr = 0; for (int i = 0; i < packet; i++) { rx_TLMOpt2[i] = '\0'; data_TLMOpt2[i] = '\0'; } - } + } // end-else-if:telecommand-send+timeout + TlcSend = false; - } // end-2nd-else-if-send-telecommand - - spacecraft.printf("\n\r .... Ho inviato il telecomando entro la finestra di timeout .... \n\r"); - spacecraft.printf(" *************************************** \n\r"); - - //__enable_irq(); - - } // end-if:telecommand - else if ((tTimeRead - tTimeStart) >= TIMEOUT) - { - rxTlcPtr = 0; - for (int i = 0; i < packet; i++) - { - rx_TLC[i] = '\0'; - data_TLC[i] = '\0'; - } - - spacecraft.printf(" .... Telecomando non inviato: timeout, riprovare! \n\r"); - } // end-else-if:telecommand+timeout - } // end-while:true -} // end-Main + } // end-2nd-else-if-send-telecommand + } + } // end-while:true +} // end-Main -/* ************************************************************* */ -/* ******** SYSTEM INTERRPUTS MANAGEMENT AND FUNCTIONS ********* */ -/* ************************************************************* */ +/* ************************************************************ */ +/* ******* SYSTEM INTERRPUTS MANAGEMENT AND FUNCTIONS ********* */ +/* ************************************************************ */ // Interrupt: DORA receives a byte from Spacecraft -void RxTelecommand() +void RxTelecommand(void) { char txChar; - while (spacecraft.readable()) - { + while (spacecraft.readable()) + { txChar = spacecraft.getc(); - rx_TLC[rxTlcPtr++] = txChar; + + if (rxTlcPtr < packet) + { + rx_TLC[rxTlcPtr++] = txChar; + } } } // Interrupt: DORA receives a byte from MIMA -void RxTelemetry() +void RxTelemetry(void) { char rxChar; while (mima.readable()) @@ -549,26 +766,39 @@ } // Once received a full telecommand frame, send it to MIMA -void TxTelecommand() +void TxTelecommand(void) { - mima.puts(data_TLC); + for (int i = 0; i < packet; i++) + { + mima.putc(data_TLC[i]); + } + TlcSend = true; } // Once received a full telemetry frame, send it to Spacecraft -void TxTelemetry() +void TxTelemetry(void) { if (tlmode_tlm == 0) { - spacecraft.puts(data_TLM); + for (int i = 0; i < packet; i++) + { + spacecraft.putc(data_TLM[i]); + } } else if (tlmode_option_1 == 0) { - spacecraft.puts(data_TLMOpt1); + for (int i = 0; i < packet; i++) + { + spacecraft.putc(data_TLMOpt1[i]); + } } else if (tlmode_option_2 == 0) { - spacecraft.puts(data_TLMOpt2); + for (int i = 0; i < packet; i++) + { + spacecraft.putc(data_TLMOpt2[i]); + } } } @@ -578,6 +808,6 @@ int myIndex; for (myIndex = 0; myIndex < arrLen; myIndex++) { - arr[myIndex] = '\0'; // terminatore + arr[myIndex] = '\0'; // terminatore } } \ No newline at end of file
--- a/tlc_tlm_list.h Fri Jul 15 14:00:59 2022 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,100 +0,0 @@ -#include "mbed.h" - -#ifndef HEADER_FILE -#define HEADER_FILE - -#define size 1 - -typedef struct Telecommand { - char *ID; - char *TAG; - char *PAYLOAD; - char LSB; -} Telecommand; - -typedef struct Telemetry { - char *ID; - char *TAG; - char *PAYLOAD; - char LSB; -} Telemetry; - -typedef struct Interferogram { - char *STARTCH; - char *CHECKSUM; - char CH; - char *ENDCH; -} Interferogram; - -// Telecomandi -extern Telecommand cmd00[size] = { {"00000", "00", "", '0'} }; -extern Telecommand mima_mode[size] = { {"00001", "00", "", '0'} }; -extern Telecommand cmd02[size] = { {"00010", "00", "", '0'} }; -extern Telecommand ldth_on_off[size] = { {"00011", "00", "", '0'} }; -extern Telecommand irth_on_off[size] = { {"00100", "00", "", '0'} }; -extern Telecommand tlmode[size] = { {"00101", "00", "", '0'} }; -extern Telecommand start_stop[size] = { {"00110", "00", "", '0'} }; -extern Telecommand temp_sens_sel[size] = { {"00111", "00", "", '0'} }; -extern Telecommand tinitscan[size] = { {"01000", "00", "", '0'} }; -extern Telecommand nskip[size] = { {"01001", "00", "", '0'} }; -extern Telecommand cover_thr[size] = { {"01010", "00", "", '0'} }; -extern Telecommand cover[size] = { {"01011", "00", "", '0'} }; -extern Telecommand cal_on_off[size] = { {"01100", "00", "", '0'} }; -extern Telecommand ld_on_off[size] = { {"01101", "00", "", '0'} }; -extern Telecommand bbth_on_off[size] = { {"01110", "00", "", '0'} }; -extern Telecommand cmd15[size] = { {"01111", "00", "", '0'} }; -extern Telecommand locs[size] = { {"10000", "00", "", '0'} }; -extern Telecommand ldcs[size] = { {"10001", "00", "", '0'} }; -extern Telecommand ldts[size] = { {"10010", "00", "", '0'} }; -extern Telecommand irts[size] = { {"10011", "00", "", '0'} }; -extern Telecommand bbts[size] = { {"10100", "00", "", '0'} }; -extern Telecommand pga[size] = { {"10101", "00", "", '0'} }; -extern Telecommand pm_loop[size] = { {"10110", "00", "", '0'} }; -extern Telecommand pm_speed[2*size] = { {"10111", "01", "", '0'}, {"10111", "10", "", '0'} }; -extern Telecommand kp[size] = { {"11000", "00", "", '0'} }; -extern Telecommand ki[size] = { {"11001", "00", "", '0'} }; -extern Telecommand kd[size] = { {"11010", "00", "", '0'} }; -extern Telecommand att[size] = { {"11011", "00", "", '0'} }; -extern Telecommand n_sample[2*size] = { {"11100", "01", "", '0'}, {"11100", "10", "", '0'} }; -extern Telecommand int_samp[size] = { {"11101", "00", "", '0'} }; -extern Telecommand cmd31[size] = { {"11110", "00", "", '0'} }; -extern Telecommand mima_reset[size] = { {"11111", "00", "", '0'} }; - -// Telemetrie -extern Telemetry irt1[2*size] = { {"00000", "01", "00000000", '1'}, {"00000", "10", "00000000", '1'} }; -extern Telemetry irt2[2*size] = { {"00001", "01", "00000000", '0'}, {"00001", "10", "00000000", '0'} }; -extern Telemetry ldt1[2*size] = { {"00010", "01", "00000000", '0'}, {"00010", "10", "00000000", '0'} }; -extern Telemetry ldt2[2*size] = { {"00011", "01", "00000000", '1'}, {"00011", "10", "00000000", '1'} }; -extern Telemetry mima_el_t1_2[2*size] = { {"00100", "01", "00000000", '0'}, {"00100", "10", "00000000", '0'} }; -extern Telemetry mima_el_t3[size] = { {"00101", "00", "00000000", '0'} }; -extern Telemetry mima_ob_t1[2*size] = { {"00110", "01", "00000000", '1'}, {"00110", "10", "00000000", '1'} }; -extern Telemetry mima_ob_t2[2*size] = { {"00111", "01", "00000000", '0'}, {"00111", "10", "00000000", '0'} }; -extern Telemetry bbt1[2*size] = { {"01000", "01", "00000000", '0'}, {"01000", "10", "00000000", '0'} }; -extern Telemetry bbt2[2*size] = { {"01001", "01", "00000000", '1'}, {"01001", "10", "00000000", '1'} }; -extern Telemetry v15pn[2*size] = { {"01010", "01", "00000000", '1'}, {"01010", "10", "00000000", '1'} }; -extern Telemetry v5pn[2*size] = { {"01011", "01", "00000000", '0'}, {"01011", "10", "00000000", '0'} }; -extern Telemetry v3[size] = { {"01100", "00", "00000000", '0'} }; -extern Telemetry vintp[2*size] = { {"01101", "01", "00000000", '0'}, {"01101", "10", "00000000", '0'} }; -extern Telemetry cali_v[2*size] = { {"01110", "01", "00000000", '0'}, {"01110", "10", "00000000", '0'} }; -extern Telemetry ldc[2*size] = { {"01111", "01", "00000000", '1'}, {"01111", "10", "00000000", '1'} }; -extern Telemetry ramp_hk[2*size] = { {"10000", "01", "00000000", '0'}, {"10000", "10", "00000000", '0'} }; -extern Telemetry ldcsr[2*size] = { {"10001", "01", "00000000", '1'}, {"10001", "10", "00000000", '1'} }; -extern Telemetry ldtr[2*size] = { {"10010", "01", "00000000", '1'}, {"10010", "10", "00000000", '1'} }; -extern Telemetry irt[2*size] = { {"10011", "01", "00000000", '0'}, {"10011", "10", "00000000", '0'} }; -extern Telemetry bbt[2*size] = { {"10100", "01", "00000000", '1'}, {"10100", "10", "00000000", '1'} }; -extern Telemetry pmspeed[2*size] = { {"10101", "01", "00000000", '0'}, {"10101", "10", "00000000", '0'} }; -extern Telemetry pmparam[2*size] = { {"10110", "01", "00000000", '0'}, {"10110", "10", "00000000", '0'} }; -extern Telemetry n_sample_r[2*size] = { {"10111", "01", "00000000", '1'}, {"10111", "10", "00000000", '1'} }; -extern Telemetry ipn[2*size] = { {"11000", "01", "00000000", '1'}, {"11000", "10", "00000000", '1'} }; -extern Telemetry mima_sts1[2*size] = { {"11001", "01", "00000000", '0'}, {"11001", "10", "00000000", '0'} }; -extern Telemetry mima_sts2[2*size] = { {"11010", "01", "00000000", '0'}, {"11010", "10", "00000000", '0'} }; -extern Telemetry mima_sts3[2*size] = { {"11011", "01", "00000000", '1'}, {"11011", "10", "00000000", '1'} }; -extern Telemetry mima_sts4[2*size] = { {"11100", "01", "00000000", '0'}, {"11100", "10", "00000000", '0'} }; -extern Telemetry techo[2*size] = { {"11101", "01", "00000000", '0'}, {"11101", "10", "00000000", '0'} }; - -// Interferometro -extern Interferogram interferogram[2*size] = { {"1111000011110000", "1111111100000001", '0', "0000111100001111"}, - {"1111000011110000", "0101010101010101", '0', "0000111100001111"} }; - - -#endif \ No newline at end of file