Add station ID generator for CAMs

Signed-off-by: Tiago Garcia <tiago.rgarcia@av.it.pt>
This commit is contained in:
Tiago Garcia 2024-07-12 12:58:48 +01:00
parent 8afeedf037
commit 73756de59e
No known key found for this signature in database
GPG Key ID: A3B1096AD19E1688
2 changed files with 10 additions and 2 deletions

View File

@ -141,6 +141,7 @@ private:
bool is_sender_; bool is_sender_;
bool reflect_packet_; bool reflect_packet_;
unsigned long stationId_;
int cam_num_; int cam_num_;
int received_cam_num_; int received_cam_num_;

View File

@ -16,6 +16,7 @@
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <exception> #include <exception>
#include <random>
#include <GeographicLib/UTMUPS.hpp> #include <GeographicLib/UTMUPS.hpp>
#include <GeographicLib/MGRS.hpp> #include <GeographicLib/MGRS.hpp>
#include <string> #include <string>
@ -55,6 +56,12 @@ namespace v2x
RCLCPP_INFO(node_->get_logger(), "CamApplication started. is_sender: %d", is_sender_); RCLCPP_INFO(node_->get_logger(), "CamApplication started. is_sender: %d", is_sender_);
set_interval(milliseconds(100)); set_interval(milliseconds(100));
//createTables(); //createTables();
// Generate ID for this station
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<unsigned long> dis(0, 4294967295);
stationId_ = dis(gen);
} }
void CamApplication::set_interval(Clock::duration interval) { void CamApplication::set_interval(Clock::duration interval) {
@ -170,7 +177,7 @@ namespace v2x
ItsPduHeader_t &header = message->header; ItsPduHeader_t &header = message->header;
header.protocolVersion = 2; header.protocolVersion = 2;
header.messageID = ItsPduHeader__messageID_cam; header.messageID = ItsPduHeader__messageID_cam;
header.stationID = cam_num_; header.stationID = stationId_;
CoopAwareness_t &cam = message->cam; CoopAwareness_t &cam = message->cam;
@ -293,7 +300,7 @@ namespace v2x
bvc.yawRate.yawRateConfidence = YawRateConfidence_unavailable; bvc.yawRate.yawRateConfidence = YawRateConfidence_unavailable;
// ------------------------------ // ------------------------------
RCLCPP_INFO(node_->get_logger(), "[CamApplication::send] Sending CAM"); RCLCPP_INFO(node_->get_logger(), "[CamApplication::send] Sending CAM from station with ID %ld", stationId_);
std::unique_ptr<geonet::DownPacket> payload{new geonet::DownPacket()}; std::unique_ptr<geonet::DownPacket> payload{new geonet::DownPacket()};
payload->layer(OsiLayer::Application) = std::move(message); payload->layer(OsiLayer::Application) = std::move(message);