@ -1,4 +1,5 @@
# include "protocolInternalLRF3D.h"
# include "protocolInternalLRF3D.h"
# define LOG( X ) m_pLog->Log( "protocolLRF3D", this, X )
# define LOG( X ) m_pLog->Log( "protocolLRF3D", this, X )
# ifdef DEBUG
# ifdef DEBUG
# define LOG_ERROR( X ) {\
# define LOG_ERROR( X ) {\
@ -12,11 +13,10 @@
protocolInternalLRF3D : : protocolInternalLRF3D ( ) : protocolParser ( ) {
protocolInternalLRF3D : : protocolInternalLRF3D ( ) : protocolParser ( ) {
m_pLog = basicLogCollection : : getInstance ( ) ;
m_pLog = basicLogCollection : : getInstance ( ) ;
m_nStatus = 0 ;
} ;
} ;
protocolInternalLRF3D : : ~ protocolInternalLRF3D ( ) {
} ;
protocolInternalLRF3D : : ~ protocolInternalLRF3D ( ) { } ;
int protocolInternalLRF3D : : packetChecker ( U8 * Buffer , size_t BufferSize ) {
int protocolInternalLRF3D : : packetChecker ( U8 * Buffer , size_t BufferSize ) {
# ifdef DUBUG_COMMUNICATION
# ifdef DUBUG_COMMUNICATION
@ -100,7 +100,7 @@ protocolPackage *protocolInternalLRF3D::packetExtractor( U8 *Buffer, size_t Buff
return NULL ;
return NULL ;
} ;
} ;
RetVal - > m_nSize = pLength + 4 ;
RetVal - > m_nSize = pLength + 4 ;
RetVal - > m_nCode = Buffer [ CMD_IDX ] ;
RetVal - > m_nCode = Buffer [ 3 ] ;
memcpy ( RetVal - > m_pData , Buffer , RetVal - > m_nSize ) ;
memcpy ( RetVal - > m_pData , Buffer , RetVal - > m_nSize ) ;
# ifdef DUBUG_COMMUNICATION
# ifdef DUBUG_COMMUNICATION
LOG ( ( CSTR ) " PacketExtractor: Packet Is Extracted (0) " ) ;
LOG ( ( CSTR ) " PacketExtractor: Packet Is Extracted (0) " ) ;
@ -123,6 +123,15 @@ protocolPackage *protocolInternalLRF3D::packetExtractor( U8 *Buffer, size_t Buff
return NULL ;
return NULL ;
} ;
} ;
uint32_t protocolInternalLRF3D : : getStatus ( ) {
uint32_t RetVal ;
m_mStatusProtector . lock ( ) ;
RetVal = m_nStatus ;
m_mStatusProtector . unlock ( ) ;
return RetVal ;
} ;
# undef LOG
# undef LOG
# undef LOG_ERROR
# undef LOG_ERROR
@ -138,85 +147,147 @@ protocolPackage *protocolInternalLRF3D::packetExtractor( U8 *Buffer, size_t Buff
# define LOG_ERROR( X ) m_pLog->Log( "protocolLRF3D_SLAVE", this, _LOG_ERROR, X );
# define LOG_ERROR( X ) m_pLog->Log( "protocolLRF3D_SLAVE", this, _LOG_ERROR, X );
# endif
# endif
protocolInternalLRF3D_SLAVE : : protocolInternalLRF3D_SLAVE ( config_setting_t * Settings ) : protocolInternalLRF3D ( ) {
protocolInternalLRF3D_SLAVE : : protocolInternalLRF3D_SLAVE ( ) : protocolInternalLRF3D ( ) {
m_pLog = basicLogCollection : : getInstance ( ) ;
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 ;
m_nTargetCount = 0 ;
memset ( m_pTargets , 0 , sizeof ( targetRecord ) * TWI_TARGET_QUEUE_SIZE ) ;
for ( uint8_t i = 0 ; i < 16 ; i + + ) {
m_pThresholds [ i ] = ( thresholdNode * ) malloc ( TH_SIZE_BYTES ) ;
if ( m_pThresholds [ i ] ! = NULL ) {
memset ( m_pThresholds [ i ] , 0 , TH_SIZE_BYTES ) ;
} ;
} ;
} ;
} ;
protocolInternalLRF3D_SLAVE : : ~ protocolInternalLRF3D_SLAVE ( ) {
protocolInternalLRF3D_SLAVE : : ~ protocolInternalLRF3D_SLAVE ( ) {
if ( m_pMasterAddress ! = NULL ) free ( m_pMasterAddress ) ;
for ( uint8_t i = 0 ; i < 16 ; i + + ) {
if ( m_pThresholds [ i ] ! = NULL ) free ( m_pThresholds [ i ] ) ;
} ;
} ;
} ;
bool protocolInternalLRF3D_SLAVE : : create ( void ) {
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 ;
return protocolInternalLRF3D : : create ( ) ;
} ;
} ;
bool protocolInternalLRF3D_SLAVE : : sendTrasholdData ( uint8_t lrf_id , uint32_t dataIdx ) {
bool protocolInternalLRF3D_SLAVE : : setTrasholdData ( uint8_t lrf_id , uint32_t * ptr ) {
if ( ptr = = NULL ) return false ;
if ( m_pThresholds [ lrf_id ] = = NULL ) return false ;
m_mData . lock ( ) ;
memcpy ( m_pThresholds [ lrf_id ] , ptr , TH_SIZE_BYTES ) ;
m_nStatus | = ( ( 1 < < lrf_id ) < < 8 ) ;
m_mData . unlock ( ) ;
return false ;
} ;
bool protocolInternalLRF3D_SLAVE : : enqueueTarget ( targetRecord * ptr ) {
if ( ptr = = NULL ) return false ;
m_mTargetProtector . lock ( ) ;
if ( m_nTargetCount < TWI_TARGET_QUEUE_SIZE ) {
memcpy ( & m_pTargets [ m_nTargetCount ] , ptr , sizeof ( targetRecord ) ) ;
m_nTargetCount + + ;
m_nStatus = ( m_nStatus & 0x00fffffe ) | ( m_nTargetCount < < 24 ) ;
} else {
memcpy ( & m_pTargets [ 0 ] , & m_pTargets [ 1 ] , ( TWI_TARGET_QUEUE_SIZE - 1 ) * sizeof ( targetRecord ) ) ;
memcpy ( & m_pTargets [ TWI_TARGET_QUEUE_SIZE - 1 ] , ptr , sizeof ( targetRecord ) ) ;
m_nStatus | = 1 ; //Target Overflow flag
} ;
m_mTargetProtector . unlock ( ) ;
return true ;
} ;
bool protocolInternalLRF3D_SLAVE : : sendTrasholdData ( uint8_t lrf_id , uint32_t Idx ) {
if ( m_pThresholds [ lrf_id ] = = NULL ) return false ;
uint32_t c_mask = ( ( 1 < < lrf_id ) < < 8 ) ;
if ( ( m_nStatus & c_mask ) = = 0 ) return false ;
uint8_t Buffer [ PROTOCOL_PARSER_BUFFER_SIZE ] ;
uint32_t node_index = Idx ;
uint32_t index = 8 ;
Buffer [ 3 ] = TWIN_TH_DATA ;
Buffer [ 4 ] = ( node_index > > 24 ) & 0xFF ;
Buffer [ 5 ] = ( node_index > > 16 ) & 0xFF ;
Buffer [ 6 ] = ( node_index > > 8 ) & 0xFF ;
Buffer [ 7 ] = ( node_index & 0xFF ) ;
while ( ( index < ( TWI_MAX_PACKAGE_SIZE_BYTES - 5 ) ) & & ( node_index < TH_SIZE_NODES ) ) {
Buffer [ index + + ] = ( m_pThresholds [ lrf_id ] [ node_index ] . data > > 24 ) & 0xFF ; //0xFE; // to clear Sunbit data
Buffer [ index + + ] = ( m_pThresholds [ lrf_id ] [ node_index ] . data > > 16 ) & 0xFF ;
Buffer [ index + + ] = ( m_pThresholds [ lrf_id ] [ node_index ] . data > > 8 ) & 0xFF ;
Buffer [ index + + ] = m_pThresholds [ lrf_id ] [ node_index ] . data & 0xFF ;
node_index + + ;
} ;
# ifdef DEBUG
LOG ( " TH Data Segment " ) ;
# endif
return m_oDataTransport - > sendData ( Buffer , FinishUpPackage ( Buffer , index ) ) ;
} ;
} ;
bool protocolInternalLRF3D_SLAVE : : sendTargets ( void ) {
bool protocolInternalLRF3D_SLAVE : : sendTargets ( void ) {
uint8_t Buffer [ PROTOCOL_PARSER_BUFFER_SIZE ] ;
if ( m_nTargetCount > 0 ) {
Buffer [ 3 ] = TWIN_TARGETS_DATA ;
uint32_t index = 5 ;
uint8_t target_index = 0 ;
m_mTargetProtector . lock ( ) ;
while ( ( index < ( TWI_MAX_PACKAGE_SIZE_BYTES - 21 ) ) & & ( target_index < m_nTargetCount ) ) {
Buffer [ index + + ] = ( m_pTargets [ target_index ] . width > > 24 ) & 0xFF ;
Buffer [ index + + ] = ( m_pTargets [ target_index ] . width > > 16 ) & 0xFF ;
Buffer [ index + + ] = ( m_pTargets [ target_index ] . width > > 8 ) & 0xFF ;
Buffer [ index + + ] = m_pTargets [ target_index ] . width & 0xFF ;
Buffer [ index + + ] = ( m_pTargets [ target_index ] . begin_id > > 24 ) & 0xFF ;
Buffer [ index + + ] = ( m_pTargets [ target_index ] . begin_id > > 16 ) & 0xFF ;
Buffer [ index + + ] = ( m_pTargets [ target_index ] . begin_id > > 8 ) & 0xFF ;
Buffer [ index + + ] = m_pTargets [ target_index ] . begin_id & 0xFF ;
Buffer [ index + + ] = ( m_pTargets [ target_index ] . end_id > > 8 ) & 0xFF ;
Buffer [ index + + ] = m_pTargets [ target_index ] . end_id & 0xFF ;
Buffer [ index + + ] = ( m_pTargets [ target_index ] . end_id > > 8 ) & 0xFF ;
Buffer [ index + + ] = m_pTargets [ target_index ] . end_id & 0xFF ;
Buffer [ index + + ] = ( m_pTargets [ target_index ] . range_min > > 24 ) & 0xFF ;
Buffer [ index + + ] = ( m_pTargets [ target_index ] . range_min > > 16 ) & 0xFF ;
Buffer [ index + + ] = ( m_pTargets [ target_index ] . range_max > > 8 ) & 0xFF ;
Buffer [ index + + ] = m_pTargets [ target_index ] . range_max & 0xFF ;
Buffer [ index + + ] = ( m_pTargets [ target_index ] . status > > 24 ) & 0xFF ;
Buffer [ index + + ] = ( m_pTargets [ target_index ] . status > > 16 ) & 0xFF ;
Buffer [ index + + ] = ( m_pTargets [ target_index ] . status > > 8 ) & 0xFF ;
Buffer [ index + + ] = m_pTargets [ target_index ] . status & 0xFF ;
target_index + + ;
} ;
m_nTargetCount - = target_index ;
m_nStatus = ( m_nStatus & 0x00fffffe ) | ( m_nTargetCount < < 24 ) ;
m_mTargetProtector . unlock ( ) ;
Buffer [ 4 ] = target_index ;
return m_oDataTransport - > sendData ( Buffer , FinishUpPackage ( Buffer , index ) ) ;
} else {
Buffer [ 3 ] = TWIN_TARGETS_DATA ;
Buffer [ 4 ] = 0 ;
return m_oDataTransport - > sendData ( Buffer , FinishUpPackage ( Buffer , 5 ) ) ;
} ;
} ;
} ;
bool protocolInternalLRF3D_SLAVE : : sendStatus ( void ) {
bool protocolInternalLRF3D_SLAVE : : sendStatus ( void ) {
if ( m_oDataTransport = = NULL ) return false ;
if ( m_oDataTransport = = NULL ) return false ;
uint8_t Buffer [ 16 ] ;
uint8_t Buffer [ 16 ] ;
Buffer [ 3 ] = 0xDC ;
Buffer [ 3 ] = TWIN_STATUS_ACK ;
Buffer [ 4 ] = ( m_nStatus > > 24 ) & 0xFF ;
Buffer [ 4 ] = ( m_nStatus > > 24 ) & 0xFF ;
Buffer [ 5 ] = ( m_nStatus > > 16 ) & 0xFF ;
Buffer [ 5 ] = ( m_nStatus > > 16 ) & 0xFF ;
Buffer [ 6 ] = ( m_nStatus > > 8 ) & 0xFF ;
Buffer [ 6 ] = ( m_nStatus > > 8 ) & 0xFF ;
Buffer [ 7 ] = m_nStatus & 0xFF ;
Buffer [ 7 ] = ( m_nStatus & 0xFF ) ;
# ifdef DEBUG
# ifdef DEBUG
LOG ( " setStatus " ) ;
LOG ( " Status ACK " ) ;
# endif
# endif
return m_oDataTransport - > sendData ( Buffer , FinishUpPackage ( Buffer , 8 ) ) ;
return m_oDataTransport - > sendData ( Buffer , FinishUpPackage ( Buffer , 8 ) ) ;
} ;
} ;
# else
bool protocolInternalLRF3D_SLAVE : : packetHandler ( protocolPackage * Package ) {
if ( Package = = NULL ) return false ;
uint8_t cCMD = Package - > m_pData [ 3 ] ;
switch ( cCMD ) {
case TWIN_STATUS_REQ : {
sendStatus ( ) ;
break ;
} ;
} ;
return true ;
} ;
# else // PRU_SLAVE
# define LOG( X ) m_pLog->Log( "protocolLRF3D_MASTER", this, X )
# define LOG( X ) m_pLog->Log( "protocolLRF3D_MASTER", this, X )
# ifdef DEBUG
# ifdef DEBUG
# define LOG_ERROR( X ) {\
# define LOG_ERROR( X ) {\
@ -227,142 +298,104 @@ protocolPackage *protocolInternalLRF3D::packetExtractor( U8 *Buffer, size_t Buff
# else
# else
# define LOG_ERROR( X ) m_pLog->Log( "protocolLRF3D_MASTER", this, _LOG_ERROR, X );
# define LOG_ERROR( X ) m_pLog->Log( "protocolLRF3D_MASTER", this, _LOG_ERROR, X );
# endif
# endif
protocolInternalLRF3D_MASTER : : protocolInternalLRF3D_MASTER ( ) {
m_pLog = basicLogCollection : : getInstance ( ) ;
} ;
protocolInternalLRF3D_MASTER : : ~ protocolInternalLRF3D_MASTER ( ) { } ;
bool protocolInternalLRF3D_MASTER : : create ( void ) {
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 ;
return protocolInternalLRF3D : : create ( ) ;
} ;
} ;
bool protocolInternalLRF3D_MASTER : : ackDataSegment ( uint32_t dataIdx ) {
if ( m_oDataTransport = = NULL ) return false ;
uint8_t Buffer [ 16 ] ;
Buffer [ 3 ] = TWIN_TH_DATA ;
Buffer [ 4 ] = ( dataIdx > > 8 ) & 0xFF ;
Buffer [ 5 ] = ( dataIdx & 0xFF ) ;
# ifdef DEBUG
LOG ( " Treshold Data Seg " ) ;
# endif
return m_oDataTransport - > sendData ( Buffer , FinishUpPackage ( Buffer , 6 ) ) ;
} ;
bool protocolInternalLRF3D_MASTER : : ackTargets ( uint32_t pkgId ) {
if ( m_oDataTransport = = NULL ) return false ;
uint8_t Buffer [ 16 ] ;
Buffer [ 3 ] = TWIN_TARGETS_REQ ;
Buffer [ 4 ] = ( pkgId > > 24 ) & 0xFF ;
Buffer [ 5 ] = ( pkgId > > 16 ) & 0xFF ;
Buffer [ 6 ] = ( pkgId > > 8 ) & 0xFF ;
Buffer [ 7 ] = ( pkgId & 0xFF ) ;
# ifdef DEBUG
LOG ( " Target Ack " ) ;
# endif
return m_oDataTransport - > sendData ( Buffer , FinishUpPackage ( Buffer , 8 ) ) ;
} ;
bool protocolInternalLRF3D_MASTER : : requestTargets ( void ) {
if ( m_oDataTransport = = NULL ) return false ;
uint8_t Buffer [ 16 ] ;
Buffer [ 3 ] = TWIN_TARGETS_REQ ;
# ifdef DEBUG
LOG ( " Target Req " ) ;
# endif
return m_oDataTransport - > sendData ( Buffer , FinishUpPackage ( Buffer , 4 ) ) ;
} ;
bool protocolInternalLRF3D_MASTER : : requestTrasholdData ( uint8_t lrf_id ) {
if ( m_oDataTransport = = NULL ) return false ;
uint8_t Buffer [ 16 ] ;
Buffer [ 3 ] = TWIN_TH_GETDATA ;
Buffer [ 4 ] = lrf_id ;
# ifdef DEBUG
LOG ( " Treshold Req " ) ;
# endif
return m_oDataTransport - > sendData ( Buffer , FinishUpPackage ( Buffer , 5 ) ) ;
} ;
bool protocolInternalLRF3D_MASTER : : requestStatus ( void ) {
if ( m_oDataTransport = = NULL ) return false ;
uint8_t Buffer [ 16 ] ;
Buffer [ 3 ] = TWIN_STATUS_REQ ;
# ifdef DEBUG
LOG ( " Status Req " ) ;
# endif
return m_oDataTransport - > sendData ( Buffer , FinishUpPackage ( Buffer , 4 ) ) ;
} ;
bool protocolInternalLRF3D_MASTER : : packetHandler ( protocolPackage * Package ) {
if ( Package = = NULL ) return false ;
uint8_t cCMD = Package - > m_pData [ 3 ] ;
switch ( cCMD ) {
case TWIN_STATUS_ACK : {
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 TWIN_TH_DATA : {
} ;
} ;
m_mLastTypeProtector . lock ( ) ;
m_bLastPackageType = ( TWIN_PCMD ) cCMD ;
m_mLastTypeProtector . unlock ( ) ;
return true ;
} ;
TWIN_PCMD protocolInternalLRF3D_MASTER : : getLastPackageType ( void ) {
TWIN_PCMD RetVal ;
m_mLastTypeProtector . lock ( ) ;
RetVal = m_bLastPackageType ;
m_mLastTypeProtector . unlock ( ) ;
return RetVal ;
} ;
# endif
# endif
# undef LOG
# undef LOG