1 #ifndef _PUD_WIREFORMAT_H_
2 #define _PUD_WIREFORMAT_H_
5 #include "olsr_protocol.h"
15 /** The version of the wire format */
16 #define PUD_WIRE_FORMAT_VERSION 0
20 * We use the smask of nmeaINFO and the flags below on top of that
23 /** Flags that the GPS information contains the nodeId */
24 #define PUD_FLAGS_ID 0x80
30 /** The number of bits for the time field */
31 #define PUD_TIME_BITS 17
37 /** The number of bits for the latitude field */
38 #define PUD_LATITUDE_BITS 28
40 /** The maximum size of the string representation of the latitude
41 * sign [0,90] [0,59] dot [0,59] [0,999] */
42 #define PUD_TX_LATITUDE_DIGITS (1 + 2 + 2 + 1 + 2 + 3)
44 /** The number of decimals of the latitude in the transmit sentence */
45 #define PUD_TX_LATITUDE_DECIMALS "5"
51 /** The number of bits for the longitude field */
52 #define PUD_LONGITUDE_BITS 27
54 /** The maximum size of the string representation of the longitude
55 * sign [0,180] [0,59] dot [0,59] [0,999] */
56 #define PUD_TX_LONGITUDE_DIGITS (1 + 3 + 2 + 1 + 2 + 3)
58 /** The number of decimals of the longitude in the transmit sentence */
59 #define PUD_TX_LONGITUDE_DECIMALS "5"
65 /** The number of bits for the altitude field */
66 #define PUD_ALTITUDE_BITS 16
68 /** The minimum altitude */
69 #define PUD_ALTITUDE_MIN (-400)
71 /** The maximum altitude */
72 #define PUD_ALTITUDE_MAX (((1 << PUD_ALTITUDE_BITS) - 1) + PUD_ALTITUDE_MIN)
74 /** The maximum size of the string representation of the altitude */
75 #define PUD_TX_ALTITUDE_DIGITS 6
81 /** The number of bits for the speed field */
82 #define PUD_SPEED_BITS 12
84 /** The maximum speed value */
85 #define PUD_SPEED_MAX ((1 << PUD_SPEED_BITS) - 1)
87 /** The maximum size of the string representation of the speed */
88 #define PUD_TX_SPEED_DIGITS 4
94 /** The number of bits for the track angle field */
95 #define PUD_TRACK_BITS 9
97 /** The maximum size of the string representation of the track angle */
98 #define PUD_TX_TRACK_DIGITS 3
104 /** The number of bits for the HDOP field */
105 #define PUD_HDOP_BITS 11
107 /** The HDOP resolution (in m) */
108 #define PUD_HDOP_RESOLUTION (0.1)
110 /** The maximum HDOP value (in m) */
111 #define PUD_HDOP_MAX (((1 << PUD_HDOP_BITS) - 1) * PUD_HDOP_RESOLUTION)
113 /** The maximum size of the string representation of the HDOP */
114 #define PUD_TX_HDOP_DIGITS 5
116 /** The number of decimals of the HDOP in the transmit sentence */
117 #define PUD_TX_HDOP_DECIMALS "3"
123 /** nodeIdType legal values */
124 typedef enum _NodeIdType {
125 /** MAC address, 48 bits, 6 bytes */
126 PUD_NODEIDTYPE_MAC = 0,
128 /** MSISDN number, 15 digits, 50 bits, 7 bytes */
129 PUD_NODEIDTYPE_MSISDN = 1,
131 /** TETRA number, 17 digits, 57 bits, 8 bytes */
132 PUD_NODEIDTYPE_TETRA = 2,
134 /** DNS name, variable length */
135 PUD_NODEIDTYPE_DNS = 3,
137 /** IPv4 address, 32 bits, 4 bytes */
138 PUD_NODEIDTYPE_IPV4 = 4,
140 /** IPv6 address, 128 bits, 16 bytes */
141 PUD_NODEIDTYPE_IPV6 = 6,
143 /** Brandweer number, 7 digits, 24 bits, 3 bytes */
144 PUD_NODEIDTYPE_192 = 192,
146 /** Ambulance number, 6 digits, 20 bits, 3 bytes */
147 PUD_NODEIDTYPE_193 = 193,
149 /** Number in the range [1, 8191], 4 digits, 13 bits, 2 bytes */
150 PUD_NODEIDTYPE_194 = 194
153 /** The maximum size of the string representation of the nodeIdType */
154 #define PUD_TX_NODEIDTYPE_DIGITS 3
160 /** The maximum size of the string representation of the nodeId */
161 #define PUD_TX_NODEID_BUFFERSIZE 1023
164 * Wire Format Structures
167 /** Sub-format GPS information, 120 bits = 15 bytes */
168 typedef struct _GpsInfo {
169 uint32_t time :PUD_TIME_BITS; /**< the number of seconds since midnight, ALWAYS present */
170 uint32_t lat :PUD_LATITUDE_BITS; /**< latitude */
171 uint32_t lon :PUD_LONGITUDE_BITS; /**< longitude */
172 uint32_t alt :PUD_ALTITUDE_BITS; /**< altitude */
173 uint32_t speed :PUD_SPEED_BITS; /**< speed */
174 uint32_t track :PUD_TRACK_BITS; /**< track angle */
175 uint32_t hdop :PUD_HDOP_BITS; /**< HDOP */
176 }__attribute__((__packed__)) GpsInfo;
178 /** Sub-format Node information, 8 + variable bits = 1 + variable bytes */
179 typedef struct _NodeInfo {
180 uint8_t nodeIdType; /**< the nodeIdType */
181 unsigned char nodeId; /**< placeholder for variable length nodeId string */
182 }__attribute__((__packed__)) NodeInfo;
184 /** Complete format, 8+8+8+120+(8+variable) bits = 18+(1+variable) bytes*/
185 typedef struct _PudOlsrWireFormat {
186 uint8_t version; /**< the version of the sentence */
187 uint8_t validityTime; /**< the validity time of the sentence */
188 uint8_t smask; /**< mask signaling the contents of the sentence */
189 GpsInfo gpsInfo; /**< the GPS information (MANDATORY) */
190 NodeInfo nodeInfo; /**< placeholder for node information (OPTIONAL) */
191 }__attribute__((__packed__)) PudOlsrWireFormat;
193 /** The size of the wire format, minus the size of the node information */
194 #define PUD_OLSRWIREFORMATSIZE (sizeof(PudOlsrWireFormat) - sizeof(NodeInfo))
196 /* ************************************************************************
198 * ************************************************************************ */
200 unsigned char getValidityTimeForOlsr(unsigned long long validityTime);
201 unsigned long getValidityTimeFromOlsr(unsigned char internal);
203 unsigned long getTimeForOlsr(int hour, int min, int sec);
204 void getTimeFromOlsr(uint32_t olsrTime, struct tm *nowStruct);
206 unsigned long getLatitudeForOlsr(double infoLat);
207 double getLatitudeFromOlsr(uint32_t olsrLat);
209 unsigned long getLongitudeForOlsr(double infoLon);
210 double getLongitudeFromOlsr(uint32_t olsrLon);
212 long getAltitudeForOlsr(double infoElv);
213 long getAltitudeFromOlsr(uint32_t olsrAlt);
215 long getSpeedForOlsr(double infoSpeed);
216 unsigned long getSpeedFromOlsr(uint32_t olsrSpeed);
218 long getTrackForOlsr(double infoTrack);
219 unsigned long getTrackFromOlsr(uint32_t olsrTrack);
221 long getHdopForOlsr(double infoHdop);
222 double getHdopFromOlsr(uint32_t olsrHdop);
224 NodeIdType getNodeIdType(int ipVersion, union olsr_message * olsrMessage);
226 #endif /* _PUD_WIREFORMAT_H_ */