message processing added

This commit is contained in:
ken
2022-07-05 10:17:07 -07:00
parent 327ee020f9
commit 8f35be3741
@@ -18,7 +18,10 @@
#define UTCm7 (7*60*60) // your timezone relative to UTC in seconds #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 <USBHost_t36.h> #include <USBHost_t36.h>
#include <TimeLib.h> #include <TimeLib.h>
@@ -58,6 +61,7 @@ char Serial2RxBuffer[Serial2RxBufferSIZE]; // global scope or static char. power
char Serial3RxBuffer[Serial3RxBufferSIZE]; // global scope or static char. power of 2. char Serial3RxBuffer[Serial3RxBufferSIZE]; // global scope or static char. power of 2.
// ^^^ end GLOBAL ^^^ // ^^^ end GLOBAL ^^^
@@ -74,7 +78,7 @@ void setup()
int i; int i;
char fname[16]; char fname[16];
myTimer.begin(TimerISR, 100000); // period in microseconds = 0.1 sec myTimer.begin(TimerISR, 1000000); // period in microseconds = 1 sec
setSyncProvider(getTeensy3Time); setSyncProvider(getTeensy3Time);
setSyncInterval(300); // default is 5 min. this call should force a sync 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.begin(9600); // MUST match Garmin
Serial1.addMemoryForRead(Serial1RxBuffer, Serial1RxBufferSIZE); Serial1.addMemoryForRead(Serial1RxBuffer, Serial1RxBufferSIZE);
Serial2.begin(115200); // MUST match Dynon EMS Serial2.begin(115200); // MUST match Dynon EFIS
Serial2.addMemoryForRead(Serial2RxBuffer, Serial2RxBufferSIZE); Serial2.addMemoryForRead(Serial2RxBuffer, Serial2RxBufferSIZE);
Serial3.begin(115200); // MUST match Dynon EMS Serial3.begin(115200); // MUST match Dynon EMS
@@ -241,7 +245,7 @@ time_t getdatetime(){
time_t t; time_t t;
TimeElements tm; TimeElements tm;
t = 0 t = 0;
return(t); return(t);
} }
@@ -250,30 +254,94 @@ time_t getdatetime(){
void loop(void) { void loop(void) {
int i; int i;
char fname[16]; 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) { if (tick) {
tick = false; tick = false;
toggleLED();
if (myFile) { if (!myFile) { /* open a new file */
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 */
myDrive1.begin(); myDrive1.begin();
myDrive1.startFilesystems(); myDrive1.startFilesystems();
if (DEBUG) Serial.print("try opening new file...\n"); if (DEBUG) Serial.print("try opening new file...\n");