|
@@ -11,8 +11,24 @@ namespace decision {
|
|
|
std::string Decision::Name() const { return "decision"; }
|
|
|
|
|
|
int Decision::Init(){
|
|
|
+<<<<<<< HEAD
|
|
|
+ LOG(INFO)<<Name()<<":Decision init...";
|
|
|
+ Database::InitDB();
|
|
|
+ Database::InsertActionDirective("1",1,"1",1);
|
|
|
+ Database::InsertLocationMap(0.1,0.1,0.1,0.1,0.1,0.1,"1",0.1,0.1);
|
|
|
+ Database::InsertLocationRuleInfo("1",1,0.1,0.1,0.1,0.1);
|
|
|
+ Database::UpdateActionDirective("1",1,2);
|
|
|
+ Database::UpdateLocationMap(0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,"1");
|
|
|
+// Database::DeleteActionDirective("1");
|
|
|
+ Database::DeleteActionDirective(1);
|
|
|
+ Database::DeleteLocationMap("1");
|
|
|
+// Database::DeleteLocationRuleInfo("1");
|
|
|
+ Database::DeleteLocationRuleInfo(1);
|
|
|
+ return 0;
|
|
|
+=======
|
|
|
LOG(INFO)<<Name()<<"Decision init...";
|
|
|
return ROBOT_SUCCESS;
|
|
|
+>>>>>>> 759ecb392596608d195b9c0ff234e1e42401a6f8
|
|
|
}
|
|
|
|
|
|
int Decision::Start(){
|
|
@@ -25,379 +41,6 @@ void Decision::Stop(){
|
|
|
return ;
|
|
|
}
|
|
|
|
|
|
-int Decision::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 Decision::InsertActionDirective(const char *ruleName, int iDirectiveID, const char *directiveInfo, int iDirectiveResult){
|
|
|
- LOG(INFO)<<Name()<<"insert into action_directive "<<
|
|
|
- "rule_name="<<*ruleName<<",<<"
|
|
|
- "directive_id="<<iDirectiveID<<",<<"
|
|
|
- "directive_info="<<directiveInfo<<",<<"
|
|
|
- "directive_result="<<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+");";
|
|
|
- const char* sql=s_sql.c_str();
|
|
|
- robot::common::Sqlite3helper::Instance().update(sqlite,sql);
|
|
|
- /********************向表中插入一条记录 end *******************************/
|
|
|
-
|
|
|
- robot::common::Sqlite3helper::Instance().close(sqlite);
|
|
|
- return 1;
|
|
|
-}
|
|
|
-
|
|
|
-int Decision::InsertLocationMap(float fLocationLon1,
|
|
|
- float fLocationLat1,
|
|
|
- float fLocationLon2,
|
|
|
- float fLocationLat2,
|
|
|
- float fLocationX1,
|
|
|
- float fLocationY1,
|
|
|
- const char *mapId,
|
|
|
- float fLocationX2,
|
|
|
- float fLocationY2){
|
|
|
-
|
|
|
- LOG(INFO)<<Name()<<"insert into location_map "<<
|
|
|
- "location_lon_1="<<fLocationLon1<<","<<
|
|
|
- "location_lat_1="<<fLocationLat1<<","<<
|
|
|
- "location_lon_2="<<fLocationLon2<<","<<
|
|
|
- "location_lat_2="<<fLocationLat2<<","<<
|
|
|
- "location_location_X_1="<<fLocationX1<<","<<
|
|
|
- "location_location_Y_2="<<fLocationY1<<","<<
|
|
|
- "map_id="<<*mapId<<","<<","<<
|
|
|
- "location_X_2="<<fLocationX2<<","<<
|
|
|
- "location_Y_2="<<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+" \
|
|
|
- );";
|
|
|
- const char* sql=s_sql.c_str();
|
|
|
- robot::common::Sqlite3helper::Instance().update(sqlite,sql);
|
|
|
- /********************向表中插入一条记录 end *******************************/
|
|
|
-
|
|
|
- robot::common::Sqlite3helper::Instance().close(sqlite);
|
|
|
- return 1;
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-int Decision::InsertLocationRuleInfo(const char *ruleName,
|
|
|
- int iLocationID,
|
|
|
- double dLocationLon,
|
|
|
- double dLocationLat,
|
|
|
- double dLocationHeight,
|
|
|
- float fLocationSpeed){
|
|
|
- LOG(INFO)<<Name()<<"insert into location_rule_info "<<
|
|
|
- "rule_name="<<*ruleName<<","<<
|
|
|
- "location_id="<<iLocationID<<","<<
|
|
|
- "location_lon="<<dLocationLon<<","<<
|
|
|
- "location_lat="<<dLocationLat<<","<<
|
|
|
- "location_height="<<dLocationHeight<<","<<
|
|
|
- "location_speed="<<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=std::to_string(dLocationLon);
|
|
|
- std::string sLocationLat=std::to_string(dLocationLat);
|
|
|
- std::string sLocationHeight=std::to_string(dLocationHeight);
|
|
|
- std::string sLocationSpeed=std::to_string(fLocationSpeed);
|
|
|
- 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+" \
|
|
|
- );";
|
|
|
- const char* sql=s_sql.c_str();
|
|
|
- robot::common::Sqlite3helper::Instance().update(sqlite,sql);
|
|
|
- /********************向表中插入一条记录 end *******************************/
|
|
|
-
|
|
|
- robot::common::Sqlite3helper::Instance().close(sqlite);
|
|
|
- return 1;
|
|
|
-}
|
|
|
-
|
|
|
-int Decision::DeleteActionDirective(const char *ruleName){
|
|
|
- LOG(INFO)<<Name()<<"delete action_directive where rule_name="<<*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;
|
|
|
- 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 Decision::DeleteActionDirective(int iDirectiveID){
|
|
|
- LOG(INFO)<<Name()<<"delete action_directive where directive_id="<<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+";";
|
|
|
- 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 Decision::DeleteLocationMap(const char *mapID){
|
|
|
- LOG(INFO)<<Name()<<"delete location_map where map_id="<<*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;
|
|
|
- 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 Decision::DeleteLocationRuleInfo(const char *ruleName){
|
|
|
- LOG(INFO)<<Name()<<"delete location_rule_info where rule_name="<<*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;
|
|
|
- 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 Decision::DeleteLocationRuleInfo(int iLocationID){
|
|
|
- LOG(INFO)<<Name()<<"delete location_rule_info where location_id="<<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;
|
|
|
- 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;
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
|
|
|
|
|
|
}
|