[Olsr-dev] [PATCH v3 1/2] httpinfo: add position information tab

Ferry Huberts (spam-protected)
Thu May 24 09:43:49 CEST 2012



On 24-05-12 09:29, Ferry Huberts wrote:
> From: Ferry Huberts<(spam-protected)>
>
> When the PUD plugin is loaded, displays the position
> information obtained from the PUD plugin, otherwise
> no position information is shown.
>
> As the PUD plugin is only available on Linux, the tab
> is (also) only available on Linux.
>
> Signed-off-by: Ferry Huberts<(spam-protected)>
> ---
>
> In olsrd_httpinfo.c the HTTPINFO_PUD includes were updated, since the arpa
> include was not needed.
>
>   Makefile.inc                      |    4 +
>   lib/httpinfo/src/olsrd_httpinfo.c |  206 +++++++++++++++++++++++++++++++++++++
>   lib/pud/src/receiver.c            |   15 +--
>   lib/pud/src/receiver.h            |   10 ++
>   src/cfgparser/olsrd_conf.c        |    4 +
>   src/olsr_cfg.h                    |    7 ++
>   6 files changed, 237 insertions(+), 9 deletions(-)
>
> diff --git a/Makefile.inc b/Makefile.inc
> index d70578e..b45b4f7 100644
> --- a/Makefile.inc
> +++ b/Makefile.inc
> @@ -198,6 +198,10 @@ ifeq ($(NO_DEBUG_MESSAGES),1)
>   CPPFLAGS +=	-DNODEBUG
>   endif
>
> +ifeq ($(OS),linux)
> +CPPFLAGS+=-DHTTPINFO_PUD -I$(TOPDIR)/lib -I$(TOPDIR)/lib/pud/nmealib/include -I$(TOPDIR)/lib/pud/wireformat/include
> +endif
> +
>   # a make function to quote "/" and "."
>   quote = $(subst .,\.,$(subst /,\/,$1))
>
> diff --git a/lib/httpinfo/src/olsrd_httpinfo.c b/lib/httpinfo/src/olsrd_httpinfo.c
> index 9965ed6..9dc7b3a 100644
> --- a/lib/httpinfo/src/olsrd_httpinfo.c
> +++ b/lib/httpinfo/src/olsrd_httpinfo.c
> @@ -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;

I've already fixed the segfault here when PUD is not loaded by 
dereferencing txGpsInfo after the null check of it (just below)

damn code style of only allowing variable declarations at the beginning 
of blocks :-(

> +	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>  </th><th>Unit</th><th>  </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&iwloc=A\">Show on Google Maps</a></p>\n");
> +
> +		abuf_appendf(abuf,
> +			"<p>\n"
> +			"<a href=\"http://www.openstreetmap.org/index.html?mlat=%f&mlon=%f&zoom=14&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)
>   {
> diff --git a/lib/pud/src/receiver.c b/lib/pud/src/receiver.c
> index 827d8d5..8897cdf 100644
> --- a/lib/pud/src/receiver.c
> +++ b/lib/pud/src/receiver.c
> @@ -3,7 +3,6 @@
>   /* Plugin includes */
>   #include "pud.h"
>   #include "state.h"
> -#include "posAvg.h"
>   #include "configuration.h"
>   #include "gpsConversion.h"
>   #include "networkInterfaces.h"
> @@ -12,7 +11,6 @@
>   #include "posFile.h"
>
>   /* OLSRD includes */
> -#include "olsr_types.h"
>   #include "net_olsr.h"
>
>   /* System includes */
> @@ -66,13 +64,6 @@ typedef enum _TimedTxInterface {
>   	TX_INTERFACE_UPLINK = 2
>   } TimedTxInterface;
>
> -/** Structure of the latest GPS information that is transmitted */
> -typedef struct _TransmitGpsInformation {
> -	bool positionUpdated; /**<  true when the position information was updated */
> -	PositionUpdateEntry txPosition; /**<  The last transmitted position */
> -	union olsr_ip_addr txGateway; /**<  the best gateway */
> -} TransmitGpsInformation;
> -
>   /** The latest position information that is transmitted */
>   static TransmitGpsInformation transmitGpsInformation;
>
> @@ -762,7 +753,13 @@ bool startReceiver(void) {
>   	}
>   	transmitGpsInformation.txGateway = olsr_cnf->main_addr;
>   	transmitGpsInformation.positionUpdated = false;
> +	transmitGpsInformation.nodeId = getNodeId();
>
> +#ifdef HTTPINFO_PUD
> +	olsr_cnf->pud_position =&transmitGpsInformation;
> +#else
> +	olsr_cnf->pud_position = NULL;
> +#endif
>   	initPositionAverageList(&positionAverageList, getAverageDepth());
>
>   	if (!initOlsrTxTimer()) {
> diff --git a/lib/pud/src/receiver.h b/lib/pud/src/receiver.h
> index 62f27d7..1ee2f42 100644
> --- a/lib/pud/src/receiver.h
> +++ b/lib/pud/src/receiver.h
> @@ -2,13 +2,23 @@
>   #define _PUD_RECEIVER_H_
>
>   /* Plugin includes */
> +#include "posAvg.h"
>
>   /* OLSRD includes */
> +#include "olsr_types.h"
>
>   /* System includes */
>   #include<stddef.h>
>   #include<stdbool.h>
>
> +/** Structure of the latest GPS information that is transmitted */
> +typedef struct _TransmitGpsInformation {
> +	unsigned char * nodeId; /**<  the nodeId */
> +	bool positionUpdated; /**<  true when the position information was updated */
> +	PositionUpdateEntry txPosition; /**<  The last transmitted position */
> +	union olsr_ip_addr txGateway; /**<  the best gateway */
> +} TransmitGpsInformation;
> +
>   bool startReceiver(void);
>   void stopReceiver(void);
>
> diff --git a/src/cfgparser/olsrd_conf.c b/src/cfgparser/olsrd_conf.c
> index ad90094..60df1f5 100644
> --- a/src/cfgparser/olsrd_conf.c
> +++ b/src/cfgparser/olsrd_conf.c
> @@ -792,6 +792,10 @@ set_default_cnf(struct olsrd_config *cnf)
>   #if defined __FreeBSD__ || defined __FreeBSD_kernel__ || defined __APPLE__ || defined __NetBSD__ || defined __OpenBSD__
>     cnf->rts = 0;
>   #endif
> +
> +#ifdef HTTPINFO_PUD
> +  cnf->pud_position = NULL;
> +#endif
>   }
>
>   struct if_config_options *
> diff --git a/src/olsr_cfg.h b/src/olsr_cfg.h
> index 349cbc2..8dc83ec 100644
> --- a/src/olsr_cfg.h
> +++ b/src/olsr_cfg.h
> @@ -44,6 +44,9 @@
>
>   #include "olsr_types.h"
>   #include "common/autobuf.h"
> +#ifdef HTTPINFO_PUD
> +#include "pud/src/receiver.h"
> +#endif
>
>   /* set to 1 to collect all startup sleep into one sleep
>    * (just as long as the longest sleep)
> @@ -304,6 +307,10 @@ struct olsrd_config {
>     int rts;                             /* Socket used for route changes on BSDs */
>   #endif
>     float lq_nat_thresh;
> +
> +#ifdef HTTPINFO_PUD
> +  TransmitGpsInformation * pud_position;
> +#endif
>   };
>
>   #if defined __cplusplus

-- 
Ferry Huberts




More information about the Olsr-dev mailing list