-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrim.cpp
251 lines (189 loc) · 4.21 KB
/
trim.cpp
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
#include "predef.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <startnet.h>
#include <ucos.h>
#include <udp.h>
#include <string.h>
#include "bd960.h"
#include "flags.h"
typedef struct
{
unsigned char stx;
unsigned char status;
unsigned char pt40;
unsigned char len1;
unsigned char tn;
unsigned char pg;
unsigned char mpg;
unsigned char data;
}__attribute__(( packed) ) rec40;
typedef struct
{
unsigned char type;
unsigned char len2;
double lattitude;
double longitude;
double ht;
} __attribute__(( packed) ) rec2;
typedef struct
{
unsigned char type;
unsigned char len2;
unsigned long msec;
unsigned short week;
unsigned char nsat;
unsigned char flag1;
unsigned char flag2;
unsigned char seq;
} __attribute__(( packed) ) rec1;
typedef struct
{
unsigned char type;
unsigned char len2;
double ECEF_X;
double ECEF_Y;
double ECEF_Z;
} __attribute__(( packed) ) rec3;
typedef struct
{
unsigned char type;
unsigned char len2;
unsigned char flags;
float hspeed;
float head;
float vv;
} __attribute__(( packed) ) rec8;
typedef struct
{
unsigned char type;
unsigned char len2;
float rms_error;
float sigma_east;
float sigma_north;
float covaren;
float sigma_up;
float semi_major;
float semi_minor;
float orientaion;
float variance;
unsigned short epoch;
} __attribute__(( packed) ) rec12;
volatile CombinedTrimGps Gps_Result;
volatile CombinedTrimGps TGps_Result;
void TickleDevice(WORD portnum, IPADDR ipaddr)
{
UDPPacket pkt;
pkt.SetSourcePort( portnum );
pkt.SetDestinationPort( portnum );
pkt.AddDataByte( 0 );
pkt.Send( ipaddr );
}
unsigned char * ParseRecord(unsigned char * cp, unsigned int & len)
{
if (cp[1]==0x03) return NULL; //End
unsigned int cplen=cp[1]+2;
if(cplen>=len) return NULL;
len-=cplen;
switch(cp[0])
{
case 1:
{rec1 * r1=(rec1*)cp;
TGps_Result.nsat=r1->nsat;
TGps_Result.week=r1->week;
TGps_Result.flag1=r1->flag1;
TGps_Result.flag2=r1->flag2;
}
break;
case 2:
{rec2 * r2=(rec2*)cp;
TGps_Result.lattitude=r2->lattitude;
TGps_Result.longitude=r2->longitude;
TGps_Result.ht=r2->ht;
}
break;
case 3:
{rec3 * r3=(rec3*)cp;
TGps_Result.ECEF_X=r3->ECEF_X;
TGps_Result.ECEF_Y=r3->ECEF_Y;
TGps_Result.ECEF_Z=r3->ECEF_Z;
}
case 8:
{rec8 * r8=(rec8*)cp;
TGps_Result.hspeed=r8->hspeed;
TGps_Result.head=r8->head;
TGps_Result.vv=r8->vv;
}
break;
case 12:
{
//rec12 * r12=(rec12*)cp;
}
break;
}
cp+=cplen;
return cp;
}
volatile int ntLastStart;
void WriteObject(BYTE id, volatile void * vdata, int olen, int allways_send);
/*-------------------------------------------------------------------
* This task will wait for incoming UDP packets and process them.
-------------------------------------------------------------------*/
void GPSUdp( void *pd )
{
// Create FIFO to store incoming packets and initialize it
OS_FIFO fifo;
OSFifoInit( &fifo );
IPADDR ipaddr = AsciiToIp("10.1.1.40");
// Register to listen for UDP packets on port number 'port'
RegisterUDPFifo( 5017, &fifo );
TickleDevice(5017,ipaddr);
int nn=0;
while ( 1 )
{
// We construct a UDP packet object using the FIFO.
// This constructor will only return when we have received a packet
UDPPacket upkt( &fifo,5 /* Replace this 0 with a tick count to have a time out delat */ );
// Did we get a valid packet or just time out?
if ( upkt.Validate() )
{
bzero((void *)&TGps_Result,sizeof(TGps_Result));
unsigned int len = upkt.GetDataSize();
if(len >= sizeof(rec40) )
{
rec40 * pr=(rec40 *) upkt.GetDataBuffer();
unsigned char * cp=&pr->data;
do
{
cp=ParseRecord(cp,len);
}
while(cp);
}
nn++;
if(nn==256)
{
nn=0;
TickleDevice(5017,ipaddr);
}
if(TGps_Result.lattitude)
{
OSLock();
memcpy((void *)&Gps_Result,(void *)&TGps_Result,sizeof(TGps_Result));
OSUnlock();
OSFlagSet(&DataFlag,NEW_GPS);
}
}
else
TickleDevice(5017,ipaddr);
}
}
bool GpsValid(volatile CombinedTrimGps & g)
{
if((g.flag1 & 0x05)==5) return true;
return false;
}
void StartGpsProcess(BYTE prio)
{
OSSimpleTaskCreatewName(GPSUdp,prio,"GPS UDP");
}