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 <atomic>
30
31#include <wx/thread.h>
32
33#include "config.h"
34#include "model/comm_drv_n2k.h"
35#include "model/conn_params.h"
36
37#ifndef __ANDROID__
38#include "serial/serial.h"
39#endif
40
41#define OUT_QUEUE_LENGTH 20
42#define MAX_OUT_QUEUE_MESSAGE_LENGTH 200
43
44#define ESCAPE 0x10
45#define STARTOFTEXT 0x02
46#define ENDOFTEXT 0x03
47
48#define MsgTypeN2kData 0x93
49#define MsgTypeN2kRequest 0x94
50
51class CommDriverN2KSerialThread; // fwd
53
54class CommDriverN2KSerial : public CommDriverN2K, public wxEvtHandler {
55public:
57 CommDriverN2KSerial(const ConnectionParams* params, DriverListener& listener);
58
59 virtual ~CommDriverN2KSerial();
60
61 void SetListener(DriverListener& l) override {};
62
63 bool Open();
64 void Close();
65
66 bool SendMessage(std::shared_ptr<const NavMsg> msg,
67 std::shared_ptr<const NavAddr> addr) override;
68
69 int SetTXPGN(int pgn) override;
70
71 // Secondary thread life toggle
72 // Used to inform launching object (this) to determine if the thread can
73 // be safely called or polled, e.g. wxThread->Destroy();
74 void SetSecThreadActive(void) { m_bsec_thread_active = true; }
75 void SetSecThreadInActive(void) { m_bsec_thread_active = false; }
76 bool IsSecThreadActive() const { return m_bsec_thread_active; }
77
78 void SetSecondaryThread(CommDriverN2KSerialThread* secondary_Thread) {
79 m_pSecondary_Thread = secondary_Thread;
80 }
81 CommDriverN2KSerialThread* GetSecondaryThread() {
82 return m_pSecondary_Thread;
83 }
84 void SetThreadRunFlag(int run) { m_Thread_run_flag = run; }
85
86 void handle_N2K_SERIAL_RAW(CommDriverN2KSerialEvent& event);
87 int GetMfgCode();
88
89 std::atomic_int m_Thread_run_flag;
90
91private:
92 void ProcessManagementPacket(std::vector<unsigned char>* payload);
98 int SendMgmtMsg(unsigned char* string, size_t string_size,
99 unsigned char cmd_code, int timeout_msec,
100 bool* response_flag);
101
102 bool m_bok;
103 std::string m_portstring;
104 std::string m_BaudRate;
105 int m_handshake;
106
107 CommDriverN2KSerialThread* m_pSecondary_Thread;
108 bool m_bsec_thread_active;
109
110 ConnectionParams m_params;
111 DriverListener& m_listener;
112
113 bool m_bmg47_resp;
114 bool m_bmg01_resp;
115 bool m_bmg4B_resp;
116 bool m_bmg41_resp;
117 bool m_bmg42_resp;
118
119 std::string m_device_common_name;
120 uint64_t NAME;
121 int m_manufacturers_code;
122 bool m_got_mfg_code;
123};
124
125#endif // guard
void SetListener(DriverListener &l) override
Set the entity which will receive incoming data.
Interface implemented by transport layer and possible other parties like test code which should handl...
Definition comm_driver.h:48