Updated API to be better organized and scoped functions

This commit is contained in:
Jordan Sherer 2018-08-09 22:44:25 -04:00
parent f4688b44d3
commit 899a914a88
3 changed files with 121 additions and 49 deletions

View File

@ -2093,6 +2093,9 @@ for assessing propagation and system performance.</string>
</item> </item>
<item> <item>
<widget class="QCheckBox" name="udpWindowToFront"> <widget class="QCheckBox" name="udpWindowToFront">
<property name="visible">
<bool>false</bool>
</property>
<property name="toolTip"> <property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Indicate acceptance of an incoming UDP request. The effect of this option varies depending on the operating system and window manager, its intent is to notify the acceptance of an incoming UDP request even if this application is minimized or hidden.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Indicate acceptance of an incoming UDP request. The effect of this option varies depending on the operating system and window manager, its intent is to notify the acceptance of an incoming UDP request even if this application is minimized or hidden.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property> </property>
@ -2103,6 +2106,9 @@ for assessing propagation and system performance.</string>
</item> </item>
<item> <item>
<widget class="QCheckBox" name="udpWindowRestore"> <widget class="QCheckBox" name="udpWindowRestore">
<property name="visible">
<bool>false</bool>
</property>
<property name="toolTip"> <property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Restore the window from minimized if an UDP request is accepted.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Restore the window from minimized if an UDP request is accepted.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property> </property>

View File

@ -5572,11 +5572,6 @@ void MainWindow::displayTextForFreq(QString text, int freq, QDateTime date, bool
block = -1; block = -1;
} }
sendNetworkMessage("RECV", text, {
{"UTC", QVariant(date.toSecsSinceEpoch())},
{"OFFSET", QVariant(freq)},
});
m_rxFrameBlockNumbers[freq] = writeMessageTextToUI(date, text, freq, bold, block); m_rxFrameBlockNumbers[freq] = writeMessageTextToUI(date, text, freq, bold, block);
} }
@ -8972,44 +8967,23 @@ void MainWindow::networkMessage(Message const &message)
return; return;
} }
if(type == "GET_CALL_ACTIVITY"){ // Inspired by FLDigi
QMap<QString, QVariant> calls; // TODO: MAIN.RX - Turn on RX
foreach(auto cd, m_callActivity.values()){ // TODO: MAIN.TX - Transmit
QMap<QString, QVariant> detail; // TODO: MAIN.TUNE - Tune
detail["SNR"] = QVariant(cd.snr); // TODO: MAIN.HALT - Halt
detail["GRID"] = QVariant(cd.grid);
detail["UTC"] = QVariant(cd.utcTimestamp.toSecsSinceEpoch());
calls[cd.call] = QVariant(detail);
}
sendNetworkMessage("CALL_ACTIVITY", "", calls); // RIG.GET_FREQ - Get the current Frequency
return; // RIG.SET_FREQ - Set the current Frequency
} if(type == "RIG.GET_FREQ"){
sendNetworkMessage("RIG.FREQ", "", {
if(type == "GET_CALLSIGN"){
sendNetworkMessage("CALLSIGN", m_config.my_callsign());
return;
}
if(type == "GET_GRID"){
sendNetworkMessage("GRID", m_config.my_grid());
return;
}
if(type == "SET_GRID"){
m_config.set_location(message.value());
return;
}
if(type == "GET_FREQ"){
sendNetworkMessage("FREQ", "", {
{"DIAL", QVariant((quint64)dialFrequency())}, {"DIAL", QVariant((quint64)dialFrequency())},
{"OFFSET", QVariant((quint64)currentFreqOffset())} {"OFFSET", QVariant((quint64)currentFreqOffset())}
}); });
return; return;
} }
if(type == "SET_FREQ"){ if(type == "RIG.SET_FREQ"){
auto params = message.params(); auto params = message.params();
if(params.contains("DIAL")){ if(params.contains("DIAL")){
bool ok = false; bool ok = false;
@ -9019,7 +8993,6 @@ void MainWindow::networkMessage(Message const &message)
displayDialFrequency(); displayDialFrequency();
} }
} }
if(params.contains("OFFSET")){ if(params.contains("OFFSET")){
bool ok = false; bool ok = false;
auto f = params["OFFSET"].toInt(&ok); auto f = params["OFFSET"].toInt(&ok);
@ -9027,10 +9000,87 @@ void MainWindow::networkMessage(Message const &message)
setFreqOffsetForRestore(f, false); setFreqOffsetForRestore(f, false);
} }
} }
}
// STATION.GET_CALLSIGN - Get the current callsign
// STATION.GET_GRID - Get the current grid locator
// STATION.SET_GRID - Set the current grid locator
if(type == "STATION.GET_CALLSIGN"){
sendNetworkMessage("STATION.CALLSIGN", m_config.my_callsign());
return; return;
} }
if(type == "SEND_MESSAGE"){ if(type == "STATION.GET_GRID"){
sendNetworkMessage("STATION.GRID", m_config.my_grid());
return;
}
if(type == "STATION.SET_GRID"){
m_config.set_location(message.value());
sendNetworkMessage("STATION.GRID", m_config.my_grid());
return;
}
// RX.GET_CALL_ACTIVITY
// RX.GET_BAND_ACTIVITY
// RX.GET_TEXT
if(type == "RX.GET_CALL_ACTIVITY"){
QMap<QString, QVariant> calls;
foreach(auto cd, m_callActivity.values()){
QMap<QString, QVariant> detail;
detail["SNR"] = QVariant(cd.snr);
detail["GRID"] = QVariant(cd.grid);
detail["UTC"] = QVariant(cd.utcTimestamp.toSecsSinceEpoch());
calls[cd.call] = QVariant(detail);
}
sendNetworkMessage("RX.CALL_ACTIVITY", "", calls);
return;
}
if(type == "RX.GET_BAND_ACTIVITY"){
QMap<QString, QVariant> offsets;
foreach(auto offset, m_bandActivity.keys()){
auto activity = m_bandActivity[offset];
if(activity.isEmpty()){
continue;
}
auto d = activity.last();
QMap<QString, QVariant> detail;
detail["FREQ"] = QVariant(d.freq);
detail["TEXT"] = QVariant(d.text);
detail["SNR"] = QVariant(d.snr);
detail["UTC"] = QVariant(d.utcTimestamp.toSecsSinceEpoch());
offsets[QString("%1").arg(offset)] = QVariant(detail);
}
sendNetworkMessage("RX.BAND_ACTIVITY", "", offsets);
return;
}
if(type == "RX.GET_TEXT"){
sendNetworkMessage("RX.TEXT", ui->textEditRX->toPlainText());
return;
}
// TX.GET_TEXT
// TX.SET_TEXT
// TX.SEND_MESSAGE
if(type == "TX.GET_TEXT"){
sendNetworkMessage("TX.TEXT", ui->extFreeTextMsgEdit->toPlainText());
return;
}
if(type == "TX.SET_TEXT"){
addMessageText(message.value(), true);
return;
}
if(type == "TX.SEND_MESSAGE"){
auto text = message.value(); auto text = message.value();
if(!text.isEmpty()){ if(!text.isEmpty()){
enqueueMessage(PriorityNormal, text, -1, nullptr); enqueueMessage(PriorityNormal, text, -1, nullptr);
@ -9038,6 +9088,14 @@ void MainWindow::networkMessage(Message const &message)
} }
} }
// WINDOW.RAISE
if(type == "WINDOW.RAISE"){
setWindowState(Qt::WindowActive);
activateWindow();
return;
}
qDebug() << "Unable to process networkMessage:" << type; qDebug() << "Unable to process networkMessage:" << type;
} }

30
udp.py
View File

@ -21,7 +21,7 @@ def to_message(typ, value='', params=None):
class Server(object): class Server(object):
first = True
def process(self, message): def process(self, message):
typ = message.get('type', '') typ = message.get('type', '')
value = message.get('value', '') value = message.get('value', '')
@ -37,20 +37,28 @@ class Server(object):
if params: if params:
print('-> params: ', params) print('-> params: ', params)
if typ == 'PING': #### if typ == 'PING':
self.send('GET_GRID') #### if self.first:
self.send('GET_FREQ') #### self.send('RX.GET_BAND_ACTIVITY')
self.send('GET_CALLSIGN') #### self.send('TX.SET_TEXT', 'HERE WE GO')
self.send('GET_CALL_ACTIVITY') #### time.sleep(1)
#### self.send('WINDOW.RAISE')
#### self.first = False
#### elif typ == 'GRID': #### if typ == 'PING':
#### self.send('STATION.GET_GRID')
#### self.send('RIG.GET_FREQ')
#### self.send('STATION.GET_CALLSIGN')
#### self.send('RX.GET_CALL_ACTIVITY')
#### elif typ == 'STATION.GRID':
#### if value != 'EM73TU49TQ': #### if value != 'EM73TU49TQ':
#### self.send('SET_GRID', 'EM73TU49TQ') #### self.send('STATION.SET_GRID', 'EM73TU49TQ')
#### elif typ == 'FREQ': #### elif typ == 'RIG.FREQ':
#### if params.get('DIAL', 0) != 14064000: #### if params.get('DIAL', 0) != 14064000:
#### self.send('SET_FREQ', '', {"DIAL": 14064000, "OFFSET": 977}) #### self.send('RIG.SET_FREQ', '', {"DIAL": 14064000, "OFFSET": 977})
#### self.send('SEND_MESSAGE', 'HELLO WORLD') #### self.send('TX.SEND_MESSAGE', 'HELLO WORLD')
elif typ == 'CLOSE': elif typ == 'CLOSE':
self.close() self.close()