I messed up the merge, so pushing it over to another repo so I don't lose it. Will tidy up and remove later
Dependencies: BufferedSerial FatFileSystemCpp mbed
Revision 53:b790ed7b838f, committed 2021-08-25
- Comitter:
- JamieB
- Date:
- Wed Aug 25 17:20:10 2021 +0000
- Parent:
- 49:df05784d9a5c
- Parent:
- 52:adbbaadca0a9
- Child:
- 54:3d7b480b8e1e
- Commit message:
- Random Commit so I can merge latest changes
Changed in this revision
LTCApp.h | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/LTCApp.h Wed Aug 25 17:02:47 2021 +0000 +++ b/LTCApp.h Wed Aug 25 17:20:10 2021 +0000 @@ -45,6 +45,14 @@ bool FilterYaw; bool AutoHyperSmooth; bool FlexibleVIPSOut; + float SerialTxDelayMS; + float UDPTxDelayMS; + float SerialTxDelayFrame; + float UDPTxDelayFrame; + bool InvertRoll; + bool InvertPitch; + bool InvertYaw; + int bypassBaud; } UserSettings_t; extern UserSettings_t UserSettings;
--- a/main.cpp Wed Aug 25 17:02:47 2021 +0000 +++ b/main.cpp Wed Aug 25 17:20:10 2021 +0000 @@ -84,7 +84,7 @@ BufferedSerial pc(USBTX, USBRX); VIPSSerial VIPS(p28, p27); -RawSerial COM1(p13, p14); +BufferedSerial COM1(p13, p14); FIZReader *FIZPort; DigitalOut led1(LED1); @@ -139,6 +139,7 @@ Timeout PPSsyncTimer; Timeout OutputDelayTimer; +Timeout UDPOutputDelayTimer; // used to generate PPS edges Ticker PPSOutputTimer; @@ -357,11 +358,11 @@ void sendFreeDpacketSerial() { -#ifdef Delay_TX_By - OutputDelayTimer.attach_us(&onOutputTxTime,Delay_TX_By*1000); -#else - onOutputTxTime();// COM1.write(&packetOut, sizeof(struct outputFormat_s)); -#endif + if (UserSettings.SerialTxDelayMS > 0) + OutputDelayTimer.attach_us(&onOutputTxTime,UserSettings.SerialTxDelayMS*1000); + else + onOutputTxTime();// COM1.write(&packetOut, sizeof(struct outputFormat_s)); + if (logging) { if (!fwrite(&fdPacket, sizeof(struct D1MsgFormat_s), 1, logFile)) { // write failed GreenLED = LED_OFF; @@ -373,14 +374,15 @@ } -void createVIPSPacket(position *posPtr) { - +void createVIPSPacket(position *posPtr) +{ + int byteCount = 4; uint32_t mask = 0x0446; // Status,orientation,accuracy,FIZ if (posPtr && UserSettings.FlexibleVIPSOut) { if (posPtr->UsedBeaconsValid) { mask |= 0x1000; - } + } if (posPtr->LLAPosition) mask |= 0x0001; } @@ -431,17 +433,17 @@ VIPSOutSize = byteCount+2; *((uint16_t*)(FlexibleVIPSOut + 2)) = VIPSOutSize; - VIPSSerial::getCRC(FlexibleVIPSOut, byteCount, (void *)(FlexibleVIPSOut+byteCount)); - } + VIPSSerial::getCRC(FlexibleVIPSOut, byteCount, (void *)(FlexibleVIPSOut+byteCount)); +} void sendVIPSPacketSerial() { -#ifdef Delay_TX_By - OutputDelayTimer.attach_us(&onOutputTxTime,Delay_TX_By*1000); -#else - onOutputTxTime();// COM1.write(&packetOut, sizeof(struct outputFormat_s)); -#endif + if (UserSettings.SerialTxDelayMS > 0) + OutputDelayTimer.attach_us(&onOutputTxTime,UserSettings.SerialTxDelayMS*1000); + else + onOutputTxTime();// COM1.write(&packetOut, sizeof(struct outputFormat_s)); + if (logging) { if (!fwrite(FlexibleVIPSOut, VIPSOutSize, 1, logFile)) { // write failed GreenLED = LED_OFF; @@ -468,6 +470,15 @@ } else NoDataWarn= true; + if (posPtr) { + if(UserSettings.InvertRoll) + posPtr->roll = 360-posPtr->roll; + if(UserSettings.InvertPitch) + posPtr->pitch = 360-posPtr->pitch; + if(UserSettings.InvertYaw) + posPtr->yaw = 360-posPtr->yaw; + } + // FreeD could be output by two different methods so calculate first if needed rather than at Tx. if ((UserSettings.SerialOutMode==mode_FreeD) || UserSettings.FreeDPort) @@ -479,8 +490,10 @@ // Network is faster so send that first. if (UserSettings.FreeDPort || UserSettings.VipsUDPPort) { - //ALSO ADD VARIABLE DELAY HERE - UDP_Tx_Now(); + if (UserSettings.UDPTxDelayMS > 0) { + UDPOutputDelayTimer.attach_us(&UDP_Tx_Now,UserSettings.UDPTxDelayMS*1000); + } else + UDP_Tx_Now(); } switch (UserSettings.SerialOutMode) { @@ -612,6 +625,18 @@ UserSettings.FilterYaw = false; UserSettings.AutoHyperSmooth = true; UserSettings.FlexibleVIPSOut = false; +<<<<<<< working copy +======= + UserSettings.SerialTxDelayMS = 0; + UserSettings.UDPTxDelayMS = 0; + UserSettings.SerialTxDelayFrame = 0; + UserSettings.UDPTxDelayFrame = 0; + UserSettings.InvertRoll = false; + UserSettings.InvertPitch = false; + UserSettings.InvertYaw = false; + UserSettings.bypassBaud = 0; + +>>>>>>> merge rev LocalFileSystem localFS("local"); FILE *LSFile= fopen("/local/settings.txt","r"); @@ -619,8 +644,13 @@ int valueIn; float floatIn; if (LSFile) { - while (!feof(LSFile)) { + while (!feof(LSFile) && !UserSettings.bypassBaud) { if (fgets(lineBuffer, 64, LSFile)) { + if (sscanf(lineBuffer,"RadioConfigPassthrough=%d",&valueIn) == 1) { + pc.printf("Switching to RADIO/USB bypass mode at %d baud\r\n",valueIn); + UserSettings.bypassBaud = valueIn; + } + if (sscanf(lineBuffer,"Output_Format=%d",&valueIn) == 1) { pc.printf("Got Output_Format value from file of %d\r\n",valueIn); UserSettings.SerialOutMode = valueIn; @@ -685,6 +715,34 @@ if (sscanf(lineBuffer,"ExtendedOutput=%d",&valueIn) == 1) { pc.printf("Got ExtendedOutput value from file of %d\r\n",valueIn); } + if (sscanf(lineBuffer,"DelaySerial=%f",&floatIn) == 1) { + pc.printf("Got serial delay value from file of %.2f ms\r\n",floatIn); + UserSettings.SerialTxDelayMS = floatIn; + } + if (sscanf(lineBuffer,"DelaySerialFrame=%f",&floatIn) == 1) { + pc.printf("Got serial delay value from file of %.2f frames\r\n",floatIn); + UserSettings.SerialTxDelayFrame = floatIn; + } + if (sscanf(lineBuffer,"DelayUDP=%f",&floatIn) == 1) { + pc.printf("Got UDP delay value from file of %.2f ms\r\n",floatIn); + UserSettings.UDPTxDelayMS = floatIn; + } + if (sscanf(lineBuffer,"DelayUDPFrame=%f",&floatIn) == 1) { + pc.printf("Got UDP delay value from file of %.2f frames\r\n",floatIn); + UserSettings.UDPTxDelayFrame = floatIn; + } + if (sscanf(lineBuffer,"InvertRoll=%d",&valueIn) == 1) { + pc.printf("Got InvertRoll value from file of %d\r\n",valueIn); + UserSettings.InvertRoll = (valueIn==1); + } + if (sscanf(lineBuffer,"InvertPitch=%d",&valueIn) == 1) { + pc.printf("Got InvertPitch value from file of %d\r\n",valueIn); + UserSettings.InvertPitch = (valueIn==1); + } + if (sscanf(lineBuffer,"InvertYaw=%d",&valueIn) == 1) { + pc.printf("Got InvertYaw value from file of %d\r\n",valueIn); + UserSettings.InvertYaw = (valueIn==1); + } } } fclose(LSFile); @@ -712,7 +770,7 @@ } int Result = -1; while (Result != 0) { - if ((UserSettings.IPAddress[0] != 0) && (UserSettings.Gateway[0] != 0) && (UserSettings.Subnet[0] != 0)) { + if ((UserSettings.IPAddress[0] != 0) && (UserSettings.Gateway[0] != 0) && (UserSettings.Subnet[0] != 0)) { pc.puts("Static IP init attempt\r\n"); Result = eth.init(UserSettings.IPAddress, UserSettings.Subnet, UserSettings.Gateway); } else { @@ -729,8 +787,8 @@ while (true) { - Result = -1; - while (Result != 0) { + Result = -1; + while (Result != 0) { Result = eth.connect(); if (Result) { pc.puts("Ethernet connect failed\r\n"); @@ -792,6 +850,59 @@ } +void XBEEBypassmode(int baud) +{ + pc.baud(baud); + +/* + COM1.baud(9600); + COM1.puts("+++"); + wait(1.2); + switch (baud) { + case 1200: + COM1.puts("ATBD0\n"); + break; + case 2400: + COM1.puts("ATBD1\n"); + break; + case 4800: + COM1.puts("ATBD2\n"); + break; + case 9600: + COM1.puts("ATBD3\n"); + break; + case 19200: + COM1.puts("ATBD4\n"); + break; + case 38400: + COM1.puts("ATBD5\n"); + break; + case 57600: + COM1.puts("ATBD6\n"); + break; + case 115200: + COM1.puts("ATBD7\n"); + break; + default: + COM1.printf("ATBD%d\n",baud); + break; + } + + wait(0.1); + COM1.puts("ATCN\n"); + wait(0.5); +*/ + + COM1.baud(baud); + while (true) { + if (pc.readable()) { + char commandIn = pc.getc(); + COM1.putc(commandIn); + } + if (COM1.readable()) + pc.putc(COM1.getc()); + } +} int main() { @@ -801,6 +912,10 @@ readSettingsFile(); + if (UserSettings.bypassBaud) { + XBEEBypassmode(UserSettings.bypassBaud); + } + switch(UserSettings.FIZmode) { case formatPreston : FIZPort = new FIZDisney(p9, p10); @@ -823,7 +938,7 @@ pc.printf("Set Default - Preston"); } // FIZPort = new FIZDigiPowerActive(p9, p10); - COM1.baud(115200); // VIPS port + COM1.baud(115200); // radio port Thread serialTask(ethernetTask, &UserSettings, osPriorityNormal, 256 * 4); @@ -894,6 +1009,14 @@ int framesPerSecond = frameRates::getClosestRate(frameTime); pc.printf("Detected frame rate %d\r\n",framesPerSecond); + if (UserSettings.SerialTxDelayFrame != 0) { + UserSettings.SerialTxDelayMS = (UserSettings.SerialTxDelayFrame*1000)/framesPerSecond; + pc.printf("Serial delay of %.2f frames calculated as %.2f ms\r\n",UserSettings.SerialTxDelayFrame,UserSettings.SerialTxDelayMS); + } + if (UserSettings.UDPTxDelayFrame != 0) { + UserSettings.UDPTxDelayMS = (UserSettings.UDPTxDelayFrame*1000)/framesPerSecond; + pc.printf("Serial delay of %.2f frames calculated as %.2f ms\r\n",UserSettings.UDPTxDelayFrame,UserSettings.UDPTxDelayMS); + } if (LTCInput.synced()) { // getting LTC so set the clock. currentFrames = framesIn;
--- a/settings.txt Wed Aug 25 17:02:47 2021 +0000 +++ b/settings.txt Wed Aug 25 17:20:10 2021 +0000 @@ -1,3 +1,12 @@ +[Radio configuration mode] + # RadioConfigPassthrough=<baud rate> + # If this option is set then normal FIZ box functionality is disabled. + # The system will instead transparently connect the USB COM port to the radio com port + # Both ports will be set to the baud rate specified. + # When used this option should be first in the options file. +//RadioConfigPassthrough=115200 + + [Serial Output Format] # Sets the serial output format. # 0 = VIPS (Default) @@ -63,7 +72,32 @@ # Currently supported fields are: # Used Beacon List (mask value 0x1000) //ExtendedOutput=1 + + +# By default the FIZ output is sent as soon as possible after the sync pulse. +# An optional delay can be added to this to either as time or as a proportion of a frame +# If both ms and frame delays are set then the frame one will be used. +# NOTE: UDP output has an aditional jitter/delay of up to 2ms due to the thread sleep times. +# BIG FLASHING NOTE IN BOLD: No additional buffering is provided so if delay is sufficently large +# that the transmit doesn't complete until after the next frame starts +# then the message will get corrupted. +# Delay the serial by a fixed number of ms +//DelaySerial=5.2 +# Delay the serial by a fraction of a frame +//DelaySerialFrame=0.3 +# Delay the serial by a fixed number of ms +//DelayUDP=5.2 +# Delay the serial by a fraction of a frame +//DelayUDPFrame=0.3 + + +# Orientation control +# These options allow the direction of the orientation channels to be inverted. +//InvertRoll=1 +//InvertPitch=1 +//InvertYaw=1 + [NOTES] - All settings are case sensitive. - Do NOT include spaces in the options lines.