Visioscan Set SDK Libraries 1.0.14
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#include "BaseCommunication.h"
15#include "EthernetSettings.h"
16#include "BaseDataExtractor.h"
17#include "Utility.h"
18#include "DevicePinger.h"
19
20using namespace std;
21
22#ifdef STARFLEETTOOLBOX_EXPORTS
23#define ETHCOMM __declspec(dllexport)
24#else
25#define ETHCOMM __declspec(dllimport)
26#endif
27
28#define DATA_READY 1;
29#define DATA_NOT_READY 0;
30
36class ETHCOMM EthernetCommunication :
37 public BaseCommunication
38{
39public:
40 const int TCP_NEWORKQUEUE_OVERFLOWLIMIT = 20;
41 const int TCP_RAWDATA_QUEUE_OVERFLOWLIMIT = 20;
42 const int MAX_SIZE_TO_READ = 40000;
43 const int COMMAND_ACK_TIMEOUT = 5000;
44
49
50
54 EthernetCommunication(MONITORING_MODE monitoring);
55
61
67 EthernetCommunication(EthernetSettings* settings, MONITORING_MODE monitoring);
68
73
77 void Connect();
78
79
84 void Disconnect();
85
91 string SendCommand(string commandToSend);
92
100 RawData WaitForRawData(int waitTimeout, unsigned long* semStatus);
101
102
103private:
108 int GetCommunicationStatus();
109
114 void Connect(bool forceMonitoring);
115
119 void StopAndClean();
120
125 SOCKET ConnectTcp();
126
131 SOCKET ConnectUdp();
132
136 void DisconnectTcp();
137
141 void DisconnectUdp();
142
143 // TCP WORKER VARIABLES AND METHODS
144 thread _tcpWorker;
145
149 void StartTcpWorker();
150
158 void TcpWorkerBusiness(string name);
159 bool _stopTcpThread = false;
160 string _commandAckAnswer;
161 HANDLE _mutexcommandAckAnswer; // semaphore to protect the _commandAckAnswer concurent access
162 HANDLE _semCommandAckAvailable; // semaphore to warn that Command ACK is available
163 HANDLE _mutexSendAvailable; // prevent the socket to be used from another process to send data
168 void setCommandAckAnswer(string pCommandAckAnswer);
169
174 string getCommandAckAnswer();
175 // END OF TCP WORKER VARIABLES AND METHODS
176
177 // UDP WORKER VARIABLES AND METHODS
178 thread _udpWorker;
179
183 void StartUdpWorker();
184
191 void UdpWorkerBusiness(string name);
192 bool _stopUdpThread = false;
193 // END UDP WORKER VARIABLES AND METHODS
194
195
202 int ProcessRawData(string dataPacket, vector<string>* dataVector);
203
204 queue<RawData> _rawDataQueue; // the MDI Raw data queue that contains the encapsulated raw data
205 HANDLE _mutexRawDataQueue; // protects the MDI Raw data queue from multi process access
206 HANDLE _semRawDataAvailable; // semaphore to warn that RAW Data are available
207 // END OF WORKER VARIABLES AND METHODS
208
209 //MODE _mode = UDP;
210 SOCKET _tcpSocket;
211 SOCKET _udpSocket;
212 DevicePinger _pinger;
213
214 bool _dataRequested = false;
215};
216
The ETHERNET device pinger: a helper to allow sending ICMP packets to a host.
Definition DevicePinger.h:29
An ETHERNET oriented communication class. It inherits from BaseCommunication. It ensures the ETHERNET...
Definition EthernetCommunication.h:38
The ETHERNET settings encapsulation for ETHERNET communication.
Definition EthernetSettings.h:21
The base class encapsulating sensor's RAW data.
Definition RawData.h:14