Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbourelly999 committed Jul 30, 2024
1 parent db47284 commit b107548
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 31 deletions.
10 changes: 0 additions & 10 deletions src/v2i-hub/SpatPlugin/src/NTCIP1202OIDs.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@
#pragma once

#include <string>
/**
* @brief Contains OIDs (Object Identifier) described in NTCIP 1202 V3 (National Transporation Communication for ITS Protocol Object
* Definitions for Actuated Signal Controllers (ASC) Interface) used for SPaT Plugin functionality.
*/
namespace NTCIP1202V3{
/**
* @brief OID for Intersection ID.
*/
static const std::string INTERSECTION_ID = " 1.3.6.1.4.1.1206.4.2.1.17.1.2.1.2";
}
/**
* @brief Contains OIDs (Object Identifier) described in NTCIP 1202 V3 (National Transporation Communication for ITS Protocol Object
* Definitions for Actuated Signal Controllers (ASC) Interface) used for SPaT Plugin functionality.
Expand Down
18 changes: 7 additions & 11 deletions src/v2i-hub/SpatPlugin/src/SignalControllerConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ namespace SpatPlugin {
SignalControllerConnection::SignalControllerConnection(const std::string &localIp, unsigned int localPort, const std::string &signalGroupMapping, const std::string &scIp, unsigned int scSNMPPort, const std::string &scSNMPCommunity, const std::string &intersectionName, unsigned int intersectionId) : spatPacketReceiver(std::make_shared<tmx::utils::UdpServer>(localIp, localPort)) ,scSNMPClient(std::make_shared<tmx::utils::snmp_client>(scIp, scSNMPPort ,scSNMPCommunity, "", "", "")), signalGroupMapping(signalGroupMapping), intersectionName(intersectionName), intersectionId(intersectionId) {

};
bool SignalControllerConnection::initializeSignalControllerConnection(bool enable_spat, bool set_intersection_id) const {
// TODO : Update to more generic TSC Initialization process that simply follows NTCIP 1202 version guidelines.
bool SignalControllerConnection::initializeSignalControllerConnection(bool enable_spat) const {
// TODO : Update to more generic TSC Initialization process that simply follows NTCIP 1202 version guidelines. Also
// set intersection ID in J2735_HEX SPAT Mode. The HEX payload should include a intersection ID.
bool status = true;
if (enable_spat)
{
Expand All @@ -32,19 +33,14 @@ namespace SpatPlugin {
enable_spat.type = tmx::utils::snmp_response_obj::response_type::INTEGER;
status = status && scSNMPClient->process_snmp_request(NTCIP1202V2::ENABLE_SPAT_OID, tmx::utils::request_type::SET, enable_spat);
}
if ( set_intersection_id ) {
tmx::utils::snmp_response_obj intersection_id;
intersection_id.val_int = intersectionId;
intersection_id.type = tmx::utils::snmp_response_obj::response_type::INTEGER;
status = status && scSNMPClient->process_snmp_request(NTCIP1202V3::INTERSECTION_ID, tmx::utils::request_type::SET, intersection_id);
}

return status;
};

void SignalControllerConnection::receiveBinarySPAT(const std::shared_ptr<SPAT> &spat, uint64_t timeMs ) const {
FILE_LOG(tmx::utils::logDEBUG) << "Receiving binary SPAT ..." << std::endl;
char buf[1000];
auto numBytes = spatPacketReceiver->TimedReceive(buf, 1000, 1000);
char buf[SPAT_BINARY_BUFFER_SIZE];
auto numBytes = spatPacketReceiver->TimedReceive(buf, SPAT_BINARY_BUFFER_SIZE, UDP_SERVER_TIMEOUT_MS);
if (numBytes > 0)
{
// Convert Binary buffer to SPAT pointer
Expand All @@ -64,7 +60,7 @@ namespace SpatPlugin {

void SignalControllerConnection::receiveUPERSPAT(std::shared_ptr<tmx::messages::SpatEncodedMessage> &spatEncoded_ptr) const {
FILE_LOG(tmx::utils::logDEBUG1) << "Receiving J2725 HEX SPAT ..." << std::endl;
auto payload = spatPacketReceiver->stringTimedReceive( 1000 );
auto payload = spatPacketReceiver->stringTimedReceive( UDP_SERVER_TIMEOUT_MS );
auto index = payload.find("Payload=");
if ( index != std::string::npos ) {
// Retreive hex string payload
Expand Down
9 changes: 6 additions & 3 deletions src/v2i-hub/SpatPlugin/src/SignalControllerConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ namespace SpatPlugin {
* @brief Numeric identifier for intersection in SPaT messages.
*/
unsigned int intersectionId;


const static unsigned int SPAT_BINARY_BUFFER_SIZE = 1000;

const static unsigned int UDP_SERVER_TIMEOUT_MS = 1000;

friend class TestSignalControllerConnection;

public:
Expand All @@ -82,10 +86,9 @@ namespace SpatPlugin {
* version of the NTCIP 1202 standard they are complaint with. To avoid failures please use
* the bool flags to indicate which OIDs need to be set for initialization.
* @param enable_spat bool flag on whether to attempt to set enable spat to true (NOT available for NTCIP 1202 versions >= 3 )
* @param set_intersection_id bool flag on whether to set intersection id (NOT available for NTCIP 1202 versions < 3)
* @return true if successful and false if not.
*/
bool initializeSignalControllerConnection(bool enable_spat, bool set_intersection_id) const;
bool initializeSignalControllerConnection(bool enable_spat) const;
/**
* @brief Method to receive SPaT data in binary format from TSC.
* @param spat an empty SPaT pointer to which the SPAT data will be written.
Expand Down
3 changes: 1 addition & 2 deletions src/v2i-hub/SpatPlugin/src/SpatPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ namespace SpatPlugin {
scConnection = std::make_unique<SignalControllerConnection>(ip_address, port, signal_group_mapping_json, signal_controller_ip, signal_controller_snmp_port,signal_controller_snmp_community, intersection_name, intersection_id);
}
// Only enable spat broadcast in simulation mode. TFHRC TSCs do not expose this OID so calls to it will fail in hardware deployment
// Only set intersection ID in J2735_HEX SPAT Mode. Is only available for TSCs that support J2735 UPER HEX SPaT broadcast, which are all NTCIP 1202V3 or later.
auto connected = scConnection->initializeSignalControllerConnection(PluginClientClockAware::isSimulationMode(), this->spatMode == "J2735_HEX");
auto connected = scConnection->initializeSignalControllerConnection(PluginClientClockAware::isSimulationMode());
if ( connected ) {
SetStatus(keyConnectionStatus, "IDLE");
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,8 @@ namespace SpatPlugin {
tmx::utils::snmp_response_obj enable_spat;
enable_spat.type = tmx::utils::snmp_response_obj::response_type::INTEGER;
enable_spat.val_int = 2;
tmx::utils::snmp_response_obj intersection_id;
intersection_id.type = tmx::utils::snmp_response_obj::response_type::INTEGER;
intersection_id.val_int = 9001;
EXPECT_CALL(*mockSnmpClient, process_snmp_request(NTCIP1202V2::ENABLE_SPAT_OID, tmx::utils::request_type::SET, enable_spat)).WillOnce(testing::DoAll(SetArgReferee<2>(enable_spat), Return(true)));
EXPECT_CALL(*mockSnmpClient, process_snmp_request(NTCIP1202V3::INTERSECTION_ID, tmx::utils::request_type::SET, intersection_id)).WillOnce(testing::DoAll(SetArgReferee<2>(enable_spat), Return(true)));
EXPECT_TRUE(signalControllerConnection->initializeSignalControllerConnection(true, true));
EXPECT_TRUE(signalControllerConnection->initializeSignalControllerConnection(true));
}

TEST_F(TestSignalControllerConnection, receiveBinarySPAT) {
Expand Down

0 comments on commit b107548

Please sign in to comment.