diff --git a/lib/App/common/SQLite_dataBinder.cpp b/lib/App/common/SQLite_dataBinder.cpp index 438058fe..1452616a 100644 --- a/lib/App/common/SQLite_dataBinder.cpp +++ b/lib/App/common/SQLite_dataBinder.cpp @@ -2792,12 +2792,12 @@ uint32_t sqliteDBC::getNetworkInfrastructureID( uint32_t nif_id ){ return tVal; }; -TARGET_SEGMENT *sqliteDBC::getRegisteredBubble( uint32_t ID ){ +TARGET_SEGMENT *sqliteDBC::getRegisteredBubble( uint32_t ID, uint8_t Blocking_Count ){ TARGET_SEGMENT *tVal = NULL; if( m_bStaIsCreated ){ char tQBuf[CTEXT]; AAssoc *result; - sprintf(tQBuf, "SELECT * FROM `days` WHERE `ROWID`=%d", ID ); + sprintf(tQBuf, "SELECT * FROM `target_bubbles` WHERE `id`=%d", ID ); #ifdef DEBUG_ALL LOG(tQBuf); #endif @@ -2809,7 +2809,7 @@ TARGET_SEGMENT *sqliteDBC::getRegisteredBubble( uint32_t ID ){ Assoc *cArr; Assoc::iterator it; memset( tVal, 0 , sizeof( TARGET_SEGMENT )); - tVal->id = ID; + tVal->db_id = ID; cArr = result->at(0); it = cArr->find("CENTER_X"); if( it != cArr->end() ){ @@ -2827,22 +2827,6 @@ TARGET_SEGMENT *sqliteDBC::getRegisteredBubble( uint32_t ID ){ if( it != cArr->end() ){ tVal->boundary = atof(it->second.c_str()); }; - it = cArr->find("TTL"); - if( it != cArr->end() ){ - tVal->ttl = atoi(it->second.c_str()); - }; - it = cArr->find("BLOCKED"); - if( it != cArr->end() ){ - tVal->blocked = (bool) atoi(it->second.c_str()); - }; - it = cArr->find("BLOCK_COUNS"); - if( it != cArr->end() ){ - tVal->blocked_count = atoi(it->second.c_str()); - }; - it = cArr->find("HIT_COUNS"); - if( it != cArr->end() ){ - tVal->hit_count = atoi(it->second.c_str()); - }; }; }; }; @@ -4264,10 +4248,20 @@ BUBBLE_FILTER_DATA *sqliteDBC::getBubbleFilterData( uint32_t id ){ if( it != cArr->end() ){ tVal->beginning_range = atof( it->second.c_str() ); }; + it = cArr->find("MAX_RANGE"); + if( it != cArr->end() ){ + tVal->maximal_range = atof( it->second.c_str() ); + }; it = cArr->find("MIN_BLOCK_COUNS"); if( it != cArr->end() ){ tVal->min_block_counts = atoi( it->second.c_str() ); }; +#ifdef BUBBLE_TIME_BUCKLE + it = cArr->find("BUCKET_TIME"); + if( it != cArr->end() ){ + tVal->bucket_time = atoi( it->second.c_str() ); + }; +#endif it = cArr->find("TTL"); if( it != cArr->end() ){ tVal->ttl = atoi( it->second.c_str() ); @@ -4289,6 +4283,9 @@ BUBBLE_FILTER_DATA *sqliteDBC::getBubbleFilterData( uint32_t id ){ tVal->enable_evt = (bool) atoi( it->second.c_str() ); }; }; +#ifdef BUBBLE_TIME_BUCKLE + if ( tVal->bucket_time < BUBBLE_FILTER_MIN_BUCKET_TIME ) tVal->bucket_time = BUBBLE_FILTER_MIN_BUCKET_TIME; +#endif }; }; deleteResult( result ); @@ -4917,20 +4914,31 @@ bool sqliteDBC::updateRegisteredBubble( TARGET_SEGMENT *ptr ){ if ( ptr == NULL ) return false; if (m_bStoIsConnected) { char tQBuf[MAX_PATH_LEN]; - sprintf(tQBuf, "UPDATE `target_bubbles` SET `CENTER_X`=%0.3f, `CENTER_Y`=%0.3f, `CENTER_Z`=%0.3f, `BOUNDARY`=%0.3f, `TTL`=%d, `HIT_COUNS`=%d, `BLOCK_COUNS`=%d, `BLOCKED`=%d WHERE `id`=%d", + if( ptr->db_id > 0 ) { + // Old record exists + sprintf(tQBuf, "UPDATE `target_bubbles` SET `CENTER_X`=%0.3f, `CENTER_Y`=%0.3f, `CENTER_Z`=%0.3f, `BOUNDARY`=%0.3f, `BLOCK_COUNS`=`BLOCK_COUNS`+1 WHERE `id`=%d", ptr->system_center.x, ptr->system_center.y, ptr->system_center.z, ptr->boundary, - ptr->ttl, - ptr->hit_count, - ptr->blocked_count, - ptr->blocked, - ptr->id ); + ptr->db_id ); + } else { + //Create New Record for Bubble + sprintf(tQBuf, "INSERT INTO `target_bubbles` SET `CENTER_X`=%0.3f, `CENTER_Y`=%0.3f, `CENTER_Z`=%0.3f, `BOUNDARY`=%0.3f, `TTL`=%d, `BLOCK_COUNS`=1", + ptr->system_center.x, + ptr->system_center.y, + ptr->system_center.z, + ptr->boundary + ); + }; #ifdef DEBUG_ALL LOG(tQBuf); #endif - m_pDataStorage->SilentQuery( tQBuf ); + if ( ptr->db_id ) { + m_pDataStorage->SilentQuery( tQBuf ); + } else { + ptr->db_id = m_pDataStorage->QueryID( tQBuf ); + }; return true; }; return false; diff --git a/lib/App/common/SQLite_dataBinder.h b/lib/App/common/SQLite_dataBinder.h index 749dd6cf..22b10c48 100644 --- a/lib/App/common/SQLite_dataBinder.h +++ b/lib/App/common/SQLite_dataBinder.h @@ -143,7 +143,7 @@ class sqliteDBC: public dataBinder { virtual uint32_t getNodeIdByTypeAndAux( uint8_t type, uint32_t aux_id ); virtual CSTR getNodeName( uint32_t NodeID ); virtual DBC_PUSHED_CMD * getNodePushedCMD( uint32_t NodeID ); - virtual TARGET_SEGMENT * getRegisteredBubble( uint32_t ID ); + virtual TARGET_SEGMENT * getRegisteredBubble( uint32_t ID, uint8_t cc ); virtual REPORT_DIRINFO * getReportDirInfo( uint32_t id ); virtual DBC_RESOURCE_DATA * getResourceData( uint32_t ResourceID ); virtual uint32_t getResourceID( uint32_t NodeID, uint8_t type, uint32_t auxID ); diff --git a/lib/App/common/dataBinder.h b/lib/App/common/dataBinder.h index ae94f8f2..0b9a16cc 100644 --- a/lib/App/common/dataBinder.h +++ b/lib/App/common/dataBinder.h @@ -148,7 +148,7 @@ class dataBinder{ virtual DBC_PUSHED_CMD * getActivePushedCMD( uint32_t NodeID ){ return NULL;}; virtual DBC_PUSHED_CMD * getPushedCMD( uint32_t CmdID ){ return NULL;}; - virtual TARGET_SEGMENT * getRegisteredBubble( uint32_t ID ){ return NULL;}; + virtual TARGET_SEGMENT * getRegisteredBubble( uint32_t ID, uint8_t cc ){ return NULL;}; //virtual uint32_t getNodeSocketID( uint32_t NodeID, uint32_t auxID, uint8_t SocketType, CSTR path ); virtual REPORT_DIRINFO * getReportDirInfo( uint32_t id ){ return NULL;}; virtual DBC_RESOURCE_DATA * getResourceData( uint32_t ResourceID ){ return NULL;}; diff --git a/lib/App/common/dataBinder_structures.h b/lib/App/common/dataBinder_structures.h index 8d5d96f6..c34518b5 100644 --- a/lib/App/common/dataBinder_structures.h +++ b/lib/App/common/dataBinder_structures.h @@ -758,10 +758,44 @@ typedef struct S_TRAIN_FILTER_DATA{ #endif }TRAIN_FILTER_DATA; + +#define BUBBLE_TIME_BUCKET + +#ifdef BUBBLE_TIME_BUCKET + #define BUBBLE_FILTER_MIN_BUCKET_TIME 150 +#endif + +typedef enum E_TARGET_SEGMENT_MODE{ + TS_MODE_REGULAR = 0, + TS_MODE_PUNCHED = 1, + TS_MODE_BLOCKED = 2, + TS_MODE_PERMANENT = 3 +}TARGET_SEGMENT_MODE; + +typedef struct S_TARGET_SEGMENT{ + C3D_DECART system_center; + uint32_t segment_id; + float boundary; + uint64_t bts; // milliseconds + uint64_t ttl; // milliseconds +#ifdef BUBBLE_TIME_BUCKET + uint32_t hit_map; // for actual usage +#endif + uint8_t hit_count; // for actual usage + uint8_t mode; + //bool blocked; + //bool permanent; + uint32_t db_id; +}TARGET_SEGMENT; + typedef struct S_BUBBLE_FILTER_DATA{ uint32_t id; float beginning_range; // mters + float maximal_range; // mters uint8_t min_block_counts; // counts +#ifdef BUBBLE_TIME_BUCKET + uint16_t bucket_time; // milliseconds +#endif uint32_t ttl; //milliseconds uint8_t t2t; // SST counts uint8_t method; diff --git a/lib/App/common/kernelEventFilterBubble.cpp b/lib/App/common/kernelEventFilterBubble.cpp index 9f4e802c..60ff1237 100644 --- a/lib/App/common/kernelEventFilterBubble.cpp +++ b/lib/App/common/kernelEventFilterBubble.cpp @@ -13,7 +13,7 @@ #define LOG_ERROR( X ) m_pLog->Log( "TBF", this, _LOG_ERROR, X ); #endif -kernelEventFilterBubble::kernelEventFilterBubble( uint32_t id ):kernelEventFilter( id, TF_BUBBLE_SEGMENTATION_FILTER ){ +kernelEventFilterBubble::kernelEventFilterBubble( uint32_t id ):kernelEventFilter( id, TF_BUBBLE_SEGMENTATION_FILTER ),basicEventHandler(),basicThread(){ m_pLog = basicLogCollection::getInstance(); }; @@ -25,6 +25,7 @@ kernelEventFilterBubble::~kernelEventFilterBubble(){ m_vTargetBubbles.clear(); }; }; + uint32_t kernelEventFilterBubble::serial = 0; bool kernelEventFilterBubble::createBubble( TARGET_DATA *ptr ){ @@ -47,8 +48,9 @@ bool kernelEventFilterBubble::createBubble( TARGET_DATA *ptr ){ bool kernelEventFilterBubble::createBubble( TARGET_SEGMENT *ptr ){ if ( ptr == NULL ) return false; - ptr->ttl = getMilliseconds() + m_sBubbleFilterData.ttl; - m_mDataProtector.lock(); + ptr->bts = getMilliseconds(); + ptr->ttl = ptr->bts + m_sBubbleFilterData.ttl; + m_mDataProtector.lock(); m_vTargetBubbles.push_back( ptr ); m_mDataProtector.unlock(); return true; @@ -86,7 +88,7 @@ bool kernelEventFilterBubble::initFilter(){ if ( tList ) { if ( tList->size() ) { for ( DBC_INT_LIST::iterator idx = tList->begin(); idx != tList->end(); idx++ ) { - TARGET_SEGMENT *tBubble = m_pDBC->getRegisteredBubble( *idx ); + TARGET_SEGMENT *tBubble = m_pDBC->getRegisteredBubble( *idx, m_sBubbleFilterData.min_block_counts ); if ( tBubble ) { if ( !createBubble( tBubble ) ) free( tBubble ); }; @@ -104,9 +106,9 @@ void kernelEventFilterBubble::m_fThreadProc( void ){ if( m_vTargetBubbles.size() ) { uint64_t ctx = getMilliseconds(); for( V_TARGET_SEGMENTS::iterator idx = m_vTargetBubbles.begin(); idx != m_vTargetBubbles.end(); ) { - // If not frozen - if( (*idx)->blocked_count < m_sBubbleFilterData.min_block_counts ) { - if( (*idx)->ttl < ctx ) { + // If not frozen or Blocked + if( (*idx)->mode < TS_MODE_BLOCKED ) { + if( (*idx)->ttl < ctx ) { // Popping Bubble if ( m_sBubbleFilterData.enable_evt ) { //Triggering Session in Kernel kernelPrototype *AK = kernelPrototype::getInstance(); @@ -116,7 +118,7 @@ void kernelEventFilterBubble::m_fThreadProc( void ){ if ( tData ) { memset( tData, 0, sizeof(TARGET_DATA) ); decart2spherical( (*idx)->system_center, tData->local_target ); - tData->area = (*idx)->boundary*1000; + tData->area = (*idx)->ttl - (*idx)->bts; tData->digital = 0; tData->system_target.x = (*idx)->system_center.x; tData->system_target.y = (*idx)->system_center.y; @@ -159,10 +161,31 @@ bool kernelEventFilterBubble::checkBubble( TARGET_SEGMENT *bubble, TARGET_DATA * bool kernelEventFilterBubble::updateBubble( TARGET_SEGMENT *bubble, TARGET_DATA *target ){ if ( bubble == NULL ) return false; if ( target == NULL ) return false; - bubble->ttl = getMilliseconds() + m_sBubbleFilterData.ttl; - bubble->hit_count++; - //Only For Not Frozen Bubles - if( bubble->blocked_count < m_sBubbleFilterData.min_block_counts ){ + uint64_t cts = getMilliseconds(); + bubble->ttl = cts + m_sBubbleFilterData.ttl; + + //Only Active Bubles + if( bubble->mode < TS_MODE_PERMANENT ){ + if ( !bubble->mode < TS_MODE_PUNCHED ) { +#ifdef BUBBLE_TIME_BUCKET + uint8_t bucket_id = ( cts - bubble->bts ) / m_sBubbleFilterData.bucket_time; + if( bucket_id < 32 ){ + bubble->hit_map |= (1 << bucket_id) & 0xFFFFFFFF; + + bubble->hit_count = 0; + for ( uint8_t i=0; i< 32; i++) if( bubble->hit_map & ( 1<< i ) ) bubble->hit_count++; + }; +#else + bubble->hit_count++; +#endif + if ( bubble->hit_count == m_sBubbleFilterData.t2t ) { + bubble->mode = TS_MODE_PUNCHED; //westlake 200 + bubble->boundary = m_sBubbleFilterData.maximal_range; + }; + } else { + // gen signal to Kernel to continue session on blocked target + }; + switch ( m_sBubbleFilterData.method ) { case TF_BUBBLE_METHOD_FIXED:{ break; @@ -193,18 +216,17 @@ bool kernelEventFilterBubble::updateBubble( TARGET_SEGMENT *bubble, TARGET_DATA break; }; }; + if ( bubble->boundary > m_sBubbleFilterData.maximal_range ) { + bubble->boundary = m_sBubbleFilterData.maximal_range; + }; }; - return true;//m_pDBC->updateRegisteredBubble(bubble); + return true; }; bool kernelEventFilterBubble::blockCurrentActiveBubbles(){ m_mDataProtector.lock(); for( V_TARGET_SEGMENTS::iterator idx = m_vTargetBubbles.begin(); idx != m_vTargetBubbles.end(); idx++ ) { - if( (*idx)->blocked_count < m_sBubbleFilterData.min_block_counts ){ - (*idx)->blocked = true; - (*idx)->blocked_count++; - m_pDBC->updateRegisteredBubble((*idx)); - }; + if( (*idx)->mode == TS_MODE_PUNCHED ) (*idx)->mode = TS_MODE_BLOCKED; }; m_mDataProtector.unlock(); }; @@ -240,25 +262,20 @@ bool kernelEventFilterBubble::validateTarget( uint32_t DevID, TARGET_DATA *ptr ) }; m_mDataProtector.unlock(); if ( cBubble != NULL ) { - if( cBubble->blocked_count >= m_sBubbleFilterData.min_block_counts ){ - //If frozen - RetValue = true; - } else { - if( cBubble->hit_count < m_sBubbleFilterData.t2t ) { - RetValue = true; - } else { - ptr->segment_id = cBubble->segment_id; - if ( m_sBubbleFilterData.propogate == 1 ) { - ptr->system_target.x = cBubble->system_center.x; - ptr->system_target.y = cBubble->system_center.y; - ptr->system_target.z = cBubble->system_center.z; - //Update All other coords of target - decart2spherical( ptr->system_target, ptr->local_target ); - ptr->global_target.lat = ptr->system_target.y; - ptr->global_target.lon = ptr->system_target.x; - ptr->global_target.alt = ptr->system_target.z; - }; + if( cBubble->mode == TS_MODE_PUNCHED ) { + ptr->segment_id = cBubble->segment_id; + if ( m_sBubbleFilterData.propogate == 1 ) { + ptr->system_target.x = cBubble->system_center.x; + ptr->system_target.y = cBubble->system_center.y; + ptr->system_target.z = cBubble->system_center.z; + //Update All other coords of target + decart2spherical( ptr->system_target, ptr->local_target ); + ptr->global_target.lat = ptr->system_target.y; + ptr->global_target.lon = ptr->system_target.x; + ptr->global_target.alt = ptr->system_target.z; }; + } else { + RetValue = true; }; } else { RetValue = createBubble( ptr ); @@ -267,10 +284,35 @@ bool kernelEventFilterBubble::validateTarget( uint32_t DevID, TARGET_DATA *ptr ) return RetValue; }; -//bool kernelEventFilterBubble::dispatchEvent( EVENT_CONTAINER *Evt ){ - //Check Only Session Ending -> To pop Frozen -// return true; -//} +bool kernelEventFilterBubble::popSessionBubbles(){ + m_mDataProtector.lock(); + if ( m_vTargetBubbles.size() ) { + for( V_TARGET_SEGMENTS::iterator idx = m_vTargetBubbles.begin(); idx != m_vTargetBubbles.end(); ){ + if( (*idx)->mode == TS_MODE_BLOCKED ) { + m_pDBC->updateRegisteredBubble((*idx)); + m_vTargetBubbles.erase(idx); + } else { + idx++; + }; + }; + }; + m_mDataProtector.unlock(); + return true; +}; + +bool kernelEventFilterBubble::dispatchEvent( EVENT_CONTAINER *Evt ){ + if( Evt == NULL ) return false; + if( m_pDBC == NULL) return false; + switch( Evt->m_eClass ) { + case EVT_CLASS_SYSTEM: + switch (Evt->m_eType) { + case EVT_LRF_END_SESSION_TO: + case EVT_LRF_END_SESSION_MA: popSessionBubbles(); break; + }; + break; + }; + return true; +}; #undef LOG #undef LOG_ERROR diff --git a/lib/App/common/kernelEventFilterBubble.h b/lib/App/common/kernelEventFilterBubble.h index 60d877d0..3f6f68cd 100644 --- a/lib/App/common/kernelEventFilterBubble.h +++ b/lib/App/common/kernelEventFilterBubble.h @@ -15,7 +15,7 @@ typedef std::vector< TARGET_SEGMENT *> V_TARGET_SEGMENTS; #define TF_BUBBLE_METHOD_EXTENT 3 -class kernelEventFilterBubble: public kernelEventFilter, /*public basicEventHandler,*/ public basicThread{ +class kernelEventFilterBubble: public kernelEventFilter, public basicEventHandler, public basicThread{ private: basicLogCollection * m_pLog; static uint32_t serial; @@ -27,6 +27,7 @@ class kernelEventFilterBubble: public kernelEventFilter, /*public basicEventHand bool createBubble( TARGET_SEGMENT *data ); // From Loaded Data bool checkBubble( TARGET_SEGMENT *bubble, TARGET_DATA *target ); bool updateBubble( TARGET_SEGMENT *bubble, TARGET_DATA *target ); + bool popSessionBubbles(); protected: virtual void m_fThreadProc( void ); public: @@ -36,6 +37,7 @@ class kernelEventFilterBubble: public kernelEventFilter, /*public basicEventHand virtual bool initFilter(); virtual bool stopFilter(); virtual bool validate(); + virtual bool dispatchEvent( EVENT_CONTAINER *Evt ); bool blockCurrentActiveBubbles(); bool resetAllBubbles(); //virtual bool dispatchEvent( EVENT_CONTAINER *Evt ); diff --git a/lib/App/common/kernelEventFilterTrain.cpp b/lib/App/common/kernelEventFilterTrain.cpp index 0b4cbf9c..d778243e 100644 --- a/lib/App/common/kernelEventFilterTrain.cpp +++ b/lib/App/common/kernelEventFilterTrain.cpp @@ -216,8 +216,8 @@ bool kernelEventFilterTrain::validateTarget( uint32_t DevID, TARGET_DATA *ptr ){ if( m_sBottomZone.SuspiciousUnconfirmed == false ){ // Check New Suspicious #ifdef EFT_MINIMAL_RANGE_SUSPICIOUS - float a = sinf( ( ptr->local_target.fi * PI_UTM ) / 360.0f ); - float b = cosf( ( ptr->local_target.fi * PI_UTM ) / 360.0f ); + float a = sinf( ( ptr->local_target.fi * PI_UTM ) / 180.0f ); + float b = cosf( ( ptr->local_target.fi * PI_UTM ) / 180.0f ); float cfr; if( ptr->local_target.fi > 90.0f ) { cfr = sqrtf( powf( a*(m_sTrainFilterData.fRightMinimalRange+m_sTrainFilterData.fRightMinimalRange)/2.0f, 2.0f) + powf(b*m_sTrainFilterData.fLeftMinimalRange, 2.0f) ); diff --git a/lib/App/mojo/mojoKernel.cpp b/lib/App/mojo/mojoKernel.cpp index 8c07dcde..2d657c2c 100644 --- a/lib/App/mojo/mojoKernel.cpp +++ b/lib/App/mojo/mojoKernel.cpp @@ -1200,6 +1200,9 @@ bool mojoKernel::dispatchEvent( EVENT_CONTAINER *Evt ){ }; case EVT_CLASS_KRNL_FILTER_BUBBLE:{ if( Evt->m_eType == EVT_FLT_BUBBLE_POPED ){ + + preserveSession(); + TARGET_DATA *tDATA = (TARGET_DATA *) Evt->m_pEvtData; DBC_EVT_RECORD tRecord; memset( &tRecord, 0, sizeof(DBC_EVT_RECORD)); diff --git a/lib/components/base/basicEvent.h b/lib/components/base/basicEvent.h index 972d1aa3..fe2fa3ac 100644 --- a/lib/components/base/basicEvent.h +++ b/lib/components/base/basicEvent.h @@ -201,17 +201,6 @@ typedef struct S_TARGET_DATA { float area; }TARGET_DATA; -typedef struct S_TARGET_SEGMENT{ - uint32_t id; - C3D_DECART system_center; - uint32_t segment_id; - float boundary; - uint64_t ttl; // milliseconds - bool blocked; - uint8_t hit_count; - uint8_t blocked_count; -}TARGET_SEGMENT; - typedef struct S_CLIENT_EVENT{ uint8_t type; //basicEventTypeID uint32_t uts; //Time Stamp Seconds diff --git a/lib/components/base/basicTypes.h b/lib/components/base/basicTypes.h index 782dd979..cde8a523 100644 --- a/lib/components/base/basicTypes.h +++ b/lib/components/base/basicTypes.h @@ -16,6 +16,8 @@ #ifndef __BASIC_TYPES_HEADER__ #define __BASIC_TYPES_HEADER__ +#define __STDC_FORMAT_MACROS 1 + #include #include #include