| Visioscan Set SDK Libraries 1.3.5 Visioscan Set SDK Help documentation file for C++ and C++/CLI |

Loading...
Searching...
No Matches
EthernetCommunication.h
1#pragma once
2#include <string>
3#include <tchar.h>
4#include <iostream>
5#include <atomic>
6#include <Ws2tcpip.h>
7#include <winsock2.h>
8#include <Windows.h>
9#include <thread>
10#include <sstream>
11#include <semaphore>
12#include <queue>
13#pragma comment(lib, "Ws2_32.lib")
14#pragma comment(lib, "Iphlpapi.lib")
15#include "BaseCommunication.h"
16#include "EthernetSettings.h"
17#include "BaseDataExtractor.h"
18#include "Utility.h"
19#include "DevicePinger.h"
20#include "CommunicationStructures.h"
21#include "CommunicationEnumeration.h"
22#include "ClockUtilities.h"
23#include <IPTypes.h>
24#include <iphlpapi.h>
25
26 using namespace std;
27
28#ifdef STARFLEETTOOLBOX_EXPORTS
29#define ETHCOMM __declspec(dllexport)
30#else
31#define ETHCOMM __declspec(dllimport)
32#endif
33
34#define DATA_READY 1
35#define DATA_NOT_READY 0
36
37#define INTERFACE_IS_IN_SAME_NET 0
38#define INTERFACE_IS_NOT_IN_SAME_NET 1
39#define INTERFACE_NOT_USED 2
40#define INTERFACE_INVALID_MASKING 3
41
42
48 class ETHCOMM EthernetCommunication :
49 public BaseCommunication
50{
51 public:
52 const int TCP_NEWORKQUEUE_OVERFLOWLIMIT = 20;
53 const int TCP_RAWDATA_QUEUE_OVERFLOWLIMIT = 20;
54 const int MAX_SIZE_TO_READ = 40000;
55 const int COMMAND_ACK_TIMEOUT = 8000;
56
60 EthernetCommunication();
61
62
66 EthernetCommunication(MONITORING_MODE monitoring);
67
72 EthernetCommunication(EthernetSettings* settings);
73
79 EthernetCommunication(EthernetSettings* settings, MONITORING_MODE monitoring);
80
84 ~EthernetCommunication();
85
89 CommunicationStatus Connect();
90
91
96 void Disconnect();
97
103 string SendCommand(string commandToSend);
104
111 string SendCommand(string commandToSend, int specificTimeout);
112
120 RawData WaitForRawData(int waitTimeout, unsigned long* semStatus);
121
122 private:
123 in_addr stringToInAddr(const string& ipStr);
124 int isInSameSubnet(const string& ipAddr, const string& subnetAddr, const string& subnetMask);
125 ConnectionState IsSensorInSameNet(const string& sensorIp);
126 PIP_ADAPTER_INFO FindAdapterForSecoket(SOCKET s);
127
128 PIP_ADAPTER_INFO _tcpAdapterInfo;
129
130 atomic<chrono::time_point<std::chrono::steady_clock>> _lastTcpDataTime;
131 atomic<chrono::time_point<std::chrono::steady_clock>> _lastUdpDataTime;
132
136 CommErrorCode GetLastErrorCode();
141 CommunicationStatus GetConnectionStatus();
142
146 CommunicationStatus Reconnect();
147
151 void StopAndClean();
152
157 CommunicationStatus ConnectTcp();
158
163 CommunicationStatus ConnectUdp();
164
168 void DisconnectTcp();
169
173 void DisconnectUdp();
174
175 // TCP WORKER VARIABLES AND METHODS
176 thread _tcpWorker;
177
181 void StartTcpWorker();
182
190 void TcpWorkerBusiness(string name);
191 std::atomic<bool> _stopTcpThread;
192 string _commandAckAnswer;
193 HANDLE _mutexcommandAckAnswer; // semaphore to protect the _commandAckAnswer concurent access
194 HANDLE _semCommandAckAvailable; // semaphore to warn that Command ACK is available
195 HANDLE _mutexSendAvailable; // prevent the socket to be used from another process to send data
200 void setCommandAckAnswer(string pCommandAckAnswer);
201
206 string getCommandAckAnswer();
207 // END OF TCP WORKER VARIABLES AND METHODS
208
209 // UDP WORKER VARIABLES AND METHODS
210 thread _udpWorker;
211
215 void StartUdpWorker();
216
223 void UdpWorkerBusiness(string name);
224 std::atomic<bool> _stopUdpThread;
225 // END UDP WORKER VARIABLES AND METHODS
226
227
234 int ProcessRawData(string dataPacket, vector<string>* dataVector);
235
236 queue<RawData> _rawDataQueue; // the MDI Raw data queue that contains the encapsulated raw data
237 HANDLE _mutexRawDataQueue; // protects the MDI Raw data queue from multi process access
238 HANDLE _semRawDataAvailable; // semaphore to warn that RAW Data are available
239 // END OF WORKER VARIABLES AND METHODS
240
241 //MODE _mode = UDP;
242 SOCKET _tcpSocket;
243 SOCKET _udpSocket;
244 DevicePinger _pinger;
245 std::atomic<bool> _wasWired;
246
247 bool _dataRequested = false;
248};
249
CommErrorCode
Definition CommunicationStructures.h:14
CommunicationStatus
Definition CommunicationStructures.h:24
DevicePinger
The ETHERNET device pinger: a helper to allow sending ICMP packets to a host.
Definition DevicePinger.h:29
EthernetCommunication
An ETHERNET oriented communication class. It inherits from BaseCommunication. It ensures the ETHERNET...
Definition EthernetCommunication.h:50
EthernetSettings
The ETHERNET settings encapsulation for ETHERNET communication.
Definition EthernetSettings.h:21
RawData
The base class encapsulating sensor's RAW data.
Definition RawData.h:14