summaryrefslogtreecommitdiff
path: root/doc/explan_packet.c.xml
blob: e7f0207eb886a0818abb01da9955cc39944a0862 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<sect1 id="packet.c"><title><filename>packet.c</filename></title>
<informaltable frame='all' pgwide='1'>
<tgroup cols='2'>
<colspec colname='c1'></colspec>
<colspec colname='c2'></colspec>
<spanspec spanname='s1' namest='c1' nameend='c2'></spanspec>

<thead>
<row>
  <entry>Functions:-</entry><entry>The packet-sniffing engine for reading data packets from GPS devices.</entry>
</row>
</thead>

<tfoot>
<row>
  <entry spanname='s1' align='left'>Notes based on code as of Tue Apr 6 10:17:55 2010 -0400.</entry>
</row>
</tfoot>

<tbody>
<row>
  <entry><function>static void nextstate(struct gps_packet_t *lexer, unsigned char c)</function></entry>
  <entry><para>This is the main packet-sniffer loop. It scans the character
  against the definitions of all the packet structures known to
  <application>gpsd</application> and, if possible, sets a new packet
  state.</para><para>If the state is <quote>xxx_RECOGNIZED</quote>,
  the packet_parse routine will despatch the packet to the appropriate
  driver.</para></entry>
</row>
<row>
  <entry><function>static void packet_accept(struct gps_packet_t *lexer, int packet_type)</function></entry>
  <entry><para>This shifts a packet that has been recognized into the
  output buffer, provided it is not bigger than the
  buffer.</para></entry>
</row>
<row>
  <entry><function>static void packet_discard(struct gps_packet_t *lexer)</function></entry>
  <entry><para>This clears a handled packet out of the input
  buffer.</para></entry>
</row>
<row>
  <entry><function>static void character_discard(struct gps_packet_t *lexer)</function></entry>
  <entry><para>This is called if the <function>nextstate()</function>
  function returns <quote>GROUND_STATE</quote>.</para><para>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
  <quote>bad</quote> character.</para></entry>
</row>
<row>
  <entry><function>ssize_t packet_parse(struct gps_packet_t *lexer, size_t fix)</function></entry>
  <entry><para>Call the <function>nextstate()</function> function to
  process the available data and set the recognition state
  correctly.</para><para>When a packet is matched to a driver, call
  <function>packet_accept()</function> and
  <function>packet_discard()</function> to handle the packet. If it is
  not matched, call <function>packet_discard()</function> and set the
  state to <quote>GROUND_STATE</quote></para><para>Return the number
  of characters handled.</para></entry>
</row>
<row>
  <entry><function>ssize_t packet_get(int fd, struct gps_packet_t *lexer)</function></entry>
  <entry><para>Reads raw data from the input port.</para><para>Returns
  the number of characters read (0 or more) or BAD_PACKET if there was
  an error in reading.</para><para>Errors
  <errortype>EAGAIN</errortype> and <errortype>EINTR</errortype> are
  not classed as failures and cause a return of 0.</para><para>In case
  of a good read of more than 0 characters, the return value is the
  output from a call to
  <function>packet_parse()</function>.</para></entry>
</row>
<row>
  <entry><function>void packet_reset(struct gps_packet_t *lexer)</function></entry>
  <entry><para>This simply resets the entire packet state machine to
  the ground state.</para></entry>
</row>
<row>
  <entry><function>void packet_nit(struct gps_packet_t *lexer)</function></entry>
  <entry><para>Zeros some counters, then resets the entire packet
  state machine to the ground state.</para></entry>
</row>
<row>
  <entry><function>void packet_pushback(struct gps_packet_t *lexer)</function></entry>
  <entry><para>This pushes back the last packet from the output buffer
  to the input buffer, provided doing so would not overflow the input
  buffer.</para></entry>
</row>
</tbody>

</tgroup>
</informaltable>
</sect1>