PX4 Firmware
PX4 Autopilot Software http://px4.io
sbf.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2018 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
34 /**
35  * @file sbf.h
36  *
37  * Septentrio protocol as defined in PPSDK SBF Reference Guide 4.1.8
38  *
39  * @author Matej Frančeškin <Matej.Franceskin@gmail.com>
40  *
41  */
42 
43 #pragma once
44 
45 #include "gps_helper.h"
46 #include "base_station.h"
47 #include "rtcm.h"
48 #include "../../definitions.h"
49 
50 #define SBF_CONFIG_FORCE_INPUT "SSSSSSSSSS\n"
51 
52 #define SBF_CONFIG_BAUDRATE "setCOMSettings, COM1, baud%d\n"
53 
54 #define SBF_CONFIG_RESET "setSBFOutput, all, COM1, none, off\n"
55 
56 #define SBF_CONFIG_RECEIVER_DYNAMICS "setReceiverDynamics, %s, UAV\n"
57 
58 #define SBF_TX_CFG_PRT_BAUDRATE 115200
59 
60 #define SBF_CONFIG "" \
61  "setDataInOut, COM1, Auto, SBF\n" \
62  "setPVTMode, Rover, All, auto\n" \
63  "setSatelliteTracking, All\n" \
64  "setSatelliteUsage, All\n" \
65  "setElevationMask, All, 10\n" \
66  "setSBFOutput, Stream1, DSK1, Support, msec100\n" \
67  "setSBFOutput, Stream2, Dsk1, Event+Comment, OnChange\n" \
68  "setSBFOutput, Stream3, COM1, DOP+VelCovGeodetic, sec1\n" \
69  "setSBFOutput, Stream4, COM1, PVTGeodetic, msec100\n" \
70  "setFileNaming, DSK1, Incremental\n" \
71  "setFileNaming, DSK1, , 'px4'\n"
72 
73 #define SBF_CONFIG_RTCM "" \
74  "setDataInOut, USB1, Auto, RTCMv3+SBF\n" \
75  "setPVTMode, Rover, All, auto\n" \
76  "setSatelliteTracking, All\n" \
77  "setSatelliteUsage, All\n" \
78  "setElevationMask, All, 10\n" \
79  "setReceiverDynamics, Moderate, Automotive\n" \
80  "setSBFOutput, Stream1, DSK1, Support, msec100\n" \
81  "setSBFOutput, Stream2, USB1, DOP+VelCovGeodetic, sec1\n" \
82  "setSBFOutput, Stream3, USB1, PVTGeodetic, msec200\n" \
83  "setFileNaming, DSK1, Incremental\n" \
84  "setFileNaming, DSK1, , 'px4rtcm'\n"
85 
86 #define SBF_CONFIG_RTCM_STATIC1 "" \
87  "setReceiverDynamics, Low, Static\n"
88 
89 #define SBF_CONFIG_RTCM_STATIC2 "" \
90  "setPVTMode, Static, , Geodetic1\n"
91 
92 #define SBF_CONFIG_RTCM_STATIC_COORDINATES "" \
93  "setStaticPosGeodetic, Geodetic1, %f, %f, %f\n"
94 
95 #define SBF_CONFIG_RTCM_STATIC_OFFSET "" \
96  "setAntennaOffset, Main, %f, %f, %f\n"
97 
98 #define SBF_CONFIG_RESET_HOT "" \
99  SBF_CONFIG_FORCE_INPUT"ExeResetReceiver, soft, none\n"
100 
101 #define SBF_CONFIG_RESET_WARM "" \
102  SBF_CONFIG_FORCE_INPUT"ExeResetReceiver, soft, PVTData\n"
103 
104 #define SBF_CONFIG_RESET_COLD "" \
105  SBF_CONFIG_FORCE_INPUT"ExeResetReceiver, hard, SatData\n"
106 
107 #define SBF_SYNC1 0x24
108 #define SBF_SYNC2 0x40
109 
110 /* Block IDs */
111 #define SBF_ID_DOP 4001
112 #define SBF_ID_PVTGeodetic 4007
113 #define SBF_ID_ChannelStatus 4013
114 #define SBF_ID_VelCovGeodetic 5908
115 
116 /*** SBF protocol binary message and payload definitions ***/
117 #pragma pack(push, 1)
118 
119 typedef struct {
120  uint8_t mode_type: 4; /**< Bit field indicating the PVT mode type, as follows:
121  0: No PVT available (the Error field indicates the cause of the absence of the PVT solution)
122  1: Stand-Alone PVT
123  2: Differential PVT
124  3: Fixed location
125  4: RTK with fixed ambiguities
126  5: RTK with float ambiguities
127  6: SBAS aided PVT
128  7: moving-base RTK with fixed ambiguities
129  8: moving-base RTK with float ambiguities
130  10:Precise Point Positioning (PPP) */
131  uint8_t mode_reserved: 2; /**< Reserved */
132  uint8_t mode_base_fixed: 1; /**< Set if the user has entered the command setPVTMode,base,auto and the receiver
133  is still in the process of determining its fixed position. */
134  uint8_t mode_2d: 1; /**< 2D/3D flag: set in 2D mode(height assumed constant and not computed). */
135  uint8_t error; /**< PVT error code. The following values are defined:
136  0: No Error
137  1: Not enough measurements
138  2: Not enough ephemerides available
139  3: DOP too large (larger than 15)
140  4: Sum of squared residuals too large
141  5: No convergence
142  6: Not enough measurements after outlier rejection
143  7: Position output prohibited due to export laws
144  8: Not enough differential corrections available
145  9: Base station coordinates unavailable
146  10:Ambiguities not fixed and user requested to only output RTK-fixed positions
147  Note: if this field has a non-zero value, all following fields are set to their Do-Not-Use value. */
148  double latitude; /**< Marker latitude, from −π/2 to +π/2, positive North of Equator */
149  double longitude; /**< Marker longitude, from −π to +π, positive East of Greenwich */
150  double height; /**< Marker ellipsoidal height (with respect to the ellipsoid specified by Datum) */
151  float undulation; /**< Geoid undulation computed from the global geoid model defined in
152  the document ’Technical Characteristics of the NAVSTAR GPS, NATO, June 1991’ */
153  float vn; /**< Velocity in the North direction */
154  float ve; /**< Velocity in the East direction */
155  float vu; /**< Velocity in the Up direction */
156  float cog; /**< Course over ground: this is defined as the angle of the vehicle with respect
157  to the local level North, ranging from 0 to 360, and increasing towards east.
158  Set to the do-not-use value when the speed is lower than 0.1m/s. */
159  double rx_clk_bias; /**< Receiver clock bias relative to system time reported in the Time System field.
160  To transfer the receiver time to the system time, use: tGPS/GST=trx-RxClkBias */
161  float RxClkDrift; /**< Receiver clock drift relative to system time (relative frequency error) */
162  uint8_t time_system; /**< Time system of which the offset is provided in this sub-block:
163  0:GPStime
164  1:Galileotime
165  3:GLONASStime */
166  uint8_t datum; /**< This field defines in which datum the coordinates are expressed:
167  0: WGS84/ITRS
168  19: Datum equal to that used by the DGNSS/RTK basestation
169  30: ETRS89(ETRF2000 realization)
170  31: NAD83(2011), North American Datum(2011)
171  32: NAD83(PA11), North American Datum, Pacificplate (2011)
172  33: NAD83(MA11), North American Datum, Marianas plate(2011)
173  34: GDA94(2010), Geocentric Datum of Australia (2010)
174  250:First user-defined datum
175  251:Second user-defined datum */
176  uint8_t nr_sv; /**< Total number of satellites used in the PVT computation. */
177  uint8_t wa_corr_info; /**< Bit field providing information about which wide area corrections have been applied:
178  Bit 0: set if orbit and satellite clock correction information is used
179  Bit 1: set if range correction information is used
180  Bit 2: set if ionospheric information is used
181  Bit 3: set if orbit accuracy information is used(UERE/SISA)
182  Bit 4: set if DO229 Precision Approach mode is active
183  Bits 5-7: Reserved */
184  uint16_t reference_id; /**< In case of DGPS or RTK operation, this field is to be interpreted as the base station identifier.
185  In SBAS operation, this field is to be interpreted as the PRN of the geostationary satellite
186  used (from 120 to 158). If multiple base stations or multiple geostationary satellites are used
187  the value is set to 65534.*/
188  uint16_t mean_corr_age; /**< In case of DGPS or RTK, this field is the mean age of the differential corrections.
189  In case of SBAS operation, this field is the mean age of the ’fast corrections’
190  provided by the SBAS satellites */
191  uint32_t signal_info; /**< Bit field indicating the type of GNSS signals having been used in the PVT computations.
192  If a bit i is set, the signal type having index i has been used. */
193  uint8_t alert_flag; /**< Bit field indicating integrity related information */
194 
195  // Revision 1
196  uint8_t nr_bases;
197  uint16_t ppp_info;
198  // Revision 2
199  uint16_t latency;
200  uint16_t h_accuracy;
201  uint16_t v_accuracy;
203 
204 typedef struct {
205  uint8_t mode_type: 4; /**< Bit field indicating the PVT mode type, as follows:
206  0: No PVT available (the Error field indicates the cause of the absence of the PVT solution)
207  1: Stand-Alone PVT
208  2: Differential PVT
209  3: Fixed location
210  4: RTK with fixed ambiguities
211  5: RTK with float ambiguities
212  6: SBAS aided PVT
213  7: moving-base RTK with fixed ambiguities
214  8: moving-base RTK with float ambiguities
215  10:Precise Point Positioning (PPP) */
216  uint8_t mode_reserved: 2; /**< Reserved */
217  uint8_t mode_base_fixed: 1;/**< Set if the user has entered the command setPVTMode,base,auto and the receiver
218  is still in the process of determining its fixed position. */
219  uint8_t mode_2d: 1; /**< 2D/3D flag: set in 2D mode(height assumed constant and not computed). */
220  uint8_t error; /**< PVT error code. The following values are defined:
221  0: No Error
222  1: Not enough measurements
223  2: Not enough ephemerides available
224  3: DOP too large (larger than 15)
225  4: Sum of squared residuals too large
226  5: No convergence
227  6: Not enough measurements after outlier rejection
228  7: Position output prohibited due to export laws
229  8: Not enough differential corrections available
230  9: Base station coordinates unavailable
231  10:Ambiguities not fixed and user requested to only output RTK-fixed positions
232  Note: if this field has a non-zero value, all following fields are set to their Do-Not-Use value. */
233  float cov_vn_vn; /**< Variance of the north-velocity estimate */
234  float cov_ve_ve; /**< Variance of the east-velocity estimate */
235  float cov_vu_vu; /**< Variance of the up - velocity estimate */
236  float cov_dt_dt; /**< Variance of the clock drift estimate */
237  float cov_vn_ve; /**< Covariance between the north - and east - velocity estimates */
238  float cov_vn_vu; /**< Covariance between the north - and up - velocity estimates */
239  float cov_vn_dt; /**< Covariance between the north - velocity and clock drift estimates */
240  float cov_ve_vu; /**< Covariance between the east - and up - velocity estimates */
241  float cov_ve_dt; /**< Covariance between the east - velocity and clock drift estimates */
242  float cov_vu_dt; /**< Covariance between the up - velocity and clock drift estimates */
244 
245 typedef struct {
246  uint8_t nr_sv; /**< Total number of satellites used in the PVT computation. */
247  uint8_t reserved;
248  uint16_t pDOP;
249  uint16_t tDOP;
250  uint16_t hDOP;
251  uint16_t vDOP;
252  float hpl; /**< Horizontal Protection Level (see the DO229 standard). */
253  float vpl; /**< Vertical Protection Level (see the DO229 standard). */
255 
256 typedef struct {
257  uint8_t antenna;
258  uint8_t reserved;
259  uint16_t tracking_status;
260  uint16_t pvt_status;
261  uint16_t pvt_info;
263 
264 /* General message and payload buffer union */
265 
266 typedef struct {
267  uint16_t sync; /** The Sync field is a 2-byte array always set to 0x24, 0x40. The first byte of every SBF block has
268  hexadecimal value 24 (decimal 36, ASCII ’$’). The second byte of every SBF block has hexadecimal
269  value 40 (decimal 64, ASCII ’@’). */
270  uint16_t crc16; /** The CRC field is the 16-bit CRC of all the bytes in an SBF block from and including the ID field
271  to the last byte of the block. The generator polynomial for this CRC is the so-called CRC-CCITT
272  polynomial: x 16 + x 12 + x 5 + x 0 . The CRC is computed in the forward direction using a seed of 0, no
273  reverse and no final XOR. */
274 uint16_t msg_id:
275  13; /** The ID field is a 2-byte block ID, which uniquely identifies the block type and its contents */
276 uint8_t msg_revision:
277  3; /** block revision number, starting from 0 at the initial block definition, and incrementing
278  each time backwards - compatible changes are performed to the block */
279  uint16_t length; /** The Length field is a 2-byte unsigned integer containing the size of the SBF block.
280  It is the total number of bytes in the SBF block including the header.
281  It is always a multiple of 4. */
282  uint32_t TOW; /**< Time-Of-Week: Time-tag, expressed in whole milliseconds from
283  the beginning of the current Galileo/GPSweek. */
284  uint16_t WNc; /**< The GPS week number associated with the TOW. WNc is a continuous
285  weekcount (hence the "c"). It is not affected by GPS week roll overs,
286  which occur every 1024 weeks. By definition of the Galileo system time,
287  WNc is also the Galileo week number + 1024. */
288  union {
292  };
293 
294  uint8_t padding[16];
295 } sbf_buf_t;
296 
297 #pragma pack(pop)
298 /*** END OF SBF protocol binary message and payload definitions ***/
299 
300 /* Decoder state */
301 typedef enum {
307 
309 {
310 public:
311  GPSDriverSBF(GPSCallbackPtr callback, void *callback_user,
312  struct vehicle_gps_position_s *gps_position,
313  struct satellite_info_s *satellite_info,
314  uint8_t dynamic_model);
315 
316  virtual ~GPSDriverSBF() override;
317 
318  int receive(unsigned timeout) override;
319  int configure(unsigned &baudrate, OutputMode output_mode) override;
320  int reset(GPSRestartType restart_type) override;
321 
322 private:
323 
324  /**
325  * @brief Parse the binary SBF packet
326  */
327  int parseChar(const uint8_t b);
328 
329  /**
330  * @brief Add payload rx byte
331  */
332  int payloadRxAdd(const uint8_t b);
333 
334  /**
335  * @brief Finish payload rx
336  */
337  int payloadRxDone(void);
338 
339  /**
340  * @brief Reset the parse state machine for a fresh start
341  */
342  void decodeInit(void);
343 
344  /**
345  * @brief Send a message
346  * @return true on success, false on write error (errno set)
347  */
348  bool sendMessage(const char *msg);
349 
350  /**
351  * @brief Send a message and waits for acknowledge
352  * @return true on success, false on write error (errno set) or ack wait timeout
353  */
354  bool sendMessageAndWaitForAck(const char *msg, const int timeout);
355 
356  struct vehicle_gps_position_s *_gps_position { nullptr };
357  struct satellite_info_s *_satellite_info { nullptr };
358  uint8_t _dynamic_model{ 7 };
359  uint64_t _last_timestamp_time { 0 };
360  bool _configured { false };
361  uint8_t _msg_status { 0 };
363  uint16_t _rx_payload_index { 0 };
365  OutputMode _output_mode { OutputMode::GPS };
366  RTCMParsing *_rtcm_parsing { nullptr };
367 };
368 
369 uint16_t crc16(const uint8_t *buf, uint32_t len);
370 
float cog
Course over ground: this is defined as the angle of the vehicle with respect to the local level North...
Definition: sbf.h:156
uint8_t mode_reserved
Reserved.
Definition: sbf.h:131
uint8_t error
PVT error code.
Definition: sbf.h:220
float cov_vn_vu
Covariance between the north - and up - velocity estimates.
Definition: sbf.h:238
float cov_vu_dt
Covariance between the up - velocity and clock drift estimates.
Definition: sbf.h:242
GPSRestartType
Definition: gps_helper.h:101
float cov_dt_dt
Variance of the clock drift estimate.
Definition: sbf.h:236
float cov_vn_ve
Covariance between the north - and east - velocity estimates.
Definition: sbf.h:237
uint8_t time_system
Time system of which the offset is provided in this sub-block: 0:GPStime 1:Galileotime 3:GLONASStime...
Definition: sbf.h:162
float ve
Velocity in the East direction.
Definition: sbf.h:154
uint16_t sync
Definition: sbf.h:267
double rx_clk_bias
Receiver clock bias relative to system time reported in the Time System field.
Definition: sbf.h:159
uint16_t reference_id
In case of DGPS or RTK operation, this field is to be interpreted as the base station identifier...
Definition: sbf.h:184
float vpl
Vertical Protection Level (see the DO229 standard).
Definition: sbf.h:253
uint8_t alert_flag
Bit field indicating integrity related information.
Definition: sbf.h:193
int reset(enum LPS22HB_BUS busid)
Reset the driver.
uint8_t mode_2d
2D/3D flag: set in 2D mode(height assumed constant and not computed).
Definition: sbf.h:219
uint8_t reserved
Definition: sbf.h:247
uint8_t error
PVT error code.
Definition: sbf.h:135
float cov_ve_dt
Covariance between the east - velocity and clock drift estimates.
Definition: sbf.h:241
static enum ST24_DECODE_STATE _decode_state
Definition: st24.cpp:66
double height
Marker ellipsoidal height (with respect to the ellipsoid specified by Datum)
Definition: sbf.h:150
static char msg[NUM_MSG][CONFIG_USART1_TXBUFSIZE]
Definition: px4io.c:89
uint8_t mode_type
Bit field indicating the PVT mode type, as follows: 0: No PVT available (the Error field indicates th...
Definition: sbf.h:120
uint16_t vDOP
Definition: sbf.h:251
float vn
Velocity in the North direction.
Definition: sbf.h:153
int(* GPSCallbackPtr)(GPSCallbackType type, void *data1, int data2, void *user)
Callback function for platform-specific stuff.
Definition: gps_helper.h:132
double latitude
Marker latitude, from −π/2 to +π/2, positive North of Equator.
Definition: sbf.h:148
uint16_t hDOP
Definition: sbf.h:250
uint16_t length
block revision number, starting from 0 at the initial block definition, and incrementing each time ba...
Definition: sbf.h:279
uint16_t mean_corr_age
In case of DGPS or RTK, this field is the mean age of the differential corrections.
Definition: sbf.h:188
double longitude
Marker longitude, from −π to +π, positive East of Greenwich.
Definition: sbf.h:149
float cov_ve_ve
Variance of the east-velocity estimate.
Definition: sbf.h:234
float cov_ve_vu
Covariance between the east - and up - velocity estimates.
Definition: sbf.h:240
uint16_t pDOP
Definition: sbf.h:248
uint32_t TOW
The Length field is a 2-byte unsigned integer containing the size of the SBF block.
Definition: sbf.h:282
sbf_decode_state_t
Definition: sbf.h:301
GPS driver base class with Base Station Support.
Definition: base_station.h:49
uint8_t mode_type
Bit field indicating the PVT mode type, as follows: 0: No PVT available (the Error field indicates th...
Definition: sbf.h:205
float RxClkDrift
Receiver clock drift relative to system time (relative frequency error)
Definition: sbf.h:161
uint8_t mode_base_fixed
Set if the user has entered the command setPVTMode,base,auto and the receiver is still in the process...
Definition: sbf.h:132
sbf_buf_t _buf
Definition: sbf.h:364
uint8_t datum
This field defines in which datum the coordinates are expressed: 0: WGS84/ITRS 19: Datum equal to tha...
Definition: sbf.h:166
float undulation
Geoid undulation computed from the global geoid model defined in the document ’Technical Characteris...
Definition: sbf.h:151
Definition: sbf.h:266
float cov_vn_dt
Covariance between the north - velocity and clock drift estimates.
Definition: sbf.h:239
uint16_t WNc
The GPS week number associated with the TOW.
Definition: sbf.h:284
uint8_t nr_sv
Total number of satellites used in the PVT computation.
Definition: sbf.h:176
uint8_t wa_corr_info
Bit field providing information about which wide area corrections have been applied: Bit 0: set if or...
Definition: sbf.h:177
uint16_t tDOP
Definition: sbf.h:249
uint8_t mode_base_fixed
Set if the user has entered the command setPVTMode,base,auto and the receiver is still in the process...
Definition: sbf.h:217
uint8_t nr_sv
Total number of satellites used in the PVT computation.
Definition: sbf.h:246
sbf_payload_vel_cov_geodetic_t payload_vel_col_geodetic
Definition: sbf.h:290
sbf_payload_pvt_geodetic_t payload_pvt_geodetic
Definition: sbf.h:289
uint16_t crc16(const uint8_t *buf, uint32_t len)
Calculate buffer CRC16.
Definition: sbf.cpp:368
float cov_vn_vn
Variance of the north-velocity estimate.
Definition: sbf.h:233
uint8_t mode_reserved
Reserved.
Definition: sbf.h:216
float vu
Velocity in the Up direction.
Definition: sbf.h:155
sbf_payload_dop_t payload_dop
Definition: sbf.h:291
uint32_t signal_info
Bit field indicating the type of GNSS signals having been used in the PVT computations.
Definition: sbf.h:191
float hpl
Horizontal Protection Level (see the DO229 standard).
Definition: sbf.h:252
float cov_vu_vu
Variance of the up - velocity estimate.
Definition: sbf.h:235
uint16_t crc16
The Sync field is a 2-byte array always set to 0x24, 0x40.
Definition: sbf.h:270
uint8_t mode_2d
2D/3D flag: set in 2D mode(height assumed constant and not computed).
Definition: sbf.h:134