123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- #include <string.h>
- #include "db/db_tool.h"
- #include "module_screen.h"
- #include "log.h"
- #include "common.h"
- #include <chrono>
- /*
- * @brief 更新大屏内显示所需人员id,区域id,部门id,电池电量状态等数据
- * @param 卡数据
- * @return 无
- * @note
- * @warning
- * @bug
- *
- * */
- void module_screen::do_write(const std::map<uint64_t, sys::_CARD_POS_> card_pos_list)
- {
- std::string p_stat = "";
- char item[200] = { 0 };
- for(auto it : card_pos_list)
- {
- memset(item, 0, 200*sizeof(char));
- // 电量状态0表示正常,1表示电量不足,
- snprintf(item, 200, "%d,%d,%d,%d,%d,%d;",it.second.ID, it.second.area_id, it.second.dept_id, (it.second.battery_stat), it.second.biz_stat, it.second.level_id);
- p_stat += std::string(item);
- }
- if(p_stat == ""){
- return;
- }
- log_info("[screen] stat info=%s", p_stat.c_str());
- char sql[4096] = {0};
- snprintf(sql, 4096, "update rt_screen_msg set person_stat='%s' where id=1;", p_stat.c_str());
- log_info("[screen] sql=%s", sql);
- db_tool::PushAsync(sql);
- }
- void module_screen::start()
- {
- m_exited = false;
- m_thread.reset(new std::thread(std::bind(&module_screen::run, this)));
- m_thread->detach();
- }
- void module_screen::run()
- {
- while(!m_exited){
- do_wellhead();
- std::this_thread::sleep_for(std::chrono::seconds(1));
- }
- }
- /*
- * @brief 更新井口人员数据,并更新电量低人员:小于等于30%
- * @param 无
- * @return 无
- * @note
- * @warning
- * @bug
- *
- * */
- void module_screen::do_wellhead()
- {
- std::lock_guard<std::mutex> lg(m_mtx);
- if(m_card_list.size() <= 0){
- return;
- }
- std::string sid = "";
- char buf[12] = {0};
- for(auto it = m_card_list.begin(); it != m_card_list.end();){
- if(time(NULL) - it->second.m_recv_time < 120){
- snprintf(buf, 12, "%ld,%d;", it->first, it->second.m_battery);
- sid += std::string(buf);
- it++;
- }else{
- m_card_list.erase(it++);
- }
- }
- char sql[4096] = {0};
- snprintf(sql, 4096, "update rt_screen_msg set wellhead_stat='%s' where id=1;", sid.c_str());
- log_info("[screen] sql=%s", sql);
- db_tool::PushAsync(sql);
- }
|