\doxysection{Usb\+Communication.\+h}
\hypertarget{a00401_source}{}\label{a00401_source}\index{UsbCommunication.h@{UsbCommunication.h}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{preprocessor}{\#pragma\ once}}
\DoxyCodeLine{00002\ }
\DoxyCodeLine{00003\ \textcolor{preprocessor}{\#pragma\ comment(lib,\ "{}Ws2\_32.lib"{})}}
\DoxyCodeLine{00004\ \textcolor{preprocessor}{\#include\ "{}BaseCommunication.h"{}}}
\DoxyCodeLine{00005\ \textcolor{preprocessor}{\#include\ "{}UsbSettings.h"{}}}
\DoxyCodeLine{00006\ }
\DoxyCodeLine{00007\ \textcolor{preprocessor}{\#include\ <thread>}}
\DoxyCodeLine{00008\ \textcolor{preprocessor}{\#include\ "{}UsbInformation.h"{}}}
\DoxyCodeLine{00009\ \textcolor{preprocessor}{\#include\ "{}ClockUtilities.h"{}}}
\DoxyCodeLine{00010\ }
\DoxyCodeLine{00011\ \textcolor{preprocessor}{\#ifdef\ STARFLEETTOOLBOX\_EXPORTS}}
\DoxyCodeLine{00012\ \textcolor{preprocessor}{\#define\ USBCOMM\ \_\_declspec(dllexport)}}
\DoxyCodeLine{00013\ \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{00014\ \textcolor{preprocessor}{\#define\ USBCOMM\ \_\_declspec(dllimport)}}
\DoxyCodeLine{00015\ \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{00016\ }
\DoxyCodeLine{00020\ \textcolor{keyword}{typedef}\ \textcolor{keyword}{struct\ }\mbox{\hyperlink{a00858}{UsbDevice}}\ \{}
\DoxyCodeLine{00021\ \ \ \ \ \textcolor{keyword}{struct\ }libusb\_transfer*\ \mbox{\hyperlink{a00858_a66335b4112350e800d76d605a8d83514}{transfer}};}
\DoxyCodeLine{00022\ \ \ \ \ \textcolor{keyword}{struct\ }libusb\_device\_handle*\ \mbox{\hyperlink{a00858_a94b542acd16049c34946b222b72049bf}{device\_handle}};}
\DoxyCodeLine{00023\ \ \ \ \ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{char}\ \mbox{\hyperlink{a00858_ad7de7c84f962cd96021a1bc9403831e8}{input\_endpoint}};\ }
\DoxyCodeLine{00024\ \ \ \ \ \textcolor{keyword}{struct\ }libusb\_context*\ \mbox{\hyperlink{a00858_adf12be563c74495af512fb17f08f8526}{usbContext}};}
\DoxyCodeLine{00025\ }
\DoxyCodeLine{00026\ \ \ \ \ BaseDataExtractor*\ \mbox{\hyperlink{a00858_a3d04c5b29a2e9f9dd3f4f89fa41b1613}{extractor}};\ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ a\ pointer\ to\ the\ communication\ extractor}}
\DoxyCodeLine{00027\ \ \ \ \ HANDLE\ \mbox{\hyperlink{a00858_a84cdbf5c41f7a3eb4547740c91ccc9d7}{dataAvailableSemaphore}};\ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ semaphore\ to\ warn\ that\ Command\ ACK\ is\ available}}
\DoxyCodeLine{00028\ \ \ \ \ HANDLE\ \mbox{\hyperlink{a00858_af8f98f5447d6da974862acd5e27149a3}{rawDataAvailableSemaphore}};\ \ \ \ \ \ \textcolor{comment}{//\ semaphore\ to\ warn\ that\ RAW\ Data\ are\ available}}
\DoxyCodeLine{00029\ \ \ \ \ HANDLE\ \mbox{\hyperlink{a00858_ad5e64c00307a55fabddc2cfd936e3e26}{semReadyToConsume}};\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ synchronisation\ for\ data\ consumed}}
\DoxyCodeLine{00030\ \ \ \ \ \textcolor{keywordtype}{string}\ \mbox{\hyperlink{a00858_a4d5af0982cb76364c42b8233f8f5355e}{commandResult}};\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ the\ command\ result}}
\DoxyCodeLine{00031\ \ \ \ \ \textcolor{keywordtype}{bool}\ \mbox{\hyperlink{a00858_aa190fef051ab42359609f19c545c08a1}{treat}}\ =\ \textcolor{keyword}{false};\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ indicates\ if\ data\ treater\ is\ in\ treatment}}
\DoxyCodeLine{00032\ \ \ \ \ vector<string>\ \mbox{\hyperlink{a00858_aa6cc13cf3016b0c5f1e28554409644cf}{localVector}};\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ temporary\ local\ vector}}
\DoxyCodeLine{00033\ \ \ \ \ \mbox{\hyperlink{a00842}{RawData}}\ \mbox{\hyperlink{a00858_a7e203f3bd07944fd5d5f09c264b963d1}{extractedData}};\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ the\ extracted\ raw\ data\ \ \ \ }}
\DoxyCodeLine{00034\ \ \ \ \ \textcolor{keywordtype}{bool}\ \mbox{\hyperlink{a00858_aa293e93f8182422ade2474380076c34b}{interruptTransfer}}\ =\ \textcolor{keyword}{true};\ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ indicates\ a\ transfert\ interruption}}
\DoxyCodeLine{00035\ \ \ \ \ \mbox{\hyperlink{a00778}{CommunicationStatus}}\ \mbox{\hyperlink{a00858_adba579d47e46ef7699a1b268d6cf56df}{commStatus}};\ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ the\ connection\ status}}
\DoxyCodeLine{00036\ \ \ \ \ atomic<chrono::time\_point<std::chrono::steady\_clock>>\ \mbox{\hyperlink{a00858_aa31120ed18ac862da93aeccc3ef137c1}{lastUsbDataTime}};\ \textcolor{comment}{//\ the\ last\ raw\ data\ \ sent}}
\DoxyCodeLine{00037\ \};}
\DoxyCodeLine{00038\ }
\DoxyCodeLine{00042\ \textcolor{keyword}{class\ }USBCOMM\ \mbox{\hyperlink{a00862}{UsbCommunication}}\ :}
\DoxyCodeLine{00043\ \ \ \ \ \textcolor{keyword}{public}\ BaseCommunication}
\DoxyCodeLine{00044\ \{}
\DoxyCodeLine{00045\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00046\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ COMMAND\_ACK\_TIMEOUT\ =\ 20000;}
\DoxyCodeLine{00047\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ MAX\_SIZE\_TO\_READ\ =\ 40000;}
\DoxyCodeLine{00048\ }
\DoxyCodeLine{00052\ \ \ \ \ \mbox{\hyperlink{a00862}{UsbCommunication}}();}
\DoxyCodeLine{00053\ \ \ \ \ \mbox{\hyperlink{a00862}{UsbCommunication}}(MONITORING\_MODE\ monitoring);}
\DoxyCodeLine{00057\ \ \ \ \ \mbox{\hyperlink{a00862}{UsbCommunication}}(\mbox{\hyperlink{a00870}{UsbSettings}}*\ settings);}
\DoxyCodeLine{00058\ \ \ \ \ \mbox{\hyperlink{a00862}{UsbCommunication}}(\mbox{\hyperlink{a00870}{UsbSettings}}*\ settings,\ MONITORING\_MODE\ monitoring);}
\DoxyCodeLine{00062\ \ \ \ \ \mbox{\hyperlink{a00862}{\string~UsbCommunication}}();}
\DoxyCodeLine{00063\ }
\DoxyCodeLine{00067\ \ \ \ \ \mbox{\hyperlink{a00778}{CommunicationStatus}}\ Connect();}
\DoxyCodeLine{00071\ \ \ \ \ \mbox{\hyperlink{a00778}{CommunicationStatus}}\ Connect(\textcolor{keywordtype}{bool}\ reconnecting);}
\DoxyCodeLine{00072\ }
\DoxyCodeLine{00076\ \ \ \ \ \textcolor{keywordtype}{void}\ Disconnect();}
\DoxyCodeLine{00077\ \ \ \ \ }
\DoxyCodeLine{00078\ }
\DoxyCodeLine{00084\ \ \ \ \ \textcolor{keywordtype}{string}\ SendCommand(\textcolor{keywordtype}{string}\ commandToSend);}
\DoxyCodeLine{00085\ }
\DoxyCodeLine{00086\ }
\DoxyCodeLine{00093\ \ \ \ \ \mbox{\hyperlink{a00842}{RawData}}\ WaitForRawData(\textcolor{keywordtype}{int}\ waitTimeout,\ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{long}*\ semStatus);}
\DoxyCodeLine{00094\ }
\DoxyCodeLine{00100\ \ \ \ \ \textcolor{keyword}{static}\ vector<UsbInformation>\ GetDeviceList();}
\DoxyCodeLine{00101\ \textcolor{keyword}{protected}:}
\DoxyCodeLine{00106\ \ \ \ \ \mbox{\hyperlink{a00778}{CommunicationStatus}}\ GetConnectionStatus();\ \ \ \ }
\DoxyCodeLine{00107\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00108\ \ \ \ \ atomic<chrono::time\_point<std::chrono::steady\_clock>>\ \_lastUsbDataTime;}
\DoxyCodeLine{00109\ }
\DoxyCodeLine{00110\ \ \ \ \ \textcolor{keywordtype}{void}\ Disconnect(\textcolor{keywordtype}{bool}\ reconnecting);}
\DoxyCodeLine{00111\ \ \ \ \ \mbox{\hyperlink{a00778}{CommunicationStatus}}\ Reconnect();}
\DoxyCodeLine{00112\ \ \ \ \ std::atomic<bool>\ \_stopHandle;}
\DoxyCodeLine{00113\ \ \ \ \ std::atomic<bool>\ \_connected;}
\DoxyCodeLine{00114\ }
\DoxyCodeLine{00115\ \ \ \ \ std::atomic<bool>\ \_alreadydisconnected;}
\DoxyCodeLine{00116\ \ \ \ \ std::atomic<bool>\ \_disconnectCalledByPeer;}
\DoxyCodeLine{00117\ }
\DoxyCodeLine{00118\ }
\DoxyCodeLine{00119\ \ \ \ \ std::atomic<int>\ \_mainConnectionStatus;\ \textcolor{comment}{//\ useful\ for\ monitoring}}
\DoxyCodeLine{00120\ }
\DoxyCodeLine{00121\ \ \ \ \ \mbox{\hyperlink{a00858}{UsbDevice}}\ usbDevice;}
\DoxyCodeLine{00122\ \ \ \ \ thread\ \_usbReceiveData;\ \ \ \ }
\DoxyCodeLine{00123\ }
\DoxyCodeLine{00124\ \ \ \ \ HANDLE\ \_mutexSendAvailable;\ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ prevent\ the\ socket\ to\ be\ used\ from\ another\ process\ to\ send\ data}}
\DoxyCodeLine{00125\ }
\DoxyCodeLine{00130\ \ \ \ \ \textcolor{keywordtype}{void}\ UsbEventDataReceiverBusiness(\textcolor{keywordtype}{void}*\ param);}
\DoxyCodeLine{00131\ }
\DoxyCodeLine{00137\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keywordtype}{void}\ \_\_stdcall\ callbackUSBReadTransferComplete(\textcolor{keyword}{struct}\ libusb\_transfer*\ xfr);}
\DoxyCodeLine{00138\ \};}
\DoxyCodeLine{00139\ }

\end{DoxyCode}
