123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- #ifndef module_traffic_light_h
- #define module_traffic_light_h
- #include <memory>
- #include <ctime>
- #include <atomic>
- #include <vector>
- #include <list>
- #include <array>
- #include "ant.h"
- #include "module_traffic_light_common.h"
- #include "line.h"
- class client;
- struct traffic_light: point{
- int m_light_id;
- int m_group_id;
- std::string m_ip;
- int m_site_id;
- int m_state;
- int m_port;
- int m_phy_light_id;
- int m_phy_direction;
- uint64_t m_rec_time;
- int m_special;
- double m_direct_distance;
- line m_line_group;
- int m_stream;
- int m_area_id;
- int m_map_id;
- int m_device_type_id;
- std::shared_ptr<client> m_clt;
- traffic_light(): m_light_id(0), m_group_id(0), m_ip(""), m_state(0), m_port(0), m_phy_light_id(0), m_phy_direction(0), m_rec_time(0), m_special(0), m_direct_distance(0.0), m_stream(0), m_area_id(0), m_map_id(0)
- {
- m_device_type_id=3;
- m_clt = nullptr;
- }
- traffic_light(double x, double y, double z, int light_id, int group_id, std::string ip, int state, int port, int pli, int pd, int special, int stream): point(x, y, z), m_light_id(light_id), m_group_id(group_id), m_ip(ip), m_state(state), m_port(port), m_phy_light_id(pli), m_phy_direction(pd), m_special(special), m_stream(stream)
- {
- m_device_type_id=3;
- m_clt = nullptr;
- }
- void update(double x, double y, double z, int light_id, int group_id, std::string ip, int state, int port, int pli, int pd, int special, int stream)
- {
- this->x = x;
- this->y = y;
- this->z = z;
- this->m_light_id = light_id;
- this->m_group_id = group_id;
- this->m_ip = ip;
- this->m_state = state;
- this->m_port = port;
- this->m_phy_light_id = pli;
- this->m_phy_direction = pd;
- this->m_special = special;
- this->m_stream = stream;
- }
- void set_state(int value = light_shape::green_all_on)
- {
- m_state = value;
- }
- void set_client(const std::shared_ptr<client>& clt)
- {
- if(m_clt != clt){
- m_clt = clt;
- }
- }
- std::shared_ptr<client> get_client()
- {
- return m_clt;
- }
- };
- using traffic_light_ptr = std::shared_ptr<traffic_light>;
- class traffic_light_group;
- using traffic_light_group_ptr = std::shared_ptr<traffic_light_group>;
- struct traffic_light_group: point{
- int m_group_id;
- double m_scope;
- uint16_t m_manual_time;
- uint16_t m_auto_interval;
- uint64_t m_card_id;
- int m_map_id;
- int m_area_id;
- time_t m_time_stamp;
- time_t m_ctrl_time;
- bool m_special;
- int m_green_light_id;
- std::string m_ctrl_name;
- std::atomic<int> m_priority;
- std::atomic<bool> m_used;
- std::atomic_flag m_owner_flag;
- std::vector<traffic_light_ptr> m_vt_lights;
- std::array<path, 2> m_path;
- int m_down_stream_idx;
- move_stream m_stream_state;
- traffic_light_group(): point(0,0), m_group_id(0), m_scope(0.0), m_manual_time(0), m_auto_interval(0), m_card_id(0), m_map_id(0), m_area_id(0), m_time_stamp(0), m_ctrl_time(0),m_special(false), m_green_light_id(0), m_ctrl_name(""), m_priority(priority_init), m_used(false)
- {
- m_vt_lights.clear();
- m_down_stream_idx = 0;
- m_owner_flag.clear();
- m_stream_state = move_stream::unknown;
- }
- traffic_light_group(double x, double y, double z, int group_id, double scope, int interval, int map_id, int area_id): point(x, y, z), m_group_id(group_id), m_scope(scope), m_auto_interval(interval), m_map_id(map_id), m_area_id(area_id)
- {
- m_priority = priority_init;
- m_vt_lights.clear();
- m_used = false;
- m_card_id = 0;
- m_down_stream_idx = 0;
- m_owner_flag.clear();
- m_stream_state = move_stream::unknown;
- }
-
- void send_cmd_light(traffic_light_ptr& ptl);
- void set_path(const std::vector<line_v>& vl);
- void set_path(const std::vector<line_v>& vl, std::vector<line_v>::const_iterator it);
-
- void set_crossing(const uint64_t& cid, const int& p)
- {
- m_card_id = cid;
- set_priority(p);
- }
- bool is_at_path(point p);
-
- void set_avoidance(const int& ld, const int& lc, const int& lcr)
- {
- m_card_id = 0;
- m_time_stamp = 0;
- set_priority(priority_avoidance);
- set_light(ld, lc, lcr);
- }
-
- void set_priority(const int& p)
- {
- m_priority.store(p);
- }
- void set_down_stream_idx(const int& v)
- {
- m_down_stream_idx = v;
- }
-
- int get_priority()
- {
- return m_priority.load();
- }
-
- void set_status(bool s)
- {
- m_used.store(s);
- }
-
- bool get_status()
- {
- return m_used.load();
- }
- move_stream get_stream_state()
- {
- return m_stream_state;
- }
- void set_stream_state(const move_stream& state)
- {
- m_stream_state = state;
- }
- move_stream get_stream(const int& cid);
-
- bool is_time_out()
- {
- if(m_time_stamp >= m_ctrl_time){
- return true;
- }
- return false;
- }
- void get_turn()
- {
- while(m_owner_flag.test_and_set(std::memory_order_acquire));
- }
- void release_turn()
- {
- m_owner_flag.clear(std::memory_order_release);
- }
-
- void reset();
-
- void set_light(const int& lid, const int& lc, const int& lcr);
-
-
- void insert(traffic_light_ptr ptl);
-
- bool exist(const int& lid);
-
- bool is_different(const int& ld, const int& lc, const int& lcr);
-
- void set_manual_ctrl(const std::string& name, const int& ld, const int& lc);
- uint64_t get_green_light_id();
-
- double updown_dist();
- int size()
- {
- return m_vt_lights.size();
- }
- void update(double x, double y, double z, int group_id, double scope, int interval, int map_id, int area_id)
- {
- this->x = x;
- this->y = y;
- this->z = z;
- this->m_group_id = group_id;
- this->m_scope = scope;
- this->m_auto_interval = interval;
- this->m_map_id = map_id;
- this->m_area_id = area_id;
- }
- };
- struct traffic_light_data{
- bool m_bigger_flag;
- std::list<traffic_light_ptr> m_traffic_group;
- traffic_light_data(): m_bigger_flag(false){
- m_traffic_group.clear();
- }
- };
- struct run_red_light{
- int32_t m_group_id;
- int m_light_id;
- int m_vid;
- int32_t m_area_id;
- std::string m_occ_time;
- run_red_light(): m_group_id(0), m_light_id(0), m_vid(0), m_area_id(0), m_occ_time(0)
- {}
- };
- #endif
|