module_motionless_persion.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #ifndef MODULE_MOTIONLESS_PERSION_H
  2. #define MODULE_MOTIONLESS_PERSION_H
  3. /**
  4. * @brief 简要说明
  5. * @author 戴月腾
  6. * @date 2019-01-12
  7. */
  8. #include"module_singleton_base.h"
  9. #include"module_i_thread.h"
  10. #include"card.h"
  11. #include"config_file.h"
  12. /**
  13. * @brief 一、硬件输出的状态
  14. 当完全静止时人卡会连续发送 30 次定位数据,在该定位数据中的加速度状态为 0;发送
  15. 完这一系列的定位数据之后进入休眠状态,不再发送任何定位数据。
  16. 当人卡从静止切换到运动状态会在毫秒级完成。然后 2 秒后把定位数据发上来,此时加
  17. 速度状态为 1(运动状态)。
  18. 二、处理逻辑
  19. 当连续收到 X(X 可以配置,X 建议不小于 10)次静止状态定位数据之后才认为完全静止。
  20. 经过 Y(Y 可以配置)秒之后开始告警,只要收到运动状态的定位数据就认为非静止立刻取消
  21. 告警
  22. */
  23. class module_motionless_persion : public i_thread, public singleton_base<module_motionless_persion>
  24. {
  25. private:
  26. friend class singleton_base<module_motionless_persion>;
  27. module_motionless_persion()
  28. {
  29. }
  30. int _acc_0count_limit;
  31. int _acc_seconds_limit;
  32. void run()
  33. {
  34. auto cardlist = card_list::instance()->m_map;
  35. auto iter_m_map=cardlist.begin();
  36. for(;iter_m_map!=cardlist.end();++iter_m_map)
  37. {
  38. deal_alarm(iter_m_map->second);
  39. }
  40. }
  41. void deal_alarm(std::shared_ptr<card_location_base>& card_ptr);
  42. public:
  43. void init(config_file& config)
  44. {
  45. sleep_ms = std::stoi(config.get("service.motionless_thread_sleep_ms","5000"));
  46. _acc_0count_limit = std::stoi(config.get("service.motionless_acc_0count_limit","20"));
  47. _acc_seconds_limit = std::stoi(config.get("service.motionless_acc_seconds_limit","120"));
  48. }
  49. void on_enter(std::shared_ptr<card_location_base> card_ptr, int index);
  50. void on_hover(std::shared_ptr<card_location_base> card_ptr, int index);
  51. void on_leave(std::shared_ptr<card_location_base> card_ptr, int index);
  52. };
  53. #endif // MODULE_MOTIONLESS_PERSION_H