2019-03-24 21:01:03 -04:00
|
|
|
#include "SpotClient.h"
|
|
|
|
#include "Message.h"
|
|
|
|
|
|
|
|
#include "moc_SpotClient.cpp"
|
|
|
|
|
|
|
|
SpotClient::SpotClient(MessageClient *client, QObject *parent):
|
|
|
|
QObject(parent),
|
|
|
|
m_client { client }
|
|
|
|
{
|
|
|
|
prepare();
|
|
|
|
|
|
|
|
connect(&m_timer, &QTimer::timeout, this, &SpotClient::processSpots);
|
|
|
|
m_timer.setInterval(60 * 1000);
|
|
|
|
m_timer.setSingleShot(false);
|
|
|
|
m_timer.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpotClient::prepare(){
|
|
|
|
QHostInfo::lookupHost("spot.js8call.com", this, SLOT(dnsLookupResult(QHostInfo)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpotClient::dnsLookupResult(QHostInfo info){
|
|
|
|
if (info.addresses().isEmpty()) {
|
|
|
|
qDebug() << "SpotClient Error:" << info.errorString();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_address = info.addresses().at(0);
|
|
|
|
qDebug() << "SpotClient Resolve:" << m_address.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpotClient::setLocalStation(QString callsign, QString grid, QString info, QString version){
|
|
|
|
bool changed = false;
|
|
|
|
|
|
|
|
if(m_call != callsign){
|
|
|
|
m_call = callsign;
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(m_grid != grid){
|
|
|
|
m_grid = grid;
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(m_info != info){
|
|
|
|
m_info = info;
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(m_version != version){
|
|
|
|
m_version = version;
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
|
2019-03-26 22:55:28 -04:00
|
|
|
// send local information to network on change, or once every 15 minutes
|
|
|
|
if(changed || m_seq % 15 == 0){
|
2019-03-24 21:01:03 -04:00
|
|
|
enqueueLocalSpot(callsign, grid, info, version);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpotClient::enqueueLocalSpot(QString callsign, QString grid, QString info, QString version){
|
|
|
|
auto m = Message("RX.LOCAL", "", {
|
|
|
|
{"CALLSIGN", QVariant(callsign)},
|
|
|
|
{"GRID", QVariant(grid)},
|
|
|
|
{"INFO", QVariant(info)},
|
|
|
|
{"VERSION", QVariant(version)},
|
|
|
|
});
|
|
|
|
|
|
|
|
m_queue.enqueue(m.toJson());
|
|
|
|
}
|
|
|
|
|
2020-04-04 22:45:51 -04:00
|
|
|
void SpotClient::enqueueSpot(QString callsign, QString grid, int submode, int dial, int offset, int snr){
|
2019-03-24 21:01:03 -04:00
|
|
|
auto m = Message("RX.SPOT", "", {
|
2019-03-25 11:58:23 -04:00
|
|
|
{"BY", QVariant(QMap<QString, QVariant>{
|
|
|
|
{"CALLSIGN", QVariant(m_call)},
|
|
|
|
{"GRID", QVariant(m_grid)},
|
|
|
|
})},
|
2019-03-24 21:01:03 -04:00
|
|
|
{"CALLSIGN", QVariant(callsign)},
|
|
|
|
{"GRID", QVariant(grid)},
|
2020-04-04 22:45:51 -04:00
|
|
|
{"FREQ", QVariant(dial+offset)},
|
|
|
|
{"DIAL", QVariant(dial)},
|
|
|
|
{"OFFSET", QVariant(offset)},
|
2019-03-24 21:01:03 -04:00
|
|
|
{"SNR", QVariant(snr)},
|
2019-12-14 22:53:34 -05:00
|
|
|
{"SPEED", QVariant(submode)},
|
2019-03-24 21:01:03 -04:00
|
|
|
});
|
|
|
|
|
2019-03-25 15:05:13 -04:00
|
|
|
m_queue.enqueue(m.toJson());
|
|
|
|
}
|
|
|
|
|
2020-04-04 22:45:51 -04:00
|
|
|
void SpotClient::enqueueCmd(QString cmd, QString from, QString to, QString relayPath, QString text, QString grid, QString extra, int submode, int dial, int offset, int snr){
|
2019-03-25 15:05:13 -04:00
|
|
|
auto m = Message("RX.DIRECTED", "", {
|
|
|
|
{"BY", QVariant(QMap<QString, QVariant>{
|
|
|
|
{"CALLSIGN", QVariant(m_call)},
|
|
|
|
{"GRID", QVariant(m_grid)},
|
|
|
|
})},
|
|
|
|
{"CMD", QVariant(cmd)},
|
|
|
|
{"FROM", QVariant(from)},
|
|
|
|
{"TO", QVariant(to)},
|
|
|
|
{"PATH", QVariant(relayPath)},
|
|
|
|
{"TEXT", QVariant(text)},
|
|
|
|
{"GRID", QVariant(grid)},
|
|
|
|
{"EXTRA", QVariant(extra)},
|
2020-04-04 22:45:51 -04:00
|
|
|
{"FREQ", QVariant(dial+offset)},
|
|
|
|
{"DIAL", QVariant(dial)},
|
|
|
|
{"OFFSET", QVariant(offset)},
|
2019-03-25 15:05:13 -04:00
|
|
|
{"SNR", QVariant(snr)},
|
2019-12-14 22:53:34 -05:00
|
|
|
{"SPEED", QVariant(submode)},
|
2019-03-25 15:05:13 -04:00
|
|
|
});
|
|
|
|
|
2019-03-24 21:01:03 -04:00
|
|
|
m_queue.enqueue(m.toJson());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpotClient::processSpots(){
|
|
|
|
if(m_address.isNull()){
|
|
|
|
prepare();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(!m_queue.isEmpty()){
|
|
|
|
sendRawSpot(m_queue.dequeue());
|
|
|
|
}
|
2019-03-25 09:52:35 -04:00
|
|
|
|
|
|
|
m_seq++;
|
2019-03-24 21:01:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SpotClient::sendRawSpot(QByteArray payload){
|
|
|
|
if(!m_address.isNull()){
|
|
|
|
m_client->send_raw_datagram(payload, m_address, 50000);
|
|
|
|
}
|
|
|
|
}
|