From c486e9f1ec90bc33b4a63733b76e94aced35228c Mon Sep 17 00:00:00 2001
Date: Tue, 19 Sep 2017 17:10:05 +1000
Subject: [PATCH] handle the antenna status in the UBX HW-MON msg
---
driver_ubx.c | 33 +++++++++++++++++++++++++++++++++
gps.h | 7 +++++++
gpsd_json.c | 2 ++
gpsd_json.xml | 5 +++++
libgps_json.c | 2 ++
5 files changed, 49 insertions(+)
diff --git a/driver_ubx.c b/driver_ubx.c
index 88be6c0..421aa04 100644
--- a/driver_ubx.c
+++ b/driver_ubx.c
@@ -73,6 +73,8 @@ static gps_mask_t ubx_msg_nav_timegps(struct gps_device_t *session,
unsigned char *buf, size_t data_len);
static void ubx_msg_mon_ver(struct gps_device_t *session,
unsigned char *buf, size_t data_len);
+static void ubx_msg_mon_hw(struct gps_device_t *session,
+ unsigned char *buf);
#ifdef RECONFIGURE_ENABLE
static void ubx_mode(struct gps_device_t *session, int mode);
#endif /* RECONFIGURE_ENABLE */
@@ -393,6 +395,36 @@ static void ubx_msg_sbas(struct gps_device_t *session, unsigned char *buf)
}
/*
+ * Hardare Monitor status
+ */
+static void ubx_msg_mon_hw(struct gps_device_t *session, unsigned char *buf)
+{
+ session->gpsdata.ant_status = (int)getub(buf, 20);
+
+ switch( session->gpsdata.ant_status )
+ {
+ case ANT_STATUS_INIT:
+ gpsd_log(&session->context->errout, LOG_PROG, "ANT_STATUS: INIT\n");
+ break;
+ case ANT_STATUS_DONT_KNOW:
+ gpsd_log(&session->context->errout, LOG_PROG, "ANT_STATUS: DONT_KNOW\n");
+ break;
+ case ANT_STATUS_OK:
+ gpsd_log(&session->context->errout, LOG_PROG, "ANT_STATUS: OK\n");
+ break;
+ case ANT_STATUS_SHORT:
+ gpsd_log(&session->context->errout, LOG_PROG, "ANT_STATUS: SHORT\n");
+ break;
+ case ANT_STATUS_OPEN:
+ gpsd_log(&session->context->errout, LOG_PROG, "ANT_STATUS: OPEN\n");
+ break;
+ default:
+ gpsd_log(&session->context->errout, LOG_PROG, "ANT_STATUS: : %d\n", session->gpsdata.ant_status );
+ break;
+ }
+}
+
+/*
* Raw Subframes
*/
static gps_mask_t ubx_msg_sfrb(struct gps_device_t *session, unsigned char *buf)
@@ -578,6 +610,7 @@ gps_mask_t ubx_parse(struct gps_device_t * session, unsigned char *buf,
break;
case UBX_MON_HW:
gpsd_log(&session->context->errout, LOG_DATA, "UBX_MON_HW\n");
+ ubx_msg_mon_hw(session, &buf[6]);
break;
case UBX_MON_USB:
gpsd_log(&session->context->errout, LOG_DATA, "UBX_MON_USB\n");
diff --git a/gps.h b/gps.h
index 77c1bcb..c6fc4e9 100644
--- a/gps.h
+++ b/gps.h
@@ -2024,9 +2024,16 @@ struct gps_data_t {
#define STATUS_FIX 1 /* yes, without DGPS */
#define STATUS_DGPS_FIX 2 /* yes, with DGPS */
+/* Antenna status */
+#define ANT_STATUS_INIT 0
+#define ANT_STATUS_DONT_KNOW 1
+#define ANT_STATUS_OK 2
+#define ANT_STATUS_SHORT 3
+#define ANT_STATUS_OPEN 4
/* precision of fix -- valid if satellites_used > 0 */
int satellites_used; /* Number of satellites used in solution */
struct dop_t dop;
+ int ant_status; /* antenna status */
/* redundant with the estimate elements in the fix structure */
double epe; /* spherical position error, 95% confidence (meters) */
diff --git a/gpsd_json.c b/gpsd_json.c
index 825851e..84f443e 100644
--- a/gpsd_json.c
+++ b/gpsd_json.c
@@ -287,6 +287,8 @@ void json_sky_dump(const struct gps_data_t *datap,
str_appendf(reply, replylen, "\"gdop\":%.2f,", datap->dop.gdop);
if (isnan(datap->dop.pdop) == 0)
str_appendf(reply, replylen, "\"pdop\":%.2f,", datap->dop.pdop);
+ if (isnan(datap->ant_status) == 0 && datap->ant_status != ANT_STATUS_INIT)
+ str_appendf(reply, replylen, "\"ant\":%d,", datap->ant_status);
/* insurance against flaky drivers */
for (i = 0; i < datap->satellites_visible; i++)
if (datap->skyview[i].PRN)
diff --git a/gpsd_json.xml b/gpsd_json.xml
index 88c8a66..a89b7f7 100644
--- a/gpsd_json.xml
+++ b/gpsd_json.xml
@@ -337,6 +337,11 @@ yet, only the "class" field will reliably be present.</para>
error estimate.</entry>
</row>
<row>
+ <entry>ant</entry>
+ <entry>No</entry>
+ <entry>numeric</entry>
+ <entry>Antenna status. If supported by the driver and the device</entry>
+<row>
<entry>satellites</entry>
<entry>Yes</entry>
<entry>list</entry>
diff --git a/libgps_json.c b/libgps_json.c
index 6a71185..b0c6273 100644
--- a/libgps_json.c
+++ b/libgps_json.c
@@ -142,6 +142,8 @@ static int json_sky_read(const char *buf, struct gps_data_t *gpsdata,
.dflt.real = NAN},
{"gdop", t_real, .addr.real = &gpsdata->dop.gdop,
.dflt.real = NAN},
+ {"ant", t_integer, .addr.integer = &gpsdata->ant_status,
+ .dflt.integer = ANT_STATUS_INIT},
{"satellites", t_array,
STRUCTARRAY(gpsdata->skyview,
json_attrs_satellites,
--
1.9.1