You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

143 lines
4.1 KiB

#include "rgooseNode2D.h"
#include "../hardware/uart/serialPort.h"
#include "../hardware/uart/serialSOL.h"
#define LOG( X ) m_pLog->Log( "2DNODE", this, X )
#ifdef DEBUG
#define LOG_ERROR( X ) {\
char _tBfrErrMSG2w34[256];\
sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
m_pLog->Log( "2DNODE", this, _LOG_ERROR, _tBfrErrMSG2w34 );\
}
#else
#define LOG_ERROR( X ) m_pLog->Log( "2DNODE", this, _LOG_ERROR, X );
#endif
ARGUS_2DSensor::ARGUS_2DSensor( uint32_t id ):argusNetNode( id ), basicThread(), protocolLGS_2D(){
m_pLog = basicLogCollection::getInstance();
DBC_LRF_DATA *tDATA = m_pDBC->getLRFData( m_sNodeData.aux_id );
m_bWM = 0;
if( tDATA != NULL ) {
memcpy( &m_sLRF_DATA, tDATA, sizeof(DBC_LRF_DATA));
} else {
memset( &m_sLRF_DATA, 0, sizeof(DBC_LRF_DATA));
};
};
ARGUS_2DSensor::~ARGUS_2DSensor(){
stopService();
};
bool ARGUS_2DSensor::startService() {
if( m_sLRF_DATA.id == 0 ){
LOG_ERROR("No DATA From Database!");
return false;
};
if( setDeviceID( m_sLRF_DATA.device_id ) ){
DBC_UART_DATA *tData = NULL;
tData = m_pDBC->getUartData( m_sLRF_DATA.uart_id );
if( tData!= NULL ) {
basicTransport *tTransport = NULL;
switch( tData->type ) {
case 1:{ // Hardware
#ifdef DEBUG
LOG("HW Port");
#endif
serialPort *tT = NULL;
tT = new serialPort();
if( tT!= NULL ){
if( tT->create( tData->path, tData->speed ) ){
tTransport = (basicTransport *) tT;
} else {
delete( tT );
};
};
break;
};
case 2:{ // E2S
#ifdef DEBUG
LOG("SOL Port");
#endif
serialSOL *tT = NULL;
tT = new serialSOL( (SOL_TYPE)tData->mode );
if( tT!= NULL ){
if( tT->create( tData->path, tData->port, tData->speed ) ){
tTransport = (basicTransport *) tT;
} else {
delete( tT );
};
};
break;
};
#ifdef DEBUG
default: LOG_ERROR("Unknown Port Type!");
#endif
};
if( tTransport!= NULL ) {
LOG( "Bind Transport Port!" );
if( setTransport( tTransport )){
if( create() ){
LOG_ERROR("Protocol <<< Create >>> Failure!");
};
} else {
LOG_ERROR("Binding Port Failure!");
};
} else LOG_ERROR("Transport Creation Failure!");
free( tData );
};
};
return init();
};
bool ARGUS_2DSensor::stopService() {
waitThreadEnd( true );
return true;
};
bool ARGUS_2DSensor::validate(){
return true;
};
void ARGUS_2DSensor::m_fThreadProc( void ){
m_bThreadStatus = TH_WORKING;
while (m_bThreadStatus < TH_ENDED) {
switch( m_bWM ) {
// Physical Connection Channel
case 0: if( getConnectionStatus() == CS_CONNECTED ) m_bWM = 1;
// Logical Connection Checking
case 1: if( !getState() ) m_bWM = 0;
// Update Parameters
case 2:
// Idle Work
case 128: if( !getState2() ) m_bWM = 0;
};
SLEEP(300);
};
};
#define SIZE_IDX 1
#define DEV_ID_IDX 2
#define CMD_IDX 3
#define SUB_CMD_IDX 4
#define DATA_BEGIN_IDX 5
bool ARGUS_2DSensor::packetHandler( protocolPackage *Package ){
return true;
};
#undef SIZE_IDX
#undef DEV_ID_IDX
#undef CMD_IDX
#undef SUB_CMD_IDX
#undef DATA_BEGIN_IDX
#undef LOG
#undef LOG_ERROR