packet.c
Functions:-The packet-sniffing engine for reading data packets from GPS devices.
Notes based on code as of Tue Apr 6 10:17:55 2010 -0400.
static void nextstate(struct gps_packet_t *lexer, unsigned char c)
This is the main packet-sniffer loop. It scans the character
against the definitions of all the packet structures known to
gpsd and, if possible, sets a new packet
state.If the state is xxx_RECOGNIZED
,
the packet_parse routine will despatch the packet to the appropriate
driver.
static void packet_accept(struct gps_packet_t *lexer, int packet_type)
This shifts a packet that has been recognized into the
output buffer, provided it is not bigger than the
buffer.
static void packet_discard(struct gps_packet_t *lexer)
This clears a handled packet out of the input
buffer.
static void character_discard(struct gps_packet_t *lexer)
This is called if the nextstate()
function returns GROUND_STATE
.In this
case the character does not match any pattern, so to discard it, the
input buffer is shifted back by one character to overwrite the
bad
character.
ssize_t packet_parse(struct gps_packet_t *lexer, size_t fix)
Call the nextstate() function to
process the available data and set the recognition state
correctly.When a packet is matched to a driver, call
packet_accept() and
packet_discard() to handle the packet. If it is
not matched, call packet_discard() and set the
state to GROUND_STATE
Return the number
of characters handled.
ssize_t packet_get(int fd, struct gps_packet_t *lexer)
Reads raw data from the input port.Returns
the number of characters read (0 or more) or BAD_PACKET if there was
an error in reading.Errors
EAGAIN and EINTR are
not classed as failures and cause a return of 0.In case
of a good read of more than 0 characters, the return value is the
output from a call to
packet_parse().
void packet_reset(struct gps_packet_t *lexer)
This simply resets the entire packet state machine to
the ground state.
void packet_nit(struct gps_packet_t *lexer)
Zeros some counters, then resets the entire packet
state machine to the ground state.
void packet_pushback(struct gps_packet_t *lexer)
This pushes back the last packet from the output buffer
to the input buffer, provided doing so would not overflow the input
buffer.