Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed Watchdog SDFileSystem DigoleSerialDisp
Sensors/GPS/Venus638flpx.cpp@23:a34af501ea89, 2018-11-30 (annotated)
- Committer:
- shimniok
- Date:
- Fri Nov 30 15:41:05 2018 +0000
- Revision:
- 23:a34af501ea89
- Parent:
- 2:fbc6e3cf3ed8
Disabled PinDetect code (for now); fixed attach() calls in various functions to use new callback class.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| shimniok | 0:a6a169de725f | 1 | #include "mbed.h" |
| shimniok | 0:a6a169de725f | 2 | #include "Venus638flpx.h" |
| shimniok | 0:a6a169de725f | 3 | |
| shimniok | 0:a6a169de725f | 4 | // TODO: parameterize LED |
| shimniok | 0:a6a169de725f | 5 | |
| shimniok | 0:a6a169de725f | 6 | Venus638flpx::Venus638flpx(PinName tx, PinName rx): |
| shimniok | 0:a6a169de725f | 7 | serial(tx, rx) |
| shimniok | 0:a6a169de725f | 8 | { |
| shimniok | 0:a6a169de725f | 9 | init(); |
| shimniok | 0:a6a169de725f | 10 | } |
| shimniok | 0:a6a169de725f | 11 | |
| shimniok | 0:a6a169de725f | 12 | void Venus638flpx::init() |
| shimniok | 0:a6a169de725f | 13 | { |
| shimniok | 0:a6a169de725f | 14 | setBaud(38400); |
| shimniok | 0:a6a169de725f | 15 | enable(); |
| shimniok | 0:a6a169de725f | 16 | disableVerbose(); |
| shimniok | 0:a6a169de725f | 17 | setUpdateRate(10); |
| shimniok | 0:a6a169de725f | 18 | } |
| shimniok | 0:a6a169de725f | 19 | |
| shimniok | 0:a6a169de725f | 20 | void Venus638flpx::setBaud(int baud) |
| shimniok | 0:a6a169de725f | 21 | { |
| shimniok | 0:a6a169de725f | 22 | serial.baud(baud); |
| shimniok | 0:a6a169de725f | 23 | } |
| shimniok | 0:a6a169de725f | 24 | |
| shimniok | 0:a6a169de725f | 25 | Serial *Venus638flpx::getSerial(void) |
| shimniok | 0:a6a169de725f | 26 | { |
| shimniok | 0:a6a169de725f | 27 | return &serial; |
| shimniok | 0:a6a169de725f | 28 | } |
| shimniok | 0:a6a169de725f | 29 | |
| shimniok | 0:a6a169de725f | 30 | void Venus638flpx::enable(void) |
| shimniok | 0:a6a169de725f | 31 | { |
| shimniok | 0:a6a169de725f | 32 | reset_available(); |
| shimniok | 23:a34af501ea89 | 33 | serial.attach(callback(this, &Venus638flpx::recv_handler), Serial::RxIrq); |
| shimniok | 0:a6a169de725f | 34 | } |
| shimniok | 0:a6a169de725f | 35 | |
| shimniok | 0:a6a169de725f | 36 | void Venus638flpx::disable(void) |
| shimniok | 0:a6a169de725f | 37 | { |
| shimniok | 0:a6a169de725f | 38 | serial.attach(NULL, Serial::RxIrq); |
| shimniok | 0:a6a169de725f | 39 | } |
| shimniok | 0:a6a169de725f | 40 | |
| shimniok | 0:a6a169de725f | 41 | /** |
| shimniok | 0:a6a169de725f | 42 | * Enable verbose messages for debugging |
| shimniok | 0:a6a169de725f | 43 | */ |
| shimniok | 0:a6a169de725f | 44 | void Venus638flpx::enableVerbose(void) |
| shimniok | 0:a6a169de725f | 45 | { |
| shimniok | 0:a6a169de725f | 46 | setNmeaMessages(1,1,1,0,1,1); |
| shimniok | 0:a6a169de725f | 47 | } |
| shimniok | 0:a6a169de725f | 48 | |
| shimniok | 0:a6a169de725f | 49 | /** |
| shimniok | 0:a6a169de725f | 50 | * Disable verbose messages for debugging |
| shimniok | 0:a6a169de725f | 51 | */ |
| shimniok | 0:a6a169de725f | 52 | void Venus638flpx::disableVerbose(void) |
| shimniok | 0:a6a169de725f | 53 | { |
| shimniok | 0:a6a169de725f | 54 | setNmeaMessages(1,1,0,0,1,0); |
| shimniok | 0:a6a169de725f | 55 | } |
| shimniok | 0:a6a169de725f | 56 | |
| shimniok | 0:a6a169de725f | 57 | void Venus638flpx::setNmeaMessages(char gga, char gsa, char gsv, char gll, char rmc, char vtg) |
| shimniok | 0:a6a169de725f | 58 | { |
| shimniok | 0:a6a169de725f | 59 | // VENUS Binary MsgID=0x08 |
| shimniok | 0:a6a169de725f | 60 | // GGA interval |
| shimniok | 0:a6a169de725f | 61 | // GSA interval |
| shimniok | 0:a6a169de725f | 62 | // GSV interval |
| shimniok | 0:a6a169de725f | 63 | // GLL interval |
| shimniok | 0:a6a169de725f | 64 | // RMC interval |
| shimniok | 0:a6a169de725f | 65 | // VTG interval |
| shimniok | 0:a6a169de725f | 66 | // ZDA interval -- hardcode off |
| shimniok | 0:a6a169de725f | 67 | char msg[15] = { 0xA0, 0xA1, 0x00, 0x09, |
| shimniok | 0:a6a169de725f | 68 | 0x08, gga, gsa, gsv, gll, rmc, vtg, 0, |
| shimniok | 0:a6a169de725f | 69 | 0, 0x0D, 0x0A |
| shimniok | 0:a6a169de725f | 70 | }; |
| shimniok | 0:a6a169de725f | 71 | for (int i=4; i < 12; i++) { |
| shimniok | 0:a6a169de725f | 72 | msg[12] ^= msg[i]; |
| shimniok | 0:a6a169de725f | 73 | } |
| shimniok | 0:a6a169de725f | 74 | for (int i=0; i < 15; i++) |
| shimniok | 0:a6a169de725f | 75 | serial.putc(msg[i]); |
| shimniok | 0:a6a169de725f | 76 | } |
| shimniok | 0:a6a169de725f | 77 | |
| shimniok | 0:a6a169de725f | 78 | void Venus638flpx::setUpdateRate(int rate) |
| shimniok | 0:a6a169de725f | 79 | { |
| shimniok | 0:a6a169de725f | 80 | char msg[10] = { 0xA0, 0xA1, 0x00, 0x03, |
| shimniok | 0:a6a169de725f | 81 | 0x0E, rate&0xFF, 01, |
| shimniok | 0:a6a169de725f | 82 | 0, 0x0D, 0x0A |
| shimniok | 0:a6a169de725f | 83 | }; |
| shimniok | 0:a6a169de725f | 84 | for (int i=4; i < 7; i++) { |
| shimniok | 0:a6a169de725f | 85 | msg[7] ^= msg[i]; |
| shimniok | 0:a6a169de725f | 86 | } |
| shimniok | 0:a6a169de725f | 87 | switch (rate) { |
| shimniok | 0:a6a169de725f | 88 | case 1 : |
| shimniok | 0:a6a169de725f | 89 | case 2 : |
| shimniok | 0:a6a169de725f | 90 | case 4 : |
| shimniok | 0:a6a169de725f | 91 | case 5 : |
| shimniok | 0:a6a169de725f | 92 | case 8 : |
| shimniok | 0:a6a169de725f | 93 | case 10 : |
| shimniok | 0:a6a169de725f | 94 | case 20 : |
| shimniok | 0:a6a169de725f | 95 | for (int i=0; i < 10; i++) |
| shimniok | 0:a6a169de725f | 96 | serial.putc(msg[i]); |
| shimniok | 0:a6a169de725f | 97 | break; |
| shimniok | 0:a6a169de725f | 98 | default : |
| shimniok | 0:a6a169de725f | 99 | break; |
| shimniok | 0:a6a169de725f | 100 | } |
| shimniok | 0:a6a169de725f | 101 | } |
| shimniok | 0:a6a169de725f | 102 | |
| shimniok | 0:a6a169de725f | 103 | |
| shimniok | 0:a6a169de725f | 104 | /* |
| shimniok | 0:a6a169de725f | 105 | void Venus638flpx::position(GeoPosition &here) |
| shimniok | 0:a6a169de725f | 106 | { |
| shimniok | 0:a6a169de725f | 107 | double latitude, longitude; |
| shimniok | 0:a6a169de725f | 108 | unsigned long age; |
| shimniok | 0:a6a169de725f | 109 | nmea.f_get_position(&latitude, &longitude, &age); |
| shimniok | 0:a6a169de725f | 110 | here.set(latitude, longitude); |
| shimniok | 0:a6a169de725f | 111 | return; |
| shimniok | 0:a6a169de725f | 112 | } |
| shimniok | 0:a6a169de725f | 113 | |
| shimniok | 0:a6a169de725f | 114 | void Venus638flpx::position(double *latitude, double *longitude) |
| shimniok | 0:a6a169de725f | 115 | { |
| shimniok | 0:a6a169de725f | 116 | unsigned long age; |
| shimniok | 0:a6a169de725f | 117 | nmea.f_get_position(latitude, longitude, &age); |
| shimniok | 0:a6a169de725f | 118 | return; |
| shimniok | 0:a6a169de725f | 119 | } |
| shimniok | 0:a6a169de725f | 120 | */ |
| shimniok | 0:a6a169de725f | 121 | |
| shimniok | 0:a6a169de725f | 122 | double Venus638flpx::latitude(void) |
| shimniok | 0:a6a169de725f | 123 | { |
| shimniok | 0:a6a169de725f | 124 | double latitude, longitude; |
| shimniok | 0:a6a169de725f | 125 | unsigned long age; |
| shimniok | 0:a6a169de725f | 126 | nmea.f_get_position(&latitude, &longitude, &age); |
| shimniok | 0:a6a169de725f | 127 | return latitude; |
| shimniok | 0:a6a169de725f | 128 | } |
| shimniok | 0:a6a169de725f | 129 | |
| shimniok | 0:a6a169de725f | 130 | double Venus638flpx::longitude(void) |
| shimniok | 0:a6a169de725f | 131 | { |
| shimniok | 0:a6a169de725f | 132 | double latitude, longitude; |
| shimniok | 0:a6a169de725f | 133 | unsigned long age; |
| shimniok | 0:a6a169de725f | 134 | nmea.f_get_position(&latitude, &longitude, &age); |
| shimniok | 0:a6a169de725f | 135 | return longitude; |
| shimniok | 0:a6a169de725f | 136 | } |
| shimniok | 0:a6a169de725f | 137 | |
| shimniok | 0:a6a169de725f | 138 | float Venus638flpx::hdop(void) |
| shimniok | 0:a6a169de725f | 139 | { |
| shimniok | 0:a6a169de725f | 140 | return nmea.f_hdop(); |
| shimniok | 0:a6a169de725f | 141 | } |
| shimniok | 0:a6a169de725f | 142 | |
| shimniok | 0:a6a169de725f | 143 | int Venus638flpx::sat_count(void) |
| shimniok | 0:a6a169de725f | 144 | { |
| shimniok | 0:a6a169de725f | 145 | return nmea.sat_count(); |
| shimniok | 0:a6a169de725f | 146 | } |
| shimniok | 0:a6a169de725f | 147 | |
| shimniok | 0:a6a169de725f | 148 | float Venus638flpx::speed_mps(void) |
| shimniok | 0:a6a169de725f | 149 | { |
| shimniok | 0:a6a169de725f | 150 | return nmea.f_speed_mps(); |
| shimniok | 0:a6a169de725f | 151 | } |
| shimniok | 0:a6a169de725f | 152 | |
| shimniok | 0:a6a169de725f | 153 | float Venus638flpx::heading_deg(void) |
| shimniok | 0:a6a169de725f | 154 | { |
| shimniok | 0:a6a169de725f | 155 | return nmea.f_course(); |
| shimniok | 0:a6a169de725f | 156 | } |
| shimniok | 0:a6a169de725f | 157 | |
| shimniok | 0:a6a169de725f | 158 | bool Venus638flpx::available(void) |
| shimniok | 0:a6a169de725f | 159 | { |
| shimniok | 0:a6a169de725f | 160 | return nmea.ready(); |
| shimniok | 0:a6a169de725f | 161 | } |
| shimniok | 0:a6a169de725f | 162 | |
| shimniok | 0:a6a169de725f | 163 | void Venus638flpx::reset_available(void) |
| shimniok | 0:a6a169de725f | 164 | { |
| shimniok | 0:a6a169de725f | 165 | nmea.reset_ready(); |
| shimniok | 0:a6a169de725f | 166 | } |
| shimniok | 0:a6a169de725f | 167 | |
| shimniok | 0:a6a169de725f | 168 | int Venus638flpx::getAvailable(void) |
| shimniok | 0:a6a169de725f | 169 | { |
| shimniok | 2:fbc6e3cf3ed8 | 170 | // TODO 2 not sure what to do here |
| shimniok | 0:a6a169de725f | 171 | return 0xff; |
| shimniok | 0:a6a169de725f | 172 | } |
| shimniok | 0:a6a169de725f | 173 | |
| shimniok | 0:a6a169de725f | 174 | void Venus638flpx::recv_handler() |
| shimniok | 0:a6a169de725f | 175 | { |
| shimniok | 0:a6a169de725f | 176 | while (serial.readable()) { |
| shimniok | 0:a6a169de725f | 177 | nmea.encode(serial.getc()); |
| shimniok | 0:a6a169de725f | 178 | } |
| shimniok | 0:a6a169de725f | 179 | } |