1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-23 01:55:48 -05:00

KiwiSDR: Add position of device to web API report.

This commit is contained in:
srcejon 2024-04-04 16:15:41 +01:00
parent 879ce0e17b
commit 35603a8c25
4 changed files with 81 additions and 1 deletions

View File

@ -49,7 +49,10 @@ KiwiSDRInput::KiwiSDRInput(DeviceAPI *deviceAPI) :
m_kiwiSDRWorkerThread(nullptr),
m_deviceDescription("KiwiSDR"),
m_running(false),
m_masterTimer(deviceAPI->getMasterTimer())
m_masterTimer(deviceAPI->getMasterTimer()),
m_latitude(std::numeric_limits<float>::quiet_NaN()),
m_longitude(std::numeric_limits<float>::quiet_NaN()),
m_altitude(std::numeric_limits<float>::quiet_NaN())
{
m_sampleFifo.setLabel(m_deviceDescription);
m_deviceAPI->setNbSourceStreams(1);
@ -237,6 +240,16 @@ bool KiwiSDRInput::handleMessage(const Message& message)
return true;
}
else if (KiwiSDRWorker::MsgReportPosition::match(message))
{
KiwiSDRWorker::MsgReportPosition& report = (KiwiSDRWorker::MsgReportPosition&) message;
m_latitude = report.getLatitude();
m_longitude = report.getLongitude();
m_altitude = report.getAltitude();
return true;
}
else if (MsgStartStop::match(message))
{
MsgStartStop& cmd = (MsgStartStop&) message;
@ -455,6 +468,9 @@ void KiwiSDRInput::webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& re
void KiwiSDRInput::webapiFormatDeviceReport(SWGSDRangel::SWGDeviceReport& response)
{
response.getKiwiSdrReport()->setStatus(getStatus());
response.getKiwiSdrReport()->setLatitude(m_latitude);
response.getKiwiSdrReport()->setLongitude(m_longitude);
response.getKiwiSdrReport()->setAltitude(m_altitude);
}
void KiwiSDRInput::webapiReverseSendSettings(const QList<QString>& deviceSettingsKeys, const KiwiSDRSettings& settings, bool force)

View File

@ -167,6 +167,9 @@ private:
const QTimer& m_masterTimer;
QNetworkAccessManager *m_networkManager;
QNetworkRequest m_networkRequest;
float m_latitude;
float m_longitude;
float m_altitude;
int getStatus() const;
bool applySettings(const KiwiSDRSettings& settings, const QList<QString>& settingsKeys, bool force);

View File

@ -21,6 +21,7 @@
#include "kiwisdrworker.h"
MESSAGE_CLASS_DEFINITION(KiwiSDRWorker::MsgReportSampleRate, Message)
MESSAGE_CLASS_DEFINITION(KiwiSDRWorker::MsgReportPosition, Message)
KiwiSDRWorker::KiwiSDRWorker(SampleSinkFifo* sampleFifo) :
QObject(),
@ -124,6 +125,41 @@ void KiwiSDRWorker::onBinaryMessageReceived(const QByteArray &message)
emit updateStatus(2);
}
}
else if ((al.size() >= 2) && al[1].startsWith("load_cfg="))
{
QByteArray urlEncoded = al[1].mid(9).toLatin1();
QString json = QUrl::fromPercentEncoding(urlEncoded);
QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8());
if (doc.isObject())
{
QJsonObject obj = doc.object();
if (obj.contains("rx_gps"))
{
QString gps = obj.value("rx_gps").toString();
QRegularExpression re("\\((-?[0-9]+(\\.[0-9]+)?), *(-?[0-9]+(\\.[0-9]+)?)\\)");
QRegularExpressionMatch match = re.match(gps);
if (match.hasMatch())
{
float latitude = match.captured(1).toFloat();
float longitude = match.captured(3).toFloat();
float altitude = 0.0f;
if (obj.contains("rx_asl")) {
altitude = (float) obj.value("rx_asl").toInt();
}
if (m_inputMessageQueue) {
m_inputMessageQueue->push(MsgReportPosition::create(latitude, longitude, altitude));
}
}
}
}
else
{
qDebug() << "KiwiSDRWorker::onBinaryMessageReceived - Document is not an object";
}
}
}
else if (message[0] == 'S' && message[1] == 'N' && message[2] == 'D')
{

View File

@ -53,6 +53,31 @@ public:
{ }
};
class MsgReportPosition : public Message {
MESSAGE_CLASS_DECLARATION
public:
float getLatitude() const { return m_latitude; }
float getLongitude() const { return m_longitude; }
float getAltitude() const { return m_altitude; }
static MsgReportPosition* create(float latitude, float longitude, float altitude) {
return new MsgReportPosition(latitude, longitude, altitude);
}
private:
float m_latitude;
float m_longitude;
float m_altitude;
MsgReportPosition(float latitude, float longitude, float altitude) :
Message(),
m_latitude(latitude),
m_longitude(longitude),
m_altitude(altitude)
{ }
};
KiwiSDRWorker(SampleSinkFifo* sampleFifo);
int getStatus() const { return m_status; }
void setInputMessageQueue(MessageQueue *messageQueue) { m_inputMessageQueue = messageQueue; }