1
0

module_motionless_persion.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #include"module_motionless_persion.h"
  2. #include"common_tool.h"
  3. #include"log.h"
  4. #include"area.h"
  5. #include"event.h"
  6. #include"tool_time.h"
  7. #include"area_business.h"
  8. struct motionless_data:business_data
  9. {
  10. motionless_data()
  11. {
  12. m_acc_0count=0;
  13. m_acc_start_time=0;
  14. }
  15. ///;检测到多少次之后定位完全静止
  16. std::atomic<int> m_acc_0count;
  17. ///检测到多久之后告警
  18. time_t m_acc_start_time;
  19. };
  20. void module_motionless_persion::on_enter(std::shared_ptr<card_location_base> card_ptr, int index)
  21. {
  22. auto area_hover_ptr = card_ptr->get_area_hover();
  23. if(!area_hover_ptr)
  24. {
  25. log_error("if(!area_hover_ptr)==true");
  26. return;
  27. }
  28. area_hover_ptr->m_data[index] = std::make_shared<motionless_data>();
  29. }
  30. void module_motionless_persion::on_hover(std::shared_ptr<card_location_base> card_ptr, int index)
  31. {
  32. auto area_hover_ptr = card_ptr->get_area_hover();
  33. if(!area_hover_ptr)
  34. {
  35. log_error("if(!area_hover_ptr)==true");
  36. return;
  37. }
  38. auto ptr = static_cast<motionless_data*>(area_hover_ptr->m_data[index].get());
  39. if(0 == static_cast<int>(card_ptr->m_acc))
  40. {
  41. ptr->m_acc_0count++;
  42. }
  43. else
  44. {
  45. ptr->m_acc_0count=0;
  46. }
  47. }
  48. void module_motionless_persion::on_leave(std::shared_ptr<card_location_base> card_ptr, int index)
  49. {
  50. auto area_hover_ptr = card_ptr->get_area_hover();
  51. if(!area_hover_ptr)
  52. {
  53. log_error("if(!area_hover_ptr)==true");
  54. return;
  55. }
  56. uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
  57. event_tool::instance()->handle_event(OT_CARD, ET_CARD_MOTIONLESS, id, 0, 0, false);
  58. area_hover_ptr->m_data[index] = std::make_shared<motionless_data>();
  59. }
  60. void module_motionless_persion::deal_alarm(std::shared_ptr<card_location_base>& card_ptr)
  61. {
  62. auto area_hover_ptr = card_ptr->get_area_hover();
  63. if(!area_hover_ptr)
  64. {
  65. log_error("if(!area_hover_ptr)==true");
  66. return;
  67. }
  68. auto arr = area_hover_ptr->m_data;
  69. int index = 1;
  70. if(arr.size()<2 || !arr[index])
  71. {
  72. return;
  73. }
  74. auto ptr = static_cast<motionless_data*>(area_hover_ptr->m_data[index].get());
  75. if(ptr->m_acc_0count >= _acc_0count_limit)
  76. {
  77. ptr->m_acc_0count = _acc_0count_limit;
  78. if(0 == ptr->m_acc_start_time)
  79. {
  80. ptr->m_acc_start_time = tool_time::now_to_seconds();
  81. }
  82. }
  83. else
  84. {
  85. ptr->m_acc_start_time=0;
  86. }
  87. bool is_alarm = (0 != ptr->m_acc_start_time
  88. &&tool_time::elapse_seconds(ptr->m_acc_start_time)> _acc_seconds_limit);
  89. uint64_t id = tool_other::type_id_to_u64(card_ptr->m_type, card_ptr->m_id);
  90. event_tool::instance()->handle_event(OT_CARD, ET_CARD_MOTIONLESS, id, 0, 0, is_alarm);
  91. }