//============================================================================= #include "stdafx.h" #include "SsiStatus.h" #include "logger.h" #include "math.h" #include "Proto_Util.h" #define MY_CONFIG 1 #define MAX_DEVPATH_LENGTH 256 #define ENDPOINT_TIMEOUT 500 #define MAX_BUFF_SIZE 1024 //=========================================================================== double CProto_Util::ScaleToMM(long lCount, double dResolution) { double dMM = 0.0; dMM = lCount * dResolution; return dMM; } //=========================================================================== long CProto_Util::MMtoScale(double lDistanceMM, double dResolution) { long lCounts = 0; if (dResolution) lCounts = (long) (lDistanceMM / dResolution); else ASSERT(0); return lCounts; } //===================================================================================== long CProto_Util::_4char2long(unsigned char *cBuff) { union { long l_value; char c_array[5]; }; memset (c_array, 0, 5); c_array[0] = cBuff[3]; c_array[1] = cBuff[2]; c_array[2] = cBuff[1]; c_array[3] = cBuff[0]; return(l_value); } //======================================================================== void CProto_Util::_reverse_dword(DWORD *dWord) { BYTE cBuff[4]; BYTE *dwBuff = (BYTE *)dWord; for ( int ii = 0 ; ii < 4 ; ++ii ) cBuff[ii]= dwBuff[ii]; dwBuff[0] = cBuff[3]; dwBuff[1] = cBuff[2]; dwBuff[2] = cBuff[1]; dwBuff[3] = cBuff[0]; } //****************************************************************************** void CProto_Util::_scale2inch(unsigned long scale, double &inch) { UNREFERENCED_PARAMETER(scale); UNREFERENCED_PARAMETER(inch); } //****************************************************************************** void CProto_Util::_inch2scale(unsigned long &scale, double inch) { UNREFERENCED_PARAMETER(scale); UNREFERENCED_PARAMETER(inch); } //****************************************************************************** // convert a string of characters into its binary form void CProto_Util::_char2bin(unsigned char *cBuff, BYTE *cBytes, int iLen) { memset(cBytes, 0, MAX_BUFF_SIZE); for (int i=0;i>8; Val = MSB|LSB; } //****************************************************************************** double CProto_Util::TimeInSecs(void) { double Secs; LARGE_INTEGER HPCounterTicksPerSecond; BOOL HasHPCounter = QueryPerformanceFrequency(&HPCounterTicksPerSecond); if (HasHPCounter == TRUE) { // Use high resolution clock. double HPCounterTicksPersec = (DWORD)((double) HPCounterTicksPerSecond.QuadPart); LARGE_INTEGER HPTicks; QueryPerformanceCounter(&HPTicks); Secs = ((double)HPTicks.QuadPart / HPCounterTicksPersec); } else { // Use clock with less resolution. Secs = GetTickCount(); Secs /= 1000.0; } return Secs; } //****************************************************************************** CProto_Util::CProto_Util() { g_pLogger = new CLogger(_T("\\UtilityDebug.Log")); }; //****************************************************************************** CProto_Util::~CProto_Util() { delete g_pLogger; g_pLogger = NULL; } #pragma warning(disable:4996) //****************************************************************************** // Send is direct and async. // The receive thread will receive data and interpret it. //****************************************************************************** SSI_STATUS CProto_Util::Initialize() { SSI_STATUS Status=SSI_STATUS_NORMAL; UNREFERENCED_PARAMETER(Status); if (g_pLogger->m_lLogMask & LOGACTIONS) g_pLogger->SendAndFlushPerMode(_T("Exit Initialize Usb\n")); return SSI_STATUS_NORMAL; } //****************************************************************************** SSI_STATUS CProto_Util::Terminate() { SSI_STATUS Status=SSI_STATUS_NORMAL; if (g_pLogger->m_lLogMask & LOGACTIONS) g_pLogger->SendAndFlushPerMode(_T("Exit Exit_MvUsb\n")); return Status; } //****************************************************************************** SSI_STATUS CProto_Util::ExtractAppPath(CString &Path) { CString tmpPath = Path; tmpPath.TrimRight(); tmpPath.TrimLeft(); int nLastSlash = tmpPath.ReverseFind('\\'); if (nLastSlash > -1) { // complete path tmpPath = Path.Left(nLastSlash); Path = tmpPath; } else { // not a complete path Path=""; }; return SSI_STATUS_NORMAL; }; //****************************************************************************** SSI_STATUS CProto_Util::GetAppPath(CString &Path) { Path=_T(""); // Speed optimization - noticed slow in GlowCode if (Path.IsEmpty()) { CString tmpPath; GetModuleFileName(NULL,tmpPath.GetBuffer(255),255); tmpPath.ReleaseBuffer(); tmpPath.TrimRight(); int nLastSlash = tmpPath.ReverseFind('\\'); if (nLastSlash >= 0) tmpPath = tmpPath.Left(nLastSlash); else tmpPath.Empty(); Path=tmpPath; } return SSI_STATUS_NORMAL; }; void CProto_Util::_ascii2bin(char *cBuff) { char x[3]; char t[MAX_BUFF_SIZE]; int iSize = strlen(cBuff)/2; memset(t, 0, MAX_BUFF_SIZE); for (int j=0;j