You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
6102 lines
149 KiB
6102 lines
149 KiB
#include "SQLite_dataBinder.h"
|
|
|
|
#include "../../components/base/basicEvent.h"
|
|
|
|
#define LOG(X) m_pLog->Log("SDBC", this, 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("SDBC", this, _LOG_ERROR, _tBfrErrMSG2w34); \
|
|
}
|
|
#else
|
|
#define LOG_ERROR(X) m_pLog->Log("SDBC", this, _LOG_ERROR, X);
|
|
#endif
|
|
|
|
sqliteDBC * sqliteDBC::_instance = NULL;
|
|
|
|
/**
|
|
* Returns the single instance of the object.
|
|
*/
|
|
sqliteDBC * sqliteDBC::getInstance(config_setting_t * Settings)
|
|
{
|
|
// check if the instance has been created yet
|
|
if (0 == _instance)
|
|
{
|
|
// if not, then create it
|
|
_instance = new sqliteDBC(Settings);
|
|
};
|
|
// return the single instance
|
|
return _instance;
|
|
}
|
|
|
|
/*
|
|
uint32_t sqliteDBC::getTsFromRDF( REPORT_DIRINFO &RDF ){
|
|
struct tm ltm;
|
|
memset( <m, 0, sizeof( struct tm ));
|
|
ltm.tm_mday = atoi( RDF.DAY );
|
|
ltm.tm_mon = atoi( RDF.MONTH ) - 1;
|
|
ltm.tm_year = atoi( RDF.YEAR ) - 1900;
|
|
return (uint32_t) timelocal( <m );
|
|
};
|
|
|
|
|
|
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, bool recreate ){
|
|
char tBuff[MAX_PATH];
|
|
sprintf( tBuff, "%s/%s", basePath, RDF.YEAR );
|
|
#ifdef DEBUG
|
|
LOG( tBuff );
|
|
#endif
|
|
if( fileExist( tBuff ) == 0 ){
|
|
if ( recreate ) {
|
|
if (!createAccessibleDir(tBuff)) return false;
|
|
} else return false;
|
|
};
|
|
sprintf( tBuff, "%s/%s/%s", basePath, RDF.YEAR, RDF.MONTH );
|
|
#ifdef DEBUG
|
|
LOG( tBuff );
|
|
#endif
|
|
if( fileExist( tBuff ) == 0 ){
|
|
if ( recreate ) {
|
|
if( !createAccessibleDir( tBuff ) ) return false;
|
|
} else return false;
|
|
};
|
|
sprintf( tBuff, "%s/%s/%s/%s", basePath, RDF.YEAR, RDF.MONTH, RDF.DAY );
|
|
#ifdef DEBUG
|
|
LOG( tBuff );
|
|
#endif
|
|
if( fileExist( tBuff ) == 0 ){
|
|
if ( recreate ) {
|
|
if( !createAccessibleDir( tBuff ) ) return false;
|
|
} else return false;
|
|
};
|
|
return true;
|
|
};
|
|
*/
|
|
|
|
sqliteDBC::sqliteDBC(config_setting_t * Settings) :
|
|
dataBinder()
|
|
{
|
|
m_pLog = basicLogCollection::getInstance();
|
|
m_pSettings = basicSettingsProvider::getInstance()->getSubNode(Settings, "DATABASE");
|
|
m_bStoIsConnected = false;
|
|
m_bMemIsConnected = false;
|
|
m_bRepIsConnected = false;
|
|
m_bStaIsConnected = false;
|
|
m_bLastEventWasClosed = false;
|
|
m_pDataStorage = NULL;
|
|
m_pDataMemory = NULL;
|
|
m_pDataReports = NULL;
|
|
m_pDataStatistics = NULL;
|
|
m_nServerID = 1;
|
|
}
|
|
|
|
sqliteDBC::~sqliteDBC()
|
|
{
|
|
if (m_pDataStorage)
|
|
{
|
|
delete(m_pDataStorage);
|
|
}
|
|
if (m_pDataMemory)
|
|
{
|
|
delete(m_pDataMemory);
|
|
}
|
|
if (m_pDataReports)
|
|
{
|
|
delete(m_pDataReports);
|
|
}
|
|
if (m_pDataStatistics)
|
|
{
|
|
delete(m_pDataStatistics);
|
|
}
|
|
m_bStoIsConnected = false;
|
|
m_bMemIsConnected = false;
|
|
m_bRepIsConnected = false;
|
|
m_bStaIsConnected = false;
|
|
_instance = NULL;
|
|
}
|
|
|
|
bool sqliteDBC::connect(void)
|
|
{
|
|
if (m_pSettings == NULL)
|
|
{
|
|
return false;
|
|
}
|
|
config_setting_t * pSetting;
|
|
const char * tBuff;
|
|
// Disconnect if Connected
|
|
m_bStoIsConnected = false;
|
|
m_bMemIsConnected = false;
|
|
m_bRepIsConnected = false;
|
|
m_bStaIsConnected = false;
|
|
m_bLastEventWasClosed = false;
|
|
|
|
// Apply New Config
|
|
#ifdef DEBUG
|
|
LOG("Reading DB Settings ... ");
|
|
#endif
|
|
if (! config_setting_lookup_string(m_pSettings, "DATA_FILE_NAME", (const char **) &tBuff))
|
|
{
|
|
pSetting = config_setting_add(m_pSettings, "DATA_FILE_NAME", CONFIG_TYPE_STRING);
|
|
sprintf(m_pDbFile, "data/mysqlitedb.db");
|
|
config_setting_set_string(pSetting, m_pDbFile);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
LOG("Data Storage not set - using default");
|
|
}
|
|
else
|
|
{
|
|
sprintf(m_pDbFile, tBuff);
|
|
};
|
|
if (! config_setting_lookup_string(m_pSettings, "REPORTS_DIR_NAME", (const char **) &tBuff))
|
|
{
|
|
pSetting = config_setting_add(m_pSettings, "REPORTS_DIR_NAME", CONFIG_TYPE_STRING);
|
|
sprintf(m_pDbReportBase, "data/reports");
|
|
config_setting_set_string(pSetting, m_pDbReportBase);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
LOG("Reports Storage not set - using default");
|
|
}
|
|
else
|
|
{
|
|
sprintf(m_pDbReportBase, tBuff);
|
|
};
|
|
if (! config_setting_lookup_string(m_pSettings, "WEB_ACCESS_USER", (const char **) &tBuff))
|
|
{
|
|
pSetting = config_setting_add(m_pSettings, "WEB_ACCESS_USER", CONFIG_TYPE_STRING);
|
|
sprintf(web_access_user, "www-data");
|
|
config_setting_set_string(pSetting, web_access_user);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
LOG("Web Access User not set - using default");
|
|
}
|
|
else
|
|
{
|
|
sprintf(web_access_user, tBuff);
|
|
};
|
|
if (! config_setting_lookup_string(m_pSettings, "WEB_ACCESS_GROUP", (const char **) &tBuff))
|
|
{
|
|
pSetting = config_setting_add(m_pSettings, "WEB_ACCESS_GROUP", CONFIG_TYPE_STRING);
|
|
sprintf(web_access_group, "www-data");
|
|
config_setting_set_string(pSetting, web_access_group);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
LOG("Web Access Group not set - using default");
|
|
}
|
|
else
|
|
{
|
|
sprintf(web_access_group, tBuff);
|
|
};
|
|
if (! fileExist(DB_SHMEM_POINT))
|
|
{
|
|
mkdir(DB_SHMEM_POINT, STORAGE_DIR_MODE); // S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IXOTH );
|
|
chown(DB_SHMEM_POINT, getUserUid(web_access_user), getUserGid(web_access_group)); // To make Accessed from PHP
|
|
chmod(DB_SHMEM_POINT, STORAGE_DIR_MODE);
|
|
};
|
|
char tB[128];
|
|
if (! config_setting_lookup_string(m_pSettings, "DATA_MEMORY_NAME", (const char **) &tBuff))
|
|
{
|
|
pSetting = config_setting_add(m_pSettings, "DATA_MEMORY_NAME", CONFIG_TYPE_STRING);
|
|
tBuff = tB;
|
|
sprintf(tB, "mem_db.db");
|
|
config_setting_set_string(pSetting, tB);
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
LOG("Memory Storage not set - using default");
|
|
};
|
|
sprintf(m_pDbMemory, "%s/%s", DB_SHMEM_POINT, tBuff);
|
|
basicSettingsProvider::getInstance()->validate();
|
|
|
|
// Kill Connection if any
|
|
if (m_pDataStorage)
|
|
{
|
|
delete(m_pDataStorage);
|
|
}
|
|
if (m_pDataMemory)
|
|
{
|
|
delete(m_pDataMemory);
|
|
}
|
|
if (m_pDataReports)
|
|
{
|
|
delete(m_pDataReports);
|
|
}
|
|
if (m_pDataStatistics)
|
|
{
|
|
delete(m_pDataStatistics);
|
|
}
|
|
m_pDataMemory = NULL;
|
|
m_pDataStorage = NULL;
|
|
m_pDataReports = NULL;
|
|
m_pDataStatistics = NULL;
|
|
|
|
#ifdef DEBUG
|
|
LOG(m_pDbFile);
|
|
#endif
|
|
// Create New Connections
|
|
m_pDataStorage = new SQLite_Connector();
|
|
if (m_pDataStorage)
|
|
{
|
|
if (m_pDataStorage->Connect(m_pDbFile, 0, true))
|
|
{
|
|
#ifdef DEBUG
|
|
LOG("DB File Opened");
|
|
#endif
|
|
chown(m_pDbFile, getUserUid(web_access_user), getUserGid(web_access_group));
|
|
chmod(m_pDbFile, DB_FILE_MODE);
|
|
m_bStoIsConnected = true;
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("Cannot Connect to DB File");
|
|
delete(m_pDataStorage);
|
|
m_pDataStorage = NULL;
|
|
LOG("Storage Deleted!");
|
|
return false;
|
|
};
|
|
};
|
|
#ifdef DEBUG
|
|
LOG(m_pDbMemory);
|
|
#endif
|
|
if (! fileExist(m_pDbMemory))
|
|
{
|
|
// Always recreate
|
|
unlink(m_pDbMemory);
|
|
};
|
|
m_pDataMemory = new SQLite_Connector();
|
|
if (m_pDataMemory)
|
|
{
|
|
|
|
if (m_pDataMemory->Connect(m_pDbMemory, 0, true))
|
|
{
|
|
#ifdef DEBUG
|
|
LOG("DB Memory Opened");
|
|
#endif
|
|
chown(m_pDbMemory, getUserUid(web_access_user), getUserGid(web_access_group));
|
|
chmod(m_pDbMemory, DB_FILE_MODE);
|
|
m_pDataMemory->SilentQuery("PRAGMA journal_mode=WAL");
|
|
// Recreate at Register Server
|
|
m_bMemIsConnected = true;
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("Cannot Connect to DB Memory");
|
|
delete(m_pDataStorage);
|
|
delete(m_pDataMemory);
|
|
m_bStoIsConnected = false;
|
|
m_pDataStorage = NULL;
|
|
m_pDataMemory = NULL;
|
|
return false;
|
|
};
|
|
};
|
|
sprintf(m_pDbStat, "%s/stat.db", m_pDbReportBase);
|
|
m_pDataStatistics = new SQLite_Connector();
|
|
if (m_pDataStatistics)
|
|
{
|
|
if (fileExist(m_pDbStat))
|
|
{
|
|
m_bStaIsCreated = false;
|
|
if (m_pDataStatistics->Connect(m_pDbStat, 0, true))
|
|
{
|
|
#ifdef DEBUG
|
|
LOG(m_pDbStat);
|
|
LOG("DB Statistics Opened");
|
|
#endif
|
|
m_pDataStatistics->SilentQuery("PRAGMA journal_mode=WAL");
|
|
m_bStaIsConnected = true;
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("Cannot Connect to DB Statistics");
|
|
delete(m_pDataStorage);
|
|
delete(m_pDataMemory);
|
|
delete(m_pDataStatistics);
|
|
m_bMemIsConnected = false;
|
|
m_bStoIsConnected = false;
|
|
m_pDataStorage = NULL;
|
|
m_pDataMemory = NULL;
|
|
m_pDataStatistics = NULL;
|
|
return false;
|
|
};
|
|
}
|
|
else
|
|
{
|
|
m_bStaIsCreated = true;
|
|
if (m_pDataStatistics->Connect(m_pDbStat, 0, true))
|
|
{
|
|
#ifdef DEBUG
|
|
LOG("NEW DB Statistics Creating");
|
|
#endif
|
|
chown(m_pDbStat, getUserUid(web_access_user), getUserGid(web_access_group));
|
|
chmod(m_pDbStat, DB_FILE_MODE);
|
|
m_pDataStatistics->SilentQuery("PRAGMA journal_mode=WAL");
|
|
m_pDataStatistics->SilentQuery(
|
|
"CREATE TABLE IF NOT EXISTS \"days\" (\"year\" INTEGER,\"month\" INTEGER,\"day\" INTEGER,\"evt_count\" INTEGER DEFAULT 0,\"session_count\" INTEGER DEFAULT 0,\"videos_count\" INTEGER DEFAULT 0,\"session_closed\" INTEGER "
|
|
"DEFAULT 0, CONSTRAINT \"date_uni\" UNIQUE(\"year\",\"month\",\"day\") );");
|
|
m_bStaIsConnected = true;
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("Cannot Connect to DB Statistics");
|
|
delete(m_pDataStorage);
|
|
delete(m_pDataMemory);
|
|
delete(m_pDataStatistics);
|
|
m_bMemIsConnected = false;
|
|
m_bStoIsConnected = false;
|
|
m_pDataStorage = NULL;
|
|
m_pDataMemory = NULL;
|
|
m_pDataStatistics = NULL;
|
|
return false;
|
|
};
|
|
};
|
|
};
|
|
m_pDataReports = new SQLite_Connector();
|
|
if (m_pDataReports)
|
|
{
|
|
memset(&m_sPRepInfo, 0, sizeof(REPORT_DIRINFO));
|
|
if (! m_bStaIsCreated)
|
|
{
|
|
#ifdef DEBUG
|
|
LOG("OLD Statistics PRESENT Report Created!");
|
|
#endif
|
|
AAssoc * result = m_pDataStatistics->Query("SELECT * FROM `days` ORDER BY `year` DESC, `month` DESC, `day` DESC LIMIT 1");
|
|
if (result)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("year");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(m_sPRepInfo.YEAR, it->second.c_str(), 4);
|
|
};
|
|
it = cArr->find("month");
|
|
if (it != cArr->end())
|
|
{
|
|
sprintf(m_sPRepInfo.MONTH, "%02d", atoi(it->second.c_str()));
|
|
};
|
|
it = cArr->find("day");
|
|
if (it != cArr->end())
|
|
{
|
|
sprintf(m_sPRepInfo.DAY, "%02d", atoi(it->second.c_str()));
|
|
};
|
|
m_sPRepInfo.ts = getTsFromRDF(m_sPRepInfo);
|
|
}
|
|
else
|
|
{
|
|
#ifdef DEBUG
|
|
LOG("No Rows Fetched from STAT!");
|
|
#endif
|
|
};
|
|
};
|
|
m_pDataMemory->deleteResult(result);
|
|
};
|
|
|
|
if (m_sPRepInfo.ts != 0)
|
|
{
|
|
#ifdef DEBUG
|
|
LOG("Have Old Reports!");
|
|
#endif
|
|
if (checkRDFDir(m_pDbReportBase, m_sPRepInfo, false) == 0)
|
|
{
|
|
LOG_ERROR("Error Connecting to Prev Report!");
|
|
m_bLastEventWasClosed = true;
|
|
}
|
|
else
|
|
{
|
|
#ifdef DEBUG
|
|
LOG("Connect to old Report Database");
|
|
#endif
|
|
sprintf(m_pDbReport, "%s/%s/%s/%s/report.db", m_pDbReportBase, m_sPRepInfo.YEAR, m_sPRepInfo.MONTH, m_sPRepInfo.DAY);
|
|
LOG(m_pDbReport);
|
|
if (fileExist(m_pDbReport))
|
|
{
|
|
SQLite_Connector * tDBC = new SQLite_Connector();
|
|
if (tDBC)
|
|
{
|
|
if (tDBC->Connect(m_pDbReport, 0, true))
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT `evt_type` FROM `events` WHERE `evt_type`=%d OR `evt_type`=%d OR `evt_type`=%d ORDER BY `ts` DESC, `ts_ms` DESC LIMIT 1", EVT_LRF_START_SESSION, EVT_LRF_END_SESSION_MA, EVT_LRF_END_SESSION_TO);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = tDBC->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("evt_type");
|
|
if (it != cArr->end())
|
|
{
|
|
if (atoi(it->second.c_str()) != EVT_LRF_START_SESSION)
|
|
{
|
|
m_bLastEventWasClosed = true;
|
|
}
|
|
};
|
|
}
|
|
else
|
|
{
|
|
m_bLastEventWasClosed = true;
|
|
}
|
|
};
|
|
deleteResult(result);
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("Error Connecting to Prev Report!");
|
|
m_bLastEventWasClosed = true;
|
|
};
|
|
delete(tDBC);
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("Error Create DB Connection Object!");
|
|
m_bLastEventWasClosed = true;
|
|
};
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("Error No Prev Report Database!");
|
|
m_bLastEventWasClosed = true;
|
|
};
|
|
};
|
|
}
|
|
else
|
|
{
|
|
m_bLastEventWasClosed = true;
|
|
};
|
|
|
|
if (m_bLastEventWasClosed)
|
|
{
|
|
#ifdef DEBUG
|
|
LOG("Last Session is Closed!");
|
|
#endif
|
|
fillRDF(time(NULL), m_sCRepInfo);
|
|
}
|
|
else
|
|
{
|
|
#ifdef DEBUG
|
|
LOG("Last Session is NOT Closed!");
|
|
#endif
|
|
memcpy(&m_sCRepInfo, &m_sPRepInfo, sizeof(REPORT_DIRINFO));
|
|
};
|
|
#ifdef DEBUG
|
|
LOG(m_pDbReportBase);
|
|
#endif
|
|
if (! checkRDFDir(m_pDbReportBase, m_sCRepInfo, true, getUserUid(web_access_user), getUserGid(web_access_group)))
|
|
{
|
|
LOG_ERROR("Cannot Open Report!!");
|
|
return false;
|
|
};
|
|
sprintf(m_pDbReport, "%s/%s/%s/%s/report.db", m_pDbReportBase, m_sCRepInfo.YEAR, m_sCRepInfo.MONTH, m_sCRepInfo.DAY);
|
|
#ifdef DEBUG
|
|
LOG(m_pDbReport);
|
|
#endif
|
|
if (m_pDataReports->Connect(m_pDbReport, 0, true))
|
|
{
|
|
#ifdef DEBUG
|
|
LOG("Report File Opened");
|
|
#endif
|
|
chown(m_pDbReport, getUserUid(web_access_user), getUserGid(web_access_group));
|
|
chmod(m_pDbReport, DB_FILE_MODE);
|
|
m_pDataReports->SilentQuery(
|
|
"CREATE TABLE IF NOT EXISTS \"events\" ( \"id\" INTEGER NOT NULL, \"node_id\" INTEGER NOT NULL, \"uuid\" TEXT NOT NULL UNIQUE, \"ts\" INTEGER NOT NULL, \"ts_ms\" INTEGER NOT NULL, \"evt_type\" INTEGER NOT NULL, \"lrf_id\" "
|
|
"INTEGER, \"range_digital\" INTEGER, \"azimuth\" REAL, \"elevation\" REAL, \"range\" REAL, \"area\" REAL, \"lat\" REAL, \"lon\" REAL, \"alt\" REAL, \"ref_id\" INTEGER, \"ref_uuid\" TEXT, PRIMARY KEY(\"id\" "
|
|
"AUTOINCREMENT) )");
|
|
m_pDataReports->SilentQuery("CREATE TABLE IF NOT EXISTS \"events_2_pictures\" ( \"evt_id\" INTEGER NOT NULL, \"picture_id\" INTEGER NOT NULL )");
|
|
m_pDataReports->SilentQuery("CREATE TABLE IF NOT EXISTS \"events_2_videos\" ( \"evt_id\" INTEGER NOT NULL, \"video_id\" INTEGER NOT NULL, \"frame\" INTEGER DEFAULT 0, \"tss\" INTEGER, \"tms\" INTEGER )");
|
|
m_pDataReports->SilentQuery(
|
|
"CREATE TABLE IF NOT EXISTS \"pictures\" ( \"id\" INTEGER NOT NULL, \"media_stream_id\" INTEGER NOT NULL, \"md5\" TEXT NOT NULL UNIQUE, \"uts\" INTEGER NOT NULL, \"uts_ms\" INTEGER NOT NULL, \"ext\" TEXT NOT NULL, "
|
|
"\"data\" BLOB COLLATE BINARY, PRIMARY KEY(\"id\" AUTOINCREMENT) )");
|
|
m_pDataReports->SilentQuery(
|
|
"CREATE TABLE IF NOT EXISTS \"videos\" ( \"id\" INTEGER NOT NULL, \"media_stream_id\" INTEGER NOT NULL, \"md5\" TEXT NOT NULL UNIQUE, \"uts\" INTEGER NOT NULL, \"uts_ms\" INTEGER NOT NULL, \"ext\" TEXT NOT NULL, \"fps\" "
|
|
"INTEGER NOT NULL, \"flength\" INTEGER, PRIMARY KEY(\"id\" AUTOINCREMENT) )");
|
|
//};
|
|
m_bRepIsConnected = true;
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("Cannot Connect to DB File");
|
|
delete(m_pDataReports);
|
|
m_pDataReports = NULL;
|
|
LOG("Storage Deleted!");
|
|
return false;
|
|
};
|
|
};
|
|
|
|
return (m_bRepIsConnected && m_bMemIsConnected && m_bStoIsConnected && m_bStaIsConnected);
|
|
}
|
|
|
|
bool sqliteDBC::isDatabaseNew()
|
|
{
|
|
bool RetVal = true;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
sprintf(tQBuf, "SELECT `os_info` FROM `system_props` LIMIT 1");
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
AAssoc * result;
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("os_info");
|
|
if (it != cArr->end())
|
|
{
|
|
RetVal = (strlen(it->second.c_str()) < 5);
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return RetVal;
|
|
}
|
|
|
|
void sqliteDBC::initMemDB(uint32_t sid)
|
|
{
|
|
m_pDataMemory->SilentQuery("DROP TABLE \"nodes_qcq\"");
|
|
m_pDataMemory->SilentQuery(
|
|
"CREATE TABLE \"nodes_qcq\" ( \
|
|
\"id\" INTEGER NOT NULL,\
|
|
\"node_id\" INTEGER NOT NULL,\
|
|
\"cmd\" INTEGER NOT NULL,\
|
|
\"status\" INTEGER DEFAULT 0,\
|
|
\"parameter\" TEXT,\
|
|
PRIMARY KEY(\"id\" AUTOINCREMENT)\
|
|
);");
|
|
m_pDataMemory->SilentQuery("DROP TABLE \"servers\"");
|
|
m_pDataMemory->SilentQuery(
|
|
"CREATE TABLE \"servers\" (\
|
|
\"id\" INTEGER NOT NULL,\
|
|
\"ts\" INTEGER DEFAULT 0,\
|
|
\"pid\" INTEGER DEFAULT 0,\
|
|
\"hw_info\" TEXT,\
|
|
\"os_info\" TEXT,\
|
|
\"cpu_cores\" INTEGER DEFAULT 1,\
|
|
\"stat_cpu1\" REAL DEFAULT 0.0,\
|
|
\"stat_cpu5\" REAL DEFAULT 0.0,\
|
|
\"stat_cpu15\" REAL DEFAULT 0.0,\
|
|
\"stat_mem\" REAL DEFAULT 0.0,\
|
|
\"stat_disk\" REAL DEFAULT 0.0,\
|
|
\"val_mem_tottal\" INTEGER DEFAULT 0,\
|
|
\"val_mem_current\" INTEGER DEFAULT 0,\
|
|
\"val_disk_tottal\" INTEGER DEFAULT 0,\
|
|
\"val_disk_current\" INTEGER DEFAULT 0,\
|
|
\"temp0\" REAL DEFAULT 0.0,\
|
|
PRIMARY KEY(\"id\" AUTOINCREMENT)\
|
|
);");
|
|
char tB[128];
|
|
sprintf(tB, "INSERT INTO `servers` (`id`,`ts`) VALUES (%d, strftime('%%s') )", sid);
|
|
m_pDataMemory->SilentQuery(tB);
|
|
}
|
|
|
|
CSTR sqliteDBC::getCurrentReportDir(void)
|
|
{
|
|
CSTR tV = NULL;
|
|
if (m_sCRepInfo.ts)
|
|
{
|
|
char tBuf[256];
|
|
sprintf(tBuf, "%s/%s/%s", m_sCRepInfo.YEAR, m_sCRepInfo.MONTH, m_sCRepInfo.DAY);
|
|
tV = strdup(tBuf);
|
|
};
|
|
return tV;
|
|
}
|
|
|
|
DBC_PUSHED_CMD * sqliteDBC::getNodePushedCMD(uint32_t NodeID)
|
|
{
|
|
DBC_PUSHED_CMD * RetVal = NULL;
|
|
if (m_bMemIsConnected)
|
|
{
|
|
char QS[MAX_PATH];
|
|
AAssoc * result;
|
|
sprintf(QS, "select * FROM `nodes_qcq` WHERE `node_id`=%d AND `status`=0 ORDER BY `id` LIMIT 1", NodeID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(QS);
|
|
#endif
|
|
result = m_pDataMemory->Query(QS);
|
|
if (result)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
RetVal = (DBC_PUSHED_CMD *) malloc(sizeof(DBC_PUSHED_CMD));
|
|
if (RetVal)
|
|
{
|
|
Assoc * cArr;
|
|
Assoc::iterator it;
|
|
|
|
memset(RetVal, 0, sizeof(DBC_PUSHED_CMD));
|
|
cArr = result->at(0);
|
|
it = cArr->find("id");
|
|
if (it != cArr->end())
|
|
{
|
|
RetVal->id = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("cmd");
|
|
if (it != cArr->end())
|
|
{
|
|
RetVal->CMD = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("parameter");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(RetVal->PARAM, it->second.c_str(), 256);
|
|
RetVal->PARAM[255] = (char) 0;
|
|
};
|
|
};
|
|
#ifdef DEBUG_ALL
|
|
}
|
|
else
|
|
{
|
|
|
|
LOG("No Rows Fetched!");
|
|
#endif
|
|
};
|
|
};
|
|
m_pDataMemory->deleteResult(result);
|
|
};
|
|
return RetVal;
|
|
}
|
|
|
|
bool sqliteDBC::updateModemManagerActiveCall(uint32_t MMID, int32_t callID)
|
|
{
|
|
if (m_bMemIsConnected)
|
|
{
|
|
char QS[MAX_PATH];
|
|
sprintf(QS, "UPDATE `module_modem` SET `active_call`=%d WHERE `id`=%d ", callID, MMID);
|
|
return m_pDataStorage->SilentQuery(QS);
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool sqliteDBC::updateModemManagerLTS(uint32_t MMID, uint32_t ts)
|
|
{
|
|
if (m_bMemIsConnected)
|
|
{
|
|
char QS[MAX_PATH];
|
|
sprintf(QS, "UPDATE `module_modem` SET `last_trigger_ts`=%d WHERE `id`=%d ", ts, MMID);
|
|
return m_pDataStorage->SilentQuery(QS);
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool sqliteDBC::updateModemManagerActivePhoneBookID(uint32_t MMID, uint32_t pbID)
|
|
{
|
|
if (m_bMemIsConnected)
|
|
{
|
|
char QS[MAX_PATH];
|
|
sprintf(QS, "UPDATE `module_modem` SET `active_ph_id`=%d WHERE `id`=%d ", pbID, MMID);
|
|
return m_pDataStorage->SilentQuery(QS);
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool sqliteDBC::updateModemManagerActiveSMS(uint32_t MMID, int32_t smsID)
|
|
{
|
|
if (m_bMemIsConnected)
|
|
{
|
|
char QS[MAX_PATH];
|
|
sprintf(QS, "UPDATE `module_modem` SET `active_sms`=%d WHERE `id`=%d ", smsID, MMID);
|
|
return m_pDataStorage->SilentQuery(QS);
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool sqliteDBC::updateNodePushedCMD(uint32_t CmdID, uint8_t status)
|
|
{
|
|
if (m_bMemIsConnected)
|
|
{
|
|
char QS[MAX_PATH];
|
|
sprintf(QS, "UPDATE `nodes_qcq` SET `status`=%d WHERE `id`=%d ", status, CmdID);
|
|
return m_pDataMemory->SilentQuery(QS);
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool sqliteDBC::cleanNodePushedCMD(void)
|
|
{
|
|
if (m_bMemIsConnected)
|
|
{
|
|
return m_pDataMemory->SilentQuery("DELETE FROM `nodes_qcq` WHERE `status` > 200");
|
|
};
|
|
return false;
|
|
}
|
|
|
|
void sqliteDBC::deleteNIF(uint32_t NifID)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
sprintf(tQBuf, "DELETE FROM `network_interfaces` WHERE `id`=%d", NifID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
};
|
|
}
|
|
|
|
void sqliteDBC::deleteNIS(uint32_t NisID) {
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
sprintf(tQBuf, "DELETE FROM `network_infrastructure` WHERE `id`=%d", NisID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
};
|
|
}
|
|
|
|
void sqliteDBC::deleteNetwork(uint32_t NetID) {
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
sprintf(tQBuf, "DELETE FROM `networks` WHERE `id`=%d", NetID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
};
|
|
}
|
|
|
|
bool sqliteDBC::deleteReportStat(REPORT_DIRINFO & RDF)
|
|
{
|
|
if (m_bStaIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
sprintf(tQBuf, "DELETE FROM `days` WHERE `year`=%s AND `month`=%s AND `day`=%s", RDF.YEAR, RDF.MONTH, RDF.DAY);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStatistics->SilentQuery(tQBuf);
|
|
return true;
|
|
};
|
|
return false;
|
|
}
|
|
|
|
void sqliteDBC::deleteResource(uint32_t ResourceID) {
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
sprintf(tQBuf, "DELETE FROM `resources` WHERE `id`=%d", ResourceID );
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
};
|
|
}
|
|
|
|
void sqliteDBC::deleteSensor(uint32_t SensorID) {
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
sprintf(tQBuf, "DELETE FROM `lrf_sensors` WHERE `id`=%d", SensorID );
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
};
|
|
}
|
|
|
|
void sqliteDBC::deleteUART(uint32_t UARTID) {
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
sprintf(tQBuf, "DELETE FROM `uart_settings` WHERE `id`=%d", UARTID );
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
};
|
|
}
|
|
|
|
bool sqliteDBC::updateServerUtilisation(DBC_SYS_LOAD_INFO * ptr)
|
|
{
|
|
if (m_bMemIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
sprintf(tQBuf,
|
|
"UPDATE `servers` SET `ts`=STRFTIME('%%s'), `cpu_cores`=%d, `stat_cpu1`=%0.1f, `stat_cpu5`=%0.1f, `stat_cpu15`=%0.1f, `stat_mem`=%0.1f, `stat_disk`=%0.1f, `temp0`=%0.1f, `val_mem_tottal`=%" PRIu64 ", `val_mem_current`=%" PRIu64
|
|
", `val_disk_tottal`=%" PRIu64 ", `val_disk_current`=%" PRIu64 " WHERE `id`=%d",
|
|
ptr->CPU_CORES, ptr->cpu1, ptr->cpu5, ptr->cpu15, ptr->mem, ptr->disk, ptr->temperature, ptr->T_DISK, ptr->C_DISK, ptr->T_MEM, ptr->C_MEM, m_nServerID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataMemory->SilentQuery(tQBuf);
|
|
return true;
|
|
};
|
|
return false;
|
|
}
|
|
|
|
/********************************************************************
|
|
* *
|
|
* Slow DB Functions *
|
|
* *
|
|
********************************************************************/
|
|
bool sqliteDBC::addLRFDraw(uint32_t node_id, CSTR uniq_id, uint8_t lrf_id, uint8_t type)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[1024];
|
|
sprintf(tQBuf, "INSERT INTO `lrf_draw`(`node_id`,`lrf_id`,`type`,`ts`,`data`) VALUES(%d,%d,%d,STRFTIME('%%s'),'%s')", node_id, lrf_id, type, uniq_id);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
return true;
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool sqliteDBC::addDeviceDraw(uint32_t DBID, uint8_t type, uint8_t lrf, void * th_data, uint32_t th_size)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
if (type == 0)
|
|
{
|
|
char tQBuf[1024];
|
|
CSTR uid = getUniqID_MD5();
|
|
if (uid == NULL)
|
|
{
|
|
return false;
|
|
}
|
|
sprintf(tQBuf, "data/device_draws/%s.raw", uid);
|
|
FILE * fd = fopen(tQBuf, "wb+");
|
|
if (fd != NULL)
|
|
{
|
|
uint32_t sisi = th_size >> 2;
|
|
fwrite(&sisi, 4, 1, fd);
|
|
fwrite(th_data, 4, sisi, fd);
|
|
fclose(fd);
|
|
bool rV = addLRFDraw(DBID, uid, lrf, type);
|
|
free(uid);
|
|
return rV;
|
|
};
|
|
free(uid);
|
|
}
|
|
else
|
|
{
|
|
return addLRFDraw(DBID, (CSTR) th_data, lrf, type);
|
|
};
|
|
};
|
|
return false;
|
|
}
|
|
|
|
void sqliteDBC::updateStats(bool evt, bool video, uint8_t ses_status)
|
|
{
|
|
if (m_bStaIsConnected && ( evt || video ))
|
|
{
|
|
char tQBuf[1024];
|
|
switch (ses_status)
|
|
{
|
|
case SESSION_CONTINUE:
|
|
{
|
|
if (video)
|
|
{
|
|
sprintf(tQBuf, "INSERT INTO `days`(`year`,`month`,`day`,`videos_count`) VALUES(%s,%s,%s,1) ON CONFLICT(`year`,`month`,`day`) DO UPDATE SET `videos_count`=`videos_count`+1", m_sCRepInfo.YEAR, m_sCRepInfo.MONTH, m_sCRepInfo.DAY);
|
|
}
|
|
else
|
|
{
|
|
sprintf(tQBuf, "INSERT INTO `days`(`year`,`month`,`day`,`evt_count`) VALUES(%s,%s,%s,1) ON CONFLICT(`year`,`month`,`day`) DO UPDATE SET `evt_count`=`evt_count`+1", m_sCRepInfo.YEAR, m_sCRepInfo.MONTH, m_sCRepInfo.DAY);
|
|
};
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStatistics->SilentQuery(tQBuf);
|
|
break;
|
|
};
|
|
case SESSION_START:
|
|
{
|
|
// Check New Day Reports
|
|
REPORT_DIRINFO tRR;// = {0}; initialized by fillRDF
|
|
fillRDF(time(NULL), tRR);
|
|
if (tRR.ts > m_sCRepInfo.ts)
|
|
{
|
|
// New Day Report
|
|
if (m_bRepIsConnected)
|
|
{
|
|
m_bRepIsConnected = false;
|
|
LOG("Disconnect Report!");
|
|
m_pDataReports->Disconnect();
|
|
};
|
|
memcpy(&m_sPRepInfo, &m_sCRepInfo, sizeof(REPORT_DIRINFO));
|
|
memcpy(&m_sCRepInfo, &tRR, sizeof(REPORT_DIRINFO));
|
|
if (checkRDFDir(m_pDbReportBase, m_sCRepInfo, true, getUserUid(web_access_user), getUserGid(web_access_group)))
|
|
{
|
|
sprintf(m_pDbReport, "%s/%s/%s/%s/report.db", m_pDbReportBase, m_sCRepInfo.YEAR, m_sCRepInfo.MONTH, m_sCRepInfo.DAY);
|
|
LOG("Connect Report!");
|
|
LOG(m_pDbReport);
|
|
if (m_pDataReports->Connect(m_pDbReport, 0, true))
|
|
{
|
|
chown(m_pDbReport, getUserUid(web_access_user), getUserGid(web_access_group));
|
|
chmod(m_pDbReport, DB_FILE_MODE);
|
|
m_pDataReports->SilentQuery(
|
|
"CREATE TABLE IF NOT EXISTS \"events\" ( \"id\" INTEGER NOT NULL, \"node_id\" INTEGER NOT NULL, \"uuid\" TEXT NOT NULL UNIQUE, \"ts\" INTEGER NOT NULL, \"ts_ms\" INTEGER NOT NULL, \"evt_type\" INTEGER NOT "
|
|
"NULL, \"lrf_id\" INTEGER, \"range_digital\" INTEGER, \"azimuth\" REAL, \"elevation\" REAL, \"range\" REAL, \"area\" REAL, \"lat\" REAL, \"lon\" REAL, \"alt\" REAL, \"ref_id\" INTEGER, \"ref_uuid\" "
|
|
"TEXT, PRIMARY KEY(\"id\" AUTOINCREMENT) )");
|
|
m_pDataReports->SilentQuery("CREATE TABLE IF NOT EXISTS \"events_2_pictures\" ( \"evt_id\" INTEGER NOT NULL, \"picture_id\" INTEGER NOT NULL )");
|
|
m_pDataReports->SilentQuery("CREATE TABLE IF NOT EXISTS \"events_2_videos\" ( \"evt_id\" INTEGER NOT NULL, \"video_id\" INTEGER NOT NULL, \"frame\" INTEGER DEFAULT 0, \"tss\" INTEGER, \"tms\" INTEGER )");
|
|
m_pDataReports->SilentQuery(
|
|
"CREATE TABLE IF NOT EXISTS \"pictures\" ( \"id\" INTEGER NOT NULL, \"media_stream_id\" INTEGER NOT NULL, \"md5\" TEXT NOT NULL UNIQUE, \"uts\" INTEGER NOT NULL, \"uts_ms\" INTEGER NOT NULL, \"ext\" TEXT "
|
|
"NOT NULL, \"data\" BLOB COLLATE BINARY, PRIMARY KEY(\"id\" AUTOINCREMENT) )");
|
|
m_pDataReports->SilentQuery(
|
|
"CREATE TABLE IF NOT EXISTS \"videos\" ( \"id\" INTEGER NOT NULL, \"media_stream_id\" INTEGER NOT NULL, \"md5\" TEXT NOT NULL UNIQUE, \"uts\" INTEGER NOT NULL, \"uts_ms\" INTEGER NOT NULL, \"ext\" TEXT NOT "
|
|
"NULL, \"fps\" INTEGER NOT NULL, \"flength\" INTEGER, PRIMARY KEY(\"id\" AUTOINCREMENT) )");
|
|
m_bRepIsConnected = true;
|
|
LOG("Report Connected!");
|
|
// Create New Day Record
|
|
sprintf(tQBuf, "INSERT INTO `days`(`year`,`month`,`day`,`session_count`,`session_closed`) VALUES(%s,%s,%s,0,0) ON CONFLICT(`year`,`month`,`day`) DO UPDATE SET `session_count`=`session_count`+1, `session_closed`=0",
|
|
m_sCRepInfo.YEAR, m_sCRepInfo.MONTH, m_sCRepInfo.DAY);
|
|
LOG(tQBuf);
|
|
m_pDataStatistics->SilentQuery(tQBuf);
|
|
};
|
|
};
|
|
};
|
|
// Create New record
|
|
sprintf(tQBuf, "INSERT INTO `days`(`year`,`month`,`day`,`session_count`,`session_closed`) VALUES(%s,%s,%s,1,0) ON CONFLICT(`year`,`month`,`day`) DO UPDATE SET `session_count`=`session_count`+1, `session_closed`=0", m_sCRepInfo.YEAR,
|
|
m_sCRepInfo.MONTH, m_sCRepInfo.DAY);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStatistics->SilentQuery(tQBuf);
|
|
|
|
break;
|
|
};
|
|
case SESSION_END:
|
|
{
|
|
sprintf(tQBuf, "INSERT INTO `days`(`year`,`month`,`day`,`session_count`,`session_closed`) VALUES(%s,%s,%s,0,1) ON CONFLICT(`year`,`month`,`day`) DO UPDATE SET `session_closed`=1", m_sCRepInfo.YEAR, m_sCRepInfo.MONTH, m_sCRepInfo.DAY);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStatistics->SilentQuery(tQBuf);
|
|
break;
|
|
};
|
|
case SESSION_DROP:
|
|
{
|
|
// sprintf( tQBuf, "UPDATE `days` SET `session_count`=`session_count`-1, `session_closed`=1 WHERE `year`='%s' AND `month`='%s' AND `day`='%s'",
|
|
sprintf(tQBuf, "UPDATE `days` SET `session_closed`=1 WHERE `year`='%s' AND `month`='%s' AND `day`='%s'", m_sCRepInfo.YEAR, m_sCRepInfo.MONTH, m_sCRepInfo.DAY);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStatistics->SilentQuery(tQBuf);
|
|
break;
|
|
};
|
|
};
|
|
};
|
|
}
|
|
|
|
bool sqliteDBC::dropSession()
|
|
{
|
|
if (m_bRepIsConnected)
|
|
{
|
|
char tQBuf[1024];
|
|
AAssoc * result;
|
|
#ifdef REMOVE_ONLY_SESSION_MARKS
|
|
sprintf(tQBuf, "SELECT `ts`, `ts_ms` FROM `events` WHERE `evt_type`=%d ORDER BY `ts` DESC,`ts_ms` DESC LIMIT 1", EVT_LRF_START_SESSION);
|
|
#else
|
|
sprintf(tQBuf, "SELECT `ts`, `ts_ms` FROM `events` WHERE `evt_type`=%d ORDER BY `ts` DESC,`ts_ms` DESC LIMIT 1", EVT_LRF_START_SESSION);
|
|
#endif
|
|
m_pDataReports->Query(tQBuf);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataReports->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
uint32_t ts = 0;
|
|
uint32_t ms = 0;
|
|
uint64_t r = 0;
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("ts");
|
|
if (it != cArr->end())
|
|
{
|
|
ts = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("ts_ms");
|
|
if (it != cArr->end())
|
|
{
|
|
ms = atoi(it->second.c_str());
|
|
};
|
|
r = ts;
|
|
r = (r * 1000) + ms;
|
|
};
|
|
deleteResult(result);
|
|
if (r)
|
|
{
|
|
#ifdef REMOVE_ONLY_SESSION_MARKS
|
|
sprintf(tQBuf, "DELETE FROM `events` WHERE ((`ts`*1000+`ts_ms`) >= %" PRIu64 ") AND ( `evt_type`=%d OR `evt_type`=%d OR `evt_type`=%d )", r, EVT_LRF_START_SESSION, EVT_LRF_END_SESSION_TO, EVT_LRF_END_SESSION_MA);
|
|
#else
|
|
sprintf(tQBuf, "DELETE FROM `events` WHERE (`ts`*1000+`ts_ms`) >= %" PRIu64, r);
|
|
#endif
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataReports->SilentQuery(tQBuf);
|
|
};
|
|
};
|
|
};
|
|
updateStats(false, false, SESSION_DROP);
|
|
return true;
|
|
}
|
|
|
|
uint32_t sqliteDBC::addEvent(DBC_EVT_RECORD * ptr)
|
|
{
|
|
if (ptr == NULL)
|
|
{
|
|
return 0;
|
|
}
|
|
if (m_bRepIsConnected)
|
|
{
|
|
char tQBuf[1024];
|
|
switch (ptr->type)
|
|
{
|
|
case EVT_LRF_END_SESSION_TO:
|
|
case EVT_LRF_END_SESSION_MA:
|
|
updateStats(false, false, SESSION_END);
|
|
sprintf(tQBuf, "INSERT INTO `events`(`node_id`,`uuid`,`ts`,`ts_ms`,`evt_type`) VALUES(%d,'%s',%d,%d,%d)", ptr->node_id, ptr->uuid, ptr->ts_s, ptr->ts_ms, ptr->type);
|
|
break;
|
|
case EVT_LRF_START_SESSION:
|
|
updateStats(false, false, SESSION_START);
|
|
sprintf(tQBuf, "INSERT INTO `events`(`node_id`,`uuid`,`ts`,`ts_ms`,`evt_type`) VALUES(%d,'%s',%d,%d,%d)", ptr->node_id, ptr->uuid, ptr->ts_s, ptr->ts_ms, ptr->type);
|
|
break;
|
|
case EVT_FLT_LATF_CHK:
|
|
case EVT_FLT_LATF_UP_DETEC:
|
|
case EVT_FLT_LATF_BT_DETEC:
|
|
case EVT_FLT_LATF_TRP_DET:
|
|
case EVT_FLT_LATF_TRP_UPDT:
|
|
case EVT_FLT_LATF_SUSP_START:
|
|
case EVT_FLT_LATF_REGULAR:
|
|
case EVT_FLT_LATF_DISABLED:
|
|
case EVT_FLT_LATF_SUSP_DET:
|
|
case EVT_FLT_LATF_DIFF_DET:
|
|
case EVT_FLT_BUBBLE_POPED:
|
|
case EVT_FLT_BUBBLE_CREATED:
|
|
case EVT_FLT_BUBBLE_BLOCK_T:
|
|
case EVT_FLT_BUBBLE_BLOCK_P:
|
|
{
|
|
updateStats();
|
|
sprintf(tQBuf,
|
|
"INSERT INTO `events`(`node_id`,`uuid`,`ts`,`ts_ms`,`evt_type`,`lrf_id`,`range_digital`,`azimuth`,`range`,`area`,`lat`,`lon`,`alt`)"
|
|
" VALUES(%d,'%s',%d,%d,%d,%d,%d,%0.2f,%0.2f,%0.2f,%0.7f,%0.7f,%0.2f)",
|
|
ptr->node_id, ptr->uuid, ptr->ts_s, ptr->ts_ms, ptr->type, ptr->lrf_id, ptr->range_digital, ptr->az, ptr->ra, ptr->area, ptr->lat, ptr->lon, ptr->alt);
|
|
break;
|
|
};
|
|
case EVT_FLT_LATF_OP_DISABLED:
|
|
case EVT_FLT_LATF_OP_TD:
|
|
case EVT_FLT_LATF_OP_TG:
|
|
case EVT_FLT_LATF_OP_EXP:
|
|
case EVT_FLT_LATF_TRP_EXP:
|
|
case EVT_FLT_LATF_SUSP_NAK:
|
|
case EVT_FLT_LATF_SUSP_EXP:
|
|
{
|
|
updateStats();
|
|
sprintf(tQBuf, "INSERT INTO `events`(`node_id`,`uuid`,`ts`,`ts_ms`,`evt_type`) VALUES(%d,'%s',%d,%d,%d)", ptr->node_id, ptr->uuid, ptr->ts_s, ptr->ts_ms, ptr->type);
|
|
break;
|
|
};
|
|
case EVT_OP_ACK_MASK:
|
|
case EVT_OP_NACK_MASK:
|
|
case EVT_OP_ON_MASK:
|
|
case EVT_OP_OFF_MASK:
|
|
case EVT_CONNECTED:
|
|
case EVT_DISCONNECTED:
|
|
case EVT_COMMUNICATION_JAMED:
|
|
case EVT_STUDY:
|
|
case EVT_BUSY:
|
|
case EVT_FLIP:
|
|
case EVT_READY:
|
|
case EVT_ERR_LRF_NO_IRQ:
|
|
case EVT_ERR_LRF_NO_ZERO:
|
|
case EVT_ERR_LRF_ANGLE:
|
|
case EVT_ERR_LRF_VOLTAGE:
|
|
case EVT_ERR_LRF_BROKEN:
|
|
case EVT_LRF_VIS_CHANGED:
|
|
case EVT_ERR_OVERFLOW:
|
|
case EVT_SST_OVERFLOW:
|
|
case EVT_VIDEO_FPS_DEGRADED:
|
|
case EVT_VIDEO_FPS_RAISED:
|
|
{
|
|
updateStats();
|
|
sprintf(tQBuf, "INSERT INTO `events`(`node_id`,`uuid`,`ts`,`ts_ms`,`evt_type`) VALUES(%d,'%s',%d,%d,%d)", ptr->node_id, ptr->uuid, ptr->ts_s, ptr->ts_ms, ptr->type);
|
|
break;
|
|
};
|
|
case EVT_ROI_ACTIVE:
|
|
case EVT_TARGET_3D_WHITE:
|
|
case EVT_TARGET_3D_BLACK:
|
|
{
|
|
updateStats();
|
|
sprintf(tQBuf,
|
|
"INSERT INTO `events`(`node_id`,`uuid`,`ts`,`ts_ms`,`evt_type`,`lrf_id`,`range_digital`,`azimuth`,`elevation`,`range`,`area`,`lat`,`lon`,`alt`)"
|
|
" VALUES(%d,'%s',%d,%d,%d,%d,%d,%0.2f,%0.2f,%0.2f,%0.2f,%0.7f,%0.7f,%0.2f)",
|
|
ptr->node_id, ptr->uuid, ptr->ts_s, ptr->ts_ms, ptr->type, ptr->lrf_id, ptr->range_digital, ptr->az, ptr->el, ptr->ra, ptr->area, ptr->lat, ptr->lon, ptr->alt);
|
|
break;
|
|
};
|
|
case EVT_TARGET_2D_WHITE:
|
|
case EVT_TARGET_2D_BLACK:
|
|
{
|
|
updateStats();
|
|
sprintf(tQBuf,
|
|
"INSERT INTO `events`(`node_id`,`uuid`,`ts`,`ts_ms`,`evt_type`,`lrf_id`,`range_digital`,`azimuth`,`range`,`area`,`lat`,`lon`,`alt`)"
|
|
" VALUES(%d,'%s',%d,%d,%d,%d,%d,%0.2f,%0.2f,%0.2f,%0.7f,%0.7f,%0.2f)",
|
|
ptr->node_id, ptr->uuid, ptr->ts_s, ptr->ts_ms, ptr->type, ptr->lrf_id, ptr->range_digital, ptr->az, ptr->ra, ptr->area, ptr->lat, ptr->lon, ptr->alt);
|
|
break;
|
|
};
|
|
default: return 0;
|
|
};
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
if (m_bRepIsConnected)
|
|
{
|
|
return ptr->id = m_pDataReports->QueryID(tQBuf);
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("Report DB Droped!");
|
|
}
|
|
};
|
|
return 0;
|
|
}
|
|
|
|
bool sqliteDBC::addIPCam(OBSERVER_RESULT * tPtr)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[2048];
|
|
char tIpBuf[32];
|
|
char tProto[32];
|
|
char tPath[CTEXT];
|
|
char * tPos;
|
|
char * tPos2;
|
|
uint16_t tPort = 0;
|
|
memcpy(tProto, tPtr->XAddrs, 5);
|
|
tProto[5] = (char) 0;
|
|
if (tProto[4] == ':')
|
|
{
|
|
tProto[4] = (char) 0;
|
|
}
|
|
memset(tPath, 0, CTEXT);
|
|
tPos = strstr(tPtr->XAddrs, "//");
|
|
if (tPos != NULL)
|
|
{
|
|
tPos2 = strstr(tPos + 2, ":");
|
|
if (tPos2 != NULL)
|
|
{
|
|
LOG("IP Port Defined!");
|
|
int len;//, len2, len3;
|
|
len = tPos2 - tPos - 2;
|
|
strncpy(tIpBuf, tPos + 2, len);
|
|
tIpBuf[len] = (char) 0;
|
|
tPort = atoi(tPos2 + 1);
|
|
strncpy(tPath, tPos + 2 + len, CTEXT);
|
|
}
|
|
else
|
|
{
|
|
tPos2 = strstr(tPos + 2, "/");
|
|
if (tPos2 != NULL)
|
|
{
|
|
int len;//, len2, len3;
|
|
len = tPos2 - tPos - 2;
|
|
strncpy(tIpBuf, tPos + 2, len);
|
|
tIpBuf[len] = (char) 0;
|
|
strncpy(tPath, tPos + 2 + len, CTEXT);
|
|
}
|
|
else
|
|
{
|
|
tPos2 = strstr(tPos + 2, "/");
|
|
LOG_ERROR("Pos 2 - err");
|
|
tIpBuf[0] = (char) 0;
|
|
};
|
|
};
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("Pos 0 - err");
|
|
tIpBuf[0] = (char) 0;
|
|
};
|
|
if (tPort)
|
|
{
|
|
sprintf(tQBuf,
|
|
"INSERT INTO cameras (`online`,`uuid`,`onvif_ctrl`,`ip`,`port`,`type`,`status`,`mac`,`hardware`,`name`,`onvif_access`) VALUES (1,'%s','%s','%s',%d,12,0,'%s','%s','%s','%s') ON CONFLICT(`uuid`) DO UPDATE SET `online`=1, `ip`='%s', "
|
|
"`port`=%d",
|
|
tPtr->RefID,
|
|
// tPtr->XAddrs,
|
|
tPath, tIpBuf, tPort, tPtr->MAC, tPtr->Hardware, tPtr->Name, tProto,
|
|
// tPtr->XAddrs,
|
|
tIpBuf, tPort);
|
|
}
|
|
else
|
|
{
|
|
sprintf(tQBuf, "INSERT INTO cameras (`online`,`uuid`,`onvif_ctrl`,`ip`,`type`,`status`,`mac`,`hardware`,`name`,`onvif_access`) VALUES (1,'%s','%s','%s',12,0,'%s','%s','%s','%s') ON CONFLICT(`uuid`) DO UPDATE SET `online`=1, `ip`='%s'",
|
|
tPtr->RefID,
|
|
// tPtr->XAddrs,
|
|
tPath, tIpBuf, tPtr->MAC, tPtr->Hardware, tPtr->Name, tProto,
|
|
// tPtr->XAddrs,
|
|
tIpBuf);
|
|
}
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
return true;
|
|
};
|
|
return false;
|
|
}
|
|
|
|
uint32_t sqliteDBC::addLocalCam(CSTR name, CSTR hardware, CSTR path, uint32_t width, uint32_t height, uint16_t fps, uint16_t den)
|
|
{
|
|
uint32_t RetVal = 0;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[1024];
|
|
char tM5[33];
|
|
if (den) den = den;
|
|
CSTR tMD5 = MD5String(path);
|
|
if (tMD5 != NULL)
|
|
{
|
|
memcpy(tM5, tMD5, 33);
|
|
tM5[32] = (char) 0;
|
|
free(tMD5);
|
|
|
|
sprintf(tQBuf, "INSERT INTO cameras (`online`,`uuid`,`type`,`status`,`hardware`,`name`,`ip`) VALUES (1,'%s',10,0,'%s','%s','%s') ON CONFLICT(`uuid`) DO UPDATE SET `online`=1", tM5, hardware, name, path);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
uint32_t camID = (uint32_t) m_pDataStorage->QueryID(tQBuf);
|
|
if (camID == 0)
|
|
{
|
|
camID = getCamId(tM5);
|
|
};
|
|
sprintf(tQBuf,
|
|
"INSERT INTO `media_streams`(`source_id`,`source_type`,`valid`,`name`,`token`,`img_width`,`img_height`,`mrl_proto`,`mrl`,`picture_proto`,`fps`) VALUES(%d,'A',1,'%s','%s',%d,%d,'v4l2','%s','v4l2',%d) ON CONFLICT(`source_id`,`token`) "
|
|
"DO UPDATE SET `valid`=1, img_width=%d, img_height=%d, `fps`=%d",
|
|
camID, name, tM5, width, height, path, fps, width, height, fps);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
RetVal = (uint32_t) m_pDataStorage->QueryID(tQBuf);
|
|
if (RetVal == 0)
|
|
{
|
|
RetVal = getMediaStreamID(camID, tM5);
|
|
};
|
|
};
|
|
};
|
|
return RetVal;
|
|
}
|
|
|
|
uint32_t sqliteDBC::addLocalNetwork(uint32_t NIF_ID, NETWORK_TYPE net_type, CSTR address, CSTR mask, CSTR gateway, CSTR broadcast)
|
|
{
|
|
uint32_t RetVal = 0;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
sprintf(tQBuf, "INSERT INTO `networks`(`nif_id`,`type`,`address`,`gateway`,`mask`,`broadcast`) VALUES (%d,%d,'%s','%s','%s','%s') ON CONFLICT(`nif_id`,`type`) DO UPDATE SET `address`='%s', `gateway`='%s', `mask`='%s', `broadcast`='%s'",
|
|
NIF_ID, net_type, address, gateway, mask, broadcast, address, gateway, mask, broadcast);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
RetVal = m_pDataStorage->QueryID(tQBuf);
|
|
// On Update IF data no need to return ID
|
|
// if( RetVal == 0 ) {
|
|
// RetVal = getNetworkInterfaceID( tKey );
|
|
//};
|
|
};
|
|
return RetVal;
|
|
}
|
|
|
|
uint32_t sqliteDBC::addLocalNetworkInfrastructure(uint32_t NIF_ID, uint32_t OUTBOUND_NIF, bool ena_dhcp, CSTR BRANG, CSTR ERANG, CSTR MASK, CSTR LEASE_TIME)
|
|
{
|
|
uint32_t RetVal = 0;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
bool ena_routing = true;
|
|
if (OUTBOUND_NIF == 0)
|
|
{
|
|
ena_routing = false;
|
|
};
|
|
if (ena_dhcp)
|
|
{
|
|
if (BRANG == NULL || ERANG == NULL || MASK == NULL || LEASE_TIME == NULL)
|
|
{
|
|
LOG_ERROR("Wrong DHCP parameters to create Network Infrastructure!");
|
|
return 0;
|
|
};
|
|
sprintf(tQBuf,
|
|
"INSERT INTO `network_infrastructure`(`nif_id`,`enable_routing`,`outbond_nif`,`enable_dhcp`,`dhcp_range_begin`,`dhcp_range_end`,`dhcp_range_mask`,`dhcp_lease_time`) VALUES (%d,%d,%d,1,'%s','%s','%s','%s') ON CONFLICT(`nif_id`) DO "
|
|
"UPDATE SET `enable_routing`=%d, `outbond_nif`=%d, `enable_dhcp`=1, `dhcp_range_begin`='%s', `dhcp_range_end`='%s', `dhcp_range_mask`='%s', `dhcp_lease_time`='%s'",
|
|
NIF_ID, ena_routing, OUTBOUND_NIF, BRANG, ERANG, MASK, LEASE_TIME, ena_routing, OUTBOUND_NIF, BRANG, ERANG, MASK, LEASE_TIME);
|
|
}
|
|
else
|
|
{
|
|
if (ena_routing)
|
|
{
|
|
sprintf(tQBuf, "INSERT INTO `network_infrastructure`(`nif_id`,`enable_routing`,`outbond_nif`) VALUES(%d,1,%d) ON CONFLICT(`nif_id`) DO UPDATE SET `enable_routing`=1, `outbond_nif`=%d", NIF_ID, OUTBOUND_NIF, OUTBOUND_NIF);
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("No Special Service Defined To Network Infrastructure!");
|
|
return 0;
|
|
};
|
|
};
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
RetVal = m_pDataStorage->QueryID(tQBuf);
|
|
// On Update IF data no need to return ID
|
|
if (RetVal == 0)
|
|
{
|
|
RetVal = getNetworkInfrastructureID(NIF_ID);
|
|
};
|
|
};
|
|
return RetVal;
|
|
}
|
|
|
|
uint32_t sqliteDBC::addLocalNIF(CSTR device, CSTR mac, NIF_TYPE dtype, NIF_MODE dmode, uint32_t aux_id)
|
|
{
|
|
uint32_t RetVal = 0;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
char * tKey = MD5String(device);
|
|
if (tKey != NULL)
|
|
{
|
|
sprintf(tQBuf, "INSERT INTO `network_interfaces` (`type`,`key`,`device_name`,`mac`,`mode`,`aux_id`) VALUES (%d,'%s','%s','%s',%d,%d) ON CONFLICT(`key`) DO UPDATE SET `mode`=%d,`aux_id`=%d,`mac`='%s'", dtype, tKey, device, mac, dmode,
|
|
aux_id, dmode, aux_id, mac);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
RetVal = m_pDataStorage->QueryID(tQBuf);
|
|
if (RetVal == 0)
|
|
{
|
|
RetVal = getNIF_ID(tKey);
|
|
};
|
|
free(tKey);
|
|
};
|
|
};
|
|
return RetVal;
|
|
}
|
|
|
|
uint32_t sqliteDBC::addLocalUART(uint8_t utype, uint32_t speed, uint8_t bit, char parity, float stop_bit, CSTR PATH, uint8_t mode, uint16_t port)
|
|
{
|
|
uint32_t RetVal = 0;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
sprintf(tQBuf, "INSERT INTO `uart_settings`(`node_id`,`type`,`speed`,`bit`,`parity`,`stop_bit`,`mode`,`port`,`path`) VALUES (%d,%d,%d,%d,'%c',%.1f,%d,%d,'%s') ON CONFLICT(`node_id`,`type`,`path`) DO UPDATE SET `id`=`id`", m_nServerNodeID,
|
|
utype, speed, bit, parity, stop_bit, mode, port, PATH);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
RetVal = m_pDataStorage->QueryID(tQBuf);
|
|
if (RetVal == 0)
|
|
{
|
|
RetVal = getUartID(m_nServerNodeID, utype, PATH);
|
|
};
|
|
};
|
|
return RetVal;
|
|
}
|
|
|
|
uint32_t sqliteDBC::addLocalWiFi(uint32_t NIF_ID, WIFI_MODE mode, CSTR SSID, CSTR password, WIFI_ENCRIPTION encryption, uint32_t router_id)
|
|
{
|
|
uint32_t RetVal = 0;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
sprintf(tQBuf,
|
|
"INSERT INTO `wifis` (`nif_id`,`mode`,`aux_id`,`SSID`,`password`,`encryption_type`) VALUES (%d,%d,%d,'%s','%s',%d) ON CONFLICT (`nif_id`) DO UPDATE SET `mode`=%d, `aux_id`=%d, `SSID`='%s', `password`='%s', `encryption_type`=%d", NIF_ID,
|
|
mode, router_id, SSID, password, encryption, mode, router_id, SSID, password, encryption);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
RetVal = m_pDataStorage->QueryID(tQBuf);
|
|
if (RetVal == 0)
|
|
{
|
|
RetVal = getWiFi_ID(NIF_ID);
|
|
};
|
|
};
|
|
return RetVal;
|
|
}
|
|
|
|
bool sqliteDBC::cleanLRFMask(uint32_t maskID, bool deleteMask)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
// sprintf( tQBuf, "DELETE FROM `lrf_mask_trace_zones` WHERE `zone_id` IN ( SELECT `id` FROM `lrf_mask_traces` WHERE `mask_id`=%d )", maskID );
|
|
#ifdef DEBUG_ALL
|
|
// LOG(tQBuf);
|
|
#endif
|
|
// m_pDataStorage->SilentQuery( tQBuf );
|
|
// sprintf( tQBuf, "DELETE FROM `lrf_mask_traces` WHERE `mask_id`=%d", maskID );
|
|
#ifdef DEBUG_ALL
|
|
// LOG(tQBuf);
|
|
#endif
|
|
// m_pDataStorage->SilentQuery( tQBuf );
|
|
sprintf(tQBuf, "DELETE FROM `lrf_mask_vertex_points` WHERE `vertex_id` IN ( SELECT `id` FROM `lrf_mask_vertexes` WHERE `mask_id`=%d )", maskID);
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
|
|
sprintf(tQBuf, "DELETE FROM `lrf_mask_vertexes` WHERE `mask_id`=%d", maskID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
// Delete Mask Itself!
|
|
if (deleteMask)
|
|
{
|
|
sprintf(tQBuf, "DELETE FROM `lrf_masks` WHERE `id`=%d", maskID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
};
|
|
return true;
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool sqliteDBC::cleanLRFWidthTable(uint32_t sensorID)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
sprintf(tQBuf, "DELETE FROM `lrf_detection_width_tables` WHERE `aux_id`=%d", sensorID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
return true;
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool sqliteDBC::cleanResources(bool all)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
if (all)
|
|
{
|
|
sprintf(tQBuf, "UPDATE `resources` SET `active`=0 WHERE `node_id`=%d", m_nServerNodeID);
|
|
}
|
|
else
|
|
{
|
|
sprintf(tQBuf, "UPDATE `resources` SET `active`=0 WHERE ( `node_id`=%d ) AND ( `type`=100 OR `type`=101 OR `type`=103 OR `type`=120 )", m_nServerNodeID);
|
|
};
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
return true;
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool sqliteDBC::wipeServerResources()
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
sprintf(tQBuf, "DELETE FROM `resources` WHERE `node_id`=%d", m_nServerNodeID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
return true;
|
|
};
|
|
return false;
|
|
}
|
|
|
|
uint32_t sqliteDBC::addLRFMask(uint32_t devID, uint8_t lrfID, uint8_t layerID)
|
|
{
|
|
uint32_t RetVal = 0;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
sprintf(tQBuf, "INSERT INTO `lrf_masks`(`sensor_id`,`lrf_id`,`layer`) VALUES(%d,%d,%d) ON CONFLICT(`sensor_id`,`lrf_id`,`layer`) DO UPDATE SET `layer`=%d", devID, lrfID, layerID, layerID);
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
RetVal = m_pDataStorage->QueryID(tQBuf);
|
|
if (RetVal == 0)
|
|
{
|
|
RetVal = getLRFMaskID(devID, lrfID, layerID);
|
|
};
|
|
};
|
|
return RetVal;
|
|
}
|
|
|
|
uint32_t sqliteDBC::addLRFMaskPolygone(uint32_t maskID, uint8_t vertexID, uint8_t r, uint8_t g, uint8_t b)
|
|
{
|
|
uint32_t RetVal = 0;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
sprintf(tQBuf, "INSERT INTO `lrf_mask_vertexes`(`mask_id`,`vertex_id`,`r`,`g`,`b`) VALUES(%d,%d,%d,%d,%d)", maskID, vertexID, r, g, b);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
RetVal = m_pDataStorage->QueryID(tQBuf);
|
|
if (RetVal == 0)
|
|
{
|
|
RetVal = getLRFMaskPolygoneID(maskID, vertexID);
|
|
};
|
|
};
|
|
return RetVal;
|
|
}
|
|
|
|
bool sqliteDBC::addLRFMaskPolygonePoint(uint32_t polyID, int16_t x, int16_t y)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
sprintf(tQBuf, "INSERT INTO `lrf_mask_vertex_points`(`vertex_id`,`x`,`y`) VALUES(%d,%d,%d)", polyID, x, y);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
return true;
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool sqliteDBC::addLRFWidthTable(uint32_t sensorID, PWIDTH_TABLE ptr)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
float kK = 100.0f / ptr->nCount;
|
|
for (int i = 0; i < ptr->nCount; i++)
|
|
{
|
|
uint16_t CC = kK * i;
|
|
sprintf(tQBuf, "INSERT INTO `lrf_detection_width_tables`(`aux_id`,`width_k`,`range_k`) VALUES(%d,%d,%d)", sensorID, ptr->pTable[i], CC);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
};
|
|
return true;
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool sqliteDBC::addPicture(DBC_SNAPSHOT_DATA * ptr, CSTR ext)
|
|
{
|
|
bool rVal = false;
|
|
if (ptr != NULL)
|
|
{
|
|
if (m_bRepIsConnected)
|
|
{
|
|
char tQBuf[2048];
|
|
uint32_t pic_id;
|
|
sprintf(tQBuf, "%s/%s/%s/%s/%s.%s", m_pDbReportBase, m_sCRepInfo.YEAR, m_sCRepInfo.MONTH, m_sCRepInfo.DAY, ptr->md5, ext);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
|
|
FILE * fd = fopen(tQBuf, "wb+");
|
|
if (fd)
|
|
{
|
|
fwrite(ptr->data, 1, ptr->data_size, fd);
|
|
fclose(fd);
|
|
chown(tQBuf, getUserUid(web_access_user), getUserGid(web_access_group));
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("Error Saving Captured picture!");
|
|
return rVal;
|
|
};
|
|
sprintf(tQBuf, "INSERT INTO pictures(`media_stream_id`,`uts`,`uts_ms`,`md5`,`ext`) VALUES(%d,%d,0,'%s','%s')", ptr->stream_id, ptr->ts, ptr->md5, ext);
|
|
pic_id = (uint32_t) m_pDataReports->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`(`evt_id`,`picture_id`) VALUES(%d,%d)", *idx, pic_id);
|
|
m_pDataReports->SilentQuery(tQBuf);
|
|
};
|
|
rVal = true;
|
|
};
|
|
};
|
|
};
|
|
return rVal;
|
|
}
|
|
|
|
uint32_t sqliteDBC::addResource(uint8_t type, CSTR devName, uint32_t auxID)
|
|
{
|
|
uint32_t RetVal = 0;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[2048];
|
|
sprintf(tQBuf, "%d:%d:%s", m_nServerNodeID, type, devName);
|
|
CSTR tMD5 = MD5String(tQBuf);
|
|
if (tMD5)
|
|
{
|
|
sprintf(tQBuf, "INSERT INTO `resources`(`node_id`,`type`,`md5`,`aux_id`,`device`,`active`) VALUES (%d,%d,'%s',%d,'%s',1) ON CONFLICT(`md5`) DO UPDATE SET `active`=1, `aux_id`=%d", m_nServerNodeID, type, tMD5, auxID, devName, auxID);
|
|
free(tMD5);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
RetVal = (uint32_t) m_pDataStorage->QueryID(tQBuf);
|
|
if (RetVal == 0)
|
|
{
|
|
RetVal = getResourceID(m_nServerNodeID, type, auxID);
|
|
};
|
|
};
|
|
};
|
|
return RetVal;
|
|
}
|
|
|
|
bool sqliteDBC::addVideoEvent(uint32_t evtID, uint32_t videoID, uint32_t frame, uint32_t tss, uint32_t tms)
|
|
{
|
|
if (m_bRepIsConnected)
|
|
{
|
|
char tQBuf[2048];
|
|
sprintf(tQBuf, "INSERT INTO `events_2_videos`(`evt_id`,`video_id`,`frame`,`tss`,`tms`) VALUES(%d,%d,%d,%d,%d)", evtID, videoID, frame, tss, tms);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataReports->SilentQuery(tQBuf);
|
|
};
|
|
return false;
|
|
}
|
|
|
|
uint32_t sqliteDBC::addVideoRecord(uint32_t streamID, CSTR md5, CSTR ext, uint32_t tss, uint32_t tms, uint32_t fps)
|
|
{
|
|
uint32_t RetVal = 0;
|
|
if (m_bRepIsConnected)
|
|
{
|
|
updateStats(false, true);
|
|
char tQBuf[2048];
|
|
sprintf(tQBuf, "INSERT INTO `videos`(`media_stream_id`,`md5`,`uts`,`uts_ms`,`ext`,`fps`) VALUES(%d,'%s',%d,%d,'%s',%d)", streamID, md5, tss, tms, ext, fps);
|
|
#ifdef DEBUG_EXTRA
|
|
LOG(tQBuf);
|
|
#endif
|
|
RetVal = (uint32_t) m_pDataReports->QueryID(tQBuf);
|
|
};
|
|
return RetVal;
|
|
}
|
|
|
|
DBC_MODULE_EMBED_VIDEO_DATA * sqliteDBC::getEmbedVideoData(uint32_t ID)
|
|
{
|
|
DBC_MODULE_EMBED_VIDEO_DATA * tPtr = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT * FROM `module_eve` WHERE `id`=%d", ID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
tPtr = (DBC_MODULE_EMBED_VIDEO_DATA *) malloc(sizeof(DBC_MODULE_EMBED_VIDEO_DATA));
|
|
if (tPtr != NULL)
|
|
{
|
|
Assoc::iterator it;
|
|
memset(tPtr, 0, sizeof(DBC_MODULE_EMBED_VIDEO_DATA));
|
|
cArr = result->at(0);
|
|
it = cArr->find("output_mode");
|
|
if (it != cArr->end())
|
|
{
|
|
tPtr->output_mode = atoi(it->second.c_str());
|
|
};
|
|
// Togo Bug
|
|
if (tPtr->output_mode == 0)
|
|
{
|
|
tPtr->output_mode = 2; // Video Output
|
|
}
|
|
|
|
it = cArr->find("web_port");
|
|
if (it != cArr->end())
|
|
{
|
|
tPtr->port = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("width");
|
|
if (it != cArr->end())
|
|
{
|
|
tPtr->width = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("height");
|
|
if (it != cArr->end())
|
|
{
|
|
tPtr->height = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("compression_quality");
|
|
if (it != cArr->end())
|
|
{
|
|
tPtr->compression_quality = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("show_ts");
|
|
if (it != cArr->end())
|
|
{
|
|
tPtr->show_ts = (bool) atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("ts_x");
|
|
if (it != cArr->end())
|
|
{
|
|
tPtr->ts_x = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("ts_y");
|
|
if (it != cArr->end())
|
|
{
|
|
tPtr->ts_y = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("ts_font_face");
|
|
if (it != cArr->end())
|
|
{
|
|
tPtr->ts_font_face = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("ts_font_scale");
|
|
if (it != cArr->end())
|
|
{
|
|
tPtr->ts_font_scale = atof(it->second.c_str());
|
|
};
|
|
it = cArr->find("ts_font_thickness");
|
|
if (it != cArr->end())
|
|
{
|
|
tPtr->ts_font_thickness = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("ts_line_type");
|
|
if (it != cArr->end())
|
|
{
|
|
tPtr->ts_line_type = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("ts_transperant");
|
|
if (it != cArr->end())
|
|
{
|
|
tPtr->ts_transperant = (bool) atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("show_label");
|
|
if (it != cArr->end())
|
|
{
|
|
tPtr->show_label = (bool) atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("label_x");
|
|
if (it != cArr->end())
|
|
{
|
|
tPtr->label_x = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("label_y");
|
|
if (it != cArr->end())
|
|
{
|
|
tPtr->label_y = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("label_font_face");
|
|
if (it != cArr->end())
|
|
{
|
|
tPtr->label_font_face = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("label_font_scale");
|
|
if (it != cArr->end())
|
|
{
|
|
tPtr->label_font_scale = atof(it->second.c_str());
|
|
};
|
|
it = cArr->find("label_font_thickness");
|
|
if (it != cArr->end())
|
|
{
|
|
tPtr->label_font_thickness = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("label_line_type");
|
|
if (it != cArr->end())
|
|
{
|
|
tPtr->label_line_type = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("label_transperant");
|
|
if (it != cArr->end())
|
|
{
|
|
tPtr->label_transperant = (bool) atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("show_logo");
|
|
if (it != cArr->end())
|
|
{
|
|
tPtr->show_logo = (bool) atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("logo_w");
|
|
if (it != cArr->end())
|
|
{
|
|
tPtr->logo_w = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("logo_h");
|
|
if (it != cArr->end())
|
|
{
|
|
tPtr->logo_h = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("logo_x");
|
|
if (it != cArr->end())
|
|
{
|
|
tPtr->logo_x = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("logo_y");
|
|
if (it != cArr->end())
|
|
{
|
|
tPtr->logo_y = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("logo_md5");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(tPtr->logo_md5, it->second.c_str(), 32);
|
|
tPtr->logo_md5[32] = (char) 0;
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tPtr;
|
|
}
|
|
|
|
DBC_MEDIA_STREAM_DATA * sqliteDBC::getMediaStreamData(uint32_t ID)
|
|
{
|
|
DBC_MEDIA_STREAM_DATA * tVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT * FROM media_streams WHERE `id`=%d", ID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
tVal = (DBC_MEDIA_STREAM_DATA *) malloc(sizeof(DBC_MEDIA_STREAM_DATA));
|
|
if (tVal != NULL)
|
|
{
|
|
memset(tVal, 0, sizeof(DBC_MEDIA_STREAM_DATA));
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
tVal->id = ID;
|
|
it = cArr->find("source_id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->source_id = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("source_type");
|
|
if (it != cArr->end())
|
|
{
|
|
sprintf(tVal->source_type, it->second.c_str());
|
|
};
|
|
it = cArr->find("valid");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->valid = (bool) atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("token");
|
|
if (it != cArr->end())
|
|
{
|
|
sprintf(tVal->token, it->second.c_str());
|
|
};
|
|
it = cArr->find("img_width");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->width = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("img_height");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->height = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("fps");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->fps = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("compression_type");
|
|
if (it != cArr->end())
|
|
{
|
|
sprintf(tVal->c_type, it->second.c_str());
|
|
};
|
|
it = cArr->find("mrl_proto");
|
|
if (it != cArr->end())
|
|
{
|
|
sprintf(tVal->mrl_proto, it->second.c_str());
|
|
};
|
|
it = cArr->find("mrl_port");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->mrl_port = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("mrl");
|
|
if (it != cArr->end())
|
|
{
|
|
sprintf(tVal->mrl, it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
uint32_t sqliteDBC::getMediaStreamID(uint32_t source_id, CSTR token)
|
|
{
|
|
uint32_t RetVal = 0;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT `id` FROM `media_streams` WHERE `source_id`=%d AND `token`='%s'", source_id, token);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("id");
|
|
if (it != cArr->end())
|
|
{
|
|
RetVal = atoi(it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return RetVal;
|
|
}
|
|
|
|
DBC_MODEM_MANAGER_DATA * sqliteDBC::getModemManagerData(uint32_t ID)
|
|
{
|
|
DBC_MODEM_MANAGER_DATA * tVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT * FROM `module_modem` WHERE `id`=%d", ID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
tVal = (DBC_MODEM_MANAGER_DATA *) malloc(sizeof(DBC_MODEM_MANAGER_DATA));
|
|
if (tVal != NULL)
|
|
{
|
|
memset(tVal, 0, sizeof(DBC_MODEM_MANAGER_DATA));
|
|
tVal->id = ID;
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("modem_id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->modem_id = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("evt_mode");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->evt_mode = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("time_window");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->time_window = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("sms_enabled");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->sms_enabled = (bool) atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("call_enabled");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->call_enabled = (bool) atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("call_hangup_wait");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->call_hangup_wait = atoi(it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
DBC_MODEM_PHONEBOOK_RECORD * sqliteDBC::getModemPhonebookRecord(uint32_t ID)
|
|
{
|
|
DBC_MODEM_PHONEBOOK_RECORD * tVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT * FROM `module_modem_phonebook` WHERE `id`=%d", ID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
tVal = (DBC_MODEM_PHONEBOOK_RECORD *) malloc(sizeof(DBC_MODEM_PHONEBOOK_RECORD));
|
|
if (tVal != NULL)
|
|
{
|
|
memset(tVal, 0, sizeof(DBC_MODEM_PHONEBOOK_RECORD));
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->id = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("number");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(tVal->number, it->second.c_str(), 63);
|
|
tVal->number[63] = (char) 0;
|
|
};
|
|
it = cArr->find("mode");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->mode = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("trig_special");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->trigger_special = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("label");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(tVal->label, it->second.c_str(), 63);
|
|
tVal->label[63] = (char) 0;
|
|
};
|
|
it = cArr->find("custom_msg");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(tVal->custom_msg, it->second.c_str(), 127);
|
|
tVal->custom_msg[127] = (char) 0;
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
DBC_MODULE_DATA * sqliteDBC::getModuleData(uint32_t ID)
|
|
{
|
|
DBC_MODULE_DATA * tVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT * FROM modules WHERE `id`=%d", ID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
tVal = (DBC_MODULE_DATA *) malloc(sizeof(DBC_MODULE_DATA));
|
|
if (tVal != NULL)
|
|
{
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->module_id = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("aux_id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->aux_id = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("type");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->type = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("enabled");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->enabled = (bool) atoi(it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
DBC_LRF_INI * sqliteDBC::getINIData(uint32_t lrfID)
|
|
{
|
|
DBC_LRF_INI * tVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT * FROM `lrf_ini_settings` WHERE `sensor_id`=%d", lrfID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
tVal = (DBC_LRF_INI *) malloc(sizeof(DBC_LRF_INI));
|
|
if (tVal != NULL)
|
|
{
|
|
memset(tVal, 0, sizeof(DBC_LRF_INI));
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("AUTORESET_ENABLE");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->_AUTO_RESET_ENABLE = (bool) atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("AUTORESET_INTERLEAVE");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->_AUTO_RESET_INTERLEAVE = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("AUTORESET_TIMEOUT");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->_AUTO_RESET_TIMEOUT = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("BOARD_TEMPERATURE");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->_BOARD_TEMPERATURE = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("BOARD_ZEROSHIFT");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->_BOARD_ZEROSHIFT = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("BOARD_SPEED");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->_BOARD_SPEED = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("RUN_DIR");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->_RUN_DIR = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("NO_BLACK_TARGETS");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->_NO_BLACK_TARGETS = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("JUST_MOVING_TARGETS");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->_JUST_MOVING_TARGETS = (bool) atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("JUST_MOVING_RADIAL");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->_JUST_MOVING_RADIAL = (bool) atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("JUST_MOVING_DISTANCE");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->_JUST_MOVING_DISTANCE = (bool) atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("FREEZ_FIRST_TH");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->_FREEZ_FIRST_TH = (bool) atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("SAVE_FIRST_TH");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->_SAVE_FIRST_TH = (bool) atoi(it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
bool sqliteDBC::getEventSessionStatus()
|
|
{
|
|
bool rv = false;
|
|
if (m_bRepIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
// Since Unimodule -> no need to check NodeID
|
|
// sprintf( tQBuf, "SELECT `evt_type` FROM `events` WHERE `node_id`=%d AND ( `evt_type`=%d OR `evt_type`=%d OR `evt_type`=%d ) ORDER BY `ts` DESC, `ts_ms` DESC LIMIT 1", nodeID, EVT_LRF_START_SESSION, EVT_LRF_END_SESSION_MA,
|
|
// EVT_LRF_END_SESSION_TO );
|
|
sprintf(tQBuf, "SELECT `evt_type` FROM `events` WHERE `evt_type`=%d OR `evt_type`=%d OR `evt_type`=%d ORDER BY `ts` DESC, `ts_ms` DESC LIMIT 1", EVT_LRF_START_SESSION, EVT_LRF_END_SESSION_MA, EVT_LRF_END_SESSION_TO);
|
|
#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("evt_type");
|
|
if (it != cArr->end())
|
|
{
|
|
if (atoi(it->second.c_str()) == EVT_LRF_START_SESSION)
|
|
{
|
|
rv = true;
|
|
}
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return rv;
|
|
}
|
|
|
|
/*
|
|
* The Last TS is from the current report (as latest)
|
|
*/
|
|
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;
|
|
}
|
|
|
|
/*
|
|
* The first TS is generaly must show a DAY of first registered event so TS fetched
|
|
* from general statistics
|
|
*/
|
|
uint32_t sqliteDBC::getFirstEventTS()
|
|
{
|
|
uint32_t rv = 0;
|
|
if (m_bStaIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT `year`,`month`,`day` FROM `days` ORDER BY `year`,`month`,`day` LIMIT 1");
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStatistics->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
REPORT_DIRINFO RDF;// = {0};
|
|
memset(&RDF, 0, sizeof(REPORT_DIRINFO));
|
|
Assoc * cArr;
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("year");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(RDF.YEAR, it->second.c_str(), 4);
|
|
};
|
|
it = cArr->find("month");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(RDF.MONTH, it->second.c_str(), 2);
|
|
};
|
|
it = cArr->find("day");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(RDF.DAY, it->second.c_str(), 2);
|
|
};
|
|
rv = getTsFromRDF(RDF);
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return rv;
|
|
}
|
|
|
|
bool sqliteDBC::deleteReportDate(uint32_t ts)
|
|
{
|
|
if (ts)
|
|
{
|
|
REPORT_DIRINFO tRDF;// = {0};
|
|
fillRDF(ts, tRDF);
|
|
LOG("Delete RDF Dir");
|
|
if (deleteRDFDir(m_pDbReportBase, tRDF))
|
|
{
|
|
LOG("Dir Deleted OK");
|
|
return deleteReportStat(tRDF);
|
|
};
|
|
};
|
|
return false;
|
|
}
|
|
|
|
DBC_LRF_DATA * sqliteDBC::getLRFData(uint32_t ID)
|
|
{
|
|
DBC_LRF_DATA * tVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT * FROM lrf_sensors WHERE `id`=%d", ID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
tVal = (DBC_LRF_DATA *) malloc(sizeof(DBC_LRF_DATA));
|
|
if (tVal != NULL)
|
|
{
|
|
memset(tVal, 0, sizeof(DBC_LRF_DATA));
|
|
Assoc::iterator it;
|
|
tVal->id = ID;
|
|
cArr = result->at(0);
|
|
it = cArr->find("data_status");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->data_status = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("serial");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(tVal->serial, it->second.c_str(), sizeof(tVal->serial) - 1);
|
|
tVal->serial[sizeof(tVal->serial) - 1] = (char) 0;
|
|
};
|
|
it = cArr->find("version");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(tVal->version, it->second.c_str(), sizeof(tVal->version) - 1);
|
|
tVal->version[sizeof(tVal->version) - 1] = (char) 0;
|
|
};
|
|
it = cArr->find("x");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->x = atof(it->second.c_str());
|
|
};
|
|
it = cArr->find("y");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->y = atof(it->second.c_str());
|
|
};
|
|
it = cArr->find("z");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->z = atof(it->second.c_str());
|
|
};
|
|
it = cArr->find("x_rot");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->x_rot = atof(it->second.c_str());
|
|
};
|
|
it = cArr->find("y_rot");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->y_rot = atof(it->second.c_str());
|
|
};
|
|
it = cArr->find("z_rot");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->z_rot = atof(it->second.c_str());
|
|
};
|
|
it = cArr->find("uart_id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->uart_id = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("device_id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->device_id = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("ip");
|
|
if (it != cArr->end())
|
|
{
|
|
sprintf(tVal->master_host, it->second.c_str());
|
|
};
|
|
it = cArr->find("aux_ip");
|
|
if (it != cArr->end())
|
|
{
|
|
sprintf(tVal->slave_host, it->second.c_str());
|
|
};
|
|
it = cArr->find("port");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->master_port = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("aux_port");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->slave_port = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("auto_draw");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->auto_draw = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("filter_id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->filter_id = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("enabled_lrf");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->enabled_lrf = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("max_range");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->max_range = atof(it->second.c_str());
|
|
};
|
|
it = cArr->find("base_shift");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->base_shift = atoi(it->second.c_str());
|
|
};
|
|
// it = cArr->find("mirror_shift");
|
|
// if( it != cArr->end() ){
|
|
// tVal->mirror_shift = atoi( it->second.c_str() );
|
|
// };
|
|
it = cArr->find("detection_profile_id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->detection_profile_id = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("prefered_camera_id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->prefered_camera_id = atoi(it->second.c_str());
|
|
};
|
|
/*
|
|
it = cArr->find("draw_lrf_id");
|
|
if( it != cArr->end() ){
|
|
tVal->draw_lrf_id = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("width_table_id");
|
|
if( it != cArr->end() ){
|
|
tVal->width_table_id = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("zoom_table_id");
|
|
if( it != cArr->end() ){
|
|
tVal->zoom_table_id = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("embd_cam");
|
|
if( it != cArr->end() ){
|
|
tVal->embd_cam = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("embd_cam_auto");
|
|
if( it != cArr->end() ){
|
|
tVal->embd_cam_auto = (bool)atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("embd_dc");
|
|
if( it != cArr->end() ){
|
|
tVal->embd_dc = atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("autoreset");
|
|
if( it != cArr->end() ){
|
|
tVal->autoreset = (bool)atoi( it->second.c_str() );
|
|
};
|
|
it = cArr->find("force_settings");
|
|
if( it != cArr->end() ){
|
|
tVal->force_settings = (bool)atoi( it->second.c_str() );
|
|
};
|
|
*/
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
PLGS_2D_PARAMETERS sqliteDBC::getLRFDetectionProfile(uint32_t lrfID, uint8_t profileID, bool master)
|
|
{
|
|
PLGS_2D_PARAMETERS retVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT * FROM `lrf_detection_profiles` WHERE `aux_id`=%d AND `profile_id`=%d AND `master`=%d", lrfID, profileID, (master) ? 1 : 0);
|
|
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->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;
|
|
}
|
|
|
|
RELAY_PARAMETERS * sqliteDBC::getLRFDryContact(uint32_t lrfID)
|
|
{
|
|
RELAY_PARAMETERS * retVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT `dc_auto`, `dc_no`, `dc_window` FROM `lrf_sensors` WHERE `id`=%d", lrfID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
retVal = (RELAY_PARAMETERS *) malloc(sizeof(RELAY_PARAMETERS));
|
|
if (retVal)
|
|
{
|
|
Assoc * cArr;
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("dc_auto");
|
|
if (it != cArr->end())
|
|
{
|
|
retVal->bAuto = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("dc_no");
|
|
if (it != cArr->end())
|
|
{
|
|
retVal->bNormallyClose = (atoi(it->second.c_str()) == 0);
|
|
};
|
|
it = cArr->find("dc_window");
|
|
if (it != cArr->end())
|
|
{
|
|
retVal->nAutoDelay = atoi(it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return retVal;
|
|
}
|
|
|
|
uint8_t sqliteDBC::getLRFDataStatus(uint32_t ID)
|
|
{
|
|
uint8_t RetVal = 0;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT `data_status` FROM `lrf_sensors` WHERE `id`=%d", ID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("data_status");
|
|
if (it != cArr->end())
|
|
{
|
|
RetVal = atoi(it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return RetVal;
|
|
}
|
|
|
|
uint32_t sqliteDBC::getLRFMaskID(uint32_t deviceID, uint8_t lrfID, uint8_t layer)
|
|
{
|
|
uint32_t RetVal = 0;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT `id` FROM `lrf_masks` WHERE `sensor_id`=%d AND `lrf_id`=%d AND `layer`=%d ", deviceID, lrfID, layer);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("id");
|
|
if (it != cArr->end())
|
|
{
|
|
RetVal = atoi(it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return RetVal;
|
|
}
|
|
|
|
uint32_t sqliteDBC::getLRFMaskPolygoneID(uint32_t maskID, uint8_t vertecID)
|
|
{
|
|
uint32_t RetVal = 0;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT `id` FROM `lrf_mask_vertexes` WHERE `mask_id`=%d AND `vertex_id`=%d", maskID, vertecID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("id");
|
|
if (it != cArr->end())
|
|
{
|
|
RetVal = atoi(it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return RetVal;
|
|
}
|
|
|
|
uint8_t sqliteDBC::getLRFMasksStatus(uint32_t deviceID)
|
|
{
|
|
uint8_t RetVal = 0;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT `layer` FROM `lrf_masks` WHERE `sensor_id`=%d AND `status`='E'", deviceID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
Assoc::iterator it;
|
|
for (size_t i = 0; i < result->size(); i++)
|
|
{
|
|
cArr = result->at(i);
|
|
it = cArr->find("layer");
|
|
if (it != cArr->end())
|
|
{
|
|
RetVal |= (1 << atoi(it->second.c_str()));
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return RetVal;
|
|
}
|
|
|
|
DBC_LRF_UPLOAD_DATA * sqliteDBC::getLRFUploadData(uint32_t upID)
|
|
{
|
|
DBC_LRF_UPLOAD_DATA * RetVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT * FROM `lrf_uploads` WHERE `id`=%d", upID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
RetVal = (DBC_LRF_UPLOAD_DATA *) malloc(sizeof(DBC_LRF_UPLOAD_DATA));
|
|
if (RetVal != NULL)
|
|
{
|
|
memset(RetVal, 0, sizeof(DBC_LRF_UPLOAD_DATA));
|
|
Assoc::iterator it;
|
|
RetVal->id = upID;
|
|
cArr = result->at(0);
|
|
it = cArr->find("md5");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(RetVal->md5, it->second.c_str(), 32);
|
|
};
|
|
it = cArr->find("file");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(RetVal->fname, it->second.c_str(), 16);
|
|
};
|
|
it = cArr->find("issue_reset");
|
|
if (it != cArr->end())
|
|
{
|
|
RetVal->transfer_mode = atoi(it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return RetVal;
|
|
}
|
|
|
|
DBC_WIDTH_TABLE * sqliteDBC::getLRFWidthTable(uint32_t lrfID)
|
|
{
|
|
DBC_WIDTH_TABLE * retVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
retVal = (DBC_WIDTH_TABLE *) malloc(sizeof(DBC_WIDTH_TABLE));
|
|
if (retVal)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT `range_k`, `width_k` FROM `lrf_detection_width_tables` WHERE `aux_id`=%d ORDER BY `range_k`", lrfID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
memset(retVal, 0, sizeof(DBC_WIDTH_TABLE));
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
retVal->count = result->size();
|
|
retVal->wt_records = (DBC_WT_RECORD *) calloc(retVal->count, sizeof(DBC_WT_RECORD));
|
|
if (retVal->wt_records)
|
|
{
|
|
Assoc * cArr;
|
|
Assoc::iterator it;
|
|
for (int i = 0; i < retVal->count; i++)
|
|
{
|
|
cArr = result->at(i);
|
|
it = cArr->find("range_k");
|
|
if (it != cArr->end())
|
|
{
|
|
retVal->wt_records[i].rangePercent = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("width_k");
|
|
if (it != cArr->end())
|
|
{
|
|
retVal->wt_records[i].widthPercent = atoi(it->second.c_str());
|
|
};
|
|
};
|
|
}
|
|
else
|
|
{
|
|
// retVal->count = 0;
|
|
LOG_ERROR("No Memory To create WT Record!");
|
|
free(retVal);
|
|
retVal = NULL;
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
}
|
|
else
|
|
{
|
|
LOG_ERROR("No Memory To create WT!");
|
|
};
|
|
};
|
|
return retVal;
|
|
}
|
|
|
|
uint32_t sqliteDBC::getNodeAuxParam(uint32_t NodeID)
|
|
{
|
|
uint32_t retVal = 0;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT `aux_parameter` FROM `nodes` WHERE `id`=%d", NodeID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("aux_parameter");
|
|
if (it != cArr->end())
|
|
{
|
|
retVal = atoi(it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return retVal;
|
|
}
|
|
|
|
DBC_NODE_DATA * sqliteDBC::getNodeData(uint32_t ID)
|
|
{
|
|
DBC_NODE_DATA * tVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT * FROM `nodes` WHERE `id`=%d", ID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
tVal = (DBC_NODE_DATA *) malloc(sizeof(DBC_NODE_DATA));
|
|
if (tVal != NULL)
|
|
{
|
|
memset(tVal, 0, sizeof(DBC_NODE_DATA));
|
|
Assoc::iterator it;
|
|
tVal->node_id = ID;
|
|
cArr = result->at(0);
|
|
it = cArr->find("type");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->type = /*(NODE_TYPE)*/ atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("aux_id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->aux_id = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("aux_parameter");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->aux_parameter = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("online");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->online = (bool) atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("enable");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->enabled = (bool) atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("name");
|
|
if (it != cArr->end())
|
|
{
|
|
sprintf(tVal->name, it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
uint32_t sqliteDBC::getNodeIdByTypeAndAux(uint8_t type, uint32_t aux_id)
|
|
{
|
|
uint32_t retVal = 0;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT `id` FROM `nodes` WHERE `type`=%d AND `aux_id`=%d", type, aux_id);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("id");
|
|
if (it != cArr->end())
|
|
{
|
|
retVal = atoi(it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return retVal;
|
|
}
|
|
|
|
CSTR sqliteDBC::getNodeName(uint32_t NodeID)
|
|
{
|
|
CSTR retVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT `name` FROM `nodes` WHERE `id`=%d", NodeID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("name");
|
|
if (it != cArr->end())
|
|
{
|
|
retVal = strdup(it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return retVal;
|
|
}
|
|
|
|
DBC_NET_IF_DATA * sqliteDBC::getNIF_Data(uint32_t nif_id)
|
|
{
|
|
DBC_NET_IF_DATA * tVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT `type`, `mode`, `device_name`, `mac`, `aux_id` FROM `network_interfaces` WHERE `id`=%d", nif_id);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
tVal = (DBC_NET_IF_DATA *) malloc(sizeof(DBC_NET_IF_DATA));
|
|
if (tVal != NULL)
|
|
{
|
|
Assoc::iterator it;
|
|
tVal->id = nif_id;
|
|
cArr = result->at(0);
|
|
it = cArr->find("type");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->type = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("mode");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->mode = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("device_name");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(tVal->device_name, it->second.c_str(), 11);
|
|
tVal->device_name[10] = (char) 0;
|
|
};
|
|
it = cArr->find("mac");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(tVal->mac, it->second.c_str(), 33);
|
|
tVal->mac[32] = (char) 0;
|
|
};
|
|
it = cArr->find("aux_id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->aux_id = atoi(it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
uint32_t sqliteDBC::getNIF_ID(CSTR key)
|
|
{
|
|
uint32_t tVal = 0;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT id FROM `network_interfaces` WHERE `key`='%s'", key);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal = atoi(it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
uint32_t sqliteDBC::getNIF_IDbyDevice(CSTR device)
|
|
{
|
|
uint32_t tVal = 0;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT id FROM `network_interfaces` WHERE `device_name`='%s'", device);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal = atoi(it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
DBC_NETWORK_DATA * sqliteDBC::getNetworkData(uint32_t net_id)
|
|
{
|
|
DBC_NETWORK_DATA * tVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT * FROM `networks` WHERE `id`=%d", net_id);
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
tVal = (DBC_NETWORK_DATA *) malloc(sizeof(DBC_NETWORK_DATA));
|
|
if (tVal)
|
|
{
|
|
Assoc * cArr;
|
|
Assoc::iterator it;
|
|
memset(tVal, 0, sizeof(DBC_NETWORK_DATA));
|
|
tVal->id = net_id;
|
|
cArr = result->at(0);
|
|
it = cArr->find("nif_id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->nif_id = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("type");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->type = (NETWORK_TYPE) atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("address");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(tVal->address, it->second.c_str(), 64);
|
|
tVal->address[64] = (char) 0;
|
|
};
|
|
it = cArr->find("mask");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(tVal->netmask, it->second.c_str(), 64);
|
|
tVal->netmask[64] = (char) 0;
|
|
};
|
|
it = cArr->find("broadcast");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(tVal->broadcast, it->second.c_str(), 64);
|
|
tVal->broadcast[64] = (char) 0;
|
|
};
|
|
it = cArr->find("gateway");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(tVal->gateway, it->second.c_str(), 64);
|
|
tVal->gateway[64] = (char) 0;
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
uint32_t sqliteDBC::getNetworkInfrastructureID(uint32_t nif_id)
|
|
{
|
|
uint32_t tVal = 0;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT id FROM `network_infrastructure` WHERE `nif_id`=%d", nif_id);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal = atoi(it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
TARGET_SEGMENT * sqliteDBC::getRegisteredBubble(uint32_t ID)
|
|
{
|
|
TARGET_SEGMENT * tVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT * FROM `target_bubbles` WHERE `id`=%d", ID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
tVal = (TARGET_SEGMENT *) malloc(sizeof(TARGET_SEGMENT));
|
|
if (tVal)
|
|
{
|
|
Assoc * cArr;
|
|
Assoc::iterator it;
|
|
memset(tVal, 0, sizeof(TARGET_SEGMENT));
|
|
tVal->db_id = ID;
|
|
cArr = result->at(0);
|
|
it = cArr->find("CENTER_X");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->system_center.x = atof(it->second.c_str());
|
|
};
|
|
it = cArr->find("CENTER_Y");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->system_center.y = atof(it->second.c_str());
|
|
};
|
|
it = cArr->find("CENTER_Z");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->system_center.z = atof(it->second.c_str());
|
|
};
|
|
it = cArr->find("BOUNDARY");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->boundary = atof(it->second.c_str());
|
|
};
|
|
it = cArr->find("BLOCK_COUNS");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->hit_count = atoi(it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
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)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT `node_id`, `type`, `aux_id`, `device` FROM `resources` WHERE `id`=%d", ResourceID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
/// @todo Valgrind tells us that tVal is lost and never freed
|
|
tVal = (DBC_RESOURCE_DATA *) malloc(sizeof(DBC_RESOURCE_DATA));
|
|
if (tVal != NULL)
|
|
{
|
|
memset(tVal, 0, sizeof(DBC_RESOURCE_DATA));
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
tVal->id = ResourceID;
|
|
it = cArr->find("node_id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->node_id = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("type");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->type = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("aux_id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->aux_id = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("device");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(tVal->device, it->second.c_str(), 64);
|
|
tVal->device[63] = (char) 0;
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
uint32_t sqliteDBC::getResourceID(uint32_t NodeID, uint8_t type, uint32_t auxID)
|
|
{
|
|
uint32_t RetVal = 0;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
sprintf(tQBuf, "SELECT `id` FROM `resources` WHERE `node_id`=%d AND `type`=%d AND `aux_id`=%d", NodeID, type, auxID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
AAssoc * result;
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("id");
|
|
if (it != cArr->end())
|
|
{
|
|
RetVal = atoi(it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return RetVal;
|
|
}
|
|
|
|
DBC_SITE_DATA * sqliteDBC::getSiteData(uint32_t ID)
|
|
{
|
|
|
|
/** @todo Valgrind is reporting an important memory leak in this method.
|
|
* See these details:
|
|
*
|
|
* ~~~~
|
|
==00:00:04:04.218 26021== 28,304 bytes in 122 blocks are definitely lost in loss record 3,966 of 3,972
|
|
==00:00:04:04.218 26021== at 0x483877F: malloc (vg_replace_malloc.c:307)
|
|
==00:00:04:04.218 26021== by 0x23452A: sqliteDBC::getSiteData(unsigned int) (SQLite_dataBinder.cpp:2981)
|
|
==00:00:04:04.218 26021== by 0x1DA681: mojoKernel::validateReports() (mojoKernel.cpp:1347)
|
|
==00:00:04:04.218 26021== by 0x1D7D16: mojoKernel::m_fThreadProc() (mojoKernel.cpp:511)
|
|
==00:00:04:04.218 26021== by 0x131B54: basicThread::m_fThreadEntryPoint(void*) (basicThread.cpp:62)
|
|
==00:00:04:04.218 26021== by 0x49B7EA6: start_thread (pthread_create.c:477)
|
|
==00:00:04:04.218 26021== by 0x7874ADE: clone (clone.S:95)
|
|
* ~~~~
|
|
*/
|
|
|
|
DBC_SITE_DATA * tVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT * FROM `system_props` WHERE `id`=%d", ID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
tVal = (DBC_SITE_DATA *) malloc(sizeof(DBC_SITE_DATA));
|
|
if (tVal != NULL)
|
|
{
|
|
memset(tVal, 0, sizeof(DBC_SITE_DATA));
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("type");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->account_id = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("name");
|
|
if (it != cArr->end())
|
|
{
|
|
sprintf(tVal->name, it->second.c_str());
|
|
};
|
|
// it = cArr->find("server_ident");
|
|
// if( it != cArr->end() ){
|
|
// sprintf( tVal->ident, it->second.c_str() );
|
|
// };
|
|
it = cArr->find("anchor_lat");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->lat = atof(it->second.c_str());
|
|
};
|
|
it = cArr->find("anchor_lon");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->lon = atof(it->second.c_str());
|
|
};
|
|
it = cArr->find("anchor_alt");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->alt = atof(it->second.c_str());
|
|
};
|
|
it = cArr->find("hemisphere");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->SH = (it->second.c_str()[0] == 'S');
|
|
};
|
|
it = cArr->find("map_id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->map_id = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("local_binding");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->local_binding = (bool) atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("work_mode");
|
|
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("preserve_empty");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->preserve_empty = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("remote_ip");
|
|
if (it != cArr->end())
|
|
{
|
|
sprintf(tVal->remote_ip, it->second.c_str());
|
|
};
|
|
it = cArr->find("remote_port");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->remote_port = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("remote_backup_ip");
|
|
if (it != cArr->end())
|
|
{
|
|
sprintf(tVal->remote_backup_ip, it->second.c_str());
|
|
};
|
|
it = cArr->find("remote_backup_port");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->remote_port = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("use_remote_server");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->use_remote_server = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("skip_local_report");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->skip_local_report = atoi(it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
uint32_t sqliteDBC::getServerID(CSTR identity)
|
|
{
|
|
uint32_t RetVal = 0;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
sprintf(tQBuf, "SELECT `id` FROM `servers` WHERE `identity`='%s'", identity);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
AAssoc * result;
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("id");
|
|
if (it != cArr->end())
|
|
{
|
|
RetVal = atoi(it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return RetVal;
|
|
}
|
|
|
|
uint32_t sqliteDBC::getServerNode(uint32_t SID)
|
|
{
|
|
uint32_t RetVal = 0;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
sprintf(tQBuf, "SELECT id FROM nodes WHERE `type`=0 AND `aux_id`=%d", SID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
AAssoc * result;
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("id");
|
|
if (it != cArr->end())
|
|
{
|
|
RetVal = atoi(it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return RetVal;
|
|
}
|
|
|
|
DBC_TARGET_FLITER_DATA * sqliteDBC::getTargetFilterData(uint32_t ID)
|
|
{
|
|
DBC_TARGET_FLITER_DATA * tVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT * FROM `target_filters` WHERE `id`=%d", ID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
tVal = (DBC_TARGET_FLITER_DATA *) malloc(sizeof(DBC_TARGET_FLITER_DATA));
|
|
if (tVal != NULL)
|
|
{
|
|
memset(tVal, 0, sizeof(DBC_TARGET_FLITER_DATA));
|
|
Assoc::iterator it;
|
|
tVal->id = ID;
|
|
cArr = result->at(0);
|
|
it = cArr->find("type");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->type = (TARGET_FILTER_TYPE) atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("aux_id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->aux_id = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("enabled");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->enabled = (bool) atoi(it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
TRAIN_FILTER_DATA * sqliteDBC::getTrainFilterData(uint32_t ID)
|
|
{
|
|
TRAIN_FILTER_DATA * tVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT * FROM `target_filter_train` WHERE `id`=%d", ID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
tVal = (TRAIN_FILTER_DATA *) malloc(sizeof(TRAIN_FILTER_DATA));
|
|
if (tVal != NULL)
|
|
{
|
|
memset(tVal, 0, sizeof(TRAIN_FILTER_DATA));
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("UPPER_SENSOR");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->nUpperSensorID = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("LOWER_SENSOR");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->nBottomSensorID = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("TRAIN_DETECT");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->bDetectTrain = (bool) atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("TRAIN_WIDTH");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->nTrainWidth = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("DECISION_TIME");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->nDecisionTime = 1000 * atoi(it->second.c_str());
|
|
};
|
|
// In case Wrong Parameter (less then Second)
|
|
if (tVal->nDecisionTime < 1000)
|
|
{
|
|
tVal->nDecisionTime = 10000;
|
|
};
|
|
it = cArr->find("SUSPECT_TIME");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->nSuspectTime = 1000 * atoi(it->second.c_str());
|
|
};
|
|
// In case Wrong Parameter (less then Second)
|
|
if (tVal->nSuspectTime < 1000)
|
|
{
|
|
tVal->nSuspectTime = 10000;
|
|
};
|
|
it = cArr->find("TRACK_TRAIN");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->bTrackTrain = (bool) atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("AUX_IP");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(tVal->aux_ip, it->second.c_str(), 15);
|
|
};
|
|
it = cArr->find("AUX_PORT");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->aux_port = atoi(it->second.c_str());
|
|
};
|
|
#ifdef EFT_AUTO_RESET_UPPER_SENSOR
|
|
it = cArr->find("UPPER_RESTART");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->nUpperSensorRestartTO = atoi(it->second.c_str()) * 3600; // Hours -> Seconds
|
|
}
|
|
else
|
|
{
|
|
tVal->nUpperSensorRestartTO = 24 * 3600;
|
|
};
|
|
#endif
|
|
#ifdef EFT_MINIMAL_RANGE_SUSPICIOUS
|
|
it = cArr->find("MINIMAL_LEFT_RANGE");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->fLeftMinimalRange = atof(it->second.c_str());
|
|
}
|
|
else
|
|
{
|
|
tVal->fLeftMinimalRange = 0.0;
|
|
};
|
|
it = cArr->find("MINIMAL_RIGHT_RANGE");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->fRightMinimalRange = atof(it->second.c_str());
|
|
}
|
|
else
|
|
{
|
|
tVal->fRightMinimalRange = 0.0;
|
|
};
|
|
#endif
|
|
it = cArr->find("DEBUG");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->bDebugMode = (bool) atoi(it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
bool sqliteDBC::cleanRegisteredBubbles(void)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
sprintf(tQBuf, "DELETE FROM `target_bubbles`");
|
|
return m_pDataStorage->SilentQuery(tQBuf);
|
|
};
|
|
return false;
|
|
}
|
|
|
|
DBC_UART_DATA * sqliteDBC::getUartData(uint32_t UartID)
|
|
{
|
|
DBC_UART_DATA * tVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT * FROM uart_settings WHERE id = %d", UartID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
tVal = (DBC_UART_DATA *) malloc(sizeof(DBC_UART_DATA));
|
|
if (tVal != NULL)
|
|
{
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("type");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->type = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("speed");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->speed = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("mode");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->mode = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("port");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->port = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("path");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(tVal->path, it->second.c_str(), 128);
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
uint32_t sqliteDBC::getUartID(uint32_t NodeID, uint8_t Type, CSTR path)
|
|
{
|
|
uint32_t RetVal = 0;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
sprintf(tQBuf, "SELECT `id` FROM `uart_settings` WHERE `node_id`=%d AND `type`=%d AND `path`='%s' ", NodeID, Type, path);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
AAssoc * result;
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("id");
|
|
if (it != cArr->end())
|
|
{
|
|
RetVal = atoi(it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return RetVal;
|
|
}
|
|
|
|
uint32_t sqliteDBC::getWiFi_ID(uint32_t nif_id)
|
|
{
|
|
uint32_t tVal = 0;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT `id` FROM `wifis` WHERE `nif_id`=%d", nif_id);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal = atoi(it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
DBC_INT_LIST * sqliteDBC::listCameras()
|
|
{
|
|
DBC_INT_LIST * tVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT `id` FROM `cameras` WHERE `status`=3");
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
tVal = new DBC_INT_LIST();
|
|
if (tVal != NULL)
|
|
{
|
|
Assoc::iterator it;
|
|
for (size_t i = 0; i < result->size(); i++)
|
|
{
|
|
cArr = result->at(i);
|
|
it = cArr->find("id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->push_back(atoi(it->second.c_str()));
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
DBC_INT_LIST * sqliteDBC::listCamPresets(uint32_t SETID)
|
|
{
|
|
DBC_INT_LIST * tVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT `id` FROM `cameras_presets` WHERE `preset_id`=%d", SETID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
tVal = new DBC_INT_LIST();
|
|
if (tVal != NULL)
|
|
{
|
|
Assoc::iterator it;
|
|
for (size_t i = 0; i < result->size(); i++)
|
|
{
|
|
cArr = result->at(i);
|
|
it = cArr->find("id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->push_back(atoi(it->second.c_str()));
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
DBC_INT_LIST * sqliteDBC::listFilters(uint32_t ServerID)
|
|
{
|
|
DBC_INT_LIST * tVal = NULL;
|
|
if (ServerID) ServerID = ServerID;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT `id` FROM `target_filters` WHERE `enabled`=1");
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
tVal = new DBC_INT_LIST();
|
|
if (tVal != NULL)
|
|
{
|
|
Assoc::iterator it;
|
|
for (size_t i = 0; i < result->size(); i++)
|
|
{
|
|
cArr = result->at(i);
|
|
it = cArr->find("id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->push_back(atoi(it->second.c_str()));
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
DBC_INT_LIST * sqliteDBC::listLRFSensors()
|
|
{
|
|
DBC_INT_LIST * tVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT `id` FROM `lrf_sensors` WHERE `data_status`>0");
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
tVal = new DBC_INT_LIST();
|
|
if (tVal != NULL)
|
|
{
|
|
Assoc::iterator it;
|
|
for (size_t i = 0; i < result->size(); i++)
|
|
{
|
|
cArr = result->at(i);
|
|
it = cArr->find("id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->push_back(atoi(it->second.c_str()));
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
DBC_INT_LIST * sqliteDBC::listLRFUploads(uint32_t deviceID)
|
|
{
|
|
DBC_INT_LIST * tVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT `id` FROM `lrf_uploads` WHERE `status`=-1 AND `sensor_id`=%d", deviceID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
tVal = new DBC_INT_LIST();
|
|
if (tVal != NULL)
|
|
{
|
|
Assoc::iterator it;
|
|
for (size_t i = 0; i < result->size(); i++)
|
|
{
|
|
cArr = result->at(i);
|
|
it = cArr->find("id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->push_back(atoi(it->second.c_str()));
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
DBC_INT_LIST * sqliteDBC::listMediaStreams(uint32_t SiteId, uint8_t listMode)
|
|
{
|
|
DBC_INT_LIST * tVal = NULL;
|
|
if ( SiteId ) SiteId = SiteId;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
switch (listMode)
|
|
{
|
|
case LIST_VALID_RECORDS : sprintf(tQBuf, "SELECT `ms`.`id` FROM `nodes` `nd` LEFT JOIN `media_streams` `ms` ON (`ms`.`id`=`nd`.`aux_parameter`) WHERE `nd`.`type` IN (10,11,12,13,14,15) AND `ms`.`valid`=1 AND `nd`.`online`=1"); break;
|
|
case LIST_INVALID_RECORDS: sprintf(tQBuf, "SELECT `ms`.`id` FROM `nodes` `nd` LEFT JOIN `media_streams` `ms` ON (`ms`.`id`=`nd`.`aux_parameter`) WHERE `nd`.`type` IN (10,11,12,13,14,15) AND `ms`.`valid`=1 AND `nd`.`online`=0"); break;
|
|
default : sprintf(tQBuf, "SELECT `ms`.`id` FROM `nodes` `nd` LEFT JOIN `media_streams` `ms` ON (`ms`.`id`=`nd`.`aux_parameter`) WHERE `nd`.`type` IN (10,11,12,13,14,15) AND `ms`.`valid`=1");
|
|
};
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
tVal = new DBC_INT_LIST();
|
|
if (tVal != NULL)
|
|
{
|
|
Assoc::iterator it;
|
|
for (size_t i = 0; i < result->size(); i++)
|
|
{
|
|
cArr = result->at(i);
|
|
it = cArr->find("id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->push_back(atoi(it->second.c_str()));
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
DBC_INT_LIST * sqliteDBC::listModules()
|
|
{
|
|
DBC_INT_LIST * tVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
AAssoc * result;
|
|
result = m_pDataStorage->Query("SELECT `id` FROM `modules` WHERE `enabled`=1");
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
tVal = new DBC_INT_LIST();
|
|
if (tVal != NULL)
|
|
{
|
|
Assoc::iterator it;
|
|
for (size_t i = 0; i < result->size(); i++)
|
|
{
|
|
cArr = result->at(i);
|
|
it = cArr->find("id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->push_back(atoi(it->second.c_str()));
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
DBC_INT_LIST * sqliteDBC::listNetworks(uint32_t nif_id)
|
|
{
|
|
DBC_INT_LIST * tVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT `id` FROM `networks` WHERE `nif_id`=%d", nif_id);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
tVal = new DBC_INT_LIST();
|
|
if (tVal != NULL)
|
|
{
|
|
Assoc::iterator it;
|
|
for (size_t i = 0; i < result->size(); i++)
|
|
{
|
|
cArr = result->at(i);
|
|
it = cArr->find("id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->push_back(atoi(it->second.c_str()));
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
DBC_INT_LIST * sqliteDBC::listNewModules(DBC_INT_LIST * old_ids)
|
|
{
|
|
DBC_INT_LIST * tVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tParam[CTEXT];
|
|
// memset( tParam, 0, CTEXT );
|
|
sprintf(tParam, "0");
|
|
if (old_ids != NULL)
|
|
{
|
|
char tBuffer[1024];
|
|
for (size_t i = 0; i < old_ids->size(); i++)
|
|
{
|
|
sprintf(tBuffer, "%s,%d", tParam, old_ids->at(i));
|
|
strncpy(tParam, tBuffer, CTEXT);
|
|
};
|
|
};
|
|
char tQBuf[2048];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT `id` FROM `modules` WHERE `enabled`=1 AND `id` NOT IN (%s)", tParam);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
tVal = new DBC_INT_LIST();
|
|
if (tVal != NULL)
|
|
{
|
|
Assoc::iterator it;
|
|
for (size_t i = 0; i < result->size(); i++)
|
|
{
|
|
cArr = result->at(i);
|
|
it = cArr->find("id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->push_back(atoi(it->second.c_str()));
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
DBC_INT_LIST * sqliteDBC::listNewNodes(DBC_INT_LIST * old_ids)
|
|
{
|
|
DBC_INT_LIST * tVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tParam[CTEXT];
|
|
// memset( tParam, 0, CTEXT );
|
|
sprintf(tParam, "0");
|
|
if (old_ids != NULL)
|
|
{
|
|
char tBuffer[1024];
|
|
for (size_t i = 0; i < old_ids->size(); i++)
|
|
{
|
|
sprintf(tBuffer, "%s,%d", tParam, old_ids->at(i));
|
|
strncpy(tParam, tBuffer, CTEXT);
|
|
};
|
|
};
|
|
char tQBuf[2048];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT id FROM nodes WHERE `type` > 0 AND `enable`=1 AND `id` NOT IN(%s)", tParam);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
tVal = new DBC_INT_LIST();
|
|
if (tVal != NULL)
|
|
{
|
|
Assoc::iterator it;
|
|
for (size_t i = 0; i < result->size(); i++)
|
|
{
|
|
cArr = result->at(i);
|
|
it = cArr->find("id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->push_back(atoi(it->second.c_str()));
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
DBC_INT_LIST * sqliteDBC::listNodes(bool all)
|
|
{
|
|
DBC_INT_LIST * tVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[1024];
|
|
AAssoc * result;
|
|
if (all)
|
|
{
|
|
sprintf(tQBuf, "SELECT `id` FROM `nodes`");
|
|
}
|
|
else
|
|
{
|
|
sprintf(tQBuf, "SELECT `id` FROM `nodes` WHERE `type` > 0 AND `enable`=1");
|
|
};
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
tVal = new DBC_INT_LIST();
|
|
if (tVal != NULL)
|
|
{
|
|
Assoc::iterator it;
|
|
for (size_t i = 0; i < result->size(); i++)
|
|
{
|
|
cArr = result->at(i);
|
|
it = cArr->find("id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->push_back(atoi(it->second.c_str()));
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
DBC_INT_LIST * sqliteDBC::listNodeFilters(uint32_t NodeID)
|
|
{
|
|
DBC_INT_LIST * tVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[1024];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT `filter_id` FROM `node_target_filters` WHERE `node_id`=%d ORDER BY `order` ASC", NodeID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
tVal = new DBC_INT_LIST();
|
|
if (tVal != NULL)
|
|
{
|
|
Assoc::iterator it;
|
|
for (size_t i = 0; i < result->size(); i++)
|
|
{
|
|
cArr = result->at(i);
|
|
it = cArr->find("filter_id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->push_back(atoi(it->second.c_str()));
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
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 (size_t 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 (size_t 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::listPhonebook()
|
|
{
|
|
DBC_INT_LIST * tVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT `id` FROM `module_modem_phonebook`");
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
tVal = new DBC_INT_LIST();
|
|
if (tVal != NULL)
|
|
{
|
|
Assoc::iterator it;
|
|
for (size_t i = 0; i < result->size(); i++)
|
|
{
|
|
cArr = result->at(i);
|
|
it = cArr->find("id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->push_back(atoi(it->second.c_str()));
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
DBC_INT_LIST * sqliteDBC::listFrozenBubbles(uint8_t cc)
|
|
{
|
|
DBC_INT_LIST * tVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
if (cc)
|
|
{
|
|
sprintf(tQBuf, "SELECT `id` FROM `target_bubbles` WHERE `BLOCK_COUNS`>%d", cc);
|
|
}
|
|
else
|
|
{
|
|
sprintf(tQBuf, "SELECT `id` FROM `target_bubbles` WHERE `BLOCKED`=1");
|
|
}
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
tVal = new DBC_INT_LIST();
|
|
if (tVal != NULL)
|
|
{
|
|
Assoc::iterator it;
|
|
for (size_t i = 0; i < result->size(); i++)
|
|
{
|
|
cArr = result->at(i);
|
|
it = cArr->find("id");
|
|
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)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
if (NodeID == 0)
|
|
{
|
|
NodeID = m_nServerNodeID;
|
|
}
|
|
sprintf(tQBuf, "SELECT `id` FROM `resources` WHERE `node_id`=%d", NodeID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
tVal = new DBC_INT_LIST();
|
|
if (tVal != NULL)
|
|
{
|
|
Assoc::iterator it;
|
|
for (size_t i = 0; i < result->size(); i++)
|
|
{
|
|
cArr = result->at(i);
|
|
it = cArr->find("id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->push_back(atoi(it->second.c_str()));
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
bool sqliteDBC::pushMemCMD(uint32_t NODE_ID, uint8_t CMD, CSTR DATA)
|
|
{
|
|
if (m_bMemIsConnected)
|
|
{
|
|
char QS[MAX_PATH];
|
|
sprintf(QS, "INSERT INTO `nodes_qcq`(`node_id`,`cmd`,`status`,`parameter`) VALUES(%d,%d,0,%s)", NODE_ID, CMD, DATA);
|
|
#ifdef DEBUG_ALL
|
|
LOG(QS);
|
|
#endif
|
|
m_pDataMemory->SilentQuery(QS);
|
|
return true;
|
|
};
|
|
return false;
|
|
}
|
|
|
|
void sqliteDBC::registerServer(uint32_t SiteID, CSTR identity, int PID, uint32_t * ServID, uint32_t * ServNode)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
m_nSiteID = SiteID;
|
|
|
|
char tQBuf[MAX_PATH_LEN];
|
|
#ifdef DEFAULT_SERVER_ID
|
|
sprintf(tQBuf, "INSERT INTO `servers`(`id`,`site_id`,`identity`,`version_string`) VALUES (%d,%d,'%s','%s') ON CONFLICT(`id`) DO UPDATE SET `identity`='%s',`version_string`='%s'", DEFAULT_SERVER_ID, SiteID, identity, _BUILD_STRING_, identity,
|
|
_BUILD_STRING_);
|
|
#else
|
|
sprintf(tQBuf, "INSERT INTO `servers`(`site_id`,`identity`,`version_string`) VALUES (%d,'%s','%s') ON CONFLICT(`identity`) DO UPDATE SET `version_string`='%s'", SiteID, identity, _BUILD_STRING_, _BUILD_STRING_);
|
|
#endif
|
|
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
#ifdef DEFAULT_SERVER_ID
|
|
m_nServerID = DEFAULT_SERVER_ID;
|
|
#else
|
|
m_nServerID = getServerID(identity);
|
|
#endif
|
|
*ServID = m_nServerID;
|
|
if (m_nServerID)
|
|
{
|
|
initMemDB(m_nServerID);
|
|
sprintf(tQBuf, "UPDATE `servers` SET `pid`=%d,`ts`=STRFTIME('%%s') WHERE `id`=%d", PID, m_nServerID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataMemory->SilentQuery(tQBuf);
|
|
|
|
sprintf(tQBuf, "INSERT INTO `nodes`(`aux_id`,`type`,`online`,`name`) VALUES (%d, 0,1,'Controller') ON CONFLICT(`type`,`aux_id`) DO UPDATE SET `online`=1", *ServID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_nServerNodeID = (uint32_t) m_pDataStorage->QueryID(tQBuf);
|
|
|
|
if (m_nServerNodeID == 0)
|
|
{
|
|
m_nServerNodeID = getServerNode(m_nServerID);
|
|
};
|
|
*ServNode = m_nServerNodeID;
|
|
// Clenup Nodes and services ...
|
|
sprintf(tQBuf, "UPDATE `nodes` SET `online`=0");
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
sprintf(tQBuf, "UPDATE `cameras` SET `online`=0 WHERE `manual`=0");
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
|
|
sprintf(tQBuf, "UPDATE `media_streams` SET `valid`=0 WHERE `source_id` IN ( SELECT `id` FROM `cameras` WHERE `manual`=0 )");
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
|
|
// sprintf(tQBuf,"UPDATE `cameras` SET `online`=1 WHERE `manual`=1" );
|
|
#ifdef DEBUG_ALL
|
|
// LOG(tQBuf);
|
|
#endif
|
|
// m_pDataStorage->SilentQuery( tQBuf );
|
|
|
|
// sprintf(tQBuf,"UPDATE `media_streams` SET `valid`=1 WHERE `source_id` IN ( SELECT `id` FROM `cameras` WHERE `online`=1 )" );
|
|
#ifdef DEBUG_ALL
|
|
// LOG(tQBuf);
|
|
#endif
|
|
// m_pDataStorage->SilentQuery( tQBuf );
|
|
|
|
// sprintf(tQBuf,"UPDATE `media_server_streams` SET `valid`=0, `online`=0" );
|
|
#ifdef DEBUG_ALL
|
|
// LOG(tQBuf);
|
|
#endif
|
|
// m_pDataStorage->SilentQuery( tQBuf );
|
|
|
|
// cleanResources( tServerNodeID );
|
|
setNodeOnline(m_nServerNodeID);
|
|
};
|
|
};
|
|
}
|
|
|
|
bool sqliteDBC::setLRFDataStatus(uint32_t lrfID, uint8_t ST)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
sprintf(tQBuf, "UPDATE `lrf_sensors` SET `data_status`=%d WHERE `id`=%d", ST, lrfID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
return true;
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool sqliteDBC::setLRFDetectionProfile(uint32_t lrfID, uint8_t profileID)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
sprintf(tQBuf, "UPDATE `lrf_sensors` SET `detection_profile_id`=%d WHERE `id`=%d", profileID, lrfID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
return true;
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool sqliteDBC::setLRFMaskStatus(uint32_t maskID, bool status)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
if (status)
|
|
{
|
|
sprintf(tQBuf, "UPDATE `lrf_masks` SET `status`='E' WHERE `id`=%d", maskID);
|
|
}
|
|
else
|
|
{
|
|
sprintf(tQBuf, "UPDATE `lrf_masks` SET `status`='D' WHERE `id`=%d", maskID);
|
|
};
|
|
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
return true;
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool sqliteDBC::setLRFAltSerial(uint32_t lrfID, CSTR Serial)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
sprintf(tQBuf, "UPDATE `lrf_sensors` SET `alt_serial`='%s' WHERE `id`=%d", Serial, lrfID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
return true;
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool sqliteDBC::setLRFAltVerison(uint32_t lrfID, CSTR version)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
sprintf(tQBuf, "UPDATE `lrf_sensors` SET `alt_version`='%s' WHERE `id`=%d", version, lrfID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
return true;
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool sqliteDBC::setNodeOffline(uint32_t NodeID)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
if (NodeID)
|
|
{
|
|
sprintf(tQBuf, "UPDATE nodes SET `online`=0 WHERE `id` = %d", NodeID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
sprintf(tQBuf, "UPDATE `resources` SET `active`=0 WHERE `node_id` = %d", NodeID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
return true;
|
|
};
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool sqliteDBC::setNodeOnline(uint32_t NodeID, uint8_t status)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
if (NodeID)
|
|
{
|
|
sprintf(tQBuf, "UPDATE `nodes` SET `online`=%d WHERE `id`=%d", status, NodeID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
sprintf(tQBuf, "UPDATE `resources` SET `active`=1 WHERE `node_id`=%d", NodeID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
return true;
|
|
};
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool sqliteDBC::setRessourceActive(uint32_t RessourceID, bool Status)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
if (RessourceID)
|
|
{
|
|
sprintf(tQBuf, "UPDATE `resources` SET `active`=%d WHERE `id`=%d", Status, RessourceID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
return true;
|
|
};
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool sqliteDBC::setStreamValid(uint32_t streamID, bool status)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
if (status)
|
|
{
|
|
sprintf(tQBuf, "UPDATE `media_streams` SET `valid`=1 WHERE `id`=%d", streamID);
|
|
}
|
|
else
|
|
{
|
|
sprintf(tQBuf, "UPDATE `media_streams` SET `valid`=0 WHERE `id`=%d", streamID);
|
|
};
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
return true;
|
|
};
|
|
return false;
|
|
}
|
|
|
|
void sqliteDBC::unregisterServer(void)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
sprintf(tQBuf, "UPDATE `cameras` SET `online`=0");
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
|
|
sprintf(tQBuf, "UPDATE `media_streams` SET `valid`=0");
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
};
|
|
setNodeOffline(m_nServerNodeID);
|
|
}
|
|
|
|
bool sqliteDBC::updateSystemInfo(DBC_SYS_INFO * ptr)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
sprintf(tQBuf, "UPDATE `system_props` SET `os_info`='%s', `hw_info`='%s' WHERE `id`=%d", ptr->OS_INFO, ptr->HW_INFO, m_nSiteID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
return true;
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool sqliteDBC::fillShadow2D(uint32_t ID, SHADOW & SH)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
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);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->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 << SH.pPolygones[idx].bType);
|
|
};
|
|
sprintf(tQBuf, "SELECT * FROM `lrf_mask_vertex_points` WHERE `vertex_id`=%d ORDER BY `id`", SH.pPolygones[idx].m_nDBID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
AAssoc * v_result = m_pDataStorage->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;
|
|
}
|
|
|
|
bool sqliteDBC::getAppDebugMode()
|
|
{
|
|
bool rVal = false;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT `work_mode` FROM `system_props` WHERE `id`=1");
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("work_mode");
|
|
if (it != cArr->end())
|
|
{
|
|
rVal = (bool) atoi(it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return rVal;
|
|
}
|
|
|
|
DBC_ATC_MODULE_DATA * sqliteDBC::getAttentionModuleData( uint32_t id ){
|
|
DBC_ATC_MODULE_DATA * tVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT * FROM `module_attention` WHERE `id`=%d", id);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
tVal = (DBC_ATC_MODULE_DATA *) malloc(sizeof(DBC_ATC_MODULE_DATA));
|
|
if (tVal != NULL)
|
|
{
|
|
memset(tVal, 0, sizeof(DBC_ATC_MODULE_DATA));
|
|
;
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("rest");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->rest_time = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("persist");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->persist_time = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("range");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->attention_zone_range = atof(it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
REST_SETTINGS *sqliteDBC::getBoschData( uint32_t id ){
|
|
REST_SETTINGS * tVal = NULL;
|
|
if (m_bStoIsConnected){
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT * FROM `module_bvms` WHERE `id`=%d", id);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
tVal = (REST_SETTINGS *) malloc(sizeof(REST_SETTINGS));
|
|
if (tVal != NULL)
|
|
{
|
|
memset(tVal, 0, sizeof(REST_SETTINGS));
|
|
;
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("ip");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(tVal->server_ip, it->second.c_str(), 48);
|
|
};
|
|
it = cArr->find("port");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->port = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("api_uri");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(tVal->rest_api, it->second.c_str(), 256);
|
|
};
|
|
it = cArr->find("auth_mode");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->auth_mode = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("access_user");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(tVal->access_user, it->second.c_str(), 48);
|
|
};
|
|
it = cArr->find("access_pass");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(tVal->access_pass, it->second.c_str(), 48);
|
|
};
|
|
it = cArr->find("detection_evt_ena");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->detection_enabled = (bool) atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("detection_evt_id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->detection_src = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("camera_evt_ena");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->camera_enabled = (bool) atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("camera_evt_id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->camera_src = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("use_ssl");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->use_ssl = (bool) atoi(it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
BUBBLE_FILTER_DATA * sqliteDBC::getBubbleFilterData(uint32_t id)
|
|
{
|
|
BUBBLE_FILTER_DATA * tVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT * FROM `target_filter_bubble` WHERE `id`=%d", id);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
tVal = (BUBBLE_FILTER_DATA *) malloc(sizeof(BUBBLE_FILTER_DATA));
|
|
if (tVal != NULL)
|
|
{
|
|
memset(tVal, 0, sizeof(BUBBLE_FILTER_DATA));
|
|
;
|
|
Assoc::iterator it;
|
|
tVal->id = id;
|
|
cArr = result->at(0);
|
|
it = cArr->find("BEGINNING_RANGE");
|
|
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_BUCKET
|
|
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());
|
|
};
|
|
it = cArr->find("T2T");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->t2t = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("PROPOGATE");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->propogate = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("METHOD");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->method = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("ENABLE_EVENT");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->enable_evt = (bool) atoi(it->second.c_str());
|
|
};
|
|
};
|
|
#ifdef BUBBLE_TIME_BUCKET
|
|
if (tVal->bucket_time < BUBBLE_FILTER_MIN_BUCKET_TIME)
|
|
{
|
|
tVal->bucket_time = BUBBLE_FILTER_MIN_BUCKET_TIME;
|
|
}
|
|
#endif
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
DBC_CAM_DATA * sqliteDBC::getCamData(uint32_t ID)
|
|
{
|
|
DBC_CAM_DATA * tVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT * FROM cameras WHERE `id`=%d", ID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
tVal = (DBC_CAM_DATA *) malloc(sizeof(DBC_CAM_DATA));
|
|
if (tVal != NULL)
|
|
{
|
|
memset(tVal, 0, sizeof(DBC_CAM_DATA));
|
|
tVal->id = ID;
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("type");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->type = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("online");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->online = (bool) atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("stream_id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->stream_id = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("hardware");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(tVal->hardware, it->second.c_str(), 32);
|
|
};
|
|
it = cArr->find("name");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(tVal->name, it->second.c_str(), 64);
|
|
};
|
|
it = cArr->find("status");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->status = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("session");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(tVal->session, it->second.c_str(), 32);
|
|
};
|
|
it = cArr->find("protocol");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->protocol = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("protocol_aux");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->protocol_aux = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("uart_id");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->uart_id = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("x");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->x = atof(it->second.c_str());
|
|
};
|
|
it = cArr->find("y");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->y = atof(it->second.c_str());
|
|
};
|
|
it = cArr->find("z");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->z = atof(it->second.c_str());
|
|
};
|
|
it = cArr->find("x_rot");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->x_rot = atof(it->second.c_str());
|
|
};
|
|
it = cArr->find("y_rot");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->y_rot = atof(it->second.c_str());
|
|
};
|
|
it = cArr->find("z_rot");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->z_rot = atof(it->second.c_str());
|
|
};
|
|
it = cArr->find("imager_type");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->imager_type = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("lens_f");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->lens_f = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("ptz_speed_step");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->ptz_speed_step = atof(it->second.c_str());
|
|
};
|
|
it = cArr->find("pan_model");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->pan_model = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("pan_angles");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->pan_angles = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("tilt_model");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->tilt_model = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("tilt_angles");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->tilt_angles = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("zoom_model");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->zoom_model = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("zoom");
|
|
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());
|
|
};
|
|
it = cArr->find("access_login");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(tVal->username, it->second.c_str(), 16);
|
|
};
|
|
it = cArr->find("access_pass");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(tVal->password, it->second.c_str(), 16);
|
|
};
|
|
it = cArr->find("uuid");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(tVal->uuid, it->second.c_str(), 64);
|
|
};
|
|
it = cArr->find("mac");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(tVal->mac, it->second.c_str(), 16);
|
|
};
|
|
it = cArr->find("ip");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(tVal->ip, it->second.c_str(), 16);
|
|
};
|
|
it = cArr->find("port");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->port = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("onvif_access");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(tVal->onvif_access, it->second.c_str(), 5);
|
|
};
|
|
it = cArr->find("onvif_ctrl");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(tVal->onvif_ctrl, it->second.c_str(), 250);
|
|
};
|
|
it = cArr->find("ptz_token");
|
|
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());
|
|
};
|
|
it = cArr->find("auth_mode");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->auth_mode = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("ptz_axel");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->ptz_axel = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("manual");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->manual = (bool) atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("homing_enable");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->homing_enable = (bool) atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("homing_to");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->homing_to = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("home_token");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(tVal->home_token, it->second.c_str(), 32);
|
|
};
|
|
it = cArr->find("eco_ir");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->eco_ir = (bool) atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("prefered_events_only");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->prefered_events_only = (bool) atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("flip_mode");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->flip_mode = atoi(it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
uint32_t sqliteDBC::getCamId(CSTR UUID)
|
|
{
|
|
uint32_t RetVal = 0;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT `id` FROM `cameras` WHERE `uuid`='%s'", UUID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("id");
|
|
if (it != cArr->end())
|
|
{
|
|
RetVal = atoi(it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return RetVal;
|
|
}
|
|
|
|
CAM_PRESET * sqliteDBC::getCamPreset(uint32_t SETID)
|
|
{
|
|
CAM_PRESET * tVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT * FROM `cameras_presets` WHERE `id`=%d", SETID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
tVal = (CAM_PRESET *) malloc(sizeof(CAM_PRESET));
|
|
if (tVal != NULL)
|
|
{
|
|
memset(tVal, 0, sizeof(CAM_PRESET));
|
|
tVal->id = SETID;
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("token");
|
|
if (it != cArr->end())
|
|
{
|
|
strncpy(tVal->token, it->second.c_str(), 2);
|
|
tVal->token[3] = (char) 0;
|
|
};
|
|
it = cArr->find("role");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->role = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("row");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->row = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("column");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->col = atoi(it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
DBC_PRESETS_INFO * sqliteDBC::getCamPresetInfo(uint32_t CamID)
|
|
{
|
|
DBC_PRESETS_INFO * tVal = NULL;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[CTEXT];
|
|
AAssoc * result;
|
|
sprintf(tQBuf, "SELECT * FROM `cameras_preset_sets` WHERE `camera_id`=%d", CamID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
tVal = (DBC_PRESETS_INFO *) malloc(sizeof(DBC_PRESETS_INFO));
|
|
if (tVal != NULL)
|
|
{
|
|
memset(tVal, 0, sizeof(DBC_PRESETS_INFO));
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("maxCount");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->maxCount = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("p_segs");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->gCols = atoi(it->second.c_str());
|
|
};
|
|
it = cArr->find("z_segs");
|
|
if (it != cArr->end())
|
|
{
|
|
tVal->gRows = atoi(it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return tVal;
|
|
}
|
|
|
|
CSTR sqliteDBC::getDataParam(uint8_t pid)
|
|
{
|
|
switch (pid)
|
|
{
|
|
case 0: return strdup(m_pDbFile); break;
|
|
case 1: return strdup(web_access_user); break;
|
|
case 2: return strdup(web_access_group); break;
|
|
};
|
|
return NULL;
|
|
}
|
|
|
|
bool sqliteDBC::updateIPCam(uint32_t CamID, CSTR Addr)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
char tIpBuf[CTEXT];
|
|
char * tPos;
|
|
char * tPos2;
|
|
uint16_t tPort = 0;
|
|
tPos = strstr(Addr, "//");
|
|
if (tPos != NULL)
|
|
{
|
|
tPos2 = strstr(tPos + 2, ":");
|
|
if (tPos2 != NULL)
|
|
{
|
|
//LOG("IP Port Defined!");
|
|
int len;//, len2, len3;
|
|
len = tPos2 - tPos - 2;
|
|
strncpy(tIpBuf, tPos + 2, len);
|
|
tIpBuf[len] = (char) 0;
|
|
tPort = atoi(tPos2 + 1);
|
|
// strncpy( tPath, tPos + 2 + len, CTEXT );
|
|
}
|
|
else
|
|
{
|
|
tPos2 = strstr(tPos + 2, "/");
|
|
if (tPos2 != NULL)
|
|
{
|
|
int len;//, len2, len3;
|
|
len = tPos2 - tPos - 2;
|
|
strncpy(tIpBuf, tPos + 2, len);
|
|
tIpBuf[len] = (char) 0;
|
|
// strncpy( tPath, tPos + 2 + len, CTEXT );
|
|
}
|
|
else
|
|
{
|
|
tPos2 = strstr(tPos + 2, "/");
|
|
//LOG_ERROR("Pos 2 - err");
|
|
tIpBuf[0] = (char) 0;
|
|
};
|
|
};
|
|
}
|
|
else
|
|
{
|
|
//LOG_ERROR("Pos 0 - err");
|
|
tIpBuf[0] = (char) 0;
|
|
};
|
|
if (tPort)
|
|
{
|
|
sprintf(tQBuf, "UPDATE `cameras` SET `online`=1, `onvif_ctrl`='%s', `ip`='%s', `port`=%d WHERE `id`=%d", Addr, tIpBuf, tPort, CamID);
|
|
}
|
|
else
|
|
{
|
|
sprintf(tQBuf, "UPDATE `cameras` SET `online`=1, `onvif_ctrl`='%s', `ip`='%s' WHERE `id`=%d", Addr, tIpBuf, CamID);
|
|
}
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
sprintf(tQBuf, "UPDATE `media_streams` SET `valid`=1 WHERE `source_id`=%d", CamID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
return true;
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool sqliteDBC::updateCamRange(uint32_t camID, float range)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
sprintf(tQBuf, "UPDATE `cameras` SET `max_range`=%.3f WHERE `id`=%d", range, camID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
return true;
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool sqliteDBC::updateCamOnlineStatus(uint32_t camID, bool online)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
if (online)
|
|
{
|
|
sprintf(tQBuf, "UPDATE `cameras` SET `online`=1 WHERE `id`=%d", camID);
|
|
}
|
|
else
|
|
{
|
|
sprintf(tQBuf, "UPDATE `cameras` SET `online`=0 WHERE `id`=%d", camID);
|
|
};
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
if (online)
|
|
{
|
|
sprintf(tQBuf, "UPDATE `media_streams` SET `valid`=1 WHERE `source_id`=%d", camID);
|
|
}
|
|
else
|
|
{
|
|
sprintf(tQBuf, "UPDATE `media_streams` SET `valid`=0 WHERE `source_id`=%d", camID);
|
|
};
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
return true;
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool sqliteDBC::updateIPCam(CSTR uuid, CSTR Addr)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
uint32_t cID = getCamId(uuid);
|
|
if (cID)
|
|
{
|
|
return updateIPCam(cID, Addr);
|
|
};
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool sqliteDBC::updateLocalCam(CSTR uuid)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
uint32_t cID = getCamId(uuid);
|
|
if (cID)
|
|
{
|
|
return updateLocalCam(cID);
|
|
};
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool sqliteDBC::updateLocalCam(uint32_t CamID)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
sprintf(tQBuf, "UPDATE cameras SET `online`=1 WHERE `id`=%d", CamID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
sprintf(tQBuf, "UPDATE `media_streams` SET `valid`=1 WHERE `source_id`=%d", CamID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
return true;
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool sqliteDBC::updateLRFComStat(uint32_t lrfID, uint32_t ErrorPerMinute)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
sprintf(tQBuf, "UPDATE `lrf_sensors` SET `com_epm`=%d WHERE `id`=%d", ErrorPerMinute, lrfID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
return true;
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool sqliteDBC::updateLRFFrozenStatus(uint32_t lrfID, bool FFT, bool SFT)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
sprintf(tQBuf, "UPDATE `lrf_ini_settings` SET `FREEZ_FIRST_TH`=%d, `SAVE_FIRST_TH`=%d WHERE `sensor_id`=%d", FFT, SFT, lrfID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
return true;
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool sqliteDBC::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)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
if (master)
|
|
{
|
|
sprintf(tQBuf,
|
|
"INSERT INTO `lrf_detection_profiles`(`aux_id`,`profile_id`,`master`,`order`,`offset`,`delta`,`flip`,`width`,`sst`,`sun`,`gp`,`spikes`) VALUES(%d,%d,1,%d,%d,%d,%d,%d,%d,%d,%d,%d)ON CONFLICT(`aux_id`,`lrf_id`,`master`) DO UPDATE SET "
|
|
"`order`=%d, `offset`=%d, `delta`=%d, `flip`=%d, `width`=%d, `sst`=%d, `sun`=%d, `gp`=%d, `spikes`=%d",
|
|
lrfID, profileID, nOrder, nOffset, nDelta, nFlip, nWidth, bSST, nSun, GP, spikes, nOrder, nOffset, nDelta, nFlip, nWidth, bSST, nSun, GP, spikes);
|
|
}
|
|
else
|
|
{
|
|
sprintf(tQBuf,
|
|
"INSERT INTO `lrf_detection_profiles`(`aux_id`,`profile_id`,`master`,`order`,`offset`,`delta`,`flip`,`width`,`sst`,`sun`,`gp`,`spikes`) VALUES(%d,%d,0,%d,%d,%d,%d,%d,%d,%d,%d,%d)ON CONFLICT(`aux_id`,`lrf_id`,`master`) DO UPDATE SET "
|
|
"`order`=%d, `offset`=%d, `delta`=%d, `flip`=%d, `width`=%d, `sst`=%d, `sun`=%d, `gp`=%d, `spikes`=%d",
|
|
lrfID, profileID, nOrder, nOffset, nDelta, nFlip, nWidth, bSST, nSun, GP, spikes, nOrder, nOffset, nDelta, nFlip, nWidth, bSST, nSun, GP, spikes);
|
|
};
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
return true;
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool sqliteDBC::updateLRFDryContact(uint32_t lrfID, bool bAuto, bool bNO, uint16_t wWindow)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
sprintf(tQBuf, "UPDATE `lrf_sensors` SET `dc_auto`=%d, `dc_no`=%d, `dc_window`=%d WHERE `id`=%d", bAuto, bNO, wWindow, lrfID);
|
|
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
return true;
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool sqliteDBC::updateLRFSerial(uint32_t lrfID, CSTR Serial)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
CSTR tES = m_pDataStorage->escapeString(Serial);
|
|
if (tES)
|
|
{
|
|
sprintf(tQBuf, "UPDATE `lrf_sensors` SET `serial`='%s' WHERE `id`=%d", tES, lrfID);
|
|
free(tES);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
return true;
|
|
};
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool sqliteDBC::updateLRFUpload(uint32_t id, uint8_t status)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
sprintf(tQBuf, "UPDATE `lrf_uploads` SET `status`=%d WHERE `id`=%d", status, id);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
return true;
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool sqliteDBC::updateLRFUnfinishedUploads(uint32_t deviceID)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
sprintf(tQBuf, "UPDATE `lrf_uploads` SET `status`=-1 WHERE `sensor_id`=%d AND `status` < 101 ", deviceID);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
return true;
|
|
};
|
|
return false;
|
|
}
|
|
|
|
bool sqliteDBC::updateLRFVerison(uint32_t lrfID, CSTR version)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
CSTR tES = m_pDataStorage->escapeString(version);
|
|
if (tES)
|
|
{
|
|
sprintf(tQBuf, "UPDATE `lrf_sensors` SET `version`='%s' WHERE `id`=%d", tES, lrfID);
|
|
free(tES);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
return true;
|
|
};
|
|
};
|
|
return false;
|
|
}
|
|
|
|
uint32_t sqliteDBC::getRegisteredBubbleId(float X, float Y, float Z)
|
|
{
|
|
uint32_t RetVal = 0;
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
sprintf(tQBuf,
|
|
"SELECT `id` FROM `target_bubbles` WHERE ( ABS(`CENTER_X`-(%0.3f)) < `BOUNDARY` ) AND "
|
|
"( ABS(`CENTER_Y`-(%0.3f)) < `BOUNDARY` ) AND "
|
|
"( ABS(`CENTER_Z`-(%0.3f)) < `BOUNDARY` ) LIMIT 1",
|
|
X, Y, Z);
|
|
#ifdef DEBUG
|
|
LOG(tQBuf);
|
|
#endif
|
|
AAssoc * result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("id");
|
|
if (it != cArr->end())
|
|
{
|
|
RetVal = atoi(it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
};
|
|
return RetVal;
|
|
}
|
|
|
|
uint8_t sqliteDBC::updateRegisteredBubble(TARGET_SEGMENT * ptr)
|
|
{
|
|
uint8_t RetVal = 0;
|
|
if (ptr == NULL)
|
|
{
|
|
return RetVal;
|
|
}
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
uint32_t tID = getRegisteredBubbleId(ptr->system_center.x, ptr->system_center.y, ptr->system_center.z);
|
|
if (tID)
|
|
{
|
|
// 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 RETURNING `BLOCK_COUNS`", ptr->system_center.x, ptr->system_center.y,
|
|
ptr->system_center.z, ptr->boundary, tID);
|
|
AAssoc * result = m_pDataStorage->Query(tQBuf);
|
|
if (result != NULL)
|
|
{
|
|
if (result->size() > 0)
|
|
{
|
|
Assoc * cArr;
|
|
Assoc::iterator it;
|
|
cArr = result->at(0);
|
|
it = cArr->find("BLOCK_COUNS");
|
|
if (it != cArr->end())
|
|
{
|
|
RetVal = atoi(it->second.c_str());
|
|
};
|
|
};
|
|
};
|
|
deleteResult(result);
|
|
}
|
|
else
|
|
{
|
|
// Create New Record for Bubble
|
|
sprintf(tQBuf, "INSERT INTO `target_bubbles`(`CENTER_X`,`CENTER_Y`,`CENTER_Z`,`BOUNDARY`,`BLOCK_COUNS`) VALUES(%0.3f,%0.3f,%0.3f,%0.3f,1)", ptr->system_center.x, ptr->system_center.y, ptr->system_center.z, ptr->boundary);
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
};
|
|
};
|
|
return RetVal;
|
|
}
|
|
|
|
bool sqliteDBC::updateServerIdentity(uint32_t m_nServerID, CSTR m_sIdentity)
|
|
{
|
|
if (m_bStoIsConnected)
|
|
{
|
|
char tQBuf[MAX_PATH_LEN];
|
|
CSTR tES = m_pDataStorage->escapeString(m_sIdentity);
|
|
if (tES)
|
|
{
|
|
sprintf(tQBuf, "UPDATE `servers` SET `identity`='%s' WHERE `id`=%d", tES, m_nServerID);
|
|
free(tES);
|
|
#ifdef DEBUG_ALL
|
|
LOG(tQBuf);
|
|
#endif
|
|
m_pDataStorage->SilentQuery(tQBuf);
|
|
return true;
|
|
};
|
|
};
|
|
return false;
|
|
}
|
|
|
|
#undef LOG
|
|
#undef LOG_ERROR
|