-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef NmeaChecksum_h | ||
#define NmeaChecksum_h | ||
|
||
#define NMEA_END_CHAR_1 '\r' | ||
|
||
/* | ||
NMEA-0183 checksum | ||
*/ | ||
|
||
uint8_t nmea0183_checksum(const char *sentence); | ||
|
||
uint8_t nmea0183_checksum(const char *sentence) { | ||
const char *n = sentence + 1; | ||
uint8_t chk = 0; | ||
/* While current char isn't '*' or sentence ending (newline) */ | ||
while ('*' != *n && NMEA_END_CHAR_1 != *n && '\0' != *n) { | ||
chk ^= (uint8_t) *n; | ||
n++; | ||
} | ||
return chk; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#ifndef NmeaXDR_h | ||
#define NmeaXDR_h | ||
|
||
/* | ||
XDR - Transducer Measurement | ||
https://gpsd.gitlab.io/gpsd/NMEA.html#_xdr_transducer_measurement | ||
https://www.eye4software.com/hydromagic/documentation/articles-and-howtos/handling-nmea0183-xdr/ | ||
Format: $--XDR,a,x.x,a,c--c, ..... *hh<CR><LF> | ||
Example: | ||
$HCXDR,A,171,D,PITCH,A,-37,D,ROLL,G,367,,MAGX,G,2420,,MAGY,G,-8984,,MAGZ*41 | ||
$SDXDR,C,23.15,C,WTHI*70 | ||
Transducer Types: | ||
A - Angular displacement | ||
C - Temperature | ||
D - Depth/Distance | ||
F - Frequency | ||
H - Humidity | ||
N - Force | ||
P - Pressure | ||
R - Flow | ||
B - Absolute humidity | ||
G - Generic | ||
I - Current | ||
L - Salinity | ||
S - Switch, valve | ||
T - Tachometer | ||
U - Voltage | ||
V - Volume | ||
could be more | ||
Unit of measurement | ||
"" - could be empty! | ||
A - Amperes | ||
B - Bars | Binary | ||
C - Celsius | ||
D - Degrees | ||
H - Hertz | ||
I - liters/second | ||
K - Kelvin | Density, kg/m3 kilogram per cubic metre | ||
M - Meters | Cubic Meters (m3) | ||
N - Newton | ||
P - Percent of full range | Pascal | ||
R - RPM | ||
S - Parts per thousand | ||
V - Volts | ||
could be more | ||
*/ | ||
|
||
/* | ||
Bareboat Necessities Sensors NMEA-0183 XDR Sentences: | ||
NMEA-0183 Sender | ||
BB | ||
Distance | ||
$BBXDR,D,0.52,M,Range_JSN_S04T*55 | ||
$BBXDR,D,0.70,M,Range_JSN_S04T*55 | ||
$BBXDR,D,0.71,M,Range_JSN_S04T*54 | ||
*/ | ||
|
||
#include "NmeaChecksum.h" | ||
|
||
void gen_nmea0183_xdr(const char *nmea_fmt, float value) { | ||
char nmea_part[82]; | ||
snprintf(nmea_part, 76, nmea_fmt, value); | ||
int checksum = nmea0183_checksum(nmea_part); | ||
Serial.printf("%s*%02X\r\n", nmea_part, checksum); | ||
} | ||
|
||
#endif |