32 changed files with 2575 additions and 1910 deletions
-
21Projects/argus/argus.vpj
-
92Projects/argus/makefile
-
4lib/App/3dSERVER/LRF_TargetTracker.cpp
-
8lib/App/3dSERVER/LRF_TargetTracker.h
-
218lib/App/3dSERVER/LRF_TwinConnector.cpp
-
54lib/App/3dSERVER/LRF_TwinConnector.h
-
2lib/data/net/clientPort.h
-
61lib/data/net/netServer.cpp
-
2lib/data/net/serverPort.h
-
142lib/data/net/transportSocket.cpp
-
113lib/data/net/transportSocket.cpp.bak
-
64lib/data/net/transportSocket.h
-
62lib/data/net/transportSocket.h.bak
-
2lib/data/protocol/protocol.cpp
-
5lib/data/protocol/protocol.h
-
369lib/data/protocol/protocolInternalLRF3D.cpp
-
72lib/data/protocol/protocolInternalLRF3D.h
-
956lib/data/protocol/protocolLGS.cpp
-
809lib/data/protocol/protocolLGS.h
-
2lib/data/protocol/protocolLGS2D.cpp
-
25lib/data/protocol/protocolLGS2D.h
-
134lib/data/protocol/protocolLGSm.cpp
-
808lib/data/protocol/protocolLGSm.h
-
12lib/data/transport/transportSerial.h
-
130lib/data/transport/transportSocket.cpp
-
53lib/data/transport/transportSocket.h
-
4lib/hardware/uart/serialPort.h
-
165lib/hardware/uart/serialSOL.cpp
-
50lib/hardware/uart/serialSOL.h
-
0lib/rgoose/rgooseNode2D.cpp
-
42lib/rgoose/rgooseNode2D.h
-
4lib/rgoose/rgooseNode3D.h
@ -0,0 +1,218 @@ |
|||
#include "LRF_TwinConnector.h"
|
|||
#define LOG( X ) m_pLog->Log( "TWINC", this, X )
|
|||
#ifdef DEBUG
|
|||
#define LOG_ERROR( X ) {\
|
|||
char _tBfrErrMSG234[256];\ |
|||
sprintf( _tBfrErrMSG234, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\ |
|||
m_pLog->Log( "TWINC", this, _LOG_ERROR, _tBfrErrMSG234 );\ |
|||
} |
|||
#else
|
|||
#define LOG_ERROR( X ) m_pLog->Log( "TWINC", this, _LOG_ERROR, X );
|
|||
#endif
|
|||
|
|||
LRF_TwinConnector::LRF_TwinConnector( config_setting_t *Settings ): basicThread(){ |
|||
m_pLog = basicLogCollection::getInstance(); |
|||
m_pSettings = basicSettingsProvider::getInstance()->getSubNode( Settings, (CSTR)"TWIN_3DLRF_CONNECTION" ); |
|||
m_pProtocol = NULL; |
|||
m_pPort = NULL; |
|||
m_nMainSocket = -1; |
|||
}; |
|||
|
|||
LRF_TwinConnector::~LRF_TwinConnector(){ |
|||
if( m_pPort != NULL ) delete( m_pPort ); |
|||
if( m_pProtocol != NULL ) delete( m_pProtocol ); |
|||
}; |
|||
|
|||
bool LRF_TwinConnector::create(){ |
|||
|
|||
#ifdef PRU_SLAVE
|
|||
m_pProtocol = new protocolInternalLRF3D_SLAVE(); |
|||
#else
|
|||
m_pProtocol = new protocolInternalLRF3D_MASTER(); |
|||
#endif
|
|||
|
|||
|
|||
int RetCode; |
|||
struct hostent *h_info; |
|||
|
|||
m_nMainSocket = socket( AF_INET, SOCK_STREAM, 0 ); |
|||
if( m_nMainSocket == -1){ |
|||
LOG_ERROR( "Some trouble with networking on this machine (Socket Error)!"); |
|||
return false; |
|||
}; |
|||
MainSocketAddress = NULL; |
|||
MainSocketAddress = ( struct sockaddr * ) malloc( sizeof( struct sockaddr_in ) ); |
|||
if( MainSocketAddress == NULL ){ |
|||
LOG_ERROR( "Some trouble with networking on this machine (Cannot Alloc Sockaddr Struct)!" ); |
|||
return false; |
|||
}; |
|||
bzero( MainSocketAddress, sizeof( struct sockaddr_in ) ); |
|||
h_info = gethostbyname ( m_pBindAddress ); |
|||
if ( h_info == NULL ){ |
|||
LOG_ERROR( "Some trouble with networking on this machine (Cannot Get Hostname)!" ); |
|||
return false; |
|||
}; |
|||
//*****************************************
|
|||
//* there we building our network address *
|
|||
//*****************************************
|
|||
bcopy( h_info->h_addr, &(((struct sockaddr_in *)MainSocketAddress)->sin_addr), h_info->h_length ); |
|||
((struct sockaddr_in *)MainSocketAddress)->sin_family = h_info->h_addrtype; |
|||
((struct sockaddr_in *)MainSocketAddress)->sin_port = htons( m_nBindPort ); |
|||
|
|||
RetCode = bind( m_nMainSocket , MainSocketAddress, sizeof( struct sockaddr_in ) ); |
|||
if ( RetCode != 0 ){ |
|||
LOG_ERROR( "Error Binding to Port/Address" ); |
|||
return false; |
|||
}; |
|||
RetCode = listen( m_nMainSocket, 128); |
|||
if ( RetCode != 0 ){ |
|||
LOG_ERROR( "Cannot Listen Port/Address" ); |
|||
return false; |
|||
}; |
|||
|
|||
U8 dontblock; |
|||
dontblock = fcntl( m_nMainSocket, F_GETFL, NULL ); |
|||
dontblock |= O_NONBLOCK | O_NDELAY; |
|||
RetCode = ioctl( m_nMainSocket, FIONBIO, (char *) &dontblock ); |
|||
if ( RetCode == 0 ){ |
|||
LOG( "Set N-Blocking Mode of Accepting Socket" ); |
|||
} else { |
|||
LOG( "Can't set N-Blocking Mode of Accepting Socket" ); |
|||
}; |
|||
return init(); |
|||
}; |
|||
|
|||
void LRF_TwinConnector::m_fThreadProc( void ){ |
|||
TWIN_COMMAND * tCMD = NULL; |
|||
int ClientSocket = -1; |
|||
struct sockaddr ClientAddress; |
|||
socklen_t ClientAddressSize; |
|||
|
|||
m_bThreadStatus = TH_WORKING; |
|||
|
|||
while( m_bThreadStatus < TH_ENDED ){ |
|||
if( m_bCCMD == TWC_NO_COMMAND && tCMD == NULL ){ |
|||
// No CMD is EXEC so check new cmds
|
|||
CMD_PROTEC.lock(); |
|||
if( m_qCMD.size() > 0 ){ |
|||
tCMD = m_qCMD.front(); |
|||
m_qCMD.pop(); |
|||
}; |
|||
CMD_PROTEC.unlock(); |
|||
}; |
|||
if( m_pPort != NULL ){ |
|||
if( m_pPort->getConnectionStatus() == CS_DISCONNECTED ){ |
|||
if( tCMD!= NULL ){ |
|||
//reset commands on disconnect
|
|||
m_bCCMD = TWC_NO_COMMAND; |
|||
if( tCMD->PTR == NULL ) free( tCMD->PTR ); |
|||
free( tCMD ); |
|||
tCMD = NULL; |
|||
}; |
|||
delete( m_pPort ); |
|||
m_pPort = NULL; |
|||
continue; |
|||
}; |
|||
if( tCMD!= NULL ){ |
|||
if( m_bCCMD == TWC_NO_COMMAND ){ |
|||
// CMD not issued yet!
|
|||
switch( tCMD->CMD ){ |
|||
case TWC_GET_STATUS:{ |
|||
if( m_pProtocol->requestStatus() ){ |
|||
m_bCCMD = tCMD->CMD; |
|||
}; |
|||
break; |
|||
}; |
|||
case TWC_GET_CONFIG:{ |
|||
break; |
|||
}; |
|||
case TWC_SET_CONFIG:{ |
|||
break; |
|||
}; |
|||
case TWC_GET_THDRAW:{ |
|||
break; |
|||
}; |
|||
case TWC_DO_REBOOT:{ |
|||
break; |
|||
}; |
|||
}; |
|||
} else { |
|||
// Waiting CMD exe status
|
|||
switch( m_bCCMD ){ |
|||
case TWC_GET_STATUS:{ |
|||
if( m_pProtocol->getLastPackageType() == STATUS_ACK ){ |
|||
m_bCCMD = TWC_NO_COMMAND; |
|||
}; |
|||
break; |
|||
}; |
|||
}; |
|||
if( m_bCCMD == TWC_NO_COMMAND && tCMD != NULL ){ |
|||
// The command is finished - Will fetch next command from queue
|
|||
if( tCMD->PTR == NULL ) free( tCMD->PTR ); |
|||
free( tCMD ); |
|||
tCMD = NULL; |
|||
}; |
|||
}; |
|||
SLEEP( 5 ); |
|||
} else { |
|||
SLEEP( 100 ); |
|||
}; |
|||
} else { |
|||
// (re)Establish Connection
|
|||
#ifdef PRU_SLAVE
|
|||
m_pPort = new clientPort( ); |
|||
#else
|
|||
ClientAddressSize = (socklen_t) sizeof( struct sockaddr_in ); |
|||
ClientSocket = accept ( m_nMainSocket, &ClientAddress, &ClientAddressSize ); |
|||
if ( ClientSocket == -1 ) { |
|||
switch( errno ){ |
|||
case EAGAIN:{ |
|||
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 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; |
|||
}; |
|||
m_bThreadStatus = TH_ENDED; |
|||
} else { |
|||
char tstr[CQUERY]; |
|||
inet_ntop( AF_INET, &(((struct sockaddr_in*) &(ClientAddress ))->sin_addr ), tstr, size ); |
|||
}; |
|||
LOG( "SLAVE LRF Connection Accepted" ); |
|||
m_pPort = new serverPort( ClientSocket ); |
|||
}; |
|||
#endif
|
|||
if( m_pPort!= NULL ){ |
|||
if( !m_pPort->create() ){ |
|||
LOG_ERROR( "Connection not established!" ); |
|||
delete( m_pPort ); |
|||
m_pPort = NULL; |
|||
} else { |
|||
m_pPort->attachParser( m_pProtocol ); |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
|
|||
@ -0,0 +1,54 @@ |
|||
#ifndef __LRF_TWINCONNECTOR_H_INCL__ |
|||
#define __LRF_TWINCONNECTOR_H_INCL__ |
|||
|
|||
|
|||
typedef enum E_TWIN_COMMAND{ |
|||
TWC_NO_COMMAND = 0, |
|||
TWC_GET_STATUS = 1, |
|||
TWC_GET_CONFIG = 2, |
|||
TWC_SET_CONFIG = 3, |
|||
TWC_GET_THDRAW = 4, |
|||
TWC_DO_REBOOT = 255 |
|||
} TWIN_COMMAND; |
|||
|
|||
typedef struct S_TWIN_CMD_RECORD{ |
|||
TWIN_COMMAND CMD; |
|||
void * PTR; |
|||
} TWIN_COMMAND; |
|||
|
|||
|
|||
typedef queue<TWIN_COMMAND *> TWIN_COMMAND_QUEUE; |
|||
|
|||
class LRF_TwinConnector: public basicThread { |
|||
private: |
|||
basicLogCollection *m_pLog; |
|||
config_setting_t *m_pSettings; |
|||
TWIN_COMMAND_QUEUE m_qCMD; |
|||
TWIN_COMMAND m_bCCMD; |
|||
basicMutex CMD_PROTEC; |
|||
#ifdef PRU_SLAVE |
|||
protocolInternalLRF3D_SLAVE *m_pProtocol; |
|||
clientPort *m_pPort; |
|||
#else |
|||
protocolInternalLRF3D_MASTER *m_pProtocol; |
|||
serverPort *m_pPort; |
|||
int m_nMainSocket; |
|||
LRF_TargetTracker m_pTracker; |
|||
#endif |
|||
protected: |
|||
void m_fThreadProc( void ); |
|||
public: |
|||
explicit LRF_TwinConnector( config_setting_t *Settings = NULL ); |
|||
virtual ~LRF_TwinConnector(); |
|||
bool create(); |
|||
#ifdef PRU_SLAVE |
|||
bool sendCurrentSettings( void ); |
|||
#else |
|||
bool attachTargetTracker( LRF_TargetTracker *ptr ); |
|||
bool requestSettings( void ); |
|||
#endif |
|||
}; |
|||
|
|||
|
|||
|
|||
#endif |
|||
@ -1,142 +0,0 @@ |
|||
#include "transportSocket.h"
|
|||
|
|||
#define LOG( X ) m_pLog->Log( "TransportSocket", this, X )
|
|||
#define LOG_ERROR( X ) m_pLog->Log( "TransportSocket", this, _LOG_ERROR, X )
|
|||
|
|||
// Constructor implementation
|
|||
transportSocket::transportSocket() : basicTransport(), basicDualThread(){ |
|||
m_pLog = basicLogCollection::getInstance(); |
|||
//m_pInputBuffer = (U8 *)malloc(MAXIMAL_SOCKET_PACKET_LENGTH);
|
|||
//if (m_pInputBuffer != NULL) {
|
|||
m_nInputBufferSize = 0; |
|||
// m_pOutputBuffer = (U8 *)malloc(MAXIMAL_SOCKET_PACKET_LENGTH);
|
|||
// if (m_pOutputBuffer != NULL) {
|
|||
m_nOutputBufferSize = 0; |
|||
#ifdef DEBUG
|
|||
LOG("Init IO Threads!"); |
|||
#endif
|
|||
if( init() ){ //basicDualThread::
|
|||
int cnt = 5; |
|||
while( cnt-- && m_bThreadAStatus < TH_WORKING ) SLEEP(1); // To ensure start Thread procedures
|
|||
#ifdef DEBUG
|
|||
LOG("Init IO Threads Done"); |
|||
#endif
|
|||
} else { |
|||
LOG_ERROR("Init IO Threads ERROR!"); |
|||
}; |
|||
// };
|
|||
//};
|
|||
}; |
|||
|
|||
// Destructor implementation
|
|||
transportSocket::~transportSocket(){ |
|||
# ifdef DEBUG
|
|||
LOG("Destruct: START"); |
|||
# endif
|
|||
m_mBufferProtectorMutex.unlock(); |
|||
if( m_bThreadAStatus > TH_ARMED ) { |
|||
waitThreadAEnd(); |
|||
# ifdef DEBUG
|
|||
LOG("DONE"); |
|||
# endif
|
|||
}; |
|||
m_mQueueProtectorMutex.unlock(); |
|||
if( m_bThreadBStatus > TH_ARMED ) { |
|||
waitThreadBEnd(); |
|||
# ifdef DEBUG
|
|||
LOG("DONE"); |
|||
# endif
|
|||
}; |
|||
//if (m_pInputBuffer != NULL) {
|
|||
// free(m_pInputBuffer);
|
|||
//};
|
|||
//if (m_pOutputBuffer != NULL) {
|
|||
// free(m_pOutputBuffer);
|
|||
//};
|
|||
# ifdef DEBUG
|
|||
LOG("Destruct: DONE"); |
|||
# endif
|
|||
}; |
|||
|
|||
void transportSocket::m_fThreadAProc(void){ |
|||
int index; |
|||
int RetVal; |
|||
m_bThreadAStatus = TH_WORKING; |
|||
LOG("Sender Thread Started!"); |
|||
while (m_bThreadAStatus < TH_ENDED) { |
|||
m_mBufferProtectorMutex.lock(); |
|||
if( m_nOutputBufferSize > 0 ){ |
|||
index = 0; |
|||
while ((index < m_nOutputBufferSize) && (m_bThreadAStatus < TH_ENDED)){ |
|||
RetVal = sendBlock(m_pOutputBuffer + index, m_nOutputBufferSize - index); |
|||
if( RetVal > 0 ) index += RetVal; |
|||
if( RetVal == -1 ){ |
|||
m_bThreadBStatus = TH_ENDED; |
|||
m_bThreadAStatus = TH_ENDED; |
|||
LOG_ERROR("Connection Error[send]"); |
|||
setConnectionStatus( CS_DISCONNECTED ); |
|||
m_nOutputBufferSize = 0; |
|||
}; |
|||
}; |
|||
m_nOutputBufferSize = 0; |
|||
m_mBufferProtectorMutex.unlock(); |
|||
} else { |
|||
m_mBufferProtectorMutex.unlock(); |
|||
SLEEP(5); |
|||
}; |
|||
}; |
|||
}; |
|||
|
|||
void transportSocket::m_fThreadBProc(void){ |
|||
m_bThreadBStatus = TH_WORKING; |
|||
int RetVal; |
|||
LOG("Recipient Thread Started!"); |
|||
while( m_bThreadBStatus < TH_ENDED ){ |
|||
RetVal = recptBlock( m_pInputBuffer, &m_nInputBufferSize); |
|||
if( RetVal == -1 ){ |
|||
LOG_ERROR("Connection Error[rcpt]"); |
|||
m_nInputBufferSize = 0; |
|||
if(!getStatus()) { |
|||
setConnectionStatus(CS_DISCONNECTED); |
|||
m_bThreadBStatus = TH_ENDED; |
|||
m_bThreadAStatus = TH_ENDED; |
|||
} else SLEEP(100); |
|||
} else if( m_nInputBufferSize > 0 ){ |
|||
if (m_vParsers.size()) { |
|||
m_mQueueProtectorMutex.lock(); |
|||
for (parseQueue::iterator index = m_vParsers.begin(); index != m_vParsers.end(); index++) { |
|||
(*index)->parse(m_pInputBuffer, m_nInputBufferSize); |
|||
}; |
|||
m_nInputBufferSize = 0; |
|||
m_mQueueProtectorMutex.unlock(); |
|||
} else { |
|||
LOG_ERROR("Try to parse data but No Parsers Assigned!"); |
|||
}; |
|||
} else { |
|||
SLEEP(5); |
|||
}; |
|||
}; |
|||
}; |
|||
|
|||
bool transportSocket::sendData(unsigned char *Data, int DataSize){ |
|||
|
|||
if( m_bThreadAStatus != TH_WORKING ) { |
|||
LOG_ERROR("Trying to Send Data Before Transport Started!"); |
|||
return false; |
|||
}; |
|||
|
|||
m_mBufferProtectorMutex.lock(); |
|||
if (m_nOutputBufferSize + DataSize > MAXIMAL_SOCKET_PACKET_LENGTH ){ |
|||
m_mBufferProtectorMutex.unlock(); |
|||
LOG_ERROR("Data Too BIG"); |
|||
return false; |
|||
}; |
|||
memcpy(m_pOutputBuffer + m_nOutputBufferSize, Data, DataSize); |
|||
m_nOutputBufferSize += DataSize; |
|||
m_mBufferProtectorMutex.unlock(); |
|||
return true; |
|||
}; |
|||
|
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
@ -1,113 +0,0 @@ |
|||
#include "transportSocket.h" |
|||
|
|||
#define LOG( X ) m_pLog->Log( "TransportSocket", this, X ) |
|||
#define LOG_ERROR( X ) m_pLog->Log( "TransportSocket", this, _LOG_ERROR, X ) |
|||
|
|||
// Constructor implementation |
|||
transportSocket::transportSocket() : basicTransport(), basicDualThread(){ |
|||
m_pLog = basicLogCollection::getInstance(); |
|||
m_pInputBuffer = (U8 *)malloc(MAXIMAL_SOCKET_PACKET_LENGTH); |
|||
if (m_pInputBuffer != NULL) { |
|||
m_nInputBufferSize = 0; |
|||
m_pOutputBuffer = (U8 *)malloc(MAXIMAL_SOCKET_PACKET_LENGTH); |
|||
if (m_pOutputBuffer != NULL) { |
|||
m_nOutputBufferSize = 0; |
|||
init(); |
|||
}; |
|||
}; |
|||
}; |
|||
|
|||
// Destructor implementation |
|||
transportSocket::~transportSocket(){ |
|||
m_mBufferProtectorMutex.unlock(); |
|||
SLEEP(1); |
|||
if( m_bThreadAStatus > TH_ARMED ) { |
|||
waitThreadAEnd( true ); |
|||
}; |
|||
m_mQueueProtectorMutex.unlock(); |
|||
SLEEP(1); |
|||
if( m_bThreadBStatus > TH_ARMED ) { |
|||
waitThreadBEnd( true ); |
|||
}; |
|||
if (m_pInputBuffer != NULL) { |
|||
free(m_pInputBuffer); |
|||
}; |
|||
if (m_pOutputBuffer != NULL) { |
|||
free(m_pOutputBuffer); |
|||
}; |
|||
}; |
|||
|
|||
void transportSocket::m_fThreadAProc(void){ |
|||
m_bThreadAStatus = TH_WORKING; |
|||
while (m_bThreadAStatus < TH_ENDED) { |
|||
m_mBufferProtectorMutex.lock(); |
|||
if( m_nOutputBufferSize > 0 ){ |
|||
int index; |
|||
int RetVal; |
|||
index = 0; |
|||
while ((index < m_nOutputBufferSize) && (m_bThreadAStatus < TH_ENDED)){ |
|||
RetVal = sendBlock(m_pOutputBuffer + index, m_nOutputBufferSize - index); |
|||
if (RetVal > 0) index += RetVal; |
|||
}; |
|||
m_nOutputBufferSize = 0; |
|||
m_mBufferProtectorMutex.unlock(); |
|||
} else { |
|||
m_mBufferProtectorMutex.unlock(); |
|||
SLEEP(1); |
|||
}; |
|||
}; |
|||
}; |
|||
|
|||
void transportSocket::m_fThreadBProc(void){ |
|||
m_bThreadBStatus = TH_WORKING; |
|||
int RetVal; |
|||
while( m_bThreadBStatus < TH_ENDED ){ |
|||
try{ |
|||
RetVal = recptBlock(m_pInputBuffer, &m_nInputBufferSize); |
|||
if (m_nInputBufferSize > 0){ |
|||
m_mQueueProtectorMutex.lock(); |
|||
for (parseQueue::iterator index = m_vParsers.begin(); index != m_vParsers.end(); index++){ |
|||
(*index)->parse(m_pInputBuffer, m_nInputBufferSize); |
|||
}; |
|||
m_mQueueProtectorMutex.unlock(); |
|||
} else if (RetVal == -1){ |
|||
m_bThreadBStatus = TH_ENDED;// |
|||
m_bThreadAStatus = TH_ENDED;// |
|||
LOG_ERROR("Connection Error"); |
|||
} else { |
|||
SLEEP(1); |
|||
}; |
|||
} |
|||
catch (exception e){ |
|||
m_bThreadBStatus = TH_ENDED;// |
|||
m_bThreadAStatus = TH_ENDED;// |
|||
LOG_ERROR("rcptBlock Error"); |
|||
}; |
|||
}; |
|||
LOG("Ended"); |
|||
}; |
|||
|
|||
void transportSocket::setConnectionStatus( CONNECTION_STATUS CS ){ |
|||
m_mQueueProtectorMutex.lock(); |
|||
for (parseQueue::iterator index = m_vParsers.begin(); index != m_vParsers.end(); index++){ |
|||
(*index)->setConnectionStatus( CS ); |
|||
}; |
|||
m_mQueueProtectorMutex.unlock(); |
|||
} |
|||
|
|||
bool transportSocket::sendData(unsigned char *Data, int DataSize){ |
|||
m_mBufferProtectorMutex.lock(); |
|||
if (m_nOutputBufferSize + DataSize > MAXIMAL_SOCKET_PACKET_LENGTH) { |
|||
m_mBufferProtectorMutex.unlock(); |
|||
LOG_ERROR("Data Too BIG"); |
|||
return false; |
|||
}; |
|||
memcpy(m_pOutputBuffer + m_nOutputBufferSize, Data, DataSize); |
|||
m_nOutputBufferSize += DataSize; |
|||
m_mBufferProtectorMutex.unlock(); |
|||
return true; |
|||
}; |
|||
|
|||
|
|||
#undef LOG |
|||
#undef LOG_ERROR |
|||
@ -1,64 +0,0 @@ |
|||
#ifndef __SOCKETTRANSPORT_H_INCL__ |
|||
#define __SOCKETTRANSPORT_H_INCL__ |
|||
|
|||
#include "../../components/base/basicDualThread.h" |
|||
#include "../../components/base/basicTransport.h" |
|||
|
|||
#define MAXIMAL_SOCKET_PACKET_LENGTH 102400 |
|||
|
|||
/** |
|||
* TODO: Add class description |
|||
* |
|||
* @author Gagua |
|||
*/ |
|||
class transportSocket : public basicTransport, public basicDualThread { |
|||
private: |
|||
basicLogCollection *m_pLog; |
|||
protected: |
|||
//U8 *m_pInputBuffer; |
|||
//U8 *m_pOutputBuffer; |
|||
U8 m_pInputBuffer[MAXIMAL_SOCKET_PACKET_LENGTH]; |
|||
U8 m_pOutputBuffer[MAXIMAL_SOCKET_PACKET_LENGTH]; |
|||
int m_nInputBufferSize; |
|||
int m_nOutputBufferSize; |
|||
|
|||
virtual void m_fThreadAProc(void); |
|||
virtual void m_fThreadBProc(void); |
|||
virtual int sendBlock(unsigned char *Data, int DataSize){ return 0; }; |
|||
virtual int recptBlock(unsigned char *Buffer, int *BufferLength){ return 0; }; |
|||
public: |
|||
// Constructor |
|||
transportSocket(); |
|||
|
|||
// Destructor |
|||
virtual ~transportSocket(); |
|||
|
|||
// Copy constructor |
|||
// TODO: Uncomment the copy constructor when you need it. |
|||
//transportSocket(const socketTransport& src); |
|||
|
|||
// Assignment operator |
|||
// TODO: Uncomment the assignment operator when you need it. |
|||
//transportSocket& operator=(const transportSocket& src); |
|||
bool sendData(unsigned char *Data, int DataSize); |
|||
}; |
|||
|
|||
// TODO: Uncomment the copy constructor when you need it. |
|||
//inline transportSocket::transportSocket(const socketTransport& src) |
|||
//{ |
|||
// // TODO: copy |
|||
//} |
|||
|
|||
// TODO: Uncomment the assignment operator when you need it. |
|||
//inline transportSocket& transportSocket::operator=(const transportSocket& rhs) |
|||
//{ |
|||
// if (this == &rhs) { |
|||
// return *this; |
|||
// } |
|||
// |
|||
// // TODO: assignment |
|||
// |
|||
// return *this; |
|||
//} |
|||
|
|||
#endif // __SOCKETTRANSPORT_H_INCL__ |
|||
@ -1,62 +0,0 @@ |
|||
#ifndef __SOCKETTRANSPORT_H_INCL__ |
|||
#define __SOCKETTRANSPORT_H_INCL__ |
|||
|
|||
#include "../../components/base/basicDualThread.h" |
|||
#include "../../components/base/basicTransport.h" |
|||
|
|||
#define MAXIMAL_SOCKET_PACKET_LENGTH 102400 |
|||
|
|||
/** |
|||
* TODO: Add class description |
|||
* |
|||
* @author Gagua |
|||
*/ |
|||
class transportSocket : public basicTransport, public basicDualThread { |
|||
private: |
|||
void m_fThreadAProc(void); |
|||
void m_fThreadBProc(void); |
|||
basicLogCollection *m_pLog; |
|||
protected: |
|||
U8 *m_pInputBuffer; |
|||
int m_nInputBufferSize; |
|||
U8 *m_pOutputBuffer; |
|||
int m_nOutputBufferSize; |
|||
virtual int sendBlock(unsigned char *Data, int DataSize){ return 0; }; |
|||
virtual int recptBlock(unsigned char *Buffer, int *BufferLength){ return 0; }; |
|||
void setConnectionStatus( CONNECTION_STATUS CS ); |
|||
public: |
|||
// Constructor |
|||
transportSocket(); |
|||
|
|||
// Destructor |
|||
virtual ~transportSocket(); |
|||
|
|||
// Copy constructor |
|||
// TODO: Uncomment the copy constructor when you need it. |
|||
//transportSocket(const socketTransport& src); |
|||
|
|||
// Assignment operator |
|||
// TODO: Uncomment the assignment operator when you need it. |
|||
//transportSocket& operator=(const transportSocket& src); |
|||
bool sendData(unsigned char *Data, int DataSize); |
|||
}; |
|||
|
|||
// TODO: Uncomment the copy constructor when you need it. |
|||
//inline transportSocket::transportSocket(const socketTransport& src) |
|||
//{ |
|||
// // TODO: copy |
|||
//} |
|||
|
|||
// TODO: Uncomment the assignment operator when you need it. |
|||
//inline transportSocket& transportSocket::operator=(const transportSocket& rhs) |
|||
//{ |
|||
// if (this == &rhs) { |
|||
// return *this; |
|||
// } |
|||
// |
|||
// // TODO: assignment |
|||
// |
|||
// return *this; |
|||
//} |
|||
|
|||
#endif // __SOCKETTRANSPORT_H_INCL__ |
|||
@ -0,0 +1,369 @@ |
|||
#include "protocolInternalLRF3D.h"
|
|||
#define LOG( X ) m_pLog->Log( "protocolLRF3D", this, X )
|
|||
#ifdef DEBUG
|
|||
#define LOG_ERROR( X ) {\
|
|||
char _tBfrErrMSG234[256];\ |
|||
sprintf( _tBfrErrMSG234, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\ |
|||
m_pLog->Log( "protocolLRF3D", this, _LOG_ERROR, _tBfrErrMSG234 );\ |
|||
} |
|||
#else
|
|||
#define LOG_ERROR( X ) m_pLog->Log( "protocolLRF3D", this, _LOG_ERROR, X );
|
|||
#endif
|
|||
|
|||
protocolInternalLRF3D::protocolInternalLRF3D(): protocolParser(){ |
|||
m_pLog = basicLogCollection::getInstance(); |
|||
}; |
|||
|
|||
protocolInternalLRF3D::~protocolInternalLRF3D(){ |
|||
|
|||
}; |
|||
|
|||
int protocolInternalLRF3D::packetChecker( U8 *Buffer, size_t BufferSize ){ |
|||
#ifdef DUBUG_COMMUNICATION
|
|||
char tmp[32]; |
|||
int i; |
|||
for( i=0;i< BufferSize; i++ ) { |
|||
sprintf( tmp, " 0x%02X", Buffer[i] ); |
|||
LOG(tmp); |
|||
}; |
|||
#endif
|
|||
if( Buffer[0] == 0xAA ){ |
|||
if( BufferSize > 5 ) { |
|||
#ifdef PRU_SLAVE
|
|||
if ((Buffer[1] & 0x80) == 0x80 ){ |
|||
#else
|
|||
if ((Buffer[1] & 0x80) == 0x00 ){ |
|||
#endif
|
|||
size_t pLength; |
|||
pLength = ((Buffer[1] & 0x7F) << 8) | Buffer[2]; |
|||
if( BufferSize >= ( pLength + 4 ) ) { |
|||
U8 pCheckSum; |
|||
pCheckSum = checksumLGS( Buffer, pLength+3 ); |
|||
if( Buffer[pLength+3] == pCheckSum ) { |
|||
#ifdef DUBUG_COMMUNICATION
|
|||
LOG((CSTR)"PacketChecker: Packet Is Recognized (0)"); |
|||
#endif
|
|||
return 0; // Ok
|
|||
} else { |
|||
#ifdef DUBUG_COMMUNICATION
|
|||
LOG((CSTR)"PacketChecker: Packet Not Recognized CHK SUM(-1)"); |
|||
#endif
|
|||
return -1; // To shift
|
|||
}; |
|||
}; |
|||
} else { |
|||
#ifdef DUBUG_COMMUNICATION
|
|||
LOG((CSTR)"PacketChecker: Packet Not Recognized TAG (-1)"); |
|||
#endif
|
|||
return -1; // To shiftSeverity Code Description Project File Line Suppression State
|
|||
}; |
|||
}; |
|||
#ifdef DUBUG_COMMUNICATION
|
|||
LOG((CSTR)"PacketChecker: Packet Not Recognized SMALL SIZE(1)"); |
|||
#endif
|
|||
return 1; // To grow
|
|||
}; |
|||
#ifdef DUBUG_COMMUNICATION
|
|||
LOG((CSTR)"PacketChecker: Packet Not Recognized START TAG(-1)"); |
|||
#endif
|
|||
return -1; // To shift
|
|||
}; |
|||
|
|||
protocolPackage *protocolInternalLRF3D::packetExtractor( U8 *Buffer, size_t BufferSize ){ |
|||
protocolPackage *RetVal; |
|||
#ifdef DUBUG_COMMUNICATION
|
|||
char tmp[32]; |
|||
int i; |
|||
for( i=0;i< BufferSize; i++ ) { |
|||
sprintf( tmp, " 0x%02X", Buffer[i] ); |
|||
LOG(tmp); |
|||
}; |
|||
#endif
|
|||
if( Buffer[0] == 0xAA ){ |
|||
if( BufferSize > 5 ){ |
|||
#ifdef PRU_SLAVE
|
|||
if ((Buffer[1] & 0x80) == 0x80 ) { |
|||
#else
|
|||
if ((Buffer[1] & 0x80) == 0x00 ) { |
|||
#endif
|
|||
size_t pLength; |
|||
pLength = ((Buffer[1] & 0x7F) << 8) | Buffer[2]; |
|||
if( BufferSize >= ( pLength+4 ) ) { |
|||
U8 pCheckSum; |
|||
pCheckSum = checksumLGS(Buffer, pLength+3 ); |
|||
if( Buffer[pLength+3] == pCheckSum ) { |
|||
RetVal = (protocolPackage *) malloc(sizeof(protocolPackage)); |
|||
if( RetVal == NULL ) return NULL; |
|||
RetVal->m_pData =(U8*)malloc( pLength+4 ); |
|||
if( RetVal->m_pData == NULL ) { |
|||
free( RetVal ); |
|||
return NULL; |
|||
}; |
|||
RetVal->m_nSize = pLength+4; |
|||
RetVal->m_nCode = Buffer[CMD_IDX]; |
|||
memcpy( RetVal->m_pData, Buffer, RetVal->m_nSize ); |
|||
#ifdef DUBUG_COMMUNICATION
|
|||
LOG((CSTR)"PacketExtractor: Packet Is Extracted (0)"); |
|||
#endif
|
|||
return RetVal; |
|||
}; |
|||
}; |
|||
} else { |
|||
LOG_ERROR("TAG mismatch!"); |
|||
}; |
|||
}; |
|||
#ifdef DUBUG_COMMUNICATION
|
|||
LOG((CSTR)"PacketExtractor: Packet Not Extracted(1)!!!"); |
|||
#endif
|
|||
return NULL; |
|||
}; |
|||
#ifdef DUBUG_COMMUNICATION
|
|||
LOG((CSTR)"PacketExtractor: Packet Not Extracted(-1)"); |
|||
#endif
|
|||
return NULL; |
|||
}; |
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
|
|||
#ifdef PRU_SLAVE
|
|||
#define LOG( X ) m_pLog->Log( "protocolLRF3D_SLAVE", this, X )
|
|||
#ifdef DEBUG
|
|||
#define LOG_ERROR( X ) {\
|
|||
char _tBfrErrMSG234[256];\ |
|||
sprintf( _tBfrErrMSG234, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\ |
|||
m_pLog->Log( "protocolLRF3D_SLAVE", this, _LOG_ERROR, _tBfrErrMSG234 );\ |
|||
} |
|||
#else
|
|||
#define LOG_ERROR( X ) m_pLog->Log( "protocolLRF3D_SLAVE", this, _LOG_ERROR, X );
|
|||
#endif
|
|||
|
|||
protocolInternalLRF3D_SLAVE::protocolInternalLRF3D_SLAVE( config_setting_t *Settings) : protocolInternalLRF3D() { |
|||
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; |
|||
}; |
|||
|
|||
protocolInternalLRF3D_SLAVE::~protocolInternalLRF3D_SLAVE(){ |
|||
if( m_pMasterAddress != NULL ) free( m_pMasterAddress ); |
|||
}; |
|||
|
|||
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; |
|||
}; |
|||
bool protocolInternalLRF3D_SLAVE::sendTrasholdData( uint8_t lrf_id, uint32_t dataIdx ){ |
|||
}; |
|||
bool protocolInternalLRF3D_SLAVE::sendTargets( void ){ |
|||
}; |
|||
|
|||
bool protocolInternalLRF3D_SLAVE::sendStatus( void ){ |
|||
if( m_oDataTransport == NULL ) return false; |
|||
uint8_t Buffer[16]; |
|||
Buffer[3] = 0xDC; |
|||
Buffer[4] = ( m_nStatus >> 24 ) & 0xFF; |
|||
Buffer[5] = ( m_nStatus >> 16 ) & 0xFF; |
|||
Buffer[6] = ( m_nStatus >> 8 ) & 0xFF; |
|||
Buffer[7] = m_nStatus & 0xFF; |
|||
#ifdef DEBUG
|
|||
LOG("setStatus"); |
|||
#endif
|
|||
return m_oDataTransport->sendData( Buffer, FinishUpPackage( Buffer, 8 ) ); |
|||
}; |
|||
#else
|
|||
#define LOG( X ) m_pLog->Log( "protocolLRF3D_MASTER", this, X )
|
|||
#ifdef DEBUG
|
|||
#define LOG_ERROR( X ) {\
|
|||
char _tBfrErrMSG234[256];\ |
|||
sprintf( _tBfrErrMSG234, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\ |
|||
m_pLog->Log( "protocolLRF3D_MASTER", this, _LOG_ERROR, _tBfrErrMSG234 );\ |
|||
} |
|||
#else
|
|||
#define LOG_ERROR( X ) m_pLog->Log( "protocolLRF3D_MASTER", this, _LOG_ERROR, X );
|
|||
#endif
|
|||
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; |
|||
}; |
|||
#endif
|
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
@ -0,0 +1,72 @@ |
|||
#ifndef __PROTOCOL_LRF_3D_INTERNAL_MASTER_SERVER_COMMUNICATION__ |
|||
#define __PROTOCOL_LRF_3D_INTERNAL_MASTER_SERVER_COMMUNICATION__ |
|||
|
|||
//aliona |
|||
//https://www.pornhub.com/view_video.php?viewkey=ph5dffcb1983567 |
|||
|
|||
#include "protocol.h" |
|||
|
|||
class protocolInternalLRF3D: public protocolParser { |
|||
private: |
|||
basicLogCollection *m_pLog; |
|||
protected: |
|||
int packetChecker( U8 *Buffer, size_t BufferSize ); |
|||
protocolPackage *packetExtractor( U8 *Buffer, size_t BufferSize ); |
|||
inline int FinishUpPackage( U8 *Buffer, size_t Size ){ |
|||
Buffer[0] = 0xAA; |
|||
Buffer[1] = ((Size - 3) >> 8) | SEND_TAG; |
|||
Buffer[2] = (Size - 3) & 0xFF; |
|||
Buffer[Size] = checksumLGS(Buffer, Size); |
|||
return Size + 1; |
|||
}; |
|||
public: |
|||
protocolInternalLRF3D(); |
|||
virtual ~protocolInternalLRF3D(); |
|||
bool create(void); |
|||
|
|||
}; |
|||
#ifdef PRU_SLAVE |
|||
class protocolInternalLRF3D_SLAVE: public protocolInternalLRF3D{ |
|||
private: |
|||
basicLogCollection *m_pLog; |
|||
config_setting_t *m_pSettings; |
|||
CSTR m_pMasterAddress; |
|||
uint16_t m_nMasterPort; |
|||
uint8_t m_bFailureReason; |
|||
uint32_t m_nStatus; |
|||
clientPort *m_pPort; |
|||
bool m_bSettingsIsLoadded; |
|||
bool sendTrasholdData( uint8_t lrf_id, uint32_t dataIdx = 0 ); |
|||
bool sendTargets( void ); |
|||
bool sendStatus( void ); |
|||
protected: |
|||
virtual bool packetHandler( protocolPackage *Package ); |
|||
public: |
|||
explicit protocolInternalLRF3D_SLAVE( config_setting_t *Settings = NULL ); |
|||
virtual ~protocolInternalLRF3D_SLAVE(); |
|||
bool create( void ); |
|||
bool setTrasholdData( uint8_t lrf_id, uint32_t *ptr ); |
|||
bool enqueueTarget( void ); |
|||
uint8_t getFailureReason( void ){ return m_bFailureReason; }; |
|||
}; |
|||
#else |
|||
class protocolInternalLRF3D_MASTER: public protocolInternalLRF3D{ |
|||
private: |
|||
basicLogCollection *m_pLog; |
|||
config_setting_t *m_pSettings; |
|||
protected: |
|||
bool packetHandler( protocolPackage *Package ); |
|||
public: |
|||
explicit protocolInternalLRF3D_MASTER( config_setting_t *Settings = NULL ); |
|||
virtual ~protocolInternalLRF3D_MASTER(); |
|||
bool create(void); |
|||
bool ackDataSegment( uint32_t dataIdx = 0 ); |
|||
bool ackTargets( uint32_t pkgId ); |
|||
bool requestTargets(void); |
|||
bool requestTrasholdData( uint8_t lrf_id ); |
|||
bool requestStatus( void ); |
|||
|
|||
}; |
|||
#endif |
|||
|
|||
#endif |
|||
956
lib/data/protocol/protocolLGS.cpp
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,2 @@ |
|||
#include "protocolLGS2D.h"
|
|||
|
|||
@ -0,0 +1,25 @@ |
|||
#ifndef __PROTOCOL_LGS_2D_HEADERS__ |
|||
#define __PROTOCOL_LGS_2D_HEADERS__ |
|||
|
|||
#include "protocolLGSm.h" |
|||
|
|||
class protocolLGS: public protocolParser{ |
|||
private: |
|||
basicLogCollection * m_pLog; |
|||
basicMutex m_mInquiryMutex; |
|||
protected: |
|||
uint8_t m_bDeviceID; |
|||
basicTransport * m_oDataTransport; |
|||
int packetChecker( uint8_t *Buffer, size_t BufferSize); |
|||
protocolPackage * packetExtractor( uint8_t *Buffer, size_t BufferSize); |
|||
public: |
|||
explicit protocolLGS( basicTransport *Transport = NULL, uint8_t DeviceID = 0 ); |
|||
virtual ~protocolLGS(); |
|||
virtual bool create(void){ return protocolParser::create(); }; |
|||
uint8_t getDeviceID(void) { return m_bDeviceID; }; |
|||
basicTransport * getTransport(void) { return m_oDataTransport; }; |
|||
bool setDeviceID( uint8_t DeviceID ){ m_bDeviceID = DeviceID; return true; }; |
|||
bool setTransport(basicTransport* m_oDataTransport); |
|||
}; |
|||
|
|||
#endif |
|||
@ -0,0 +1,134 @@ |
|||
#include "protocolLGS.h"
|
|||
|
|||
#define LOG( X ) m_pLog->Log( "LGSM", this, X )
|
|||
#define LOG_ERROR( X ) m_pLog->Log( "LGSM", this, _LOG_ERROR, X )
|
|||
|
|||
protocolLGSm::protocolLGSm( basicTransport *Transport, U8 DeviceID ):protocolParser(){ |
|||
m_pLog = basicLogCollection::getInstance(); |
|||
m_bDeviceID = DeviceID; |
|||
m_oDataTransport = Transport; |
|||
if( m_oDataTransport != NULL ) { |
|||
m_oDataTransport->addRecipient( ( protocolParser *) this ); |
|||
}; |
|||
}; |
|||
|
|||
protocolLGSm::~protocolLGSm(){ |
|||
# ifdef DEBUG
|
|||
LOG("Destructor Begin"); |
|||
# endif
|
|||
m_mInquiryMutex.unlock(); |
|||
# ifdef DEBUG
|
|||
LOG("Destructor End"); |
|||
# endif
|
|||
}; |
|||
|
|||
bool protocolLGSm::setTransport(basicTransport* Transport){ |
|||
if (Transport == NULL) return false; |
|||
if (m_oDataTransport != NULL) { |
|||
LOG_ERROR("Transport Already Assigned!"); |
|||
return false; |
|||
}; |
|||
m_oDataTransport = Transport; |
|||
return m_oDataTransport->addRecipient(this); |
|||
}; |
|||
|
|||
int protocolLGSm::packetChecker(U8 *Buffer, size_t BufferSize ){ |
|||
#ifdef DUBUG_COMMUNICATION
|
|||
char tmp[32]; |
|||
int i; |
|||
for( i=0;i< BufferSize; i++ ) { |
|||
sprintf( tmp, " 0x%02X", Buffer[i] ); |
|||
LOG(tmp); |
|||
}; |
|||
#endif
|
|||
if( Buffer[0] == 0x55 ){ |
|||
if( BufferSize > 5 ) { |
|||
if (((Buffer[SIZE_IDX_A] & MASTER_TAG) == ACCEPT_TAG) && (Buffer[DEV_ID_IDX] == m_bDeviceID || Buffer[DEV_ID_IDX] == 0)){ |
|||
size_t pLength; |
|||
pLength = ((Buffer[SIZE_IDX_A] & 0x7F) << 8) | Buffer[SIZE_IDX_B]; |
|||
if( BufferSize >= ( pLength + 4 ) ) { |
|||
U8 pCheckSum; |
|||
pCheckSum = checksumLGS(Buffer, pLength+3 ); |
|||
if( Buffer[pLength+3] == pCheckSum ) { |
|||
#ifdef DUBUG_COMMUNICATION
|
|||
LOG((CSTR)"PacketChecker: Packet Is Recognized (0)"); |
|||
#endif
|
|||
return 0; // Ok
|
|||
} else { |
|||
#ifdef DUBUG_COMMUNICATION
|
|||
LOG((CSTR)"PacketChecker: Packet Not Recognized CHK SUM(-1)"); |
|||
#endif
|
|||
return -1; // To shift
|
|||
}; |
|||
}; |
|||
} else { |
|||
#ifdef DUBUG_COMMUNICATION
|
|||
LOG((CSTR)"PacketChecker: Packet Not Recognized TAG (-1)"); |
|||
#endif
|
|||
return -1; // To shiftSeverity Code Description Project File Line Suppression State
|
|||
|
|||
}; |
|||
}; |
|||
#ifdef DUBUG_COMMUNICATION
|
|||
LOG((CSTR)"PacketChecker: Packet Not Recognized SMALL SIZE(1)"); |
|||
#endif
|
|||
return 1; // To grow
|
|||
}; |
|||
#ifdef DUBUG_COMMUNICATION
|
|||
LOG((CSTR)"PacketChecker: Packet Not Recognized START TAG(-1)"); |
|||
#endif
|
|||
return -1; // To shift
|
|||
}; |
|||
|
|||
protocolPackage *protocolLGSm::packetExtractor(U8 *Buffer, size_t BufferSize ){ |
|||
protocolPackage *RetVal; |
|||
#ifdef DUBUG_COMMUNICATION
|
|||
char tmp[32]; |
|||
int i; |
|||
for( i=0;i< BufferSize; i++ ) { |
|||
sprintf( tmp, " 0x%02X", Buffer[i] ); |
|||
LOG(tmp); |
|||
}; |
|||
#endif
|
|||
if( Buffer[0] == 0x55 ){ |
|||
if( BufferSize > 5 ){ |
|||
if (((Buffer[SIZE_IDX_A] & MASTER_TAG) == ACCEPT_TAG) && (Buffer[DEV_ID_IDX] == m_bDeviceID || Buffer[DEV_ID_IDX] == 0)) { |
|||
size_t pLength; |
|||
pLength = ((Buffer[SIZE_IDX_A] & 0x7F) << 8) | Buffer[SIZE_IDX_B]; |
|||
if( BufferSize >= ( pLength+4 ) ) { |
|||
U8 pCheckSum; |
|||
pCheckSum = checksumLGS(Buffer, pLength+3 ); |
|||
if( Buffer[pLength+3] == pCheckSum ) { |
|||
RetVal = (protocolPackage *) malloc(sizeof(protocolPackage)); |
|||
if( RetVal == NULL ) return NULL; |
|||
RetVal->m_pData =(U8*)malloc( pLength+4 ); |
|||
if( RetVal->m_pData == NULL ) { |
|||
free( RetVal ); |
|||
return NULL; |
|||
}; |
|||
RetVal->m_nSize = pLength+4; |
|||
RetVal->m_nCode = Buffer[CMD_IDX]; |
|||
memcpy( RetVal->m_pData, Buffer, RetVal->m_nSize ); |
|||
#ifdef DUBUG_COMMUNICATION
|
|||
LOG((CSTR)"PacketExtractor: Packet Is Extracted (0)"); |
|||
#endif
|
|||
return RetVal; |
|||
}; |
|||
}; |
|||
} else { |
|||
LOG_ERROR("TAG mismatch!"); |
|||
}; |
|||
}; |
|||
#ifdef DUBUG_COMMUNICATION
|
|||
LOG((CSTR)"PacketExtractor: Packet Not Extracted(1)!!!"); |
|||
#endif
|
|||
return NULL; |
|||
}; |
|||
#ifdef DUBUG_COMMUNICATION
|
|||
LOG((CSTR)"PacketExtractor: Packet Not Extracted(-1)"); |
|||
#endif
|
|||
return NULL; |
|||
}; |
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
@ -0,0 +1,808 @@ |
|||
#ifndef __PROTOCOL_LGS_HEADERS__ |
|||
#define __PROTOCOL_LGS_HEADERS__ |
|||
|
|||
#include "../../components/base/basicFunctionality.h" |
|||
#include "../../components/base/basicTransport.h" |
|||
#include "../../components/base/basicMutex.h" |
|||
#include "../../components/base/basicEventHeap.h" |
|||
#include "../../hardware/soc/general/3DLRF.h" |
|||
#include "../../alg/lgs/mask.h" |
|||
|
|||
#include "protocol.h" |
|||
|
|||
#define TARGET_WITH_WIDTH |
|||
#define MAXIMAL_SOCKET_PACKET_LENGTH 102400 |
|||
#define BOARDDATA_PACKAGE_SIZE_BYTES 0x4000 |
|||
#define BOARDDATA_PACKAGE_SIZE_NODES 0x1000 |
|||
|
|||
/* |
|||
typedef struct S_LGS_PARAMETERS{ |
|||
uint8_t nOrder; |
|||
uint8_t nOffset; |
|||
uint8_t nDelta; |
|||
uint8_t nSun; |
|||
uint8_t bSST; |
|||
uint16_t nFlip; // For Quick models (pls30) must be up to 1024 |
|||
uint32_t nWidth; // With future devices may gain big numbers |
|||
// 3D LRF Specific |
|||
uint8_t bBuildThByCore; |
|||
uint8_t nGPointSamples; |
|||
} LGS_PARAMETERS, *PLGS_PARAMETERS; |
|||
*/ |
|||
|
|||
typedef enum{ |
|||
STG_DISCONNECTED = 0x00, |
|||
STG_CONNECTED = 0x01, |
|||
STG_STUDY = 0x02, |
|||
STG_REDY = 0x04, |
|||
STG_BUSY = 0x06, |
|||
STG_NONE = 0xFF |
|||
}E_LGS_STAGE; |
|||
|
|||
typedef enum{ |
|||
CWM_INIT = 0, |
|||
CWM_PINGPONG = 1, |
|||
CWM_BORDER = 2, |
|||
CWM_FILE = 3, |
|||
CWM_MASK = 4, |
|||
CWM_PARAMS = 5, |
|||
CWM_INITIAL_PARAM = 252, |
|||
CWM_INITIAL_MASKS_INFO = 253, |
|||
CWM_INITIAL_MASKS_DATA = 254, |
|||
CWM_ERROR = 255 |
|||
} E_CLIENT_WORK_MODE; |
|||
|
|||
typedef enum{ |
|||
SUB_DATA_INTEGRITY_UNKNOWN = 0x00, |
|||
SUB_DATA_INTEGRITY_ERROR = 0xA5, |
|||
SUB_DATA_INTEGRITY_VALID = 0xFF |
|||
}E_LGS_DATA_INTEGRITY_FLAG; |
|||
|
|||
// commands |
|||
typedef enum{ |
|||
CMD_STATE = 0x00, |
|||
CMD_QUIT = 0x01, |
|||
CMD_RESET = 0x02, |
|||
CMD_BORDER = 0x03, |
|||
CMD_MODE = 0x04, |
|||
CMD_GETFILE = 0x05, |
|||
CMD_RESTART = 0x06, |
|||
CMD_PARAMETERS = 0x07, |
|||
CMD_GET_SERIAL_NUMBER = 0x08, |
|||
CMD_SET_ADDRESS = 0x09, |
|||
CMD_GET_SOFTWARE_VERSION = 0x0A, |
|||
CMD_UNSUPPORTED = 0x0B, |
|||
CMD_SET_COMM_SPEED = 0x0C, |
|||
CMD_FULL_BORDER = 0x0D, |
|||
CMD_FULL_RESET = 0x0E, |
|||
CMD_CAMERA = 0x0F, |
|||
CMD_SET_SERIAL_NUMBER = 0x10, |
|||
CMD_BOARDDATA = 0x11, |
|||
CMD_GET_CAMERA_PARAMETERS = 0x12, |
|||
CMD_SET_CAMERA_PARAMETERS = 0x13, |
|||
CMD_RELAY = 0x14, |
|||
CMD_GET_RELAY_PARAMETERS = 0x15, |
|||
CMD_SET_RELAY_PARAMETERS = 0x16, |
|||
CMD_FS_SUB_PACKET = 0x17, |
|||
CMD_STATE_2 = 0x18, |
|||
CMD_GET_WIDTH_TABLE = 0x19, |
|||
CMD_SET_WIDTH_TABLE = 0x1A, |
|||
CMD_GET_VOLTAGE = 0x1B, |
|||
CMD_GET_VOLTAGE_PARAMETERS = 0x1C, |
|||
CMD_SET_VOLTAGE_PARAMETERS = 0x1D, |
|||
CMD_GET_HZ_DATA = 0x1E, |
|||
CMD_SET_HZ_DATA = 0x1F, |
|||
CMD_GET_CALIBRATION_TABLE = 0x20, |
|||
CMD_SET_CALIBRATION_TABLE = 0x21, |
|||
CMD_GET_LRF_DISABLE = 0x22, |
|||
CMD_SET_LRF_DISABLE = 0x23, |
|||
CMD_GET_ZOOM_TABLE = 0x24, |
|||
CMD_SET_ZOOM_TABLE = 0x25, |
|||
CMD_GET_TILT_TABLE = 0x26, |
|||
CMD_SET_TILT_TABLE = 0x27, |
|||
CMD_GET_HZ_ENABLE = 0x28, |
|||
CMD_SET_HZ_ENABLE = 0x29, |
|||
CMD_EVT = 0x2A, |
|||
CMD_GET_PARAMETERS = 0x2B, |
|||
CMD_SET_PARAMETERS = 0x2C, |
|||
CMD_FLIP_COMPLETE = 0x2D, |
|||
CMD_SCAN_COMPLETE = 0x2E, |
|||
CMD_TARGET = 0x2F, |
|||
CMD_TARGET_WW = 0x30, |
|||
CMD_TARGET_MW = 0x31, |
|||
CMD_TARGET_MB = 0x32, |
|||
CMD_TARGET_ZZ = 0x33, |
|||
CMD_GET_HZ_INFO = 0x34, |
|||
CMD_HZ_INFO = 0x35, |
|||
CMD_GET_HZ_POLY = 0x36, |
|||
CMD_SET_HZ_POLY = 0x37, |
|||
CMD_SET_HZ_POLY_ACK = 0x38, |
|||
CMD_GET_HZ_STATUS = 0x39, |
|||
CMD_SET_HZ_STATUS = 0x3A, |
|||
|
|||
CMD_DHWM_START_MOTORS = 0x50, |
|||
CMD_DHWM_STOP_MOTORS = 0x51, |
|||
CMD_ACK = 0xFA, |
|||
CMD_NACK = 0xFB, |
|||
CMD_NONE = 0xFF |
|||
} E_LGS_CMD; |
|||
|
|||
// modes |
|||
enum{ |
|||
MODE_SET = 0x80, // 10000000 set/get mode |
|||
MODE_MASK = 0x0F, // 00001111 mode mask |
|||
MODE_DETECTOR = 0x01, // 00000001 detecting mode - default |
|||
MODE_BORDER = 0x02, // 00000010 border of visibilite draw mode |
|||
MODE_FILESYSTEM = 0x03, // 00000011 remote file system server mode |
|||
MODE_GETFILE = 0x04, // 00000100 get file mode |
|||
MODE_SENDBOARDDATA1 = 0x05, // 00000101 send board data for external processing |
|||
MODE_SENDBOARDDATA2 = 0x06, // 00000110 send board data for external processing |
|||
MODE_BOARDDATA = 0x07 // 00000111 board data for external processing |
|||
}; |
|||
|
|||
// --------------- CMD_STATE ---------------------- |
|||
// information type |
|||
enum{ |
|||
IT_MASK = 0x80, // 10000000 |
|||
IT_ERROR = 0x00, // 00000000 |
|||
IT_TARGET = 0x80 // 10000000 |
|||
}; |
|||
|
|||
// device id |
|||
enum{ |
|||
ID_MASK = 0x40, // 01000000 |
|||
ID_DEVICE0 = 0x00, // 00000000 |
|||
ID_DEVICE1 = 0x40 // 01000000 |
|||
}; |
|||
|
|||
// target type |
|||
enum{ |
|||
TT_MASK = 0x3C, // 00111100 |
|||
TT_NORMAL = 0x00, // 00000000 |
|||
TT_WIDE = 0x04, // 00000100 |
|||
TT_FLIP = 0x08, // 00001000 |
|||
TT_CAMERA = 0x0C, // 00001100 |
|||
TT_TEST = 0x10, // 00010000 |
|||
TT_BLIND = 0x14 // 00010100 |
|||
}; |
|||
|
|||
// target data |
|||
enum{ |
|||
TD_MASK = 0x03, // 00000011 |
|||
TD_ANGLE = 0x02, // 00000010 |
|||
TD_RANGE = 0x01 // 00000001 |
|||
}; |
|||
|
|||
// errors |
|||
enum{ |
|||
ER_MASK = 0x3F, // 00111111 |
|||
ER_NONE = 0x00, // 00000000 |
|||
ER_ANGLE = 0x01, // 00000001 |
|||
ER_SUNBIT = 0x02, // 00000010 |
|||
ER_OVERFLOW = 0x04, // 00000100 |
|||
ER_SSTOVERFLOW = 0x08, // 00001000 |
|||
ER_MODE = 0x10, // 00010000 |
|||
ER_NOIRQ = 0x20 // 00100000 |
|||
}; |
|||
|
|||
// --------------- CMD_BORDER ---------------------- |
|||
enum{ |
|||
BD_ERRORMASK = 0xE0, // 11100000 |
|||
BD_ERRORMODE = 0x80, // 10000000 |
|||
BD_ERRORANGLE = 0x40, // 01000000 |
|||
BD_NOTREADY = 0x20, // 00100000 |
|||
BD_ANGLEMASK = 0x10, // 00010000 |
|||
BD_RANGE0MASK = 0x0C, // 00001100 |
|||
BD_RANGE1MASK = 0x03, // 00000011 |
|||
}; |
|||
// --------------- CMD_FILE ------------------ |
|||
enum{ |
|||
GF_ERRORMASK = 0xC0, // 11000000 |
|||
GF_ERRORMODE = 0x80, // 10000000 |
|||
GF_ERRORFILE = 0x40, // 01000000 |
|||
GF_OP_INDEX = 0x3C, // 00111100 |
|||
GF_OP_MASK = 0x03, // 00000011 |
|||
GF_OP_OK = 0x00, // 00000000 |
|||
GF_OP_OPEN = 0x01, // 00000001 |
|||
GF_OP_DATA = 0x02, // 00000010 |
|||
GF_OP_CLOSE = 0x03, // 00000011 |
|||
}; |
|||
// --------------- CMD_PARAMETERS ------------------ |
|||
enum{ |
|||
DP_OP_MASK = 0x80, |
|||
DP_OP_GET = 0x00, |
|||
DP_OP_SET = 0x80, |
|||
DP_DEVICE_MASK = 0x40, |
|||
DP_DEVICE_0 = 0x00, |
|||
DP_DEVICE_1 = 0x40, |
|||
DP_SST = 0x01, |
|||
}; |
|||
|
|||
enum{ |
|||
FB_READY_MASK = 0x80, // 10000000 |
|||
FB_READY = 0x80, // 10000000 |
|||
FB_NOT_READY = 0x00, // 10000000 |
|||
FB_ANGLE_MASK = 0x1F, // 00011111 |
|||
FB_RANGE_MASK = 0xF00, // 00011111 |
|||
FB_RANGE_1_SHIFT = 4, // 11110000 |
|||
FB_RANGE_2_SHIFT = 8, // 00001111 |
|||
}; |
|||
|
|||
// --------------- CMD_CAMERA ------------------ |
|||
/* |
|||
typedef enum{ |
|||
CMD_CAMERA_GET_STATUS = 0, |
|||
CMD_CAMERA_GET_PTZ = 1, |
|||
CMD_CAMERA_SET_PTZ = 2, |
|||
CMD_CAMERA_MOVE_PAN = 3, |
|||
CMD_CAMERA_MOVE_TILT = 4, |
|||
CMD_CAMERA_MOVE_ZOOM = 5, |
|||
CMD_CAMERA_SET_IRIS = 6, |
|||
CMD_CAMERA_BUSY = 7, |
|||
CMD_CAMERA_ERROR = 8, |
|||
CMD_CAMERA_WIPER = 9, |
|||
CMD_CAMERA_SET_FOCUS = 10, |
|||
CMD_CAMERA_GET_FOCUS = 11, |
|||
CMD_CAMERA_MOVE_FOCUS = 12, |
|||
CMD_CAMERA_GET_DOPLER = 13, |
|||
CMD_CAMERA_SET_DOPLER = 14, |
|||
CMD_CAMERA_DOPLER_ALARM = 15, |
|||
CMD_CAMERA_GET_DOPLER_MASK = 16, |
|||
CMD_CAMERA_SET_DOPLER_MASK = 17, |
|||
}E_CAMERA_CMD; |
|||
*/ |
|||
|
|||
enum{ |
|||
CAMERA_ERROR_NO_CAMERA = 0 |
|||
}; |
|||
|
|||
enum{ |
|||
CAMERA_MAX_DOPLER_MASK = 8 |
|||
}; |
|||
|
|||
typedef struct CAMERA_POS_PTZ{ |
|||
U16 posPan; |
|||
U16 posTilt; |
|||
U16 posZoom; |
|||
}CAMERA_POS_PTZ; |
|||
|
|||
typedef struct CAMERA_MOVE_PAN{ |
|||
U16 panSpeed; |
|||
U8 panRight; |
|||
}CAMERA_MOVE_PAN; |
|||
|
|||
typedef struct CAMERA_MOVE_TILT{ |
|||
U16 tiltSpeed; |
|||
U8 tiltUp; |
|||
}CAMERA_MOVE_TILT; |
|||
|
|||
typedef struct CAMERA_MOVE_ZOOM{ |
|||
U16 zoomSpeed; |
|||
U8 zoomTele; |
|||
}CAMERA_MOVE_ZOOM; |
|||
|
|||
typedef struct CAMERA_MOVE_FOCUS{ |
|||
U16 focusSpeed; |
|||
U8 focusFar; |
|||
}CAMERA_MOVE_FOCUS; |
|||
|
|||
typedef struct CAMERA_POS_IRIS{ |
|||
U16 irisValue; |
|||
}CAMERA_POS_IRIS; |
|||
|
|||
typedef struct CAMERA_POS_FOCUS{ |
|||
U16 focusValue; |
|||
}CAMERA_POS_FOCUS; |
|||
|
|||
typedef struct CAMERA_BUSY{ |
|||
U8 busyCommand; |
|||
}CAMERA_BUSY; |
|||
|
|||
typedef struct CAMERA_ERROR{ |
|||
U16 errID; |
|||
}CAMERA_ERROR; |
|||
|
|||
typedef struct CAMERA_WIPER{ |
|||
U8 wiperOn; |
|||
}CAMERA_WIPER; |
|||
|
|||
typedef struct CAMERA_DOPLER{ |
|||
U8 doplerOn; |
|||
U16 doplerPanStep; |
|||
U32 doplerTimeout; |
|||
}CAMERA_DOPLER; |
|||
|
|||
typedef struct CAMERA_DOPLER_ALARM{ |
|||
U8 doplerAlarm; |
|||
U16 doplerPan; |
|||
}CAMERA_DOPLER_ALARM; |
|||
|
|||
typedef struct CAMERA_DOPLER_MASK{ |
|||
U16 nStart; |
|||
U16 nStop; |
|||
}CAMERA_DOPLER_MASK; |
|||
|
|||
typedef struct CAMERA_DOPLER_MASK_ARRAY{ |
|||
U8 bEnabled; |
|||
U8 nCount; |
|||
CAMERA_DOPLER_MASK pMask[CAMERA_MAX_DOPLER_MASK]; |
|||
}CAMERA_DOPLER_MASK_ARRAY; |
|||
|
|||
typedef struct CAMERA_DATA{ |
|||
U8 nCommand; |
|||
union { |
|||
CAMERA_POS_PTZ posPTZ; |
|||
CAMERA_MOVE_PAN movePan; |
|||
CAMERA_MOVE_TILT moveTilt; |
|||
CAMERA_MOVE_ZOOM moveZoom; |
|||
CAMERA_POS_IRIS posIris; |
|||
CAMERA_BUSY busy; |
|||
CAMERA_ERROR error; |
|||
CAMERA_WIPER wiper; |
|||
CAMERA_POS_FOCUS posFocus; |
|||
CAMERA_MOVE_FOCUS moveFocus; |
|||
CAMERA_DOPLER dopler; |
|||
CAMERA_DOPLER_ALARM doplerAlarm; |
|||
CAMERA_DOPLER_MASK_ARRAY doplerMask; |
|||
}; |
|||
} CAMERA_DATA, *PCAMERA_DATA; |
|||
|
|||
// --------------- CMD_GET_CAMERA_PARAMETERS / CMD_SET_CAMERA_PARAMETERS ------------------ |
|||
typedef enum{ |
|||
CAMERA_TYPE_MIGVAN_878 = 0x00, |
|||
CAMERA_TYPE_MIGVAN_KD6Z = 0x01, |
|||
CAMERA_TYPE_MIC1300 = 0x02, |
|||
CAMERA_TYPE_JVC_TKS576 = 0x03, |
|||
CAMERA_TYPE_PHILIPS_G3AD_NEW= 0x04, |
|||
CAMERA_TYPE_VICON = 0x05, |
|||
CAMERA_TYPE_PELCO = 0x06, |
|||
CAMERA_TYPE_HEBRON = 0x07, |
|||
CAMERA_TYPE_3_TRACK = 0x08, |
|||
CAMERA_TYPE_AMERICAN_DYNAMICS = 0x09, |
|||
CAMERA_TYPE_PHILIPS_G3AD_OLD= 0x0A, |
|||
CAMERA_TYPE_NESHER = 0x0B, |
|||
CAMERA_TYPE_NONE = 0xFF, |
|||
}E_CAMERA_TYPE; |
|||
|
|||
// ------------------------------------ CMD_RELAY --------------------------------------- |
|||
typedef enum{ |
|||
CMD_RELAY_GET = 0, |
|||
CMD_RELAY_SET = 1, |
|||
}E_RELAY_CMD; |
|||
|
|||
typedef struct RELAY_DATA{ |
|||
U8 nCommand; |
|||
U8 bOutput; |
|||
}RELAY_DATA, *PRELAY_DATA; |
|||
|
|||
typedef struct RELAY_PARAMETERS{ |
|||
U8 bAuto; // allow auto relay |
|||
U8 bNormallyClose; |
|||
U16 nAutoDelay; // in 0.1 sec (0,0 .. 3000,0 sec) |
|||
}RELAY_PARAMETERS, *PRELAY_PARAMETERS; |
|||
|
|||
// --------------- CMD_STATE_2 ------------------------ |
|||
typedef enum S2_INFO_TYPE{ |
|||
S2_IT_TARGET_POLAR = 0, |
|||
S2_IT_TARGET_DEKART = 1, |
|||
S2_IT_FLAGS = 2, |
|||
S2_IT_DEVICE_FLAGS = 3, |
|||
S2_IT_ERROR_ANGLE = 4, |
|||
S2_IT_FLIP = 5, |
|||
S2_IT_BLIND = 6, |
|||
S2_IT_TARGET_POLAR_WIDTH = 7, // SERGEY 2008/05/02 |
|||
S2_IT_TARGET_DEKART_WIDTH = 8 // SERGEY 2008/05/02 |
|||
}S2_INFO_TYPE; |
|||
|
|||
typedef enum S2_INFO_TYPE_FLAGS{ |
|||
S2_ITF_ERROR_MODE = 0x01, |
|||
S2_ITF_ERROR_NO_IRQ = 0x02, |
|||
S2_ITF_ERROR_NO_ZERO_MARK = 0x04, |
|||
S2_ITF_CAMERA = 0x08, |
|||
S2_ITF_VOLTAGE = 0x10, |
|||
}S2_INFO_TYPE_FLAGS; |
|||
|
|||
typedef enum S2_INFO_TYPE_DEVICE_FLAGS{ |
|||
S2_ITDF_ERROR_SUN = 0x01, |
|||
S2_ITDF_ERROR_OVERFLOW = 0x02, |
|||
S2_ITDF_ERROR_SST_OVERFLOW = 0x04, |
|||
}S2_INFO_TYPE_DEVICE_FLAGS; |
|||
|
|||
typedef enum S2_INFO_TYPE_TARGET{ |
|||
S2_ITT_NORMAL = 0x00, |
|||
S2_ITT_WIDE = 0x10, |
|||
S2_ITT_TYPE_MASK = 0xF0, |
|||
S2_ITT_DEVICE_MASK = 0x0F, |
|||
}S2_INFO_TYPE_TARGET; |
|||
|
|||
typedef enum S2_INFO_TYPE_BLIND{ |
|||
S2_ITB_STATE_MASK = 0x80, |
|||
S2_ITB_START = 0x00, |
|||
S2_ITB_STOP = 0x80, |
|||
S2_ITB_REASON_MASK = 0x7F, |
|||
S2_ITB_MEDIUM_RANGE = 0x01, |
|||
S2_ITB_180_DEGREE = 0x02, |
|||
S2_ITB_FOG_SPIKES = 0x03, |
|||
S2_ITB_PD = 0x04, |
|||
}S2_INFO_TYPE_BLIND; |
|||
|
|||
typedef enum S2_REQUEST_TYPE{ |
|||
S2_RT_TARGET_MASK = 0x01, |
|||
S2_RT_TARGET_POLAR = 0x00, |
|||
S2_RT_TARGET_DEKART = 0x01, |
|||
}S2_REQUEST_TYPE; |
|||
|
|||
typedef enum S2_REQUEST_WIDTH{ |
|||
S2_RW_MASK = 0x02, |
|||
S2_RW_DISABLE = 0x00, |
|||
S2_RW_ENABLE = 0x02, |
|||
}S2_REQUEST_WIDTH; |
|||
|
|||
typedef struct S_S2_PACKAGE{ |
|||
uint32_t aaa; |
|||
}S2_PACKAGE; |
|||
|
|||
// --------------- CMD_INFO ------------ |
|||
|
|||
|
|||
|
|||
// --------------- CMD_FS_SUB_PACKET ------------------ |
|||
enum{ |
|||
FS_CMD_SEND_CMD = 0, |
|||
FS_CMD_SEND_EVT = 1, |
|||
FS_CMD_RECEIVE_CMD = 2, |
|||
FS_CMD_RECEIVE_EVT = 3, |
|||
|
|||
FS_ERROR_SUCCESS = 0x00, // 00000000 |
|||
FS_ERROR_MODE = 0x01, // 00000001 |
|||
}; |
|||
|
|||
typedef struct FS_SEND_CMD{ |
|||
U8 nOrder; |
|||
U8 nLast; |
|||
U16 nPosition; |
|||
U8 nSubSize; |
|||
U8 pSubBuffer[1]; |
|||
}FS_SEND_CMD; |
|||
|
|||
typedef struct FS_SEND_EVT{ |
|||
U8 nError; |
|||
U8 nOrder; |
|||
}FS_SEND_EVT; |
|||
|
|||
typedef struct FS_RECEIVE_CMD{ |
|||
U8 nOrder; |
|||
U16 nPosition; |
|||
}FS_RECEIVE_CMD; |
|||
|
|||
typedef struct FS_RECEIVE_EVT{ |
|||
U8 nError; |
|||
U8 nOrder; |
|||
U8 nLast; |
|||
U16 nPosition; |
|||
U8 nSubSize; |
|||
U8 pSubBuffer[1]; |
|||
}FS_RECEIVE_EVT; |
|||
|
|||
typedef struct FS_DATA{ |
|||
U8 nCommand; |
|||
union { |
|||
FS_SEND_CMD sendcmd; |
|||
FS_SEND_EVT sendevt; |
|||
FS_RECEIVE_CMD receivecmd; |
|||
FS_RECEIVE_EVT receiveevt; |
|||
}; |
|||
}FS_DATA, *PFS_DATA; |
|||
|
|||
typedef struct FS_DATA_EX : public FS_DATA { |
|||
U8 pReserved[MAX_PATH]; |
|||
}FS_DATA_EX, *PFS_DATA_EX; |
|||
|
|||
// --------------- CMD_GET_WIDTH_TABLE & CMD_SET_WIDTH_TABLE ------------------------ |
|||
enum { WIDTH_TABLE_SIZE = 16 }; |
|||
|
|||
typedef struct WIDTH_TABLE{ |
|||
U8 nCount; |
|||
U16 pTable[WIDTH_TABLE_SIZE]; |
|||
}WIDTH_TABLE, *PWIDTH_TABLE; |
|||
|
|||
// --------------- CMD_VOLTAGE ------------------ |
|||
typedef enum VOLTAGE_STATUS{ |
|||
VS_OK = 0, |
|||
VS_FAILURE = 1, |
|||
}VOLTAGE_STATUS; |
|||
|
|||
// --------------- CMD_GET_VOLTAGE_PARAMETERS / CMD_SET_VOLTAGE_PARAMETERS ------------------ |
|||
typedef struct VOLTAGE_PARAMETERS{ |
|||
U8 bControl; |
|||
}VOLTAGE_PARAMETERS, *PVOLTAGE_PARAMETERS; |
|||
|
|||
// -------------- CMD_HZ_GET_DATA / CMD_HZ_SET_DATA ----------------------------- |
|||
typedef enum HZ_INFO_TYPE{ |
|||
HZIT_CMD_GET_HEADER = 0, |
|||
HZIT_EVT_GET_HEADER = 1, |
|||
HZIT_CMD_GET_POLYGON = 2, |
|||
HZIT_EVT_GET_POLYGON = 3, |
|||
HZIT_CMD_GET_POLYGON_POINT = 4, |
|||
HZIT_EVT_GET_POLYGON_POINT = 5, |
|||
HZIT_CMD_GET_RAY = 6, |
|||
HZIT_EVT_GET_RAY = 7, |
|||
HZIT_CMD_GET_RAY_LINE = 8, |
|||
HZIT_EVT_GET_RAY_LINE = 9, |
|||
HZIT_CMD_SET_HEADER = 10, |
|||
HZIT_EVT_SET_HEADER = 11, |
|||
HZIT_CMD_SET_POLYGON = 12, |
|||
HZIT_EVT_SET_POLYGON = 13, |
|||
HZIT_CMD_SET_POLYGON_POINT = 14, |
|||
HZIT_EVT_SET_POLYGON_POINT = 15, |
|||
HZIT_CMD_SET_RAY = 16, |
|||
HZIT_EVT_SET_RAY = 17, |
|||
HZIT_CMD_SET_RAY_LINE = 18, |
|||
HZIT_EVT_SET_RAY_LINE = 19, |
|||
HZIT_CMD_SET_DONE = 20, |
|||
HZIT_EVT_SET_DONE = 21, |
|||
HZIT_EVT_ERROR = 255, |
|||
}HZ_INFO_TYPE; |
|||
|
|||
typedef struct HZ_POINT{ |
|||
U16 wX; // 0..4095 |
|||
U16 wY; // 0..4095 |
|||
}HZ_POINT, *LPHZ_POINT; |
|||
|
|||
typedef struct HZ_LINE{ |
|||
U8 bType; // region type |
|||
U16 wMin; // 0..2047 |
|||
U16 wMax; // 0..2047 |
|||
}HZ_LINE, *LPHZ_LINE; |
|||
|
|||
typedef struct HZ_PACKET{ |
|||
U8 bSubSize; |
|||
U8 bType; |
|||
U8 bSequence; |
|||
}HZ_PACKET, *PHZ_PACKET; |
|||
|
|||
// --------- CMD_HZ_GET_DATA ----------- |
|||
typedef HZ_PACKET HZ_CMD_GET_HEADER, *PHZ_CMD_GET_HEADER; |
|||
typedef struct HZ_EVT_GET_HEADER : public HZ_PACKET{ |
|||
U16 wPolygonCount; |
|||
U16 wRayCount; |
|||
U32 dwTypeOn; |
|||
}HZ_EVT_GET_HEADER, *PHZ_EVT_GET_HEADER; |
|||
|
|||
typedef struct HZ_CMD_GET_POLYGON : public HZ_PACKET{ |
|||
U16 wPolygonIndex; |
|||
}HZ_CMD_GET_POLYGON, *PHZ_CMD_GET_POLYGON; |
|||
|
|||
typedef struct HZ_EVT_GET_POLYGON : public HZ_PACKET{ |
|||
U8 bPolygonType; |
|||
U16 wPointCount; |
|||
}HZ_EVT_GET_POLYGON, *PHZ_EVT_GET_POLYGON; |
|||
|
|||
typedef struct HZ_CMD_GET_POLYGON_POINT : public HZ_PACKET{ |
|||
U16 wPolygonIndex; |
|||
U16 wPointIndex; |
|||
}HZ_CMD_GET_POLYGON_POINT, *PHZ_CMD_GET_POLYGON_POINT; |
|||
|
|||
typedef struct HZ_EVT_GET_POLYGON_POINT : public HZ_PACKET{ |
|||
HZ_POINT Point; |
|||
}HZ_EVT_GET_POLYGON_POINT, *PHZ_EVT_GET_POLYGON_POINT; |
|||
|
|||
typedef struct HZ_CMD_GET_RAY : public HZ_PACKET{ |
|||
U16 wRayIndex; |
|||
}HZ_CMD_GET_RAY, *PHZ_CMD_GET_RAY; |
|||
|
|||
typedef struct HZ_EVT_GET_RAY : public HZ_PACKET{ |
|||
U16 wLineCount; |
|||
}HZ_EVT_GET_RAY, *PHZ_EVT_GET_RAY; |
|||
|
|||
typedef struct HZ_CMD_GET_RAY_LINE : public HZ_PACKET{ |
|||
U16 wRayIndex; |
|||
U16 wLineIndex; |
|||
}HZ_CMD_GET_RAY_LINE, *PHZ_CMD_GET_RAY_LINE; |
|||
|
|||
typedef struct HZ_EVT_GET_RAY_LINE : public HZ_PACKET{ |
|||
HZ_LINE Line; |
|||
}HZ_EVT_GET_RAY_LINE, *PHZ_EVT_GET_RAY_LINE; |
|||
|
|||
// ----------- CMD_HZ_SET_DATA -------------- |
|||
typedef struct HZ_CMD_SET_HEADER : public HZ_PACKET{ |
|||
U16 wPolygonCount; |
|||
U16 wRayCount; |
|||
U32 dwTypeOn; |
|||
}HZ_CMD_SET_HEADER, *PHZ_CMD_SET_HEADER; |
|||
|
|||
typedef HZ_PACKET HZ_EVT_SET_HEADER, *PHZ_EVT_SET_HEADER; |
|||
|
|||
typedef struct HZ_CMD_SET_POLYGON : public HZ_PACKET{ |
|||
U16 wPolygonIndex; |
|||
U8 bPolygonType; |
|||
U16 wPointCount; |
|||
}HZ_CMD_SET_POLYGON, *PHZ_CMD_SET_POLYGON; |
|||
|
|||
typedef HZ_PACKET HZ_EVT_SET_POLYGON, *PHZ_EVT_SET_POLYGON; |
|||
|
|||
typedef struct HZ_CMD_SET_POLYGON_POINT : public HZ_PACKET{ |
|||
U16 wPolygonIndex; |
|||
U16 wPointIndex; |
|||
HZ_POINT Point; |
|||
}HZ_CMD_SET_POLYGON_POINT, *PHZ_CMD_SET_POLYGON_POINT; |
|||
|
|||
typedef HZ_PACKET HZ_EVT_SET_POLYGON_POINT, *PHZ_EVT_SET_POLYGON_POINT; |
|||
|
|||
typedef struct HZ_CMD_SET_RAY : public HZ_PACKET{ |
|||
U16 wRayIndex; |
|||
U16 wLineCount; |
|||
}HZ_CMD_SET_RAY, *PHZ_CMD_SET_RAY; |
|||
|
|||
typedef HZ_PACKET HZ_EVT_SET_RAY, *PHZ_EVT_SET_RAY; |
|||
|
|||
typedef struct HZ_CMD_SET_RAY_LINE : public HZ_PACKET{ |
|||
U16 wRayIndex; |
|||
U16 wLineIndex; |
|||
HZ_LINE Line; |
|||
}HZ_CMD_SET_RAY_LINE, *PHZ_CMD_SET_RAY_LINE; |
|||
|
|||
typedef HZ_PACKET HZ_EVT_SET_RAY_LINE, *PHZ_EVT_SET_RAY_LINE; |
|||
|
|||
typedef HZ_PACKET HZ_CMD_SET_DONE, *PHZ_CMD_SET_DONE; |
|||
|
|||
typedef HZ_PACKET HZ_EVT_SET_DONE, *PHZ_EVT_SET_DONE; |
|||
|
|||
// ----------- CMD_HZ_GET_DATA / CMD_HZ_SET_DATA -------------- |
|||
enum{ |
|||
HZER_NONE = 0, |
|||
HZER_OUT_OF_MEMORY = 1, |
|||
HZER_RAY_COUNT = 2, |
|||
HZER_RAY_INDEX = 3, |
|||
HZER_RAY_LINE_INDEX = 4, |
|||
HZER_POLYGON_INDEX = 5, |
|||
HZER_POLYGON_POINT_INDEX = 6, |
|||
}; |
|||
|
|||
typedef struct HZ_EVT_ERROR : public HZ_PACKET{ |
|||
U8 bCmdType; |
|||
U8 bErrorId; |
|||
}HZ_EVT_ERROR, *PHZ_EVT_ERROR; |
|||
|
|||
|
|||
// ----------- CMD_GET_CT_TABLE / CMD_SET_CT_TABLE -------------- |
|||
enum{ |
|||
CIT_NONE = 0, |
|||
|
|||
CIT_CMD_SET_HEADER = 1, |
|||
CIT_EVT_SET_HEADER = 2, |
|||
CIT_EVT_SET_ITEM = 3, |
|||
CIT_CMD_SET_ITEM = 4, |
|||
CIT_CMD_SET_DONE = 5, |
|||
CIT_EVT_SET_DONE = 6, |
|||
|
|||
CIT_CMD_GET_HEADER = 7, |
|||
CIT_EVT_GET_HEADER = 8, |
|||
CIT_CMD_GET_ITEM = 9, |
|||
CIT_EVT_GET_ITEM = 10, |
|||
|
|||
CIT_EVT_ERROR = 255, |
|||
}; |
|||
|
|||
enum{ |
|||
CER_NONE = 0, |
|||
CER_OUT_OF_MEMORY = 1, |
|||
CER_INDEX = 2, |
|||
}; |
|||
|
|||
typedef struct CT_PACKET{ |
|||
U8 bSize; |
|||
U8 bType; |
|||
U8 bSequence; |
|||
}CT_PACKET, *PCT_PACKET; |
|||
|
|||
// error |
|||
typedef struct CT_ERROR_EVT : public CT_PACKET{ |
|||
U8 bCmdType; |
|||
U8 bErrorId; |
|||
}CT_ERROR_EVT, *PCT_ERROR_EVT; |
|||
|
|||
|
|||
// set header |
|||
typedef struct CT_SET_HEADER_CMD : public CT_PACKET{ |
|||
U8 bCount; |
|||
}CT_SET_HEADER_CMD, *PCT_SET_HEADER_CMD; |
|||
|
|||
typedef struct CT_SET_HEADER_EVT : public CT_PACKET{ |
|||
}CT_SET_HEADER_EVT, *PCT_SET_HEADER_EVT; |
|||
|
|||
// set item |
|||
typedef struct CT_SET_ITEM_CMD : public CT_PACKET{ |
|||
U8 bIndex; |
|||
U16 wReal; |
|||
U16 wA2D; |
|||
}CT_SET_ITEM_CMD, *PCT_SET_ITEM_CMD; |
|||
|
|||
typedef struct CT_SET_ITEM_EVT : public CT_PACKET{ |
|||
}CT_SET_ITEM_EVT, *PCT_SET_ITEM_EVT; |
|||
|
|||
// set done |
|||
typedef struct CT_SET_DONE_CMD : public CT_PACKET{ |
|||
}CT_SET_DONE_CMD, *PCT_SET_DONE_CMD; |
|||
|
|||
typedef struct CT_SET_DONE_EVT : public CT_PACKET{ |
|||
}CT_SET_DONE_EVT, *PCT_SET_DONE_EVT; |
|||
|
|||
// get header |
|||
typedef struct CT_GET_HEADER_CMD : public CT_PACKET{ |
|||
}CT_GET_HEADER_CMD, *PCT_GET_HEADER_CMD; |
|||
|
|||
typedef struct CT_GET_HEADER_EVT : public CT_PACKET{ |
|||
U8 bCount; |
|||
}CT_GET_HEADER_EVT, *PCT_GET_HEADER_EVT; |
|||
|
|||
// get item |
|||
typedef struct CT_GET_ITEM_CMD : public CT_PACKET{ |
|||
U8 bIndex; |
|||
}CT_GET_ITEM_CMD, *PCT_GET_ITEM_CMD; |
|||
|
|||
typedef struct CT_GET_ITEM_EVT : public CT_PACKET{ |
|||
U16 wReal; |
|||
U16 wA2D; |
|||
}CT_GET_ITEM_EVT, *PCT_GET_ITEM_EVT; |
|||
|
|||
|
|||
// ----------- CMD_GET_LRF_ENABLE / CMD_SET_LRF_ENABLE -------------- |
|||
typedef struct LRF_DISABLE{ |
|||
uint8_t bMaster; |
|||
uint8_t bSlave; |
|||
}LRF_DISABLE, *PLRF_DISABLE; |
|||
|
|||
// ----------- CMD_GET_ZOOM_TABLE / CMD_SET_ZOOM_TABLE -------------- |
|||
enum { ZOOM_TILT_TABLE_SIZE = 10 }; |
|||
|
|||
typedef struct ZOOM_TABLE{ |
|||
uint8_t nCount; |
|||
uint8_t pTable[ZOOM_TILT_TABLE_SIZE]; |
|||
}ZOOM_TABLE, *PZOOM_TABLE; |
|||
|
|||
// ----------- CMD_GET_TILT_TABLE / CMD_SET_TILT_TABLE -------------- |
|||
typedef struct TILT_TABLE{ |
|||
uint8_t nCount; |
|||
uint8_t pTable[ZOOM_TILT_TABLE_SIZE]; |
|||
}TILT_TABLE, *PTILT_TABLE; |
|||
|
|||
#define MASTER_TAG 0x80 |
|||
#define SENSOR_TAG 0x00 |
|||
|
|||
#define SIZE_IDX_A 1 |
|||
#define SIZE_IDX_B 2 |
|||
#define DEV_ID_IDX 3 |
|||
#define CMD_IDX 4 |
|||
#define SUB_CMD_IDX 5 |
|||
#define DATA_BEGIN_IDX 6 |
|||
|
|||
|
|||
#ifdef _CLIENT_APPLICATION_ |
|||
#define SEND_TAG MASTER_TAG |
|||
#define ACCEPT_TAG SENSOR_TAG |
|||
#else |
|||
#define SEND_TAG SENSOR_TAG |
|||
#define ACCEPT_TAG MASTER_TAG |
|||
#endif |
|||
|
|||
class protocolLGSm: public protocolParser{ |
|||
private: |
|||
basicLogCollection *m_pLog; |
|||
basicMutex m_mInquiryMutex; |
|||
protected: |
|||
uint8_t m_bDeviceID; |
|||
basicTransport *m_oDataTransport; |
|||
int packetChecker( uint8_t *Buffer, size_t BufferSize); |
|||
protocolPackage *packetExtractor( uint8_t *Buffer, size_t BufferSize); |
|||
public: |
|||
explicit protocolLGSm( basicTransport *Transport = NULL, uint8_t DeviceID = 0 ); |
|||
virtual ~protocolLGSm(); |
|||
virtual bool create(void){ return protocolParser::create(); }; |
|||
uint8_t getDeviceID(void) { return m_bDeviceID; }; |
|||
basicTransport * getTransport(void) { return m_oDataTransport; }; |
|||
bool setDeviceID( uint8_t DeviceID ){ m_bDeviceID = DeviceID; return true; }; |
|||
bool setTransport(basicTransport* m_oDataTransport); |
|||
}; |
|||
|
|||
#endif |
|||
@ -0,0 +1,165 @@ |
|||
#include "serialSOL.h"
|
|||
|
|||
#define LOG( X ) m_pLog->Log( "serialPort", this, X )
|
|||
#define LOG_ERROR( X ) m_pLog->Log( "serialPort", this, _LOG_ERROR, X )
|
|||
|
|||
serialSOL::serialSOL( SOL_TYPE t ): transportSocket(){ |
|||
m_pLog = m_pLog = basicLogCollection::getInstance(); |
|||
m_eSolType = t; |
|||
m_bInitComplete = false; |
|||
m_nSocketFD = -1; |
|||
m_sServerAddr; |
|||
m_sClientAddr; |
|||
memset( &m_sServerAddr, 0, sizeof( m_sServerAddr ) ); |
|||
memset( &m_sClientAddr, 0, sizeof( m_sClientAddr ) ); |
|||
}; |
|||
|
|||
serialSOL::~serialSOL(){ |
|||
|
|||
}; |
|||
|
|||
bool serialSOL::create( CSTR address, uint16_t port, int Speed ){ |
|||
switch( m_eSolType ) { |
|||
case SOL_TCP_CLIENT:{ |
|||
break; |
|||
}; |
|||
case SOL_UDP_CLIENT:{ |
|||
// Creating socket file descriptor
|
|||
if ( (m_nSocketFD = socket(AF_INET, SOCK_DGRAM, 0)) < 0 ) { |
|||
LOG_ERROR("Socket Creation Failed!"); |
|||
return false; |
|||
}; |
|||
fcntl( m_nSocketFD, F_SETFL, O_NONBLOCK ); |
|||
// Filling server information
|
|||
m_sServerAddr.sin_family = AF_INET; |
|||
m_sServerAddr.sin_addr.s_addr = INADDR_ANY; |
|||
m_sServerAddr.sin_port = htons( port ); |
|||
|
|||
break; |
|||
}; |
|||
case SOL_TCP_SERVER:{ |
|||
break; |
|||
}; |
|||
case SOL_UDP_SERVER:{ |
|||
// Creating socket file descriptor
|
|||
if ( (m_nSocketFD = socket( AF_INET, SOCK_DGRAM, 0 )) < 0 ) { |
|||
LOG_ERROR("Socket Creation Failed!"); |
|||
return false; |
|||
}; |
|||
fcntl( m_nSocketFD, F_SETFL, O_NONBLOCK); |
|||
// Filling server information
|
|||
m_sServerAddr.sin_family = AF_INET; // IPv4
|
|||
m_sServerAddr.sin_addr.s_addr = INADDR_ANY; |
|||
m_sServerAddr.sin_port = htons( port ); |
|||
|
|||
// Bind the socket with the server address
|
|||
if ( bind( m_nSocketFD, (const struct sockaddr *)&m_sServerAddr, sizeof(m_sServerAddr)) < 0 ){ |
|||
LOG_ERROR("Bind Failed"); |
|||
return false; |
|||
}; |
|||
break; |
|||
}; |
|||
}; |
|||
return true; |
|||
}; |
|||
|
|||
int serialSOL::sendBlock( unsigned char *Data, int DataSize ){ |
|||
if( !m_bInitComplete || !m_bConnected ) return -1; // Exit after unsuccess reconnect
|
|||
|
|||
int RetVal; |
|||
|
|||
if( m_nSocketFD > -1 ){ |
|||
#ifdef DUBUG_COMMUNICATION
|
|||
char cBuffer[256]; |
|||
sprintf(cBuffer,"Write into Socket %d bytes", DataSize ); |
|||
LOG(cBuffer); |
|||
#endif
|
|||
socklen_t addr_len = sizeof( m_sClientAddr ); |
|||
RetVal = sendto( m_nSocketFD, (const char *)Data, DataSize, MSG_CONFIRM, (const struct sockaddr *) &m_sClientAddr, addr_len ); |
|||
|
|||
if( ( RetVal == -1 ) && (errno != EINTR ) && ( errno != EWOULDBLOCK ) ) { |
|||
LOG_ERROR("Error acures while writing data into the Socket"); |
|||
shutdown( m_nSocketFD, 2 ); |
|||
close( m_nSocketFD ); |
|||
m_nSocketFD = -1; |
|||
m_bConnected = false; |
|||
setConnectionStatus( CS_DISCONNECTED ); |
|||
return -1; |
|||
}; |
|||
|
|||
if( RetVal < 0 ) RetVal = 0; |
|||
|
|||
#ifdef DUBUG_COMMUNICATION
|
|||
sprintf(cBuffer,"Bytes Sent: %ld", RetVal); |
|||
LOG(cBuffer); |
|||
#endif
|
|||
|
|||
} else { |
|||
LOG_ERROR("Not Connected!"); |
|||
m_bConnected = false; |
|||
setConnectionStatus( CS_DISCONNECTED ); |
|||
return -1; |
|||
}; |
|||
|
|||
return RetVal; |
|||
}; |
|||
|
|||
int serialSOL::recptBlock( unsigned char *Buffer, int *BufferLength ){ |
|||
if( !m_bInitComplete || !m_bConnected ){ |
|||
LOG_ERROR("Not Connected!"); |
|||
m_bInitComplete = false; |
|||
m_bConnected = false; |
|||
setConnectionStatus( CS_DISCONNECTED ); |
|||
return -1; // Exit after unsuccess reconnect
|
|||
}; |
|||
int RetVal; |
|||
if( m_nSocketFD > -1 ) { |
|||
socklen_t addr_len = sizeof( m_sClientAddr ); //len is value/resuslt
|
|||
RetVal = recvfrom( m_nSocketFD, (char *)Buffer, MAXIMAL_SOCKET_PACKET_LENGTH, MSG_WAITALL, ( struct sockaddr *) &m_sClientAddr, &addr_len ); |
|||
if( RetVal < 1 ){ |
|||
if( errno!=EAGAIN && errno!=EINTR ) { |
|||
LOG_ERROR("Peer Closes Connection!"); |
|||
shutdown( m_nSocketFD, 2 ); |
|||
close( m_nSocketFD ); |
|||
*BufferLength = 0; |
|||
m_bConnected = false; |
|||
m_nSocketFD = -1; |
|||
setConnectionStatus( CS_DISCONNECTED ); |
|||
return -1; |
|||
}; |
|||
}; |
|||
} else { |
|||
LOG_ERROR("Not Connected!"); |
|||
*BufferLength = 0; |
|||
m_bConnected = false; |
|||
setConnectionStatus( CS_DISCONNECTED ); |
|||
return -1; |
|||
}; |
|||
if (RetVal > 0) { |
|||
#ifdef DUBUG_COMMUNICATION
|
|||
char cBuffer[165]; |
|||
sprintf(cBuffer, "Bytes received: %d", RetVal); |
|||
LOG(cBuffer); |
|||
#endif
|
|||
*BufferLength = RetVal; |
|||
return RetVal; |
|||
}; |
|||
|
|||
*BufferLength = 0; |
|||
|
|||
if (RetVal == -1) return 0; |
|||
|
|||
if (RetVal == 0){ |
|||
errno = 0; |
|||
return 0; |
|||
}; |
|||
|
|||
/* r < -1, should never happen. */ |
|||
errno = EIO; |
|||
|
|||
return 0; |
|||
}; |
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
|
|||
@ -0,0 +1,42 @@ |
|||
#ifndef __OBJECT_NET_NODE_2D_HEADERS__ |
|||
#define __OBJECT_NET_NODE_2D_HEADERS__ |
|||
|
|||
#include "rgooseNode.h" |
|||
|
|||
#include "../components/base/basicObject.h" |
|||
#include "../components/base/basicMutex.h" |
|||
#include "../components/base/basicDualThread.h" |
|||
#include "../components/base/basicLogCollection.h" |
|||
#include "../components/base/basicEventHeap.h" |
|||
#include "../components/base/basicPosition.h" |
|||
#include "../components/object/objectSystemAnchor.h" |
|||
#include "../components/base/basicSettingsProvider.h" |
|||
#include "../alg/lgs/mask.h" |
|||
|
|||
|
|||
class ARGUS_2DSensor: public argusNetNode{ |
|||
|
|||
public: |
|||
ARGUS_2DSensor(); |
|||
~ARGUS_2DSensor(); |
|||
virtual bool isAttached() { |
|||
} |
|||
virtual bool isDetached() { |
|||
} |
|||
virtual bool startService() { |
|||
} |
|||
virtual bool stopService() { |
|||
} |
|||
virtual bool validate() { |
|||
} |
|||
virtual objectCaps getCaps(void) { |
|||
} |
|||
virtual int getID(void) { |
|||
} |
|||
virtual objectStatus getStatus(void) { |
|||
} |
|||
virtual CSTR getUID(void) { |
|||
} |
|||
}; |
|||
|
|||
#endif |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue