Browse Source

Mid-changes MASTER-SLAVE connection

AGP
Evgeny Gagua 6 years ago
parent
commit
2016338a85
  1. 21
      Projects/argus/argus.vpj
  2. 92
      Projects/argus/makefile
  3. 4
      lib/App/3dSERVER/LRF_TargetTracker.cpp
  4. 8
      lib/App/3dSERVER/LRF_TargetTracker.h
  5. 218
      lib/App/3dSERVER/LRF_TwinConnector.cpp
  6. 54
      lib/App/3dSERVER/LRF_TwinConnector.h
  7. 2
      lib/data/net/clientPort.h
  8. 61
      lib/data/net/netServer.cpp
  9. 2
      lib/data/net/serverPort.h
  10. 142
      lib/data/net/transportSocket.cpp
  11. 113
      lib/data/net/transportSocket.cpp.bak
  12. 64
      lib/data/net/transportSocket.h
  13. 62
      lib/data/net/transportSocket.h.bak
  14. 2
      lib/data/protocol/protocol.cpp
  15. 5
      lib/data/protocol/protocol.h
  16. 369
      lib/data/protocol/protocolInternalLRF3D.cpp
  17. 72
      lib/data/protocol/protocolInternalLRF3D.h
  18. 956
      lib/data/protocol/protocolLGS.cpp
  19. 809
      lib/data/protocol/protocolLGS.h
  20. 2
      lib/data/protocol/protocolLGS2D.cpp
  21. 25
      lib/data/protocol/protocolLGS2D.h
  22. 134
      lib/data/protocol/protocolLGSm.cpp
  23. 808
      lib/data/protocol/protocolLGSm.h
  24. 12
      lib/data/transport/transportSerial.h
  25. 130
      lib/data/transport/transportSocket.cpp
  26. 53
      lib/data/transport/transportSocket.h
  27. 4
      lib/hardware/uart/serialPort.h
  28. 165
      lib/hardware/uart/serialSOL.cpp
  29. 50
      lib/hardware/uart/serialSOL.h
  30. 0
      lib/rgoose/rgooseNode2D.cpp
  31. 42
      lib/rgoose/rgooseNode2D.h
  32. 4
      lib/rgoose/rgooseNode3D.h

21
Projects/argus/argus.vpj

@ -293,8 +293,11 @@
<F N="../../lib/data/ponvif/ponvif.cpp"/>
<F N="../../lib/data/protocol/protocol.cpp"/>
<F N="../../lib/data/protocol/protocolDefender.cpp"/>
<F N="../../lib/data/protocol/protocolEuropeanGeneral.cpp"/>
<F N="../../lib/data/protocol/protocolHTTP.cpp"/>
<F N="../../lib/data/protocol/protocolLGS.cpp"/>
<F N="../../lib/data/protocol/protocolLGS2D.cpp"/>
<F N="../../lib/data/protocol/protocolLGSm.cpp"/>
<F N="../../lib/data/protocol/protocolSafeShore.cpp"/>
<F N="../../lib/data/protocol/protocolZLMEDIA.cpp"/>
<F N="../../lib/App/argus/RGoose_Kernel.cpp"/>
@ -303,17 +306,22 @@
<F N="../../lib/rgoose/rgooseIPCamera.cpp"/>
<F N="../../lib/rgoose/rgooseModuleFactory.cpp"/>
<F N="../../lib/rgoose/rgooseNode.cpp"/>
<F N="../../lib/rgoose/rgooseNode2D.cpp"/>
<F N="../../lib/rgoose/rgooseNode3D.cpp"/>
<F N="../../lib/rgoose/rgooseNodeFactory.cpp"/>
<F N="../../lib/rgoose/rgooseServerModule.cpp"/>
<F N="../../lib/rgoose/rgooseUSBRelayModule.cpp"/>
<F N="../../lib/rgoose/rgooseZLMediaModule.cpp"/>
<F N="../../lib/hardware/uart/serialPort.cpp"/>
<F N="../../lib/hardware/uart/serialSOL.cpp"/>
<F N="../../lib/data/net/serverPort.cpp"/>
<F N="../../lib/data/servletWS/servletChannelWS.cpp"/>
<F N="../../lib/data/servletWS/servletClientHandlerWS.cpp"/>
<F N="../../lib/data/servletWS/servletWS.cpp"/>
<F N="../../lib/data/ssdp/ssdpAnnouncer.cpp"/>
<F N="../../lib/alg/generic/Transform.cpp"/>
<F N="../../lib/data/net/transportSocket.cpp"/>
<F N="../../lib/data/transport/transportSerial.cpp"/>
<F N="../../lib/data/transport/transportSocket.cpp"/>
<F N="../../lib/alg/generic/utm.cpp"/>
<F N="../../lib/data/protocol/xmlParser.cpp"/>
</Folder>
@ -327,14 +335,19 @@
<F N="../../lib/components/base/basicObject.h"/>
<F N="../../lib/components/base/basicSettingsProvider.h"/>
<F N="../../lib/components/base/basicThread.h"/>
<F N="../../lib/components/base/basicTransport.h"/>
<F N="../../lib/components/base/basicTypes.h"/>
<F N="../../lib/data/net/clientPort.h"/>
<F N="../../lib/data/mysql/database_class.h"/>
<F N="../../lib/alg/generic/heapDebug.h"/>
<F N="../../lib/alg/generic/libzip.h"/>
<F N="../../lib/data/NginxMediaServer/mediaNginxStreamingProxyManager.h"/>
<F N="../../lib/data/ponvif/ponvif.h"/>
<F N="../../lib/data/protocol/protocolEuropeanGeneral.h"/>
<F N="../../lib/data/protocol/protocolHTTP.h"/>
<F N="../../lib/data/protocol/protocolLGS.h"/>
<F N="../../lib/data/protocol/protocolLGS2D.h"/>
<F N="../../lib/data/protocol/protocolLGSm.h"/>
<F N="../../lib/data/protocol/protocolZLMEDIA.h"/>
<F N="../../lib/App/argus/RGoose_Kernel.h"/>
<F N="../../lib/rgoose/rgooseCamera.h"/>
@ -343,12 +356,18 @@
<F N="../../lib/rgoose/rgooseModule.h"/>
<F N="../../lib/rgoose/rgooseModuleFactory.h"/>
<F N="../../lib/rgoose/rgooseNode.h"/>
<F N="../../lib/rgoose/rgooseNode2D.h"/>
<F N="../../lib/rgoose/rgooseNode3D.h"/>
<F N="../../lib/rgoose/rgooseNodeFactory.h"/>
<F N="../../lib/rgoose/rgooseServerModule.h"/>
<F N="../../lib/rgoose/rgooseUSBRelayModule.h"/>
<F N="../../lib/rgoose/rgooseZLMediaModule.h"/>
<F N="../../lib/hardware/uart/serialPort.h"/>
<F N="../../lib/hardware/uart/serialSOL.h"/>
<F N="../../lib/data/net/serverPort.h"/>
<F N="../../lib/data/servletWS/servletClientHandlerWS.h"/>
<F N="../../lib/data/transport/transportSerial.h"/>
<F N="../../lib/data/transport/transportSocket.h"/>
</Folder>
<Folder
Name="Resource Files"

92
Projects/argus/makefile

@ -45,16 +45,20 @@ COMMON_OBJ=$(OUTDIR)/ArgusBackend.o $(OUTDIR)/base64.o \
$(OUTDIR)/objectFileLoggingService.o $(OUTDIR)/objectSystemAnchor.o \
$(OUTDIR)/onvifMediaObserver.o $(OUTDIR)/ponvif.o \
$(OUTDIR)/protocol.o $(OUTDIR)/protocolDefender.o \
$(OUTDIR)/protocolHTTP.o $(OUTDIR)/protocolLGS.o \
$(OUTDIR)/protocolSafeShore.o $(OUTDIR)/protocolZLMEDIA.o \
$(OUTDIR)/RGoose_Kernel.o $(OUTDIR)/rgooseCamera.o \
$(OUTDIR)/rgooseDBConnector.o $(OUTDIR)/rgooseIPCamera.o \
$(OUTDIR)/rgooseModuleFactory.o $(OUTDIR)/rgooseNode.o \
$(OUTDIR)/protocolEuropeanGeneral.o $(OUTDIR)/protocolHTTP.o \
$(OUTDIR)/protocolLGS.o $(OUTDIR)/protocolLGS2D.o \
$(OUTDIR)/protocolLGSm.o $(OUTDIR)/protocolSafeShore.o \
$(OUTDIR)/protocolZLMEDIA.o $(OUTDIR)/RGoose_Kernel.o \
$(OUTDIR)/rgooseCamera.o $(OUTDIR)/rgooseDBConnector.o \
$(OUTDIR)/rgooseIPCamera.o $(OUTDIR)/rgooseModuleFactory.o \
$(OUTDIR)/rgooseNode.o $(OUTDIR)/rgooseNode2D.o \
$(OUTDIR)/rgooseNode3D.o $(OUTDIR)/rgooseNodeFactory.o \
$(OUTDIR)/rgooseServerModule.o $(OUTDIR)/rgooseUSBRelayModule.o \
$(OUTDIR)/rgooseZLMediaModule.o $(OUTDIR)/servletChannelWS.o \
$(OUTDIR)/servletClientHandlerWS.o $(OUTDIR)/servletWS.o \
$(OUTDIR)/ssdpAnnouncer.o $(OUTDIR)/Transform.o \
$(OUTDIR)/rgooseZLMediaModule.o $(OUTDIR)/serialPort.o \
$(OUTDIR)/serialSOL.o $(OUTDIR)/serverPort.o \
$(OUTDIR)/servletChannelWS.o $(OUTDIR)/servletClientHandlerWS.o \
$(OUTDIR)/servletWS.o $(OUTDIR)/ssdpAnnouncer.o \
$(OUTDIR)/Transform.o $(OUTDIR)/transportSerial.o \
$(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o $(OUTDIR)/xmlParser.o
OBJ=$(COMMON_OBJ) $(CFG_OBJ)
ALL_OBJ=$(OUTDIR)/ArgusBackend.o $(OUTDIR)/base64.o \
@ -76,16 +80,20 @@ ALL_OBJ=$(OUTDIR)/ArgusBackend.o $(OUTDIR)/base64.o \
$(OUTDIR)/objectFileLoggingService.o $(OUTDIR)/objectSystemAnchor.o \
$(OUTDIR)/onvifMediaObserver.o $(OUTDIR)/ponvif.o \
$(OUTDIR)/protocol.o $(OUTDIR)/protocolDefender.o \
$(OUTDIR)/protocolHTTP.o $(OUTDIR)/protocolLGS.o \
$(OUTDIR)/protocolSafeShore.o $(OUTDIR)/protocolZLMEDIA.o \
$(OUTDIR)/RGoose_Kernel.o $(OUTDIR)/rgooseCamera.o \
$(OUTDIR)/rgooseDBConnector.o $(OUTDIR)/rgooseIPCamera.o \
$(OUTDIR)/rgooseModuleFactory.o $(OUTDIR)/rgooseNode.o \
$(OUTDIR)/protocolEuropeanGeneral.o $(OUTDIR)/protocolHTTP.o \
$(OUTDIR)/protocolLGS.o $(OUTDIR)/protocolLGS2D.o \
$(OUTDIR)/protocolLGSm.o $(OUTDIR)/protocolSafeShore.o \
$(OUTDIR)/protocolZLMEDIA.o $(OUTDIR)/RGoose_Kernel.o \
$(OUTDIR)/rgooseCamera.o $(OUTDIR)/rgooseDBConnector.o \
$(OUTDIR)/rgooseIPCamera.o $(OUTDIR)/rgooseModuleFactory.o \
$(OUTDIR)/rgooseNode.o $(OUTDIR)/rgooseNode2D.o \
$(OUTDIR)/rgooseNode3D.o $(OUTDIR)/rgooseNodeFactory.o \
$(OUTDIR)/rgooseServerModule.o $(OUTDIR)/rgooseUSBRelayModule.o \
$(OUTDIR)/rgooseZLMediaModule.o $(OUTDIR)/servletChannelWS.o \
$(OUTDIR)/servletClientHandlerWS.o $(OUTDIR)/servletWS.o \
$(OUTDIR)/ssdpAnnouncer.o $(OUTDIR)/Transform.o \
$(OUTDIR)/rgooseZLMediaModule.o $(OUTDIR)/serialPort.o \
$(OUTDIR)/serialSOL.o $(OUTDIR)/serverPort.o \
$(OUTDIR)/servletChannelWS.o $(OUTDIR)/servletClientHandlerWS.o \
$(OUTDIR)/servletWS.o $(OUTDIR)/ssdpAnnouncer.o \
$(OUTDIR)/Transform.o $(OUTDIR)/transportSerial.o \
$(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o $(OUTDIR)/xmlParser.o \
-lpthread -lmysqlclient -lssl -lcurl -lm -lcrypto -lconfig -lz \
-lv4l1 -lv4l2 -lhidapi-libusb `pkg-config libavcodec libavdevice \
@ -96,6 +104,9 @@ COMPILE=g++ -c -x c++ "-DDEBUG" "-D__STDC_CONSTANT_MACROS" -g -std=c++11 -Wno-w
LINK=g++ -g -o "$(OUTFILE)" $(ALL_OBJ)
# Pattern rules
$(OUTDIR)/%.o : ../../lib/data/transport/%.cpp
$(COMPILE)
$(OUTDIR)/%.o : ../../lib/alg/lgs/%.cpp
$(COMPILE)
@ -120,6 +131,9 @@ $(OUTDIR)/%.o : ../../lib/alg/generic/%.cpp
$(OUTDIR)/%.o : ../../lib/components/base/%.cpp
$(COMPILE)
$(OUTDIR)/%.o : ../../lib/hardware/uart/%.cpp
$(COMPILE)
$(OUTDIR)/%.o : ../../lib/components/object/%.cpp
$(COMPILE)
@ -193,16 +207,20 @@ COMMON_OBJ=$(OUTDIR)/ArgusBackend.o $(OUTDIR)/base64.o \
$(OUTDIR)/objectFileLoggingService.o $(OUTDIR)/objectSystemAnchor.o \
$(OUTDIR)/onvifMediaObserver.o $(OUTDIR)/ponvif.o \
$(OUTDIR)/protocol.o $(OUTDIR)/protocolDefender.o \
$(OUTDIR)/protocolHTTP.o $(OUTDIR)/protocolLGS.o \
$(OUTDIR)/protocolSafeShore.o $(OUTDIR)/protocolZLMEDIA.o \
$(OUTDIR)/RGoose_Kernel.o $(OUTDIR)/rgooseCamera.o \
$(OUTDIR)/rgooseDBConnector.o $(OUTDIR)/rgooseIPCamera.o \
$(OUTDIR)/rgooseModuleFactory.o $(OUTDIR)/rgooseNode.o \
$(OUTDIR)/protocolEuropeanGeneral.o $(OUTDIR)/protocolHTTP.o \
$(OUTDIR)/protocolLGS.o $(OUTDIR)/protocolLGS2D.o \
$(OUTDIR)/protocolLGSm.o $(OUTDIR)/protocolSafeShore.o \
$(OUTDIR)/protocolZLMEDIA.o $(OUTDIR)/RGoose_Kernel.o \
$(OUTDIR)/rgooseCamera.o $(OUTDIR)/rgooseDBConnector.o \
$(OUTDIR)/rgooseIPCamera.o $(OUTDIR)/rgooseModuleFactory.o \
$(OUTDIR)/rgooseNode.o $(OUTDIR)/rgooseNode2D.o \
$(OUTDIR)/rgooseNode3D.o $(OUTDIR)/rgooseNodeFactory.o \
$(OUTDIR)/rgooseServerModule.o $(OUTDIR)/rgooseUSBRelayModule.o \
$(OUTDIR)/rgooseZLMediaModule.o $(OUTDIR)/servletChannelWS.o \
$(OUTDIR)/servletClientHandlerWS.o $(OUTDIR)/servletWS.o \
$(OUTDIR)/ssdpAnnouncer.o $(OUTDIR)/Transform.o \
$(OUTDIR)/rgooseZLMediaModule.o $(OUTDIR)/serialPort.o \
$(OUTDIR)/serialSOL.o $(OUTDIR)/serverPort.o \
$(OUTDIR)/servletChannelWS.o $(OUTDIR)/servletClientHandlerWS.o \
$(OUTDIR)/servletWS.o $(OUTDIR)/ssdpAnnouncer.o \
$(OUTDIR)/Transform.o $(OUTDIR)/transportSerial.o \
$(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o $(OUTDIR)/xmlParser.o
OBJ=$(COMMON_OBJ) $(CFG_OBJ)
ALL_OBJ=$(OUTDIR)/ArgusBackend.o $(OUTDIR)/base64.o \
@ -224,16 +242,20 @@ ALL_OBJ=$(OUTDIR)/ArgusBackend.o $(OUTDIR)/base64.o \
$(OUTDIR)/objectFileLoggingService.o $(OUTDIR)/objectSystemAnchor.o \
$(OUTDIR)/onvifMediaObserver.o $(OUTDIR)/ponvif.o \
$(OUTDIR)/protocol.o $(OUTDIR)/protocolDefender.o \
$(OUTDIR)/protocolHTTP.o $(OUTDIR)/protocolLGS.o \
$(OUTDIR)/protocolSafeShore.o $(OUTDIR)/protocolZLMEDIA.o \
$(OUTDIR)/RGoose_Kernel.o $(OUTDIR)/rgooseCamera.o \
$(OUTDIR)/rgooseDBConnector.o $(OUTDIR)/rgooseIPCamera.o \
$(OUTDIR)/rgooseModuleFactory.o $(OUTDIR)/rgooseNode.o \
$(OUTDIR)/protocolEuropeanGeneral.o $(OUTDIR)/protocolHTTP.o \
$(OUTDIR)/protocolLGS.o $(OUTDIR)/protocolLGS2D.o \
$(OUTDIR)/protocolLGSm.o $(OUTDIR)/protocolSafeShore.o \
$(OUTDIR)/protocolZLMEDIA.o $(OUTDIR)/RGoose_Kernel.o \
$(OUTDIR)/rgooseCamera.o $(OUTDIR)/rgooseDBConnector.o \
$(OUTDIR)/rgooseIPCamera.o $(OUTDIR)/rgooseModuleFactory.o \
$(OUTDIR)/rgooseNode.o $(OUTDIR)/rgooseNode2D.o \
$(OUTDIR)/rgooseNode3D.o $(OUTDIR)/rgooseNodeFactory.o \
$(OUTDIR)/rgooseServerModule.o $(OUTDIR)/rgooseUSBRelayModule.o \
$(OUTDIR)/rgooseZLMediaModule.o $(OUTDIR)/servletChannelWS.o \
$(OUTDIR)/servletClientHandlerWS.o $(OUTDIR)/servletWS.o \
$(OUTDIR)/ssdpAnnouncer.o $(OUTDIR)/Transform.o \
$(OUTDIR)/rgooseZLMediaModule.o $(OUTDIR)/serialPort.o \
$(OUTDIR)/serialSOL.o $(OUTDIR)/serverPort.o \
$(OUTDIR)/servletChannelWS.o $(OUTDIR)/servletClientHandlerWS.o \
$(OUTDIR)/servletWS.o $(OUTDIR)/ssdpAnnouncer.o \
$(OUTDIR)/Transform.o $(OUTDIR)/transportSerial.o \
$(OUTDIR)/transportSocket.o $(OUTDIR)/utm.o $(OUTDIR)/xmlParser.o \
-lpthread -lmysqlclient -lssl -lcurl -lm -lcrypto -lconfig -lz \
-lv4l1 -lv4l2 -lhidapi-libusb `pkg-config libavcodec libavdevice \
@ -244,6 +266,9 @@ COMPILE=g++ -c -x c++ "-DDEBUG" "-D__STDC_CONSTANT_MACROS" -std=c++11 -Wno-writ
LINK=g++ -o "$(OUTFILE)" $(ALL_OBJ)
# Pattern rules
$(OUTDIR)/%.o : ../../lib/data/transport/%.cpp
$(COMPILE)
$(OUTDIR)/%.o : ../../lib/alg/lgs/%.cpp
$(COMPILE)
@ -268,6 +293,9 @@ $(OUTDIR)/%.o : ../../lib/alg/generic/%.cpp
$(OUTDIR)/%.o : ../../lib/components/base/%.cpp
$(COMPILE)
$(OUTDIR)/%.o : ../../lib/hardware/uart/%.cpp
$(COMPILE)
$(OUTDIR)/%.o : ../../lib/components/object/%.cpp
$(COMPILE)

lib/App/3dSERVER/LRF_targetTracker.cpp → lib/App/3dSERVER/LRF_TargetTracker.cpp

lib/App/3dSERVER/LRF_targetTracker.h → lib/App/3dSERVER/LRF_TargetTracker.h

218
lib/App/3dSERVER/LRF_TwinConnector.cpp

@ -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

54
lib/App/3dSERVER/LRF_TwinConnector.h

@ -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

2
lib/data/net/clientPort.h

@ -20,7 +20,7 @@
#include <windows.h>
#endif
#include "transportSocket.h"
#include "../transport/transportSocket.h"
/**
* TODO: Add class description

61
lib/data/net/netServer.cpp

@ -352,7 +352,7 @@ void networkServer::m_fThreadProc( void ){
m_bThreadStatus = TH_WORKING;
while (m_bThreadStatus < TH_ENDED ){
ClientSocket = accept ( MainSocket, &ClientAddress, &size );
if ( ClientSocket == -1 ) {
if ( ClientSocket < 0 ) {
switch( errno ){
case EAGAIN:{
// Checkup client disconnection
@ -397,55 +397,22 @@ void networkServer::m_fThreadProc( void ){
};
m_bThreadStatus = TH_ENDED;
} else {
if ( ClientSocket >= 0 ) {
if( m_bConnectionType == 1 ){
char tstr[CQUERY];
if( m_bConnectionType == 1 ){
char tstr[CQUERY];
#ifdef __linux__
inet_ntop( AF_INET, &(((struct sockaddr_in*) &(ClientAddress ))->sin_addr ), tstr, size );
inet_ntop( AF_INET, &(((struct sockaddr_in*) &(ClientAddress ))->sin_addr ), tstr, size );
#else
strcpy( tstr, inet_ntoa( ((struct sockaddr_in*)&ClientAddress)->sin_addr ) );
//InetNtop(AF_INET, &(((struct sockaddr_in*) &(ClientAddress ))->sin_addr ), tstr, size );
strcpy( tstr, inet_ntoa( ((struct sockaddr_in*)&ClientAddress)->sin_addr ) );
//InetNtop(AF_INET, &(((struct sockaddr_in*) &(ClientAddress ))->sin_addr ), tstr, size );
#endif
};
LOG( "Client Connection Accepted" );
LRF_ClientHandler *tHandle;
tHandle = new LRF_ClientHandler( ClientSocket );
if( tHandle != NULL ) {
tHandle->attachEngine( m_pDetectorKernel );
m_vHandlersPool.push_back( (networkClientHandler *) tHandle );
};
} 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:
#ifdef __linux__
case ESOCKTNOSUPPORT:
#endif
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;
};
};
LOG( "Client Connection Accepted" );
LRF_ClientHandler *tHandle;
tHandle = new LRF_ClientHandler( ClientSocket );
if( tHandle != NULL ) {
tHandle->attachEngine( m_pDetectorKernel );
m_vHandlersPool.push_back( (networkClientHandler *) tHandle );
};
};
};
LOG( "Core Worker Thread Ended" );

2
lib/data/net/serverPort.h

@ -20,7 +20,7 @@
#include <windows.h>
#endif
#include "transportSocket.h"
#include "../transport/transportSocket.h"
/**
* TODO: Add class description

142
lib/data/net/transportSocket.cpp

@ -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

113
lib/data/net/transportSocket.cpp.bak

@ -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

64
lib/data/net/transportSocket.h

@ -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__

62
lib/data/net/transportSocket.h.bak

@ -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__

2
lib/data/protocol/protocol.cpp

@ -12,7 +12,7 @@ protocolParser::protocolParser(config_setting_t *Settings) :basicThread(),m_mBuf
m_bBufferAltered = false;
m_bStatus = 1;
m_eConnectionStatus = CS_UNKNOWN;
m_pSettings = basicSettingsProvider::getInstance()->getSubNode(Settings, (CSTR)PROTO_TAG_GROUP);
//m_pSettings = basicSettingsProvider::getInstance()->getSubNode(Settings, (CSTR)PROTO_TAG_GROUP);
};
protocolParser::~protocolParser(){

5
lib/data/protocol/protocol.h

@ -30,7 +30,7 @@ class protocolParser : public basicThread{
basicMutex m_mBufferProtectorMutex;
protected:
config_setting_t *m_pSettings;
//config_setting_t *m_pSettings;
CONNECTION_STATUS m_eConnectionStatus;
basicLogCollection *m_pLog;
U8 m_bStatus;
@ -43,7 +43,8 @@ class protocolParser : public basicThread{
void (*m_pCustomHandler)( protocolPackage *pPp );
//static void *m_ParserProc( void *Param );
public:
explicit protocolParser( config_setting_t *Settings = NULL );
//explicit protocolParser( config_setting_t *Settings = NULL );
protocolParser();
virtual ~protocolParser();
virtual bool create(void);
bool parse( U8 *Buffer, size_t BufferSize );

369
lib/data/protocol/protocolInternalLRF3D.cpp

@ -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

72
lib/data/protocol/protocolInternalLRF3D.h

@ -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

809
lib/data/protocol/protocolLGS.h

@ -1,809 +1,10 @@
#ifndef __PROTOCOL_LGS_HEADERS__
#define __PROTOCOL_LGS_HEADERS__
#ifndef __PROTOCOL_LGS_3D_HEADERS__
#define __PROTOCOL_LGS_3D_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"
#include "protocolLGSm.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 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);
};
class protocolLGS_CLIENT: public protocolLGS{
class protocolLGS_CLIENT: public protocolLGSm{
private:
basicLogCollection *m_pLog;
public:
@ -832,7 +33,7 @@ class protocolLGS_CLIENT: public protocolLGS{
};
class protocolLGS_SERVER: public protocolLGS{
class protocolLGS_SERVER: public protocolLGSm{
private:
basicLogCollection *m_pLog;
public:

2
lib/data/protocol/protocolLGS2D.cpp

@ -0,0 +1,2 @@
#include "protocolLGS2D.h"

25
lib/data/protocol/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

134
lib/data/protocol/protocolLGSm.cpp

@ -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

808
lib/data/protocol/protocolLGSm.h

@ -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

12
lib/data/transport/transportSerial.h

@ -12,16 +12,16 @@ class transportSerial: public basicTransport, public basicDualThread {
void m_fThreadAProc(void);
void m_fThreadBProc(void);
protected:
U8 *m_pInputBuffer;
int m_nInputBufferSize;
U8 *m_pOutputBuffer;
int m_nOutputBufferSize;
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;};
public:
transportSerial();
~transportSerial();
bool sendData( unsigned char *Data, int DataSize );
virtual ~transportSerial();
bool sendData( unsigned char *Data, int DataSize );
};

130
lib/data/transport/transportSocket.cpp

@ -6,79 +6,137 @@
// 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;
LOG("Starting");
init();
};
//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(){
if (m_pInputBuffer != NULL) {
free(m_pInputBuffer);
};
if (m_pOutputBuffer != NULL) {
free(m_pOutputBuffer);
};
# 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("Thread A Started");
LOG("Sender Thread Started!");
while (m_bThreadAStatus < TH_ENDED) {
m_mBufferProtectorMutex.lock();
if (m_nOutputBufferSize > 0) {
int index;
int RetVal;
if( m_nOutputBufferSize > 0 ){
index = 0;
//LOG("Buffer ready to Send");
while ((index < m_nOutputBufferSize) && (m_bThreadAStatus < TH_ENDED)){
RetVal = sendBlock(m_pOutputBuffer + index, m_nOutputBufferSize - index);
if (RetVal > 0) index += RetVal;
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;
};
};
//LOG("Buffer is Sent");
m_nOutputBufferSize = 0;
m_mBufferProtectorMutex.unlock();
} else {
m_mBufferProtectorMutex.unlock();
SLEEP(5);
};
m_mBufferProtectorMutex.unlock();
SLEEP(1);
};
};
void transportSocket::m_fThreadBProc(void){
m_bThreadBStatus = TH_WORKING;
LOG("Thread B Started");
while (m_bThreadBStatus < TH_ENDED) {
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);
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!");
};
m_mQueueProtectorMutex.unlock();
} else {
SLEEP(5);
};
SLEEP(1);
};
};
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) {
if (m_nOutputBufferSize + DataSize > MAXIMAL_SOCKET_PACKET_LENGTH ){
m_mBufferProtectorMutex.unlock();
LOG("Data Too BIG");
LOG_ERROR("Data Too BIG");
return false;
};
//LOG("Output Data Set");
memcpy(m_pOutputBuffer + m_nOutputBufferSize, Data, DataSize);
m_nOutputBufferSize += DataSize;
m_mBufferProtectorMutex.unlock();
return true;
};
#undef LOG
#undef LOG_ERROR

53
lib/data/transport/transportSocket.h

@ -12,22 +12,53 @@
* @author Gagua
*/
class transportSocket : public basicTransport, public basicDualThread {
private:
basicLogCollection * m_pLog;
void m_fThreadAProc(void);
void m_fThreadBProc(void);
private:
basicLogCollection *m_pLog;
protected:
U8 * m_pInputBuffer;
int m_nInputBufferSize;
U8 * m_pOutputBuffer;
int m_nOutputBufferSize;
//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 int sendBlock(unsigned char *Data, int DataSize){ return 0; };
virtual int recptBlock(unsigned char *Buffer, int *BufferLength){ return 0; };
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();
bool sendData(unsigned char *Data, int DataSize);
// 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__

4
lib/hardware/uart/serialPort.h

@ -9,8 +9,8 @@
#include <fcntl.h> // File control definitions
#include <errno.h> // Error number definitions
#ifdef __linux__
#include <unistd.h> // UNIX standard function definitions
#include <termios.h> // POSIX terminal control definitions
#include <unistd.h> // UNIX standard function definitions
#include <termios.h> // POSIX terminal control definitions
#else
#endif

165
lib/hardware/uart/serialSOL.cpp

@ -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

50
lib/hardware/uart/serialSOL.h

@ -1,5 +1,5 @@
#ifndef __SERIAL_PORT_serial-over-LAN__
#define __SERIAL_PORT_serial-over-LAN__
#ifndef __SERIAL_PORT_SERIAL_OVER_LAN__
#define __SERIAL_PORT_SERIAL_OVER_LAN__
/*
#!/bin/bash
@ -15,7 +15,53 @@
http://www.dest-unreach.org/socat/doc/socat-ttyovertcp.txt
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h> // File control definitions
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#ifdef DEBUG
//#define _DEBUG_SOL_COMMUNICATION_
#endif
#include "../../data/transport/transportSocket.h"
typedef enum E_SOL_TYPE{
SOL_UDP_CLIENT = 0,
SOL_TCP_CLIENT = 1,
SOL_UDP_SERVER = 2,
SOL_TCP_SERVER = 3
}SOL_TYPE;
/**
* TODO: Add class description
*
* @author gagua
*/
class serialSOL: public transportSocket {
private:
basicLogCollection *m_pLog;
SOL_TYPE m_eSolType;
bool m_bInitComplete;
int m_nSocketFD;
struct sockaddr_in m_sServerAddr;
struct sockaddr_in m_sClientAddr;
protected:
int sendBlock( unsigned char *Data, int DataSize );
int recptBlock( unsigned char *Buffer, int *BufferLength );
public:
explicit serialSOL( SOL_TYPE t );
virtual ~serialSOL();
bool create( CSTR address, uint16_t port, int Speed );
};
#endif

0
lib/rgoose/rgooseNode2D.cpp

42
lib/rgoose/rgooseNode2D.h

@ -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

4
lib/rgoose/rgooseNode3D.h

@ -1,5 +1,5 @@
#ifndef __OBJECT_LGS_HEADERS__
#define __OBJECT_LGS_HEADERS__
#ifndef __OBJECT_NET_NODE_3D_HEADERS__
#define __OBJECT_NET_NODE_3D_HEADERS__
#ifndef __linux__
#include <WinSock2.h>

Loading…
Cancel
Save