123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721 |
- #include "trm_drivingface_module.h"
- #include "log.h"
- #include "three_rates_impl.h"
- #include "common_data.h"
- #include <string>
- std::shared_ptr<drivingface_card> trm_drivingface_module::get_drivingfase_card(std::string card_id)
- {
- MAP_DRIVINGFACE_CARD::iterator it = mp_drivingface_card_list.find(card_id);
- if (it == mp_drivingface_card_list.end())
- {
- return nullptr;
- }
- return it->second;
- }
- std::shared_ptr<drivingface_card> trm_drivingface_module::get_drivingfase_card(uint64_t drivingface_id)
- {
- for (auto it : mp_drivingface_card_list)
- {
- if (nullptr != it.second && it.second->m_drivingface_id == drivingface_id)
- {
- return it.second;
- }
- }
- return nullptr;
- }
- //移除掘进面
- void trm_drivingface_module::remove_drivingface(int drivingface_id )
- {
- for (MAP_DRIVINGFACE_CARD::iterator it = mp_drivingface_card_list.begin() ; it != mp_drivingface_card_list.end() ;++it)
- {
- if (nullptr != it->second && (int)it->second->m_drivingface_id == drivingface_id)
- {
- mp_drivingface_card_list.erase(it);
- logn_info(2,"remove_drivingface:%d ",drivingface_id);
- break;
- }
- }
- mp_simulate_reader_list.erase(drivingface_id);
- }
- int trm_drivingface_module::init_all(bool status)
- {
- set_restart(status);
- init_reader();
- init_drivingface_card();
- init_drivingface_ref_points();
- return 0;
- }
- int trm_drivingface_module::init_reader()
- {
- const char* sql = "select reader_id from dat_reader where enable_simulate_card=1;";
- std::string error = "";
- MYSQL_RES* pRes = nullptr;
- MYSQL_ROW row;
- pRes = sDBConnPool.Query(sql,error);
- if(nullptr == pRes){
- logn_error(2,"init_reader Query exist error, error: %s", error.c_str());
- return -1;
- }
- std::shared_ptr<reader_info> reader_ptr = nullptr;
- while(NULL != (row = mysql_fetch_row(pRes))){
- uint32_t reader_id = atoi(row[0]==NULL?0:row[0]);
- auto it = mp_simulate_reader_list.find(reader_id);
- if(it!=mp_simulate_reader_list.end()){
- reader_ptr = it->second;
- }else{
- reader_ptr = std::make_shared<reader_info>();
- mp_simulate_reader_list.insert({reader_id,reader_ptr});
- }
- reader_ptr->m_reader_id = reader_id;
- }
- mysql_free_result(pRes);
- return 0;
- }
- /*
- * 初始化掘进机卡信息
- *
- * 参数
- * 无
- *
- * 返回值
- * 返回查询记录条数
- *
- */
- int trm_drivingface_module::init_drivingface_card(const std::string & sz_drivingface_id/* = "-1"*/)
- {
- std::string sql = "select c.card_id, b.base_point_x, b.base_point_y, b.base_point_z, b.drivingface_id, d.area_id, a.warning_threshold, \
- a.over_count_num, d.map_id, b.drivingface_type, a.small_reader_id, a.big_reader_id, a.schedule_work_time, \
- a.schedule_tunnelling_times, b.drifting_footage_unit, c.dept_id, a.vehicle_id, a.relay_small_reader_id \
- from dat_drivingface_vehicle a, dat_drivingface b, dat_vehicle_extend c ,dat_work_face d\
- where a.vehicle_id = c.vehicle_id and a.drivingface_id = b.drivingface_id and a.drivingface_id = d.work_face_id";
- if (std::atoi(sz_drivingface_id.c_str()) > 0 )
- {
- sql += " and a.drivingface_id = " + sz_drivingface_id ;
- }
- sql.append(";");
- std::string error;
- YADB::CDBResultSet dbRes;
- sDBConnPool.Query(sql.c_str(),dbRes,error);
- int nCount = dbRes.GetRecordCount(error);
- if(nCount > 0){
- while(dbRes.GetNextRecod(error)){
- std::string card_id = "";
- dbRes.GetField("card_id",card_id,error);
- double bpx = 0.0;
- dbRes.GetField("base_point_x",bpx,error);
- double bpy = 0.0;
- dbRes.GetField("base_point_y",bpy,error);
- double bpz = 0.0;
- dbRes.GetField("base_point_z",bpz,error);
- int id = 0;
- dbRes.GetField("drivingface_id",id,error);
- int area_id = 0;
- dbRes.GetField("area_id",area_id,error);
- double wth = 0.0;
- dbRes.GetField("warning_threshold",wth,error);
- int ocn = 0;
- dbRes.GetField("over_count_num",ocn,error);
- int map_id = 0;
- dbRes.GetField("map_id",map_id,error);
- int dt = 0;
- dbRes.GetField("drivingface_type",dt,error);
- int sri = 0;
- dbRes.GetField("small_reader_id",sri,error);
- int bri = 0;
- dbRes.GetField("big_reader_id",bri,error);
- int swt = 0;
- dbRes.GetField("schedule_work_time",swt,error);
- double stt = 0.0;
- dbRes.GetField("schedule_tunnelling_times",stt,error);
- double dfu = 0.0;
- dbRes.GetField("drifting_footage_unit",dfu,error);
- int dept_id = 0;
- dbRes.GetField("dept_id",dept_id,error);
- int v_id = 0;
- dbRes.GetField("vehicle_id",v_id,error);
- int rsr = 0;
- dbRes.GetField("relay_small_reader_id",rsr,error);
- std::shared_ptr<drivingface_card> pdc = get_drivingfase_card(id);
- if(nullptr == pdc)
- {
- pdc = std::make_shared<drivingface_card>();
- mp_drivingface_card_list.insert({card_id,pdc});
- }
- pdc->m_card_id = card_id;
- pdc->m_drivingface_id = id;
- pdc->m_vehicle_id = v_id;
- pdc->m_area_id = area_id;
- pdc->m_relay_small_reader_id = rsr;
- pdc->m_locate_small_reader_id = sri;
- pdc->m_big_reader_id = bri;
- pdc->m_dept_id = dept_id;
- pdc->m_schedule_tunnelling_times = stt;
- pdc->m_schedule_work_times = swt;
- pdc->m_drifting_footage_unit = dfu;
- pdc->x = bpx;
- pdc->y = bpy;
- pdc->z = bpz;
- }
- }
- logn_info(2,"Init drivingface:%s Count=%d",sz_drivingface_id.c_str(),nCount);
- return nCount;
- }
- /*
- * 初始化掘进机-掘进面偏移数据
- *
- * 参数
- * 无
- *
- * 返回值
- * 返回查询记录条数
- *
- */
- int trm_drivingface_module::init_drivingface_ref_points(const std::string & sz_drivingface_id/* = "-1"*/)
- {
- std::string sql = "select drivingface_id,idx,base_x,base_y,base_z,offset from dat_drivingface_ref_point";
- if (std::atoi(sz_drivingface_id.c_str()) > 0 )
- {
- sql += " where drivingface_id = " + sz_drivingface_id ;
- }
- sql += " order by drivingface_id asc,idx asc;";
- std::string error;
- YADB::CDBResultSet dbRes;
- sDBConnPool.Query(sql.c_str(),dbRes,error);
- int nCount = dbRes.GetRecordCount(error);
- if(nCount > 0)
- {
- struct sref_point
- {
- std::vector<point> po_list;
- double fOffset;
- };
- std::map<int,sref_point> map_points ;
- while(dbRes.GetNextRecod(error))
- {
- int v_idx = 0;
- dbRes.GetField("idx",v_idx,error);
- int driv_id = 0;
- dbRes.GetField("drivingface_id",driv_id,error);
- int db_offset = 0;
- dbRes.GetField("offset",db_offset,error);
- double x = 0;
- dbRes.GetField("base_x", x, error);
- double y = 0;
- dbRes.GetField("base_y", y, error);
- double z = 0;
- dbRes.GetField("base_z", z, error);
- point po(x,y,z);
- auto it = map_points.find(driv_id);
- if (it == map_points.end())
- {
- sref_point v ;
- v.po_list.push_back(po);
- v.fOffset = db_offset;
- map_points[driv_id] = v;
- continue;
- }
- sref_point & t_ref = map_points[driv_id];
- if ( v_idx > (int)t_ref.po_list.size())
- {
- t_ref.po_list.push_back(po);
- t_ref.fOffset = db_offset;
- }
- }
- for (auto &it : map_points)
- {
- std::shared_ptr<drivingface_card> drivingface_ptr = get_drivingfase_card((uint64_t)it.first);
- if (nullptr != drivingface_ptr)
- {
- drivingface_ptr->m_vt_ref_points = it.second.po_list;
- drivingface_ptr->m_fOffset = it.second.fOffset;
- }
- }
- }
- logn_info(2,"init_drivingface_ref_points: drivingface=%s sql=%s",sz_drivingface_id.c_str(),sql.c_str());
- return nCount;
- }
- /*
- * 如果采集重启了,需要从数据库中查找最新的最大掘进距离及坐标信息
- *
- * 参数
- * pCard 卡信息
- * 返回值
- * 正常返回0,否则返回其他值
- *
- * */
- int trm_drivingface_module::init_drivingface_nearest_info(std::shared_ptr<drivingface_card> pCard)
- {
- //如果采集重启了,需要从数据库中加载历史最大掘进距离及坐标信息
- if(nullptr != pCard && pCard->m_restart)
- {
- char sql[2000] = {0};
- snprintf(sql,sizeof(sql),
- "select start_x,start_y from his_regular_cycle_detail where start_time=(select max(start_time) \
- from his_regular_cycle_detail where work_face_id =%d) and work_face_id =%d;",
- (int)pCard->m_drivingface_id,
- (int)pCard->m_drivingface_id
- );
- std::string error = "";
- MYSQL_ROW row;
- MYSQL_RES* pRes = nullptr;
- pRes = sDBConnPool.Query(sql,error);
- if(nullptr == pRes){
- logn_error(2,"init_drivingface_nearest_info Query exist error, error: %s", error.c_str());
- return -1;
- }
- while(NULL != (row = mysql_fetch_row(pRes))){
- double x = row[0]==NULL?0:atof(row[0]);
- double y = row[1]==NULL?0:atof(row[1]);
- pCard->m_max_point.set(x,y);
- }
- mysql_free_result(pRes);
- //保存基准点的坐标
- double map_scale = G_CommonData->m_map_scale;
- point p(pCard->x,pCard->y);
- int idx = pCard->m_vt_ref_points.size();
- if (idx > 0 )
- {
- p.set(pCard->m_vt_ref_points[idx - 1]);
- if (idx > 1 && pCard->m_total_ref_point_dist < ZERO_PRECISION )
- {
- double d = 0.0;
- point tp(pCard->m_vt_ref_points[0]);
- for (int i = 1; i <= idx ; ++i)
- {
- point ttp(pCard->m_vt_ref_points[i]);
- d += tp.dist(ttp) * map_scale;
- }
- pCard->m_total_ref_point_dist = d;
- logn_info(2,"[init_drivingface_recently_info] drivingface_id: %d, trpd: %.4f",pCard->m_drivingface_id,pCard->m_total_ref_point_dist);
- }
- }
- //如果数据库中无最大距离和位置数据,则根据当前卡计算并保存
- //如果有数据,则保存最大距离信息
- if(pCard->m_max_point.empty())
- {
- pCard->m_max_point.set(pCard->x, pCard->y);
- }
- pCard->m_max_distance = pCard->m_total_ref_point_dist + pCard->m_max_point.dist(p) * map_scale + pCard->m_fOffset;
- pCard->m_restart = false;
- }
- return -1;
- }
- int trm_drivingface_module::deal_drivingface_service(std::shared_ptr<drivingface_card> pCard,std::shared_ptr<card_pos> p_tcp_card)
- {
- if(nullptr == pCard || nullptr == p_tcp_card)
- {
- return -1;
- }
- //更新机器信息
- pCard->x = p_tcp_card->x;
- pCard->y = p_tcp_card->y;
- pCard->m_rec_time = p_tcp_card->rec_time;
- //确保掘进机已读取最后一次的位置及最大距离
- init_drivingface_nearest_info(pCard);
- time_t cur_time = time(NULL);
- time_point tp;
- tp.m_t = cur_time;
- tp.x = pCard->x;
- tp.y = pCard->y;
- if(!tp.empty())
- {
- pCard->m_vt_points.push_back(tp);
- //记录时刻的位置
- deal_drivingface_real_distance(pCard,tp);
- //保存掘进米数
- size_t len = pCard->m_vt_points.size();
- if(cur_time - pCard->m_vt_points[0].m_t >= 60 && len > 0)
- {
- double sum_x = 0.0, sum_y = 0.0;
- for(size_t i = 0; i < len;++i)
- {
- sum_x += pCard->m_vt_points[i].x;
- sum_y += pCard->m_vt_points[i].y;
- }
- deal_drivingface_regular_cycle(pCard,point(sum_x/len,sum_y/len,0));
- }
- }
- return 0;
- }
- /*
- * 正常正规循环率处理逻辑
- * */
- int trm_drivingface_module::deal_drivingface_regular_cycle(std::shared_ptr<drivingface_card> pCard, const point& p)
- {
- save_drivingface_regular_cycle(pCard,p);
- return 0;
- }
- /*
- * 超时正规循环率处理逻辑
- * */
- int trm_drivingface_module::deal_drivingface_regular_cycle()
- {
- time_t cur_time = time(NULL);
- std::string day_end_time = "";
- day_end_time = tools::time_tools::time_t2string(cur_time);
- day_end_time = day_end_time.substr(11);
- for(auto it : mp_drivingface_card_list)
- {
- int len = (int)it.second->m_vt_points.size();
- if(len > 0)
- {
- if(cur_time - it.second->m_vt_points[len-1].m_t > 120 || day_end_time=="23:59:59")
- {
- double sum_x = 0.0, sum_y = 0.0;
- for(int i = 0;i < len ; ++i)
- {
- sum_x += it.second->m_vt_points[i].x;
- sum_y += it.second->m_vt_points[i].y;
- }
- if("23:59:59" == day_end_time){
- logn_info(2,"deal_drivingface_regular_cycle deal cross-day problem");
- }
- save_drivingface_regular_cycle(it.second,point(sum_x / len,sum_y / len));
- }
- }
- }
- return 0;
- }
- /*
- * 正常坐标同步处理:保存1分钟的掘进距离和时间信息到his_draw_position表内,用于web端画实时掘进曲线图使用
- *
- * 参数
- * pCard :掘进机卡
- * p :坐标
- * 返回值
- * 正常返回0,否则返回其他值
- *
- * */
- int trm_drivingface_module::deal_drivingface_real_distance(std::shared_ptr<drivingface_card> pCard,const point& p)
- {
- char meta_sql[100] = {'\0'};
- double cur_distance = 0.0;
- double map_scale = G_CommonData->m_map_scale;
- int idx = pCard->m_vt_ref_points.size()-1;
- if (idx < 0)
- {
- logn_error(2,"[deal_drivingface_real_distance] drivingface_id: %d no ref point info.",pCard->m_drivingface_id);
- return -1;
- }
- point base_point;
- base_point.set(pCard->m_vt_ref_points[idx]);
- cur_distance = pCard->m_total_ref_point_dist + p.dist(base_point) * map_scale + pCard->m_fOffset;
- logn_info(2,"[deal_drivingface_real_distance] card_id: %s, cur_distance: %.3f, offset: %.3f, x: %.3f, y: %.3f, drivingface_id: %d, ref_totals: %d, ref_idx: %d, ref_x: %.3f, ref_y: %.3f",
- pCard->m_card_id.c_str(),cur_distance,pCard->m_fOffset,
- pCard->x,pCard->y,
- pCard->m_drivingface_id,pCard->m_vt_ref_points.size(),
- idx,pCard->m_vt_ref_points[idx].x,pCard->m_vt_ref_points[idx].y
- );
- time_t cur_time = time(NULL);
- if (pCard->m_b_first_record)
- {
- pCard->m_b_first_record = false;
- pCard->m_str_record = "";
- pCard->m_record_cycle_start_time = cur_time;
- pCard->m_record_avg_dist += cur_distance;
- pCard->m_record_max_dist = pCard->m_record_min_dist = cur_distance;
- pCard->m_record_totals++;
- snprintf(meta_sql,sizeof(meta_sql),"%s,%.4f;",tools::time_tools::time_t2string(cur_time).c_str(),cur_distance);
- pCard->m_str_record = meta_sql;
- }
- else
- {
- snprintf(meta_sql,sizeof(meta_sql),"%s,%.4f;",tools::time_tools::time_t2string(cur_time).c_str(),cur_distance);
- std::string r = meta_sql;
- pCard->m_str_record += r;
- pCard->m_record_avg_dist += cur_distance;
- pCard->m_record_totals++;
- pCard->m_record_max_dist = pCard->m_record_max_dist > cur_distance ? pCard->m_record_max_dist : cur_distance;
- pCard->m_record_min_dist = pCard->m_record_min_dist < cur_distance ? pCard->m_record_min_dist : cur_distance;
-
- //如果有一分钟的数据,则保存结果
- if (cur_time - pCard->m_record_cycle_start_time >= 60)
- {
- if (pCard->m_record_totals>0)
- {
- pCard->m_record_avg_dist /= pCard->m_record_totals;
- }
- char t_sql_log[8192];
- memset(t_sql_log,0,8192*sizeof(char));
- sprintf(t_sql_log,"insert ignore into his_draw_position(work_face_id,write_time,avg_distance,max_distance,min_distance) values('%d','%s',%.4f,%.4f,%.4f);",
- (int)pCard->m_drivingface_id,
- tools::time_tools::time_t2string(cur_time).c_str(),
- pCard->m_record_avg_dist,
- pCard->m_record_max_dist,
- pCard->m_record_min_dist);
- std::string error = "";
- if (sDBConnPool.ExecuteSql(t_sql_log,error ) < 0 )
- {
- logn_error(2,"deal_drivingface_real_distance Failed to ExecuteSql:%s,Err=%s\n", t_sql_log, error.c_str());
- }
- pCard->m_str_record = "";
- pCard->m_record_cycle_start_time = cur_time;
- pCard->m_record_avg_dist = pCard->m_record_max_dist = 0.0;
- pCard->m_record_min_dist = 999999.9;
- pCard->m_record_totals = 0;
- }
- }
- return 0;
- }
- /*
- * 超时检查处理:保存1分钟的掘进距离和时间信息到his_draw_position表内,用于web端画实时掘进曲线图使用
- *
- * 参数
- * 无
- * 返回值
- * 正常返回0,否则返回其他值
- *
- * */
- int trm_drivingface_module::deal_drivingface_real_distance()
- {
- for(auto it : mp_drivingface_card_list)
- {
- time_t cur_time = time(NULL);
- std::shared_ptr<drivingface_card> card = it.second;
- //b.当前时间大于开始记录的起始时间2分钟;
- //c.卡的记录的内容长度大于0
- if(cur_time - it.second->m_record_cycle_start_time >= 120 && it.second->m_str_record.length() > 0)
- {
- //计算平均距离
- if (it.second->m_record_totals > 0)
- {
- it.second->m_record_avg_dist /= it.second->m_record_totals;
- }
- if (it.second->m_record_max_dist < 1E-4 && it.second->m_record_max_dist < it.second->m_record_avg_dist)
- {
- it.second->m_record_max_dist = it.second->m_record_avg_dist;
- }
- if (it.second->m_record_min_dist >= 999999.9 && it.second->m_record_min_dist > it.second->m_record_avg_dist)
- {
- it.second->m_record_min_dist = it.second->m_record_avg_dist;
- }
- char sql[8192] = {'\0'};
- sprintf(sql,"insert ignore into his_draw_position(work_face_id,write_time,avg_distance,max_distance,min_distance) values('%d','%s',%.4f,%.4f,%.4f);",
- (int)it.second->m_drivingface_id,
- tools::time_tools::time_t2string(cur_time).c_str(),
- it.second->m_record_avg_dist,
- it.second->m_record_max_dist,
- it.second->m_record_min_dist);
- std::string log = "";
- std::string error = "";
- if(sDBConnPool.ExecuteSql(sql,error) < 0){
- logn_error(2,"deal_drivingface_real_distance null param Failed to ExecuteSql:%s,Err=%s\n", sql, error.c_str());
- }
- it.second->m_str_record = "";
- it.second->m_record_cycle_start_time = 0;
- it.second->m_b_first_record = true;
- it.second->m_record_avg_dist = it.second->m_record_max_dist = 0.0;
- it.second->m_record_min_dist = 999999.9;
- it.second->m_record_totals = 0;
- }
- }
- return 0;
- }
- /*
- * 将掘进机的最大掘进距离和坐标保存到数据库中
- *
- * 参数
- * pCard 掘进机信息
- * p 当前传入的卡定位坐标
- *
- * 返回值
- * 正常返回0,否则返回其他值
- * */
- int trm_drivingface_module::save_drivingface_regular_cycle(std::shared_ptr<drivingface_card> pCard,const point& p)
- {
- if(pCard->m_drifting_footage_unit < 1E-4){
- logn_error(2,"save_drivingface_regular_cycle: drivingface:%d-%s input params(drifting_footage_unit) is illegal"
- ,pCard->m_drivingface_id,pCard->m_card_id.c_str());
- return -1;
- }
- //处理时间
- time_t cur_time = time(NULL);
- std::string start_time = tools::time_tools::time_t2string(pCard->m_vt_points[0].m_t);
- std::string end_time = tools::time_tools::time_t2string(cur_time);
- //计算本次定位点p与基准点的距离
- int idx = pCard->m_vt_ref_points.size()-1;
- if (idx < 0)
- {
- logn_error(2,"[regular_cycle] drivingface_id: %d no ref point info.\n",pCard->m_drivingface_id);
- return -1;
- }
- point base_point(pCard->m_vt_ref_points[idx]);
- double cur_distance = 0.0;
- cur_distance = pCard->m_total_ref_point_dist + p.dist(base_point) * G_CommonData->m_map_scale + pCard->m_fOffset;
- logn_info(2,"[regular_cycle] card_id: %s, drivingface_id: %d, cur_distance: %.4f, max_distance: %.4f, distanceToRef: %.4f, offset: %.4f, totalRefdist: %.4f, x: %.4f ,y: %.4f"
- ,pCard->m_card_id.c_str(), pCard->m_drivingface_id,cur_distance,pCard->m_max_distance,p.dist(base_point)* G_CommonData->m_map_scale
- ,pCard->m_fOffset,pCard->m_total_ref_point_dist,p.x, p.y);
- //计算本次定位点与基准点的距离
- if(cur_distance > pCard->m_max_distance)
- {
- //计算排数
- double row_space = 0.0;
- row_space = (cur_distance - pCard->m_max_distance);
- //计算排数信息
- double schedule_value = 0.0;
- schedule_value = get_drivingface_schedule_value(pCard->m_drivingface_id,2);
- double sv = schedule_value*pCard->m_drifting_footage_unit;
- if (abs(sv) < 1E-4)
- {
- sv = 8.0;
- }
- if (row_space > sv*1.5)
- {
- smooth_row_spacing(row_space,sv);
- }
- double row_spacing = row_space;
- //保存最大进尺和对应的坐标
- pCard->m_max_distance = cur_distance;
- pCard->m_max_point.set(p);
- //数据入库
- char sql[500] = {'\0'};
- snprintf(sql,
- sizeof(sql),
- "insert ignore into his_regular_cycle_detail(work_face_id,detail_type,start_time,end_time,detail_value,schedule_value,dept_id,start_x,start_y) values(%d,%d,'%s','%s',%.4f,%.4f,%d,%.3f,%.3f);",
- (int)pCard->m_drivingface_id,
- 2,
- start_time.c_str(),
- end_time.c_str(),
- row_spacing,
- schedule_value,
- (int)pCard->m_dept_id,
- p.x,p.y);
- std::string error = "";
- if(sDBConnPool.ExecuteSql(sql,error) < 0){
- logn_error(2,"save_drivingface_regular_cycle Failed to ExecuteSql:%s,Err=%s\n", sql, error.c_str());
- }
- }
- pCard->m_vt_points.resize(0);
- return 0;
- }
- /*
- * 平滑掘进机进尺的距离信息
- *
- * param
- * value 需要平滑的进尺距离
- * sv 掘进面计划进尺
- *
- */
- void trm_drivingface_module::smooth_row_spacing(double& value,const double& sv)
- {
- //debug_print_syslog(0,"[smooth_row_spacing] before smooth: value: %.4f , standard_value: %.4f",value,sv);
- int m = (int)value/((int)sv);
- double tmp_value = 0.0;
- tmp_value = value - m*sv;
- time_t s = time(NULL);
- struct tm * p = localtime(&s);
- if (p->tm_hour <= 12)
- {
- tmp_value = tmp_value/2;
- }
- //debug_print_syslog(0,"[smooth_row_spacing] after smooth: value: %.4f , standard_value: %.4f",tmp_value,sv);
- value = tmp_value;
- }
- double trm_drivingface_module::get_drivingface_schedule_value(const uint64_t& id,const uint8_t type)
- {
- double ret = 0.0;
- char sql[500] = {'\0'};
- std::string cur_time = tools::time_tools::time_t2string(time(NULL));
- snprintf(sql,sizeof(sql),"select workface_id,schedule_tunnelling_times from dat_workface_scheduling where schedule_date=date('%s') and workface_id=%d;",
- cur_time.c_str(),
- (int)id);
- MYSQL_RES* pRes = nullptr;
- MYSQL_ROW row;
- std::string error = "";
- pRes = sDBConnPool.Query(sql,error);
- if(nullptr == pRes){
- logn_error(2,"get_drivingface_schedule_value Query exist error, error: %s", error.c_str());
- return ret;
- }
- //uint64_t face_id = 0;
- while(NULL != (row = mysql_fetch_row(pRes))){
- //face_id = atoi(row[0] == NULL?0:row[0]);
- ret = atof(row[1]==NULL?0:row[1]);
- }
- mysql_free_result(pRes);
- return ret;
- }
|