19 #define DEBUG_PRINT_TM 0 20 #define IP_DATA_BUFFER_SIZE 80 23 namespace traffic_manager {
25 using namespace constants::SpeedThreshold;
26 using namespace constants::PID;
46 std::lock_guard<std::mutex> lock(
_mutex);
56 std::lock_guard<std::mutex> lock(
_mutex);
63 std::lock_guard<std::mutex> lock(
_mutex);
65 tm.second->SynchronousTick();
71 std::lock_guard<std::mutex> lock(
_mutex);
76 if(tm_ptr !=
nullptr) {
87 auto GetLocalIP = [=](
const uint16_t sport)-> std::pair<std::string, uint16_t> {
88 std::pair<std::string, uint16_t> localIP;
89 int sock = socket(AF_INET, SOCK_DGRAM, 0);
92 std::cout <<
"Error number 1: " << errno << std::endl;
93 std::cout <<
"Error message: " << strerror(errno) << std::endl;
98 std::memset(&loopback, 0,
sizeof(loopback));
99 loopback.sin_family = AF_INET;
100 loopback.sin_addr.s_addr = INADDR_LOOPBACK;
101 loopback.sin_port = htons(9);
102 err = connect(sock, reinterpret_cast<sockaddr*>(&loopback),
sizeof(loopback));
105 std::cout <<
"Error number 2: " << errno << std::endl;
106 std::cout <<
"Error message: " << strerror(errno) << std::endl;
109 socklen_t addrlen =
sizeof(loopback);
110 err = getsockname(sock, reinterpret_cast<struct sockaddr*> (&loopback), &addrlen);
113 std::cout <<
"Error number 3: " << errno << std::endl;
114 std::cout <<
"Error message: " << strerror(errno) << std::endl;
120 localIP = std::pair<std::string, uint16_t>(std::string(buffer), sport);
123 std::cout <<
"Error number 4: " << errno << std::endl;
124 std::cout <<
"Error message: " << strerror(errno) << std::endl;
145 std::pair<std::string, uint16_t> serverTM;
150 longitudinal_highway_param,
152 lateral_highway_param,
153 perc_difference_from_limit,
158 serverTM = GetLocalIP(port);
161 episode_proxy.
Lock()->AddTrafficManagerRunning(serverTM);
165 std::cout <<
"NEW@: Registered TM at " 166 << serverTM.first <<
":" 167 << serverTM.second <<
" ..... SUCCESS." 172 _tm_map.insert(std::make_pair(port, tm_ptr));
182 if(episode_proxy.
Lock()->IsTrafficManagerRunning(port)) {
185 std::pair<std::string, uint16_t> serverTM =
186 episode_proxy.
Lock()->GetTrafficManagerRunning(port);
196 if(tm_ptr !=
nullptr) {
200 std::cout <<
"OLD@: Registered TM at " 201 << serverTM.first <<
":" 202 << serverTM.second <<
" ..... TRY " 209 _tm_map.insert(std::make_pair(port, tm_ptr));
223 std::cout <<
"OLD@: Registered TM at " 224 << serverTM.first <<
":" 225 << serverTM.second <<
" ..... FAILED "
static const std::vector< float > LATERAL_HIGHWAY_PARAM
static const std::vector< float > LATERAL_PARAM
bool CreateTrafficManagerClient(carla::client::detail::EpisodeProxy episode_proxy, uint16_t port)
This file contains definitions of common data structures used in traffic manager. ...
static std::map< uint16_t, TrafficManagerBase * > _tm_map
#define SOCK_INVALID_INDEX
< socket sockaddr_in
#define IP_DATA_BUFFER_SIZE
The function of this class is to integrate all the various stages of the traffic manager appropriatel...
static const std::vector< float > LONGITUDIAL_HIGHWAY_PARAM
static const std::vector< float > LONGITUDIAL_PARAM
TrafficManagerBase * GetTM(uint16_t port) const
static const float INITIAL_PERCENTAGE_SPEED_DIFFERENCE
The function of this class is to integrate all the various stages of the traffic manager appropriatel...
SharedPtrType Lock() const
Same as TryLock but never return nullptr.
The function of this class is to integrate all the various stages of the traffic manager appropriatel...
void HealthCheckRemoteTM()
Method to check server is alive or not.
void CreateTrafficManagerServer(carla::client::detail::EpisodeProxy episode_proxy, uint16_t port)
virtual void ShutDown()=0