|
@@ -1,646 +0,0 @@
|
|
-/******************************************************************************
|
|
|
|
- * Copyright 2020 The siasun Transport Authors. All Rights Reserved.
|
|
|
|
- * Author: madesheng
|
|
|
|
- * Licensed under the Apache License, Version 1.0 (the "License");
|
|
|
|
- *****************************************************************************/
|
|
|
|
-#include "decisiondatabase.h"
|
|
|
|
-#include <string>
|
|
|
|
-namespace robot {
|
|
|
|
-namespace decisionSpace {
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-std::string DecisionDatabase::Name() { return "Database"; }
|
|
|
|
-
|
|
|
|
-std::string to_string_with_precision(double a_value, int n){
|
|
|
|
- std::ostringstream out;
|
|
|
|
- out<<std::setprecision(n)<<a_value;
|
|
|
|
- return out.str();
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-int DecisionDatabase::InitDB(){
|
|
|
|
- LOG(INFO)<<Name()<<":Decision database init...";
|
|
|
|
-
|
|
|
|
- /***************************打开数据库 start ****************************/
|
|
|
|
- sqlite3 * sqlite = robot::common::Sqlite3helper::Instance().open("robot.db");
|
|
|
|
- if(sqlite==nullptr){
|
|
|
|
- LOG(INFO)<<Name()<<":Decision opendb fail";
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
- /***************************打开数据库 end ******************************/
|
|
|
|
-
|
|
|
|
- /****************检查,初始化表 action_directive start *******************/
|
|
|
|
- int haveTable = robot::common::Sqlite3helper::Instance().isTableExits(sqlite,"action_directive");
|
|
|
|
- if(haveTable ==-1){
|
|
|
|
- LOG(INFO)<<Name()<<":Decision exits table ->action_directive fail";
|
|
|
|
- return 0;
|
|
|
|
- }else if(haveTable == 0){
|
|
|
|
- int createResult = robot::common::Sqlite3helper::Instance().createTable(sqlite,
|
|
|
|
- "CREATE TABLE action_directive ( \
|
|
|
|
- rule_name VARCHAR (50) NOT NULL, \
|
|
|
|
- directive_id BIGINT NOT NULL, \
|
|
|
|
- directive_info VARCHAR (255), \
|
|
|
|
- directive_result INT, \
|
|
|
|
- PRIMARY KEY ( \
|
|
|
|
- rule_name, \
|
|
|
|
- directive_id \
|
|
|
|
- ) \
|
|
|
|
- );"
|
|
|
|
- );
|
|
|
|
- if(createResult == 0){
|
|
|
|
- LOG(INFO)<<Name()<<":Decision create table ->action_directive fail";
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- /****************检查,初始化表 action_directive end **********************/
|
|
|
|
-
|
|
|
|
- /******************检查,初始化表 location_map start **********************/
|
|
|
|
-// haveTable = robot::common::Sqlite3helper::Instance().isTableExits(sqlite,"location_map");
|
|
|
|
-// if(haveTable ==-1){
|
|
|
|
-// LOG(INFO)<<Name()<<":Decision exits table -> location_map fail";
|
|
|
|
-// return 0;
|
|
|
|
-// }else if(haveTable == 0){
|
|
|
|
-// int createResult = robot::common::Sqlite3helper::Instance().createTable(sqlite,
|
|
|
|
-// "CREATE TABLE location_map ( \
|
|
|
|
-// location_lon_1 FLOAT (53) NOT NULL, \
|
|
|
|
-// location_lat_1 FLOAT (53) NOT NULL, \
|
|
|
|
-// location_lon_2 FLOAT (53) NOT NULL, \
|
|
|
|
-// location_lat_2 FLOAT (53) NOT NULL, \
|
|
|
|
-// location_X_1 FLOAT (53) NOT NULL, \
|
|
|
|
-// location_Y_1 FLOAT (53) NOT NULL, \
|
|
|
|
-// map_id VARCHAR (100) PRIMARY KEY \
|
|
|
|
-// NOT NULL, \
|
|
|
|
-// location_X_2 FLOAT (53) NOT NULL, \
|
|
|
|
-// location_Y_2 FLOAT (53) NOT NULL \
|
|
|
|
-// );"
|
|
|
|
-// );
|
|
|
|
-// if(createResult == 0){
|
|
|
|
-// LOG(INFO)<<Name()<<":Decision create table -> location_map fail";
|
|
|
|
-// return 0;
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
- /******************检查,初始化表 location_map end ************************/
|
|
|
|
-
|
|
|
|
- /**************检查,初始化表 location_rule_info start ********************/
|
|
|
|
- haveTable = robot::common::Sqlite3helper::Instance().isTableExits(sqlite,"location_rule_info");
|
|
|
|
- if(haveTable ==-1){
|
|
|
|
- LOG(INFO)<<Name()<<":Decision exits table -> location_rule_info fail";
|
|
|
|
- return 0;
|
|
|
|
- }else if(haveTable == 0){
|
|
|
|
- int createResult = robot::common::Sqlite3helper::Instance().createTable(sqlite,
|
|
|
|
- "CREATE TABLE location_rule_info ( \
|
|
|
|
- rule_name VARCHAR (50) NOT NULL, \
|
|
|
|
- location_id BIGINT NOT NULL, \
|
|
|
|
- location_lon DECIMAL (38) NOT NULL, \
|
|
|
|
- location_lat DECIMAL (38) NOT NULL, \
|
|
|
|
- location_height DECIMAL (38) NOT NULL, \
|
|
|
|
- location_speed FLOAT (53) NOT NULL, \
|
|
|
|
- PRIMARY KEY ( \
|
|
|
|
- rule_name, \
|
|
|
|
- location_id \
|
|
|
|
- ) \
|
|
|
|
- );"
|
|
|
|
- );
|
|
|
|
- if(createResult == 0){
|
|
|
|
- LOG(INFO)<<Name()<<":Decision create table -> location_map fail";
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- /**************检查,初始化表 location_rule_info end **********************/
|
|
|
|
- robot::common::Sqlite3helper::Instance().close(sqlite);
|
|
|
|
- return 1;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-int DecisionDatabase::InsertActionDirective(const char *ruleName, int iDirectiveID, const char *directiveInfo, int iDirectiveResult){
|
|
|
|
-
|
|
|
|
- /***************************打开数据库 start ****************************/
|
|
|
|
- sqlite3 * sqlite = robot::common::Sqlite3helper::Instance().open("robot.db");
|
|
|
|
- if(sqlite==nullptr){
|
|
|
|
- LOG(INFO)<<Name()<<":Decision opendb fail";
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
- /***************************打开数据库 end ******************************/
|
|
|
|
-
|
|
|
|
- /********************向表中插入一条记录 start *****************************/
|
|
|
|
- std::string sRuleName = ruleName;
|
|
|
|
- std::string sDirectiveID = std::to_string(iDirectiveID);
|
|
|
|
- std::string sDirectiveInfo = directiveInfo;
|
|
|
|
- std::string sDirectiveResult = std::to_string(iDirectiveResult);
|
|
|
|
- std::string s_sql="INSERT INTO action_directive ( \
|
|
|
|
- rule_name, \
|
|
|
|
- directive_id, \
|
|
|
|
- directive_info, \
|
|
|
|
- directive_result \
|
|
|
|
- ) \
|
|
|
|
- VALUES (\'"+sRuleName+"\', \
|
|
|
|
- "+sDirectiveID+", \
|
|
|
|
- \'"+sDirectiveInfo+"\', \
|
|
|
|
- "+sDirectiveResult+");";
|
|
|
|
- LOG(INFO)<<s_sql;
|
|
|
|
- const char* sql=s_sql.c_str();
|
|
|
|
- robot::common::Sqlite3helper::Instance().update(sqlite,sql);
|
|
|
|
- /********************向表中插入一条记录 end *******************************/
|
|
|
|
-
|
|
|
|
- robot::common::Sqlite3helper::Instance().close(sqlite);
|
|
|
|
- return 1;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-int DecisionDatabase::InsertLocationMap(float fLocationLon1,
|
|
|
|
- float fLocationLat1,
|
|
|
|
- float fLocationLon2,
|
|
|
|
- float fLocationLat2,
|
|
|
|
- float fLocationX1,
|
|
|
|
- float fLocationY1,
|
|
|
|
- const char *mapId,
|
|
|
|
- float fLocationX2,
|
|
|
|
- float fLocationY2){
|
|
|
|
-
|
|
|
|
- /***************************打开数据库 start ****************************/
|
|
|
|
- sqlite3 * sqlite = robot::common::Sqlite3helper::Instance().open("robot.db");
|
|
|
|
- if(sqlite==nullptr){
|
|
|
|
- LOG(INFO)<<Name()<<"Decision opendb fail";
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
- /***************************打开数据库 end ******************************/
|
|
|
|
-
|
|
|
|
- /********************向表中插入一条记录 start *****************************/
|
|
|
|
- std::string sLocationLon1=std::to_string(fLocationLon1);
|
|
|
|
- std::string sLocationLat1=std::to_string(fLocationLat1);
|
|
|
|
- std::string sLocationLon2=std::to_string(fLocationLon2);
|
|
|
|
- std::string sLocationLat2=std::to_string(fLocationLat2);
|
|
|
|
- std::string sLocationX1=std::to_string(fLocationX1);
|
|
|
|
- std::string sLocationY1=std::to_string(fLocationY1);
|
|
|
|
- std::string sMapId=mapId;
|
|
|
|
- std::string sLocationX2=std::to_string(fLocationX2);
|
|
|
|
- std::string sLocationY2=std::to_string(fLocationY2);
|
|
|
|
-
|
|
|
|
- std::string s_sql="INSERT INTO location_map ( \
|
|
|
|
- location_lon_1, \
|
|
|
|
- location_lat_1, \
|
|
|
|
- location_lon_2, \
|
|
|
|
- location_lat_2, \
|
|
|
|
- location_X_1, \
|
|
|
|
- location_Y_1, \
|
|
|
|
- map_id, \
|
|
|
|
- location_X_2, \
|
|
|
|
- location_Y_2 \
|
|
|
|
- ) \
|
|
|
|
- VALUES ( \
|
|
|
|
- "+sLocationLon1+", \
|
|
|
|
- "+sLocationLat1+", \
|
|
|
|
- "+sLocationLon2+", \
|
|
|
|
- "+sLocationLat2+", \
|
|
|
|
- "+sLocationX1+", \
|
|
|
|
- "+sLocationY1+", \
|
|
|
|
- \'"+sMapId+"\', \
|
|
|
|
- "+sLocationX2+", \
|
|
|
|
- "+sLocationY2+" \
|
|
|
|
- );";
|
|
|
|
- LOG(INFO)<<s_sql;
|
|
|
|
- const char* sql=s_sql.c_str();
|
|
|
|
- robot::common::Sqlite3helper::Instance().update(sqlite,sql);
|
|
|
|
- /********************向表中插入一条记录 end *******************************/
|
|
|
|
-
|
|
|
|
- robot::common::Sqlite3helper::Instance().close(sqlite);
|
|
|
|
- return 1;
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-int DecisionDatabase::InsertLocationRuleInfo(const char *ruleName,
|
|
|
|
- int iLocationID,
|
|
|
|
- double dLocationLon,
|
|
|
|
- double dLocationLat,
|
|
|
|
- float dLocationHeight,
|
|
|
|
- float fLocationSpeed){
|
|
|
|
-
|
|
|
|
- /***************************打开数据库 start ****************************/
|
|
|
|
- sqlite3 * sqlite = robot::common::Sqlite3helper::Instance().open("robot.db");
|
|
|
|
- if(sqlite==nullptr){
|
|
|
|
- LOG(INFO)<<Name()<<"Decision opendb fail";
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
- /***************************打开数据库 end ******************************/
|
|
|
|
-
|
|
|
|
- /********************向表中插入一条记录 start *****************************/
|
|
|
|
- std::string sRuleName=ruleName;
|
|
|
|
- std::string sLocationID=std::to_string(iLocationID);
|
|
|
|
- std::string sLocationLon=to_string_with_precision(dLocationLon,12);
|
|
|
|
- std::string sLocationLat=to_string_with_precision(dLocationLat,11);
|
|
|
|
- std::string sLocationHeight=to_string_with_precision(dLocationHeight,4);
|
|
|
|
- std::string sLocationSpeed=to_string_with_precision(fLocationSpeed, 4);
|
|
|
|
- std::string s_sql="INSERT INTO location_rule_info ( \
|
|
|
|
- rule_name, \
|
|
|
|
- location_id, \
|
|
|
|
- location_lon, \
|
|
|
|
- location_lat, \
|
|
|
|
- location_height, \
|
|
|
|
- location_speed \
|
|
|
|
- ) \
|
|
|
|
- VALUES ( \
|
|
|
|
- \'"+sRuleName+"\', \
|
|
|
|
- "+sLocationID+", \
|
|
|
|
- "+sLocationLon+", \
|
|
|
|
- "+sLocationLat+", \
|
|
|
|
- "+sLocationHeight+", \
|
|
|
|
- "+sLocationSpeed+" \
|
|
|
|
- );";
|
|
|
|
- //LOG(INFO)<<s_sql;
|
|
|
|
- const char* sql=s_sql.c_str();
|
|
|
|
- robot::common::Sqlite3helper::Instance().update(sqlite,sql);
|
|
|
|
- /********************向表中插入一条记录 end *******************************/
|
|
|
|
-
|
|
|
|
- robot::common::Sqlite3helper::Instance().close(sqlite);
|
|
|
|
- return 1;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-int DecisionDatabase::InsertLocationRuleInfoAndActionDirective(const char* ruleName,
|
|
|
|
- int iDirectiveID,
|
|
|
|
- const char* directiveInfo,
|
|
|
|
- int iDirectiveResult,
|
|
|
|
- int iLocationID,
|
|
|
|
- double dLocationLon,
|
|
|
|
- double dLocationLat,
|
|
|
|
- float dLocationHeight,
|
|
|
|
- float fLocationSpeed)
|
|
|
|
-{
|
|
|
|
- int iRet = 0;
|
|
|
|
- /***************************打开数据库 start ****************************/
|
|
|
|
- sqlite3 * sqlite = robot::common::Sqlite3helper::Instance().open("robot.db");
|
|
|
|
- if(sqlite==nullptr){
|
|
|
|
- LOG(INFO)<<Name()<<"Decision opendb fail";
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
- /***************************打开数据库 end ******************************/
|
|
|
|
- robot::common::Sqlite3helper::Instance().transaction(sqlite);
|
|
|
|
- try
|
|
|
|
- {
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- /********************向表中插入一条记录 start *****************************/
|
|
|
|
- std::string sRuleName=ruleName;
|
|
|
|
- std::string sLocationID=std::to_string(iLocationID);
|
|
|
|
- std::string sLocationLon=to_string_with_precision(dLocationLon,12);
|
|
|
|
- std::string sLocationLat=to_string_with_precision(dLocationLat,11);
|
|
|
|
- std::string sLocationHeight=to_string_with_precision(dLocationHeight,4);
|
|
|
|
- std::string sLocationSpeed=to_string_with_precision(fLocationSpeed, 4);
|
|
|
|
- std::string s_sqlsqlLocation="INSERT INTO location_rule_info ( \
|
|
|
|
- rule_name, \
|
|
|
|
- location_id, \
|
|
|
|
- location_lon, \
|
|
|
|
- location_lat, \
|
|
|
|
- location_height, \
|
|
|
|
- location_speed \
|
|
|
|
- ) \
|
|
|
|
- VALUES ( \
|
|
|
|
- \'"+sRuleName+"\', \
|
|
|
|
- "+sLocationID+", \
|
|
|
|
- "+sLocationLon+", \
|
|
|
|
- "+sLocationLat+", \
|
|
|
|
- "+sLocationHeight+", \
|
|
|
|
- "+sLocationSpeed+" \
|
|
|
|
- );";
|
|
|
|
- //LOG(INFO)<<s_sqlsqlLocation;
|
|
|
|
- const char* sqlLocation=s_sqlsqlLocation.c_str();
|
|
|
|
- robot::common::Sqlite3helper::Instance().update(sqlite, sqlLocation);
|
|
|
|
-
|
|
|
|
- //std::string sRuleName = ruleName;
|
|
|
|
- std::string sDirectiveID = std::to_string(iDirectiveID);
|
|
|
|
- std::string sDirectiveInfo = directiveInfo;
|
|
|
|
- std::string sDirectiveResult = std::to_string(iDirectiveResult);
|
|
|
|
- std::string s_sql="INSERT INTO action_directive ( \
|
|
|
|
- rule_name, \
|
|
|
|
- directive_id, \
|
|
|
|
- directive_info, \
|
|
|
|
- directive_result \
|
|
|
|
- ) \
|
|
|
|
- VALUES (\'"+sRuleName+"\', \
|
|
|
|
- "+sDirectiveID+", \
|
|
|
|
- \'"+sDirectiveInfo+"\', \
|
|
|
|
- "+sDirectiveResult+");";
|
|
|
|
- //LOG(INFO)<<s_sql;
|
|
|
|
- const char* sql=s_sql.c_str();
|
|
|
|
- robot::common::Sqlite3helper::Instance().update(sqlite,sql);
|
|
|
|
- /********************向表中插入一条记录 end *******************************/
|
|
|
|
- robot::common::Sqlite3helper::Instance().commitTransaction(sqlite);
|
|
|
|
- iRet =1;
|
|
|
|
- }
|
|
|
|
- catch (ros::Exception ex)
|
|
|
|
- {
|
|
|
|
- robot::common::Sqlite3helper::Instance().rollbackTransaction(sqlite);
|
|
|
|
- iRet = -1;
|
|
|
|
- }
|
|
|
|
- robot::common::Sqlite3helper::Instance().close(sqlite);
|
|
|
|
- return iRet;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-int DecisionDatabase::DeleteActionDirective(const char *ruleName){
|
|
|
|
-
|
|
|
|
- /***************************打开数据库 start ****************************/
|
|
|
|
- sqlite3 * sqlite = robot::common::Sqlite3helper::Instance().open("robot.db");
|
|
|
|
- if(sqlite==nullptr){
|
|
|
|
- LOG(INFO)<<Name()<<"Decision opendb fail";
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
- /***************************打开数据库 end ******************************/
|
|
|
|
-
|
|
|
|
- std::string sRuleName= ruleName;
|
|
|
|
- std::string s_sql="DELETE FROM action_directive WHERE rule_name=\'" + sRuleName+"\'";
|
|
|
|
- //LOG(INFO)<<s_sql;
|
|
|
|
- const char* sql=s_sql.c_str();
|
|
|
|
- int deleteResult = robot::common::Sqlite3helper::Instance().update(sqlite,sql);
|
|
|
|
- robot::common::Sqlite3helper::Instance().close(sqlite);
|
|
|
|
- if(deleteResult == 0){
|
|
|
|
- return 0;
|
|
|
|
- }else{
|
|
|
|
- return 1;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-int DecisionDatabase::DeleteActionDirective(int iDirectiveID){
|
|
|
|
-
|
|
|
|
- /***************************打开数据库 start ****************************/
|
|
|
|
- sqlite3 * sqlite = robot::common::Sqlite3helper::Instance().open("robot.db");
|
|
|
|
- if(sqlite==nullptr){
|
|
|
|
- LOG(INFO)<<Name()<<"Decision opendb fail";
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
- /***************************打开数据库 end ******************************/
|
|
|
|
-
|
|
|
|
- std::string sDirectiveID=std::to_string(iDirectiveID);
|
|
|
|
- std::string s_sql="DELETE FROM action_directive WHERE directive_id=" + sDirectiveID+";";
|
|
|
|
- //LOG(INFO)<<s_sql;
|
|
|
|
- const char* sql=s_sql.c_str();
|
|
|
|
- int deleteResult = robot::common::Sqlite3helper::Instance().update(sqlite,sql);
|
|
|
|
- robot::common::Sqlite3helper::Instance().close(sqlite);
|
|
|
|
- if(deleteResult == 0){
|
|
|
|
- return 0;
|
|
|
|
- }else{
|
|
|
|
- return 1;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-int DecisionDatabase::DeleteLocationMap(const char *mapID){
|
|
|
|
-
|
|
|
|
- /***************************打开数据库 start ****************************/
|
|
|
|
- sqlite3 * sqlite = robot::common::Sqlite3helper::Instance().open("robot.db");
|
|
|
|
- if(sqlite==nullptr){
|
|
|
|
- LOG(INFO)<<Name()<<"Decision opendb fail";
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
- /***************************打开数据库 end ******************************/
|
|
|
|
-
|
|
|
|
- std::string sMapID=mapID;
|
|
|
|
- std::string s_sql="DELETE FROM location_map WHERE map_id=" + sMapID;
|
|
|
|
- //LOG(INFO)<<s_sql;
|
|
|
|
- const char* sql=s_sql.c_str();
|
|
|
|
- int deleteResult = robot::common::Sqlite3helper::Instance().update(sqlite,sql);
|
|
|
|
- robot::common::Sqlite3helper::Instance().close(sqlite);
|
|
|
|
- if(deleteResult == 0){
|
|
|
|
- return 0;
|
|
|
|
- }else{
|
|
|
|
- return 1;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-int DecisionDatabase::DeleteLocationRuleInfo(const char *ruleName){
|
|
|
|
-
|
|
|
|
- /***************************打开数据库 start ****************************/
|
|
|
|
- sqlite3 * sqlite = robot::common::Sqlite3helper::Instance().open("robot.db");
|
|
|
|
- if(sqlite==nullptr){
|
|
|
|
- LOG(INFO)<<Name()<<"Decision opendb fail";
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
- /***************************打开数据库 end ******************************/
|
|
|
|
-
|
|
|
|
- std::string sRuleName=ruleName;
|
|
|
|
- std::string s_sql="DELETE FROM location_rule_info WHERE rule_name=\'" + sRuleName+"\'";
|
|
|
|
- //LOG(INFO)<<s_sql;
|
|
|
|
- const char* sql=s_sql.c_str();
|
|
|
|
- int deleteResult = robot::common::Sqlite3helper::Instance().update(sqlite,sql);
|
|
|
|
- robot::common::Sqlite3helper::Instance().close(sqlite);
|
|
|
|
- if(deleteResult == 0){
|
|
|
|
- return 0;
|
|
|
|
- }else{
|
|
|
|
- return 1;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-int DecisionDatabase::DeleteLocationRuleInfo(int iLocationID){
|
|
|
|
-
|
|
|
|
- /***************************打开数据库 start ****************************/
|
|
|
|
- sqlite3 * sqlite = robot::common::Sqlite3helper::Instance().open("robot.db");
|
|
|
|
- if(sqlite==nullptr){
|
|
|
|
- LOG(INFO)<<Name()<<"Decision opendb fail";
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
- /***************************打开数据库 end ******************************/
|
|
|
|
-
|
|
|
|
- std::string sLocationID=std::to_string(iLocationID);
|
|
|
|
- std::string s_sql="DELETE FROM location_rule_info WHERE location_id=" + sLocationID;
|
|
|
|
- //LOG(INFO)<<s_sql;
|
|
|
|
- const char* sql=s_sql.c_str();
|
|
|
|
- int deleteResult = robot::common::Sqlite3helper::Instance().update(sqlite,sql);
|
|
|
|
- robot::common::Sqlite3helper::Instance().close(sqlite);
|
|
|
|
- if(deleteResult == 0){
|
|
|
|
- return 0;
|
|
|
|
- }else{
|
|
|
|
- return 1;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-int DecisionDatabase::UpdateActionDirective(const char* ruleName,int iDirectiveID,int iNewDirectiveResult){
|
|
|
|
-
|
|
|
|
- /***************************打开数据库 start ****************************/
|
|
|
|
- sqlite3 * sqlite = robot::common::Sqlite3helper::Instance().open("robot.db");
|
|
|
|
- if(sqlite==nullptr){
|
|
|
|
- LOG(INFO)<<Name()<<"Decision opendb fail";
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
- /***************************打开数据库 end ******************************/
|
|
|
|
-
|
|
|
|
- std::string sRuleName=ruleName;
|
|
|
|
- std::string sDirectiveID=std::to_string(iDirectiveID);
|
|
|
|
- std::string sNewDirectiveResult=std::to_string(iNewDirectiveResult);
|
|
|
|
- std::string s_sql="UPDATE action_directive SET \
|
|
|
|
- directive_result=\'"+sNewDirectiveResult+"\' \
|
|
|
|
- WHERE rule_name=\'"+sRuleName+"\' AND \
|
|
|
|
- directive_id="+sDirectiveID+";";
|
|
|
|
- //LOG(INFO)<<s_sql;
|
|
|
|
- const char* sql=s_sql.c_str();
|
|
|
|
- int updateResult = robot::common::Sqlite3helper::Instance().update(sqlite,sql);
|
|
|
|
- if(updateResult == 0){
|
|
|
|
- return 0;
|
|
|
|
- }else{
|
|
|
|
- return 1;
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-int DecisionDatabase::UpdateLocationMap(float fNewLocationLon1,
|
|
|
|
- float fNewLocationLat1,
|
|
|
|
- float fNewLocationLon2,
|
|
|
|
- float fNewLocationLat2,
|
|
|
|
- float fNewLocationX1,
|
|
|
|
- float fNewLocationY1,
|
|
|
|
- float fNewLocationX2,
|
|
|
|
- float fNewLocationY2,
|
|
|
|
- const char * mapId){
|
|
|
|
-
|
|
|
|
- /***************************打开数据库 start ****************************/
|
|
|
|
- sqlite3 * sqlite = robot::common::Sqlite3helper::Instance().open("robot.db");
|
|
|
|
- if(sqlite==nullptr){
|
|
|
|
- LOG(INFO)<<Name()<<"Decision opendb fail";
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
- /***************************打开数据库 end ******************************/
|
|
|
|
-
|
|
|
|
- std::string sLocationLon1=std::to_string(fNewLocationLon1);
|
|
|
|
- std::string sLocationLat1=std::to_string(fNewLocationLat1);
|
|
|
|
- std::string sLocationLon2=std::to_string(fNewLocationLon2);
|
|
|
|
- std::string sLocationLat2=std::to_string(fNewLocationLat2);
|
|
|
|
- std::string sLocationX1=std::to_string(fNewLocationX1);
|
|
|
|
- std::string sLocationY1=std::to_string(fNewLocationY1);
|
|
|
|
- std::string sMapId=mapId;
|
|
|
|
- std::string sLocationX2=std::to_string(fNewLocationX2);
|
|
|
|
- std::string sLocationY2=std::to_string(fNewLocationY2);
|
|
|
|
- std::string s_sql="UPDATE location_map SET \
|
|
|
|
- location_lon_1="+sLocationLon1+", \
|
|
|
|
- location_lat_1="+sLocationLat1+", \
|
|
|
|
- location_lon_2="+sLocationLon2+", \
|
|
|
|
- location_lat_2="+sLocationLat2+", \
|
|
|
|
- location_X_1="+sLocationX1+", \
|
|
|
|
- location_Y_1="+sLocationY1+", \
|
|
|
|
- location_X_2="+sLocationX2+", \
|
|
|
|
- location_Y_2="+sLocationY2+" \
|
|
|
|
- WHERE map_id=\'"+sMapId+"\';";
|
|
|
|
- //LOG(INFO)<<s_sql;
|
|
|
|
- const char* sql=s_sql.c_str();
|
|
|
|
- int updateResult = robot::common::Sqlite3helper::Instance().update(sqlite,sql);
|
|
|
|
- robot::common::Sqlite3helper::Instance().close(sqlite);
|
|
|
|
- if(updateResult == 0){
|
|
|
|
- return 0;
|
|
|
|
- }else{
|
|
|
|
- return 1;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-std::vector<ACTION_DIRECTIVE> DecisionDatabase::QueryActionDirective(int iStart, int iLength){
|
|
|
|
- std::vector<ACTION_DIRECTIVE> actionDirectives;
|
|
|
|
- /***************************打开数据库 start ****************************/
|
|
|
|
- sqlite3 * sqlite = robot::common::Sqlite3helper::Instance().open("robot.db");
|
|
|
|
- if(sqlite==nullptr){
|
|
|
|
- LOG(INFO)<<Name()<<"Decision opendb fail";
|
|
|
|
- return std::vector<ACTION_DIRECTIVE>(0);
|
|
|
|
- }
|
|
|
|
- /***************************打开数据库 end ******************************/
|
|
|
|
- std::string sStart=std::to_string(iStart);
|
|
|
|
- std::string sLength=std::to_string(iLength);
|
|
|
|
- std::string s_sql="SELECT * FROM action_directive limit "+sStart+","+sLength;
|
|
|
|
- //LOG(INFO)<<s_sql;
|
|
|
|
- const char* sql=s_sql.c_str();
|
|
|
|
- robot::common::query_result_t* result=robot::common::Sqlite3helper::Instance().query(sqlite,sql);
|
|
|
|
- while(result->next()){
|
|
|
|
- ACTION_DIRECTIVE actionDirective;
|
|
|
|
- actionDirective.RuleName=result->value((char*)"rule_name");
|
|
|
|
- actionDirective.DirectiveID=std::atoi(result->value((char*)"directive_id"));
|
|
|
|
- actionDirective.DirectiveResult=std::atoi(result->value((char*)"directive_result"));
|
|
|
|
- actionDirective.DirectiveInfo=result->value((char*)"directive_info");
|
|
|
|
- actionDirectives.push_back(actionDirective);
|
|
|
|
- }
|
|
|
|
- return actionDirectives;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-std::vector<LOCATION_RULE_INFO> DecisionDatabase::QueryLocationRuleInfo(int iStart, int iLength){
|
|
|
|
- std::vector<LOCATION_RULE_INFO> locationRuleInfos;
|
|
|
|
- /***************************打开数据库 start ****************************/
|
|
|
|
- sqlite3 * sqlite = robot::common::Sqlite3helper::Instance().open("robot.db");
|
|
|
|
- if(sqlite==nullptr){
|
|
|
|
- LOG(INFO)<<Name()<<"Decision opendb fail";
|
|
|
|
- return std::vector<LOCATION_RULE_INFO>(0);
|
|
|
|
- }
|
|
|
|
- /***************************打开数据库 end ******************************/
|
|
|
|
- std::string sStart=std::to_string(iStart);
|
|
|
|
- std::string sLength=std::to_string(iLength);
|
|
|
|
- std::string s_sql="SELECT * FROM location_rule_info limit "+sStart+","+sLength;
|
|
|
|
- LOG(INFO)<<s_sql;
|
|
|
|
- const char* sql=s_sql.c_str();
|
|
|
|
- robot::common::query_result_t* result=robot::common::Sqlite3helper::Instance().query(sqlite,sql);
|
|
|
|
- while(result->next()){
|
|
|
|
- LOCATION_RULE_INFO locationRuleInfo;
|
|
|
|
- locationRuleInfo.RuleName=result->value((char*)"rule_name");
|
|
|
|
- locationRuleInfo.LocationLon=std::atof(result->value((char*)"location_lon"));
|
|
|
|
- locationRuleInfo.LocationLat=std::atof(result->value((char*)"location_lat"));
|
|
|
|
- locationRuleInfo.LocationHeight=std::atof(result->value((char*)"location_height"));
|
|
|
|
- locationRuleInfo.LocationID=std::atoi(result->value((char*)"location_id"));
|
|
|
|
- locationRuleInfo.LocationSpeed=std::atof(result->value((char*)"location_speed"));
|
|
|
|
- locationRuleInfos.push_back(locationRuleInfo);
|
|
|
|
- }
|
|
|
|
- return locationRuleInfos;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-int DecisionDatabase::countOfActionDirective(){
|
|
|
|
- /***************************打开数据库 start ****************************/
|
|
|
|
- sqlite3 * sqlite = robot::common::Sqlite3helper::Instance().open("robot.db");
|
|
|
|
- if(sqlite==nullptr){
|
|
|
|
- LOG(INFO)<<Name()<<"Decision opendb fail";
|
|
|
|
- return -1;
|
|
|
|
- }
|
|
|
|
- /***************************打开数据库 end ******************************/
|
|
|
|
- std::string s_sql="SELECT count(*) FROM action_directive";
|
|
|
|
- //LOG(INFO)<<s_sql;
|
|
|
|
- const char* sql=s_sql.c_str();
|
|
|
|
- robot::common::query_result_t* result=robot::common::Sqlite3helper::Instance().query(sqlite,sql);
|
|
|
|
- while(result->next()){
|
|
|
|
- return std::atoi(result->value((char*)"count(*)"));
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-int DecisionDatabase::countOfLocationMap(){
|
|
|
|
- /***************************打开数据库 start ****************************/
|
|
|
|
- sqlite3 * sqlite = robot::common::Sqlite3helper::Instance().open("robot.db");
|
|
|
|
- if(sqlite==nullptr){
|
|
|
|
- LOG(INFO)<<Name()<<"Decision opendb fail";
|
|
|
|
- return -1;
|
|
|
|
- }
|
|
|
|
- /***************************打开数据库 end ******************************/
|
|
|
|
- std::string s_sql="SELECT count(*) FROM location_map";
|
|
|
|
- //LOG(INFO)<<s_sql;
|
|
|
|
- const char* sql=s_sql.c_str();
|
|
|
|
- robot::common::query_result_t* result=robot::common::Sqlite3helper::Instance().query(sqlite,sql);
|
|
|
|
- while(result->next()){
|
|
|
|
- return std::atoi(result->value((char*)"count(*)"));
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-int DecisionDatabase::countOfLocationRuleInfo(){
|
|
|
|
- /***************************打开数据库 start ****************************/
|
|
|
|
- sqlite3 * sqlite = robot::common::Sqlite3helper::Instance().open("robot.db");
|
|
|
|
- if(sqlite==nullptr){
|
|
|
|
- LOG(INFO)<<Name()<<"Decision opendb fail";
|
|
|
|
- return -1;
|
|
|
|
- }
|
|
|
|
- /***************************打开数据库 end ******************************/
|
|
|
|
- std::string s_sql="SELECT count(*) FROM location_rule_info";
|
|
|
|
- //LOG(INFO)<<s_sql;
|
|
|
|
- const char* sql=s_sql.c_str();
|
|
|
|
- robot::common::query_result_t* result=robot::common::Sqlite3helper::Instance().query(sqlite,sql);
|
|
|
|
- while(result->next()){
|
|
|
|
- return std::atoi(result->value((char*)"count(*)"));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-}
|
|
|