Merged master 8748
This commit is contained in:
@@ -1,416 +0,0 @@
|
||||
#include "MessageClient.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include <QUdpSocket>
|
||||
#include <QHostInfo>
|
||||
#include <QTimer>
|
||||
#include <QQueue>
|
||||
#include <QByteArray>
|
||||
#include <QHostAddress>
|
||||
|
||||
#include "NetworkMessage.hpp"
|
||||
|
||||
#include "pimpl_impl.hpp"
|
||||
|
||||
#include "moc_MessageClient.cpp"
|
||||
|
||||
class MessageClient::impl
|
||||
: public QUdpSocket
|
||||
{
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
impl (QString const& id, QString const& version, QString const& revision,
|
||||
port_type server_port, MessageClient * self)
|
||||
: self_ {self}
|
||||
, id_ {id}
|
||||
, version_ {version}
|
||||
, revision_ {revision}
|
||||
, server_port_ {server_port}
|
||||
, schema_ {2} // use 2 prior to negotiation not 1 which is broken
|
||||
, heartbeat_timer_ {new QTimer {this}}
|
||||
{
|
||||
connect (heartbeat_timer_, &QTimer::timeout, this, &impl::heartbeat);
|
||||
connect (this, &QIODevice::readyRead, this, &impl::pending_datagrams);
|
||||
|
||||
heartbeat_timer_->start (NetworkMessage::pulse * 1000);
|
||||
|
||||
// bind to an ephemeral port
|
||||
bind ();
|
||||
}
|
||||
|
||||
~impl ()
|
||||
{
|
||||
closedown ();
|
||||
}
|
||||
|
||||
enum StreamStatus {Fail, Short, OK};
|
||||
|
||||
void parse_message (QByteArray const& msg);
|
||||
void pending_datagrams ();
|
||||
void heartbeat ();
|
||||
void closedown ();
|
||||
StreamStatus check_status (QDataStream const&) const;
|
||||
void send_message (QByteArray const&);
|
||||
void send_message (QDataStream const& out, QByteArray const& message)
|
||||
{
|
||||
if (OK == check_status (out))
|
||||
{
|
||||
send_message (message);
|
||||
}
|
||||
else
|
||||
{
|
||||
Q_EMIT self_->error ("Error creating UDP message");
|
||||
}
|
||||
}
|
||||
|
||||
Q_SLOT void host_info_results (QHostInfo);
|
||||
|
||||
MessageClient * self_;
|
||||
QString id_;
|
||||
QString version_;
|
||||
QString revision_;
|
||||
QString server_string_;
|
||||
port_type server_port_;
|
||||
QHostAddress server_;
|
||||
quint32 schema_;
|
||||
QTimer * heartbeat_timer_;
|
||||
|
||||
// hold messages sent before host lookup completes asynchronously
|
||||
QQueue<QByteArray> pending_messages_;
|
||||
QByteArray last_message_;
|
||||
};
|
||||
|
||||
#include "MessageClient.moc"
|
||||
|
||||
void MessageClient::impl::host_info_results (QHostInfo host_info)
|
||||
{
|
||||
if (QHostInfo::NoError != host_info.error ())
|
||||
{
|
||||
Q_EMIT self_->error ("UDP server lookup failed:\n" + host_info.errorString ());
|
||||
pending_messages_.clear (); // discard
|
||||
}
|
||||
else if (host_info.addresses ().size ())
|
||||
{
|
||||
server_ = host_info.addresses ()[0];
|
||||
|
||||
// send initial heartbeat which allows schema negotiation
|
||||
heartbeat ();
|
||||
|
||||
// clear any backlog
|
||||
while (pending_messages_.size ())
|
||||
{
|
||||
send_message (pending_messages_.dequeue ());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MessageClient::impl::pending_datagrams ()
|
||||
{
|
||||
while (hasPendingDatagrams ())
|
||||
{
|
||||
QByteArray datagram;
|
||||
datagram.resize (pendingDatagramSize ());
|
||||
QHostAddress sender_address;
|
||||
port_type sender_port;
|
||||
if (0 <= readDatagram (datagram.data (), datagram.size (), &sender_address, &sender_port))
|
||||
{
|
||||
parse_message (datagram);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MessageClient::impl::parse_message (QByteArray const& msg)
|
||||
{
|
||||
try
|
||||
{
|
||||
//
|
||||
// message format is described in NetworkMessage.hpp
|
||||
//
|
||||
NetworkMessage::Reader in {msg};
|
||||
if (OK == check_status (in) && id_ == in.id ()) // OK and for us
|
||||
{
|
||||
if (schema_ < in.schema ()) // one time record of server's
|
||||
// negotiated schema
|
||||
{
|
||||
schema_ = in.schema ();
|
||||
}
|
||||
|
||||
//
|
||||
// message format is described in NetworkMessage.hpp
|
||||
//
|
||||
switch (in.type ())
|
||||
{
|
||||
case NetworkMessage::Reply:
|
||||
{
|
||||
// unpack message
|
||||
QTime time;
|
||||
qint32 snr;
|
||||
float delta_time;
|
||||
quint32 delta_frequency;
|
||||
QByteArray mode;
|
||||
QByteArray message;
|
||||
in >> time >> snr >> delta_time >> delta_frequency >> mode >> message;
|
||||
if (check_status (in) != Fail)
|
||||
{
|
||||
Q_EMIT self_->reply (time, snr, delta_time, delta_frequency
|
||||
, QString::fromUtf8 (mode), QString::fromUtf8 (message));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case NetworkMessage::Replay:
|
||||
if (check_status (in) != Fail)
|
||||
{
|
||||
last_message_.clear ();
|
||||
Q_EMIT self_->replay ();
|
||||
}
|
||||
break;
|
||||
|
||||
case NetworkMessage::HaltTx:
|
||||
{
|
||||
bool auto_only {false};
|
||||
in >> auto_only;
|
||||
if (check_status (in) != Fail)
|
||||
{
|
||||
Q_EMIT self_->halt_tx (auto_only);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case NetworkMessage::FreeText:
|
||||
{
|
||||
QByteArray message;
|
||||
bool send {true};
|
||||
in >> message >> send;
|
||||
if (check_status (in) != Fail)
|
||||
{
|
||||
Q_EMIT self_->free_text (QString::fromUtf8 (message), send);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// Ignore
|
||||
//
|
||||
// Note that although server heartbeat messages are not
|
||||
// parsed here they are still partially parsed in the
|
||||
// message reader class to negotiate the maximum schema
|
||||
// number being used on the network.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (std::exception const& e)
|
||||
{
|
||||
Q_EMIT self_->error (QString {"MessageClient exception: %1"}.arg (e.what ()));
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
Q_EMIT self_->error ("Unexpected exception in MessageClient");
|
||||
}
|
||||
}
|
||||
|
||||
void MessageClient::impl::heartbeat ()
|
||||
{
|
||||
if (server_port_ && !server_.isNull ())
|
||||
{
|
||||
QByteArray message;
|
||||
NetworkMessage::Builder hb {&message, NetworkMessage::Heartbeat, id_, schema_};
|
||||
hb << NetworkMessage::Builder::schema_number // maximum schema number accepted
|
||||
<< version_.toUtf8 () << revision_.toUtf8 ();
|
||||
if (OK == check_status (hb))
|
||||
{
|
||||
writeDatagram (message, server_, server_port_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MessageClient::impl::closedown ()
|
||||
{
|
||||
if (server_port_ && !server_.isNull ())
|
||||
{
|
||||
QByteArray message;
|
||||
NetworkMessage::Builder out {&message, NetworkMessage::Close, id_, schema_};
|
||||
if (OK == check_status (out))
|
||||
{
|
||||
writeDatagram (message, server_, server_port_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MessageClient::impl::send_message (QByteArray const& message)
|
||||
{
|
||||
if (server_port_)
|
||||
{
|
||||
if (!server_.isNull ())
|
||||
{
|
||||
if (message != last_message_) // avoid duplicates
|
||||
{
|
||||
writeDatagram (message, server_, server_port_);
|
||||
last_message_ = message;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pending_messages_.enqueue (message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto MessageClient::impl::check_status (QDataStream const& stream) const -> StreamStatus
|
||||
{
|
||||
auto stat = stream.status ();
|
||||
StreamStatus result {Fail};
|
||||
switch (stat)
|
||||
{
|
||||
case QDataStream::ReadPastEnd:
|
||||
result = Short;
|
||||
break;
|
||||
|
||||
case QDataStream::ReadCorruptData:
|
||||
Q_EMIT self_->error ("Message serialization error: read corrupt data");
|
||||
break;
|
||||
|
||||
case QDataStream::WriteFailed:
|
||||
Q_EMIT self_->error ("Message serialization error: write error");
|
||||
break;
|
||||
|
||||
default:
|
||||
result = OK;
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
MessageClient::MessageClient (QString const& id, QString const& version, QString const& revision,
|
||||
QString const& server, port_type server_port, QObject * self)
|
||||
: QObject {self}
|
||||
, m_ {id, version, revision, server_port, this}
|
||||
{
|
||||
connect (&*m_, static_cast<void (impl::*) (impl::SocketError)> (&impl::error)
|
||||
, [this] (impl::SocketError e)
|
||||
{
|
||||
#if defined (Q_OS_WIN) && QT_VERSION >= 0x050500
|
||||
if (e != impl::NetworkError // take this out when Qt 5.5
|
||||
// stops doing this
|
||||
// spuriously
|
||||
&& e != impl::ConnectionRefusedError) // not
|
||||
// interested
|
||||
// in this with
|
||||
// UDP socket
|
||||
#else
|
||||
Q_UNUSED (e);
|
||||
#endif
|
||||
{
|
||||
Q_EMIT error (m_->errorString ());
|
||||
}
|
||||
});
|
||||
set_server (server);
|
||||
}
|
||||
|
||||
QHostAddress MessageClient::server_address () const
|
||||
{
|
||||
return m_->server_;
|
||||
}
|
||||
|
||||
auto MessageClient::server_port () const -> port_type
|
||||
{
|
||||
return m_->server_port_;
|
||||
}
|
||||
|
||||
void MessageClient::set_server (QString const& server)
|
||||
{
|
||||
m_->server_.clear ();
|
||||
m_->server_string_ = server;
|
||||
if (!server.isEmpty ())
|
||||
{
|
||||
// queue a host address lookup
|
||||
QHostInfo::lookupHost (server, &*m_, SLOT (host_info_results (QHostInfo)));
|
||||
}
|
||||
}
|
||||
|
||||
void MessageClient::set_server_port (port_type server_port)
|
||||
{
|
||||
m_->server_port_ = server_port;
|
||||
}
|
||||
|
||||
void MessageClient::send_raw_datagram (QByteArray const& message, QHostAddress const& dest_address
|
||||
, port_type dest_port)
|
||||
{
|
||||
if (dest_port && !dest_address.isNull ())
|
||||
{
|
||||
m_->writeDatagram (message, dest_address, dest_port);
|
||||
}
|
||||
}
|
||||
|
||||
void MessageClient::status_update (Frequency f, QString const& mode, QString const& dx_call
|
||||
, QString const& report, QString const& tx_mode
|
||||
, bool tx_enabled, bool transmitting, bool decoding
|
||||
, qint32 rx_df, qint32 tx_df, QString const& de_call
|
||||
, QString const& de_grid, QString const& dx_grid
|
||||
, bool watchdog_timeout, QString const& sub_mode
|
||||
, bool fast_mode)
|
||||
{
|
||||
if (m_->server_port_ && !m_->server_string_.isEmpty ())
|
||||
{
|
||||
QByteArray message;
|
||||
NetworkMessage::Builder out {&message, NetworkMessage::Status, m_->id_, m_->schema_};
|
||||
out << f << mode.toUtf8 () << dx_call.toUtf8 () << report.toUtf8 () << tx_mode.toUtf8 ()
|
||||
<< tx_enabled << transmitting << decoding << rx_df << tx_df << de_call.toUtf8 ()
|
||||
<< de_grid.toUtf8 () << dx_grid.toUtf8 () << watchdog_timeout << sub_mode.toUtf8 ()
|
||||
<< fast_mode;
|
||||
m_->send_message (out, message);
|
||||
}
|
||||
}
|
||||
|
||||
void MessageClient::decode (bool is_new, QTime time, qint32 snr, float delta_time, quint32 delta_frequency
|
||||
, QString const& mode, QString const& message_text)
|
||||
{
|
||||
if (m_->server_port_ && !m_->server_string_.isEmpty ())
|
||||
{
|
||||
QByteArray message;
|
||||
NetworkMessage::Builder out {&message, NetworkMessage::Decode, m_->id_, m_->schema_};
|
||||
out << is_new << time << snr << delta_time << delta_frequency << mode.toUtf8 () << message_text.toUtf8 ();
|
||||
m_->send_message (out, message);
|
||||
}
|
||||
}
|
||||
|
||||
void MessageClient::WSPR_decode (bool is_new, QTime time, qint32 snr, float delta_time, Frequency frequency
|
||||
, qint32 drift, QString const& callsign, QString const& grid, qint32 power)
|
||||
{
|
||||
if (m_->server_port_ && !m_->server_string_.isEmpty ())
|
||||
{
|
||||
QByteArray message;
|
||||
NetworkMessage::Builder out {&message, NetworkMessage::WSPRDecode, m_->id_, m_->schema_};
|
||||
out << is_new << time << snr << delta_time << frequency << drift << callsign.toUtf8 ()
|
||||
<< grid.toUtf8 () << power;
|
||||
m_->send_message (out, message);
|
||||
}
|
||||
}
|
||||
|
||||
void MessageClient::clear_decodes ()
|
||||
{
|
||||
if (m_->server_port_ && !m_->server_string_.isEmpty ())
|
||||
{
|
||||
QByteArray message;
|
||||
NetworkMessage::Builder out {&message, NetworkMessage::Clear, m_->id_, m_->schema_};
|
||||
m_->send_message (out, message);
|
||||
}
|
||||
}
|
||||
|
||||
void MessageClient::qso_logged (QDateTime timeOff, QString const& dx_call, QString const& dx_grid
|
||||
, Frequency dial_frequency, QString const& mode, QString const& report_sent
|
||||
, QString const& report_received, QString const& tx_power
|
||||
, QString const& comments, QString const& name, QDateTime timeOn)
|
||||
{
|
||||
if (m_->server_port_ && !m_->server_string_.isEmpty ())
|
||||
{
|
||||
QByteArray message;
|
||||
NetworkMessage::Builder out {&message, NetworkMessage::QSOLogged, m_->id_, m_->schema_};
|
||||
out << timeOff << dx_call.toUtf8 () << dx_grid.toUtf8 () << dial_frequency << mode.toUtf8 ()
|
||||
<< report_sent.toUtf8 () << report_received.toUtf8 () << tx_power.toUtf8 () << comments.toUtf8 () << name.toUtf8 () << timeOn;
|
||||
m_->send_message (out, message);
|
||||
}
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
subroutine softsym9w(id2,npts,xdt0,f0,width,nsubmode,xdt1,i1softsymbols)
|
||||
|
||||
parameter (NFFT=6912,NH=NFFT/2,NQ=NH/2)
|
||||
real s(NQ)
|
||||
real s2(0:8,85)
|
||||
real s3(0:7,69)
|
||||
real x(NFFT)
|
||||
complex cx(0:NH)
|
||||
integer*2 id2(60*12000)
|
||||
integer*1 i1SoftSymbolsScrambled(207)
|
||||
integer*1 i1softsymbols(207)
|
||||
include 'jt9sync.f90'
|
||||
equivalence (x,cx)
|
||||
|
||||
if(npts.eq.-99) stop !Silence compiler warning
|
||||
df=12000.0/NFFT
|
||||
i0a=max(1.0,(xdt0-1.0)*12000.0)
|
||||
i0b=(xdt0+1.0)*12000.0
|
||||
k1=max(1,nint((f0-0.5*width)/df))
|
||||
k2=min(NQ,nint((f0+0.5*width)/df))
|
||||
smax=0.
|
||||
i0pk=1
|
||||
i1softsymbols=0
|
||||
|
||||
do i0=i0a,i0b,432
|
||||
s=0.
|
||||
ssum=0.
|
||||
do j=1,16
|
||||
ia=i0 + (ii(j)-1)*nfft
|
||||
ib=ia+NFFT-1
|
||||
x=1.e-6*id2(ia:ib)
|
||||
call four2a(x,nfft,1,-1,0) !r2c FFT
|
||||
do k=1,NQ
|
||||
s(k)=s(k) + real(cx(k))**2 + aimag(cx(k))**2
|
||||
enddo
|
||||
enddo
|
||||
ssum=ssum + sum(s(k1:k2))
|
||||
if(ssum.gt.smax) then
|
||||
smax=ssum
|
||||
i0pk=i0
|
||||
else
|
||||
if(ssum.lt.0.7*smax) exit
|
||||
endif
|
||||
end do
|
||||
xdt1=(i0pk-1)/12000.0
|
||||
|
||||
if(i0pk.le.0) go to 999
|
||||
|
||||
m=0
|
||||
do j=1,85
|
||||
ia=i0pk + (j-1)*nfft
|
||||
ib=ia+NFFT-1
|
||||
x=1.e-6*id2(ia:ib)
|
||||
call four2a(x,nfft,1,-1,0) !r2c FFT
|
||||
do k=1,NQ
|
||||
s(k)=real(cx(k))**2 + aimag(cx(k))**2
|
||||
enddo
|
||||
|
||||
dtone=df*(2**nsubmode)
|
||||
do i=0,8
|
||||
f=f0 + i*dtone
|
||||
k1=max(1,nint((f-0.5*width)/df))
|
||||
k2=min(NQ,nint((f+0.5*width)/df))
|
||||
s2(i,j)=sum(s(k1:k2)) !Symbol spectra, including sync
|
||||
enddo
|
||||
|
||||
if(isync(j).eq.0) then
|
||||
m=m+1
|
||||
s3(0:7,m)=s2(1:8,j) !Symbol spectra, data only
|
||||
endif
|
||||
|
||||
! write(19,3101) j,s2(0:8,j)
|
||||
!3101 format(i2,9f8.2)
|
||||
enddo
|
||||
|
||||
ss=0.
|
||||
sig=0.
|
||||
do j=1,69
|
||||
smax=0.
|
||||
do i=0,7
|
||||
smax=max(smax,s3(i,j))
|
||||
ss=ss+s3(i,j)
|
||||
enddo
|
||||
sig=sig+smax
|
||||
ss=ss-smax
|
||||
enddo
|
||||
ave=ss/(69*7) !Baseline
|
||||
call pctile(s2,9*85,35,xmed)
|
||||
s3=s3/ave
|
||||
sig=sig/69. !Signal
|
||||
t=max(1.0,sig - 1.0)
|
||||
snrdb=db(t)
|
||||
|
||||
m0=3
|
||||
k=0
|
||||
do j=1,69
|
||||
smax=0.
|
||||
do i=0,7
|
||||
if(s3(i,j).gt.smax) smax=s3(i,j)
|
||||
enddo
|
||||
|
||||
do m=m0-1,0,-1 !Get bit-wise soft symbols
|
||||
if(m.eq.2) then
|
||||
r1=max(s3(4,j),s3(5,j),s3(6,j),s3(7,j))
|
||||
r0=max(s3(0,j),s3(1,j),s3(2,j),s3(3,j))
|
||||
else if(m.eq.1) then
|
||||
r1=max(s3(2,j),s3(3,j),s3(4,j),s3(5,j))
|
||||
r0=max(s3(0,j),s3(1,j),s3(6,j),s3(7,j))
|
||||
else
|
||||
r1=max(s3(1,j),s3(2,j),s3(4,j),s3(7,j))
|
||||
r0=max(s3(0,j),s3(3,j),s3(5,j),s3(6,j))
|
||||
endif
|
||||
|
||||
k=k+1
|
||||
i4=nint(10.0*(r1-r0))
|
||||
if(i4.lt.-127) i4=-127
|
||||
if(i4.gt.127) i4=127
|
||||
i1SoftSymbolsScrambled(k)=i4
|
||||
enddo
|
||||
enddo
|
||||
|
||||
! Remove interleaving
|
||||
call interleave9(i1SoftSymbolsScrambled,-1,i1SoftSymbols)
|
||||
|
||||
999 return
|
||||
end subroutine softsym9w
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,36 @@
|
||||
// boost/detail/lightweight_main.hpp -------------------------------------------------//
|
||||
|
||||
// Copyright Beman Dawes 2010
|
||||
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// See http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <iostream>
|
||||
#include <exception>
|
||||
|
||||
//--------------------------------------------------------------------------------------//
|
||||
// //
|
||||
// exception reporting main() that calls cpp_main() //
|
||||
// //
|
||||
//--------------------------------------------------------------------------------------//
|
||||
|
||||
int cpp_main(int argc, char* argv[]);
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
try
|
||||
{
|
||||
return cpp_main(argc, argv);
|
||||
}
|
||||
|
||||
catch (const std::exception& ex)
|
||||
{
|
||||
std::cout
|
||||
<< "\nERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR\n"
|
||||
<< "\n****************************** std::exception *****************************\n"
|
||||
<< ex.what()
|
||||
<< "\n***************************************************************************\n"
|
||||
<< std::endl;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
Reference in New Issue
Block a user