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

Files at this revision

API Documentation at this revision

Comitter:
AndyA
Date:
Tue Aug 17 14:52:50 2021 +0000
Parent:
45:03d255642704
Parent:
42:9653486372a6
Child:
48:475b3c5f5707
Commit message:
0.14 - Merge (and bug fix) flexible output. Allow independent UDP port enables

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
position.cpp Show annotated file Show diff for this revision Revisions of this file
settings.txt Show annotated file Show diff for this revision Revisions of this file
--- a/LTCApp.h	Thu Aug 12 11:31:31 2021 +0000
+++ b/LTCApp.h	Tue Aug 17 14:52:50 2021 +0000
@@ -30,7 +30,8 @@
 typedef struct UserSettings_s {
     int FIZmode;
     int SerialOutMode;
-    int UDPPort;
+    int FreeDPort;
+    int VipsUDPPort;
     char IPAddress[32];
     char Gateway[32];
     char Subnet[32];
--- a/main.cpp	Thu Aug 12 11:31:31 2021 +0000
+++ b/main.cpp	Tue Aug 17 14:52:50 2021 +0000
@@ -1,4 +1,4 @@
-#define APP_VERSION 0.12
+#define APP_VERSION 0.14
 
 /*
 Settings file options
@@ -26,6 +26,9 @@
     Data is sent as a UDP broadcast on the select port number.
     A port number of 0 disables UDP output.
 
+VIPS_UDP_Port=pppp
+    Same As Above
+
 IP_addr=aaa.bbb.ccc.ddd
 Subnet=aaa.bbb.ccc.ddd
 Gateway=aaa.bbb.ccc.ddd
@@ -375,8 +378,9 @@
     int byteCount = 4;
     uint32_t mask = 0x0446; // Status,orientation,accuracy,FIZ
     if (posPtr && UserSettings.FlexibleVIPSOut) {
-        if (posPtr->UsedBeaconsValid)
+        if (posPtr->UsedBeaconsValid) {
             mask |= 0x1000;
+            }
         if (posPtr->LLAPosition)
             mask |= 0x0001;
     }
@@ -394,8 +398,8 @@
         byteCount +=8;
         *((float*)(FlexibleVIPSOut + byteCount)) = posPtr->Height;
         byteCount +=4;
-        FlexibleVIPSOut[  byteCount++] =   posPtr->beacons;
-        FlexibleVIPSOut[  byteCount++] =   posPtr->solutionType;
+        FlexibleVIPSOut[byteCount++] = posPtr->beacons;
+        FlexibleVIPSOut[byteCount++] = posPtr->solutionType;
         *((uint16_t*)(FlexibleVIPSOut + byteCount)) = posPtr->KFStatus;
         byteCount +=2;
         *((float*)(FlexibleVIPSOut + byteCount)) = posPtr->roll;
@@ -410,16 +414,18 @@
         byteCount += blankBytes;
     }
 
-    FlexibleVIPSOut[  byteCount++] = 0;
-    FlexibleVIPSOut[  byteCount++] = 0;
-    FlexibleVIPSOut[  byteCount++] = 0;
-    FlexibleVIPSOut[  byteCount++] = posPtr?posPtr->ID:0;
+    FlexibleVIPSOut[byteCount++] = 0;
+    FlexibleVIPSOut[byteCount++] = 0;
+    FlexibleVIPSOut[byteCount++] = 0;
+    FlexibleVIPSOut[byteCount++] = posPtr?posPtr->ID:0;
 
     FIZPort->getMostRecent((uint32_t*)(FlexibleVIPSOut + byteCount), (uint16_t*)(FlexibleVIPSOut + byteCount+4), (uint16_t*)(FlexibleVIPSOut + byteCount+6));
     byteCount+=8;
 
-    if (mask | 0x1000) // pos must be valid for this to be set
+    if (mask | 0x1000) { // pos must be valid for this to be set
         memcpy(FlexibleVIPSOut + byteCount,posPtr->UsedBeacons,12);
+        byteCount+=12;
+    }
 
     // set length to current size plus checksum.
     VIPSOutSize = byteCount+2;
@@ -428,12 +434,12 @@
     VIPSSerial::getCRC(FlexibleVIPSOut, byteCount, (void *)(FlexibleVIPSOut+byteCount));
 
     if (posPtr && (posPtr->KFStatus < 0x200)) {
-            led2 = 0;
-            RedLED = LED_ON;
-        } else {
-            led2 = 1;
-            RedLED = LED_OFF;
-        }
+        led2 = 0;
+        RedLED = LED_ON;
+    } else {
+        led2 = 1;
+        RedLED = LED_OFF;
+    }
 
 #ifdef Delay_TX_By
     OutputDelayTimer.attach_us(&onOutputTxTime,Delay_TX_By*1000);
@@ -450,7 +456,7 @@
     }
 }
 
-void UDPTxFreeD()
+void UDP_Tx_Now()
 {
     EthTxNow = true;
 }
@@ -468,12 +474,13 @@
 
 
 // FreeD could be output by two different methods so calculate first if needed rather than at Tx.
-    if ((UserSettings.SerialOutMode==mode_FreeD) || UserSettings.UDPPort)
+    if ((UserSettings.SerialOutMode==mode_FreeD) || UserSettings.FreeDPort)
         createFreeDPacket(posPtr);
 
 // Network is faster so send that first.
-    if (UserSettings.UDPPort) {
-        UDPTxFreeD();
+    if (UserSettings.FreeDPort || UserSettings.VipsUDPPort) {
+        //ALSO ADD VARIABLE DELAY HERE
+        UDP_Tx_Now();
     }
 
     switch (UserSettings.SerialOutMode) {
@@ -581,7 +588,8 @@
 
     UserSettings.FIZmode = formatPreston;
     UserSettings.SerialOutMode = mode_VIPS;
-    UserSettings.UDPPort = 0;
+    UserSettings.FreeDPort = 0;
+    UserSettings.VipsUDPPort = 0;
     UserSettings.IPAddress[0] = 0;
     UserSettings.Gateway[0] = 0;
     UserSettings.Subnet[0] = 0;
@@ -612,7 +620,11 @@
                 }
                 if (sscanf(lineBuffer,"FreeD_Port=%d",&valueIn) == 1) {
                     pc.printf("Got FreeD_Port value from file of %d\r\n",valueIn);
-                    UserSettings.UDPPort = valueIn;
+                    UserSettings.FreeDPort = valueIn;
+                }
+                if (sscanf(lineBuffer,"VIPS_UDP_Port=%d",&valueIn) == 1) {
+                    pc.printf("Got VIPS_Port value from file of %d\r\n",valueIn);
+                    UserSettings.VipsUDPPort = valueIn;
                 }
                 if (sscanf(lineBuffer,"IP_addr=%s",UserSettings.IPAddress) == 1) {
                     pc.printf("Got IP_addr value from file of %s\r\n",UserSettings.IPAddress);
@@ -674,16 +686,19 @@
     UDPSocket* FreeDSocket = NULL;
     Endpoint FreeDTarget;
 
+    UDPSocket* VIPSSocket = NULL;
+    Endpoint VIPSTarget;
+
     UserSettings_t *settingsPtr = (UserSettings_t *) settings;
 
     pc.puts("Ethernet task startup\r\n");
-    if (!settingsPtr->UDPPort) {
+    if (!settingsPtr->FreeDPort && !settingsPtr->VipsUDPPort) {
         pc.puts("No UDP port set. Ethernet task exiting\r\n");
         return;
     }
     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 {
@@ -700,8 +715,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");
@@ -712,22 +727,45 @@
 
         if (FreeDSocket)
             delete FreeDSocket;
-        FreeDSocket = new UDPSocket();
-        FreeDSocket->init();
-        FreeDSocket->set_broadcasting(true);
-        FreeDTarget.set_address(0xFFFFFFFF, UserSettings.UDPPort);
+        if (UserSettings.FreeDPort) {
+            FreeDSocket = new UDPSocket();
+            FreeDSocket->init();
+            FreeDSocket->set_broadcasting(true);
+            FreeDTarget.set_address(0xFFFFFFFF, UserSettings.FreeDPort);
+        }
 
+        if (VIPSSocket)
+            delete VIPSSocket;
+        if (UserSettings.VipsUDPPort) {
+            VIPSSocket = new UDPSocket();
+            VIPSSocket->init();
+            VIPSSocket->set_broadcasting(true);
+            VIPSTarget.set_address(0xFFFFFFFF, UserSettings.VipsUDPPort);
+        }
         while (true) {
             if (EthTxNow) {
                 EthTxNow = false;
-                if (!FreeDSocket) {
-                    pc.puts("No UDP socket\r\n");
+                if (!FreeDSocket && UserSettings.FreeDPort) {
+                    pc.puts("No FreeD UDP socket\r\n");
+                    break;
+                }
+                if (!VIPSSocket && UserSettings.VipsUDPPort) {
+                    pc.puts("No VIPS UDP socket\r\n");
                     break;
                 }
-                Result = FreeDSocket->sendTo(FreeDTarget,(char *)&fdPacket, sizeof(struct D1MsgFormat_s));
-                if (Result != sizeof(struct D1MsgFormat_s)) {
-                    pc.puts("UDP Tx Failed!\r\n");
-                    break;
+                if (FreeDSocket) {
+                    Result = FreeDSocket->sendTo(FreeDTarget,(char *)&fdPacket, sizeof(struct D1MsgFormat_s));
+                    if (Result != sizeof(struct D1MsgFormat_s)) {
+                        pc.puts("FreeD UDP Tx Failed!\r\n");
+                        break;
+                    }
+                }
+                if (VIPSSocket) {
+                    Result = VIPSSocket->sendTo(VIPSTarget,(char *)FlexibleVIPSOut, VIPSOutSize);
+                    if (Result != VIPSOutSize) {
+                        pc.puts("VIPS UDP Tx Failed!\r\n");
+                        break;
+                    }
                 }
 //                pc.puts("UDP Tx\r\n");
             } else
--- a/position.cpp	Thu Aug 12 11:31:31 2021 +0000
+++ b/position.cpp	Tue Aug 17 14:52:50 2021 +0000
@@ -76,7 +76,9 @@
     output->beacons = pos1->beacons;
     output->solutionType = pos1->solutionType;
     output->KFStatus = pos1->KFStatus;
-    memcpy(output->UsedBeacons,pos1->UsedBeacons,12);
+    output->UsedBeaconsValid = pos1->UsedBeaconsValid;
+    if (output->UsedBeaconsValid)
+        memcpy(output->UsedBeacons,pos1->UsedBeacons,12);
 
     return true;
 }
--- a/settings.txt	Thu Aug 12 11:31:31 2021 +0000
+++ b/settings.txt	Tue Aug 17 14:52:50 2021 +0000
@@ -22,6 +22,7 @@
 # A port number of 0 disables UDP output.
 --------------------------------
 FreeD_Port=12345
+VIPS_UDP_Port=7000
 --------------------------------
  
 [Network Settings]