diff --git a/Projects/argus/argus.vpj b/Projects/argus/argus.vpj index cc7bdb81..a15e0c4e 100644 --- a/Projects/argus/argus.vpj +++ b/Projects/argus/argus.vpj @@ -293,8 +293,11 @@ + + + @@ -303,17 +306,22 @@ + + + + - + + @@ -327,14 +335,19 @@ + + + + + @@ -343,12 +356,18 @@ + + + + + + +#include "LRF_TargetTracker.h" + #define LOG( X ) m_pLog->Log( "Tracker", this, X ) #define LOG_ERROR( X ) m_pLog->Log( "Tracker", this, _LOG_ERROR, X ) diff --git a/lib/App/3dSERVER/LRF_targetTracker.h b/lib/App/3dSERVER/LRF_TargetTracker.h similarity index 89% rename from lib/App/3dSERVER/LRF_targetTracker.h rename to lib/App/3dSERVER/LRF_TargetTracker.h index 27cc7cff..9da16907 100644 --- a/lib/App/3dSERVER/LRF_targetTracker.h +++ b/lib/App/3dSERVER/LRF_TargetTracker.h @@ -6,6 +6,8 @@ #include "../../components/base/basicEventHeap.h" #include "../../hardware/soc/general/3DLRF.h" +#include + #define TRACKER_MAX_TARGETS_POOL 128 #define TRACKER_DEFAULT_TTL_VALUE 3 // Scans to live @@ -41,7 +43,7 @@ typedef struct S_TRACKING_RECORD{ * * @author gagua */ -class LRF_targetTracker { +class LRF_TargetTracker { private: basicLogCollection * m_pLog; basicEventHeap * m_pEventHeap; @@ -58,10 +60,10 @@ class LRF_targetTracker { void extentTrackingRecord( TRACKING_RECORD *A, TRACKING_RECORD *B ); public: // Constructor - explicit LRF_targetTracker( int SST = 0, uint32_t Width = 0, uint32_t Delta = 32 ); + explicit LRF_TargetTracker( int SST = 0, uint32_t Width = 0, uint32_t Delta = 32 ); // Destructor - virtual ~LRF_targetTracker(); + virtual ~LRF_TargetTracker(); int validateTarget( targetRecord *TR, bool master = true ); void ScanComplete( void ); void MirrorComplete( void ); diff --git a/lib/App/3dSERVER/LRF_TwinConnector.cpp b/lib/App/3dSERVER/LRF_TwinConnector.cpp new file mode 100644 index 00000000..2ab91676 --- /dev/null +++ b/lib/App/3dSERVER/LRF_TwinConnector.cpp @@ -0,0 +1,218 @@ +#include "LRF_TwinConnector.h" +#define LOG( X ) m_pLog->Log( "TWINC", this, X ) +#ifdef DEBUG + #define LOG_ERROR( X ) {\ + char _tBfrErrMSG234[256];\ + sprintf( _tBfrErrMSG234, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\ + m_pLog->Log( "TWINC", this, _LOG_ERROR, _tBfrErrMSG234 );\ + } +#else + #define LOG_ERROR( X ) m_pLog->Log( "TWINC", this, _LOG_ERROR, X ); +#endif + +LRF_TwinConnector::LRF_TwinConnector( config_setting_t *Settings ): basicThread(){ + m_pLog = basicLogCollection::getInstance(); + m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, (CSTR)"TWIN_3DLRF_CONNECTION" ); + m_pProtocol = NULL; + m_pPort = NULL; + m_nMainSocket = -1; +}; + +LRF_TwinConnector::~LRF_TwinConnector(){ + if( m_pPort != NULL ) delete( m_pPort ); + if( m_pProtocol != NULL ) delete( m_pProtocol ); +}; + +bool LRF_TwinConnector::create(){ + +#ifdef PRU_SLAVE + m_pProtocol = new protocolInternalLRF3D_SLAVE(); +#else + m_pProtocol = new protocolInternalLRF3D_MASTER(); +#endif + + + int RetCode; + struct hostent *h_info; + + m_nMainSocket = socket( AF_INET, SOCK_STREAM, 0 ); + if( m_nMainSocket == -1){ + LOG_ERROR( "Some trouble with networking on this machine (Socket Error)!"); + return false; + }; + MainSocketAddress = NULL; + MainSocketAddress = ( struct sockaddr * ) malloc( sizeof( struct sockaddr_in ) ); + if( MainSocketAddress == NULL ){ + LOG_ERROR( "Some trouble with networking on this machine (Cannot Alloc Sockaddr Struct)!" ); + return false; + }; + bzero( MainSocketAddress, sizeof( struct sockaddr_in ) ); + h_info = gethostbyname ( m_pBindAddress ); + if ( h_info == NULL ){ + LOG_ERROR( "Some trouble with networking on this machine (Cannot Get Hostname)!" ); + return false; + }; + //***************************************** + //* there we building our network address * + //***************************************** + bcopy( h_info->h_addr, &(((struct sockaddr_in *)MainSocketAddress)->sin_addr), h_info->h_length ); + ((struct sockaddr_in *)MainSocketAddress)->sin_family = h_info->h_addrtype; + ((struct sockaddr_in *)MainSocketAddress)->sin_port = htons( m_nBindPort ); + + RetCode = bind( m_nMainSocket , MainSocketAddress, sizeof( struct sockaddr_in ) ); + if ( RetCode != 0 ){ + LOG_ERROR( "Error Binding to Port/Address" ); + return false; + }; + RetCode = listen( m_nMainSocket, 128); + if ( RetCode != 0 ){ + LOG_ERROR( "Cannot Listen Port/Address" ); + return false; + }; + + U8 dontblock; + dontblock = fcntl( m_nMainSocket, F_GETFL, NULL ); + dontblock |= O_NONBLOCK | O_NDELAY; + RetCode = ioctl( m_nMainSocket, FIONBIO, (char *) &dontblock ); + if ( RetCode == 0 ){ + LOG( "Set N-Blocking Mode of Accepting Socket" ); + } else { + LOG( "Can't set N-Blocking Mode of Accepting Socket" ); + }; + return init(); +}; + +void LRF_TwinConnector::m_fThreadProc( void ){ + TWIN_COMMAND * tCMD = NULL; + int ClientSocket = -1; + struct sockaddr ClientAddress; + socklen_t ClientAddressSize; + + m_bThreadStatus = TH_WORKING; + + while( m_bThreadStatus < TH_ENDED ){ + if( m_bCCMD == TWC_NO_COMMAND && tCMD == NULL ){ + // No CMD is EXEC so check new cmds + CMD_PROTEC.lock(); + if( m_qCMD.size() > 0 ){ + tCMD = m_qCMD.front(); + m_qCMD.pop(); + }; + CMD_PROTEC.unlock(); + }; + if( m_pPort != NULL ){ + if( m_pPort->getConnectionStatus() == CS_DISCONNECTED ){ + if( tCMD!= NULL ){ + //reset commands on disconnect + m_bCCMD = TWC_NO_COMMAND; + if( tCMD->PTR == NULL ) free( tCMD->PTR ); + free( tCMD ); + tCMD = NULL; + }; + delete( m_pPort ); + m_pPort = NULL; + continue; + }; + if( tCMD!= NULL ){ + if( m_bCCMD == TWC_NO_COMMAND ){ + // CMD not issued yet! + switch( tCMD->CMD ){ + case TWC_GET_STATUS:{ + if( m_pProtocol->requestStatus() ){ + m_bCCMD = tCMD->CMD; + }; + break; + }; + case TWC_GET_CONFIG:{ + break; + }; + case TWC_SET_CONFIG:{ + break; + }; + case TWC_GET_THDRAW:{ + break; + }; + case TWC_DO_REBOOT:{ + break; + }; + }; + } else { + // Waiting CMD exe status + switch( m_bCCMD ){ + case TWC_GET_STATUS:{ + if( m_pProtocol->getLastPackageType() == STATUS_ACK ){ + m_bCCMD = TWC_NO_COMMAND; + }; + break; + }; + }; + if( m_bCCMD == TWC_NO_COMMAND && tCMD != NULL ){ + // The command is finished - Will fetch next command from queue + if( tCMD->PTR == NULL ) free( tCMD->PTR ); + free( tCMD ); + tCMD = NULL; + }; + }; + SLEEP( 5 ); + } else { + SLEEP( 100 ); + }; + } else { + // (re)Establish Connection +#ifdef PRU_SLAVE + m_pPort = new clientPort( ); +#else + ClientAddressSize = (socklen_t) sizeof( struct sockaddr_in ); + ClientSocket = accept ( m_nMainSocket, &ClientAddress, &ClientAddressSize ); + if ( ClientSocket == -1 ) { + switch( errno ){ + case EAGAIN:{ + SLEEP(10); + continue; + }; + //case EWOULDBLOCK: me->Log(" The socket is marked non-blocking and no connections are present to be accepted."); break; + case EBADF: LOG_ERROR( "The descriptor is invalid." ); break; + case ECONNABORTED: LOG_ERROR( "A connection has been aborted."); break; + case EINTR: LOG_ERROR( "The system call was interrupted by a signal that was caught before a valid connection arrived."); break; + case EINVAL: LOG_ERROR( "Socket is not listening for connections, or addrlen is invalid (e.g., is negative)."); break; + case EMFILE: LOG_ERROR( "The per-process limit of open file descriptors has been reached."); break; + case ENFILE: LOG_ERROR( "The system limit on the total number of open files has been reached."); break; + case ENOTSOCK: LOG_ERROR( "The descriptor references a file, not a socket."); break; + case EOPNOTSUPP: LOG_ERROR( "The referenced socket is not of type SOCK_STREAM."); break; + case EFAULT: LOG_ERROR( "The addr argument is not in a writable part of the user address space."); break; + case ENOBUFS: + case ENOMEM: LOG_ERROR( "Not enough free memory. This often means that the memory allocation is limited by the socket buffer limits, not by the system memory."); break; + case EPROTO: LOG_ERROR( "Protocol error."); break; + case EPERM: LOG_ERROR( "Firewall rules forbid connection."); break; + case ENOSR: + case ESOCKTNOSUPPORT: + case EPROTONOSUPPORT: + case ETIMEDOUT: LOG_ERROR( " Unusual error in Kernel (Timeout, No Socket Support in Kernel, Unsupported Protocol)"); break; + //case ERESTARTSYS: me->Log(" Unusual error by Kernel"); break; + default: LOG_ERROR( " Unhandled error in Kernel"); break; + }; + m_bThreadStatus = TH_ENDED; + } else { + char tstr[CQUERY]; + inet_ntop( AF_INET, &(((struct sockaddr_in*) &(ClientAddress ))->sin_addr ), tstr, size ); + }; + LOG( "SLAVE LRF Connection Accepted" ); + m_pPort = new serverPort( ClientSocket ); + }; +#endif + if( m_pPort!= NULL ){ + if( !m_pPort->create() ){ + LOG_ERROR( "Connection not established!" ); + delete( m_pPort ); + m_pPort = NULL; + } else { + m_pPort->attachParser( m_pProtocol ); + }; + }; + }; + }; +}; + +#undef LOG +#undef LOG_ERROR + diff --git a/lib/App/3dSERVER/LRF_TwinConnector.h b/lib/App/3dSERVER/LRF_TwinConnector.h new file mode 100644 index 00000000..d07924ea --- /dev/null +++ b/lib/App/3dSERVER/LRF_TwinConnector.h @@ -0,0 +1,54 @@ +#ifndef __LRF_TWINCONNECTOR_H_INCL__ +#define __LRF_TWINCONNECTOR_H_INCL__ + + +typedef enum E_TWIN_COMMAND{ + TWC_NO_COMMAND = 0, + TWC_GET_STATUS = 1, + TWC_GET_CONFIG = 2, + TWC_SET_CONFIG = 3, + TWC_GET_THDRAW = 4, + TWC_DO_REBOOT = 255 +} TWIN_COMMAND; + +typedef struct S_TWIN_CMD_RECORD{ + TWIN_COMMAND CMD; + void * PTR; +} TWIN_COMMAND; + + +typedef queue TWIN_COMMAND_QUEUE; + +class LRF_TwinConnector: public basicThread { + private: + basicLogCollection *m_pLog; + config_setting_t *m_pSettings; + TWIN_COMMAND_QUEUE m_qCMD; + TWIN_COMMAND m_bCCMD; + basicMutex CMD_PROTEC; +#ifdef PRU_SLAVE + protocolInternalLRF3D_SLAVE *m_pProtocol; + clientPort *m_pPort; +#else + protocolInternalLRF3D_MASTER *m_pProtocol; + serverPort *m_pPort; + int m_nMainSocket; + LRF_TargetTracker m_pTracker; +#endif + protected: + void m_fThreadProc( void ); + public: + explicit LRF_TwinConnector( config_setting_t *Settings = NULL ); + virtual ~LRF_TwinConnector(); + bool create(); +#ifdef PRU_SLAVE + bool sendCurrentSettings( void ); +#else + bool attachTargetTracker( LRF_TargetTracker *ptr ); + bool requestSettings( void ); +#endif +}; + + + +#endif diff --git a/lib/data/net/clientPort.h b/lib/data/net/clientPort.h index c33597e7..0555db7a 100644 --- a/lib/data/net/clientPort.h +++ b/lib/data/net/clientPort.h @@ -20,7 +20,7 @@ #include #endif -#include "transportSocket.h" +#include "../transport/transportSocket.h" /** * TODO: Add class description diff --git a/lib/data/net/netServer.cpp b/lib/data/net/netServer.cpp index 6196eadf..1e0afa10 100644 --- a/lib/data/net/netServer.cpp +++ b/lib/data/net/netServer.cpp @@ -352,7 +352,7 @@ void networkServer::m_fThreadProc( void ){ m_bThreadStatus = TH_WORKING; while (m_bThreadStatus < TH_ENDED ){ ClientSocket = accept ( MainSocket, &ClientAddress, &size ); - if ( ClientSocket == -1 ) { + if ( ClientSocket < 0 ) { switch( errno ){ case EAGAIN:{ // Checkup client disconnection @@ -397,55 +397,22 @@ void networkServer::m_fThreadProc( void ){ }; m_bThreadStatus = TH_ENDED; } else { - if ( ClientSocket >= 0 ) { - if( m_bConnectionType == 1 ){ - char tstr[CQUERY]; + if( m_bConnectionType == 1 ){ + char tstr[CQUERY]; #ifdef __linux__ - inet_ntop( AF_INET, &(((struct sockaddr_in*) &(ClientAddress ))->sin_addr ), tstr, size ); + inet_ntop( AF_INET, &(((struct sockaddr_in*) &(ClientAddress ))->sin_addr ), tstr, size ); #else - strcpy( tstr, inet_ntoa( ((struct sockaddr_in*)&ClientAddress)->sin_addr ) ); - //InetNtop(AF_INET, &(((struct sockaddr_in*) &(ClientAddress ))->sin_addr ), tstr, size ); + strcpy( tstr, inet_ntoa( ((struct sockaddr_in*)&ClientAddress)->sin_addr ) ); + //InetNtop(AF_INET, &(((struct sockaddr_in*) &(ClientAddress ))->sin_addr ), tstr, size ); #endif - }; - LOG( "Client Connection Accepted" ); - LRF_ClientHandler *tHandle; - tHandle = new LRF_ClientHandler( ClientSocket ); - if( tHandle != NULL ) { - tHandle->attachEngine( m_pDetectorKernel ); - m_vHandlersPool.push_back( (networkClientHandler *) tHandle ); - }; - } else { - LOG_ERROR( "Client Socket Error" ); - switch( errno ){ - //case EAGAIN: continue; - case EWOULDBLOCK: LOG_ERROR( " The socket is marked non-blocking and no connections are present to be accepted." ); break; - case EBADF: LOG_ERROR( " The descriptor is invalid." ); break; - case ECONNABORTED: LOG_ERROR( " A connection has been aborted." ); break; - case EINTR:{// If Interrupted by Signal - No Harm was done - LOG_ERROR( " The system call was interrupted by a signal that was caught before a valid connection arrived." ); - continue; - }; - case EINVAL: LOG_ERROR( " Socket is not listening for connections, or addrlen is invalid (e.g., is negative)." ); break; - case EMFILE: LOG_ERROR( " The per-process limit of open file descriptors has been reached."); break; - case ENFILE: LOG_ERROR( " The system limit on the total number of open files has been reached."); break; - case ENOTSOCK: LOG_ERROR( " The descriptor references a file, not a socket."); break; - case EOPNOTSUPP: LOG_ERROR( " The referenced socket is not of type SOCK_STREAM." ); break; - case EFAULT: LOG_ERROR( " The addr argument is not in a writable part of the user address space." ); break; - case ENOBUFS: - case ENOMEM: LOG_ERROR( " Not enough free memory. This often means that the memory allocation is limited by the socket buffer limits, not by the system memory." ); break; - case EPROTO: LOG_ERROR( " Protocol error." ); break; - case EPERM: LOG_ERROR( " Firewall rules forbid connection." ); break; - case ENOSR: -#ifdef __linux__ - case ESOCKTNOSUPPORT: -#endif - case EPROTONOSUPPORT: - case ETIMEDOUT: LOG_ERROR( " Unusual error in Kernel (Timeout, No Socket Support in Kernel, Unsupported Protocol)" ); break; - //case ERESTARTSYS: me->Log(" Unusual error by Kernel"); break; - default: LOG_ERROR( " Unhandled error in Kernel" ); break; - }; - m_bThreadStatus = TH_ENDED; - }; + }; + LOG( "Client Connection Accepted" ); + LRF_ClientHandler *tHandle; + tHandle = new LRF_ClientHandler( ClientSocket ); + if( tHandle != NULL ) { + tHandle->attachEngine( m_pDetectorKernel ); + m_vHandlersPool.push_back( (networkClientHandler *) tHandle ); + }; }; }; LOG( "Core Worker Thread Ended" ); diff --git a/lib/data/net/serverPort.h b/lib/data/net/serverPort.h index 05a76790..2eee9a7a 100644 --- a/lib/data/net/serverPort.h +++ b/lib/data/net/serverPort.h @@ -20,7 +20,7 @@ #include #endif -#include "transportSocket.h" +#include "../transport/transportSocket.h" /** * TODO: Add class description diff --git a/lib/data/net/transportSocket.cpp b/lib/data/net/transportSocket.cpp deleted file mode 100644 index 2c123d80..00000000 --- a/lib/data/net/transportSocket.cpp +++ /dev/null @@ -1,142 +0,0 @@ -#include "transportSocket.h" - -#define LOG( X ) m_pLog->Log( "TransportSocket", this, X ) -#define LOG_ERROR( X ) m_pLog->Log( "TransportSocket", this, _LOG_ERROR, X ) - -// Constructor implementation -transportSocket::transportSocket() : basicTransport(), basicDualThread(){ - m_pLog = basicLogCollection::getInstance(); - //m_pInputBuffer = (U8 *)malloc(MAXIMAL_SOCKET_PACKET_LENGTH); - //if (m_pInputBuffer != NULL) { - m_nInputBufferSize = 0; - // m_pOutputBuffer = (U8 *)malloc(MAXIMAL_SOCKET_PACKET_LENGTH); - // if (m_pOutputBuffer != NULL) { - m_nOutputBufferSize = 0; -#ifdef DEBUG - LOG("Init IO Threads!"); -#endif - if( init() ){ //basicDualThread:: - int cnt = 5; - while( cnt-- && m_bThreadAStatus < TH_WORKING ) SLEEP(1); // To ensure start Thread procedures -#ifdef DEBUG - LOG("Init IO Threads Done"); -#endif - } else { - LOG_ERROR("Init IO Threads ERROR!"); - }; - // }; - //}; -}; - -// Destructor implementation -transportSocket::~transportSocket(){ -# ifdef DEBUG - LOG("Destruct: START"); -# endif - m_mBufferProtectorMutex.unlock(); - if( m_bThreadAStatus > TH_ARMED ) { - waitThreadAEnd(); -# ifdef DEBUG - LOG("DONE"); -# endif - }; - m_mQueueProtectorMutex.unlock(); - if( m_bThreadBStatus > TH_ARMED ) { - waitThreadBEnd(); -# ifdef DEBUG - LOG("DONE"); -# endif - }; - //if (m_pInputBuffer != NULL) { - // free(m_pInputBuffer); - //}; - //if (m_pOutputBuffer != NULL) { - // free(m_pOutputBuffer); - //}; -# ifdef DEBUG - LOG("Destruct: DONE"); -# endif -}; - -void transportSocket::m_fThreadAProc(void){ - int index; - int RetVal; - m_bThreadAStatus = TH_WORKING; - LOG("Sender Thread Started!"); - while (m_bThreadAStatus < TH_ENDED) { - m_mBufferProtectorMutex.lock(); - if( m_nOutputBufferSize > 0 ){ - index = 0; - while ((index < m_nOutputBufferSize) && (m_bThreadAStatus < TH_ENDED)){ - RetVal = sendBlock(m_pOutputBuffer + index, m_nOutputBufferSize - index); - if( RetVal > 0 ) index += RetVal; - if( RetVal == -1 ){ - m_bThreadBStatus = TH_ENDED; - m_bThreadAStatus = TH_ENDED; - LOG_ERROR("Connection Error[send]"); - setConnectionStatus( CS_DISCONNECTED ); - m_nOutputBufferSize = 0; - }; - }; - m_nOutputBufferSize = 0; - m_mBufferProtectorMutex.unlock(); - } else { - m_mBufferProtectorMutex.unlock(); - SLEEP(5); - }; - }; -}; - -void transportSocket::m_fThreadBProc(void){ - m_bThreadBStatus = TH_WORKING; - int RetVal; - LOG("Recipient Thread Started!"); - while( m_bThreadBStatus < TH_ENDED ){ - RetVal = recptBlock( m_pInputBuffer, &m_nInputBufferSize); - if( RetVal == -1 ){ - LOG_ERROR("Connection Error[rcpt]"); - m_nInputBufferSize = 0; - if(!getStatus()) { - setConnectionStatus(CS_DISCONNECTED); - m_bThreadBStatus = TH_ENDED; - m_bThreadAStatus = TH_ENDED; - } else SLEEP(100); - } else if( m_nInputBufferSize > 0 ){ - if (m_vParsers.size()) { - m_mQueueProtectorMutex.lock(); - for (parseQueue::iterator index = m_vParsers.begin(); index != m_vParsers.end(); index++) { - (*index)->parse(m_pInputBuffer, m_nInputBufferSize); - }; - m_nInputBufferSize = 0; - m_mQueueProtectorMutex.unlock(); - } else { - LOG_ERROR("Try to parse data but No Parsers Assigned!"); - }; - } else { - SLEEP(5); - }; - }; -}; - -bool transportSocket::sendData(unsigned char *Data, int DataSize){ - - if( m_bThreadAStatus != TH_WORKING ) { - LOG_ERROR("Trying to Send Data Before Transport Started!"); - return false; - }; - - m_mBufferProtectorMutex.lock(); - if (m_nOutputBufferSize + DataSize > MAXIMAL_SOCKET_PACKET_LENGTH ){ - m_mBufferProtectorMutex.unlock(); - LOG_ERROR("Data Too BIG"); - return false; - }; - memcpy(m_pOutputBuffer + m_nOutputBufferSize, Data, DataSize); - m_nOutputBufferSize += DataSize; - m_mBufferProtectorMutex.unlock(); - return true; -}; - - -#undef LOG -#undef LOG_ERROR \ No newline at end of file diff --git a/lib/data/net/transportSocket.cpp.bak b/lib/data/net/transportSocket.cpp.bak deleted file mode 100644 index 2c51a2ba..00000000 --- a/lib/data/net/transportSocket.cpp.bak +++ /dev/null @@ -1,113 +0,0 @@ -#include "transportSocket.h" - -#define LOG( X ) m_pLog->Log( "TransportSocket", this, X ) -#define LOG_ERROR( X ) m_pLog->Log( "TransportSocket", this, _LOG_ERROR, X ) - -// Constructor implementation -transportSocket::transportSocket() : basicTransport(), basicDualThread(){ - m_pLog = basicLogCollection::getInstance(); - m_pInputBuffer = (U8 *)malloc(MAXIMAL_SOCKET_PACKET_LENGTH); - if (m_pInputBuffer != NULL) { - m_nInputBufferSize = 0; - m_pOutputBuffer = (U8 *)malloc(MAXIMAL_SOCKET_PACKET_LENGTH); - if (m_pOutputBuffer != NULL) { - m_nOutputBufferSize = 0; - init(); - }; - }; -}; - -// Destructor implementation -transportSocket::~transportSocket(){ - m_mBufferProtectorMutex.unlock(); - SLEEP(1); - if( m_bThreadAStatus > TH_ARMED ) { - waitThreadAEnd( true ); - }; - m_mQueueProtectorMutex.unlock(); - SLEEP(1); - if( m_bThreadBStatus > TH_ARMED ) { - waitThreadBEnd( true ); - }; - if (m_pInputBuffer != NULL) { - free(m_pInputBuffer); - }; - if (m_pOutputBuffer != NULL) { - free(m_pOutputBuffer); - }; -}; - -void transportSocket::m_fThreadAProc(void){ - m_bThreadAStatus = TH_WORKING; - while (m_bThreadAStatus < TH_ENDED) { - m_mBufferProtectorMutex.lock(); - if( m_nOutputBufferSize > 0 ){ - int index; - int RetVal; - index = 0; - while ((index < m_nOutputBufferSize) && (m_bThreadAStatus < TH_ENDED)){ - RetVal = sendBlock(m_pOutputBuffer + index, m_nOutputBufferSize - index); - if (RetVal > 0) index += RetVal; - }; - m_nOutputBufferSize = 0; - m_mBufferProtectorMutex.unlock(); - } else { - m_mBufferProtectorMutex.unlock(); - SLEEP(1); - }; - }; -}; - -void transportSocket::m_fThreadBProc(void){ - m_bThreadBStatus = TH_WORKING; - int RetVal; - while( m_bThreadBStatus < TH_ENDED ){ - try{ - RetVal = recptBlock(m_pInputBuffer, &m_nInputBufferSize); - if (m_nInputBufferSize > 0){ - m_mQueueProtectorMutex.lock(); - for (parseQueue::iterator index = m_vParsers.begin(); index != m_vParsers.end(); index++){ - (*index)->parse(m_pInputBuffer, m_nInputBufferSize); - }; - m_mQueueProtectorMutex.unlock(); - } else if (RetVal == -1){ - m_bThreadBStatus = TH_ENDED;// - m_bThreadAStatus = TH_ENDED;// - LOG_ERROR("Connection Error"); - } else { - SLEEP(1); - }; - } - catch (exception e){ - m_bThreadBStatus = TH_ENDED;// - m_bThreadAStatus = TH_ENDED;// - LOG_ERROR("rcptBlock Error"); - }; - }; - LOG("Ended"); -}; - -void transportSocket::setConnectionStatus( CONNECTION_STATUS CS ){ - m_mQueueProtectorMutex.lock(); - for (parseQueue::iterator index = m_vParsers.begin(); index != m_vParsers.end(); index++){ - (*index)->setConnectionStatus( CS ); - }; - m_mQueueProtectorMutex.unlock(); -} - -bool transportSocket::sendData(unsigned char *Data, int DataSize){ - m_mBufferProtectorMutex.lock(); - if (m_nOutputBufferSize + DataSize > MAXIMAL_SOCKET_PACKET_LENGTH) { - m_mBufferProtectorMutex.unlock(); - LOG_ERROR("Data Too BIG"); - return false; - }; - memcpy(m_pOutputBuffer + m_nOutputBufferSize, Data, DataSize); - m_nOutputBufferSize += DataSize; - m_mBufferProtectorMutex.unlock(); - return true; -}; - - -#undef LOG -#undef LOG_ERROR \ No newline at end of file diff --git a/lib/data/net/transportSocket.h b/lib/data/net/transportSocket.h deleted file mode 100644 index 0aaeaa74..00000000 --- a/lib/data/net/transportSocket.h +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef __SOCKETTRANSPORT_H_INCL__ -#define __SOCKETTRANSPORT_H_INCL__ - -#include "../../components/base/basicDualThread.h" -#include "../../components/base/basicTransport.h" - -#define MAXIMAL_SOCKET_PACKET_LENGTH 102400 - -/** - * TODO: Add class description - * - * @author Gagua - */ -class transportSocket : public basicTransport, public basicDualThread { -private: - basicLogCollection *m_pLog; -protected: - //U8 *m_pInputBuffer; - //U8 *m_pOutputBuffer; - U8 m_pInputBuffer[MAXIMAL_SOCKET_PACKET_LENGTH]; - U8 m_pOutputBuffer[MAXIMAL_SOCKET_PACKET_LENGTH]; - int m_nInputBufferSize; - int m_nOutputBufferSize; - - virtual void m_fThreadAProc(void); - virtual void m_fThreadBProc(void); - virtual int sendBlock(unsigned char *Data, int DataSize){ return 0; }; - virtual int recptBlock(unsigned char *Buffer, int *BufferLength){ return 0; }; -public: - // Constructor - transportSocket(); - - // Destructor - virtual ~transportSocket(); - - // Copy constructor - // TODO: Uncomment the copy constructor when you need it. - //transportSocket(const socketTransport& src); - - // Assignment operator - // TODO: Uncomment the assignment operator when you need it. - //transportSocket& operator=(const transportSocket& src); - bool sendData(unsigned char *Data, int DataSize); -}; - -// TODO: Uncomment the copy constructor when you need it. -//inline transportSocket::transportSocket(const socketTransport& src) -//{ -// // TODO: copy -//} - -// TODO: Uncomment the assignment operator when you need it. -//inline transportSocket& transportSocket::operator=(const transportSocket& rhs) -//{ -// if (this == &rhs) { -// return *this; -// } -// -// // TODO: assignment -// -// return *this; -//} - -#endif // __SOCKETTRANSPORT_H_INCL__ diff --git a/lib/data/net/transportSocket.h.bak b/lib/data/net/transportSocket.h.bak deleted file mode 100644 index 9cbc6f76..00000000 --- a/lib/data/net/transportSocket.h.bak +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef __SOCKETTRANSPORT_H_INCL__ -#define __SOCKETTRANSPORT_H_INCL__ - -#include "../../components/base/basicDualThread.h" -#include "../../components/base/basicTransport.h" - -#define MAXIMAL_SOCKET_PACKET_LENGTH 102400 - -/** - * TODO: Add class description - * - * @author Gagua - */ -class transportSocket : public basicTransport, public basicDualThread { -private: - void m_fThreadAProc(void); - void m_fThreadBProc(void); - basicLogCollection *m_pLog; -protected: - U8 *m_pInputBuffer; - int m_nInputBufferSize; - U8 *m_pOutputBuffer; - int m_nOutputBufferSize; - virtual int sendBlock(unsigned char *Data, int DataSize){ return 0; }; - virtual int recptBlock(unsigned char *Buffer, int *BufferLength){ return 0; }; - void setConnectionStatus( CONNECTION_STATUS CS ); -public: - // Constructor - transportSocket(); - - // Destructor - virtual ~transportSocket(); - - // Copy constructor - // TODO: Uncomment the copy constructor when you need it. - //transportSocket(const socketTransport& src); - - // Assignment operator - // TODO: Uncomment the assignment operator when you need it. - //transportSocket& operator=(const transportSocket& src); - bool sendData(unsigned char *Data, int DataSize); -}; - -// TODO: Uncomment the copy constructor when you need it. -//inline transportSocket::transportSocket(const socketTransport& src) -//{ -// // TODO: copy -//} - -// TODO: Uncomment the assignment operator when you need it. -//inline transportSocket& transportSocket::operator=(const transportSocket& rhs) -//{ -// if (this == &rhs) { -// return *this; -// } -// -// // TODO: assignment -// -// return *this; -//} - -#endif // __SOCKETTRANSPORT_H_INCL__ diff --git a/lib/data/protocol/protocol.cpp b/lib/data/protocol/protocol.cpp index a9dd960f..330e52fd 100644 --- a/lib/data/protocol/protocol.cpp +++ b/lib/data/protocol/protocol.cpp @@ -12,7 +12,7 @@ protocolParser::protocolParser(config_setting_t *Settings) :basicThread(),m_mBuf m_bBufferAltered = false; m_bStatus = 1; m_eConnectionStatus = CS_UNKNOWN; - m_pSettings = basicSettingsProvider::getInstance()->getSubNode(Settings, (CSTR)PROTO_TAG_GROUP); + //m_pSettings = basicSettingsProvider::getInstance()->getSubNode(Settings, (CSTR)PROTO_TAG_GROUP); }; protocolParser::~protocolParser(){ diff --git a/lib/data/protocol/protocol.h b/lib/data/protocol/protocol.h index 4f7feb28..23425fd3 100644 --- a/lib/data/protocol/protocol.h +++ b/lib/data/protocol/protocol.h @@ -30,7 +30,7 @@ class protocolParser : public basicThread{ basicMutex m_mBufferProtectorMutex; protected: - config_setting_t *m_pSettings; + //config_setting_t *m_pSettings; CONNECTION_STATUS m_eConnectionStatus; basicLogCollection *m_pLog; U8 m_bStatus; @@ -43,7 +43,8 @@ class protocolParser : public basicThread{ void (*m_pCustomHandler)( protocolPackage *pPp ); //static void *m_ParserProc( void *Param ); public: - explicit protocolParser( config_setting_t *Settings = NULL ); + //explicit protocolParser( config_setting_t *Settings = NULL ); + protocolParser(); virtual ~protocolParser(); virtual bool create(void); bool parse( U8 *Buffer, size_t BufferSize ); diff --git a/lib/data/protocol/protocolInternalLRF3D.cpp b/lib/data/protocol/protocolInternalLRF3D.cpp new file mode 100644 index 00000000..095d74c1 --- /dev/null +++ b/lib/data/protocol/protocolInternalLRF3D.cpp @@ -0,0 +1,369 @@ +#include "protocolInternalLRF3D.h" +#define LOG( X ) m_pLog->Log( "protocolLRF3D", this, X ) +#ifdef DEBUG + #define LOG_ERROR( X ) {\ + char _tBfrErrMSG234[256];\ + sprintf( _tBfrErrMSG234, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\ + m_pLog->Log( "protocolLRF3D", this, _LOG_ERROR, _tBfrErrMSG234 );\ + } +#else + #define LOG_ERROR( X ) m_pLog->Log( "protocolLRF3D", this, _LOG_ERROR, X ); +#endif + +protocolInternalLRF3D::protocolInternalLRF3D(): protocolParser(){ + m_pLog = basicLogCollection::getInstance(); +}; + +protocolInternalLRF3D::~protocolInternalLRF3D(){ + +}; + +int protocolInternalLRF3D::packetChecker( U8 *Buffer, size_t BufferSize ){ +#ifdef DUBUG_COMMUNICATION + char tmp[32]; + int i; + for( i=0;i< BufferSize; i++ ) { + sprintf( tmp, " 0x%02X", Buffer[i] ); + LOG(tmp); + }; +#endif + if( Buffer[0] == 0xAA ){ + if( BufferSize > 5 ) { +#ifdef PRU_SLAVE + if ((Buffer[1] & 0x80) == 0x80 ){ +#else + if ((Buffer[1] & 0x80) == 0x00 ){ +#endif + size_t pLength; + pLength = ((Buffer[1] & 0x7F) << 8) | Buffer[2]; + if( BufferSize >= ( pLength + 4 ) ) { + U8 pCheckSum; + pCheckSum = checksumLGS( Buffer, pLength+3 ); + if( Buffer[pLength+3] == pCheckSum ) { +#ifdef DUBUG_COMMUNICATION + LOG((CSTR)"PacketChecker: Packet Is Recognized (0)"); +#endif + return 0; // Ok + } else { +#ifdef DUBUG_COMMUNICATION + LOG((CSTR)"PacketChecker: Packet Not Recognized CHK SUM(-1)"); +#endif + return -1; // To shift + }; + }; + } else { +#ifdef DUBUG_COMMUNICATION + LOG((CSTR)"PacketChecker: Packet Not Recognized TAG (-1)"); +#endif + return -1; // To shiftSeverity Code Description Project File Line Suppression State + }; + }; +#ifdef DUBUG_COMMUNICATION + LOG((CSTR)"PacketChecker: Packet Not Recognized SMALL SIZE(1)"); +#endif + return 1; // To grow + }; +#ifdef DUBUG_COMMUNICATION + LOG((CSTR)"PacketChecker: Packet Not Recognized START TAG(-1)"); +#endif + return -1; // To shift +}; + +protocolPackage *protocolInternalLRF3D::packetExtractor( U8 *Buffer, size_t BufferSize ){ + protocolPackage *RetVal; +#ifdef DUBUG_COMMUNICATION + char tmp[32]; + int i; + for( i=0;i< BufferSize; i++ ) { + sprintf( tmp, " 0x%02X", Buffer[i] ); + LOG(tmp); + }; +#endif + if( Buffer[0] == 0xAA ){ + if( BufferSize > 5 ){ +#ifdef PRU_SLAVE + if ((Buffer[1] & 0x80) == 0x80 ) { +#else + if ((Buffer[1] & 0x80) == 0x00 ) { +#endif + size_t pLength; + pLength = ((Buffer[1] & 0x7F) << 8) | Buffer[2]; + if( BufferSize >= ( pLength+4 ) ) { + U8 pCheckSum; + pCheckSum = checksumLGS(Buffer, pLength+3 ); + if( Buffer[pLength+3] == pCheckSum ) { + RetVal = (protocolPackage *) malloc(sizeof(protocolPackage)); + if( RetVal == NULL ) return NULL; + RetVal->m_pData =(U8*)malloc( pLength+4 ); + if( RetVal->m_pData == NULL ) { + free( RetVal ); + return NULL; + }; + RetVal->m_nSize = pLength+4; + RetVal->m_nCode = Buffer[CMD_IDX]; + memcpy( RetVal->m_pData, Buffer, RetVal->m_nSize ); +#ifdef DUBUG_COMMUNICATION + LOG((CSTR)"PacketExtractor: Packet Is Extracted (0)"); +#endif + return RetVal; + }; + }; + } else { + LOG_ERROR("TAG mismatch!"); + }; + }; +#ifdef DUBUG_COMMUNICATION + LOG((CSTR)"PacketExtractor: Packet Not Extracted(1)!!!"); +#endif + return NULL; + }; +#ifdef DUBUG_COMMUNICATION + LOG((CSTR)"PacketExtractor: Packet Not Extracted(-1)"); +#endif + return NULL; +}; + +#undef LOG +#undef LOG_ERROR + +#ifdef PRU_SLAVE + #define LOG( X ) m_pLog->Log( "protocolLRF3D_SLAVE", this, X ) + #ifdef DEBUG + #define LOG_ERROR( X ) {\ + char _tBfrErrMSG234[256];\ + sprintf( _tBfrErrMSG234, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\ + m_pLog->Log( "protocolLRF3D_SLAVE", this, _LOG_ERROR, _tBfrErrMSG234 );\ + } + #else + #define LOG_ERROR( X ) m_pLog->Log( "protocolLRF3D_SLAVE", this, _LOG_ERROR, X ); + #endif + + protocolInternalLRF3D_SLAVE::protocolInternalLRF3D_SLAVE( config_setting_t *Settings) : protocolInternalLRF3D() { + m_pLog = basicLogCollection::getInstance(); + m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, (CSTR)"MASTER_LRF_CONNECTION" ); + m_bFailureReason = 0; + m_bSettingsIsLoadded = false; + m_pMasterAddress = (CSTR) malloc( 16 ); + m_pPort = NULL; + }; + + protocolInternalLRF3D_SLAVE::~protocolInternalLRF3D_SLAVE(){ + if( m_pMasterAddress != NULL ) free( m_pMasterAddress ); + }; + + bool protocolInternalLRF3D_SLAVE::create( void ){ + config_setting_t *pSetting; + int tVal; + char tBuffer[256]; + + m_bFailureReason = 1; + + if( m_pSettings == NULL ) return false; + if ( m_pMasterAddress == NULL ) return false; + + if ( !m_bSettingsIsLoadded ){ + if (!config_setting_lookup_string(m_pSettings, "MASTER_ADDRESS", (const char**)&m_pMasterAddress)) { + strncpy( m_pMasterAddress, "10.0.0.1", 15 ); + pSetting = config_setting_add(m_pSettings, "MASTER_ADDRESS", CONFIG_TYPE_STRING); + config_setting_set_string(pSetting, m_pMasterAddress); + basicSettingsProvider::getInstance()->compromise(); + } else { + sprintf( tBuffer, "MASTER IP Address Read From Settings: %s", m_pMasterAddress ); + LOG( tBuffer ); + }; + if( !config_setting_lookup_int( m_pSettings, "MASTER_PORT", &tVal ) ){ + tVal = m_nMasterPort = 6564; + pSetting = config_setting_add( m_pSettings, "MASTER_PORT", CONFIG_TYPE_INT ); + config_setting_set_bool( pSetting, tVal ); + basicSettingsProvider::getInstance()->compromise(); + } else { + m_nMasterPort = tVal; + sprintf( tBuffer, "MASTER PORT Read From Settings: %d", tVal ); + LOG( tBuffer ); + }; + //basicSettingsProvider::getInstance()->validate(); + m_bSettingsIsLoadded = true; + }; + m_bFailureReason = 2; + if( m_pPort == NULL ){ + m_pPort = new clientPort( m_pMasterAddress, m_nMasterPort, true ); + if( m_pPort == NULL ) return false; + m_pPort->addRecipient( this ); + m_bFailureReason = 3; + if( m_pPort->getConnectionStatus() != CS_CONNECTED ) return false; + } else { + m_bFailureReason = 3; + if( !m_pPort->connectTo( m_pMasterAddress, m_nMasterPort ) ) return false; + }; + m_bFailureReason = 0; + return true; + }; + bool protocolInternalLRF3D_SLAVE::sendTrasholdData( uint8_t lrf_id, uint32_t dataIdx ){ + }; + bool protocolInternalLRF3D_SLAVE::sendTargets( void ){ + }; + + bool protocolInternalLRF3D_SLAVE::sendStatus( void ){ + if( m_oDataTransport == NULL ) return false; + uint8_t Buffer[16]; + Buffer[3] = 0xDC; + Buffer[4] = ( m_nStatus >> 24 ) & 0xFF; + Buffer[5] = ( m_nStatus >> 16 ) & 0xFF; + Buffer[6] = ( m_nStatus >> 8 ) & 0xFF; + Buffer[7] = m_nStatus & 0xFF; +#ifdef DEBUG + LOG("setStatus"); +#endif + return m_oDataTransport->sendData( Buffer, FinishUpPackage( Buffer, 8 ) ); + }; +#else + #define LOG( X ) m_pLog->Log( "protocolLRF3D_MASTER", this, X ) + #ifdef DEBUG + #define LOG_ERROR( X ) {\ + char _tBfrErrMSG234[256];\ + sprintf( _tBfrErrMSG234, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\ + m_pLog->Log( "protocolLRF3D_MASTER", this, _LOG_ERROR, _tBfrErrMSG234 );\ + } + #else + #define LOG_ERROR( X ) m_pLog->Log( "protocolLRF3D_MASTER", this, _LOG_ERROR, X ); + #endif + bool protocolInternalLRF3D_MASTER::create( void ){ + config_setting_t *pSetting; + int tVal; + char tBuffer[256]; + + m_bFailureReason = 1; + + if( m_pSettings == NULL ) return false; + if ( m_pBindAddress == NULL ) return false; + + if ( !m_bSettingsIsLoadded ){ + if (!config_setting_lookup_string(m_pSettings, "BIND_ADDRESS", (const char**)&m_pBindAddress)) { + strncpy( m_pBindAddress, "10.0.0.1", 15 ); + pSetting = config_setting_add(m_pSettings, "BIND_ADDRESS", CONFIG_TYPE_STRING); + config_setting_set_string(pSetting, m_pBindAddress); + basicSettingsProvider::getInstance()->compromise(); + } else { + sprintf( tBuffer, "BIND to IP Address Read From Settings: %s", m_pBindAddress ); + LOG( tBuffer ); + }; + if( !config_setting_lookup_int( m_pSettings, "BIND_PORT", &tVal ) ){ + tVal = m_nBindPort = 6564; + pSetting = config_setting_add( m_pSettings, "BIND_PORT", CONFIG_TYPE_INT ); + config_setting_set_bool( pSetting, tVal ); + basicSettingsProvider::getInstance()->compromise(); + } else { + m_nBindPort = tVal; + sprintf( tBuffer, "BIND to PORT Read From Settings: %d", tVal ); + LOG( tBuffer ); + }; + //basicSettingsProvider::getInstance()->validate(); + m_bSettingsIsLoadded = true; + }; + m_bFailureReason = 2; + if( m_pPort == NULL ){ + + + struct sockaddr ClientAddress; + socklen_t size; + int ClientSocket; + + size = (socklen_t) sizeof( struct sockaddr_in ); + + ClientSocket = accept ( MainSocket, &ClientAddress, &size ); + if ( ClientSocket == -1 ) { + switch( errno ){ + case EAGAIN:{ + // Checkup client disconnection + if( m_vHandlersPool.size()) { + for( vectorNetHandlers::iterator index = m_vHandlersPool.begin(); index < m_vHandlersPool.end(); index++ ) { + LRF_ClientHandler *tClient = (LRF_ClientHandler *)(*index); + if( tClient->getConnectionStatus() == CS_DISCONNECTED ){ + // Remove Client Handler + LOG("Remove Client"); + delete( tClient ); + m_vHandlersPool.erase( index ); + LOG("Client Stoped"); + LOG("Remove Client Done"); + }; + }; + }; + SLEEP(10); + continue; + }; + //case EWOULDBLOCK: me->Log(" The socket is marked non-blocking and no connections are present to be accepted."); break; + case EBADF: LOG_ERROR( "The descriptor is invalid." ); break; + case ECONNABORTED: LOG_ERROR( "A connection has been aborted."); break; + case EINTR: LOG_ERROR( "The system call was interrupted by a signal that was caught before a valid connection arrived."); break; + case EINVAL: LOG_ERROR( "Socket is not listening for connections, or addrlen is invalid (e.g., is negative)."); break; + case EMFILE: LOG_ERROR( "The per-process limit of open file descriptors has been reached."); break; + case ENFILE: LOG_ERROR( "The system limit on the total number of open files has been reached."); break; + case ENOTSOCK: LOG_ERROR( "The descriptor references a file, not a socket."); break; + case EOPNOTSUPP: LOG_ERROR( "The referenced socket is not of type SOCK_STREAM."); break; + case EFAULT: LOG_ERROR( "The addr argument is not in a writeable part of the user address space."); break; + case ENOBUFS: + case ENOMEM: LOG_ERROR( "Not enough free memory. This often means that the memory allocation is limited by the socket buffer limits, not by the system memory."); break; + case EPROTO: LOG_ERROR( "Protocol error."); break; + case EPERM: LOG_ERROR( "Firewall rules forbid connection."); break; + case ENOSR: + case ESOCKTNOSUPPORT: + case EPROTONOSUPPORT: + case ETIMEDOUT: LOG_ERROR( " Unusual error in Kernel (Timeout, No Socket Support in Kernel, Unsupported Protocol)"); break; + //case ERESTARTSYS: me->Log(" Unusual error by Kernel"); break; + default: LOG_ERROR( " Unhanded error in Kernel"); break; + }; + m_bThreadStatus = TH_ENDED; + } else { + if ( ClientSocket >= 0 ) { + if( m_bConnectionType == 1 ){ + char tstr[CQUERY]; + inet_ntop( AF_INET, &(((struct sockaddr_in*) &(ClientAddress ))->sin_addr ), tstr, size ); + }; + LOG( "Client Connection Accepted" ); + m_pPort = new serverPort( ClientSocket ); + } else { + LOG_ERROR( "Client Socket Error" ); + switch( errno ){ + //case EAGAIN: continue; + case EWOULDBLOCK: LOG_ERROR( " The socket is marked non-blocking and no connections are present to be accepted." ); break; + case EBADF: LOG_ERROR( " The descriptor is invalid." ); break; + case ECONNABORTED: LOG_ERROR( " A connection has been aborted." ); break; + case EINTR:{// If Interrupted by Signal - No Harm was done + LOG_ERROR( " The system call was interrupted by a signal that was caught before a valid connection arrived." ); + continue; + }; + case EINVAL: LOG_ERROR( " Socket is not listening for connections, or addrlen is invalid (e.g., is negative)." ); break; + case EMFILE: LOG_ERROR( " The per-process limit of open file descriptors has been reached."); break; + case ENFILE: LOG_ERROR( " The system limit on the total number of open files has been reached."); break; + case ENOTSOCK: LOG_ERROR( " The descriptor references a file, not a socket."); break; + case EOPNOTSUPP: LOG_ERROR( " The referenced socket is not of type SOCK_STREAM." ); break; + case EFAULT: LOG_ERROR( " The addr argument is not in a writable part of the user address space." ); break; + case ENOBUFS: + case ENOMEM: LOG_ERROR( " Not enough free memory. This often means that the memory allocation is limited by the socket buffer limits, not by the system memory." ); break; + case EPROTO: LOG_ERROR( " Protocol error." ); break; + case EPERM: LOG_ERROR( " Firewall rules forbid connection." ); break; + case ENOSR: + case ESOCKTNOSUPPORT: + case EPROTONOSUPPORT: + case ETIMEDOUT: LOG_ERROR( " Unusual error in Kernel (Timeout, No Socket Support in Kernel, Unsupported Protocol)" ); break; + //case ERESTARTSYS: me->Log(" Unusual error by Kernel"); break; + default: LOG_ERROR( " Unhandled error in Kernel" ); break; + }; + return false; + }; + }; + if( m_pPort == NULL ) return false; + m_pPort->addRecipient( this ); + m_bFailureReason = 3; + if( m_pPort->getConnectionStatus() != CS_CONNECTED ) return false; + } else { + m_bFailureReason = 3; + if( !m_pPort->connectTo( m_pMasterAddress, m_nMasterPort ) ) return false; + }; + m_bFailureReason = 0; + return true; + }; +#endif + +#undef LOG +#undef LOG_ERROR diff --git a/lib/data/protocol/protocolInternalLRF3D.h b/lib/data/protocol/protocolInternalLRF3D.h new file mode 100644 index 00000000..bb53f119 --- /dev/null +++ b/lib/data/protocol/protocolInternalLRF3D.h @@ -0,0 +1,72 @@ +#ifndef __PROTOCOL_LRF_3D_INTERNAL_MASTER_SERVER_COMMUNICATION__ +#define __PROTOCOL_LRF_3D_INTERNAL_MASTER_SERVER_COMMUNICATION__ + +//aliona +//https://www.pornhub.com/view_video.php?viewkey=ph5dffcb1983567 + +#include "protocol.h" + +class protocolInternalLRF3D: public protocolParser { + private: + basicLogCollection *m_pLog; + protected: + int packetChecker( U8 *Buffer, size_t BufferSize ); + protocolPackage *packetExtractor( U8 *Buffer, size_t BufferSize ); + inline int FinishUpPackage( U8 *Buffer, size_t Size ){ + Buffer[0] = 0xAA; + Buffer[1] = ((Size - 3) >> 8) | SEND_TAG; + Buffer[2] = (Size - 3) & 0xFF; + Buffer[Size] = checksumLGS(Buffer, Size); + return Size + 1; + }; + public: + protocolInternalLRF3D(); + virtual ~protocolInternalLRF3D(); + bool create(void); + +}; +#ifdef PRU_SLAVE + class protocolInternalLRF3D_SLAVE: public protocolInternalLRF3D{ + private: + basicLogCollection *m_pLog; + config_setting_t *m_pSettings; + CSTR m_pMasterAddress; + uint16_t m_nMasterPort; + uint8_t m_bFailureReason; + uint32_t m_nStatus; + clientPort *m_pPort; + bool m_bSettingsIsLoadded; + bool sendTrasholdData( uint8_t lrf_id, uint32_t dataIdx = 0 ); + bool sendTargets( void ); + bool sendStatus( void ); + protected: + virtual bool packetHandler( protocolPackage *Package ); + public: + explicit protocolInternalLRF3D_SLAVE( config_setting_t *Settings = NULL ); + virtual ~protocolInternalLRF3D_SLAVE(); + bool create( void ); + bool setTrasholdData( uint8_t lrf_id, uint32_t *ptr ); + bool enqueueTarget( void ); + uint8_t getFailureReason( void ){ return m_bFailureReason; }; + }; +#else + class protocolInternalLRF3D_MASTER: public protocolInternalLRF3D{ + private: + basicLogCollection *m_pLog; + config_setting_t *m_pSettings; + protected: + bool packetHandler( protocolPackage *Package ); + public: + explicit protocolInternalLRF3D_MASTER( config_setting_t *Settings = NULL ); + virtual ~protocolInternalLRF3D_MASTER(); + bool create(void); + bool ackDataSegment( uint32_t dataIdx = 0 ); + bool ackTargets( uint32_t pkgId ); + bool requestTargets(void); + bool requestTrasholdData( uint8_t lrf_id ); + bool requestStatus( void ); + + }; +#endif + +#endif \ No newline at end of file diff --git a/lib/data/protocol/protocolLGS.cpp b/lib/data/protocol/protocolLGS.cpp index d58140db..e94da42e 100644 --- a/lib/data/protocol/protocolLGS.cpp +++ b/lib/data/protocol/protocolLGS.cpp @@ -12,136 +12,10 @@ inline int FinishUpPackage(U8 *Buffer, size_t Size, U8 DeviceID){ return Size + 1; }; -protocolLGS::protocolLGS( basicTransport *Transport, U8 DeviceID ):protocolParser(){ - m_pLog = basicLogCollection::getInstance(); - m_bDeviceID = DeviceID; - m_oDataTransport = Transport; - if( m_oDataTransport != NULL ) { - m_oDataTransport->addRecipient( ( protocolParser *) this ); - }; -}; - -protocolLGS::~protocolLGS(){ -# ifdef DEBUG - LOG("Destructor Begin"); -# endif - m_mInquiryMutex.unlock(); -# ifdef DEBUG - LOG("Destructor End"); -# endif -}; - -bool protocolLGS::setTransport(basicTransport* Transport){ - if (Transport == NULL) return false; - if (m_oDataTransport != NULL) { - LOG_ERROR("Transport Already Assigned!"); - return false; - }; - m_oDataTransport = Transport; - return m_oDataTransport->addRecipient(this); -}; - -int protocolLGS::packetChecker(U8 *Buffer, size_t BufferSize ){ -#ifdef DUBUG_COMMUNICATION - char tmp[32]; - int i; - for( i=0;i< BufferSize; i++ ) { - sprintf( tmp, " 0x%02X", Buffer[i] ); - LOG(tmp); - }; -#endif - if( Buffer[0] == 0x55 ){ - if( BufferSize > 5 ) { - if (((Buffer[SIZE_IDX_A] & MASTER_TAG) == ACCEPT_TAG) && (Buffer[DEV_ID_IDX] == m_bDeviceID || Buffer[DEV_ID_IDX] == 0)){ - size_t pLength; - pLength = ((Buffer[SIZE_IDX_A] & 0x7F) << 8) | Buffer[SIZE_IDX_B]; - if( BufferSize >= ( pLength + 4 ) ) { - U8 pCheckSum; - pCheckSum = checksumLGS(Buffer, pLength+3 ); - if( Buffer[pLength+3] == pCheckSum ) { -#ifdef DUBUG_COMMUNICATION - LOG((CSTR)"PacketChecker: Packet Is Recognized (0)"); -#endif - return 0; // Ok - } else { -#ifdef DUBUG_COMMUNICATION - LOG((CSTR)"PacketChecker: Packet Not Recognized CHK SUM(-1)"); -#endif - return -1; // To shift - }; - }; - } else { -#ifdef DUBUG_COMMUNICATION - LOG((CSTR)"PacketChecker: Packet Not Recognized TAG (-1)"); -#endif - return -1; // To shift - }; - }; -#ifdef DUBUG_COMMUNICATION - LOG((CSTR)"PacketChecker: Packet Not Recognized SMALL SIZE(1)"); -#endif - return 1; // To grow - }; -#ifdef DUBUG_COMMUNICATION - LOG((CSTR)"PacketChecker: Packet Not Recognized START TAG(-1)"); -#endif - return -1; // To shift -}; - -protocolPackage *protocolLGS::packetExtractor(U8 *Buffer, size_t BufferSize ){ - protocolPackage *RetVal; -#ifdef DUBUG_COMMUNICATION - char tmp[32]; - int i; - for( i=0;i< BufferSize; i++ ) { - sprintf( tmp, " 0x%02X", Buffer[i] ); - LOG(tmp); - }; -#endif - if( Buffer[0] == 0x55 ){ - if( BufferSize > 5 ){ - if (((Buffer[SIZE_IDX_A] & MASTER_TAG) == ACCEPT_TAG) && (Buffer[DEV_ID_IDX] == m_bDeviceID || Buffer[DEV_ID_IDX] == 0)) { - size_t pLength; - pLength = ((Buffer[SIZE_IDX_A] & 0x7F) << 8) | Buffer[SIZE_IDX_B]; - if( BufferSize >= ( pLength+4 ) ) { - U8 pCheckSum; - pCheckSum = checksumLGS(Buffer, pLength+3 ); - if( Buffer[pLength+3] == pCheckSum ) { - RetVal = (protocolPackage *) malloc(sizeof(protocolPackage)); - if( RetVal == NULL ) return NULL; - RetVal->m_pData =(U8*)malloc( pLength+4 ); - if( RetVal->m_pData == NULL ) { - free( RetVal ); - return NULL; - }; - RetVal->m_nSize = pLength+4; - RetVal->m_nCode = Buffer[CMD_IDX]; - memcpy( RetVal->m_pData, Buffer, RetVal->m_nSize ); -#ifdef DUBUG_COMMUNICATION - LOG((CSTR)"PacketExtractor: Packet Is Extracted (0)"); -#endif - return RetVal; - }; - }; - } else { - LOG_ERROR("TAG mismatch!"); - }; - }; -#ifdef DUBUG_COMMUNICATION - LOG((CSTR)"PacketExtractor: Packet Not Extracted(1)!!!"); -#endif - return NULL; - }; -#ifdef DUBUG_COMMUNICATION - LOG((CSTR)"PacketExtractor: Packet Not Extracted(-1)"); -#endif - return NULL; -}; - /* protocolLGS_CLIENT Methods */ -protocolLGS_CLIENT::protocolLGS_CLIENT( basicTransport *Transport, U8 DeviceID ) : protocolLGS( Transport, DeviceID ){ +protocolLGS_CLIENT::protocolLGS_CLIENT( basicTransport *Transport, U8 DeviceID ) : protocolLGSm( Transport, DeviceID ){ m_pLog = basicLogCollection::getInstance(); }; @@ -149,178 +23,154 @@ protocolLGS_CLIENT::~protocolLGS_CLIENT(){ }; -bool protocolLGS_CLIENT::getState( void ){; - if( this ){ - U8 Buffer[16]; - Buffer[CMD_IDX] = CMD_STATE; +bool protocolLGS_CLIENT::getState( void ){ + U8 Buffer[16]; + if( m_oDataTransport == NULL ) return false; + + Buffer[CMD_IDX] = CMD_STATE; #ifdef DEBUG - LOG("getState"); + LOG("getState"); #endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage( Buffer, 5, m_bDeviceID)); - }; - return false; + return m_oDataTransport->sendData(Buffer, FinishUpPackage( Buffer, 5, m_bDeviceID)); }; bool protocolLGS_CLIENT::getState2( void ){ - if( this ){ - U8 Buffer[16]; - Buffer[CMD_IDX] = CMD_STATE_2; + if( m_oDataTransport == NULL ) return false; + U8 Buffer[16]; + Buffer[CMD_IDX] = CMD_STATE_2; #ifdef TARGET_WITH_WIDTH - Buffer[SUB_CMD_IDX] = 0x02; + Buffer[SUB_CMD_IDX] = 0x02; #else - Buffer[SUB_CMD_IDX] = 0x00; + Buffer[SUB_CMD_IDX] = 0x00; #endif #ifdef DEBUG - LOG("getState2"); + LOG("getState2"); #endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage( Buffer, 6, m_bDeviceID)); - }; - return false; + return m_oDataTransport->sendData(Buffer, FinishUpPackage( Buffer, 6, m_bDeviceID)); }; bool protocolLGS_CLIENT::doFullReset( void ){ - if( this ) { - U8 Buffer[16]; - Buffer[CMD_IDX] = CMD_FULL_RESET; + if( m_oDataTransport == NULL ) return false; + U8 Buffer[16]; + Buffer[CMD_IDX] = CMD_FULL_RESET; #ifdef DEBUG - LOG("doFullReset"); + LOG("doFullReset"); #endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 5, m_bDeviceID)); - }; - return false; + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 5, m_bDeviceID)); }; bool protocolLGS_CLIENT::doReset( void ){ - if( this ) { - U8 Buffer[16]; - Buffer[CMD_IDX] = CMD_RESET; + if( m_oDataTransport == NULL ) return false; + U8 Buffer[16]; + Buffer[CMD_IDX] = CMD_RESET; #ifdef DEBUG - LOG("doReset"); + LOG("doReset"); #endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 5, m_bDeviceID)); - }; - return false; + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 5, m_bDeviceID)); }; bool protocolLGS_CLIENT::doStartMotors( void ){ - if( this ) { - U8 Buffer[16]; - Buffer[CMD_IDX] = CMD_DHWM_START_MOTORS; + if( m_oDataTransport == NULL ) return false; + U8 Buffer[16]; + Buffer[CMD_IDX] = CMD_DHWM_START_MOTORS; #ifdef DEBUG - LOG("doStartMotors"); + LOG("doStartMotors"); #endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 5, m_bDeviceID)); - }; - return false; + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 5, m_bDeviceID)); }; bool protocolLGS_CLIENT::doStopMotors( void ){ - if( this ) { - U8 Buffer[16]; - Buffer[CMD_IDX] = CMD_DHWM_STOP_MOTORS; + if( m_oDataTransport == NULL ) return false; + U8 Buffer[16]; + Buffer[CMD_IDX] = CMD_DHWM_STOP_MOTORS; #ifdef DEBUG - LOG("doStopMotors"); + LOG("doStopMotors"); #endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 5, m_bDeviceID)); - }; - return false; + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 5, m_bDeviceID)); }; bool protocolLGS_CLIENT::getDraw( uint32_t SampleID, uint8_t KernelID ){ - if( this ) { - U8 Buffer[16]; - Buffer[CMD_IDX] = CMD_FULL_BORDER; - Buffer[5] = (SampleID >> 24) & 0xFF; - Buffer[6] = (SampleID >> 16) & 0xFF; - Buffer[7] = (SampleID >> 8) & 0xFF; - Buffer[8] = SampleID & 0xFF; - Buffer[9] = KernelID; -#ifdef DEBUG - LOG("getDraw"); -#endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 10, m_bDeviceID)); - }; - return false; + if( m_oDataTransport == NULL ) return false; + U8 Buffer[16]; + Buffer[CMD_IDX] = CMD_FULL_BORDER; + Buffer[5] = (SampleID >> 24) & 0xFF; + Buffer[6] = (SampleID >> 16) & 0xFF; + Buffer[7] = (SampleID >> 8) & 0xFF; + Buffer[8] = SampleID & 0xFF; + Buffer[9] = KernelID; +#ifdef DEBUG + LOG("getDraw"); +#endif + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 10, m_bDeviceID)); }; bool protocolLGS_CLIENT::setMode( U8 Mode ){ - if( this ) { - U8 Buffer[16]; - Buffer[CMD_IDX] = CMD_MODE; - Buffer[SUB_CMD_IDX] = Mode | 0x80; + if( m_oDataTransport == NULL ) return false; + U8 Buffer[16]; + Buffer[CMD_IDX] = CMD_MODE; + Buffer[SUB_CMD_IDX] = Mode | 0x80; #ifdef DEBUG - LOG("setMode"); + LOG("setMode"); #endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 6, m_bDeviceID)); - }; - return false; + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 6, m_bDeviceID)); }; bool protocolLGS_CLIENT::getParameters( void ){ - if( this ) { - U8 Buffer[16]; - Buffer[CMD_IDX] = CMD_GET_PARAMETERS; + if( m_oDataTransport == NULL ) return false; + U8 Buffer[16]; + Buffer[CMD_IDX] = CMD_GET_PARAMETERS; #ifdef DEBUG - LOG("getParameters"); + LOG("getParameters"); #endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 5, m_bDeviceID)); - }; - return false; + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 5, m_bDeviceID)); }; bool protocolLGS_CLIENT::setParameters( PLGS_PARAMETERS ptr ){ - if( this ) { - U8 counter; - U8 Buffer[64]; - Buffer[CMD_IDX] = CMD_SET_PARAMETERS; - counter = SUB_CMD_IDX; - for( int i=0; i < sizeof( LGS_PARAMETERS ); i++ ){ - Buffer[counter] = *(((U8*)ptr)+i); - counter++; - }; -#ifdef DEBUG - LOG("setParameters"); -#endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, counter, m_bDeviceID)); - }; - return false; + if( m_oDataTransport == NULL ) return false; + U8 counter; + U8 Buffer[64]; + Buffer[CMD_IDX] = CMD_SET_PARAMETERS; + counter = SUB_CMD_IDX; + for( int i=0; i < sizeof( LGS_PARAMETERS ); i++ ){ + Buffer[counter] = *(((U8*)ptr)+i); + counter++; + }; +#ifdef DEBUG + LOG("setParameters"); +#endif + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, counter, m_bDeviceID)); }; bool protocolLGS_CLIENT::getShadowPoly( uint8_t PolyID ){ - if( this ) { - U8 Buffer[16]; - Buffer[CMD_IDX] = CMD_GET_HZ_POLY; - Buffer[SUB_CMD_IDX] = PolyID; + if( m_oDataTransport == NULL ) return false; + U8 Buffer[16]; + Buffer[CMD_IDX] = CMD_GET_HZ_POLY; + Buffer[SUB_CMD_IDX] = PolyID; #ifdef DEBUG - LOG("getShadowPoly"); + LOG("getShadowPoly"); #endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 6, m_bDeviceID)); - }; - return false; + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 6, m_bDeviceID)); }; bool protocolLGS_CLIENT::getShadowStatus( uint8_t MaskID ){ - if( this ) { - U8 Buffer[16]; - Buffer[CMD_IDX] = CMD_GET_HZ_STATUS; - Buffer[SUB_CMD_IDX] = MaskID; // Future Use - Mask ID + if( m_oDataTransport == NULL ) return false; + U8 Buffer[16]; + Buffer[CMD_IDX] = CMD_GET_HZ_STATUS; + Buffer[SUB_CMD_IDX] = MaskID; // Future Use - Mask ID #ifdef DEBUG - LOG("getShadowStatus"); + LOG("getShadowStatus"); #endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 6, m_bDeviceID)); - }; - return false; + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 6, m_bDeviceID)); }; bool protocolLGS_CLIENT::getShadowInfo( void ){ - if( this ) { - U8 Buffer[16]; - Buffer[CMD_IDX] = CMD_GET_HZ_INFO; + if( m_oDataTransport == NULL ) return false; + U8 Buffer[16]; + Buffer[CMD_IDX] = CMD_GET_HZ_INFO; #ifdef DEBUG - LOG("getShadowInfo"); + LOG("getShadowInfo"); #endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 5, m_bDeviceID)); - }; - return false; + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 5, m_bDeviceID)); }; bool protocolLGS_CLIENT::setShadowPoly( simplePolygone *SP ){ - if (SP == NULL){ + if( m_oDataTransport == NULL ) return false; + if ( SP == NULL ){ uint8_t Buffer[16]; Buffer[CMD_IDX] = CMD_SET_HZ_POLY; Buffer[SUB_CMD_IDX] = 0; @@ -329,84 +179,78 @@ bool protocolLGS_CLIENT::setShadowPoly( simplePolygone *SP ){ #endif return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 6, m_bDeviceID)); }; - if( this ) { - U8 counter; - U8 Buffer[PROTOCOL_PARSER_BUFFER_SIZE]; - Buffer[CMD_IDX] = CMD_SET_HZ_POLY; - Buffer[SUB_CMD_IDX] = SP->count; - Buffer[SUB_CMD_IDX+1] = SP->color[0]; - Buffer[SUB_CMD_IDX+2] = SP->color[1]; - Buffer[SUB_CMD_IDX+3] = SP->color[2]; - counter = SUB_CMD_IDX+4; - for( uint8_t i = 0; i < SP->count; i++ ){ - uint16_t x,y; - x = SP->points[i].x(); - y = SP->points[i].y(); - Buffer[counter++] = ( x >> 8 ) & 0xFF; - Buffer[counter++] = x & 0xFF; - Buffer[counter++] = ( y >> 8 ) & 0xFF; - Buffer[counter++] = y & 0xFF; - }; -#ifdef DEBUG - LOG("sendShadowPoly"); -#endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, counter, m_bDeviceID ) ); - }; - return false; + + U8 counter; + U8 Buffer[PROTOCOL_PARSER_BUFFER_SIZE]; + Buffer[CMD_IDX] = CMD_SET_HZ_POLY; + Buffer[SUB_CMD_IDX] = SP->count; + Buffer[SUB_CMD_IDX+1] = SP->color[0]; + Buffer[SUB_CMD_IDX+2] = SP->color[1]; + Buffer[SUB_CMD_IDX+3] = SP->color[2]; + counter = SUB_CMD_IDX+4; + for( uint8_t i = 0; i < SP->count; i++ ){ + uint16_t x,y; + x = SP->points[i].x(); + y = SP->points[i].y(); + Buffer[counter++] = ( x >> 8 ) & 0xFF; + Buffer[counter++] = x & 0xFF; + Buffer[counter++] = ( y >> 8 ) & 0xFF; + Buffer[counter++] = y & 0xFF; + }; +#ifdef DEBUG + LOG("sendShadowPoly"); +#endif + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, counter, m_bDeviceID ) ); }; bool protocolLGS_CLIENT::setShadowStatus( bool Status, uint8_t MaskID ){ - if( this ) { - U8 Buffer[16]; - Buffer[CMD_IDX] = CMD_SET_HZ_ENABLE; - Buffer[SUB_CMD_IDX] = MaskID; // Future Use - Mask ID - Buffer[6] = (uint8_t)Status; + if( m_oDataTransport == NULL ) return false; + U8 Buffer[16]; + Buffer[CMD_IDX] = CMD_SET_HZ_ENABLE; + Buffer[SUB_CMD_IDX] = MaskID; // Future Use - Mask ID + Buffer[6] = (uint8_t)Status; #ifdef DEBUG - LOG("setShadowStatus"); + LOG("setShadowStatus"); #endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 7, m_bDeviceID)); - }; - return false; + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 7, m_bDeviceID)); }; bool protocolLGS_CLIENT::setShadowTrace( vectorZoneMask *VM ){ if( VM == NULL ) return false; - if( this ) { - uint16_t counter; - uint8_t Buffer[PROTOCOL_PARSER_BUFFER_SIZE]; - uint16_t tVal; - Buffer[CMD_IDX] = CMD_SET_HZ_DATA; - tVal = VM->size(); - Buffer[SUB_CMD_IDX] = ( tVal >> 8 ) & 0xFF; - Buffer[SUB_CMD_IDX+1] = tVal & 0xFF; - counter = SUB_CMD_IDX+2; - for( uint16_t i = 0; i < tVal; i++ ){ - uint16_t x, y, start, stop; - x = VM->at( i )->column; - y = VM->at( i )->count; - Buffer[counter++] = ( x >> 8 ) & 0xFF; - Buffer[counter++] = x & 0xFF; - Buffer[counter++] = ( y >> 8 ) & 0xFF; - Buffer[counter++] = y & 0xFF; - for( uint8_t j = 0; j < y; j++ ){ - start = VM->at( i )->zones[j].start; - stop = VM->at( i )->zones[j].stop; - Buffer[counter++] = ( start >> 8 ) & 0xFF; - Buffer[counter++] = start & 0xFF; - Buffer[counter++] = ( stop >> 8 ) & 0xFF; - Buffer[counter++] = stop & 0xFF; - }; - }; -#ifdef DEBUG - LOG("setShadowTrace"); -#endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, counter, m_bDeviceID ) ); - }; - return false; + if( m_oDataTransport == NULL ) return false; + uint16_t counter; + uint8_t Buffer[PROTOCOL_PARSER_BUFFER_SIZE]; + uint16_t tVal; + Buffer[CMD_IDX] = CMD_SET_HZ_DATA; + tVal = VM->size(); + Buffer[SUB_CMD_IDX] = ( tVal >> 8 ) & 0xFF; + Buffer[SUB_CMD_IDX+1] = tVal & 0xFF; + counter = SUB_CMD_IDX+2; + for( uint16_t i = 0; i < tVal; i++ ){ + uint16_t x, y, start, stop; + x = VM->at( i )->column; + y = VM->at( i )->count; + Buffer[counter++] = ( x >> 8 ) & 0xFF; + Buffer[counter++] = x & 0xFF; + Buffer[counter++] = ( y >> 8 ) & 0xFF; + Buffer[counter++] = y & 0xFF; + for( uint8_t j = 0; j < y; j++ ){ + start = VM->at( i )->zones[j].start; + stop = VM->at( i )->zones[j].stop; + Buffer[counter++] = ( start >> 8 ) & 0xFF; + Buffer[counter++] = start & 0xFF; + Buffer[counter++] = ( stop >> 8 ) & 0xFF; + Buffer[counter++] = stop & 0xFF; + }; + }; +#ifdef DEBUG + LOG("setShadowTrace"); +#endif + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, counter, m_bDeviceID ) ); }; /* protocolLGS_SERVER Methods */ -protocolLGS_SERVER::protocolLGS_SERVER( basicTransport *Transport, U8 DeviceID ) : protocolLGS( Transport, DeviceID ){ +protocolLGS_SERVER::protocolLGS_SERVER( basicTransport *Transport, U8 DeviceID ) : protocolLGSm( Transport, DeviceID ){ m_pLog = basicLogCollection::getInstance(); }; @@ -418,368 +262,328 @@ protocolLGS_SERVER::~protocolLGS_SERVER(){ }; bool protocolLGS_SERVER::sendBorderError(uint8_t Error){ - if( this ){ - U8 Buffer[16]; - Buffer[CMD_IDX] = CMD_BORDER; - Buffer[SUB_CMD_IDX] = Error; + if( m_oDataTransport == NULL ) return false; + U8 Buffer[16]; + Buffer[CMD_IDX] = CMD_BORDER; + Buffer[SUB_CMD_IDX] = Error; # ifdef DEBUG - LOG("sendBorderError"); + LOG("sendBorderError"); # endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 6, m_bDeviceID)); - }; - return false; + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 6, m_bDeviceID)); }; bool protocolLGS_SERVER::sendBorderData(uint32_t SampleID, uint8_t KernelID, thresholdNode *WorkingSAF){ - if (this){ - U8 Buffer[PROTOCOL_PARSER_BUFFER_SIZE]; - - Buffer[CMD_IDX] = CMD_BORDER; - Buffer[SUB_CMD_IDX] = BD_ANGLEMASK | BD_RANGE0MASK | BD_RANGE1MASK; - int index = 6; - int cCount = 0; - int node_index = SampleID; - while ((index < BOARDDATA_PACKAGE_SIZE_BYTES ) && (node_index < TH_SIZE_NODES) ){ - thresholdNode cNode; - //cNode = WorkingSAF[node_index++]; - memcpy( &cNode, &WorkingSAF[node_index++], sizeof(thresholdNode)); - Buffer[index++] = (cNode.data >> 24 ) & 0xFE; // to clear Sunbit data - Buffer[index++] = (cNode.data >> 16 ) & 0xFF; - Buffer[index++] = (cNode.data >> 8 ) & 0xFF; - Buffer[index++] = cNode.data & 0xFF; - cCount++; - }; -# ifdef DEBUG - LOG("sendBorderData"); -# endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 5 + index, m_bDeviceID)); - }; - return false; + if( m_oDataTransport == NULL ) return false; + U8 Buffer[PROTOCOL_PARSER_BUFFER_SIZE]; + + Buffer[CMD_IDX] = CMD_BORDER; + Buffer[SUB_CMD_IDX] = BD_ANGLEMASK | BD_RANGE0MASK | BD_RANGE1MASK; + int index = 6; + int cCount = 0; + int node_index = SampleID; + while ((index < BOARDDATA_PACKAGE_SIZE_BYTES ) && (node_index < TH_SIZE_NODES) ){ + thresholdNode cNode; + //cNode = WorkingSAF[node_index++]; + memcpy( &cNode, &WorkingSAF[node_index++], sizeof(thresholdNode)); + Buffer[index++] = (cNode.data >> 24 ) & 0xFE; // to clear Sunbit data + Buffer[index++] = (cNode.data >> 16 ) & 0xFF; + Buffer[index++] = (cNode.data >> 8 ) & 0xFF; + Buffer[index++] = cNode.data & 0xFF; + cCount++; + }; +#ifdef DEBUG + LOG("sendBorderData"); +#endif + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 5 + index, m_bDeviceID)); }; bool protocolLGS_SERVER::sendTarget(U16 Angle, U16 Azimuth, U16 Range){ - if( this ) { - U8 Buffer[16]; - Buffer[CMD_IDX] = CMD_TARGET; - Buffer[5] = ( Angle >> 8 ) & 0xFF; - Buffer[6] = Angle & 0xFF; - Buffer[7] = ( Azimuth >> 8 ) & 0xFF; - Buffer[8] = Azimuth & 0xFF; - Buffer[9] = ( Range >> 8 ) & 0xFF; - Buffer[10] = Range & 0xFF; + if( m_oDataTransport == NULL ) return false; + U8 Buffer[16]; + Buffer[CMD_IDX] = CMD_TARGET; + Buffer[5] = ( Angle >> 8 ) & 0xFF; + Buffer[6] = Angle & 0xFF; + Buffer[7] = ( Azimuth >> 8 ) & 0xFF; + Buffer[8] = Azimuth & 0xFF; + Buffer[9] = ( Range >> 8 ) & 0xFF; + Buffer[10] = Range & 0xFF; #ifndef SKIP_TARGET_LOG - #ifdef DEBUG - LOG("sendTarget"); - #endif + #ifdef DEBUG + LOG("sendTarget"); + #endif #endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 11, m_bDeviceID)); - }; - return false; + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 11, m_bDeviceID)); }; bool protocolLGS_SERVER::sendTargetW(U16 Angle, U16 Azimuth, U16 Range, U32 Width){ - if( this ) { - U8 Buffer[16]; - Buffer[CMD_IDX] = CMD_TARGET_WW; - Buffer[5] = ( Angle >> 8 ) & 0xFF; - Buffer[6] = Angle & 0xFF; - Buffer[7] = ( Azimuth >> 8 ) & 0xFF; - Buffer[8] = Azimuth & 0xFF; - Buffer[9] = ( Range >> 8 ) & 0xFF; - Buffer[10] = Range & 0xFF; - Buffer[11] = ( Width >> 24 ) & 0xFF; - Buffer[12] = ( Width >> 16 ) & 0xFF; - Buffer[13] = ( Width >> 8 ) & 0xFF; - Buffer[14] = Width & 0xFF; + if( m_oDataTransport == NULL ) return false; + U8 Buffer[16]; + Buffer[CMD_IDX] = CMD_TARGET_WW; + Buffer[5] = ( Angle >> 8 ) & 0xFF; + Buffer[6] = Angle & 0xFF; + Buffer[7] = ( Azimuth >> 8 ) & 0xFF; + Buffer[8] = Azimuth & 0xFF; + Buffer[9] = ( Range >> 8 ) & 0xFF; + Buffer[10] = Range & 0xFF; + Buffer[11] = ( Width >> 24 ) & 0xFF; + Buffer[12] = ( Width >> 16 ) & 0xFF; + Buffer[13] = ( Width >> 8 ) & 0xFF; + Buffer[14] = Width & 0xFF; #ifndef SKIP_TARGET_LOG -#ifdef DEBUG - LOG("sendTargetW"); -#endif + #ifdef DEBUG + LOG("sendTargetW"); + #endif #endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 15, m_bDeviceID)); - }; - return false; + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 15, m_bDeviceID)); }; bool protocolLGS_SERVER::sendTargetM( uint32_t SampleID, U8 Kernel, U16 Range, U32 Width, bool isBlack ){ - if (this) { - U8 Buffer[18]; - Buffer[CMD_IDX] = (isBlack) ? CMD_TARGET_MB : CMD_TARGET_MW; - Buffer[5] = (SampleID >> 24) & 0xFF; - Buffer[6] = (SampleID >> 16) & 0xFF; - Buffer[7] = (SampleID >> 8) & 0xFF; - Buffer[8] = SampleID & 0xFF; - Buffer[9] = Kernel; - Buffer[10] = (Range >> 8) & 0xFF; - Buffer[11] = Range & 0xFF; - Buffer[12] = (Width >> 24) & 0xFF; - Buffer[13] = (Width >> 16) & 0xFF; - Buffer[14] = (Width >> 8) & 0xFF; - Buffer[15] = Width & 0xFF; + if( m_oDataTransport == NULL ) return false; + U8 Buffer[18]; + Buffer[CMD_IDX] = (isBlack) ? CMD_TARGET_MB : CMD_TARGET_MW; + Buffer[5] = (SampleID >> 24) & 0xFF; + Buffer[6] = (SampleID >> 16) & 0xFF; + Buffer[7] = (SampleID >> 8) & 0xFF; + Buffer[8] = SampleID & 0xFF; + Buffer[9] = Kernel; + Buffer[10] = (Range >> 8) & 0xFF; + Buffer[11] = Range & 0xFF; + Buffer[12] = (Width >> 24) & 0xFF; + Buffer[13] = (Width >> 16) & 0xFF; + Buffer[14] = (Width >> 8) & 0xFF; + Buffer[15] = Width & 0xFF; #ifndef SKIP_TARGET_LOG -#ifdef DEBUG - LOG("sendTargetW"); -#endif + #ifdef DEBUG + LOG("sendTargetW"); + #endif #endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 16, m_bDeviceID)); - }; - return false; + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 16, m_bDeviceID)); }; bool protocolLGS_SERVER::sendTargetZ( TARGET_DATA *ptr ){ - if (this) { - U8 Buffer[256]; - uint8_t cnt; - Buffer[CMD_IDX] = CMD_TARGET_ZZ; - cnt = SUB_CMD_IDX; - for( int index = 0; index < sizeof(TARGET_DATA); index++ ){ - Buffer[cnt++] = ((uint8_t *)ptr )[index]; - }; + if( m_oDataTransport == NULL ) return false; + U8 Buffer[256]; + uint8_t cnt; + Buffer[CMD_IDX] = CMD_TARGET_ZZ; + cnt = SUB_CMD_IDX; + for( int index = 0; index < sizeof(TARGET_DATA); index++ ){ + Buffer[cnt++] = ((uint8_t *)ptr )[index]; + }; #ifndef SKIP_TARGET_LOG -#ifdef DEBUG - LOG("sendTargetZ"); -#endif + #ifdef DEBUG + LOG("sendTargetZ"); + #endif #endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, cnt, m_bDeviceID)); - }; - return false; + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, cnt, m_bDeviceID)); }; bool protocolLGS_SERVER::sendFlip(U16 Count){ - if( this ) { - U8 Buffer[16]; - Buffer[CMD_IDX] = CMD_FLIP_COMPLETE; - Buffer[5] = ( Count >> 8 ) & 0xFF; - Buffer[6] = Count & 0xFF; + if( m_oDataTransport == NULL ) return false; + U8 Buffer[16]; + Buffer[CMD_IDX] = CMD_FLIP_COMPLETE; + Buffer[5] = ( Count >> 8 ) & 0xFF; + Buffer[6] = Count & 0xFF; #ifdef DEBUG - LOG("sendFlip"); + LOG("sendFlip"); #endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 7, m_bDeviceID)); - }; - return false; + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 7, m_bDeviceID)); }; bool protocolLGS_SERVER::sendEvent(U8 Code){ - if( this ) { - U8 Buffer[16]; - Buffer[CMD_IDX] = CMD_EVT; - Buffer[SUB_CMD_IDX] = Code; + if( m_oDataTransport == NULL ) return false; + U8 Buffer[16]; + Buffer[CMD_IDX] = CMD_EVT; + Buffer[SUB_CMD_IDX] = Code; #ifdef DEBUG - LOG("sendEvent"); + LOG("sendEvent"); #endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 6, m_bDeviceID)); - }; - return false; + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 6, m_bDeviceID)); }; bool protocolLGS_SERVER::sendMode(U8 Mode){ - if( this ) { - U8 Buffer[16]; - Buffer[CMD_IDX] = CMD_MODE; - Buffer[SUB_CMD_IDX] = Mode | 0x80; + if( m_oDataTransport == NULL ) return false; + U8 Buffer[16]; + Buffer[CMD_IDX] = CMD_MODE; + Buffer[SUB_CMD_IDX] = Mode | 0x80; #ifdef DEBUG - LOG("sendMode"); + LOG("sendMode"); #endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 6, m_bDeviceID)); - }; - return false; + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 6, m_bDeviceID)); }; bool protocolLGS_SERVER::sendState(U8 State){ - if (this) { - U8 Buffer[256]; - U8 index; - Buffer[CMD_IDX] = CMD_STATE; - Buffer[SUB_CMD_IDX] = State; - index = DATA_BEGIN_IDX; + if( m_oDataTransport == NULL ) return false; + U8 Buffer[256]; + U8 index; + Buffer[CMD_IDX] = CMD_STATE; + Buffer[SUB_CMD_IDX] = State; + index = DATA_BEGIN_IDX; #if defined( __linux__ ) && !defined( __GUI__ ) - U8 *ptr; - ptr = (U8 *)&gsSOFT_INFO; - for( U8 i = 0; i < sizeof(SOFTWARE_INFO); i++ ) { - Buffer[index] = ptr[i]; - index++; - }; + U8 *ptr; + ptr = (U8 *)&gsSOFT_INFO; + for( U8 i = 0; i < sizeof(SOFTWARE_INFO); i++ ) { + Buffer[index] = ptr[i]; + index++; + }; #endif #ifdef DEBUG - LOG("sendState"); + LOG("sendState"); #endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage( Buffer, index, m_bDeviceID )); - }; - return false; + return m_oDataTransport->sendData(Buffer, FinishUpPackage( Buffer, index, m_bDeviceID )); }; bool protocolLGS_SERVER::sendScan(void){ - if (this) { - U8 Buffer[16]; - Buffer[CMD_IDX] = CMD_SCAN_COMPLETE; + if( m_oDataTransport == NULL ) return false; + U8 Buffer[16]; + Buffer[CMD_IDX] = CMD_SCAN_COMPLETE; #ifdef DEBUG - LOG("sendScan"); + LOG("sendScan"); #endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 5, m_bDeviceID)); - }; - return false; + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 5, m_bDeviceID)); }; bool protocolLGS_SERVER::sendState2(U8 State, U8 bTargetsCount, U8 *pTargetsData ){ - if (this) { - U8 Buffer[MAXIMAL_SOCKET_PACKET_LENGTH]; - Buffer[CMD_IDX] = CMD_STATE_2; - Buffer[SUB_CMD_IDX] = State; - Buffer[6] = bTargetsCount; - if( bTargetsCount == 0 ) { - #ifdef DEBUG - LOG("sendState2"); - #endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 7, m_bDeviceID)); - } else { - memcpy( &Buffer[7], pTargetsData, bTargetsCount*sizeof(CLIENT_EVENT)); - #ifdef DEBUG - LOG("sendState2+Targets"); - #endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 7 + bTargetsCount*sizeof(CLIENT_EVENT), m_bDeviceID)); - }; - }; - return false; + if( m_oDataTransport == NULL ) return false; + U8 Buffer[MAXIMAL_SOCKET_PACKET_LENGTH]; + Buffer[CMD_IDX] = CMD_STATE_2; + Buffer[SUB_CMD_IDX] = State; + Buffer[6] = bTargetsCount; + if( bTargetsCount == 0 ) { +#ifdef DEBUG + LOG("sendState2"); +#endif + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 7, m_bDeviceID)); + } else { + memcpy( &Buffer[7], pTargetsData, bTargetsCount*sizeof(CLIENT_EVENT)); +#ifdef DEBUG + LOG("sendState2+Targets"); +#endif + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 7 + bTargetsCount*sizeof(CLIENT_EVENT), m_bDeviceID)); + }; }; bool protocolLGS_SERVER::sendParameters(PLGS_PARAMETERS ptr){ - if( this ) { - if( ptr != NULL ) { - U8 counter; - U8 Buffer[128]; - Buffer[2] = m_bDeviceID; - Buffer[CMD_IDX] = CMD_PARAMETERS; - Buffer[SUB_CMD_IDX] = SUB_DATA_INTEGRITY_VALID; - counter = 6; - for( int i=0; i < sizeof( LGS_PARAMETERS ); i++ ){ - Buffer[counter] = *(((U8*)ptr)+i); - counter++; - }; -#ifdef DEBUG - LOG("sendParameters VALID"); -#endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, counter, m_bDeviceID)); - } else { - U8 Buffer[64]; - Buffer[2] = m_bDeviceID; - Buffer[CMD_IDX] = CMD_PARAMETERS; - Buffer[SUB_CMD_IDX] = SUB_DATA_INTEGRITY_ERROR; -#ifdef DEBUG - LOG("sendParameters EMPTY"); -#endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 6, m_bDeviceID)); - }; - }; - return false; + if( m_oDataTransport == NULL ) return false; + if( ptr != NULL ) { + U8 counter; + U8 Buffer[128]; + Buffer[2] = m_bDeviceID; + Buffer[CMD_IDX] = CMD_PARAMETERS; + Buffer[SUB_CMD_IDX] = SUB_DATA_INTEGRITY_VALID; + counter = 6; + for( int i=0; i < sizeof( LGS_PARAMETERS ); i++ ){ + Buffer[counter] = *(((U8*)ptr)+i); + counter++; + }; +#ifdef DEBUG + LOG("sendParameters VALID"); +#endif + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, counter, m_bDeviceID)); + } else { + U8 Buffer[64]; + Buffer[2] = m_bDeviceID; + Buffer[CMD_IDX] = CMD_PARAMETERS; + Buffer[SUB_CMD_IDX] = SUB_DATA_INTEGRITY_ERROR; +#ifdef DEBUG + LOG("sendParameters EMPTY"); +#endif + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 6, m_bDeviceID)); + }; }; bool protocolLGS_SERVER::sendShadowInfo( ShadowMask *ShObj ){ if( ShObj == NULL ) return false; - if( this ) { - U8 Buffer[16]; - Buffer[2] = m_bDeviceID; - Buffer[CMD_IDX] = CMD_HZ_INFO; - Buffer[SUB_CMD_IDX] = ShObj->isActive() ? 0xFF : 0x00; - Buffer[6] = ShObj->getPolyCount(); + if( m_oDataTransport == NULL ) return false; + U8 Buffer[16]; + Buffer[2] = m_bDeviceID; + Buffer[CMD_IDX] = CMD_HZ_INFO; + Buffer[SUB_CMD_IDX] = ShObj->isActive() ? 0xFF : 0x00; + Buffer[6] = ShObj->getPolyCount(); #ifdef DEBUG - LOG("sendShadowInfo"); + LOG("sendShadowInfo"); #endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 7, m_bDeviceID ) ); - }; - return false; + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 7, m_bDeviceID ) ); }; bool protocolLGS_SERVER::sendSetPolyACK(uint8_t id){ - if (this) { - U8 Buffer[16]; - Buffer[2] = m_bDeviceID; - Buffer[CMD_IDX] = CMD_SET_HZ_POLY_ACK; - Buffer[5] = id; + if( m_oDataTransport == NULL ) return false; + U8 Buffer[16]; + Buffer[2] = m_bDeviceID; + Buffer[CMD_IDX] = CMD_SET_HZ_POLY_ACK; + Buffer[5] = id; #ifdef DEBUG - LOG("sendSetPolyACK"); + LOG("sendSetPolyACK"); #endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 6, m_bDeviceID)); - }; - return false; + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 6, m_bDeviceID)); }; bool protocolLGS_SERVER::sendShadowStatus( bool Status, uint8_t ShadowID ){ - if( this ) { - U8 Buffer[16]; - Buffer[2] = m_bDeviceID; - Buffer[CMD_IDX] = CMD_SET_HZ_STATUS; - Buffer[SUB_CMD_IDX] = ShadowID; - Buffer[6] = (uint8_t) Status; + if( m_oDataTransport == NULL ) return false; + U8 Buffer[16]; + Buffer[2] = m_bDeviceID; + Buffer[CMD_IDX] = CMD_SET_HZ_STATUS; + Buffer[SUB_CMD_IDX] = ShadowID; + Buffer[6] = (uint8_t) Status; #ifdef DEBUG - LOG("sendShadowStatus"); + LOG("sendShadowStatus"); #endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 7, m_bDeviceID ) ); - }; - return false; + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 7, m_bDeviceID ) ); }; bool protocolLGS_SERVER::sendShadowPoly( simplePolygone *SP ){ if( SP == NULL ) return false; - if( this ) { - U8 counter; - U8 Buffer[PROTOCOL_PARSER_BUFFER_SIZE]; - Buffer[2] = m_bDeviceID; - Buffer[CMD_IDX] = CMD_SET_HZ_POLY; - Buffer[SUB_CMD_IDX] = SP->count; - Buffer[SUB_CMD_IDX+1] = SP->color[0]; - Buffer[SUB_CMD_IDX+2] = SP->color[1]; - Buffer[SUB_CMD_IDX+3] = SP->color[2]; - counter = SUB_CMD_IDX+4; - for( uint8_t i = 0; i < SP->count; i++ ){ - uint16_t x,y; - x = SP->points[i].x(); - y = SP->points[i].y(); - Buffer[counter++] = ( x >> 8 ) & 0xFF; - Buffer[counter++] = x & 0xFF; - Buffer[counter++] = ( y >> 8 ) & 0xFF; - Buffer[counter++] = y & 0xFF; - }; -#ifdef DEBUG - LOG("sendShadowPoly"); -#endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, counter, m_bDeviceID ) ); - }; - return false; + if( m_oDataTransport == NULL ) return false; + U8 counter; + U8 Buffer[PROTOCOL_PARSER_BUFFER_SIZE]; + Buffer[2] = m_bDeviceID; + Buffer[CMD_IDX] = CMD_SET_HZ_POLY; + Buffer[SUB_CMD_IDX] = SP->count; + Buffer[SUB_CMD_IDX+1] = SP->color[0]; + Buffer[SUB_CMD_IDX+2] = SP->color[1]; + Buffer[SUB_CMD_IDX+3] = SP->color[2]; + counter = SUB_CMD_IDX+4; + for( uint8_t i = 0; i < SP->count; i++ ){ + uint16_t x,y; + x = SP->points[i].x(); + y = SP->points[i].y(); + Buffer[counter++] = ( x >> 8 ) & 0xFF; + Buffer[counter++] = x & 0xFF; + Buffer[counter++] = ( y >> 8 ) & 0xFF; + Buffer[counter++] = y & 0xFF; + }; +#ifdef DEBUG + LOG("sendShadowPoly"); +#endif + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, counter, m_bDeviceID ) ); }; bool protocolLGS_SERVER::sendResetACK( void ){ - if( this ) { - U8 Buffer[16]; - Buffer[CMD_IDX] = CMD_RESET; + if( m_oDataTransport == NULL ) return false; + U8 Buffer[16]; + Buffer[CMD_IDX] = CMD_RESET; #ifdef DEBUG - LOG("sendResetACK"); + LOG("sendResetACK"); #endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 5, m_bDeviceID ) ); - }; - return false; + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 5, m_bDeviceID ) ); }; bool protocolLGS_SERVER::sendFullResetACK( void ){ - if( this ) { - U8 Buffer[16]; - Buffer[CMD_IDX] = CMD_RESET; + if( m_oDataTransport == NULL ) return false; + U8 Buffer[16]; + Buffer[CMD_IDX] = CMD_RESET; #ifdef DEBUG - LOG("sendFullResetACK"); + LOG("sendFullResetACK"); #endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 5, m_bDeviceID ) ); - }; - return false; + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 5, m_bDeviceID ) ); }; bool protocolLGS_SERVER::sendGenericACK(bool Status){ - if (this) { - U8 Buffer[16]; - Buffer[CMD_IDX] = (Status)?CMD_ACK:CMD_NACK; + if( m_oDataTransport == NULL ) return false; + U8 Buffer[16]; + Buffer[CMD_IDX] = (Status)?CMD_ACK:CMD_NACK; #ifdef DEBUG - LOG("sendGenerickACK"); + LOG("sendGenerickACK"); #endif - return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 5, m_bDeviceID)); - }; - return false; + return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 5, m_bDeviceID)); }; #undef LOG diff --git a/lib/data/protocol/protocolLGS.h b/lib/data/protocol/protocolLGS.h index 73106e45..7be77d18 100644 --- a/lib/data/protocol/protocolLGS.h +++ b/lib/data/protocol/protocolLGS.h @@ -1,809 +1,10 @@ -#ifndef __PROTOCOL_LGS_HEADERS__ -#define __PROTOCOL_LGS_HEADERS__ +#ifndef __PROTOCOL_LGS_3D_HEADERS__ +#define __PROTOCOL_LGS_3D_HEADERS__ -#include "../../components/base/basicFunctionality.h" -#include "../../components/base/basicTransport.h" -#include "../../components/base/basicMutex.h" -#include "../../components/base/basicEventHeap.h" -#include "../../hardware/soc/general/3DLRF.h" -#include "../../alg/lgs/mask.h" -#include "protocol.h" +#include "protocolLGSm.h" -#define TARGET_WITH_WIDTH -#define MAXIMAL_SOCKET_PACKET_LENGTH 102400 -#define BOARDDATA_PACKAGE_SIZE_BYTES 0x4000 -#define BOARDDATA_PACKAGE_SIZE_NODES 0x1000 -/* -typedef struct S_LGS_PARAMETERS{ - uint8_t nOrder; - uint8_t nOffset; - uint8_t nDelta; - uint8_t nSun; - uint8_t bSST; - uint16_t nFlip; // For Quick models (pls30) must be up to 1024 - uint32_t nWidth; // With future devices may gain big numbers - // 3D LRF Specific - uint8_t bBuildThByCore; - uint8_t nGPointSamples; -} LGS_PARAMETERS, *PLGS_PARAMETERS; -*/ - -typedef enum{ - STG_DISCONNECTED = 0x00, - STG_CONNECTED = 0x01, - STG_STUDY = 0x02, - STG_REDY = 0x04, - STG_BUSY = 0x06, - STG_NONE = 0xFF -}E_LGS_STAGE; - -typedef enum{ - CWM_INIT = 0, - CWM_PINGPONG = 1, - CWM_BORDER = 2, - CWM_FILE = 3, - CWM_MASK = 4, - CWM_PARAMS = 5, - CWM_INITIAL_PARAM = 252, - CWM_INITIAL_MASKS_INFO = 253, - CWM_INITIAL_MASKS_DATA = 254, - CWM_ERROR = 255 -} E_CLIENT_WORK_MODE; - -typedef enum{ - SUB_DATA_INTEGRITY_UNKNOWN = 0x00, - SUB_DATA_INTEGRITY_ERROR = 0xA5, - SUB_DATA_INTEGRITY_VALID = 0xFF -}E_LGS_DATA_INTEGRITY_FLAG; - -// commands -typedef enum{ - CMD_STATE = 0x00, - CMD_QUIT = 0x01, - CMD_RESET = 0x02, - CMD_BORDER = 0x03, - CMD_MODE = 0x04, - CMD_GETFILE = 0x05, - CMD_RESTART = 0x06, - CMD_PARAMETERS = 0x07, - CMD_GET_SERIAL_NUMBER = 0x08, - CMD_SET_ADDRESS = 0x09, - CMD_GET_SOFTWARE_VERSION = 0x0A, - CMD_UNSUPPORTED = 0x0B, - CMD_SET_COMM_SPEED = 0x0C, - CMD_FULL_BORDER = 0x0D, - CMD_FULL_RESET = 0x0E, - CMD_CAMERA = 0x0F, - CMD_SET_SERIAL_NUMBER = 0x10, - CMD_BOARDDATA = 0x11, - CMD_GET_CAMERA_PARAMETERS = 0x12, - CMD_SET_CAMERA_PARAMETERS = 0x13, - CMD_RELAY = 0x14, - CMD_GET_RELAY_PARAMETERS = 0x15, - CMD_SET_RELAY_PARAMETERS = 0x16, - CMD_FS_SUB_PACKET = 0x17, - CMD_STATE_2 = 0x18, - CMD_GET_WIDTH_TABLE = 0x19, - CMD_SET_WIDTH_TABLE = 0x1A, - CMD_GET_VOLTAGE = 0x1B, - CMD_GET_VOLTAGE_PARAMETERS = 0x1C, - CMD_SET_VOLTAGE_PARAMETERS = 0x1D, - CMD_GET_HZ_DATA = 0x1E, - CMD_SET_HZ_DATA = 0x1F, - CMD_GET_CALIBRATION_TABLE = 0x20, - CMD_SET_CALIBRATION_TABLE = 0x21, - CMD_GET_LRF_DISABLE = 0x22, - CMD_SET_LRF_DISABLE = 0x23, - CMD_GET_ZOOM_TABLE = 0x24, - CMD_SET_ZOOM_TABLE = 0x25, - CMD_GET_TILT_TABLE = 0x26, - CMD_SET_TILT_TABLE = 0x27, - CMD_GET_HZ_ENABLE = 0x28, - CMD_SET_HZ_ENABLE = 0x29, - CMD_EVT = 0x2A, - CMD_GET_PARAMETERS = 0x2B, - CMD_SET_PARAMETERS = 0x2C, - CMD_FLIP_COMPLETE = 0x2D, - CMD_SCAN_COMPLETE = 0x2E, - CMD_TARGET = 0x2F, - CMD_TARGET_WW = 0x30, - CMD_TARGET_MW = 0x31, - CMD_TARGET_MB = 0x32, - CMD_TARGET_ZZ = 0x33, - CMD_GET_HZ_INFO = 0x34, - CMD_HZ_INFO = 0x35, - CMD_GET_HZ_POLY = 0x36, - CMD_SET_HZ_POLY = 0x37, - CMD_SET_HZ_POLY_ACK = 0x38, - CMD_GET_HZ_STATUS = 0x39, - CMD_SET_HZ_STATUS = 0x3A, - - CMD_DHWM_START_MOTORS = 0x50, - CMD_DHWM_STOP_MOTORS = 0x51, - CMD_ACK = 0xFA, - CMD_NACK = 0xFB, - CMD_NONE = 0xFF -} E_LGS_CMD; - -// modes -enum{ - MODE_SET = 0x80, // 10000000 set/get mode - MODE_MASK = 0x0F, // 00001111 mode mask - MODE_DETECTOR = 0x01, // 00000001 detecting mode - default - MODE_BORDER = 0x02, // 00000010 border of visibilite draw mode - MODE_FILESYSTEM = 0x03, // 00000011 remote file system server mode - MODE_GETFILE = 0x04, // 00000100 get file mode - MODE_SENDBOARDDATA1 = 0x05, // 00000101 send board data for external processing - MODE_SENDBOARDDATA2 = 0x06, // 00000110 send board data for external processing - MODE_BOARDDATA = 0x07 // 00000111 board data for external processing -}; - -// --------------- CMD_STATE ---------------------- -// information type -enum{ - IT_MASK = 0x80, // 10000000 - IT_ERROR = 0x00, // 00000000 - IT_TARGET = 0x80 // 10000000 -}; - -// device id -enum{ - ID_MASK = 0x40, // 01000000 - ID_DEVICE0 = 0x00, // 00000000 - ID_DEVICE1 = 0x40 // 01000000 -}; - -// target type -enum{ - TT_MASK = 0x3C, // 00111100 - TT_NORMAL = 0x00, // 00000000 - TT_WIDE = 0x04, // 00000100 - TT_FLIP = 0x08, // 00001000 - TT_CAMERA = 0x0C, // 00001100 - TT_TEST = 0x10, // 00010000 - TT_BLIND = 0x14 // 00010100 -}; - -// target data -enum{ - TD_MASK = 0x03, // 00000011 - TD_ANGLE = 0x02, // 00000010 - TD_RANGE = 0x01 // 00000001 -}; - -// errors -enum{ - ER_MASK = 0x3F, // 00111111 - ER_NONE = 0x00, // 00000000 - ER_ANGLE = 0x01, // 00000001 - ER_SUNBIT = 0x02, // 00000010 - ER_OVERFLOW = 0x04, // 00000100 - ER_SSTOVERFLOW = 0x08, // 00001000 - ER_MODE = 0x10, // 00010000 - ER_NOIRQ = 0x20 // 00100000 -}; - -// --------------- CMD_BORDER ---------------------- -enum{ - BD_ERRORMASK = 0xE0, // 11100000 - BD_ERRORMODE = 0x80, // 10000000 - BD_ERRORANGLE = 0x40, // 01000000 - BD_NOTREADY = 0x20, // 00100000 - BD_ANGLEMASK = 0x10, // 00010000 - BD_RANGE0MASK = 0x0C, // 00001100 - BD_RANGE1MASK = 0x03, // 00000011 -}; -// --------------- CMD_FILE ------------------ -enum{ - GF_ERRORMASK = 0xC0, // 11000000 - GF_ERRORMODE = 0x80, // 10000000 - GF_ERRORFILE = 0x40, // 01000000 - GF_OP_INDEX = 0x3C, // 00111100 - GF_OP_MASK = 0x03, // 00000011 - GF_OP_OK = 0x00, // 00000000 - GF_OP_OPEN = 0x01, // 00000001 - GF_OP_DATA = 0x02, // 00000010 - GF_OP_CLOSE = 0x03, // 00000011 -}; -// --------------- CMD_PARAMETERS ------------------ -enum{ - DP_OP_MASK = 0x80, - DP_OP_GET = 0x00, - DP_OP_SET = 0x80, - DP_DEVICE_MASK = 0x40, - DP_DEVICE_0 = 0x00, - DP_DEVICE_1 = 0x40, - DP_SST = 0x01, -}; - -enum{ - FB_READY_MASK = 0x80, // 10000000 - FB_READY = 0x80, // 10000000 - FB_NOT_READY = 0x00, // 10000000 - FB_ANGLE_MASK = 0x1F, // 00011111 - FB_RANGE_MASK = 0xF00, // 00011111 - FB_RANGE_1_SHIFT = 4, // 11110000 - FB_RANGE_2_SHIFT = 8, // 00001111 -}; - -// --------------- CMD_CAMERA ------------------ -/* -typedef enum{ - CMD_CAMERA_GET_STATUS = 0, - CMD_CAMERA_GET_PTZ = 1, - CMD_CAMERA_SET_PTZ = 2, - CMD_CAMERA_MOVE_PAN = 3, - CMD_CAMERA_MOVE_TILT = 4, - CMD_CAMERA_MOVE_ZOOM = 5, - CMD_CAMERA_SET_IRIS = 6, - CMD_CAMERA_BUSY = 7, - CMD_CAMERA_ERROR = 8, - CMD_CAMERA_WIPER = 9, - CMD_CAMERA_SET_FOCUS = 10, - CMD_CAMERA_GET_FOCUS = 11, - CMD_CAMERA_MOVE_FOCUS = 12, - CMD_CAMERA_GET_DOPLER = 13, - CMD_CAMERA_SET_DOPLER = 14, - CMD_CAMERA_DOPLER_ALARM = 15, - CMD_CAMERA_GET_DOPLER_MASK = 16, - CMD_CAMERA_SET_DOPLER_MASK = 17, -}E_CAMERA_CMD; -*/ - -enum{ - CAMERA_ERROR_NO_CAMERA = 0 -}; - -enum{ - CAMERA_MAX_DOPLER_MASK = 8 -}; - -typedef struct CAMERA_POS_PTZ{ - U16 posPan; - U16 posTilt; - U16 posZoom; -}CAMERA_POS_PTZ; - -typedef struct CAMERA_MOVE_PAN{ - U16 panSpeed; - U8 panRight; -}CAMERA_MOVE_PAN; - -typedef struct CAMERA_MOVE_TILT{ - U16 tiltSpeed; - U8 tiltUp; -}CAMERA_MOVE_TILT; - -typedef struct CAMERA_MOVE_ZOOM{ - U16 zoomSpeed; - U8 zoomTele; -}CAMERA_MOVE_ZOOM; - -typedef struct CAMERA_MOVE_FOCUS{ - U16 focusSpeed; - U8 focusFar; -}CAMERA_MOVE_FOCUS; - -typedef struct CAMERA_POS_IRIS{ - U16 irisValue; -}CAMERA_POS_IRIS; - -typedef struct CAMERA_POS_FOCUS{ - U16 focusValue; -}CAMERA_POS_FOCUS; - -typedef struct CAMERA_BUSY{ - U8 busyCommand; -}CAMERA_BUSY; - -typedef struct CAMERA_ERROR{ - U16 errID; -}CAMERA_ERROR; - -typedef struct CAMERA_WIPER{ - U8 wiperOn; -}CAMERA_WIPER; - -typedef struct CAMERA_DOPLER{ - U8 doplerOn; - U16 doplerPanStep; - U32 doplerTimeout; -}CAMERA_DOPLER; - -typedef struct CAMERA_DOPLER_ALARM{ - U8 doplerAlarm; - U16 doplerPan; -}CAMERA_DOPLER_ALARM; - -typedef struct CAMERA_DOPLER_MASK{ - U16 nStart; - U16 nStop; -}CAMERA_DOPLER_MASK; - -typedef struct CAMERA_DOPLER_MASK_ARRAY{ - U8 bEnabled; - U8 nCount; - CAMERA_DOPLER_MASK pMask[CAMERA_MAX_DOPLER_MASK]; -}CAMERA_DOPLER_MASK_ARRAY; - -typedef struct CAMERA_DATA{ - U8 nCommand; - union { - CAMERA_POS_PTZ posPTZ; - CAMERA_MOVE_PAN movePan; - CAMERA_MOVE_TILT moveTilt; - CAMERA_MOVE_ZOOM moveZoom; - CAMERA_POS_IRIS posIris; - CAMERA_BUSY busy; - CAMERA_ERROR error; - CAMERA_WIPER wiper; - CAMERA_POS_FOCUS posFocus; - CAMERA_MOVE_FOCUS moveFocus; - CAMERA_DOPLER dopler; - CAMERA_DOPLER_ALARM doplerAlarm; - CAMERA_DOPLER_MASK_ARRAY doplerMask; - }; -} CAMERA_DATA, *PCAMERA_DATA; - -// --------------- CMD_GET_CAMERA_PARAMETERS / CMD_SET_CAMERA_PARAMETERS ------------------ -typedef enum{ - CAMERA_TYPE_MIGVAN_878 = 0x00, - CAMERA_TYPE_MIGVAN_KD6Z = 0x01, - CAMERA_TYPE_MIC1300 = 0x02, - CAMERA_TYPE_JVC_TKS576 = 0x03, - CAMERA_TYPE_PHILIPS_G3AD_NEW= 0x04, - CAMERA_TYPE_VICON = 0x05, - CAMERA_TYPE_PELCO = 0x06, - CAMERA_TYPE_HEBRON = 0x07, - CAMERA_TYPE_3_TRACK = 0x08, - CAMERA_TYPE_AMERICAN_DYNAMICS = 0x09, - CAMERA_TYPE_PHILIPS_G3AD_OLD= 0x0A, - CAMERA_TYPE_NESHER = 0x0B, - CAMERA_TYPE_NONE = 0xFF, -}E_CAMERA_TYPE; - -// ------------------------------------ CMD_RELAY --------------------------------------- -typedef enum{ - CMD_RELAY_GET = 0, - CMD_RELAY_SET = 1, -}E_RELAY_CMD; - -typedef struct RELAY_DATA{ - U8 nCommand; - U8 bOutput; -}RELAY_DATA, *PRELAY_DATA; - -typedef struct RELAY_PARAMETERS{ - U8 bAuto; // allow auto relay - U8 bNormallyClose; - U16 nAutoDelay; // in 0.1 sec (0,0 .. 3000,0 sec) -}RELAY_PARAMETERS, *PRELAY_PARAMETERS; - -// --------------- CMD_STATE_2 ------------------------ -typedef enum S2_INFO_TYPE{ - S2_IT_TARGET_POLAR = 0, - S2_IT_TARGET_DEKART = 1, - S2_IT_FLAGS = 2, - S2_IT_DEVICE_FLAGS = 3, - S2_IT_ERROR_ANGLE = 4, - S2_IT_FLIP = 5, - S2_IT_BLIND = 6, - S2_IT_TARGET_POLAR_WIDTH = 7, // SERGEY 2008/05/02 - S2_IT_TARGET_DEKART_WIDTH = 8 // SERGEY 2008/05/02 -}S2_INFO_TYPE; - -typedef enum S2_INFO_TYPE_FLAGS{ - S2_ITF_ERROR_MODE = 0x01, - S2_ITF_ERROR_NO_IRQ = 0x02, - S2_ITF_ERROR_NO_ZERO_MARK = 0x04, - S2_ITF_CAMERA = 0x08, - S2_ITF_VOLTAGE = 0x10, -}S2_INFO_TYPE_FLAGS; - -typedef enum S2_INFO_TYPE_DEVICE_FLAGS{ - S2_ITDF_ERROR_SUN = 0x01, - S2_ITDF_ERROR_OVERFLOW = 0x02, - S2_ITDF_ERROR_SST_OVERFLOW = 0x04, -}S2_INFO_TYPE_DEVICE_FLAGS; - -typedef enum S2_INFO_TYPE_TARGET{ - S2_ITT_NORMAL = 0x00, - S2_ITT_WIDE = 0x10, - S2_ITT_TYPE_MASK = 0xF0, - S2_ITT_DEVICE_MASK = 0x0F, -}S2_INFO_TYPE_TARGET; - -typedef enum S2_INFO_TYPE_BLIND{ - S2_ITB_STATE_MASK = 0x80, - S2_ITB_START = 0x00, - S2_ITB_STOP = 0x80, - S2_ITB_REASON_MASK = 0x7F, - S2_ITB_MEDIUM_RANGE = 0x01, - S2_ITB_180_DEGREE = 0x02, - S2_ITB_FOG_SPIKES = 0x03, - S2_ITB_PD = 0x04, -}S2_INFO_TYPE_BLIND; - -typedef enum S2_REQUEST_TYPE{ - S2_RT_TARGET_MASK = 0x01, - S2_RT_TARGET_POLAR = 0x00, - S2_RT_TARGET_DEKART = 0x01, -}S2_REQUEST_TYPE; - -typedef enum S2_REQUEST_WIDTH{ - S2_RW_MASK = 0x02, - S2_RW_DISABLE = 0x00, - S2_RW_ENABLE = 0x02, -}S2_REQUEST_WIDTH; - -typedef struct S_S2_PACKAGE{ - uint32_t aaa; -}S2_PACKAGE; - -// --------------- CMD_INFO ------------ - - - -// --------------- CMD_FS_SUB_PACKET ------------------ -enum{ - FS_CMD_SEND_CMD = 0, - FS_CMD_SEND_EVT = 1, - FS_CMD_RECEIVE_CMD = 2, - FS_CMD_RECEIVE_EVT = 3, - - FS_ERROR_SUCCESS = 0x00, // 00000000 - FS_ERROR_MODE = 0x01, // 00000001 -}; - -typedef struct FS_SEND_CMD{ - U8 nOrder; - U8 nLast; - U16 nPosition; - U8 nSubSize; - U8 pSubBuffer[1]; -}FS_SEND_CMD; - -typedef struct FS_SEND_EVT{ - U8 nError; - U8 nOrder; -}FS_SEND_EVT; - -typedef struct FS_RECEIVE_CMD{ - U8 nOrder; - U16 nPosition; -}FS_RECEIVE_CMD; - -typedef struct FS_RECEIVE_EVT{ - U8 nError; - U8 nOrder; - U8 nLast; - U16 nPosition; - U8 nSubSize; - U8 pSubBuffer[1]; -}FS_RECEIVE_EVT; - -typedef struct FS_DATA{ - U8 nCommand; - union { - FS_SEND_CMD sendcmd; - FS_SEND_EVT sendevt; - FS_RECEIVE_CMD receivecmd; - FS_RECEIVE_EVT receiveevt; - }; -}FS_DATA, *PFS_DATA; - -typedef struct FS_DATA_EX : public FS_DATA { - U8 pReserved[MAX_PATH]; -}FS_DATA_EX, *PFS_DATA_EX; - -// --------------- CMD_GET_WIDTH_TABLE & CMD_SET_WIDTH_TABLE ------------------------ -enum { WIDTH_TABLE_SIZE = 16 }; - -typedef struct WIDTH_TABLE{ - U8 nCount; - U16 pTable[WIDTH_TABLE_SIZE]; -}WIDTH_TABLE, *PWIDTH_TABLE; - -// --------------- CMD_VOLTAGE ------------------ -typedef enum VOLTAGE_STATUS{ - VS_OK = 0, - VS_FAILURE = 1, -}VOLTAGE_STATUS; - -// --------------- CMD_GET_VOLTAGE_PARAMETERS / CMD_SET_VOLTAGE_PARAMETERS ------------------ -typedef struct VOLTAGE_PARAMETERS{ - U8 bControl; -}VOLTAGE_PARAMETERS, *PVOLTAGE_PARAMETERS; - -// -------------- CMD_HZ_GET_DATA / CMD_HZ_SET_DATA ----------------------------- -typedef enum HZ_INFO_TYPE{ - HZIT_CMD_GET_HEADER = 0, - HZIT_EVT_GET_HEADER = 1, - HZIT_CMD_GET_POLYGON = 2, - HZIT_EVT_GET_POLYGON = 3, - HZIT_CMD_GET_POLYGON_POINT = 4, - HZIT_EVT_GET_POLYGON_POINT = 5, - HZIT_CMD_GET_RAY = 6, - HZIT_EVT_GET_RAY = 7, - HZIT_CMD_GET_RAY_LINE = 8, - HZIT_EVT_GET_RAY_LINE = 9, - HZIT_CMD_SET_HEADER = 10, - HZIT_EVT_SET_HEADER = 11, - HZIT_CMD_SET_POLYGON = 12, - HZIT_EVT_SET_POLYGON = 13, - HZIT_CMD_SET_POLYGON_POINT = 14, - HZIT_EVT_SET_POLYGON_POINT = 15, - HZIT_CMD_SET_RAY = 16, - HZIT_EVT_SET_RAY = 17, - HZIT_CMD_SET_RAY_LINE = 18, - HZIT_EVT_SET_RAY_LINE = 19, - HZIT_CMD_SET_DONE = 20, - HZIT_EVT_SET_DONE = 21, - HZIT_EVT_ERROR = 255, -}HZ_INFO_TYPE; - -typedef struct HZ_POINT{ - U16 wX; // 0..4095 - U16 wY; // 0..4095 -}HZ_POINT, *LPHZ_POINT; - -typedef struct HZ_LINE{ - U8 bType; // region type - U16 wMin; // 0..2047 - U16 wMax; // 0..2047 -}HZ_LINE, *LPHZ_LINE; - -typedef struct HZ_PACKET{ - U8 bSubSize; - U8 bType; - U8 bSequence; -}HZ_PACKET, *PHZ_PACKET; - -// --------- CMD_HZ_GET_DATA ----------- -typedef HZ_PACKET HZ_CMD_GET_HEADER, *PHZ_CMD_GET_HEADER; -typedef struct HZ_EVT_GET_HEADER : public HZ_PACKET{ - U16 wPolygonCount; - U16 wRayCount; - U32 dwTypeOn; -}HZ_EVT_GET_HEADER, *PHZ_EVT_GET_HEADER; - -typedef struct HZ_CMD_GET_POLYGON : public HZ_PACKET{ - U16 wPolygonIndex; -}HZ_CMD_GET_POLYGON, *PHZ_CMD_GET_POLYGON; - -typedef struct HZ_EVT_GET_POLYGON : public HZ_PACKET{ - U8 bPolygonType; - U16 wPointCount; -}HZ_EVT_GET_POLYGON, *PHZ_EVT_GET_POLYGON; - -typedef struct HZ_CMD_GET_POLYGON_POINT : public HZ_PACKET{ - U16 wPolygonIndex; - U16 wPointIndex; -}HZ_CMD_GET_POLYGON_POINT, *PHZ_CMD_GET_POLYGON_POINT; - -typedef struct HZ_EVT_GET_POLYGON_POINT : public HZ_PACKET{ - HZ_POINT Point; -}HZ_EVT_GET_POLYGON_POINT, *PHZ_EVT_GET_POLYGON_POINT; - -typedef struct HZ_CMD_GET_RAY : public HZ_PACKET{ - U16 wRayIndex; -}HZ_CMD_GET_RAY, *PHZ_CMD_GET_RAY; - -typedef struct HZ_EVT_GET_RAY : public HZ_PACKET{ - U16 wLineCount; -}HZ_EVT_GET_RAY, *PHZ_EVT_GET_RAY; - -typedef struct HZ_CMD_GET_RAY_LINE : public HZ_PACKET{ - U16 wRayIndex; - U16 wLineIndex; -}HZ_CMD_GET_RAY_LINE, *PHZ_CMD_GET_RAY_LINE; - -typedef struct HZ_EVT_GET_RAY_LINE : public HZ_PACKET{ - HZ_LINE Line; -}HZ_EVT_GET_RAY_LINE, *PHZ_EVT_GET_RAY_LINE; - -// ----------- CMD_HZ_SET_DATA -------------- -typedef struct HZ_CMD_SET_HEADER : public HZ_PACKET{ - U16 wPolygonCount; - U16 wRayCount; - U32 dwTypeOn; -}HZ_CMD_SET_HEADER, *PHZ_CMD_SET_HEADER; - -typedef HZ_PACKET HZ_EVT_SET_HEADER, *PHZ_EVT_SET_HEADER; - -typedef struct HZ_CMD_SET_POLYGON : public HZ_PACKET{ - U16 wPolygonIndex; - U8 bPolygonType; - U16 wPointCount; -}HZ_CMD_SET_POLYGON, *PHZ_CMD_SET_POLYGON; - -typedef HZ_PACKET HZ_EVT_SET_POLYGON, *PHZ_EVT_SET_POLYGON; - -typedef struct HZ_CMD_SET_POLYGON_POINT : public HZ_PACKET{ - U16 wPolygonIndex; - U16 wPointIndex; - HZ_POINT Point; -}HZ_CMD_SET_POLYGON_POINT, *PHZ_CMD_SET_POLYGON_POINT; - -typedef HZ_PACKET HZ_EVT_SET_POLYGON_POINT, *PHZ_EVT_SET_POLYGON_POINT; - -typedef struct HZ_CMD_SET_RAY : public HZ_PACKET{ - U16 wRayIndex; - U16 wLineCount; -}HZ_CMD_SET_RAY, *PHZ_CMD_SET_RAY; - -typedef HZ_PACKET HZ_EVT_SET_RAY, *PHZ_EVT_SET_RAY; - -typedef struct HZ_CMD_SET_RAY_LINE : public HZ_PACKET{ - U16 wRayIndex; - U16 wLineIndex; - HZ_LINE Line; -}HZ_CMD_SET_RAY_LINE, *PHZ_CMD_SET_RAY_LINE; - -typedef HZ_PACKET HZ_EVT_SET_RAY_LINE, *PHZ_EVT_SET_RAY_LINE; - -typedef HZ_PACKET HZ_CMD_SET_DONE, *PHZ_CMD_SET_DONE; - -typedef HZ_PACKET HZ_EVT_SET_DONE, *PHZ_EVT_SET_DONE; - -// ----------- CMD_HZ_GET_DATA / CMD_HZ_SET_DATA -------------- -enum{ - HZER_NONE = 0, - HZER_OUT_OF_MEMORY = 1, - HZER_RAY_COUNT = 2, - HZER_RAY_INDEX = 3, - HZER_RAY_LINE_INDEX = 4, - HZER_POLYGON_INDEX = 5, - HZER_POLYGON_POINT_INDEX = 6, -}; - -typedef struct HZ_EVT_ERROR : public HZ_PACKET{ - U8 bCmdType; - U8 bErrorId; -}HZ_EVT_ERROR, *PHZ_EVT_ERROR; - - -// ----------- CMD_GET_CT_TABLE / CMD_SET_CT_TABLE -------------- -enum{ - CIT_NONE = 0, - - CIT_CMD_SET_HEADER = 1, - CIT_EVT_SET_HEADER = 2, - CIT_EVT_SET_ITEM = 3, - CIT_CMD_SET_ITEM = 4, - CIT_CMD_SET_DONE = 5, - CIT_EVT_SET_DONE = 6, - - CIT_CMD_GET_HEADER = 7, - CIT_EVT_GET_HEADER = 8, - CIT_CMD_GET_ITEM = 9, - CIT_EVT_GET_ITEM = 10, - - CIT_EVT_ERROR = 255, -}; - -enum{ - CER_NONE = 0, - CER_OUT_OF_MEMORY = 1, - CER_INDEX = 2, -}; - -typedef struct CT_PACKET{ - U8 bSize; - U8 bType; - U8 bSequence; -}CT_PACKET, *PCT_PACKET; - -// error -typedef struct CT_ERROR_EVT : public CT_PACKET{ - U8 bCmdType; - U8 bErrorId; -}CT_ERROR_EVT, *PCT_ERROR_EVT; - - -// set header -typedef struct CT_SET_HEADER_CMD : public CT_PACKET{ - U8 bCount; -}CT_SET_HEADER_CMD, *PCT_SET_HEADER_CMD; - -typedef struct CT_SET_HEADER_EVT : public CT_PACKET{ -}CT_SET_HEADER_EVT, *PCT_SET_HEADER_EVT; - -// set item -typedef struct CT_SET_ITEM_CMD : public CT_PACKET{ - U8 bIndex; - U16 wReal; - U16 wA2D; -}CT_SET_ITEM_CMD, *PCT_SET_ITEM_CMD; - -typedef struct CT_SET_ITEM_EVT : public CT_PACKET{ -}CT_SET_ITEM_EVT, *PCT_SET_ITEM_EVT; - -// set done -typedef struct CT_SET_DONE_CMD : public CT_PACKET{ -}CT_SET_DONE_CMD, *PCT_SET_DONE_CMD; - -typedef struct CT_SET_DONE_EVT : public CT_PACKET{ -}CT_SET_DONE_EVT, *PCT_SET_DONE_EVT; - -// get header -typedef struct CT_GET_HEADER_CMD : public CT_PACKET{ -}CT_GET_HEADER_CMD, *PCT_GET_HEADER_CMD; - -typedef struct CT_GET_HEADER_EVT : public CT_PACKET{ - U8 bCount; -}CT_GET_HEADER_EVT, *PCT_GET_HEADER_EVT; - -// get item -typedef struct CT_GET_ITEM_CMD : public CT_PACKET{ - U8 bIndex; -}CT_GET_ITEM_CMD, *PCT_GET_ITEM_CMD; - -typedef struct CT_GET_ITEM_EVT : public CT_PACKET{ - U16 wReal; - U16 wA2D; -}CT_GET_ITEM_EVT, *PCT_GET_ITEM_EVT; - - -// ----------- CMD_GET_LRF_ENABLE / CMD_SET_LRF_ENABLE -------------- -typedef struct LRF_DISABLE{ - uint8_t bMaster; - uint8_t bSlave; -}LRF_DISABLE, *PLRF_DISABLE; - -// ----------- CMD_GET_ZOOM_TABLE / CMD_SET_ZOOM_TABLE -------------- -enum { ZOOM_TILT_TABLE_SIZE = 10 }; - -typedef struct ZOOM_TABLE{ - uint8_t nCount; - uint8_t pTable[ZOOM_TILT_TABLE_SIZE]; -}ZOOM_TABLE, *PZOOM_TABLE; - -// ----------- CMD_GET_TILT_TABLE / CMD_SET_TILT_TABLE -------------- -typedef struct TILT_TABLE{ - uint8_t nCount; - uint8_t pTable[ZOOM_TILT_TABLE_SIZE]; -}TILT_TABLE, *PTILT_TABLE; - -#define MASTER_TAG 0x80 -#define SENSOR_TAG 0x00 - -#define SIZE_IDX_A 1 -#define SIZE_IDX_B 2 -#define DEV_ID_IDX 3 -#define CMD_IDX 4 -#define SUB_CMD_IDX 5 -#define DATA_BEGIN_IDX 6 - -#ifdef _CLIENT_APPLICATION_ - #define SEND_TAG MASTER_TAG - #define ACCEPT_TAG SENSOR_TAG -#else - #define SEND_TAG SENSOR_TAG - #define ACCEPT_TAG MASTER_TAG -#endif - -class protocolLGS: public protocolParser{ - private: - basicLogCollection *m_pLog; - basicMutex m_mInquiryMutex; - protected: - uint8_t m_bDeviceID; - basicTransport *m_oDataTransport; - int packetChecker( uint8_t *Buffer, size_t BufferSize); - protocolPackage *packetExtractor( uint8_t *Buffer, size_t BufferSize); - public: - explicit protocolLGS( basicTransport *Transport = NULL, uint8_t DeviceID = 0 ); - virtual ~protocolLGS(); - virtual bool create(void){ return protocolParser::create(); }; - uint8_t getDeviceID(void) { return m_bDeviceID; }; - basicTransport * getTransport(void) { return m_oDataTransport; }; - bool setDeviceID( uint8_t DeviceID ){ m_bDeviceID = DeviceID; return true; }; - bool setTransport(basicTransport* m_oDataTransport); -}; - -class protocolLGS_CLIENT: public protocolLGS{ +class protocolLGS_CLIENT: public protocolLGSm{ private: basicLogCollection *m_pLog; public: @@ -832,7 +33,7 @@ class protocolLGS_CLIENT: public protocolLGS{ }; -class protocolLGS_SERVER: public protocolLGS{ +class protocolLGS_SERVER: public protocolLGSm{ private: basicLogCollection *m_pLog; public: diff --git a/lib/data/protocol/protocolLGS2D.cpp b/lib/data/protocol/protocolLGS2D.cpp new file mode 100644 index 00000000..35242e57 --- /dev/null +++ b/lib/data/protocol/protocolLGS2D.cpp @@ -0,0 +1,2 @@ +#include "protocolLGS2D.h" + diff --git a/lib/data/protocol/protocolLGS2D.h b/lib/data/protocol/protocolLGS2D.h new file mode 100644 index 00000000..a35c20f7 --- /dev/null +++ b/lib/data/protocol/protocolLGS2D.h @@ -0,0 +1,25 @@ +#ifndef __PROTOCOL_LGS_2D_HEADERS__ +#define __PROTOCOL_LGS_2D_HEADERS__ + +#include "protocolLGSm.h" + +class protocolLGS: public protocolParser{ + private: + basicLogCollection * m_pLog; + basicMutex m_mInquiryMutex; + protected: + uint8_t m_bDeviceID; + basicTransport * m_oDataTransport; + int packetChecker( uint8_t *Buffer, size_t BufferSize); + protocolPackage * packetExtractor( uint8_t *Buffer, size_t BufferSize); + public: + explicit protocolLGS( basicTransport *Transport = NULL, uint8_t DeviceID = 0 ); + virtual ~protocolLGS(); + virtual bool create(void){ return protocolParser::create(); }; + uint8_t getDeviceID(void) { return m_bDeviceID; }; + basicTransport * getTransport(void) { return m_oDataTransport; }; + bool setDeviceID( uint8_t DeviceID ){ m_bDeviceID = DeviceID; return true; }; + bool setTransport(basicTransport* m_oDataTransport); +}; + +#endif diff --git a/lib/data/protocol/protocolLGSm.cpp b/lib/data/protocol/protocolLGSm.cpp new file mode 100644 index 00000000..9987341c --- /dev/null +++ b/lib/data/protocol/protocolLGSm.cpp @@ -0,0 +1,134 @@ +#include "protocolLGS.h" + +#define LOG( X ) m_pLog->Log( "LGSM", this, X ) +#define LOG_ERROR( X ) m_pLog->Log( "LGSM", this, _LOG_ERROR, X ) + +protocolLGSm::protocolLGSm( basicTransport *Transport, U8 DeviceID ):protocolParser(){ + m_pLog = basicLogCollection::getInstance(); + m_bDeviceID = DeviceID; + m_oDataTransport = Transport; + if( m_oDataTransport != NULL ) { + m_oDataTransport->addRecipient( ( protocolParser *) this ); + }; +}; + +protocolLGSm::~protocolLGSm(){ +# ifdef DEBUG + LOG("Destructor Begin"); +# endif + m_mInquiryMutex.unlock(); +# ifdef DEBUG + LOG("Destructor End"); +# endif +}; + +bool protocolLGSm::setTransport(basicTransport* Transport){ + if (Transport == NULL) return false; + if (m_oDataTransport != NULL) { + LOG_ERROR("Transport Already Assigned!"); + return false; + }; + m_oDataTransport = Transport; + return m_oDataTransport->addRecipient(this); +}; + +int protocolLGSm::packetChecker(U8 *Buffer, size_t BufferSize ){ +#ifdef DUBUG_COMMUNICATION + char tmp[32]; + int i; + for( i=0;i< BufferSize; i++ ) { + sprintf( tmp, " 0x%02X", Buffer[i] ); + LOG(tmp); + }; +#endif + if( Buffer[0] == 0x55 ){ + if( BufferSize > 5 ) { + if (((Buffer[SIZE_IDX_A] & MASTER_TAG) == ACCEPT_TAG) && (Buffer[DEV_ID_IDX] == m_bDeviceID || Buffer[DEV_ID_IDX] == 0)){ + size_t pLength; + pLength = ((Buffer[SIZE_IDX_A] & 0x7F) << 8) | Buffer[SIZE_IDX_B]; + if( BufferSize >= ( pLength + 4 ) ) { + U8 pCheckSum; + pCheckSum = checksumLGS(Buffer, pLength+3 ); + if( Buffer[pLength+3] == pCheckSum ) { +#ifdef DUBUG_COMMUNICATION + LOG((CSTR)"PacketChecker: Packet Is Recognized (0)"); +#endif + return 0; // Ok + } else { +#ifdef DUBUG_COMMUNICATION + LOG((CSTR)"PacketChecker: Packet Not Recognized CHK SUM(-1)"); +#endif + return -1; // To shift + }; + }; + } else { +#ifdef DUBUG_COMMUNICATION + LOG((CSTR)"PacketChecker: Packet Not Recognized TAG (-1)"); +#endif + return -1; // To shiftSeverity Code Description Project File Line Suppression State + + }; + }; +#ifdef DUBUG_COMMUNICATION + LOG((CSTR)"PacketChecker: Packet Not Recognized SMALL SIZE(1)"); +#endif + return 1; // To grow + }; +#ifdef DUBUG_COMMUNICATION + LOG((CSTR)"PacketChecker: Packet Not Recognized START TAG(-1)"); +#endif + return -1; // To shift +}; + +protocolPackage *protocolLGSm::packetExtractor(U8 *Buffer, size_t BufferSize ){ + protocolPackage *RetVal; +#ifdef DUBUG_COMMUNICATION + char tmp[32]; + int i; + for( i=0;i< BufferSize; i++ ) { + sprintf( tmp, " 0x%02X", Buffer[i] ); + LOG(tmp); + }; +#endif + if( Buffer[0] == 0x55 ){ + if( BufferSize > 5 ){ + if (((Buffer[SIZE_IDX_A] & MASTER_TAG) == ACCEPT_TAG) && (Buffer[DEV_ID_IDX] == m_bDeviceID || Buffer[DEV_ID_IDX] == 0)) { + size_t pLength; + pLength = ((Buffer[SIZE_IDX_A] & 0x7F) << 8) | Buffer[SIZE_IDX_B]; + if( BufferSize >= ( pLength+4 ) ) { + U8 pCheckSum; + pCheckSum = checksumLGS(Buffer, pLength+3 ); + if( Buffer[pLength+3] == pCheckSum ) { + RetVal = (protocolPackage *) malloc(sizeof(protocolPackage)); + if( RetVal == NULL ) return NULL; + RetVal->m_pData =(U8*)malloc( pLength+4 ); + if( RetVal->m_pData == NULL ) { + free( RetVal ); + return NULL; + }; + RetVal->m_nSize = pLength+4; + RetVal->m_nCode = Buffer[CMD_IDX]; + memcpy( RetVal->m_pData, Buffer, RetVal->m_nSize ); +#ifdef DUBUG_COMMUNICATION + LOG((CSTR)"PacketExtractor: Packet Is Extracted (0)"); +#endif + return RetVal; + }; + }; + } else { + LOG_ERROR("TAG mismatch!"); + }; + }; +#ifdef DUBUG_COMMUNICATION + LOG((CSTR)"PacketExtractor: Packet Not Extracted(1)!!!"); +#endif + return NULL; + }; +#ifdef DUBUG_COMMUNICATION + LOG((CSTR)"PacketExtractor: Packet Not Extracted(-1)"); +#endif + return NULL; +}; + +#undef LOG +#undef LOG_ERROR diff --git a/lib/data/protocol/protocolLGSm.h b/lib/data/protocol/protocolLGSm.h new file mode 100644 index 00000000..2415ebaf --- /dev/null +++ b/lib/data/protocol/protocolLGSm.h @@ -0,0 +1,808 @@ +#ifndef __PROTOCOL_LGS_HEADERS__ +#define __PROTOCOL_LGS_HEADERS__ + +#include "../../components/base/basicFunctionality.h" +#include "../../components/base/basicTransport.h" +#include "../../components/base/basicMutex.h" +#include "../../components/base/basicEventHeap.h" +#include "../../hardware/soc/general/3DLRF.h" +#include "../../alg/lgs/mask.h" + +#include "protocol.h" + +#define TARGET_WITH_WIDTH +#define MAXIMAL_SOCKET_PACKET_LENGTH 102400 +#define BOARDDATA_PACKAGE_SIZE_BYTES 0x4000 +#define BOARDDATA_PACKAGE_SIZE_NODES 0x1000 + +/* +typedef struct S_LGS_PARAMETERS{ + uint8_t nOrder; + uint8_t nOffset; + uint8_t nDelta; + uint8_t nSun; + uint8_t bSST; + uint16_t nFlip; // For Quick models (pls30) must be up to 1024 + uint32_t nWidth; // With future devices may gain big numbers + // 3D LRF Specific + uint8_t bBuildThByCore; + uint8_t nGPointSamples; +} LGS_PARAMETERS, *PLGS_PARAMETERS; +*/ + +typedef enum{ + STG_DISCONNECTED = 0x00, + STG_CONNECTED = 0x01, + STG_STUDY = 0x02, + STG_REDY = 0x04, + STG_BUSY = 0x06, + STG_NONE = 0xFF +}E_LGS_STAGE; + +typedef enum{ + CWM_INIT = 0, + CWM_PINGPONG = 1, + CWM_BORDER = 2, + CWM_FILE = 3, + CWM_MASK = 4, + CWM_PARAMS = 5, + CWM_INITIAL_PARAM = 252, + CWM_INITIAL_MASKS_INFO = 253, + CWM_INITIAL_MASKS_DATA = 254, + CWM_ERROR = 255 +} E_CLIENT_WORK_MODE; + +typedef enum{ + SUB_DATA_INTEGRITY_UNKNOWN = 0x00, + SUB_DATA_INTEGRITY_ERROR = 0xA5, + SUB_DATA_INTEGRITY_VALID = 0xFF +}E_LGS_DATA_INTEGRITY_FLAG; + +// commands +typedef enum{ + CMD_STATE = 0x00, + CMD_QUIT = 0x01, + CMD_RESET = 0x02, + CMD_BORDER = 0x03, + CMD_MODE = 0x04, + CMD_GETFILE = 0x05, + CMD_RESTART = 0x06, + CMD_PARAMETERS = 0x07, + CMD_GET_SERIAL_NUMBER = 0x08, + CMD_SET_ADDRESS = 0x09, + CMD_GET_SOFTWARE_VERSION = 0x0A, + CMD_UNSUPPORTED = 0x0B, + CMD_SET_COMM_SPEED = 0x0C, + CMD_FULL_BORDER = 0x0D, + CMD_FULL_RESET = 0x0E, + CMD_CAMERA = 0x0F, + CMD_SET_SERIAL_NUMBER = 0x10, + CMD_BOARDDATA = 0x11, + CMD_GET_CAMERA_PARAMETERS = 0x12, + CMD_SET_CAMERA_PARAMETERS = 0x13, + CMD_RELAY = 0x14, + CMD_GET_RELAY_PARAMETERS = 0x15, + CMD_SET_RELAY_PARAMETERS = 0x16, + CMD_FS_SUB_PACKET = 0x17, + CMD_STATE_2 = 0x18, + CMD_GET_WIDTH_TABLE = 0x19, + CMD_SET_WIDTH_TABLE = 0x1A, + CMD_GET_VOLTAGE = 0x1B, + CMD_GET_VOLTAGE_PARAMETERS = 0x1C, + CMD_SET_VOLTAGE_PARAMETERS = 0x1D, + CMD_GET_HZ_DATA = 0x1E, + CMD_SET_HZ_DATA = 0x1F, + CMD_GET_CALIBRATION_TABLE = 0x20, + CMD_SET_CALIBRATION_TABLE = 0x21, + CMD_GET_LRF_DISABLE = 0x22, + CMD_SET_LRF_DISABLE = 0x23, + CMD_GET_ZOOM_TABLE = 0x24, + CMD_SET_ZOOM_TABLE = 0x25, + CMD_GET_TILT_TABLE = 0x26, + CMD_SET_TILT_TABLE = 0x27, + CMD_GET_HZ_ENABLE = 0x28, + CMD_SET_HZ_ENABLE = 0x29, + CMD_EVT = 0x2A, + CMD_GET_PARAMETERS = 0x2B, + CMD_SET_PARAMETERS = 0x2C, + CMD_FLIP_COMPLETE = 0x2D, + CMD_SCAN_COMPLETE = 0x2E, + CMD_TARGET = 0x2F, + CMD_TARGET_WW = 0x30, + CMD_TARGET_MW = 0x31, + CMD_TARGET_MB = 0x32, + CMD_TARGET_ZZ = 0x33, + CMD_GET_HZ_INFO = 0x34, + CMD_HZ_INFO = 0x35, + CMD_GET_HZ_POLY = 0x36, + CMD_SET_HZ_POLY = 0x37, + CMD_SET_HZ_POLY_ACK = 0x38, + CMD_GET_HZ_STATUS = 0x39, + CMD_SET_HZ_STATUS = 0x3A, + + CMD_DHWM_START_MOTORS = 0x50, + CMD_DHWM_STOP_MOTORS = 0x51, + CMD_ACK = 0xFA, + CMD_NACK = 0xFB, + CMD_NONE = 0xFF +} E_LGS_CMD; + +// modes +enum{ + MODE_SET = 0x80, // 10000000 set/get mode + MODE_MASK = 0x0F, // 00001111 mode mask + MODE_DETECTOR = 0x01, // 00000001 detecting mode - default + MODE_BORDER = 0x02, // 00000010 border of visibilite draw mode + MODE_FILESYSTEM = 0x03, // 00000011 remote file system server mode + MODE_GETFILE = 0x04, // 00000100 get file mode + MODE_SENDBOARDDATA1 = 0x05, // 00000101 send board data for external processing + MODE_SENDBOARDDATA2 = 0x06, // 00000110 send board data for external processing + MODE_BOARDDATA = 0x07 // 00000111 board data for external processing +}; + +// --------------- CMD_STATE ---------------------- +// information type +enum{ + IT_MASK = 0x80, // 10000000 + IT_ERROR = 0x00, // 00000000 + IT_TARGET = 0x80 // 10000000 +}; + +// device id +enum{ + ID_MASK = 0x40, // 01000000 + ID_DEVICE0 = 0x00, // 00000000 + ID_DEVICE1 = 0x40 // 01000000 +}; + +// target type +enum{ + TT_MASK = 0x3C, // 00111100 + TT_NORMAL = 0x00, // 00000000 + TT_WIDE = 0x04, // 00000100 + TT_FLIP = 0x08, // 00001000 + TT_CAMERA = 0x0C, // 00001100 + TT_TEST = 0x10, // 00010000 + TT_BLIND = 0x14 // 00010100 +}; + +// target data +enum{ + TD_MASK = 0x03, // 00000011 + TD_ANGLE = 0x02, // 00000010 + TD_RANGE = 0x01 // 00000001 +}; + +// errors +enum{ + ER_MASK = 0x3F, // 00111111 + ER_NONE = 0x00, // 00000000 + ER_ANGLE = 0x01, // 00000001 + ER_SUNBIT = 0x02, // 00000010 + ER_OVERFLOW = 0x04, // 00000100 + ER_SSTOVERFLOW = 0x08, // 00001000 + ER_MODE = 0x10, // 00010000 + ER_NOIRQ = 0x20 // 00100000 +}; + +// --------------- CMD_BORDER ---------------------- +enum{ + BD_ERRORMASK = 0xE0, // 11100000 + BD_ERRORMODE = 0x80, // 10000000 + BD_ERRORANGLE = 0x40, // 01000000 + BD_NOTREADY = 0x20, // 00100000 + BD_ANGLEMASK = 0x10, // 00010000 + BD_RANGE0MASK = 0x0C, // 00001100 + BD_RANGE1MASK = 0x03, // 00000011 +}; +// --------------- CMD_FILE ------------------ +enum{ + GF_ERRORMASK = 0xC0, // 11000000 + GF_ERRORMODE = 0x80, // 10000000 + GF_ERRORFILE = 0x40, // 01000000 + GF_OP_INDEX = 0x3C, // 00111100 + GF_OP_MASK = 0x03, // 00000011 + GF_OP_OK = 0x00, // 00000000 + GF_OP_OPEN = 0x01, // 00000001 + GF_OP_DATA = 0x02, // 00000010 + GF_OP_CLOSE = 0x03, // 00000011 +}; +// --------------- CMD_PARAMETERS ------------------ +enum{ + DP_OP_MASK = 0x80, + DP_OP_GET = 0x00, + DP_OP_SET = 0x80, + DP_DEVICE_MASK = 0x40, + DP_DEVICE_0 = 0x00, + DP_DEVICE_1 = 0x40, + DP_SST = 0x01, +}; + +enum{ + FB_READY_MASK = 0x80, // 10000000 + FB_READY = 0x80, // 10000000 + FB_NOT_READY = 0x00, // 10000000 + FB_ANGLE_MASK = 0x1F, // 00011111 + FB_RANGE_MASK = 0xF00, // 00011111 + FB_RANGE_1_SHIFT = 4, // 11110000 + FB_RANGE_2_SHIFT = 8, // 00001111 +}; + +// --------------- CMD_CAMERA ------------------ +/* +typedef enum{ + CMD_CAMERA_GET_STATUS = 0, + CMD_CAMERA_GET_PTZ = 1, + CMD_CAMERA_SET_PTZ = 2, + CMD_CAMERA_MOVE_PAN = 3, + CMD_CAMERA_MOVE_TILT = 4, + CMD_CAMERA_MOVE_ZOOM = 5, + CMD_CAMERA_SET_IRIS = 6, + CMD_CAMERA_BUSY = 7, + CMD_CAMERA_ERROR = 8, + CMD_CAMERA_WIPER = 9, + CMD_CAMERA_SET_FOCUS = 10, + CMD_CAMERA_GET_FOCUS = 11, + CMD_CAMERA_MOVE_FOCUS = 12, + CMD_CAMERA_GET_DOPLER = 13, + CMD_CAMERA_SET_DOPLER = 14, + CMD_CAMERA_DOPLER_ALARM = 15, + CMD_CAMERA_GET_DOPLER_MASK = 16, + CMD_CAMERA_SET_DOPLER_MASK = 17, +}E_CAMERA_CMD; +*/ + +enum{ + CAMERA_ERROR_NO_CAMERA = 0 +}; + +enum{ + CAMERA_MAX_DOPLER_MASK = 8 +}; + +typedef struct CAMERA_POS_PTZ{ + U16 posPan; + U16 posTilt; + U16 posZoom; +}CAMERA_POS_PTZ; + +typedef struct CAMERA_MOVE_PAN{ + U16 panSpeed; + U8 panRight; +}CAMERA_MOVE_PAN; + +typedef struct CAMERA_MOVE_TILT{ + U16 tiltSpeed; + U8 tiltUp; +}CAMERA_MOVE_TILT; + +typedef struct CAMERA_MOVE_ZOOM{ + U16 zoomSpeed; + U8 zoomTele; +}CAMERA_MOVE_ZOOM; + +typedef struct CAMERA_MOVE_FOCUS{ + U16 focusSpeed; + U8 focusFar; +}CAMERA_MOVE_FOCUS; + +typedef struct CAMERA_POS_IRIS{ + U16 irisValue; +}CAMERA_POS_IRIS; + +typedef struct CAMERA_POS_FOCUS{ + U16 focusValue; +}CAMERA_POS_FOCUS; + +typedef struct CAMERA_BUSY{ + U8 busyCommand; +}CAMERA_BUSY; + +typedef struct CAMERA_ERROR{ + U16 errID; +}CAMERA_ERROR; + +typedef struct CAMERA_WIPER{ + U8 wiperOn; +}CAMERA_WIPER; + +typedef struct CAMERA_DOPLER{ + U8 doplerOn; + U16 doplerPanStep; + U32 doplerTimeout; +}CAMERA_DOPLER; + +typedef struct CAMERA_DOPLER_ALARM{ + U8 doplerAlarm; + U16 doplerPan; +}CAMERA_DOPLER_ALARM; + +typedef struct CAMERA_DOPLER_MASK{ + U16 nStart; + U16 nStop; +}CAMERA_DOPLER_MASK; + +typedef struct CAMERA_DOPLER_MASK_ARRAY{ + U8 bEnabled; + U8 nCount; + CAMERA_DOPLER_MASK pMask[CAMERA_MAX_DOPLER_MASK]; +}CAMERA_DOPLER_MASK_ARRAY; + +typedef struct CAMERA_DATA{ + U8 nCommand; + union { + CAMERA_POS_PTZ posPTZ; + CAMERA_MOVE_PAN movePan; + CAMERA_MOVE_TILT moveTilt; + CAMERA_MOVE_ZOOM moveZoom; + CAMERA_POS_IRIS posIris; + CAMERA_BUSY busy; + CAMERA_ERROR error; + CAMERA_WIPER wiper; + CAMERA_POS_FOCUS posFocus; + CAMERA_MOVE_FOCUS moveFocus; + CAMERA_DOPLER dopler; + CAMERA_DOPLER_ALARM doplerAlarm; + CAMERA_DOPLER_MASK_ARRAY doplerMask; + }; +} CAMERA_DATA, *PCAMERA_DATA; + +// --------------- CMD_GET_CAMERA_PARAMETERS / CMD_SET_CAMERA_PARAMETERS ------------------ +typedef enum{ + CAMERA_TYPE_MIGVAN_878 = 0x00, + CAMERA_TYPE_MIGVAN_KD6Z = 0x01, + CAMERA_TYPE_MIC1300 = 0x02, + CAMERA_TYPE_JVC_TKS576 = 0x03, + CAMERA_TYPE_PHILIPS_G3AD_NEW= 0x04, + CAMERA_TYPE_VICON = 0x05, + CAMERA_TYPE_PELCO = 0x06, + CAMERA_TYPE_HEBRON = 0x07, + CAMERA_TYPE_3_TRACK = 0x08, + CAMERA_TYPE_AMERICAN_DYNAMICS = 0x09, + CAMERA_TYPE_PHILIPS_G3AD_OLD= 0x0A, + CAMERA_TYPE_NESHER = 0x0B, + CAMERA_TYPE_NONE = 0xFF, +}E_CAMERA_TYPE; + +// ------------------------------------ CMD_RELAY --------------------------------------- +typedef enum{ + CMD_RELAY_GET = 0, + CMD_RELAY_SET = 1, +}E_RELAY_CMD; + +typedef struct RELAY_DATA{ + U8 nCommand; + U8 bOutput; +}RELAY_DATA, *PRELAY_DATA; + +typedef struct RELAY_PARAMETERS{ + U8 bAuto; // allow auto relay + U8 bNormallyClose; + U16 nAutoDelay; // in 0.1 sec (0,0 .. 3000,0 sec) +}RELAY_PARAMETERS, *PRELAY_PARAMETERS; + +// --------------- CMD_STATE_2 ------------------------ +typedef enum S2_INFO_TYPE{ + S2_IT_TARGET_POLAR = 0, + S2_IT_TARGET_DEKART = 1, + S2_IT_FLAGS = 2, + S2_IT_DEVICE_FLAGS = 3, + S2_IT_ERROR_ANGLE = 4, + S2_IT_FLIP = 5, + S2_IT_BLIND = 6, + S2_IT_TARGET_POLAR_WIDTH = 7, // SERGEY 2008/05/02 + S2_IT_TARGET_DEKART_WIDTH = 8 // SERGEY 2008/05/02 +}S2_INFO_TYPE; + +typedef enum S2_INFO_TYPE_FLAGS{ + S2_ITF_ERROR_MODE = 0x01, + S2_ITF_ERROR_NO_IRQ = 0x02, + S2_ITF_ERROR_NO_ZERO_MARK = 0x04, + S2_ITF_CAMERA = 0x08, + S2_ITF_VOLTAGE = 0x10, +}S2_INFO_TYPE_FLAGS; + +typedef enum S2_INFO_TYPE_DEVICE_FLAGS{ + S2_ITDF_ERROR_SUN = 0x01, + S2_ITDF_ERROR_OVERFLOW = 0x02, + S2_ITDF_ERROR_SST_OVERFLOW = 0x04, +}S2_INFO_TYPE_DEVICE_FLAGS; + +typedef enum S2_INFO_TYPE_TARGET{ + S2_ITT_NORMAL = 0x00, + S2_ITT_WIDE = 0x10, + S2_ITT_TYPE_MASK = 0xF0, + S2_ITT_DEVICE_MASK = 0x0F, +}S2_INFO_TYPE_TARGET; + +typedef enum S2_INFO_TYPE_BLIND{ + S2_ITB_STATE_MASK = 0x80, + S2_ITB_START = 0x00, + S2_ITB_STOP = 0x80, + S2_ITB_REASON_MASK = 0x7F, + S2_ITB_MEDIUM_RANGE = 0x01, + S2_ITB_180_DEGREE = 0x02, + S2_ITB_FOG_SPIKES = 0x03, + S2_ITB_PD = 0x04, +}S2_INFO_TYPE_BLIND; + +typedef enum S2_REQUEST_TYPE{ + S2_RT_TARGET_MASK = 0x01, + S2_RT_TARGET_POLAR = 0x00, + S2_RT_TARGET_DEKART = 0x01, +}S2_REQUEST_TYPE; + +typedef enum S2_REQUEST_WIDTH{ + S2_RW_MASK = 0x02, + S2_RW_DISABLE = 0x00, + S2_RW_ENABLE = 0x02, +}S2_REQUEST_WIDTH; + +typedef struct S_S2_PACKAGE{ + uint32_t aaa; +}S2_PACKAGE; + +// --------------- CMD_INFO ------------ + + + +// --------------- CMD_FS_SUB_PACKET ------------------ +enum{ + FS_CMD_SEND_CMD = 0, + FS_CMD_SEND_EVT = 1, + FS_CMD_RECEIVE_CMD = 2, + FS_CMD_RECEIVE_EVT = 3, + + FS_ERROR_SUCCESS = 0x00, // 00000000 + FS_ERROR_MODE = 0x01, // 00000001 +}; + +typedef struct FS_SEND_CMD{ + U8 nOrder; + U8 nLast; + U16 nPosition; + U8 nSubSize; + U8 pSubBuffer[1]; +}FS_SEND_CMD; + +typedef struct FS_SEND_EVT{ + U8 nError; + U8 nOrder; +}FS_SEND_EVT; + +typedef struct FS_RECEIVE_CMD{ + U8 nOrder; + U16 nPosition; +}FS_RECEIVE_CMD; + +typedef struct FS_RECEIVE_EVT{ + U8 nError; + U8 nOrder; + U8 nLast; + U16 nPosition; + U8 nSubSize; + U8 pSubBuffer[1]; +}FS_RECEIVE_EVT; + +typedef struct FS_DATA{ + U8 nCommand; + union { + FS_SEND_CMD sendcmd; + FS_SEND_EVT sendevt; + FS_RECEIVE_CMD receivecmd; + FS_RECEIVE_EVT receiveevt; + }; +}FS_DATA, *PFS_DATA; + +typedef struct FS_DATA_EX : public FS_DATA { + U8 pReserved[MAX_PATH]; +}FS_DATA_EX, *PFS_DATA_EX; + +// --------------- CMD_GET_WIDTH_TABLE & CMD_SET_WIDTH_TABLE ------------------------ +enum { WIDTH_TABLE_SIZE = 16 }; + +typedef struct WIDTH_TABLE{ + U8 nCount; + U16 pTable[WIDTH_TABLE_SIZE]; +}WIDTH_TABLE, *PWIDTH_TABLE; + +// --------------- CMD_VOLTAGE ------------------ +typedef enum VOLTAGE_STATUS{ + VS_OK = 0, + VS_FAILURE = 1, +}VOLTAGE_STATUS; + +// --------------- CMD_GET_VOLTAGE_PARAMETERS / CMD_SET_VOLTAGE_PARAMETERS ------------------ +typedef struct VOLTAGE_PARAMETERS{ + U8 bControl; +}VOLTAGE_PARAMETERS, *PVOLTAGE_PARAMETERS; + +// -------------- CMD_HZ_GET_DATA / CMD_HZ_SET_DATA ----------------------------- +typedef enum HZ_INFO_TYPE{ + HZIT_CMD_GET_HEADER = 0, + HZIT_EVT_GET_HEADER = 1, + HZIT_CMD_GET_POLYGON = 2, + HZIT_EVT_GET_POLYGON = 3, + HZIT_CMD_GET_POLYGON_POINT = 4, + HZIT_EVT_GET_POLYGON_POINT = 5, + HZIT_CMD_GET_RAY = 6, + HZIT_EVT_GET_RAY = 7, + HZIT_CMD_GET_RAY_LINE = 8, + HZIT_EVT_GET_RAY_LINE = 9, + HZIT_CMD_SET_HEADER = 10, + HZIT_EVT_SET_HEADER = 11, + HZIT_CMD_SET_POLYGON = 12, + HZIT_EVT_SET_POLYGON = 13, + HZIT_CMD_SET_POLYGON_POINT = 14, + HZIT_EVT_SET_POLYGON_POINT = 15, + HZIT_CMD_SET_RAY = 16, + HZIT_EVT_SET_RAY = 17, + HZIT_CMD_SET_RAY_LINE = 18, + HZIT_EVT_SET_RAY_LINE = 19, + HZIT_CMD_SET_DONE = 20, + HZIT_EVT_SET_DONE = 21, + HZIT_EVT_ERROR = 255, +}HZ_INFO_TYPE; + +typedef struct HZ_POINT{ + U16 wX; // 0..4095 + U16 wY; // 0..4095 +}HZ_POINT, *LPHZ_POINT; + +typedef struct HZ_LINE{ + U8 bType; // region type + U16 wMin; // 0..2047 + U16 wMax; // 0..2047 +}HZ_LINE, *LPHZ_LINE; + +typedef struct HZ_PACKET{ + U8 bSubSize; + U8 bType; + U8 bSequence; +}HZ_PACKET, *PHZ_PACKET; + +// --------- CMD_HZ_GET_DATA ----------- +typedef HZ_PACKET HZ_CMD_GET_HEADER, *PHZ_CMD_GET_HEADER; +typedef struct HZ_EVT_GET_HEADER : public HZ_PACKET{ + U16 wPolygonCount; + U16 wRayCount; + U32 dwTypeOn; +}HZ_EVT_GET_HEADER, *PHZ_EVT_GET_HEADER; + +typedef struct HZ_CMD_GET_POLYGON : public HZ_PACKET{ + U16 wPolygonIndex; +}HZ_CMD_GET_POLYGON, *PHZ_CMD_GET_POLYGON; + +typedef struct HZ_EVT_GET_POLYGON : public HZ_PACKET{ + U8 bPolygonType; + U16 wPointCount; +}HZ_EVT_GET_POLYGON, *PHZ_EVT_GET_POLYGON; + +typedef struct HZ_CMD_GET_POLYGON_POINT : public HZ_PACKET{ + U16 wPolygonIndex; + U16 wPointIndex; +}HZ_CMD_GET_POLYGON_POINT, *PHZ_CMD_GET_POLYGON_POINT; + +typedef struct HZ_EVT_GET_POLYGON_POINT : public HZ_PACKET{ + HZ_POINT Point; +}HZ_EVT_GET_POLYGON_POINT, *PHZ_EVT_GET_POLYGON_POINT; + +typedef struct HZ_CMD_GET_RAY : public HZ_PACKET{ + U16 wRayIndex; +}HZ_CMD_GET_RAY, *PHZ_CMD_GET_RAY; + +typedef struct HZ_EVT_GET_RAY : public HZ_PACKET{ + U16 wLineCount; +}HZ_EVT_GET_RAY, *PHZ_EVT_GET_RAY; + +typedef struct HZ_CMD_GET_RAY_LINE : public HZ_PACKET{ + U16 wRayIndex; + U16 wLineIndex; +}HZ_CMD_GET_RAY_LINE, *PHZ_CMD_GET_RAY_LINE; + +typedef struct HZ_EVT_GET_RAY_LINE : public HZ_PACKET{ + HZ_LINE Line; +}HZ_EVT_GET_RAY_LINE, *PHZ_EVT_GET_RAY_LINE; + +// ----------- CMD_HZ_SET_DATA -------------- +typedef struct HZ_CMD_SET_HEADER : public HZ_PACKET{ + U16 wPolygonCount; + U16 wRayCount; + U32 dwTypeOn; +}HZ_CMD_SET_HEADER, *PHZ_CMD_SET_HEADER; + +typedef HZ_PACKET HZ_EVT_SET_HEADER, *PHZ_EVT_SET_HEADER; + +typedef struct HZ_CMD_SET_POLYGON : public HZ_PACKET{ + U16 wPolygonIndex; + U8 bPolygonType; + U16 wPointCount; +}HZ_CMD_SET_POLYGON, *PHZ_CMD_SET_POLYGON; + +typedef HZ_PACKET HZ_EVT_SET_POLYGON, *PHZ_EVT_SET_POLYGON; + +typedef struct HZ_CMD_SET_POLYGON_POINT : public HZ_PACKET{ + U16 wPolygonIndex; + U16 wPointIndex; + HZ_POINT Point; +}HZ_CMD_SET_POLYGON_POINT, *PHZ_CMD_SET_POLYGON_POINT; + +typedef HZ_PACKET HZ_EVT_SET_POLYGON_POINT, *PHZ_EVT_SET_POLYGON_POINT; + +typedef struct HZ_CMD_SET_RAY : public HZ_PACKET{ + U16 wRayIndex; + U16 wLineCount; +}HZ_CMD_SET_RAY, *PHZ_CMD_SET_RAY; + +typedef HZ_PACKET HZ_EVT_SET_RAY, *PHZ_EVT_SET_RAY; + +typedef struct HZ_CMD_SET_RAY_LINE : public HZ_PACKET{ + U16 wRayIndex; + U16 wLineIndex; + HZ_LINE Line; +}HZ_CMD_SET_RAY_LINE, *PHZ_CMD_SET_RAY_LINE; + +typedef HZ_PACKET HZ_EVT_SET_RAY_LINE, *PHZ_EVT_SET_RAY_LINE; + +typedef HZ_PACKET HZ_CMD_SET_DONE, *PHZ_CMD_SET_DONE; + +typedef HZ_PACKET HZ_EVT_SET_DONE, *PHZ_EVT_SET_DONE; + +// ----------- CMD_HZ_GET_DATA / CMD_HZ_SET_DATA -------------- +enum{ + HZER_NONE = 0, + HZER_OUT_OF_MEMORY = 1, + HZER_RAY_COUNT = 2, + HZER_RAY_INDEX = 3, + HZER_RAY_LINE_INDEX = 4, + HZER_POLYGON_INDEX = 5, + HZER_POLYGON_POINT_INDEX = 6, +}; + +typedef struct HZ_EVT_ERROR : public HZ_PACKET{ + U8 bCmdType; + U8 bErrorId; +}HZ_EVT_ERROR, *PHZ_EVT_ERROR; + + +// ----------- CMD_GET_CT_TABLE / CMD_SET_CT_TABLE -------------- +enum{ + CIT_NONE = 0, + + CIT_CMD_SET_HEADER = 1, + CIT_EVT_SET_HEADER = 2, + CIT_EVT_SET_ITEM = 3, + CIT_CMD_SET_ITEM = 4, + CIT_CMD_SET_DONE = 5, + CIT_EVT_SET_DONE = 6, + + CIT_CMD_GET_HEADER = 7, + CIT_EVT_GET_HEADER = 8, + CIT_CMD_GET_ITEM = 9, + CIT_EVT_GET_ITEM = 10, + + CIT_EVT_ERROR = 255, +}; + +enum{ + CER_NONE = 0, + CER_OUT_OF_MEMORY = 1, + CER_INDEX = 2, +}; + +typedef struct CT_PACKET{ + U8 bSize; + U8 bType; + U8 bSequence; +}CT_PACKET, *PCT_PACKET; + +// error +typedef struct CT_ERROR_EVT : public CT_PACKET{ + U8 bCmdType; + U8 bErrorId; +}CT_ERROR_EVT, *PCT_ERROR_EVT; + + +// set header +typedef struct CT_SET_HEADER_CMD : public CT_PACKET{ + U8 bCount; +}CT_SET_HEADER_CMD, *PCT_SET_HEADER_CMD; + +typedef struct CT_SET_HEADER_EVT : public CT_PACKET{ +}CT_SET_HEADER_EVT, *PCT_SET_HEADER_EVT; + +// set item +typedef struct CT_SET_ITEM_CMD : public CT_PACKET{ + U8 bIndex; + U16 wReal; + U16 wA2D; +}CT_SET_ITEM_CMD, *PCT_SET_ITEM_CMD; + +typedef struct CT_SET_ITEM_EVT : public CT_PACKET{ +}CT_SET_ITEM_EVT, *PCT_SET_ITEM_EVT; + +// set done +typedef struct CT_SET_DONE_CMD : public CT_PACKET{ +}CT_SET_DONE_CMD, *PCT_SET_DONE_CMD; + +typedef struct CT_SET_DONE_EVT : public CT_PACKET{ +}CT_SET_DONE_EVT, *PCT_SET_DONE_EVT; + +// get header +typedef struct CT_GET_HEADER_CMD : public CT_PACKET{ +}CT_GET_HEADER_CMD, *PCT_GET_HEADER_CMD; + +typedef struct CT_GET_HEADER_EVT : public CT_PACKET{ + U8 bCount; +}CT_GET_HEADER_EVT, *PCT_GET_HEADER_EVT; + +// get item +typedef struct CT_GET_ITEM_CMD : public CT_PACKET{ + U8 bIndex; +}CT_GET_ITEM_CMD, *PCT_GET_ITEM_CMD; + +typedef struct CT_GET_ITEM_EVT : public CT_PACKET{ + U16 wReal; + U16 wA2D; +}CT_GET_ITEM_EVT, *PCT_GET_ITEM_EVT; + + +// ----------- CMD_GET_LRF_ENABLE / CMD_SET_LRF_ENABLE -------------- +typedef struct LRF_DISABLE{ + uint8_t bMaster; + uint8_t bSlave; +}LRF_DISABLE, *PLRF_DISABLE; + +// ----------- CMD_GET_ZOOM_TABLE / CMD_SET_ZOOM_TABLE -------------- +enum { ZOOM_TILT_TABLE_SIZE = 10 }; + +typedef struct ZOOM_TABLE{ + uint8_t nCount; + uint8_t pTable[ZOOM_TILT_TABLE_SIZE]; +}ZOOM_TABLE, *PZOOM_TABLE; + +// ----------- CMD_GET_TILT_TABLE / CMD_SET_TILT_TABLE -------------- +typedef struct TILT_TABLE{ + uint8_t nCount; + uint8_t pTable[ZOOM_TILT_TABLE_SIZE]; +}TILT_TABLE, *PTILT_TABLE; + +#define MASTER_TAG 0x80 +#define SENSOR_TAG 0x00 + +#define SIZE_IDX_A 1 +#define SIZE_IDX_B 2 +#define DEV_ID_IDX 3 +#define CMD_IDX 4 +#define SUB_CMD_IDX 5 +#define DATA_BEGIN_IDX 6 + + +#ifdef _CLIENT_APPLICATION_ + #define SEND_TAG MASTER_TAG + #define ACCEPT_TAG SENSOR_TAG +#else + #define SEND_TAG SENSOR_TAG + #define ACCEPT_TAG MASTER_TAG +#endif + +class protocolLGSm: public protocolParser{ + private: + basicLogCollection *m_pLog; + basicMutex m_mInquiryMutex; + protected: + uint8_t m_bDeviceID; + basicTransport *m_oDataTransport; + int packetChecker( uint8_t *Buffer, size_t BufferSize); + protocolPackage *packetExtractor( uint8_t *Buffer, size_t BufferSize); + public: + explicit protocolLGSm( basicTransport *Transport = NULL, uint8_t DeviceID = 0 ); + virtual ~protocolLGSm(); + virtual bool create(void){ return protocolParser::create(); }; + uint8_t getDeviceID(void) { return m_bDeviceID; }; + basicTransport * getTransport(void) { return m_oDataTransport; }; + bool setDeviceID( uint8_t DeviceID ){ m_bDeviceID = DeviceID; return true; }; + bool setTransport(basicTransport* m_oDataTransport); +}; + +#endif diff --git a/lib/data/transport/transportSerial.h b/lib/data/transport/transportSerial.h index 53d11682..b0f8a8c8 100644 --- a/lib/data/transport/transportSerial.h +++ b/lib/data/transport/transportSerial.h @@ -12,16 +12,16 @@ class transportSerial: public basicTransport, public basicDualThread { void m_fThreadAProc(void); void m_fThreadBProc(void); protected: - U8 *m_pInputBuffer; - int m_nInputBufferSize; - U8 *m_pOutputBuffer; - int m_nOutputBufferSize; + U8 * m_pInputBuffer; + int m_nInputBufferSize; + U8 * m_pOutputBuffer; + int m_nOutputBufferSize; virtual int sendBlock(unsigned char *Data, int DataSize){ return 0;}; virtual int recptBlock(unsigned char *Buffer, int *BufferLength){ return 0;}; public: transportSerial(); - ~transportSerial(); - bool sendData( unsigned char *Data, int DataSize ); + virtual ~transportSerial(); + bool sendData( unsigned char *Data, int DataSize ); }; diff --git a/lib/data/transport/transportSocket.cpp b/lib/data/transport/transportSocket.cpp index 9fbd6b59..2c123d80 100644 --- a/lib/data/transport/transportSocket.cpp +++ b/lib/data/transport/transportSocket.cpp @@ -6,79 +6,137 @@ // Constructor implementation transportSocket::transportSocket() : basicTransport(), basicDualThread(){ m_pLog = basicLogCollection::getInstance(); - m_pInputBuffer = (U8 *)malloc(MAXIMAL_SOCKET_PACKET_LENGTH); - if (m_pInputBuffer != NULL) { - m_nInputBufferSize = 0; - m_pOutputBuffer = (U8 *)malloc(MAXIMAL_SOCKET_PACKET_LENGTH); - if (m_pOutputBuffer != NULL) { - m_nOutputBufferSize = 0; - LOG("Starting"); - init(); - }; + //m_pInputBuffer = (U8 *)malloc(MAXIMAL_SOCKET_PACKET_LENGTH); + //if (m_pInputBuffer != NULL) { + m_nInputBufferSize = 0; + // m_pOutputBuffer = (U8 *)malloc(MAXIMAL_SOCKET_PACKET_LENGTH); + // if (m_pOutputBuffer != NULL) { + m_nOutputBufferSize = 0; +#ifdef DEBUG + LOG("Init IO Threads!"); +#endif + if( init() ){ //basicDualThread:: + int cnt = 5; + while( cnt-- && m_bThreadAStatus < TH_WORKING ) SLEEP(1); // To ensure start Thread procedures +#ifdef DEBUG + LOG("Init IO Threads Done"); +#endif + } else { + LOG_ERROR("Init IO Threads ERROR!"); }; + // }; + //}; }; // Destructor implementation transportSocket::~transportSocket(){ - if (m_pInputBuffer != NULL) { - free(m_pInputBuffer); - }; - if (m_pOutputBuffer != NULL) { - free(m_pOutputBuffer); - }; +# ifdef DEBUG + LOG("Destruct: START"); +# endif + m_mBufferProtectorMutex.unlock(); + if( m_bThreadAStatus > TH_ARMED ) { + waitThreadAEnd(); +# ifdef DEBUG + LOG("DONE"); +# endif + }; + m_mQueueProtectorMutex.unlock(); + if( m_bThreadBStatus > TH_ARMED ) { + waitThreadBEnd(); +# ifdef DEBUG + LOG("DONE"); +# endif + }; + //if (m_pInputBuffer != NULL) { + // free(m_pInputBuffer); + //}; + //if (m_pOutputBuffer != NULL) { + // free(m_pOutputBuffer); + //}; +# ifdef DEBUG + LOG("Destruct: DONE"); +# endif }; void transportSocket::m_fThreadAProc(void){ + int index; + int RetVal; m_bThreadAStatus = TH_WORKING; - LOG("Thread A Started"); + LOG("Sender Thread Started!"); while (m_bThreadAStatus < TH_ENDED) { m_mBufferProtectorMutex.lock(); - if (m_nOutputBufferSize > 0) { - int index; - int RetVal; + if( m_nOutputBufferSize > 0 ){ index = 0; - //LOG("Buffer ready to Send"); while ((index < m_nOutputBufferSize) && (m_bThreadAStatus < TH_ENDED)){ RetVal = sendBlock(m_pOutputBuffer + index, m_nOutputBufferSize - index); - if (RetVal > 0) index += RetVal; + if( RetVal > 0 ) index += RetVal; + if( RetVal == -1 ){ + m_bThreadBStatus = TH_ENDED; + m_bThreadAStatus = TH_ENDED; + LOG_ERROR("Connection Error[send]"); + setConnectionStatus( CS_DISCONNECTED ); + m_nOutputBufferSize = 0; + }; }; - //LOG("Buffer is Sent"); m_nOutputBufferSize = 0; + m_mBufferProtectorMutex.unlock(); + } else { + m_mBufferProtectorMutex.unlock(); + SLEEP(5); }; - m_mBufferProtectorMutex.unlock(); - SLEEP(1); }; }; void transportSocket::m_fThreadBProc(void){ m_bThreadBStatus = TH_WORKING; - LOG("Thread B Started"); - while (m_bThreadBStatus < TH_ENDED) { - recptBlock(m_pInputBuffer, &m_nInputBufferSize); - if (m_nInputBufferSize > 0) { - m_mQueueProtectorMutex.lock(); - for (parseQueue::iterator index = m_vParsers.begin(); index != m_vParsers.end(); index++){ - (*index)->parse(m_pInputBuffer, m_nInputBufferSize); + int RetVal; + LOG("Recipient Thread Started!"); + while( m_bThreadBStatus < TH_ENDED ){ + RetVal = recptBlock( m_pInputBuffer, &m_nInputBufferSize); + if( RetVal == -1 ){ + LOG_ERROR("Connection Error[rcpt]"); + m_nInputBufferSize = 0; + if(!getStatus()) { + setConnectionStatus(CS_DISCONNECTED); + m_bThreadBStatus = TH_ENDED; + m_bThreadAStatus = TH_ENDED; + } else SLEEP(100); + } else if( m_nInputBufferSize > 0 ){ + if (m_vParsers.size()) { + m_mQueueProtectorMutex.lock(); + for (parseQueue::iterator index = m_vParsers.begin(); index != m_vParsers.end(); index++) { + (*index)->parse(m_pInputBuffer, m_nInputBufferSize); + }; + m_nInputBufferSize = 0; + m_mQueueProtectorMutex.unlock(); + } else { + LOG_ERROR("Try to parse data but No Parsers Assigned!"); }; - m_mQueueProtectorMutex.unlock(); + } else { + SLEEP(5); }; - SLEEP(1); }; }; bool transportSocket::sendData(unsigned char *Data, int DataSize){ + + if( m_bThreadAStatus != TH_WORKING ) { + LOG_ERROR("Trying to Send Data Before Transport Started!"); + return false; + }; + m_mBufferProtectorMutex.lock(); - if (m_nOutputBufferSize + DataSize > MAXIMAL_SOCKET_PACKET_LENGTH) { + if (m_nOutputBufferSize + DataSize > MAXIMAL_SOCKET_PACKET_LENGTH ){ m_mBufferProtectorMutex.unlock(); - LOG("Data Too BIG"); + LOG_ERROR("Data Too BIG"); return false; }; - //LOG("Output Data Set"); memcpy(m_pOutputBuffer + m_nOutputBufferSize, Data, DataSize); m_nOutputBufferSize += DataSize; m_mBufferProtectorMutex.unlock(); return true; }; + #undef LOG #undef LOG_ERROR \ No newline at end of file diff --git a/lib/data/transport/transportSocket.h b/lib/data/transport/transportSocket.h index 6491204e..0aaeaa74 100644 --- a/lib/data/transport/transportSocket.h +++ b/lib/data/transport/transportSocket.h @@ -12,22 +12,53 @@ * @author Gagua */ class transportSocket : public basicTransport, public basicDualThread { -private: - basicLogCollection * m_pLog; - void m_fThreadAProc(void); - void m_fThreadBProc(void); +private: + basicLogCollection *m_pLog; protected: - U8 * m_pInputBuffer; - int m_nInputBufferSize; - U8 * m_pOutputBuffer; - int m_nOutputBufferSize; + //U8 *m_pInputBuffer; + //U8 *m_pOutputBuffer; + U8 m_pInputBuffer[MAXIMAL_SOCKET_PACKET_LENGTH]; + U8 m_pOutputBuffer[MAXIMAL_SOCKET_PACKET_LENGTH]; + int m_nInputBufferSize; + int m_nOutputBufferSize; - virtual int sendBlock(unsigned char *Data, int DataSize){ return 0; }; - virtual int recptBlock(unsigned char *Buffer, int *BufferLength){ return 0; }; + virtual void m_fThreadAProc(void); + virtual void m_fThreadBProc(void); + virtual int sendBlock(unsigned char *Data, int DataSize){ return 0; }; + virtual int recptBlock(unsigned char *Buffer, int *BufferLength){ return 0; }; public: + // Constructor transportSocket(); + + // Destructor virtual ~transportSocket(); - bool sendData(unsigned char *Data, int DataSize); + + // Copy constructor + // TODO: Uncomment the copy constructor when you need it. + //transportSocket(const socketTransport& src); + + // Assignment operator + // TODO: Uncomment the assignment operator when you need it. + //transportSocket& operator=(const transportSocket& src); + bool sendData(unsigned char *Data, int DataSize); }; +// TODO: Uncomment the copy constructor when you need it. +//inline transportSocket::transportSocket(const socketTransport& src) +//{ +// // TODO: copy +//} + +// TODO: Uncomment the assignment operator when you need it. +//inline transportSocket& transportSocket::operator=(const transportSocket& rhs) +//{ +// if (this == &rhs) { +// return *this; +// } +// +// // TODO: assignment +// +// return *this; +//} + #endif // __SOCKETTRANSPORT_H_INCL__ diff --git a/lib/hardware/uart/serialPort.h b/lib/hardware/uart/serialPort.h index 4c77d1cc..ded4ae39 100644 --- a/lib/hardware/uart/serialPort.h +++ b/lib/hardware/uart/serialPort.h @@ -9,8 +9,8 @@ #include // File control definitions #include // Error number definitions #ifdef __linux__ -#include // UNIX standard function definitions -#include // POSIX terminal control definitions + #include // UNIX standard function definitions + #include // POSIX terminal control definitions #else #endif diff --git a/lib/hardware/uart/serialSOL.cpp b/lib/hardware/uart/serialSOL.cpp new file mode 100644 index 00000000..7a1e3238 --- /dev/null +++ b/lib/hardware/uart/serialSOL.cpp @@ -0,0 +1,165 @@ +#include "serialSOL.h" + +#define LOG( X ) m_pLog->Log( "serialPort", this, X ) +#define LOG_ERROR( X ) m_pLog->Log( "serialPort", this, _LOG_ERROR, X ) + +serialSOL::serialSOL( SOL_TYPE t ): transportSocket(){ + m_pLog = m_pLog = basicLogCollection::getInstance(); + m_eSolType = t; + m_bInitComplete = false; + m_nSocketFD = -1; + m_sServerAddr; + m_sClientAddr; + memset( &m_sServerAddr, 0, sizeof( m_sServerAddr ) ); + memset( &m_sClientAddr, 0, sizeof( m_sClientAddr ) ); +}; + +serialSOL::~serialSOL(){ + +}; + +bool serialSOL::create( CSTR address, uint16_t port, int Speed ){ + switch( m_eSolType ) { + case SOL_TCP_CLIENT:{ + break; + }; + case SOL_UDP_CLIENT:{ + // Creating socket file descriptor + if ( (m_nSocketFD = socket(AF_INET, SOCK_DGRAM, 0)) < 0 ) { + LOG_ERROR("Socket Creation Failed!"); + return false; + }; + fcntl( m_nSocketFD, F_SETFL, O_NONBLOCK ); + // Filling server information + m_sServerAddr.sin_family = AF_INET; + m_sServerAddr.sin_addr.s_addr = INADDR_ANY; + m_sServerAddr.sin_port = htons( port ); + + break; + }; + case SOL_TCP_SERVER:{ + break; + }; + case SOL_UDP_SERVER:{ + // Creating socket file descriptor + if ( (m_nSocketFD = socket( AF_INET, SOCK_DGRAM, 0 )) < 0 ) { + LOG_ERROR("Socket Creation Failed!"); + return false; + }; + fcntl( m_nSocketFD, F_SETFL, O_NONBLOCK); + // Filling server information + m_sServerAddr.sin_family = AF_INET; // IPv4 + m_sServerAddr.sin_addr.s_addr = INADDR_ANY; + m_sServerAddr.sin_port = htons( port ); + + // Bind the socket with the server address + if ( bind( m_nSocketFD, (const struct sockaddr *)&m_sServerAddr, sizeof(m_sServerAddr)) < 0 ){ + LOG_ERROR("Bind Failed"); + return false; + }; + break; + }; + }; + return true; +}; + +int serialSOL::sendBlock( unsigned char *Data, int DataSize ){ + if( !m_bInitComplete || !m_bConnected ) return -1; // Exit after unsuccess reconnect + + int RetVal; + + if( m_nSocketFD > -1 ){ +#ifdef DUBUG_COMMUNICATION + char cBuffer[256]; + sprintf(cBuffer,"Write into Socket %d bytes", DataSize ); + LOG(cBuffer); +#endif + socklen_t addr_len = sizeof( m_sClientAddr ); + RetVal = sendto( m_nSocketFD, (const char *)Data, DataSize, MSG_CONFIRM, (const struct sockaddr *) &m_sClientAddr, addr_len ); + + if( ( RetVal == -1 ) && (errno != EINTR ) && ( errno != EWOULDBLOCK ) ) { + LOG_ERROR("Error acures while writing data into the Socket"); + shutdown( m_nSocketFD, 2 ); + close( m_nSocketFD ); + m_nSocketFD = -1; + m_bConnected = false; + setConnectionStatus( CS_DISCONNECTED ); + return -1; + }; + + if( RetVal < 0 ) RetVal = 0; + +#ifdef DUBUG_COMMUNICATION + sprintf(cBuffer,"Bytes Sent: %ld", RetVal); + LOG(cBuffer); +#endif + + } else { + LOG_ERROR("Not Connected!"); + m_bConnected = false; + setConnectionStatus( CS_DISCONNECTED ); + return -1; + }; + + return RetVal; +}; + +int serialSOL::recptBlock( unsigned char *Buffer, int *BufferLength ){ + if( !m_bInitComplete || !m_bConnected ){ + LOG_ERROR("Not Connected!"); + m_bInitComplete = false; + m_bConnected = false; + setConnectionStatus( CS_DISCONNECTED ); + return -1; // Exit after unsuccess reconnect + }; + int RetVal; + if( m_nSocketFD > -1 ) { + 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 ){ + if( errno!=EAGAIN && errno!=EINTR ) { + LOG_ERROR("Peer Closes Connection!"); + shutdown( m_nSocketFD, 2 ); + close( m_nSocketFD ); + *BufferLength = 0; + m_bConnected = false; + m_nSocketFD = -1; + setConnectionStatus( CS_DISCONNECTED ); + return -1; + }; + }; + } else { + LOG_ERROR("Not Connected!"); + *BufferLength = 0; + m_bConnected = false; + setConnectionStatus( CS_DISCONNECTED ); + return -1; + }; + if (RetVal > 0) { +#ifdef DUBUG_COMMUNICATION + char cBuffer[165]; + sprintf(cBuffer, "Bytes received: %d", RetVal); + LOG(cBuffer); +#endif + *BufferLength = RetVal; + return RetVal; + }; + + *BufferLength = 0; + + if (RetVal == -1) return 0; + + if (RetVal == 0){ + errno = 0; + return 0; + }; + + /* r < -1, should never happen. */ + errno = EIO; + + return 0; +}; + +#undef LOG +#undef LOG_ERROR + diff --git a/lib/hardware/uart/serialSOL.h b/lib/hardware/uart/serialSOL.h index c8760fb3..5f9069c1 100644 --- a/lib/hardware/uart/serialSOL.h +++ b/lib/hardware/uart/serialSOL.h @@ -1,5 +1,5 @@ -#ifndef __SERIAL_PORT_serial-over-LAN__ -#define __SERIAL_PORT_serial-over-LAN__ +#ifndef __SERIAL_PORT_SERIAL_OVER_LAN__ +#define __SERIAL_PORT_SERIAL_OVER_LAN__ /* #!/bin/bash @@ -15,7 +15,53 @@ http://www.dest-unreach.org/socat/doc/socat-ttyovertcp.txt */ +#include +#include +#include +#include +#include // File control definitions +#include +#include +#include +#include +#ifdef DEBUG + //#define _DEBUG_SOL_COMMUNICATION_ +#endif + +#include "../../data/transport/transportSocket.h" + + +typedef enum E_SOL_TYPE{ + SOL_UDP_CLIENT = 0, + SOL_TCP_CLIENT = 1, + SOL_UDP_SERVER = 2, + SOL_TCP_SERVER = 3 +}SOL_TYPE; + +/** + * TODO: Add class description + * + * @author gagua + */ +class serialSOL: public transportSocket { + private: + basicLogCollection *m_pLog; + SOL_TYPE m_eSolType; + bool m_bInitComplete; + int m_nSocketFD; + + struct sockaddr_in m_sServerAddr; + struct sockaddr_in m_sClientAddr; + + protected: + int sendBlock( unsigned char *Data, int DataSize ); + int recptBlock( unsigned char *Buffer, int *BufferLength ); + public: + explicit serialSOL( SOL_TYPE t ); + virtual ~serialSOL(); + bool create( CSTR address, uint16_t port, int Speed ); +}; #endif diff --git a/lib/rgoose/rgooseNode2D.cpp b/lib/rgoose/rgooseNode2D.cpp new file mode 100644 index 00000000..e69de29b diff --git a/lib/rgoose/rgooseNode2D.h b/lib/rgoose/rgooseNode2D.h new file mode 100644 index 00000000..abb0135f --- /dev/null +++ b/lib/rgoose/rgooseNode2D.h @@ -0,0 +1,42 @@ +#ifndef __OBJECT_NET_NODE_2D_HEADERS__ +#define __OBJECT_NET_NODE_2D_HEADERS__ + +#include "rgooseNode.h" + +#include "../components/base/basicObject.h" +#include "../components/base/basicMutex.h" +#include "../components/base/basicDualThread.h" +#include "../components/base/basicLogCollection.h" +#include "../components/base/basicEventHeap.h" +#include "../components/base/basicPosition.h" +#include "../components/object/objectSystemAnchor.h" +#include "../components/base/basicSettingsProvider.h" +#include "../alg/lgs/mask.h" + + +class ARGUS_2DSensor: public argusNetNode{ + + public: + ARGUS_2DSensor(); + ~ARGUS_2DSensor(); + virtual bool isAttached() { + } + virtual bool isDetached() { + } + virtual bool startService() { + } + virtual bool stopService() { + } + virtual bool validate() { + } + virtual objectCaps getCaps(void) { + } + virtual int getID(void) { + } + virtual objectStatus getStatus(void) { + } + virtual CSTR getUID(void) { + } +}; + +#endif diff --git a/lib/rgoose/rgooseNode3D.h b/lib/rgoose/rgooseNode3D.h index a6846c65..69fdd7ab 100644 --- a/lib/rgoose/rgooseNode3D.h +++ b/lib/rgoose/rgooseNode3D.h @@ -1,5 +1,5 @@ -#ifndef __OBJECT_LGS_HEADERS__ -#define __OBJECT_LGS_HEADERS__ +#ifndef __OBJECT_NET_NODE_3D_HEADERS__ +#define __OBJECT_NET_NODE_3D_HEADERS__ #ifndef __linux__ #include