-
Notifications
You must be signed in to change notification settings - Fork 1
/
TSIP.h
283 lines (261 loc) · 10.2 KB
/
TSIP.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/*=============================================================================*
* TSIP.h
*
* TSIP is Trimble's interface software command set
*
* TSIP packet structure is the same for both commands and reports.
* The packet format is:
* <DLE> <id> <data string bytes> <DLE> <ETX>
* Where:
* <DLE> is the byte 0x10
* <ETX> is the byte 0x03
* <id> is a packet identifier byte, which can have any value excepting
* <ETX> and <DLE>.
* The bytes in the data string can have any value.
* To prevent confusion with the frame sequences <DLE> <id> and <DLE> <ETX>,
* every <DLE> byte in the data string is preceded by an extra <DLE> byte
* ('stuffing'). These extra <DLE> bytes must be added ('stuffed') before
* sending a packet and removed after receiving the packet. Notice that a
* simple <DLE> <ETX> sequence does not necessarily signify the end of the
* packet, as these can be bytes in the middle of a data string.
* The end of a packet is <ETX> preceded by an odd number of <DLE> bytes.
*
* Multiple-byte numbers (integer, float, and double) follow the
* ANSI / IEEE Std. 754 IEEE Standard for binary Floating-Point Arithmetic.
* They are sent most-significant byte first.
* Note that switching the byte order will be required in Intel-based machines.
*
* The data types used in the ThunderBolt TSIP are defined below.
* UINT8 - An 8 bit unsigned integer (0 to 255).
* SINT8 - An 8 bit signed integer (-128 to 127).
* INT16 - A 16 bit unsigned integer (0 to 65,535).
* SINT16 - A 16 bit signed integer (-32,768 to 32,767).
* UINT32 - A 32 bit unsigned integer (0 to 4,294,967,295)
* SINT32 - A 32 bit signed integer (-2,147,483,648 to 2,147,483,647).
* Single Float (4 bytes) (3.4x10-38 to 1.7x10+38) (24 bit precision)
* Double Float (8 bytes) (1.7x10-308 to 3.4x10+308) (53 bit precision)
*
* Note: Default serial port settings are: 9600, 8-none-1
*
*==============================================================================*/
/*=============================================================================*
* Report Packet 0x8F-AB Primary Timing Packet
*
* Byte Bit Item Type Value Description
* ==== ====== =============== ======= ======= ===============================
* 0 Subcode UINT8 0xAB
* 1-4 Time of Week UINT32 GPS seconds of week
* 5-6 Week Number UINT16 GPS Week Number (see above)
* 7-8 UTC Offset SINT16 UTC Offset (seconds) GPS Time
* 9 Timing Flag Bits
* 0 0 GPS Time
* 1 UTC Time
* 1 0 GPS PPS
* 1 UTC PPS
* 2 0 time is set
* 1 time is not set
* 3 0 have UTC info
* 1 does not have UTC info
* 4 0 time from GPS
* 1 time from user
* 10 Seconds UINT8 0-59 (60 for UTC leap second event)
* 11 Minutes UINT8 0-59 Minutes of Hour
* 12 Hours UINT8 0-23 Hour of Day
* 13 Day of Month UINT8 1-31 Day of Month
* 14 Month UINT8 1-12 Month of Year
* 15-16 Year UINT16 Four digits of Year (e.g. 1998)
*
* Notes:
* 1) multi-byte data is sent most significant byte first
* 2) byte position refers to the data packet (<DLE> and <ID> removed)
*==============================================================================*/
/*=============================================================================*
* Report Packet 0x8F-AC Supplemental Timing Packet
*
* Byte Bit Item Type Value Description
* ==== ====== =============== ======= ======= ===============================
* 0 Subcode UINT8 0xAC
* 1 Receiver Mode UINT8 0 Automatic (2D/3D)
* 1 Single Satellite (Time)
* 3 Horizontal (2D)
* 4 Full Position (3D)
* 5 DGPS Reference
* 6 Clock Hold (2D)
* 7 Overdetermined Clock
* 2 Disciplining Mode UINT8 0 Normal
* 1 Power-Up
* 2 Auto Holdover
* 3 Manual Holdover
* 4 Recovery
* 5 Not Used
* 6 Disciplining disabled
* 3 Self-Survey UINT 8 0-100% Progress
* 4-7 Holdover Duration UINT 32 seconds
* 8-9 Critical Alarms UINT16 bit
* 0 ROM checksum error
* 1 RAM check has failed
* 2 Power supply failure
* 3 FPGA check has failed
* 4 Oscillator control voltage at rail
* 10-11 Minor Alarms UINT16 bit
* 0 Control voltage is near rail
* 1 Antenna open
* 2 Antenna shorted
* 3 Not tracking satellites
* 4 Not disciplining oscillator
* 5 Survey-in progress
* 6 No stored position
* 7 Leap second pending
* 8 In test mode
* 12 GPS Decoding UINT8 0 Doing fixes
* 1 Don’t have GPS time
* 3 PDOP is too high
* 8 No usable sats
* 9 Only 1 usable sat
* 10 Only 2 usable sats
* 11 Only 3 usable sats
* 12 The chosen sat is unusable
* 16 TRAIM rejected the fix
* 13 Disciplining Status UINT8 0 Phase locking
* 1 Oscillator warming up
* 2 Frequency locking
* 3 Placing PPS
* 4 Initializing loop filter
* 5 Compensating OCXO
* 6 Inactive
* 7 Not used
* 8 Recovery mode
* 14 Spare Status 1 UINT8 0
* 15 Spare Status 2 UINT8 0
* 16-19 PPS Offset Single Estimate of UTC/GPS offset (ns)
* 20-23 10 MHz Offset Single Estimate of UTC/GPS offset(ppb)
* 24-27 DAC Value UINT32 Offset binary (0x00 - 0xFFFFF)
* 28-31 DAC Voltage Single Volts
* 32-35 Temperature Single degrees C
* 36-43 Latitude Double radians
* 44-51 Longitude Double radians
* 52-59 Altitude Double meters
* 60-67 Spare Future expansion
* Receive COM 8 Packet ID: 8F-AC Data Length: 68
* AC
* 07
* 00
* 00
* 00 00 00 00
* 00 00
* 00 80
* 00
* 00
* 00
* 00
* BF A6 07 4B
* 3C 9F 82 FA
* 00 08 9E B9 Dac Value 89eb9
* 3E C6 67 40 dac voltage .387516
* 42 21 22 43
* 3F E9 16 02 98 F4 95 06
* BF F9 F5 46 8F 0A D0 12
* 40 72 2C 86 63 97 C0 00
* 00 00 00 00 00 00 00 01
*==============================================================================*/
#include <stdint.h>
#define NUM_MODES 17
//#define MSG_LEN 18
/* ===== GPS Stuff ===== */
enum {
WAIT_FOR_START,
WAIT_FOR_DLE_ETX, // we have received a char that was not DLE or ETX
WAIT_FOR_ETX, // we have received char+DLE, waiting for ETX
WAIT_FOR_DLE, // we have received char+DLE+ETX, waiting for DLE or else exit
WAIT_FOR_ID,
WAIT_FOR_END_MSG,
SEND_HDR,
SEND_MSG,
SEND_ETX
};
#define ETX 0x03
#define DLE 0x10
#define IO_BUF_ID_INDEX 1
#define IO_BUF_ID2_INDEX 2
#define SUPERPACKET 0x8F
#define PRIMARY_TIMING_PCKT 0xAB
#define PRIMARY_TIMING_PCKT_LEN 17
#define SUPPLEMENTAL_TIMING_PCKT 0xAC
#define SUPPLEMENTAL_TIMING_PCKT_LEN 60
/* ===== TSIP stuff ===== */
char Month[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
// NUM_MODES is defined in TSIP.h
// MSG_LEN is defined in general.h
uint8_t DIM[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
char RxMode[8][MSG_LEN] = {
"RX: Auto 2D/3D",
"RX: Single Sat",
"RX: Unknown!!!",
"RX: Horiz. (2D)",
"RX: Full Pos(3D)",
"RX: DGPS Refer",
"RX: Clk Hold(2D)",
"RX: Overdet Clk" // Normal mode
};
char DiscMode[7][MSG_LEN] = {
"MODE: Normal", // Normal mode
"MODE: Power-Up",
"MODE: Auto Hldvr",
"MODE: Man. Hldvr",
"MODE: Recovery",
"MODE: Unknown!!!",
"MODE: Disabled"
};
char GPSDecodeStatus[17][MSG_LEN] = {
"GPS: Doing Fixes", // Normal Mode
"GPS: No GPS Time",
"GPS: Unknown!!!",
"GPS: PDOP to HI",
"GPS: Unknown!!!",
"GPS: Unknown!!!",
"GPS: Unknown!!!",
"GPS: Unknown!!!",
"GPS: No Use SATS",
"GPS: Only 1 SAT",
"GPS: Only 2 SATS",
"GPS: Only 3 SATS",
"GPS: SAT Unusabl",
"GPS: Unknown!!!",
"GPS: Unknown!!!",
"GPS: Unknown!!!",
"GPS: TRIAM Rejec"
};
char DiscActivity[9][MSG_LEN] = {
"ACT: Phase Lock",
"ACT: Osc Warmup",
"ACT: Freq Lock",
"ACT: Placing PPS",
"ACT: Init. loop",
"ACT: Compensate",
"ACT: Inactive",
"ACT: Unknown!!!",
"ACT: Recovery LP"
};
/* ----- typedef and union used to convert byte to uint or int ----- */
typedef union int_t INTType;
typedef union int_t UINTType;
union int_t {
int i;
unsigned int u;
struct {
uint8_t lo;
uint8_t hi;
}b;
};
typedef union long_t FLOATType;
typedef union long_t LONGType;
union long_t {
float f;
uint32_t l;
struct {
uint8_t llo;
uint8_t lo;
uint8_t hi;
uint8_t hhi;
}b;
};