diff --git a/Projects/la_mojo/build b/Projects/la_mojo/build index 5181f2f3..8c1e4e77 100755 --- a/Projects/la_mojo/build +++ b/Projects/la_mojo/build @@ -7,7 +7,7 @@ #make clean -e "CFG=LRF_Proxy_ONLY" #make -e "CFG=LRF_Proxy_ONLY" -j$(nproc) -#make clean -e "CFG=Debug86" +make clean -e "CFG=Debug86" make -e "CFG=Debug86" -j$(nproc) #cd Debug86 #strip ./mojo_d diff --git a/lib/App/common/deviceNodeCamera.cpp b/lib/App/common/deviceNodeCamera.cpp index 8c745bbe..df20d95e 100644 --- a/lib/App/common/deviceNodeCamera.cpp +++ b/lib/App/common/deviceNodeCamera.cpp @@ -1442,6 +1442,7 @@ void deviceNodeCamera::m_fThreadProc(void) }; setWM( CAM_WS_READY ); };*/ + LOG("INit GoHome"); setWM(CAM_WS_READY); break; }; diff --git a/lib/App/common/deviceNodeEthernet2Serial.cpp b/lib/App/common/deviceNodeEthernet2Serial.cpp index a820346b..f9719a21 100644 --- a/lib/App/common/deviceNodeEthernet2Serial.cpp +++ b/lib/App/common/deviceNodeEthernet2Serial.cpp @@ -23,12 +23,19 @@ deviceETH2UART::deviceETH2UART(uint32_t nodeID) : deviceNode(nodeID), hardwareResource(), basicTransport(), +#ifdef SERIAL_PING_PONG + basicThread() +#else basicDualThread() +#endif { // m_pLog = basicLogCollection::getInstance(); memset(&m_sUartData, 0, sizeof(m_sUartData)); +#ifdef SERIAL_PING_PONG +#else m_nInputBufferSize = 0; m_nOutputBufferSize = 0; +#endif m_iDeviceFD = -1; m_iMasterFD = -1; m_iInFID = -1; @@ -640,8 +647,11 @@ bool deviceETH2UART::closePort() //char tBuff[128]; setConnectionStatus(CS_DISCONNECTED); - +#ifdef SERIAL_PING_PONG + if (m_bThreadStatus != TH_PRE_INIT) +#else if (m_bThreadAStatus != TH_PRE_INIT && m_bThreadBStatus != TH_PRE_INIT) +#endif { uninit(); }; @@ -697,7 +707,134 @@ bool deviceETH2UART::closePort() }; return true; } +#ifdef SERIAL_PING_PONG +void deviceETH2UART::m_fThreadProc(void) +{ + int index; + int RetVal; + m_bThreadStatus = TH_WORKING; +#ifdef DEBUG + LOG("Sender Thread Started!"); +#endif + pthread_setname_np( pthread_self(), "E2S IO" ); + while (m_bThreadStatus < TH_ENDED){ + m_mBufferProtectorMutex.lock(); + if (! m_qIO.empty()){ + SIO_TZ * tIOData; + tIOData = m_qIO.front(); + m_mBufferProtectorMutex.unlock(); + if( tIOData ){ + // Remove from Queue + m_mBufferProtectorMutex.lock(); + m_qIO.pop(); + m_mBufferProtectorMutex.unlock(); + + index = 0; + //Sending Data to line + while ((index < tIOData->out_size) && (m_bThreadStatus < TH_ENDED)){ + #ifdef DEBUG_COMMUNICATION + char TT[128]; + sprintf(TT, "Send \t%d bytes for \t%p", ( tIOData->out_size - index ), tIOData->boundParser ); + LOG(TT); + #endif + RetVal = sendBlock(tIOData->out_buffer + index, tIOData->out_size - index); + if (RetVal > 0){ + index += RetVal; + } else { + // if 0 or -(error) + if (RetVal == 0) { + usleep(100); + } else { + setConnectionStatus(CS_DISCONNECTED); + // m_nOutputBufferSize = 0; + tIOData->out_size = 0; + m_bThreadStatus = TH_ENDED; + LOG_ERROR("Connection Droped on Sending Data"); + }; + }; + }; + //Try to receive data from line + tIOData->out_size = 0; + bool tDataOnline = false; + uint8_t tTOCounter = 20; + do { + RetVal = recptBlock( tIOData->inp_buffer, &tIOData->inp_size ); + if( RetVal == -1 ){ + setConnectionStatus(CS_DISCONNECTED); + tIOData->inp_size = 0; + m_bThreadStatus = TH_ENDED; + LOG_ERROR("Connection Droped on Reception Data"); + } else if( tIOData->inp_size ){ + tDataOnline = true; + if( tIOData->boundParser == NULL ){ + + } else { + #ifdef DEBUG_COMMUNICATION + char tB[128]; + sprintf( tB, "Read \t%d bytes for \t%p", tIOData->inp_size, tIOData->boundParser ); + LOG( tB ); + #endif + tDataOnline = tIOData->boundParser->parse( tIOData->inp_buffer, tIOData->inp_size ); + }; + } else { + if (tTOCounter) { + tTOCounter--; + SLEEP(5); + #ifdef DEBUG_COMMUNICATION + } else { + LOG_ERROR("PACK TIMEOUT!"); + #endif + }; + }; + + } while ((m_bThreadStatus < TH_ENDED) && tTOCounter && ! (tDataOnline && RetVal == 0)); // Pack1 conditions -> White Space after Data. + // Free Package + #ifdef DEBUG_COMMUNICATION + LOG("Finishing Read Package"); + #endif + free(tIOData); + } else { + // Mutex already unlocked! + SLEEP(5); + }; + } else { + m_mBufferProtectorMutex.unlock(); + SLEEP(5); + }; + }; +} + +bool deviceETH2UART::sendData(uint8_t * Data, int DataSize, protocolParser *src ){ + if ( m_bThreadStatus != TH_WORKING ) { + if( m_bThreadStatus < TH_WORKING ) { + LOG_ERROR("Trying to Send Data Before Thread is Started!"); + } else { + LOG_ERROR("Trying to Send Data After Thread is Dead!"); + } + return false; + }; + if (DataSize > MAXIMAL_SERIAL_IO_BUFFER_LENGTH) { + LOG_ERROR("Data Too BIG"); + } else { + SIO_TZ * tData = (SIO_TZ *) malloc(sizeof(SIO_TZ)); + if (tData) { + memset( tData, 0, sizeof(SIO_TZ) ); + tData->out_size = DataSize; + tData->boundParser = src; + memcpy( tData->out_buffer, Data, DataSize ); + m_mBufferProtectorMutex.lock(); + m_qIO.push(tData); + m_mBufferProtectorMutex.unlock(); + return true; + } else { + LOG_ERROR("MemAlloc Error!"); + }; + }; + return false; +} + +#else // !SERIAL_PING_PONG void deviceETH2UART::m_fThreadAProc(void) { int index; @@ -820,6 +957,7 @@ bool deviceETH2UART::sendData(uint8_t * Data, int DataSize) m_mBufferProtectorMutex.unlock(); return true; } +#endif // !SERIAL_PING_PONG bool deviceETH2UART::reconnect(void) { diff --git a/lib/App/common/deviceNodeEthernet2Serial.h b/lib/App/common/deviceNodeEthernet2Serial.h index 47f1d942..5d86e7f3 100644 --- a/lib/App/common/deviceNodeEthernet2Serial.h +++ b/lib/App/common/deviceNodeEthernet2Serial.h @@ -2,10 +2,14 @@ #define __DEVICE_NODE_ETHERNET2SERIAL_HEADER__ #include "../../data/transport/transportSocket.h" +//#include "../components/base/basicTransport.h" #include "deviceNode.h" #include "hardwareResource.h" - -class deviceETH2UART : public deviceNode, public hardwareResource, public basicTransport, public basicDualThread +#ifdef SERIAL_PING_PONG + class deviceETH2UART : public deviceNode, public hardwareResource, public basicTransport, public basicThread +#else + class deviceETH2UART : public deviceNode, public hardwareResource, public basicTransport, public basicDualThread +#endif { private: @@ -28,22 +32,27 @@ class deviceETH2UART : public deviceNode, public hardwareResource, public basicT int recptBlock(unsigned char * Buffer, int * BufferLength); protected: - - U8 m_pInputBuffer[MAXIMAL_SOCKET_IO_BUFFER_LENGTH]; +#ifdef SERIAL_PING_PONG + virtual void m_fThreadProc(void); + Q_SIO_TZ m_qIO; +#else + U8 m_pInputBuffer[MAXIMAL_SOCKET_IO_BUFFER_LENGTH]; U8 m_pOutputBuffer[MAXIMAL_SOCKET_IO_BUFFER_LENGTH]; int m_nInputBufferSize; int m_nOutputBufferSize; - virtual void m_fThreadAProc(void); virtual void m_fThreadBProc(void); - +#endif public: - explicit deviceETH2UART(uint32_t nodeID); ~deviceETH2UART(); virtual bool create(void); virtual bool validate(void); +#ifdef SERIAL_PING_PONG + virtual bool sendData(uint8_t * Data, int DataSize, protocolParser *src = NULL ); +#else virtual bool sendData(uint8_t * Data, int DataSize); +#endif virtual bool reconnect(void); }; diff --git a/lib/App/common/hardwareResourceSerialProvider.cpp b/lib/App/common/hardwareResourceSerialProvider.cpp index 7e48c633..3c89ce37 100644 --- a/lib/App/common/hardwareResourceSerialProvider.cpp +++ b/lib/App/common/hardwareResourceSerialProvider.cpp @@ -1169,10 +1169,31 @@ void hardwareResourceSerialProvider::m_fThreadProc(void) LOG_ERROR("Connection Droped on Reception Data"); } else if( tIOData->inp_size ){ tDataOnline = true; +#ifndef SERIAL_PING_PONG + do { + m_mQueueProtectorMutex.lock(); + if( m_vParsers.size() ){ + for( parseQueue::iterator idx = m_vParsers.begin(); idx != m_vParsers.end(); idx++) { + (*idx)->parse(tIOData->inp_buffer, tIOData->inp_size); + } + tIOData->inp_size = 0; + m_mQueueProtectorMutex.unlock(); + } else { + #ifdef DEBUG_EXTRA + LOG( m_sUartData.path ); + LOG((char *) tIOData->inp_buffer ); + LOG_ERROR("Try to parse data but No Parsers Assigned!"); + #endif + tIOData->inp_size = 0; + m_mQueueProtectorMutex.unlock(); + SLEEP(100); + }; + } while ((m_vParsers.size() == 0) && (m_bThreadStatus < TH_ENDED)); +#else if( tIOData->boundParser == NULL ){ //No Specified Parser in Package!! /* - do { + do { m_mQueueProtectorMutex.lock(); if( m_vParsers.size() ){ for( parseQueue::iterator idx = m_vParsers.begin(); idx != m_vParsers.end(); idx++) { @@ -1190,7 +1211,7 @@ void hardwareResourceSerialProvider::m_fThreadProc(void) m_mQueueProtectorMutex.unlock(); SLEEP(100); }; - } while ((m_vParsers.size() == 0) && (m_bThreadStatus < TH_ENDED)); + } while ((m_vParsers.size() == 0) && (m_bThreadStatus < TH_ENDED)); */ } else { #ifdef DEBUG_COMMUNICATION @@ -1200,6 +1221,7 @@ void hardwareResourceSerialProvider::m_fThreadProc(void) #endif tDataOnline = tIOData->boundParser->parse( tIOData->inp_buffer, tIOData->inp_size ); }; +#endif //SERIAL_PING_PONG } else { if (tTOCounter) { tTOCounter--; @@ -1227,8 +1249,11 @@ void hardwareResourceSerialProvider::m_fThreadProc(void) }; }; } - -bool hardwareResourceSerialProvider::sendData(uint8_t * Data, int DataSize, protocolParser *src) +#ifdef SERIAL_PING_PONG + bool hardwareResourceSerialProvider::sendData(uint8_t * Data, int DataSize, protocolParser *src) +#else + bool hardwareResourceSerialProvider::sendData(uint8_t * Data, int DataSize ) +#endif { if (m_bThreadStatus != TH_WORKING) { @@ -1253,7 +1278,9 @@ bool hardwareResourceSerialProvider::sendData(uint8_t * Data, int DataSize, prot { memset( tData, 0, sizeof(SIO_TZ) ); tData->out_size = DataSize; +#ifdef SERIAL_PING_PONG tData->boundParser = src; +#endif memcpy( tData->out_buffer, Data, DataSize ); m_mBufferProtectorMutex.lock(); m_qIO.push(tData); diff --git a/lib/App/common/hardwareResourceSerialProvider.h b/lib/App/common/hardwareResourceSerialProvider.h index e054c748..f8234808 100644 --- a/lib/App/common/hardwareResourceSerialProvider.h +++ b/lib/App/common/hardwareResourceSerialProvider.h @@ -43,26 +43,7 @@ // #define DEBUG_SERIAL_COMMUNICATION #endif -#ifndef MAXIMAL_SERIAL_IO_BUFFER_LENGTH - #define MAXIMAL_SERIAL_IO_BUFFER_LENGTH 102400 -#endif - -#if defined( HALF_DUPLEX ) || defined( SERIAL_PING_PONG ) - #include - typedef struct S_SIO_TZ { - bool wReplay; - bool finished; - bool success; - int inp_size; - int out_size; -#ifdef SERIAL_PING_PONG - protocolParser * boundParser; -#endif - uint8_t out_buffer[MAXIMAL_SERIAL_IO_BUFFER_LENGTH]; - uint8_t inp_buffer[MAXIMAL_SERIAL_IO_BUFFER_LENGTH]; - } SIO_TZ; - - typedef std::queue Q_SIO_TZ; +#if defined( HALF_DUPLEX ) || defined( SERIAL_PING_PONG ) class hardwareResourceSerialProvider : public hardwareResource, public basicTransport, public basicThread { diff --git a/lib/App/common/kernelModuleModemManager.cpp b/lib/App/common/kernelModuleModemManager.cpp index 961091d1..60bba970 100644 --- a/lib/App/common/kernelModuleModemManager.cpp +++ b/lib/App/common/kernelModuleModemManager.cpp @@ -516,48 +516,31 @@ void kernelModuleModemManager::m_fThreadProc(void) }; } -bool kernelModuleModemManager::dispatchEvent(EVENT_CONTAINER * Evt) -{ - if (moduleActive) - { - if (Evt == NULL) - { - return false; - } -#ifdef DEBUG_EXTRA - if (Evt->m_eClass == EVT_CLASS_SYSTEM) - { - if (Evt->m_eType == EVT_LRF_START_SESSION) - { - sessionStarted = true; - setWM(MDM_INIT_CALL_WM); - }; - if (Evt->m_eType == EVT_LRF_END_SESSION_TO || Evt->m_eType == EVT_LRF_END_SESSION_MA) - { - }; - }; -#endif - if (sessionStarted) - { - return true; - } - - switch (Evt->m_eType) - { +bool kernelModuleModemManager::dispatchEvent(EVENT_CONTAINER * Evt){ + if (moduleActive){ + if (Evt == NULL) return false; + switch (Evt->m_eType){ case EVT_TARGET_1D: case EVT_TARGET_3D_WHITE: case EVT_TARGET_3D_BLACK: case EVT_TARGET_2D_WHITE: - case EVT_TARGET_2D_BLACK: - { - //Only Work On Session Start -> No need to follow each detection - //sessionStarted = true; - //setWM(MDM_INIT_CALL_WM); + case EVT_TARGET_2D_BLACK:{ + if (!sessionStarted) { + //Only Work On Session Start -> No need to follow each detection + sessionStarted = true; + setWM(MDM_INIT_CALL_WM); + }; break; }; + case EVT_LRF_START_SESSION:{ + if (!sessionStarted) { + sessionStarted = true; + setWM(MDM_INIT_CALL_WM); + }; + break; + }; case EVT_LRF_END_SESSION_TO: - case EVT_LRF_END_SESSION_MA: - { + case EVT_LRF_END_SESSION_MA:{ sessionStarted = false; break; }; diff --git a/lib/components/base/basicTransport.h b/lib/components/base/basicTransport.h index 5e3b5f80..0e93a4ee 100644 --- a/lib/components/base/basicTransport.h +++ b/lib/components/base/basicTransport.h @@ -6,15 +6,40 @@ #include #include - -#define SERIAL_PING_PONG +#include #ifdef DEBUG // #ifndef DUBUG_COMMUNICATION - // #define DUBUG_COMMUNICATION + // #define DUBUG_COMMUNICATION // #endif #endif +#define SERIAL_PING_PONG + +#ifdef SERIAL_PING_PONG + class protocolParser; +#endif + + +#ifndef MAXIMAL_SERIAL_IO_BUFFER_LENGTH + #define MAXIMAL_SERIAL_IO_BUFFER_LENGTH 102400 +#endif + +typedef struct S_SIO_TZ { + bool wReplay; + bool finished; + bool success; + int inp_size; + int out_size; +#ifdef SERIAL_PING_PONG + protocolParser * boundParser; +#endif + uint8_t out_buffer[MAXIMAL_SERIAL_IO_BUFFER_LENGTH]; + uint8_t inp_buffer[MAXIMAL_SERIAL_IO_BUFFER_LENGTH]; +} SIO_TZ; + +typedef std::queue Q_SIO_TZ; + class protocolParser; typedef std::vector parseQueue; diff --git a/lib/data/transport/transportSocket.h b/lib/data/transport/transportSocket.h index 7e0d60bf..c52b78f4 100644 --- a/lib/data/transport/transportSocket.h +++ b/lib/data/transport/transportSocket.h @@ -22,20 +22,18 @@ class transportSocket : public basicTransport, public basicDualThread basicLogCollection * m_pLog; protected: - U8 m_pInputBuffer[MAXIMAL_SOCKET_IO_BUFFER_LENGTH]; U8 m_pOutputBuffer[MAXIMAL_SOCKET_IO_BUFFER_LENGTH]; int m_nInputBufferSize; int m_nOutputBufferSize; + virtual void m_fThreadAProc(void); + virtual void m_fThreadBProc(void); int m_nSenderSetMax; int m_nReaderSetMax; fd_set m_sSenderSet; fd_set m_sReaderSet; int m_iControlPipeFD[2]; - bool m_bInitComplete; - - virtual void m_fThreadAProc(void); - virtual void m_fThreadBProc(void); + bool m_bInitComplete; virtual int sendBlock(unsigned char * Data, int DataSize) { @@ -55,7 +53,7 @@ class transportSocket : public basicTransport, public basicDualThread transportSocket(); virtual ~transportSocket(); - virtual bool sendData(unsigned char * Data, int DataSize); + virtual bool sendData(unsigned char * Data, int DataSize); virtual bool reconnect(void) {