summaryrefslogtreecommitdiff
path: root/recipes-navigation/gpsd/gpsd-3.18.1/0006-ubxtimelps.patch
blob: 030001c59e686a6fd199c18e76c1f08e4b44b1dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
diff -Naru gpsd-3.18.1.orig/driver_ubx.c gpsd-3.18.1/driver_ubx.c
--- gpsd-3.18.1.orig/driver_ubx.c	2018-10-26 16:01:08.010358178 -0500
+++ gpsd-3.18.1/driver_ubx.c	2018-10-29 17:30:18.354526227 -0500
@@ -57,6 +57,29 @@
 #define UBX_CFG_LEN		20
 #define outProtoMask		14
 
+#ifdef UBLOXTIMELS_ENABLE
+/* UBX-NAV-TIMELS support */
+static char *srcOfCurrLs[] = {
+  "firmware",
+  "GPS GLONASS difference",
+  "GPS",
+  "SBAS",
+  "BeiDou",
+  "Galileo",
+  "Aided data",
+  "Configured"
+};
+static char *srcOfLsChange[] = {
+  "No Source",
+  "Undefined",
+  "GPS",
+  "SBAS",
+  "BeiDou",
+  "Galileo",
+  "GLONOSS",
+};
+#endif  /* UBLOXTIMELS_ENABLE */
+
 static gps_mask_t ubx_parse(struct gps_device_t *session, unsigned char *buf,
 			    size_t len);
 static gps_mask_t ubx_msg_nav_eoe(struct gps_device_t *session,
@@ -397,6 +420,90 @@
     return mask;
 }
 
+#ifdef UBLOXTIMELS_ENABLE
+/**
+ * Navigation time to leap second
+ * 
+ * Sets leap_notify if leap second is < 23 hours away.
+ */
+static void
+ubx_msg_nav_timels(struct gps_device_t *session, unsigned char *buf,
+		size_t data_len)
+{
+    int version;
+    unsigned int flags;
+    int valid_curr_ls;
+    int valid_time_to_ls_event;
+    
+    if (data_len != 24) {
+        gpsd_log(&session->context->errout, LOG_WARN, 
+	  "UBX-NAV-TIMELS: unexpected length %d, expecting 24\n",
+	  data_len);
+	return;
+    }
+    version = getsb(buf,4);
+    /* Only version 0 is defined so far. */
+    flags = (unsigned int)getub(buf, 23);
+    gpsd_log(&session->context->errout, LOG_DATA,
+        "UBX-NAV-TIMELS: flags 0x%x message version %d\n",flags, version);
+    valid_curr_ls = flags & UBX_TIMELS_VALID_CURR_LS;
+    valid_time_to_ls_event = flags & UBX_TIMELS_VALID_TIME_LS_EVT;
+    if(valid_curr_ls) {
+      unsigned int src_of_curr_ls = getub(buf,8);
+      int curr_ls = getsb(buf,9);
+      char *src = "Unknown";
+      
+      if(src_of_curr_ls < (sizeof srcOfCurrLs/(sizeof srcOfCurrLs[0])))
+	src = srcOfCurrLs[src_of_curr_ls];
+	
+      gpsd_log(&session->context->errout, LOG_DATA,
+	     "UBX-NAV-TIMELS: source_of_current_leapsecond=%u:%s curr_ls=%d\n",
+	     src_of_curr_ls,src,curr_ls);
+      session->context->leap_seconds = curr_ls;
+      session->context->valid |= LEAP_SECOND_VALID;
+    } /* Valid current leap second */
+    if(valid_time_to_ls_event) {
+      char *src="Unknown";
+      unsigned int src_of_ls_change;
+      unsigned short dateOfLSGpsWn, dateOfLSGpsDn;
+      int lsChange = getsb(buf,11);
+      int timeToLsEvent = getles32(buf,12);
+      src_of_ls_change = getub(buf,10);
+      if(src_of_ls_change < (sizeof srcOfLsChange/(sizeof srcOfLsChange[0])))
+	src = srcOfLsChange[src_of_ls_change];
+      dateOfLSGpsWn = getles16(buf,16);
+      dateOfLSGpsDn = getles16(buf,18);
+      gpsd_log(&session->context->errout, LOG_DATA,
+	 "UBX_NAV_TIMELS: source_of_leapsecond_change=%u:%s "
+	 "leapSecondChage=%d timeToLsEvent=%d\n",
+	 src_of_ls_change,src,lsChange,timeToLsEvent);
+      gpsd_log(&session->context->errout, LOG_DATA,
+	       "UBX_NAV_TIMELS: dateOfLSGpsWn=%d dateOfLSGpsDn=%d\n",
+	       dateOfLSGpsWn,dateOfLSGpsDn);
+      if(timeToLsEvent < 60*60*23 && timeToLsEvent > 0) {
+	if(lsChange == 0)
+	   session->context->leap_notify = LEAP_NOWARNING;
+	else if (lsChange == 1)
+	  session->context->leap_notify = LEAP_ADDSECOND;
+	else if (lsChange == -1)
+	  session->context->leap_notify = LEAP_DELSECOND;
+      } else
+	session->context->leap_notify = LEAP_NOWARNING;
+
+      if (session->context->leap_notify == LEAP_ADDSECOND)
+	gpsd_log(&session->context->errout,LOG_INF,
+		"UBX_NAV_TIMELS: Add leap second today\n");
+      else if (session->context->leap_notify == LEAP_DELSECOND)
+	gpsd_log(&session->context->errout,LOG_INF,
+		 "UBX_NAV_TIMELS: Remove leap second today\n");
+      
+      gpsd_log(&session->context->errout, LOG_DATA,
+	       "UBX_NAV_TIMELS: leaving: leap_notify=%d\n",
+	session->context->leap_notify);
+    }
+}
+#endif  /* UBLOXTIMELS_ENABLE */
+
  /**
  * Geodetic position solution message
  */
@@ -1129,6 +1236,9 @@
 	break;
     case UBX_NAV_TIMELS:
 	gpsd_log(&session->context->errout, LOG_DATA, "UBX_NAV_TIMELS\n");
+#ifdef UBLOXTIMELS_ENABLE
+	ubx_msg_nav_timels(session, &buf[UBX_PREFIX_LEN],data_len);
+#endif // UBLOXTIMELS_ENABLE
 	break;
     case UBX_NAV_TIMEUTC:
 	gpsd_log(&session->context->errout, LOG_DATA, "UBX_NAV_TIMEUTC\n");
@@ -1172,6 +1282,7 @@
 	gpsd_log(&session->context->errout, LOG_DATA, "UBX_RXM_RTCM\n");
 	break;
     case UBX_RXM_SFRB:
+        gpsd_log(&session->context->errout, LOG_DATA, "UBX_RXM_SFRB\n");
 	mask = ubx_rxm_sfrb(session, &buf[UBX_PREFIX_LEN]);
 	break;
     case UBX_RXM_SFRBX:
@@ -1474,6 +1585,12 @@
 	msg[1] = 0x20;		/* msg id  = UBX_NAV_TIMEGPS */
 	msg[2] = 0x00;		/* rate */
 	(void)ubx_write(session, 0x06u, 0x01, msg, 3);
+#ifdef UBLOXTIMELS_ENABLE
+	msg[0] = 0x01;		/* class */
+	msg[1] = 0x26;		/* msg id  = UBX_NAV_TIMELS */
+	msg[2] = 0xff;		/* rate */
+#endif /* UBLOXTIMELS_ENABLE */
+	(void)ubx_write(session, 0x06u, 0x01, msg, 3);
 	msg[0] = 0x01;		/* class */
 	msg[1] = 0x30;		/* msg id  = NAV-SVINFO */
 	msg[2] = 0x00;		/* rate */
@@ -1558,6 +1675,12 @@
 	msg[1] = 0x20;		/* msg id  = UBX_NAV_TIMEGPS */
 	msg[2] = 0x01;		/* rate */
 	(void)ubx_write(session, 0x06u, 0x01, msg, 3);
+#ifdef UBLOXTIMELS_ENABLE
+	msg[0] = 0x01;		/* class */
+	msg[1] = 0x26;		/* msg id  = UBX_NAV_TIMELS */
+	msg[2] = 0xff;		/* rate */
+	(void)ubx_write(session, 0x06u, 0x01, msg, 3);
+#endif /* UBLOXTIMELS_ENABLE */
 	msg[0] = 0x01;		/* class */
 	msg[1] = 0x30;		/* msg id  = NAV-SVINFO */
 	msg[2] = 0x0a;		/* rate */
diff -Naru gpsd-3.18.1.orig/driver_ubx.h gpsd-3.18.1/driver_ubx.h
--- gpsd-3.18.1.orig/driver_ubx.h	2018-10-26 16:01:08.010358178 -0500
+++ gpsd-3.18.1/driver_ubx.h	2018-10-26 16:26:09.114313738 -0500
@@ -210,6 +210,9 @@
 #define UBX_SOL_VALID_WEEK 0x04
 #define UBX_SOL_VALID_TIME 0x08
 
+#define UBX_TIMELS_VALID_CURR_LS 0x01
+#define UBX_TIMELS_VALID_TIME_LS_EVT 0x01
+
 #define UBX_TIMEGPS_VALID_TIME        0x01
 #define UBX_TIMEGPS_VALID_WEEK        0x02
 #define UBX_TIMEGPS_VALID_LEAP_SECOND 0x04
diff -Naru gpsd-3.18.1.orig/SConstruct gpsd-3.18.1/SConstruct
--- gpsd-3.18.1.orig/SConstruct	2018-10-26 15:53:30.174371732 -0500
+++ gpsd-3.18.1/SConstruct	2018-10-26 15:55:33.726368074 -0500
@@ -178,6 +178,7 @@
     ("tripmate",      True,  "DeLorme TripMate support"),
     ("tsip",          True,  "Trimble TSIP support"),
     ("ublox",         True,  "u-blox Protocol support"),
+    ("ubloxtimels",   False, "u-blox UBX-NAV-TIMELS support (leap second)"),
     # Non-GPS protocols
     ("aivdm",         True,  "AIVDM support"),
     ("gpsclock",      True,  "GPSClock support"),