\doxysection{Usb\+Communication.\+h}
\hypertarget{a00449_source}{}\label{a00449_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{a00944}{UsbDevice}}\ \{}
\DoxyCodeLine{00021\ \ \ \ \ \textcolor{keyword}{struct\ }libusb\_transfer*\ \mbox{\hyperlink{a00944_a66335b4112350e800d76d605a8d83514}{transfer}};}
\DoxyCodeLine{00022\ \ \ \ \ \textcolor{keyword}{struct\ }libusb\_device\_handle*\ \mbox{\hyperlink{a00944_a94b542acd16049c34946b222b72049bf}{device\_handle}};}
\DoxyCodeLine{00023\ \ \ \ \ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{char}\ \mbox{\hyperlink{a00944_ad7de7c84f962cd96021a1bc9403831e8}{input\_endpoint}};\ }
\DoxyCodeLine{00024\ \ \ \ \ \textcolor{keyword}{struct\ }libusb\_context*\ \mbox{\hyperlink{a00944_adf12be563c74495af512fb17f08f8526}{usbContext}};}
\DoxyCodeLine{00025\ }
\DoxyCodeLine{00026\ \ \ \ \ BaseDataExtractor*\ \mbox{\hyperlink{a00944_a3d04c5b29a2e9f9dd3f4f89fa41b1613}{extractor}};\ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ a\ pointer\ to\ the\ communication\ extractor}}
\DoxyCodeLine{00027\ \ \ \ \ HANDLE\ \mbox{\hyperlink{a00944_a84cdbf5c41f7a3eb4547740c91ccc9d7}{dataAvailableSemaphore}};\ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ semaphore\ to\ warn\ that\ Command\ ACK\ is\ available}}
\DoxyCodeLine{00028\ \ \ \ \ HANDLE\ \mbox{\hyperlink{a00944_af8f98f5447d6da974862acd5e27149a3}{rawDataAvailableSemaphore}};\ \ \ \ \ \ \textcolor{comment}{//\ semaphore\ to\ warn\ that\ RAW\ Data\ are\ available}}
\DoxyCodeLine{00029\ \ \ \ \ HANDLE\ \mbox{\hyperlink{a00944_ad5e64c00307a55fabddc2cfd936e3e26}{semReadyToConsume}};\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ synchronisation\ for\ data\ consumed}}
\DoxyCodeLine{00030\ \ \ \ \ \textcolor{keywordtype}{string}\ \mbox{\hyperlink{a00944_a4d5af0982cb76364c42b8233f8f5355e}{commandResult}};\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ the\ command\ result}}
\DoxyCodeLine{00031\ \ \ \ \ \textcolor{keywordtype}{bool}\ \mbox{\hyperlink{a00944_aa190fef051ab42359609f19c545c08a1}{treat}}\ =\ \textcolor{keyword}{false};\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ indicates\ if\ data\ treater\ is\ in\ treatment}}
\DoxyCodeLine{00032\ \ \ \ \ vector<string>\ \mbox{\hyperlink{a00944_aa6cc13cf3016b0c5f1e28554409644cf}{localVector}};\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ temporary\ local\ vector}}
\DoxyCodeLine{00033\ \ \ \ \ \mbox{\hyperlink{a00928}{RawData}}\ \mbox{\hyperlink{a00944_a7e203f3bd07944fd5d5f09c264b963d1}{extractedData}};\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ the\ extracted\ raw\ data\ \ \ \ }}
\DoxyCodeLine{00034\ \ \ \ \ \textcolor{keywordtype}{bool}\ \mbox{\hyperlink{a00944_aa293e93f8182422ade2474380076c34b}{interruptTransfer}}\ =\ \textcolor{keyword}{true};\ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ indicates\ a\ transfert\ interruption}}
\DoxyCodeLine{00035\ \ \ \ \ \mbox{\hyperlink{a00856}{CommunicationStatus}}\ \mbox{\hyperlink{a00944_adba579d47e46ef7699a1b268d6cf56df}{commStatus}};\ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ the\ connection\ status}}
\DoxyCodeLine{00036\ \ \ \ \ atomic<chrono::time\_point<std::chrono::steady\_clock>>\ \mbox{\hyperlink{a00944_aa31120ed18ac862da93aeccc3ef137c1}{lastUsbDataTime}};\ \textcolor{comment}{//\ the\ last\ raw\ data\ \ sent}}
\DoxyCodeLine{00037\ \ \ \ \ \textcolor{keywordtype}{int}*\ \mbox{\hyperlink{a00944_aa58c177b85087d595c76d1d0f6675cf2}{callbackConnectionStatus}};}
\DoxyCodeLine{00038\ \};}
\DoxyCodeLine{00039\ }
\DoxyCodeLine{00043\ \textcolor{keyword}{class\ }USBCOMM\ \mbox{\hyperlink{a00948}{UsbCommunication}}\ :}
\DoxyCodeLine{00044\ \ \ \ \ \textcolor{keyword}{public}\ BaseCommunication}
\DoxyCodeLine{00045\ \{}
\DoxyCodeLine{00046\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00047\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ COMMAND\_ACK\_TIMEOUT\ =\ 20000;}
\DoxyCodeLine{00048\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ MAX\_SIZE\_TO\_READ\ =\ 40000;}
\DoxyCodeLine{00049\ }
\DoxyCodeLine{00053\ \ \ \ \ \mbox{\hyperlink{a00948}{UsbCommunication}}();}
\DoxyCodeLine{00054\ \ \ \ \ \mbox{\hyperlink{a00948}{UsbCommunication}}(MONITORING\_MODE\ monitoring);}
\DoxyCodeLine{00058\ \ \ \ \ \mbox{\hyperlink{a00948}{UsbCommunication}}(\mbox{\hyperlink{a00956}{UsbSettings}}*\ settings);}
\DoxyCodeLine{00059\ \ \ \ \ \mbox{\hyperlink{a00948}{UsbCommunication}}(\mbox{\hyperlink{a00956}{UsbSettings}}*\ settings,\ MONITORING\_MODE\ monitoring);}
\DoxyCodeLine{00063\ \ \ \ \ \mbox{\hyperlink{a00948}{\string~UsbCommunication}}();}
\DoxyCodeLine{00064\ }
\DoxyCodeLine{00068\ \ \ \ \ \mbox{\hyperlink{a00856}{CommunicationStatus}}\ Connect();}
\DoxyCodeLine{00072\ \ \ \ \ \mbox{\hyperlink{a00856}{CommunicationStatus}}\ Connect(\textcolor{keywordtype}{bool}\ reconnecting);}
\DoxyCodeLine{00073\ }
\DoxyCodeLine{00077\ \ \ \ \ \textcolor{keywordtype}{void}\ Disconnect();}
\DoxyCodeLine{00078\ \ \ \ \ }
\DoxyCodeLine{00079\ }
\DoxyCodeLine{00085\ \ \ \ \ \textcolor{keywordtype}{string}\ SendCommand(\textcolor{keywordtype}{string}\ commandToSend);}
\DoxyCodeLine{00086\ }
\DoxyCodeLine{00093\ \ \ \ \ \textcolor{keywordtype}{string}\ SendCommand(\textcolor{keywordtype}{string}\ commandToSend,\ \textcolor{keywordtype}{int}\ specificTimeout);}
\DoxyCodeLine{00094\ }
\DoxyCodeLine{00101\ \ \ \ \ \mbox{\hyperlink{a00928}{RawData}}\ WaitForRawData(\textcolor{keywordtype}{int}\ waitTimeout,\ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{long}*\ semStatus);}
\DoxyCodeLine{00102\ }
\DoxyCodeLine{00108\ \ \ \ \ \textcolor{keyword}{static}\ vector<UsbInformation>\ GetDeviceList();}
\DoxyCodeLine{00109\ \textcolor{keyword}{protected}:}
\DoxyCodeLine{00114\ \ \ \ \ \mbox{\hyperlink{a00856}{CommunicationStatus}}\ GetConnectionStatus();\ \ \ \ }
\DoxyCodeLine{00115\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00116\ \ \ \ \ atomic<chrono::time\_point<std::chrono::steady\_clock>>\ \_lastUsbDataTime;}
\DoxyCodeLine{00117\ }
\DoxyCodeLine{00118\ \ \ \ \ \textcolor{keywordtype}{void}\ Disconnect(\textcolor{keywordtype}{bool}\ reconnecting);}
\DoxyCodeLine{00119\ \ \ \ \ \mbox{\hyperlink{a00856}{CommunicationStatus}}\ Reconnect();}
\DoxyCodeLine{00120\ \ \ \ \ std::atomic<bool>\ \_stopHandle;}
\DoxyCodeLine{00121\ \ \ \ \ std::atomic<bool>\ \_connected;}
\DoxyCodeLine{00122\ }
\DoxyCodeLine{00123\ \ \ \ \ std::atomic<bool>\ \_alreadydisconnected;}
\DoxyCodeLine{00124\ \ \ \ \ std::atomic<bool>\ \_disconnectCalledByPeer;}
\DoxyCodeLine{00125\ }
\DoxyCodeLine{00126\ }
\DoxyCodeLine{00127\ \ \ \ \ std::atomic<int>\ \_mainConnectionStatus;\ \textcolor{comment}{//\ useful\ for\ monitoring}}
\DoxyCodeLine{00128\ \ \ \ \ \textcolor{keywordtype}{int}\ \_callbackConnectionStatus\ =\ 0;}
\DoxyCodeLine{00129\ }
\DoxyCodeLine{00130\ \ \ \ \ \mbox{\hyperlink{a00944}{UsbDevice}}\ usbDevice;}
\DoxyCodeLine{00131\ \ \ \ \ thread\ \_usbReceiveData;\ \ \ \ }
\DoxyCodeLine{00132\ }
\DoxyCodeLine{00133\ \ \ \ \ HANDLE\ \_mutexSendAvailable;\ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ prevent\ the\ socket\ to\ be\ used\ from\ another\ process\ to\ send\ data}}
\DoxyCodeLine{00134\ }
\DoxyCodeLine{00139\ \ \ \ \ \textcolor{keywordtype}{void}\ UsbEventDataReceiverBusiness(\textcolor{keywordtype}{void}*\ param);}
\DoxyCodeLine{00140\ }
\DoxyCodeLine{00146\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keywordtype}{void}\ \_\_stdcall\ callbackUSBReadTransferComplete(\textcolor{keyword}{struct}\ libusb\_transfer*\ xfr);}
\DoxyCodeLine{00147\ \};}
\DoxyCodeLine{00148\ }

\end{DoxyCode}
