26 #ifndef _COMMDRIVERN2KNET_H
27 #define _COMMDRIVERN2KNET_H
29 #include <wx/wxprec.h>
35 #include "model/comm_can_util.h"
36 #include "model/comm_drv_n2k.h"
37 #include "model/conn_params.h"
39 #include <wx/datetime.h>
46 #define GSocket GlibGSocket
47 #include <wx/socket.h>
50 #include <wx/socket.h>
54 #include <sys/socket.h>
55 #include <netinet/in.h>
58 #define RX_BUFFER_SIZE_NET 4096
61 #define STARTOFTEXT 0x02
62 #define ENDOFTEXT 0x03
64 #define MsgTypeN2kData 0x93
65 #define MsgTypeN2kRequest 0x94
70 N2KFormat_Undefined = 0,
72 N2KFormat_Actisense_RAW_ASCII,
73 N2KFormat_Actisense_N2K_ASCII,
74 N2KFormat_Actisense_N2K,
75 N2KFormat_Actisense_RAW,
76 N2KFormat_Actisense_NGT,
96 size_t capacity()
const;
100 void put(
unsigned char item);
105 std::unique_ptr<unsigned char[]> buf_;
108 const size_t max_size_;
127 bool SetOutputSocketOptions(wxSocketBase* tsock);
128 void OnServerSocketEvent(wxSocketEvent& event);
129 void OnTimerSocket(wxTimerEvent& event) { OnTimerSocket(); }
130 void OnTimerSocket();
132 void OpenNetworkGPSD();
133 void OpenNetworkTCP(
unsigned int addr);
134 void OpenNetworkUDP(
unsigned int addr);
135 void OnSocketReadWatchdogTimer(wxTimerEvent& event);
138 bool SendMessage(std::shared_ptr<const NavMsg> msg,
139 std::shared_ptr<const NavAddr> addr)
override;
140 wxSocketBase* GetSock()
const {
return m_sock; }
147 wxString GetNetPort()
const {
return m_net_port; }
148 wxIPV4address GetAddr()
const {
return m_addr; }
149 wxTimer* GetSocketThreadWatchdogTimer() {
150 return &m_socketread_watchdog_timer;
152 wxTimer* GetSocketTimer() {
return &m_socket_timer; }
153 void SetSock(wxSocketBase* sock) { m_sock = sock; }
154 void SetTSock(wxSocketBase* sock) { m_tsock = sock; }
155 wxSocketBase* GetTSock()
const {
return m_tsock; }
156 void SetSockServer(wxSocketServer* sock) { m_socket_server = sock; }
157 wxSocketServer* GetSockServer()
const {
return m_socket_server; }
158 void SetMulticast(
bool multicast) { m_is_multicast = multicast; }
159 bool GetMulticast()
const {
return m_is_multicast; }
161 NetworkProtocol GetProtocol() {
return m_net_protocol; }
162 void SetBrxConnectEvent(
bool event) { m_brx_connect_event = event; }
163 bool GetBrxConnectEvent() {
return m_brx_connect_event; }
165 void SetConnectTime(wxDateTime time) { m_connect_time = time; }
166 wxDateTime GetConnectTime() {
return m_connect_time; }
168 dsPortType GetPortType()
const {
return m_io_select; }
169 wxString GetPort()
const {
return m_portstring; }
171 std::vector<unsigned char> PushFastMsgFragment(
const CanHeader& header,
173 std::vector<unsigned char> PushCompleteMsg(
const CanHeader header,
175 const can_frame frame);
177 void HandleCanFrameInput(can_frame frame);
179 ConnectionType GetConnectionType()
const {
return m_connection_type; }
181 bool ChecksumOK(
const std::string& sentence);
182 void SetOk(
bool ok) { m_bok = ok; };
184 N2K_Format DetectFormat(std::vector<unsigned char> packet);
185 bool ProcessActisense_ASCII_RAW(std::vector<unsigned char> packet);
186 bool ProcessActisense_ASCII_N2K(std::vector<unsigned char> packet);
187 bool ProcessActisense_N2K(std::vector<unsigned char> packet);
188 bool ProcessActisense_RAW(std::vector<unsigned char> packet);
189 bool ProcessActisense_NGT(std::vector<unsigned char> packet);
190 bool ProcessSeaSmart(std::vector<unsigned char> packet);
191 bool ProcessMiniPlex(std::vector<unsigned char> packet);
194 bool SendN2KNetwork(std::shared_ptr<const Nmea2000Msg> &msg,
195 std::shared_ptr<const NavAddr2000> dest_addr);
197 std::vector<std::vector<unsigned char>>
198 GetTxVector(
const std::shared_ptr<const Nmea2000Msg> &msg,
199 std::shared_ptr<const NavAddr2000> dest_addr);
200 bool SendSentenceNetwork(std::vector<std::vector<unsigned char>> payload);
201 bool HandleMgntMsg(uint64_t pgn, std::vector<unsigned char> &payload);
205 NetworkProtocol m_net_protocol;
206 wxIPV4address m_addr;
207 wxSocketBase* m_sock;
208 wxSocketBase* m_tsock;
209 wxSocketServer* m_socket_server;
215 std::string m_sock_buffer;
216 wxString m_portstring;
217 dsPortType m_io_select;
218 wxDateTime m_connect_time;
219 bool m_brx_connect_event;
220 bool m_bchecksumCheck;
221 ConnectionType m_connection_type;
223 wxTimer m_socket_timer;
224 wxTimer m_socketread_watchdog_timer;
228 bool m_bInMsg, m_bGotESC, m_bGotSOT;
231 unsigned char *rx_buffer;
232 std::string m_sentence;
235 N2K_Format m_n2k_format;
241 DECLARE_EVENT_TABLE()
void SetListener(DriverListener &l) override
Set the entity which will receive incoming data.
void OnSocketEvent(wxSocketEvent &event)
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...
Track fast message fragments eventually forming complete messages.
Define an action to be performed when a KeyProvider is notified.