From a7daeaa63b86c8ce54ed0e125c89f0fc1d469ab6 Mon Sep 17 00:00:00 2001 From: Evgeny Gagua at Mercury Date: Sun, 27 Dec 2020 12:03:49 +0200 Subject: [PATCH] Mekorot step --- Projects/MEKOROT/MEKOROT.vcxproj | 3 ++ Projects/MEKOROT/MEKOROT.vcxproj.filters | 9 ++++ Projects/MEKOROT/MEKOROT_Kernel.cpp | 47 +++++++++++++++++-- .../CudaWare_64_DNN_Learning/main_window.ui | 11 +++++ lib/alg/lgs/mask.h | 2 +- lib/components/base/basicCamera.cpp | 8 ++-- lib/components/base/basicFunctionality.cpp | 4 ++ lib/components/base/basicFunctionality.h | 4 +- lib/components/base/basicLIBAV.h | 2 +- lib/components/base/basicTransport.h | 4 +- lib/data/protocol/protocol.cpp | 13 ++++- lib/data/protocol/protocol.h | 23 +++++---- lib/hardware/soc/general/3DLRF.h | 12 ++--- lib/hardware/uart/serialPort.cpp | 10 ++-- lib/hardware/uart/serialSOL.cpp | 31 ++++++++++-- lib/hardware/uart/serialSOL.h | 20 +++++--- 16 files changed, 159 insertions(+), 44 deletions(-) diff --git a/Projects/MEKOROT/MEKOROT.vcxproj b/Projects/MEKOROT/MEKOROT.vcxproj index 095b21a2..21289455 100644 --- a/Projects/MEKOROT/MEKOROT.vcxproj +++ b/Projects/MEKOROT/MEKOROT.vcxproj @@ -181,9 +181,12 @@ + + + diff --git a/Projects/MEKOROT/MEKOROT.vcxproj.filters b/Projects/MEKOROT/MEKOROT.vcxproj.filters index 5b277b7b..8e689a6e 100644 --- a/Projects/MEKOROT/MEKOROT.vcxproj.filters +++ b/Projects/MEKOROT/MEKOROT.vcxproj.filters @@ -111,6 +111,15 @@ Source Files + + Source Files + + + Source Files + + + Source Files + diff --git a/Projects/MEKOROT/MEKOROT_Kernel.cpp b/Projects/MEKOROT/MEKOROT_Kernel.cpp index e5c0d642..ceee9f07 100644 --- a/Projects/MEKOROT/MEKOROT_Kernel.cpp +++ b/Projects/MEKOROT/MEKOROT_Kernel.cpp @@ -3,6 +3,30 @@ #define LOG( X ) m_pLog->Log( "KRNL", this, X ) #define LOG_ERROR( X ) m_pLog->Log( "KRNL", this, _LOG_ERROR, X ) +bool getconchar(KEY_EVENT_RECORD& krec) { + DWORD cc, NOF; + INPUT_RECORD irec; + HANDLE h = GetStdHandle(STD_INPUT_HANDLE); + + if (h == NULL) { + return false; // console not found + }; + if (!GetNumberOfConsoleInputEvents(h, &NOF)) return false; + if( NOF ) for(int i=0;igetSubNode(ptr, (CSTR)"KERNEL"); @@ -12,6 +36,7 @@ mekorotKernel::mekorotKernel(config_setting_t* ptr) : protocolLGS_CLIENT(), basi m_nSerialSpeed = 19200; m_bDeviceID[0] = m_bDeviceID[1] = m_bDeviceID[2] = -1; m_bDeviceFlags[0] = m_bDeviceFlags[1] = m_bDeviceFlags[2] = false; + m_bDeviceTO[0] = m_bDeviceTO[1] = m_bDeviceTO[2] = 0; }; mekorotKernel::~mekorotKernel() { @@ -29,7 +54,7 @@ bool mekorotKernel::init(void){ basicSettingsProvider::getInstance()->compromise(); if (pSetting == NULL) { LOG_ERROR("Failure while adding setting!"); - return -1; + return false; }; config_setting_set_string(pSetting, m_pSerialDevice); }; @@ -41,7 +66,7 @@ bool mekorotKernel::init(void){ basicSettingsProvider::getInstance()->compromise(); if (pSetting == NULL) { LOG_ERROR("Failure while adding setting!"); - return -1; + return false; }; config_setting_set_int(pSetting, m_nSerialSpeed ); }; @@ -53,7 +78,7 @@ bool mekorotKernel::init(void){ basicSettingsProvider::getInstance()->compromise(); if (pSetting == NULL) { LOG_ERROR("Failure while adding setting!"); - return -1; + return false; }; config_setting_set_int(pSetting, m_bDeviceID[0]); }; @@ -65,7 +90,7 @@ bool mekorotKernel::init(void){ basicSettingsProvider::getInstance()->compromise(); if (pSetting == NULL) { LOG_ERROR("Failure while adding setting!"); - return -1; + return false; }; config_setting_set_int(pSetting, m_bDeviceID[1]); }; @@ -77,7 +102,7 @@ bool mekorotKernel::init(void){ basicSettingsProvider::getInstance()->compromise(); if (pSetting == NULL) { LOG_ERROR("Failure while adding setting!"); - return -1; + return false; }; config_setting_set_int(pSetting, m_bDeviceID[2]); }; @@ -90,6 +115,18 @@ bool mekorotKernel::init(void){ void mekorotKernel::m_fThreadProc(void){ m_bThreadStatus = TH_WORKING; while (m_bThreadStatus < TH_ENDED) { + KEY_EVENT_RECORD krec; + if( getconchar(krec) ){ + //Parse KeyBoard Input + char tBuffer[128]; + sprintf(tBuffer, "Key Stroke Code: %d", krec.wVirtualKeyCode); + LOG(tBuffer); + if (krec.wVirtualKeyCode == 81 || krec.wVirtualKeyCode == 75) { // q Or k + LOG("Exit by Operator Request!"); + m_bThreadStatus = TH_ENDED; + continue; + }; + }; switch( m_bStage ) { case MEKOROT_KRNL_STG_CONNECT:{ if (m_pSerial == NULL) { diff --git a/lib/App/CudaWare_64_DNN_Learning/main_window.ui b/lib/App/CudaWare_64_DNN_Learning/main_window.ui index c7900ec6..f63b4845 100644 --- a/lib/App/CudaWare_64_DNN_Learning/main_window.ui +++ b/lib/App/CudaWare_64_DNN_Learning/main_window.ui @@ -191,6 +191,9 @@ Qt::Horizontal + + Qt::ToolButtonTextBesideIcon + true @@ -202,11 +205,19 @@ + + + :/general/bulb.png:/general/bulb.png + New Network + + + :/menu/PNG/devices/030.png:/menu/PNG/devices/030.png + Open diff --git a/lib/alg/lgs/mask.h b/lib/alg/lgs/mask.h index dad7c8fc..16fd2ab3 100644 --- a/lib/alg/lgs/mask.h +++ b/lib/alg/lgs/mask.h @@ -5,7 +5,7 @@ #include "../../hardware/soc/general/3DLRF.h" #include "../../components/base/basicLogCollection.h" -#if defined( __linux__ ) && !defined( __GUI__ ) +#if ( defined( __linux__ ) && !defined( __GUI__ ) ) || defined( _MEKOROT_ ) typedef struct{ private: int16_t m_x; diff --git a/lib/components/base/basicCamera.cpp b/lib/components/base/basicCamera.cpp index 59c51ab0..b2032a07 100644 --- a/lib/components/base/basicCamera.cpp +++ b/lib/components/base/basicCamera.cpp @@ -315,9 +315,11 @@ void basicCamera::updateSettings(void){ void basicCamera::dispatchEvent( basicEvent *Evt ){ if( Evt->m_eClass == EVT_CLASS_SENSOR ) { switch (Evt->m_eType){ - case EVT_TARGET: - case EVT_TARGET_WHITE: - case EVT_TARGET_BLACK: + case EVT_TARGET_1D: + case EVT_TARGET_2D_WHITE: + case EVT_TARGET_2D_BLACK: + case EVT_TARGET_3D_WHITE: + case EVT_TARGET_3D_BLACK: case EVT_ALARM: CLIENT_EVENT *tData; tData = ( CLIENT_EVENT *) Evt->m_pEvtData; diff --git a/lib/components/base/basicFunctionality.cpp b/lib/components/base/basicFunctionality.cpp index c2230ba0..95024210 100644 --- a/lib/components/base/basicFunctionality.cpp +++ b/lib/components/base/basicFunctionality.cpp @@ -197,7 +197,11 @@ CSTR getTStr( CSTR Fmt ){ } //RetVal =(CSTR) malloc( strlen(DateStr) +1 ); //if( RetVal != NULL ) strcpy( RetVal, DateStr ); +#ifdef __linux__ return strdup(DateStr); +#else + return _strdup(DateStr); +#endif }; #ifdef __linux__ diff --git a/lib/components/base/basicFunctionality.h b/lib/components/base/basicFunctionality.h index ac18dc5a..aef9b5f7 100644 --- a/lib/components/base/basicFunctionality.h +++ b/lib/components/base/basicFunctionality.h @@ -16,7 +16,9 @@ #else //#include //#include - #define WIN32_LEAN_AND_MEAN + #ifndef WIN32_LEAN_AND_MEAN + #define WIN32_LEAN_AND_MEAN + #endif #include #include #include diff --git a/lib/components/base/basicLIBAV.h b/lib/components/base/basicLIBAV.h index 518a3a82..bd51952f 100644 --- a/lib/components/base/basicLIBAV.h +++ b/lib/components/base/basicLIBAV.h @@ -9,7 +9,7 @@ #include #ifdef _OPENCV_ #include - #include + //#include //using namespace cv; #else #ifdef _SDL_ diff --git a/lib/components/base/basicTransport.h b/lib/components/base/basicTransport.h index dae956a2..58e1aa29 100644 --- a/lib/components/base/basicTransport.h +++ b/lib/components/base/basicTransport.h @@ -8,7 +8,9 @@ #include "basicLogCollection.h" #ifdef DEBUG - #define DUBUG_COMMUNICATION + #ifndef DUBUG_COMMUNICATION + #define DUBUG_COMMUNICATION + #endif #endif class protocolParser; diff --git a/lib/data/protocol/protocol.cpp b/lib/data/protocol/protocol.cpp index 849eb17d..09a03ef2 100644 --- a/lib/data/protocol/protocol.cpp +++ b/lib/data/protocol/protocol.cpp @@ -8,23 +8,27 @@ protocolParser::protocolParser() : m_mBufferProtectorMutex(){ m_pLog = basicLogCollection::getInstance(); + m_eConnectionStatus = CS_UNKNOWN; m_pParserBuffer = (U8*) malloc(PROTOCOL_PARSER_BUFFER_SIZE); m_nParserDataCount = 0; m_bStatus = 0; m_pCustomHandler = NULL; m_bBufferAltered = false; m_bStatus = 1; +#ifdef PROTOCOL_PARSER_IN_THREAD m_bParserThreadStatus = TH_PRE_INIT; - m_eConnectionStatus = CS_UNKNOWN; +#endif }; protocolParser::~protocolParser(){ # ifdef DEBUG LOG("Destructor Begin"); # endif +#ifdef PROTOCOL_PARSER_IN_THREAD if (m_bParserThreadStatus > TH_ARMED ) { waitParserThreadEnd( true ); }; +#endif m_mBufferProtectorMutex.unlock(); if (m_bParserThreadStatus < TH_ENDED ) { waitParserThreadEnd( true ); @@ -39,6 +43,7 @@ protocolParser::~protocolParser(){ bool protocolParser::create(void){ if (m_pParserBuffer != NULL) { +#ifdef PROTOCOL_PARSER_IN_THREAD if (m_bParserThreadStatus == TH_PRE_INIT) { m_bParserThreadStatus = TH_ARMED; #if defined( __linux__ ) || defined(WIN_PTHREAD) @@ -61,6 +66,7 @@ bool protocolParser::create(void){ LOG_ERROR("Thread object not ready to be created."); return false; }; +#endif return true; } else return false; }; @@ -94,6 +100,8 @@ bool protocolParser::parse( U8 *Buffer, size_t BufferSize ){ memcpy( m_pParserBuffer+m_nParserDataCount, Buffer, BufferSize ); m_nParserDataCount+=BufferSize; rv = m_bBufferAltered = true; +#ifndef PROTOCOL_PARSER_IN_THREAD +#endif }; m_mBufferProtectorMutex.unlock(); }; @@ -106,6 +114,7 @@ void protocolParser::dataEraser( U8 *&tPtr ){ tPtr = NULL; }; +#ifdef PROTOCOL_PARSER_IN_THREAD void protocolParser::m_fParserThreadProc(void){ int RetVal; m_bParserThreadStatus = TH_WORKING; @@ -208,7 +217,7 @@ void protocolParser::waitParserThreadEnd(bool forced){ #endif }; - +#endif //#ifndef PROTOCOL_PARSER_IN_THREAD bool protocolParser::getPackage( U8 **Package, size_t *Size ){ if( this ) { m_mBufferProtectorMutex.lock(); diff --git a/lib/data/protocol/protocol.h b/lib/data/protocol/protocol.h index 36e94fdf..042cc0cb 100644 --- a/lib/data/protocol/protocol.h +++ b/lib/data/protocol/protocol.h @@ -7,12 +7,15 @@ #include "../../components/base/basicTransport.h" #include "../../components/base/basicThread.h" +#define PROTOCOL_PARSER_IN_THREAD #define PROTO_TAG_GROUP "PROTOCOL" #define PROTO_QUEUE_MAX_PACKAGES 32 #define PROTOCOL_PARSER_BUFFER_SIZE 102400 #ifdef DEBUG - #define DUBUG_COMMUNICATION + #ifndef DUBUG_COMMUNICATION + #define DUBUG_COMMUNICATION + #endif #endif typedef struct S_protocolPackage{ @@ -30,17 +33,19 @@ class protocolParser { size_t m_nParserDataCount; bool m_bBufferAltered; basicMutex m_mBufferProtectorMutex; -#if defined( __linux__ ) || defined(WIN_PTHREAD) - pthread_t m_sParserThreadHandler; - static void *m_fParserThreadEntryPoint(void *); -#else - HANDLE m_hParserThreadHandle; - DWORD m_dwThreadID; - static DWORD WINAPI m_fParserThreadEntryPoint( LPVOID lpParameter ); -#endif +#ifdef PROTOCOL_PARSER_IN_THREAD + #if defined( __linux__ ) || defined(WIN_PTHREAD) + pthread_t m_sParserThreadHandler; + static void *m_fParserThreadEntryPoint(void *); + #else + HANDLE m_hParserThreadHandle; + DWORD m_dwThreadID; + static DWORD WINAPI m_fParserThreadEntryPoint( LPVOID lpParameter ); + #endif thredStatus m_bParserThreadStatus; void m_fParserThreadProc(void); void waitParserThreadEnd( bool forced = false ); +#endif protected: basicTransport *m_oDataTransport; CONNECTION_STATUS m_eConnectionStatus; diff --git a/lib/hardware/soc/general/3DLRF.h b/lib/hardware/soc/general/3DLRF.h index 3b73b02a..6a834fd8 100644 --- a/lib/hardware/soc/general/3DLRF.h +++ b/lib/hardware/soc/general/3DLRF.h @@ -620,14 +620,14 @@ enum { inline void make3Ddeg(uint32_t sid, float &az, float &el, bool master = true ){ az = ((float)(TH_LINE_NODES - (sid % TH_LINE_NODES))) * (B_DEGREE_FOV / (float)M_SCAN_POINTS); if ( master ){ - el = 90.0 - (float)(sid / TH_LINE_NODES) * (Q_DEGREE_FOV / Q_SCAN_COUNT) - Q_SHIFT_DOWN_FOV; + el = 90.0f - (float)(sid / TH_LINE_NODES) * (Q_DEGREE_FOV / Q_SCAN_COUNT) - Q_SHIFT_DOWN_FOV; } else { - el = 90.0 - (Q_SCAN_COUNT - (float)(sid / TH_LINE_NODES)) * (Q_DEGREE_FOV / Q_BLOCK_COUNT) - Q_SHIFT_DOWN_FOV; + el = 90.0f - (Q_SCAN_COUNT - (float)(sid / TH_LINE_NODES)) * (Q_DEGREE_FOV / Q_BLOCK_COUNT) - Q_SHIFT_DOWN_FOV; }; if( el < 0 ) { - el *= -1.0; - az = az + 180.0; - if( az > 360.0 ) az = az - 360.0; + el *= -1.0f; + az = az + 180.0f; + if( az > 360.0f ) az = az - 360.0f; }; }; @@ -686,7 +686,7 @@ enum { inline uint32_t makeSID(int kID, int qID, int bID){ int cid; int cqid; - int mid; + //int mid; int ccp; int opp; cqid = qID % Q_Q_INTERLEAVE; diff --git a/lib/hardware/uart/serialPort.cpp b/lib/hardware/uart/serialPort.cpp index d8afc3a8..47e3cc15 100644 --- a/lib/hardware/uart/serialPort.cpp +++ b/lib/hardware/uart/serialPort.cpp @@ -289,11 +289,11 @@ bool serialPort::HW_init( CSTR DevicePath, int Speed ){ CommTimeouts.WriteTotalTimeoutMultiplier = 10; CommTimeouts.WriteTotalTimeoutConstant = 100; */ - CommTimeouts.ReadIntervalTimeout = 0UL; - CommTimeouts.ReadTotalTimeoutMultiplier = 0UL; - CommTimeouts.ReadTotalTimeoutConstant = 0UL; - CommTimeouts.WriteTotalTimeoutMultiplier = 0UL; - CommTimeouts.WriteTotalTimeoutConstant = 0UL; + CommTimeouts.ReadIntervalTimeout = 1UL; + CommTimeouts.ReadTotalTimeoutMultiplier = 1UL; + CommTimeouts.ReadTotalTimeoutConstant = 1UL; + CommTimeouts.WriteTotalTimeoutMultiplier = 1UL; + CommTimeouts.WriteTotalTimeoutConstant = 1UL; // Set the time-out parameters for all read and write operations on the port. if (!SetCommTimeouts(m_ioFID, &CommTimeouts)){ sprintf(MsgBuffer, "Port [%s] Could not create the read thread.(SetCommTimeouts Failed)", m_sDevicePath); diff --git a/lib/hardware/uart/serialSOL.cpp b/lib/hardware/uart/serialSOL.cpp index 7a1e3238..87f4c80d 100644 --- a/lib/hardware/uart/serialSOL.cpp +++ b/lib/hardware/uart/serialSOL.cpp @@ -8,10 +8,13 @@ serialSOL::serialSOL( SOL_TYPE t ): transportSocket(){ m_eSolType = t; m_bInitComplete = false; m_nSocketFD = -1; + +#ifdef __linux__ m_sServerAddr; m_sClientAddr; memset( &m_sServerAddr, 0, sizeof( m_sServerAddr ) ); memset( &m_sClientAddr, 0, sizeof( m_sClientAddr ) ); +#endif }; serialSOL::~serialSOL(){ @@ -24,6 +27,7 @@ bool serialSOL::create( CSTR address, uint16_t port, int Speed ){ break; }; case SOL_UDP_CLIENT:{ +#ifdef __linux__ // Creating socket file descriptor if ( (m_nSocketFD = socket(AF_INET, SOCK_DGRAM, 0)) < 0 ) { LOG_ERROR("Socket Creation Failed!"); @@ -34,13 +38,28 @@ bool serialSOL::create( CSTR address, uint16_t port, int Speed ){ m_sServerAddr.sin_family = AF_INET; m_sServerAddr.sin_addr.s_addr = INADDR_ANY; m_sServerAddr.sin_port = htons( port ); - +#else + WSADATA wsaData; + // Initialize Winsock version 2.2 + + if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) { + char tBuff[128]; + sprintf(tBuff, "WSAStartup failed with error %ld", WSAGetLastError()); + LOG_ERROR(tBuff); + return false; + } else { + char tBuff[128]; + sprintf(tBuff, "The Winsock DLL status is %s.", wsaData.szSystemStatus); + LOG(tBuff); + }; +#endif break; }; case SOL_TCP_SERVER:{ break; }; case SOL_UDP_SERVER:{ +#ifdef __linux__ // Creating socket file descriptor if ( (m_nSocketFD = socket( AF_INET, SOCK_DGRAM, 0 )) < 0 ) { LOG_ERROR("Socket Creation Failed!"); @@ -57,6 +76,7 @@ bool serialSOL::create( CSTR address, uint16_t port, int Speed ){ LOG_ERROR("Bind Failed"); return false; }; +#endif break; }; }; @@ -66,7 +86,7 @@ bool serialSOL::create( CSTR address, uint16_t port, int Speed ){ int serialSOL::sendBlock( unsigned char *Data, int DataSize ){ if( !m_bInitComplete || !m_bConnected ) return -1; // Exit after unsuccess reconnect - int RetVal; + int RetVal = 0; if( m_nSocketFD > -1 ){ #ifdef DUBUG_COMMUNICATION @@ -74,6 +94,7 @@ int serialSOL::sendBlock( unsigned char *Data, int DataSize ){ sprintf(cBuffer,"Write into Socket %d bytes", DataSize ); LOG(cBuffer); #endif +#ifdef __linux__ socklen_t addr_len = sizeof( m_sClientAddr ); RetVal = sendto( m_nSocketFD, (const char *)Data, DataSize, MSG_CONFIRM, (const struct sockaddr *) &m_sClientAddr, addr_len ); @@ -86,7 +107,7 @@ int serialSOL::sendBlock( unsigned char *Data, int DataSize ){ setConnectionStatus( CS_DISCONNECTED ); return -1; }; - +#endif if( RetVal < 0 ) RetVal = 0; #ifdef DUBUG_COMMUNICATION @@ -112,8 +133,9 @@ int serialSOL::recptBlock( unsigned char *Buffer, int *BufferLength ){ setConnectionStatus( CS_DISCONNECTED ); return -1; // Exit after unsuccess reconnect }; - int RetVal; + int RetVal = 0; if( m_nSocketFD > -1 ) { +#ifdef __linux__ socklen_t addr_len = sizeof( m_sClientAddr ); //len is value/resuslt RetVal = recvfrom( m_nSocketFD, (char *)Buffer, MAXIMAL_SOCKET_PACKET_LENGTH, MSG_WAITALL, ( struct sockaddr *) &m_sClientAddr, &addr_len ); if( RetVal < 1 ){ @@ -128,6 +150,7 @@ int serialSOL::recptBlock( unsigned char *Buffer, int *BufferLength ){ return -1; }; }; +#endif } else { LOG_ERROR("Not Connected!"); *BufferLength = 0; diff --git a/lib/hardware/uart/serialSOL.h b/lib/hardware/uart/serialSOL.h index 5f9069c1..fc9d537a 100644 --- a/lib/hardware/uart/serialSOL.h +++ b/lib/hardware/uart/serialSOL.h @@ -17,13 +17,17 @@ #include #include -#include #include #include // File control definitions #include -#include -#include -#include +#ifdef __linux__ + #include + #include + #include + #include +#else + #include +#endif #ifdef DEBUG //#define _DEBUG_SOL_COMMUNICATION_ @@ -50,10 +54,14 @@ class serialSOL: public transportSocket { SOL_TYPE m_eSolType; bool m_bInitComplete; int m_nSocketFD; - +#ifdef __linux__ struct sockaddr_in m_sServerAddr; struct sockaddr_in m_sClientAddr; - +#else + WSADATA wsaData; + SOCKET ReceivingSocket; + SOCKADDR_IN ReceiverAddr; +#endif protected: int sendBlock( unsigned char *Data, int DataSize ); int recptBlock( unsigned char *Buffer, int *BufferLength );