Skip to content

Commit

Permalink
update RSU status message
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-du-car committed Nov 7, 2023
1 parent 4b70589 commit 0ec2806
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/tmx/Messages/include/MessageTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ static CONSTEXPR const char *MSGSUBTYPE_OUTGOING_STRING = "Outgoing";
static CONSTEXPR const char *MSGSUBTYPE_SHUTDOWN_STRING = "Shutdown";
static CONSTEXPR const char *MSGSUBTYPE_TIMESYNC_STRING = "TimeSync";
static CONSTEXPR const char *MSGSUBTYPE_SENSOR_DETECTED_OBJECT_STRING = "SensorDetectedObject";
static CONSTEXPR const char *MSGSUBTYPE_RSU_STATUS_STRING = "RSUStatus";

} /* End namespace messages */

Expand Down
25 changes: 25 additions & 0 deletions src/tmx/Messages/include/RSUStatusMessage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once


#include <tmx/messages/message.hpp>
#include "MessageTypes.h"


namespace tmx::messages {


class RSUStatusMessage : public tmx::message
{
public:
RSUStatusMessage() {}

/// Message type for routing this message through TMX core.
static constexpr const char* MessageType = MSGTYPE_APPLICATION_STRING;

/// Message sub type for routing this message through TMX core.
static constexpr const char* MessageSubType = MSGSUBTYPE_RSU_STATUS_STRING;
};

} /* namespace tmx::messages */


2 changes: 2 additions & 0 deletions src/tmx/TmxUtils/src/SNMPClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ namespace tmx::utils {
// get Integer value
if(vars->type == ASN_INTEGER){
if(vars->val.integer){
val.type = snmp_response_obj::response_type::INTEGER;
val.val_int = *vars->val.integer;
PLOG(logDEBUG1) << "Integer value in object: " << val.val_int;
}
Expand All @@ -194,6 +195,7 @@ namespace tmx::utils {
{
val.val_string.push_back(vars->val.string[i]);
}
val.type = snmp_response_obj::response_type::STRING;

}
else{
Expand Down
25 changes: 16 additions & 9 deletions src/v2i-hub/RSUHealthMonitorPlugin/src/RSUHealthMonitorPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ namespace RSUHealthMonitor
ptree pt;
istringstream iss(json_str);
read_json(iss, pt);
_rsuOIDConfigMap.clear();
BOOST_FOREACH (ptree::value_type &child, pt.get_child("RSUOIDConfig"))
{
// Array elements have no names.
Expand Down Expand Up @@ -84,14 +85,14 @@ namespace RSUHealthMonitor
{
while (true)
{
PLOG(logERROR) << "RSU status update call at every " << _interval;

for_each(_rsuOIDConfigMap.begin(), _rsuOIDConfigMap.end(), [this](RSUOIDConfig &config)
PLOG(logDEBUG) << "RSU status update call at every " << _interval << "seconds!";
Json::Value rsuStatuJson;
//Sending RSU SNMP call for each field as each field has its own OID.
for_each(_rsuOIDConfigMap.begin(), _rsuOIDConfigMap.end(), [this, &rsuStatuJson](RSUOIDConfig &config)
{
try
{
Json::Value rsuStatuJson;
PLOG(logINFO) << "SNMP RSU status call for field:"<< config.field << ", OID: " << config.oid << " RSU IP: " << _rsuIp << ", RSU port: " << _snmpPort << ", User: " << _securityUser << ", auth pass phrase: " << _authPassPhrase;
PLOG(logINFO) << "SNMP RSU status call for field:"<< config.field << ", OID: " << config.oid;
snmp_response_obj responseVal;
if(_snmpClientPtr != nullptr)
{
Expand All @@ -104,16 +105,22 @@ namespace RSUHealthMonitor
{
string response_str(responseVal.val_string.begin(), responseVal.val_string.end());
rsuStatuJson[config.field] = response_str;
}
Json::FastWriter fasterWirter;
string json_str = fasterWirter.write(rsuStatuJson);
PLOG(logINFO) << "SNMP Response: "<< json_str;
}
}
}
catch (std::exception &ex)
{
PLOG(logERROR) << "SNMP call failure due to: " << ex.what();
} });
//Broadcast the RSU status info when there are any RSU responses.
if (!rsuStatuJson.empty())
{
Json::FastWriter fasterWirter;
string json_str = fasterWirter.write(rsuStatuJson);
tmx::messages::RSUStatusMessage sendRsuStatusMsg;
sendRsuStatusMsg.set_contents(json_str);
BroadcastMessage(sendRsuStatusMsg);
}
this_thread::sleep_for(chrono::seconds(_interval));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <boost/property_tree/json_parser.hpp>
#include "SNMPClient.h"
#include <jsoncpp/json/json.h>
#include "RSUStatusMessage.h"

using namespace tmx::utils;
using namespace std;
Expand Down

0 comments on commit 0ec2806

Please sign in to comment.