area_business_motionless_persion.cpp 3.0 KB

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