172414584ccad8c2fc301aeae609452200a473c6
[olsrd.git] / lib / pud / src / dump.c
1 #include "dump.h"
2
3 #ifdef PUD_DUMP_GPS_PACKETS
4
5 /* Plugin includes */
6 #include "pud.h"
7
8 /* OLSRD includes */
9 #include "olsr.h"
10
11 /* System includes */
12 #include <string.h>
13
14 /** the number of bytes/characters per line */
15 #define PUD_DUMP_GPS_PACKETS_CHARSPERLINE 16
16
17 /**
18  Prints a packet in hex/ascii.
19
20  @param packet
21  a pointer to the packet
22  @param length
23  the number of bytes in the packet
24  */
25 void dump_packet(unsigned char* packet, unsigned int length) {
26         unsigned int packetPos;
27         unsigned int linePos;
28         unsigned char line[PUD_DUMP_GPS_PACKETS_CHARSPERLINE + 1];
29
30         for (packetPos = 0; packetPos < length; packetPos
31                         += PUD_DUMP_GPS_PACKETS_CHARSPERLINE) {
32                 unsigned int copyLength = PUD_DUMP_GPS_PACKETS_CHARSPERLINE;
33                 if ((packetPos + copyLength) > length) {
34                         copyLength = length - packetPos;
35                 }
36
37                 memcpy(&line[0], &packet[packetPos], copyLength);
38                 line[copyLength] = '\0';
39
40                 olsr_printf(0, "%s: ", PUD_PLUGIN_ABBR);
41                 for (linePos = 0; linePos < PUD_DUMP_GPS_PACKETS_CHARSPERLINE; linePos++) {
42                         if (linePos >= copyLength) {
43                                 olsr_printf(0, "   ");
44                         } else {
45                                 olsr_printf(0, "%2.2X ", packet[packetPos + linePos]);
46                                 if ((line[linePos] < 32) || (line[linePos] > 126)) {
47                                         line[linePos] = '.';
48                                 }
49                         }
50                 }
51                 olsr_printf(0, " %s\n", line);
52         }
53 }
54
55 #endif /* PUD_DUMP_GPS_PACKETS */
56
57 #ifdef PUD_DUMP_NMEA
58
59 /* Plugin includes */
60
61 /* OLSRD includes */
62 #include "olsr.h"
63
64 /* System includes */
65 #include <nmea/info.h>
66 #include <nmea/sentence.h>
67
68 void dump_nmeaInfo(nmeaINFO * nmeaInfo, const char * prefix) {
69         olsr_printf(0,
70                         "%s (%p)\n" /* prefix */
71                         "  smask = %02x%s%s%s%s%s\n"
72                         "  utc   = %04u%02u%02u %02u:%02u:%02u.%02u\n"
73                         "  sig   = %s (%u)\n"
74                         "  fix   = %s (%u)\n"
75                         "  PDOP  = %fm\n"
76                         "  HDOP  = %fm\n"
77                         "  VDOP  = %fm\n"
78                         "  lat   = %f\n"
79                         "  lon   = %f\n"
80                         "  alt   = %f\n"
81                         "  speed = %f\n"
82                         "  track = %f\n"
83                         "  decl  = %f\n"
84                         "\n",
85                         prefix, nmeaInfo,
86                         nmeaInfo->smask,
87                         ((nmeaInfo->smask & GPGGA) != 0) ? " GPGGA" : "",
88                         ((nmeaInfo->smask & GPGSA) != 0) ? " GPGSA" : "",
89                         ((nmeaInfo->smask & GPGSV) != 0) ? " GPGSV" : "",
90                         ((nmeaInfo->smask & GPRMC) != 0) ? " GPRMC" : "",
91                         ((nmeaInfo->smask & GPVTG) != 0) ? " GPVTG" : "",
92                         (nmeaInfo->utc.year + 1900), nmeaInfo->utc.mon, nmeaInfo->utc.day,
93                         nmeaInfo->utc.hour, nmeaInfo->utc.min, nmeaInfo->utc.sec, nmeaInfo->utc.hsec,
94                         (nmeaInfo->sig == NMEA_SIG_BAD) ? "BAD" : (nmeaInfo->sig == NMEA_SIG_LOW) ? "LOW" : (nmeaInfo->sig == NMEA_SIG_MID) ? "MID" : (nmeaInfo->sig == NMEA_SIG_HIGH) ? "HIGH" : "UNKNOWN", nmeaInfo->sig,
95                         (nmeaInfo->fix == NMEA_FIX_BAD) ? "BAD" : (nmeaInfo->fix == NMEA_FIX_2D) ? "2D" : (nmeaInfo->fix == NMEA_FIX_3D) ? "3D" : "UNKNOWN", nmeaInfo->fix,
96                         nmeaInfo->PDOP,
97                         nmeaInfo->HDOP,
98                         nmeaInfo->VDOP,
99                         nmeaInfo->lat,
100                         nmeaInfo->lon,
101                         nmeaInfo->elv,
102                         nmeaInfo->speed,
103                         nmeaInfo->direction,
104                         nmeaInfo->declination
105         );
106 }
107
108 #endif /* PUD_DUMP_NMEA */