Skip to content
Snippets Groups Projects
Commit a2c4e6d6 authored by Hoop77's avatar Hoop77
Browse files

platoon.config update

parent 53c5ff2b
No related merge requests found
VehicleId: 1 use 1,2 or 3 here depending on the position of the car in platoon; 1 = LEADER
BroadCast: 10.255.255.255
VehicleEndpoint: 2 10.5.37.195
\ No newline at end of file
/opt/ros/lunar/share/catkin/cmake/toplevel.cmake
\ No newline at end of file
/opt/ros/kinetic/share/catkin/cmake/toplevel.cmake
\ No newline at end of file
#ifndef EXCEPTIONS_H
#define EXCEPTIONS_H
namespace car {
#ifndef EXCEPTIONS_H
#define EXCEPTIONS_H
namespace car
{
class MissingParameters: public std::exception {
virtual const char* what() const throw() {
return "Found too few paramters!";
}
};
class MissingParameters : public std::exception
{
virtual const char * what() const throw()
{
return "Found too few paramters!";
}
};
class FileNotFound: public std::runtime_error {
class FileNotFound : public std::runtime_error
{
public:
explicit FileNotFound(const std::string & filename)
: runtime_error("File not found: " + filename)
{}
};
};
}
......
......@@ -2,8 +2,6 @@
#include "exceptions/Exceptions.h"
#include "PlatoonProtocolLib/NetworkInfo.h"
#include <pluginlib/class_list_macros.h>
#include <iostream>
......@@ -17,10 +15,10 @@ PLUGINLIB_EXPORT_CLASS(car::MainNode, nodelet::Nodelet);
namespace car
{
platoonProtocol::NetworkInfo readNetworkInfo() {
/** This reads ~/.CarConfig/platoon.config */
// TODO: ConfigReader!
platoonProtocol::VehicleId readVehicleId() {
// open config file
std::string userHome = getenv("HOME");
std::ifstream configFile;
......@@ -32,40 +30,75 @@ platoonProtocol::NetworkInfo readNetworkInfo() {
// desired parameters
platoonProtocol::VehicleId vehicleId;
bool foundVehicleId = false;
std::string broadCastAdress;
bool foundBroadCastAdress = false;
std::string contentLine;
while (!configFile.eof()) {
std::getline(configFile, contentLine);
// split this line
std::istringstream iss(contentLine);
std::vector<std::string> words {std::istream_iterator<std::string>(iss), {} };
if ( words.size() > 1) { // this line contains parameter[at(0)] and value[at(1)]
if ( words.at(0) == "VehicleId:" ) {
vehicleId = std::stoi(words.at(1));
foundVehicleId = true;
} else if ( words.at(0) == "BroadCast:" ) {
broadCastAdress = words.at(1);
foundBroadCastAdress = true;
while (!configFile.eof())
{
std::getline(configFile, contentLine);
// split this line
std::istringstream iss(contentLine);
std::vector<std::string> words{std::istream_iterator<std::string>(iss), {} };
if (words.size() > 1)
{
if (words.at(0) == "VehicleId:")
{
vehicleId = std::stoi(words.at(1));
foundVehicleId = true;
}
}
}
if(!foundVehicleId)
throw MissingParameters();
configFile.close();
return vehicleId;
}
platoonProtocol::Vehicle::VehicleEndpoints readVehicleEndpoints() {
// open config file
std::string userHome = getenv("HOME");
std::ifstream configFile;
std::string filename = userHome + "/CarConfig/platoon.config";
configFile.open(filename, std::ifstream::in);
if (!configFile.is_open())
throw FileNotFound{filename};
// desired parameters
platoonProtocol::Vehicle::VehicleEndpoints endpoints;
std::string contentLine;
while (!configFile.eof())
{
std::getline(configFile, contentLine);
// split this line
std::istringstream iss(contentLine);
std::vector<std::string> words{std::istream_iterator<std::string>(iss), {} };
if (words.size() > 1)
{
if (words.at(0) == "VehicleEndpoint:")
{
auto vehicleId = static_cast<platoonProtocol::VehicleId>(std::stoi(words.at(1)));
auto host = words.at(2);
endpoints.emplace_back(platoonProtocol::VehicleEndpoint{vehicleId, host});
}
}
}
if ( !(foundVehicleId && foundBroadCastAdress) ) { throw MissingParameters(); }
configFile.close();
return platoonProtocol::NetworkInfo{vehicleId, broadCastAdress};
return endpoints;
}
MainNode::MainNode()
: nh()
, messageOStream(nh, "MainNode")
, c2cNet()
, c2c(platoonProtocol::Vehicle::Role::FOLLOWER, c2cNet, readNetworkInfo())
, c2c(platoonProtocol::Vehicle::Role::FOLLOWER, c2cNet, readVehicleId())
, pcNet()
, pc(pc2car::CommandReceiver::create(pcNet))
, egoMotion(nh)
......@@ -79,6 +112,7 @@ MainNode::MainNode()
platoonController.setCruiseControllerNotify(cruiseControllerNotify);
pc->receiveCommands([this] (auto commandCode) {platoonControllerThread.notify();} );
c2c.setCallback( [this] {platoonControllerThread.notify();} );
c2c.addVehicleEndpoints(readVehicleEndpoints());
}
void MainNode::onInit()
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment