Skip to content

Commit

Permalink
PR Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbourelly999 committed Jul 29, 2024
1 parent 53a91c6 commit ad9383c
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 25 deletions.
17 changes: 13 additions & 4 deletions src/tmx/Messages/test/Main.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
/*
* Main.cpp
/**
* Copyright (C) 2024 LEIDOS.
*
* Created on: May 10, 2016
* Author: ivp
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

#include <gtest/gtest.h>
Expand Down
2 changes: 1 addition & 1 deletion src/v2i-hub/CDASimAdapter/scripts/send_timestep_udp.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def generate_time_sync():
count_num += 1
sock.sendto(encoded_msg,host)
print( encoded_msg.decode(encoding= 'UTF-8'), 'was sent to ', host)
time.sleep(.1)
time.sleep(5)
except socket.gaierror:

print ('There an error resolving the host')
Expand Down
2 changes: 1 addition & 1 deletion src/v2i-hub/SpatPlugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ This plugin has several configuration parameters. Below these are listed out as

**TSC_IP**: The IPv4 address of the destination Traffic Signal Controller (TSC).

**TSC_Remote_SNMP_Port**: The destination port on the Traffic Signal Controller (TSC) for SNMP NTCIP communication."
**TSC_Remote_SNMP_Port**: The destination port on the Traffic Signal Controller (TSC) for SNMP NTCIP 1202 communication."

**SPAT_Mode**: The format of received SPAT from Traffic Signal Controller (TSC). Acceptance values are BINARY and J2735_HEX.
> [!NOTE]
Expand Down
19 changes: 14 additions & 5 deletions src/v2i-hub/SpatPlugin/src/NTCIP1202OIDs.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,23 @@
#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 ENABLE_SPAT
*/
static const std::string ENABLE_SPAT_OID = "1.3.6.1.4.1.1206.3.5.2.9.44.1.0";
/**
* @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.
*/
namespace NTCIP1202V2{
/**
* @brief OID for ENABLE_SPAT
*/
static const std::string ENABLE_SPAT_OID = "1.3.6.1.4.1.1206.3.5.2.9.44.1.0";
}
23 changes: 17 additions & 6 deletions src/v2i-hub/SpatPlugin/src/SignalControllerConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,23 @@ 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 &intersectionName, unsigned int intersectionId) : spatPacketReceiver(std::make_shared<tmx::utils::UdpServer>(localIp, localPort)) ,scSNMPClient(std::make_shared<tmx::utils::snmp_client>(scIp, scSNMPPort ,"administrator", "", "", "")), signalGroupMapping(signalGroupMapping), intersectionName(intersectionName), intersectionId(intersectionId) {

};
bool SignalControllerConnection::initializeSignalControllerConnection() const {
// TODO : Set Intersection ID and Intersection Name
tmx::utils::snmp_response_obj resp;
resp.val_int = 2;
resp.type = tmx::utils::snmp_response_obj::response_type::INTEGER;
return scSNMPClient->process_snmp_request(NTCIP1202V3::ENABLE_SPAT_OID, tmx::utils::request_type::SET, resp);
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 status = true;
if (enable_spat)
{
tmx::utils::snmp_response_obj enable_spat;
enable_spat.val_int = 2;
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 {
Expand Down
10 changes: 8 additions & 2 deletions src/v2i-hub/SpatPlugin/src/SignalControllerConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,17 @@ namespace SpatPlugin {
* @param intersectionID Intersection ID.
*/
SignalControllerConnection(const std::string &localIp, unsigned int localPort, const std::string &signalGroupMapping, const std::string &scIp, unsigned int scSNMPPort, const std::string &intersectionName, unsigned int intersectionID);

/**
* @brief Method attempts to send SNMP SET request to SNMP object to enable SPAT broadcasting.
* @brief Method attempts to send SNMP SET requests to initialize the TSC. NOTE: Some of the
* OIDs in called in this initialize method may not be exposed by a TSC depending on which
* 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() const;
bool initializeSignalControllerConnection(bool enable_spat, bool set_intersection_id) 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
4 changes: 3 additions & 1 deletion src/v2i-hub/SpatPlugin/src/SpatPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ namespace SpatPlugin {
else {
scConnection = std::make_unique<SignalControllerConnection>(ip_address, port, signal_group_mapping_json, signal_controller_ip, signal_controller_snmp_port, intersection_name, intersection_id);
}
auto connected = scConnection->initializeSignalControllerConnection();
// 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");
if ( connected ) {
SetStatus(keyConnectionStatus, "IDLE");
try {
Expand Down
15 changes: 10 additions & 5 deletions src/v2i-hub/SpatPlugin/test/TestSignalControllerConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <MockSNMPClient.h>
#include <MockUdpServer.h>
#include <tmx/messages/J2735Exception.hpp>
#include <NTCIP1202OIDs.h>

using testing::_;
using testing::Action;
Expand Down Expand Up @@ -91,11 +92,15 @@ namespace SpatPlugin {
};

TEST_F(TestSignalControllerConnection, initialize) {
tmx::utils::snmp_response_obj set_value;
set_value.type = tmx::utils::snmp_response_obj::response_type::INTEGER;
set_value.val_int = 2;
EXPECT_CALL(*mockSnmpClient, process_snmp_request("1.3.6.1.4.1.1206.3.5.2.9.44.1.0", tmx::utils::request_type::SET, set_value)).WillOnce(testing::DoAll(SetArgReferee<2>(set_value), Return(true)));
EXPECT_TRUE(signalControllerConnection->initializeSignalControllerConnection());
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));
}

TEST_F(TestSignalControllerConnection, receiveBinarySPAT) {
Expand Down

0 comments on commit ad9383c

Please sign in to comment.