From 8d9aa04b712705f5f13c2f472eb9a59f0ace07d4 Mon Sep 17 00:00:00 2001 From: dev Date: Sun, 23 Jun 2024 18:48:21 -0400 Subject: [PATCH] Updates --- src/tmx/TmxUtils/src/UdpServer.cpp | 4 ++-- src/tmx/TmxUtils/src/UdpServer.h | 2 +- src/v2i-hub/MUSTSensorDriverPlugin/README.md | 2 +- .../scripts/MockMUSTSensor.py | 6 +++--- .../src/MUSTSensorDriverPlugin.cpp | 21 ++++++++++++++----- .../src/MUSTSensorDriverPlugin.h | 2 +- 6 files changed, 24 insertions(+), 13 deletions(-) mode change 100644 => 100755 src/v2i-hub/MUSTSensorDriverPlugin/scripts/MockMUSTSensor.py diff --git a/src/tmx/TmxUtils/src/UdpServer.cpp b/src/tmx/TmxUtils/src/UdpServer.cpp index e5e157d78..26155ac74 100644 --- a/src/tmx/TmxUtils/src/UdpServer.cpp +++ b/src/tmx/TmxUtils/src/UdpServer.cpp @@ -198,9 +198,9 @@ namespace tmx::utils { return -1; } - std::string UdpServer::stringTimedReceive() { + std::string UdpServer::stringTimedReceive(int maxWait_ms) { std::vector msg(4000); - int num_of_bytes = this->TimedReceive(msg.data(),4000, 5); + int num_of_bytes = this->TimedReceive(msg.data(),4000, maxWait_ms); if (num_of_bytes > 0 ) { msg.resize(num_of_bytes); std::string ret(msg.data()); diff --git a/src/tmx/TmxUtils/src/UdpServer.h b/src/tmx/TmxUtils/src/UdpServer.h index db41f3fed..7c3b5664b 100644 --- a/src/tmx/TmxUtils/src/UdpServer.h +++ b/src/tmx/TmxUtils/src/UdpServer.h @@ -37,7 +37,7 @@ class UdpServer virtual int Receive(char *msg, size_t maxSize); virtual int TimedReceive(char *msg, size_t maxSize, int maxWait_ms); - virtual std::string stringTimedReceive(); + virtual std::string stringTimedReceive(int maxWait_ms=5); private: int _socket; diff --git a/src/v2i-hub/MUSTSensorDriverPlugin/README.md b/src/v2i-hub/MUSTSensorDriverPlugin/README.md index 086255a64..781c34333 100644 --- a/src/v2i-hub/MUSTSensorDriverPlugin/README.md +++ b/src/v2i-hub/MUSTSensorDriverPlugin/README.md @@ -2,7 +2,7 @@ ## Introduction -[MUST](https://www.aiwaysion.com/technology) (Mobile Unit for Sensing Traffic) Sensor from AI Waysion is a camera based sensor, planned to be used for cooperative perception in freight use cases.. The MUST Sensor provides detections via UDP packets made up of CSV (Comma Separated Values) string data. The V2X-Hub MUST Sensor Driver Plugin will then consume these messages and translate them to **Sensor Detected Object** messages, which is V2X-Hub's generic detection message. This message is consumable by the **CARMA Streets [Sensor Data Sharing Service](https://github.com/usdot-fhwa-stol/carma-streets/blob/develop/sensor_data_sharing_service/README.md)** which will generate **Sensor Data Sharing Message**s according to the J3224 standard for broadcast to other traffic actors in the area. +[MUST](https://www.aiwaysion.com/technology) (Mobile Unit for Sensing Traffic) Sensor from AI Waysion is a camera based sensor, planned to be used for cooperative perception in freight use cases. The MUST Sensor provides detections via UDP packets made up of CSV (Comma Separated Values) string data. The V2X-Hub MUST Sensor Driver Plugin will then consume these messages and translate them to **Sensor Detected Object** messages, which is V2X-Hub's generic detection message. This message is consumable by the **CARMA Streets [Sensor Data Sharing Service](https://github.com/usdot-fhwa-stol/carma-streets/blob/develop/sensor_data_sharing_service/README.md)** which will generate **Sensor Data Sharing Message**s according to the J3224 standard for broadcast to other traffic actors in the area. ## Related Plugins diff --git a/src/v2i-hub/MUSTSensorDriverPlugin/scripts/MockMUSTSensor.py b/src/v2i-hub/MUSTSensorDriverPlugin/scripts/MockMUSTSensor.py old mode 100644 new mode 100755 index e35efeb9f..8ab55a4f8 --- a/src/v2i-hub/MUSTSensorDriverPlugin/scripts/MockMUSTSensor.py +++ b/src/v2i-hub/MUSTSensorDriverPlugin/scripts/MockMUSTSensor.py @@ -35,8 +35,8 @@ class MUSTDetection: track_id: int timestamp: int - def to_csv(): - return f'{self.classification},{self.x},{self.y},{self.heading},{self.speed},{self.size},{self.confidence},{self.track_id},{self.timstamp}' + def to_csv(self): + return f'{self.classification.value},{self.x},{self.y},{self.heading},{self.speed},{self.size.value},{self.confidence},{self.track_id},{self.timestamp}' def move_detection(): return @@ -48,7 +48,7 @@ def create_socket(): print('Socket error because of %s' %(err)) def send_detection(sock, detection, host): try: - msg = detection + msg = detection.to_csv() encoded_msg = str.encode(msg) sock.sendto(encoded_msg,host) print( encoded_msg.decode(encoding= 'UTF-8'), 'was sent to ', host) diff --git a/src/v2i-hub/MUSTSensorDriverPlugin/src/MUSTSensorDriverPlugin.cpp b/src/v2i-hub/MUSTSensorDriverPlugin/src/MUSTSensorDriverPlugin.cpp index 527c2218c..92b04a71d 100644 --- a/src/v2i-hub/MUSTSensorDriverPlugin/src/MUSTSensorDriverPlugin.cpp +++ b/src/v2i-hub/MUSTSensorDriverPlugin/src/MUSTSensorDriverPlugin.cpp @@ -27,7 +27,12 @@ namespace MUSTSensorDriverPlugin { SubscribeToMessages(); } - + void MUSTSensorDriverPlugin::OnStateChange(IvpPluginState state) { + PluginClientClockAware::OnStateChange(state); + if (state == IvpPluginState_registered) { + UpdateConfigSettings(); + } + } void MUSTSensorDriverPlugin::UpdateConfigSettings() { @@ -44,7 +49,7 @@ namespace MUSTSensorDriverPlugin { GetConfigValue("DetectionReceiverIP", ip_address); GetConfigValue("DetectionReceiverPort", port); createUdpServer(ip_address, port); - SetStatus(keyMUSTSensorConnectionStatus, "IDLE", true); + SetStatus(keyMUSTSensorConnectionStatus, "IDLE"); mustSensorPacketReceiverThreadId = mustSensorPacketReceiverThread->AddPeriodicTick([this]() { this->processMUSTSensorDetection(); @@ -60,18 +65,24 @@ namespace MUSTSensorDriverPlugin { MUSTSensorDetection detection = csvToDectection(mustSensorPacketReceiver->stringTimedReceive()); if ( !connected ) { connected = true; - SetStatus(keyMUSTSensorConnectionStatus, "CONNECTED", true); + SetStatus(keyMUSTSensorConnectionStatus, "CONNECTED"); } tmx::messages::SensorDetectedObject msg = mustDetectionToSensorDetectedObject(detection, sensorId, projString); PLOG(logDEBUG1) << "Sending Simulated SensorDetectedObject Message " << msg << std::endl; this->BroadcastMessage(msg, _name, 0 , IvpMsgFlags_None); } catch( const tmx::utils::UdpServerRuntimeError &e) { - SetStatus(keyMUSTSensorConnectionStatus, "DISCONNECTED", true); + PLOG(logERROR) << "Error occurred processing MUSTSensorDetection" << e << std::endl; + SetStatus(keyMUSTSensorConnectionStatus, "DISCONNECTED"); connected = false; } + catch ( const std::runtime_error &e){ + PLOG(logERROR) << "Error occurred processing MUSTSensorDetection" << e.what() << std::endl; + SetStatus(keyMUSTSensorConnectionStatus, "DISCONNECTED"); + connected = false; + } }else { - SetStatus(keyMUSTSensorConnectionStatus, "DISCONNECTED", true); + SetStatus(keyMUSTSensorConnectionStatus, "DISCONNECTED"); connected = false; } } diff --git a/src/v2i-hub/MUSTSensorDriverPlugin/src/MUSTSensorDriverPlugin.h b/src/v2i-hub/MUSTSensorDriverPlugin/src/MUSTSensorDriverPlugin.h index fd37dfafa..ee13460e8 100644 --- a/src/v2i-hub/MUSTSensorDriverPlugin/src/MUSTSensorDriverPlugin.h +++ b/src/v2i-hub/MUSTSensorDriverPlugin/src/MUSTSensorDriverPlugin.h @@ -58,7 +58,7 @@ namespace MUSTSensorDriverPlugin void UpdateConfigSettings(); void OnConfigChanged(const char *key, const char *value) override; void createUdpServer(const std::string &address, unsigned int port); - + void OnStateChange(IvpPluginState state); void processMUSTSensorDetection(); public: