You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

250 lines
7.7KB

  1. /*
  2. * This file is Copyright (c) 2010 by the GPSD project
  3. * SPDX-License-Identifier: BSD-2-clause
  4. */
  5. #include "gpsd_config.h" /* must be before all includes */
  6. #include <stdio.h>
  7. #include <string.h> /* for strlcat() */
  8. #include "gpsd.h"
  9. #include "bits.h"
  10. #include "gpsmon.h"
  11. #ifdef ITRAX_ENABLE
  12. #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), getleu16(buf, 7 + 14));
  73. svlist = (unsigned int) ((unsigned short) getleu32(buf, 7 + 16) | getleu32(buf, 7 + 24));
  74. hour = (unsigned short) getleu16(buf, 7 + 66);
  75. min = (unsigned short) getleu16(buf, 7 + 68);
  76. sec = (unsigned short) getleu16(buf, 7 + 70);
  77. //nsec = (unsigned short) getleu32(buf, 7 + 72);
  78. year = (unsigned short) getleu16(buf, 7 + 76);
  79. mon = (unsigned short) getleu16(buf, 7 + 78);
  80. day = (unsigned short) getleu16(buf, 7 + 80);
  81. gps_week = (unsigned short) getles16(buf, 7 + 82);
  82. tow = (unsigned short) getleu32(buf, 7 + 84);
  83. epx = (double)(getles32(buf, 7 + 96) / 100.0);
  84. epy = (double)(getles32(buf, 7 + 100) / 100.0);
  85. epz = (double)(getles32(buf, 7 + 104) / 100.0);
  86. evx = (double)(getles32(buf, 7 + 186) / 1000.0);
  87. evy = (double)(getles32(buf, 7 + 190) / 1000.0);
  88. evz = (double)(getles32(buf, 7 + 194) / 1000.0);
  89. latitude = (double)(getles32(buf, 7 + 144) / 1e7);
  90. longitude = (double)(getles32(buf, 7 + 148) / 1e7);
  91. altitude = (float)(getles32(buf, 7 + 152) / 1e3);
  92. climb = (float)(getles32(buf, 7 + 206) / 1e3);
  93. speed = (float)(getleu32(buf, 7 + 210) / 1e3);
  94. track = (float)(getleu16(buf, 7 + 214) / 1e2);
  95. hdop = (float)(getleu16(buf, 7 + 56) / 100.0);
  96. gdop = (float)(getleu16(buf, 7 + 58) / 100.0);
  97. pdop = (float)(getleu16(buf, 7 + 60) / 100.0);
  98. vdop = (float)(getleu16(buf, 7 + 62) / 100.0);
  99. tdop = (float)(getleu16(buf, 7 + 64) / 100.0);
  100. (void)wmove(navfixwin, 1, 11);
  101. (void)wprintw(navfixwin, "%12.2lf %12.2lf %12.2lfm", epx, epy, epz);
  102. (void)wmove(navfixwin, 2, 11);
  103. (void)wprintw(navfixwin, "%11.2lf %11.2lf %11.2lfm/s", evx, evy, evz);
  104. (void)wmove(navfixwin, 4, 11);
  105. (void)wprintw(navfixwin, "%11.8lf %13.8lf %8.1lfm",
  106. latitude, longitude, altitude);
  107. (void)mvwaddch(navfixwin, 4, 22, ACS_DEGREE);
  108. (void)mvwaddch(navfixwin, 4, 38, ACS_DEGREE);
  109. (void)wmove(navfixwin, 5, 11);
  110. (void)wprintw(navfixwin, "%6.2lfm/s %5.1lf %6.2lfm/s climb",
  111. speed, track, climb);
  112. (void)mvwaddch(navfixwin, 5, 27, ACS_DEGREE);
  113. (void)wmove(navfixwin, 7, 11);
  114. (void)wprintw(navfixwin, "%04u-%02u-%02u %02u:%02u:%02u",
  115. year, mon, day, hour, min, sec);
  116. (void)wmove(navfixwin, 8, 11);
  117. (void)wprintw(navfixwin, "%04u+%010.3lf", gps_week, tow / 1000.0);
  118. (void)wmove(navfixwin, 8, 33);
  119. d = (tow / 1000) / 86400;
  120. tod = (tow / 1000) - (d * 86400);
  121. sec = (unsigned short)tod % 60;
  122. min = (unsigned short)(tod / 60) % 60;
  123. hour = (unsigned short)tod / 3600;
  124. (void)wprintw(navfixwin, "%1d %02d:%02d:%02d", d, hour, min, sec);
  125. (void)wmove(navfixwin, 10, 9);
  126. (void)wprintw(navfixwin, "%-5.1f", hdop);
  127. (void)wmove(navfixwin, 10, 18);
  128. (void)wprintw(navfixwin, "%-5.1f", vdop);
  129. (void)wmove(navfixwin, 10, 27);
  130. (void)wprintw(navfixwin, "%-5.1f", pdop);
  131. (void)wmove(navfixwin, 10, 36);
  132. (void)wprintw(navfixwin, "%-5.1f", tdop);
  133. (void)wmove(navfixwin, 10, 45);
  134. (void)wprintw(navfixwin, "%-5.1f", gdop);
  135. (void)wmove(navfixwin, 11, 6);
  136. {
  137. char prn[4], satlist[38];
  138. unsigned long i; // unsigned long just in case ints are 32-bit
  139. satlist[0] = '\0';
  140. for (i = 0; i < 32; i++) {
  141. if (svlist & (1 << i)) {
  142. (void)snprintf(prn, 4, "%lu ", i + 1);
  143. (void)strlcat(satlist, prn, sizeof(satlist));
  144. }
  145. }
  146. (void)wprintw(navfixwin, "%02d = %-38s", nsv, satlist);
  147. }
  148. (void)wnoutrefresh(navfixwin);
  149. }
  150. static void display_itk_prnstatus(unsigned char *buf, size_t len)
  151. {
  152. int i, nchan;
  153. if (len < 62)
  154. return;
  155. nchan = (int)getleu16(buf, 7 + 50);
  156. if (nchan > MAX_NR_VISIBLE_PRNS)
  157. nchan = MAX_NR_VISIBLE_PRNS;
  158. for (i = 0; i < nchan; i++) {
  159. int off = 7 + 52 + 10 * i;
  160. unsigned short fl;
  161. unsigned char ss, prn, el, az;
  162. fl = (unsigned short)getleu16(buf, off);
  163. ss = (unsigned char)getleu16(buf, off + 2) & 0xff;
  164. prn = (unsigned char)getleu16(buf, off + 4) & 0xff;
  165. el = (unsigned char)getles16(buf, off + 6) & 0xff;
  166. az = (unsigned char)getles16(buf, off + 8) & 0xff;
  167. (void)wmove(satwin, i + 2, 4);
  168. (void)wprintw(satwin, "%3d %3d %2d %02d %04x %c",
  169. prn, az, el, ss, fl,
  170. (fl & PRN_FLAG_USE_IN_NAV) ? 'Y' : ' ');
  171. }
  172. for (; i < MAX_NR_VISIBLE_PRNS; i++) {
  173. (void)wmove(satwin, (int)i + 2, 4);
  174. (void)wprintw(satwin, " ");
  175. }
  176. (void)wnoutrefresh(satwin);
  177. return;
  178. }
  179. static void italk_update(void)
  180. {
  181. unsigned char *buf;
  182. size_t len;
  183. unsigned char type;
  184. buf = session.lexer.outbuffer;
  185. len = session.lexer.outbuflen;
  186. type = (unsigned char)getub(buf, 4);
  187. switch (type) {
  188. case ITALK_NAV_FIX:
  189. display_itk_navfix(buf, len);
  190. break;
  191. case ITALK_PRN_STATUS:
  192. display_itk_prnstatus(buf, len);
  193. break;
  194. default:
  195. break;
  196. }
  197. }
  198. static int italk_command(char line[]UNUSED)
  199. {
  200. return COMMAND_UNKNOWN;
  201. }
  202. static void italk_wrap(void)
  203. {
  204. (void)delwin(satwin);
  205. return;
  206. }
  207. const struct monitor_object_t italk_mmt = {
  208. .initialize = italk_initialize,
  209. .update = italk_update,
  210. .command = italk_command,
  211. .wrap = italk_wrap,
  212. .min_y = 23,.min_x = 80, /* size of the device window */
  213. .driver = &driver_italk,
  214. };
  215. #endif