-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlink.cpp
More file actions
859 lines (836 loc) · 30 KB
/
Copy pathlink.cpp
File metadata and controls
859 lines (836 loc) · 30 KB
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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
#include "link.h"
#include <QDebug>
#include <QObject>
#include <QDateTime>
#include <QDir>
#include <QRandomGenerator>
#include <QStandardPaths>
#include "datalogger.h"
#include "vedtp.h"
Link::Link()
{
joystickcontroller.initialize();
QObject::connect(this, &Link::_invokeWriteBytes, &receiver, &Receiver::senddatagram);
connect(&receiver,&Receiver::datareceived,this, &Link::send_data_to_process);
connect(this, &Link::data_processed, this,&Link::data_to_be_updated);
connect(&randomTimer, &QTimer::timeout,
this, &Link::generateRandomData);
heartbeatTimer = new QTimer(this);
connect(heartbeatTimer, &QTimer::timeout, this, &Link::send_heart_beat);
heartbeatTimer->start(static_cast<int>(round(1000.0 / FREQ_HEARTBEAT)));
joystickTimer = new QTimer(this);
connect(joystickTimer, &QTimer::timeout, this, &Link::sendJoystickData);
joystickTimer->start(static_cast<int>(round(1000.0 / FREQ_JOYSTICK)));
connect(&joystickcontroller, &JoystickController::leftaxisX,this,&Link::set_joystick_values);
connect(&joystickcontroller, &JoystickController::leftaxisY,this,&Link::set_joystick_values2);
connect(&joystickcontroller, &JoystickController::rightaxisX,this,&Link::set_joystick_values3);
connect(&joystickcontroller, &JoystickController::rightaxisY,this,&Link::set_joystick_values4);
create_directory();
}
Link::~Link()
{
}
void Link::send_heart_beat()
{
heartbeat_data.loggedState = NOT_LOGGED; // System logged state ( enum : Logged_State)
heartbeat_data.vehicleID = VEHICLE_ACR; // Vehicle type ( enum : Vehicle_ID)
heartbeat_data.armedState = DISARMED; // System armed state ( enum : ARM_State)
heartbeat_data.systemMode = MODE_HOLD; // System mode state (enum : System_Mode)
heartbeat_data.gps_fix = GPS_NO_FIX; // System gps fix (enum : GPSFixStatus)
heartbeat_data.failsafe_flags = FAILSAFE_NONE; // System failsafe flags (enum : Failsafe_flags)
heartbeat_data.system_health = SYSTEM_HEALTH_OK; // System health flag (enum : SystemHealth)
heartbeat_data.sensors_validity = 0;
heartbeat_data.uptime_ms =static_cast<uint32_t>(QDateTime::currentDateTime().toMSecsSinceEpoch());
VEDTP_Main heartbeat_send_packet; // for holding the main vedtp packet
uint8_t encode_status = encode_HEARTBEAT(&heartbeat_send_packet,&heartbeat_data); // encode heartbeat function from vedtp protocol library
//qDebug()<<heartbeat_send_packet.device;
if(encode_status)
{
mavlink_send_buffer(heartbeat_send_packet);
}
}
void Link::mavlink_send_buffer(VEDTP_Main vedtp_send)
{
//VEDTP_Main vedtp_send;
constexpr size_t bufferSize = sizeof(VEDTP_Main);
uint8_t buffer[bufferSize];
memcpy(buffer, &vedtp_send, bufferSize);
writeByteThreadSafe(reinterpret_cast<const char*>(buffer), bufferSize);
}
void Link::writeByteThreadSafe(const char *bytes, int length)
{
emit _invokeWriteBytes(QByteArray(bytes, length));
}
void Link::send_data(QByteArray datagram)
{
receiver.senddatagram(datagram);
}
void Link::send_data_to_process(QByteArray data)
{
static VEDTP_Main vedtp_recv; // declare vedtp_recv
uint8_t data_buffer_storage[VEDTP_HEADER_SIZE];
for(uint16_t i = 0; i < data.size(); i++){
uint8_t Vedtp_feed_status = feed_Me_Bytes(data[i], &vedtp_recv);
switch (Vedtp_feed_status){ // check the status for feeding bytes
case VEDTP_INCOMPLETE: // packet is not fully arrived yes, just wait and do nothing
break;
case VEDTP_COMPLETE: // got the complete vedtp packet
qDebug()<<"DEVICEID"<<vedtp_recv.device;
switch (vedtp_recv.device){ // check the device id
case DEVICE_HEARTBEAT: // if the device id matches the heartbeat device id,
// qDebug()<<"Packet has Heartbeat Data.\n";
decode_status = decode_HEARTBEAT(&vedtp_recv, &heartbeat_data); // decode the heartbeat packet
if(decode_status){ // if decode is success,
qDebug()<<"Heartbeat data decoded successfully.\n\n"; // print or process the data
qDebug()<<heartbeat_data.loggedState<<
heartbeat_data.vehicleID<<
heartbeat_data.armedState<<
heartbeat_data.systemMode<<
heartbeat_data.gps_fix<<
heartbeat_data.failsafe_flags<<
heartbeat_data.system_health<<
heartbeat_data.sensors_validity<<
heartbeat_data.uptime_ms;
emit data_processed(DEVICE_HEARTBEAT);
}
else {
qDebug()<<"Heartbeat data decoding failed, Check the parameters.\n";
}
break;
//gps
case DEVICE_AHRS:
qDebug()<<"Packet has AHRS Data.\n";
decode_status = decode_AHRS(&vedtp_recv, &ahrs_data); // decode the heartbeat packet
if(decode_status){ // if decode is success,
qDebug()<<"AHRS data decoded successfully.\n\n"; // print or process the data
qDebug()<<ahrs_data.yaw_deg<<
ahrs_data.pitch_deg<<
ahrs_data.roll_deg<<
ahrs_data.uptime_ms;
emit data_processed(DEVICE_AHRS);
}
else {
qDebug()<<"AHRS data decoding failed, Check the parameters.\n";
}
break;
//imu
case DEVICE_IMU:
qDebug()<<"Packet has IMU data";
decode_status = decode_IMU(&vedtp_recv, &IMU_data);
if(decode_status){
qDebug()<<"IMU data decoded successfully";
qDebug()<<IMU_data.acceleration
<<IMU_data.gyro
<<IMU_data.magnetic
<<IMU_data.rotationvector
<<IMU_data.linearacceleration
<<IMU_data.gravity
<<IMU_data.temperature_C
<<IMU_data.systemcalibration
<<IMU_data.gyrocalibration
<<IMU_data.accelerometercalibration
<<IMU_data.magnetometercalibration
<<IMU_data.uptime_ms;
emit data_processed(DEVICE_IMU);
}
else{
qDebug()<<"IMU data decoding failure";
}
break;
case DEVICE_EXTERNAL_ATMOSPHERE: // if the device id matches the heartbeat device id,
qDebug()<<"Packet has EXTERNAL ATMOSPHERE DATA.\n";
decode_status = decode_EXTERNAL_ATMOSPHERE(&vedtp_recv, &External_atmosphere_data); // decode the heartbeat packet
if(decode_status){ // if decode is success,
qDebug()<<"External data decoded successfully.\n\n"; // print or process the data
qDebug()<<External_atmosphere_data.temperature_C<<External_atmosphere_data.pressure_mbar<<
// Air/Water temp
External_atmosphere_data.depth_m<< // From pressure sensor (e.g., MS5837)
External_atmosphere_data.salinity_ppt; // Parts per thousand (marine salinity)
emit data_processed(DEVICE_EXTERNAL_ATMOSPHERE);
}
else {
qDebug()<<"external atmosphere data decoding failed, Check the parameters.\n";
}
break;
case DEVICE_POWER_HEALTH: // if the device id matches the heartbeat device id,
qDebug()<<"Packet has Power Health DATA.\n";
decode_status = decode_POWER_HEALTH(&vedtp_recv, &Power_health_data); // decode the heartbeat packet
if(decode_status){ // if decode is success,
qDebug()<<"Power Health data decoded successfully.\n\n"; // print or process the data
qDebug()<<Power_health_data.battery_voltage; // Parts per thousand (marine salinity)
emit data_processed(DEVICE_POWER_HEALTH);
}
else {
qDebug()<<"power health data decoding failed, Check the parameters.\n";
}
break;
case DEVICE_SONAR: // if the device id matches the heartbeat device id,
qDebug()<<"Packet has Sonar Data.\n";
decode_status = decode_SONAR(&vedtp_recv, &sonar_data); // decode the heartbeat packet
if(decode_status){ // if decode is success,
qDebug()<<"Sonar data decoded successfully.\n\n"; // print or process the data
qDebug()<<sonar_data.range_m<<
sonar_data.confidence;
emit data_processed(DEVICE_SONAR);
}
else {
qDebug()<<"Sonar data decoding failed, Check the parameters.\n";
}
break;
case DEVICE_MOTOR: // if the device id matches the heartbeat device id,
qDebug()<<"Packet has Motor Data.\n";
decode_status = decode_MOTOR(&vedtp_recv, &motor_data); // decode the heartbeat packet
if(decode_status){ // if decode is success,
qDebug()<<"Device motor data decoded successfully.\n\n"; // print or process the data
qDebug()<<motor_data.velocity[3];
// sonar_data.confidence;
emit data_processed(DEVICE_MOTOR);
}
else {
qDebug()<<"Motor data decoding failed, Check the parameters.\n";
}
break;
case DEVICE_DEVICE_ERROR: // if the device id matches the heartbeat device id,
decode_status = decode_DEVICE_ERROR(&vedtp_recv, &error_data); // decode the heartbeat packet
if(decode_status){ // if decode is success,
qDebug()<<"Device error decoded successfully.\n\n"; // print or process the data
qDebug()<<"error data :"<<error_data.device_id<<error_data.error_type<<
error_data.severity<<error_data.flags<<
error_data.uptime_ms;
emit data_processed(DEVICE_DEVICE_ERROR);
}
else {
qDebug()<<"Heartbeat data decoding failed, Check the parameters.\n";
}
break;
case DEVICE_COMMAND_ACK: // if the device id matches the heartbeat device id,
qDebug()<<"Packet has Command Acknowledgement Data.\n";
decode_status = decode_COMMAND_ACK(&vedtp_recv, &acknowledgement_data); // decode the heartbeat packet
if(decode_status){ // if decode is success,
qDebug()<<"command acknowldgement data decoded successfully.\n\n"; // print or process the data
qDebug()<<
acknowledgement_data.command<<
acknowledgement_data.result<<
acknowledgement_data.source<<
acknowledgement_data.flags<<
acknowledgement_data.message<<
acknowledgement_data.uptime_ms;
emit data_processed(DEVICE_COMMAND_ACK);
}
else {
qDebug()<<"Command Acknowledgement data decoding failed, Check the parameters.\n";
}
break;
}
break;
case VEDTP_INVALID_START_BYTES: // invalid start byte, means packet is not started yet, just do nothing
break;
case VEDTP_INVALID_SECOND_BYTES: // invalid second byte, means either the first byte triggered with random data or packet got corrupted. do nothing or show error
qDebug()<<"Invalid Senond Byte";
break;
case VEDTP_CRC_FAIL: // crc checking fail, packet is corrupted. do nothing or show error
qDebug()<<"CRC Fail";
break;
case VEDTP_PROTOCOL_VERSION_MISMATCH: // Protocol version mismatch. show error or update protocol version
qDebug()<<"Protocol version mismatch";
break;
default:
break;
}
}
}
void Link::data_to_be_updated(int device)
{
switch(device){
case DEVICE_HEARTBEAT:
heart_beat_parsing();
break;
case DEVICE_AHRS:
AHRS_parsing();
break;
case DEVICE_EXTERNAL_ATMOSPHERE:
env_parsing();
break;
case DEVICE_SONAR:
sonar_parsing();
break;
case DEVICE_MOTOR:
motor_parsing();
break;
case DEVICE_COMMAND_ACK:
command_parsing();
break;
case DEVICE_DEVICE_ERROR:
// qDebug()<<"error_parsing";
error_parsing();
break;
}
}
void Link::heart_beat_parsing()
{
loggedState = heartbeat_data.loggedState;
vehicleID = heartbeat_data.vehicleID;
armedState = heartbeat_data.armedState;
systemMode = heartbeat_data.systemMode;
gps_fix = heartbeat_data.gps_fix;
failsafe_flags = heartbeat_data.failsafe_flags;
system_health= heartbeat_data.system_health;
sensors_validity = heartbeat_data.sensors_validity;
uptime_ms_heartbeat = heartbeat_data.uptime_ms;
if(loggedState ==0)
{
login("VOTPL","VOTPL");
}
}
void Link::AHRS_parsing()
{
// if (yawTimer.elapsed() >= 1000) {
setYaw_value(ahrs_data.yaw_deg);
// yawTimer.restart();
//}
//yaw_deg = ahrs_data.yaw_deg;
setPitch_value(ahrs_data.pitch_deg);
setRoll_value(ahrs_data.roll_deg);
setuptime_ms_ahrs_value(ahrs_data.uptime_ms);
//pitch_deg = ahrs_data.pitch_deg;
//roll_deg = ahrs_data.roll_deg;
//uptime_ms_ahrs = ahrs_data.uptime_ms;
}
void Link::env_parsing()
{
settemperature(External_atmosphere_data.temperature_C);
setdepth(External_atmosphere_data.depth_m);
setsalinity(External_atmosphere_data.salinity_ppt);
}
void Link::error_parsing()
{
// setDeviceId(error_data.device_id);
// setErrorType( error_data.error_type);
// setseverity(error_data.severity);
// setuptimemserror(error_data.uptime_ms);
qDebug()<<"Deive Id error "<<error_data.device_id;
switch(error_data.device_id){
case DEVICE_HEARTBEAT:
//error_device = Device_HEARTBEAT;
device_id = DEVICE_HEARTBEAT;
break;
case DEVICE_GPS:
device_id=DEVICE_GPS;
break;
case DEVICE_AHRS:
device_id = DEVICE_AHRS;
break;
case DEVICE_IMU:
device_id=DEVICE_IMU;
break;
case DEVICE_EXTERNAL_ATMOSPHERE:
device_id = DEVICE_EXTERNAL_ATMOSPHERE;
break;
case DEVICE_SONAR:
device_id = DEVICE_SONAR;
break;
case DEVICE_JOYSTICK:
device_id = DEVICE_JOYSTICK;
break;
case DEVICE_POWER_HEALTH:
device_id = DEVICE_POWER_HEALTH;
break;
case DEVICE_COMMAND_ACK:
device_id = DEVICE_COMMAND_ACK;
break;
case DEVICE_MOTOR:
device_id = DEVICE_MOTOR;
break;
}
switch(error_data.error_type)
{
case DEVICE_ERROR_INIT:
error_type=DEVICE_ERROR_INIT;
break;
case DEVICE_ERROR_HEARTBEAT:
error_type=DEVICE_ERROR_HEARTBEAT;
break;
case DEVICE_ERROR_DATA_TRANSFER_FAILED:
error_type=DEVICE_ERROR_DATA_TRANSFER_FAILED;
break;
case DEVICE_ERROR_CRC_MISMATCH:
error_type=DEVICE_ERROR_CRC_MISMATCH;
break;
case DEVICE_ERROR_TIMEOUT:
error_type=DEVICE_ERROR_TIMEOUT;
break;
case DEVICE_ERROR_OUT_OF_RANGE:
error_type=DEVICE_ERROR_OUT_OF_RANGE;
break;
case DEVICE_ERROR_NOT_RESPONDING:
error_type=DEVICE_ERROR_NOT_RESPONDING;
break;
case DEVICE_ERROR_COMMUNICATION_LOST:
error_type=DEVICE_ERROR_COMMUNICATION_LOST;
break;
case DEVICE_ERROR_CALIBRATION_FAILED:
error_type=DEVICE_ERROR_CALIBRATION_FAILED;
break;
case DEVICE_ERROR_UNKNOWN:
error_type=DEVICE_ERROR_UNKNOWN;
// emit
break;
}
emit errordetected();
// switch(error_data.severity)
// {
// case
}
//void Link::
void Link::power_health_parsing()
{
setBatteryVoltage(Power_health_data.battery_voltage);
}
void Link::motor_parsing()
{
setMotorVelocity4(motor_data.velocity[3]);
}
void Link::sonar_parsing()
{
setSonarRange(sonar_data.range_m);
setSonarConfidence(sonar_data.confidence);
}
void Link::command_parsing()
{
setCommand(acknowledgement_data.command);
setResult(acknowledgement_data.result);
setSource( acknowledgement_data.source);
setFlagsAck(acknowledgement_data.flags);
setMessage(acknowledgement_data.message);
setUptimeMsAck(acknowledgement_data.uptime_ms);
}
float Link::yaw_value() const
{
return yaw_deg;
}
float Link:: pitch_value() const
{
return pitch_deg;
}
float Link::roll_value() const
{
return roll_deg;
}
quint32 Link::uptime_ms_ahrs_value() const
{
return uptime_ms_ahrs;
}
float Link::temperature() const
{
qDebug()<<temperature_C;
return temperature_C;
}
float Link::depth() const
{
return depth_m;
}
float Link::salinity () const
{
return salinity_ppt;
}
uint8_t Link::deviceId() const
{
return device_id;
}
uint8_t Link::errorType() const
{
return error_type;
}
uint8_t Link:: error_severity() const
{
return severity;
}
uint8_t Link::errorflags() const
{
return flags;
}
quint64 Link::uptime_mserror() const
{
return uptime_ms_error;
}
float Link:: motorVelocity4() const
{
return velocity[3];
}
float Link::batteryVoltage() const
{
return battery_voltage;
}
float Link::sonarRange() const
{
return range_m;
}
float Link:: sonarConfidence() const
{
return confidence;
}
uint8_t Link::commandValue() const
{
return command;
}
uint8_t Link::resultValue() const
{
return result;
}
uint8_t Link:: sourceValue() const
{
return source;
}
uint8_t Link:: flagsAck() const
{
return flags_ack;
}
QString Link:: messageValue() const
{
return message;
}
quint64 Link:: uptimeMsAck() const
{
return uptime_ms_ack;
}
int Link::mapvalue(double value, int InputMin, int InputMax, int outputMin,int outputMax)
{
//qDebug()<<"Mapped Value";
double mappedValue =
(value - InputMin) * (outputMax - outputMin)
/ static_cast<double>(InputMax - InputMin)
+ outputMin;
//qDebug()<<mappedValue;
//Clamp the mapped value
if (mappedValue < outputMin)
return outputMin;
else if (mappedValue > outputMax)
return outputMax;
else
return mappedValue;
}
void Link::setYaw_value(float value)
{
if (qFuzzyCompare(yaw_deg, value))
return;
yaw_deg = value;
emit yawValueChanged(yaw_deg);
}
void Link:: setPitch_value(float value)
{
if(qFuzzyCompare(pitch_deg, value))
return;
pitch_deg = value;
emit pitchValueChanged(pitch_deg);
}
void Link::setRoll_value(float value)
{
if(qFuzzyCompare(roll_deg, value))
return;
roll_deg = value;
emit rollValueChanged(roll_deg);
}
void Link::setuptime_ms_ahrs_value(quint64 value)
{
if(uptime_ms_ahrs==value)
return;
uptime_ms_ahrs = value;
emit uptimeChanged(uptime_ms_ahrs);
}
void Link::settemperature(float value)
{
if(qFuzzyCompare(temperature_C, value))
return;
temperature_C = value;
// qDebug()<<"UI"<<temperature_C;
emit temperatureChanged(temperature_C);
}
void Link::setdepth(float value)
{
if(qFuzzyCompare(1.0+depth_m,1.0+ value))
return;
depth_m=value;
emit depthChanged(depth_m);
}
void Link::setsalinity(float value)
{
if(qFuzzyCompare(1.0+salinity_ppt,1.0+value))
return;
salinity_ppt = value;
emit salinityChanged(salinity_ppt);
}
void Link:: setDeviceId(uint8_t value)
{
if(device_id == value)
return;
device_id = value;
emit deviceIdChanged(device_id);
}
void Link:: setErrorType(uint8_t value)
{
if(error_type == value)
return;
error_type = value;
emit errorTypeChanged(error_type);
}
void Link:: setFlags(uint8_t value)
{
if(flags==value)
return;
flags = value;
emit flagsChanged(flags);
}
void Link:: setseverity(uint8_t value)
{
if(severity==value)
return;
severity=value;
emit severityChanged(value);
}
void Link:: setuptimemserror(quint64 value)
{
if(uptime_ms_error == value)
return;
uptime_ms_error = value;
emit uptimemserrorChanged(uptime_ms_error);
}
void Link::setMotorVelocity4(float value)
{
if(qFuzzyCompare(1.0+velocity[3],1.0+value))
return;
velocity[3]=value;
emit motorVelocity4Changed(velocity[3]);
}
void Link::setBatteryVoltage(float value)
{
if(qFuzzyCompare(1.0+battery_voltage,1.0+value))
return;
battery_voltage = value;
emit batteryVoltageChanged(battery_voltage);
}
void Link::setSonarRange(float value)
{
if(qFuzzyCompare(1.0+range_m,1.0+value))
return;
range_m = value;
emit sonarRangeChanged(range_m);
}
void Link::setSonarConfidence(float value)
{
if(qFuzzyCompare(1.0+confidence,1.0+value))
return;
confidence = value;
emit sonarConfidenceChanged(confidence);
}
void Link::setCommand(uint8_t value)
{
if(command==value)
return;
command = value;
emit commandChanged(command);
}
void Link::setResult(uint8_t value)
{
if(result==value)
return;
result = value;
emit resultChanged(result);
}
void Link::setSource(uint8_t value)
{
if(source==value)
return;
source = value;
emit sourceChanged(source);
}
void Link::setFlagsAck(uint8_t value)
{
if(flags_ack == value)
return;
flags_ack = value;
emit flagsAckChanged(flags_ack);
}
void Link:: setMessage(const QString & value)
{
if(message == value)
return;
message = value;
emit messageChanged(message);
}
void Link::setUptimeMsAck(quint64 value)
{
if(uptime_ms_ack == value)
return;
uptime_ms_ack = value;
emit uptimeMsAckChanged(uptime_ms_ack);
}
void Link::generateRandomData()
{
float randomYaw =
QRandomGenerator::global()->generateDouble() * 360.0f - 180.0f;
setYaw_value(randomYaw);
}
void Link::create_directory()
{
QString targetDirectory = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation);
QString logFileDir = targetDirectory + "/orcascreenshots";
QDir().mkpath(logFileDir);
QString targetDirectory2 = QStandardPaths::writableLocation(QStandardPaths::MoviesLocation);
QString logFileDir2 = targetDirectory2 + "/orca videos";
QDir().mkpath(logFileDir2);
QString targetDirectory3 = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
log_path = targetDirectory3 + "/orca log_files";
QDir().mkpath(log_path);
QString targetDirectory4 = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
QString error_path = targetDirectory4 + "/orca ErrorFiles";
QDir().mkpath(error_path);
QString targetDirectory5 = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
QString pdf_path = targetDirectory5 + "/orca PdfFiles";
QDir logDir(pdf_path);
QDir().mkpath(pdf_path);
}
void Link::sendJoystickData()
{
JOYSTICK_Packet joy = {};
joy.channels[0] = y_axis_left;
joy.channels[1] = x_axis_left;
joy.channels[2] = x_axis_right;
joy.channels[3] = y_axis_right;
joy.channels[4] = light_intensity;
joy.channels[5] = light_intensity;
joy.channels[6] = light_intensity;
joy.channels[7] = light_intensity;
/*qDebug()<<"channels 0: "<<joy.channels[0];
qDebug()<<"channel 1: "<<joy.channels[1];
qDebug()<<"chanel 2: "<<joy.channels[2];
qDebug()<<"channel 3: "<<joy.channels[3];
qDebug()<<"channel 4: "<<joy.channels[4];*/
VEDTP_Main JOYSTICK_send_Packet;
joy.flags=0;
joy.uptime_ms = static_cast<uint32_t>(QDateTime::currentDateTime().toMSecsSinceEpoch());
uint8_t encode_status = encode_JOYSTICK(&JOYSTICK_send_Packet,&joy); // encode heartbeat function from vedtp protocol library
if(encode_status)
{
mavlink_send_buffer(JOYSTICK_send_Packet);
}
}
void Link::set_joystick_values(double y_axis_, double x_axis_)
{
y_axis_left = mapvalue(y_axis_,InputMin, InputMax, outputMin, outputMax);
x_axis_left = mapvalue(x_axis_,InputMin, InputMax, outputMin, outputMax);
qDebug()<<"set_joystick_values";
//x_axis_left = static_cast<uint16_t>(x_axis_);
//x_axis_right = static_cast<uint16_t>(x_axis1_);
//y_axis_right = static_cast<uint16_t>(y_axis1_);
qDebug()<<"y_axis_left"<<y_axis_left;
qDebug()<<"x_axis_left"<<x_axis_left;
//qDebug()<<x_axis_right;
//qDebug()<<y_axis_right;
}
void Link::set_joystick_values2(double y_axis_, double x_axis_)
{
y_axis_left = mapvalue(y_axis_,InputMin, InputMax, outputMin, outputMax);
x_axis_left = mapvalue(x_axis_, InputMin, InputMax, outputMin, outputMax);
qDebug()<<"set_joystick_values2";
qDebug()<<"y_axis_left"<<y_axis_left;
qDebug()<<"x_axis_left"<<x_axis_left;
}
void Link::set_joystick_values3(double y_axis_, double x_axis_)
{
y_axis_right = mapvalue(y_axis_, InputMin, InputMax, outputMin, outputMax);
x_axis_right = mapvalue(x_axis_, InputMin, InputMax, outputMin, outputMax);
qDebug()<<"set_joystick_values3";
qDebug()<<"y_axis_right"<<y_axis_right;
qDebug()<<"x_axis_right"<<x_axis_right;
}
void Link::set_joystick_values4(double y_axis_, double x_axis_)
{
y_axis_right = mapvalue(y_axis_,InputMin, InputMax, outputMin, outputMax);
x_axis_right = mapvalue(x_axis_,InputMin, InputMax, outputMin, outputMax);
qDebug()<<"set_joystick_values4";
qDebug()<<"y_axis_right"<<y_axis_right;
qDebug()<<"x_axis_right"<<x_axis_right;
}
void Link::joystick_activated(int mode, bool value)
{
if (mode == MODE_DEPTH_HOLD && value) {
is_depth_hold = !is_depth_hold;
COMMAND_Packet cmd = {};
//vedtp_send = encode_COMMAND(&cmd);
//qDebug() << "Depth Hold:" << is_depth_hold;
}
}
void Link::sendMode(System_Mode mode)
{
COMMAND_Packet cmd{};
cmd.id = CMD_MODE;
cmd.target = DEVICE_COMMAND;
cmd.flags = 0;
cmd.param_count = 1;
cmd.param[0] = static_cast<int16_t>(mode);
cmd.char1[12] = static_cast<uint8_t>(mode);
cmd.char2[12] = static_cast<uint8_t>(mode);
cmd.uptime_ms = QDateTime::currentMSecsSinceEpoch();
VEDTP_Main vedtp{};
if (!encode_COMMAND(&vedtp, &cmd)) {
qDebug() << "[MODE] Encode failed";
return;
}
emit _invokeWriteBytes(
QByteArray(reinterpret_cast<char*>(&vedtp),
sizeof(VEDTP_Main))
);
qDebug() << "[MODE] Sent mode:" << mode;
}
void Link::setManualMode()
{
sendMode(MODE_MANUAL);
}
void Link::setHoldMode()
{
sendMode(MODE_HOLD);
}
void Link::setAutoMode()
{
sendMode(MODE_AUTO);
}
void Link::setRTSMode()
{
sendMode(MODE_RTL);
}
void Link::sendModeCommand(unsigned char mode)
{
sendMode(static_cast<System_Mode>(mode));
}
QByteArray Link::errorcatched()
{
errorArray.clear();
errorArray.append(device_id);
qDebug()<<"error device id "<<device_id;
errorArray.append(error_type);
qDebug()<<"error_type"<<error_type;
return errorArray;
}
void Link::login(QString username, QString password)
{
COMMAND_Packet cmd{};
cmd.id=CMD_LOGIN;
cmd.target=DEVICE_COMMAND;
cmd.flags=0;
cmd.param_count=2;
username ="VOTPL";
password ="VOTPL";
strcpy(cmd.char1, username.toUtf8().constData());
strcpy(cmd.char2, password.toUtf8().constData());
//cmd.char1[12] ="votpl";
cmd.uptime_ms = QDateTime::currentMSecsSinceEpoch();
VEDTP_Main heartbeat_send_packet; // for holding the main vedtp packet
if (!encode_COMMAND(&vedtp, &cmd)) {
qDebug() << "Login successfully";
return;
}
emit _invokeWriteBytes(
QByteArray(reinterpret_cast<char*>(&vedtp),
sizeof(VEDTP_Main))
);//cmd.param[0]=static_cast<>
}