48using namespace std::literals::chrono_literals;
53 m_portstring(params->GetDSPort()),
54 m_baudrate(params->Baudrate),
56 [&](const std::vector<unsigned char>& v) { SendMessage(v); },
57 m_portstring, m_baudrate)),
60 m_stats_timer(*
this, 2s) {
61 m_garmin_handler =
nullptr;
62 this->attributes[
"commPort"] = params->Port.ToStdString();
63 this->attributes[
"userComment"] = params->UserComment.ToStdString();
64 this->attributes[
"ioDirection"] = DsPortTypeToString(params->IOSelect);
69CommDriverN0183Serial::~CommDriverN0183Serial() { Close(); }
71bool CommDriverN0183Serial::Open() {
73 comx = m_params.GetDSPort().AfterFirst(
':');
74 if (comx.IsEmpty())
return false;
76 wxString port_uc = m_params.GetDSPort().Upper();
78 auto send_func = [&](
const std::vector<unsigned char>& v) { SendMessage(v); };
79 if ((wxNOT_FOUND != port_uc.Find(
"USB")) &&
80 (wxNOT_FOUND != port_uc.Find(
"GARMIN"))) {
82 }
else if (m_params.Garmin) {
92void CommDriverN0183Serial::Close() {
94 wxString::Format(
"Closing NMEA Driver %s", m_portstring.c_str()));
99 if (m_serial_io->IsRunning()) {
100 wxLogMessage(
"Stopping Secondary Thread");
101 m_serial_io->RequestStop();
102 std::chrono::milliseconds elapsed;
103 if (m_serial_io->WaitUntilStopped(10s, elapsed)) {
104 MESSAGE_LOG <<
"Stopped in " << elapsed.count() <<
" msec.";
106 MESSAGE_LOG <<
"Not stopped after 10 sec.";
111 if (m_garmin_handler) {
112 m_garmin_handler->Close();
113 delete m_garmin_handler;
114 m_garmin_handler =
nullptr;
118bool CommDriverN0183Serial::IsGarminThreadActive()
const {
119 if (m_garmin_handler) {
122 if (m_garmin_handler->m_usb_handle != INVALID_HANDLE_VALUE)
132void CommDriverN0183Serial::StopGarminUSBIOThread(
bool b_pause)
const {
133 if (m_garmin_handler) {
134 m_garmin_handler->StopIOThread(b_pause);
138bool CommDriverN0183Serial::SendMessage(std::shared_ptr<const NavMsg> msg,
139 std::shared_ptr<const NavAddr> addr) {
140 auto msg_0183 = std::dynamic_pointer_cast<const Nmea0183Msg>(msg);
141 wxString sentence(msg_0183->payload.c_str());
143 if (m_serial_io->IsRunning()) {
144 for (
int retries = 0; retries < 10; retries += 1) {
145 if (m_serial_io->SetOutMsg(sentence)) {
155void CommDriverN0183Serial::SendMessage(
const std::vector<unsigned char>& msg) {
158 if (m_params.IOSelect == DS_TYPE_OUTPUT)
return;
NMEA0183 basic parsing common parts:
void SendToListener(const std::string &payload, DriverListener &listener, const ConnectionParams ¶ms)
Wrap argument string in NavMsg pointer, forward to listener.
Interface for handling incoming messages.
Where messages are sent to or received from.
Nmea0183 serial communications wrapper, possibly running a thread.
Line-oriented input/output buffers.
Communication statistics infrastructure.
Enhanced logging interface on top of wx/log.h.
General observable implementation with several specializations.
Basic synchronization primitive.