@ -13,6 +13,7 @@
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
//
//
# include <cmath>
# include "mojoKernel.h"
# include "mojoKernel.h"
static int getLocalReportPeriod ( void ) ;
static int getLocalReportPeriod ( void ) ;
@ -972,6 +973,10 @@ void mojoKernel::m_fThreadProc(void){
case CMD_KRNL_SYSTEM_TASK : {
case CMD_KRNL_SYSTEM_TASK : {
break ;
break ;
} ;
} ;
case CMD_KRNL_MAP_ROI : {
mapROI ( tCMD - > PARAM ) ;
break ;
} ;
case NODE_FORCE_FINISH_ALARM : {
case NODE_FORCE_FINISH_ALARM : {
stopSession ( ) ;
stopSession ( ) ;
break ;
break ;
@ -1267,6 +1272,79 @@ void mojoKernel::validateFilters()
} ;
} ;
}
}
/*
CMD_KRNL_MAP_ROI : a click on the monitoring map ( Mojo_Web doApplicationOperation 15 ) .
PARAM " <format>;<a>;<b> " :
- format 0 : WGS84 , a = lat , b = lon ( degrees ) - > system coordinates through the site anchor ( UTM , meters ) ;
- format 1 : local binding ( bitmap map ) , a = y , b = x in map units : the map shows a node at
anchor + its local coordinates , so system = map - anchor .
The point is sent as EVT_ROI_ACTIVE ( EVT_CLASS_SYSTEM ) like a sensor ' s ROI : it is an event of the
report ( dispatchEvent ) and every camera that can see it ( testFOV ) looks at it .
*/
bool mojoKernel : : mapROI ( const char * param )
{
char tB [ 256 ] ;
int tFormat = - 1 ;
double tA = 0 , tC = 0 ;
if ( param = = NULL | | sscanf ( param , " %d;%lf;%lf " , & tFormat , & tA , & tC ) ! = 3 | | ( tFormat ! = 0 & & tFormat ! = 1 ) | | ! std : : isfinite ( tA ) | | ! std : : isfinite ( tC ) )
{
snprintf ( tB , sizeof ( tB ) , " Map ROI: wrong parameter [%.64s] " , param ? param : " " ) ;
LOG_ERROR ( tB ) ;
return false ;
} ;
if ( m_pSystemAnchor = = NULL )
{
LOG_ERROR ( " Map ROI: no system anchor! " ) ;
return false ;
} ;
bool tLocal = ( tFormat = = 1 ) ;
if ( tLocal ! = m_pSystemAnchor - > beLocal ( ) )
{
// the map type was changed after the start: the anchor still uses the other system
snprintf ( tB , sizeof ( tB ) , " Map ROI: the map is %s, the site anchor is %s - ignored (restart needed) " , tLocal ? " local " : " WGS84 " , m_pSystemAnchor - > beLocal ( ) ? " local " : " WGS84 " ) ;
LOG_ERROR ( tB ) ;
return false ;
} ;
TARGET_DATA * tData = ( TARGET_DATA * ) malloc ( sizeof ( TARGET_DATA ) ) ; // freed with the event
if ( tData = = NULL )
{
return false ;
} ;
memset ( tData , 0 , sizeof ( TARGET_DATA ) ) ;
tData - > source_position . lat = m_pSystemAnchor - > getLat ( ) ;
tData - > source_position . lon = m_pSystemAnchor - > getLon ( ) ;
tData - > source_position . alt = m_pSystemAnchor - > getAlt ( ) ;
if ( tLocal )
{
tData - > system_target . x = ( C3D_FLOAT ) ( tC - m_pSystemAnchor - > getX ( ) ) ;
tData - > system_target . y = ( C3D_FLOAT ) ( tA - m_pSystemAnchor - > getY ( ) ) ;
tData - > system_target . z = 0 ;
// as the sensors do in a local system
tData - > global_target . lat = tData - > system_target . y ;
tData - > global_target . lon = tData - > system_target . x ;
tData - > global_target . alt = tData - > system_target . z ;
}
else
{
tData - > global_target . lat = ( C3D_FLOAT ) tA ;
tData - > global_target . lon = ( C3D_FLOAT ) tC ;
tData - > global_target . alt = m_pSystemAnchor - > getZ ( ) ; // no height on the map: the site's ground level
m_pSystemAnchor - > convertToSystem ( tData - > global_target , tData - > system_target ) ;
} ;
snprintf ( tB , sizeof ( tB ) , " Map ROI: %s %.7f %.7f -> system x:%.2f y:%.2f z:%.2f " , tLocal ? " local " : " WGS84 " , tA , tC , tData - > system_target . x , tData - > system_target . y , tData - > system_target . z ) ;
LOG ( tB ) ;
startSession ( ) ;
EVENT_CONTAINER * bEVT = createBasicEvent ( m_nServerNodeID , EVT_CLASS_SYSTEM , EVT_ROI_ACTIVE , NULL , NULL , tData ) ;
if ( bEVT = = NULL )
{
LOG_ERROR ( " Map ROI: event creation failure! " ) ;
free ( tData ) ;
return false ;
} ;
m_pEventHeap - > broadcast ( bEVT ) ;
return true ;
}
bool mojoKernel : : dispatchEvent ( EVENT_CONTAINER * Evt )
bool mojoKernel : : dispatchEvent ( EVENT_CONTAINER * Evt )
{
{
if ( Evt = = NULL )
if ( Evt = = NULL )
@ -1308,6 +1386,27 @@ bool mojoKernel::dispatchEvent(EVENT_CONTAINER * Evt)
case EVT_CLASS_SYSTEM :
case EVT_CLASS_SYSTEM :
switch ( Evt - > m_eType )
switch ( Evt - > m_eType )
{
{
case EVT_ROI_ACTIVE :
{
// Map ROI (mapROI): an event of the report like a sensor's ROI, the cameras look at the point
preserveSession ( ) ;
TARGET_DATA * tDATA = ( TARGET_DATA * ) Evt - > m_pEvtData ;
if ( tDATA ! = NULL )
{
DBC_EVT_RECORD tRecord ;
memset ( & tRecord , 0 , sizeof ( DBC_EVT_RECORD ) ) ;
tRecord . node_id = Evt - > m_nSourceNodeID ;
tRecord . type = Evt - > m_eType ;
strncpy ( tRecord . uuid , Evt - > m_UUID , 64 ) ;
tRecord . ts_s = Evt - > m_UMSTS / 1000 ;
tRecord . ts_ms = Evt - > m_UMSTS % 1000 ;
tRecord . lat = tDATA - > global_target . lat ;
tRecord . lon = tDATA - > global_target . lon ;
tRecord . alt = tDATA - > global_target . alt ;
Evt - > m_db_id = m_pDBC - > addEvent ( & tRecord ) ;
} ;
break ;
} ;
case EVT_LRF_START_SESSION :
case EVT_LRF_START_SESSION :
case EVT_LRF_END_SESSION_TO :
case EVT_LRF_END_SESSION_TO :
case EVT_LRF_END_SESSION_MA :
case EVT_LRF_END_SESSION_MA :