|
|
|
@ -16,9 +16,12 @@ mojoRemoteClient::mojoRemoteClient( mojoKernel * ptr ):protocolParser(){ |
|
|
|
m_pLog = basicLogCollection::getInstance(); |
|
|
|
m_pPort = NULL; |
|
|
|
m_pMaster = ptr; |
|
|
|
m_nOutbondSerial = 0; |
|
|
|
m_nInbondSerial = 0; |
|
|
|
m_bShutdownCommunication = true; |
|
|
|
m_bCommunicationEstablished = false; |
|
|
|
m_bRegisteredWithRemotePeer = false; |
|
|
|
m_qCMD = new RPC_CMD_QUEUE(); |
|
|
|
}; |
|
|
|
|
|
|
|
mojoRemoteClient::~mojoRemoteClient(){ |
|
|
|
@ -30,6 +33,7 @@ mojoRemoteClient::~mojoRemoteClient(){ |
|
|
|
m_bCommunicationEstablished = false; |
|
|
|
m_bRegisteredWithRemotePeer = false; |
|
|
|
if ( m_pPort ) delete( m_pPort ); |
|
|
|
delete( m_qCMD ); |
|
|
|
}; |
|
|
|
|
|
|
|
bool mojoRemoteClient::create(){ |
|
|
|
@ -83,28 +87,40 @@ protocolPackage *mojoRemoteClient::packetExtractor(U8 *Buffer, size_t BufferSize |
|
|
|
}; |
|
|
|
|
|
|
|
bool mojoRemoteClient::packetHandler( protocolPackage *Package ){ |
|
|
|
uint32_t tQueryMessage; |
|
|
|
m_mQueryProtector.lock(); |
|
|
|
tQueryMessage = m_nQueryMessage; |
|
|
|
m_mQueryProtector.unlock(); |
|
|
|
|
|
|
|
m_nInbondSerial = Package->m_pData[1]; |
|
|
|
m_nInbondSerial = ( m_nInbondSerial << 8 ) | Package->m_pData[2]; |
|
|
|
m_nInbondSerial = ( m_nInbondSerial << 8 ) | Package->m_pData[3]; |
|
|
|
m_nInbondSerial = ( m_nInbondSerial << 8 ) | Package->m_pData[4]; |
|
|
|
|
|
|
|
switch( Package->m_nCode ){ |
|
|
|
case ARGUS_DATA_MSG_REGISTER: { |
|
|
|
if ( tQueryMessage == ARGUS_DATA_MSG_REGISTER ) { |
|
|
|
m_mQueryProtector.lock(); |
|
|
|
m_nQueryMessage = 0; |
|
|
|
m_mQueryProtector.unlock(); |
|
|
|
}; |
|
|
|
case ARGUS_DATA_MSG_REGISTER: |
|
|
|
m_bRegisteredWithRemotePeer = true; |
|
|
|
enqueueInfoMsg(); |
|
|
|
finishTransaction(); |
|
|
|
break; |
|
|
|
}; |
|
|
|
case ARGUS_DATA_MSG_DISABLED: |
|
|
|
case ARGUS_DATA_MSG_ACCESS_DENIED:{ |
|
|
|
if ( tQueryMessage == ARGUS_DATA_MSG_REGISTER ) { |
|
|
|
m_mQueryProtector.lock(); |
|
|
|
m_nQueryMessage = 0; |
|
|
|
m_mQueryProtector.unlock(); |
|
|
|
case ARGUS_DATA_MSG_ACCESS_DENIED: m_bRegisteredWithRemotePeer = false; |
|
|
|
case ARGUS_DATA_MSG_DISABLED: finishTransaction(); break; |
|
|
|
case ARGUS_DATA_MSG_REQ_TIME_SYNC:{ |
|
|
|
RPC_CMD_RECORD *tCMD = (RPC_CMD_RECORD *)malloc(sizeof(RPC_CMD_RECORD)); |
|
|
|
if ( tCMD ) { |
|
|
|
tCMD->CMD = ARGUS_DATA_MSG_TIME_SYNC; |
|
|
|
tCMD->DATA_SIZE = sizeof( ARGUS_DATA_TIME_SYNC_REQ ); |
|
|
|
tCMD->DATA = malloc(tCMD->DATA_SIZE); |
|
|
|
if (tCMD->DATA) { |
|
|
|
ARGUS_DATA_TIME_SYNC_REQ *tDATA = (ARGUS_DATA_TIME_SYNC_REQ*)tCMD->DATA; |
|
|
|
tDATA->STS = getMilliseconds(); |
|
|
|
if ( peer_send_rpc_pack( tCMD ) ) { |
|
|
|
setTO( 3 ); |
|
|
|
free( tCMD->DATA ); |
|
|
|
free( tCMD ); |
|
|
|
break; |
|
|
|
}; |
|
|
|
free( tCMD->DATA ); |
|
|
|
}; |
|
|
|
free( tCMD ); |
|
|
|
}; |
|
|
|
m_bRegisteredWithRemotePeer = false; |
|
|
|
finishTransaction(); |
|
|
|
break; |
|
|
|
}; |
|
|
|
case ARGUS_DATA_MSG_TIME_SYNC:{ |
|
|
|
@ -133,118 +149,255 @@ bool mojoRemoteClient::packetHandler( protocolPackage *Package ){ |
|
|
|
sprintf( tB,"tv_s:%lld tv_ns:%lld", tS.tv_sec, tS.tv_nsec ); |
|
|
|
LOG( tB ); |
|
|
|
#endif
|
|
|
|
finishTransaction(); |
|
|
|
break; |
|
|
|
}; |
|
|
|
}; |
|
|
|
return true; |
|
|
|
}; |
|
|
|
|
|
|
|
uint8_t mojoRemoteClient::getAutomationStage( ){ |
|
|
|
m_mAutomationStageProtector.lock(); |
|
|
|
uint8_t retVal = m_bAutomationStage; |
|
|
|
m_mAutomationStageProtector.unlock(); |
|
|
|
return retVal; |
|
|
|
}; |
|
|
|
|
|
|
|
void mojoRemoteClient::setAutomationStage( uint8_t stg ){ |
|
|
|
m_mAutomationStageProtector.lock(); |
|
|
|
m_bAutomationStage = stg; |
|
|
|
m_mAutomationStageProtector.unlock(); |
|
|
|
}; |
|
|
|
|
|
|
|
void mojoRemoteClient::finishTransaction(){ |
|
|
|
m_mCurrentCMDProtector.lock(); |
|
|
|
if ( m_pCurrentCMD ) { |
|
|
|
if ( m_pCurrentCMD->DATA ) free( m_pCurrentCMD->DATA ); |
|
|
|
free( m_pCurrentCMD ); |
|
|
|
m_pCurrentCMD = NULL; |
|
|
|
}; |
|
|
|
m_mCurrentCMDProtector.unlock(); |
|
|
|
}; |
|
|
|
|
|
|
|
bool mojoRemoteClient::validateTransaction(){ |
|
|
|
if ( m_mCurrentCMDProtector.try_lock() ) { |
|
|
|
if ( m_pCurrentCMD == NULL ) { |
|
|
|
m_mCurrentCMDProtector.unlock(); |
|
|
|
return true; |
|
|
|
}; |
|
|
|
m_mCurrentCMDProtector.unlock(); |
|
|
|
}; |
|
|
|
return false; |
|
|
|
}; |
|
|
|
|
|
|
|
bool mojoRemoteClient::pushNewTransaction( RPC_CMD_RECORD *ptr ){ |
|
|
|
if ( ptr == NULL ) return false; |
|
|
|
m_mCurrentCMDProtector.lock(); |
|
|
|
if ( m_qCMD->push( ptr ) != -1 ){ |
|
|
|
m_mCurrentCMDProtector.unlock(); |
|
|
|
return true; |
|
|
|
}; |
|
|
|
m_mCurrentCMDProtector.unlock(); |
|
|
|
return false; |
|
|
|
}; |
|
|
|
|
|
|
|
bool mojoRemoteClient::fetchNewTransaction(){ |
|
|
|
m_mCurrentCMDProtector.lock(); |
|
|
|
if ( m_pCurrentCMD ) { |
|
|
|
m_mCurrentCMDProtector.unlock(); |
|
|
|
return false; |
|
|
|
}; |
|
|
|
m_pCurrentCMD = m_qCMD->pop(); |
|
|
|
if ( m_pCurrentCMD ) { |
|
|
|
m_mCurrentCMDProtector.unlock(); |
|
|
|
return true; |
|
|
|
}; |
|
|
|
m_mCurrentCMDProtector.unlock(); |
|
|
|
return false; |
|
|
|
}; |
|
|
|
|
|
|
|
void mojoRemoteClient::enqueueInfoMsg(){ |
|
|
|
RPC_CMD_RECORD *tCMD = (RPC_CMD_RECORD *)malloc(sizeof(RPC_CMD_RECORD)); |
|
|
|
if ( tCMD ) { |
|
|
|
tCMD->CMD = ARGUS_DATA_MSG_INFO; |
|
|
|
tCMD->DATA_SIZE = sizeof( ARGUS_DATA_MOJO_INFO ); |
|
|
|
tCMD->DATA = malloc(tCMD->DATA_SIZE); |
|
|
|
if (tCMD->DATA) { |
|
|
|
ARGUS_DATA_MOJO_INFO *tINFO = (ARGUS_DATA_MOJO_INFO*)tCMD->DATA; |
|
|
|
tINFO->MOJO_WORK_MODE = 2; |
|
|
|
tINFO->UPPER_ID = 2; |
|
|
|
tINFO->BOTTOM_ID = 3; |
|
|
|
tINFO->CAM_ID = 4; |
|
|
|
tINFO->CPU_COUNT = m_pMaster->m_sSysInfo.CPU_CORES; |
|
|
|
tINFO->TOT_DISK = m_pMaster->m_sSysInfo.T_DISK; |
|
|
|
tINFO->TOT_MEMO = m_pMaster->m_sSysInfo.T_MEM; |
|
|
|
if ( pushNewTransaction( tCMD ) ) return; |
|
|
|
free( tCMD->DATA ); |
|
|
|
}; |
|
|
|
free( tCMD ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
void mojoRemoteClient::enqueueStatMsg(){ |
|
|
|
RPC_CMD_RECORD *tCMD = (RPC_CMD_RECORD *)malloc(sizeof(RPC_CMD_RECORD)); |
|
|
|
if ( tCMD ) { |
|
|
|
tCMD->CMD = ARGUS_DATA_MSG_INFO; |
|
|
|
tCMD->DATA_SIZE = sizeof( ARGUS_DATA_MOJO_STATUS ); |
|
|
|
tCMD->DATA = malloc(tCMD->DATA_SIZE); |
|
|
|
if (tCMD->DATA) { |
|
|
|
ARGUS_DATA_MOJO_STATUS *cSTATUS = (ARGUS_DATA_MOJO_STATUS*)tCMD->DATA; |
|
|
|
DBC_SYS_LOAD_INFO cSYSSTAT; |
|
|
|
uint8_t tS = m_pMaster->m_pDBC->getLRFDataStatus( 1 ); |
|
|
|
cSTATUS->STATUSES = 0xff00ff00 | tS; |
|
|
|
m_pMaster->getSystemUtilization( &cSYSSTAT ); |
|
|
|
cSTATUS->CPU_LOAD = round( cSYSSTAT.cpu15 ); |
|
|
|
cSTATUS->CPU_TEMP = round( cSYSSTAT.temperature ); |
|
|
|
//if( cSTATUS->CPU_LOAD == 0xFF ) cSTATUS->CPU_LOAD = 0;
|
|
|
|
//if( cSTATUS->CPU_TEMP == 0xFF ) cSTATUS->CPU_TEMP = 0;
|
|
|
|
cSTATUS->DISK_UTI = cSYSSTAT.disk; |
|
|
|
cSTATUS->MEMO_UTI = cSYSSTAT.mem; |
|
|
|
if ( pushNewTransaction( tCMD ) ) return; |
|
|
|
free( tCMD->DATA ); |
|
|
|
}; |
|
|
|
free( tCMD ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
void mojoRemoteClient::enqueueTimeReq(){ |
|
|
|
RPC_CMD_RECORD *tCMD = (RPC_CMD_RECORD *)malloc(sizeof(RPC_CMD_RECORD)); |
|
|
|
if ( tCMD ) { |
|
|
|
tCMD->CMD = ARGUS_DATA_MSG_REQ_TIME_SYNC; |
|
|
|
tCMD->DATA_SIZE = 0; |
|
|
|
tCMD->DATA = NULL; |
|
|
|
if ( pushNewTransaction( tCMD ) ) return; |
|
|
|
free( tCMD ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
void mojoRemoteClient::setTO( uint8_t seconds ){ |
|
|
|
m_mTOProtoctor.lock(); |
|
|
|
m_bTOCounter = seconds; |
|
|
|
m_mTOProtoctor.unlock(); |
|
|
|
}; |
|
|
|
|
|
|
|
bool mojoRemoteClient::decTO(){ |
|
|
|
m_mTOProtoctor.lock(); |
|
|
|
if ( m_bTOCounter ) { |
|
|
|
m_bTOCounter--; |
|
|
|
m_mTOProtoctor.unlock(); |
|
|
|
return true; |
|
|
|
}; |
|
|
|
m_mTOProtoctor.unlock(); |
|
|
|
return false; |
|
|
|
}; |
|
|
|
|
|
|
|
void mojoRemoteClient::m_fThreadProc( void ){ |
|
|
|
time_t tTimeTSeconds = 0; |
|
|
|
time_t cTimeTSeconds = 0; |
|
|
|
uint8_t bTO_COUNTER = 0; |
|
|
|
uint32_t tSecondsCounter = 0; |
|
|
|
|
|
|
|
m_bThreadStatus = TH_WORKING; |
|
|
|
#ifdef DEBUG
|
|
|
|
LOG("Connector Thread Started"); |
|
|
|
#endif
|
|
|
|
while ( m_bThreadStatus < TH_ENDED ) { |
|
|
|
// seconds Counter (for internal purposes)
|
|
|
|
cTimeTSeconds = time( NULL ); |
|
|
|
if ( cTimeTSeconds!=tTimeTSeconds ) { |
|
|
|
//Process each second
|
|
|
|
//Process each second
|
|
|
|
if ( cTimeTSeconds != tTimeTSeconds ) { |
|
|
|
tSecondsCounter++; |
|
|
|
tTimeTSeconds = cTimeTSeconds; |
|
|
|
switch ( m_bAutomationStage ) { |
|
|
|
case ARGUS_RPC_STAGE_WAIT_RECONNECT:{ |
|
|
|
if ( bTO_COUNTER ) { |
|
|
|
bTO_COUNTER--; |
|
|
|
} else { |
|
|
|
m_bAutomationStage = ARGUS_RPC_STAGE_CONNECT; |
|
|
|
switch ( getAutomationStage() ) { |
|
|
|
case ARGUS_RPC_STAGE_CONNECT:{ |
|
|
|
#ifdef DEBUG
|
|
|
|
char tB[128]; |
|
|
|
sprintf(tB,"Creating Remote connection to [%s:%d]", m_pMaster->m_sSiteData.remote_ip, m_pMaster->m_sSiteData.remote_port ); |
|
|
|
LOG( tB ); |
|
|
|
#endif
|
|
|
|
if( m_pMaster->m_sSiteData.remote_port ) { |
|
|
|
m_pPort = new clientPort( m_pMaster->m_sSiteData.remote_ip, m_pMaster->m_sSiteData.remote_port ); |
|
|
|
if( m_pPort ) { |
|
|
|
if( m_pPort->create() ) { |
|
|
|
#ifdef DEBUG
|
|
|
|
LOG("Connection Sucessfull"); |
|
|
|
#endif
|
|
|
|
m_bShutdownCommunication = false; |
|
|
|
m_bCommunicationEstablished = true; |
|
|
|
m_bRegisteredWithRemotePeer = false; |
|
|
|
setTransport( m_pPort, false ); |
|
|
|
setAutomationStage( ARGUS_RPC_STAGE_REGISTER ); |
|
|
|
} else { |
|
|
|
delete( m_pPort ); |
|
|
|
m_pPort = NULL; |
|
|
|
m_bShutdownCommunication = true; |
|
|
|
m_bCommunicationEstablished = false; |
|
|
|
m_bRegisteredWithRemotePeer = false; |
|
|
|
setTO( 30 ); //30 sec to wait
|
|
|
|
setAutomationStage( ARGUS_RPC_STAGE_WAIT_RECONNECT ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
break; |
|
|
|
}; |
|
|
|
case ARGUS_RPC_STAGE_IDLE:{ |
|
|
|
uint8_t tS = m_pMaster->m_pDBC->getLRFDataStatus( 1 ); |
|
|
|
ARGUS_DATA_MOJO_STATUS cSTATUS; |
|
|
|
DBC_SYS_LOAD_INFO cSYSSTAT; |
|
|
|
cSTATUS.STATUSES = 0xff00ff00 | tS; |
|
|
|
m_pMaster->getSystemUtilization( &cSYSSTAT ); |
|
|
|
cSTATUS.CPU_LOAD = round( cSYSSTAT.cpu15 ); |
|
|
|
cSTATUS.CPU_TEMP = round( cSYSSTAT.temperature ); |
|
|
|
//if( cSTATUS.CPU_LOAD == 0xFF ) cSTATUS.CPU_LOAD = 0;
|
|
|
|
//if( cSTATUS.CPU_TEMP == 0xFF ) cSTATUS.CPU_TEMP = 0;
|
|
|
|
cSTATUS.DISK_UTI = cSYSSTAT.disk; |
|
|
|
cSTATUS.MEMO_UTI = cSYSSTAT.mem; |
|
|
|
peer_send_status( &cSTATUS ); |
|
|
|
case ARGUS_RPC_STAGE_WAIT_RECONNECT:{ |
|
|
|
if ( !decTO() ) setAutomationStage( ARGUS_RPC_STAGE_CONNECT ); |
|
|
|
break; |
|
|
|
}; |
|
|
|
}; |
|
|
|
if( ( tSecondsCounter % ARGUS_SECONDS_TO_SYNC_TIME ) == 15 ) { |
|
|
|
LOG("Req Time Sync!"); |
|
|
|
ARGUS_DATA_TIME_SYNC_REQ tTR; |
|
|
|
tTR.STS = getMilliseconds(); |
|
|
|
peer_send_time_sync_req( &tTR ); |
|
|
|
}; |
|
|
|
}; |
|
|
|
switch ( m_bAutomationStage ) { |
|
|
|
case ARGUS_RPC_STAGE_CONNECT:{ |
|
|
|
#ifdef DEBUG
|
|
|
|
char tB[128]; |
|
|
|
sprintf(tB,"Creating Remote connection to [%s:%d]", m_pMaster->m_sSiteData.remote_ip, m_pMaster->m_sSiteData.remote_port ); |
|
|
|
LOG( tB ); |
|
|
|
#endif
|
|
|
|
if( m_pMaster->m_sSiteData.remote_port ) { |
|
|
|
m_pPort = new clientPort( m_pMaster->m_sSiteData.remote_ip, m_pMaster->m_sSiteData.remote_port ); |
|
|
|
if( m_pPort ) { |
|
|
|
if( m_pPort->create() ) { |
|
|
|
LOG("Connection Sucessfull"); |
|
|
|
m_bShutdownCommunication = false; |
|
|
|
m_bCommunicationEstablished = true; |
|
|
|
m_bRegisteredWithRemotePeer = false; |
|
|
|
setTransport( m_pPort, false ); |
|
|
|
m_bAutomationStage = ARGUS_RPC_STAGE_REGISTER; |
|
|
|
} else { |
|
|
|
delete( m_pPort ); |
|
|
|
m_pPort = NULL; |
|
|
|
m_bShutdownCommunication = true; |
|
|
|
m_bCommunicationEstablished = false; |
|
|
|
m_bRegisteredWithRemotePeer = false; |
|
|
|
bTO_COUNTER = 30; //30 sec to wait
|
|
|
|
m_bAutomationStage = ARGUS_RPC_STAGE_WAIT_RECONNECT; |
|
|
|
case ARGUS_RPC_STAGE_REGISTER:{ |
|
|
|
RPC_CMD_RECORD *tCMD = (RPC_CMD_RECORD*) malloc(sizeof(RPC_CMD_RECORD)); |
|
|
|
if ( tCMD ) { |
|
|
|
tCMD->CMD = ARGUS_DATA_MSG_REGISTER; |
|
|
|
tCMD->DATA_SIZE = strlen( m_pMaster->m_sIdentity ); |
|
|
|
tCMD->DATA = malloc(tCMD->DATA_SIZE); |
|
|
|
if ( tCMD->DATA ) { |
|
|
|
strncpy( (char *)tCMD->DATA, m_pMaster->m_sIdentity, tCMD->DATA_SIZE ); |
|
|
|
if( pushNewTransaction( tCMD ) ){ |
|
|
|
setAutomationStage( ARGUS_RPC_STAGE_WAIT_ACK ); |
|
|
|
setTO( 3 ); // Wait for 3 seconds to be registered with server
|
|
|
|
break; |
|
|
|
}; |
|
|
|
free( tCMD->DATA ); |
|
|
|
}; |
|
|
|
free( tCMD ); |
|
|
|
}; |
|
|
|
break; |
|
|
|
}; |
|
|
|
break; |
|
|
|
}; |
|
|
|
case ARGUS_RPC_STAGE_WAIT_RECONNECT: break; |
|
|
|
case ARGUS_RPC_STAGE_REGISTER:{ |
|
|
|
if( peer_send_reg_req( m_pMaster->m_sIdentity )){ |
|
|
|
//m_nQueryMessage = ARGUS_RPC_STAGE_REGISTER;
|
|
|
|
m_bAutomationStage = ARGUS_RPC_STAGE_SEND_HELLO; |
|
|
|
bTO_COUNTER = 1; |
|
|
|
case ARGUS_RPC_STAGE_WAIT_ACK:{ |
|
|
|
LOG("TO On Waiting Responce!"); |
|
|
|
if ( !decTO() ) setAutomationStage( ARGUS_RPC_STAGE_CLOSE ); |
|
|
|
break; |
|
|
|
}; |
|
|
|
break; |
|
|
|
}; |
|
|
|
case ARGUS_RPC_STAGE_SEND_HELLO:{ |
|
|
|
ARGUS_DATA_MOJO_INFO tINFO; |
|
|
|
tINFO.MOJO_WORK_MODE = 2; |
|
|
|
tINFO.UPPER_ID = 2; |
|
|
|
tINFO.BOTTOM_ID = 3; |
|
|
|
tINFO.CAM_ID = 4; |
|
|
|
tINFO.CPU_COUNT = m_pMaster->m_sSysInfo.CPU_CORES; |
|
|
|
tINFO.TOT_DISK = m_pMaster->m_sSysInfo.T_DISK; |
|
|
|
tINFO.TOT_MEMO = m_pMaster->m_sSysInfo.T_MEM; |
|
|
|
if( peer_send_hello( &tINFO ) ) { |
|
|
|
m_bAutomationStage = ARGUS_RPC_STAGE_IDLE; |
|
|
|
case ARGUS_RPC_STAGE_IDLE: if( ( tSecondsCounter % ARGUS_SECONDS_TO_SYNC_TIME ) == 15 ) enqueueTimeReq(); else enqueueStatMsg(); break; |
|
|
|
case ARGUS_RPC_STAGE_DISCONNECT:{ |
|
|
|
// Gracefully Disconnect
|
|
|
|
//if( peer_send_disconnect() ){
|
|
|
|
// bTO_COUNTER = 1;
|
|
|
|
// setAutomationStage( ARGUS_RPC_STAGE_WAIT_ACK );
|
|
|
|
//} else setAutomationStage( ARGUS_RPC_STAGE_CLOSE );
|
|
|
|
break; |
|
|
|
}; |
|
|
|
case ARGUS_RPC_STAGE_CLOSE:{ |
|
|
|
// Just Disconnect
|
|
|
|
delete( m_pPort ); |
|
|
|
m_pPort = NULL; |
|
|
|
m_bShutdownCommunication = true; |
|
|
|
m_bCommunicationEstablished = false; |
|
|
|
m_bRegisteredWithRemotePeer = false; |
|
|
|
setTO( 30 ); //30 sec to wait
|
|
|
|
setAutomationStage( ARGUS_RPC_STAGE_WAIT_RECONNECT ); |
|
|
|
break; |
|
|
|
}; |
|
|
|
break; |
|
|
|
}; |
|
|
|
case ARGUS_RPC_STAGE_IDLE:{ |
|
|
|
|
|
|
|
break; |
|
|
|
}; |
|
|
|
}; |
|
|
|
SLEEP(DEFAULT_THREAD_SLEEP_TIME); |
|
|
|
|
|
|
|
if ( validateTransaction() ) { |
|
|
|
if ( fetchNewTransaction() ) { |
|
|
|
if( peer_send_rpc_pack( m_pCurrentCMD ) ) { |
|
|
|
setTO( 1 ); |
|
|
|
setAutomationStage( ARGUS_RPC_STAGE_WAIT_ACK ); |
|
|
|
}; |
|
|
|
} else SLEEP( DEFAULT_THREAD_SLEEP_TIME ); |
|
|
|
} else SLEEP( DEFAULT_THREAD_SLEEP_TIME ); |
|
|
|
}; |
|
|
|
LOG("Connector Thread Ended!"); |
|
|
|
}; |
|
|
|
@ -252,80 +405,32 @@ void mojoRemoteClient::m_fThreadProc( void ){ |
|
|
|
/*
|
|
|
|
Register With Server and make Time Sync With Server |
|
|
|
*/ |
|
|
|
bool mojoRemoteClient::peer_send_reg_req( CSTR identity ){ |
|
|
|
if( identity == NULL ) return false; |
|
|
|
if( !m_bCommunicationEstablished ) return false; |
|
|
|
if( m_bRegisteredWithRemotePeer ) return true; |
|
|
|
uint8_t tBuffer[256]; |
|
|
|
uint32_t tPackSize = ARGUS_HEADER_SIZE+33; |
|
|
|
tBuffer[ARGUS_HEADER_SIZE] = ARGUS_DATA_MSG_REGISTER; |
|
|
|
memcpy( tBuffer+1+ARGUS_HEADER_SIZE, identity, 32 ); |
|
|
|
if( m_pPort->sendData( tBuffer, argus_rpc_finishupPackage( tBuffer, tPackSize ) ) ) { |
|
|
|
m_mQueryProtector.lock(); |
|
|
|
m_nQueryMessage = ARGUS_DATA_MSG_REGISTER; |
|
|
|
m_mQueryProtector.unlock(); |
|
|
|
//Waiting For Responce
|
|
|
|
while( 1 ){ |
|
|
|
if( m_bShutdownCommunication ) break; |
|
|
|
m_mQueryProtector.lock(); |
|
|
|
if( m_nQueryMessage == 0 ) { |
|
|
|
m_mQueryProtector.unlock(); |
|
|
|
break; |
|
|
|
}; |
|
|
|
m_mQueryProtector.unlock(); |
|
|
|
SLEEP(1); |
|
|
|
}; |
|
|
|
m_bAutomationStage = ARGUS_RPC_STAGE_IDLE; |
|
|
|
}; |
|
|
|
return m_bRegisteredWithRemotePeer; |
|
|
|
}; |
|
|
|
|
|
|
|
bool mojoRemoteClient::peer_send_evt( ARGUS_DATA_EVENT *ptr ){ |
|
|
|
if( ptr == NULL ) return false; |
|
|
|
bool mojoRemoteClient::peer_send_rpc_pack( RPC_CMD_RECORD *ptr){ |
|
|
|
bool retVal; |
|
|
|
if ( ptr == NULL ) return false; |
|
|
|
if( !m_bCommunicationEstablished ) return false; |
|
|
|
if( !m_bRegisteredWithRemotePeer ) return false; |
|
|
|
uint8_t tBuffer[1024]; |
|
|
|
tBuffer[ARGUS_HEADER_SIZE] = ARGUS_DATA_MSG_EVT; |
|
|
|
m_mBufferProtector.lock(); |
|
|
|
m_pBuffer[ARGUS_HEADER_SIZE] = ptr->CMD; |
|
|
|
uint16_t i = 0; |
|
|
|
for(; i < sizeof(ARGUS_DATA_EVENT); i++) tBuffer[ARGUS_HEADER_SIZE+1+i] = ((uint8_t*)ptr)[i]; |
|
|
|
return m_pPort->sendData(tBuffer, argus_rpc_finishupPackage(tBuffer, ARGUS_HEADER_SIZE+1+i )); |
|
|
|
}; |
|
|
|
|
|
|
|
bool mojoRemoteClient::peer_send_hello( ARGUS_DATA_MOJO_INFO *ptr ){ |
|
|
|
if( ptr == NULL ) return false; |
|
|
|
if( !m_bCommunicationEstablished ) return false; |
|
|
|
if( !m_bRegisteredWithRemotePeer ) return false; |
|
|
|
uint8_t tBuffer[1024]; |
|
|
|
tBuffer[ARGUS_HEADER_SIZE] = ARGUS_DATA_MSG_INFO; |
|
|
|
uint16_t i = 0; |
|
|
|
for(; i < sizeof(ARGUS_DATA_MOJO_INFO); i++) tBuffer[ARGUS_HEADER_SIZE+1+i] = ((uint8_t*)ptr)[i]; |
|
|
|
return m_pPort->sendData(tBuffer, argus_rpc_finishupPackage(tBuffer, ARGUS_HEADER_SIZE+1+i )); |
|
|
|
}; |
|
|
|
|
|
|
|
bool mojoRemoteClient::peer_send_status( ARGUS_DATA_MOJO_STATUS *ptr ){ |
|
|
|
if( ptr == NULL ) return false; |
|
|
|
if( !m_bCommunicationEstablished ) return false; |
|
|
|
if( !m_bRegisteredWithRemotePeer ) return false; |
|
|
|
uint8_t tBuffer[1024]; |
|
|
|
tBuffer[ARGUS_HEADER_SIZE] = ARGUS_DATA_MSG_KEEP_ALIVE; |
|
|
|
uint16_t i = 0; |
|
|
|
for(; i < sizeof(ARGUS_DATA_MOJO_STATUS); i++) tBuffer[ARGUS_HEADER_SIZE+1+i] = ((uint8_t*)ptr)[i]; |
|
|
|
return m_pPort->sendData(tBuffer, argus_rpc_finishupPackage(tBuffer, ARGUS_HEADER_SIZE+1+i )); |
|
|
|
for (; i < ptr->DATA_SIZE; i++) m_pBuffer[ARGUS_HEADER_SIZE+1+i] = ((uint8_t *)ptr->DATA)[i]; |
|
|
|
m_nOutbondSerial++; |
|
|
|
retVal = m_pPort->sendData( m_pBuffer, argus_rpc_finishupPackage( m_pBuffer, m_nOutbondSerial, ARGUS_HEADER_SIZE+1+i )); |
|
|
|
m_mBufferProtector.unlock(); |
|
|
|
return retVal; |
|
|
|
}; |
|
|
|
|
|
|
|
bool mojoRemoteClient::peer_send_time_sync_req( ARGUS_DATA_TIME_SYNC_REQ *ptr ){ |
|
|
|
bool mojoRemoteClient::createVideoTransferTask( ARGUS_DATA_VIDEO_SEGMENT *ptr ){ |
|
|
|
if( ptr == NULL ) return false; |
|
|
|
if( !m_bCommunicationEstablished ) return false; |
|
|
|
if( !m_bRegisteredWithRemotePeer ) return false; |
|
|
|
uint8_t tBuffer[1024]; |
|
|
|
tBuffer[ARGUS_HEADER_SIZE] = ARGUS_DATA_MSG_TIME_SYNC; |
|
|
|
tBuffer[ARGUS_HEADER_SIZE] = ARGUS_DATA_MSG_VIDEO_INFO; |
|
|
|
uint16_t i = 0; |
|
|
|
for(; i < sizeof(ARGUS_DATA_TIME_SYNC_REQ); i++) tBuffer[ARGUS_HEADER_SIZE+1+i] = ((uint8_t*)ptr)[i]; |
|
|
|
return m_pPort->sendData(tBuffer, argus_rpc_finishupPackage(tBuffer, ARGUS_HEADER_SIZE+1+i )); |
|
|
|
}; |
|
|
|
|
|
|
|
bool mojoRemoteClient::createVideoTransferTask( ARGUS_DATA_VIDEO_SEGMENT *ptr ){ |
|
|
|
return true; |
|
|
|
for(; i < sizeof(ARGUS_DATA_VIDEO_SEGMENT); i++) tBuffer[ARGUS_HEADER_SIZE+1+i] = ((uint8_t*)ptr)[i]; |
|
|
|
m_nOutbondSerial++; |
|
|
|
return m_pPort->sendData(tBuffer, argus_rpc_finishupPackage(tBuffer, m_nOutbondSerial, ARGUS_HEADER_SIZE+1+i )); |
|
|
|
}; |
|
|
|
|
|
|
|
bool mojoRemoteClient::validate(){ |
|
|
|
@ -380,16 +485,23 @@ bool mojoRemoteClient::validate(){ |
|
|
|
}; |
|
|
|
|
|
|
|
bool mojoRemoteClient::addEvent( EVENT_CONTAINER *Evt ){ |
|
|
|
bool retVal = false; |
|
|
|
#ifdef DEBUG
|
|
|
|
LOG("Add Evt!"); |
|
|
|
ARGUS_DATA_EVENT *tPac = argus_rpc_convert_evt( Evt ); |
|
|
|
if( tPac ){ |
|
|
|
retVal = peer_send_evt( tPac ); |
|
|
|
free( tPac ); |
|
|
|
#endif
|
|
|
|
if ( Evt == NULL ) return false; |
|
|
|
RPC_CMD_RECORD *tPack = (RPC_CMD_RECORD *)malloc(sizeof(RPC_CMD_RECORD)); |
|
|
|
if ( tPack ) { |
|
|
|
tPack->DATA = (void*) argus_rpc_convert_evt( Evt ); |
|
|
|
if ( tPack->DATA ) { |
|
|
|
tPack->CMD = ARGUS_DATA_MSG_EVT; |
|
|
|
tPack->DATA_SIZE = sizeof( ARGUS_DATA_EVENT ); |
|
|
|
if( m_qCMD->push( tPack ) ) return true; |
|
|
|
free( tPack->DATA ); |
|
|
|
}; |
|
|
|
free( tPack ); |
|
|
|
}; |
|
|
|
return retVal; |
|
|
|
return false; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
#undef LOG
|
|
|
|
#undef LOG_ERROR
|