From 8f35be3741260a62267dd85c9129db0a82673df5 Mon Sep 17 00:00:00 2001 From: ken Date: Tue, 5 Jul 2022 10:17:07 -0700 Subject: [PATCH] message processing added --- .../USBDrive_Airplane_Data_Logger.ino | 116 ++++++++++++++---- 1 file changed, 92 insertions(+), 24 deletions(-) diff --git a/USBDrive_Airplane_Data_Logger/USBDrive_Airplane_Data_Logger.ino b/USBDrive_Airplane_Data_Logger/USBDrive_Airplane_Data_Logger.ino index e791ef2..6aa49b0 100644 --- a/USBDrive_Airplane_Data_Logger/USBDrive_Airplane_Data_Logger.ino +++ b/USBDrive_Airplane_Data_Logger/USBDrive_Airplane_Data_Logger.ino @@ -18,7 +18,10 @@ #define UTCm7 (7*60*60) // your timezone relative to UTC in seconds -#include "GPS_position.h" +// end of message characters +#define GPS_EOM '\x003' +#define EFIS_EOM '\n' +#define EMS_EOM '\n' #include #include @@ -58,6 +61,7 @@ char Serial2RxBuffer[Serial2RxBufferSIZE]; // global scope or static char. power char Serial3RxBuffer[Serial3RxBufferSIZE]; // global scope or static char. power of 2. + // ^^^ end GLOBAL ^^^ @@ -74,7 +78,7 @@ void setup() int i; char fname[16]; - myTimer.begin(TimerISR, 100000); // period in microseconds = 0.1 sec + myTimer.begin(TimerISR, 1000000); // period in microseconds = 1 sec setSyncProvider(getTeensy3Time); setSyncInterval(300); // default is 5 min. this call should force a sync @@ -92,7 +96,7 @@ void setup() Serial1.begin(9600); // MUST match Garmin Serial1.addMemoryForRead(Serial1RxBuffer, Serial1RxBufferSIZE); - Serial2.begin(115200); // MUST match Dynon EMS + Serial2.begin(115200); // MUST match Dynon EFIS Serial2.addMemoryForRead(Serial2RxBuffer, Serial2RxBufferSIZE); Serial3.begin(115200); // MUST match Dynon EMS @@ -241,7 +245,7 @@ time_t getdatetime(){ time_t t; TimeElements tm; - t = 0 + t = 0; return(t); } @@ -250,30 +254,94 @@ time_t getdatetime(){ void loop(void) { int i; char fname[16]; + int msg1 = 0; + int msg2 = 0; + int msg3 = 0; + int i1 = 0; + int i2 = 0; + int i3 = 0; + char GPSRx[Serial1RxBufferSIZE]; + char EFISRx[Serial2RxBufferSIZE]; + char EMSRx[Serial3RxBufferSIZE]; + bool MSG_OVFL = false; + + + // process until end of message + if (Serial1.available()) { + GPSRx[i1]=Serial1.read(); + if (GPSRx[i1] == GPS_EOM) msg1 = i1; + i1++; + GPSRx[i1]=NULL; + if (i1 == Serial1RxBufferSIZE - 1) { + MSG_OVFL = true; + msg1 = i1; + } + } + + // process until end of message + if (Serial2.available()) { + EFISRx[i2]=Serial2.read(); + if (EFISRx[i2] == EFIS_EOM) msg2 = i2; + i2++; + EFISRx[i2]=NULL; + if (i2 == Serial2RxBufferSIZE - 1) { + MSG_OVFL = true; + msg2 = i2; + } + } + + // process until end of message + if (Serial3.available()) { + EMSRx[i3]=Serial3.read(); + if (EMSRx[i3] == EMS_EOM) msg3 = i3; + i3++; + EMSRx[i3]=NULL; + if (i3 == Serial3RxBufferSIZE - 1) { + MSG_OVFL = true; + msg3 = i3; + } + } + + + if (myFile) { + if (msg1>0) { + myFile.print("G:"); + myFile.write(GPSRx,msg1); + msg1=0; + i1=0; + if (MSG_OVFL) { + myFile.println("G: OVERFLOW!"); + MSG_OVFL = false; + } + } + if (msg2>0) { + myFile.print("F:"); + myFile.write(EFISRx,msg2); + msg2=0; + i2=0; + if (MSG_OVFL) { + myFile.println("F: OVERFLOW!"); + MSG_OVFL = false; + } + } + if (msg3>0) { + myFile.print("E:"); + myFile.write(EMSRx,msg3); + msg3=0; + i3=0; + if (MSG_OVFL) { + myFile.println("E: OVERFLOW!"); + MSG_OVFL = false; + } + } + } + - # process eom uart1 - # process eom uart2 - # process eom uart3 if (tick) { tick = false; + toggleLED(); - if (myFile) { - if (msg1>0) { - myFile.print("G:"); - # write(Rx1,msg1) - msg1=0; - } - if (msg2>0) { - myFile.print("F:"); - # write(Rx2,msg2) - msg2=0; - } - if (msg3>0) { - myFile.print("E:"); - # write(Rx3,msg3) - msg3=0; - } - } else { /* open a new file */ + if (!myFile) { /* open a new file */ myDrive1.begin(); myDrive1.startFilesystems(); if (DEBUG) Serial.print("try opening new file...\n");