123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- #include <algorithm>
- #include "module_traffic_light.h"
- #include "module_traffic_light_manager.h"
- void traffic_light_group::reset()
- {
- m_time_stamp = 0;
- m_ctrl_name = "";
- m_card_id = 0;
- set_status(false);
- set_priority(priority_init);
- for(auto it = m_vt_lights.begin();it != m_vt_lights.end(); ++it){
- auto tl = traffic_light_manager::instance()->find_light((*it)->m_phy_light_id);
- if(tl != nullptr){
- tl->set_state();
- }
- }
- }
- void traffic_light_group::insert(traffic_light_ptr ptl)
- {
- ptl->m_direct_distance = this->dist_direct(*ptl);
- line tmp(*this, *ptl);
- ptl->m_line_group = tmp;
- m_vt_lights.push_back(ptl);
- if(1 == ptl->m_special){
- m_special = 1;
- }
- }
- void traffic_light_group::set_light(const int& ld, const int& lc, const int& lcr)
- {
- for(auto it = m_vt_lights.begin(); it != m_vt_lights.end(); ++it){
- auto ptl = traffic_light_manager::instance()->find_light((*it)->m_light_id);
- if(ptl != nullptr){
- if(ptl->m_light_id == ld){
- ptl->set_state(lc);
- send_cmd_light(ptl);
- }else{
- ptl->set_state(lcr);
- send_cmd_light(ptl);
- }
- break;
- }
- }
- }
- bool traffic_light_group::is_different(const int& ld, const int& lc, const int& lcr)
- {
- bool ret = false;
- get_turn();
- if(get_priority() <= priority_avoidance)
- {
- for(auto it = m_vt_lights.begin(); it != m_vt_lights.end(); ++it)
- {
- if((*it)->m_light_id == ld)
- {
- if((*it)->m_state != lc)
- {
- ret = true;
- break;
- }
- }else{
- if((*it)->m_state != lcr)
- {
- ret = true;
- break;
- }
- }
- }
- }
- if(ret){
- set_avoidance(ld, lc, lcr);
- }
- release_turn();
- return ret;
- }
- void traffic_light_group::send_cmd_light(traffic_light_ptr& ptl)
- {
- if(nullptr != ptl){
- // 控制码
- int shape = 0;
- if(red == ptl->m_state){
- shape = red_circle_solid;
- }else if(green == ptl->m_state){
- shape = green_down;
- }else{
- shape = green_spark;
- }
- traffic_light_manager::instance()->send_light_ctrl(ptl->m_light_id, DT_LIGHT, shape);
- }
- }
- void traffic_light_group::set_manual_ctrl(const std::string& name, const int& ld, const int& lc)
- {
- get_turn();
- m_ctrl_name = name;
- m_time_stamp = time(NULL);
- set_priority(priority_manual_ctrl);
- m_card_id = 0;
- auto ptl = std::find_if(m_vt_lights.begin(), m_vt_lights.end(),[=](traffic_light_ptr lp){
- if(lp->m_light_id == ld)
- {
- return true;
- }else{
- return false;
- }
- });
- if(ptl != m_vt_lights.end()){
- (*ptl)->set_state(lc);
- }
- release_turn();
- }
|