ソースを参照

fixed web server status web operator location is lost

fixes #54
Andrew Tridgell 3 年 前
コミット
c23905a1e2
3 ファイル変更31 行追加20 行削除
  1. 23 18
      RemoteIDModule/RemoteIDModule.ino
  2. 7 1
      RemoteIDModule/status.cpp
  3. 1 1
      RemoteIDModule/web/index.html

+ 23 - 18
RemoteIDModule/RemoteIDModule.ino

@@ -41,6 +41,7 @@ static BLE_TX ble;
 
 // OpenDroneID output data structure
 ODID_UAS_Data UAS_data;
+String status_reason;
 static uint32_t last_location_ms;
 static WebInterface webif;
 
@@ -304,10 +305,6 @@ void loop()
 
     const uint32_t now_ms = millis();
 
-    if (g.webserver_enable) {
-        webif.update();
-    }
-
     // the transports have common static data, so we can just use the
     // first for status
 #if AP_MAVLINK_ENABLED
@@ -324,6 +321,28 @@ void loop()
 
     led.update();
 
+    status_reason = "";
+
+    if (last_location_ms == 0 ||
+        now_ms - last_location_ms > 5000) {
+        UAS_data.Location.Status = ODID_STATUS_REMOTE_ID_SYSTEM_FAILURE;
+    }
+
+    if (last_system_ms == 0 ||
+        now_ms - last_system_ms > 5000) {
+        UAS_data.Location.Status = ODID_STATUS_REMOTE_ID_SYSTEM_FAILURE;
+    }
+
+    if (transport.get_parse_fail() != nullptr) {
+        UAS_data.Location.Status = ODID_STATUS_REMOTE_ID_SYSTEM_FAILURE;
+        status_reason = String(transport.get_parse_fail());
+    }
+
+    // web update has to happen after we update Status above
+    if (g.webserver_enable) {
+        webif.update();
+    }
+
     if (g.bcast_powerup) {
         // if we are broadcasting on powerup we always mark location valid
         // so the location with default data is sent
@@ -339,20 +358,6 @@ void loop()
         }
     }
 
-    if (last_location_ms == 0 ||
-        now_ms - last_location_ms > 5000) {
-        UAS_data.Location.Status = ODID_STATUS_REMOTE_ID_SYSTEM_FAILURE;
-    }
-
-    if (last_system_ms == 0 ||
-        now_ms - last_system_ms > 5000) {
-        UAS_data.Location.Status = ODID_STATUS_REMOTE_ID_SYSTEM_FAILURE;
-    }
-
-    if (transport.get_parse_fail() != nullptr) {
-        UAS_data.Location.Status = ODID_STATUS_REMOTE_ID_SYSTEM_FAILURE;
-    }
-    
     set_data(transport);
 
     static uint32_t last_update_wifi_nan_ms;

+ 7 - 1
RemoteIDModule/status.cpp

@@ -9,6 +9,7 @@
 #include "util.h"
 
 extern ODID_UAS_Data UAS_data;
+extern String status_reason;
 
 typedef struct {
     String name;
@@ -229,6 +230,10 @@ String status_json(void)
     snprintf(minsec_str, sizeof(minsec_str), "%02d:%02d", min, sec);
     char githash[20];
     snprintf(githash, sizeof(githash), "(%08x)", GIT_VERSION);
+    String reason = "";
+    if (status_reason != nullptr && status_reason.length() > 0) {
+        reason = "(" + status_reason + ")";
+    }
     const json_table_t table[] = {
         { "STATUS:VERSION", String(FW_VERSION_MAJOR) + "." + String(FW_VERSION_MINOR) + " " + githash},
         { "STATUS:BOARD_ID", String(BOARD_ID)},
@@ -256,7 +261,8 @@ String status_json(void)
         { "SYSTEM:ClassEU", ENUM_MAP(classeu, UAS_data.System.ClassEU) },
         { "SYSTEM:OperatorAltitudeGeo", AltString(UAS_data.System.OperatorAltitudeGeo) },
         { "SYSTEM:Timestamp", String(UAS_data.System.Timestamp) },
-        { "LOCATION:Status", ENUM_MAP(status, UAS_data.Location.Status) },
+        { "LOCATION:Status", ENUM_MAP(status, UAS_data.Location.Status)},
+        { "LOCATION:StatusReason", reason },
         { "LOCATION:Direction", String(UAS_data.Location.Direction) },
         { "LOCATION:SpeedHorizontal", String(UAS_data.Location.SpeedHorizontal) },
         { "LOCATION:SpeedVertical", String(UAS_data.Location.SpeedVertical) },

+ 1 - 1
RemoteIDModule/web/index.html

@@ -76,7 +76,7 @@
   <fieldset>
     <legend>Location</legend>
     <table class="values">
-      <tr><td>Status</td><td><div id="LOCATION:Status"></div><td></tr>
+      <tr><td>Status</td><td><div id="LOCATION:Status"></div><div id="LOCATION:StatusReason"></div><td></tr>
       <tr><td>Direction</td><td><div id="LOCATION:Direction"></div><td></tr>
       <tr><td>SpeedHorizontal</td><td><div id="LOCATION:SpeedHorizontal"></div><td></tr>
       <tr><td>SpeedVertical</td><td><div id="LOCATION:SpeedVertical"></div><td></tr>