-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTestModule.cpp
324 lines (305 loc) · 11.3 KB
/
TestModule.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
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#include <unistd.h>
#include <iostream>
#include <iomanip>
#include <thread>
#include <csignal>
#include <sys/time.h>
#include "RPiGPS/RPiGPS.hpp"
#include "RPiSBus/RPiSBus.hpp"
#include "RPiIBus/RPiIBus.hpp"
#include "RPiFlow/RPiFlow.hpp"
#include "CRSF/CRSFUartRC.hpp"
int signalIn = 0;
int TimestartUpLoad = 0;
int GetTimestamp()
{
struct timeval tv;
gettimeofday(&tv, NULL);
return ((tv.tv_sec * (uint64_t)1000000 + tv.tv_usec));
}
int main(int argc, char *argv[])
{
int argvs;
TimestartUpLoad = GetTimestamp();
while ((argvs = getopt(argc, argv, "vhi:s:g:G:c:C:f:R:")) != -1)
{
switch (argvs)
{
case 'v':
std::cout << "[RPiSingleAPM] version 1.0.f Beta , Acess By TSKangetsu\n"
<< " checkout : https://github.com/TSKangetsu/RPiSingleAPM \n";
break;
case 'h':
std::cout << "-i /dev/ttyS0 for Ibus\n"
<< "-s /dev/ttyS0 for Sbus\n"
<< "-g /dev/ttyS0 for M8NGPS\n"
<< "-G /dev/ttyS0 for M8NGPS Parsed Data\n"
<< "-c for QML5883 Compass\n"
<< "-f /dev/ttyS0 for MatekSys 3901-L0X\n";
break;
case 'i':
{
int ChannelsData[14];
int sbusData[32];
int lose;
long int time;
long int timee;
Ibus *IbusT;
IbusT = new Ibus(optarg);
while (true)
{
time = GetTimestamp() - TimestartUpLoad;
lose = IbusT->IbusRead(ChannelsData, 4000, 2);
if (lose != -1)
{
for (size_t i = 0; i < 14; i++)
{
std::cout << ChannelsData[i] << " ";
}
timee = GetTimestamp() - TimestartUpLoad;
std::cout << "T: " << timee - time;
std::cout << " \n";
}
}
}
break;
case 's':
{
long int time;
long int timee;
int ChannelsData[16];
int sbusData[25];
int lose;
Sbus newSBUS(optarg);
while (true)
{
time = GetTimestamp() - TimestartUpLoad;
lose = newSBUS.SbusRead(ChannelsData, 4700, 2);
if (lose != -1)
{
std::cout << lose << " ";
for (size_t i = 0; i < 16; i++)
{
std::cout << ChannelsData[i] << " ";
}
timee = GetTimestamp() - TimestartUpLoad;
std::cout << timee - time << " ";
std::cout << "\n";
}
}
}
break;
case 'g':
{
long int time;
long int timee;
std::string GPSData;
std::string dataP[10];
GPSUart myUart(optarg);
myUart.GPSReOpen();
while (true)
{
if (myUart.GPSCheckDataAvaliable())
{
long int timees = GetTimestamp() - TimestartUpLoad;
std::cout << "\nlast frame time Get : " << timees - time << "\n";
myUart.GPSRead(GPSData);
std::cout << GPSData;
time = GetTimestamp() - TimestartUpLoad;
}
usleep(180000);
}
}
break;
case 'G':
{
long int time;
long int timee;
std::string GPSData;
GPSUartData mydata;
GPSUart *myUart = new GPSUart(optarg);
myUart->GPSReOpen();
while (true)
{
time = GetTimestamp() - TimestartUpLoad;
mydata = myUart->GPSParse();
std::cout << "satillites: " << mydata.satillitesCount << " ";
std::cout << "DataError: " << mydata.DataUnCorrect << " ";
std::cout << "lat: " << std::setprecision(9) << mydata.lat << " ";
std::cout << "lng: " << std::setprecision(10) << mydata.lng << " \n";
std::cout << "ALT: " << std::setprecision(4) << mydata.GPSAlititude << "M "
<< "HDOP " << std::setprecision(4) << mydata.HDOP << " "
<< "Quailty: " << mydata.GPSQuality << " "
<< "GeoidalSP: " << mydata.GPSGeoidalSP << "\n";
long int timees = GetTimestamp() - TimestartUpLoad;
std::cout << "last frame time : " << timees - time << "\n";
timee = GetTimestamp() - TimestartUpLoad;
if ((timee - time) > 200000)
usleep(1500);
else
usleep(200000 - (timee - time));
}
}
break;
case 'C':
{
std::signal(SIGINT, [](int signal)
{ signalIn = signal; });
int rawx = 0;
int rawy = 0;
int rawz = 0;
int calibration[10];
calibration[0] = -5000;
calibration[2] = -5000;
calibration[4] = -5000;
calibration[1] = 5000;
calibration[3] = 5000;
calibration[5] = 5000;
int flip[3] = {0, 0, 0};
GPSI2CCompass mycompassTest(optarg, 0x0d, COMPASS_QMC5883L, flip);
mycompassTest.CompassCaliInit();
while (true)
{
mycompassTest.CompassGetRaw(rawx, rawy, rawz);
std::cout << "X:" << std::setw(7) << std::setfill(' ') << rawx << " "
<< "Y:" << std::setw(7) << std::setfill(' ') << rawy << " "
<< "Z:" << std::setw(7) << std::setfill(' ') << rawz << " "
<< "V:" << std::setw(7) << std::setfill(' ') << (int)sqrt(rawx * rawx + rawy * rawy + rawz * rawz) << " \n";
mycompassTest.CompassCalibration(true, calibration);
usleep(50 * 1000);
if (signalIn == SIGINT)
break;
}
std::cout << "\n\n";
std::cout << "XMAX: " << calibration[0] << "\n";
std::cout << "XMIN: " << calibration[1] << "\n";
std::cout << "YMAX: " << calibration[2] << "\n";
std::cout << "YMIN: " << calibration[3] << "\n";
std::cout << "ZMAX: " << calibration[4] << "\n";
std::cout << "ZMIN: " << calibration[5] << "\n";
}
break;
case 'c':
{
int rawx = 0;
int rawy = 0;
int rawz = 0;
double angleUnfix = 0;
int flip[3] = {0, 0, 0};
GPSI2CCompass mycompassTest(optarg, 0x0d, COMPASS_QMC5883L, flip);
mycompassTest.CompassApply(1537, 1106, 2597, 2268, 1488, 1090);
while (true)
{
mycompassTest.CompassGetRaw(rawx, rawy, rawz);
mycompassTest.CompassGetUnfixAngle(angleUnfix);
std::cout << "Angle: " << std::setw(7) << std::setfill(' ') << angleUnfix << "\n";
std::cout << "X:" << std::setw(7) << std::setfill(' ') << rawx << " "
<< "Y:" << std::setw(7) << std::setfill(' ') << rawy << " "
<< "Z:" << std::setw(7) << std::setfill(' ') << rawz << " \n";
usleep(50 * 1000);
}
}
break;
case 'f':
{
long int time;
long int timee;
int x;
int y;
int alt;
int rfqulity;
int opqulity;
std::string myData;
MSPUartFlow myUart(optarg);
system("clear");
while (true)
{
std::cout << "\n";
std::cout << "\033[100A";
std::cout << "\033[K";
int Status = myUart.MSPDataRead(x, y, opqulity, alt, rfqulity);
if (Status > 0)
{
std::cout << "x:" << x << " \n";
std::cout << "y:" << y << " \n";
std::cout << "opquality:" << opqulity << " \n";
std::cout << "alt:" << alt << " \n";
std::cout << "rfquality:" << rfqulity << " \n";
std::cout << "Status:" << Status << " \n";
}
else
{
std::cout << "error frame recv\n";
}
timee = GetTimestamp() - TimestartUpLoad;
std::cout << "last frame time : " << timee - time << "\n";
time = GetTimestamp() - TimestartUpLoad;
if ((timee - time) > 35000)
usleep(50);
else
usleep(35000 - (timee - time));
}
}
break;
case 'R':
{
long int time;
long int timee;
CRSF test(optarg);
int channelData[50];
int st = 300;
//
std::thread telethread =
std::thread(
[&]
{
while (true)
{
test.CRSFTelemtry(
CRSFTelemetry::crsfFrameBatterySensor(
crsfProtocol::CRSF_SYNC_BYTE,
160, 160, 800, 80));
test.CRSFTelemtry(
CRSFTelemetry::crsfFrameAttitude(
crsfProtocol::CRSF_SYNC_BYTE,
50, 150, 300));
test.CRSFTelemtry(CRSFTelemetry::crsfFrameFlightMode(crsfProtocol::CRSF_SYNC_BYTE, "HELO"));
test.CRSFTelemtry(
CRSFTelemetry::crsfFrameVarioSensor(
crsfProtocol::CRSF_SYNC_BYTE, -20));
// FIXME: GPSheading should be unsign,but telemetry is sign, so..
test.CRSFTelemtry(CRSFTelemetry::crsfFrameGps(
crsfProtocol::CRSF_SYNC_BYTE,
100, -100, 10, 32800, 1005, 8));
usleep(200 * 1000);
}
});
while (true)
{
time = GetTimestamp() - TimestartUpLoad;
//
int retValue = test.CRSFRead(channelData);
if (retValue > 0)
{
for (size_t i = 0; i < 15; i++)
{
std::cout << test.rcToUs(channelData[i]) << " ";
}
std::cout << "\n";
}
else
{
std::cout << "error frame recived"
<< "\n";
}
//
timee = GetTimestamp() - TimestartUpLoad;
std::cout << "ret: " << retValue
<< " last frame time : " << timee - time << " "
<< "\n";
}
}
break;
}
}
}