Pārlūkot izejas kodu

1.增加1318特殊处理 2.修复呼叫协议 3.禁区修复

lixioayao 5 gadi atpakaļ
vecāks
revīzija
50cf9a6048

+ 1 - 2
Makefile.am

@@ -31,7 +31,7 @@ AM_CPPFLAGS=-Wall -pthread -m64 -g  -std=c++11 -I${prefix}/include -I/usr/local/
 AM_LDFLAGS=-Wall -pthread -m64 -g  -std=c++11  -L${prefix}/lib  -L/usr/local/mysql/lib
 
 yals_SOURCES=${AM_SOURCES} main.cpp
-yals_CPPFLAGS=${AM_CPPFLAGS} -DSITE_AREA
+yals_CPPFLAGS=${AM_CPPFLAGS}
 yals_LDFLAGS=${AM_LDFLAGS}  -lev -lzlog -lrt -lboost_chrono -lboost_system -lboost_thread -lmysqlclient -lthree_rates
 
 yals_LDADD=db/libyadb.a websocket/libwebsocket.a
@@ -48,7 +48,6 @@ test_SOURCES=test.cpp base64.cpp point.cpp
 test_CPPFLAGS=${AM_CPPFLAGS}
 test_LDFLAGS=${AM_LDFLAGS}  -L. -lzlog -lrt
 
-#DEFS= -DSITE_AREA
 DEFS=
 EXTRA_DIST=
 

+ 1 - 1
area.cpp

@@ -351,7 +351,7 @@ void area_list::init_monkeycar_area(int id)
 
 std::shared_ptr<area>  area_list::create(int type,int id,int limit_count_person, int limit_time_person,double scale,int32_t mapid,int32_t b_type) 
 {
-	if(type==AREA_TYPE_FORBIDDEN)	
+	if(type==AREA_TYPE_NO_COVER)	
 	{
 		return std::make_shared<special_area>(id,limit_count_person,limit_time_person,scale,mapid,b_type);
 	}

+ 40 - 4
card_base.cpp

@@ -139,7 +139,17 @@ void card_location_base::on_message(zloop<task*> * loop,const message_locinfo&lo
 		m_message_handle->on_message(loop,loc,is_history);
 	}
 }
-
+struct ld_1318
+{
+    ld_1318(double a,double b,double c)
+        :x(a)
+        ,y(b)
+        ,speed(c)
+    {}
+    double x;
+    double y;
+    double speed;
+};
 //前端推送位置函数.
 void card_location_base::upt_card_pos(YA::_CARD_POS_&cp, point &pt)
 {
@@ -151,13 +161,39 @@ void card_location_base::upt_card_pos(YA::_CARD_POS_&cp, point &pt)
     }
     else
          _p=pt;
-	cp.x = tool_other::round(_p.x,3);
-	cp.y = tool_other::round(_p.y,3);
 	//cp.z = pt.z;
 
 	cp.Type=m_type;
 	cp.ID = m_id;
-	cp.speed = abs(ceil(m_speed));
+
+    if(m_type==4 &&  m_id==1318)
+    {
+        static std::list<ld_1318> list_1318;
+        if(list_1318.size()>=60)
+        {
+            double tx=0,ty=0,ts=0;
+            std::for_each(list_1318.begin(),list_1318.end(),[&tx,&ty,&ts](const ld_1318& ld){
+                        tx+=ld.x;ty=ld.y;ts+=ld.speed;
+                        });
+            size_t n=list_1318.size();
+
+            tx/=n;ts/=n;
+            _p.set(tx,ty,0);
+            cp.speed = ts;
+            list_1318.pop_front();
+            log_info("get_speed:%d (%f,%f), %f",m_id,tx,ty,ts);
+        }
+        else
+            _p=*this;
+        double speed = abs((int)(m_speed*10000)/10000.);
+        list_1318.emplace_back(x,y,speed);
+    }
+    else
+        cp.speed = abs(ceil(m_speed));
+
+	cp.x = tool_other::round(_p.x,3);
+	cp.y = tool_other::round(_p.y,3);
+
 	cp.running_stat = m_stat;
 	cp.dept_id = m_deptid;
 	cp.display=m_display;

+ 9 - 1
crc.cpp

@@ -35,7 +35,7 @@ static unsigned short ccitt_table[256] = {
 0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0
 };
-unsigned short do_crc(unsigned char *q, int len)
+uint16_t  do_crc(unsigned char *q, int len)
 {
 	unsigned short crc = 0;
 
@@ -44,7 +44,15 @@ unsigned short do_crc(unsigned char *q, int len)
 
 	return crc;
 }
+uint16_t  do_crc_1(std::vector<char>&v, int len)
+{
+	unsigned short crc = 0;
+    
+    for(std::size_t i=len ;i<v.size();i++)
+		crc = ccitt_table[((crc >> 8) ^ v[i]) & 0xff] ^ (crc << 8);
 
+	return crc;
+}
 
 /*
 ----------------------------------------------

+ 2 - 0
crc.h

@@ -1,5 +1,7 @@
 
 #ifndef _CRC_HPP_
 #include <stdint.h>
+#include <vector>
 uint16_t do_crc(unsigned char *ptr,int len); // 字节查表法求CRC
+uint16_t do_crc_1(std::vector<char> &v, int len);
 #endif //CRC

+ 6 - 3
loc_point.cpp

@@ -9,6 +9,7 @@ loc_point::loc_point()
     :m_time(0)
     ,m_ct(-1)
 	,m_cid(-1)
+    ,m_type(-1)
     ,m_sid(-1)
     ,m_acc(0)
     ,m_rav(0)
@@ -49,10 +50,10 @@ void loc_point::debug_out(const char *str)const
 {
     char time_buff[128];
 #if 1
-    log_info("[%s]t=%s,sit=%d,card=%d,ct=%d,cred=%d,"
+    logn_info(3,"t=%s,sit=%d,card=%d,ct=%d,cred=%d,"
             "tof1=%d,tof2=%d,pt=(%.2lf,"
-            "%.2lf),rsp=1,acc=%.2f,dist=%.2lf,dist1=%.2lf,dist2=%.2lf,rav=%.2f,speed:%.2f\n",
-            str,now(time_buff,m_time), m_sid, 
+            "%.2lf),rsp=1,acc=%.2f,dist=%.2lf,dist1=%.2lf,dist2=%.2lf,rav=%.2f,speed:%f\n",
+            now(time_buff,m_time), m_sid, 
 			m_cid,
 			m_ct, m_cred_level,
             m_tof[0], m_tof[1],  x,
@@ -90,6 +91,7 @@ void loc_point::set_source(const loc_message&li,const loc_message&li2)
 {
     m_sid = li.m_sit->m_id;
 	m_cid = li.m_card_id;
+    m_type=li.m_card_type;
     m_time=std::min(li.m_loc_time,li2.m_loc_time);
     m_ct=li.m_card_ct;
     m_acc=li.m_acc *10;// 1270.;
@@ -103,6 +105,7 @@ void loc_point::set_source(const loc_message&li)
 {
     m_sid = li.m_sit->m_id;
 	m_cid = li.m_card_id;
+    m_type=li.m_card_type;
     m_time=li.m_loc_time;
     m_ct=li.m_card_ct;
     m_acc=li.m_acc *10;// 1270.;

+ 1 - 0
loc_point.h

@@ -11,6 +11,7 @@ struct loc_point:point
 	int64_t m_time;
 	int     m_ct;
 	uint32_t m_cid;
+    uint8_t m_type;
     int     m_sid;
 	float	m_acc;
 	float	m_rav;

+ 15 - 7
module_service/module_call.cpp

@@ -13,10 +13,8 @@
 #include"ant.h"
 #include"websocket/constdef.h"
 #include"websocket/wsClientMgr.h"
-
+#include "crc.h"
 #include"mine.h"
-
-
 uint64_t module_call::call_card::to_id64()
 {
     return tool_other::type_id_to_u64(cardtype, cardid);
@@ -92,6 +90,9 @@ void module_call::send_to_sites(call_site_map& site_map)
 
         std::vector<char> arr;
 
+        int16_t cmd = 0x77ab;
+        arr.push_back(cmd>>8);
+        arr.push_back(cmd);
         //分站地址 4字节,支持大小分站呼叫协议;added by zhuyf 2018/06/04
         //大小分站的全员呼叫,分站id要求4字节全为FF
         uint32_t anchor_id = (iter_site->second->is_call_all()? 0xffffffff : static_cast<uint32_t>(iter_site->first));
@@ -127,10 +128,17 @@ void module_call::send_to_sites(call_site_map& site_map)
             continue;
         }
 
-        //std::vector<char> arr2 = arr;
+        int16_t len=arr.size()+2;
+        int16_t crc=do_crc_1(arr,0);
+
+        auto it= arr.begin();arr.insert(it,len);
+        it= arr.begin();arr.insert(it,len>>8);
+
+        arr.push_back(crc>>8);arr.push_back(crc);
+        std::vector<char> arr2 = arr;
         sit_ptr->m_clt->send(std::move(arr));
 
-        //print_test(std::move(arr2), iter_site->first);
+        print_test(std::move(arr2), iter_site->first);
     }
 }
 
@@ -173,7 +181,7 @@ web发给采集:发起呼叫
 */
 void module_call::accept_call(sio::message::ptr const& data)
 {
-    int call_type = -1, call_level = -1, call_time_interval=-1;
+    int call_type = -1, call_level = 1, call_time_interval=-1;
     uint32_t call_time_out = 0;
     std::string user_name;
 
@@ -656,7 +664,7 @@ void module_call::get_user_all_call_cards(call_user_ptr& user_ptr,
 */
 void module_call::system_call_apoint(int card_id,int card_type)
 {
-    int call_type = -1, call_level = -1, call_time_interval=-1;
+    int call_type = -1, call_level = 1, call_time_interval=-1;
     uint32_t call_time_out = 0;
     std::string user_name = "system_apoint";
 

+ 10 - 7
module_service/module_meta_date_changed.cpp

@@ -29,10 +29,13 @@ void module_meta_date_changed::accept(sio::message::ptr const& data)
     std::string szParam = "0";
     tool_map::try_get_value(szParam,JSON_KEY_ID,data);
 
+    int id=-1;
+    tool_map::try_get_value(id,JSON_KEY_ID,data);
+
     std::string op_type="";
     tool_map::try_get_value(op_type, JSON_KEY_OP_TYPE, data);
 
-    log_info("web发来数据:JSON_CMD_VALUE_META_DATA_CHANGED,%s---%s",szParam.c_str(),op_type.c_str());
+    log_info("web发来数据:JSON_CMD_VALUE_META_DATA_CHANGED,%d.%s---%s",id,szParam.c_str(),op_type.c_str());
     if(!szParam.empty() && !op_type.empty())
     {
         EDIT_TYPE_ID edit_type_id;
@@ -58,7 +61,7 @@ void module_meta_date_changed::accept(sio::message::ptr const& data)
         }
         else if(JSON_KEY_NAME_AREA == name)
         {
-            deal_call_edit_area(szParam, edit_type_id);
+            deal_call_edit_area(szParam,id, edit_type_id);
         }
         else if(JSON_KEY_NAME_READER == name)
         {
@@ -182,20 +185,20 @@ void module_meta_date_changed::deal_call_edit_card(std::string & id64, EDIT_TYPE
     }
 }
 
-void module_meta_date_changed::deal_call_edit_area(const std::string& id, EDIT_TYPE_ID edit_type_id)
+void module_meta_date_changed::deal_call_edit_area(const std::string& id, int& aid,EDIT_TYPE_ID edit_type_id)
 {
-    int aid=std::stoi(id);
     if(ET_INSERT == edit_type_id || ET_UPDATE == edit_type_id)
     {
         area_list::instance()->init_from_db(aid);
     }
     else if(ET_DELETE == edit_type_id)
     {
-        if(auto area_ptr = area_list::instance()->get(aid))
+        int cid = std::stoi(id);
+        if(auto area_ptr = area_list::instance()->get(cid))
         {
-            log_info("区域删除:areaid=%d", aid);
+            log_info("区域删除:areaid=%d", cid);
             area_ptr->clear();
-            area_list::instance()->remove(aid);
+            area_list::instance()->remove(cid);
         }
     }
 }

+ 1 - 1
module_service/module_meta_date_changed.h

@@ -59,7 +59,7 @@ private:
 
     void deal_call_edit_antenna(int id,EDIT_TYPE_ID edit_type_id);
 
-    void deal_call_edit_area(const std::string & id, EDIT_TYPE_ID edit_type_id);
+    void deal_call_edit_area(const std::string & id,int &iid, EDIT_TYPE_ID edit_type_id);
 
     void deal_call_edit_map(int id, EDIT_TYPE_ID edit_type_id);
 

+ 3 - 2
select_tool.cpp

@@ -178,8 +178,8 @@ bool select_point_object::select_solution(const std::vector<point> &vp,const sit
           tvp.push_back(res[i]);
 
 		m_d(0).inc_cl(10);
-   }
-   point pt = select_solution0(tvp,sit->m_scale);
+    }
+    point pt = select_solution0(tvp,sit->m_scale);
 	if(pt.empty() || m_d.empty())
 		return false;
 	m_d(0).set(pt);
@@ -191,6 +191,7 @@ bool select_point_object::select_solution(const std::vector<point> &vp,const sit
 		if(m_last) m_d(0).m_dist=0.01*m_last->m_dist>0?1:-1;
 	}
 
+	m_d(0).m_dist1=sit->dist_direct(pt);
     //
 	//std_info("revise_by_history:::%llu",m_d(0).m_time);
     bool fg=revise_by_history(pt,sit,m_d(0).m_time);

+ 19 - 1
select_tool.h

@@ -196,7 +196,25 @@ struct person_point_filter:select_point_object
 		{
 			select_one_ant(c,vp);
 		}
-
+        loc_point &refc=m_d(1);
+        if(c.m_type==4 &&  c.cl()<=20 && refc.is_same_site(c) && refc.time_off(c)<5 ){    
+            logn_info(3,"{test_lemon}first point:site=%d,card=%d,(%f,%f) else:(%f,%f),cred:%d,size:%d",c.m_sid,c.m_cid,c[0].x,c[0].y,c[1].x,c[1].y,c.cl(),vp.size());
+            if(const auto & site_ptr=sit_list::instance()->get(c.m_sid)){
+                double d1=0,d2=0,d3=0;
+                d1=refc.m_dist1;
+                d2=site_ptr->dist_direct(c[0]);
+                d3=site_ptr->dist_direct(c[1]);
+                if(d1*d2<0 && d1*d3>0){
+                    logn_info(3,"{test_lemon+++++++}first point:site=%d,card=%d,(%f,%f) else:(%f,%f),cred:%d,size:%d",c.m_sid,c.m_cid,c[0].x,c[0].y,c[1].x,c[1].y,c.cl(),vp.size());
+                    point t=c[0];
+                    c[0]=c[1];
+                    c[1]=t;
+			        c.set_cl(0);
+                }
+                else if(d1*d2<0 && d1*d3<0)
+                  c[0].set(refc);
+            }
+        }    
 	}
 	virtual fit_result * get_best_fit()
 	{