|
@@ -13,11 +13,19 @@ traffic_light_manager* traffic_light_manager::instance()
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
- * 加载红绿灯基础信息
|
|
|
+ * @breif
|
|
|
+ * 加载红绿灯基础信息
|
|
|
+ * @param
|
|
|
+ * int lid 红绿灯号
|
|
|
+ * @return
|
|
|
+ * 无
|
|
|
+ * @note
|
|
|
+ * @warning
|
|
|
+ * @bug
|
|
|
* */
|
|
|
void traffic_light_manager::init_light_from_db(int lid)
|
|
|
{
|
|
|
- std::string sql = "select light_id, lights_group_id, ip, x, y ,z, reader_id, state, port, physics_light_id, physics_light_direction, special_flag, stream_state from dat_light";
|
|
|
+ /*std::string sql = "select light_id, lights_group_id, ip, x, y ,z, reader_id, state, port, physics_light_id, physics_light_direction, special_flag, stream_state from dat_light";
|
|
|
if(0 == lid){
|
|
|
sql += ";";
|
|
|
}else{
|
|
@@ -72,15 +80,73 @@ void traffic_light_manager::init_light_from_db(int lid)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ logn_info(2, "sql:%s",sql.c_str());*/
|
|
|
+ std::string sql = "select light_id, lights_group_id, x, y, stream_state from dat_light";
|
|
|
+ if(0 == lid){
|
|
|
+ sql += ";";
|
|
|
+ }else{
|
|
|
+ sql += " where light_id = " + std::to_string(lid);
|
|
|
+ sql += ";";
|
|
|
+ }
|
|
|
+
|
|
|
+ std::string err = "";
|
|
|
+
|
|
|
+ YADB::CDBResultSet res;
|
|
|
+ sDBConnPool.Query(sql.c_str(), res, err);
|
|
|
+ int count = res.GetRecordCount(err);
|
|
|
+ if(count < 1){
|
|
|
+ log_error("增加或修改失败,error:%s", sql.c_str());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ while(res.GetNextRecod(err)){
|
|
|
+ int light_id = 0;
|
|
|
+ res.GetField("light_id", light_id, err);
|
|
|
+ int group_id = 0;
|
|
|
+ res.GetField("lights_group_id", group_id, err);
|
|
|
+ std::string ip = "";
|
|
|
+ res.GetField("ip", ip, err);
|
|
|
+ double x = 0.0, y = 0.0, z = 0.0;
|
|
|
+ res.GetField("x", x, err);
|
|
|
+ res.GetField("y", y, err);
|
|
|
+ int site_id = 0, state = 0, port = 0, phy_light_id = 0, phy_direction = 0, special = 0, stream = 0;
|
|
|
+ res.GetField("stream_state", stream, err);
|
|
|
+ traffic_light_ptr pl = find_light(light_id);
|
|
|
+ if(nullptr == pl){
|
|
|
+ pl = std::make_shared<traffic_light>(x, y, z, light_id, group_id, ip, state, port, phy_light_id, phy_direction, special, stream);
|
|
|
+ m_unmap_lights.insert(std::make_pair(light_id, pl));
|
|
|
+ }else{
|
|
|
+ pl->update(x, y , z, light_id, group_id, ip, state, port, phy_light_id, phy_direction, special, stream);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将红绿灯分配到对应组中
|
|
|
+ auto it_group = m_unmap_groups.find(pl->m_group_id);
|
|
|
+ if(it_group != m_unmap_groups.end())
|
|
|
+ {
|
|
|
+ it_group->second->m_vt_lights.push_back(pl);
|
|
|
+ pl->m_area_id = it_group->second->m_area_id;
|
|
|
+ pl->m_map_id = it_group->second->m_map_id;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
logn_info(2, "sql:%s",sql.c_str());
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
- * 加载红绿灯组基础信息
|
|
|
+ * @brief
|
|
|
+ * 加载红绿灯组基础信息
|
|
|
+ * @param
|
|
|
+ * int gid 红绿灯组id
|
|
|
+ * @return
|
|
|
+ * 无
|
|
|
+ * @note
|
|
|
+ * @warning
|
|
|
+ * @bug
|
|
|
+ *
|
|
|
* */
|
|
|
void traffic_light_manager::init_light_group_from_db(int gid)
|
|
|
{
|
|
|
- std::string sql = "select lights_group_id, x, y, z, scope, map_id, area_id, manual_control_time, light_auto_interval, up_stream_idx from dat_lights_group";
|
|
|
+ /*std::string sql = "select lights_group_id, x, y, z, scope, map_id, area_id, manual_control_time, light_auto_interval, up_stream_idx from dat_lights_group";
|
|
|
if(gid > 0){
|
|
|
sql += " where lights_group_id = " + std::to_string(gid);
|
|
|
}
|
|
@@ -127,7 +193,42 @@ void traffic_light_manager::init_light_group_from_db(int gid)
|
|
|
}
|
|
|
|
|
|
logn_info(2, "sql:%s",sql.c_str());
|
|
|
- output_upstreamidx();
|
|
|
+ output_upstreamidx();*/
|
|
|
+
|
|
|
+ std::string sql = "select lights_group_id, x, y, scope from dat_lights_group";
|
|
|
+ if(gid > 0){
|
|
|
+ sql += " where lights_group_id = " + std::to_string(gid);
|
|
|
+ }
|
|
|
+ sql += ";";
|
|
|
+
|
|
|
+ std::string err = "";
|
|
|
+ YADB::CDBResultSet res;
|
|
|
+
|
|
|
+ sDBConnPool.Query(sql.c_str(), res, err);
|
|
|
+ int count = res.GetRecordCount(err);
|
|
|
+ if(count < 1){
|
|
|
+ log_error("增加或修改失败,数据库中找不到:sql=%s", sql.c_str());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ while(res.GetNextRecod(err)){
|
|
|
+ int group_id = 0;
|
|
|
+ res.GetField("lights_group_id", group_id, err);
|
|
|
+ double x = 0.0, y = 0.0, z = 0.0, scope = 0.0;
|
|
|
+ res.GetField("x", x, err);
|
|
|
+ res.GetField("y", y, err);
|
|
|
+ res.GetField("scope", scope, err);
|
|
|
+ int map_id = 0, area_id = 0;
|
|
|
+ traffic_light_group_ptr pg = find_group(group_id);
|
|
|
+ if(nullptr == pg){
|
|
|
+ pg = std::make_shared<traffic_light_group>(x, y, 0.0, group_id, scope, 0, 0, 0);
|
|
|
+ m_unmap_groups.insert(std::make_pair(group_id, pg));
|
|
|
+ }else{
|
|
|
+ pg->update(x, y, z, group_id, scope, 0, 0, 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ logn_info(2, "sql:%s",sql.c_str());
|
|
|
}
|
|
|
|
|
|
void traffic_light_manager::init_light_group_path()
|