Browse Source

呼救逻辑修改,只支持如下情况

0001111111111111000000000001111111111111111
                           ^呼救

要求第二组0的持续时间小于60秒
zzj 6 years ago
parent
commit
413913202f
6 changed files with 152 additions and 12 deletions
  1. 45 0
      card_base.cpp
  2. 3 0
      card_base.h
  3. 7 5
      card_message_handle.cpp
  4. 1 1
      common.h
  5. 6 4
      module_service/module_mgr.cpp
  6. 90 2
      test.cpp

+ 45 - 0
card_base.cpp

@@ -29,6 +29,51 @@ card_location_base::card_location_base(const std::string&type,uint32_t id,uint16
 
 void card_location_base::do_status(int st)
 {
+	time_t now=time(0);
+	bool   help_flag=false;
+
+	if((m_help_bit & 1) && (st & STATUS_HELP))
+	{
+		//      1111111111
+		//               ^
+		m_help_last_time=now;
+	}
+	else if((m_help_bit & 1) && (st & STATUS_HELP)==0)
+	{
+		//      11111111100000
+		//               ^
+		m_help_bit<<=1;
+	}
+	else if((m_help_bit & 1)==0 && (st & STATUS_HELP))
+	{
+		//      00000000011111
+		//               ^
+
+		if((m_help_bit&0x3)==2)
+		{
+			log_warn("handle_m_help,card_id:%d\n",m_id);
+			help_flag=true;
+		}
+
+		m_help_last_time=now;
+		m_help_bit<<=1;
+		m_help_bit|=1;
+	}
+	else 
+	{
+		//      11111111100000
+		//                   ^
+		if(now-m_help_last_time>60)
+		{
+			m_help_bit=0;
+		}
+	}
+
+	if(!help_flag)
+	{
+		st = st & (0xFFFFFFFF ^ STATUS_HELP);
+	}
+
     module_mgr::do_status((STATUS_CARD)st, m_id, m_type);
 }
 

+ 3 - 0
card_base.h

@@ -73,6 +73,9 @@ struct card_location_base:card,std::enable_shared_from_this<card_location_base>
 
 	std::atomic<int> m_upmine_flag{0};
 
+	time_t m_help_last_time=0;
+	int    m_help_bit=0;
+
 	void inc_upmine_flag()
 	{
 		++m_upmine_flag;

+ 7 - 5
card_message_handle.cpp

@@ -158,22 +158,24 @@ void card_message_handle::on_message(zloop<task*> * loop,const message_locinfo&l
 		log_warn("%s","当前代码没有处理历史消息记录。");
 		return;
 	}
-	STATUS_CARD c_status = STATUS_POWER_NOMARL;
+	int c_status = STATUS_POWER_NOMARL;
 	if(loc.m_batty_status == 2)
 	{
-		c_status = STATUS_POWER_LOWER_SERIOUS;
+		c_status ^= STATUS_POWER_NOMARL;
+		c_status  = STATUS_POWER_LOWER_SERIOUS;
 	}
-	m_card->do_status(c_status);
 
 	if(loc.m_callinfo & 0x80)
 	{
-		m_card->do_status(STATUS_HELP);
+		c_status  |= STATUS_HELP;
 	}
+
 	if((loc.m_callinfo & 0x01) || (loc.m_callinfo & 0x02))
 	{
-		m_card->do_status(STATUS_CALL);
+		c_status  |= STATUS_CALL;
 	}
 
+	m_card->do_status(c_status);
 	m_ct_list[loc.m_card_ct&(m_ct_list.size()-1)]->on_message(loop,loc);
 }
 

+ 1 - 1
common.h

@@ -24,8 +24,8 @@ enum STA_TYPE
 enum STATUS_CARD
 {
 	STATUS_NORMAL=0,
+    STATUS_POWER_NOMARL = 1,
     STATUS_POWER_LOWER_SERIOUS = 2, //电量极低
-    STATUS_POWER_NOMARL = 3,
 	STATUS_OVER_SPEED=8,
 	STATUS_AREA_OVER_TIME=16,
 	STATUS_HELP=128,

+ 6 - 4
module_service/module_mgr.cpp

@@ -57,15 +57,16 @@ void module_mgr::do_status(STATUS_CARD st, uint32_t card_id, int32_t type)
         return;
     }
 
-    if(STATUS_HELP == st)
+    if((STATUS_HELP & st) != 0)
     {
         module_call_help::instance()->rev_from_card_help(card_ptr);
     }
-    if(STATUS_CALL == st)
+    if((STATUS_CALL & st) != 0)
     {
         module_call::instance()->rev_from_card_resp(card_ptr);
     }
-    if(STATUS_POWER_LOWER_SERIOUS == st)
+
+    if((STATUS_POWER_LOWER_SERIOUS & st) != 0)
     {
         if(!card_ptr->get_event_flag(ET_CARD_LOW_POWER_SERIOUS))
         {
@@ -73,7 +74,8 @@ void module_mgr::do_status(STATUS_CARD st, uint32_t card_id, int32_t type)
             module_other_alarm::power_lower_serious(card_ptr);
         }
     }
-    if(STATUS_POWER_NOMARL == st)
+
+    if((STATUS_POWER_NOMARL & st) != 0)
     {
         if(card_ptr->get_event_flag(ET_CARD_LOW_POWER_SERIOUS))
         {

+ 90 - 2
test.cpp

@@ -191,8 +191,7 @@ void set_path(const std::vector<line_v>&v_line,const std::vector<double>&slope)
 }
 
 
-
-int main()
+void test()
 {
 {
 	std::vector<line_v> vl;
@@ -229,8 +228,97 @@ int main()
 
 	set_path(vl,{10});
 }
+}
+
+
+int STATUS_HELP=0x80;
+
+	int m_id=1;
+	int help_bit=0;
+	time_t help_last_time=0;
+void help(int st)
+{
+
+	time_t now=time(0);
+
+
+	if((help_bit & 1) && (st & STATUS_HELP))
+	{
+//      1111111111
+//               ^
+		help_last_time=now;
+	}
+	else if((help_bit & 1) && (st & STATUS_HELP)==0)
+	{
+//      11111111100000
+//               ^
+		help_bit<<=1;
+	}
+	else if((help_bit & 1)==0 && (st & STATUS_HELP))
+	{
+//      00000000011111
+//               ^
+
+		if((help_bit&0x3)==2)
+		{
+			printf("handle_help,card_id:%d\n",m_id);
+		}
+		
+		help_last_time=now;
+		help_bit<<=1;
+		help_bit|=1;
+	}
+	else 
+	{
+//      11111111100000
+//                   ^
+		if(now-help_last_time>60)
+		{
+			help_bit=0;
+		}
+	}
+}
+
+void gen_help(int cnt,int bit=1)
+{
+	for(int i=0;i<cnt;i++)
+	{
+		help(bit?STATUS_HELP:0);
+		sleep(1);
+		printf("%d",bit);
+		fflush(stdout);
+	}
+}
+
+int main()
+{
+	help_bit=0;
+	gen_help(10,0);
+	gen_help(60,1);
+	gen_help(10,0);
+	gen_help(10,1);
+	printf("\n");
+
+	help_bit=0;
+	gen_help(120,1);
+	printf("\n");
+
+	help_bit=0;
+	gen_help(10,0);
+	gen_help(60,1);
+	gen_help(70,0);
+	gen_help(10,1);
+	gen_help(10,0);
+	gen_help(60,1);
+	printf("\n");
+
+	help_bit=0;
+	gen_help(120,0);
+	printf("\n");
 
 	return 0;
 }
 
 
+
+