OpenCPN Partial API docs
Loading...
Searching...
No Matches
comm_drv_n2k_serial.h
1/***************************************************************************
2 *
3 * Project: OpenCPN
4 * Purpose:
5 * Author: David Register, Alec Leamas
6 *
7 ***************************************************************************
8 * Copyright (C) 2022 by David Register, Alec Leamas *
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the *
22 * Free Software Foundation, Inc., *
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
24 **************************************************************************/
25
26#ifndef _COMMDRIVERN2KSERIAL_H
27#define _COMMDRIVERN2KSERIAL_H
28
29#include <wx/thread.h>
30
31#include "comm_drv_n2k.h"
32#include "conn_params.h"
33
34#ifndef __OCPN__ANDROID__
35#include "serial/serial.h"
36#endif
37
38#define OUT_QUEUE_LENGTH 20
39#define MAX_OUT_QUEUE_MESSAGE_LENGTH 200
40
41#define ESCAPE 0x10
42#define STARTOFTEXT 0x02
43#define ENDOFTEXT 0x03
44
45#define MsgTypeN2kData 0x93
46#define MsgTypeN2kRequest 0x94
47
49class CommDriverN2KSerialThread; // fwdA
50
53
55class CommDriverN2KSerial : public CommDriverN2K, public wxEvtHandler {
56public:
58 CommDriverN2KSerial(const ConnectionParams* params, DriverListener& listener);
59
60 virtual ~CommDriverN2KSerial();
61
63 void Activate() override;
64
65 void SetListener(DriverListener& l) override{};
66
67 bool Open();
68 void Close();
69
70 bool SendMessage(std::shared_ptr<const NavMsg> msg,
71 std::shared_ptr<const NavAddr> addr) override;
72
73 int SetTXPGN(int pgn) override;
74
75 // Secondary thread life toggle
76 // Used to inform launching object (this) to determine if the thread can
77 // be safely called or polled, e.g. wxThread->Destroy();
78 void SetSecThreadActive(void) { m_bsec_thread_active = true; }
79 void SetSecThreadInActive(void) { m_bsec_thread_active = false; }
80 bool IsSecThreadActive() const { return m_bsec_thread_active; }
81
82 void SetSecondaryThread(CommDriverN2KSerialThread* secondary_Thread) {
83 m_pSecondary_Thread = secondary_Thread;
84 }
85 CommDriverN2KSerialThread* GetSecondaryThread() {
86 return m_pSecondary_Thread;
87 }
88 void SetThreadRunFlag(int run) { m_Thread_run_flag = run; }
89
90 void handle_N2K_SERIAL_RAW(CommDriverN2KSerialEvent& event);
91
92 int m_Thread_run_flag;
93
94private:
95 void ProcessManagementPacket(std::vector<unsigned char> *payload);
96 int SendMgmtMsg( unsigned char *string, size_t string_size,
97 unsigned char cmd_code,
98 int timeout_msec, bool *response_flag);
99
100 bool m_bok;
101 std::string m_portstring;
102 std::string m_BaudRate;
103 int m_handshake;
104
105 CommDriverN2KSerialThread* m_pSecondary_Thread;
106 bool m_bsec_thread_active;
107
108 ConnectionParams m_params;
109 DriverListener& m_listener;
110
111 bool m_bmg47_resp;
112 bool m_bmg01_resp;
113 bool m_bmg4B_resp;
114 bool m_bmg41_resp;
115 bool m_bmg42_resp;
116
117 std::string m_device_common_name;
118 uint64_t NAME;
119 int m_manufacturers_code;
120 bool m_got_mfg_code;
121
122};
123
124#endif // guard
Internal event worker thread -> main driver.
Internal worker thread.
Driver for NMEA200 messages over serial connections.
void Activate() override
Register driver and possibly do other post-ctor steps.
void SetListener(DriverListener &l) override
Set the entity which will receive incoming data.
Abstract driver interface for NMEA2000 messages.
Definition: comm_drv_n2k.h:33
Interface implemented by transport layer and possible other parties like test code which should handl...
Definition: comm_driver.h:47