Browse Source

New Stage Management in Device Part1

AGP
Evgeny Gagua 3 years ago
parent
commit
f721a79384
  1. 165
      lib/App/common/SQLite_dataBinder.cpp
  2. 16
      lib/App/common/SQLite_dataBinder.h
  3. 7
      lib/App/common/dataBinder.h
  4. 15
      lib/App/common/dataBinder_structures.h
  5. 1604
      lib/App/common/deviceNode2D.cpp
  6. 7
      lib/App/common/deviceNode2D.h
  7. 54
      lib/App/common/deviceNodeSensor.cpp
  8. 31
      lib/App/common/deviceNodeSensor.h
  9. 4
      lib/App/common/kernelModuleEmbedVideo.cpp
  10. 157
      lib/App/mojo/mojoKernel.cpp
  11. 8
      lib/App/mojo/mojoKernel.h
  12. 6
      lib/alg/lgs/detectorStructures.h
  13. 24
      lib/data/protocol/protocolLGS2D.cpp
  14. 3
      lib/data/protocol/protocolLGS2D.h

165
lib/App/common/SQLite_dataBinder.cpp

@ -51,32 +51,25 @@ void sqliteDBC::fillRDF( uint32_t ts, REPORT_DIRINFO &RDF ){
};
};
bool sqliteDBC::createAccessibleDir( CSTR path ){
if( mkdir( path, STORAGE_DIR_MODE ) != 0 ) return false;
chown( path, web_access_user, web_access_group );
return true;
};
bool sqliteDBC::checkRDFDir( CSTR basePath, REPORT_DIRINFO &RDF ){
char tBuff[CLOG];
int RetVal;
char tBuff[MAX_PATH];
sprintf( tBuff, "%s/%s", basePath, RDF.YEAR );
if( fileExist( tBuff ) == 0 ){
RetVal = mkdir( tBuff, STORAGE_DIR_MODE );
chown( tBuff, web_access_user, web_access_group );
if( RetVal!= 0 ) {
return false;
};
if( !createAccessibleDir( tBuff ) ) return false;
};
sprintf( tBuff, "%s/%s/%s", basePath, RDF.YEAR, RDF.MONTH );
if( fileExist( tBuff ) == 0 ){
RetVal = mkdir( tBuff, STORAGE_DIR_MODE );
chown( tBuff, web_access_user, web_access_group );
if( RetVal!= 0 ) {
return false;
};
if( !createAccessibleDir( tBuff ) ) return false;
};
sprintf( tBuff, "%s/%s/%s/%s", basePath, RDF.YEAR, RDF.MONTH, RDF.DAY );
sprintf( tBuff, "%s/%s/%s/%s", basePath, RDF.YEAR, RDF.MONTH, RDF.DAY );
if( fileExist( tBuff ) == 0 ){
RetVal = mkdir( tBuff, STORAGE_DIR_MODE );
chown( tBuff, web_access_user, web_access_group );
if( RetVal!= 0 ) {
return false;
};
if( !createAccessibleDir( tBuff ) ) return false;
};
return true;
};
@ -529,6 +522,14 @@ void sqliteDBC::deleteNetwork( uint32_t NetID ){
};
bool sqliteDBC::deleteReportStat( uint32_t id ){
if ( m_bStaIsConnected ) {
char tQBuf[MAX_PATH_LEN];
sprintf(tQBuf, "DELETE FROM `days` WHERE `ROWID`=%d", id );
m_pDataStatistics->SilentQuery( tQBuf );
};
};
void sqliteDBC::deleteResource( uint32_t ResourceID ){
};
@ -1638,6 +1639,32 @@ bool sqliteDBC::getEventSessionStatus( uint32_t nodeID ){
return rv;
};
uint32_t sqliteDBC::getLastEventTS(){
uint32_t rv = 0;
if( m_bRepIsConnected ){
char tQBuf[CTEXT];
AAssoc *result;
sprintf( tQBuf, "SELECT `ts` FROM `events` ORDER BY `ts` DESC, `ts_ms` DESC LIMIT 1" );
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDataReports->Query( tQBuf );
if( result!= NULL ) {
if( result->size() > 0 ) {
Assoc *cArr;
Assoc::iterator it;
cArr = result->at(0);
it = cArr->find("ts");
if( it != cArr->end() ){
rv = atoi( it->second.c_str() );
};
};
};
deleteResult( result );
};
return rv;
};
DBC_LRF_DATA *sqliteDBC::getLRFData( uint32_t ID ){
DBC_LRF_DATA * tVal = NULL;
if( m_bStoIsConnected ){
@ -2214,6 +2241,44 @@ uint32_t sqliteDBC::getNetworkInfrastructureID( uint32_t nif_id ){
return tVal;
};
REPORT_DIRINFO *sqliteDBC::getReportDirInfo( uint32_t id ){
REPORT_DIRINFO *tVal = NULL;
if( m_bStaIsCreated ){
char tQBuf[CTEXT];
AAssoc *result;
sprintf(tQBuf, "SELECT * FROM `days` WHERE `ROWID`=%d", id );
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
result = m_pDataStorage->Query( tQBuf );
if( result!= NULL ) {
if( result->size() > 0 ) {
tVal = (REPORT_DIRINFO *) malloc( sizeof(REPORT_DIRINFO));
if ( tVal ) {
Assoc *cArr;
Assoc::iterator it;
memset( tVal, 0 , sizeof( REPORT_DIRINFO));
cArr = result->at(0);
it = cArr->find("year");
if( it != cArr->end() ){
strncpy( tVal->YEAR, it->second.c_str(), 5 );
};
it = cArr->find("month");
if( it != cArr->end() ){
strncpy( tVal->MONTH, it->second.c_str(), 3 );
};
it = cArr->find("day");
if( it != cArr->end() ){
strncpy( tVal->DAY, it->second.c_str(), 3 );
};
};
};
};
deleteResult( result );
};
return tVal;
};
DBC_RESOURCE_DATA *sqliteDBC::getResourceData( uint32_t ResourceID ){
DBC_RESOURCE_DATA *tVal = NULL;
if( m_bStoIsConnected ){
@ -2340,6 +2405,14 @@ DBC_SITE_DATA *sqliteDBC::getSiteData( uint32_t ID ){
if( it != cArr->end() ){
tVal->work_mode = atoi(it->second.c_str());
};
it = cArr->find("report_cleanup");
if( it != cArr->end() ){
tVal->report_cleanup = atoi(it->second.c_str());
};
it = cArr->find("report_backup");
if( it != cArr->end() ){
tVal->report_backup = atoi(it->second.c_str());
};
};
};
};
@ -2838,6 +2911,62 @@ DBC_INT_LIST *sqliteDBC::listNodes( bool all ){
return tVal;
};
DBC_INT_LIST *sqliteDBC::listOlderReportStat( CSTR Y, CSTR M, CSTR D ){
DBC_INT_LIST * tVal = NULL;
if ( m_bStaIsConnected ) {
char tQBuf[MAX_PATH_LEN];
AAssoc *result;
sprintf(tQBuf, "SELECT `ROWID` FROM `days` WHERE ((`year`*12*31)+(`month`*31)+`day`)<=((%s*12*31)+(%s*31)+%s) ORDER BY `ROWID`", Y, M, D );
result = m_pDataStatistics->Query( tQBuf );
if( result!= NULL ) {
if( result->size() > 0 ) {
Assoc *cArr;
tVal = new DBC_INT_LIST();
if( tVal != NULL ) {
Assoc::iterator it;
for(int i=0;i<result->size();i++) {
cArr = result->at(i);
it = cArr->find("ROWID");
if( it != cArr->end() ){
tVal->push_back( atoi( it->second.c_str() ));
};
};
};
};
};
deleteResult( result );
};
return tVal;
};
DBC_INT_LIST *sqliteDBC::listOlderReportStat( uint32_t TS ){
DBC_INT_LIST * tVal = NULL;
if ( m_bStaIsConnected ) {
char tQBuf[MAX_PATH_LEN];
AAssoc *result;
sprintf(tQBuf, "SELECT `ROWID` FROM `days` WHERE `ts`< %d", TS );
result = m_pDataStatistics->Query( tQBuf );
if( result!= NULL ) {
if( result->size() > 0 ) {
Assoc *cArr;
tVal = new DBC_INT_LIST();
if( tVal != NULL ) {
Assoc::iterator it;
for(int i=0;i<result->size();i++) {
cArr = result->at(i);
it = cArr->find("ROWID");
if( it != cArr->end() ){
tVal->push_back( atoi( it->second.c_str() ));
};
};
};
};
};
deleteResult( result );
};
return tVal;
};
DBC_INT_LIST *sqliteDBC::listResources( uint32_t NodeID ){
DBC_INT_LIST * tVal = NULL;
if( m_bStoIsConnected ){

16
lib/App/common/SQLite_dataBinder.h

@ -11,13 +11,6 @@
#define DB_SHMEM_POINT "/dev/shm/argus"
typedef struct S_REPORT_DIRINFO{
char YEAR[5];
char MONTH[3];
char DAY[3];
time_t ts;
}REPORT_DIRINFO;
#ifndef STORAGE_DIR_MODE
#define STORAGE_DIR_MODE 0x1F5 //f disabled write by others
#endif
@ -67,7 +60,7 @@ class sqliteDBC: public dataBinder {
void initMemDB( uint32_t sid = 1 );
uint32_t getTsFromRDF( REPORT_DIRINFO &RDF );
void fillRDF( uint32_t ts, REPORT_DIRINFO &RDF );
void updateStats( bool evt = true, bool video = false, uint8_t ses_status = SESSION_CONTINUE );
bool checkRDFDir( CSTR basePath, REPORT_DIRINFO &RDF );
@ -75,6 +68,7 @@ class sqliteDBC: public dataBinder {
explicit sqliteDBC( config_setting_t * Settings );
public:
virtual void fillRDF( uint32_t ts, REPORT_DIRINFO &RDF );
static sqliteDBC * getInstance( config_setting_t * Settings = NULL );
virtual ~sqliteDBC();
/* Functionality */
@ -101,10 +95,12 @@ class sqliteDBC: public dataBinder {
virtual bool cleanLRFMask( uint32_t maskID, bool deleteMask = false );
virtual bool cleanNodePushedCMD( void );
virtual bool createAccessibleDir( CSTR path );
virtual void deleteNIF( uint32_t NifID );
virtual void deleteNIS( uint32_t NisID );
virtual void deleteNetwork( uint32_t NetID );
virtual bool deleteReportStat( uint32_t id );
virtual void deleteResource( uint32_t ResourceID );
virtual void deleteSensor( uint32_t SensorID );
virtual void deleteUART( uint32_t UARTID );
@ -116,6 +112,7 @@ class sqliteDBC: public dataBinder {
virtual DBC_MODULE_EMBED_VIDEO_DATA * getEmbedVideoData( uint32_t ID );
virtual DBC_LRF_INI * getINIData( uint32_t lrfID );
virtual bool getEventSessionStatus( uint32_t nodeID );
virtual uint32_t getLastEventTS();
virtual DBC_LRF_DATA * getLRFData( uint32_t ID );
virtual uint8_t getLRFDataStatus( uint32_t ID );
virtual PLGS_2D_PARAMETERS getLRFDetectionProfile( uint32_t lrfID, uint8_t profileID, bool master );
@ -135,6 +132,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 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 );
virtual DBC_SITE_DATA * getSiteData( uint32_t ID );
@ -152,6 +150,8 @@ class sqliteDBC: public dataBinder {
virtual DBC_INT_LIST * listNewModules( DBC_INT_LIST * old_ids );
virtual DBC_INT_LIST * listNewNodes( DBC_INT_LIST * old_ids );
virtual DBC_INT_LIST * listNodes( bool all = false );
virtual DBC_INT_LIST * listOlderReportStat( CSTR Y, CSTR M, CSTR D );
virtual DBC_INT_LIST * listOlderReportStat( uint32_t TS );
virtual DBC_INT_LIST * listResources( uint32_t NodeID = 0 );
virtual void registerServer( uint32_t SiteID, CSTR identity, int PID, uint32_t *ServID, uint32_t *ServNode );

7
lib/App/common/dataBinder.h

@ -48,7 +48,10 @@ class dataBinder{
virtual bool cleanEvents2VideoBinding( uint32_t PicID ){ return false;};
virtual bool cleanNodePushedCMD( void ){ return false;};
virtual bool cleanSensorFileSysItems( uint32_t sensorID ){ return false;};
virtual bool createAccessibleDir( CSTR path ){ return false; };
virtual bool deleteReportStat( uint32_t id ){};
virtual void fillRDF( uint32_t ts, REPORT_DIRINFO &RDF ){};
virtual void lazyEventArchiver( uint32_t DalayTime = 10 ){};
virtual DBC_INT_LIST * listCamMediaStreams( uint32_t CAMID ){ return NULL;};
@ -69,6 +72,8 @@ class dataBinder{
virtual DBC_INT_LIST * listNodes( bool all = false ){ return NULL;};
//virtual DBC_INT_LIST * listSockets( uint32_t NodeID ){ return NULL;};
virtual DBC_INT_LIST * listResources( uint32_t NodeID = 0 ){ return NULL;};
virtual DBC_INT_LIST * listOlderReportStat( CSTR Y, CSTR M, CSTR D ){ return NULL;};
virtual DBC_INT_LIST * listOlderReportStat( uint32_t TS ){ return NULL;};
virtual simplePolygone * loadLRFMaskVertex( uint32_t vid ){ return NULL;};
virtual bool getAllCamRecords( uint32_t SiteID, vectorCamRecords &VR ){ return false;};
@ -88,6 +93,7 @@ class dataBinder{
//virtual bool getLastEvents( vectorEventRecords &VR, uint32_t tss, uint32_t tsms );
virtual DBC_LRF_INI * getINIData( uint32_t lrfID ){ return NULL; };
virtual bool getEventSessionStatus( uint32_t nodeID ){ return false; };
virtual uint32_t getLastEventTS(){ return 0; };
virtual DBC_LRF_DATA * getLRFData( uint32_t ID ){ return NULL;};
virtual uint8_t getLRFDataStatus( uint32_t ID ){ return 0;};
virtual PLGS_2D_PARAMETERS getLRFDetectionProfile( uint32_t lrfID, uint8_t profileID, bool master ){ return NULL;};
@ -123,6 +129,7 @@ class dataBinder{
virtual DBC_PUSHED_CMD * getPushedCMD( uint32_t CmdID ){ 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;};
virtual uint32_t getResourceID( uint32_t NodeID, uint8_t type, uint32_t auxID ){ return 0;};
virtual uint32_t getServerID( CSTR identity ){ return 0;};

15
lib/App/common/dataBinder_structures.h

@ -11,6 +11,8 @@
#define MAX_BUFF_SIZE 102400 //100K
#define HUMAN_FRIENDLY_JSON true
#define LIST_ALL_RECORDS 0
#define LIST_VALID_RECORDS 1
#define LIST_INVALID_RECORDS 2
@ -473,6 +475,10 @@ typedef struct S_DBC_LRF_DATA{
uint8_t embd_dc;
bool autoreset;
bool force_settings;
bool dc_auto;
bool dc_no;
uint16_t dc_window;
//LRF_DETECTION_PROFILE mlrf_profile[LRF_MAX_DETECTION_PROFILES];
//LRF_DETECTION_PROFILE slrf_profile[LRF_MAX_DETECTION_PROFILES];
//LRF_DETECTION_PROFILE *mlrf_profile;
@ -532,6 +538,8 @@ typedef struct S_DBC_SITE_DATA{
bool SH;
uint8_t map_id;
bool local_binding;
uint32_t report_cleanup;
uint32_t report_backup;
}DBC_SITE_DATA;
typedef struct S_DBC_FH_DATA{
@ -767,4 +775,11 @@ typedef struct S_DBC_REPORT_INFO{
uint32_t sts;
}DBC_REPORT_INFO;
typedef struct S_REPORT_DIRINFO{
char YEAR[5];
char MONTH[3];
char DAY[3];
time_t ts;
}REPORT_DIRINFO;
#endif

1604
lib/App/common/deviceNode2D.cpp
File diff suppressed because it is too large
View File

7
lib/App/common/deviceNode2D.h

@ -70,6 +70,7 @@ typedef enum E_WORKING_STATE_LRF2D{
WS_2D_WAIT_CHECK_REPLAY
} WORKING_STATE_LRF2D;
#define ANODE_2D_MAX_DRAW_ANGLES 6000
#define ARGUS_DS_DISCONNECTED 0
@ -131,8 +132,7 @@ typedef enum E_COMMAND_SEQUENCE_TYPE{
} COMMAND_SEQUENCE_TYPE;
class device2DSensor: public deviceNodeSensor, public protocolLGS_2D{
private:
private:
uint8_t m_bPortType;
basicTransport * m_pPort;
@ -182,6 +182,9 @@ class device2DSensor: public deviceNodeSensor, public protocolLGS_2D{
bool PtInPolygons( TEST_POINT& point, uint8_t F );
bool PtInPolygon( SHADOW_POLY& Poly, TEST_POINT& point );
bool rasterizeShadow();
bool saveShadowToDB( void );
bool loadShadowFromDB( void );
bool cleanShadowInDB( void );
void updateDataStatus( uint8_t ds, uint8_t ns = NODE_STATUS_WORK );
//bool downloadFile( CSTR fname );
//COMMAND_SEQUENCE_TYPE m_eCurrentSequence;

54
lib/App/common/deviceNodeSensor.cpp

@ -133,9 +133,47 @@ LPCTSTR m_pSetting[] =
};
*/
LRF_WORK_STAGE operator ++( LRF_WORK_STAGE &id, int ){
LRF_WORK_STAGE currentID = id;
if( LRF_WS_COUNT < id + 1 ){
id = LRF_WS_COUNT;
} else {
id = static_cast<LRF_WORK_STAGE>( id + 1 );
};
return ( currentID );
};
void deviceNodeSensor::transactionResetResult( void ){
m_mPPModeProtector.lock();
m_ePPMODE = STG_PUSH;
m_mPPModeProtector.unlock();
};
void deviceNodeSensor::transactionSetResult( bool ACK ){
m_mPPModeProtector.lock();
m_ePPMODE = (ACK)?STG_POOL:STG_PUSH;
m_mPPModeProtector.unlock();
};
void deviceNodeSensor::transactionWaitResult( void ){
m_mPPModeProtector.lock();
m_ePPMODE = STG_WAIT;
m_mPPModeProtector.unlock();
};
STAGE_PP_CONDITION deviceNodeSensor::getPPStatus(){
STAGE_PP_CONDITION rv;
m_mPPModeProtector.lock();
rv = m_ePPMODE;
m_mPPModeProtector.unlock();
return rv;
};
deviceNodeSensor::deviceNodeSensor( uint32_t id ):deviceNode( id ),m_oPosition(){
m_nCommErrorsCounter = 0;
m_ePPMODE = STG_INIT;
m_bValidationSkipCounter = DAFAULT_VALIDATION_SKIP_COUNTER;
m_nCommErrorsStatTO = COMMUNICATION_ERROR_STATISTIC_HARVEST_INTERVAL_IN_SECONDS;
m_pEventHeap = basicEventHeap::getInstance();
@ -194,7 +232,12 @@ deviceNodeSensor::deviceNodeSensor( uint32_t id ):deviceNode( id ),m_oPosition()
};
deviceNodeSensor::deviceNodeSensor( DBC_NODE_DATA *Data ):deviceNode( Data ),m_oPosition(){
m_nCommErrorsCounter = 0;
m_ePPMODE = STG_INIT;
m_bValidationSkipCounter = DAFAULT_VALIDATION_SKIP_COUNTER;
m_nCommErrorsStatTO = COMMUNICATION_ERROR_STATISTIC_HARVEST_INTERVAL_IN_SECONDS;
m_pEventHeap = basicEventHeap::getInstance();
//m_pLog = basicLogCollection::getInstance();
memset( &m_sLRF_DATA, 0, sizeof(DBC_LRF_DATA));
m_pTargetFilter = NULL;
@ -913,6 +956,15 @@ void deviceNodeSensor::setStage( LRF_WORK_STAGE st, bool update_old_stage ){
m_mStageProtector.unlock();
};
void deviceNodeSensor::goNextStage( bool update_old_stage ){
m_mStageProtector.lock();
if( m_eWorkingStage < LRF_WS_COUNT ){
if( update_old_stage ) m_eOldWorkingStage = m_eWorkingStage;
m_eWorkingStage++;
};
m_mStageProtector.unlock();
};
LRF_WORK_STAGE deviceNodeSensor::getStage(){
LRF_WORK_STAGE rV;
m_mStageProtector.lock();
@ -965,7 +1017,7 @@ bool deviceNodeSensor::generateIniFile( uint8_t i ){
}
return false;
};
void deviceNodeSensor::RegisterCommError( bool withEvent ){
void deviceNodeSensor::registerCommError( bool withEvent ){
m_nCommErrorsCounter++;
if ( withEvent ) {
EVENT_CONTAINER *bEVT = createBasicEvent(m_sNodeData.node_id, m_eEventClass, EVT_COMMUNICATION_JAMED, NULL, NULL, NULL);

31
lib/App/common/deviceNodeSensor.h

@ -92,11 +92,21 @@ typedef enum E_LRF_WORK_MODE{
LRF_WM_COUNT
} LRF_WORK_MODE;
// For the Stage's Push - Pool condition
typedef enum E_STAGE_PP_CONDITION {
STG_INIT = 0,
STG_PUSH = 1,
STG_WAIT = 2,
STG_POOL = 3
} STAGE_PP_CONDITION;
#define TRANSACTION_RESULT_OK true
#define TRANSACTION_RESULT_BAD false
#define TRANSACTION_RESULT_REPEAT false
typedef enum E_LRF_WORK_STAGE{
LRF_WS_INIT = 0x00,
LRF_WS_WAIT = 0x01,
LRF_WS_DELAY,
LRF_WS_STAGE_1,
LRF_WS_INIT = 0x00,
LRF_WS_STAGE_1 = 0x01,
LRF_WS_STAGE_2,
LRF_WS_STAGE_3,
LRF_WS_STAGE_4,
@ -111,16 +121,22 @@ typedef enum E_LRF_WORK_STAGE{
LRF_WS_STAGE_13,
LRF_WS_STAGE_14,
LRF_WS_STAGE_15,
LRF_WS_DELAY,
LRF_WS_WAIT,
LRF_WS_COUNT
} LRF_WORK_STAGE;
LRF_WORK_STAGE operator ++( LRF_WORK_STAGE &id, int );
#define COMMUNICATION_ERROR_STATISTIC_HARVEST_INTERVAL_IN_SECONDS 60
class deviceNodeSensor: public deviceNode, public basicThread{
private:
STAGE_PP_CONDITION m_ePPMODE;
LRF_WORK_STAGE m_eWorkingStage;
LRF_WORK_STAGE m_eOldWorkingStage;
basicMutex m_mStageProtector;
basicMutex m_mPPModeProtector;
uint32_t m_nCommErrorsCounter;
uint32_t m_nCommErrorsStatTO;
protected:
@ -143,9 +159,14 @@ class deviceNodeSensor: public deviceNode, public basicThread{
uint8_t * create2dDraw( uint32_t *out_size, uint32_t *th_data, size_t th_size, uint16_t max_digital, int radial_shift, CSTR tpl, bool byMinimum = true );
bool reloadDeviceNodeFromDB();
void setStage( LRF_WORK_STAGE st, bool update_old_stage = true );
void RegisterCommError( bool withEvent = false );
void registerCommError( bool withEvent = false );
LRF_WORK_STAGE getStage();
LRF_WORK_STAGE getPrevStage();
void goNextStage( bool update_old_stage = true );
void transactionResetResult( void );
void transactionSetResult( bool ACK = TRANSACTION_RESULT_OK );
void transactionWaitResult( void );
STAGE_PP_CONDITION getPPStatus();
bool generateIniFile( uint8_t i );
bool generateSnFile( uint8_t i );

4
lib/App/common/kernelModuleEmbedVideo.cpp

@ -2736,13 +2736,13 @@ bool streamHandler::initVideoOutput(){
};
m_pVideoCodec = avcodec_find_encoder( VIDEO_OUTPUT_CODEC );
if( m_pVideoCodec == NULL ){
LOG_ERROR("Out VideoCodec Not Found!");
LOG_ERROR("Output VideoCodec Not Found!");
avformat_free_context( m_pFormatCtxA );
avformat_free_context( m_pFormatCtxB );
return false;
#ifdef DEBUG_EXTRA
} else {
LOG("Out Video Codec Found");
LOG("Output Video Codec Found");
#endif
};

157
lib/App/mojo/mojoKernel.cpp

@ -16,6 +16,8 @@
#include "mojoKernel.h"
#include "../data/json/json_tool.h"
#include <strings.h>
#include <sys/time.h>
#include <time.h>
#include <json/value.h>
#include <json/writer.h>
#include <json/reader.h>
@ -156,6 +158,7 @@ bool mojoKernel::create(){
t.lon = tSiteData->lon;
t.alt = tSiteData->alt;
m_pSystemAnchor = systemAnchor::getInstance( tSiteData->SH, &t, tSiteData->local_binding );
memcpy( &m_sSiteData, tSiteData, sizeof( DBC_SITE_DATA ));
free( tSiteData );
} else {
LOG_ERROR("Error Loading Site DATA!");
@ -163,8 +166,26 @@ bool mojoKernel::create(){
t.lat = 0;
t.lon = 0;
t.alt = 0;
memset( &m_sSiteData, 0, sizeof( DBC_SITE_DATA ));
m_pSystemAnchor = systemAnchor::getInstance( false, &t, true );
};
//Check date/Time if correct!
// On some systems the System Date may be in past cause last session was interrupted by powero loose
uint32_t tTS = m_pDBC->getLastEventTS();
if ( tTS ) {
// Have last TS
struct timespec tS = { 0 };
if( clock_gettime( CLOCK_REALTIME, &tS ) == 0 ){
//time_t cTS = time(NULL);
if ( tTS > tS.tv_sec ) {
// System Time is in the Past
LOG("Correcting System Time!");
tS.tv_sec = tTS;
tS.tv_nsec = tTS * 1000000;
if (clock_settime(CLOCK_REALTIME, &tS) != 0) LOG_ERROR("Time Correction Failed!");
};
};
} else LOG_ERROR("No Last TS fetched from DB!");
m_bDebugMode = m_pDBC->getAppDebugMode();
@ -279,6 +300,8 @@ void mojoKernel::m_fThreadProc( void ){
validateSession();
validateReports();
m_pHardwareManager->updateSysInfo( &m_sSysInfo );
DBC_PUSHED_CMD * tCMD = m_pDBC->getNodePushedCMD( m_nServerNodeID ); //Kernel
if( tCMD != NULL ) {
@ -890,5 +913,139 @@ void mojoKernel::handleVideo( VIDEO_SEGMENT_INFO *ptr ){
} else LOG_ERROR("Video File is Missing!");
};
bool mojoKernel::validateReports( void ){
DBC_SITE_DATA *tSiteData = m_pDBC->getSiteData( 1 );
if( tSiteData ) {
// Check if settings has been changed in DB
if ( tSiteData->report_cleanup != m_sSiteData.report_cleanup || tSiteData->report_backup != m_sSiteData.report_backup ) return false;
} else {
LOG_ERROR("Error Loading Site DATA!");
return false;
};
if ( m_sSiteData.report_cleanup ) {
if ( m_sSiteData.report_cleanup > m_sSiteData.report_backup ) {
if ( m_sSiteData.report_backup ) {
// Do needed backup
};
};
cleanUpReportDir( m_sSiteData.report_cleanup );
} else {
if ( m_sSiteData.report_backup ) {
// Only Do Backup - No Cleanup
};
};
return true;
};
void mojoKernel::backupReports( uint32_t days ){
REPORT_DIRINFO tRDI = {0};
uint32_t cTS = (uint32_t)time(NULL);
cTS -= 86400 * days;
m_pDBC->fillRDF( cTS, tRDI );
DBC_INT_LIST *TL = m_pDBC->listOlderReportStat( tRDI.YEAR, tRDI.MONTH, tRDI.DAY );
if ( TL ) {
for ( DBC_INT_LIST::iterator idx = TL->begin(); idx < TL->end(); idx++ ) {
REPORT_DIRINFO *tRDI = m_pDBC->getReportDirInfo( *idx );
if ( tRDI ) {
char tB[MAX_PATH];
char dB[MAX_PATH];
sprintf( tB, "%s/data/reports/%s/%s/%s", getcwd(dB, MAX_PATH), tRDI->YEAR, tRDI->MONTH, tRDI->DAY );
char tPATH[MAX_PATH];
sprintf( tPATH, "%s/data/archive/%s_%s_%s", getcwd(dB, MAX_PATH), tRDI->YEAR, tRDI->MONTH, tRDI->DAY );
if ( fileExist( tB ) ) {
if ( !fileExist( tPATH ) ) {
// Try Create Job if sucess then create dir to skip next validation
if( createCronJob( 0, tPATH, cTS ) ){
// Create Backup Dir
if( m_pDBC->createAccessibleDir( tPATH ) ){
// Create Just One Backup Per Time!
free( tRDI );
break;
};
};
};// else proceed next
};
free( tRDI );
};
};
delete( TL );
};
};
void mojoKernel::cleanUpReportDir( uint32_t days ){
// Cleanup Current reports no Backup
REPORT_DIRINFO tRDI = {0};
uint32_t cTS = (uint32_t)time(NULL);
cTS -= 86400 * days;
m_pDBC->fillRDF( cTS, tRDI );
DBC_INT_LIST *TL = m_pDBC->listOlderReportStat( tRDI.YEAR, tRDI.MONTH, tRDI.DAY );
if ( TL ) {
for ( DBC_INT_LIST::iterator idx = TL->begin(); idx < TL->end(); idx++ ) {
REPORT_DIRINFO *tRDI = m_pDBC->getReportDirInfo( *idx );
if ( tRDI ) {
char tB[MAX_PATH];
char dB[MAX_PATH];
sprintf( tB, "%s/data/reports/%s/%s/%s", getcwd(dB, MAX_PATH), tRDI->YEAR, tRDI->MONTH, tRDI->DAY );
//char tPATH[MAX_PATH];
//sprintf( tPATH, "%s/data/archive/%s/%s/%s", getcwd(dB, MAX_PATH), tRDI->YEAR, tRDI->MONTH, tRDI->DAY );
if ( fileExist( tB ) ) {
DIR *dir = opendir( tB );
if( dir ){
struct dirent *d;
while( ( d = readdir(dir) ) != NULL ) {
if ( strlen( d->d_name ) > 3 ) {
char tPATH[MAX_PATH];
sprintf( tPATH, "%s/%s", tB, d->d_name );
unlink( tPATH );
};
};
closedir( dir );
};
if ( dirEmpty( tB ) ) unlink( tB );
};
free( tRDI );
};
m_pDBC->deleteReportStat( *idx );
};
delete( TL );
};
};
bool mojoKernel::createCronJob( uint8_t job, CSTR param_str, int param_int ){
if ( !fileExist("/srv/etc/cron.lock") ) {
Json::Value root;
//Json::Value data;
switch ( job ) {
case CRON_JOB_CREATE_BACKUP:{
root["operation"] = CRON_JOB_CREATE_BACKUP;
//data["number"] = 1;
root["ts"] = param_int;
root["backup_dst"] = std::string( param_str );
break;
};
// No default JOB!
default: return false;
};
FILE *fd = fopen("/srv/etc/cron_.json","w+");
if ( fd ) {
if( HUMAN_FRIENDLY_JSON ) {
Json::FastWriter writer;
const std::string json_file = writer.write(root);
fprintf( fd, json_file.c_str() );
} else {
Json::StreamWriterBuilder builder;
const std::string json_file = Json::writeString( builder, root );
fprintf( fd, json_file.c_str() );
};
fclose( fd );
return true;
};
};
return false;
};
#undef LOG
#undef LOG_ERROR

8
lib/App/mojo/mojoKernel.h

@ -45,6 +45,8 @@
#define MOJO_KERNEL_TAG_SITE_ID "SITE_ID"
#define MOJO_KERNEL_TAG_SERVER_IDENTITY "IDENTITY"
#define CRON_JOB_CREATE_BACKUP 20
/**
* LRF_Kernel class - manages communication between client
* handlers and PRU cores bseide of Event management.
@ -58,6 +60,7 @@ class mojoKernel: public kernelPrototype{
ShadowMask * m_pShadow;
time_t m_tTimeTSeconds;
DBC_SYS_LOAD_INFO m_sSysInfo;
DBC_SITE_DATA m_sSiteData;
char m_sIdentity[128];
uint32_t m_nInstanceID;
uint32_t m_nServerID;
@ -86,7 +89,10 @@ class mojoKernel: public kernelPrototype{
static mojoKernel * _instance;
void handleVideo( VIDEO_SEGMENT_INFO *ptr );
bool validateReports( void );
bool createCronJob( uint8_t job, CSTR param_str = NULL, int param_int = 0 );
void cleanUpReportDir( uint32_t days );
void backupReports( uint32_t days );
protected:
virtual void m_fThreadProc( void );
// Constructor

6
lib/alg/lgs/detectorStructures.h

@ -104,6 +104,12 @@ typedef struct S_LGS_2D_PARAMETERS{
uint8_t bSST;
}LGS_2D_PARAMETERS, *PLGS_2D_PARAMETERS;
//typedef struct S_RELAY_PARAMETERS {
// uint8_t bAuto; // allow auto relay
// uint8_t bNormallyClose;
// uint16_t nAutoDelay; // in 0.1 sec (0,0 .. 3000,0 sec)
//} RELAY_PARAMETERS, *PRELAY_PARAMETERS;
typedef struct S_LGS_3D_PARAMETERS{
uint8_t nOrder;
uint8_t nOffset;

24
lib/data/protocol/protocolLGS2D.cpp

@ -238,6 +238,16 @@ bool protocolLGS_2D::getParameters( bool MASTER ){
return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 5, m_bDeviceID));
};
bool protocolLGS_2D::getRelayParameters( void ){
U8 Buffer[16];
if( m_oDataTransport == NULL ) return false;
Buffer[CMD_IDX] = CMD_GET_RELAY_PARAMETERS;
#ifdef DEBUG_EXTRA
LOG("getRelayParameters");
#endif
return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 4, m_bDeviceID));
};
bool protocolLGS_2D::getShadowPoly( uint8_t sequence, uint16_t PolyID ){
U8 Buffer[16];
if( m_oDataTransport == NULL ) return false;
@ -572,6 +582,20 @@ bool protocolLGS_2D::setParameters( PLGS_2D_PARAMETERS ptr, bool MASTER, uint8_t
return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 18, m_bDeviceID));
};
bool protocolLGS_2D::setRelayParameters( PRELAY_PARAMETERS ptr ){
U8 Buffer[16];
if( m_oDataTransport == NULL ) return false;
Buffer[CMD_IDX] = CMD_SET_RELAY_PARAMETERS;
Buffer[4] = ptr->bAuto;
Buffer[5] = ptr->bNormallyClose;
Buffer[6] = (ptr->nAutoDelay >> 8) & 0xFF;
Buffer[7] = ptr->nAutoDelay & 0xFF;
#ifdef DEBUG_EXTRA
LOG("setParameters");
#endif
return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 8, m_bDeviceID));
};
bool protocolLGS_2D::getSerialNumber( void ){
U8 Buffer[16];
if( m_oDataTransport == NULL ) return false;

3
lib/data/protocol/protocolLGS2D.h

@ -39,6 +39,7 @@ class protocolLGS_2D: public protocolParser{
bool getFullDraw( uint16_t Angle );
bool getFastDraw( uint16_t Angle );
bool getParameters( bool MASTER = true );
bool getRelayParameters( void );
bool getSerialNumber( void );
bool getShadowInfo( uint8_t seq );
bool getShadowPoly( uint8_t seq, uint16_t PolyID );
@ -56,7 +57,7 @@ class protocolLGS_2D: public protocolParser{
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 setRelayParameters( PRELAY_PARAMETERS ptr );
bool setShadowInfo( uint8_t seq, SHADOW & SH );
bool setShadowPoly( uint8_t seq, SHADOW & SH, uint16_t PolyID );
bool setShadowPolyPoint( uint8_t seq, SHADOW & SH, uint16_t PolyID, uint16_t PointID );

Loading…
Cancel
Save