Skip to content

Commit

Permalink
Morse Decoder: implemented API. For f4exb#2112
Browse files Browse the repository at this point in the history
  • Loading branch information
f4exb committed May 21, 2024
1 parent 7772ac4 commit 176fe03
Show file tree
Hide file tree
Showing 21 changed files with 1,255 additions and 42 deletions.
128 changes: 91 additions & 37 deletions plugins/feature/morsedecoder/morsedecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ MorseDecoder::MorseDecoder(WebAPIAdapterInterface *webAPIAdapterInterface) :
m_selectedChannel(nullptr),
m_dataPipe(nullptr)
{
qDebug("DemodAnalyzer::DemodAnalyzer: webAPIAdapterInterface: %p", webAPIAdapterInterface);
qDebug("MorseDecoder::MorseDecoder: webAPIAdapterInterface: %p", webAPIAdapterInterface);
setObjectName(m_featureId);
m_state = StIdle;
m_errorMessage = "DemodAnalyzer error";
m_errorMessage = "MorseDecoder error";
m_networkManager = new QNetworkAccessManager();
QObject::connect(
m_networkManager,
Expand Down Expand Up @@ -183,7 +183,7 @@ bool MorseDecoder::handleMessage(const Message& cmd)
if (MsgConfigureMorseDecoder::match(cmd))
{
MsgConfigureMorseDecoder& cfg = (MsgConfigureMorseDecoder&) cmd;
qDebug() << "MorseDecoder::handleMessage: MsgConfigureDemodAnalyzer";
qDebug() << "MorseDecoder::handleMessage: MsgConfigureMorseDecoder";
applySettings(cfg.getSettings(), cfg.getSettingsKeys(), cfg.getForce());

return true;
Expand Down Expand Up @@ -329,12 +329,12 @@ void MorseDecoder::applySettings(const MorseDecoderSettings& settings, const QLi
m_logFile.setFileName(settings.m_logFilename);
if (m_logFile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text))
{
qDebug() << "RttyDemod::applySettings - Logging to: " << settings.m_logFilename;
qDebug() << "MorseDecoder::applySettings - Logging to: " << settings.m_logFilename;
m_logStream.setDevice(&m_logFile);
}
else
{
qDebug() << "RttyDemod::applySettings - Unable to open log file: " << settings.m_logFilename;
qDebug() << "MorseDecoder::applySettings - Unable to open log file: " << settings.m_logFilename;
}
}
}
Expand Down Expand Up @@ -455,8 +455,8 @@ int MorseDecoder::webapiSettingsGet(
QString& errorMessage)
{
(void) errorMessage;
response.setDemodAnalyzerSettings(new SWGSDRangel::SWGDemodAnalyzerSettings());
response.getDemodAnalyzerSettings()->init();
response.setMorseDecoderSettings(new SWGSDRangel::SWGMorseDecoderSettings());
response.getMorseDecoderSettings()->init();
webapiFormatFeatureSettings(response, m_settings);
return 200;
}
Expand All @@ -474,7 +474,7 @@ int MorseDecoder::webapiSettingsPutPatch(
MsgConfigureMorseDecoder *msg = MsgConfigureMorseDecoder::create(settings, featureSettingsKeys, force);
m_inputMessageQueue.push(msg);

qDebug("DemodAnalyzer::webapiSettingsPutPatch: forward to GUI: %p", m_guiMessageQueue);
qDebug("MorseDecoder::webapiSettingsPutPatch: forward to GUI: %p", m_guiMessageQueue);
if (m_guiMessageQueue) // forward to GUI if any
{
MsgConfigureMorseDecoder *msgToGUI = MsgConfigureMorseDecoder::create(settings, featureSettingsKeys, force);
Expand All @@ -490,36 +490,68 @@ void MorseDecoder::webapiFormatFeatureSettings(
SWGSDRangel::SWGFeatureSettings& response,
const MorseDecoderSettings& settings)
{
if (response.getDemodAnalyzerSettings()->getTitle()) {
*response.getDemodAnalyzerSettings()->getTitle() = settings.m_title;
if (response.getMorseDecoderSettings()->getTitle()) {
*response.getMorseDecoderSettings()->getTitle() = settings.m_title;
} else {
response.getDemodAnalyzerSettings()->setTitle(new QString(settings.m_title));
response.getMorseDecoderSettings()->setTitle(new QString(settings.m_title));
}

response.getDemodAnalyzerSettings()->setRgbColor(settings.m_rgbColor);
response.getDemodAnalyzerSettings()->setUseReverseApi(settings.m_useReverseAPI ? 1 : 0);
response.getMorseDecoderSettings()->setRgbColor(settings.m_rgbColor);
response.getMorseDecoderSettings()->setUseReverseApi(settings.m_useReverseAPI ? 1 : 0);

if (response.getDemodAnalyzerSettings()->getReverseApiAddress()) {
*response.getDemodAnalyzerSettings()->getReverseApiAddress() = settings.m_reverseAPIAddress;
if (response.getMorseDecoderSettings()->getReverseApiAddress()) {
*response.getMorseDecoderSettings()->getReverseApiAddress() = settings.m_reverseAPIAddress;
} else {
response.getDemodAnalyzerSettings()->setReverseApiAddress(new QString(settings.m_reverseAPIAddress));
response.getMorseDecoderSettings()->setReverseApiAddress(new QString(settings.m_reverseAPIAddress));
}

response.getDemodAnalyzerSettings()->setReverseApiPort(settings.m_reverseAPIPort);
response.getDemodAnalyzerSettings()->setReverseApiFeatureSetIndex(settings.m_reverseAPIFeatureSetIndex);
response.getDemodAnalyzerSettings()->setReverseApiFeatureIndex(settings.m_reverseAPIFeatureIndex);
response.getMorseDecoderSettings()->setReverseApiPort(settings.m_reverseAPIPort);
response.getMorseDecoderSettings()->setReverseApiFeatureSetIndex(settings.m_reverseAPIFeatureSetIndex);
response.getMorseDecoderSettings()->setReverseApiFeatureIndex(settings.m_reverseAPIFeatureIndex);
response.getMorseDecoderSettings()->setUdpEnabled(settings.m_udpEnabled ? 1 : 0);

if (response.getMorseDecoderSettings()->getUdpAddress()) {
*response.getMorseDecoderSettings()->getUdpAddress() = settings.m_udpAddress;
} else {
response.getMorseDecoderSettings()->setUdpAddress(new QString(settings.m_udpAddress));
}

response.getMorseDecoderSettings()->setUdpPort(settings.m_udpPort);

if (response.getMorseDecoderSettings()->getLogFiledName()) {
*response.getMorseDecoderSettings()->getLogFiledName() = settings.m_logFilename;
} else {
response.getMorseDecoderSettings()->setLogFiledName(new QString(settings.m_logFilename));
}

response.getMorseDecoderSettings()->setLogEnabled(settings.m_logEnabled ? 1 : 0);
response.getMorseDecoderSettings()->setAuto(settings.m_auto ? 1 : 0);

if (settings.m_scopeGUI)
{
if (response.getMorseDecoderSettings()->getScopeConfig())
{
settings.m_scopeGUI->formatTo(response.getMorseDecoderSettings()->getScopeConfig());
}
else
{
SWGSDRangel::SWGGLScope *swgGLScope = new SWGSDRangel::SWGGLScope();
settings.m_scopeGUI->formatTo(swgGLScope);
response.getMorseDecoderSettings()->setScopeConfig(swgGLScope);
}
}

if (settings.m_rollupState)
{
if (response.getDemodAnalyzerSettings()->getRollupState())
if (response.getMorseDecoderSettings()->getRollupState())
{
settings.m_rollupState->formatTo(response.getDemodAnalyzerSettings()->getRollupState());
settings.m_rollupState->formatTo(response.getMorseDecoderSettings()->getRollupState());
}
else
{
SWGSDRangel::SWGRollupState *swgRollupState = new SWGSDRangel::SWGRollupState();
settings.m_rollupState->formatTo(swgRollupState);
response.getDemodAnalyzerSettings()->setRollupState(swgRollupState);
response.getMorseDecoderSettings()->setRollupState(swgRollupState);
}
}
}
Expand All @@ -530,28 +562,49 @@ void MorseDecoder::webapiUpdateFeatureSettings(
SWGSDRangel::SWGFeatureSettings& response)
{
if (featureSettingsKeys.contains("title")) {
settings.m_title = *response.getDemodAnalyzerSettings()->getTitle();
settings.m_title = *response.getMorseDecoderSettings()->getTitle();
}
if (featureSettingsKeys.contains("rgbColor")) {
settings.m_rgbColor = response.getDemodAnalyzerSettings()->getRgbColor();
settings.m_rgbColor = response.getMorseDecoderSettings()->getRgbColor();
}
if (featureSettingsKeys.contains("useReverseAPI")) {
settings.m_useReverseAPI = response.getDemodAnalyzerSettings()->getUseReverseApi() != 0;
settings.m_useReverseAPI = response.getMorseDecoderSettings()->getUseReverseApi() != 0;
}
if (featureSettingsKeys.contains("reverseAPIAddress")) {
settings.m_reverseAPIAddress = *response.getDemodAnalyzerSettings()->getReverseApiAddress();
settings.m_reverseAPIAddress = *response.getMorseDecoderSettings()->getReverseApiAddress();
}
if (featureSettingsKeys.contains("reverseAPIPort")) {
settings.m_reverseAPIPort = response.getDemodAnalyzerSettings()->getReverseApiPort();
settings.m_reverseAPIPort = response.getMorseDecoderSettings()->getReverseApiPort();
}
if (featureSettingsKeys.contains("reverseAPIFeatureSetIndex")) {
settings.m_reverseAPIFeatureSetIndex = response.getDemodAnalyzerSettings()->getReverseApiFeatureSetIndex();
settings.m_reverseAPIFeatureSetIndex = response.getMorseDecoderSettings()->getReverseApiFeatureSetIndex();
}
if (featureSettingsKeys.contains("reverseAPIFeatureIndex")) {
settings.m_reverseAPIFeatureIndex = response.getDemodAnalyzerSettings()->getReverseApiFeatureIndex();
settings.m_reverseAPIFeatureIndex = response.getMorseDecoderSettings()->getReverseApiFeatureIndex();
}
if (featureSettingsKeys.contains("udpEnabled")) {
settings.m_udpEnabled = response.getMorseDecoderSettings()->getUdpEnabled() != 0;
}
if (featureSettingsKeys.contains("udpAddress")) {
settings.m_udpAddress = *response.getMorseDecoderSettings()->getUdpAddress();
}
if (featureSettingsKeys.contains("udpPort")) {
settings.m_udpPort = response.getMorseDecoderSettings()->getUdpPort();
}
if (featureSettingsKeys.contains("logFilename")) {
settings.m_logFilename = *response.getMorseDecoderSettings()->getLogFiledName();
}
if (featureSettingsKeys.contains("logEnabled")) {
settings.m_logEnabled = response.getMorseDecoderSettings()->getLogEnabled() != 0;
}
if (featureSettingsKeys.contains("auto")) {
settings.m_auto = response.getMorseDecoderSettings()->getAuto() != 0;
}
if (settings.m_scopeGUI && featureSettingsKeys.contains("scopeGUI")) {
settings.m_scopeGUI->updateFrom(featureSettingsKeys, response.getMorseDecoderSettings()->getScopeConfig());
}
if (settings.m_rollupState && featureSettingsKeys.contains("rollupState")) {
settings.m_rollupState->updateFrom(featureSettingsKeys, response.getDemodAnalyzerSettings()->getRollupState());
settings.m_rollupState->updateFrom(featureSettingsKeys, response.getMorseDecoderSettings()->getRollupState());
}
}

Expand All @@ -560,17 +613,17 @@ void MorseDecoder::webapiReverseSendSettings(const QList<QString>& featureSettin
SWGSDRangel::SWGFeatureSettings *swgFeatureSettings = new SWGSDRangel::SWGFeatureSettings();
// swgFeatureSettings->setOriginatorFeatureIndex(getIndexInDeviceSet());
// swgFeatureSettings->setOriginatorFeatureSetIndex(getDeviceSetIndex());
swgFeatureSettings->setFeatureType(new QString("DemodAnalyzer"));
swgFeatureSettings->setDemodAnalyzerSettings(new SWGSDRangel::SWGDemodAnalyzerSettings());
SWGSDRangel::SWGDemodAnalyzerSettings *swgDemodAnalyzerSettings = swgFeatureSettings->getDemodAnalyzerSettings();
swgFeatureSettings->setFeatureType(new QString("MorseDecoder"));
swgFeatureSettings->setMorseDecoderSettings(new SWGSDRangel::SWGMorseDecoderSettings());
SWGSDRangel::SWGMorseDecoderSettings *swgMorseDecoderSettings = swgFeatureSettings->getMorseDecoderSettings();

// transfer data that has been modified. When force is on transfer all data except reverse API data

if (featureSettingsKeys.contains("title") || force) {
swgDemodAnalyzerSettings->setTitle(new QString(settings.m_title));
swgMorseDecoderSettings->setTitle(new QString(settings.m_title));
}
if (featureSettingsKeys.contains("rgbColor") || force) {
swgDemodAnalyzerSettings->setRgbColor(settings.m_rgbColor);
swgMorseDecoderSettings->setRgbColor(settings.m_rgbColor);
}

QString channelSettingsURL = QString("http://%1:%2/sdrangel/featureset/%3/feature/%4/settings")
Expand Down Expand Up @@ -650,16 +703,17 @@ int MorseDecoder::webapiActionsPost(
QString& errorMessage) {

MainCore* m_core = MainCore::instance();
auto action = query.getDemodAnalyzerActions();
auto action = query.getMorseDecoderActions();

if (action == nullptr) {
errorMessage = QString("missing MorseDecoderActions in request");
return 404;
}

auto deviceId = action->getDeviceId();
auto chanId = action->getChannelId();

ChannelAPI * chan = m_core->getChannel(deviceId, chanId);

if (chan == nullptr) {
errorMessage = QString("device(%1) or channel (%2) on the device does not exist").arg(deviceId).arg(chanId);
return 404;
Expand Down
4 changes: 2 additions & 2 deletions plugins/feature/morsedecoder/morsedecoderwebapiadapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ int MorseDecoderWebAPIAdapter::webapiSettingsGet(
QString& errorMessage)
{
(void) errorMessage;
response.setDemodAnalyzerSettings(new SWGSDRangel::SWGDemodAnalyzerSettings());
response.getDemodAnalyzerSettings()->init();
response.setMorseDecoderSettings(new SWGSDRangel::SWGMorseDecoderSettings());
response.getMorseDecoderSettings()->init();
MorseDecoder::webapiFormatFeatureSettings(response, m_settings);

return 200;
Expand Down
78 changes: 77 additions & 1 deletion sdrbase/resources/webapi/doc/html2/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6429,6 +6429,9 @@
"MapActions" : {
"$ref" : "#/definitions/MapActions"
},
"MorseDecoderActions" : {
"$ref" : "#/definitions/MorseDecoderActions"
},
"PERTesterActions" : {
"$ref" : "#/definitions/PERTesterActions"
},
Expand Down Expand Up @@ -6681,6 +6684,9 @@
"MapSettings" : {
"$ref" : "#/definitions/MapSettings"
},
"MorseDecoderSettings" : {
"$ref" : "#/definitions/MorseDecoderSettings"
},
"PERTesterSettings" : {
"$ref" : "#/definitions/PERTesterSettings"
},
Expand Down Expand Up @@ -10495,6 +10501,76 @@
}
},
"description" : "MetisMISOSettings"
};
defs.MorseDecoderActions = {
"properties" : {
"deviceId" : {
"type" : "integer",
"description" : "Device Id/Number that channel belongs to"
},
"channelId" : {
"type" : "integer",
"description" : "Channel Id/Number of the channel within the device"
}
},
"description" : "Morse Decoder actions"
};
defs.MorseDecoderSettings = {
"properties" : {
"title" : {
"type" : "string"
},
"rgbColor" : {
"type" : "integer"
},
"useReverseAPI" : {
"type" : "integer",
"description" : "Synchronize with reverse API\n * 1 - yes\n * 0 - no\n"
},
"reverseAPIAddress" : {
"type" : "string"
},
"reverseAPIPort" : {
"type" : "integer"
},
"udpEnabled" : {
"type" : "integer",
"description" : "Send decoded text via UDP\n * 1 - send\n * 0 - do not send\n"
},
"udpAddress" : {
"type" : "string",
"description" : "Address to semd text via UDP"
},
"udpPort" : {
"type" : "integer",
"description" : "Port to semd text via UDP"
},
"logFiledName" : {
"type" : "string",
"description" : "File to log the decoded text to"
},
"logEnabled" : {
"type" : "integer",
"description" : "Log decoded text to file\n * 1 - log\n * 0 - do not log\n"
},
"auto" : {
"type" : "integer",
"description" : "Auto detect CW pitch and keying speed\n * 1 - auto detect\n * 0 - use last values\n"
},
"reverseAPIFeatureSetIndex" : {
"type" : "integer"
},
"reverseAPIFeatureIndex" : {
"type" : "integer"
},
"scopeConfig" : {
"$ref" : "#/definitions/GLScope"
},
"rollupState" : {
"$ref" : "#/definitions/RollupState"
}
},
"description" : "MorseDecoder"
};
defs.NFMDemodReport = {
"properties" : {
Expand Down Expand Up @@ -58976,7 +59052,7 @@ <h3> Status: 501 - Function not implemented </h3>
</div>
<div id="generator">
<div class="content">
Generated 2024-05-13T21:38:23.490+02:00
Generated 2024-05-21T02:18:43.789+02:00
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ FeatureActions:
$ref: "/doc/swagger/include/LimeRFE.yaml#/LimeRFEActions"
MapActions:
$ref: "/doc/swagger/include/Map.yaml#/MapActions"
MorseDecoderActions:
$ref: "/doc/swagger/include/MorseDecoder.yaml#/MorseDecoderActions"
PERTesterActions:
$ref: "/doc/swagger/include/PERTester.yaml#/PERTesterActions"
RigCtlServerActions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ FeatureSettings:
$ref: "/doc/swagger/include/LimeRFE.yaml#/LimeRFESettings"
MapSettings:
$ref: "/doc/swagger/include/Map.yaml#/MapSettings"
MorseDecoderSettings:
$ref: "/doc/swagger/include/MorseDecoder.yaml#/MorseDecoderSettings"
PERTesterSettings:
$ref: "/doc/swagger/include/PERTester.yaml#/PERTesterSettings"
RadiosondeSettings:
Expand Down
Loading

0 comments on commit 176fe03

Please sign in to comment.