Răsfoiți Sursa

fill in key packets

Andrew Tridgell 3 ani în urmă
părinte
comite
9e00fbd172

+ 75 - 0
RemoteIDModule/RemoteIDModule.ino

@@ -137,6 +137,81 @@ static const char *check_parse(void)
     return nullptr;
 }
 
+static String escape_string(String s)
+{
+    s.replace("\"", "");
+    return s;
+}
+
+/*
+  create a json string from a table
+ */
+static String json_format(const json_table_t *table, uint8_t n)
+{
+    String s = "{";
+    for (uint8_t i=0; i<n; i++) {
+        const auto &t = table[i];
+        s += "\"" + t.name + "\" : ";
+        s += "\"" + escape_string(t.value) + "\"";
+        if (i != n-1) {
+            s += ",";
+        }
+    }
+    s += "}";
+    return s;
+}
+
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
+
+String status_json(void)
+{
+    const uint32_t now_s = millis() / 1000;
+    const uint32_t sec = now_s % 60;
+    const uint32_t min = (now_s / 60) % 60;
+    const uint32_t hr = (now_s / 3600) % 24;
+    const json_table_t table[] = {
+        { "STATUS:VERSION", String(FW_VERSION_MAJOR) + "." + String(FW_VERSION_MINOR) },
+        { "STATUS:UPTIME", String(hr) + ":" + String(min) + ":" + String(sec) },
+        { "STATUS:FREEMEM", String(ESP.getFreeHeap()) },
+        { "BASICID:UAType", String(UAS_data.BasicID[0].UAType) },
+        { "BASICID:IDType", String(UAS_data.BasicID[0].IDType) },
+        { "BASICID:UASID", String(UAS_data.BasicID[0].UASID) },
+        { "OPERATORID:IDType", String(UAS_data.OperatorID.OperatorIdType) },
+        { "OPERATORID:ID", String(UAS_data.OperatorID.OperatorId) },
+        { "SELFID:DescType", String(UAS_data.SelfID.DescType) },
+        { "SELFID:Desc", String(UAS_data.SelfID.Desc) },
+        { "SYSTEM:OperatorLocationType", String(UAS_data.System.OperatorLocationType) },
+        { "SYSTEM:ClassificationType", String(UAS_data.System.ClassificationType) },
+        { "SYSTEM:OperatorLatitude", String(UAS_data.System.OperatorLatitude) },
+        { "SYSTEM:OperatorLongitude", String(UAS_data.System.OperatorLongitude) },
+        { "SYSTEM:AreaCount", String(UAS_data.System.AreaCount) },
+        { "SYSTEM:AreaRadius", String(UAS_data.System.AreaRadius) },
+        { "SYSTEM:AreaCeiling", String(UAS_data.System.AreaCeiling) },
+        { "SYSTEM:AreaFloor", String(UAS_data.System.AreaFloor) },
+        { "SYSTEM:CategoryEU", String(UAS_data.System.CategoryEU) },
+        { "SYSTEM:ClassEU", String(UAS_data.System.ClassEU) },
+        { "SYSTEM:OperatorAltitudeGeo", String(UAS_data.System.OperatorAltitudeGeo) },
+        { "SYSTEM:Timestamp", String(UAS_data.System.Timestamp) },
+        { "LOCATION:Status", String(UAS_data.Location.Status) },
+        { "LOCATION:Direction", String(UAS_data.Location.Direction) },
+        { "LOCATION:SpeedHorizontal", String(UAS_data.Location.SpeedHorizontal) },
+        { "LOCATION:SpeedVertical", String(UAS_data.Location.SpeedVertical) },
+        { "LOCATION:Latitude", String(UAS_data.Location.Latitude) },
+        { "LOCATION:Longitude", String(UAS_data.Location.Longitude) },
+        { "LOCATION:AltitudeBaro", String(UAS_data.Location.AltitudeBaro) },
+        { "LOCATION:AltitudeGeo", String(UAS_data.Location.AltitudeGeo) },
+        { "LOCATION:HeightType", String(UAS_data.Location.HeightType) },
+        { "LOCATION:Height", String(UAS_data.Location.Height) },
+        { "LOCATION:HorizAccuracy", String(UAS_data.Location.HorizAccuracy) },
+        { "LOCATION:VertAccuracy", String(UAS_data.Location.VertAccuracy) },
+        { "LOCATION:BaroAccuracy", String(UAS_data.Location.BaroAccuracy) },
+        { "LOCATION:SpeedAccuracy", String(UAS_data.Location.SpeedAccuracy) },
+        { "LOCATION:TSAccuracy", String(UAS_data.Location.TSAccuracy) },
+        { "LOCATION:TimeStamp", String(UAS_data.Location.TimeStamp) },
+    };
+    return json_format(table, ARRAY_SIZE(table));
+}
+
 /*
   fill in UAS_data from MAVLink packets
  */

+ 70 - 5
RemoteIDModule/web/index.html

@@ -11,16 +11,81 @@
 </head>
 
 <body>
+  <a href="/index.html"><img src="images/logo.jpg" alt="ArduPilot"></a></p>
   <h1>ArduRemoteID</h1>
 
   <h2>Status</h2>
 
-  <table class="values">
-    <tr><td>Version</td><td><div id="STATUS:VERSION"></div></td></tr>
-    <tr><td>Up Time</td><td><div id="STATUS:UPTIME"></div></td></tr>
-    <tr><td>Free Memory</td><td><div id="STATUS:FREEMEM"></div></td></tr>
-  </table>
+  <fieldset>
+    <legend>System</legend>
+    <table class="values">
+      <tr><td>Version</td><td><div id="STATUS:VERSION"></div></td></tr>
+      <tr><td>Up Time</td><td><div id="STATUS:UPTIME"></div></td></tr>
+      <tr><td>Free Memory</td><td><div id="STATUS:FREEMEM"></div></td></tr>
+    </table>
+  </fieldset>
+  <fieldset>
+    <legend>BasicID</legend>
+    <table class="values">
+      <tr><td>UAType</td><td><div id="BASICID:UAType"></div></td></tr>
+      <tr><td>IDType</td><td><div id="BASICID:IDType"></div></td></tr>
+      <tr><td>UASID</td><td><div id="BASICID:UASID"></div></td></tr>
+    </table>
+  </fieldset>
+  <fieldset>
+    <legend>OperatorID</legend>
+    <table class="values">
+      <tr><td>IDType</td><td><div id="OPERATORID:IDType"></div></td></tr>
+      <tr><td>ID</td><td><div id="OPERATORID:ID"></div></td></tr>
+    </table>
+  </fieldset>
+  <fieldset>
+    <legend>SelfID</legend>
+    <table class="values">
+      <tr><td>DescriptionType</td><td><div id="SELFID:DescType"></div></td></tr>
+      <tr><td>Description</td><td><div id="SELFID:Desc"></div></td></tr>
+    </table>
+  </fieldset>
+  <fieldset>
+    <legend>System</legend>
+    <table class="values">
+      <tr><td>OperatorLocationType</td><td><div id="SYSTEM:OperatorLocationType"></div></td></tr>
+      <tr><td>ClassificationType</td><td><div id="SYSTEM:ClassificationType"></div></td></tr>
+      <tr><td>OperatorLatitude</td><td><div id="SYSTEM:OperatorLatitude"></div></td></tr>
+      <tr><td>OperatorLongitude</td><td><div id="SYSTEM:OperatorLongitude"></div></td></tr>
+      <tr><td>AreaCount</td><td><div id="SYSTEM:AreaCount"></div></td></tr>
+      <tr><td>AreaRadius</td><td><div id="SYSTEM:AreaRadius"></div></td></tr>
+      <tr><td>AreaCeiling</td><td><div id="SYSTEM:AreaCeiling"></div></td></tr>
+      <tr><td>AreaFloor</td><td><div id="SYSTEM:AreaFloor"></div></td></tr>
+      <tr><td>CategoryEU</td><td><div id="SYSTEM:CategoryEU"></div></td></tr>
+      <tr><td>ClassEU</td><td><div id="SYSTEM:ClassEU"></div></td></tr>
+      <tr><td>OperatorAltitudeGeo</td><td><div id="SYSTEM:OperatorAltitudeGeo"></div></td></tr>
+      <tr><td>Timestamp</td><td><div id="SYSTEM:Timestamp"></div></td></tr>
+    </table>
+  </fieldset>
 
+  <fieldset>
+    <legend>Location</legend>
+    <table class="values">
+      <tr><td>Status</td><td><div id="LOCATION:Status"></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>
+      <tr><td>Latitude</td><td><div id="LOCATION:Latitude"></div><td></tr>
+      <tr><td>Longitude</td><td><div id="LOCATION:Longitude"></div><td></tr>
+      <tr><td>AltitudeBaro</td><td><div id="LOCATION:AltitudeBaro"></div><td></tr>
+      <tr><td>AltitudeGeo</td><td><div id="LOCATION:AltitudeGeo"></div><td></tr>
+      <tr><td>HeightType</td><td><div id="LOCATION:HeightType"></div><td></tr>
+      <tr><td>Height</td><td><div id="LOCATION:Height"></div><td></tr>
+      <tr><td>HorizAccuracy</td><td><div id="LOCATION:HorizAccuracy"></div><td></tr>
+      <tr><td>VertAccuracy</td><td><div id="LOCATION:VertAccuracy"></div><td></tr>
+      <tr><td>BaroAccuracy</td><td><div id="LOCATION:BaroAccuracy"></div><td></tr>
+      <tr><td>SpeedAccuracy</td><td><div id="LOCATION:SpeedAccuracy"></div><td></tr>
+      <tr><td>TSAccuracy</td><td><div id="LOCATION:TSAccuracy"></div><td></tr>
+      <tr><td>TimeStamp</td><td><div id="LOCATION:TimeStamp"></div><td></tr>
+    </table>
+  </fieldset>
+  
   <h2>Firmware Update</h2>
 
   <form method='POST' action='#' enctype='multipart/form-data' id='upload_form'>

+ 1 - 12
RemoteIDModule/web/styles/main.css

@@ -7,20 +7,9 @@ body {
 	margin:0px;
 	padding:0px;
 	background-color: #fff;
-    background-image: url(images/bg.jpg);
+    background-image: url(/images/bg.jpg);
 }
 
-#logo {
-    background-image:url(images/logo.jpg);
-	background-repeat:no-repeat;
-    height: 140px;
-	width: 407px;
-	-moz-box-shadow: 2px 2px 5px #888;
-	-webkit-box-shadow: 2px 2px 5px #888;
-	box-shadow: 2px 2px 5px #888;
-	background-color: #000;
-}
-  
 h2 {
 	text-shadow: #ccc 0px 1px 0px;
 	text-decoration:none;

+ 3 - 36
RemoteIDModule/webinterface.cpp

@@ -64,30 +64,7 @@ class ROMFS_Handler : public RequestHandler
 
 } ROMFS_Handler;
 
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
-
-typedef struct {
-    String name;
-    String value;
-} json_table_t;
-
-/*
-  create a json string from a table
- */
-static String json_format(const json_table_t *table, uint8_t n)
-{
-    String s = "{";
-    for (uint8_t i=0; i<n; i++) {
-        const auto &t = table[i];
-        s += "\"" + t.name + "\" : ";
-        s += "\"" + t.value + "\"";
-        if (i != n-1) {
-            s += ",";
-        }
-    }
-    s += "}";
-    return s;
-}
+extern String status_json(void);
 
 /*
   serve files from ROMFS
@@ -95,7 +72,6 @@ static String json_format(const json_table_t *table, uint8_t n)
 class AJAX_Handler : public RequestHandler
 {
     bool canHandle(HTTPMethod method, String uri) {
-        Serial.printf("ajax check '%s'", uri);
         return uri == "/ajax/status.json";
     }
 
@@ -103,16 +79,7 @@ class AJAX_Handler : public RequestHandler
         if (requestUri != "/ajax/status.json") {
             return false;
         }
-        const uint32_t now_s = millis() / 1000;
-        const uint32_t sec = now_s % 60;
-        const uint32_t min = (now_s / 60) % 60;
-        const uint32_t hr = (now_s / 3600) % 24;
-        const json_table_t table[] = {
-            { "STATUS:VERSION", String(FW_VERSION_MAJOR) + "." + String(FW_VERSION_MINOR) },
-            { "STATUS:UPTIME", String(hr) + ":" + String(min) + ":" + String(sec) },
-            { "STATUS:FREEMEM", String(ESP.getFreeHeap()) },
-        };
-        server.send(200, "application/json", json_format(table, ARRAY_SIZE(table)));
+        server.send(200, "application/json", status_json());
         return true;
     }
 
@@ -127,8 +94,8 @@ void WebInterface::init(void)
     WiFi.softAP(g.wifi_ssid, g.wifi_password);
     IPAddress myIP = WiFi.softAPIP();
 
-    server.addHandler( &ROMFS_Handler );
     server.addHandler( &AJAX_Handler );
+    server.addHandler( &ROMFS_Handler );
 
     /*handling uploading firmware file */
     server.on("/update", HTTP_POST, []() {

+ 5 - 0
RemoteIDModule/webinterface.h

@@ -7,6 +7,11 @@
 #include <Arduino.h>
 #include "version.h"
 
+typedef struct {
+    String name;
+    String value;
+} json_table_t;
+
 class WebInterface {
 public:
     void init(void);