#include #include #include #include #include #include #include #include #include "tool_time.h" #define log_error printf #define log_info printf struct path { std::array m_line; path() { } std::string to_str() const { std::stringstream ss; for(int i=0;i<2;i++) { ss<<"line:" <&v_line,std::vector::const_iterator itm) { std::array m_path; auto it=itm; for(int i=0;i<2 && it!=v_line.end();++it,++i) m_path[0][i]=*it; it=itm-1; for(int i=0;i<2 && it>=v_line.begin();--it,++i) { m_path[1][i]=*it; m_path[1][i].swap_point(); } for(auto&p:m_path) { log_info("%s\n",p.to_str().c_str()); } } void set_path2(const std::vector&v_line_) { std::vector vl(v_line_); vl.reserve(vl.size()+2); //找到距离天线最近的端点 auto min_it=vl.begin(); double dist=10; for(auto it=vl.begin();it!=vl.end();it++) { double d=it->as_line().dist(*this); if(dv[0].dist(*this)-dist)<1) { set_path(vl,min_it); } else if(abs(min_it->v[1].dist(*this)-dist)<1) { set_path(vl,min_it+1); } else { point proj=min_it->projection(*this); vl.insert(min_it+1,line_v(proj,min_it->v[1])); min_it->set_point(1,proj); if(min_it->v[0].z)//slope ..555 { double slope=min_it->v[0].z; double len_a=min_it->v[0].dist((min_it+1)->v[1]); double len_0=slope*min_it->length()/len_a; double len_1=slope-len_0; min_it->v[0].z=min_it->v[1].z=len_0; (min_it+1)->v[0].z=(min_it+1)->v[1].z=len_1; } set_path(vl,min_it+1); } } }; void print_vl(const std::vector&vl) { printf("-----------------------------------\n"); for(auto&v:vl) { printf("%s\n",v.to_string().c_str()); } } void set_path(const std::vector&v_line,const std::vector&slope) { if(v_line.empty()) return; const auto&find_line=[](const point&pt,int first,std::vector&vl){ for(auto it=vl.begin();it!=vl.end();it++) { if(it->v[first].dist(pt)<1) return it; if(it->v[first?0:1].dist(pt)<1) { point p=it->v[0]; it->v[0]=it->v[1]; it->v[1]=p; return it; } } return vl.end(); }; //构造一个首尾相连的结构 print_vl(v_line); std::vector vl(v_line.begin()+1,v_line.end()); std::vector target(v_line.begin(),v_line.begin()+1); target[0][0].z=target[0][1].z=slope[0]; for(int i=0,c=vl.size();i vl; vl.push_back(line_v(point(-10,0),point(0,0))); vl.push_back(line_v(point(0,0),point(100,100.1))); print_vl(vl); set_path(vl,{10,20}); } { std::vector vl; vl.push_back(line_v(point(200,200),point(100,100.1))); vl.push_back(line_v(point(200,200),point(200,220))); set_path(vl,{10,20}); } { std::vector vl; vl.push_back(line_v(point(-10,0),point(0,0))); vl.push_back(line_v(point(0,0),point(200,200))); set_path(vl,{10,20}); } { std::vector vl; vl.push_back(line_v(point(0,0),point(200,200))); 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;itm_hour=0;loc_t->tm_min=0;loc_t->tm_sec=0; time_t x = mktime(loc_t); return x*1000; } int main() { unsigned now=time(0); std::cout<