httpinfo: add position information tab
[olsrd.git] / lib / httpinfo / src / olsrd_httpinfo.c
index 9965ed6..9dc7b3a 100644 (file)
@@ -63,6 +63,9 @@
 #include "ipcalc.h"
 #include "lq_plugin.h"
 #include "common/autobuf.h"
+#ifdef HTTPINFO_PUD
+  #include <pud/src/pud.h>
+#endif
 
 #include "olsrd_httpinfo.h"
 #include "admin_interface.h"
@@ -178,6 +181,10 @@ static void build_nodes_body(struct autobuf *);
 
 static void build_all_body(struct autobuf *);
 
+#ifdef HTTPINFO_PUD
+static void build_pud_body(struct autobuf *);
+#endif
+
 static void build_about_body(struct autobuf *);
 
 static void build_cfgfile_body(struct autobuf *);
@@ -216,6 +223,9 @@ static const struct tab_entry tab_entries[] = {
   {"Configuration", "config", build_config_body, true},
   {"Routes", "routes", build_routes_body, true},
   {"Links/Topology", "nodes", build_nodes_body, true},
+#ifdef HTTPINFO_PUD
+  {"Position", "position", build_pud_body, true},
+#endif
   {"All", "all", build_all_body, true},
 #ifdef ADMIN_INTERFACE
   {"Admin", "admin", build_admin_body, true},
@@ -1089,6 +1099,202 @@ build_all_body(struct autobuf *abuf)
   build_mid_body(abuf);
 }
 
+#ifdef HTTPINFO_PUD
+static void build_pud_body(struct autobuf *abuf) {
+       TransmitGpsInformation * txGpsInfo = olsr_cnf->pud_position;
+       char * nodeId = (char *) txGpsInfo->nodeId;
+       char nodeIdString[1024];
+
+       if (!txGpsInfo) {
+               abuf_puts(abuf, "<h2>" PUD_PLUGIN_ABBR " plugin not loaded</h2>\n");
+               return;
+       }
+
+       if (!txGpsInfo->nodeId || !strlen((char *) txGpsInfo->nodeId)) {
+               inet_ntop(olsr_cnf->ip_version, &olsr_cnf->main_addr, &nodeIdString[0], sizeof(nodeIdString));
+               nodeId = nodeIdString;
+       }
+
+       /* start of table */
+       abuf_appendf(abuf,
+               "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n"
+               "<tr><th>Parameter</th><th>&nbsp;&nbsp;</th><th>Unit</th><th>&nbsp;&nbsp;</th><th>Value</th></tr>\n"
+               "<tr><td>Name</td><td></td><td></td><td></td><td id=\"nodeId\">%s</td>\n",
+               nodeId
+       );
+
+       abuf_puts(abuf, "<tr><td>Date / Time</td><td></td><td>UTC</td><td></td><td id=\"utc\">");
+       if (nmea_INFO_has_field(txGpsInfo->txPosition.nmeaInfo.smask, UTC)) {
+               abuf_appendf(abuf, "%04d%02d%02d %02d:%02d:%02d.%02d",
+                       txGpsInfo->txPosition.nmeaInfo.utc.year + 1900,
+                       txGpsInfo->txPosition.nmeaInfo.utc.mon,
+                       txGpsInfo->txPosition.nmeaInfo.utc.day,
+                       txGpsInfo->txPosition.nmeaInfo.utc.hour,
+                       txGpsInfo->txPosition.nmeaInfo.utc.min,
+                       txGpsInfo->txPosition.nmeaInfo.utc.sec,
+                       txGpsInfo->txPosition.nmeaInfo.utc.hsec
+               );
+       } else {
+               abuf_puts(abuf, "N.A.");
+       }
+       abuf_puts(abuf, "</td>\n");
+
+       abuf_puts(abuf, "<tr><td>Signal Strength</td><td></td><td></td><td></td><td id=\"sig\">");
+       if (nmea_INFO_has_field(txGpsInfo->txPosition.nmeaInfo.smask, SIG)) {
+               const char * s;
+               switch (txGpsInfo->txPosition.nmeaInfo.sig) {
+                       case NMEA_SIG_BAD:
+                               s = "BAD";
+                               break;
+                       case NMEA_SIG_LOW:
+                               s = "LOW";
+                               break;
+                       case NMEA_SIG_MID:
+                               s = "MID";
+                               break;
+                       case NMEA_SIG_HIGH:
+                               s = "HIGH";
+                               break;
+                       default:
+                               s = "Unknown";
+                               break;
+               }
+               abuf_appendf(abuf, "%s (%d)", s, txGpsInfo->txPosition.nmeaInfo.sig);
+       } else {
+               abuf_puts(abuf, "N.A.");
+       }
+       abuf_puts(abuf, "</td>\n");
+
+       abuf_puts(abuf, "<tr><td>Fix</td><td></td><td></td><td></td><td id=\"fix\">");
+       if (nmea_INFO_has_field(txGpsInfo->txPosition.nmeaInfo.smask, FIX)) {
+               const char * s;
+               switch (txGpsInfo->txPosition.nmeaInfo.fix) {
+                       case NMEA_FIX_BAD:
+                               s = "BAD";
+                               break;
+                       case NMEA_FIX_2D:
+                               s = "2D";
+                               break;
+                       case NMEA_FIX_3D:
+                               s = "3D";
+                               break;
+                       default:
+                               s = "Unknown";
+                               break;
+               }
+               abuf_appendf(abuf, "%s (%d)", s, txGpsInfo->txPosition.nmeaInfo.fix);
+       } else {
+               abuf_puts(abuf, "N.A.");
+       }
+       abuf_puts(abuf, "</td>\n");
+
+       abuf_puts(abuf, "<tr><td>PDOP</td><td></td><td></td><td></td><td id=\"pdop\">");
+       if (nmea_INFO_has_field(txGpsInfo->txPosition.nmeaInfo.smask, PDOP)) {
+               abuf_appendf(abuf, "%f", txGpsInfo->txPosition.nmeaInfo.PDOP);
+       } else {
+               abuf_puts(abuf, "N.A.");
+       }
+       abuf_puts(abuf, "</td>\n");
+
+       abuf_puts(abuf, "<tr><td>HDOP</td><td></td><td></td><td></td><td id=\"hdop\">");
+       if (nmea_INFO_has_field(txGpsInfo->txPosition.nmeaInfo.smask, HDOP)) {
+               abuf_appendf(abuf, "%f", txGpsInfo->txPosition.nmeaInfo.HDOP);
+       } else {
+               abuf_puts(abuf, "N.A.");
+       }
+       abuf_puts(abuf, "</td>\n");
+
+       abuf_puts(abuf, "<tr><td>VDOP</td><td></td><td></td><td></td><td id=\"vdop\">");
+       if (nmea_INFO_has_field(txGpsInfo->txPosition.nmeaInfo.smask, VDOP)) {
+               abuf_appendf(abuf, "%f", txGpsInfo->txPosition.nmeaInfo.VDOP);
+       } else {
+               abuf_puts(abuf, "N.A.");
+       }
+       abuf_puts(abuf, "</td>\n");
+
+       abuf_puts(abuf, "<tr><td>Latitude</td><td></td><td>degrees</td><td></td><td id=\"lat\">");
+       if (nmea_INFO_has_field(txGpsInfo->txPosition.nmeaInfo.smask, LAT)) {
+               abuf_appendf(abuf, "%f", txGpsInfo->txPosition.nmeaInfo.lat);
+       } else {
+               abuf_puts(abuf, "N.A.");
+       }
+       abuf_puts(abuf, "</td>\n");
+
+       abuf_puts(abuf, "<tr><td>Longitude</td><td></td><td>degrees</td><td></td><td id=\"lon\">");
+       if (nmea_INFO_has_field(txGpsInfo->txPosition.nmeaInfo.smask, LON)) {
+               abuf_appendf(abuf, "%f", txGpsInfo->txPosition.nmeaInfo.lon);
+       } else {
+               abuf_puts(abuf, "N.A.");
+       }
+       abuf_puts(abuf, "</td>\n");
+
+       abuf_puts(abuf, "<tr><td>Elevation</td><td></td><td>m</td><td></td><td id=\"elv\">");
+       if (nmea_INFO_has_field(txGpsInfo->txPosition.nmeaInfo.smask, ELV)) {
+               abuf_appendf(abuf, "%f", txGpsInfo->txPosition.nmeaInfo.elv);
+       } else {
+               abuf_puts(abuf, "N.A.");
+       }
+       abuf_puts(abuf, "</td>\n");
+
+       abuf_puts(abuf, "<tr><td>Speed</td><td></td><td>kph</td><td></td><td id=\"speed\">");
+       if (nmea_INFO_has_field(txGpsInfo->txPosition.nmeaInfo.smask, SPEED)) {
+               abuf_appendf(abuf, "%f", txGpsInfo->txPosition.nmeaInfo.speed);
+       } else {
+               abuf_puts(abuf, "N.A.");
+       }
+       abuf_puts(abuf, "</td>\n");
+
+       abuf_puts(abuf, "<tr><td>Direction</td><td></td><td>degrees</td><td></td><td id=\"direction\">");
+       if (nmea_INFO_has_field(txGpsInfo->txPosition.nmeaInfo.smask, DIRECTION)) {
+               abuf_appendf(abuf, "%f", txGpsInfo->txPosition.nmeaInfo.direction);
+       } else {
+               abuf_puts(abuf, "N.A.");
+       }
+       abuf_puts(abuf, "</td>\n");
+
+       abuf_puts(abuf, "<tr><td>Declination</td><td></td><td>degrees</td><td></td><td id=\"declination\">");
+       if (nmea_INFO_has_field(txGpsInfo->txPosition.nmeaInfo.smask, DECLINATION)) {
+               abuf_appendf(abuf, "%f", txGpsInfo->txPosition.nmeaInfo.declination);
+       } else {
+               abuf_puts(abuf, "N.A.");
+       }
+       abuf_puts(abuf, "</td>\n");
+
+       /* end of table */
+       abuf_puts(abuf, "</table>\n");
+
+       if (nmea_INFO_has_field(txGpsInfo->txPosition.nmeaInfo.smask, LAT)
+                       && nmea_INFO_has_field(txGpsInfo->txPosition.nmeaInfo.smask, LON)) {
+               const char * c = nodeId;
+
+               abuf_appendf(abuf,
+                       "<p>\n"
+                       "<a href=\"http://maps.google.com/maps?q=%f,+%f+%%28",
+                       txGpsInfo->txPosition.nmeaInfo.lat,
+                       txGpsInfo->txPosition.nmeaInfo.lon
+               );
+
+               while (*c != '\0') {
+                       if (*c == ' ' || *c == '\t') {
+                               abuf_puts(abuf, "+");
+                       } else {
+                               abuf_appendf(abuf, "%c", *c);
+                       }
+                       c++;
+               }
+
+               abuf_puts(abuf, "%29&amp;iwloc=A\">Show on Google Maps</a></p>\n");
+
+               abuf_appendf(abuf,
+                       "<p>\n"
+                       "<a href=\"http://www.openstreetmap.org/index.html?mlat=%f&amp;mlon=%f&amp;zoom=14&amp;layers=M\">Show on OpenStreetMap</a></p>\n",
+                       txGpsInfo->txPosition.nmeaInfo.lat,
+                       txGpsInfo->txPosition.nmeaInfo.lon
+               );
+       }
+}
+#endif
+
 static void
 build_about_body(struct autobuf *abuf)
 {