diff --git a/Projects/argus/build b/Projects/argus/build index be703d90..c3596910 100755 --- a/Projects/argus/build +++ b/Projects/argus/build @@ -2,7 +2,7 @@ #make clean -e "CFG=Debug" -make -j4 -e "CFG=Debug" +#make -j4 -e "CFG=Debug" #make clean -e "CFG=Release" diff --git a/lib/App/3dSERVER/LRF_SlimKernel.cpp b/lib/App/3dSERVER/LRF_SlimKernel.cpp index e7513bd1..bde7ecd0 100644 --- a/lib/App/3dSERVER/LRF_SlimKernel.cpp +++ b/lib/App/3dSERVER/LRF_SlimKernel.cpp @@ -317,7 +317,7 @@ void LRF_Kernel::m_fThreadProc( void ){ if( m_lCycleCounter % 1000 == 0 ) { #endif // Generate Target - CNNT++; + /*CNNT++; targetRecord cNode; cNode.begin_id = ((TH_SIZE_NODES>>1)+CCNT*(TH_LINE_NODES>>3)+CNNT)%TH_SIZE_NODES; cNode.end_id = (cNode.begin_id+TH_LINE_NODES)%TH_SIZE_NODES; @@ -334,6 +334,21 @@ void LRF_Kernel::m_fThreadProc( void ){ m_pTracker->validateTarget( &cNode, m_pHardwareManager->isMaster() ); CCNT++; CCNT &= 7; + */ + // Generate Target + CNNT++; + targetRecord cNode; + cNode.begin_id = ((TH_SIZE_NODES>>1)+CCNT*(TH_LINE_NODES>>3)+CNNT)%TH_SIZE_NODES; + cNode.end_id = (cNode.begin_id+TH_LINE_NODES)%TH_SIZE_NODES; + cNode.status = 0; + cNode.flags.active = 1; + cNode.flags.lrf = CCNT; + cNode.flags.w_cnt = 2; + cNode.width = ((4095>>3)*(8-CCNT))<<1; + cNode.flags.type = TARGET_WHITE; + m_pTracker->validateTarget( &cNode, m_pHardwareManager->isMaster() ); + CCNT++; + CCNT &= 7; }; #endif diff --git a/lib/components/base/basicTypes.h b/lib/components/base/basicTypes.h index 7728cb25..7c0bdd2e 100644 --- a/lib/components/base/basicTypes.h +++ b/lib/components/base/basicTypes.h @@ -34,6 +34,14 @@ #define MAX_PATH_LEN 1024 +#define BUF_1MB 1048576 +#define BUF_2MB 2097152 +#define BUF_3MB 3145728 +#define BUF_4MB 4194304 +#define BUF_5MB 5242880 +#define BUF_6MB 6291456 +#define BUF_7MB 7340032 +#define BUF_8MB 8388608 #define MAX_CRED_LEN 256 // defined below 1024 #define MAX_PATH 260 // in Windows 260 #define DEFAULT_SERVER_PORT 2222 diff --git a/lib/data/mysql/database_class.cpp b/lib/data/mysql/database_class.cpp index 77c3e031..c1f7da91 100644 --- a/lib/data/mysql/database_class.cpp +++ b/lib/data/mysql/database_class.cpp @@ -271,11 +271,25 @@ AAssoc *MySQL_Connector::Query( CSTR QS, bool useCache ){ }; CSTR MySQL_Connector::escapeString( CSTR str ){ - CSTR temp; - m_mAccessMutex.lock(); - temp = ( CSTR ) malloc( strlen( str ) * 2 + 1 ); - mysql_real_escape_string( m_pDBLink, temp, str, strlen( str ) ); - m_mAccessMutex.unlock(); + CSTR temp = ( CSTR ) malloc( strlen( str ) * 2 + 1 ); + if ( temp ) { + m_mAccessMutex.lock(); + mysql_real_escape_string( m_pDBLink, temp, str, strlen(str) ); + m_mAccessMutex.unlock(); + }; + return temp; +}; + +CSTR MySQL_Connector::escapeBinary( uint8_t *Data, uint32_t Size ){ + CSTR temp = NULL; + if( Data && Size ){ + temp = ( CSTR ) malloc( Size * 2 + 1 ); + if ( temp ) { + m_mAccessMutex.lock(); + mysql_real_escape_string( m_pDBLink, temp, (const char*) Data, Size ); + m_mAccessMutex.unlock(); + }; + }; return temp; }; diff --git a/lib/data/mysql/database_class.h b/lib/data/mysql/database_class.h index 87303ecb..b0367b52 100644 --- a/lib/data/mysql/database_class.h +++ b/lib/data/mysql/database_class.h @@ -25,14 +25,15 @@ class MySQL_Connector{ uint16_t m_nPort; public: MySQL_Connector(); - MySQL_Connector( CSTR DBHost, CSTR DBUser, CSTR DBPassword, U16 Port = 3300 ); - MySQL_Connector( CSTR DBName, CSTR DBHost, CSTR DBUser, CSTR DBPassword, U16 Port = 3300 ); + MySQL_Connector( CSTR DBHost, CSTR DBUser, CSTR DBPassword, U16 Port = 3306 ); + MySQL_Connector( CSTR DBName, CSTR DBHost, CSTR DBUser, CSTR DBPassword, U16 Port = 3306 ); //MySQL_Connector( char *LocalUnixSocket, char *DBUser, char* DBPassword ); virtual ~MySQL_Connector(); - bool Connect( CSTR DBHost, CSTR DBUser, CSTR DBPassword, uint16_t Port = 3300 ); - bool Connect( CSTR DBName, CSTR DBHost, CSTR DBUser, CSTR DBPassword, uint16_t Port = 3300 ); + bool Connect( CSTR DBHost, CSTR DBUser, CSTR DBPassword, uint16_t Port = 3306 ); + bool Connect( CSTR DBName, CSTR DBHost, CSTR DBUser, CSTR DBPassword, uint16_t Port = 3306 ); bool ReConnect( void ); CSTR escapeString( CSTR str ); + CSTR escapeBinary( uint8_t *Data, uint32_t Size ); bool isConnected( void ){ return m_bIsConnected; }; uint64_t QueryID( CSTR QS ); void SilentQuery( CSTR QS ); diff --git a/lib/rgoose/rgooseCamera.cpp b/lib/rgoose/rgooseCamera.cpp index 126db71d..7835d1c2 100644 --- a/lib/rgoose/rgooseCamera.cpp +++ b/lib/rgoose/rgooseCamera.cpp @@ -1087,15 +1087,41 @@ bool ARGUS_Camera::testFOV( C3D_SPH_RADIANS L ){ bool ARGUS_Camera::testFOV( C3D_SPH_DEGREES SL ){ #ifdef DEBUG char tB[128]; - if( SL.r > m_fMaxRange || SL.r < m_fMinRange ){ - sprintf( tB, "Target Range( %.3f.m ) is not in a Range %.3f.m <-> %.3f.m", SL.r, m_fMinRange, m_fMaxRange ); - LOG( tB ); - return false; - }; -#else - if( SL.r > m_fMaxRange || SL.r < m_fMinRange ) return false; #endif - + + switch ( m_sCamData.triggering_mode ) { + case CAM_TRIGGER_STRICT:{ + if( SL.r > m_fMaxRange || SL.r < m_fMinRange ){ +#ifdef DEBUG + sprintf( tB, "Target Range( %.3f.m ) is not in a Range %.3f.m <-> %.3f.m", SL.r, m_fMinRange, m_fMaxRange ); + LOG( tB ); +#endif + return false; + }; + break; + }; + case CAM_TRIGGER_ALL_NEAR:{ + if( SL.r > m_fMaxRange ){ +#ifdef DEBUG + sprintf( tB, "Target Range( %.3f.m ) is not in a Range %.3f.m <-> %.3f.m", SL.r, m_fMinRange, m_fMaxRange ); + LOG( tB ); +#endif + return false; + }; + break; + }; + case CAM_TRIGGER_ALL_FAR:{ + if( SL.r < m_fMinRange ){ +#ifdef DEBUG + sprintf( tB, "Target Range( %.3f.m ) is not in a Range %.3f.m <-> %.3f.m", SL.r, m_fMinRange, m_fMaxRange ); + LOG( tB ); +#endif + return false; + }; + break; + }; + case CAM_TRIGGER_ALL: return true; + }; float HS = AC_imager_width[m_sCamData.imager_type]; float VS = AC_imager_height[m_sCamData.imager_type]; diff --git a/lib/rgoose/rgooseDBConnector.cpp b/lib/rgoose/rgooseDBConnector.cpp index e22b8069..d390adbc 100644 --- a/lib/rgoose/rgooseDBConnector.cpp +++ b/lib/rgoose/rgooseDBConnector.cpp @@ -2458,6 +2458,7 @@ DBC_CAM_DATA *argusDBC::getCamData( uint32_t ID ){ if( it != cArr->end() ){ tVal->zoom = atof( it->second.c_str() ); }; + //it = cArr->find("max_range"); //if( it != cArr->end() ){ // tVal->max_range = atof( it->second.c_str() ); @@ -2498,6 +2499,10 @@ DBC_CAM_DATA *argusDBC::getCamData( uint32_t ID ){ if( it != cArr->end() ){ strncpy( tVal->ptz_token, it->second.c_str(), 64); }; + it = cArr->find("trigger_mode"); + if( it != cArr->end() ){ + tVal->triggering_mode = atoi( it->second.c_str() ); + }; }; }; }; @@ -3857,25 +3862,36 @@ uint32_t argusDBC::addVideoRecord( uint32_t streamID, CSTR md5, uint32_t partID }; bool argusDBC::addPicture( DBC_SNAPSHOT_DATA *ptr, CSTR ext ){ - if( ptr == NULL ) return false; - if( m_bIsConnected ){ - uint32_t pic_id; - char tQBuf[MAX_PATH_LEN]; - sprintf( tQBuf, "INSERT INTO `pictures` SET `media_stream_id`=%d, `ts`=NOW(), `md5`='%s', `ext`='%s'", - ptr->stream_id, ptr->md5, ext ); -#ifdef DEBUG_ALL - LOG(tQBuf); -#endif - pic_id = (uint32_t) m_pDatabase->QueryID( tQBuf ); - if ( pic_id ) { - for( DBC_INT_LIST::iterator idx = ptr->assoc_event_ids.begin(); idx < ptr->assoc_event_ids.end(); idx++ ) { - sprintf( tQBuf, "INSERT INTO `events_2_pictures` SET `evt_id`=%d, `picture_id`=%d", (*idx), pic_id ); - m_pDatabase->SilentQuery( tQBuf ); + bool rVal = false; + if( ptr != NULL ){ + if( m_bIsConnected ){ + CSTR tPData = m_pDatabase->escapeBinary( ptr->data, ptr->data_size ); + if ( tPData ) { + uint32_t pic_id; + CSTR tQBuf = (CSTR)malloc(BUF_4MB); + if( tQBuf ) { + //sprintf( tQBuf, "INSERT INTO `pictures` SET `media_stream_id`=%d, `ts`=NOW(), `md5`='%s', `ext`='%s'", + sprintf( tQBuf, "INSERT INTO pictures(media_stream_id,ts,md5,ext,data) VALUES(%d,NOW(),'%s','%s','%s')", + ptr->stream_id, ptr->md5, ext, tPData ); + pic_id = (uint32_t) m_pDatabase->QueryID( tQBuf ); + if ( pic_id ) { + for( DBC_INT_LIST::iterator idx = ptr->assoc_event_ids.begin(); idx < ptr->assoc_event_ids.end(); idx++ ) { + sprintf( tQBuf, "INSERT INTO `events_2_pictures` SET `evt_id`=%d, `picture_id`=%d", (*idx), pic_id ); + m_pDatabase->SilentQuery( tQBuf ); + }; + rVal = true; + }; + free( tQBuf ); + } else { + LOG_ERROR("Error Allocating Query Buffer!"); + }; + free( tPData ); + } else { + LOG_ERROR( "Error escaping Pic Data!"); }; - return true; }; }; - return false; + return rVal; }; bool argusDBC::updateLRFDetectionProfile( uint32_t lrfID, uint8_t profileID, bool master, uint16_t nOrder, uint16_t nOffset, uint16_t nDelta, uint16_t nWidth, uint16_t nFlip, uint16_t nSun, uint8_t bSST, uint32_t GP, uint32_t spikes ){ diff --git a/lib/rgoose/rgooseModuleEmbedVideo.cpp b/lib/rgoose/rgooseModuleEmbedVideo.cpp index d2391ce1..d70301b8 100644 --- a/lib/rgoose/rgooseModuleEmbedVideo.cpp +++ b/lib/rgoose/rgooseModuleEmbedVideo.cpp @@ -900,20 +900,11 @@ void argusModuleEmbedVideo::dispatchEvent( EVENT_CONTAINER *Evt ){ #endif DBC_SNAPSHOT_DATA *tData = (DBC_SNAPSHOT_DATA *) Evt->m_pEvtData; if( tData ){ - if( saveStreamPicture(tData) ){ - //Create Event Finish Capture - } else { -#ifdef DEBUG - LOG_ERROR("Save Error!"); -#endif - }; - LOG("Free Data!"); + if( !saveStreamPicture( tData ) ) LOG_ERROR("Save Error!"); tData->assoc_event_ids.clear(); delete( tData ); Evt->m_pEvtData = NULL; - } else { - LOG("No Data!"); - }; + } else LOG_ERROR("No Evt Data!"); break; }; }; @@ -928,54 +919,31 @@ void argusModuleEmbedVideo::dispatchEvent( EVENT_CONTAINER *Evt ){ bool argusModuleEmbedVideo::saveStreamPicture( DBC_SNAPSHOT_DATA *ptr ){ if( ptr == NULL ) return false; if( ptr->assoc_event_ids.size() ){ - LOG("Have EVTS!"); - if( m_mapCAPTURES.find( ptr->stream_id ) != m_mapCAPTURES.end()) { - LOG("CAP FOUND!"); - FILE *tFD; + if( m_mapCAPTURES.find( ptr->stream_id ) != m_mapCAPTURES.end() ){ m_mPictureProtector.lock(); - size_t tBufferSize = m_mapCAPTURES[ptr->stream_id].size(); - uint8_t * tBuffer = (uint8_t *) malloc( tBufferSize ); - if( tBuffer ){ - LOG("Buff OK!"); - memcpy( tBuffer, m_mapCAPTURES[ptr->stream_id].data(), tBufferSize ); + ptr->data = (uint8_t *) malloc( m_mapCAPTURES[ptr->stream_id].size() ); + if( ptr->data ){ + ptr->data_size = m_mapCAPTURES[ptr->stream_id].size(); + memcpy( ptr->data, m_mapCAPTURES[ptr->stream_id].data(), ptr->data_size ); m_mPictureProtector.unlock(); - - CSTR MD5 = MD5Binary( tBuffer, tBufferSize ); + CSTR MD5 = MD5Binary( ptr->data, ptr->data_size ); if( MD5 ){ - LOG("MD5 OK!"); - char tFileName[MAX_PATH]; strncpy( ptr->md5, MD5, 32 ); - LOG( ptr->md5 ); - free(MD5); - if( generateSavePicPath( ptr->md5, tFileName ) ){ - LOG( tFileName ); - FILE *fd = fopen( tFileName, "wb+" ); - if( fd ){ - fwrite( tBuffer, 1, tBufferSize, fd ); - fclose(fd); - chown( tFileName, "nobody", "nogroup" ); - return m_pDBC->addPicture( ptr, "jpg" ); - //retVal = m_pDBC->addPicture( id, MD5, "jpg" ); - } else { - LOG_ERROR("Can not open picture file!"); - }; - } else { - LOG_ERROR("Can not generate file name!"); - }; - - } else { - LOG_ERROR("no MD5 Hash!"); - }; - free(tBuffer); + free( MD5 ); + if( !m_pDBC->addPicture( ptr, "jpg" ) ) LOG_ERROR("Database Error to consume capture!"); + } else LOG_ERROR("no MD5 Hash!"); + free( ptr->data ); } else { m_mPictureProtector.unlock(); - LOG_ERROR("no memory to allocate!"); + LOG_ERROR("No memory to allocate!"); }; - } else { + } #ifdef DEBUG + else { LOG("No apropriate Stream Found!"); + } #endif - }; + ; }; return true; }; @@ -1000,16 +968,10 @@ bool argusModuleEmbedVideo::saveStreamPicture( uint32_t id ){ fclose(fd); chown( tFileName, "nobody", "nogroup" ); //retVal = m_pDBC->addPicture( id, MD5, "jpg" ); - } else { - LOG_ERROR("Can not open picture file!"); - }; - } else { - LOG_ERROR("Can not generate file name!"); - }; + } else LOG_ERROR("Can not open picture file!"); + } else LOG_ERROR("Can not generate file name!"); free(MD5); - } else { - LOG_ERROR("no MD5 Hash!"); - }; + } else LOG_ERROR("no MD5 Hash!"); free(tBuffer); } else { m_mPictureProtector.unlock(); @@ -1020,16 +982,12 @@ bool argusModuleEmbedVideo::saveStreamPicture( uint32_t id ){ }; int argusModuleEmbedVideo::getWidh( void ){ - if( m_sEmbedVideoData.width ){ - return m_sEmbedVideoData.width; - }; + if( m_sEmbedVideoData.width ) return m_sEmbedVideoData.width; return -1; }; int argusModuleEmbedVideo::getHeight( void ){ - if( m_sEmbedVideoData.height ) { - return m_sEmbedVideoData.height; - }; + if( m_sEmbedVideoData.height ) return m_sEmbedVideoData.height; return -1; }; diff --git a/lib/rgoose/rgooseNode2D.cpp b/lib/rgoose/rgooseNode2D.cpp index 437948a0..9672d949 100644 --- a/lib/rgoose/rgooseNode2D.cpp +++ b/lib/rgoose/rgooseNode2D.cpp @@ -324,7 +324,7 @@ void ARGUS_2DSensor::m_fThreadProc( void ){ }; }; } -#ifdef DEBUG +#ifdef DEBUG_EXTRA else { char tB[256]; sprintf( tB, "HWM Has No UART PORT[%d]!", m_sLRF_DATA.uart_id ); diff --git a/lib/rgoose/rgooseNodeSensor.cpp b/lib/rgoose/rgooseNodeSensor.cpp index e965ce40..814f3a14 100644 --- a/lib/rgoose/rgooseNodeSensor.cpp +++ b/lib/rgoose/rgooseNodeSensor.cpp @@ -25,51 +25,73 @@ argusNodeSensor::~argusNodeSensor(){ // scale factor -> 4/9 bool argusNodeSensor::handleDeviceDraw( uint8_t kID, void *th_data, size_t th_size, bool byMinimum ){ - LOG("TRY SAVE"); if( th_data == NULL ) return false; if( th_size == 0 ) return false; if( m_pDBC == NULL ) return false; - LOG("SAVE"); + + //Clear Old Draw CSTR old = m_pDBC->getLRFDraw( getNodeID() ); if ( old ) { // delete old draw - LOG("DELETE OLD DRAW"); char filename[256]; sprintf( filename, "data/device_draws/%s_100.png", old ); if( fileExist( filename ) ){ unlink( filename ); }; + sprintf( filename, "data/device_draws/%s_50.png", old ); + if( fileExist( filename ) ){ + unlink( filename ); + }; + sprintf( filename, "data/device_draws/%s_25.png", old ); + if( fileExist( filename ) ){ + unlink( filename ); + }; + sprintf( filename, "data/device_draws/%s_12.png", old ); + if( fileExist( filename ) ){ + unlink( filename ); + }; sprintf( filename, "data/device_draws/%s_map.png", old ); if( fileExist( filename ) ){ unlink( filename ); }; - free(old); - } else { - LOG("NO OLD DRAW"); - } + free( old ); + }; + CSTR uid = getUniqID_MD5(); if( uid == NULL ) return false; - switch (getNodeType()) { + switch( getNodeType() ){ case ARGUS_ALS_SENSOR: case ARGUS_LFS_SENSOR: case ARGUS_PLS_200_SENSOR: case ARGUS_PLS_360_SENSOR: case ARGUS_NET_PLS_200:{ - + char * emptyBG = "data/assets/images/lfs_draw_empty_100.png"; + if ( fileExist( emptyBG ) ) { + cv::Mat tImage = cv::imread( emptyBG, cv::IMREAD_UNCHANGED ); + if( tImage.rows != 512 || tImage.cols != 1024 ){ + LOG_ERROR( "Background Image wrong size (should be 1024x512)!" ); + free( uid ); + return false; + }; + //m_pDBC->addLRFDraw( getNodeID(), TH_SIZE_NODES, uid, kID, 1, true ); + } else { + LOG_ERROR( "Background Image is Not Found!" ); + free( uid ); + return false; + }; break; }; case ARGUS_3D_SENSOR:{ char * emptyBG = "data/assets/images/empty_3d.png"; thresholdNode * ptr = (thresholdNode *) th_data; - LOG("SAVE 3D DRAW!"); + if ( fileExist( emptyBG ) ) { - LOG("BG Exists"); cv::Mat tImage = cv::imread( emptyBG, cv::IMREAD_UNCHANGED ); if( tImage.rows != 512 || tImage.cols != 1024 ){ LOG_ERROR( "Background Image wrong size (should be 1024x512)!" ); free( uid ); return false; - } else LOG("BG READ"); + }; uint8_t * tMemory = tImage.data; thresholdNode * cNode = NULL; @@ -80,7 +102,7 @@ bool argusNodeSensor::handleDeviceDraw( uint8_t kID, void *th_data, size_t th_si bool no_data = false; float tVal; bool master = ( kID < 16 ); - LOG("Start Draw "); + for( int idx = 0; idx < ( TH_SIZE_NODES << 2 ); idx++ ) { // tik-tak if( ( idx % 4 ) == 0 ){ mem++; @@ -135,10 +157,13 @@ bool argusNodeSensor::handleDeviceDraw( uint8_t kID, void *th_data, size_t th_si return false; }; tImage.release(); +#ifdef DEBUG_EXTRA LOG("Draw Saved!"); - +#endif cv::Mat tMap( Q_SCAN_COUNT, TH_LINE_NODES, CV_8UC4 ); +#ifdef DEBUG_EXTRA LOG("Map Creating"); +#endif tMemory = tMap.data; for( int j = 0; j < Q_SCAN_COUNT; j++ ){ for( int i = 0; i < TH_LINE_NODES; i++ ){ @@ -228,7 +253,7 @@ bool argusNodeSensor::handleDeviceDraw( uint8_t kID, void *th_data, size_t th_si tMap.release(); m_pDBC->addLRFDraw( getNodeID(), TH_SIZE_NODES, uid, kID, 1, true ); } else { - LOG_ERROR( "Background Image is Missed!" ); + LOG_ERROR( "Background Image is Not Found!" ); free( uid ); return false; }; diff --git a/lib/rgoose/rgooseTypes.h b/lib/rgoose/rgooseTypes.h index a31b81b9..cee261c9 100644 --- a/lib/rgoose/rgooseTypes.h +++ b/lib/rgoose/rgooseTypes.h @@ -191,6 +191,12 @@ typedef enum E_ARGUS_NETWORK_TYPE{ NETWORK_IPV6 = 1, } ARGUS_NETWORK_TYPE; +typedef enum E_ARGUS_CAM_TRIGGER_MODE{ + CAM_TRIGGER_STRICT = 0, + CAM_TRIGGER_ALL_NEAR = 1, + CAM_TRIGGER_ALL_FAR = 2, + CAM_TRIGGER_ALL = 3 +}ARGUS_CAM_TRIGGER_MODE; typedef struct S_DBC_CAM_DATA{ uint32_t id; @@ -230,6 +236,7 @@ typedef struct S_DBC_CAM_DATA{ char onvif_access[6]; char onvif_ctrl[251]; char ptz_token[65]; + uint8_t triggering_mode; }DBC_CAM_DATA; typedef struct S_DBC_NETWORK_DATA{ @@ -590,6 +597,8 @@ typedef struct S_DBC_SNAPSHOT_DATA{ DBC_INT_LIST assoc_event_ids; uint32_t stream_id; uint32_t ts; + uint32_t data_size; + uint8_t * data; }DBC_SNAPSHOT_DATA;