monitor_tnt.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * monitor_tnt.c - gpsmon support for True North Revolution devices.
  3. *
  4. * This file is Copyright (c) 2010-2018 by the GPSD project
  5. * SPDX-License-Identifier: BSD-2-clause
  6. */
  7. #include "gpsd_config.h" /* must be before all includes */
  8. #include <assert.h>
  9. #include "gpsd.h"
  10. #include "gpsmon.h"
  11. #ifdef TNT_ENABLE
  12. extern const struct gps_type_t driver_trueNorth;
  13. static WINDOW *thtmwin;
  14. static bool tnt_initialize(void)
  15. {
  16. thtmwin = derwin(devicewin, 6, 80, 0, 0);
  17. assert(thtmwin != NULL);
  18. (void)wborder(thtmwin, 0, 0, 0, 0, 0, 0, 0, 0),
  19. (void)syncok(thtmwin, true);
  20. (void)wattrset(thtmwin, A_BOLD);
  21. (void)mvwaddstr(thtmwin, 0, 35, " PTNTHTM ");
  22. (void)mvwaddstr(thtmwin, 1, 1, "Heading: ");
  23. (void)mvwaddstr(thtmwin, 2, 1, "Pitch: ");
  24. (void)mvwaddstr(thtmwin, 3, 1, "Roll: ");
  25. (void)mvwaddstr(thtmwin, 4, 1, "Dip: ");
  26. (void)mvwaddstr(thtmwin, 1, 40, "Magnetometer Status: ");
  27. (void)mvwaddstr(thtmwin, 2, 40, "Pitch Status: ");
  28. (void)mvwaddstr(thtmwin, 3, 40, "Roll Status ");
  29. (void)mvwaddstr(thtmwin, 4, 40, "Horizontal Field: ");
  30. (void)wattrset(thtmwin, A_NORMAL);
  31. return true;
  32. }
  33. static void tnt_update(void)
  34. {
  35. /*
  36. * We have to do our own field parsing because the way this
  37. * gets called, nmea_parse() is never called on the sentence.
  38. */
  39. (void)nmea_parse((char *)session.lexer.outbuffer, &session);
  40. (void)mvwaddstr(thtmwin, 1, 19, session.nmea.field[1]);
  41. (void)mvwaddstr(thtmwin, 2, 19, session.nmea.field[3]);
  42. (void)mvwaddstr(thtmwin, 3, 19, session.nmea.field[5]);
  43. (void)mvwaddstr(thtmwin, 4, 19, session.nmea.field[7]);
  44. (void)mvwaddstr(thtmwin, 1, 61, session.nmea.field[2]);
  45. (void)mvwaddstr(thtmwin, 2, 61, session.nmea.field[4]);
  46. (void)mvwaddstr(thtmwin, 3, 61, session.nmea.field[6]);
  47. (void)mvwaddstr(thtmwin, 4, 61, session.nmea.field[8]);
  48. }
  49. static int tnt_command(char line[] UNUSED)
  50. {
  51. /*
  52. * Interpret a command line. Whatever characters the user types will
  53. * be echoed in the command buffer at the top right of the display. When
  54. * he/she presses enter the command line will be passed to this function
  55. * for interpretation. Note: packet receipt is suspended while this
  56. * function is executing.
  57. *
  58. * This method is optional. If you set the command method pointer to
  59. * NULL, gpsmon will behave sanely, accepting no device-specific commands.
  60. *
  61. * It is a useful convention to use uppercase letters for
  62. * driver-specific commands and leave lowercase ones for the
  63. * generic gpsmon ones.
  64. */
  65. /*
  66. * Return COMMAND_UNKNOWN to tell gpsmon you can't interpret the line, and
  67. * it will be passed to the generic command interpreter to be handled there.
  68. * You can alse return COMMAND_MATCH to tell it you handled the command,
  69. * or COMMAND_TERMINATE to tell gpsmon you handled it and gpsmon should
  70. * terminate.
  71. */
  72. return COMMAND_UNKNOWN;
  73. }
  74. static void tnt_wrap(void)
  75. {
  76. (void)delwin(thtmwin);
  77. }
  78. /*
  79. * Use mmt = monitor method table as a suffix for naming these things
  80. * Yours will need to be added to the monitor_objects table in gpsmon.c,
  81. * then of course you need to link your module into gpsmon.
  82. */
  83. const struct monitor_object_t tnt_mmt = {
  84. .initialize = tnt_initialize,
  85. .update = tnt_update,
  86. .command = tnt_command,
  87. .wrap = tnt_wrap,
  88. .min_y = 6,.min_x = 80, /* size of the device window */
  89. .driver = &driver_trueNorth,
  90. };
  91. #endif /* TNT_ENABLE */
  92. /*
  93. * Helpers:
  94. *
  95. * bool monitor_control_send(unsigned char *buf, size_t len)
  96. * Ship a packet payload to the device. Calls the driver send_control()
  97. * method to add headers/trailers/checksum; also dumps the sent
  98. * packet to the packet window, if the send_control() is playing
  99. * nice by using session.msgbuf to assemble the message.
  100. *
  101. * void monitor_log(const char *fmt, ...)
  102. * Write a message to the packet window. Safe if the packet window
  103. * is not on screen.
  104. *
  105. * void monitor_complain(const char *fmt, ...)
  106. * Post an error message to the command window, wait till user presses a key.
  107. * You get to make sure the message will fit.
  108. *
  109. * void monitor_fixframe(WINDOW *win)
  110. * Fix the frame of win to the right of the current location by redrawing
  111. * ACS_VLINE there. Useful after doing wclrtoeol() and writing on the
  112. * line.
  113. *
  114. * The libgpsd session object is accessible as the global variable 'session'.
  115. */