diff --git a/lib/App/3dSERVER/LRF_Kernel.cpp b/lib/App/3dSERVER/LRF_Kernel.cpp index 80df270e..7e531436 100644 --- a/lib/App/3dSERVER/LRF_Kernel.cpp +++ b/lib/App/3dSERVER/LRF_Kernel.cpp @@ -584,7 +584,7 @@ void LRF_Kernel::m_fThreadProc( void ){ }; break; #endif // NO_BLACK_TARGETS - +// nohup sleep 30 & echo $! > pidfile case SCAN_COMPLETE: #ifdef PRU_SLAVE #else @@ -592,14 +592,14 @@ void LRF_Kernel::m_fThreadProc( void ){ #endif sprintf( Buffer,"Scan Complete [%d,%d]", cNode.width, cNode.begin_id ); #ifdef DEBUG - LOG( Buffer ); + //LOG( Buffer ); #endif tEvt = createBasicEvent( 0, EVT_CLASS_SENSOR, EVT_SCAN, Buffer, NULL ); break; case SCAN_FROZEN: sprintf( Buffer,"Scan was Frozen", cNode.width, cNode.begin_id ); #ifdef DEBUG - LOG( Buffer ); + //LOG( Buffer ); #endif tEvt = createBasicEvent( 0, EVT_CLASS_SENSOR, EVT_SCAN, Buffer, NULL ); #ifdef PRU_SLAVE @@ -611,6 +611,7 @@ void LRF_Kernel::m_fThreadProc( void ){ // cTrackID = m_pTracker->validateTarget( pTarget, false ); // }; //}; + m_pTracker->ScanComplete(); #endif diff --git a/lib/App/3dSERVER/LRF_Kernel.h b/lib/App/3dSERVER/LRF_Kernel.h index 8ff6cedc..4c742553 100644 --- a/lib/App/3dSERVER/LRF_Kernel.h +++ b/lib/App/3dSERVER/LRF_Kernel.h @@ -112,8 +112,8 @@ class LRF_Kernel: public basicThread { bool attachNetServer( networkServer *srvPort ); bool stopMotors( void ); bool startMotors( void ); - ShadowMask * getShadowMask( void ){ return m_pShadow; }; #endif + ShadowMask * getShadowMask( void ){ return m_pShadow; }; bool create( LRF_HardwareManager *ptr = NULL ); void WaitFinish( bool Force = false ); diff --git a/lib/App/3dSERVER/LRF_TwinConnector.cpp b/lib/App/3dSERVER/LRF_TwinConnector.cpp index 452655f1..618c033e 100644 --- a/lib/App/3dSERVER/LRF_TwinConnector.cpp +++ b/lib/App/3dSERVER/LRF_TwinConnector.cpp @@ -2,6 +2,13 @@ #include "LRF_Kernel.h" #include "LRF_TargetTracker.h" +#define STB_IMAGE_IMPLEMENTATION + #include "../../data/stbi/stb_image.h" + #define STB_IMAGE_WRITE_IMPLEMENTATION + #include "../../data/stbi/stb_image_write.h" + #undef STB_IMAGE_WRITE_IMPLEMENTATION +#undef STB_IMAGE_IMPLEMENTATION + #define LOG( X ) m_pLog->Log( "TWINC", this, X ) #ifdef DEBUG #define LOG_ERROR( X ) {\ @@ -16,9 +23,9 @@ 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_pEngine = NULL; + m_nStatus = 0; #ifdef PRU_SLAVE m_nMasterPort = 0; m_pMasterAddress = (CSTR) malloc( 16 ); @@ -33,7 +40,6 @@ LRF_TwinConnector::LRF_TwinConnector( config_setting_t *Settings ): basicThread( LRF_TwinConnector::~LRF_TwinConnector(){ if( m_pPort != NULL ) delete( m_pPort ); - if( m_pProtocol != NULL ) delete( m_pProtocol ); #ifdef PRU_SLAVE if( m_pMasterAddress ) free( m_pMasterAddress ); @@ -98,23 +104,23 @@ bool LRF_TwinConnector::create(){ return false; }; #ifdef PRU_SLAVE - m_pProtocol = new protocolInternalLRF3D_SLAVE(); - if( m_pProtocol == NULL ){ - LOG_ERROR("Error creating protocol!"); - return false; - }; - if( !m_pProtocol->create() ) return false; + //m_pProtocol = new protocolInternalLRF3D_SLAVE(); + //if( m_pProtocol == NULL ){ + // LOG_ERROR("Error creating protocol!"); + // return false; + //}; + if( !protocolInternalLRF3D_SLAVE::create() ) return false; #else int RetCode; struct hostent * h_info; struct sockaddr_in * MainSocketAddress = NULL; - m_pProtocol = new protocolInternalLRF3D_MASTER(); - if( m_pProtocol == NULL ){ - LOG_ERROR("Error creating protocol!"); - return false; - }; - if( !m_pProtocol->create() ) return false; + //m_pProtocol = new protocolInternalLRF3D_MASTER(); + //if( m_pProtocol == NULL ){ + // LOG_ERROR("Error creating protocol!"); + // return false; + //}; + if( !protocolInternalLRF3D_MASTER::create() ) return false; m_nMainSocket = socket( AF_INET, SOCK_STREAM, 0 ); if( m_nMainSocket == -1){ @@ -165,6 +171,17 @@ bool LRF_TwinConnector::create(){ }; #ifdef PRU_SLAVE + bool LRF_TwinConnector::packetHandler( protocolPackage *Package ){ + if( Package == NULL ) return false; + TWIN_COMMAND cCMD = (TWIN_COMMAND) Package->m_pData[3]; + switch( cCMD ) { + case TWC_GET_STATUS:{ + sendStatus(); + break; + }; + }; + return true; + }; void LRF_TwinConnector::m_fThreadProc( void ){ TWIN_CMD_REC * tCMD = NULL; int ClientSocket = -1; @@ -228,19 +245,44 @@ bool LRF_TwinConnector::create(){ LOG("(re)Establish Connection"); m_pPort = new clientPort( m_pMasterAddress, m_nMasterPort, true ); if( m_pPort!= NULL ){ - m_pProtocol->setTransport( m_pPort ); + setTransport( m_pPort ); m_bWorkingMode = TWI_STAGE_CONNECTED; }; }; }; }; #else //Master + bool LRF_TwinConnector::packetHandler( protocolPackage *Package ){ + if( Package == NULL ) return false; + TWIN_COMMAND cCMD = (TWIN_COMMAND)Package->m_pData[3]; + switch( cCMD ) { + case TWC_ACK_STATUS:{ + uint32_t tStatus; +#ifdef DEBUG + LOG("Status ACK reseived"); +#endif + tStatus = ( Package->m_pData[4] << 24 ) | ( Package->m_pData[5] << 16 ) | ( Package->m_pData[6] << 8 ) | Package->m_pData[7]; + m_mStatusProtector.lock(); + m_nStatus = tStatus; + m_mStatusProtector.unlock(); + break; + }; + case TWC_TH_DATA:{ + + }; + }; + m_mLastTypeProtector.lock(); + m_bLastPackageType = cCMD; + m_mLastTypeProtector.unlock(); + return true; + }; void LRF_TwinConnector::m_fThreadProc( void ){ int ClientSocket = -1; struct sockaddr ClientAddress; socklen_t ClientAddressSize; long long cMilliseconds; long long cStatusTO = 0; + long long cDrawTO = 0; m_bThreadStatus = TH_WORKING; @@ -248,6 +290,29 @@ bool LRF_TwinConnector::create(){ cMilliseconds = getMilliseconds(); + // TH Saving procedure + if( cDrawTO == 0 ) { + cDrawTO = cMilliseconds; + } else if ( ( cMilliseconds - cDrawTO ) > TWI_DRAW_LOOP_MS ){ + cDrawTO = cMilliseconds; + if( m_pEngine!= NULL ) { + // Store Local TH Draws + thresholdNode *tMem; + uint32_t tSize; + for( uint8_t i=0; i<16; i++ ) { + // just in case if we must end work + if( m_bThreadStatus != TH_WORKING ) break; + tMem = m_pEngine->getTreshold( tSize, i ); + if( tMem!= NULL ) { + char tBuffer[256]; + sprintf( tBuffer, "data/th_data_%d.png", i ); + if( !saveTHPicture( tMem, tBuffer, false )){ + LOG_ERROR("TH PNG save failure!"); + }; + }; + }; + }; + }; // Port exists - SLAVE is connected if( m_pPort != NULL ){ // Check if still connected @@ -262,19 +327,19 @@ bool LRF_TwinConnector::create(){ // No Current Request Issued switch( m_bWorkingMode ) { case TWI_STAGE_CONNECTED:{ - if( m_pProtocol->requestSoftwareVersion() ){ + if( requestSoftwareVersion() ){ m_bCCMD = TWC_ACK_VERSION; }; break; }; case TWI_STAGE_INIT_1:{ - if( m_pProtocol->requestCurrentSettings() ){ + if( requestCurrentSettings() ){ m_bCCMD = TWC_ACK_CONFIG; }; break; }; case TWI_STAGE_INIT_2:{ - if( m_pProtocol->requestShadow() ){ + if( requestShadow() ){ m_bCCMD = TWC_ACK_SHADOW; }; break; @@ -282,18 +347,18 @@ bool LRF_TwinConnector::create(){ case TWI_STAGE_MAIN_LOOP:{ if( ( cMilliseconds - cStatusTO ) > TWI_STATUS_LOOP_MS ) { cStatusTO = cMilliseconds; - m_pProtocol->requestStatus(); + requestStatus(); m_bCCMD = TWC_ACK_STATUS; LOG("Req Status"); } else { SLEEP( TWI_SLOW_LOOP_SLEEP ); - }; + } break; }; }; } else { // Waiting CMD ACK status - if( m_pProtocol->getLastPackageType() == m_bCCMD ) { + if( getLastPackageType() == m_bCCMD ) { switch( m_bCCMD ){ case TWC_ACK_VERSION:{ m_bWorkingMode = TWI_STAGE_INIT_1; @@ -311,26 +376,26 @@ bool LRF_TwinConnector::create(){ #ifdef DEBUG LOG("Registered Ack Status"); #endif - uint32_t nStatus = m_pProtocol->getStatus(); - if( ( nStatus & TWI_STATUS_TARGET_MASK ) > 0 ){ + //uint32_t nStatus = getStatus(); + if( ( m_nStatus & TWI_STATUS_TARGET_MASK ) > 0 ){ #ifdef DEBUG LOG("Have new Targets!"); #endif //m_pProtocol->setTData( m_pTargets ); - m_pProtocol->requestTargets(); + requestTargets(); m_bCCMD = TWC_GET_TARGETS; continue; }; break; }; case TWC_GET_TARGETS:{ - if( m_pProtocol->getLastPackageType() == TWC_TARGETS_DATA ){ + if( getLastPackageType() == TWC_TARGETS_DATA ){ m_bCCMD = TWC_NO_COMMAND; #ifdef DEBUG LOG("Registered Ack Targets"); #endif if( m_pTracker != NULL ) { - uint8_t nCNT = (( m_pProtocol->getStatus() & TWI_STATUS_TARGET_MASK ) >> 8 ); + uint8_t nCNT = (( m_nStatus & TWI_STATUS_TARGET_MASK ) >> 8 ); for( uint8_t index = 0; index < nCNT; index++ ){ m_pTracker->validateTarget( &m_pTargets[index], false ); }; @@ -383,13 +448,21 @@ bool LRF_TwinConnector::create(){ m_pPort = new serverPort( ClientSocket ); }; if( m_pPort!= NULL ){ - m_pProtocol->setTransport( m_pPort ); + setTransport( m_pPort ); // Reset Stage m_bWorkingMode = TWI_STAGE_CONNECTED; }; }; }; }; + bool LRF_TwinConnector::attachTargetTracker( LRF_TargetTracker *ptr ){ + if(ptr == NULL) return false; + m_pTracker = ptr; + return false; + }; + bool LRF_TwinConnector::updateSettings( void ){ + return true; + }; #endif //!PRU_SLAVE bool LRF_TwinConnector::cleanTHData( uint8_t kid ){ @@ -453,13 +526,93 @@ bool LRF_TwinConnector::saveTHData( uint8_t kid, thresholdNode *ptr ){ return true; }; +bool LRF_TwinConnector::saveTHPicture( thresholdNode *ptr, CSTR fileName, bool monochrome ){ + uint8_t *tMemory = NULL; + thresholdNode *cNode = NULL; + uint8_t *cPixel = NULL; + uint8_t cSpace; + if( monochrome ) { + cSpace = 1; + } else { + cSpace = 4; + }; + tMemory = (uint8_t *) malloc( TH_SIZE_NODES * cSpace ); + if( tMemory == NULL ){ + + return false; + }; + #ifndef PRU_SLAVE -bool LRF_TwinConnector::attachTargetTracker( LRF_TargetTracker *ptr ){ - if(ptr == NULL) return false; - m_pTracker = ptr; - return false; -}; + for( int j = 0; j < Q_SCAN_COUNT; j++ ) { + for ( int i = 0; i < TH_LINE_NODES; i++ ) { + cNode = ptr+(j*i); + //cNode = ptr+( TH_LINE_NODES * j + i ); +#else + for( int j = (Q_SCAN_COUNT-1); j < -1; j++ ) { + for ( int i = 0; i < TH_LINE_NODES; i++ ) { + cNode = ptr+( TH_LINE_NODES * j + i ); #endif + cPixel = tMemory+(cSpace*i*j); + if( monochrome ) { +#ifdef CHECK_SUN_BIT + if( cNode->values.sbit ) { + cPixel[0] = 0; + } else { + cPixel[0] = (uint8_t)((((float) cNode->values.min ) * 255.f ) / 4096.f ); + }; +#else + cPixel[0] = (uint8_t)((((float) cNode->values.min ) * 255.f ) / 4096.f ); +#endif + } else { +#ifdef CHECK_SUN_BIT + if( cNode->values.sbit ) { + // Set Red + cPixel[0] = 0x00; + cPixel[1] = 0xff; + cPixel[2] = 0x00; + cPixel[3] = 0xff; + } else { + if( cNode->values.cnt == 0 ) { + // Set Blue + cPixel[0] = 0x00; + cPixel[1] = 0x00; + cPixel[2] = 0xff; + cPixel[3] = 0xff; + } else { + uint32_t tColor; + float tVal = ((float) cNode->values.min ) / 4096.f; + tColor = interpolate( 0x000000ff, 0xffffffff, tVal ); + cPixel[0] = ( tColor >> 24 ) & 0xFF; + cPixel[1] = ( tColor >> 16 ) & 0xFF; + cPixel[2] = ( tColor >> 8 ) & 0xFF; + cPixel[3] = tColor & 0xFF; + }; + }; +#else + if( cNode->values.cnt == 0 ) { + // Set Blue + cPixel[0] = 0x00; + cPixel[1] = 0x00; + cPixel[2] = 0xff; + cPixel[3] = 0xff; + } else { + uint32_t tColor; + float tVal = ((float) cNode->values.min ) / 4096.f; + tColor = interpolate( 0x000000ff, 0xffffffff, tVal ); + cPixel[0] = ( tColor >> 24 ) & 0xFF; + cPixel[1] = ( tColor >> 16 ) & 0xFF; + cPixel[2] = ( tColor >> 8 ) & 0xFF; + cPixel[3] = tColor & 0xFF; + }; +#endif + }; + }; + }; + int RetVal = stbi_write_png( fileName, TH_LINE_NODES, Q_SCAN_COUNT, cSpace, tMemory, TH_LINE_NODES * cSpace ); + free( tMemory ); + if( RetVal == 0 ) return false; + return true; +}; #undef LOG #undef LOG_ERROR diff --git a/lib/App/3dSERVER/LRF_TwinConnector.h b/lib/App/3dSERVER/LRF_TwinConnector.h index 232dcae7..a6987d84 100644 --- a/lib/App/3dSERVER/LRF_TwinConnector.h +++ b/lib/App/3dSERVER/LRF_TwinConnector.h @@ -13,6 +13,7 @@ #define TWI_SLOW_LOOP_SLEEP 100 #define TWI_STATUS_LOOP_MS 500 #define TWI_RECONNECT_LOOP_SLEEP 1000 +#define TWI_DRAW_LOOP_MS 300000 // 5 minutes; #define STORAGE_DIR_MODE 0x1FF @@ -36,32 +37,40 @@ typedef enum E_TWI_WM{ class LRF_Kernel; class LRF_TargetTracker; -class LRF_TwinConnector: public basicThread { +#ifdef PRU_SLAVE + class LRF_TwinConnector: public basicThread, protocolInternalLRF3D_SLAVE { +#else + class LRF_TwinConnector: public basicThread, protocolInternalLRF3D_MASTER { +#endif private: basicLogCollection * m_pLog; config_setting_t * m_pSettings; + TWIN_COMMAND m_bCCMD; basicMutex CMD_PROTEC; LRF_Kernel * m_pEngine; uint8_t m_bWorkingMode; + + uint32_t m_nStatus; + basicMutex m_mStatusProtector; + #ifdef PRU_SLAVE + clientPort * m_pPort; TWIN_COMMAND_QUEUE m_qCMD; - protocolInternalLRF3D_SLAVE * m_pProtocol; - clientPort * m_pPort; uint16_t m_nMasterPort; CSTR m_pMasterAddress; #else - protocolInternalLRF3D_MASTER * m_pProtocol; serverPort * m_pPort; int m_nMainSocket; LRF_TargetTracker * m_pTracker; uint16_t m_nBindPort; CSTR m_pBindAddress; - targetRecord m_pTargets[TWI_TARGET_QUEUE_SIZE]; - LGS_PARAMETERS m_sPARAMETERS[2]; + //targetRecord m_pTargets[TWI_TARGET_QUEUE_SIZE]; #endif + bool saveTHPicture( thresholdNode *ptr, CSTR fileName, bool monochrome ); protected: - void m_fThreadProc( void ); + void m_fThreadProc( void ); // Connection Handling Thread + virtual bool packetHandler( protocolPackage *Package ); public: explicit LRF_TwinConnector( config_setting_t *Settings = NULL ); virtual ~LRF_TwinConnector(); @@ -76,9 +85,7 @@ class LRF_TwinConnector: public basicThread { bool sendEvent(); #else bool attachTargetTracker( LRF_TargetTracker *ptr ); - bool requestCurrentSettings( void ); - bool requestSoftwareVersion( void ); - bool updateCurrentSettings( void ); + bool updateSettings( void ); #endif }; diff --git a/lib/data/protocol/protocol.cpp b/lib/data/protocol/protocol.cpp index 1fd586a2..849eb17d 100644 --- a/lib/data/protocol/protocol.cpp +++ b/lib/data/protocol/protocol.cpp @@ -14,7 +14,7 @@ protocolParser::protocolParser() : m_mBufferProtectorMutex(){ m_pCustomHandler = NULL; m_bBufferAltered = false; m_bStatus = 1; - m_bThreadStatus = TH_PRE_INIT; + m_bParserThreadStatus = TH_PRE_INIT; m_eConnectionStatus = CS_UNKNOWN; }; @@ -22,12 +22,12 @@ protocolParser::~protocolParser(){ # ifdef DEBUG LOG("Destructor Begin"); # endif - if (m_bThreadStatus > TH_ARMED ) { - waitThreadEnd( true ); + if (m_bParserThreadStatus > TH_ARMED ) { + waitParserThreadEnd( true ); }; m_mBufferProtectorMutex.unlock(); - if (m_bThreadStatus < TH_ENDED ) { - waitThreadEnd( true ); + if (m_bParserThreadStatus < TH_ENDED ) { + waitParserThreadEnd( true ); }; if( m_pParserBuffer != NULL ) { free( m_pParserBuffer ); @@ -39,19 +39,19 @@ protocolParser::~protocolParser(){ bool protocolParser::create(void){ if (m_pParserBuffer != NULL) { - if (m_bThreadStatus == TH_PRE_INIT) { - m_bThreadStatus = TH_ARMED; + if (m_bParserThreadStatus == TH_PRE_INIT) { + m_bParserThreadStatus = TH_ARMED; #if defined( __linux__ ) || defined(WIN_PTHREAD) - int RetVal = pthread_create( &m_sThreadHandler, NULL, m_fThreadEntryPoint, ( void * ) this ); + int RetVal = pthread_create( &m_sParserThreadHandler, NULL, m_fParserThreadEntryPoint, ( void * ) this ); if( RetVal == -1 ) { LOG_ERROR("Thread Creation Failed."); return false; }; #else - m_hThreadHandle = CreateThread( + m_hParserThreadHandle = CreateThread( NULL, 0, - (LPTHREAD_START_ROUTINE)m_fThreadEntryPoint, + (LPTHREAD_START_ROUTINE)m_fParserThreadEntryPoint, (LPVOID)this, 0, &m_dwThreadID ); @@ -106,17 +106,17 @@ void protocolParser::dataEraser( U8 *&tPtr ){ tPtr = NULL; }; -void protocolParser::m_fThreadProc(void){ +void protocolParser::m_fParserThreadProc(void){ int RetVal; - m_bThreadStatus = TH_WORKING; - while(m_bThreadStatus < TH_ENDED){ + m_bParserThreadStatus = TH_WORKING; + while(m_bParserThreadStatus < TH_ENDED){ if( m_eConnectionStatus < CS_DISCONNECTED ){ - if( ( m_bBufferAltered == false ) && ( m_bThreadStatus < TH_ENDED ) ) { + if( ( m_bBufferAltered == false ) && ( m_bParserThreadStatus < TH_ENDED ) ) { SLEEP(3); continue; }; m_mBufferProtectorMutex.lock(); - while ((m_nParserDataCount > 0) && (m_bThreadStatus < TH_ENDED)){ + while ((m_nParserDataCount > 0) && (m_bParserThreadStatus < TH_ENDED)){ #ifdef DUBUG_COMMUNICATION LOG("Check Pack"); #endif @@ -166,21 +166,21 @@ void protocolParser::m_fThreadProc(void){ m_mBufferProtectorMutex.unlock(); } else { // Handle Disconnect - m_bThreadStatus = TH_ENDED; + m_bParserThreadStatus = TH_ENDED; }; }; }; #if defined( __linux__ ) || defined(WIN_PTHREAD) - void *protocolParser::m_fThreadEntryPoint( void *ptr ){ + void *protocolParser::m_fParserThreadEntryPoint( void *ptr ){ #else - DWORD WINAPI protocolParser::m_fThreadEntryPoint( LPVOID ptr){ + DWORD WINAPI protocolParser::m_fParserThreadEntryPoint( LPVOID ptr){ #endif protocolParser *mThis; mThis = ( protocolParser * ) ptr; - if( mThis->m_bThreadStatus == TH_ARMED ) { - mThis->m_fThreadProc(); - mThis->m_bThreadStatus = TH_EXIT; + if( mThis->m_bParserThreadStatus == TH_ARMED ) { + mThis->m_fParserThreadProc(); + mThis->m_bParserThreadStatus = TH_EXIT; } else { SLOG_ERROR("Thread is not ARMED!"); }; @@ -192,19 +192,19 @@ void protocolParser::m_fThreadProc(void){ #endif }; -void protocolParser::waitThreadEnd(bool forced){ +void protocolParser::waitParserThreadEnd(bool forced){ - if( m_bThreadStatus > TH_WORKING || m_bThreadStatus < TH_ARMED ) return; + if( m_bParserThreadStatus > TH_WORKING || m_bParserThreadStatus < TH_ARMED ) return; - if( forced ) m_bThreadStatus = TH_ENDED; - while (m_bThreadStatus != TH_EXIT){ + if( forced ) m_bParserThreadStatus = TH_ENDED; + while (m_bParserThreadStatus != TH_EXIT){ SLEEP(DEFAULT_THREAD_SLEEP_TIME); }; #if defined( __linux__ ) || defined(WIN_PTHREAD) - pthread_join(m_sThreadHandler, NULL); + pthread_join(m_sParserThreadHandler, NULL); #else - WaitForSingleObject(m_hThreadHandle, 2000); - CloseHandle(m_hThreadHandle); + WaitForSingleObject(m_hParserThreadHandle, 2000); + CloseHandle(m_hParserThreadHandle); #endif }; diff --git a/lib/data/protocol/protocol.h b/lib/data/protocol/protocol.h index 2d1a09f3..36e94fdf 100644 --- a/lib/data/protocol/protocol.h +++ b/lib/data/protocol/protocol.h @@ -25,33 +25,32 @@ typedef std::vector< protocolPackage *> packagePoll; class protocolParser { private: + basicLogCollection *m_pLog; U8 *m_pParserBuffer; size_t m_nParserDataCount; bool m_bBufferAltered; basicMutex m_mBufferProtectorMutex; #if defined( __linux__ ) || defined(WIN_PTHREAD) - pthread_t m_sThreadHandler; - static void *m_fThreadEntryPoint(void *); + pthread_t m_sParserThreadHandler; + static void *m_fParserThreadEntryPoint(void *); #else - HANDLE m_hThreadHandle; + HANDLE m_hParserThreadHandle; DWORD m_dwThreadID; - static DWORD WINAPI m_fThreadEntryPoint( LPVOID lpParameter ); + static DWORD WINAPI m_fParserThreadEntryPoint( LPVOID lpParameter ); #endif - protected: - basicLogCollection *m_pLog; + thredStatus m_bParserThreadStatus; + void m_fParserThreadProc(void); + void waitParserThreadEnd( bool forced = false ); + protected: basicTransport *m_oDataTransport; CONNECTION_STATUS m_eConnectionStatus; U8 m_bStatus; packagePoll m_vPackagePool; - thredStatus m_bThreadStatus; - - void m_fThreadProc(void); virtual int packetChecker(U8 *Buffer, size_t BufferSize){ return 0;}; virtual protocolPackage *packetExtractor(U8 *Buffer, size_t BufferSize){ return NULL; }; virtual bool packetHandler( protocolPackage *Package ){ return false; }; virtual void dataEraser(U8*& tPtr); void (*m_pCustomHandler)( protocolPackage *pPp ); - void waitThreadEnd( bool forced = false ); public: protocolParser(); virtual ~protocolParser(); diff --git a/lib/data/protocol/protocolInternalLRF3D.cpp b/lib/data/protocol/protocolInternalLRF3D.cpp index b9d8f89f..13fe5474 100644 --- a/lib/data/protocol/protocolInternalLRF3D.cpp +++ b/lib/data/protocol/protocolInternalLRF3D.cpp @@ -13,7 +13,6 @@ protocolInternalLRF3D::protocolInternalLRF3D(): protocolParser(){ m_pLog = basicLogCollection::getInstance(); - m_nStatus = 0; }; protocolInternalLRF3D::~protocolInternalLRF3D(){}; @@ -123,13 +122,13 @@ protocolPackage *protocolInternalLRF3D::packetExtractor( U8 *Buffer, size_t Buff return NULL; }; -uint32_t protocolInternalLRF3D::getStatus(){ - uint32_t RetVal; - m_mStatusProtector.lock(); - RetVal = m_nStatus; - m_mStatusProtector.unlock(); - return RetVal; -}; +//uint32_t protocolInternalLRF3D::getStatus(){ +// uint32_t RetVal; +// m_mStatusProtector.lock(); +// RetVal = m_nStatus; +// m_mStatusProtector.unlock(); +// return RetVal; +//}; #undef LOG @@ -279,17 +278,6 @@ uint32_t protocolInternalLRF3D::getStatus(){ return m_oDataTransport->sendData( Buffer, FinishUpPackage( Buffer, 8 ) ); }; - bool protocolInternalLRF3D_SLAVE::packetHandler( protocolPackage *Package ){ - if( Package == NULL ) return false; - TWIN_COMMAND cCMD = (TWIN_COMMAND) Package->m_pData[3]; - switch( cCMD ) { - case TWC_GET_STATUS:{ - sendStatus(); - break; - }; - }; - return true; - }; #else // PRU_SLAVE #define LOG( X ) m_pLog->Log( "protocolLRF3D_MASTER", this, X ) #ifdef DEBUG @@ -368,30 +356,6 @@ uint32_t protocolInternalLRF3D::getStatus(){ return m_oDataTransport->sendData( Buffer, FinishUpPackage( Buffer, 4 ) ); }; - bool protocolInternalLRF3D_MASTER::packetHandler( protocolPackage *Package ){ - if( Package == NULL ) return false; - TWIN_COMMAND cCMD = (TWIN_COMMAND)Package->m_pData[3]; - switch( cCMD ) { - case TWC_ACK_STATUS:{ - uint32_t tStatus; -#ifdef DEBUG - LOG("Status ACK reseived"); -#endif - tStatus = ( Package->m_pData[4] << 24 ) | ( Package->m_pData[5] << 16 ) | ( Package->m_pData[6] << 8 ) | Package->m_pData[7]; - m_mStatusProtector.lock(); - m_nStatus = tStatus; - m_mStatusProtector.unlock(); - break; - }; - case TWC_TH_DATA:{ - - }; - }; - m_mLastTypeProtector.lock(); - m_bLastPackageType = cCMD; - m_mLastTypeProtector.unlock(); - return true; - }; TWIN_COMMAND protocolInternalLRF3D_MASTER::getLastPackageType( void ){ TWIN_COMMAND RetVal; m_mLastTypeProtector.lock(); diff --git a/lib/data/protocol/protocolInternalLRF3D.h b/lib/data/protocol/protocolInternalLRF3D.h index 1d4f0dac..5ca1b260 100644 --- a/lib/data/protocol/protocolInternalLRF3D.h +++ b/lib/data/protocol/protocolInternalLRF3D.h @@ -73,8 +73,6 @@ class protocolInternalLRF3D: public protocolParser { private: basicLogCollection *m_pLog; protected: - uint32_t m_nStatus; - basicMutex m_mStatusProtector; int packetChecker( U8 *Buffer, size_t BufferSize ); protocolPackage *packetExtractor( U8 *Buffer, size_t BufferSize ); inline int FinishUpPackage( U8 *Buffer, size_t Size ){ @@ -88,19 +86,19 @@ class protocolInternalLRF3D: public protocolParser { protocolInternalLRF3D(); virtual ~protocolInternalLRF3D(); virtual bool create(){ return protocolParser::create(); }; - uint32_t getStatus(); + //uint32_t getStatus(); }; #ifdef PRU_SLAVE class protocolInternalLRF3D_SLAVE: public protocolInternalLRF3D{ private: - basicLogCollection *m_pLog; + basicLogCollection *m_pLog; + protected: thresholdNode *m_pThresholds[16]; // 8 - learning 8 - working basicMutex m_mData; bool sendTrasholdData( uint8_t lrf_id, uint32_t dataIdx = 0 ); bool sendTargets( void ); bool sendStatus( void ); - protected: - virtual bool packetHandler( protocolPackage *Package ); + virtual bool packetHandler( protocolPackage *Package ){ return true; }; public: protocolInternalLRF3D_SLAVE(); virtual ~protocolInternalLRF3D_SLAVE(); @@ -112,15 +110,15 @@ class protocolInternalLRF3D: public protocolParser { #else //!PRU_SLAVE class protocolInternalLRF3D_MASTER: public protocolInternalLRF3D{ private: - basicLogCollection * m_pLog; - TWIN_COMMAND m_bLastPackageType; + basicLogCollection * m_pLog; + protected: + virtual bool packetHandler( protocolPackage *Package ){ return true; }; basicMutex m_mLastTypeProtector; + TWIN_COMMAND m_bLastPackageType; thresholdNode * m_pTrashold; targetRecord m_pTargets[TWI_TARGET_QUEUE_SIZE]; uint8_t m_nTargetCount; basicMutex m_mTargetProtector; - protected: - bool packetHandler( protocolPackage *Package ); public: protocolInternalLRF3D_MASTER(); virtual ~protocolInternalLRF3D_MASTER(); diff --git a/lib/hardware/soc/general/3DLRF.h b/lib/hardware/soc/general/3DLRF.h index 0e6c9670..5f31a8fd 100644 --- a/lib/hardware/soc/general/3DLRF.h +++ b/lib/hardware/soc/general/3DLRF.h @@ -660,10 +660,10 @@ enum { // }; // x = sid % TH_LINE_NODES; // }; - inline int32_t makeIds( int x, int y, bool Master = true ){ + inline uint32_t makeIds( int x, int y, bool Master = true ){ return (Master)?(288-y)*TH_LINE_NODES+x:y*TH_LINE_NODES+x; }; - inline int interpolate(int color1, int color2, float progress) { + inline uint32_t interpolate(int color1, int color2, float progress) { int a1 = (color1 & 0xff000000) >> 24; int r1 = (color1 & 0x00ff0000) >> 16; int g1 = (color1 & 0x0000ff00) >> 8; @@ -683,7 +683,7 @@ enum { return (newA << 24) + (newR << 16) + (newG << 8) + newB; }; - inline int makeSID(int kID, int qID, int bID){ + inline uint32_t makeSID(int kID, int qID, int bID){ int cid; int cqid; int mid;