monitor_italk.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /*
  2. * This file is Copyright 2010 by the GPSD project
  3. * SPDX-License-Identifier: BSD-2-clause
  4. */
  5. #include "../include/gpsd_config.h" /* must be before all includes */
  6. #include <stdio.h>
  7. #include <string.h> /* for strlcat() */
  8. #include "../include/gpsd.h"
  9. #include "../include/bits.h"
  10. #include "../include/gpsmon.h"
  11. #ifdef ITRAX_ENABLE
  12. #include "../include/driver_italk.h"
  13. extern const struct gps_type_t driver_italk;
  14. static WINDOW *satwin, *navfixwin;
  15. #define display (void)mvwprintw
  16. static bool italk_initialize(void)
  17. {
  18. int i;
  19. /* "heavily inspired" by monitor_nmea.c */
  20. if ((satwin =
  21. derwin(devicewin, MAX_NR_VISIBLE_PRNS + 3, 27, 0, 0)) == NULL)
  22. return false;
  23. (void)wborder(satwin, 0, 0, 0, 0, 0, 0, 0, 0), (void)syncok(satwin, true);
  24. (void)wattrset(satwin, A_BOLD);
  25. display(satwin, 1, 1, "Ch PRN Az El S/N Flag U");
  26. for (i = 0; i < MAX_NR_VISIBLE_PRNS; i++)
  27. display(satwin, (int)(i + 2), 1, "%2d", i);
  28. display(satwin, MAX_NR_VISIBLE_PRNS + 2, 7, " PRN_STATUS ");
  29. (void)wattrset(satwin, A_NORMAL);
  30. /* "heavily inspired" by monitor_nmea.c */
  31. if ((navfixwin = derwin(devicewin, 13, 52, 0, 27)) == NULL)
  32. return false;
  33. (void)wborder(navfixwin, 0, 0, 0, 0, 0, 0, 0, 0),
  34. (void)wattrset(navfixwin, A_BOLD);
  35. (void)wmove(navfixwin, 1, 1);
  36. (void)wprintw(navfixwin, "ECEF Pos:");
  37. (void)wmove(navfixwin, 2, 1);
  38. (void)wprintw(navfixwin, "ECEF Vel:");
  39. (void)wmove(navfixwin, 4, 1);
  40. (void)wprintw(navfixwin, "LTP Pos:");
  41. (void)wmove(navfixwin, 5, 1);
  42. (void)wprintw(navfixwin, "LTP Vel:");
  43. (void)wmove(navfixwin, 7, 1);
  44. (void)wprintw(navfixwin, "Time UTC:");
  45. (void)wmove(navfixwin, 8, 1);
  46. (void)wprintw(navfixwin, "Time GPS: Day:");
  47. (void)wmove(navfixwin, 10, 1);
  48. (void)wprintw(navfixwin, "DOP [H] [V] [P] [T] [G]");
  49. (void)wmove(navfixwin, 11, 1);
  50. (void)wprintw(navfixwin, "Fix:");
  51. display(navfixwin, 12, 20, " NAV_FIX ");
  52. (void)wattrset(navfixwin, A_NORMAL);
  53. return true;
  54. }
  55. static void display_itk_navfix(unsigned char *buf, size_t len)
  56. {
  57. unsigned int tow, tod, d, svlist;
  58. unsigned short gps_week, nsv;
  59. unsigned short year, mon, day, hour, min, sec;
  60. double epx, epy, epz, evx, evy, evz;
  61. double latitude, longitude;
  62. float altitude, speed, track, climb;
  63. float hdop, gdop, pdop, vdop, tdop;
  64. if (len != 296)
  65. return;
  66. #ifdef __UNUSED__
  67. flags = (unsigned short) getleu16(buf, 7 + 4);
  68. cflags = (unsigned short) getleu16(buf, 7 + 6);
  69. pflags = (unsigned short) getleu16(buf, 7 + 8);
  70. #endif /* __UNUSED__ */
  71. #define MAX(a,b) (((a) > (b)) ? (a) : (b))
  72. nsv = (unsigned short) MAX(getleu16(buf, 7 + 12),
  73. getleu16(buf, 7 + 14));
  74. svlist = (unsigned int)((unsigned short)getleu32(buf, 7 + 16) |
  75. getleu32(buf, 7 + 24));
  76. hour = (unsigned short) getleu16(buf, 7 + 66);
  77. min = (unsigned short) getleu16(buf, 7 + 68);
  78. sec = (unsigned short) getleu16(buf, 7 + 70);
  79. //nsec = (unsigned short) getleu32(buf, 7 + 72);
  80. year = (unsigned short) getleu16(buf, 7 + 76);
  81. mon = (unsigned short) getleu16(buf, 7 + 78);
  82. day = (unsigned short) getleu16(buf, 7 + 80);
  83. gps_week = (unsigned short) getles16(buf, 7 + 82);
  84. tow = (unsigned short) getleu32(buf, 7 + 84);
  85. epx = (double)(getles32(buf, 7 + 96) / 100.0);
  86. epy = (double)(getles32(buf, 7 + 100) / 100.0);
  87. epz = (double)(getles32(buf, 7 + 104) / 100.0);
  88. evx = (double)(getles32(buf, 7 + 186) / 1000.0);
  89. evy = (double)(getles32(buf, 7 + 190) / 1000.0);
  90. evz = (double)(getles32(buf, 7 + 194) / 1000.0);
  91. latitude = (double)(getles32(buf, 7 + 144) / 1e7);
  92. longitude = (double)(getles32(buf, 7 + 148) / 1e7);
  93. altitude = (float)(getles32(buf, 7 + 152) / 1e3);
  94. climb = (float)(getles32(buf, 7 + 206) / 1e3);
  95. speed = (float)(getleu32(buf, 7 + 210) / 1e3);
  96. track = (float)(getleu16(buf, 7 + 214) / 1e2);
  97. hdop = (float)(getleu16(buf, 7 + 56) / 100.0);
  98. gdop = (float)(getleu16(buf, 7 + 58) / 100.0);
  99. pdop = (float)(getleu16(buf, 7 + 60) / 100.0);
  100. vdop = (float)(getleu16(buf, 7 + 62) / 100.0);
  101. tdop = (float)(getleu16(buf, 7 + 64) / 100.0);
  102. (void)wmove(navfixwin, 1, 11);
  103. (void)wprintw(navfixwin, "%12.2lf %12.2lf %12.2lfm", epx, epy, epz);
  104. (void)wmove(navfixwin, 2, 11);
  105. (void)wprintw(navfixwin, "%11.2lf %11.2lf %11.2lfm/s", evx, evy, evz);
  106. (void)wmove(navfixwin, 4, 11);
  107. (void)wprintw(navfixwin, "%11.8lf %13.8lf %8.1lfm",
  108. latitude, longitude, altitude);
  109. (void)mvwaddch(navfixwin, 4, 22, ACS_DEGREE);
  110. (void)mvwaddch(navfixwin, 4, 38, ACS_DEGREE);
  111. (void)wmove(navfixwin, 5, 11);
  112. (void)wprintw(navfixwin, "%6.2lfm/s %5.1lf %6.2lfm/s climb",
  113. speed, track, climb);
  114. (void)mvwaddch(navfixwin, 5, 27, ACS_DEGREE);
  115. (void)wmove(navfixwin, 7, 11);
  116. (void)wprintw(navfixwin, "%04u-%02u-%02u %02u:%02u:%02u",
  117. year, mon, day, hour, min, sec);
  118. (void)wmove(navfixwin, 8, 11);
  119. (void)wprintw(navfixwin, "%04u+%010.3lf", gps_week, tow / 1000.0);
  120. (void)wmove(navfixwin, 8, 33);
  121. d = (tow / 1000) / 86400;
  122. tod = (tow / 1000) - (d * 86400);
  123. sec = (unsigned short)tod % 60;
  124. min = (unsigned short)(tod / 60) % 60;
  125. hour = (unsigned short)tod / 3600;
  126. (void)wprintw(navfixwin, "%1d %02d:%02d:%02d", d, hour, min, sec);
  127. (void)wmove(navfixwin, 10, 9);
  128. (void)wprintw(navfixwin, "%-5.1f", hdop);
  129. (void)wmove(navfixwin, 10, 18);
  130. (void)wprintw(navfixwin, "%-5.1f", vdop);
  131. (void)wmove(navfixwin, 10, 27);
  132. (void)wprintw(navfixwin, "%-5.1f", pdop);
  133. (void)wmove(navfixwin, 10, 36);
  134. (void)wprintw(navfixwin, "%-5.1f", tdop);
  135. (void)wmove(navfixwin, 10, 45);
  136. (void)wprintw(navfixwin, "%-5.1f", gdop);
  137. (void)wmove(navfixwin, 11, 6);
  138. {
  139. char prn[4], satlist[38];
  140. uint64_t i; // uint64_t just in case ints are 32-bit
  141. satlist[0] = '\0';
  142. for (i = 0; i < 32; i++) {
  143. if (svlist & (1ULL << i)) {
  144. (void)snprintf(prn, 4, "%llu ", (unsigned long long)i + 1);
  145. (void)strlcat(satlist, prn, sizeof(satlist));
  146. }
  147. }
  148. (void)wprintw(navfixwin, "%02d = %-38s", nsv, satlist);
  149. }
  150. (void)wnoutrefresh(navfixwin);
  151. }
  152. static void display_itk_prnstatus(unsigned char *buf, size_t len)
  153. {
  154. int i, nchan;
  155. if (len < 62)
  156. return;
  157. nchan = (int)getleu16(buf, 7 + 50);
  158. if (nchan > MAX_NR_VISIBLE_PRNS)
  159. nchan = MAX_NR_VISIBLE_PRNS;
  160. for (i = 0; i < nchan; i++) {
  161. int off = 7 + 52 + 10 * i;
  162. unsigned short fl;
  163. unsigned char ss, prn, el, az;
  164. fl = (unsigned short)getleu16(buf, off);
  165. ss = (unsigned char)getleu16(buf, off + 2) & 0xff;
  166. prn = (unsigned char)getleu16(buf, off + 4) & 0xff;
  167. el = (unsigned char)getles16(buf, off + 6) & 0xff;
  168. az = (unsigned char)getles16(buf, off + 8) & 0xff;
  169. (void)wmove(satwin, i + 2, 4);
  170. (void)wprintw(satwin, "%3d %3d %2d %02d %04x %c",
  171. prn, az, el, ss, fl,
  172. (fl & PRN_FLAG_USE_IN_NAV) ? 'Y' : ' ');
  173. }
  174. for (; i < MAX_NR_VISIBLE_PRNS; i++) {
  175. (void)wmove(satwin, (int)i + 2, 4);
  176. (void)wprintw(satwin, " ");
  177. }
  178. (void)wnoutrefresh(satwin);
  179. return;
  180. }
  181. static void italk_update(void)
  182. {
  183. unsigned char *buf;
  184. size_t len;
  185. unsigned char type;
  186. buf = session.lexer.outbuffer;
  187. len = session.lexer.outbuflen;
  188. type = (unsigned char)getub(buf, 4);
  189. switch (type) {
  190. case ITALK_NAV_FIX:
  191. display_itk_navfix(buf, len);
  192. break;
  193. case ITALK_PRN_STATUS:
  194. display_itk_prnstatus(buf, len);
  195. break;
  196. default:
  197. break;
  198. }
  199. }
  200. static int italk_command(char line[]UNUSED)
  201. {
  202. return COMMAND_UNKNOWN;
  203. }
  204. static void italk_wrap(void)
  205. {
  206. (void)delwin(satwin);
  207. return;
  208. }
  209. const struct monitor_object_t italk_mmt = {
  210. .initialize = italk_initialize,
  211. .update = italk_update,
  212. .command = italk_command,
  213. .wrap = italk_wrap,
  214. .min_y = 23,.min_x = 80, /* size of the device window */
  215. .driver = &driver_italk,
  216. };
  217. #endif
  218. // vim: set expandtab shiftwidth=4