explan_serial.c.xml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <sect1 id="serial.c"><title><filename>serial.c</filename></title>
  2. <informaltable frame='all' pgwide='1'>
  3. <tgroup cols='2'>
  4. <colspec colname='c1'></colspec>
  5. <colspec colname='c2'></colspec>
  6. <spanspec spanname='s1' namest='c1' nameend='c2'></spanspec>
  7. <thead>
  8. <row>
  9. <entry>Functions:-</entry><entry>This provides serial port handling services to the daemon. It handles the tricky task of scanning for and changing port parameters, especially baudrate.</entry>
  10. </row>
  11. </thead>
  12. <tfoot>
  13. <row>
  14. <entry spanname='s1' align='left'>Notes based on code as of Tue Apr 6 10:17:55 2010 -0400.</entry>
  15. </row>
  16. </tfoot>
  17. <tbody>
  18. <row>
  19. <entry><function>void gpsd_tty_init(struct gps_device_t *session)</function></entry>
  20. <entry><para>To be called on allocating a device. Mark GPS fd closed
  21. and its baud rate unknown.</para><para>If we are supporting
  22. <function>ntpd</function> shared memory segments, ensure they are
  23. initially unused.</para></entry>
  24. </row>
  25. <row>
  26. <entry><function>void cfmakeraw(struct termios *termios_p)</function></entry>
  27. <entry><para>Workaround for systems (Cygwin, Solaris), which are missing
  28. <function>cfmakeraw()</function>. It is pasted from man page and
  29. added in <function>serial.c</function> arbitrarily.</para></entry>
  30. </row>
  31. <row>
  32. <entry><function>speed_t gpsd_get_speed(struct termios* ttyctl)</function></entry>
  33. <entry><para>Calls <function>cfgetospeed()</function> and returns
  34. the baud rate, if known. Default otherwise is 115200.</para></entry>
  35. </row>
  36. <row>
  37. <entry><function>bool gpsd_set_raw(struct gps_device_t *session)</function></entry>
  38. <entry><para>Tries to set port to raw mode and returns success or
  39. not.</para></entry>
  40. </row>
  41. <row>
  42. <entry><function>void gpsd_set_speed(struct gps_device_t *session, speed_t speed, unsigned char parity, unsigned int stopbits)</function></entry>
  43. <entry><para>Sets the speed, parity and stopbits.</para><para>Lots
  44. of black magic fiddling goes on to ensure the port is flushed on the
  45. baud rate change and wakeup strings are fired off just in case the
  46. device needs prodding into life.</para><para>READ THE CODE AND
  47. COMMENTS!!!</para><para>Prior to exit, a call is made to
  48. <function>packet_reset()</function> to ensure the packet state
  49. machine is initialised.</para></entry>
  50. </row>
  51. <row>
  52. <entry><function>int gpsd_open(struct gps_device_t *session)</function></entry>
  53. <entry><para>Test the device and flag it as R/W if it is a character
  54. device, or R/O if it isn't.</para><para>Try to open it in
  55. non-blocking and no-control mode.</para><para>If that fails, try
  56. again, adding read-only mode. If that also fails, exit with an
  57. error.</para><para>On no error, force the saved baudrate if we have
  58. a fixed port speed (typically embedded devices). Check if we have a
  59. saved baudrate and if so, activate it.</para><para>Preset the packet
  60. type to BAD_PACKET.</para><para>Check if the device we have opened
  61. is a tty. If it is a tty, read the original terminal
  62. parameters.</para><para>Exit with an error code -1 on failure to do
  63. so.</para><para>Save the old parameters, set important control
  64. flags, then set the speed.</para><para>Finally, return the allocated
  65. fd.</para></entry>
  66. </row>
  67. <row>
  68. <entry><function>bool gpsd_write(struct gps_device_t *session, void const *buf, size_t len)</function></entry>
  69. <entry><para>If the device is read-only, simply return
  70. 0.</para><para>If not, try to write <function>len</function>
  71. characters to the device. Waiting until all data has been
  72. sent.</para><para>Return the number of bytes written.</para></entry>
  73. </row>
  74. <row>
  75. <entry><function>bool gpsd_next_hunt_setting(struct gps_device_t *session)</function></entry>
  76. <entry><para>Check if we have had SNIFF_RETRIES attempts at current
  77. baudrate. If not, return <quote>true</quote>.</para><para>If we have
  78. exceeded the limit, reset the counter and see if there are any more
  79. rates to try at.</para><para>If no (fixed baudrate or all attempts
  80. exhausted), return <quote>false</quote>, otherwise, set the next
  81. speed and return <quote>true</quote>.</para></entry>
  82. </row>
  83. <row>
  84. <entry><function>void gpsd_assert_sync(struct gps_device_t *session)</function></entry>
  85. <entry><para>To be called when we want to register that we've synced
  86. with a device. We've achieved first sync with the device. Remember
  87. the baudrate so we can try it first next time this device is
  88. opened.</para></entry>
  89. </row>
  90. <row>
  91. <entry><function>void gpsd_close(struct gps_device_t *session)</function></entry>
  92. <entry><para>If there is an active fd, check if it is a tty
  93. device. If it is, force the baudrate to 0 (should terminate the
  94. connection and de-assert control lines).</para><para> Set the HUPCL
  95. flag in the original data, write the old data to the port, close the
  96. fd and clear that fd number from the session data.</para></entry>
  97. </row>
  98. </tbody>
  99. </tgroup>
  100. </informaltable>
  101. </sect1>