Browse Source
Before Spain
Before Spain
63 changed files with 4580 additions and 1338 deletions
-
4.gitignore
-
134Projects/LRF_ServerSlim/LRF_ServerSlim.vpj
-
2Projects/LRF_ServerSlim/build
-
217Projects/LRF_ServerSlim/makefile
-
6Projects/argus/argus.vpj
-
84Projects/argus/makefile
-
9lib/App/3dSERVER/LRF_HardwareManager.cpp
-
6lib/App/3dSERVER/LRF_SlimKernel.cpp
-
89lib/alg/generic/Transform.cpp
-
27lib/alg/generic/Transform.h
-
22lib/components/base/basicCameraInfo.cpp
-
8lib/components/base/basicCameraInfo.h
-
14lib/components/base/basicEngine.h
-
8lib/components/base/basicEvent.cpp
-
7lib/components/base/basicEvent.h
-
39lib/components/base/basicFunctionality.cpp
-
5lib/components/base/basicFunctionality.h
-
2lib/components/base/basicObject.cpp
-
4lib/components/base/basicObject.h
-
34lib/components/base/basicPosition.cpp
-
16lib/components/base/basicPosition.h
-
11lib/components/base/basicValidatable.h
-
703lib/components/object/objectSystemAnchor.cpp
-
7lib/components/object/objectSystemAnchor.h
-
3lib/data/net/netServer.h
-
4lib/data/protocol/protocolLGS3D.h
-
6lib/data/protocol/protocolLGS3D_client.cpp
-
4lib/hardware/soc/general/3DLRF.h
-
1072lib/rgoose/rgooseCamera.cpp
-
101lib/rgoose/rgooseCamera.h
-
438lib/rgoose/rgooseDBConnector.cpp
-
36lib/rgoose/rgooseDBConnector.h
-
72lib/rgoose/rgooseHardwareManager.cpp
-
5lib/rgoose/rgooseHardwareManager.h
-
118lib/rgoose/rgooseHardwareResource.cpp
-
10lib/rgoose/rgooseHardwareResource.h
-
2lib/rgoose/rgooseHardwareResourceNetworkProvider.cpp
-
124lib/rgoose/rgooseHardwareResourceSerialProvider.cpp
-
4lib/rgoose/rgooseHardwareResourceSerialProvider.h
-
159lib/rgoose/rgooseKernel.cpp
-
7lib/rgoose/rgooseKernel.h
-
134lib/rgoose/rgooseModuleEmbedVideo.cpp
-
5lib/rgoose/rgooseModuleEmbedVideo.h
-
266lib/rgoose/rgooseModuleKafka.cpp
-
26lib/rgoose/rgooseModuleKafka.h
-
2lib/rgoose/rgooseModuleModemManager.cpp
-
4lib/rgoose/rgooseModuleZLMedia.cpp
-
7lib/rgoose/rgooseNode.cpp
-
66lib/rgoose/rgooseNode.h
-
116lib/rgoose/rgooseNode2D.cpp
-
7lib/rgoose/rgooseNode2D.h
-
310lib/rgoose/rgooseNode3D.cpp
-
5lib/rgoose/rgooseNode3D.h
-
706lib/rgoose/rgooseNodeEthernet2Serial.cpp
-
55lib/rgoose/rgooseNodeEthernet2Serial.h
-
29lib/rgoose/rgooseNodeFactory.cpp
-
16lib/rgoose/rgooseNodePTZCamControl.cpp
-
7lib/rgoose/rgooseNodePTZCamControl.h
-
429lib/rgoose/rgooseNodeSensor.cpp
-
69lib/rgoose/rgooseNodeSensor.h
-
8lib/rgoose/rgooseNodeStaticCamControl.cpp
-
4lib/rgoose/rgooseNodeStaticCamControl.h
-
24lib/rgoose/rgooseTypes.h
217
Projects/LRF_ServerSlim/makefile
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
84
Projects/argus/makefile
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,11 @@ |
|||
#ifndef __BASE_VALIDATABLE_PROPERTY_HEADER__ |
|||
#define __BASE_VALIDATABLE_PROPERTY_HEADER__ |
|||
|
|||
class basicValidatable{ |
|||
public: |
|||
basicValidatable(){}; |
|||
virtual ~basicValidatable(){}; |
|||
virtual bool validate(){ return false; }; |
|||
}; |
|||
|
|||
#endif |
|||
@ -1,333 +1,372 @@ |
|||
#include "objectSystemAnchor.h"
|
|||
#ifdef DEBUG
|
|||
#include "../base/basicLogCollection.h"
|
|||
#define LOG( X ) basicLogCollection::getInstance()->Log( "ANCHOR", this, X )
|
|||
#define LOG_ERROR( X ) {\
|
|||
char _tBfrErrMSG2w34[256];\ |
|||
sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\ |
|||
basicLogCollection::getInstance()->Log( "ANCHOR", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ |
|||
} |
|||
#endif
|
|||
#include "objectSystemAnchor.h"
|
|||
#ifdef DEBUG
|
|||
#include "../base/basicLogCollection.h"
|
|||
#define LOG( X ) basicLogCollection::getInstance()->Log( "ANCHOR", this, X )
|
|||
#define LOG_ERROR( X ) {\
|
|||
char _tBfrErrMSG2w34[256];\ |
|||
sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\ |
|||
basicLogCollection::getInstance()->Log( "ANCHOR", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ |
|||
} |
|||
#endif
|
|||
|
|||
systemAnchor* systemAnchor::_instance = 0; |
|||
|
|||
/**
|
|||
* Returns the single instance of the object. |
|||
*/ |
|||
systemAnchor* systemAnchor::getInstance( bool SOUTH, C3D_WGS84_LOC *ptr ) { |
|||
// check if the instance has been created yet
|
|||
if (0 == _instance) { |
|||
// if not, then create it
|
|||
_instance = new systemAnchor( SOUTH, ptr ); |
|||
} |
|||
// return the single instance
|
|||
return _instance; |
|||
}; |
|||
|
|||
systemAnchor::systemAnchor( bool SOUTH, C3D_WGS84_LOC *ptr ): m_SCC(){ |
|||
config_setting_t *pSetting; |
|||
m_pSettings = NULL; |
|||
m_bSouthHemisphere = 0; |
|||
if( ptr == NULL ) { |
|||
pSetting = basicSettingsProvider::getInstance()->getSubNode( NULL, "APPLICATION_GUI" ); |
|||
if( pSetting != NULL ){ |
|||
m_pSettings = basicSettingsProvider::getInstance()->getSubNode( pSetting, "SYSTEM_ANCHOR" ); |
|||
}; |
|||
// Read Config
|
|||
if( m_pSettings != NULL ){ |
|||
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LAT ); |
|||
if (pSetting == NULL){ |
|||
lat = 0.f; |
|||
pSetting = config_setting_add(m_pSettings, TAG_POSITION_LAT, CONFIG_TYPE_FLOAT ); |
|||
config_setting_set_float( pSetting, lat ); |
|||
basicSettingsProvider::getInstance()->compromise(); |
|||
} else { |
|||
lat = (float)config_setting_get_float(pSetting); |
|||
}; |
|||
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LON ); |
|||
if (pSetting == NULL){ |
|||
lon = 0.f; |
|||
pSetting = config_setting_add(m_pSettings, TAG_POSITION_LON, CONFIG_TYPE_FLOAT ); |
|||
config_setting_set_float( pSetting, lon ); |
|||
basicSettingsProvider::getInstance()->compromise(); |
|||
} else { |
|||
lon = config_setting_get_float(pSetting); |
|||
}; |
|||
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ALT ); |
|||
if (pSetting == NULL){ |
|||
z = 0.f; |
|||
pSetting = config_setting_add(m_pSettings, TAG_POSITION_ALT, CONFIG_TYPE_FLOAT ); |
|||
config_setting_set_float( pSetting, z ); |
|||
basicSettingsProvider::getInstance()->compromise(); |
|||
} else { |
|||
z = config_setting_get_float(pSetting); |
|||
}; |
|||
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_SOUTH_HS); |
|||
if (pSetting == NULL){ |
|||
m_bSouthHemisphere = false; |
|||
pSetting = config_setting_add(m_pSettings, TAG_POSITION_SOUTH_HS, CONFIG_TYPE_BOOL ); |
|||
config_setting_set_bool(pSetting, m_bSouthHemisphere); |
|||
basicSettingsProvider::getInstance()->compromise(); |
|||
} else { |
|||
m_bSouthHemisphere = config_setting_get_bool(pSetting); |
|||
}; |
|||
#ifdef FLOAT_64
|
|||
double A, B; |
|||
utmZone = CC.LatLonToUTMXY( lat, lon, 0 , A, B ); |
|||
x = A; |
|||
y = B; |
|||
#else
|
|||
utmZone = m_SCC.LatLonToUTMXY(lat, lon, m_bSouthHemisphere, x, y); |
|||
#endif
|
|||
basicSettingsProvider::getInstance()->validate(); |
|||
}; |
|||
} else { |
|||
m_bSouthHemisphere = SOUTH; |
|||
lat = ptr->lat; |
|||
lon = ptr->lon; |
|||
z = ptr->alt; |
|||
#ifdef FLOAT_64
|
|||
double A, B; |
|||
utmZone = CC.LatLonToUTMXY( lat, lon, 0 , A, B ); |
|||
x = A; |
|||
y = B; |
|||
#else
|
|||
utmZone = m_SCC.LatLonToUTMXY(lat, lon, m_bSouthHemisphere, x, y); |
|||
#endif
|
|||
}; |
|||
#ifdef DEBUG
|
|||
char tBuff[256]; |
|||
sprintf( tBuff, "WGS84[lat:%0.6f Lon:%0.6f Alt:%0.6f] UMTS[x:%0.4f y:%0.4f z:%0.4f]", lat, lon, z, x, y, z ); |
|||
LOG( tBuff ); |
|||
#endif
|
|||
}; |
|||
|
|||
systemAnchor::~systemAnchor(){ |
|||
/*
|
|||
config_setting_t *pSetting; |
|||
C3D_FLOAT tVal; |
|||
bool tBool; |
|||
|
|||
m_pSettings = NULL; |
|||
pSetting = basicSettingsProvider::getInstance()->getSubNode( NULL, "APPLICATION_GUI" ); |
|||
if( pSetting != NULL ){ |
|||
m_pSettings = basicSettingsProvider::getInstance()->getSubNode( pSetting, "SYSTEM_ANCHOR" ); |
|||
}; |
|||
// Read Config
|
|||
if( m_pSettings != NULL ){ |
|||
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LAT); |
|||
if (pSetting == NULL){ |
|||
pSetting = config_setting_add(m_pSettings, TAG_POSITION_LAT, CONFIG_TYPE_FLOAT ); |
|||
config_setting_set_float(pSetting, lat ); |
|||
basicSettingsProvider::getInstance()->compromise(); |
|||
} else { |
|||
tVal = config_setting_get_float(pSetting); |
|||
if( lat != tVal ){ |
|||
config_setting_set_float(pSetting, lat ); |
|||
basicSettingsProvider::getInstance()->compromise(); |
|||
}; |
|||
}; |
|||
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LON); |
|||
if (pSetting == NULL){ |
|||
pSetting = config_setting_add(m_pSettings, TAG_POSITION_LON, CONFIG_TYPE_FLOAT ); |
|||
config_setting_set_float(pSetting, lon ); |
|||
basicSettingsProvider::getInstance()->compromise(); |
|||
} else { |
|||
tVal = config_setting_get_float(pSetting); |
|||
if( lon != tVal ){ |
|||
config_setting_set_float(pSetting, lon ); |
|||
basicSettingsProvider::getInstance()->compromise(); |
|||
}; |
|||
}; |
|||
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ALT); |
|||
if (pSetting == NULL){ |
|||
pSetting = config_setting_add(m_pSettings, TAG_POSITION_ALT, CONFIG_TYPE_FLOAT ); |
|||
config_setting_set_float(pSetting, z ); |
|||
basicSettingsProvider::getInstance()->compromise(); |
|||
} else { |
|||
tVal = config_setting_get_float(pSetting); |
|||
if( z != tVal ){ |
|||
config_setting_set_float(pSetting, z ); |
|||
basicSettingsProvider::getInstance()->compromise(); |
|||
}; |
|||
}; |
|||
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_SOUTH_HS); |
|||
if (pSetting == NULL){ |
|||
pSetting = config_setting_add(m_pSettings, TAG_POSITION_SOUTH_HS, CONFIG_TYPE_BOOL ); |
|||
config_setting_set_bool(pSetting, m_bSouthHemisphere ); |
|||
basicSettingsProvider::getInstance()->compromise(); |
|||
} else { |
|||
tBool = config_setting_get_bool(pSetting); |
|||
if (m_bSouthHemisphere != tBool){ |
|||
config_setting_set_bool(pSetting, m_bSouthHemisphere ); |
|||
basicSettingsProvider::getInstance()->compromise(); |
|||
}; |
|||
}; |
|||
basicSettingsProvider::getInstance()->validate(); |
|||
}; |
|||
*/ |
|||
}; |
|||
|
|||
bool systemAnchor::convertToLocal(basicPosition *SP, C3D_WGS84_LOC POS, C3D_SPH_DEGREES& LOC) { |
|||
if (SP == NULL) return false; |
|||
transform_3* pTF = SP->getTransform(); |
|||
C3D_DECART tDec; |
|||
vector_3 A, B; |
|||
tDec.z = POS.alt; |
|||
m_SCC.LatLonToUTMXY(POS.lat, POS.lon, SP->getUTMZone(), tDec.x, tDec.y); |
|||
A[0] = tDec.x; |
|||
A[1] = tDec.y; |
|||
A[2] = tDec.z; |
|||
pTF->get_vector_local(A, B); |
|||
tDec.x = B[0]; |
|||
tDec.y = B[1]; |
|||
tDec.z = B[2]; |
|||
decart2spherical(tDec, LOC); |
|||
return true; |
|||
}; |
|||
|
|||
bool systemAnchor::convertToLocal(basicPosition *SP, C3D_WGS84_LOC POS, C3D_SPH_RADIANS& LOC) { |
|||
if (SP == NULL) return false; |
|||
transform_3* pTF = SP->getTransform(); |
|||
C3D_DECART tDec; |
|||
vector_3 A, B; |
|||
tDec.z = POS.alt; |
|||
m_SCC.LatLonToUTMXY(POS.lat, POS.lon, getUTMZone(), tDec.x, tDec.y); |
|||
A[0] = tDec.x;// - SP->getX();
|
|||
A[1] = tDec.y;// - SP->getY();
|
|||
A[2] = tDec.z;// - SP->getZ();
|
|||
pTF->get_vector_local( A, B ); |
|||
tDec.x = B[0]; |
|||
tDec.y = B[1]; |
|||
tDec.z = B[2]; |
|||
decart2spherical(tDec, LOC); |
|||
return true; |
|||
}; |
|||
|
|||
bool systemAnchor::convertToLocal( basicPosition *SP, C3D_DECART POS, C3D_SPH_DEGREES& LOC) { |
|||
if (SP == NULL) return false; |
|||
transform_3* pTF = SP->getTransform(); |
|||
C3D_DECART tDec; |
|||
vector_3 A, B; |
|||
// POS - is Relative to System Anchore!!
|
|||
A[0] = getX() + POS.x; |
|||
A[1] = getY() + POS.y; |
|||
A[2] = getZ() + POS.z; |
|||
pTF->get_vector_local( A, B ); |
|||
tDec.x = B[0]; |
|||
tDec.y = B[1]; |
|||
tDec.z = B[2]; |
|||
decart2spherical(tDec, LOC); |
|||
return true; |
|||
}; |
|||
|
|||
bool systemAnchor::convertToLocal(basicPosition *SP, C3D_DECART POS, C3D_SPH_RADIANS& LOC) { |
|||
if (SP == NULL) return false; |
|||
transform_3* pTF = SP->getTransform(); |
|||
C3D_DECART tDec; |
|||
vector_3 A, B; |
|||
// POS - is Relative to System Anchore!!
|
|||
A[0] = getX() + POS.x; |
|||
A[1] = getY() + POS.y; |
|||
A[2] = getZ() + POS.z; |
|||
pTF->get_vector_local(A, B); |
|||
tDec.x = B[0]; |
|||
tDec.y = B[1]; |
|||
tDec.z = B[2]; |
|||
decart2spherical(tDec, LOC); |
|||
return true; |
|||
}; |
|||
|
|||
bool systemAnchor::convertToSystem(basicPosition *SP, C3D_WGS84_LOC POS, C3D_DECART& LOC) { |
|||
if (SP == NULL) return false; |
|||
C3D_DECART tDec; |
|||
tDec.z = POS.alt; |
|||
m_SCC.LatLonToUTMXY(POS.lat, POS.lon, SP->getUTMZone(), tDec.x, tDec.y); |
|||
LOC.x = tDec.x - getX(); |
|||
LOC.y = tDec.y - getX(); |
|||
LOC.z = tDec.z - getZ(); |
|||
return true; |
|||
}; |
|||
|
|||
bool systemAnchor::convertToSystem(basicPosition *SP, C3D_SPH_DEGREES POS, C3D_DECART& LOC) { |
|||
if (SP == NULL) return false; |
|||
transform_3* pTF = SP->getTransform(); |
|||
C3D_DECART tDec; |
|||
vector_3 A, B; |
|||
spherical2decart( POS, tDec ); |
|||
A[0] = tDec.x; |
|||
A[1] = tDec.y; |
|||
A[2] = tDec.z; |
|||
pTF->get_vector_world(A, B); |
|||
LOC.x = B[0] - getX(); |
|||
LOC.y = B[1] - getY(); |
|||
LOC.z = B[2] - getZ(); |
|||
return true; |
|||
}; |
|||
|
|||
bool systemAnchor::convertToSystem(basicPosition *SP, C3D_SPH_RADIANS POS, C3D_DECART& LOC) { |
|||
if (SP == NULL) return false; |
|||
transform_3* pTF = SP->getTransform(); |
|||
C3D_DECART tDec; |
|||
vector_3 A, B; |
|||
spherical2decart( POS, tDec ); |
|||
A[0] = tDec.x; |
|||
A[1] = tDec.y; |
|||
A[2] = tDec.z; |
|||
pTF->get_vector_world(A, B); |
|||
LOC.x = B[0] - getX(); |
|||
LOC.y = B[1] - getY(); |
|||
LOC.z = B[2] - getZ(); |
|||
return true; |
|||
}; |
|||
|
|||
bool systemAnchor::convertToGlobal(basicPosition *SP, C3D_SPH_DEGREES POS, C3D_WGS84_LOC& LOC) { |
|||
if (SP == NULL) return false; |
|||
transform_3* pTF = SP->getTransform(); |
|||
C3D_DECART tDec; |
|||
vector_3 A, B; |
|||
spherical2decart( POS, tDec ); |
|||
A[0] = tDec.x; |
|||
A[1] = tDec.y; |
|||
A[2] = tDec.z; |
|||
pTF->get_vector_world(A, B); |
|||
tDec.x = B[0];// + SP->getX();
|
|||
tDec.y = B[1];// + SP->getY();
|
|||
tDec.z = B[2];// + SP->getZ();
|
|||
m_SCC.UTMXYToLatLon( tDec.x, tDec.y, getUTMZone(), m_bSouthHemisphere, LOC.lat, LOC.lon); |
|||
LOC.alt = tDec.z; |
|||
return true; |
|||
}; |
|||
|
|||
bool systemAnchor::convertToGlobal(basicPosition *SP, C3D_SPH_RADIANS POS, C3D_WGS84_LOC& LOC) { |
|||
if (SP == NULL) return false; |
|||
transform_3* pTF = SP->getTransform(); |
|||
C3D_DECART tDec; |
|||
vector_3 A, B; |
|||
spherical2decart(POS, tDec); |
|||
A[0] = tDec.x; |
|||
A[1] = tDec.y; |
|||
A[2] = tDec.z; |
|||
pTF->get_vector_world(A, B); |
|||
tDec.x = B[0];// + SP->getX();
|
|||
tDec.y = B[1];// + SP->getY();
|
|||
tDec.z = B[2];// + SP->getZ();
|
|||
m_SCC.UTMXYToLatLon(tDec.x, tDec.y, getUTMZone(), m_bSouthHemisphere, LOC.lat, LOC.lon); |
|||
LOC.alt = tDec.z; |
|||
return true; |
|||
}; |
|||
|
|||
bool systemAnchor::convertToGlobal(basicPosition *SP, C3D_DECART POS, C3D_WGS84_LOC& LOC) { |
|||
C3D_DECART tDec; |
|||
tDec.x = POS.x; |
|||
tDec.y = POS.y; |
|||
tDec.z = POS.z; |
|||
m_SCC.UTMXYToLatLon(tDec.x, tDec.y, getUTMZone(), m_bSouthHemisphere, LOC.lat, LOC.lon); |
|||
LOC.alt = tDec.z; |
|||
return true; |
|||
}; |
|||
|
|||
#ifdef DEBUG
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
#endif
|
|||
systemAnchor* systemAnchor::_instance = 0; |
|||
|
|||
/**
|
|||
* Returns the single instance of the object. |
|||
*/ |
|||
systemAnchor* systemAnchor::getInstance( bool SOUTH, C3D_WGS84_LOC *ptr, bool jl ) { |
|||
// check if the instance has been created yet
|
|||
if (0 == _instance) { |
|||
// if not, then create it
|
|||
_instance = new systemAnchor( SOUTH, ptr, jl ); |
|||
} |
|||
// return the single instance
|
|||
return _instance; |
|||
}; |
|||
|
|||
systemAnchor::systemAnchor( bool SOUTH, C3D_WGS84_LOC *ptr, bool beJustLocal ): m_SCC(){ |
|||
config_setting_t *pSetting; |
|||
m_pSettings = NULL; |
|||
m_bSouthHemisphere = 0; |
|||
m_bUseJustLocalDiffCoords = beJustLocal; |
|||
m_bSouthHemisphere = SOUTH; |
|||
if( ptr == NULL ) { |
|||
pSetting = basicSettingsProvider::getInstance()->getSubNode( NULL, "APPLICATION_GUI" ); |
|||
if( pSetting != NULL ){ |
|||
m_pSettings = basicSettingsProvider::getInstance()->getSubNode( pSetting, "SYSTEM_ANCHOR" ); |
|||
}; |
|||
// Read Config
|
|||
if( m_pSettings != NULL ){ |
|||
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LAT ); |
|||
if (pSetting == NULL){ |
|||
lat = 0.f; |
|||
pSetting = config_setting_add(m_pSettings, TAG_POSITION_LAT, CONFIG_TYPE_FLOAT ); |
|||
config_setting_set_float( pSetting, lat ); |
|||
basicSettingsProvider::getInstance()->compromise(); |
|||
} else { |
|||
lat = (float)config_setting_get_float(pSetting); |
|||
}; |
|||
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LON ); |
|||
if (pSetting == NULL){ |
|||
lon = 0.f; |
|||
pSetting = config_setting_add(m_pSettings, TAG_POSITION_LON, CONFIG_TYPE_FLOAT ); |
|||
config_setting_set_float( pSetting, lon ); |
|||
basicSettingsProvider::getInstance()->compromise(); |
|||
} else { |
|||
lon = config_setting_get_float(pSetting); |
|||
}; |
|||
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ALT ); |
|||
if (pSetting == NULL){ |
|||
z = 0.f; |
|||
pSetting = config_setting_add(m_pSettings, TAG_POSITION_ALT, CONFIG_TYPE_FLOAT ); |
|||
config_setting_set_float( pSetting, z ); |
|||
basicSettingsProvider::getInstance()->compromise(); |
|||
} else { |
|||
z = config_setting_get_float(pSetting); |
|||
}; |
|||
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_SOUTH_HS); |
|||
if (pSetting == NULL){ |
|||
m_bSouthHemisphere = false; |
|||
pSetting = config_setting_add(m_pSettings, TAG_POSITION_SOUTH_HS, CONFIG_TYPE_BOOL ); |
|||
config_setting_set_bool(pSetting, m_bSouthHemisphere); |
|||
basicSettingsProvider::getInstance()->compromise(); |
|||
} else { |
|||
m_bSouthHemisphere = config_setting_get_bool(pSetting); |
|||
}; |
|||
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LOCAL); |
|||
if (pSetting == NULL){ |
|||
m_bUseJustLocalDiffCoords = false; |
|||
pSetting = config_setting_add(m_pSettings, TAG_POSITION_LOCAL, CONFIG_TYPE_BOOL ); |
|||
config_setting_set_bool(pSetting, m_bUseJustLocalDiffCoords); |
|||
basicSettingsProvider::getInstance()->compromise(); |
|||
} else { |
|||
m_bUseJustLocalDiffCoords = config_setting_get_bool(pSetting); |
|||
}; |
|||
#ifdef FLOAT_64
|
|||
double A, B; |
|||
utmZone = CC.LatLonToUTMXY( lat, lon, 0 , A, B ); |
|||
x = A; |
|||
y = B; |
|||
#else
|
|||
utmZone = m_SCC.LatLonToUTMXY(lat, lon, m_bSouthHemisphere, x, y); |
|||
#endif
|
|||
basicSettingsProvider::getInstance()->validate(); |
|||
}; |
|||
} else { |
|||
lat = ptr->lat; |
|||
lon = ptr->lon; |
|||
z = ptr->alt; |
|||
#ifdef FLOAT_64
|
|||
double A, B; |
|||
utmZone = CC.LatLonToUTMXY( lat, lon, 0 , A, B ); |
|||
x = A; |
|||
y = B; |
|||
#else
|
|||
utmZone = m_SCC.LatLonToUTMXY(lat, lon, m_bSouthHemisphere, x, y); |
|||
#endif
|
|||
}; |
|||
#ifdef DEBUG
|
|||
char tBuff[256]; |
|||
sprintf( tBuff, "WGS84[lat:%0.6f Lon:%0.6f Alt:%0.6f] UMTS[x:%0.4f y:%0.4f z:%0.4f]", lat, lon, z, x, y, z ); |
|||
LOG( tBuff ); |
|||
#endif
|
|||
}; |
|||
|
|||
systemAnchor::~systemAnchor(){ |
|||
/*
|
|||
config_setting_t *pSetting; |
|||
C3D_FLOAT tVal; |
|||
bool tBool; |
|||
|
|||
m_pSettings = NULL; |
|||
pSetting = basicSettingsProvider::getInstance()->getSubNode( NULL, "APPLICATION_GUI" ); |
|||
if( pSetting != NULL ){ |
|||
m_pSettings = basicSettingsProvider::getInstance()->getSubNode( pSetting, "SYSTEM_ANCHOR" ); |
|||
}; |
|||
// Read Config
|
|||
if( m_pSettings != NULL ){ |
|||
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LAT); |
|||
if (pSetting == NULL){ |
|||
pSetting = config_setting_add(m_pSettings, TAG_POSITION_LAT, CONFIG_TYPE_FLOAT ); |
|||
config_setting_set_float(pSetting, lat ); |
|||
basicSettingsProvider::getInstance()->compromise(); |
|||
} else { |
|||
tVal = config_setting_get_float(pSetting); |
|||
if( lat != tVal ){ |
|||
config_setting_set_float(pSetting, lat ); |
|||
basicSettingsProvider::getInstance()->compromise(); |
|||
}; |
|||
}; |
|||
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_LON); |
|||
if (pSetting == NULL){ |
|||
pSetting = config_setting_add(m_pSettings, TAG_POSITION_LON, CONFIG_TYPE_FLOAT ); |
|||
config_setting_set_float(pSetting, lon ); |
|||
basicSettingsProvider::getInstance()->compromise(); |
|||
} else { |
|||
tVal = config_setting_get_float(pSetting); |
|||
if( lon != tVal ){ |
|||
config_setting_set_float(pSetting, lon ); |
|||
basicSettingsProvider::getInstance()->compromise(); |
|||
}; |
|||
}; |
|||
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_ALT); |
|||
if (pSetting == NULL){ |
|||
pSetting = config_setting_add(m_pSettings, TAG_POSITION_ALT, CONFIG_TYPE_FLOAT ); |
|||
config_setting_set_float(pSetting, z ); |
|||
basicSettingsProvider::getInstance()->compromise(); |
|||
} else { |
|||
tVal = config_setting_get_float(pSetting); |
|||
if( z != tVal ){ |
|||
config_setting_set_float(pSetting, z ); |
|||
basicSettingsProvider::getInstance()->compromise(); |
|||
}; |
|||
}; |
|||
pSetting = config_setting_get_member(m_pSettings, TAG_POSITION_SOUTH_HS); |
|||
if (pSetting == NULL){ |
|||
pSetting = config_setting_add(m_pSettings, TAG_POSITION_SOUTH_HS, CONFIG_TYPE_BOOL ); |
|||
config_setting_set_bool(pSetting, m_bSouthHemisphere ); |
|||
basicSettingsProvider::getInstance()->compromise(); |
|||
} else { |
|||
tBool = config_setting_get_bool(pSetting); |
|||
if (m_bSouthHemisphere != tBool){ |
|||
config_setting_set_bool(pSetting, m_bSouthHemisphere ); |
|||
basicSettingsProvider::getInstance()->compromise(); |
|||
}; |
|||
}; |
|||
basicSettingsProvider::getInstance()->validate(); |
|||
}; |
|||
*/ |
|||
}; |
|||
|
|||
bool systemAnchor::convertToLocal(basicPosition *SP, C3D_WGS84_LOC POS, C3D_SPH_DEGREES& LOC) { |
|||
if (SP == NULL) return false; |
|||
transform_3* pTF = SP->getTransform(); |
|||
C3D_DECART tDec; |
|||
vector_3 A, B; |
|||
tDec.z = POS.alt; |
|||
m_SCC.LatLonToUTMXY(POS.lat, POS.lon, SP->getUTMZone(), tDec.x, tDec.y); |
|||
A[0] = tDec.x; |
|||
A[1] = tDec.y; |
|||
A[2] = tDec.z; |
|||
pTF->get_vector_local(A, B); |
|||
tDec.x = B[0]; |
|||
tDec.y = B[1]; |
|||
tDec.z = B[2]; |
|||
decart2spherical(tDec, LOC); |
|||
return true; |
|||
}; |
|||
|
|||
bool systemAnchor::convertToLocal(basicPosition *SP, C3D_WGS84_LOC POS, C3D_SPH_RADIANS& LOC) { |
|||
if (SP == NULL) return false; |
|||
transform_3* pTF = SP->getTransform(); |
|||
C3D_DECART tDec; |
|||
vector_3 A, B; |
|||
tDec.z = POS.alt; |
|||
m_SCC.LatLonToUTMXY(POS.lat, POS.lon, getUTMZone(), tDec.x, tDec.y); |
|||
A[0] = tDec.x;// - SP->getX();
|
|||
A[1] = tDec.y;// - SP->getY();
|
|||
A[2] = tDec.z;// - SP->getZ();
|
|||
pTF->get_vector_local( A, B ); |
|||
tDec.x = B[0]; |
|||
tDec.y = B[1]; |
|||
tDec.z = B[2]; |
|||
decart2spherical(tDec, LOC); |
|||
return true; |
|||
}; |
|||
|
|||
bool systemAnchor::convertToLocal( basicPosition *SP, C3D_DECART POS, C3D_SPH_DEGREES& LOC) { |
|||
if (SP == NULL) return false; |
|||
transform_3* pTF = SP->getTransform(); |
|||
C3D_DECART tDec; |
|||
vector_3 A, B; |
|||
// POS - is Relative to System Anchore!!
|
|||
if( m_bUseJustLocalDiffCoords ) { |
|||
A[0] = POS.x - getX(); // in general getX() = 0 as other coords of anchore
|
|||
A[1] = POS.y - getY(); |
|||
A[2] = POS.z - getZ(); |
|||
} else { |
|||
A[0] = POS.x; |
|||
A[1] = POS.y; |
|||
A[2] = POS.z; |
|||
}; |
|||
//A[0] = getX() + POS.x;
|
|||
//A[1] = getY() + POS.y;
|
|||
//A[2] = getZ() + POS.z;
|
|||
pTF->get_vector_local( A, B ); |
|||
tDec.x = B[0]; |
|||
tDec.y = B[1]; |
|||
tDec.z = B[2]; |
|||
decart2spherical(tDec, LOC); |
|||
return true; |
|||
}; |
|||
|
|||
bool systemAnchor::convertToLocal(basicPosition *SP, C3D_DECART POS, C3D_SPH_RADIANS& LOC) { |
|||
if (SP == NULL) return false; |
|||
transform_3* pTF = SP->getTransform(); |
|||
C3D_DECART tDec; |
|||
vector_3 A, B; |
|||
// POS - is Relative to System Anchore!!
|
|||
A[0] = getX() + POS.x; |
|||
A[1] = getY() + POS.y; |
|||
A[2] = getZ() + POS.z; |
|||
pTF->get_vector_local(A, B); |
|||
tDec.x = B[0]; |
|||
tDec.y = B[1]; |
|||
tDec.z = B[2]; |
|||
decart2spherical(tDec, LOC); |
|||
return true; |
|||
}; |
|||
|
|||
bool systemAnchor::convertToSystem(basicPosition *SP, C3D_WGS84_LOC POS, C3D_DECART& LOC) { |
|||
if (SP == NULL) return false; |
|||
C3D_DECART tDec; |
|||
tDec.z = POS.alt; |
|||
m_SCC.LatLonToUTMXY( POS.lat, POS.lon, SP->getUTMZone(), tDec.x, tDec.y ); |
|||
LOC.x = tDec.x - getX(); |
|||
LOC.y = tDec.y - getX(); |
|||
LOC.z = tDec.z - getZ(); |
|||
return true; |
|||
}; |
|||
|
|||
bool systemAnchor::convertToSystem(basicPosition *SP, C3D_SPH_DEGREES POS, C3D_DECART& LOC) { |
|||
if (SP == NULL) return false; |
|||
transform_3* pTF = SP->getTransform(); |
|||
C3D_DECART tDec; |
|||
vector_3 A, B; |
|||
spherical2decart( POS, tDec ); |
|||
A[0] = tDec.x; |
|||
A[1] = tDec.y; |
|||
A[2] = tDec.z; |
|||
#ifdef DEBUG_EXTRA
|
|||
char tB[256]; |
|||
sprintf( tB, "Local Decart: %.3f %.3f %.3f", A[0], A[1], A[2] ); |
|||
LOG( tB ); |
|||
#endif
|
|||
pTF->get_vector_world( A, B ); |
|||
#ifdef DEBUG_EXTRA
|
|||
sprintf( tB, "World Decart: %.3f %.3f %.3f", B[0], B[1], B[2] ); |
|||
LOG( tB ); |
|||
#endif
|
|||
#ifdef DEBUG_EXTRA
|
|||
sprintf( tB, "Systen Decart: %.3f %.3f %.3f", getX(), getY(), getZ() ); |
|||
LOG( tB ); |
|||
#endif
|
|||
//LOC.x = B[0] - getX();
|
|||
LOC.x = B[0] + SP->getX() - getX(); |
|||
//LOC.y = B[1] - getY();
|
|||
LOC.y = B[1] + SP->getY() - getY(); |
|||
//LOC.z = B[2] - getZ();
|
|||
LOC.z = B[2] + SP->getZ() - getZ(); |
|||
#ifdef DEBUG_EXTRA
|
|||
sprintf( tB, "Final System Decart: %.3f %.3f %.3f", LOC.x, LOC.y, LOC.z ); |
|||
LOG( tB ); |
|||
#endif
|
|||
return true; |
|||
}; |
|||
|
|||
bool systemAnchor::convertToSystem(basicPosition *SP, C3D_SPH_RADIANS POS, C3D_DECART& LOC) { |
|||
if (SP == NULL) return false; |
|||
transform_3* pTF = SP->getTransform(); |
|||
C3D_DECART tDec; |
|||
vector_3 A, B; |
|||
spherical2decart( POS, tDec ); |
|||
A[0] = tDec.x; |
|||
A[1] = tDec.y; |
|||
A[2] = tDec.z; |
|||
pTF->get_vector_world(A, B); |
|||
LOC.x = B[0] + SP->getX() - getX(); |
|||
LOC.y = B[1] + SP->getY() - getY(); |
|||
LOC.z = B[2] + SP->getZ() - getZ(); |
|||
return true; |
|||
}; |
|||
|
|||
bool systemAnchor::convertToGlobal(basicPosition *SP, C3D_SPH_DEGREES POS, C3D_WGS84_LOC& LOC) { |
|||
if (SP == NULL) return false; |
|||
transform_3* pTF = SP->getTransform(); |
|||
C3D_DECART tDec; |
|||
vector_3 A, B; |
|||
spherical2decart( POS, tDec ); |
|||
A[0] = tDec.x; |
|||
A[1] = tDec.y; |
|||
A[2] = tDec.z; |
|||
pTF->get_vector_world(A, B); |
|||
tDec.x = B[0] + SP->getX(); |
|||
tDec.y = B[1] + SP->getY(); |
|||
tDec.z = B[2] + SP->getZ(); |
|||
m_SCC.UTMXYToLatLon( tDec.x, tDec.y, getUTMZone(), m_bSouthHemisphere, LOC.lat, LOC.lon); |
|||
LOC.alt = tDec.z; |
|||
return true; |
|||
}; |
|||
|
|||
bool systemAnchor::convertToGlobal(basicPosition *SP, C3D_SPH_RADIANS POS, C3D_WGS84_LOC& LOC) { |
|||
if (SP == NULL) return false; |
|||
transform_3* pTF = SP->getTransform(); |
|||
C3D_DECART tDec; |
|||
vector_3 A, B; |
|||
spherical2decart(POS, tDec); |
|||
A[0] = tDec.x; |
|||
A[1] = tDec.y; |
|||
A[2] = tDec.z; |
|||
pTF->get_vector_world(A, B); |
|||
tDec.x = B[0] + SP->getX(); |
|||
tDec.y = B[1] + SP->getY(); |
|||
tDec.z = B[2] + SP->getZ(); |
|||
m_SCC.UTMXYToLatLon(tDec.x, tDec.y, getUTMZone(), m_bSouthHemisphere, LOC.lat, LOC.lon); |
|||
LOC.alt = tDec.z; |
|||
return true; |
|||
}; |
|||
|
|||
bool systemAnchor::convertToGlobal(basicPosition *SP, C3D_DECART POS, C3D_WGS84_LOC& LOC) { |
|||
C3D_DECART tDec; |
|||
tDec.x = POS.x + getX(); |
|||
tDec.y = POS.y + getY(); |
|||
tDec.z = POS.z + getZ(); |
|||
m_SCC.UTMXYToLatLon(tDec.x, tDec.y, getUTMZone(), m_bSouthHemisphere, LOC.lat, LOC.lon); |
|||
LOC.alt = tDec.z; |
|||
return true; |
|||
}; |
|||
|
|||
#ifdef DEBUG
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
#endif
|
|||
1072
lib/rgoose/rgooseCamera.cpp
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,706 @@ |
|||
#include "rgooseNodeEthernet2Serial.h"
|
|||
#include "rgooseHardwareManager.h"
|
|||
#include "../data/protocol/protocol.h"
|
|||
|
|||
#define LOG( X ) m_pLog->Log( "E2UART", this, X )
|
|||
|
|||
#ifdef DEBUG
|
|||
#define LOG_ERROR( X ) {\
|
|||
char _tBfrErrMSG2w34[256];\ |
|||
sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\ |
|||
m_pLog->Log( "E2UART", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ |
|||
} |
|||
#else
|
|||
#define LOG_ERROR( X ) m_pLog->Log( "E2UART", this, _LOG_ERROR, X );
|
|||
#endif
|
|||
|
|||
ARGUS_ETH2UART::ARGUS_ETH2UART( uint32_t nodeID ) : argusNetNode( nodeID ), argusHardwareResource(), basicTransport(), basicDualThread(){ |
|||
m_pLog = basicLogCollection::getInstance(); |
|||
memset( &m_sUartData, 0, sizeof(m_sUartData)); |
|||
m_nInputBufferSize = 0; |
|||
m_nOutputBufferSize = 0; |
|||
m_iDeviceFD = -1; |
|||
m_iMasterFD = -1; |
|||
m_iInFID = -1; |
|||
m_iOutFID = -1; |
|||
LOG("CREATE res!"); |
|||
argusHardwareResource::create( m_sNodeData.aux_parameter, ARGUS_HARDWARE_PROVIDER_SERIAL ); |
|||
}; |
|||
|
|||
ARGUS_ETH2UART::~ARGUS_ETH2UART(){ |
|||
closePort(); |
|||
argusHardwareManager * tH = argusHardwareManager::getInstance(); |
|||
if ( tH ) { |
|||
tH->resignResource( this ); |
|||
}; |
|||
}; |
|||
|
|||
bool ARGUS_ETH2UART::create( void ){ |
|||
DBC_UART_DATA *tDATA = NULL; |
|||
LOG("CREATE!"); |
|||
if( m_sResourceSettings.id == 0 ) return false; |
|||
if( m_sResourceSettings.aux_id == 0 ) return false; |
|||
|
|||
tDATA = m_pDBC->getUartData( m_sResourceSettings.aux_id ); |
|||
if( tDATA!= NULL ) { |
|||
memcpy( &m_sUartData, tDATA, sizeof(DBC_UART_DATA)); |
|||
#ifdef DEBUG
|
|||
LOG("KOKO!"); |
|||
LOG( m_sUartData.path ); |
|||
#endif
|
|||
free( tDATA ); |
|||
m_bValid = create_SOL(); |
|||
}; |
|||
|
|||
if ( m_bValid ) { |
|||
argusHardwareManager * tH = argusHardwareManager::getInstance(); |
|||
if ( tH ) { |
|||
tH->assignResource( this ); |
|||
}; |
|||
}; |
|||
return m_bValid; |
|||
}; |
|||
|
|||
bool ARGUS_ETH2UART::validate( void ){ |
|||
if( m_bValid ) { |
|||
m_bValid = pingDevice(); |
|||
if( !m_bValid ){ |
|||
LOG_ERROR("No Ping to device!"); |
|||
closePort(); |
|||
}; |
|||
}; |
|||
#ifdef DEBUG_EXTRA
|
|||
LOG("Check Settings For Changes"); |
|||
#endif
|
|||
DBC_UART_DATA *tDATA = m_pDBC->getUartData( m_sResourceSettings.aux_id ); |
|||
if( tDATA!= NULL ){ |
|||
bool bFlag = true; |
|||
if( strcmp(tDATA->path,m_sUartData.path)!= 0 ) bFlag = false; |
|||
//if( bFlag && ( m_sUartData.speed != tDATA->speed ) ) bFlag = false; //Speed for SOL port Erelevant
|
|||
if( bFlag && ( m_sUartData.mode != tDATA->mode ) ) bFlag = false; |
|||
if( bFlag && ( m_sUartData.port != tDATA->port ) ) bFlag = false; |
|||
if( !bFlag ) { |
|||
#ifdef DEBUG
|
|||
LOG("Settings Has been Changed!"); |
|||
#endif
|
|||
if( m_bValid ) closePort(); // if port not closed
|
|||
// Apply new settings
|
|||
memcpy( &m_sUartData, tDATA, sizeof(DBC_UART_DATA)); |
|||
#ifdef DEBUG
|
|||
LOG("Reconect with new settings"); |
|||
#endif
|
|||
m_bValid = create_SOL(); |
|||
}; |
|||
free( tDATA ); |
|||
} else { |
|||
LOG_ERROR("Error Fetch DB Data!"); |
|||
}; |
|||
// Finally in any case If Not Connected -> try to Connect!
|
|||
if( !m_bValid ) { |
|||
#ifdef DEBUG
|
|||
LOG("Try to Conncet"); |
|||
#endif
|
|||
m_bValid = create_SOL(); |
|||
}; |
|||
return m_bValid; |
|||
}; |
|||
|
|||
|
|||
#include <netinet/ip_icmp.h>
|
|||
// Define the Packet Constants
|
|||
// ping packet size
|
|||
#define PING_PKT_S 64
|
|||
|
|||
// Automatic port number
|
|||
#define PORT_NO 0
|
|||
|
|||
// Automatic port number
|
|||
#define PING_SLEEP_RATE 1000000
|
|||
|
|||
// Gives the timeout delay for receiving packets
|
|||
// in seconds
|
|||
#define RECV_TIMEOUT 1
|
|||
|
|||
// ping packet structure
|
|||
struct ping_pkt { |
|||
struct icmphdr hdr; |
|||
char msg[PING_PKT_S-sizeof(struct icmphdr)]; |
|||
}; |
|||
|
|||
bool ARGUS_ETH2UART::pingDevice(){ |
|||
bool RetVal = false; |
|||
if( m_bValid ) { |
|||
#ifdef DEBUG_EXTRA
|
|||
LOG("Pinging Device!"); |
|||
#endif
|
|||
int sockfd; |
|||
int ttl_val=64, msg_count=0, i, flag=1, msg_received_count=0; |
|||
struct ping_pkt pckt; |
|||
struct sockaddr_in ping_addr; |
|||
struct sockaddr_in r_addr; |
|||
struct timeval tv_out; |
|||
|
|||
tv_out.tv_sec = 0; |
|||
tv_out.tv_usec = 300000; // 1/3 of second
|
|||
|
|||
|
|||
ping_addr.sin_family = AF_INET; |
|||
ping_addr.sin_addr.s_addr = inet_addr( m_sUartData.path ); |
|||
//ping_addr.sin_port = htons( m_nPort );
|
|||
#ifdef DEBUG_EXTRA
|
|||
LOG( m_sUartData.path ); |
|||
#endif
|
|||
sockfd = socket( AF_INET, SOCK_RAW, IPPROTO_ICMP ); |
|||
if( sockfd < 0 ){ |
|||
LOG_ERROR("Socket file descriptor not received!"); |
|||
return false; |
|||
}; |
|||
|
|||
// set socket options at ip to TTL and value to 64,
|
|||
// change to what you want by setting ttl_val
|
|||
if( setsockopt( sockfd, SOL_IP, IP_TTL, &ttl_val, sizeof(ttl_val)) != 0 ){ |
|||
LOG_ERROR("Setting socket options to TTL failed!"); |
|||
shutdown( sockfd, SHUT_RDWR ); |
|||
close( sockfd ); |
|||
return false; |
|||
}; |
|||
|
|||
// setting timeout of recv setting
|
|||
setsockopt( sockfd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&tv_out, sizeof tv_out ); |
|||
|
|||
// flag is whether packet was sent or not
|
|||
flag=1; |
|||
|
|||
//filling packet
|
|||
bzero(&pckt, sizeof(pckt)); |
|||
|
|||
pckt.hdr.type = ICMP_ECHO; |
|||
pckt.hdr.un.echo.id = getpid(); |
|||
|
|||
for ( i = 0; i < sizeof(pckt.msg)-1; i++ ) pckt.msg[i] = i+'0'; |
|||
|
|||
pckt.msg[i] = 0; |
|||
pckt.hdr.un.echo.sequence = msg_count++; |
|||
pckt.hdr.checksum = checksumPing( &pckt, sizeof(pckt)); //checksum(&pckt, sizeof(pckt));
|
|||
|
|||
|
|||
//SLEEP( 300 );
|
|||
|
|||
//send packet
|
|||
if( sendto( sockfd, &pckt, sizeof(pckt), 0, (struct sockaddr*)&ping_addr, sizeof(ping_addr)) <= 0 ){ |
|||
LOG_ERROR("Packet Sending Failed!"); |
|||
shutdown( sockfd, SHUT_RDWR ); |
|||
close( sockfd ); |
|||
return false; |
|||
}; |
|||
|
|||
//receive packet
|
|||
socklen_t addr_len = sizeof(r_addr); |
|||
|
|||
if( recvfrom( sockfd, &pckt, sizeof(pckt), 0, (struct sockaddr*)&r_addr, &addr_len) <= 0 ){ |
|||
LOG_ERROR("Packet receive failed!"); |
|||
shutdown( sockfd, SHUT_RDWR ); |
|||
close( sockfd ); |
|||
return false; |
|||
} else { |
|||
#ifdef DEBUG_EXTRA
|
|||
LOG("Device Is OK!"); |
|||
#endif
|
|||
RetVal = true; |
|||
}; |
|||
shutdown( sockfd, SHUT_RDWR ); |
|||
close( sockfd ); |
|||
}; |
|||
return RetVal; |
|||
}; |
|||
|
|||
bool ARGUS_ETH2UART::create_SOL(){ |
|||
|
|||
/*
|
|||
if( m_sUartData.mode == SOL_NOT_DEFINED ) { |
|||
LOG_ERROR("No Connection Type Defined!"); |
|||
return false; |
|||
}; |
|||
*/ |
|||
if( m_sUartData.port == 0 ) { |
|||
LOG_ERROR("No Port Defined!"); |
|||
return false; |
|||
}; |
|||
if( m_sUartData.speed == 0 ){ |
|||
LOG_ERROR("No Speed Defined!"); |
|||
return false; |
|||
}; |
|||
if( m_sUartData.path[0] == (char)0 ) { |
|||
LOG_ERROR("No Adress Defined!"); |
|||
return false; |
|||
}; |
|||
|
|||
switch( m_sUartData.mode ) { |
|||
case SOL_UDP_CLIENT:{ |
|||
#ifdef DEBUG
|
|||
LOG("PORT IS CLIENT - Create UDP Server"); |
|||
#endif
|
|||
#ifdef __linux__
|
|||
// Creating socket file descriptor
|
|||
if ( (m_iDeviceFD = socket( AF_INET, SOCK_DGRAM, 0 )) < 0 ) { |
|||
LOG_ERROR("UDP Socket Creation Failed!"); |
|||
return false; |
|||
}; |
|||
fcntl( m_iDeviceFD, F_SETFL, O_NONBLOCK); |
|||
// Filling server information
|
|||
struct sockaddr_in tServerAddr; |
|||
memset( &tServerAddr, 0, sizeof(tServerAddr) ); |
|||
tServerAddr.sin_family = AF_INET; // IPv4
|
|||
tServerAddr.sin_addr.s_addr = INADDR_ANY; |
|||
tServerAddr.sin_port = htons( m_sUartData.port ); |
|||
|
|||
// Bind the socket with the server address
|
|||
if ( bind( m_iDeviceFD, (const struct sockaddr *)&tServerAddr, sizeof(tServerAddr)) < 0 ){ |
|||
LOG_ERROR("UDP Bind Failed"); |
|||
return false; |
|||
}; |
|||
#else
|
|||
WSADATA wsaData; |
|||
// Initialize Winsock version 2.2
|
|||
char tBuff[128]; |
|||
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) { |
|||
sprintf(tBuff, "WSAStartup failed with error %ld", WSAGetLastError()); |
|||
LOG_ERROR(tBuff); |
|||
return false; |
|||
} else { |
|||
sprintf(tBuff, "The Winsock DLL status is %s.", wsaData.szSystemStatus); |
|||
LOG(tBuff); |
|||
}; |
|||
// Set up a SOCKADDR_IN structure that will tell bind that we
|
|||
// want to receive datagrams from all interfaces using port 5150.
|
|||
// The IPv4 family
|
|||
ReceiverAddr.sin_family = AF_INET; |
|||
// Port no. 5150
|
|||
ReceiverAddr.sin_port = htons( m_nPort ); |
|||
// From all interface (0.0.0.0)
|
|||
ReceiverAddr.sin_addr.s_addr = htonl(INADDR_ANY); |
|||
// Associate the address information with the socket using bind.
|
|||
// At this point you can receive datagrams on your bound socket.
|
|||
if( bind(m_sSocket, (SOCKADDR*)&ReceiverAddr, sizeof(ReceiverAddr)) == SOCKET_ERROR ){ |
|||
sprintf( tBuff, "Server: bind() failed!Error : %ld.", WSAGetLastError()); |
|||
// Close the socket
|
|||
closesocket(m_sSocket); |
|||
// Do the clean up
|
|||
WSACleanup(); |
|||
// and exit with error
|
|||
LOG_ERROR(tBuff); |
|||
return false; |
|||
} else { |
|||
LOG("UDP Server: bind() is OK!"); |
|||
}; |
|||
// Some info on the receiver side...
|
|||
SOCKADDR_IN tAddr; |
|||
int tLen = sizeof(SOCKADDR_IN); |
|||
getsockname(m_sSocket, (SOCKADDR*)&tAddr, &tLen); |
|||
sprintf( tBuff, "Receiving IP(s) used : %s", inet_ntoa(tAddr.sin_addr)); |
|||
LOG(tBuff); |
|||
sprintf(tBuff,"Receiving port used : %d", htons(tAddr.sin_port)); |
|||
LOG(tBuff); |
|||
SelectTiming = recvfromTimeOutUDP(m_sSocket, 10, 0); |
|||
#endif
|
|||
break; |
|||
}; |
|||
case SOL_TCP_CLIENT:{ |
|||
#ifdef DEBUG
|
|||
LOG("PORT IS CLIENT - Create TCP Server"); |
|||
#endif
|
|||
break; |
|||
}; |
|||
case SOL_UDP_SERVER:{ |
|||
#ifdef DEBUG
|
|||
LOG("PORT IS SERVER - Create UDP Client"); |
|||
#endif
|
|||
#ifdef __linux__
|
|||
// Creating socket file descriptor
|
|||
if ( (m_iDeviceFD = socket( AF_INET, SOCK_DGRAM, 0)) < 0 ) { |
|||
LOG_ERROR("Socket Creation Failed!"); |
|||
return false; |
|||
}; |
|||
fcntl( m_iDeviceFD, F_SETFL, O_NONBLOCK ); |
|||
|
|||
// Filling server information
|
|||
struct sockaddr_in tServerAddr; |
|||
memset( &tServerAddr, 0, sizeof(tServerAddr) ); |
|||
tServerAddr.sin_family = AF_INET; |
|||
tServerAddr.sin_addr.s_addr = INADDR_ANY; |
|||
tServerAddr.sin_port = htons( m_sUartData.port ); |
|||
#else
|
|||
|
|||
#endif
|
|||
break; |
|||
}; |
|||
case SOL_TCP_SERVER:{ |
|||
#ifdef DEBUG
|
|||
LOG("PORT IS SERVER - Create TCP Client"); |
|||
#endif
|
|||
|
|||
// socket create and varification
|
|||
m_iDeviceFD = socket( AF_INET, SOCK_STREAM, 0 ); |
|||
if( m_iDeviceFD == -1) { |
|||
LOG_ERROR("Socket creation failed!"); |
|||
return false; |
|||
} |
|||
#ifdef DEBUG
|
|||
else LOG("Socket successfully created"); |
|||
#endif
|
|||
|
|||
|
|||
// assign IP, PORT
|
|||
struct sockaddr_in tServerAddr; |
|||
memset( &tServerAddr, 0, sizeof(tServerAddr) ); |
|||
tServerAddr.sin_family = AF_INET; |
|||
tServerAddr.sin_addr.s_addr = inet_addr( m_sUartData.path ); |
|||
tServerAddr.sin_port = htons( m_sUartData.port ); |
|||
|
|||
// connect the client socket to server socket
|
|||
if( connect( m_iDeviceFD, (struct sockaddr *)&tServerAddr, sizeof(tServerAddr) ) !=0 ){ |
|||
char cBuffer[128]; |
|||
sprintf(cBuffer,"ERROR connect to [%s:%d] (%s)", m_sUartData.path, m_sUartData.port, strerror(errno) ); |
|||
LOG_ERROR( cBuffer ); |
|||
return false; |
|||
} |
|||
#ifdef DEBUG
|
|||
else LOG("Connected to the server"); |
|||
#endif
|
|||
|
|||
// Set non-blocking
|
|||
int arg; |
|||
if( (arg = fcntl( m_iDeviceFD, F_GETFL, NULL)) < 0) { |
|||
char tBuf[128]; |
|||
sprintf( tBuf, "Error fcntl(..., F_GETFL) (%s)", strerror(errno)); |
|||
LOG_ERROR( tBuf ); |
|||
return false; |
|||
}; |
|||
arg |= O_NONBLOCK; |
|||
if( fcntl( m_iDeviceFD, F_SETFL, arg) < 0) { |
|||
char tBuf[128]; |
|||
sprintf( tBuf, "Error fcntl(..., F_SETFL) (%s)", strerror(errno)); |
|||
LOG_ERROR( tBuf ); |
|||
return false; |
|||
}; |
|||
setConnectionStatus( CS_CONNECTED ); |
|||
break; |
|||
}; |
|||
}; |
|||
return init(); |
|||
}; |
|||
|
|||
bool ARGUS_ETH2UART::closePort(){ |
|||
char tBuff[128]; |
|||
|
|||
setConnectionStatus( CS_DISCONNECTED ); |
|||
|
|||
if( m_bThreadAStatus != TH_PRE_INIT && m_bThreadBStatus != TH_PRE_INIT ){ |
|||
uninit(); |
|||
}; |
|||
if( m_iDeviceFD != -1 ) { |
|||
switch( m_sUartData.mode ) { |
|||
case SOL_UDP_CLIENT: |
|||
case SOL_TCP_CLIENT: |
|||
case SOL_UDP_SERVER: { |
|||
#ifdef __linux__
|
|||
close( m_iDeviceFD ); |
|||
#else
|
|||
// When your application is finished receiving datagrams close the socket.
|
|||
LOG("Server: Finished receiving.Closing the listening socket..."); |
|||
if( closesocket(m_sSocket) != 0 ){ |
|||
sprintf(tBuff, "closesocket() failed!Error code : %ld", WSAGetLastError()); |
|||
LOG_ERROR(tBuff); |
|||
} else { |
|||
LOG("closesocket() is OK..."); |
|||
}; |
|||
// When your application is finished call WSACleanup.
|
|||
LOG("Server: Cleaning up..."); |
|||
if (WSACleanup() != 0) { |
|||
sprintf(tBuff, "WSACleanup() failed!Error code : %ld", WSAGetLastError()); |
|||
LOG_ERROR(tBuff); |
|||
} else { |
|||
LOG("WSACleanup() is OK"); |
|||
}; |
|||
#endif
|
|||
break; |
|||
}; |
|||
case SOL_TCP_SERVER:{ |
|||
close( m_iDeviceFD ); |
|||
break; |
|||
}; |
|||
}; |
|||
m_iDeviceFD = -1; |
|||
}; |
|||
return true; |
|||
}; |
|||
|
|||
void ARGUS_ETH2UART::m_fThreadAProc(void){ |
|||
int index; |
|||
int RetVal; |
|||
m_bThreadAStatus = TH_WORKING; |
|||
#ifdef DEBUG
|
|||
LOG("Sender Thread Started!"); |
|||
#endif
|
|||
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 ){ |
|||
setConnectionStatus( CS_DISCONNECTED ); |
|||
m_nOutputBufferSize = 0; |
|||
m_bThreadBStatus = TH_ENDED; |
|||
m_bThreadAStatus = TH_ENDED; |
|||
LOG_ERROR("Connection Droped on Sending Data"); |
|||
}; |
|||
}; |
|||
m_nOutputBufferSize = 0; |
|||
m_mBufferProtectorMutex.unlock(); |
|||
} else { |
|||
m_mBufferProtectorMutex.unlock(); |
|||
SLEEP(5); |
|||
}; |
|||
}; |
|||
}; |
|||
|
|||
void ARGUS_ETH2UART::m_fThreadBProc(void){ |
|||
m_bThreadBStatus = TH_WORKING; |
|||
int RetVal; |
|||
#ifdef DEBUG
|
|||
LOG("Recipient Thread Started!"); |
|||
#endif
|
|||
while( m_bThreadBStatus < TH_ENDED ){ |
|||
RetVal = recptBlock( m_pInputBuffer, &m_nInputBufferSize); |
|||
if( RetVal == -1 ){ |
|||
setConnectionStatus(CS_DISCONNECTED); |
|||
m_nInputBufferSize = 0; |
|||
//if(!getStatus()) {
|
|||
m_bThreadBStatus = TH_ENDED; |
|||
m_bThreadAStatus = TH_ENDED; |
|||
//} else SLEEP(100);
|
|||
LOG_ERROR("Connection Droped on Reception Data"); |
|||
} else if( m_nInputBufferSize > 0 ){ |
|||
do{ |
|||
m_mQueueProtectorMutex.lock(); |
|||
if( m_vParsers.size() ){ |
|||
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 { |
|||
m_nInputBufferSize = 0; |
|||
m_mQueueProtectorMutex.unlock(); |
|||
#ifdef DEBUG_EXTRA
|
|||
LOG_ERROR("Try to parse data but No Parsers Assigned!"); |
|||
#endif
|
|||
SLEEP(100); |
|||
}; |
|||
} while( ( m_vParsers.size() == 0 ) && ( m_bThreadBStatus < TH_ENDED ) && ( m_bThreadBStatus < TH_ENDED ) ); |
|||
} else { |
|||
SLEEP(5); |
|||
}; |
|||
}; |
|||
}; |
|||
|
|||
bool ARGUS_ETH2UART::sendData( uint8_t *Data, int DataSize ){ |
|||
if( m_bThreadAStatus != TH_WORKING ) { |
|||
if( m_bThreadAStatus < TH_WORKING ) { |
|||
LOG_ERROR("Trying to Send Data Before Thread is Started!"); |
|||
} else { |
|||
LOG_ERROR("Trying to Send Data After Thread is Dead!"); |
|||
} |
|||
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; |
|||
}; |
|||
|
|||
bool ARGUS_ETH2UART::reconnect( void ){ |
|||
closePort(); |
|||
m_bValid = create_SOL(); |
|||
return m_bValid; |
|||
}; |
|||
|
|||
int ARGUS_ETH2UART::recptBlock( unsigned char *Buffer, int *BufferLength ){ |
|||
|
|||
#ifdef __linux__
|
|||
int RetVal = 0; |
|||
#else
|
|||
DWORD RetVal = 0; |
|||
#endif
|
|||
|
|||
if( m_eConnectionStatus == CS_CONNECTED ){ |
|||
#ifdef __linux__
|
|||
if( m_iDeviceFD > -1 ) { |
|||
struct sockaddr ClientAddress; |
|||
socklen_t addr_len = sizeof( ClientAddress ); //len is value/resuslt
|
|||
//RetVal = recvfrom( m_nSocketFD, (char *)Buffer, MAXIMAL_SOCKET_PACKET_LENGTH, MSG_WAITALL, ( struct sockaddr *) &m_sClientAddr, &addr_len );
|
|||
RetVal = recvfrom( m_iDeviceFD, (char *)Buffer, MAXIMAL_SOCKET_PACKET_LENGTH, MSG_DONTWAIT, ( struct sockaddr *) &ClientAddress, &addr_len ); |
|||
if( RetVal < 1 ){ |
|||
if( errno!=EAGAIN && errno!=EINTR ) { |
|||
LOG_ERROR("Peer Closes Connection!"); |
|||
shutdown( m_iDeviceFD, 2 ); |
|||
close( m_iDeviceFD ); |
|||
*BufferLength = 0; |
|||
m_iDeviceFD = -1; |
|||
setConnectionStatus( CS_DISCONNECTED ); |
|||
return -1; |
|||
}; |
|||
}; |
|||
|
|||
} else { |
|||
LOG_ERROR("Not Connected!"); |
|||
*BufferLength = 0; |
|||
setConnectionStatus( CS_DISCONNECTED ); |
|||
return -1; |
|||
}; |
|||
#else
|
|||
switch ( m_eType ) { |
|||
case SOL_UDP_CLIENT: |
|||
case SOL_TCP_CLIENT: |
|||
case SOL_UDP_SERVER: { |
|||
SOCKADDR_IN tAddr; |
|||
int tLen = sizeof(SOCKADDR_IN); |
|||
RetVal = recvfrom( m_sSocket, (char*)Buffer, MAXIMAL_SOCKET_PACKET_LENGTH, 0, (struct sockaddr*) &tAddr, &tLen); |
|||
if (RetVal == SOCKET_ERROR){ |
|||
char cBuffer[165]; |
|||
sprintf(cBuffer,"recvfrom() failed with error code : %d", WSAGetLastError()); |
|||
LOG_ERROR(cBuffer); |
|||
}; |
|||
break; |
|||
}; |
|||
}; |
|||
#endif
|
|||
} else { |
|||
//make prep for connection SOL_TCP_SERVER
|
|||
if( m_sUartData.mode == SOL_TCP_CLIENT ){ |
|||
//ACCEPT
|
|||
struct sockaddr ClientAddress; |
|||
socklen_t size = (socklen_t) sizeof( struct sockaddr_in ); |
|||
//int ClientSocket;
|
|||
m_iDeviceFD = accept( m_iMasterFD, &ClientAddress, &size ); |
|||
if( m_iDeviceFD < 0 ) { |
|||
setConnectionStatus( CS_DISCONNECTED ); |
|||
LOG_ERROR("Connection Accept Failure!"); |
|||
}; |
|||
} else { |
|||
LOG_ERROR("RCPT ON not connected!"); |
|||
shutdown( m_iDeviceFD, 2 ); |
|||
close( m_iDeviceFD ); |
|||
*BufferLength = 0; |
|||
m_iDeviceFD = -1; |
|||
setConnectionStatus( CS_DISCONNECTED ); |
|||
}; |
|||
return -1; // Exit after unsuccess reconnect
|
|||
}; |
|||
|
|||
if( RetVal > 0 ){ |
|||
#ifdef DEBUG_SERIAL_COMMUNICATION
|
|||
char MsgBuffer[CLOG]; |
|||
if( RetVal > 1 || RetVal == 0 ) { |
|||
sprintf( MsgBuffer, "Received %d bytes", RetVal ); |
|||
} else { |
|||
sprintf( MsgBuffer, "Received 1 byte"); |
|||
}; |
|||
LOG( MsgBuffer ); |
|||
for (int i = 0; i < RetVal; i++) { |
|||
sprintf(MsgBuffer, "0x%02X", Buffer[i]); |
|||
LOG(MsgBuffer); |
|||
}; |
|||
#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; |
|||
}; |
|||
|
|||
int ARGUS_ETH2UART::sendBlock(unsigned char* Data, int DataSize) { |
|||
#ifdef __linux__
|
|||
int RetVal = 0; |
|||
#else
|
|||
DWORD RetVal = 0; |
|||
#endif
|
|||
|
|||
if( m_eConnectionStatus == CS_CONNECTED ){ |
|||
#ifdef __linux__
|
|||
if( m_iDeviceFD > -1 ){ |
|||
|
|||
#ifdef DEBUG_EXTRA
|
|||
char cBuffer[256]; |
|||
sprintf(cBuffer, "Write into Port %d bytes", DataSize); |
|||
LOG(cBuffer); |
|||
#endif
|
|||
struct sockaddr ClientAddress; |
|||
socklen_t addr_len = sizeof(ClientAddress); |
|||
RetVal = sendto( m_iDeviceFD, (const char*)Data, DataSize, MSG_CONFIRM, (const struct sockaddr*) &ClientAddress, addr_len); |
|||
|
|||
if ((RetVal == -1) && (errno != EINTR) && (errno != EWOULDBLOCK)) { |
|||
LOG_ERROR("Error acures while writing data into the Socket"); |
|||
shutdown( m_iDeviceFD, 2); |
|||
close( m_iDeviceFD); |
|||
m_iDeviceFD = -1; |
|||
setConnectionStatus(CS_DISCONNECTED); |
|||
return -1; |
|||
}; |
|||
|
|||
if (RetVal < 0) RetVal = 0; |
|||
|
|||
#ifdef DEBUG_EXTRA
|
|||
sprintf(cBuffer, "Bytes Sent: %ld", RetVal); |
|||
LOG(cBuffer); |
|||
#ifdef DEBUG_SERIAL_COMMUNICATION
|
|||
for(int zz=0; zz < RetVal; zz++ ) { |
|||
sprintf(cBuffer, "SD: 0x%02X", (uint8_t)Data[zz]); |
|||
LOG(cBuffer); |
|||
}; |
|||
#endif
|
|||
#endif
|
|||
|
|||
} else { |
|||
LOG_ERROR("Not Connected!"); |
|||
//m_bConnected = false;
|
|||
setConnectionStatus(CS_DISCONNECTED); |
|||
return -1; |
|||
}; |
|||
#else // Windows
|
|||
if (sendto( m_sSocket, (char *)Data, DataSize, 0, (struct sockaddr*) &ReceiverAddr, sizeof(ReceiverAddr)) == SOCKET_ERROR) { |
|||
char cBuffer[256]; |
|||
sprintf(cBuffer, "sendto() failed with error code : %d", WSAGetLastError()); |
|||
LOG_ERROR( cBuffer ); |
|||
return -1; |
|||
}; |
|||
#endif
|
|||
} else { |
|||
#ifdef DEBUG
|
|||
LOG( "Port is not Ready to Send" ); |
|||
#endif
|
|||
return -1; |
|||
}; |
|||
return RetVal; |
|||
}; |
|||
|
|||
|
|||
#undef LOG_ERROR
|
|||
#undef LOG
|
|||
@ -0,0 +1,55 @@ |
|||
#ifndef __ARGUS_NODE_ETHERNET2SERIAL_HEADER__ |
|||
#define __ARGUS_NODE_ETHERNET2SERIAL_HEADER__ |
|||
|
|||
#include "rgooseNode.h" |
|||
#include "rgooseHardwareResource.h" |
|||
#include "../components/base/basicTransport.h" |
|||
#include "../components/base/basicDualThread.h" |
|||
|
|||
#ifndef MAXIMAL_SOCKET_PACKET_LENGTH |
|||
#define MAXIMAL_SOCKET_PACKET_LENGTH 102400 |
|||
#endif |
|||
|
|||
#ifndef MAXIMAL_SERIAL_PACKET_LENGTH |
|||
#define MAXIMAL_SERIAL_PACKET_LENGTH MAXIMAL_SOCKET_PACKET_LENGTH |
|||
#endif |
|||
|
|||
class ARGUS_ETH2UART: public argusNetNode, public argusHardwareResource, public basicTransport, public basicDualThread{ |
|||
private: |
|||
basicLogCollection * m_pLog; |
|||
DBC_UART_DATA m_sUartData; |
|||
|
|||
int m_iDeviceFD; |
|||
int m_iMasterFD; |
|||
#ifdef __linux__ |
|||
int m_iInFID; |
|||
int m_iOutFID; |
|||
#else |
|||
DCB PortDCB; |
|||
HANDLE m_ioFID; |
|||
#endif |
|||
bool pingDevice(); |
|||
bool create_SOL(); |
|||
bool closePort(); |
|||
int sendBlock(unsigned char *Data, int DataSize); |
|||
int recptBlock(unsigned char *Buffer, int *BufferLength); |
|||
protected: |
|||
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); |
|||
public: |
|||
explicit ARGUS_ETH2UART( uint32_t nodeID ); |
|||
~ARGUS_ETH2UART(); |
|||
virtual bool create( void ); |
|||
virtual bool validate( void ); |
|||
virtual bool sendData( uint8_t *Data, int DataSize ); |
|||
virtual bool reconnect( void ); |
|||
}; |
|||
|
|||
|
|||
#endif |
|||
|
|||
@ -0,0 +1,429 @@ |
|||
#include "rgooseNodeSensor.h"
|
|||
#include <opencv2/opencv.hpp>
|
|||
|
|||
#define LOG( X ) m_pLog->Log( "NODSEN", this, X )
|
|||
#define LOG_ERROR( X ) m_pLog->Log( "NODSEN", this, _LOG_ERROR, X )
|
|||
|
|||
argusNodeSensor::argusNodeSensor( uint32_t id ):argusNetNode( id ),m_oPosition(){ |
|||
m_pLog = basicLogCollection::getInstance(); |
|||
m_pTargetFilter = NULL; |
|||
}; |
|||
|
|||
argusNodeSensor::argusNodeSensor( DBC_NODE_DATA *Data ):argusNetNode( Data ),m_oPosition(){ |
|||
m_pLog = basicLogCollection::getInstance(); |
|||
m_pTargetFilter = NULL; |
|||
}; |
|||
|
|||
|
|||
argusNodeSensor::~argusNodeSensor(){ |
|||
|
|||
}; |
|||
|
|||
#define SKIP_LINE_PIXELS 28
|
|||
#define HEIGHT 512
|
|||
#define WIDTH 1024
|
|||
// scale factor -> 4/9
|
|||
|
|||
bool argusNodeSensor::handleDeviceDraw( uint8_t kID, void *th_data, size_t th_size, bool byMinimum ){ |
|||
LOG("TRY SAVE"); |
|||
if( th_data == NULL ) return false; |
|||
if( th_size == 0 ) return false; |
|||
if( m_pDBC == NULL ) return false; |
|||
LOG("SAVE"); |
|||
CSTR old = m_pDBC->getLRFDraw( getNodeID() ); |
|||
if ( old ) { |
|||
// delete old draw
|
|||
LOG("DELETE OLD DRAW"); |
|||
char filename[256]; |
|||
sprintf( filename, "data/device_draws/%s_100.png", old ); |
|||
if( fileExist( filename ) ){ |
|||
unlink( filename ); |
|||
}; |
|||
sprintf( filename, "data/device_draws/%s_map.png", old ); |
|||
if( fileExist( filename ) ){ |
|||
unlink( filename ); |
|||
}; |
|||
free(old); |
|||
} else { |
|||
LOG("NO OLD DRAW"); |
|||
} |
|||
CSTR uid = getUniqID_MD5(); |
|||
if( uid == NULL ) return false; |
|||
switch (getNodeType()) { |
|||
case ARGUS_ALS_SENSOR: |
|||
case ARGUS_LFS_SENSOR: |
|||
case ARGUS_PLS_200_SENSOR: |
|||
case ARGUS_PLS_360_SENSOR: |
|||
case ARGUS_NET_PLS_200:{ |
|||
|
|||
break; |
|||
}; |
|||
case ARGUS_3D_SENSOR:{ |
|||
char * emptyBG = "data/assets/images/empty_3d.png"; |
|||
thresholdNode * ptr = (thresholdNode *) th_data; |
|||
LOG("SAVE 3D DRAW!"); |
|||
if ( fileExist( emptyBG ) ) { |
|||
LOG("BG Exists"); |
|||
cv::Mat tImage = cv::imread( emptyBG, cv::IMREAD_UNCHANGED ); |
|||
if( tImage.rows != 512 || tImage.cols != 1024 ){ |
|||
LOG_ERROR( "Background Image wrong size (should be 1024x512)!" ); |
|||
free( uid ); |
|||
return false; |
|||
} else LOG("BG READ"); |
|||
|
|||
uint8_t * tMemory = tImage.data; |
|||
thresholdNode * cNode = NULL; |
|||
uint8_t * cPixel = NULL; |
|||
int pix = 0; |
|||
int mem = 0; |
|||
bool s_bit = false; |
|||
bool no_data = false; |
|||
float tVal; |
|||
bool master = ( kID < 16 ); |
|||
LOG("Start Draw "); |
|||
for( int idx = 0; idx < ( TH_SIZE_NODES << 2 ); idx++ ) { // tik-tak
|
|||
if( ( idx % 4 ) == 0 ){ |
|||
mem++; |
|||
if ( master ) { |
|||
cNode = ptr + TH_SIZE_NODES - mem - 1; |
|||
} else { |
|||
cNode = ptr + mem - 1; |
|||
}; |
|||
if( !s_bit ) s_bit = cNode->values.sbit; |
|||
if( !no_data ) no_data = ( cNode->values.cnt == 0 ); |
|||
if( !s_bit && !no_data ){ |
|||
if( byMinimum ) { |
|||
tVal = ((float)cNode->values.min) / 4096.f; |
|||
} else { |
|||
tVal = ((float)cNode->values.max) / 4096.f; |
|||
}; |
|||
}; |
|||
}; |
|||
if( ( idx % 9 ) == 0 ){ |
|||
if( mem > ( SKIP_LINE_PIXELS * TH_LINE_NODES ) ) { |
|||
cPixel = tMemory + (pix << 2); |
|||
pix++; |
|||
if( s_bit ) { // Set Red
|
|||
cPixel[0] = 0x00; cPixel[1] = 0x00; cPixel[2] = 0xff; cPixel[3] = 0xff; |
|||
} else { |
|||
if( no_data ) { // Set Blue
|
|||
cPixel[0] = 0xff; cPixel[1] = 0x00; cPixel[2] = 0x00; cPixel[3] = 0xff; |
|||
} else { |
|||
uint32_t tColor; |
|||
tColor = interpolate( 0x000000ff, 0xffffffff, tVal ); |
|||
cPixel[0] = ( tColor >> 24 ) & 0xFF; |
|||
cPixel[1] = ( tColor >> 16 ) & 0xFF; |
|||
cPixel[2] = ( tColor >> 8 ) & 0xFF; |
|||
cPixel[3] = tColor & 0xFF; |
|||
}; |
|||
}; |
|||
s_bit = false; |
|||
no_data = false; |
|||
}; |
|||
}; |
|||
}; |
|||
|
|||
char filename[256]; |
|||
sprintf( filename, "data/device_draws/%s_100.png", uid ); |
|||
//int RetVal = stbi_write_png( filename, 1024, 512, cSpace, tMemory, 1024 * cSpace );
|
|||
vector<int> compression_params; |
|||
compression_params.push_back( cv::IMWRITE_PNG_COMPRESSION ); |
|||
compression_params.push_back(9); |
|||
if(! cv::imwrite( filename, tImage, compression_params ) ){ |
|||
tImage.release(); |
|||
free( uid ); |
|||
return false; |
|||
}; |
|||
tImage.release(); |
|||
LOG("Draw Saved!"); |
|||
|
|||
cv::Mat tMap( Q_SCAN_COUNT, TH_LINE_NODES, CV_8UC4 ); |
|||
LOG("Map Creating"); |
|||
tMemory = tMap.data; |
|||
for( int j = 0; j < Q_SCAN_COUNT; j++ ){ |
|||
for( int i = 0; i < TH_LINE_NODES; i++ ){ |
|||
//cNode = ptr+(j*i);
|
|||
//cNode = &ptr[ ( TH_LINE_NODES * j ) + i ];
|
|||
int ids = 0; |
|||
int idd = 0; |
|||
if ( master ) { |
|||
//cNode = ptr+makeIds( i, j , true );
|
|||
//cPixel = tMemory+( cSpace * makeIds( i, j , false ));
|
|||
ids = makeIds( i, j , true ); |
|||
idd = 4 * makeIds( i, j , false ); |
|||
//cNode = ptr + ( i * j );
|
|||
//cPixel = tMemory + ( cSpace * i * j );
|
|||
} else { |
|||
//cNode = ptr+makeIds( i, j , false );
|
|||
//cPixel = tMemory+( cSpace * makeIds( i, j , false ));
|
|||
ids = makeIds( i, j , false ); |
|||
idd = 4 * makeIds( i, j , false ); |
|||
}; |
|||
|
|||
cNode = ptr + ids ; |
|||
cPixel = tMemory + idd; |
|||
|
|||
if( 0 ) { // Monochrome
|
|||
#ifdef CHECK_SUN_BIT
|
|||
if( cNode->values.sbit ) { |
|||
cPixel[0] = 0; |
|||
} else { |
|||
cPixel[0] = (uint8_t)((((float) cNode->values.min ) * 255.f ) / 4096.f ); |
|||
}; |
|||
#else
|
|||
cPixel[0] = (uint8_t)((((float) cNode->values.min ) * 255.f ) / 4096.f ); |
|||
#endif
|
|||
} else { |
|||
#ifdef CHECK_SUN_BIT
|
|||
if( cNode->values.sbit ) { |
|||
// Set Red
|
|||
cPixel[0] = 0x00; |
|||
cPixel[1] = 0x00; |
|||
cPixel[2] = 0xff; |
|||
cPixel[3] = 0xff; |
|||
} else { |
|||
if( cNode->values.cnt == 0 ) { |
|||
// Set Blue
|
|||
cPixel[0] = 0xff; |
|||
cPixel[1] = 0x00; |
|||
cPixel[2] = 0x00; |
|||
cPixel[3] = 0xff; |
|||
} else { |
|||
uint32_t tColor; |
|||
float tVal = ((float) cNode->values.min ) / 4096.f; |
|||
tColor = interpolate( 0x000000ff, 0xffffffff, tVal ); |
|||
cPixel[0] = ( tColor >> 24 ) & 0xFF; |
|||
cPixel[1] = ( tColor >> 16 ) & 0xFF; |
|||
cPixel[2] = ( tColor >> 8 ) & 0xFF; |
|||
cPixel[3] = tColor & 0xFF; |
|||
}; |
|||
}; |
|||
#else
|
|||
if( cNode->values.cnt == 0 ) { |
|||
// Set Blue
|
|||
cPixel[0] = 0xff; |
|||
cPixel[1] = 0x00; |
|||
cPixel[2] = 0x00; |
|||
cPixel[3] = 0xff; |
|||
} else { |
|||
uint32_t tColor; |
|||
float tVal = ((float) cNode->values.min ) / 4096.f; |
|||
tColor = interpolate( 0x000000ff, 0xffffffff, tVal ); |
|||
cPixel[0] = ( tColor >> 24 ) & 0xFF; |
|||
cPixel[1] = ( tColor >> 16 ) & 0xFF; |
|||
cPixel[2] = ( tColor >> 8 ) & 0xFF; |
|||
cPixel[3] = tColor & 0xFF; |
|||
}; |
|||
#endif
|
|||
}; |
|||
}; |
|||
}; |
|||
sprintf( filename, "data/device_draws/%s_map.png", uid ); |
|||
LOG(filename); |
|||
if(! cv::imwrite( filename, tMap, compression_params ) ){ |
|||
tMap.release(); |
|||
free( uid ); |
|||
return false; |
|||
}; |
|||
tMap.release(); |
|||
m_pDBC->addLRFDraw( getNodeID(), TH_SIZE_NODES, uid, kID, 1, true ); |
|||
} else { |
|||
LOG_ERROR( "Background Image is Missed!" ); |
|||
free( uid ); |
|||
return false; |
|||
}; |
|||
break; |
|||
}; |
|||
}; |
|||
free( uid ); |
|||
return true; |
|||
}; |
|||
|
|||
/*
|
|||
#define STB_IMAGE_IMPLEMENTATION
|
|||
#include "../data/stbi/stb_image.h"
|
|||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
|||
#include "../data/stbi/stb_image_write.h"
|
|||
#undef STB_IMAGE_WRITE_IMPLEMENTATION
|
|||
#undef STB_IMAGE_IMPLEMENTATION
|
|||
|
|||
|
|||
|
|||
bool argus3DLIDAR::saveTHPicture( thresholdNode *ptr, CSTR uid, bool master, bool byMinimum, bool monochrome ){ |
|||
uint8_t *tMemory = NULL; |
|||
thresholdNode *cNode = NULL; |
|||
uint8_t *cPixel = NULL; |
|||
int cSpace; |
|||
|
|||
|
|||
int x, y; |
|||
tMemory = stbi_load( "data/assets/images/empty_3d.png", &x, &y, &cSpace, STBI_default ); |
|||
|
|||
if( tMemory == NULL ){ |
|||
LOG_ERROR("Draw Memory Alloc Eror!"); |
|||
return false; |
|||
}; |
|||
|
|||
if( x != 1024 || y != 512 ){ |
|||
LOG("Wrong IMG Size!"); |
|||
free( tMemory ); |
|||
return NULL; |
|||
}; |
|||
|
|||
int pix = 0; |
|||
int mem = 0; |
|||
bool s_bit = false; |
|||
bool no_data = false; |
|||
float tVal; |
|||
|
|||
for ( int idx = 0; idx < ( TH_SIZE_NODES << 2 ); idx++ ) { // tik-tak
|
|||
|
|||
if( ( idx % 4 ) == 0 ){ |
|||
mem++; |
|||
if ( master ) { |
|||
cNode = ptr + TH_SIZE_NODES - mem - 1; |
|||
} else { |
|||
cNode = ptr + mem - 1; |
|||
}; |
|||
if( !s_bit ) s_bit = cNode->values.sbit; |
|||
if( !no_data ) no_data = ( cNode->values.cnt == 0 ); |
|||
if( !s_bit && !no_data ){ |
|||
if( byMinimum ) { |
|||
tVal = ((float)cNode->values.min) / 4096.f; |
|||
} else { |
|||
tVal = ((float)cNode->values.max) / 4096.f; |
|||
}; |
|||
}; |
|||
}; |
|||
|
|||
if( ( idx % 9 ) == 0 ){ |
|||
if( mem > ( SKIP_LINE_PIXELS * TH_LINE_NODES ) ) { |
|||
cPixel = tMemory + (pix << 2); |
|||
pix++; |
|||
if( s_bit ) { // Set Red
|
|||
cPixel[0] = 0x00; cPixel[1] = 0xff; cPixel[2] = 0x00; cPixel[3] = 0xff; |
|||
} else { |
|||
if( no_data ) { // Set Blue
|
|||
cPixel[0] = 0x00; cPixel[1] = 0x00; cPixel[2] = 0xff; cPixel[3] = 0xff; |
|||
} else { |
|||
uint32_t tColor; |
|||
tColor = interpolate( 0x000000ff, 0xffffffff, tVal ); |
|||
cPixel[0] = ( tColor >> 24 ) & 0xFF; |
|||
cPixel[1] = ( tColor >> 16 ) & 0xFF; |
|||
cPixel[2] = ( tColor >> 8 ) & 0xFF; |
|||
cPixel[3] = tColor & 0xFF; |
|||
}; |
|||
}; |
|||
s_bit = false; |
|||
no_data = false; |
|||
} |
|||
}; |
|||
}; |
|||
|
|||
char filename[256]; |
|||
sprintf( filename, "data/device_draws/%s_100.png", uid ); |
|||
int RetVal = stbi_write_png( filename, 1024, 512, cSpace, tMemory, 1024 * cSpace ); |
|||
free( tMemory ); |
|||
if( RetVal == 0 ) return false; |
|||
|
|||
if( monochrome ) { |
|||
cSpace = 1; |
|||
} else { |
|||
cSpace = 4; |
|||
}; |
|||
|
|||
tMemory = (uint8_t *) malloc( TH_SIZE_NODES * cSpace ); |
|||
if( tMemory == NULL ){ |
|||
LOG_ERROR("Map Memory Alloc Eror!"); |
|||
return false; |
|||
}; |
|||
|
|||
for (int j = 0; j < Q_SCAN_COUNT; j++) { |
|||
for ( int i = 0; i < TH_LINE_NODES; i++ ) { |
|||
//cNode = ptr+(j*i);
|
|||
//cNode = &ptr[ ( TH_LINE_NODES * j ) + i ];
|
|||
int ids = 0; |
|||
int idd = 0; |
|||
if ( master ) { |
|||
//cNode = ptr+makeIds( i, j , true );
|
|||
//cPixel = tMemory+( cSpace * makeIds( i, j , false ));
|
|||
ids = makeIds( i, j , true ); |
|||
idd = cSpace * makeIds( i, j , false ); |
|||
//cNode = ptr + ( i * j );
|
|||
//cPixel = tMemory + ( cSpace * i * j );
|
|||
} else { |
|||
//cNode = ptr+makeIds( i, j , false );
|
|||
//cPixel = tMemory+( cSpace * makeIds( i, j , false ));
|
|||
ids = makeIds( i, j , false ); |
|||
idd = cSpace * makeIds( i, j , false ); |
|||
}; |
|||
|
|||
cNode = ptr + ids ; |
|||
cPixel = tMemory + idd; |
|||
|
|||
if( monochrome ) { |
|||
#ifdef CHECK_SUN_BIT
|
|||
if( cNode->values.sbit ) { |
|||
cPixel[0] = 0; |
|||
} else { |
|||
cPixel[0] = (uint8_t)((((float) cNode->values.min ) * 255.f ) / 4096.f ); |
|||
}; |
|||
#else
|
|||
cPixel[0] = (uint8_t)((((float) cNode->values.min ) * 255.f ) / 4096.f ); |
|||
#endif
|
|||
} else { |
|||
#ifdef CHECK_SUN_BIT
|
|||
if( cNode->values.sbit ) { |
|||
// Set Red
|
|||
cPixel[0] = 0x00; |
|||
cPixel[1] = 0xff; |
|||
cPixel[2] = 0x00; |
|||
cPixel[3] = 0xff; |
|||
} else { |
|||
if( cNode->values.cnt == 0 ) { |
|||
// Set Blue
|
|||
cPixel[0] = 0x00; |
|||
cPixel[1] = 0x00; |
|||
cPixel[2] = 0xff; |
|||
cPixel[3] = 0xff; |
|||
} else { |
|||
uint32_t tColor; |
|||
float tVal = ((float) cNode->values.min ) / 4096.f; |
|||
tColor = interpolate( 0x000000ff, 0xffffffff, tVal ); |
|||
cPixel[0] = ( tColor >> 24 ) & 0xFF; |
|||
cPixel[1] = ( tColor >> 16 ) & 0xFF; |
|||
cPixel[2] = ( tColor >> 8 ) & 0xFF; |
|||
cPixel[3] = tColor & 0xFF; |
|||
}; |
|||
}; |
|||
#else
|
|||
if( cNode->values.cnt == 0 ) { |
|||
// Set Blue
|
|||
cPixel[0] = 0x00; |
|||
cPixel[1] = 0x00; |
|||
cPixel[2] = 0xff; |
|||
cPixel[3] = 0xff; |
|||
} else { |
|||
uint32_t tColor; |
|||
float tVal = ((float) cNode->values.min ) / 4096.f; |
|||
tColor = interpolate( 0x000000ff, 0xffffffff, tVal ); |
|||
cPixel[0] = ( tColor >> 24 ) & 0xFF; |
|||
cPixel[1] = ( tColor >> 16 ) & 0xFF; |
|||
cPixel[2] = ( tColor >> 8 ) & 0xFF; |
|||
cPixel[3] = tColor & 0xFF; |
|||
}; |
|||
#endif
|
|||
}; |
|||
}; |
|||
}; |
|||
|
|||
sprintf( filename, "data/device_draws/%s_map.png", uid ); |
|||
RetVal = stbi_write_png( filename, TH_LINE_NODES, Q_SCAN_COUNT, cSpace, tMemory, TH_LINE_NODES * cSpace ); |
|||
free( tMemory ); |
|||
if( RetVal == 0 ) return false; |
|||
return true; |
|||
}; |
|||
*/ |
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
@ -0,0 +1,69 @@ |
|||
#ifndef __ARGUS_NODE_SENSOR_HEADER__ |
|||
#define __ARGUS_NODE_SENSOR_HEADER__ |
|||
|
|||
#include "rgooseNode.h" |
|||
|
|||
#define ARGUS_LRF_PCMD_FULL_RESET 1 |
|||
#define ARGUS_LRF_PCMD_RESET 2 |
|||
#define ARGUS_LRF_PCMD_DRAW 3 |
|||
#define ARGUS_LRF_PCMD_GET_PROFILE 3 |
|||
|
|||
#define ARGUS_LRF_PCMD_SET_MASK_1 60 |
|||
#define ARGUS_LRF_PCMD_SET_MASK_2 61 |
|||
#define ARGUS_LRF_PCMD_SET_MASK_3 62 |
|||
#define ARGUS_LRF_PCMD_SET_MASK_4 63 |
|||
#define ARGUS_LRF_PCMD_SET_MASK_5 64 |
|||
|
|||
#define ARGUS_LRF_PCMD_MASK_1_ON 65 |
|||
#define ARGUS_LRF_PCMD_MASK_2_ON 66 |
|||
#define ARGUS_LRF_PCMD_MASK_3_ON 67 |
|||
#define ARGUS_LRF_PCMD_MASK_4_ON 68 |
|||
#define ARGUS_LRF_PCMD_MASK_5_ON 69 |
|||
|
|||
#define ARGUS_LRF_PCMD_MASK_1_OFF 70 |
|||
#define ARGUS_LRF_PCMD_MASK_2_OFF 71 |
|||
#define ARGUS_LRF_PCMD_MASK_3_OFF 72 |
|||
#define ARGUS_LRF_PCMD_MASK_4_OFF 73 |
|||
#define ARGUS_LRF_PCMD_MASK_5_OFF 74 |
|||
|
|||
#define ARGUS_LRF_PCMD_CLEAN_MASK_1 75 |
|||
#define ARGUS_LRF_PCMD_CLEAN_MASK_2 76 |
|||
#define ARGUS_LRF_PCMD_CLEAN_MASK_3 77 |
|||
#define ARGUS_LRF_PCMD_CLEAN_MASK_4 78 |
|||
#define ARGUS_LRF_PCMD_CLEAN_MASK_5 79 |
|||
|
|||
#define ARGUS_LRF_PCMD_SET_DP_0 100 |
|||
#define ARGUS_LRF_PCMD_SET_DP_1 101 |
|||
#define ARGUS_LRF_PCMD_SET_DP_2 102 |
|||
#define ARGUS_LRF_PCMD_SET_DP_3 103 |
|||
#define ARGUS_LRF_PCMD_UPLOAD_FILE 120 |
|||
|
|||
#define ARGUS_LRF_PCMD_UPDATE_ALL 255 |
|||
|
|||
|
|||
|
|||
|
|||
#define NODE_CMD_RESET_STUDY 230 |
|||
#define NODE_CMD_FULL_RESET 235 |
|||
#define NODE_CMD_UPLOAD_SHADOW 234 |
|||
#define NODE_CMD_UPLOAD_FILE 240 |
|||
#define NODE_CMD_GET_DEVICE_DRAW 100 |
|||
|
|||
class argusNodeSensor: public argusNetNode{ |
|||
private: |
|||
basicLogCollection * m_pLog; |
|||
protected: |
|||
basicPosition m_oPosition; |
|||
ARGUS_TARGET_FILTER * m_pTargetFilter; |
|||
bool handleDeviceDraw( uint8_t kID, void *th_data, size_t th_size, bool byMinimum = true ); |
|||
public: |
|||
explicit argusNodeSensor( uint32_t id ); |
|||
explicit argusNodeSensor( DBC_NODE_DATA *Data ); |
|||
virtual ~argusNodeSensor(); |
|||
virtual void simulateTarget( void ){}; |
|||
}; |
|||
|
|||
|
|||
|
|||
#endif |
|||
|
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue