site_message_handle.cpp 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // Created by Administrator on 2019/1/14.
  3. //
  4. #include "site_message_handle.h"
  5. #include "system_basic_info/SystemAnalysis.h"
  6. #include "common_tool.h"
  7. #include "ant.h"
  8. #include "event.h"
  9. site_message_handle::site_message_handle()
  10. {
  11. m_time_last_rec = 0;
  12. }
  13. /** 解析 分站发送过来的数据中(分站的信息数据)*/
  14. void site_message_handle::parse_data_locate_reader(int msgId,const message_siteinfo &loc ,bool bHistroy)
  15. {
  16. LOCATION_SYSTEM_BRANCH(LOCATION_SYSTEM_BRANCH_15);
  17. std::shared_ptr<site> pSite = sit_list::instance()->get(loc.m_site_id);
  18. //bool isErrorReader = false;
  19. if(pSite){
  20. //add_socket_to_list(dwConnID, reader_id, DEVICE_TYPE::DT_CARD_READER);
  21. LOCATION_SYSTEM_BRANCH(LOCATION_SYSTEM_BRANCH_16);
  22. }else{
  23. pSite = std::make_shared<site>();
  24. pSite->m_id = loc.m_site_id;
  25. LOCATION_SYSTEM_BRANCH(LOCATION_SYSTEM_BRANCH_17);
  26. }
  27. // 接收数据时间
  28. pSite->m_rec_time = time(NULL);
  29. m_time_last_rec = pSite->m_rec_time; // 更新最后信号时间
  30. // 分站时间戳
  31. pSite->m_tick_count = loc.m_time_stamp;
  32. // 分站时间
  33. // 7字节 从第一个字节开始,分别表示秒、分、时、天、周、月、年
  34. struct tm reader_time;
  35. reader_time.tm_sec = loc.m_sec;
  36. reader_time.tm_min = loc.m_min;
  37. reader_time.tm_hour = loc.m_hour;
  38. reader_time.tm_mday = loc.m_day;
  39. reader_time.tm_wday = loc.m_week;
  40. reader_time.tm_mon = loc.m_mon - 1;
  41. reader_time.tm_year = loc.m_year + 100; // + 2000 - 1900
  42. pSite->m_time = mktime(&reader_time);
  43. //改为大小分站信息,最高位第7位表示大小分站,1表示大分站,0表示小分站
  44. //高6位表示分站(大或小)在大分站的左侧或右侧,1代表在大分站的左侧,0表示在大分站的右侧
  45. //高5位预留位,用于区分是读卡分站还是大小分站
  46. uint8_t reader_type = loc.m_site_relation >>7; //大小分站的区别
  47. uint8_t reader_dir = (loc.m_site_relation >>6)&0x01;
  48. uint8_t reader_type_locate = (loc.m_site_relation >>5)&0x01; //大小分站与读卡分站的区别
  49. uint8_t relay_counts = loc.m_site_relation&0x0F;
  50. pSite->m_reader_dir = reader_dir;
  51. pSite->m_relay_counts = relay_counts;
  52. reader_power_battery_alarm(loc.m_site_id,loc.m_site_power);
  53. log_info("id:%d, n:%d, %.2d-%.2d-%.2d %.2d:%.2d:%.2d, sta: %d,reader_power: %d"
  54. ",reader_type: %d,is_big_reader: %d,is_left: %d, counts: %d",
  55. loc.m_site_id, loc.m_time_stamp, loc.m_year, loc.m_mon, loc.m_day\
  56. , loc.m_hour, loc.m_min,loc.m_sec\
  57. , loc.m_site_state,loc.m_site_power,reader_type_locate,reader_type,reader_dir,relay_counts);/*tep:%d,*/
  58. }
  59. void site_message_handle::reader_power_battery_alarm(unsigned int site_id, int powerType)
  60. {
  61. std::shared_ptr<site> pSite = sit_list::instance()->get(site_id);
  62. if (pSite == nullptr || !pSite->m_needpower_alarm)
  63. {
  64. return ;//如果分站不需要电池供电告警,
  65. }
  66. if (powerType != pSite->m_powerType && pSite->m_powerType == 1)
  67. {
  68. //交流电 变成直流电(掉电),发送警告
  69. event_tool::instance()->handle_event(site_id,ET_READER_POWER_BY_BATTERY,0,powerType,true);
  70. }
  71. else if (powerType != pSite->m_powerType && pSite->m_powerType != 1)
  72. {
  73. //直流电 变成交流电,取消警告
  74. event_tool::instance()->handle_event(site_id,ET_READER_POWER_BY_BATTERY,0,powerType,false);
  75. }
  76. log_info("[event warning: reader power supply by battery] reader_id: Power %d->%d.",site_id,pSite->m_powerType,powerType);
  77. pSite->m_powerType = powerType;
  78. }