Skip to content

Commit e2ef0f1

Browse files
committed
Calibration stand via UDP link
1 parent 360fc75 commit e2ef0f1

32 files changed

+392
-172
lines changed

DevDriver.cpp

+12-22
Original file line numberDiff line numberDiff line change
@@ -134,22 +134,6 @@ int DevDriver::getDevDefAddress() {
134134
return idUART->devDefAddress();
135135
}
136136

137-
int DevDriver::dopplerVeloX() {
138-
return idDVL->velX();
139-
}
140-
141-
int DevDriver::dopplerVeloY() {
142-
return idDVL->velY();
143-
}
144-
145-
int DevDriver::dopplerVeloZ() {
146-
return idDVL->velZ();
147-
}
148-
149-
int DevDriver::dopplerDist() {
150-
return idDVL->dist();
151-
}
152-
153137
void DevDriver::dvlChangeMode(bool ismode1, bool ismode2, bool ismode3, bool ismode4, float range_mode4) {
154138
idDVLMode->setModes(ismode1, ismode2, ismode3, ismode4, range_mode4);
155139
}
@@ -345,7 +329,7 @@ void DevDriver::setUartState(bool state) {
345329
}
346330
}
347331

348-
void DevDriver::askBeaconPosition(IDBinUsblSolution::AskBeacon ask) {
332+
void DevDriver::askBeaconPosition(IDBinUsblSolution::USBLRequestBeacon ask) {
349333
if(!m_state.connect) return;
350334
idUSBL->askBeacon(ask);
351335
}
@@ -1047,12 +1031,18 @@ void DevDriver::receivedDVLMode(Type type, Version ver, Resp resp) {
10471031

10481032
void DevDriver::receivedUSBL(Type type, Version ver, Resp resp) {
10491033
Q_UNUSED(type);
1050-
Q_UNUSED(ver);
1051-
Q_UNUSED(resp);
10521034

1053-
usblSolutionComplete(idUSBL->usblSolution());
1054-
// emit distComplete(idUSBL->usblSolution().distance_m*1000);
1055-
// emit attitudeComplete(idUSBL->usblSolution().azimuth_deg, idUSBL->usblSolution().elevation_deg, 0);
1035+
1036+
1037+
if(resp == respNone) {
1038+
if(ver == Parsers::v0) {
1039+
emit usblSolutionComplete(idUSBL->usblSolution());
1040+
} else if(ver == Parsers::v1) {
1041+
qDebug("usbl p.ver %d", ver);
1042+
emit beaconActivationComplete(0);
1043+
}
1044+
}
1045+
10561046
}
10571047

10581048
void DevDriver::process() {

DevDriver.h

+5-10
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,6 @@ class DevDriver : public QObject
103103
void setDevDefAddress(int addr);
104104
int getDevDefAddress();
105105

106-
int dopplerVeloX();
107-
int dopplerVeloY();
108-
int dopplerVeloZ();
109-
int dopplerDist();
110-
111-
112-
113-
114106
QString devName() { return m_devName; }
115107
uint32_t devSerialNumber();
116108
QString devPN();
@@ -174,7 +166,10 @@ class DevDriver : public QObject
174166
void iqComplete(QByteArray data, uint8_t type);
175167
void attitudeComplete(float yaw, float pitch, float roll);
176168
void distComplete(int dist);
169+
177170
void usblSolutionComplete(IDBinUsblSolution::UsblSolution data);
171+
void beaconActivationComplete(uint8_t id);
172+
178173
void positionComplete(uint32_t date, uint32_t time, double lat, double lon);
179174
void chartSetupChanged();
180175
void dspSetupChanged();
@@ -226,10 +221,10 @@ public slots:
226221
void setUartState(bool state);
227222

228223
void askBeaconPosition() {
229-
IDBinUsblSolution::AskBeacon ask;
224+
IDBinUsblSolution::USBLRequestBeacon ask;
230225
askBeaconPosition(ask);
231226
}
232-
void askBeaconPosition(IDBinUsblSolution::AskBeacon ask);
227+
void askBeaconPosition(IDBinUsblSolution::USBLRequestBeacon ask);
233228
void enableBeaconOnce(float timeout);
234229

235230
protected:

DevQProperty.h

-5
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,6 @@ class DevQProperty : public DevDriver
5151

5252
Q_PROPERTY(int upgradeFWStatus READ upgradeFWStatus NOTIFY upgradeChanged)
5353

54-
Q_PROPERTY(int dopplerVeloX READ dopplerVeloX NOTIFY dopplerVeloComplete)
55-
Q_PROPERTY(int dopplerVeloY READ dopplerVeloY NOTIFY dopplerVeloComplete)
56-
Q_PROPERTY(int dopplerVeloZ READ dopplerVeloZ NOTIFY dopplerVeloComplete)
57-
Q_PROPERTY(int dopplerDist READ dopplerDist NOTIFY dopplerVeloComplete)
58-
5954
Q_PROPERTY(QString devName READ devName NOTIFY deviceVersionChanged)
6055
Q_PROPERTY(int devSN READ devSerialNumber NOTIFY deviceVersionChanged)
6156
Q_PROPERTY(QString fwVersion READ fwVersion NOTIFY deviceVersionChanged)

DeviceManager.cpp

+34-4
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,35 @@ void DeviceManager::upgradeLastDev(QByteArray data)
482482
}
483483
}
484484

485+
void DeviceManager::beaconActivationReceive(uint8_t id) {
486+
QList<DevQProperty *> usbl_devs = getDevList(BoardUSBL);
487+
if(usbl_devs.size() > 0) {
488+
IDBinUsblSolution::USBLRequestBeacon ask = {};
489+
usbl_devs[0]->askBeaconPosition(ask);
490+
}
491+
}
492+
493+
void DeviceManager::beaconDirectQueueAsk() {
494+
QList<DevQProperty *> usbl_devs = getDevList(BoardUSBLBeacon);
495+
qDebug("Sent request to the Beacon # %d", -1);
496+
if(usbl_devs.size() > 0) {
497+
usbl_devs[0]->enableBeaconOnce(3);
498+
qDebug("Sent request to the Beacon # %d", 0);
499+
}
500+
}
501+
502+
void DeviceManager::setUSBLBeaconDirectAsk(bool is_ask) {
503+
isUSBLBeaconDirectAsk = is_ask;
504+
qDebug("Beacon auto scan is: %d", is_ask);
505+
if(is_ask == true) {
506+
QObject::connect(&beacon_timer, &QTimer::timeout, this, &DeviceManager::beaconDirectQueueAsk);
507+
beacon_timer.setInterval(3000);
508+
beacon_timer.start();
509+
} else {
510+
beacon_timer.stop();
511+
}
512+
}
513+
485514
#ifdef MOTOR
486515
float DeviceManager::getFAngle()
487516
{
@@ -557,14 +586,14 @@ void DeviceManager::clearTasks()
557586
}
558587

559588
void DeviceManager::calibrationStandIn(float currFAngle, float taskFAngle, float currSAngle, float taskSAngle) {
589+
emit encoderComplete(currFAngle, -currSAngle, NAN);
590+
emit posIsConstant(currFAngle, taskFAngle, currSAngle, taskSAngle);
591+
560592
QList<DevQProperty *> usbl_devs = getDevList(BoardUSBL);
561593
if(usbl_devs.size() > 0) {
562-
IDBinUsblSolution::AskBeacon ask;
594+
IDBinUsblSolution::USBLRequestBeacon ask;
563595
usbl_devs[0]->askBeaconPosition(ask);
564596
}
565-
566-
emit encoderComplete(currFAngle, currSAngle, NAN);
567-
emit posIsConstant(currFAngle, taskFAngle, currSAngle, taskSAngle);
568597
}
569598
#endif
570599

@@ -659,6 +688,7 @@ DevQProperty* DeviceManager::createDev(QUuid uuid, Link* link, uint8_t addr)
659688
connect(dev, &DevQProperty::attitudeComplete, this, &DeviceManager::attitudeComplete);
660689
connect(dev, &DevQProperty::distComplete, this, &DeviceManager::distComplete);
661690
connect(dev, &DevQProperty::usblSolutionComplete, this, &DeviceManager::usblSolutionComplete);
691+
connect(dev, &DevQProperty::beaconActivationComplete, this, &DeviceManager::beaconActivationReceive);
662692
connect(dev, &DevQProperty::dopplerBeamComplete, this, &DeviceManager::dopplerBeamComlete);
663693
connect(dev, &DevQProperty::dvlSolutionComplete, this, &DeviceManager::dvlSolutionComplete);
664694
connect(dev, &DevQProperty::upgradeProgressChanged, this, &DeviceManager::upgradeProgressChanged);

DeviceManager.h

+8
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ public slots:
5353
void setProtoBinConsoled(bool isConsoled);
5454
void upgradeLastDev(QByteArray data);
5555

56+
void beaconActivationReceive(uint8_t id);
57+
void beaconDirectQueueAsk();
58+
bool isbeaconDirectQueueAsk() { return isUSBLBeaconDirectAsk; }
59+
void setUSBLBeaconDirectAsk(bool is_ask);
60+
5661
#ifdef MOTOR
5762
float getFAngle();
5863
float getSAngle();
@@ -146,6 +151,9 @@ public slots:
146151
bool isConsoled_;
147152
volatile bool break_;
148153

154+
bool isUSBLBeaconDirectAsk = false;
155+
QTimer beacon_timer;
156+
149157
#ifdef MOTOR
150158
std::unique_ptr<MotorControl> motorControl_;
151159
float fAngle_ = 0.0f;

DeviceManagerWrapper.h

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class DeviceManagerWrapper : public QObject
2525
Q_PROPERTY(int pilotArmState READ pilotArmState NOTIFY vruChanged)
2626
Q_PROPERTY(int pilotModeState READ pilotModeState NOTIFY vruChanged)
2727

28+
Q_PROPERTY(bool isbeaconDirectQueueAsk WRITE setUSBLBeaconDirectAsk)
29+
2830
#ifdef MOTOR
2931
// MotorControl on DeviceManager
3032
Q_PROPERTY(int countMotorDevices READ getMotorCountDevices NOTIFY motorDeviceChanged)
@@ -56,6 +58,7 @@ class DeviceManagerWrapper : public QObject
5658

5759
void setProtoBinConsoled(bool state) { getWorker()->setProtoBinConsoled(state); }
5860

61+
void setUSBLBeaconDirectAsk(bool is_ask) { getWorker()->setUSBLBeaconDirectAsk(is_ask); }
5962
public slots:
6063

6164
Q_INVOKABLE bool isCreatedId(int id) { return getWorker()->isCreatedId(id); };

IDBinnary.cpp

+8-9
Original file line numberDiff line numberDiff line change
@@ -893,31 +893,30 @@ void IDBinDVLMode::setModes(bool ismode1, bool ismode2, bool ismode3, bool ismod
893893

894894
Resp IDBinUsblSolution::parsePayload(FrameParser &proto) {
895895
if(proto.ver() == v0) {
896-
if(static_cast<int16_t>(sizeof(UsblSolution)) <= proto.readAvailable()) {
897-
_usblSolution = proto.read<UsblSolution>();
898-
qInfo("USBL d: %f, a: %f,e: %f, p: %lld", _usblSolution.distance_m, _usblSolution.azimuth_deg, _usblSolution.elevation_deg, _usblSolution.carrier_counter);
899-
} else {
900-
return respErrorPayload;
901-
}
896+
_usblSolution = proto.read<UsblSolution>();
897+
qInfo("USBL d: %f, a: %f,e: %f, p: %lld", _usblSolution.distance_m, _usblSolution.azimuth_deg, _usblSolution.elevation_deg, _usblSolution.carrier_counter);
898+
} else if(proto.ver() == v1) {
899+
_beaconResponcel = proto.read<BeaconActivationResponce>();
900+
qInfo("Beacon responce: %d", _beaconResponcel.id);
902901
} else {
903902
return respErrorVersion;
904903
}
905904

906905
return respOk;
907906
}
908907

909-
void IDBinUsblSolution::askBeacon(AskBeacon ask) {
908+
void IDBinUsblSolution::askBeacon(USBLRequestBeacon ask) {
910909
ProtoBinOut req_out;
911910
req_out.create(GETTING, Version::v0, id(), m_address);
912-
req_out.write<AskBeacon>(ask);
911+
req_out.write<USBLRequestBeacon>(ask);
913912
req_out.end();
914913

915914
emit binFrameOut(req_out);
916915
}
917916

918917
void IDBinUsblSolution::enableBeaconOnce(float timeout) {
919918
ProtoBinOut req_out;
920-
req_out.create(SETTING, Version::v1, id(), m_address);
919+
req_out.create(GETTING, Version::v1, id(), m_address);
921920
req_out.write<F4>(timeout);
922921
req_out.end();
923922

IDBinnary.h

+22-9
Original file line numberDiff line numberDiff line change
@@ -904,30 +904,43 @@ class IDBinUsblSolution : public IDBin
904904

905905
float snr = 0;
906906

907-
// double latitude;
908-
// double longitude;
909-
// float depth;
907+
float x_m = NAN;
908+
float y_m = NAN;
909+
double latitude_deg = NAN;
910+
double longitude_deg = NAN;
911+
float depth_m = NAN;
910912
} __attribute__((packed));
911913

912-
struct AskBeacon {
914+
struct USBLRequestBeacon {
913915
uint8_t id = 0; // 0 is promisc mode
914916
uint8_t reserved = 0;
915917
uint16_t watermark = 0;
916-
double latitude = NAN;
917-
double longitude = NAN;
918-
float external_heading = NAN;
919-
float force_beacon_depth = NAN;
918+
double latitude_deg = NAN;
919+
double longitude_deg = NAN;
920+
float external_heading_deg = NAN;
921+
float force_beacon_depth_m = NAN;
922+
} __attribute__((packed));
923+
924+
struct BeaconActivationResponce {
925+
uint8_t id = 0; // 0 is promisc mode
926+
uint8_t reserved = 0;
927+
uint16_t reserved1 = 0;
928+
} __attribute__((packed));
929+
930+
struct BeaconActivate {
931+
float timeout_s = 2;
920932
} __attribute__((packed));
921933

922934
UsblSolution usblSolution() {
923935
return _usblSolution;
924936
}
925937

926-
void askBeacon(AskBeacon ask);
938+
void askBeacon(USBLRequestBeacon ask);
927939
void enableBeaconOnce(float timeout);
928940

929941
protected:
930942
UsblSolution _usblSolution;
943+
BeaconActivationResponce _beaconResponcel;
931944
};
932945

933946

KoggerApp.pro

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ QT += network
44
QT += qml
55

66
#CONFIG += FLASHER
7-
# CONFIG += MOTOR # motor_control definition
7+
CONFIG += MOTOR # motor_control definition
88

99
!android {
1010
QT += serialport

Link.cpp

+29-13
Original file line numberDiff line numberDiff line change
@@ -356,17 +356,17 @@ bool Link::getIsForceStopped() const
356356
return isForcedStopped_;
357357
}
358358

359-
#ifdef MOTOR
360-
void Link::setIsMotorDevice(bool isMotorDevice)
361-
{
362-
isMotorDevice_ = isMotorDevice;
363-
}
364-
365-
bool Link::getIsMotorDevice() const
366-
{
367-
return isMotorDevice_;
368-
}
369-
#endif
359+
// #ifdef MOTOR
360+
// void Link::setIsMotorDevice(bool isMotorDevice)
361+
// {
362+
// isMotorDevice_ = isMotorDevice;
363+
// }
364+
365+
// bool Link::getIsMotorDevice() const
366+
// {
367+
// return isMotorDevice_;
368+
// }
369+
// #endif
370370

371371
bool Link::writeFrame(FrameParser frame)
372372
{
@@ -438,7 +438,7 @@ void Link::readyRead()
438438
QIODevice* dev = device();
439439
if (dev != nullptr) {
440440

441-
if (!isMotorDevice_) {
441+
if (attribute_ == LinkAttributeNone) {
442442
if (linkType_ == LinkType::LinkIPUDP) {
443443
QUdpSocket* socsUpd = (QUdpSocket*)dev;
444444
while (socsUpd->hasPendingDatagrams()) {
@@ -458,7 +458,23 @@ void Link::readyRead()
458458
}
459459
}
460460
else {
461-
emit dataReady(dev->readAll());
461+
if (linkType_ == LinkType::LinkIPUDP) {
462+
QUdpSocket* socsUpd = (QUdpSocket*)dev;
463+
while (socsUpd->hasPendingDatagrams()) {
464+
QByteArray datagram;
465+
datagram.resize(socsUpd->pendingDatagramSize());
466+
QHostAddress sender;
467+
quint16 senderPort;
468+
qint64 slen = socsUpd->readDatagram(datagram.data(), datagram.size(), &sender, &senderPort);
469+
if (slen == -1) {
470+
break;
471+
}
472+
emit dataReady(datagram);
473+
}
474+
}
475+
else {
476+
emit dataReady(dev->readAll());
477+
}
462478
}
463479
}
464480
#else

0 commit comments

Comments
 (0)