\doxysection{Ethernet\+Communication.\+h}
\hypertarget{a00383_source}{}\label{a00383_source}\index{EthernetCommunication.h@{EthernetCommunication.h}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{preprocessor}{\#pragma\ once}}
\DoxyCodeLine{00002\ \textcolor{preprocessor}{\#include\ <string>}}
\DoxyCodeLine{00003\ \textcolor{preprocessor}{\#include\ <tchar.h>}}
\DoxyCodeLine{00004\ \textcolor{preprocessor}{\#include\ <iostream>}}
\DoxyCodeLine{00005\ \textcolor{preprocessor}{\#include\ <atomic>}}
\DoxyCodeLine{00006\ \textcolor{preprocessor}{\#include\ <Ws2tcpip.h>}}
\DoxyCodeLine{00007\ \textcolor{preprocessor}{\#include\ <winsock2.h>}}
\DoxyCodeLine{00008\ \textcolor{preprocessor}{\#include\ <Windows.h>}}
\DoxyCodeLine{00009\ \textcolor{preprocessor}{\#include\ <thread>}}
\DoxyCodeLine{00010\ \textcolor{preprocessor}{\#include\ <sstream>}}
\DoxyCodeLine{00011\ \textcolor{preprocessor}{\#include\ <semaphore>}\ }
\DoxyCodeLine{00012\ \textcolor{preprocessor}{\#include\ <queue>}}
\DoxyCodeLine{00013\ \textcolor{preprocessor}{\#pragma\ comment(lib,\ "{}Ws2\_32.lib"{})}}
\DoxyCodeLine{00014\ \textcolor{preprocessor}{\#pragma\ comment(lib,\ "{}Iphlpapi.lib"{})}}
\DoxyCodeLine{00015\ \textcolor{preprocessor}{\#include\ "{}BaseCommunication.h"{}}}
\DoxyCodeLine{00016\ \textcolor{preprocessor}{\#include\ "{}EthernetSettings.h"{}}}
\DoxyCodeLine{00017\ \textcolor{preprocessor}{\#include\ "{}BaseDataExtractor.h"{}}}
\DoxyCodeLine{00018\ \textcolor{preprocessor}{\#include\ "{}Utility.h"{}}}
\DoxyCodeLine{00019\ \textcolor{preprocessor}{\#include\ "{}DevicePinger.h"{}}}
\DoxyCodeLine{00020\ \textcolor{preprocessor}{\#include\ "{}CommunicationStructures.h"{}}}
\DoxyCodeLine{00021\ \textcolor{preprocessor}{\#include\ "{}CommunicationEnumeration.h"{}}}
\DoxyCodeLine{00022\ \textcolor{preprocessor}{\#include\ "{}ClockUtilities.h"{}}}
\DoxyCodeLine{00023\ \textcolor{preprocessor}{\#include\ <IPTypes.h>}}
\DoxyCodeLine{00024\ \textcolor{preprocessor}{\#include\ <iphlpapi.h>}}
\DoxyCodeLine{00025\ }
\DoxyCodeLine{00026\ \textcolor{keyword}{using\ namespace\ }std;}
\DoxyCodeLine{00027\ }
\DoxyCodeLine{00028\ \textcolor{preprocessor}{\#ifdef\ STARFLEETTOOLBOX\_EXPORTS}}
\DoxyCodeLine{00029\ \textcolor{preprocessor}{\#define\ ETHCOMM\ \_\_declspec(dllexport)}}
\DoxyCodeLine{00030\ \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{00031\ \textcolor{preprocessor}{\#define\ ETHCOMM\ \_\_declspec(dllimport)}}
\DoxyCodeLine{00032\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00033\ }
\DoxyCodeLine{00034\ \textcolor{preprocessor}{\#define\ DATA\_READY\ 1}}
\DoxyCodeLine{00035\ \textcolor{preprocessor}{\#define\ DATA\_NOT\_READY\ 0}}
\DoxyCodeLine{00036\ }
\DoxyCodeLine{00037\ \textcolor{preprocessor}{\#define\ INTERFACE\_IS\_IN\_SAME\_NET\ 0}}
\DoxyCodeLine{00038\ \textcolor{preprocessor}{\#define\ INTERFACE\_IS\_NOT\_IN\_SAME\_NET\ 1}}
\DoxyCodeLine{00039\ \textcolor{preprocessor}{\#define\ INTERFACE\_NOT\_USED\ 2}}
\DoxyCodeLine{00040\ \textcolor{preprocessor}{\#define\ INTERFACE\_INVALID\_MASKING\ 3}}
\DoxyCodeLine{00041\ }
\DoxyCodeLine{00042\ }
\DoxyCodeLine{00048\ \textcolor{keyword}{class\ }ETHCOMM\ \mbox{\hyperlink{a00872}{EthernetCommunication}}\ :}
\DoxyCodeLine{00049\ \ \ \ \ \textcolor{keyword}{public}\ BaseCommunication}
\DoxyCodeLine{00050\ \{}
\DoxyCodeLine{00051\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00052\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ TCP\_NEWORKQUEUE\_OVERFLOWLIMIT\ =\ 20;}
\DoxyCodeLine{00053\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ TCP\_RAWDATA\_QUEUE\_OVERFLOWLIMIT\ =\ 20;}
\DoxyCodeLine{00054\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ MAX\_SIZE\_TO\_READ\ =\ 40000;}
\DoxyCodeLine{00055\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ COMMAND\_ACK\_TIMEOUT\ =\ 8000;}
\DoxyCodeLine{00056\ }
\DoxyCodeLine{00060\ \ \ \ \ \mbox{\hyperlink{a00872}{EthernetCommunication}}();}
\DoxyCodeLine{00061\ }
\DoxyCodeLine{00062\ }
\DoxyCodeLine{00066\ \ \ \ \ \mbox{\hyperlink{a00872}{EthernetCommunication}}(MONITORING\_MODE\ monitoring);}
\DoxyCodeLine{00067\ }
\DoxyCodeLine{00072\ \ \ \ \ \mbox{\hyperlink{a00872}{EthernetCommunication}}(\mbox{\hyperlink{a00876}{EthernetSettings}}*\ settings);}
\DoxyCodeLine{00073\ }
\DoxyCodeLine{00079\ \ \ \ \ \mbox{\hyperlink{a00872}{EthernetCommunication}}(\mbox{\hyperlink{a00876}{EthernetSettings}}*\ settings,\ MONITORING\_MODE\ monitoring);}
\DoxyCodeLine{00080\ }
\DoxyCodeLine{00084\ \ \ \ \ \mbox{\hyperlink{a00872}{\string~EthernetCommunication}}();}
\DoxyCodeLine{00085\ }
\DoxyCodeLine{00089\ \ \ \ \ \mbox{\hyperlink{a00856}{CommunicationStatus}}\ Connect();}
\DoxyCodeLine{00090\ }
\DoxyCodeLine{00091\ }
\DoxyCodeLine{00096\ \ \ \ \ \textcolor{keywordtype}{void}\ Disconnect();}
\DoxyCodeLine{00097\ }
\DoxyCodeLine{00103\ \ \ \ \ \textcolor{keywordtype}{string}\ SendCommand(\textcolor{keywordtype}{string}\ commandToSend);}
\DoxyCodeLine{00104\ }
\DoxyCodeLine{00111\ \ \ \ \ \textcolor{keywordtype}{string}\ SendCommand(\textcolor{keywordtype}{string}\ commandToSend,\ \textcolor{keywordtype}{int}\ specificTimeout);}
\DoxyCodeLine{00112\ }
\DoxyCodeLine{00120\ \ \ \ \ \mbox{\hyperlink{a00928}{RawData}}\ WaitForRawData(\textcolor{keywordtype}{int}\ waitTimeout,\ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{long}*\ semStatus);}
\DoxyCodeLine{00121\ }
\DoxyCodeLine{00122\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00123\ \ \ \ \ in\_addr\ stringToInAddr(\textcolor{keyword}{const}\ \textcolor{keywordtype}{string}\&\ ipStr);}
\DoxyCodeLine{00124\ \ \ \ \ \textcolor{keywordtype}{int}\ isInSameSubnet(\textcolor{keyword}{const}\ \textcolor{keywordtype}{string}\&\ ipAddr,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{string}\&\ subnetAddr,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{string}\&\ subnetMask);}
\DoxyCodeLine{00125\ \ \ \ \ ConnectionState\ IsSensorInSameNet(\textcolor{keyword}{const}\ \textcolor{keywordtype}{string}\&\ sensorIp);}
\DoxyCodeLine{00126\ \ \ \ \ PIP\_ADAPTER\_INFO\ FindAdapterForSecoket(SOCKET\ s);}
\DoxyCodeLine{00127\ }
\DoxyCodeLine{00128\ \ \ \ \ PIP\_ADAPTER\_INFO\ \_tcpAdapterInfo;}
\DoxyCodeLine{00129\ }
\DoxyCodeLine{00130\ \ \ \ \ atomic<chrono::time\_point<std::chrono::steady\_clock>>\ \_lastTcpDataTime;}
\DoxyCodeLine{00131\ \ \ \ \ atomic<chrono::time\_point<std::chrono::steady\_clock>>\ \_lastUdpDataTime;}
\DoxyCodeLine{00132\ }
\DoxyCodeLine{00136\ \ \ \ \ \mbox{\hyperlink{a00848}{CommErrorCode}}\ GetLastErrorCode();}
\DoxyCodeLine{00141\ \ \ \ \ \mbox{\hyperlink{a00856}{CommunicationStatus}}\ GetConnectionStatus();}
\DoxyCodeLine{00142\ }
\DoxyCodeLine{00146\ \ \ \ \ \mbox{\hyperlink{a00856}{CommunicationStatus}}\ Reconnect();}
\DoxyCodeLine{00147\ }
\DoxyCodeLine{00151\ \ \ \ \ \textcolor{keywordtype}{void}\ StopAndClean();}
\DoxyCodeLine{00152\ }
\DoxyCodeLine{00157\ \ \ \ \ \mbox{\hyperlink{a00856}{CommunicationStatus}}\ ConnectTcp();}
\DoxyCodeLine{00158\ }
\DoxyCodeLine{00163\ \ \ \ \ \mbox{\hyperlink{a00856}{CommunicationStatus}}\ ConnectUdp();}
\DoxyCodeLine{00164\ }
\DoxyCodeLine{00168\ \ \ \ \ \textcolor{keywordtype}{void}\ DisconnectTcp();}
\DoxyCodeLine{00169\ }
\DoxyCodeLine{00173\ \ \ \ \ \textcolor{keywordtype}{void}\ DisconnectUdp();}
\DoxyCodeLine{00174\ }
\DoxyCodeLine{00175\ \ \ \ \ \textcolor{comment}{//\ TCP\ WORKER\ VARIABLES\ AND\ METHODS}}
\DoxyCodeLine{00176\ \ \ \ \ thread\ \_tcpWorker;}
\DoxyCodeLine{00177\ }
\DoxyCodeLine{00181\ \ \ \ \ \textcolor{keywordtype}{void}\ StartTcpWorker();}
\DoxyCodeLine{00182\ }
\DoxyCodeLine{00190\ \ \ \ \ \textcolor{keywordtype}{void}\ TcpWorkerBusiness(\textcolor{keywordtype}{string}\ name);}
\DoxyCodeLine{00191\ \ \ \ \ std::atomic<bool>\ \ \_stopTcpThread;}
\DoxyCodeLine{00192\ \ \ \ \ \textcolor{keywordtype}{string}\ \_commandAckAnswer;}
\DoxyCodeLine{00193\ \ \ \ \ HANDLE\ \_mutexcommandAckAnswer;\ \ \ \ \ \ \textcolor{comment}{//\ semaphore\ to\ protect\ the\ \_commandAckAnswer\ concurent\ access}}
\DoxyCodeLine{00194\ \ \ \ \ HANDLE\ \_semCommandAckAvailable;\ \ \ \ \ \textcolor{comment}{//\ semaphore\ to\ warn\ that\ Command\ ACK\ is\ available}}
\DoxyCodeLine{00195\ \ \ \ \ HANDLE\ \_mutexSendAvailable;\ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ prevent\ the\ socket\ to\ be\ used\ from\ another\ process\ to\ send\ data}}
\DoxyCodeLine{00200\ \ \ \ \ \textcolor{keywordtype}{void}\ setCommandAckAnswer(\textcolor{keywordtype}{string}\ pCommandAckAnswer);}
\DoxyCodeLine{00201\ }
\DoxyCodeLine{00206\ \ \ \ \ \textcolor{keywordtype}{string}\ getCommandAckAnswer();}
\DoxyCodeLine{00207\ \ \ \ \ \textcolor{comment}{//\ END\ OF\ TCP\ WORKER\ VARIABLES\ AND\ METHODS}}
\DoxyCodeLine{00208\ }
\DoxyCodeLine{00209\ \ \ \ \ \textcolor{comment}{//\ UDP\ WORKER\ VARIABLES\ AND\ METHODS}}
\DoxyCodeLine{00210\ \ \ \ \ thread\ \_udpWorker;}
\DoxyCodeLine{00211\ }
\DoxyCodeLine{00215\ \ \ \ \ \textcolor{keywordtype}{void}\ StartUdpWorker();}
\DoxyCodeLine{00216\ }
\DoxyCodeLine{00223\ \ \ \ \ \textcolor{keywordtype}{void}\ UdpWorkerBusiness(\textcolor{keywordtype}{string}\ name);}
\DoxyCodeLine{00224\ \ \ \ \ std::atomic<bool>\ \ \_stopUdpThread;}
\DoxyCodeLine{00225\ \ \ \ \ \textcolor{comment}{//\ END\ UDP\ WORKER\ VARIABLES\ AND\ METHODS}}
\DoxyCodeLine{00226\ }
\DoxyCodeLine{00227\ \ \ \ \ }
\DoxyCodeLine{00234\ \ \ \ \ \textcolor{keywordtype}{int}\ ProcessRawData(\textcolor{keywordtype}{string}\ dataPacket,\ vector<string>*\ dataVector);}
\DoxyCodeLine{00235\ }
\DoxyCodeLine{00236\ \ \ \ \ queue<RawData>\ \_rawDataQueue;\ \ \ \ \ \ \ \textcolor{comment}{//\ the\ MDI\ Raw\ data\ queue\ that\ contains\ the\ encapsulated\ raw\ data\ \ \ \ }}
\DoxyCodeLine{00237\ \ \ \ \ HANDLE\ \_mutexRawDataQueue;\ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ protects\ the\ MDI\ Raw\ data\ queue\ from\ multi\ process\ access}}
\DoxyCodeLine{00238\ \ \ \ \ HANDLE\ \_semRawDataAvailable;\ \ \ \ \ \ \ \ \textcolor{comment}{//\ semaphore\ to\ warn\ that\ RAW\ Data\ are\ available}}
\DoxyCodeLine{00239\ \ \ \ \ \textcolor{comment}{//\ END\ OF\ WORKER\ VARIABLES\ AND\ METHODS}}
\DoxyCodeLine{00240\ \ \ \ \ }
\DoxyCodeLine{00241\ \ \ \ \ \textcolor{comment}{//MODE\ \_mode\ =\ UDP;}}
\DoxyCodeLine{00242\ \ \ \ \ SOCKET\ \_tcpSocket;}
\DoxyCodeLine{00243\ \ \ \ \ SOCKET\ \_udpSocket;\ \ \ }
\DoxyCodeLine{00244\ \ \ \ \ \mbox{\hyperlink{a00868}{DevicePinger}}\ \_pinger;}
\DoxyCodeLine{00245\ \ \ \ \ std::atomic<bool>\ \_wasWired;}
\DoxyCodeLine{00246\ }
\DoxyCodeLine{00247\ \ \ \ \ \textcolor{keywordtype}{bool}\ \_dataRequested\ =\ \textcolor{keyword}{false};}
\DoxyCodeLine{00248\ \};}
\DoxyCodeLine{00249\ }

\end{DoxyCode}
