|
1 | 1 | #pragma once |
2 | 2 |
|
3 | 3 | #include "gps.h" |
4 | | -#include "../hal/MF_Serial.h" |
| 4 | +#include "../hal/hal.h" |
5 | 5 | #include "GPS-uBlox/qqqlab_GPS_UBLOX.h" |
6 | 6 | //#include "GPS-uBlox/qqqlab_AutoBaud.h" |
7 | 7 |
|
8 | 8 | class GpsGizmoUblox: public GpsGizmo { |
9 | | -public: |
10 | | - GpsGizmoUblox(GpsState *state, MF_Serial *ser_bus, int baud) { |
11 | | - //baud is initial GPS baud rate to try |
12 | | - if(baud<=0) baud = 230400; |
| 9 | + private: |
| 10 | + GpsGizmoUblox() {} //private constructor |
13 | 11 |
|
14 | | - //optional auto-baud to speed up gps connection |
15 | | - //baud = autobaud(PIN_GPS_RX); |
16 | | - //Serial.printf("Initial GPS baud rate:%d\n", baud); |
| 12 | + public: |
| 13 | + static GpsGizmoUblox* create(GpsState *state, int ser_bus_id, int baud) { |
| 14 | + //get serial bus |
| 15 | + if(baud == 0) baud = 230400; //baud is initial GPS baud rate to try |
| 16 | + MF_Serial* ser_bus = hal_get_ser_bus(ser_bus_id, baud); |
| 17 | + if(!ser_bus) return nullptr; |
17 | 18 |
|
18 | | - //start GPS Serial with initial baud |
19 | | - ser_bus->begin(baud); |
| 19 | + //setup gizmo |
| 20 | + auto gizmo = new GpsGizmoUblox(); |
| 21 | + gizmo->gps_ublox.state = state; |
| 22 | + gizmo->gps_ublox.ser_bus = ser_bus; |
| 23 | + gizmo->gps_ublox.rate_ms = 100; //optional - gps update rate in milliseconds (default 100) |
| 24 | + gizmo->gps_ublox.save_config = 2, //optional - save config 0:Do not save config, 1:Save config, 2:Save only when needed (default 2) |
| 25 | + gizmo->gps_ublox.gnss_mode = 0; //optonial - GNSS system(s) to use Bitmask: 1:GPS, 2:SBAS, 4:Galileo, 8:Beidou, 16:IMES, 32:QZSS, 64:GLONASS (default 0=leave as configured) |
| 26 | + return gizmo; |
| 27 | + } |
20 | 28 |
|
21 | | - //start GPS |
22 | | - gps_ublox.state = state; |
23 | | - gps_ublox.ser_bus = ser_bus; |
24 | | - gps_ublox.rate_ms = 100; //optional - gps update rate in milliseconds (default 100) |
25 | | - gps_ublox.save_config = 2, //optional - save config 0:Do not save config, 1:Save config, 2:Save only when needed (default 2) |
26 | | - gps_ublox.gnss_mode = 0; //optonial - GNSS system(s) to use Bitmask: 1:GPS, 2:SBAS, 4:Galileo, 8:Beidou, 16:IMES, 32:QZSS, 64:GLONASS (default 0=leave as configured) |
27 | | - } |
| 29 | + bool update() override { |
| 30 | + //update GPS (call at least 10 times per second) |
| 31 | + return gps_ublox.update(); |
| 32 | + } |
| 33 | + |
| 34 | + protected: |
| 35 | + class GPS_UBLOX : public AP_GPS_UBLOX { |
| 36 | + public: |
| 37 | + MF_Serial *ser_bus; |
28 | 38 |
|
29 | | - bool update() override { |
30 | | - //update GPS (call at least 10 times per second) |
31 | | - return gps_ublox.update(); |
32 | | - } |
33 | | - |
34 | | -protected: |
35 | | - class GPS_UBLOX : public AP_GPS_UBLOX { |
36 | | - public: |
37 | | - MF_Serial *ser_bus; |
38 | | - |
39 | | - //interface |
40 | | - void I_setBaud(int baud) override {ser_bus->begin(baud);} |
41 | | - inline int I_availableForWrite() override {return ser_bus->availableForWrite();} |
42 | | - inline int I_available() override {return ser_bus->available();} |
43 | | - inline int I_read(uint8_t* data, size_t len) override {return ser_bus->read(data, len);} |
44 | | - inline int I_write(uint8_t* data, size_t len) override {return ser_bus->write(data, len);} |
45 | | - inline uint32_t I_millis() override {return ::millis();} |
46 | | - void I_print(const char *str) override {Serial.print("GPS: "); Serial.print(str);} |
47 | | - } gps_ublox; |
48 | | -}; |
| 39 | + //interface |
| 40 | + void I_setBaud(int baud) override {ser_bus->begin(baud);} |
| 41 | + inline int I_availableForWrite() override {return ser_bus->availableForWrite();} |
| 42 | + inline int I_available() override {return ser_bus->available();} |
| 43 | + inline int I_read(uint8_t* data, size_t len) override {return ser_bus->read(data, len);} |
| 44 | + inline int I_write(uint8_t* data, size_t len) override {return ser_bus->write(data, len);} |
| 45 | + inline uint32_t I_millis() override {return ::millis();} |
| 46 | + void I_print(const char *str) override {Serial.print("GPS: "); Serial.print(str);} |
| 47 | + } gps_ublox; |
| 48 | + }; |
0 commit comments