diff --git a/Projects/argus/argus.vpj b/Projects/argus/argus.vpj
index fca335cd..31cb6037 100644
--- a/Projects/argus/argus.vpj
+++ b/Projects/argus/argus.vpj
@@ -26,7 +26,7 @@
RunFromDir="%rw">
+ OtherOptions="-std=c++11 -Wno-write-strings -I../../lib/include -I/usr/local/include/liveMedia `pkg-config opencv4 libavcodec libavdevice libavfilter libavformat libavutil libpostproc libswresample libswscale --cflags`"/>
+
+
+
+
+ OtherOptions="-std=c++11 -Wno-write-strings -I../../lib/include -I/usr/local/include/liveMedia `pkg-config opencv4 libavcodec libavdevice libavfilter libavformat libavutil libpostproc libswresample libswscale --cflags`"/>
+
+
+
+
@@ -362,6 +370,7 @@
+
+
a ){
+ return a + (rand() *( b - a )) / RAND_MAX;
+ };
+ return b + ( rand() * ( a - b )) / RAND_MAX;
+};
+
CSTR getUniqID_UUID( uint32_t SEED ){
/*
char buf[46];
diff --git a/lib/components/base/basicFunctionality.h b/lib/components/base/basicFunctionality.h
index ba212b29..e9c3eed5 100644
--- a/lib/components/base/basicFunctionality.h
+++ b/lib/components/base/basicFunctionality.h
@@ -53,6 +53,9 @@ CArray * explode( char Delim, CSTR S_Str );
CSTR implode( CArray *Data, CSTR S_Str, U8 Start, U8 End );
CSTR getTStr( CSTR Fmt = NULL );
CSTR getUniqID_SHA256(void);
+
+int rand( int a, int b );
+
CSTR getUniqID_MD5(void);
CSTR getUniqID_UUID( uint32_t SEED = 0);
CSTR strReplace( CSTR orig, CSTR rep, CSTR with );
diff --git a/lib/components/base/basicLIBAV.h b/lib/components/base/basicLIBAV.h
index e7488f21..9db65bab 100644
--- a/lib/components/base/basicLIBAV.h
+++ b/lib/components/base/basicLIBAV.h
@@ -20,8 +20,6 @@
#include "basicTypes.h"
#include "basicLogCollection.h"
-
-
#ifdef __linux__
#ifndef UINT64_C
diff --git a/lib/components/base/basicMediaSource.h b/lib/components/base/basicMediaSource.h
index a76d7cb8..7c2a84ea 100644
--- a/lib/components/base/basicMediaSource.h
+++ b/lib/components/base/basicMediaSource.h
@@ -26,6 +26,8 @@ class basicMediaSource {
};
bool isAttached( void ) { return ( m_pMediaDestination != NULL ); };
void setStreaming(bool T){ m_bStreamingSource = T; };
+ virtual bool _open( CSTR URI, bool ShowDeviceMenu = false, float framerate=-1.0f, int inputPin = -1, int width = -1, int height = -1 , int s_width=-1, int s_height=-1 ){ return false; };
+ virtual bool _close( void ){ return true; };
virtual bool _stop(void){ return true; };
MediaStateStatus getStatus( void ){ return m_eMediaStatus;};
};
diff --git a/lib/components/base/basicPosition.h b/lib/components/base/basicPosition.h
index dd42caf7..c78d2641 100644
--- a/lib/components/base/basicPosition.h
+++ b/lib/components/base/basicPosition.h
@@ -68,8 +68,10 @@ class basicPosition: public position3D{
S_TRANS_MATRIX m_sMatrix;
transform_3 *m_pTransform;
int m_nZoneID;
- void updateMatrix( void );
+
public:
+ void updateMatrix( void );
+
// Constructor
basicPosition();
diff --git a/lib/components/object/objectSystemAnchor.cpp b/lib/components/object/objectSystemAnchor.cpp
index c98cb617..db216121 100644
--- a/lib/components/object/objectSystemAnchor.cpp
+++ b/lib/components/object/objectSystemAnchor.cpp
@@ -202,11 +202,24 @@ bool systemAnchor::convertToLocal(basicPosition *SP, C3D_WGS84_LOC POS, C3D_SPH_
C3D_DECART tDec;
vector_3 A, B;
tDec.z = POS.alt;
+#ifdef DEBUG
+ char tB[256];
+ sprintf(tB, "Global WGS: %.3f %.3f %.3f", POS.lat, POS.lon, POS.alt );
+ LOG( tB );
+#endif
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();
+#ifdef DEBUG
+ sprintf( tB, "Global Decart: %.3f %.3f %.3f", A[0], A[1], A[2] );
+ LOG( tB );
+#endif
pTF->get_vector_local( A, B );
+#ifdef DEBUG
+ sprintf( tB, "Local Decart: %.3f %.3f %.3f", B[0], B[1], B[2] );
+ LOG( tB );
+#endif
tDec.x = B[0];
tDec.y = B[1];
tDec.z = B[2];
@@ -219,23 +232,38 @@ bool systemAnchor::convertToLocal( basicPosition *SP, C3D_DECART POS, C3D_SPH_DE
transform_3* pTF = SP->getTransform();
C3D_DECART tDec;
vector_3 A, B;
+#ifdef DEBUG
+ char tB[256];
+ sprintf(tB, "System Decart: %.3f %.3f %.3f", POS.x, POS.y, POS.z );
+ LOG( tB );
+#endif
// 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();
+ 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] = POS.x + getX();
+ A[1] = POS.y + getY();
+ A[2] = POS.z + getZ();
};
+#ifdef DEBUG
+ sprintf(tB, "Prepared Global Decart: %.3f %.3f %.3f", A[0], A[1], A[2] );
+ LOG( tB );
+#endif
//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];
+ tDec.x = B[0] + getX() - SP->getX();
+ tDec.y = B[1] + getY() - SP->getY();
+ tDec.z = B[2] + getZ() - SP->getZ();
+#ifdef DEBUG
+ sprintf(tB, "Local Decart: %.3f %.3f %.3f", B[0], B[1], B[2] );
+ LOG( tB );
+ sprintf(tB, "Local Decart: %.3f %.3f %.3f", tDec.x, tDec.y, tDec.z );
+ LOG( tB );
+#endif
decart2spherical(tDec, LOC);
return true;
};
@@ -277,27 +305,27 @@ bool systemAnchor::convertToSystem(basicPosition *SP, C3D_SPH_DEGREES POS, C3D_D
A[0] = tDec.x;
A[1] = tDec.y;
A[2] = tDec.z;
-#ifdef DEBUG_EXTRA
+#ifdef DEBUG
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
+#ifdef DEBUG
sprintf( tB, "World Decart: %.3f %.3f %.3f", B[0], B[1], B[2] );
LOG( tB );
#endif
-#ifdef DEBUG_EXTRA
+#ifdef DEBUG
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
+ 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
sprintf( tB, "Final System Decart: %.3f %.3f %.3f", LOC.x, LOC.y, LOC.z );
LOG( tB );
#endif
@@ -314,9 +342,12 @@ bool systemAnchor::convertToSystem(basicPosition *SP, C3D_SPH_RADIANS POS, C3D_D
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();
+ //LOC.x = B[0] + SP->getX() - getX();
+ LOC.x = B[0] - getX();
+ //LOC.y = B[1] + SP->getY() - getY();
+ LOC.y = B[1] - getY();
+ //LOC.z = B[2] + SP->getZ() - getZ();
+ LOC.z = B[2] - getZ();
return true;
};
@@ -330,9 +361,12 @@ bool systemAnchor::convertToGlobal(basicPosition *SP, C3D_SPH_DEGREES POS, C3D_W
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();
+ //tDec.x = B[0] + SP->getX();
+ tDec.x = B[0] + SP->getX() - getX();
+ //tDec.y = B[1] + SP->getY();
+ tDec.y = B[1] + SP->getY() - getY();
+ //tDec.z = B[2] + SP->getZ();
+ tDec.z = B[2] + SP->getZ() - getZ();
m_SCC.UTMXYToLatLon( tDec.x, tDec.y, getUTMZone(), m_bSouthHemisphere, LOC.lat, LOC.lon);
LOC.alt = tDec.z;
return true;
@@ -348,9 +382,12 @@ bool systemAnchor::convertToGlobal(basicPosition *SP, C3D_SPH_RADIANS POS, C3D_W
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();
+ //tDec.x = B[0] + SP->getX();
+ tDec.x = B[0] + SP->getX() - getX();
+ //tDec.y = B[1] + SP->getY();
+ tDec.y = B[1] + SP->getY() - getY();
+ //tDec.z = B[2] + SP->getZ();
+ tDec.z = B[2] + SP->getZ() - getZ();
m_SCC.UTMXYToLatLon(tDec.x, tDec.y, getUTMZone(), m_bSouthHemisphere, LOC.lat, LOC.lon);
LOC.alt = tDec.z;
return true;
diff --git a/lib/data/curl/curlRequest.cpp b/lib/data/curl/curlRequest.cpp
index 3359b542..51d51766 100644
--- a/lib/data/curl/curlRequest.cpp
+++ b/lib/data/curl/curlRequest.cpp
@@ -146,22 +146,30 @@ void curlRequest::init_CURL(){
};
};
-void curlRequest::setCredentials( CSTR user, CSTR password, bool use_digest ){
+void curlRequest::setCredentials( CSTR user, CSTR password, uint8_t AuthMode ){
if( !strlen(user) || !strlen(password) ) return;
sprintf(m_cUserPassword, "%s:%s", user, password );
curl_easy_setopt( m_pCURL, CURLOPT_USERPWD, m_cUserPassword );
- if( use_digest ) {
- curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST );
- } else {
- curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );
+ switch ( AuthMode ) {
+ case 0: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ); break;
+ case 1: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST ); break;
+ case 2: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST_IE ); break;
+ case 3: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_BEARER ); break;
+ case 4: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_NEGOTIATE ); break;
+ case 5: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_NTLM ); break;
+ case 6: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_NTLM_WB ); break;
+ case 7: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_ANY ); break;
+ case 8: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE ); break;
+ case 9: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_ONLY ); break;
+ //case 10: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_AWS_SIGV4 ); break;
};
};
static char *EmptyExpectConstant = (CSTR)"Expect:";
static char *EmptyAcceptConstant = (CSTR)"Accept: */*";
static char *AcceptEncoding = (CSTR)"Accept-Encoding: gzip, deflate";
-void curlRequest::setPOST( CSTR postDATA, int size ){
- if( m_pCURL != NULL ){
+void curlRequest::setPOST( CSTR postDATA, int size ){
+ if( m_pCURL != NULL ){
if( !postDATA ){
#ifdef DEBUG
LOG_ERROR("No Post Data Supplied In Post Request!");
@@ -169,13 +177,13 @@ void curlRequest::setPOST( CSTR postDATA, int size ){
return;
};
if( !size ) size = strlen( postDATA );
- m_pPostData = (CSTR) malloc( size+1 );
+ m_pPostData = (CSTR) malloc( size+1 );
if( !m_pPostData ){
LOG_ERROR("Memory Allocation Error!");
return;
};
- memcpy( m_pPostData, postDATA, size );
- m_pPostData[size] = (char)0;
+ memcpy( m_pPostData, postDATA, size );
+ m_pPostData[size] = (char)0;
sprintf( m_cContentLength, "Content-Length: %d", size );
m_HeaderList = curl_slist_append( m_HeaderList, EmptyExpectConstant );
m_HeaderList = curl_slist_append( m_HeaderList, EmptyAcceptConstant );
@@ -183,9 +191,9 @@ void curlRequest::setPOST( CSTR postDATA, int size ){
m_HeaderList = curl_slist_append( m_HeaderList, m_cContentLength );
curl_easy_setopt( m_pCURL, CURLOPT_HTTPHEADER, m_HeaderList );
curl_easy_setopt( m_pCURL, CURLOPT_POST, 1 );
- curl_easy_setopt( m_pCURL, CURLOPT_POSTFIELDS, m_pPostData );
+ curl_easy_setopt( m_pCURL, CURLOPT_POSTFIELDS, m_pPostData );
} else LOG_ERROR("Wrong CURL handle!");
-};
+};
void curlRequest::setHandler(void *baseObject, void *(*start_routine) (void *, void*), void* ptr ){
#ifdef DEBUG_EXTRA
diff --git a/lib/data/curl/curlRequest.h b/lib/data/curl/curlRequest.h
index e69b20a3..0be0246f 100644
--- a/lib/data/curl/curlRequest.h
+++ b/lib/data/curl/curlRequest.h
@@ -52,7 +52,7 @@ class curlRequest{
size_t getSize(void){ return m_nMemorySize; };
CSTR getURL(void){ return m_pURL; };
void setHandler(void *baseObject, void *(*start_routine) (void *, void*), void *ptr );
- void setCredentials( CSTR user, CSTR password, bool use_digest = true );
+ void setCredentials( CSTR user, CSTR password, uint8_t AuthMode = 0 );
void setPOST( CSTR postDATA , int size = 0 );
void issue(void);
bool isFinished(void){ return m_bRequestComplete; };
diff --git a/lib/data/media/video/videoAVLIBSource.cpp b/lib/data/media/video/videoAVLIBSource.cpp
index 2992fbed..972fe6be 100644
--- a/lib/data/media/video/videoAVLIBSource.cpp
+++ b/lib/data/media/video/videoAVLIBSource.cpp
@@ -25,8 +25,7 @@ videoAVLIBSource::videoAVLIBSource( void *opaque ): basicMediaSource(), basicThr
m_pLog = basicLogCollection::getInstance();
m_bStreamingSource = true;
m_bSizeIsAutomatic = false;
- m_nWidth = 640;
- m_nHeight = 480;
+ m_nOutWidth = m_nInWidth = m_nOutHeight = m_nInHeight = -1;
m_bSrcType = AVLIB_SOURCE_NOTDEF;
if( opaque ) {
m_pOpaque = opaque;
@@ -62,8 +61,7 @@ videoAVLIBSource::videoAVLIBSource( char *Source, void *opaque ) : basicMediaSou
m_pLog = basicLogCollection::getInstance();
m_bStreamingSource = true;
m_bSizeIsAutomatic = false;
- m_nWidth = 640;
- m_nHeight = 480;
+ m_nOutWidth = m_nInWidth = m_nOutHeight = m_nInHeight = -1;
m_bSrcType = AVLIB_SOURCE_NOTDEF;
if( opaque ) {
m_pOpaque = opaque;
@@ -122,13 +120,13 @@ videoAVLIBSource::~videoAVLIBSource(){
};
};
-bool videoAVLIBSource::setSize( int Width, int Height ){
+bool videoAVLIBSource::setOutputSize( int Width, int Height ){
if( m_pVideoState ){
if( m_pVideoState->m_bStatus == MS_INIT ) {
if( Width && Height ) {
m_bSizeIsAutomatic = false;
- m_nWidth = Width;
- m_nHeight = Height;
+ m_nOutWidth = Width;
+ m_nOutHeight = Height;
return true;
};
};
@@ -141,7 +139,7 @@ bool videoAVLIBSource::setProportionalByWidth(int Width){
if( m_pVideoState->m_bStatus == MS_INIT ) {
if( Width > 0 ) {
m_bSizeIsAutomatic = true;
- m_nWidth = Width;
+ m_nOutWidth = Width;
return true;
};
};
@@ -154,7 +152,7 @@ bool videoAVLIBSource::setProportionalByHeight(int Height){
if( m_pVideoState->m_bStatus == MS_INIT ) {
if( Height > 0 ) {
m_bSizeIsAutomatic = true;
- m_nHeight = Height;
+ m_nOutHeight = Height;
return true;
};
};
@@ -201,7 +199,7 @@ bool videoAVLIBSource::_stop(void){
};
//https://www.youtube.com/watch?v=Lu3LZmhC_DY
-bool videoAVLIBSource::_open(char *URI, bool ShowDeviceMenu, float framerate, int inputPin, int width, int height, bool scaled, int s_width, int s_height ){
+bool videoAVLIBSource::_open(char *URI, bool ShowDeviceMenu, float framerate, int inputPin, int width, int height, int s_width, int s_height ){
if (m_pVideoState == NULL) return false;
if (m_bThreadStatus > TH_PRE_INIT ) return false;
if (m_pVideoState->m_bStatus == MS_INIT) {
@@ -300,6 +298,20 @@ bool videoAVLIBSource::_open(char *URI, bool ShowDeviceMenu, float framerate, in
av_dict_set(&m_pVideoState->m_pFormatOpts, "rtsp_transport", "tcp", 0);
av_dict_set(&m_pVideoState->m_pFormatOpts, "stimeout", "5000000", 0);
av_dict_set(&m_pVideoState->m_pFormatOpts, "buffer_size", "1024000", 0);
+
+/*
+ av_dict_set_int(&opts, "rw_timeout", 5000000, 0);
+ av_dict_set_int(&opts, "tcp_nodelay", 1, 0);
+ av_dict_set_int(&opts, "stimeout", 10000000, 0);
+ av_dict_set(&opts, "user_agent", "Mozilla/5.0", 0);
+ av_dict_set(&opts, "rtsp_transport", "tcp", 0);
+ av_dict_set(&opts, "rtsp_flags", "prefer_tcp", 0);
+ av_dict_set_int(&opts, "buffer_size", BUFSIZE, 0);
+
+ pFormatCtx->flags |= AVFMT_FLAG_NONBLOCK;
+ pFormatCtx->flags |= AVFMT_FLAG_DISCARD_CORRUPT;
+ pFormatCtx->flags |= AVFMT_FLAG_NOBUFFER;
+*/
} else {
#ifdef DEBUG
LOG("Linux Video Device");
@@ -331,7 +343,7 @@ bool videoAVLIBSource::_open(char *URI, bool ShowDeviceMenu, float framerate, in
//av_dict_set(&options, "timeout", "8000", 0);
int RetVal = 0;
strncpy( m_pVideoState->m_pFileName, URI, MAX_PATH_LEN );
- LOG("Before Open1");
+ //LOG("Before Open1");
if( ( RetVal = avformat_open_input(&m_pVideoState->m_pFormatCtx, m_pVideoState->m_pFileName, NULL, &m_pVideoState->m_pFormatOpts) ) != 0 ){
//av_dict_free(&options);
char tBuffer[1024];
@@ -340,7 +352,7 @@ bool videoAVLIBSource::_open(char *URI, bool ShowDeviceMenu, float framerate, in
LOG_ERROR(Buffer);
return false;
};
- LOG("After Open1");
+ //LOG("After Open1");
AVDictionaryEntry *e;
if( e = av_dict_get( m_pVideoState->m_pFormatOpts, "", NULL, AV_DICT_IGNORE_SUFFIX )){
sprintf(Buffer, "Option %s not recognized by the demuxer", e->key);
@@ -398,7 +410,7 @@ bool videoAVLIBSource::_open(char *URI, bool ShowDeviceMenu, float framerate, in
//m_pVideoState->m_pFormatCtx->streams[m_pVideoState->m_iVideoStreamID]->codecpar->codec_id
m_pVideoState->m_pVideoCodec = avcodec_find_decoder( m_pVideoState->m_pCodecCtx->codec_id );
#else
-# ifdef DEBUG
+# ifdef DEBUG_EXTRA
LOG("YABABA-2!");
# endif
/* find the video stream information */
@@ -442,7 +454,7 @@ bool videoAVLIBSource::_open(char *URI, bool ShowDeviceMenu, float framerate, in
*/
//m_pVideoState->m_pCodecCtx->thread_count = 2;
//m_pVideoState->m_pCodecCtx->thread_type = FF_THREAD_FRAME;
-#ifdef DEBUG
+#ifdef DEBUG_EXTRA
LOG("Before Open2");
#endif
if( avcodec_open2( m_pVideoState->m_pCodecCtx, m_pVideoState->m_pVideoCodec, NULL ) < 0 ){
@@ -467,58 +479,56 @@ bool videoAVLIBSource::_open(char *URI, bool ShowDeviceMenu, float framerate, in
return false;
};
#endif
-#ifdef DEBUG
+#ifdef DEBUG_EXTRA
char tB[256];
sprintf( tB, "Setting Frame [%dx%d]", m_nWidth, m_nHeight );
LOG( tB );
sprintf( tB, "Source Frame [%dx%d]", m_pVideoState->m_pCodecCtx->width, m_pVideoState->m_pCodecCtx->height );
LOG( tB );
#endif
- if( scaled ){
-#ifdef DEBUG
- LOG("Size is Scaled");
-#endif
- m_nWidth = s_width;
- m_nHeight = s_height;
+ if( ( s_width > 0 ) && ( s_height > 0 ) ){
+ m_nOutWidth = s_width;
+ m_nOutHeight = s_height;
} else {
if( m_bSizeIsAutomatic ){
-#ifdef DEBUG
+#ifdef DEBUG_EXTRA
LOG("Size is Automatic");
#endif
- if(( m_nWidth == -1 )&&( m_nHeight == -1 )){
- m_nWidth = m_pVideoState->m_pCodecCtx->width;
- m_nHeight = m_pVideoState->m_pCodecCtx->height;
+ if(( m_nOutWidth == -1 )&&( m_nOutHeight == -1 )){
+ m_nOutWidth = m_pVideoState->m_pCodecCtx->width;
+ m_nOutHeight = m_pVideoState->m_pCodecCtx->height;
} else {
// Proportional
- if( m_nHeight == -1 ){
+ if( m_nOutHeight == -1 ){
float k = ((float)m_pVideoState->m_pCodecCtx->height) / ((float)m_pVideoState->m_pCodecCtx->width);
- m_nHeight = (int)(((float)m_nWidth ) * k );
+ m_nOutHeight = (int)(((float)m_nOutWidth ) * k );
} else {
float k = ((float)m_pVideoState->m_pCodecCtx->width) / ((float)m_pVideoState->m_pCodecCtx->height);
- m_nWidth = (int)(((float)m_nHeight ) * k );
+ m_nOutWidth = (int)(((float)m_nOutHeight ) * k );
};
};
} else {
-#ifdef DEBUG
+#ifdef DEBUG_EXTRA
LOG("Size is Manual");
#endif
- if( width > 0 ){
- m_nWidth = width;
- };
- if( height > 0 ){
- m_nHeight = height;
+ if( ( width > 0 ) && ( height > 0 ) ){
+ m_nOutWidth = width;
+ m_nOutHeight = height;
+ } else {
+ m_nOutWidth = m_pVideoState->m_pCodecCtx->width;
+ m_nOutHeight = m_pVideoState->m_pCodecCtx->height;
};
};
};
-#ifdef DEBUG
- sprintf( tB, "Using Size [%dx%d]", m_nWidth, m_nHeight );
+#ifdef DEBUG_EXTRA
+ sprintf( tB, "Using Size [%dx%d]", m_nOutWidth, m_nOutHeight );
LOG( tB );
sprintf(tB,"swsPar: IN: %dx%d [%d] OUT: %dx%d [%d] {%d}", m_pVideoState->m_pCodecCtx->width,
m_pVideoState->m_pCodecCtx->height,
m_pVideoState->m_pCodecCtx->pix_fmt,
- m_nWidth,
- m_nHeight,
+ m_nOutWidth,
+ m_nOutHeight,
AV_PIX_FMT_BGR24,
SWS_BICUBIC );
LOG( tB );
@@ -527,8 +537,8 @@ bool videoAVLIBSource::_open(char *URI, bool ShowDeviceMenu, float framerate, in
m_pVideoState->m_pCodecCtx->width,
m_pVideoState->m_pCodecCtx->height,
m_pVideoState->m_pCodecCtx->pix_fmt,
- m_nWidth,
- m_nHeight,
+ m_nOutWidth,
+ m_nOutHeight,
AV_PIX_FMT_BGR24,
SWS_BICUBIC, //SWS_FAST_BILINEAR,// | SWS_ACCURATE_RND,//SWS_BILINEAR,//SWS_BICUBIC,
NULL,
@@ -540,7 +550,7 @@ bool videoAVLIBSource::_open(char *URI, bool ShowDeviceMenu, float framerate, in
LOG_ERROR("Error Allocating SwsCtx!");
return false;
};
-#ifdef DEBUG
+#ifdef DEBUG_EXTRA
LOG("Allocation Done->Start Thread!");
#endif
return init();
@@ -550,7 +560,7 @@ bool videoAVLIBSource::_open(char *URI, bool ShowDeviceMenu, float framerate, in
void videoAVLIBSource::m_fThreadProc( void ){
AVPacket * pPacket = NULL;
- cv::Mat mRGB( m_nHeight, m_nWidth, CV_8UC3, cv::Scalar( 255, 0, 255 ) );
+ cv::Mat mRGB( m_nOutHeight, m_nOutWidth, CV_8UC3, cv::Scalar( 255, 0, 255 ) );
AVFrame * pFrame = NULL;
AVFrame * pFrameBGR = NULL;
uint8_t * pBGRbuffer = NULL;
@@ -574,7 +584,7 @@ void videoAVLIBSource::m_fThreadProc( void ){
m_bThreadStatus = TH_ENDED;
LOG_ERROR("Error allocating BGR AVFrame!");
} else {
- dec_ret = av_image_alloc ( pFrameBGR->data, pFrameBGR->linesize, m_nWidth, m_nHeight, AV_PIX_FMT_BGR24, BUFFER_ALIGN );
+ dec_ret = av_image_alloc ( pFrameBGR->data, pFrameBGR->linesize, m_nOutWidth, m_nOutHeight, AV_PIX_FMT_BGR24, BUFFER_ALIGN );
sprintf( tB, "Allocated: %d bytes to Frame", dec_ret );
LOG( tB );
if ( dec_ret < 0 ) {
@@ -604,7 +614,7 @@ void videoAVLIBSource::m_fThreadProc( void ){
m_pVideoState->m_bStatus = MS_STOPED;
while( m_pMediaDestination == NULL && m_bThreadStatus == TH_WORKING ){
SLEEP(20);
-#ifdef DEBUG
+#ifdef DEBUG_EXTRA
LOG("Waiting Destination");
#endif
};
@@ -612,7 +622,7 @@ void videoAVLIBSource::m_fThreadProc( void ){
if( m_bSrcType == AVLIB_SOURCE_IPSTREAM ){
//av_read_play( m_pVideoState->m_pFormatCtx );
};
-#ifdef DEBUG
+#ifdef DEBUG_EXTRA
LOG("Presentation Started.");
#endif
while( m_pVideoState->m_bStatus < MS_CLOSING && m_bThreadStatus != TH_ENDED ){
@@ -653,7 +663,7 @@ void videoAVLIBSource::m_fThreadProc( void ){
try{
//sprintf( tB, "Try to copy %d[%dx%d] bytes to %d[%dx%d]", pFrameBGR->linesize[0] * m_nHeight, pFrameBGR->width, pFrameBGR->height, mRGB.total() * mRGB.elemSize(), mRGB.cols, mRGB.rows );
//LOG(tB);
- memcpy( mRGB.data, pFrameBGR->data[0], pFrameBGR->linesize[0] * m_nHeight );
+ memcpy( mRGB.data, pFrameBGR->data[0], pFrameBGR->linesize[0] * m_nOutHeight );
//LOG("13");
if(!m_pMediaDestination->pushFrame( mRGB, m_pOpaque )){
m_pMediaDestination = NULL;
diff --git a/lib/data/media/video/videoAVLIBSource.h b/lib/data/media/video/videoAVLIBSource.h
index 7c9d0637..be4d4dee 100644
--- a/lib/data/media/video/videoAVLIBSource.h
+++ b/lib/data/media/video/videoAVLIBSource.h
@@ -22,8 +22,10 @@ class videoAVLIBSource : public basicMediaSource, public basicThread {
void * m_pOpaque;
uint8_t m_bSrcType;
//uint8_t * m_pOut_buffer;
- int m_nWidth;
- int m_nHeight;
+ int m_nInWidth;
+ int m_nInHeight;
+ int m_nOutWidth;
+ int m_nOutHeight;
int m_iY_size;
#ifndef _NOAUDIO_
mediaBus * m_pAudioBus;
@@ -33,8 +35,8 @@ class videoAVLIBSource : public basicMediaSource, public basicThread {
protected:
void m_fThreadProc( void );
public:
- bool _open( CSTR URI, bool ShowDeviceMenu = false, float framerate=-1.f, int inputPin = -1, int width = -1, int height = -1 , bool scaled=false, int s_width=-1, int s_height=-1 );
- bool _close( void );
+ virtual bool _open( CSTR URI, bool ShowDeviceMenu = false, float framerate=-1.0f, int inputPin = -1, int width = -1, int height = -1 , int s_width=-1, int s_height=-1 );
+ virtual bool _close( void );
virtual bool _stop( void );
bool isFinished( void );
MediaStateStatus getStatus( void );
@@ -42,7 +44,7 @@ class videoAVLIBSource : public basicMediaSource, public basicThread {
videoAVLIBSource( CSTR URI, void *opaque=NULL );
//videoAVLIBSource( config_setting_t *CFG, void *opaque=NULL );
virtual ~videoAVLIBSource();
- bool setSize( int Width,
+ bool setOutputSize( int Width,
int Height );
bool setProportionalByWidth( int Width );
bool setProportionalByHeight( int Height );
diff --git a/lib/data/media/video/videoLive555AVLibSource.cpp b/lib/data/media/video/videoLive555AVLibSource.cpp
new file mode 100644
index 00000000..d438f613
--- /dev/null
+++ b/lib/data/media/video/videoLive555AVLibSource.cpp
@@ -0,0 +1,597 @@
+#include "videoLive555AVLibSource.h"
+
+
+
+StreamClientState::StreamClientState()
+ : iter(NULL), session(NULL), subsession(NULL), streamTimerTask(NULL), duration(0.0) {
+};
+
+StreamClientState::~StreamClientState() {
+ delete iter;
+ if( session != NULL ){
+ // We also need to delete "session", and unschedule "streamTimerTask" (if set)
+ UsageEnvironment& env = session->envir(); // alias
+
+ env.taskScheduler().unscheduleDelayedTask(streamTimerTask);
+ Medium::close(session);
+ };
+};
+
+
+CustomRTSPClient* CustomRTSPClient::createNew(
+ videoLIVE555Source *session,
+ UsageEnvironment& env,
+ char const* rtspURL,
+ int verbosityLevel,
+ char const* applicationName,
+ portNumBits tunnelOverHTTPPortNum) {
+ return new CustomRTSPClient(session, env, rtspURL, verbosityLevel, applicationName, tunnelOverHTTPPortNum);
+};
+
+CustomRTSPClient::CustomRTSPClient(
+ videoLIVE555Source *session,
+ UsageEnvironment& env,
+ char const* rtspURL,
+ int verbosityLevel,
+ char const* applicationName,
+ portNumBits tunnelOverHTTPPortNum)
+ : RTSPClient(env,rtspURL, verbosityLevel, applicationName, tunnelOverHTTPPortNum, -1) ,
+ session(session){
+};
+
+CustomRTSPClient::~CustomRTSPClient() {
+};
+
+#define LOG( X ) m_pLog->Log( "LIVE555_SIN", this, X )
+
+#define MLOG( X ) ME->m_pLog->Log( "LIVE555_SIN", ME, 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( "LIVE555_SIN", this, _LOG_ERROR, _tBfrErrMSG2w34 );\
+ }
+#else
+ #define LOG_ERROR( X ) m_pLog->Log( "LIVE555_SIN", this, _LOG_ERROR, X );
+#endif
+
+DummySink* DummySink::createNew( videoLIVE555Source* session, UsageEnvironment& env, MediaSubsession& subsession, char const* streamId, int w, int h, int ww, int hh ) {
+ return new DummySink( session, env, subsession, streamId, w, h, ww, hh );
+}
+
+DummySink::DummySink(videoLIVE555Source* session, UsageEnvironment& env, MediaSubsession& subsession, char const* streamId, int w, int h, int ww, int hh )
+ : MediaSink(env),
+ session(session),
+ frameIndex(0),
+ fSubsession(subsession) {
+ m_pLog = basicLogCollection::getInstance();
+ fStreamId = strDup(streamId);
+
+ m_nInWidth = w;
+ m_nInHeight = h;
+ m_nOutWidth = ww;
+ m_nOutHeight = hh;
+
+ fReceiveBuffer = new u_int8_t[DUMMY_SINK_RECEIVE_BUFFER_SIZE];
+ fReceiveBufferAV = new u_int8_t[DUMMY_SINK_RECEIVE_BUFFER_SIZE + 4];
+
+ fReceiveBufferAV[0] = 0;
+ fReceiveBufferAV[1] = 0;
+ fReceiveBufferAV[2] = 0;
+ fReceiveBufferAV[3] = 1;
+
+ av_init_packet(&avpkt);
+ avpkt.flags |= AV_PKT_FLAG_KEY;
+ avpkt.pts = avpkt.dts = 0;
+
+ memset(inbuf + INBUF_SIZE, 0, AV_INPUT_BUFFER_PADDING_SIZE);
+
+ LOG( subsession.codecName() );
+ m_eCodecProbe = AV_CODEC_ID_NONE;
+ if( strcmp(fSubsession.codecName(),"H264") == 0 ){
+ m_eCodecProbe = AV_CODEC_ID_H264;
+ };
+ if( strcmp(fSubsession.codecName(),"JPEG") == 0 ){
+ m_eCodecProbe = AV_CODEC_ID_MJPEG;
+ };
+ if( strcmp(fSubsession.codecName(),"H265") == 0 ){
+ m_eCodecProbe = AV_CODEC_ID_HEVC;
+ };
+
+ codec = avcodec_find_decoder( m_eCodecProbe );
+ if (!codec) {
+ LOG_ERROR( "codec not found!" );
+ };
+
+ codecContext = avcodec_alloc_context3(codec);
+ frame = av_frame_alloc();
+ rgbFrame = av_frame_alloc();
+ //avpicture_alloc( ( AVPicture *) rgbFrame, AV_PIX_FMT_RGB24, 1920, 1080);
+ avpicture_alloc( ( AVPicture *) rgbFrame, AV_PIX_FMT_BGR24, 1280, 720 );
+
+ if (codec->capabilities & AV_CODEC_CAP_TRUNCATED) {
+ codecContext->flags |= AV_CODEC_FLAG_TRUNCATED; // we do not send complete frames
+ }
+
+ if ( ( fSubsession.videoWidth() > 0 ) && ( fSubsession.videoHeight() > 0 ) ) {
+ m_nInWidth = fSubsession.videoWidth();
+ m_nInHeight = fSubsession.videoHeight();
+ };
+
+ codecContext->width = m_nInWidth;
+ codecContext->height = m_nInHeight;
+ codecContext->pix_fmt = AV_PIX_FMT_YUV420P;
+
+ if (avcodec_open2(codecContext,codec,NULL) < 0) {
+ LOG_ERROR( "could not open codec" );
+ }
+
+ //this->swsContext = sws_getContext( codecContext->width, codecContext->height, codecContext->pix_fmt, 1920, 1080, AV_PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL);
+ this->swsContext = sws_getContext( codecContext->width, codecContext->height, codecContext->pix_fmt, m_nOutWidth, m_nOutHeight, AV_PIX_FMT_BGR24, SWS_BICUBIC, NULL, NULL, NULL);
+ m_pRGB = new cv::Mat( m_nOutHeight, m_nOutWidth, CV_8UC3, cv::Scalar( 255, 0, 255 ) );
+ char tB[128];
+ sprintf( tB, "Created Sink [%dx%d]->[1280x720]", codecContext->width,codecContext->height );
+ LOG( tB );
+};
+
+DummySink::~DummySink() {
+ delete[] fReceiveBuffer;
+ delete [] fReceiveBufferAV;
+ delete[] fStreamId;
+}
+
+void DummySink::afterGettingFrame(void* clientData, unsigned frameSize, unsigned numTruncatedBytes, struct timeval presentationTime, unsigned durationInMicroseconds ) {
+ DummySink* sink = (DummySink*)clientData;
+ sink->afterGettingFrame(frameSize, numTruncatedBytes, presentationTime, durationInMicroseconds);
+};
+
+void DummySink::afterGettingFrame(unsigned frameSize, unsigned numTruncatedBytes, struct timeval presentationTime, unsigned /*durationInMicroseconds*/) {
+ // We've just received a frame of data. (Optionally) print out information about it:
+ //if (strcmp(fSubsession.codecName(),"H264") == 0) {
+ if( m_eCodecProbe != AV_CODEC_ID_NONE ) {
+ avpkt.data = fReceiveBufferAV;
+ avpkt.size = frameSize + 4;
+ memcpy (fReceiveBufferAV + 4, fReceiveBuffer, frameSize);
+ avpkt.data = fReceiveBufferAV;
+ len = avcodec_decode_video2 (codecContext, frame, &got_picture, &avpkt);
+ if (len < 0) {
+ //LOG_ERROR( "Error while decoding frame " );// << frameIndex << "\n";
+ } else if (got_picture) {
+ //envir() << "->Picture decoded :" << frameIndex << "\n";
+ //LOG( "Picture decoded" );
+ sws_scale( this->swsContext, this->frame->data,this->frame->linesize, 0, this->codecContext->height, this->rgbFrame->data, this->rgbFrame->linesize );
+ memcpy( m_pRGB->data, this->rgbFrame->data[0], this->rgbFrame->linesize[0] * m_nOutHeight );
+ this->session->consumeFrame( m_pRGB );
+ frameIndex ++;
+ };
+ } else{
+ LOG("Codec Not Handled!");
+ LOG( fSubsession.codecName() );
+ };
+ // Then continue, to request the next frame of data:
+ continuePlaying();
+}
+
+Boolean DummySink::continuePlaying() {
+ if (fSource == NULL) return False; // sanity check (should not happen)
+
+ // Request the next frame of data from our input source. "afterGettingFrame()" will get called later, when it arrives:
+ fSource->getNextFrame(fReceiveBuffer, DUMMY_SINK_RECEIVE_BUFFER_SIZE,
+ afterGettingFrame, this,
+ onSourceClosure, this);
+ return True;
+}
+
+void DummySink::setSprop(u_int8_t const* prop, unsigned size) {
+ uint8_t *buf;
+ uint8_t *buf_start;
+ buf = (uint8_t *)malloc(1000);
+ buf_start = buf + 4;
+
+ avpkt.data = buf;
+ avpkt.data[0] = 0;
+ avpkt.data[1] = 0;
+ avpkt.data[2] = 0;
+ avpkt.data[3] = 1;
+ memcpy (buf_start, prop, size);
+ avpkt.size = size + 4;
+ len = avcodec_decode_video2 (codecContext, frame, &got_picture, &avpkt);
+ if (len < 0) {
+ //envir() << "Error while decoding frame" << frame;
+ LOG_ERROR( "Error while decoding frame" );
+ // exit(6);
+ };
+
+ LOG( "after setSprop" );
+ // exit (111);
+};
+
+#undef LOG_ERROR
+#undef MLOG
+#undef LOG
+#define LOG( X ) m_pLog->Log( "LIVE555_SRC", this, X )
+#define MLOG( X ) ME->m_pLog->Log( "LIVE555_SRC", ME, 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( "LIVE555_SRC", this, _LOG_ERROR, _tBfrErrMSG2w34 );\
+ }
+#else
+ #define LOG_ERROR( X ) m_pLog->Log( "LIVE555_SRC", this, _LOG_ERROR, X );
+#endif
+
+videoLIVE555Source::videoLIVE555Source( void *opaque ):
+ m_pScheduler(BasicTaskScheduler::createNew()),
+ m_pUsageEnvironment(BasicUsageEnvironment::createNew(*m_pScheduler)),
+ basicMediaSource(),
+ //MediaSink(*m_pUsageEnvironment),
+ basicThread(),
+ m_pLog(basicLogCollection::getInstance()),
+ m_pOpaque(opaque){
+ m_nOutWidth = m_nInWidth = m_nOutHeight = m_nInHeight = -1;
+ if( !initLibAV() ) return;
+};
+
+videoLIVE555Source::videoLIVE555Source( CSTR URI, void *opaque ):
+ m_pScheduler(BasicTaskScheduler::createNew()),
+ m_pUsageEnvironment(BasicUsageEnvironment::createNew(*m_pScheduler)),
+ basicMediaSource(),
+ //MediaSink(*m_pUsageEnvironment),
+ basicThread(),
+ m_pLog(basicLogCollection::getInstance()),
+ m_pOpaque(opaque){
+ m_nOutWidth = m_nInWidth = m_nOutHeight = m_nInHeight = -1;
+ if( !initLibAV() ) return;
+ _open( URI );
+};
+
+videoLIVE555Source::~videoLIVE555Source(){
+ _stop();
+ //if ( m_pSink ) delete( m_pSink );
+};
+
+void videoLIVE555Source::m_fThreadProc( void ){
+ _eventLoopWatchVariable = 0;
+ m_pScheduler->doEventLoop( &_eventLoopWatchVariable );
+ LOG( "Rtsp event finished" );
+ m_pUsageEnvironment->reclaim();
+ m_pUsageEnvironment = NULL;
+ delete m_pScheduler;
+ m_pScheduler = NULL;
+};
+
+
+Boolean videoLIVE555Source::continuePlaying(){
+ return False;
+};
+
+void videoLIVE555Source::continueAfterDESCRIBE( RTSPClient* rtspClient, int resultCode, char* resultString){
+ CustomRTSPClient * MM = (CustomRTSPClient *) rtspClient;
+ videoLIVE555Source * ME = (videoLIVE555Source *) MM->getSession();
+ MLOG("After Describe EVT");
+ do {
+ UsageEnvironment& env = rtspClient->envir(); // alias
+ StreamClientState& scs = MM->getStreamClientState(); // alias
+
+ if (resultCode != 0) {
+ MLOG( "Failed to get a SDP description: ");
+ MLOG( resultString );
+ delete[] resultString;
+ break;
+ };
+
+ char* const sdpDescription = resultString;
+ MLOG( "Got a SDP description:" );
+ MLOG( sdpDescription );
+
+ // Create a media session object from this SDP description:
+ scs.session = MediaSession::createNew(env, sdpDescription);
+ delete[] sdpDescription; // because we don't need it anymore
+ if (scs.session == NULL) {
+ MLOG( "Failed to create a MediaSession object from the SDP description:" );
+ MLOG( env.getResultMsg() );
+ break;
+ } else if (!scs.session->hasSubsessions()) {
+ MLOG( "This session has no media subsessions (i.e., no \"m=\" lines)" );
+ break;
+ };
+
+ // Then, create and set up our data source objects for the session. We do this by iterating over the session's 'subsessions',
+ // calling "MediaSubsession::initiate()", and then sending a RTSP "SETUP" command, on each one.
+ // (Each 'subsession' will have its own data source.)
+ scs.iter = new MediaSubsessionIterator(*scs.session);
+ ME->setupNextSubsession(rtspClient);
+ return;
+ } while (0);
+ // An unrecoverable error occurred with this stream.
+ ME->shutdownStream( rtspClient );
+};
+
+void videoLIVE555Source::continueAfterSETUP( RTSPClient* rtspClient, int resultCode, char* resultString){
+ CustomRTSPClient * MM = (CustomRTSPClient *) rtspClient;
+ videoLIVE555Source * ME = (videoLIVE555Source *) MM->getSession();
+ MLOG("After Setup EVT");
+ do {
+ UsageEnvironment& env = rtspClient->envir(); // alias
+ StreamClientState& streamClientState = MM->getStreamClientState(); // alias
+ if( resultCode != 0 ){
+ MLOG( "Failed to set up the subsession:");
+ MLOG( streamClientState.subsession->mediumName() );
+ MLOG( streamClientState.subsession->codecName() );
+ MLOG( resultString );
+ break;
+ };
+
+ MLOG( "Set up the subsession" );
+ MLOG( streamClientState.subsession->mediumName() );
+ MLOG( streamClientState.subsession->codecName() );
+ if (streamClientState.subsession->rtcpIsMuxed()) {
+ char tB[128];
+ sprintf( tB, "client port %d", streamClientState.subsession->clientPortNum() );
+ MLOG( tB );
+ } else {
+ char tB[128];
+ sprintf( tB, "client ports %d-%d", streamClientState.subsession->clientPortNum(), streamClientState.subsession->clientPortNum()+1 );
+ MLOG( tB );
+ };
+
+ const char *sprop = streamClientState.subsession->fmtp_spropparametersets();
+ uint8_t const* sps = NULL;
+ unsigned spsSize = 0;
+ uint8_t const* pps = NULL;
+ unsigned ppsSize = 0;
+
+ if (sprop != NULL) {
+ unsigned numSPropRecords;
+ SPropRecord* sPropRecords = parseSPropParameterSets(sprop, numSPropRecords);
+ for (unsigned i = 0; i < numSPropRecords; ++i) {
+ if (sPropRecords[i].sPropLength == 0) continue; // bad data
+ u_int8_t nal_unit_type = (sPropRecords[i].sPropBytes[0])&0x1F;
+ if (nal_unit_type == 7/*SPS*/) {
+ sps = sPropRecords[i].sPropBytes;
+ spsSize = sPropRecords[i].sPropLength;
+ } else if (nal_unit_type == 8/*PPS*/) {
+ pps = sPropRecords[i].sPropBytes;
+ ppsSize = sPropRecords[i].sPropLength;
+ }
+ }
+ }
+
+ // Having successfully setup the subsession, create a data sink for it, and call "startPlaying()" on it.
+ // (This will prepare the data sink to receive data; the actual flow of data from the client won't start happening until later,
+ // after we've sent a RTSP "PLAY" command.)
+
+ streamClientState.subsession->sink = DummySink::createNew(ME, env, *streamClientState.subsession, rtspClient->url(), ME->m_nInWidth, ME->m_nInHeight, ME->m_nOutWidth, ME->m_nOutHeight );
+ // perhaps use your own custom "MediaSink" subclass instead
+ if (streamClientState.subsession->sink == NULL) {
+ MLOG( "Failed to create a data sink for the subsession" );
+ MLOG( streamClientState.subsession->mediumName() );
+ MLOG( streamClientState.subsession->codecName() );
+ MLOG( env.getResultMsg() );
+ break;
+ };
+
+ MLOG( "Created a data sink for the subsession" );
+ MLOG( streamClientState.subsession->mediumName() );
+ MLOG( streamClientState.subsession->codecName() );
+
+ streamClientState.subsession->miscPtr = rtspClient; // a hack to let subsession handler functions get the "RTSPClient" from the subsession
+
+
+ if (sps != NULL) {
+ ((DummySink *)streamClientState.subsession->sink)->setSprop(sps, spsSize);
+ }
+ if (pps != NULL) {
+ ((DummySink *)streamClientState.subsession->sink)->setSprop(pps, ppsSize);
+ }
+
+ streamClientState.subsession->sink->startPlaying(*(streamClientState.subsession->readSource()),
+ subsessionAfterPlaying, streamClientState.subsession);
+
+ // Also set a handler to be called if a RTCP "BYE" arrives for this subsession:
+ if (streamClientState.subsession->rtcpInstance() != NULL) {
+ streamClientState.subsession->rtcpInstance()->setByeHandler( subsessionByeHandler, streamClientState.subsession );
+ }
+
+ } while (0);
+ delete[] resultString;
+ // Set up the next subsession, if any:
+ ME->setupNextSubsession(rtspClient);
+};
+void videoLIVE555Source::continueAfterPLAY( RTSPClient* rtspClient, int resultCode, char* resultString){
+ Boolean success = False;
+ CustomRTSPClient * MM = (CustomRTSPClient *) rtspClient;
+ videoLIVE555Source * ME = (videoLIVE555Source *) MM->getSession();
+ MLOG("After Play EVT");
+ do {
+ UsageEnvironment& env = rtspClient->envir(); // alias
+ StreamClientState& scs = ((CustomRTSPClient*)rtspClient)->getStreamClientState(); // alias
+
+ if (resultCode != 0) {
+ MLOG( "Failed to start playing session: " );
+ MLOG( resultString );
+ break;
+ };
+
+ // Set a timer to be handled at the end of the stream's expected duration (if the stream does not already signal its end
+ // using a RTCP "BYE"). This is optional. If, instead, you want to keep the stream active - e.g., so you can later
+ // 'seek' back within it and do another RTSP "PLAY" - then you can omit this code.
+ // (Alternatively, if you don't want to receive the entire stream, you could set this timer for some shorter value.)
+ if (scs.duration > 0) {
+ unsigned const delaySlop = 2; // number of seconds extra to delay, after the stream's expected duration. (This is optional.)
+ scs.duration += delaySlop;
+ unsigned uSecsToDelay = (unsigned)(scs.duration*1000000);
+ scs.streamTimerTask = env.taskScheduler().scheduleDelayedTask(uSecsToDelay, (TaskFunc*)streamTimerHandler, rtspClient);
+ }
+
+ MLOG( "Started playing session" );
+ //if (scs.duration > 0) {
+ // env << " (for up to " << scs.duration << " seconds)";
+ // }
+
+ success = True;
+ } while (0);
+ delete[] resultString;
+
+ if (!success) {
+ // An unrecoverable error occurred with this stream.
+ ME->shutdownStream(rtspClient);
+ };
+};
+// Other event handler functions:
+// called when a stream's subsession (e.g., audio or video substream) ends
+void videoLIVE555Source::subsessionAfterPlaying( void* clientData ){
+ MediaSubsession* subsession = (MediaSubsession*)clientData;
+ RTSPClient* rtspClient = (RTSPClient*)(subsession->miscPtr);
+ CustomRTSPClient * MM = (CustomRTSPClient *) rtspClient;
+ videoLIVE555Source * ME = (videoLIVE555Source *) MM->getSession();
+ // Begin by closing this subsession's stream:
+ Medium::close(subsession->sink);
+ subsession->sink = NULL;
+
+ // Next, check whether *all* subsessions' streams have now been closed:
+ MediaSession& session = subsession->parentSession();
+ MediaSubsessionIterator iter(session);
+ while ((subsession = iter.next()) != NULL) {
+ if (subsession->sink != NULL) return; // this subsession is still active
+ }
+
+ // All subsessions' streams have now been closed, so shutdown the client:
+ ME->shutdownStream(rtspClient);
+};
+
+// called when a RTCP "BYE" is received for a subsession
+void videoLIVE555Source::subsessionByeHandler( void* clientData ){//, char const* reason ){
+ MediaSubsession* subsession = (MediaSubsession*)clientData;
+ RTSPClient* rtspClient = (RTSPClient*)subsession->miscPtr;
+ CustomRTSPClient * MM = (CustomRTSPClient *) rtspClient;
+ videoLIVE555Source * ME = (videoLIVE555Source *) MM->getSession();
+ UsageEnvironment& env = rtspClient->envir(); // alias
+
+ MLOG( "Received RTCP \"BYE\" on subsession" );
+ MLOG( subsession->mediumName() );
+ MLOG( subsession->codecName() );
+ // Now act as if the subsession had closed:
+ subsessionAfterPlaying(subsession);
+};
+
+void videoLIVE555Source::streamTimerHandler( void* clientData ){
+ CustomRTSPClient* rtspClient = (CustomRTSPClient*)clientData;
+ StreamClientState& scs = rtspClient->getStreamClientState(); // alias
+ videoLIVE555Source * ME = (videoLIVE555Source *) rtspClient->getSession();
+ scs.streamTimerTask = NULL;
+
+ // Shut down the stream:
+ ME->shutdownStream(rtspClient);
+};
+
+
+// The main streaming routine (for each "rtsp://" URL):
+void videoLIVE555Source::openURL(UsageEnvironment& env, char const* progName, char const* rtspURL){
+ LOG("openURL Called!");
+};
+// Used to iterate through each stream's 'subsessions', setting up each one:
+void videoLIVE555Source::setupNextSubsession(RTSPClient* rtspClient){
+ CustomRTSPClient * MM = (CustomRTSPClient *) rtspClient;
+ videoLIVE555Source * ME = (videoLIVE555Source *) MM->getSession();
+ MLOG("Next Subsession EVT");
+ UsageEnvironment& env = rtspClient->envir(); // alias
+ StreamClientState& scs = MM->getStreamClientState(); // alias
+
+ scs.subsession = scs.iter->next();
+ if (scs.subsession != NULL) {
+ if (!scs.subsession->initiate()) {
+ MLOG( "Failed to initiate the subsession:" );
+ MLOG( scs.subsession->mediumName() );
+ MLOG( scs.subsession->codecName() );
+ MLOG( env.getResultMsg() );
+ setupNextSubsession(rtspClient); // give up on this subsession; go to the next one
+ } else {
+ MLOG( "Initiated the subsession");
+ MLOG( scs.subsession->mediumName() );
+ MLOG( scs.subsession->codecName() );
+
+ if (scs.subsession->rtcpIsMuxed()) {
+ char tB[64];
+ sprintf( tB, "client port %d", scs.subsession->clientPortNum() );
+ MLOG( tB );
+ } else {
+ char tB[64];
+ sprintf( tB, "client ports %d-%d", scs.subsession->clientPortNum(), scs.subsession->clientPortNum()+1 );
+ MLOG( tB );
+ };
+ // Continue setting up this subsession, by sending a RTSP "SETUP" command:
+ rtspClient->sendSetupCommand(*scs.subsession, continueAfterSETUP, False, REQUEST_STREAMING_OVER_TCP);
+ }
+ return;
+ };
+
+ // We've finished setting up all of the subsessions. Now, send a RTSP "PLAY" command to start the streaming:
+ if (scs.session->absStartTime() != NULL) {
+ // Special case: The stream is indexed by 'absolute' time, so send an appropriate "PLAY" command:
+ rtspClient->sendPlayCommand(*scs.session, continueAfterPLAY, scs.session->absStartTime(), scs.session->absEndTime());
+ } else {
+ scs.duration = scs.session->playEndTime() - scs.session->playStartTime();
+ rtspClient->sendPlayCommand(*scs.session, continueAfterPLAY);
+ };
+};
+
+// Used to shut down and close a stream (including its "RTSPClient" object):
+void videoLIVE555Source::shutdownStream(RTSPClient* rtspClient, int exitCode ){
+ CustomRTSPClient * MM = (CustomRTSPClient *) rtspClient;
+ videoLIVE555Source * ME = (videoLIVE555Source *) MM->getSession();
+ MLOG("Shutdown EVT");
+};
+
+// https://chowdera.com/2021/01/20210102084512591N.html
+// https://github.com/drriguz/Kamera
+bool videoLIVE555Source::_open( CSTR URI, bool ShowDeviceMenu, float framerate, int inputPin, int width, int height, int s_width, int s_height ){
+
+ m_nInHeight = height;
+ m_nInWidth = width;
+ m_nOutHeight = s_height;
+ m_nOutWidth = s_width;
+
+ m_pRtspClient = CustomRTSPClient::createNew( this, *m_pUsageEnvironment, URI, RTSP_CLIENT_VERBOSITY_LEVEL, "ARGUS CLIENT" );
+ if( m_pRtspClient == NULL) {
+ char tB[256];
+ sprintf( tB, "Failed to create a RTSP client for URL \"%s\":%s", URI, m_pUsageEnvironment->getResultMsg() );
+ LOG_ERROR( tB );
+ return false;
+ };
+ m_pRtspClient->sendDescribeCommand(continueAfterDESCRIBE);
+ return init();
+};
+
+void videoLIVE555Source::consumeFrame( cv::Mat *frm ){
+ if ( m_pMediaDestination == NULL ) return;
+ if(!m_pMediaDestination->pushFrame( *frm, m_pOpaque )){
+ m_pMediaDestination = NULL;
+ };
+};
+
+bool videoLIVE555Source::_close( void ){
+ return _stop();
+};
+bool videoLIVE555Source::_stop( void ){
+ shutdownStream( m_pRtspClient );
+ _eventLoopWatchVariable = 1;
+ basicThread::waitThreadEnd( true );
+ return true;
+};
+bool videoLIVE555Source::isFinished( void ){ return false;};
+MediaStateStatus videoLIVE555Source::getStatus( void ){ return MS_UNDEFINED; };
+bool videoLIVE555Source::setSize( int Width, int Height ){ return false; };
+bool videoLIVE555Source::setProportionalByWidth( int Width ){ return false; };
+bool videoLIVE555Source::setProportionalByHeight( int Height ){ return false; };
+bool videoLIVE555Source::setFPS( int ){ return false; };
+bool videoLIVE555Source::setName( CSTR Name ){ return false; };
+bool videoLIVE555Source::setFrameAspectRatio( FrameAspectRatio AspectRatio ){ return false; };
+
+
+#undef MLOG
+#undef LOG
+#undef LOG_ERROR
+
diff --git a/lib/data/media/video/videoLive555AVLibSource.h b/lib/data/media/video/videoLive555AVLibSource.h
new file mode 100644
index 00000000..5b8759d7
--- /dev/null
+++ b/lib/data/media/video/videoLive555AVLibSource.h
@@ -0,0 +1,180 @@
+#ifndef __VIDEOLIVE555AVLIBSOURCE_H_INCL__
+#define __VIDEOLIVE555AVLIBSOURCE_H_INCL__
+
+#include "../../../components/base/basicLIBAV.h"
+#include "../../../components/base/basicMediaSource.h"
+#include "../../../components/base/basicSettings.h"
+#include "../../../components/base/basicThread.h"
+#include "../../../components/base/basicLogCollection.h"
+#include "../../../alg/generic/md5.h"
+
+#include
+#include
+
+#define RTSP_CLIENT_VERBOSITY_LEVEL 1
+#define INBUF_SIZE 40960
+#define AUDIO_INBUF_SIZE 20480
+#define AUDIO_REFILL_THRESH 4096
+#define DUMMY_SINK_RECEIVE_BUFFER_SIZE 400000
+#define REQUEST_STREAMING_OVER_TCP True
+
+class videoLIVE555Source;
+
+class StreamClientState{
+ public:
+ StreamClientState();
+ virtual ~StreamClientState();
+ public:
+ MediaSubsessionIterator * iter;
+ MediaSession * session;
+ MediaSubsession * subsession;
+ TaskToken streamTimerTask;
+ double duration;
+};
+
+
+class CustomRTSPClient: public RTSPClient {
+ private:
+ videoLIVE555Source * session;
+ StreamClientState streamClientState;
+ public:
+ static CustomRTSPClient * createNew(
+ videoLIVE555Source *session,
+ UsageEnvironment& env,
+ char const* rtspURL,
+ int verbosityLevel = 0,
+ char const* applicationName = NULL,
+ portNumBits tunnelOverHTTPPortNum = 0);
+
+ StreamClientState& getStreamClientState() { return this->streamClientState; }
+ videoLIVE555Source * getSession() { return this->session; }
+ protected:
+ CustomRTSPClient( videoLIVE555Source *session,
+ UsageEnvironment& env,
+ char const* rtspURL,
+ int verbosityLevel,
+ char const* applicationName,
+ portNumBits tunnelOverHTTPPortNum );
+ virtual ~CustomRTSPClient();
+};
+
+class DummySink: public MediaSink {
+ public:
+ static DummySink* createNew( videoLIVE555Source *session,
+ UsageEnvironment& env,
+ MediaSubsession& subsession, // identifies the kind of data that's being received
+ char const* streamId = NULL, int w = -1, int h = -1, int ww = -1, int hh = -1 ); // identifies the stream itself (optional)
+ virtual ~DummySink();
+ private:
+ basicLogCollection * m_pLog;
+ AVCodecID m_eCodecProbe;
+ cv::Mat * m_pRGB;
+
+ int m_nInWidth;
+ int m_nInHeight;
+ int m_nOutWidth;
+ int m_nOutHeight;
+
+ DummySink( videoLIVE555Source *session, UsageEnvironment& env, MediaSubsession& subsession, char const* streamId, int w, int h, int ww, int hh );
+ // called only by "createNew()"
+
+
+ static void afterGettingFrame(void* clientData, unsigned frameSize,
+ unsigned numTruncatedBytes,
+ struct timeval presentationTime,
+ unsigned durationInMicroseconds);
+ void afterGettingFrame(unsigned frameSize, unsigned numTruncatedBytes,
+ struct timeval presentationTime, unsigned durationInMicroseconds);
+ //void saveFrameToFile()
+ private:
+ // redefined virtual functions:
+ virtual Boolean continuePlaying();
+
+ public:
+ void setSprop(u_int8_t const* prop, unsigned size);
+ private:
+ videoLIVE555Source* session;
+ private:
+ u_int8_t* fReceiveBuffer;
+ u_int8_t* fReceiveBufferAV;
+ MediaSubsession& fSubsession;
+ char* fStreamId;
+ private:
+ AVCodec *codec;
+ AVCodecContext *codecContext;
+ int frameIndex;
+ int got_picture;
+ int len;
+ AVFrame *frame;
+ AVFrame *rgbFrame;
+ SwsContext* swsContext;
+ uint8_t inbuf[INBUF_SIZE + AV_INPUT_BUFFER_PADDING_SIZE];
+ char buf[1024];
+ AVPacket avpkt;
+};
+
+class videoLIVE555Source : public basicMediaSource, public basicThread {
+ private:
+ basicLogCollection * m_pLog;
+ void * m_pOpaque;
+
+ int m_nInWidth;
+ int m_nInHeight;
+ int m_nOutWidth;
+ int m_nOutHeight;
+
+ StreamClientState streamClientState;
+
+ virtual Boolean continuePlaying();
+ uint8_t * fReceiveBuffer;
+ TaskScheduler * m_pScheduler;
+ UsageEnvironment * m_pUsageEnvironment;
+
+ char _eventLoopWatchVariable;
+
+ CustomRTSPClient * m_pRtspClient;
+ DummySink * m_pSink;
+ MediaSubsession * fSubsession;
+ char * fStreamId;
+
+ static void continueAfterDESCRIBE( RTSPClient* rtspClient, int resultCode, char* resultString);
+ static void continueAfterSETUP( RTSPClient* rtspClient, int resultCode, char* resultString);
+ static void continueAfterPLAY( RTSPClient* rtspClient, int resultCode, char* resultString);
+ // Other event handler functions:
+ static void subsessionAfterPlaying( void* clientData );
+ // called when a stream's subsession (e.g., audio or video substream) ends
+ static void subsessionByeHandler( void* clientData );//, char const* reason );
+ // called when a RTCP "BYE" is received for a subsession
+ static void streamTimerHandler( void* clientData );
+ // The main streaming routine (for each "rtsp://" URL):
+
+ void openURL(UsageEnvironment& env, char const* progName, char const* rtspURL);
+ // Used to iterate through each stream's 'subsessions', setting up each one:
+ void setupNextSubsession( RTSPClient* rtspClient );
+
+
+ // Used to shut down and close a stream (including its "RTSPClient" object):
+ void shutdownStream( RTSPClient* rtspClient, int exitCode = 1);
+ protected:
+ void m_fThreadProc( void );
+
+ public:
+ virtual bool _open( CSTR URI, bool ShowDeviceMenu = false, float framerate=-1.0f, int inputPin = -1, int width = -1, int height = -1 , int s_width=-1, int s_height=-1 );
+ virtual bool _close( void );
+ virtual bool _stop( void );
+ bool isFinished( void );
+ MediaStateStatus getStatus( void );
+ videoLIVE555Source( void *opaque=NULL );
+ videoLIVE555Source( CSTR URI, void *opaque=NULL );
+ virtual ~videoLIVE555Source();
+ bool setSize( int Width,
+ int Height );
+ bool setProportionalByWidth( int Width );
+ bool setProportionalByHeight( int Height );
+ bool setFPS( int );
+ bool setName( CSTR Name );
+ bool setFrameAspectRatio( FrameAspectRatio AspectRatio );
+ void consumeFrame( cv::Mat *frm );
+};
+
+#endif
diff --git a/lib/data/ponvif/ponvif.cpp b/lib/data/ponvif/ponvif.cpp
index d4494f9c..82170a36 100644
--- a/lib/data/ponvif/ponvif.cpp
+++ b/lib/data/ponvif/ponvif.cpp
@@ -73,6 +73,7 @@ pOnvif::pOnvif(){
m_sCapabilities.Media = NULL;
m_sCapabilities.PTZ = NULL;
m_sCapabilities.Extension = NULL;
+ m_bAuthMode = 0;
LOG("Constructor Done!");
};
@@ -461,8 +462,22 @@ bool pOnvif::create( void ) {
struct tm * tTS;
tTS = core_GetSystemDateAndTime();
if( tTS != NULL ){
+ char tB[128];
+ sprintf( tB, "TS from dev: %04d-%02d-%02d %02d:%02d:%02d",
+ tTS->tm_year, tTS->tm_mon, tTS->tm_mday,
+ tTS->tm_hour, tTS->tm_min, tTS->tm_sec );
+ LOG( tB );
+ // WTF ??!!
+ tTS->tm_year -= 1900;
+ tTS->tm_mon -= 1;
+
time_t tTimeStamp = mktime( tTS );
- m_nDeltaTime = time(NULL) - tTimeStamp;// -5;
+
+ m_nDeltaTime = time(NULL) - tTimeStamp;
+
+ sprintf( tB,"TS:[%d] D:[%d]", tTimeStamp, m_nDeltaTime );
+ LOG(tB);
+
free( tTS );
} else return false;
} catch ( exception e ) {
@@ -518,37 +533,51 @@ struct tm *pOnvif::core_GetSystemDateAndTime( void ) {
if( RetVal!= NULL ) {
memset( RetVal, 0, sizeof(struct tm) );
XMLNode zNode = response.getChildNode("Body", 0);
- XMLNode fNode = zNode.getChildNode("GetSystemDateAndTimeResponse", 0);
- XMLNode hNode = fNode.getChildNode("SystemDateAndTime", 0);
- XMLNode tNode = hNode.getChildNode("UTCDateTime", 0);
- if( !tNode.isEmpty() ) {
- RetVal->tm_isdst = 0;
- XMLNode ttNode = tNode.getChildNode( "Time", 0 );
- XMLNode dtNode = tNode.getChildNode( "Date", 0 );
- {
- XMLNode t = ttNode.getChildNode("Hour",0);
- RetVal->tm_hour = atoi( t.getText(0) );
- }
- {
- XMLNode t = ttNode.getChildNode("Minute",0);
- RetVal->tm_min = atoi( t.getText(0) );
- }
- {
- XMLNode t = ttNode.getChildNode("Second",0);
- RetVal->tm_sec = atoi( t.getText(0) );
- }
- {
- XMLNode t = dtNode.getChildNode("Year",0);
- RetVal->tm_year = atoi( t.getText(0) );
- }
- {
- XMLNode t = dtNode.getChildNode("Month",0);
- RetVal->tm_mon = atoi( t.getText(0) );
- }
- {
- XMLNode t = dtNode.getChildNode("Day",0);
- RetVal->tm_mday = atoi( t.getText(0) );
- }
+ if ( !zNode.isEmpty() ) {
+ XMLNode fNode = zNode.getChildNode("GetSystemDateAndTimeResponse", 0);
+ if ( !fNode.isEmpty() ) {
+ XMLNode hNode = fNode.getChildNode("SystemDateAndTime", 0);
+ if ( !hNode.isEmpty() ) {
+ XMLNode tNode = hNode.getChildNode("UTCDateTime", 0);
+ if( !tNode.isEmpty() ) {
+ RetVal->tm_isdst = 0;
+ XMLNode ttNode = tNode.getChildNode( "Time", 0 );
+ XMLNode dtNode = tNode.getChildNode( "Date", 0 );
+ {
+ XMLNode t = ttNode.getChildNode("Hour",0);
+ RetVal->tm_hour = atoi( t.getText(0) );
+ }
+ {
+ XMLNode t = ttNode.getChildNode("Minute",0);
+ RetVal->tm_min = atoi( t.getText(0) );
+ }
+ {
+ XMLNode t = ttNode.getChildNode("Second",0);
+ RetVal->tm_sec = atoi( t.getText(0) );
+ }
+ {
+ XMLNode t = dtNode.getChildNode("Year",0);
+ RetVal->tm_year = atoi( t.getText(0) );
+ }
+ {
+ XMLNode t = dtNode.getChildNode("Month",0);
+ RetVal->tm_mon = atoi( t.getText(0) );
+ }
+ {
+ XMLNode t = dtNode.getChildNode("Day",0);
+ RetVal->tm_mday = atoi( t.getText(0) );
+ }
+ } else {
+ LOG_ERROR("UTCDateTime is Not Found!");
+ };
+ } else {
+ LOG_ERROR("SystemDateAndTime is Not Found!");
+ };
+ } else {
+ LOG_ERROR("GetSystemDateAndTimeResponse is Not Found!");
+ };
+ } else {
+ LOG_ERROR("Body is Not Found!");
};
};
return RetVal;
@@ -1690,7 +1719,7 @@ accessToken pOnvif::_passwordDigest( CSTR username, CSTR password, time_t timest
if( tmp == NULL ){
LOG_ERROR("gmtime Error!");
};
- if( strftime( tTS, 200, "%FT%T.000Z", tmp )==0 ){
+ if( strftime( tTS, 200, "%FT%TZ", tmp )==0 ){
LOG_ERROR("strftime returned 0!");
};
} else {
@@ -1699,7 +1728,7 @@ accessToken pOnvif::_passwordDigest( CSTR username, CSTR password, time_t timest
if( tmp == NULL ){
LOG_ERROR("gmtime Error!");
};
- if( strftime( tTS, 200, "%FT%T.000Z", tmp )==0 ){
+ if( strftime( tTS, 200, "%FT%TZ", tmp )==0 ){
LOG_ERROR("strftime returned 0!");
};
};
@@ -1783,7 +1812,7 @@ bool pOnvif::_send_request( CSTR url, CSTR post_string, bool mustReturnData ){
fclose(tf);
mustReturnData = true; //In Debug Allways Read Return
#endif
- tRC->setCredentials( m_pUsername, m_pPassword, false );
+ tRC->setCredentials( m_pUsername, m_pPassword, m_bAuthMode );
tRC->setPOST( post_string, strlen(post_string) );
if( mustReturnData ) {
tRC->setHandler( (void*)this, pOnvif::parser, (void*)tRC );
@@ -1844,6 +1873,19 @@ bool pOnvif::_send_request( CSTR url, CSTR post_string, bool mustReturnData ){
curl_easy_setopt( m_pCURL, CURLOPT_POSTFIELDS, post_string);
sprintf( tBuffer,"%s:%s", m_pUsername, m_pPassword );
curl_easy_setopt( m_pCURL, CURLOPT_USERPWD, tBuffer );
+ switch ( m_bAuthMode ) {
+ case 0: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ); break;
+ case 1: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST ); break;
+ case 2: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST_IE ); break;
+ case 3: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_BEARER ); break;
+ case 4: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_NEGOTIATE ); break;
+ case 5: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_NTLM ); break;
+ case 6: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_NTLM_WB ); break;
+ case 7: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_ANY ); break;
+ case 8: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE ); break;
+ case 9: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_ONLY ); break;
+ //case 10: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_AWS_SIGV4 ); break;
+ };
#ifdef DEBUG
char tErrorBuffer[CURL_ERROR_SIZE];
curl_easy_setopt( m_pCURL, CURLOPT_ERRORBUFFER, tErrorBuffer );
@@ -1874,6 +1916,26 @@ int pOnvif::_writer( char *data, size_t size, size_t nmemb, pOnvif *Ptr ){
};
#endif
+bool pOnvif::setAuthMode( uint8_t Mode ){
+ m_bAuthMode = Mode;
+#ifdef DEBUG
+ switch ( m_bAuthMode ) {
+ case 0: LOG("Set Auth CURLAUTH_BASIC" ); break;
+ case 1: LOG("Set Auth CURLAUTH_DIGEST" ); break;
+ case 2: LOG("Set Auth CURLAUTH_DIGEST_IE" ); break;
+ case 3: LOG("Set Auth CURLAUTH_BEARER" ); break;
+ case 4: LOG("Set Auth CURLAUTH_NEGOTIATE" ); break;
+ case 5: LOG("Set Auth CURLAUTH_NTLM" ); break;
+ case 6: LOG("Set Auth CURLAUTH_NTLM_WB" ); break;
+ case 7: LOG("Set Auth CURLAUTH_ANY" ); break;
+ case 8: LOG("Set Auth CURLAUTH_ANYSAFE" ); break;
+ case 9: LOG("Set Auth CURLAUTH_ONLY" ); break;
+ case 10: LOG("Set Auth CURLAUTH_AWS_SIGV4" ); break;
+ };
+#endif
+ return true;
+};
+
#undef LOG
#undef TLOG
#undef LOG_ERROR
\ No newline at end of file
diff --git a/lib/data/ponvif/ponvif.h b/lib/data/ponvif/ponvif.h
index 3e45dd82..d0d42f8b 100644
--- a/lib/data/ponvif/ponvif.h
+++ b/lib/data/ponvif/ponvif.h
@@ -49,9 +49,9 @@
#define PONVIF_PACK_RELATIVE_MOVE (CSTR)"%s%s%s%s%s"
#define PONVIF_PACK_RELATIVE_ZOOM (CSTR)"%s%s%s%s%s"
#define PONVIF_PACK_ABSOLUTE_MOVE (CSTR)"%s%s%s%s%s"
-#define PONVIF_PACK_CONTINUOUS_MOVE (CSTR)"%s%s%s%s%s"
+#define PONVIF_PACK_CONTINUOUS_MOVE (CSTR)"%s%s%s%s%s"
//#define PONVIF_PACK_CONTINUOUS_MOVE_A (CSTR)"Profile_1"
-#define PONVIF_PACK_CONTINUOUS_ZOOM (CSTR)"%s%s%s%s%s"
+#define PONVIF_PACK_CONTINUOUS_ZOOM (CSTR)"%s%s%s%s%s"
#define PONVIF_PACK_PTZ_STOP (CSTR)"%s%s%s%s%struetrue"
#define PONVIF_ENVELOPE_EXT (CSTR)"%s%s"
@@ -444,6 +444,7 @@ class pOnvif{
int m_nDiscoveryMCastPort;
bool m_bDiscoveryHideDuplicates;
bool parser_done;
+ uint8_t m_bAuthMode;
#ifndef CURL_MANAGER
static int _writer( char *data, size_t size, size_t nmemb, pOnvif *Ptr );
#endif
@@ -462,6 +463,7 @@ class pOnvif{
bool setUsername( CSTR username );
CSTR getUsername( void );
bool setPassword( CSTR password );
+ bool setAuthMode( uint8_t Mode );
CSTR getPassword( void );
CSTR getDeviceUri( void );
bool setDeviceUri( CSTR deviceUri );
diff --git a/lib/data/protocol/protocolLGS2D.cpp b/lib/data/protocol/protocolLGS2D.cpp
index 347bca35..5a48dc28 100644
--- a/lib/data/protocol/protocolLGS2D.cpp
+++ b/lib/data/protocol/protocolLGS2D.cpp
@@ -42,7 +42,19 @@ int protocolLGS_2D::FinishUpPackage( uint8_t *Buffer, size_t Size, uint8_t Devic
Buffer[SIZE_IDX] = ((Size - 2) & 0xFF) | SEND_TAG;
Buffer[DEV_ID_IDX] = DeviceID;
Buffer[Size] = checksumLGS( Buffer, Size );
- return (int)(Size + 1);
+
+#ifdef LEGACY_2ZEROS_BEFORE_PACKAGE
+ uint8_t ZUBBI[1024];
+ memcpy( ZUBBI, Buffer, Size+1 );
+ memcpy( Buffer+2, ZUBBI, Size+1 );
+ Buffer[0]=0;
+ Buffer[1]=0;
+ Buffer[Size+3]=0;
+ Buffer[Size+4]=0;
+ return (int)(Size + 5);
+#else
+ return (int)(Size + 1);
+#endif
};
int protocolLGS_2D::packetChecker(U8 *Buffer, size_t BufferSize ){
@@ -222,15 +234,36 @@ bool protocolLGS_2D::getParameters( bool MASTER ){
return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 5, m_bDeviceID));
};
-bool protocolLGS_2D::getShadowPoly( uint8_t PolyID ){
+bool protocolLGS_2D::getShadowPoly( uint16_t PolyID ){
U8 Buffer[16];
if( m_oDataTransport == NULL ) return false;
- Buffer[CMD_IDX] = CMD_GET_HZ_POLY;
- Buffer[SUB_CMD_IDX] = PolyID;
+ Buffer[CMD_IDX] = CMD_GET_HZ_DATA;
+ Buffer[SUB_CMD_IDX] = sizeof( HZ_CMD_GET_POLYGON ) - sizeof( HZ_PACKET );
+ Buffer[5] = HZIT_CMD_GET_POLYGON;
+ Buffer[6] = 0;
+ Buffer[7] = PolyID & 0xff;
+ Buffer[8] = ( PolyID >> 8 ) & 0xff;
#ifdef DEBUG
LOG("getShadowPoly");
#endif
- return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 5, m_bDeviceID));
+ return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 9, m_bDeviceID));
+};
+
+bool protocolLGS_2D::getShadowPolyPoint( uint16_t PolyID, uint16_t PointID ){
+ U8 Buffer[16];
+ if( m_oDataTransport == NULL ) return false;
+ Buffer[CMD_IDX] = CMD_GET_HZ_DATA;
+ Buffer[SUB_CMD_IDX] = sizeof( HZ_CMD_GET_POLYGON_POINT ) - sizeof( HZ_PACKET );
+ Buffer[5] = HZIT_CMD_GET_POLYGON_POINT;
+ Buffer[6] = 0;
+ Buffer[7] = PolyID & 0xff;
+ Buffer[8] = ( PolyID >> 8 ) & 0xff;
+ Buffer[9] = PointID & 0xff;
+ Buffer[10] = ( PointID >> 8 ) & 0xff;
+#ifdef DEBUG
+ LOG("getShadowPolyPoint");
+#endif
+ return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 11, m_bDeviceID));
};
bool protocolLGS_2D::getShadowStatus( uint8_t MaskID ){
@@ -247,13 +280,124 @@ bool protocolLGS_2D::getShadowStatus( uint8_t MaskID ){
bool protocolLGS_2D::getShadowInfo( void ){
U8 Buffer[16];
if( m_oDataTransport == NULL ) return false;
- Buffer[CMD_IDX] = CMD_GET_HZ_INFO;
+ Buffer[CMD_IDX] = CMD_GET_HZ_DATA;
+ Buffer[SUB_CMD_IDX] = 0;
+ Buffer[5] = HZIT_CMD_GET_HEADER;
+ Buffer[6] = 0;
#ifdef DEBUG
LOG("getShadowInfo");
#endif
- return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 4, m_bDeviceID));
+ return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 7, m_bDeviceID));
+};
+
+bool protocolLGS_2D::setShadowInfo( SHADOW & SH ){
+ uint8_t Buffer[20];
+ if( m_oDataTransport == NULL ) return false;
+ Buffer[CMD_IDX] = CMD_SET_HZ_DATA;
+ Buffer[SUB_CMD_IDX] = 8;
+ Buffer[5] = HZIT_CMD_SET_HEADER;
+ Buffer[6] = 0;
+ Buffer[7] = SH.m_nPolygonCount & 0xFF;
+ Buffer[8] = ( SH.m_nPolygonCount >> 8 ) & 0xFF;
+ Buffer[9] = 360 & 0xFF;
+ Buffer[10] = ( 360 >> 8 ) & 0xFF;
+ Buffer[11] = SH.m_nEnabled & 0xFF;
+ Buffer[12] = ( SH.m_nEnabled >> 8 ) & 0xFF;
+ Buffer[13] = ( SH.m_nEnabled >> 16 ) & 0xFF;
+ Buffer[14] = ( SH.m_nEnabled >> 24 ) & 0xFF;
+#ifdef DEBUG
+ LOG("setShadowInfo");
+#endif
+ return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 15, m_bDeviceID ) );
+};
+
+bool protocolLGS_2D::setShadowPoly( SHADOW & SH, uint16_t PolyID ){
+ uint8_t Buffer[16];
+ if( m_oDataTransport == NULL ) return false;
+ Buffer[CMD_IDX] = CMD_SET_HZ_DATA;
+ Buffer[SUB_CMD_IDX] = 5;
+ Buffer[5] = HZIT_CMD_SET_POLYGON;
+ Buffer[6] = 0;
+ Buffer[7] = PolyID & 0xFF;
+ Buffer[8] = ( PolyID >> 8 ) & 0xFF;
+ Buffer[9] = SH.pPolygones[PolyID].bType;
+ Buffer[10] = SH.pPolygones[PolyID].wCount & 0xFF;
+ Buffer[11] = ( SH.pPolygones[PolyID].wCount >> 8 ) & 0xFF;
+#ifdef DEBUG
+ LOG("sendShadowPoly");
+#endif
+ return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 12, m_bDeviceID ) );
};
+bool protocolLGS_2D::setShadowPolyPoint( SHADOW & SH, uint16_t PolyID, uint16_t PointID ){
+ uint8_t Buffer[20];
+ if( m_oDataTransport == NULL ) return false;
+ Buffer[CMD_IDX] = CMD_SET_HZ_DATA;
+ Buffer[SUB_CMD_IDX] = 8;
+ Buffer[5] = HZIT_CMD_SET_POLYGON_POINT;
+ Buffer[6] = 0;
+ Buffer[7] = PolyID & 0xFF;
+ Buffer[8] = ( PolyID >> 8 ) & 0xFF;
+ Buffer[9] = PointID & 0xFF;
+ Buffer[10] = ( PointID >> 8 ) & 0xFF;
+ Buffer[11] = SH.pPolygones[PolyID].pPoint[PointID].wX & 0xFF;
+ Buffer[12] = (SH.pPolygones[PolyID].pPoint[PointID].wX >> 8) & 0xFF;
+ Buffer[13] = SH.pPolygones[PolyID].pPoint[PointID].wY & 0xFF;
+ Buffer[14] = (SH.pPolygones[PolyID].pPoint[PointID].wY >> 8) & 0xFF;
+#ifdef DEBUG
+ LOG("sendShadowPolyPoint");
+#endif
+ return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 15, m_bDeviceID ) );
+};
+bool protocolLGS_2D::setShadowRayLine( SHADOW & SH, uint16_t RLID ){
+ uint8_t Buffer[16];
+ if( m_oDataTransport == NULL ) return false;
+ Buffer[CMD_IDX] = CMD_SET_HZ_DATA;
+ Buffer[SUB_CMD_IDX] = 4;
+ Buffer[5] = HZIT_CMD_SET_RAY;
+ Buffer[6] = 0;
+ Buffer[7] = RLID & 0xFF;
+ Buffer[8] = ( RLID >> 8 ) & 0xFF;
+ Buffer[9] = SH.ray_lines[RLID].nCount & 0xFF;
+ Buffer[10] = ( SH.ray_lines[RLID].nCount >> 8 ) & 0xFF;
+#ifdef DEBUG
+ LOG("setShadowRayLine");
+#endif
+ return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 11, m_bDeviceID ) );
+};
+bool protocolLGS_2D::setShadowRay( SHADOW & SH, uint16_t RLID, uint16_t RayID ){
+ uint8_t Buffer[20];
+ if( m_oDataTransport == NULL ) return false;
+ Buffer[CMD_IDX] = CMD_SET_HZ_DATA;
+ Buffer[SUB_CMD_IDX] = 9;
+ Buffer[5] = HZIT_CMD_SET_RAY_LINE;
+ Buffer[6] = 0;
+ Buffer[7] = RLID & 0xFF;
+ Buffer[8] = ( RLID >> 8 ) & 0xFF;
+ Buffer[9] = RayID & 0xFF;
+ Buffer[10] = ( RayID >> 8 ) & 0xFF;
+ Buffer[11] = SH.ray_lines[RLID].rays[RayID].bType;
+ Buffer[12] = SH.ray_lines[RLID].rays[RayID].nMin & 0xFF;
+ Buffer[13] = ( SH.ray_lines[RLID].rays[RayID].nMin >> 8 ) & 0xFF;
+ Buffer[14] = SH.ray_lines[RLID].rays[RayID].nMax & 0xFF;
+ Buffer[15] = ( SH.ray_lines[RLID].rays[RayID].nMax >> 8 ) & 0xFF;
+#ifdef DEBUG
+ LOG("setShadowRay");
+#endif
+ return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 16, m_bDeviceID ) );
+};
+bool protocolLGS_2D::setShadowDone( void ){
+ uint8_t Buffer[10];
+ if( m_oDataTransport == NULL ) return false;
+ Buffer[CMD_IDX] = CMD_SET_HZ_DATA;
+ Buffer[SUB_CMD_IDX] = 0;
+ Buffer[5] = HZIT_CMD_SET_DONE;
+ Buffer[6] = 0;
+#ifdef DEBUG
+ LOG("setShadowDone");
+#endif
+ return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 7, m_bDeviceID ) );
+};
bool protocolLGS_2D::getState( void ){
U8 Buffer[16];
if( m_oDataTransport == NULL ) return false;
@@ -301,41 +445,6 @@ bool protocolLGS_2D::getMode( void ){
return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 5, m_bDeviceID));
};
-bool protocolLGS_2D::setShadowPoly( simplePolygone *SP ){
- if( m_oDataTransport == NULL ) return false;
- if ( SP == NULL ){
- uint8_t Buffer[16];
- Buffer[CMD_IDX] = CMD_SET_HZ_POLY;
- Buffer[SUB_CMD_IDX] = 0;
-#ifdef DEBUG
- LOG("clearShadowPoly");
-#endif
- return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 5, m_bDeviceID));
- };
-
- U8 counter;
- U8 Buffer[PROTOCOL_PARSER_BUFFER_SIZE];
- Buffer[CMD_IDX] = CMD_SET_HZ_POLY;
- Buffer[SUB_CMD_IDX] = SP->count;
- Buffer[SUB_CMD_IDX+1] = SP->color[0];
- Buffer[SUB_CMD_IDX+2] = SP->color[1];
- Buffer[SUB_CMD_IDX+3] = SP->color[2];
- counter = SUB_CMD_IDX+4;
- for( uint8_t i = 0; i < SP->count; i++ ){
- uint16_t x,y;
- x = SP->points[i].x();
- y = SP->points[i].y();
- Buffer[counter++] = ( x >> 8 ) & 0xFF;
- Buffer[counter++] = x & 0xFF;
- Buffer[counter++] = ( y >> 8 ) & 0xFF;
- Buffer[counter++] = y & 0xFF;
- };
-#ifdef DEBUG
- LOG("sendShadowPoly");
-#endif
- return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, counter, m_bDeviceID ) );
-};
-
bool protocolLGS_2D::setShadowStatus( bool Status, uint8_t MaskID ){
U8 Buffer[16];
if( m_oDataTransport == NULL ) return false;
@@ -347,7 +456,7 @@ bool protocolLGS_2D::setShadowStatus( bool Status, uint8_t MaskID ){
#endif
return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 6, m_bDeviceID));
};
-
+/*
bool protocolLGS_2D::setShadowTrace( vectorZoneMask *VM ){
if( VM == NULL ) return false;
if( m_oDataTransport == NULL ) return false;
@@ -381,6 +490,41 @@ bool protocolLGS_2D::setShadowTrace( vectorZoneMask *VM ){
#endif
return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, counter, m_bDeviceID ) );
};
+*/
+bool protocolLGS_2D::setComSpeed( uint32_t spd ){
+ U8 Buffer[16];
+ if( m_oDataTransport == NULL ) return false;
+ Buffer[CMD_IDX] = CMD_SET_COMM_SPEED;
+ Buffer[4] = spd & 0xFF;
+ Buffer[5] = ( spd >> 8 ) & 0xFF;
+ Buffer[6] = ( spd >> 16 ) & 0xFF;
+ Buffer[7] = ( spd >> 24 ) & 0xFF;
+#ifdef DEBUG
+ LOG("setComSpeed");
+#endif
+ return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 8, m_bDeviceID));
+};
+
+bool protocolLGS_2D::setDeviceAddress( uint8_t DeviceID, CSTR Serial ){
+ U8 Buffer[16];
+ if( m_oDataTransport == NULL ) return false;
+ Buffer[CMD_IDX] = CMD_SET_ADDRESS;
+ Buffer[4] = DeviceID;
+#ifdef DEBUG
+ LOG("setComSpeed");
+#endif
+ if ( Serial ) {
+ uint8_t len = strlen(Serial);
+ Buffer[5] = len;
+ for( uint8_t i=0; i< len; i++ ) {
+ Buffer[6+i] = Serial[i];
+ };
+ return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 6+len, m_bDeviceID));
+ } else {
+ Buffer[5] = 0;
+ return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 6, m_bDeviceID));
+ };
+};
bool protocolLGS_2D::setDetectionProfile( uint8_t profile ){
U8 Buffer[16];
@@ -395,24 +539,31 @@ bool protocolLGS_2D::setDetectionProfile( uint8_t profile ){
bool protocolLGS_2D::setParameters( PLGS_2D_PARAMETERS ptr, bool MASTER, uint8_t profile ){
- U8 counter;
U8 Buffer[64];
if( m_oDataTransport == NULL ) return false;
- Buffer[CMD_IDX] = CMD_SET_PARAMETERS;
+ Buffer[CMD_IDX] = CMD_PARAMETERS;
if(MASTER) {
Buffer[4] = 0x80;
} else {
Buffer[4] = 0xC0;
};
- counter = 5;
- for( int i=0; i < sizeof( LGS_2D_PARAMETERS ); i++ ){
- Buffer[counter] = *(((U8*)ptr)+i);
- counter++;
- };
+ Buffer[5] = ( ptr->nOrder >> 8 ) & 0xFF;
+ Buffer[6] = ptr->nOrder & 0xFF;
+ Buffer[7] = (ptr->nOffset >> 8) & 0xFF;
+ Buffer[8] = ptr->nOffset & 0xFF;
+ Buffer[9] = (ptr->nDelta >> 8) & 0xFF;
+ Buffer[10] = ptr->nDelta & 0xFF;
+ Buffer[11] = (ptr->nWidth >> 8) & 0xFF;
+ Buffer[12] = ptr->nWidth & 0xFF;
+ Buffer[13] = (ptr->nFlip >> 8) & 0xFF;
+ Buffer[14] = ptr->nFlip & 0xFF;
+ Buffer[15] = (ptr->nSun >> 8) & 0xFF;
+ Buffer[16] = ptr->nSun & 0xFF;
+ Buffer[17] = ptr->bSST & 0xFF;
#ifdef DEBUG
LOG("setParameters");
#endif
- return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, counter, m_bDeviceID));
+ return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 18, m_bDeviceID));
};
bool protocolLGS_2D::getSerialNumber( void ){
@@ -445,6 +596,39 @@ bool protocolLGS_2D::getDetectionProfile( void ){
return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 4, m_bDeviceID));
};
+bool protocolLGS_2D::sendFS_package( PFS_DATA pFSData ){
+ U8 Buffer[1024];
+ uint32_t nCnt = 1;
+ if( m_oDataTransport == NULL ) return false;
+ Buffer[CMD_IDX] = CMD_FS_SUB_PACKET;
+ switch ( pFSData->nCommand ) {
+ case FS_CMD_SEND_CMD: nCnt += sizeof(FS_SEND_CMD) + pFSData->sendcmd.nSubSize; break;
+ case FS_CMD_SEND_EVT: nCnt += sizeof(FS_SEND_EVT); break;
+ case FS_CMD_RECEIVE_CMD: nCnt += sizeof(FS_RECEIVE_CMD); break;
+ case FS_CMD_RECEIVE_EVT: nCnt += sizeof(FS_RECEIVE_EVT) + pFSData->receiveevt.nSubSize; break;
+ default: break;
+ };
+ for( int i = 0; i < nCnt; i++ ) Buffer[SUB_CMD_IDX + i] = ((uint8_t *)pFSData )[i];
+#ifdef DEBUG
+ LOG("sendFS_package");
+#endif
+ return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, SUB_CMD_IDX + nCnt, m_bDeviceID));
+};
+
+bool protocolLGS_2D::sendGF_package( uint8_t CMD, uint8_t cnt, uint8_t *Data ){
+ U8 Buffer[300];
+ if( m_oDataTransport == NULL ) return false;
+ Buffer[CMD_IDX] = CMD_GETFILE;
+ Buffer[SUB_CMD_IDX] = CMD;
+ Buffer[DATA_BEGIN_IDX] = cnt;
+ for( uint8_t i = 0; i < cnt; i ++ ) Buffer[DATA_BEGIN_IDX+1]=Data[i];
+#ifdef DEBUG
+ LOG("sendGF_package");
+#endif
+ return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, DATA_BEGIN_IDX+1+cnt, m_bDeviceID));
+};
+
+
#undef SIZE_IDX
#undef DEV_ID_IDX
#undef CMD_IDX
diff --git a/lib/data/protocol/protocolLGS2D.h b/lib/data/protocol/protocolLGS2D.h
index 15d218e0..cf322502 100644
--- a/lib/data/protocol/protocolLGS2D.h
+++ b/lib/data/protocol/protocolLGS2D.h
@@ -5,7 +5,9 @@
#include "protocolLGS_data.h"
#include "../../alg/lgs/detectorStructures.h"
#include "../../alg/lgs/mask.h"
+#include "../../rgoose/rgooseTypes.h"
+#define LEGACY_2ZEROS_BEFORE_PACKAGE
class protocolLGS_2D: public protocolParser{
private:
@@ -32,22 +34,32 @@ class protocolLGS_2D: public protocolParser{
bool getParameters( bool MASTER = true );
bool getSerialNumber( void );
bool getShadowInfo( void );
- bool getShadowPoly( uint8_t PolyID );
+ bool getShadowPoly( uint16_t PolyID );
+ bool getShadowPolyPoint( uint16_t PolyID, uint16_t PointID );
bool getShadowStatus( uint8_t MaskID = 0 );
bool getState( void );
bool getState2( void );
bool getVersionString( void );
bool getVoltage(void);
+
+ bool setComSpeed( uint32_t spd );
bool setDetectionProfile( uint8_t profile );
bool setDeviceID( uint8_t DeviceID ){ m_bDeviceID = DeviceID; return true; };
+ bool setDeviceAddress( uint8_t DeviceID, CSTR Serial = NULL );
bool setMode( U8 Mode );
bool setParameters( PLGS_2D_PARAMETERS ptr, bool MASTER = true, uint8_t profile = 0 );
- bool setShadowPoly( simplePolygone *SP );
+
+ bool setShadowInfo( SHADOW & SH );
+ bool setShadowPoly( SHADOW & SH, uint16_t PolyID );
+ bool setShadowPolyPoint( SHADOW & SH, uint16_t PolyID, uint16_t PointID );
+ bool setShadowRayLine( SHADOW & SH, uint16_t RLID );
+ bool setShadowRay( SHADOW & SH, uint16_t RLID, uint16_t RayID );
+ bool setShadowDone( void );
bool setShadowStatus( bool Status, uint8_t MaskID = 0 );
- bool setShadowTrace( vectorZoneMask *VM );
-
- bool sendFile( CSTR FileName );
+ bool sendGF_package( uint8_t CMD, uint8_t cnt, uint8_t *Data );
+ bool sendFS_package( PFS_DATA pFSData );
+
};
#endif
diff --git a/lib/data/protocol/protocolLGS_data.h b/lib/data/protocol/protocolLGS_data.h
index c06becfd..ed2d832a 100644
--- a/lib/data/protocol/protocolLGS_data.h
+++ b/lib/data/protocol/protocolLGS_data.h
@@ -800,9 +800,11 @@ typedef enum E_HZ_INFO_TYPE{
HZIT_EVT_ERROR = 255,
}HZ_INFO_TYPE;
+#define MAX_2D_SHADOW_RAY_LINES 360
+
typedef struct S_HZ_POINT{
- U16 wX; // 0..4095
- U16 wY; // 0..4095
+ int16_t wX; //-2047 .. 2047 // 0..4095
+ int16_t wY; //-2047 .. 2047 // 0..4095
}HZ_POINT, *LPHZ_POINT;
typedef struct S_HZ_LINE{
diff --git a/lib/data/protocol/protocolPTZ_APIX.cpp b/lib/data/protocol/protocolPTZ_APIX.cpp
new file mode 100644
index 00000000..e69de29b
diff --git a/lib/data/protocol/protocolPTZ_APIX.h b/lib/data/protocol/protocolPTZ_APIX.h
new file mode 100644
index 00000000..240af5d8
--- /dev/null
+++ b/lib/data/protocol/protocolPTZ_APIX.h
@@ -0,0 +1,11 @@
+#ifndef __PROTOCOL_PTZ_AXIS_APIX__
+#define __PROTOCOL_PTZ_AXIS_APIX__
+
+
+
+//https://www.axis.com/vapix-library/subjects/t10175981/section/t10036011/display
+
+
+
+
+#endif
diff --git a/lib/data/protocol/protocolPTZ_ONVIF.cpp b/lib/data/protocol/protocolPTZ_ONVIF.cpp
index 662b49d5..ab08ce30 100644
--- a/lib/data/protocol/protocolPTZ_ONVIF.cpp
+++ b/lib/data/protocol/protocolPTZ_ONVIF.cpp
@@ -8,6 +8,7 @@ protocolPTZ_ONVIF::protocolPTZ_ONVIF( config_setting_t *Settings ) :protocolPTZ(
m_pLog = basicLogCollection::getInstance();
m_bLastCommandIssued = CMD_PTZ_NOOP;
m_pSettings = Settings;
+ m_bAuthMode = 0;
#ifdef USE_PONVIF
m_pOnVif = NULL;
m_pProfile = NULL;
@@ -20,7 +21,7 @@ protocolPTZ_ONVIF::protocolPTZ_ONVIF( config_setting_t *Settings ) :protocolPTZ(
memset( m_pPassword, 0, MAX_CRED_LEN );
};
-protocolPTZ_ONVIF::protocolPTZ_ONVIF( CSTR ip, CSTR username, CSTR password ) :protocolPTZ(), m_mInquiryMutex(){
+protocolPTZ_ONVIF::protocolPTZ_ONVIF( CSTR ip, CSTR username, CSTR password, uint8_t AuthMode ) :protocolPTZ(), m_mInquiryMutex(){
m_pLog = basicLogCollection::getInstance();
m_bLastCommandIssued = CMD_PTZ_NOOP;
m_pSettings = NULL;
@@ -34,6 +35,9 @@ protocolPTZ_ONVIF::protocolPTZ_ONVIF( CSTR ip, CSTR username, CSTR password ) :p
LOG( ip );
LOG( username );
LOG( password );
+ m_bAuthMode = AuthMode;
+ sprintf( m_pDeviceURI, "Auth Mode: [%d]", m_bAuthMode );
+ LOG( m_pDeviceURI );
sprintf( m_pDeviceURI, "http://%s/onvif/device_service", ip );
//strncpy( m_pDeviceURI, ip, MAX_PATH_LEN );
strncpy( m_pUser, username, MAX_CRED_LEN );
@@ -65,6 +69,10 @@ bool protocolPTZ_ONVIF::setPassword( CSTR password ){
return true;
};
+bool protocolPTZ_ONVIF::setAuthMode( uint8_t Mode ){
+ m_bAuthMode = Mode;
+ return true;
+};
bool protocolPTZ_ONVIF::create( void ){
if (!protocolPTZ::create()) return false;
@@ -96,6 +104,7 @@ bool protocolPTZ_ONVIF::create( void ){
m_pOnVif->setDeviceUri( m_pDeviceURI );
m_pOnVif->setUsername( m_pUser );
m_pOnVif->setPassword( m_pPassword );
+ m_pOnVif->setAuthMode( m_bAuthMode );
if( m_pOnVif->create() ){
m_pProfile = m_pOnVif->getProfiles()->at(0);
return true;
diff --git a/lib/data/protocol/protocolPTZ_ONVIF.h b/lib/data/protocol/protocolPTZ_ONVIF.h
index 09b05e86..bd837e55 100644
--- a/lib/data/protocol/protocolPTZ_ONVIF.h
+++ b/lib/data/protocol/protocolPTZ_ONVIF.h
@@ -16,6 +16,7 @@ class protocolPTZ_ONVIF: public protocolPTZ{
char m_pUser[MAX_CRED_LEN];
char m_pPassword[MAX_CRED_LEN];
char m_pDeviceURI[MAX_PATH_LEN];
+ uint8_t m_bAuthMode;
#ifdef USE_PONVIF
pOnvif * m_pOnVif;
videoSourceProfile * m_pProfile;
@@ -29,7 +30,7 @@ class protocolPTZ_ONVIF: public protocolPTZ{
basicMutex m_mInquiryMutex;
public:
explicit protocolPTZ_ONVIF( config_setting_t *Settings = NULL );
- protocolPTZ_ONVIF( CSTR ip, CSTR username, CSTR password );
+ protocolPTZ_ONVIF( CSTR ip, CSTR username, CSTR password, uint8_t AuthMode = 0 );
virtual ~protocolPTZ_ONVIF();
virtual bool create( void );
#ifndef USE_PONVIF
@@ -41,6 +42,7 @@ class protocolPTZ_ONVIF: public protocolPTZ{
bool setIPAddress( CSTR ip );
bool setUsername( CSTR username );
bool setPassword( CSTR password );
+ bool setAuthMode( uint8_t Mode );
};
diff --git a/lib/rgoose/rgooseCamera.cpp b/lib/rgoose/rgooseCamera.cpp
index 0545c754..b5aaadc0 100644
--- a/lib/rgoose/rgooseCamera.cpp
+++ b/lib/rgoose/rgooseCamera.cpp
@@ -272,24 +272,21 @@ bool ARGUS_Camera::create(){
LOG( tB );
#endif
if( tSYS->beLocal() ){
- m_oPosition.setPositionXYZ( m_sCamData.x, m_sCamData.y, m_sCamData.z );
+ m_oPosition.setPositionXYZ( m_sCamData.x, m_sCamData.y, m_sCamData.z, 0 );
} else {
- int Zone = tSYS->getUTMZone();
C3D_DECART tpp = tSYS->getXYZ();
- m_oPosition.setPositionXYZ( tpp.x + m_sCamData.x, tpp.y + m_sCamData.y, tpp.z + m_sCamData.z, Zone );
-#ifdef DEBUG
- sprintf( tB, "Finalized Sensor Location: Lat:%.3f Lon:%.3f Alt:%.3f", m_oPosition.getLat(), m_oPosition.getLon(), m_oPosition.getAlt() );
- LOG( tB );
- sprintf( tB, "Finalized Sensor Location: x:%.3f y:%.3f z:%.3f", m_oPosition.getX(), m_oPosition.getY(), m_oPosition.getZ() );
- LOG( tB );
-#endif
+ m_oPosition.setPositionXYZ( tpp.x + m_sCamData.x, tpp.y + m_sCamData.y, tpp.z + m_sCamData.z, tSYS->getUTMZone() );
};
-
+ m_oPosition.setOrientationDeg( m_sCamData.x_rot , m_sCamData.y_rot, m_sCamData.z_rot );
+ m_oPosition.updateMatrix();
#ifdef DEBUG
- sprintf( tB, "Orientation: x:%.3f y:%.3f z:%.3f", m_sCamData.x_rot , m_sCamData.y_rot, m_sCamData.z_rot );
+ sprintf( tB, "Finalized Sensor Location: Lat:%.3f Lon:%.3f Alt:%.3f", m_oPosition.getLat(), m_oPosition.getLon(), m_oPosition.getAlt() );
+ LOG( tB );
+ sprintf( tB, "Finalized Sensor Location: x:%.3f y:%.3f z:%.3f", m_oPosition.getX(), m_oPosition.getY(), m_oPosition.getZ() );
+ LOG( tB );
+ sprintf( tB, "Orientation: x:%.3f y:%.3f z:%.3f", m_oPosition.getRotX_deg(), m_oPosition.getRotY_deg(), m_oPosition.getRotZ_deg() );
LOG( tB );
#endif
- m_oPosition.setOrientationDeg( m_sCamData.x_rot , m_sCamData.y_rot, m_sCamData.z_rot );
if( m_pProtocol != NULL ){
LOG_ERROR("Cannot Start: Service Already Running!");
@@ -399,7 +396,7 @@ bool ARGUS_Camera::create(){
#ifdef DEBUG
LOG("ONVIF");
#endif
- m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF( m_sCamData.ip, m_sCamData.username, m_sCamData.password );
+ m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF( m_sCamData.ip, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode );
if( m_pProtocol!=NULL ) {
if( !m_pProtocol->create() ) {
LOG_ERROR("Error Creating Proto!");
@@ -814,7 +811,7 @@ void ARGUS_Camera::m_fThreadProc( void ){
LOG("INIT GO -1 -1 -1");
#endif
//setBusy( true );
- if( m_pProtocol->goAbsolute( -1, -1, -1 ) ) setWM( CAM_WS_READY );
+ if( m_pProtocol->goAbsolute( -1, 0, -1 ) ) setWM( CAM_WS_READY );
//setBusy( false );
break;
};
@@ -1065,6 +1062,9 @@ bool ARGUS_Camera::testFOV( C3D_DECART L ){
systemAnchor* tSystem = systemAnchor::getInstance();
if ( tSystem == NULL ) return false;
C3D_SPH_DEGREES SL;
+#ifdef DEBUG
+ LOG("Test FOV local Decart coords");
+#endif
if( !tSystem->convertToLocal( &m_oPosition, L, SL ) ) return false;
return testFOV( SL );
};
@@ -1074,6 +1074,9 @@ bool ARGUS_Camera::testFOV( C3D_WGS84_LOC L ){
systemAnchor* tSystem = systemAnchor::getInstance();
if ( tSystem == NULL ) return false;
C3D_SPH_DEGREES SL;
+#ifdef DEBUG
+ LOG("Test FOV WGS coords");
+#endif
if( !tSystem->convertToLocal( &m_oPosition, L, SL ) ) return false;
return testFOV( SL );
};
@@ -1081,6 +1084,9 @@ bool ARGUS_Camera::testFOV( C3D_WGS84_LOC L ){
bool ARGUS_Camera::testFOV( C3D_SPH_RADIANS L ){
//Local Coords
C3D_SPH_DEGREES SL;
+#ifdef DEBUG
+ LOG("Test FOV local Spherical(rad) coords");
+#endif
spherical2spherical( L, SL );
return testFOV( SL );
};
@@ -1089,7 +1095,9 @@ bool ARGUS_Camera::testFOV( C3D_SPH_DEGREES SL ){
#ifdef DEBUG
char tB[128];
#endif
-
+#ifdef DEBUG
+ LOG("Test FOV local Spherical(deg) coords");
+#endif
switch ( m_sCamData.triggering_mode ) {
case CAM_TRIGGER_STRICT:{
if( SL.r > m_fMaxRange || SL.r < m_fMinRange ){
@@ -1190,6 +1198,9 @@ bool ARGUS_Camera::lookAt( uint32_t TargetRefID, C3D_WGS84_LOC L ){
systemAnchor* tSystem = systemAnchor::getInstance();
if( tSystem == NULL ) return false;
C3D_SPH_DEGREES SL;
+#ifdef DEBUG
+ LOG("Look at WGS coords!");
+#endif
tSystem->convertToLocal(&m_oPosition, L, SL );
return lookAt(TargetRefID, SL );
};
@@ -1198,12 +1209,18 @@ bool ARGUS_Camera::lookAt( uint32_t TargetRefID, C3D_DECART L ){
systemAnchor* tSystem = systemAnchor::getInstance();
if( tSystem == NULL ) return false;
C3D_SPH_DEGREES SL;
+#ifdef DEBUG
+ LOG("Look at System Decart coords!");
+#endif
tSystem->convertToLocal( &m_oPosition, L, SL );
return lookAt(TargetRefID, SL );
};
bool ARGUS_Camera::lookAt( uint32_t TargetRefID, C3D_SPH_RADIANS L ){
C3D_SPH_DEGREES SL;
+#ifdef DEBUG
+ LOG("Look at spherical(rad) 2 spherical(deg) coords!");
+#endif
spherical2spherical( L, SL );
return lookAt(TargetRefID, SL );
};
@@ -1214,7 +1231,9 @@ bool ARGUS_Camera::lookAt( uint32_t TargetRefID, C3D_SPH_DEGREES L ){
//LOG( tB );
//sprintf( tB, "Cam GoTo %.3f %.3f %.3f", fP, fT, fZ );
//LOG( tB );
-
+#ifdef DEBUG
+ LOG("Look at local spherical deg. coords!(final)");
+#endif
//if( getWM() == CAM_WS_READY ){
// C3D_ORIENT_ONVIF LL;
// spherical2onvif( L, LL, m_fMaxRange, m_sCamData.pan_model, m_sCamData.pan_angles, m_sCamData.tilt_model, m_sCamData.tilt_angles );
@@ -1265,12 +1284,15 @@ bool ARGUS_Camera::connectToStream( uint32_t id ){
if( tKM ) {
DBC_MEDIA_STREAM_DATA *tDATA = m_pDBC->getMediaStreamData( id );
if( tDATA ) {
- LOG( tDATA->mrl_proto );
m_sMediaSource.mediaStreamId = id;
+ if( strncmp(tDATA->mrl_proto, "v4l2", 4) == 0 ) {
+ if (m_pSource != NULL) delete((videoAVLIBSource*)m_pSource);
+ m_pSource = (basicMediaSource *) new videoAVLIBSource(&m_sMediaSource);
+ } else {
+ if (m_pSource != NULL) delete((videoLIVE555Source*)m_pSource);
+ m_pSource = (basicMediaSource *) new videoLIVE555Source(&m_sMediaSource);
+ };
- if( m_pSource != NULL ) delete( m_pSource );
-
- m_pSource = new videoAVLIBSource(&m_sMediaSource);
if( m_pSource != NULL ) {
char tMRL[1024];
#ifdef DEBUG
@@ -1311,7 +1333,7 @@ bool ARGUS_Camera::connectToStream( uint32_t id ){
};
};
LOG( tMRL );
- if( m_pSource->_open( tMRL, false, -1, pix, tDATA->width, tDATA->height, true, tW, tH ) ){
+ if( m_pSource->_open( tMRL, false, -1.0f, pix, tDATA->width, tDATA->height, tW, tH ) ){
m_bSourceConnected = m_pSource->attachDestination( (argusModuleEmbedVideo*) tKM );
if ( !m_bSourceConnected ) {
delete( m_pSource );
@@ -1356,7 +1378,7 @@ bool ARGUS_Camera::validateStream( void ){
if( m_bSourceConnected ) {
if( m_pSource ) {
if( m_pSource->isAttached() ){
- if( !m_pSource->isFinished() ) return true;
+ if( m_pSource->getStatus() < MS_STOPED ) return true;
#ifdef DEBUG
LOG("Source is Finished!");
#endif
diff --git a/lib/rgoose/rgooseCamera.h b/lib/rgoose/rgooseCamera.h
index 0a365ae0..5ca1424a 100644
--- a/lib/rgoose/rgooseCamera.h
+++ b/lib/rgoose/rgooseCamera.h
@@ -21,6 +21,7 @@
#include "../components/base/basicMutex.h"
#include "../data/protocol/protocolPTZ.h"
#include "../data/media/video/videoAVLIBSource.h"
+#include "../data/media/video/videoLive555AVLibSource.h"
#include "../components/base/basicEventHeap.h"
#include "rgooseDBConnector.h"
#include "rgooseNode.h"
@@ -108,7 +109,7 @@ typedef struct S_CAM_ROI{
typedef std::vector vCAM_ROIS;
-#define LOSE_INTERES_TIME_MS 10000
+#define LOSE_INTERES_TIME_MS 2000
class ARGUS_Camera: public argusNetNode, public basicThread {
private:
@@ -141,7 +142,9 @@ class ARGUS_Camera: public argusNetNode, public basicThread {
CAM_TASK_QUEUE m_qCAM_TASK;
basicMutex m_mQPROTECTOR;
- videoAVLIBSource * m_pSource;
+ //videoAVLIBSource * m_pSource;
+ //videoLIVE555Source * m_pSource;
+ basicMediaSource * m_pSource;
uint32_t m_nRelativeMoveCounter;
uint8_t m_bRelativeMoveMatrix;
float m_fSpeedRise;
diff --git a/lib/rgoose/rgooseDBConnector.cpp b/lib/rgoose/rgooseDBConnector.cpp
index db0ebdcd..68ed95bf 100644
--- a/lib/rgoose/rgooseDBConnector.cpp
+++ b/lib/rgoose/rgooseDBConnector.cpp
@@ -732,23 +732,23 @@ bool argusDBC::getAllCamRecords( uint32_t SiteID, vectorCamRecords &VR ){
};
it = cArr->find("access_login");
if( it != cArr->end() ){
- strncpy( tVal->username, it->second.c_str(), 16 );
+ strncpy( tVal->username, it->second.c_str(), 32 );
};
it = cArr->find("access_pass");
if( it != cArr->end() ){
- strncpy( tVal->password, it->second.c_str(), 16 );
+ strncpy( tVal->password, it->second.c_str(), 32 );
};
it = cArr->find("uuid");
if( it != cArr->end() ){
- strncpy( tVal->uuid, it->second.c_str(), CLOG );
+ strncpy( tVal->uuid, it->second.c_str(), 64 );
};
it = cArr->find("mac");
if( it != cArr->end() ){
- strncpy( tVal->mac, it->second.c_str(), 16 );
+ strncpy( tVal->mac, it->second.c_str(), 17 );
};
it = cArr->find("ip");
if( it != cArr->end() ){
- strncpy( tVal->ip, it->second.c_str(), 16 );
+ strncpy( tVal->ip, it->second.c_str(), 17 );
};
it = cArr->find("port");
if( it != cArr->end() ){
@@ -1463,6 +1463,74 @@ DBC_FH_DATA *argusDBC::getFlyHunterData( uint32_t ID ){
};
return tVal;
};
+bool argusDBC::fillShadow2D( uint32_t ID, SHADOW & SH ){
+ if( m_bIsConnected ){
+ char tQBuf[CTEXT];
+ AAssoc *result;
+ sprintf(tQBuf, "SELECT `lv`.`id`, `lm`.`layer`, `lm`.`status` FROM `lrf_mask_vertexes` `lv` LEFT JOIN `lrf_masks` `lm` ON (`lm`.`id` = `lv`.`mask_id`) WHERE `lm`.`sensor_id`=%d ORDER BY `lv`.`id`", ID );
+ LOG(tQBuf);
+ result = m_pDatabase->Query( tQBuf );
+ if( result!= NULL ) {
+ if( result->size() > 0 ) {
+ SH.m_nEnabled = 0xFFFFFFFF;
+ SH.m_nPolygonCount = result->size();
+ SH.pPolygones = (SHADOW_POLY *) calloc( SH.m_nPolygonCount, sizeof( SHADOW_POLY ) );
+ if ( SH.pPolygones ) {
+ Assoc * cArr;
+ for ( uint8_t idx = 0; idx < result->size(); idx++ ) {
+ Assoc::iterator it;
+ cArr = result->at(idx);
+ it = cArr->find("id");
+ if( it != cArr->end() ){
+ SH.pPolygones[idx].m_nDBID = atoi(it->second.c_str());
+ };
+ it = cArr->find("layer");
+ if( it != cArr->end() ){
+ SH.pPolygones[idx].bType = atoi(it->second.c_str());
+ };
+ it = cArr->find("status");
+ if( it != cArr->end() ){
+ SH.m_nEnabled &= ( it->second.c_str()[0] == 'E' )?0xFFFFFFFF:~(1<Query( tQBuf );
+ if( v_result!= NULL ) {
+ if( v_result->size() > 0 ) {
+ SH.pPolygones[idx].wCount = v_result->size();
+ SH.pPolygones[idx].pPoint = (HZ_POINT *) calloc( SH.pPolygones[idx].wCount, sizeof( HZ_POINT ) );
+ if(SH.pPolygones[idx].pPoint ) {
+ for ( uint32_t zdx =0; zdx < SH.pPolygones[idx].wCount; zdx++ ) {
+ cArr = v_result->at(zdx);
+ it = cArr->find("x");
+ if( it != cArr->end() ){
+ SH.pPolygones[idx].pPoint[zdx].wX = atoi(it->second.c_str());
+ };
+ it = cArr->find("y");
+ if( it != cArr->end() ){
+ SH.pPolygones[idx].pPoint[zdx].wY = atoi(it->second.c_str());
+ };
+ LOG("Point Added!");
+ };
+ } else {
+ LOG("No mem for Points!");
+ };
+ } else {
+ LOG("No Points!");
+ SH.pPolygones[idx].wCount = 0;
+ SH.pPolygones[idx].pPoint = NULL;
+ };
+ deleteResult( v_result );
+ };
+ };
+ };
+ };
+ deleteResult( result );
+ };
+ return true;
+ };
+ return false;
+};
DBC_SITE_DATA *argusDBC::getSiteData( uint32_t ID ){
DBC_SITE_DATA * tVal = NULL;
@@ -1733,6 +1801,58 @@ uint8_t argusDBC::getLRFDataStatus( uint32_t ID ){
return RetVal;
};
+PLGS_2D_PARAMETERS argusDBC::getLRFDetectionProfile( uint32_t lrfID, uint8_t profileID, bool master ){
+ PLGS_2D_PARAMETERS retVal = NULL;
+ if(m_bIsConnected){
+ char tQBuf[CTEXT];
+ AAssoc *result;
+ sprintf(tQBuf, "SELECT * FROM `lrf_detection_profiles` WHERE `aux_id`=%d AND `profile_id`=%d AND `master`=b'%c'", lrfID, profileID,((master)?'1':'0') );
+
+#ifdef DEBUG
+ LOG(tQBuf);
+#endif
+ result = m_pDatabase->Query( tQBuf );
+ if( result!= NULL ) {
+ if( result->size() > 0 ) {
+ retVal = (PLGS_2D_PARAMETERS) malloc(sizeof(LGS_2D_PARAMETERS));
+ memset( retVal, 0, sizeof(LGS_2D_PARAMETERS));
+ Assoc *cArr;
+ Assoc::iterator it;
+ cArr = result->at(0);
+ it = cArr->find("order");
+ if( it != cArr->end() ){
+ retVal->nOrder = atoi(it->second.c_str());
+ };
+ it = cArr->find("offset");
+ if( it != cArr->end() ){
+ retVal->nOffset = atoi(it->second.c_str());
+ };
+ it = cArr->find("delta");
+ if( it != cArr->end() ){
+ retVal->nDelta = atoi(it->second.c_str());
+ };
+ it = cArr->find("flip");
+ if( it != cArr->end() ){
+ retVal->nFlip = atoi(it->second.c_str());
+ };
+ it = cArr->find("width");
+ if( it != cArr->end() ){
+ retVal->nWidth = atoi(it->second.c_str());
+ };
+ it = cArr->find("sst");
+ if( it != cArr->end() ){
+ retVal->bSST = atoi(it->second.c_str());
+ };
+ it = cArr->find("sun");
+ if( it != cArr->end() ){
+ retVal->nSun = atoi(it->second.c_str());
+ };
+ };
+ };
+ deleteResult( result );
+ };
+ return retVal;
+};
CSTR argusDBC::getLRFDraw( uint32_t DBID ){
CSTR RetVal = NULL;
if(m_bIsConnected){
@@ -2426,11 +2546,11 @@ DBC_CAM_DATA *argusDBC::getCamData( uint32_t ID ){
if( it != cArr->end() ){
tVal->x_rot = atof( it->second.c_str() );
};
- it = cArr->find("x_rot");
+ it = cArr->find("y_rot");
if( it != cArr->end() ){
tVal->y_rot = atof( it->second.c_str() );
};
- it = cArr->find("x_rot");
+ it = cArr->find("z_rot");
if( it != cArr->end() ){
tVal->z_rot = atof( it->second.c_str() );
};
@@ -2515,6 +2635,10 @@ DBC_CAM_DATA *argusDBC::getCamData( uint32_t ID ){
if( it != cArr->end() ){
tVal->triggering_mode = atoi( it->second.c_str() );
};
+ it = cArr->find("auth_mode");
+ if( it != cArr->end() ){
+ tVal->auth_mode = atoi( it->second.c_str() );
+ };
};
};
};
@@ -3247,11 +3371,12 @@ uint32_t argusDBC::addResource( uint32_t NodeID, uint8_t type, CSTR devName, uin
uint32_t RetVal = 0;
if( m_bIsConnected ){
char tQBuf[2048];
- //CSTR tMD5 = MD5String( devName );
- //if( tMD5 ) {
- //sprintf( tQBuf, "INSERT INTO `resources` SET `node_id`=%d, `type`=%d, `md5`='%s', `aux_id`=%d, `device`='%s', `active`=1 ON DUPLICATE KEY UPDATE `active`=1, `aux_id`=%d, `device`='%s'", NodeID, type, tMD5, auxID, devName, auxID, devName );
- sprintf( tQBuf, "INSERT INTO `resources` SET `node_id`=%d, `type`=%d, `aux_id`=%d, `device`='%s', `active`=1 ON DUPLICATE KEY UPDATE `active`=1, `aux_id`=%d, `device`='%s'", NodeID, type, auxID, devName, auxID, devName );
- // free( tMD5 );
+ sprintf( tQBuf, "%d:%d:%s", NodeID, type, devName );
+ CSTR tMD5 = MD5String( tQBuf );
+ if( tMD5 ) {
+ sprintf( tQBuf, "INSERT INTO `resources` SET `node_id`=%d, `type`=%d, `md5`='%s', `aux_id`=%d, `device`='%s', `active`=1 ON DUPLICATE KEY UPDATE `active`=1, `aux_id`=%d", NodeID, type, tMD5, auxID, devName, auxID );
+ //sprintf( tQBuf, "INSERT INTO `resources` SET `node_id`=%d, `type`=%d, `aux_id`=%d, `device`='%s', `active`=1 ON DUPLICATE KEY UPDATE `active`=1, `aux_id`=%d, `device`='%s'", NodeID, type, auxID, devName, auxID, devName );
+ free( tMD5 );
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
@@ -3259,7 +3384,7 @@ uint32_t argusDBC::addResource( uint32_t NodeID, uint8_t type, CSTR devName, uin
if( RetVal == 0 ) {
RetVal = getResourceID( NodeID, type, auxID );
};
- //};
+ };
};
return RetVal;
};
@@ -3678,7 +3803,7 @@ uint32_t argusDBC::addLocalWiFi( uint32_t NIF_ID, ARGUS_WIFI_MODE mode, CSTR SSI
};
uint32_t argusDBC::addLRFMask( uint32_t devID, uint8_t lrfID, uint8_t layerID ){
- uint32_t RetVal = 0;
+ uint32_t RetVal = 0;
if( m_bIsConnected ) {
char tQBuf[MAX_PATH_LEN];
sprintf( tQBuf, "INSERT INTO `lrf_masks` SET `sensor_id`=%d, `lrf_id`=%d, `layer`=%d ON DUPLICATE KEY UPDATE `id`=`id`",
@@ -3715,7 +3840,7 @@ uint32_t argusDBC::addLRFMaskPolygone( uint32_t maskID, uint8_t r, uint8_t g, ui
return RetVal;
};
-bool argusDBC::addLRFMaskPolygonePoint( uint32_t polyID, uint16_t x, uint16_t y ){
+bool argusDBC::addLRFMaskPolygonePoint( uint32_t polyID, int16_t x, int16_t y ){
if( m_bIsConnected ) {
char tQBuf[MAX_PATH_LEN];
sprintf( tQBuf, "INSERT INTO `lrf_mask_vertex_points` SET `vertex_id`=%d, `x`=%d, `y`=%d",
@@ -3949,6 +4074,7 @@ bool argusDBC::addDeviceDraw( uint32_t DBID, uint8_t type, uint8_t lrf, void *th
m_pDatabase->SilentQuery( tQBuf );
sprintf( tQBuf, "INSERT INTO lrf_draw(node_id,ts,lrf_id,type,size,data) VALUES(%d,NOW(),%d,%d,%d,'%s')", DBID, lrf, type, th_size, tPData );
m_pDatabase->SilentQuery( tQBuf );
+ LOG( "Inserted Draw OK!" );
free( tQBuf );
rVal = true;
} else {
@@ -4040,7 +4166,9 @@ bool argusDBC::updateLRFDetectionProfile( uint32_t lrfID, uint8_t profileID, boo
if( m_bIsConnected ) {
char tQBuf[MAX_PATH_LEN];
if( master ) {
- sprintf( tQBuf, "UPDATE `lrf_detection_profiles` SET `order`=%d, `offset`=%d, `delta`=%d, `flip`=%d, `width`=%d, `sst`=%d, `sun`=%d, `gp`=%d, `spikes`=%d WHERE `aux_id`=%d AND `profile_id`=%d AND `master`=b'1'",
+ sprintf( tQBuf, "INSERT INTO `lrf_detection_profiles` SET `aux_id`=%d, `profile_id`=%d, `master`=b'1', `order`=%d, `offset`=%d, `delta`=%d, `flip`=%d, `width`=%d, `sst`=%d, `sun`=%d, `gp`=%d, `spikes`=%d ON DUPLICATE KEY UPDATE `order`=%d, `offset`=%d, `delta`=%d, `flip`=%d, `width`=%d, `sst`=%d, `sun`=%d, `gp`=%d, `spikes`=%d",
+ lrfID,
+ profileID,
nOrder,
nOffset,
nDelta,
@@ -4050,10 +4178,19 @@ bool argusDBC::updateLRFDetectionProfile( uint32_t lrfID, uint8_t profileID, boo
nSun,
GP,
spikes,
- lrfID,
- profileID );
+ nOrder,
+ nOffset,
+ nDelta,
+ nFlip,
+ nWidth,
+ bSST,
+ nSun,
+ GP,
+ spikes );
} else {
- sprintf( tQBuf, "UPDATE `lrf_detection_profiles` SET `order`=%d, `offset`=%d, `delta`=%d, `flip`=%d, `width`=%d, `sst`=%d, `sun`=%d, `gp`=%d, `spikes`=%d WHERE `aux_id`=%d AND `profile_id`=%d AND `master`=b'0'",
+ sprintf( tQBuf, "INSERT INTO `lrf_detection_profiles` SET `aux_id`=%d, `profile_id`=%d, `master`=b'0', `order`=%d, `offset`=%d, `delta`=%d, `flip`=%d, `width`=%d, `sst`=%d, `sun`=%d, `gp`=%d, `spikes`=%d ON DUPLICATE KEY UPDATE `order`=%d, `offset`=%d, `delta`=%d, `flip`=%d, `width`=%d, `sst`=%d, `sun`=%d, `gp`=%d, `spikes`=%d",
+ lrfID,
+ profileID,
nOrder,
nOffset,
nDelta,
@@ -4063,8 +4200,15 @@ bool argusDBC::updateLRFDetectionProfile( uint32_t lrfID, uint8_t profileID, boo
nSun,
GP,
spikes,
- lrfID,
- profileID );
+ nOrder,
+ nOffset,
+ nDelta,
+ nFlip,
+ nWidth,
+ bSST,
+ nSun,
+ GP,
+ spikes );
};
#ifdef DEBUG_ALL
LOG(tQBuf);
diff --git a/lib/rgoose/rgooseDBConnector.h b/lib/rgoose/rgooseDBConnector.h
index 4bfe859c..aff77614 100644
--- a/lib/rgoose/rgooseDBConnector.h
+++ b/lib/rgoose/rgooseDBConnector.h
@@ -42,7 +42,7 @@ class argusDBC{
bool addLRFDraw( uint32_t DBID, uint32_t SIZE, CSTR ID, uint8_t kID =0, uint8_t type = 0, bool rendered = false );
uint32_t addLRFMask( uint32_t devID, uint8_t lrfID = 0, uint8_t layerID = 0 );
uint32_t addLRFMaskPolygone( uint32_t maskID, uint8_t r, uint8_t g, uint8_t b );
- bool addLRFMaskPolygonePoint( uint32_t polyID, uint16_t x, uint16_t y );
+ bool addLRFMaskPolygonePoint( uint32_t polyID, int16_t x, int16_t y );
//bool addIPCam( uint32_t SiteID, resultWoWo *tPtr );
bool addIPCam( uint32_t SiteID, OBSERVER_RESULT *tPtr );
@@ -103,6 +103,7 @@ class argusDBC{
//bool getLastEvents( vectorEventRecords &VR, uint32_t tss, uint32_t tsms );
DBC_LRF_DATA * getLRFData( uint32_t ID );
uint8_t getLRFDataStatus( uint32_t ID );
+ PLGS_2D_PARAMETERS getLRFDetectionProfile( uint32_t lrfID, uint8_t profileID, bool master );
CSTR getLRFDraw( uint32_t DBID );
uint32_t getLRFMaskID( uint32_t deviceID, uint8_t lrfID = 0, uint8_t layer = 0 );
DBC_MEDIA_STREAM_DATA * getMediaStreamData( uint32_t ID );
@@ -134,6 +135,7 @@ class argusDBC{
DBC_UART_DATA * getUartData( uint32_t UartID );
uint32_t getUartID( uint32_t NodeID, uint8_t Type, CSTR path );
uint32_t getWiFi_ID( uint32_t nif_id );
+ bool fillShadow2D( uint32_t ID, SHADOW & SH );
void deleteCamCapPicture( uint32_t PicID );
void deleteNode( uint32_t NodeID );
diff --git a/lib/rgoose/rgooseHardwareManager.cpp b/lib/rgoose/rgooseHardwareManager.cpp
index f483c294..845e1adb 100644
--- a/lib/rgoose/rgooseHardwareManager.cpp
+++ b/lib/rgoose/rgooseHardwareManager.cpp
@@ -1091,28 +1091,28 @@ argusHardwareResource *argusHardwareManager::requestResource( ARGUS_HARDWARE_PRO
DBC_INT_LIST *argusHardwareManager::requestResourcesByType( ARGUS_HARDWARE_PROVIDERS type ){
DBC_INT_LIST *RetVal = NULL;
-#ifdef DEBUG_EXTRA
+#ifdef DEBUG
char tBuffer[128];
sprintf( tBuffer, "Requested Resource type: %d", type );
LOG( tBuffer );
#endif
m_mVectorProtector.lock();
if( m_vResources.size() ) {
-#ifdef DEBUG_EXTRA
+#ifdef DEBUG
LOG("Have Some Resources!");
#endif
RetVal = new DBC_INT_LIST();
if( RetVal ) {
-#ifdef DEBUG_EXTRA
+#ifdef DEBUG
LOG("RetVal Created!");
#endif
for( VECTOR_HW_RESOURCES::iterator idx = m_vResources.begin(); idx < m_vResources.end(); idx++ ) {
-#ifdef DEBUG_EXTRA
+#ifdef DEBUG
sprintf( tBuffer, "Have Resource type: %d", (*idx)->getHardwareType() );
LOG( tBuffer );
#endif
if( (*idx)->getProviderType() == type ) {
-#ifdef DEBUG_EXTRA
+#ifdef DEBUG
LOG("Matched!");
#endif
RetVal->push_back((*idx)->getDbId());
diff --git a/lib/rgoose/rgooseHardwareResourceSerialProvider.cpp b/lib/rgoose/rgooseHardwareResourceSerialProvider.cpp
index cea55dba..a3ff725a 100644
--- a/lib/rgoose/rgooseHardwareResourceSerialProvider.cpp
+++ b/lib/rgoose/rgooseHardwareResourceSerialProvider.cpp
@@ -1,3 +1,4 @@
+//#define DEBUG_EXTRA
#include "rgooseHardwareResourceSerialProvider.h"
#include "../data/protocol/protocol.h"
#include "rgooseDBConnector.h"
@@ -429,11 +430,13 @@ bool argusHardwareResourceSerialProvider::create_HW(){
//m_iFID = open( DevicePath, O_RDWR| O_NONBLOCK | O_NDELAY );
if( strstr( m_sUartData.path, "USB" ) == NULL ){
+ LOG("MANUAL RTS CTL");
m_bManualRTS = true;
wiringPiSetup();
//Set RTS Pin
pinMode( 0, OUTPUT );
} else {
+ LOG("NO RTS CTL");
m_bManualRTS = false;
};
@@ -950,7 +953,7 @@ int argusHardwareResourceSerialProvider::recptBlock( unsigned char *Buffer, int
return -1;
};
}
-#ifdef DEBUG_EXTRA
+#ifdef DEBUG
else LOG( "Port is not Ready to Receive" )
#endif
;
diff --git a/lib/rgoose/rgooseHardwareResourceSerialProvider.h b/lib/rgoose/rgooseHardwareResourceSerialProvider.h
index 56c52375..0381a6f6 100644
--- a/lib/rgoose/rgooseHardwareResourceSerialProvider.h
+++ b/lib/rgoose/rgooseHardwareResourceSerialProvider.h
@@ -20,8 +20,8 @@
#endif
-#ifdef DEBUG
- //#define DEBUG_SERIAL_COMMUNICATION
+#ifdef DEBUG_EXTRA
+ #define DEBUG_SERIAL_COMMUNICATION
#endif
#ifndef MAXIMAL_SOCKET_PACKET_LENGTH
diff --git a/lib/rgoose/rgooseKernel.cpp b/lib/rgoose/rgooseKernel.cpp
index 9560ac03..0bef329e 100644
--- a/lib/rgoose/rgooseKernel.cpp
+++ b/lib/rgoose/rgooseKernel.cpp
@@ -15,6 +15,7 @@
#include
#include
#include
+#include
#include "../data/json/json_tool.h"
#include
@@ -471,11 +472,10 @@ void argusKernel::m_fThreadProc( void ){
};
case ARGUS_CMD_KRNL_DELNODE:{
uint32_t tNodeID = atoi( tCMD->PARAM );
- if( tNodeID == 0 ) break;
+ if (tNodeID == 0) break;
if( m_pNodeFactory == NULL) break;
// Turn Off Node
m_pNodeFactory->deleteNode( tNodeID );
-
break;
};
case ARGUS_CMD_KRNL_RESET_SITE:{
@@ -495,6 +495,18 @@ void argusKernel::m_fThreadProc( void ){
m_bExitCause = 4; // Go -> Detect Hardware in BACKEND
break;
};
+ case ARGUS_CMD_KRNL_SYNC_TIME:{
+ uint32_t uts = atoi( tCMD->PARAM );
+ if( uts ){
+ time_t ts = (time_t)uts;
+ if( stime( &ts ) == 0 ){
+ // Restert Server;
+ m_bThreadStatus = TH_ENDED;
+ m_bExitCause = 0;
+ };
+ };
+ break;
+ };
case ARGUS_CMD_KRNL_SYSTEM_TASK:{
try{
Json::Value root;
@@ -1009,6 +1021,7 @@ void argusKernel::dispatchEvent( EVENT_CONTAINER *Evt ){
};
break;
};
+ case EVT_ROI_ACTIVE:
case EVT_TARGET_2D_BLACK:
case EVT_TARGET_2D_WHITE:{
TARGET_DATA *tDATA = (TARGET_DATA *)Evt->m_pEvtData;
diff --git a/lib/rgoose/rgooseKernel.h b/lib/rgoose/rgooseKernel.h
index 3c4b7689..9b8d789a 100644
--- a/lib/rgoose/rgooseKernel.h
+++ b/lib/rgoose/rgooseKernel.h
@@ -100,6 +100,7 @@ struct serial_struct {
#define ARGUS_CMD_KRNL_RESET_SITE 245
#define ARGUS_CMD_KRNL_RESTART 250
#define ARGUS_CMD_KRNL_PNP 251
+#define ARGUS_CMD_KRNL_SYNC_TIME 252
#define ARGUS_CMD_KRNL_SHUTDOWN 255
#define ARGUS_CMD_KRNL_SYSTEM_TASK 120
#define ARGUS_CMD_MODULES_RELOAD 60
diff --git a/lib/rgoose/rgooseModuleOnvifObserver.cpp b/lib/rgoose/rgooseModuleOnvifObserver.cpp
index dc6f728d..839db719 100644
--- a/lib/rgoose/rgooseModuleOnvifObserver.cpp
+++ b/lib/rgoose/rgooseModuleOnvifObserver.cpp
@@ -125,7 +125,7 @@ void argusModuleOnvifObserver::m_fThreadProc(){
bool bOptVal;
int bOptLen;
int iOptLen;
- uint8_t bCounterTO = 100; // 1 second
+ uint16_t bCounterTO = 600; // 3 second
char rBuffer[MAX_BUFF_SIZE];
#ifdef DEBUG
char tB[128];
@@ -143,9 +143,11 @@ void argusModuleOnvifObserver::m_fThreadProc(){
struct sockaddr src_addr;
socklen_t addrlen = sizeof( src_addr );
RetVal = recvfrom( socketFD, rBuffer, MAX_BUFF_SIZE, 0, &src_addr, &addrlen );
- sprintf( tB, "(%d){%d}MSG[%d] from %s", bCounterTO, socketFD, RetVal, inet_ntoa(((struct sockaddr_in *)&src_addr)->sin_addr) );
- LOG( tB );
-#else
+ if ( RetVal > -1 ) {
+ sprintf(tB, "(%d){%d}MSG[%d] from %s", bCounterTO, socketFD, RetVal, inet_ntoa(((struct sockaddr_in *)&src_addr)->sin_addr));
+ LOG( tB );
+ };
+#else //http://192.168.200.127/axis-cgi/com/ptz.cgi?info=1&camera=1
RetVal = recvfrom( socketFD, rBuffer, MAX_BUFF_SIZE, 0, NULL, NULL );
#endif
if ((RetVal == -1) && /*(errno != EAGAIN) &&*/ (errno != EINTR) && (errno != EWOULDBLOCK)) {
@@ -155,6 +157,7 @@ void argusModuleOnvifObserver::m_fThreadProc(){
continue; // Error ocured but continue to next address
};
if( RetVal < 1 ){
+ //LOG("SLEEP");
SLEEP(DEFAULT_THREAD_SLEEP_TIME);
continue; // No Data - wait to next time
};
@@ -171,6 +174,7 @@ void argusModuleOnvifObserver::m_fThreadProc(){
LOG("Probe Finished with unrecognized data!");
#endif
};
+ continue; //To Fetch Another responces
} else {
#ifdef DEBUG
LOG("Probe Finished By Timeout!");
@@ -185,13 +189,13 @@ void argusModuleOnvifObserver::m_fThreadProc(){
m_bProbeIsActive = false;
//Sleep 5 minutes if done all scans
if ( m_bCurrentNIF == 0 ){
- for( int i=30000; i, m_bThreadStatus < TH_ENDED; i-- ) SLEEP( DEFAULT_THREAD_SLEEP_TIME );
+ for( int i=12000; i, m_bThreadStatus < TH_ENDED; i-- ) SLEEP( DEFAULT_THREAD_SLEEP_TIME );
};
} else {
// start new probe;
m_mNIFMUTEX.lock();
if ( m_vNIFIPS.size() ) {
-#ifdef DEBUG_EXTRA
+#ifdef DEBUG
sprintf( tB, "Starting probe on %s address", m_vNIFIPS.at(m_bCurrentNIF) );
LOG( tB );
#endif
@@ -203,9 +207,97 @@ void argusModuleOnvifObserver::m_fThreadProc(){
r_address.sin_addr.s_addr = inet_addr(m_vNIFIPS.at(m_bCurrentNIF));
bOptVal = true;
#ifdef DEBUG_EXTRA
- LOG("Sending Probe Request");
+ LOG("Set Broadcast Flag");
#endif
RetVal = setsockopt( socketFD, SOL_SOCKET, SO_BROADCAST, (char*)&bOptVal, bOptLen );
+ struct group_req req;
+ req.gr_interface = 0;
+ memcpy( &req.gr_group, &r_address, sizeof(r_address));
+ RetVal = setsockopt( socketFD, IPPROTO_IP, MCAST_JOIN_GROUP, (char*)&req, sizeof(req) );
+/*
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+// Join multicast group, support both IPv4 and IPv6. * @param sockfd socket descripter * @param grp sockaddr * @param grplen sockaddr length * @return 0:on success; non-zero:on failed
+static int mcast_join(int sockfd, const struct sockaddr *grp, socklen_t grplen){
+
+ #if MCAST_JOIN_GROUP
+ struct group_req req;
+ req.gr_interface = 0;
+ if (grplen > sizeof(req.gr_group)) {
+ errno = EINVAL;
+ return -1;
+ }
+ memcpy(&req.gr_group, grp, grplen);
+ return (setsockopt(sockfd, IPPROTO_IP, MCAST_JOIN_GROUP, &req, sizeof(req)));
+#else
+ switch (grp->sa_family) {
+ case AF_INET: {
+ struct ip_mreq mreq;
+ struct ifreq ifreq;
+ memcpy(&mreq.imr_multiaddr, &((const struct sockaddr_in *) grp)->sin_addr, sizeof(struct in_addr));
+ mreq.imr_interface.s_addr = htonl(INADDR_ANY);
+ return (setsockopt(sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
+ &mreq, sizeof(mreq)));
+ }
+ #ifdef IPV6
+ #ifndef IPV6_JOIN_GROUP // APIv0 compatibility
+ #define IPV6_JOIN_GROUP IPV6_ADD_MEMBERSHIP
+ #endif
+ case AF_INET6: {
+ struct ipv6_mreq mreq6;
+ memcpy(&mreq6.ipv6mr_multiaddr, &((const struct sockaddr_in6 *) grp)->sin6_addr, sizeof(struct in6_addr));
+ mreq6.ipv6mr_interface = 0;
+ return (setsockopt(sockfd, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq6, sizeof(mreq6)));
+ }
+ #endif
+ default:
+ errno = EAFNOSUPPORT;
+ return -1;
+ }
+#endif
+};
+
+int main(int argc, char **argv){
+
+ int fd = socket(AF_INET, SOCK_DGRAM, 0);
+ struct sockaddr_in grp;
+ bzero(&grp, sizeof(grp));
+ grp.sin_family = AF_INET;
+ grp.sin_addr.s_addr = inet_addr("224.0.0.1");;
+ if (mcast_join(fd, (struct sockaddr*)(&grp), sizeof(grp)))
+ perror("Join multicast group failed");
+}
+
+*/
+
+ //The broadcast address to be used may be determined by issuing an ioctl() with the SIOCGIFBRDADDR request.
+
+ if ( RetVal > -1 ) {
+ LOG_ERROR("Setting Socked as Broadcasted Error!");
+ };
+
+ //
+ struct sockaddr_in tServerAddr;
+ memset( &tServerAddr, 0, sizeof(tServerAddr) );
+ tServerAddr.sin_family = AF_INET; // IPv4
+ tServerAddr.sin_addr.s_addr = inet_addr( "0.0.0.0" ); //INADDR_ANY;
+ tServerAddr.sin_port = htons(rand( 20000, 40000));
+
+ // Bind the socket with the server address
+ RetVal = bind( socketFD, (const struct sockaddr *)&tServerAddr, sizeof(tServerAddr));
+ if ( RetVal > -1 ) {
+ LOG_ERROR("Bind Socked Error!");
+ };
+#ifdef DEBUG_EXTRA
+ LOG("Sending Probe Request");
+#endif
RetVal = sendto( socketFD, send_buff, strlen(send_buff), 0, (struct sockaddr*)&r_address, sizeof(struct sockaddr_in));
if ( RetVal > -1 ) {
#ifdef DEBUG_EXTRA
@@ -219,7 +311,7 @@ void argusModuleOnvifObserver::m_fThreadProc(){
u_long val = 1;
ioctlsocket( socketFD, FIONBIO, &val );//none block
#endif
- bCounterTO = 100;
+ bCounterTO = 600;
m_bProbeIsActive = true;
} else {
#ifdef DEBUG
@@ -270,11 +362,23 @@ bool argusModuleOnvifObserver::reloadSettings(){
#endif
argusHardwareManager *tHWM = m_pKernel->getHardwareManager();
if( tHWM != NULL ) {
+#ifdef DEBUG
+ LOG("Check IPS 11");
+#endif
DBC_INT_LIST *rIDS = tHWM->requestResourcesByType( ARGUS_HARDWARE_PROVIDER_NETWORK );
if( rIDS != NULL ) {
+#ifdef DEBUG
+ LOG("Check IPS 22");
+#endif
for( DBC_INT_LIST::iterator idx = rIDS->begin(); idx < rIDS->end(); idx++ ){
+#ifdef DEBUG
+ LOG("Check IPS 33");
+#endif
argusHardwareResourceNetwork *tRES = (argusHardwareResourceNetwork *) tHWM->requestResource( ARGUS_HARDWARE_PROVIDER_NETWORK, *idx );
if( tRES != NULL ) {
+#ifdef DEBUG
+ LOG("Have NIF Resource");
+#endif
CSTR BC = tRES->getBroadcast();
if( BC!= NULL ) {
#ifdef DEBUG
@@ -315,13 +419,13 @@ bool argusModuleOnvifObserver::reloadSettings(){
#endif
CSTR tBC = (CSTR) malloc(16);
if ( tBC ) {
- strncpy(tBC, HTTPMU_HOST_ADDRESS, 16);
+ sprintf(tBC, HTTPMU_HOST_ADDRESS );
m_mNIFMUTEX.lock();
m_vNIFIPS.push_back( tBC );
m_mNIFMUTEX.unlock();
} else {
LOG_ERROR("Malloc Error!");
- };
+ };
return true;
};
diff --git a/lib/rgoose/rgooseNode2D.cpp b/lib/rgoose/rgooseNode2D.cpp
index f8118829..3d4f02f3 100644
--- a/lib/rgoose/rgooseNode2D.cpp
+++ b/lib/rgoose/rgooseNode2D.cpp
@@ -2,6 +2,8 @@
#include "rgooseHardwareResourceSerialProvider.h"
#include "rgooseKernel.h"
+#define LGS_MAX_DETECTOR_RANGE 2047
+
#define LOG( X ) m_pLog->Log( "NODE2D", this, X )
#ifdef DEBUG
@@ -106,6 +108,7 @@ LPCTSTR m_pSetting[] =
*/
ARGUS_2DSensor::ARGUS_2DSensor( uint32_t id ):argusNodeSensor( id ), basicThread(), protocolLGS_2D(){
m_bWM = ANODE_WM_2D_BEFORE_START;
+ m_bOWM = ANODE_WM_2D_BEFORE_START;
m_eSensorClass = EVT_CLASS_SENSOR_LFS;
m_pLog = basicLogCollection::getInstance();
m_pEventHeap = basicEventHeap::getInstance();
@@ -115,6 +118,9 @@ ARGUS_2DSensor::ARGUS_2DSensor( uint32_t id ):argusNodeSensor( id ), basicThread
m_nProcessingCmdId = 0;
cleanupDeviceStructures();
memset( m_vDrawRanges, 0, sizeof( m_vDrawRanges ));
+ memset( &m_sShadowHelper, 0 , sizeof(SHADOW_IO_HELPER));
+ memset( &m_sShadow, 0 , sizeof(SHADOW));
+ memset( &m_sGetFileHelper, 0, sizeof(GETFILE_IO_HELPER));
if( m_sLRF_DATA.uart_id ) {
DBC_UART_DATA *tUART = NULL;
tUART = m_pDBC->getUartData( m_sLRF_DATA.uart_id );
@@ -135,8 +141,24 @@ void ARGUS_2DSensor::cleanupDeviceStructures( void ){
m_bOpRetryCnt = 3;
memset( m_tSN, 0, 33 );
memset( m_tSV, 0, 65 );
+ cleanShadowStructs();
+ if (m_sGetFileHelper.fd!= NULL ) {
+ fclose( m_sGetFileHelper.fd );
+ };
+ memset( &m_sGetFileHelper, 0, sizeof(GETFILE_IO_HELPER));
m_bSerialStringValid = false;
m_bVersionStringValid = false;
+
+};
+
+void ARGUS_2DSensor::cleanShadowStructs(){
+ if ( m_sShadow.pPolygones ) {
+ for (int i = 0; i < m_sShadow.m_nPolygonCount; i++) if (m_sShadow.pPolygones[i].pPoint) free( m_sShadow.pPolygones[i].pPoint );
+ free(m_sShadow.pPolygones);
+ };
+ for (int i = 0; i < 360; i++) if (m_sShadow.ray_lines[i].rays) free(m_sShadow.ray_lines[i].rays );
+ memset(&m_sShadow, 0, sizeof(SHADOW));
+ memset(&m_sShadowHelper, 0, sizeof(SHADOW_IO_HELPER));
};
ARGUS_2DSensor::~ARGUS_2DSensor(){
@@ -174,12 +196,13 @@ bool ARGUS_2DSensor::startService() {
// LOG_ERROR("Position <<< Create >>> Failure!");
// return false;
//};
+
systemAnchor * SA = systemAnchor::getInstance();
if( SA ){
LOG("SysAnchor OK");
if ( SA->beLocal() ) {
LOG("SysAnchor beLocal!");
- m_oPosition.setPositionXYZ( m_sLRF_DATA.x, m_sLRF_DATA.y, m_sLRF_DATA.z, SA->getUTMZone() );
+ m_oPosition.setPositionXYZ( m_sLRF_DATA.x, m_sLRF_DATA.y, m_sLRF_DATA.z, 0 ); //SA->getUTMZone() );
m_oPosition.setOrientationDeg( m_sLRF_DATA.x_rot , m_sLRF_DATA.y_rot, m_sLRF_DATA.z_rot );
} else {
LOG("SysAnchor is Global Position System!");
@@ -192,11 +215,19 @@ bool ARGUS_2DSensor::startService() {
m_oPosition.setPositionXYZ( m_sLRF_DATA.x , m_sLRF_DATA.y, m_sLRF_DATA.z );
m_oPosition.setOrientationDeg( m_sLRF_DATA.x_rot , m_sLRF_DATA.y_rot, m_sLRF_DATA.z_rot );
};
+ m_oPosition.updateMatrix();
char tB[128];
+#ifdef DEBUG
+ sprintf( tB, "Data Pos: %.4f %.4f %.4f", m_sLRF_DATA.x, m_sLRF_DATA.y, m_sLRF_DATA.z );
+ LOG( tB );
+ sprintf( tB, "Data Pos: %.4f %.4f %.4f", m_sLRF_DATA.x_rot, m_sLRF_DATA.y_rot, m_sLRF_DATA.z_rot );
+ LOG( tB );
+#endif
sprintf( tB, "Sensor Position: %.4f %.4f %.4f", m_oPosition.getLat(), m_oPosition.getLon(), m_oPosition.getAlt() );
LOG( tB );
-
+ sprintf( tB, "Sensor Orientation: %.4f %.4f %.4f", m_oPosition.getRotX_deg() , m_oPosition.getRotY_deg(), m_oPosition.getRotZ_deg() );
+ LOG( tB );
if( m_sLRF_DATA.filter_id > 0 ) {
LOG("DEFINED FILTER");
argusKernel *AK = argusKernel::getInstance();
@@ -213,6 +244,7 @@ bool ARGUS_2DSensor::stopService() {
m_mWMProtector.unlock();
waitThreadEnd( true );
m_pDBC->setNodeOffline( m_sNodeData.node_id );
+ cleanupDeviceStructures();
return true;
};
@@ -258,7 +290,47 @@ bool ARGUS_2DSensor::validate(){
tNCMD->db_cmd = tCMD->id;
tNCMD->parameter = NULL;
enqueueCommand( tNCMD );
- }
+ };
+ break;
+ };
+ case ARGUS_LRF_PCMD_SET_DP_0:{
+ NODE_COMMAND *tNCMD = (NODE_COMMAND *) malloc( sizeof(NODE_COMMAND));
+ if (tNCMD) {
+ tNCMD->cmd = NODE_CMD_UPLOAD_SETTINGS_0;
+ tNCMD->db_cmd = tCMD->id;
+ tNCMD->parameter = NULL;
+ enqueueCommand( tNCMD );
+ };
+ break;
+ };
+ case ARGUS_LRF_PCMD_SET_DP_1:{
+ NODE_COMMAND *tNCMD = (NODE_COMMAND *) malloc( sizeof(NODE_COMMAND));
+ if (tNCMD) {
+ tNCMD->cmd = NODE_CMD_UPLOAD_SETTINGS_1;
+ tNCMD->db_cmd = tCMD->id;
+ tNCMD->parameter = NULL;
+ enqueueCommand( tNCMD );
+ };
+ break;
+ };
+ case ARGUS_LRF_PCMD_SET_DP_2:{
+ NODE_COMMAND *tNCMD = (NODE_COMMAND *) malloc( sizeof(NODE_COMMAND));
+ if (tNCMD) {
+ tNCMD->cmd = NODE_CMD_UPLOAD_SETTINGS_2;
+ tNCMD->db_cmd = tCMD->id;
+ tNCMD->parameter = NULL;
+ enqueueCommand( tNCMD );
+ };
+ break;
+ };
+ case ARGUS_LRF_PCMD_SET_DP_3:{
+ NODE_COMMAND *tNCMD = (NODE_COMMAND *) malloc( sizeof(NODE_COMMAND));
+ if (tNCMD) {
+ tNCMD->cmd = NODE_CMD_UPLOAD_SETTINGS_3;
+ tNCMD->db_cmd = tCMD->id;
+ tNCMD->parameter = NULL;
+ enqueueCommand( tNCMD );
+ };
break;
};
case ARGUS_LRF_PCMD_UPLOAD_FILE:{
@@ -334,6 +406,19 @@ bool ARGUS_2DSensor::validate(){
#endif
break;
};
+ case NODE_CMD_UPDATE_SHADOW:{
+ LOG("Update Shadow CMD!");
+ if (tCMD->CMD) m_nProcessingCmdId = tCMD->id; else m_nProcessingCmdId = 0;
+ cleanShadowStructs();
+ if( m_pDBC->fillShadow2D( m_sNodeData.aux_id, m_sShadow ) ){
+ LOG("Loadded From DB");
+ if( rasterizeShadow() ){
+ LOG("Mask is Rasterized");
+ setWM( ANODE_WM_2D_SET_MASK_INFO );
+ };
+ };
+ break;
+ };
default:
m_pDBC->updateNodePushedCMD( tCMD->id, DBC_CMD_FINISHED );
};
@@ -407,8 +492,8 @@ void ARGUS_2DSensor::m_fThreadProc( void ){
LOG_ERROR("Fall Back to Disconnected!");
} else {
// Cleanup Current data;
- setWM( ANODE_WM_2D_WAIT_CONNECT );
cleanupDeviceStructures();
+ setWM( ANODE_WM_2D_WAIT_CONNECT );
};
break;
};
@@ -421,118 +506,182 @@ void ARGUS_2DSensor::m_fThreadProc( void ){
break;
};
case ANODE_WM_2D_SET_INIT_MODE:{
- m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
if( !setMode(MODE_DETECTOR) ) {
m_pDBC->setNodeOffline( m_sNodeData.node_id );
LOG_ERROR("Fall Back to Disconnected!");
setWM( ANODE_WM_2D_CREATE_PORT );
- } else setWM( ANODE_WM_2D_WAIT_INIT_MODE );
- break;
- };
- case ANODE_WM_2D_WAIT_INIT_MODE:{
- if(( m_bTimeOutCounter-- )==0 ){
- LOG_ERROR("Communication TO!");
- setWM( ANODE_WM_2D_SET_INIT_MODE );
- };
+ } else setWM( ANODE_WM_2D_WAIT_DEVICE_REPLAY );
break;
};
case ANODE_WM_2D_GET_SERIAL_NUM:{
- m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
if( !getSerialNumber() ) {
LOG_ERROR("Fall Back to Disconnected!");
setWM( ANODE_WM_2D_CREATE_PORT );
- } else setWM( ANODE_WM_2D_WAIT_SERIAL_NUM );
- break;
- };
- case ANODE_WM_2D_WAIT_SERIAL_NUM:{
- if(( m_bTimeOutCounter-- )==0 ){
- LOG_ERROR("Communication TO!");
- setWM( ANODE_WM_2D_GET_SERIAL_NUM );
- };
+ } else setWM( ANODE_WM_2D_WAIT_DEVICE_REPLAY );
break;
};
case ANODE_WM_2D_GET_VERSION:{
- m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
if( !getVersionString() ) {
LOG_ERROR("Fall Back to Disconnected!");
setWM( ANODE_WM_2D_CREATE_PORT );
- } else setWM( ANODE_WM_2D_WAIT_VERSION );
- break;
- };
- case ANODE_WM_2D_WAIT_VERSION:{
- if(( m_bTimeOutCounter-- )==0 ){
- LOG_ERROR("Communication TO!");
- setWM( ANODE_WM_2D_GET_VERSION );
- };
+ } else setWM( ANODE_WM_2D_WAIT_DEVICE_REPLAY );
break;
};
case ANODE_WM_2D_GET_DETECTION_PROFILE:{
- m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
if( !getDetectionProfile() ) {
LOG_ERROR("Fall Back to Disconnected!");
setWM( ANODE_WM_2D_CREATE_PORT );
- } else setWM( ANODE_WM_2D_WAIT_DETECTION_PROFILE );
+ } else setWM( ANODE_WM_2D_WAIT_DEVICE_REPLAY );
break;
};
- case ANODE_WM_2D_WAIT_DETECTION_PROFILE:{
- if(( m_bTimeOutCounter-- )==0 ){
- LOG_ERROR("Communication TO!");
- setWM( ANODE_WM_2D_GET_DETECTION_PROFILE );
- };
+ case ANODE_WM_2D_GET_MASTER_PARAM:{
+ if( !getParameters( true ) ) {
+ LOG_ERROR("Fall Back to Disconnected!");
+ setWM( ANODE_WM_2D_CREATE_PORT );
+ } else setWM( ANODE_WM_2D_WAIT_DEVICE_REPLAY );
break;
};
- case ANODE_WM_2D_GET_MASTER_PARAM:{
- //Get Master Settings
+ case ANODE_WM_2D_GET_SLAVE_PARAM:{
+ if( !getParameters( false ) ) {
+ LOG_ERROR("Fall Back to Disconnected!");
+ setWM( ANODE_WM_2D_CREATE_PORT );
+ } else setWM( ANODE_WM_2D_WAIT_DEVICE_REPLAY );
+ break;
+ };
+ //Masks!
+ case ANODE_WM_2D_GET_MASK_INFO:{
+ if( !getShadowInfo() ) {
+ LOG_ERROR("Fall Back to Disconnected!");
+ setWM( ANODE_WM_2D_CREATE_PORT );
+ } else setWM( ANODE_WM_2D_WAIT_DEVICE_REPLAY );
+ break;
+ };
+ case ANODE_WM_2D_GET_SHADOW_POLY_INFO:{
+ if (!getShadowPoly( m_sShadowHelper.m_nCurrentPolygon )) {
+ LOG_ERROR("Fall Back to Disconnected!");
+ setWM( ANODE_WM_2D_CREATE_PORT );
+ } else setWM( ANODE_WM_2D_WAIT_DEVICE_REPLAY );
+ break;
+ };
+ case ANODE_WM_2D_GET_SHADOW_POLY_POINT:{
m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
- if( !getParameters( true ) ) {
+ if (!getShadowPolyPoint(m_sShadowHelper.m_nCurrentPolygon, m_sShadowHelper.m_nCurrentPoint)) {
LOG_ERROR("Fall Back to Disconnected!");
setWM( ANODE_WM_2D_CREATE_PORT );
- } else setWM( ANODE_WM_2D_WAIT_MASTER_PARAM );
+ } else setWM( ANODE_WM_2D_WAIT_DEVICE_REPLAY );
break;
};
- case ANODE_WM_2D_WAIT_MASTER_PARAM:{
- //Wait Settings
- if((m_bTimeOutCounter--)==0){
- LOG_ERROR("Communication TO!");
- setWM( ANODE_WM_2D_GET_MASTER_PARAM );
+ case ANODE_WM_2D_SET_MASK_INFO:{
+ if (!setShadowInfo( m_sShadow )) {
+ LOG_ERROR("Fall Back to Disconnected!");
+ setWM( ANODE_WM_2D_CREATE_PORT );
+ } else setWM( ANODE_WM_2D_WAIT_DEVICE_REPLAY );
+ break;
+ };
+ case ANODE_WM_2D_SET_SHADOW_POLY_INFO:{
+ if(!setShadowPoly(m_sShadow, m_sShadowHelper.m_nCurrentPolygon)){
+ LOG_ERROR("Fall Back to Disconnected!");
+ setWM( ANODE_WM_2D_CREATE_PORT );
+ } else{
+ setWM( ANODE_WM_2D_WAIT_DEVICE_REPLAY );
+ //while( m_bWM == ANODE_WM_2D_WAIT_DEVICE_REPLAY ) SLEEP(1);
+ //continue;
};
break;
};
- case ANODE_WM_2D_GET_SLAVE_PARAM:{
- //Get Slave Settings
- m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
- if( !getParameters( false ) ) {
+ case ANODE_WM_2D_SET_SHADOW_POLY_POINT:{
+ if (!setShadowPolyPoint(m_sShadow, m_sShadowHelper.m_nCurrentPolygon, m_sShadowHelper.m_nCurrentPoint)) {
LOG_ERROR("Fall Back to Disconnected!");
setWM( ANODE_WM_2D_CREATE_PORT );
- } else setWM( ANODE_WM_2D_WAIT_SLAVE_PARAM );
+ } else{
+ setWM( ANODE_WM_2D_WAIT_DEVICE_REPLAY );
+ //while( m_bWM == ANODE_WM_2D_WAIT_DEVICE_REPLAY ) SLEEP(1);
+ //continue;
+ };
break;
};
- case ANODE_WM_2D_WAIT_SLAVE_PARAM:{
- //Wait Settings
- if((m_bTimeOutCounter--)==0){
- LOG_ERROR("Communication TO!");
- setWM( ANODE_WM_2D_GET_SLAVE_PARAM );
+ case ANODE_WM_2D_SET_SHADOW_RAY_LINE:{
+ if (!setShadowRayLine(m_sShadow, m_sShadowHelper.m_nCurrentRayLine )) {
+ LOG_ERROR("Fall Back to Disconnected!");
+ setWM( ANODE_WM_2D_CREATE_PORT );
+ } else {
+ setWM( ANODE_WM_2D_WAIT_DEVICE_REPLAY );
+ //while( m_bWM == ANODE_WM_2D_WAIT_DEVICE_REPLAY ) SLEEP(1);
+ //continue;
};
break;
};
- case ANODE_WM_2D_SET_BORDER_MODE:{
- m_nSleepTime = LGS_DEFAULT_SLEEP_TIME;
- m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
- if( !setMode( MODE_BORDER )){
+ case ANODE_WM_2D_SET_SHADOW_RAY:{
+ if (!setShadowRay(m_sShadow, m_sShadowHelper.m_nCurrentRayLine, m_sShadowHelper.m_nCurrentRay )) {
LOG_ERROR("Fall Back to Disconnected!");
setWM( ANODE_WM_2D_CREATE_PORT );
- } else setWM( ANODE_WM_2D_WAIT_BORDER_MODE );
+ } else {
+ setWM( ANODE_WM_2D_WAIT_DEVICE_REPLAY );
+ //while( m_bWM == ANODE_WM_2D_WAIT_DEVICE_REPLAY ) SLEEP(1);
+ //continue;
+ };
break;
};
- case ANODE_WM_2D_WAIT_BORDER_MODE:{
- if((m_bTimeOutCounter--)==0){
- if( m_bOpRetryCnt-- ){
- setWM( ANODE_WM_2D_SET_BORDER_MODE );
- } else {
- LOG_ERROR("Communication TO!");
- setWM( ANODE_WM_2D_SET_BORDER_MODE );
+ case ANODE_WM_2D_SET_SHADOW_DONE:{
+ if (!setShadowDone()) {
+ LOG_ERROR("Fall Back to Disconnected!");
+ setWM( ANODE_WM_2D_CREATE_PORT );
+ } else setWM( ANODE_WM_2D_WAIT_DEVICE_REPLAY );
+ break;
+ };
+ case ANODE_WM_2D_SET_GETFILE_MODE:{
+ if (!setMode( MODE_GETFILE )) {
+ LOG_ERROR("Fall Back to Disconnected!");
+ setWM( ANODE_WM_2D_CREATE_PORT );
+ } else setWM( ANODE_WM_2D_WAIT_DEVICE_REPLAY );
+ break;
+ };
+ case ANODE_WM_2D_SEND_GETFILE_MODE:{
+ switch( m_sGetFileHelper.state ) {
+ case GF_OP_OK:{
+ m_sGetFileHelper.fd = fopen( m_sGetFileHelper.sourceName, "rb" );
+ if ( m_sGetFileHelper.fd ) {
+ m_sGetFileHelper.state = GF_OP_OPEN;
+ m_sGetFileHelper.data_size = strlen(m_sGetFileHelper.destName);
+ memcpy( m_sGetFileHelper.data, m_sGetFileHelper.destName, m_sGetFileHelper.data_size );
+ } else {
+ memset( &m_sGetFileHelper, 0, sizeof( GETFILE_IO_HELPER ));
+ setWM( ANODE_WM_2D_SET_DETECTION_MODE );
+ continue;
+ };
+ break;
+ };
+ case GF_OP_OPEN:{
+ m_sGetFileHelper.state = GF_OP_DATA;
+ m_sGetFileHelper.data_size = fread(m_sGetFileHelper.data, 1, 250, m_sGetFileHelper.fd);
+ break;
+ };
+ case GF_OP_DATA:{
+ m_sGetFileHelper.data_size = fread(m_sGetFileHelper.data, 1, 250, m_sGetFileHelper.fd);
+ if ( m_sGetFileHelper.data_size == 0 || feof( m_sGetFileHelper.fd )) {
+ m_sGetFileHelper.state = GF_OP_CLOSE;
+ continue;
+ };
+ break;
+ };
+ case GF_OP_CLOSE:{
+ m_sGetFileHelper.data_size = 0;
+ fclose( m_sGetFileHelper.fd );
+ break;
};
};
+ if ( !sendGF_package( m_sGetFileHelper.state, m_sGetFileHelper.data_size, m_sGetFileHelper.data )) {
+ LOG_ERROR("Fall Back to Disconnected!");
+ setWM( ANODE_WM_2D_CREATE_PORT );
+ } else setWM( ANODE_WM_2D_WAIT_DEVICE_REPLAY );
+ break;
+ };
+ case ANODE_WM_2D_SET_BORDER_MODE:{
+ m_nSleepTime = LGS_DEFAULT_SLEEP_TIME;
+ if( !setMode( MODE_BORDER )){
+ LOG_ERROR("Fall Back to Disconnected!");
+ setWM( ANODE_WM_2D_CREATE_PORT );
+ } else setWM( ANODE_WM_2D_WAIT_DEVICE_REPLAY );
break;
};
case ANODE_WM_2D_GET_FAST_DRAW:{
@@ -540,103 +689,96 @@ void ARGUS_2DSensor::m_fThreadProc( void ){
setWM( ANODE_WM_2D_SET_BORDER_MODE );
} else {
m_nSleepTime = LGS_DEFAULT_SLEEP_TIME;
- m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
if( !getFastDraw( m_nCurrentAngle ) ) {
LOG_ERROR("Fall Back to Disconnected!");
setWM( ANODE_WM_2D_CREATE_PORT );
} else {
m_nSleepTime = LGS_ALERT_SLEEP_TIME;
- setWM( ANODE_WM_2D_WAIT_FAST_DRAW );
+ setWM( ANODE_WM_2D_WAIT_DEVICE_REPLAY );
};
}
break;
};
- case ANODE_WM_2D_WAIT_FAST_DRAW:{
- if((m_bTimeOutCounter--)==0){
- if( m_bOpRetryCnt-- ){
- setWM( ANODE_WM_2D_GET_FAST_DRAW );
- } else {
- LOG_ERROR("Waited Angle Draw Communication TO!");
- m_nCurrentAngle = 0;
- setWM( ANODE_WM_2D_SET_DETECTION_MODE );
- };
- };
- break;
- };
case ANODE_WM_2D_SET_DETECTION_MODE:{
- m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
m_nSleepTime = LGS_DEFAULT_SLEEP_TIME;
if( !setMode(MODE_DETECTOR)) {
LOG_ERROR("Fall Back to Disconnected!");
setWM( ANODE_WM_2D_CREATE_PORT );
- } else setWM( ANODE_WM_2D_WAIT_DETECTION_MODE );
- break;
- };
- case ANODE_WM_2D_WAIT_DETECTION_MODE:{
- if((m_bTimeOutCounter--)==0){
- LOG_ERROR("Communication TO!");
- setWM( ANODE_WM_2D_SET_DETECTION_MODE );
- };
+ } else setWM( ANODE_WM_2D_WAIT_DEVICE_REPLAY );
break;
};
case ANODE_WM_2D_SET_FILESYSTEM_MODE:{
- m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
if( !setMode(MODE_FILESYSTEM)) {
LOG_ERROR("Fall Back to Disconnected!");
setWM( ANODE_WM_2D_CREATE_PORT );
- } else setWM( ANODE_WM_2D_WAIT_FILESYSTEM_MODE );
- break;
- };
- case ANODE_WM_2D_WAIT_FILESYSTEM_MODE:{
- if((m_bTimeOutCounter--)==0){
- LOG_ERROR("Communication TO!");
- setWM( ANODE_WM_2D_SET_FILESYSTEM_MODE );
- };
+ } else setWM( ANODE_WM_2D_WAIT_DEVICE_REPLAY );
break;
};
case ANODE_WM_2D_FS_TRANSFER_MODE:{
-
+
break;
};
// Special Mode - Push COMMMANDS
-
+ case ANODE_WM_2D_SET_MASTER_PARAM:{
+ PLGS_2D_PARAMETERS tData = m_pDBC->getLRFDetectionProfile( m_sNodeData.aux_id, m_nActiveDetectionProfile, true );
+ if ( tData ) {
+ if (!setParameters( tData, true, m_nActiveDetectionProfile)) {
+ LOG_ERROR("Fall Back to Disconnected!");
+ setWM( ANODE_WM_2D_CREATE_PORT );
+ } else setWM( ANODE_WM_2D_WAIT_DEVICE_REPLAY );
+ free( tData );
+ } else setWM( ANODE_WM_2D_PING );
+ break;
+ };
+ case ANODE_WM_2D_SET_SLAVE_PARAM:{
+ PLGS_2D_PARAMETERS tData = m_pDBC->getLRFDetectionProfile( m_sNodeData.aux_id, m_nActiveDetectionProfile, false );
+ if ( tData ) {
+ if (!setParameters( tData, false, m_nActiveDetectionProfile)) {
+ LOG_ERROR("Fall Back to Disconnected!");
+ setWM( ANODE_WM_2D_CREATE_PORT );
+ } else setWM( ANODE_WM_2D_WAIT_DEVICE_REPLAY );
+ free( tData );
+ } else setWM( ANODE_WM_2D_PING );
+ break;
+ };
case ANODE_WM_2D_ISSUE_FULL_RESET:{
- m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
if( !doFullReset()) {
LOG_ERROR("Fall Back to Disconnected!");
setWM( ANODE_WM_2D_CREATE_PORT );
- } else setWM( ANODE_WM_2D_WAIT_FULL_RESET );
+ } else setWM( ANODE_WM_2D_WAIT_DEVICE_REPLAY );
break;
};
- case ANODE_WM_2D_WAIT_FULL_RESET:{
- if((m_bTimeOutCounter--)==0){
- LOG_ERROR("Communication TO! After Reset-> Go Connect!");
- setWM( ANODE_WM_2D_CONNECT );
- };
- break;
- };
-
case ANODE_WM_2D_ISSUE_RESET:{
- m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
if( !doReset()) {
LOG_ERROR("Fall Back to Disconnected!");
setWM( ANODE_WM_2D_CREATE_PORT );
- } else setWM( ANODE_WM_2D_WAIT_RESET );
+ } else setWM( ANODE_WM_2D_WAIT_DEVICE_REPLAY );
break;
};
-
- case ANODE_WM_2D_WAIT_RESET:{
- if((m_bTimeOutCounter--)==0){
- LOG_ERROR("Communication TO! After Reset-> Go Connect!");
- setWM( ANODE_WM_2D_CONNECT );
+ case ANODE_WM_2D_WAIT_DEVICE_REPLAY:
+ m_bOpRetryCnt = 3;
+ m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
+ m_bWM = ANODE_WM_2D_WAIT_CHECK_REPLAY;
+ case ANODE_WM_2D_WAIT_CHECK_REPLAY:{
+ if(( --m_bTimeOutCounter )==0 ){
+#ifdef DEBUG_EXTRA
+ LOG_ERROR("Communication TO!");
+#endif
+ if( --m_bOpRetryCnt ){
+ setWM( m_bOWM );
+ } else {
+ setWM( ANODE_WM_2D_CONNECT );//ANODE_WM_2D_CREATE_PORT );
+ };
};
break;
};
-
// Idle Work
case ANODE_WM_2D_PING:{
m_bTimeOutCounter = LGS_DEFAULT_TO_COUNTER;
if( NODE_COMMAND * tCMD = fetchCommand() ) {
+#ifdef DEBUG
+ LOG("fetched cmd");
+#endif
switch( tCMD->cmd ) {
case NODE_CMD_FULL_RESET:{
if( tCMD->db_cmd ) m_nProcessingCmdId = tCMD->db_cmd; else m_nProcessingCmdId = 0;
@@ -659,6 +801,12 @@ void ARGUS_2DSensor::m_fThreadProc( void ){
setWM( ANODE_WM_2D_SET_BORDER_MODE );
break;
};
+ case NODE_CMD_UPLOAD_SETTINGS_0:{
+ if( tCMD->db_cmd ) m_nProcessingCmdId = tCMD->db_cmd; else m_nProcessingCmdId = 0;
+ m_nActiveDetectionProfile = 0;
+ setWM( ANODE_WM_2D_SET_MASTER_PARAM );
+ break;
+ };
case NODE_CMD_ROI_ACTIVE:{
uint16_t AZ, RANGE, WIDTH;
uint8_t LRFID = 0;
@@ -701,7 +849,7 @@ void ARGUS_2DSensor::m_fThreadProc( void ){
setWM( ANODE_WM_2D_PING );
} else {
LOG_ERROR("Communication TO!");
- setWM( ANODE_WM_2D_PING );
+ setWM( ANODE_WM_2D_CONNECT );
};
};
break;
@@ -739,6 +887,7 @@ uint8_t ARGUS_2DSensor::getWM( void ){
void ARGUS_2DSensor::setWM( uint8_t MD ){
m_mWMProtector.lock();
+ m_bOWM = m_bWM;
m_bWM = MD;
m_mWMProtector.unlock();
};
@@ -777,17 +926,15 @@ bool ARGUS_2DSensor::packetHandler( protocolPackage *Package ){
break;
};
case CMD_BORDER:{
- if ( getWM() == ANODE_WM_2D_WAIT_FAST_DRAW ) {
+ //if( m_bOWM == ANODE_WM_2D_GET_FAST_DRAW ){
m_bOpRetryCnt = 3;
- if ((Package->m_pData[SUB_CMD_IDX] & 0xC0) == 0x00) {
+ if ((Package->m_pData[SUB_CMD_IDX] & BD_ERRORMASK) == 0x00) {
uint16_t AZ;
uint16_t RANGE_A;
uint16_t RANGE_B;
AZ = ( ( ( Package->m_pData[SUB_CMD_IDX] & 0x10 ) >> 4 ) << 8 ) | Package->m_pData[5];
RANGE_A = ( ( ( Package->m_pData[SUB_CMD_IDX] & 0x0C ) >> 2 ) << 8 ) | Package->m_pData[6];
RANGE_B = ( ( Package->m_pData[SUB_CMD_IDX] & 0x03 ) << 8 ) | Package->m_pData[7];
- //sprintf( tBuff, "B[%d]>", AZ );
- //LOG( tBuff );
if( AZ < 359 ) {
m_vDrawRanges[m_nCurrentAngle]=( RANGE_A << 16 ) | RANGE_B;
m_nCurrentAngle = AZ+1;
@@ -807,34 +954,41 @@ bool ARGUS_2DSensor::packetHandler( protocolPackage *Package ){
};
};
} else {
- if( Package->m_pData[SUB_CMD_IDX] == 0x80 ) {
- LOG("ERR Data Not Ready");
- // Data Not Ready
- m_nCurrentAngle = 0;
- //check WM
- setWM( ANODE_WM_2D_GET_FAST_DRAW );
- } else {
- LOG("ERR REQ AZ");
- // Error Requested Angle
- setWM( ANODE_WM_2D_PING );
+ switch((Package->m_pData[SUB_CMD_IDX] & BD_ERRORMASK)){
+ case BD_NOTREADY: {
+ // Data Not Ready
+ m_nCurrentAngle = 0;
+ //check WM
+ setWM( ANODE_WM_2D_GET_FAST_DRAW );
+ break;
+ };
+ case BD_ERRORANGLE:{
+ // Error Requested Angle
+ setWM( ANODE_WM_2D_PING );
+ break;
+ };
+ case BD_ERRORMODE:{
+ setWM( ANODE_WM_2D_PING );
+ break;
+ };
};
};
- } else {
- LOG("ERR Wrong Mode!");
- setWM( ANODE_WM_2D_SET_DETECTION_MODE );
- m_nCurrentAngle = 0;
- };
+ //} else {
+ // LOG("ERR Wrong Mode!");
+ // setWM( ANODE_WM_2D_SET_DETECTION_MODE );
+ // m_nCurrentAngle = 0;
+ //};
break;
};
case CMD_MODE:{
m_bDeviceWM = Package->m_pData[SUB_CMD_IDX];
uint8_t tCWD = getWM();
#ifdef DEBUG
- sprintf( tBuff, "CWD:%d Remote Mode:[0x%02X] Current Device Mode: 0x%02X", tCWD, m_bWM, m_bDeviceWM );
+ sprintf( tBuff, "Working Mode:0x%02X Real Mode:0x%02X Virtual Mode:0x%02X", tCWD, m_bWM, m_bDeviceWM );
LOG( tBuff );
#endif
- switch( tCWD ) {
- case ANODE_WM_2D_WAIT_CONNECT:{
+ switch( m_bOWM ) {
+ case ANODE_WM_2D_CONNECT:{
// Initial Connection
m_pDBC->setNodeOnline( m_sNodeData.node_id, ARGUS_NODE_STATUS_INIT );
if( m_bDeviceWM != MODE_DETECTOR ) {
@@ -844,7 +998,7 @@ bool ARGUS_2DSensor::packetHandler( protocolPackage *Package ){
};
break;
};
- case ANODE_WM_2D_WAIT_INIT_MODE:{
+ case ANODE_WM_2D_SET_INIT_MODE:{
if( m_bDeviceWM != MODE_DETECTOR ) {
setWM( ANODE_WM_2D_SET_INIT_MODE );
} else {
@@ -852,17 +1006,17 @@ bool ARGUS_2DSensor::packetHandler( protocolPackage *Package ){
};
break;
};
- case ANODE_WM_2D_WAIT_BORDER_MODE:{
+ case ANODE_WM_2D_SET_BORDER_MODE:{
if( m_bDeviceWM == MODE_BORDER ) {
+ m_nCurrentAngle = 0;
setWM( ANODE_WM_2D_GET_FAST_DRAW );
//m_nSleepTime = LGS_ALERT_SLEEP_TIME;
- m_nCurrentAngle = 0;
} else {
setWM( ANODE_WM_2D_SET_BORDER_MODE );
};
break;
};
- case ANODE_WM_2D_WAIT_DETECTION_MODE:{
+ case ANODE_WM_2D_SET_DETECTION_MODE:{
if( m_bDeviceWM == MODE_DETECTOR ) {
setWM( ANODE_WM_2D_PING );
m_nSleepTime = LGS_DEFAULT_SLEEP_TIME;
@@ -874,7 +1028,7 @@ bool ARGUS_2DSensor::packetHandler( protocolPackage *Package ){
};
break;
};
- case ANODE_WM_2D_WAIT_FILESYSTEM_MODE:{
+ case ANODE_WM_2D_SET_FILESYSTEM_MODE:{
if( m_bDeviceWM == MODE_FILESYSTEM ) {
setWM( ANODE_WM_2D_FS_TRANSFER_MODE );
m_nSleepTime = LGS_DEFAULT_SLEEP_TIME;
@@ -887,6 +1041,18 @@ bool ARGUS_2DSensor::packetHandler( protocolPackage *Package ){
};
break;
};
+ case ANODE_WM_2D_SET_GETFILE_MODE:{
+ if ( m_bDeviceWM == MODE_GETFILE ) {
+ if( m_sGetFileHelper.state == GF_OP_OK ) {
+ setWM( ANODE_WM_2D_SEND_GETFILE_MODE );
+ } else {
+ setWM( ANODE_WM_2D_SET_DETECTION_MODE );
+ };
+ } else {
+ setWM( ANODE_WM_2D_SET_GETFILE_MODE );
+ };
+ break;
+ };
};
break;
};
@@ -989,59 +1155,77 @@ bool ARGUS_2DSensor::packetHandler( protocolPackage *Package ){
#ifdef DEBUG
LOG("CMD_UNSUPPORTED");
#endif
- switch( getWM() ) {
- case ANODE_WM_2D_WAIT_DETECTION_PROFILE:{
+ switch( m_bOWM ) {
+ case ANODE_WM_2D_GET_DETECTION_PROFILE:{
//m_bMultiProfileSupported = false;
m_nActiveDetectionProfile = 0;
setWM( ANODE_WM_2D_GET_MASTER_PARAM );
break;
};
+ default:
+ setWM( ANODE_WM_2D_PING );
+ break;
};
break;
};
- case CMD_PARAMETERS:
- case CMD_GET_PARAMETERS:
- case CMD_SET_PARAMETERS:{
- LGS_2D_PARAMETERS tParams;
- //RaspberyPi - not Intel - cannot copy
- //memcpy( &tParams, Package->m_pData + DATA_BEGIN_IDX, sizeof( LGS_2D_PARAMETERS ) );
- tParams.nOrder = ( Package->m_pData[5] << 8 ) | Package->m_pData[6];
- tParams.nOffset = ( Package->m_pData[7] << 8 ) | Package->m_pData[8];
- tParams.nDelta = ( Package->m_pData[9] << 8 ) | Package->m_pData[10];
- tParams.nWidth = ( Package->m_pData[11] << 8 ) | Package->m_pData[12];
- tParams.nFlip = ( Package->m_pData[13] << 8 ) | Package->m_pData[14];
- tParams.nSun = ( Package->m_pData[15] << 8 ) | Package->m_pData[16];
- tParams.bSST = Package->m_pData[17];
-
- if( Package->m_pData[SUB_CMD_IDX] == 0x80 ) {
-#ifdef DEBUG
- LOG("CMD MASTER PARAMETERS");
-#endif
- //m_pDBC->updateMasterDetectorLRF( m_sNodeData.aux_id, tParams.nOrder, tParams.nOffset, tParams.nDelta, tParams.nWidth, tParams.nFlip, tParams.nSun, tParams.bSST );
- setWM( ANODE_WM_2D_GET_SLAVE_PARAM );
- } else {
-#ifdef DEBUG
- LOG("CMD SLAVE PARAMETERS");
-#endif
- //m_pDBC->updateSlaveDetectorLRF( m_sNodeData.aux_id, tParams.nOrder, tParams.nOffset, tParams.nDelta, tParams.nWidth, tParams.nFlip, tParams.nSun, tParams.bSST );
- setWM( ANODE_WM_2D_PING );
- };
-#ifdef DEBUG
- sprintf(tBuff, " SST:\t%d", tParams.bSST );
- LOG(tBuff);
- sprintf(tBuff, " DELTA:\t%d", tParams.nDelta );
- LOG(tBuff);
- sprintf(tBuff, " Flip:\t%d", tParams.nFlip );
- LOG(tBuff);
- sprintf(tBuff, " OFFSET:\t%d", tParams.nOffset );
- LOG(tBuff);
- sprintf(tBuff, " ORDER:\t%d", tParams.nOrder );
- LOG(tBuff);
- sprintf(tBuff, " SUN:\t%d", tParams.nSun );
- LOG(tBuff);
- sprintf(tBuff, " WIDTH:\t%d", tParams.nWidth );
- LOG(tBuff);
-#endif
+ case CMD_PARAMETERS:{
+ LOG("PARAMETERS");
+ switch ( m_bOWM ) {
+ case ANODE_WM_2D_SET_MASTER_PARAM:
+ LOG("SET MASTER ACK");
+ setWM(ANODE_WM_2D_SET_SLAVE_PARAM);
+ break;
+ case ANODE_WM_2D_SET_SLAVE_PARAM:
+ LOG("SET SLAVE ACK");
+ setWM(ANODE_WM_2D_PING);
+ break;
+ default:{
+ LOG("FROM DEVICE");
+ LGS_2D_PARAMETERS tParams;
+ //RaspberyPi - not Intel - cannot copy
+ //memcpy( &tParams, Package->m_pData + DATA_BEGIN_IDX, sizeof( LGS_2D_PARAMETERS ) );
+ tParams.nOrder = ( Package->m_pData[5] << 8 ) | Package->m_pData[6];
+ tParams.nOffset = ( Package->m_pData[7] << 8 ) | Package->m_pData[8];
+ tParams.nDelta = ( Package->m_pData[9] << 8 ) | Package->m_pData[10];
+ tParams.nWidth = ( Package->m_pData[11] << 8 ) | Package->m_pData[12];
+ tParams.nFlip = ( Package->m_pData[13] << 8 ) | Package->m_pData[14];
+ tParams.nSun = ( Package->m_pData[15] << 8 ) | Package->m_pData[16];
+ tParams.bSST = Package->m_pData[17];
+
+ if( Package->m_pData[SUB_CMD_IDX] == 0x80 ) {
+ #ifdef DEBUG
+ LOG("CMD MASTER PARAMETERS");
+ #endif
+ //m_pDBC->updateMasterDetectorLRF( m_sNodeData.aux_id, tParams.nOrder, tParams.nOffset, tParams.nDelta, tParams.nWidth, tParams.nFlip, tParams.nSun, tParams.bSST );
+ m_pDBC->updateLRFDetectionProfile( m_sNodeData.aux_id, 0, true, tParams.nOrder, tParams.nOffset, tParams.nDelta, tParams.nWidth, tParams.nFlip, tParams.nSun, tParams.bSST );
+ setWM( ANODE_WM_2D_GET_SLAVE_PARAM );//ANODE_WM_2D_GET_MASK_INFO??
+ } else {
+ #ifdef DEBUG
+ LOG("CMD SLAVE PARAMETERS");
+ #endif
+ //m_pDBC->updateSlaveDetectorLRF( m_sNodeData.aux_id, tParams.nOrder, tParams.nOffset, tParams.nDelta, tParams.nWidth, tParams.nFlip, tParams.nSun, tParams.bSST );
+ m_pDBC->updateLRFDetectionProfile( m_sNodeData.aux_id, 0, false, tParams.nOrder, tParams.nOffset, tParams.nDelta, tParams.nWidth, tParams.nFlip, tParams.nSun, tParams.bSST );
+ setWM( ANODE_WM_2D_GET_MASK_INFO );
+ };
+ #ifdef DEBUG
+ sprintf(tBuff, " SST:\t%d", tParams.bSST );
+ LOG(tBuff);
+ sprintf(tBuff, " DELTA:\t%d", tParams.nDelta );
+ LOG(tBuff);
+ sprintf(tBuff, " Flip:\t%d", tParams.nFlip );
+ LOG(tBuff);
+ sprintf(tBuff, " OFFSET:\t%d", tParams.nOffset );
+ LOG(tBuff);
+ sprintf(tBuff, " ORDER:\t%d", tParams.nOrder );
+ LOG(tBuff);
+ sprintf(tBuff, " SUN:\t%d", tParams.nSun );
+ LOG(tBuff);
+ sprintf(tBuff, " WIDTH:\t%d", tParams.nWidth );
+ LOG(tBuff);
+ #endif
+ break;
+ };
+ };
break;
};
case CMD_FULL_BORDER:{
@@ -1253,6 +1437,290 @@ bool ARGUS_2DSensor::packetHandler( protocolPackage *Package ){
m_nActiveDetectionProfile = 0;
break;
};
+ case CMD_GET_HZ_DATA:{
+ //HZ_PACKET tPack = (PHZ_PACKET) Package->m_pData + SUB_CMD_IDX;
+ switch( Package->m_pData[DATA_BEGIN_IDX] ) {
+ case HZIT_EVT_GET_HEADER:{
+ HZ_EVT_GET_HEADER pC;
+ pC.bSubSize = Package->m_pData[SUB_CMD_IDX];
+ pC.bType = Package->m_pData[DATA_BEGIN_IDX];
+ pC.bSequence = Package->m_pData[DATA_BEGIN_IDX+1];
+ pC.wPolygonCount = Package->m_pData[DATA_BEGIN_IDX+3];
+ pC.wPolygonCount = ( pC.wPolygonCount << 8 ) | Package->m_pData[DATA_BEGIN_IDX+2];
+ pC.wRayCount = Package->m_pData[DATA_BEGIN_IDX+5];
+ pC.wRayCount = ( pC.wRayCount << 8 ) | Package->m_pData[DATA_BEGIN_IDX+4];
+ pC.dwTypeOn = Package->m_pData[DATA_BEGIN_IDX+9];
+ pC.dwTypeOn = ( pC.dwTypeOn << 8 ) | Package->m_pData[DATA_BEGIN_IDX+8];
+ pC.dwTypeOn = ( pC.dwTypeOn << 8 ) | Package->m_pData[DATA_BEGIN_IDX+7];
+ pC.dwTypeOn = ( pC.dwTypeOn << 8 ) | Package->m_pData[DATA_BEGIN_IDX+6];
+#ifdef DEBUG
+ sprintf( tBuff, "Poly Cnt: %d Ray Cnt: %d Status: 0x%04X", pC.wPolygonCount, pC.wRayCount, pC.dwTypeOn );
+ LOG( tBuff );
+#endif
+ if ( pC.wPolygonCount ) {
+ cleanShadowStructs();
+ m_sShadow.m_nEnabled = pC.dwTypeOn;
+ m_sShadow.pPolygones = (SHADOW_POLY *) calloc(pC.wPolygonCount,sizeof(SHADOW_POLY));
+ if ( m_sShadow.pPolygones ) {
+ memset( m_sShadow.pPolygones, 0, pC.wPolygonCount*sizeof(SHADOW_POLY) );
+ m_sShadow.m_nPolygonCount = pC.wPolygonCount;
+ setWM(ANODE_WM_2D_GET_SHADOW_POLY_INFO);
+ } else {
+ LOG_ERROR("Error Alocation Memory foe Shadow!");
+ setWM( ANODE_WM_2D_PING );
+ };
+ } else {
+ setWM( ANODE_WM_2D_PING );
+ };
+ break;
+ };
+ case HZIT_EVT_GET_POLYGON:{
+ uint16_t wPointCount = Package->m_pData[DATA_BEGIN_IDX+4];
+ wPointCount = ( wPointCount << 8 ) | Package->m_pData[DATA_BEGIN_IDX+3];
+#ifdef DEBUG
+ sprintf( tBuff, "Poly[%d] Info: Points %d type: %d",
+ m_sShadowHelper.m_nCurrentPolygon,
+ wPointCount, Package->m_pData[DATA_BEGIN_IDX+2]
+ );
+ LOG( tBuff );
+#endif
+ if ( wPointCount ) {
+ m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].bType = Package->m_pData[DATA_BEGIN_IDX+2];
+ m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].pPoint = (HZ_POINT*)calloc( wPointCount, sizeof(HZ_POINT));
+ if ( m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].pPoint ) {
+ memset(m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].pPoint, 0, wPointCount*sizeof(HZ_POINT));
+ m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].wCount = wPointCount;
+ m_sShadowHelper.m_nCurrentPoint = 0;
+ setWM( ANODE_WM_2D_GET_SHADOW_POLY_POINT );
+ } else {
+ LOG_ERROR("Error Alloc Memory for Polygone points!");
+ setWM(ANODE_WM_2D_PING);
+ };
+ } else {
+ m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].pPoint = NULL;
+ m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].wCount = 0;
+ if(m_sShadowHelper.m_nCurrentPolygon < m_sShadow.m_nPolygonCount ) {
+ m_sShadowHelper.m_nCurrentPolygon++;
+ setWM(ANODE_WM_2D_GET_SHADOW_POLY_INFO);
+ } else {
+ setWM(ANODE_WM_2D_PING);
+ };
+ };
+ break;
+ };
+ case HZIT_EVT_GET_POLYGON_POINT:{
+ m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].pPoint[m_sShadowHelper.m_nCurrentPoint].wX = Package->m_pData[DATA_BEGIN_IDX+3];
+ m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].pPoint[m_sShadowHelper.m_nCurrentPoint].wX = (m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].pPoint[m_sShadowHelper.m_nCurrentPoint].wX << 8 ) | Package->m_pData[DATA_BEGIN_IDX+2];
+ m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].pPoint[m_sShadowHelper.m_nCurrentPoint].wY = Package->m_pData[DATA_BEGIN_IDX+5];
+ m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].pPoint[m_sShadowHelper.m_nCurrentPoint].wY = (m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].pPoint[m_sShadowHelper.m_nCurrentPoint].wY << 8 ) | Package->m_pData[DATA_BEGIN_IDX+4];
+#ifdef DEBUG
+ sprintf( tBuff, "PolyPoint[%d] of %d X: %d Y: %d",
+ m_sShadowHelper.m_nCurrentPoint,
+ m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].wCount,
+ m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].pPoint[m_sShadowHelper.m_nCurrentPoint].wX,
+ m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].pPoint[m_sShadowHelper.m_nCurrentPoint].wY
+ );
+ LOG( tBuff );
+#endif
+ m_sShadowHelper.m_nCurrentPoint++;
+ if( m_sShadowHelper.m_nCurrentPoint < m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].wCount ) {
+ setWM( ANODE_WM_2D_GET_SHADOW_POLY_POINT );
+ } else {
+#ifdef DEBUG
+ LOG("Done Load Poly Points");
+#endif
+ m_sShadowHelper.m_nCurrentPolygon++;
+ if(m_sShadowHelper.m_nCurrentPolygon < m_sShadow.m_nPolygonCount ) {
+ setWM( ANODE_WM_2D_GET_SHADOW_POLY_INFO );
+ } else {
+ for( uint8_t MaskLayer=0; MaskLayer < 5; MaskLayer++ ) {
+ uint32_t tMaskID = m_pDBC->getLRFMaskID( m_sLRF_DATA.id , 0, MaskLayer );
+ if( tMaskID ) {
+ m_pDBC->cleanLRFMask( tMaskID, true );
+ tMaskID = 0;
+ };
+ for( uint8_t i = 0; i < m_sShadow.m_nPolygonCount; i++ ){
+ if( m_sShadow.pPolygones[i].bType == MaskLayer ){
+ if( m_sShadow.pPolygones[i].pPoint ){
+ if( tMaskID == 0 ) {
+ tMaskID = m_pDBC->addLRFMask( m_sLRF_DATA.id, 0, MaskLayer );
+ };
+ if( tMaskID ) {
+ uint32_t tPolyID = 0;
+ switch( MaskLayer ) {
+ case 0: tPolyID = m_pDBC->addLRFMaskPolygone(tMaskID, 255, 0, 255); break;
+ case 1: tPolyID = m_pDBC->addLRFMaskPolygone(tMaskID, 255, 255, 0); break;
+ case 2: tPolyID = m_pDBC->addLRFMaskPolygone(tMaskID, 0, 255, 255); break;
+ case 3: tPolyID = m_pDBC->addLRFMaskPolygone(tMaskID, 0, 255, 0); break;
+ case 4: tPolyID = m_pDBC->addLRFMaskPolygone(tMaskID, 0, 0, 255); break;
+ default: tPolyID = m_pDBC->addLRFMaskPolygone(tMaskID, 0, 0, 0 ); break;
+ };
+ if ( tPolyID ) {
+ for ( uint16_t k=0;k < m_sShadow.pPolygones[i].wCount; k++ ) {
+ m_pDBC->addLRFMaskPolygonePoint(
+ tPolyID,
+ m_sShadow.pPolygones[i].pPoint[k].wX,
+ m_sShadow.pPolygones[i].pPoint[k].wY
+ );
+ };
+ };
+ };
+ };
+ };
+ };
+ if ( tMaskID ) {
+ m_pDBC->setLRFMaskStatus( tMaskID, ( m_sShadow.m_nEnabled & (1<m_pData[DATA_BEGIN_IDX] );
+ LOG( tBuff );
+#endif
+ switch( Package->m_pData[DATA_BEGIN_IDX] ) {
+ case HZIT_EVT_SET_HEADER:
+ LOG("Header OK");
+ memset( &m_sShadowHelper, 0, sizeof(SHADOW_IO_HELPER) );
+ setWM( ANODE_WM_2D_SET_SHADOW_POLY_INFO );
+ break;
+ case HZIT_EVT_SET_POLYGON:
+ LOG("Poligon Added OK");
+ m_sShadowHelper.m_nCurrentPoint = 0;
+ setWM( ANODE_WM_2D_SET_SHADOW_POLY_POINT );
+ break;
+ case HZIT_EVT_SET_POLYGON_POINT:
+ if (m_sShadowHelper.m_nCurrentPoint < (m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].wCount - 1) ) {
+#ifdef DEBUG
+ sprintf( tBuff,"Send Point %d of %d", (m_sShadowHelper.m_nCurrentPoint + 1), m_sShadow.pPolygones[m_sShadowHelper.m_nCurrentPolygon].wCount );
+ LOG( tBuff );
+#endif
+ m_sShadowHelper.m_nCurrentPoint++;
+ setWM( ANODE_WM_2D_SET_SHADOW_POLY_POINT );
+ } else {
+ if (m_sShadowHelper.m_nCurrentPolygon < (m_sShadow.m_nPolygonCount - 1)) {
+#ifdef DEBUG
+ sprintf(tBuff, "Send Polygon %d of %d", (m_sShadowHelper.m_nCurrentPolygon + 1), m_sShadow.m_nPolygonCount );
+ LOG( tBuff );
+#endif
+ m_sShadowHelper.m_nCurrentPolygon++;
+ setWM( ANODE_WM_2D_SET_SHADOW_POLY_INFO );
+ } else {
+#ifdef DEBUG
+ LOG("Start Send Rays!");
+#endif
+ m_sShadowHelper.m_nCurrentRayLine = 0;
+ for( ; m_sShadowHelper.m_nCurrentRayLine < MAX_2D_SHADOW_RAY_LINES; m_sShadowHelper.m_nCurrentRayLine++ ) if( m_sShadow.ray_lines[m_sShadowHelper.m_nCurrentRayLine].nCount ) break;
+ if ( m_sShadowHelper.m_nCurrentRayLine < MAX_2D_SHADOW_RAY_LINES ) {
+#ifdef DEBUG
+ sprintf( tBuff,"Send Ray Line %d of %d", ( m_sShadowHelper.m_nCurrentRayLine + 1 ), MAX_2D_SHADOW_RAY_LINES );
+ LOG( tBuff );
+#endif
+ setWM(ANODE_WM_2D_SET_SHADOW_RAY_LINE);
+ } else {
+#ifdef DEBUG
+ LOG("Skip Uploading Rays -> No Rays Detected!");
+#endif
+ setWM( ANODE_WM_2D_SET_SHADOW_DONE );
+ };
+ };
+ };
+ break;
+ case HZIT_EVT_SET_RAY:
+ LOG("Rey Line Added OK");
+ m_sShadowHelper.m_nCurrentRay = 0;
+ setWM( ANODE_WM_2D_SET_SHADOW_RAY );
+ break;
+ case HZIT_EVT_SET_RAY_LINE:
+ if( m_sShadowHelper.m_nCurrentRay < (m_sShadow.ray_lines[m_sShadowHelper.m_nCurrentRayLine].nCount-1)) {
+#ifdef DEBUG
+ sprintf( tBuff,"Send Ray %d of %d", (m_sShadowHelper.m_nCurrentRay + 1), m_sShadow.ray_lines[m_sShadowHelper.m_nCurrentRayLine].nCount );
+ LOG( tBuff );
+#endif
+ m_sShadowHelper.m_nCurrentRay++;
+ setWM( ANODE_WM_2D_SET_SHADOW_RAY );
+ } else {
+ if (m_sShadowHelper.m_nCurrentRayLine < (MAX_2D_SHADOW_RAY_LINES-1) ) {
+ m_sShadowHelper.m_nCurrentRayLine++;
+ for( ; m_sShadowHelper.m_nCurrentRayLine < MAX_2D_SHADOW_RAY_LINES; m_sShadowHelper.m_nCurrentRayLine++ ) if( m_sShadow.ray_lines[m_sShadowHelper.m_nCurrentRayLine].nCount ) break;
+ if ( m_sShadowHelper.m_nCurrentRayLine < MAX_2D_SHADOW_RAY_LINES ) {
+#ifdef DEBUG
+ sprintf( tBuff,"Send Ray Line %d of %d", ( m_sShadowHelper.m_nCurrentRayLine + 1 ), MAX_2D_SHADOW_RAY_LINES );
+ LOG( tBuff );
+#endif
+ setWM(ANODE_WM_2D_SET_SHADOW_RAY_LINE);
+ } else {
+#ifdef DEBUG
+ LOG("Finish Uploadding Rays!");
+#endif
+ setWM( ANODE_WM_2D_SET_SHADOW_DONE );
+ };
+ } else {
+ setWM( ANODE_WM_2D_SET_SHADOW_DONE );
+ };
+ };
+ break;
+ case HZIT_EVT_SET_DONE:
+#ifdef DEBUG
+ LOG("Cleanup!");
+#endif
+ memset( &m_sShadowHelper, 0, sizeof(SHADOW_IO_HELPER) );
+ setWM( ANODE_WM_2D_PING );
+ break;
+ case HZIT_EVT_ERROR:{
+ HZ_EVT_ERROR pC;
+#ifdef DEBUG
+ LOG("ERROR SET SHADOW PING_PONG!");
+#endif
+ setWM( ANODE_WM_2D_PING );
+ break;
+ };
+ };
+ break;
+ };
+ case CMD_GETFILE:{
+ if( ( Package->m_pData[SUB_CMD_IDX] & GF_ERRORMASK ) != 0 ){
+ if( ( Package->m_pData[SUB_CMD_IDX] & GF_ERRORMODE ) != 0 ){
+ LOG_ERROR("Error: GF-Wrond WM!");
+ };
+ if( ( Package->m_pData[SUB_CMD_IDX] & GF_ERRORFILE ) != 0 ){
+ LOG_ERROR("Error: GF-File Error!");
+ };
+ setWM( ANODE_WM_2D_PING );
+ } else {
+
+ };
+ break;
+ };
};
};
return true;
@@ -1285,6 +1753,15 @@ TARGET_DATA *ARGUS_2DSensor::prepareTargetData( uint16_t AZ, uint16_t RANGE, uin
// global - C3D_WGS84_LOC
tSystem->convertToSystem( &m_oPosition, tVal->local_target, tVal->system_target );
tSystem->convertToGlobal( &m_oPosition, tVal->local_target, tVal->global_target );
+#ifdef DEBUG
+ char tB[128];
+ sprintf(tB, "tCords Local: %0.3f %0.3f %0.3f", tVal->local_target.r, tVal->local_target.fi, tVal->local_target.tetta );
+ LOG( tB );
+ sprintf(tB, "tCords System: %0.3f %0.3f %0.3f", tVal->system_target.x, tVal->system_target.y, tVal->system_target.z );
+ LOG( tB );
+ sprintf(tB, "tCords Global: %0.3f %0.3f %0.3f", tVal->global_target.lat, tVal->global_target.lon, tVal->global_target.alt );
+ LOG( tB );
+#endif
};
};
return tVal;
@@ -1358,6 +1835,302 @@ CSTR ARGUS_2DSensor::generateSettingFile(){
return RetVal;
};
+inline int DBL_CMP( const double& a, const double& b, const double quality = 1e-10 ){
+ if( fabs(a - b) <= fabs(quality) ) return 0;
+ if( a > b ) return 1;
+ return -1;
+};
+
+typedef struct S_VERTEX{
+ double x, y, r;
+ BOOL f;
+ int n;
+}VERTEX, *PVERTEX;
+
+typedef struct S_SEGMENT{
+ int pPoints[2];
+ int nIndex;
+}SEGMENT, *PSEGMENT;
+
+typedef struct S_SEGMENTS{
+ PVERTEX pPoints;
+ int nCount;
+}SEGMENTS, *PSEGMENTS;
+
+BOOL CrossProduct( PVERTEX ln0, PVERTEX ln1, PVERTEX pCross, bool fCheck0 = true, bool fCheck1 = true ){
+#undef B0
+ double A0, A1, B0, B1, X, Y;
+
+ if( DBL_CMP(ln0[0].x, ln0[1].x) == 0 ){
+ A0 = DBL_MAX;
+ B0 = ln0[0].x;
+ } else {
+ A0 = (ln0[0].y - ln0[1].y) / (ln0[0].x - ln0[1].x);
+ B0 = ln0[0].y - A0 * ln0[0].x;
+ };
+ if(DBL_CMP(ln1[0].x , ln1[1].x) == 0){
+ A1 = DBL_MAX;
+ B1 = ln1[0].x;
+ } else {
+ A1 = (ln1[0].y - ln1[1].y) / (ln1[0].x - ln1[1].x);
+ B1 = ln1[0].y - A1 * ln1[0].x;
+ };
+ if(A0 == DBL_MAX){
+ if(A1 == DBL_MAX) return FALSE;
+ X = B0;
+ Y = A1 * X + B1;
+ } else {
+ if(A1 == DBL_MAX) X = B1;
+ else {
+ if(DBL_CMP( A1, A0 ) != 0) X = (B0 - B1) / (A1 - A0); else return FALSE;
+ };
+ Y = A0 * X + B0;
+ };
+ double y = Y, x = X;
+ if( fCheck0 ){
+ double x0 = ln0[0].x, x1 = ln0[1].x;
+ double y0 = ln0[0].y, y1 = ln0[1].y;
+ if(DBL_CMP(y0, y1) == -1 && (DBL_CMP(y0, y) == 1 || DBL_CMP(y, y1) == 1)) return FALSE;
+ if(DBL_CMP(y0, y1) == 1 && (DBL_CMP(y0, y) == -1 || DBL_CMP(y, y1) == -1)) return FALSE;
+ if(DBL_CMP(x0, x1) == -1 && (DBL_CMP(x0, x) == 1 || DBL_CMP(x, x1) == 1)) return FALSE;
+ if(DBL_CMP(x0, x1) == 1 && (DBL_CMP(x0, x) == -1 || DBL_CMP(x, x1) == -1)) return FALSE;
+ };
+
+ if( fCheck1 ){
+ double x0 = ln1[0].x, x1 = ln1[1].x;
+ double y0 = ln1[0].y, y1 = ln1[1].y;
+ if(DBL_CMP(y0, y1) == -1 && (DBL_CMP(y0, y) == 1 || DBL_CMP(y, y1) == 1)) return FALSE;
+ if(DBL_CMP(y0, y1) == 1 && (DBL_CMP(y0, y) == -1 || DBL_CMP(y, y1) == -1)) return FALSE;
+ if(DBL_CMP(x0, x1) == -1 && (DBL_CMP(x0, x) == 1 || DBL_CMP(x, x1) == 1)) return FALSE;
+ if(DBL_CMP(x0, x1) == 1 && (DBL_CMP(x0, x) == -1 || DBL_CMP(x, x1) == -1)) return FALSE;
+ };
+ pCross->x = X;
+ pCross->y = Y;
+ return TRUE;
+};
+
+BOOL PtInLine( PVERTEX ln, VERTEX& p ){
+ double A, B;
+ if(DBL_CMP(ln[0].x, ln[1].x) == 0){
+ A = DBL_MAX;
+ B = ln[0].x;
+ } else {
+ A = (ln[0].y - ln[1].y) / (ln[0].x - ln[1].x);
+ B = ln[0].y - A * ln[0].x;
+ };
+
+ if(A == DBL_MAX) {
+ if( DBL_CMP(p.x, B) == 0) return TRUE;
+ } else {
+ if(DBL_CMP(p.x * A + B, p.y) == 0) return TRUE;
+ };
+ return FALSE;
+};
+
+int comparePoints( const void *arg1, const void *arg2 ){
+ if(((PVERTEX)arg1)->r > ((PVERTEX)arg2)->r) return +1;
+ if(((PVERTEX)arg1)->r < ((PVERTEX)arg2)->r) return -1;
+ return 0;
+};
+
+void AddPointToSegment( PSEGMENTS pSegments, int nIndex, PVERTEX pPoint){
+ PVERTEX pNew = new VERTEX[pSegments[nIndex].nCount + 1];
+
+ memcpy( pNew, pSegments[nIndex].pPoints, sizeof(VERTEX) * pSegments[nIndex].nCount );
+ memcpy( pNew + pSegments[nIndex].nCount, pPoint, sizeof(VERTEX));
+
+ if(pSegments[nIndex].pPoints) delete pSegments[nIndex].pPoints;
+
+ pSegments[nIndex].pPoints = pNew;
+ pSegments[nIndex].nCount++;
+};
+
+#include
+
+void StickSegments( PSEGMENTS pSegments, int nIndex ){
+ if( pSegments[nIndex].nCount ){
+ qsort( pSegments[nIndex].pPoints, pSegments[nIndex].nCount, sizeof(VERTEX), comparePoints );
+
+ PVERTEX pTemp = new VERTEX[pSegments[nIndex].nCount];
+ PVERTEX pPoints = pSegments[nIndex].pPoints;
+
+ int f, nT = 0;
+ pTemp[nT++] = pPoints[0];
+ f = pPoints[0].f;
+
+ for(int i = 1; i < pSegments[nIndex].nCount;){
+ f += pPoints[i].f;
+ if(f == 0){
+ pTemp[nT++] = pPoints[i++];
+ if(i < pSegments[nIndex].nCount){
+ pTemp[nT++] = pPoints[i];
+ f = pPoints[i++].f;
+ };
+ } else i++;
+ };
+ if(pSegments[nIndex].pPoints) delete[] pSegments[nIndex].pPoints;
+ pSegments[nIndex].pPoints = new VERTEX[nT];
+ memcpy( pSegments[nIndex].pPoints, pTemp, sizeof(VERTEX) * nT );
+ pSegments[nIndex].nCount = nT;
+ if(pTemp) delete[] pTemp;
+ };
+};
+
+int compareSegments(const void *arg1, const void *arg2){
+ if(((PSEGMENT)arg1)->nIndex > ((PSEGMENT)arg2)->nIndex) return +1;
+ if(((PSEGMENT)arg1)->nIndex < ((PSEGMENT)arg2)->nIndex) return -1;
+ if(((PSEGMENT)arg1)->pPoints[0] > ((PSEGMENT)arg2)->pPoints[0]) return +1;
+ if(((PSEGMENT)arg1)->pPoints[0] < ((PSEGMENT)arg2)->pPoints[0]) return -1;
+ return 0;
+};
+
+uint16_t pnpoly( uint16_t nvert, float *vertx, float *verty, float testx, float testy ){
+ uint16_t c = 0;
+ for( uint16_t i = 0, j = nvert-1; i < nvert; j = i++ ) if ( ((verty[i]>testy) != (verty[j]>testy)) && (testx < (vertx[j]-vertx[i]) * (testy-verty[i]) / (verty[j]-verty[i]) + vertx[i]) ) c = !c;
+ return c;
+};
+
+bool ARGUS_2DSensor::PtInPolygons( TEST_POINT& point, uint8_t F ){
+ for( uint16_t i = 0; i < m_sShadow.m_nPolygonCount; i++) if( F == m_sShadow.pPolygones[i].bType ) if ( PtInPolygon( m_sShadow.pPolygones[i], point ) ) return true;
+ return false;
+};
+
+bool ARGUS_2DSensor::PtInPolygon( SHADOW_POLY& Poly, TEST_POINT& point ){
+ if( Poly.wCount < 3 ) return false;
+ float *vertx = (float *) calloc( Poly.wCount, sizeof(float));
+ float *verty = (float *) calloc( Poly.wCount, sizeof(float));
+ for( int z =0; z < Poly.wCount; z++ ) {
+ vertx[z] = (float)Poly.pPoint[z].wX;
+ verty[z] = (float)Poly.pPoint[z].wY;
+ };
+ if ( pnpoly( Poly.wCount, vertx, verty, point.x, point.y )){
+ free(vertx);
+ free(verty);
+ return TRUE;
+ };
+ free(vertx);
+ free(verty);
+ return FALSE;
+};
+
+bool ARGUS_2DSensor::rasterizeShadow(){
+ const double TWO_PI = 6.2831853071796;
+ bool masked[5] = {0};
+ uint16_t cMin, cMax;
+ double k = TWO_PI /((double)MAX_2D_SHADOW_RAY_LINES );
+ double z_shift = k * ((double)m_sLRF_DATA.base_shift );
+
+ for( uint16_t i=0; i < MAX_2D_SHADOW_RAY_LINES; i++ ) {
+ double ca = k * i + z_shift; // must be checked sign!!
+ double sin_val = sin( ca );
+ double cos_val = cos( ca );
+ for( uint16_t range_digital = 0; range_digital < 2047; range_digital++ ) {
+ TEST_POINT TP;
+ TP.x = (float)(cos_val*((double)range_digital));
+ TP.y = (float)(sin_val*((double)range_digital));
+ for( uint8_t z=0; z < 5; z++ ){
+ if (masked[z]) {
+ if(!PtInPolygons( TP, z )){
+ masked[z] = false;
+ cMax = range_digital;
+ m_sShadow.ray_lines[i].rays = (SHADOW_RAY *) realloc( m_sShadow.ray_lines[i].rays, m_sShadow.ray_lines[i].nCount+1 );
+ if ( m_sShadow.ray_lines[i].rays == NULL ) {
+ m_sShadow.ray_lines[i].nCount = 0;
+ return false;
+ };
+ m_sShadow.ray_lines[i].rays[m_sShadow.ray_lines[i].nCount].nMin = cMin;
+ m_sShadow.ray_lines[i].rays[m_sShadow.ray_lines[i].nCount].nMax = cMax;
+ m_sShadow.ray_lines[i].rays[m_sShadow.ray_lines[i].nCount].bType = z;
+ m_sShadow.ray_lines[i].nCount++;
+#ifdef DEBUG
+ char tB[128];
+ sprintf( tB ,"New Ray: Mask[%d] angle[%d] min[%d] max[%d]", z, i, cMin, cMax );
+ LOG(tB);
+#endif
+ };
+ } else {
+ if(PtInPolygons( TP, z )){
+ masked[z] = true;
+ cMin = range_digital;
+ };
+ };
+ };
+ };
+ for( uint8_t z=0; z < 5; z++ ){
+ if ( masked[z] ) {
+ masked[z] = false;
+ cMax = 2047;
+ m_sShadow.ray_lines[i].rays = (SHADOW_RAY *) realloc( m_sShadow.ray_lines[i].rays, m_sShadow.ray_lines[i].nCount + 1 );
+ if ( m_sShadow.ray_lines[i].rays == NULL ) {
+ m_sShadow.ray_lines[i].nCount = 0;
+ return false;
+ };
+ m_sShadow.ray_lines[i].rays[m_sShadow.ray_lines[i].nCount].nMin = cMin;
+ m_sShadow.ray_lines[i].rays[m_sShadow.ray_lines[i].nCount].nMax = cMax;
+ m_sShadow.ray_lines[i].rays[m_sShadow.ray_lines[i].nCount].bType = z;
+ m_sShadow.ray_lines[i].nCount++;
+#ifdef DEBUG
+ char tB[128];
+ sprintf( tB ,"New Ray: Mask[%d] angle[%d] min[%d] max[%d]", z, i, cMin, cMax );
+ LOG(tB);
+#endif
+ };
+ };
+ };
+ return true;
+};
+
+#ifdef DEBUG_EXTRA
+void ARGUS_2DSensor::makeShadowPic( CSTR picname ){
+ cv::Scalar zone_colors[6] = { cv::Scalar(0, 0, 255),
+ cv::Scalar(255, 20, 255),
+ cv::Scalar(0, 255, 255),
+ cv::Scalar(0, 255, 0),
+ cv::Scalar(255, 0, 0),
+ cv::Scalar(120, 120, 120)
+ };
+ const double TWO_PI = 6.2831853071796;
+ double k = TWO_PI /((double)MAX_2D_SHADOW_RAY_LINES );
+ double z_shift = k * ((double)m_sLRF_DATA.base_shift );
+ cv::Mat tPic(512, 512, CV_8UC3, cv::Scalar(20, 20, 20));
+ double cx = 256.0;
+ double cy = 256.0;
+ double r = 255.0/2048.0;
+ for ( int i = 0; i < 360; i++ ) {
+ double ca = k * i + z_shift; // must be checked sign!!
+ double sin_val = sin( ca );
+ double cos_val = cos( ca );
+ cv::line( tPic, cv::Point( cx, cy ), cv::Point( cx+cos_val*256, cy+sin_val*256 ), zone_colors[5], 1, cv::LINE_AA );
+ if( m_sShadow.ray_lines[i].nCount ){
+ for ( int z=0; z < m_sShadow.ray_lines[i].nCount; z++ ) {
+ int r1 = m_sShadow.ray_lines[i].rays[z].nMin;
+ int r2 = m_sShadow.ray_lines[i].rays[z].nMax;
+ cv::Scalar color = zone_colors[m_sShadow.ray_lines[i].rays[z].bType];
+ int x1 = cx+(cos_val*r1*r);
+ int y1 = cy+(sin_val*r1*r);
+ int x2 = cx+(cos_val*r2*r);
+ int y2 = cy+(sin_val*r2*r);
+ cv::line(tPic, cv::Point(x1, y1), cv::Point( x2, y2), color, 1, cv::LINE_AA);
+ };
+ };
+ };
+ vector compression_params;
+ compression_params.push_back(cv::IMWRITE_PNG_COMPRESSION);
+ compression_params.push_back(9);
+ //compression_params.push_back( cv::IMWRITE_JPEG_QUALITY );
+ //compression_params.push_back( m_sEmbedVideoData.compression_quality );
+ vector buf;
+ cv::imencode( ".png", tPic, buf, compression_params );
+ FILE *fd;
+ fd = fopen( picname, "wb");
+ if ( fd ) {
+ fwrite( buf.data(), 1, buf.size(), fd );
+ fclose( fd );
+ };
+ buf.clear();
+};
+#endif
+
#undef SIZE_IDX
#undef DEV_ID_IDX
#undef CMD_IDX
diff --git a/lib/rgoose/rgooseNode2D.h b/lib/rgoose/rgooseNode2D.h
index c19d2b5b..3a1387fe 100644
--- a/lib/rgoose/rgooseNode2D.h
+++ b/lib/rgoose/rgooseNode2D.h
@@ -15,8 +15,8 @@
#include "../data/protocol/protocolLGS2D.h"
#define LGS_DEFAULT_SLEEP_TIME 333
-#define LGS_ALERT_SLEEP_TIME 30
-#define LGS_DEFAULT_TO_COUNTER 30
+#define LGS_ALERT_SLEEP_TIME 1
+#define LGS_DEFAULT_TO_COUNTER 2
#define LGS_INITIAL_FLIPS 8
#define ANODE_WM_2D_BEFORE_START 0
@@ -24,43 +24,69 @@
#define ANODE_WM_2D_CONNECT 2
#define ANODE_WM_2D_WAIT_CONNECT 3
#define ANODE_WM_2D_SET_INIT_MODE 4
-#define ANODE_WM_2D_WAIT_INIT_MODE 5
#define ANODE_WM_2D_GET_SERIAL_NUM 6
-#define ANODE_WM_2D_WAIT_SERIAL_NUM 7
#define ANODE_WM_2D_GET_VERSION 8
-#define ANODE_WM_2D_WAIT_VERSION 9
#define ANODE_WM_2D_GET_DETECTION_PROFILE 10
-#define ANODE_WM_2D_WAIT_DETECTION_PROFILE 11
#define ANODE_WM_2D_GET_MASTER_PARAM 12
-#define ANODE_WM_2D_WAIT_MASTER_PARAM 13
#define ANODE_WM_2D_GET_SLAVE_PARAM 14
-#define ANODE_WM_2D_WAIT_SLAVE_PARAM 15
-
-#define ANODE_WM_2D_SET_BORDER_MODE 16
-#define ANODE_WM_2D_WAIT_BORDER_MODE 17
-#define ANODE_WM_2D_GET_FAST_DRAW 18
-#define ANODE_WM_2D_WAIT_FAST_DRAW 19
-#define ANODE_WM_2D_SET_DETECTION_MODE 20
-#define ANODE_WM_2D_WAIT_DETECTION_MODE 21
-#define ANODE_WM_2D_SET_FILESYSTEM_MODE 22
-#define ANODE_WM_2D_WAIT_FILESYSTEM_MODE 23
-#define ANODE_WM_2D_FS_TRANSFER_MODE 24
+#define ANODE_WM_2D_GET_MASK_INFO 16
+#define ANODE_WM_2D_SET_MASK_INFO 18
+
+
+#define ANODE_WM_2D_SET_BORDER_MODE 32
+#define ANODE_WM_2D_GET_FAST_DRAW 34
+#define ANODE_WM_2D_SET_DETECTION_MODE 36
+#define ANODE_WM_2D_SET_FILESYSTEM_MODE 38
+#define ANODE_WM_2D_FS_TRANSFER_MODE 39
+
+#define ANODE_WM_2D_SET_SHADOW_DONE 40
+#define ANODE_WM_2D_GET_SHADOW_POLY_INFO 41
+#define ANODE_WM_2D_GET_SHADOW_POLY_POINT 43
+#define ANODE_WM_2D_SET_SHADOW_POLY_INFO 45
+#define ANODE_WM_2D_SET_SHADOW_POLY_POINT 47
+#define ANODE_WM_2D_SET_SHADOW_RAY_LINE 48
+#define ANODE_WM_2D_SET_SHADOW_RAY 49
+
+#define ANODE_WM_2D_SET_GETFILE_MODE 50
+#define ANODE_WM_2D_SEND_GETFILE_MODE 52
+#define ANODE_WM_2D_SET_MASTER_PARAM 58
+#define ANODE_WM_2D_SET_SLAVE_PARAM 59
#define ANODE_WM_2D_ISSUE_FULL_RESET 64
-#define ANODE_WM_2D_WAIT_FULL_RESET 65
#define ANODE_WM_2D_ISSUE_RESET 66
-#define ANODE_WM_2D_WAIT_RESET 67
#define ANODE_WM_2D_PING 128
#define ANODE_WM_2D_PONG 129
#define ANODE_WM_2D_SLEEP_AND_RECONNECT 130
+#define ANODE_WM_2D_WAIT_DEVICE_REPLAY 254
+#define ANODE_WM_2D_WAIT_CHECK_REPLAY 255
#define ANODE_2D_MAX_DRAW_ANGLES 6000
-
-
+typedef struct S_SHADOW_IO_HELPER{
+ uint16_t m_nCurrentPolygon;
+ uint16_t m_nCurrentPoint;
+ uint16_t m_nCurrentRayLine;
+ uint16_t m_nCurrentRay;
+}SHADOW_IO_HELPER;
+
+typedef struct S_GETFILE_IO_HELPER{
+ uint32_t fileSize;
+ uint32_t index;
+ char destName[33];
+ char sourceName[33];
+ uint8_t state;
+ FILE * fd;
+ uint8_t data[250];
+ uint8_t data_size;
+}GETFILE_IO_HELPER;
+
+typedef struct S_TEST_POINT{
+ float x;
+ float y;
+}TEST_POINT;
class ARGUS_2DSensor: public argusNodeSensor, public basicThread, public protocolLGS_2D{
private:
@@ -71,12 +97,13 @@ class ARGUS_2DSensor: public argusNodeSensor, public basicThread, public protoco
uint8_t m_bPortType;
basicTransport * m_pPort;
uint8_t m_bWM;
+ uint8_t m_bOWM;
basicMutex m_mWMProtector;
uint8_t m_bDeviceWM;
uint32_t m_nSleepTime;
uint16_t m_bTimeOutCounter;
uint8_t m_bInitialFlips;
- uint16_t m_nCurrentAngle;
+ uint16_t m_nCurrentAngle;
uint8_t m_bDrawType;
uint8_t m_bOpRetryCnt;
uint32_t m_nProcessingCmdId;
@@ -88,6 +115,11 @@ class ARGUS_2DSensor: public argusNodeSensor, public basicThread, public protoco
char m_sCurrentFile[MAX_PATH];
uint32_t m_nUploadID;
uint8_t m_nActiveDetectionProfile;
+ //Shadow
+ SHADOW_IO_HELPER m_sShadowHelper;
+ SHADOW m_sShadow;
+ //GetFile
+ GETFILE_IO_HELPER m_sGetFileHelper;
TARGET_DATA * prepareTargetData( uint16_t AZ, uint16_t RANGE, uint32_t WIDTH, uint8_t LRFID = 0 );
//void saveRawDrawData( uint16_t alngles );
@@ -95,6 +127,13 @@ class ARGUS_2DSensor: public argusNodeSensor, public basicThread, public protoco
void setWM( uint8_t MD );
void cleanupDeviceStructures();
CSTR generateSettingFile();
+ void cleanShadowStructs();
+ bool PtInPolygons( TEST_POINT& point, uint8_t F );
+ bool PtInPolygon( SHADOW_POLY& Poly, TEST_POINT& point );
+ bool rasterizeShadow();
+#ifdef DEBUG_EXTRA
+ void makeShadowPic( CSTR picname );
+#endif
protected:
virtual bool packetHandler( protocolPackage *Package );
virtual void m_fThreadProc( void );
diff --git a/lib/rgoose/rgooseNodeSensor.cpp b/lib/rgoose/rgooseNodeSensor.cpp
index 3e11e3ad..07e793c2 100644
--- a/lib/rgoose/rgooseNodeSensor.cpp
+++ b/lib/rgoose/rgooseNodeSensor.cpp
@@ -43,8 +43,10 @@ argusNodeSensor::~argusNodeSensor(){
uint8_t *argusNodeSensor::create2dDraw( uint32_t *out_size, uint32_t *th_data, size_t th_size, uint16_t max_digital, int radial_shift, CSTR tpl, bool byMinimum ){
uint8_t *RetVal = NULL;
*out_size = 0;
+ LOG("C2DD");
if( th_data != NULL && th_size != 0 ) {
if ( fileExist( tpl ) ) {
+ LOG(tpl);
cv::Mat tImage = cv::imread( tpl, cv::IMREAD_UNCHANGED );
int psize = th_size / ( sizeof( uint32_t ));
float stp = 2.0f * ( M_PI / (float) psize );
@@ -53,7 +55,7 @@ uint8_t *argusNodeSensor::create2dDraw( uint32_t *out_size, uint32_t *th_data, s
int x0 = (tImage.cols >> 1);
int y0 = (tImage.rows >> 1);
float maxR = ((float) x0 ) * 0.98f;
-
+ LOG("C2DD - Start");
cv::Point pts[(psize << 1)];
cv::Point ptt[(psize+2)];
@@ -103,11 +105,23 @@ uint8_t *argusNodeSensor::create2dDraw( uint32_t *out_size, uint32_t *th_data, s
ppz[0] = ptt;
npz[0] = ( rpt - 1);
+ LOG("C2DD -> draw finish");
+
cv::Mat ttMOMO = cv::imread( tpl, cv::IMREAD_UNCHANGED );
+ LOG("C2DD -> read tpl2 finish");
cv::fillPoly( ttMOMO, ppt, npp, 1, cv::Scalar( 0, 128, 255, 50 ), cv::LINE_8 );
- cv::fillPoly( ttMOMO, ppz, npz, 1, cv::Scalar( 0, 0, 0, 100 ), cv::LINE_8 );
+ LOG("C2DD -> poly1 finish");
+ //try {
+ // cv::fillPoly(ttMOMO, ppz, npz, 1, cv::Scalar(0, 0, 0, 100), cv::LINE_8);
+ // LOG("C2DD -> poly2 finish");
+ //} catch ( cv::Exception& e ) {
+ // LOG("C2DD -> poly2 Error!");
+ // LOG( e.what() );
+ //};
cv::addWeighted( tImage, 0.5, ttMOMO, 0.5, 0.0, tImage );
+ LOG("C2DD -> add img finish");
ttMOMO.release();
+ LOG("C2DD -> img release finish");
vector compression_params;
compression_params.push_back( cv::IMWRITE_PNG_COMPRESSION );
compression_params.push_back(9);
@@ -116,7 +130,7 @@ uint8_t *argusNodeSensor::create2dDraw( uint32_t *out_size, uint32_t *th_data, s
vector buf;
cv::imencode( ".png", tImage, buf, compression_params );
tImage.release();
-
+ LOG("C2DD -> compress finish");
*out_size = buf.size();
RetVal = (uint8_t *) malloc( *out_size );
if( RetVal ) {
diff --git a/lib/rgoose/rgooseNodeSensor.h b/lib/rgoose/rgooseNodeSensor.h
index 70cd5f2e..9d42396a 100644
--- a/lib/rgoose/rgooseNodeSensor.h
+++ b/lib/rgoose/rgooseNodeSensor.h
@@ -62,6 +62,11 @@
#define NODE_CMD_GET_DEVICE_DRAW 100
#define NODE_CMD_ROI_ACTIVE 65
#define NODE_CMD_ALARM 66
+#define NODE_CMD_UPDATE_SHADOW 67
+#define NODE_CMD_UPLOAD_SETTINGS_0 80
+#define NODE_CMD_UPLOAD_SETTINGS_1 81
+#define NODE_CMD_UPLOAD_SETTINGS_2 82
+#define NODE_CMD_UPLOAD_SETTINGS_3 83
class argusNodeSensor: public argusNetNode{
private:
diff --git a/lib/rgoose/rgooseTypes.h b/lib/rgoose/rgooseTypes.h
index ff3e9aa6..889e027b 100644
--- a/lib/rgoose/rgooseTypes.h
+++ b/lib/rgoose/rgooseTypes.h
@@ -16,6 +16,8 @@
#include
#include
#endif
+#include "../alg/lgs/detectorStructures.h"
+#include "../data/protocol/protocolLGS_data.h"
#define ONE_DAY_HISTORY 86400
#define ONE_HOUR_HISTORY 3600
@@ -237,6 +239,7 @@ typedef struct S_DBC_CAM_DATA{
char onvif_ctrl[251];
char ptz_token[65];
uint8_t triggering_mode;
+ uint8_t auth_mode;
}DBC_CAM_DATA;
typedef struct S_DBC_NETWORK_DATA{
@@ -628,5 +631,31 @@ typedef struct S_DBC_SNAPSHOT_DATA{
#define ARGUS_NODE_STATUS_TROUBLE 3
#define ARGUS_NODE_STATUS_ALARM 4
+typedef struct S_SHADOW_RAY{
+ uint8_t bType;
+ uint16_t nMin;
+ uint16_t nMax;
+} SHADOW_RAY;
+
+typedef struct S_SHADOW_RAY_LINE{
+ uint16_t nCount;
+ SHADOW_RAY * rays;
+}SHADOW_RAY_LINE;
+
+typedef struct S_SHADOW_POLY{
+ uint8_t bType;
+ uint16_t wCount;
+ HZ_POINT * pPoint;
+ uint32_t m_nDBID;
+}SHADOW_POLY;
+
+typedef struct S_SHADOW{
+ uint16_t m_nPolygonCount;
+ SHADOW_POLY * pPolygones;
+ SHADOW_RAY_LINE ray_lines[MAX_2D_SHADOW_RAY_LINES];
+ uint32_t m_nEnabled;
+}SHADOW;
+
+
#endif
\ No newline at end of file