OpenCPN Partial API docs
comm_drv_n0183_serial.h
Go to the documentation of this file.
1  /**************************************************************************
2  * Copyright (C) 2022 by David Register, Alec Leamas *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation; either version 2 of the License, or *
7  * (at your option) any later version. *
8  * *
9  * This program is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU General Public License *
15  * along with this program; if not, write to the *
16  * Free Software Foundation, Inc., *
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18  **************************************************************************/
19 
22 #ifndef _COMMDRIVERN0183SERIAL_H
23 #define _COMMDRIVERN0183SERIAL_H
24 
25 #include <atomic>
26 #include <string>
27 
28 #include <wx/event.h>
29 
30 #include "model/comm_drv_n0183.h"
31 #include "model/comm_out_queue.h"
32 #include "model/conn_params.h"
33 #include "model/garmin_protocol_mgr.h"
34 
35 class CommDriverN0183SerialThread; // Internal
36 
37 class CommDriverN0183SerialEvent : public wxEvent {
38 public:
39  CommDriverN0183SerialEvent( wxEventType commandType, int id);
41 
42  // accessors
43  void SetPayload(std::shared_ptr<std::vector<unsigned char>> data);
44  std::shared_ptr<std::vector<unsigned char>> GetPayload();
45 
46  // required for sending with wxPostEvent()
47  wxEvent* Clone() const;
48 private:
49  std::shared_ptr<std::vector<unsigned char>> m_payload;
50 };
51 
52 wxDECLARE_EVENT(wxEVT_COMMDRIVER_N0183_SERIAL, CommDriverN0183SerialEvent);
53 
54 
55 class CommDriverN0183Serial : public CommDriverN0183, public wxEvtHandler {
56 public:
58 
59  virtual ~CommDriverN0183Serial();
60 
62  void Activate() override;
63 
64  bool Open();
65  void Close();
66 
67  // Secondary thread life toggle
68  // Used to inform launching object (this) to determine if the thread can
69  // be safely called or polled, e.g. wxThread->Destroy();
70  void SetSecThreadActive(void) { m_sec_thread_active = true; }
71  void SetSecThreadInActive(void) { m_sec_thread_active = false; }
72  bool IsSecThreadActive() const { return m_sec_thread_active; }
73 
74  bool IsGarminThreadActive();
75  void StopGarminUSBIOThread(bool bPause);
76 
77  void SetSecondaryThread(CommDriverN0183SerialThread* secondary_Thread) {
78  m_secondary_thread = secondary_Thread;
79  }
80  CommDriverN0183SerialThread* GetSecondaryThread() {
81  return m_secondary_thread;
82  }
83  void SetThreadRunFlag(int run) { m_Thread_run_flag = run; }
84 
85  std::atomic_int m_Thread_run_flag;
86 
87  ConnectionParams GetParams() const { return m_params; }
88 
89  bool SendMessage(std::shared_ptr<const NavMsg> msg,
90  std::shared_ptr<const NavAddr> addr) override;
91 
92 private:
93  bool m_ok;
94  std::string m_portstring;
95  std::string m_baudrate;
96  int m_handshake;
97 
98  CommDriverN0183SerialThread* m_secondary_thread;
99  bool m_sec_thread_active;
100 
101  GarminProtocolHandler * m_garmin_handler;
102 
103  ConnectionParams m_params;
104  DriverListener& m_listener;
105 
106  std::unique_ptr<CommOutQueue> m_out_queue;
107 
108  void handle_N0183_MSG(CommDriverN0183SerialEvent& event);
109 };
110 
111 #endif // guard
void Activate() override
Register driver and possibly do other post-ctor steps.
Interface implemented by transport layer and possible other parties like test code which should handl...
Definition: comm_driver.h:47