106 if (errno != EAGAIN) {
107 fprintf(stderr,
"Unexpected error while reading from serial port (handle ID: 0x%02x)\n",
109 fprintf(stderr,
"read returned \"%s\" in readMessage\n", strerror(errno));
124 if (ti == 0) { out->
raw[0] = 0xFD; }
131 if ((*index) == (*hw)) {
132 if ((*hw) > 0 && (*index) > 0) {
140 if (ti == 0) { out->
raw[0] = 0xFD; }
144 if (((*hw) - (*index)) < 8) {
148 if (ti == 0) { out->
raw[0] = 0xFD; }
152 int eom = (*index) + 1;
159 if ((eom - (*index)) > 82) {
172 if (ti == 0) { out->
raw[0] = 0xFD; }
182 out->
talker[0] = buf[som++];
183 out->
talker[1] = buf[som++];
184 if (out->
talker[0] ==
'P') {
185 out->
talker[2] = buf[som++];
186 out->
talker[3] = buf[som++];
192 if (buf[som++] !=
',') {
207 char csA = buf[som++];
208 char csB = buf[som++];
218 cs = (csA -
'a') + 10;
226 cs = (csA -
'A') + 10;
253 cs += (csB -
'a') + 10;
261 cs += (csB -
'A') + 10;
282 if (cs != out->
checksum) { valid =
false; }
292 if ((eom - som) > 1) {
321 int ret = write(handle, buf, size);
323 return (ret == (ssize_t) size);
int openSerialConnection(const char *port, const int baudRate)
Open a serial connection at a given baud rate.
#define NMEA_CSUM_MARK
NMEA Checksum Delimiter.
bool nmea_readMessage_buf(int handle, nmea_msg_t *out, uint8_t buf[NMEA_SERIAL_BUFF], int *index, int *hw)
Read data from handle, and parse message if able.
#define NMEA_END_BYTE2
NMEA End Byte 1: Line Feed.
#define NMEA_START_BYTE2
NMEA Start Byte 2.
bool nmea_writeMessage(int handle, const nmea_msg_t *out)
Send message to attached device.
bool nmea_readMessage(int handle, nmea_msg_t *out)
Static wrapper around mp_readMessage_buf.
int nmea_openConnection(const char *port, const int baudRate)
Set up a connection to the specified port.
#define NMEA_END_BYTE1
NMEA End Byte 1: Carriage Return.
void nmea_closeConnection(int handle)
Close existing connection.
#define NMEA_START_BYTE1
NMEA0183 Start Byte 1.
#define NMEA_SERIAL_BUFF
Default serial buffer allocation size.
void nmea_calc_checksum(const nmea_msg_t *msg, uint8_t *cs)
Calculate checksum for NMEA message.
size_t nmea_flat_array(const nmea_msg_t *msg, char **out)
Convert NMEA message to array of bytes for transmission.
Generic NMEA message structure.
bool encapsulated
Encapsulated message (all data in raw)
uint8_t checksum
Message Checksum.
char message[3]
Message ID.
char talker[4]
Talker ID (2-4 characters)
uint8_t rawlen
Length of data stored in raw.