#include "protocolTGZ.h" #define LOG( X ) m_pLog->Log( "protocolTGZ", this, X ) #define LOG_ERROR( X ) m_pLog->Log( "protocolTGZ", this, _LOG_ERROR, X ) protocolTGZ::protocolTGZ( basicTransport *canBus /*, U8 MyID, U8 PeerID */ ): protocolParser(){ m_pLog = basicLogCollection::getInstance(); lastSent = 0; preparing = 0; lastReceived = 0; m_bRun = false; m_bErrorReset = false; m_bPRF = 0; m_bRatio = 0; m_bDivider = 1; m_oDataTransport = canBus; if( m_oDataTransport != NULL ){ m_oDataTransport->addRecipient( this ); }; //m_bHostID = MyID; //m_bDeviceID = PeerID; m_nQFreq = 0; m_nBFreq = 0; m_bVersion2 = false; update(); }; int protocolTGZ::packetChecker( U8 *Buffer, size_t BufferSize ){ if( BufferSize > 3 ) { lastReceived = (Buffer[3]<<24)|(Buffer[2]<<16)|(Buffer[1]<<8)|Buffer[0]; LOG("Rcpt Package"); return 0; } else return -1; }; protocolPackage *protocolTGZ::packetExtractor(U8 *Buffer, size_t BufferSize ){ protocolPackage *RetVal = NULL; if( BufferSize > 3 ) { lastReceived = (Buffer[3]<<24)|(Buffer[2]<<16)|(Buffer[1]<<8)|Buffer[0]; RetVal = (protocolPackage *)malloc(sizeof(protocolPackage)); if(RetVal!= NULL) { RetVal->m_nSize = BufferSize; RetVal->m_pData = (U8*)malloc(BufferSize); if( RetVal->m_pData != NULL ) { memcpy(RetVal->m_pData, Buffer, BufferSize); } else { RetVal->m_nSize = 0; }; }; char text[256]; sprintf( text,"Extracted Package [0x%02X][0x%02X][0x%02X][0x%02X]",Buffer[0],Buffer[1],Buffer[2],Buffer[3] ); LOG( text ); }; return RetVal; }; bool protocolTGZ::startDeviceStateInquiry( void ){ LOG("Start Device Inquiry"); //if( this ){ U8 Buffer[4]; Buffer[0]=( preparing & 0xFF ); Buffer[1]=(( preparing >> 8 ) & 0xFF); Buffer[2]=(( preparing >> 16 ) & 0xFF); Buffer[3]=(( preparing >> 24 ) & 0xFF); char text[256]; sprintf( text,"Buffer is set [0x%02X][0x%02X][0x%02X][0x%02X]",Buffer[0],Buffer[1],Buffer[2],Buffer[3] ); LOG( text ); //Buffer[5]=checksumLGS( Buffer, 5 ); //pthread_mutex_lock( &m_mInquiryMutex ); LOG("Ask State"); lastSent = preparing; m_oDataTransport->sendData( Buffer, 4 ); //pthread_mutex_lock( &m_mInquiryMutex ); //pthread_mutex_unlock( &m_mInquiryMutex ); LOG("Ask State -> Done"); return true; //}; //return false; }; void protocolTGZ::update( void ){ preparing = 0; if( !m_bVersion2 ) { preparing = ( preparing & (~0x00000001))|((m_bErrorReset)?0x00000001:0); preparing = ( preparing & (~0x00000002))|((m_bRun)?0x00000002:0); preparing = ( preparing & (~0x0000FF00))|( m_bPRF << 8 ); preparing = ( preparing & (~0x00FF0000))|( m_bRatio << 16 ); preparing = ( preparing & (~0xFF000000))|( m_bDivider << 24 ); } else { preparing = ( preparing & (~0x00000001))|((m_bErrorReset)?0x00000001:0); preparing = ( preparing & (~0x00000002))|((m_bRun)?0x00000002:0); preparing |= ( m_nBFreq & 0x3FFF ) << 2; preparing |= ( m_nQFreq & 0xFFFF ) << 16; }; }; #undef LOG #undef LOG_ERROR