-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Vh 1216 fix spat plugin segfault simulation (#621)
<!-- Thanks for the contribution, this is awesome. --> # PR Details ## Description This pull request updates the SPAT plugin to fix a number of issues with the legacy implementation. - Overly complex legacy code in SPaT Plugin - Reduced duplication using existing classes for SNMP Client and UDP Server. Previous implementation created custom SNMP Client and UDP server. - Reduced use of raw pointers to mitigate the possibility of memory leaks. - Improved documentation for SPaT plugin. - Added unit testing - Added functionality to consume J2735 UPER HEX SPaT from signal controller. Additionally to help provide these improvements in the SPaT plugin, several improvements were made in the TMX Utils functionality. - Fix SNMP Client to have working SNMP Set implementation (allows reused of existing client instead of standalone SNMP client implementation for SPaT plugin) - Improvement PluginClientClockAware base class to automatically subscribe to TimeSync messages and getter for clock to wait for clock initialization. These improvements removed all simulation specific implementation from inheriting classes including the SpatPlugin <!--- Describe your changes in detail --> ## Related Issue [VH-1216](https://usdot-carma.atlassian.net/browse/VH-1216) <!--- This project only accepts pull requests related to open issues --> <!--- If suggesting a new feature or change, please discuss it in an issue first --> <!--- If fixing a bug, there should be an issue describing it with steps to reproduce --> <!--- Please link to the issue here: --> ## Motivation and Context Fix SPaT plugin for simulation and improve overall usability and maintainability. <!--- Why is this change required? What problem does it solve? --> ## How Has This Been Tested? Tested using virtual signal controller for both binary and hex spat payloads. Also tested in sim mode using the following steps 1) Deploy Virtual Signal Controller. 2) Deploy V2X-Hub in SIM MODE using Dev Container deployment 3) Run `src/v2i-hub/CDASimAdapter/scripts/send_timestep_udp.py` script to send periodic time sync messages. 4) Enable SPaT Plugin <!--- Please describe in detail how you tested your changes. --> <!--- Include details of your testing environment, and the tests you ran to --> <!--- see how your change affects other areas of the code, etc. --> ## Types of changes <!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [x] Defect fix (non-breaking change that fixes an issue) - [x] New feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that cause existing functionality to change) ## Checklist: <!--- Go over all the following points, and put an `x` in all the boxes that apply. --> <!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> - [ ] I have added any new packages to the sonar-scanner.properties file - [x] My change requires a change to the documentation. - [x] I have updated the documentation accordingly. - [x] I have read the **CONTRIBUTING** document. [V2XHUB Contributing Guide](https://github.com/usdot-fhwa-OPS/V2X-Hub/blob/develop/Contributing.md) - [x] I have added tests to cover my changes. - [x] All new and existing tests passed. [VH-1216]: https://usdot-carma.atlassian.net/browse/VH-1216?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
- Loading branch information
1 parent
2b9f38f
commit 2303a49
Showing
34 changed files
with
1,387 additions
and
993 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Copyright (C) 2024 LEIDOS. | ||
* | ||
* 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> | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
testing::InitGoogleTest(&argc, argv); | ||
return RUN_ALL_TESTS(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <gtest/gtest.h> | ||
#include "TimeSyncMessage.h" | ||
namespace tmx::messages { | ||
|
||
TEST(TestTimeSyncMessage, to_string) { | ||
TimeSyncMessage msg(20, 30); | ||
std::string json = "{ \"timestep\":20, \"seq\":30}"; | ||
EXPECT_EQ( json, msg.to_string()); | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,20 @@ | ||
PROJECT ( SpatPlugin VERSION 7.6.0 LANGUAGES CXX ) | ||
|
||
SET (TMX_PLUGIN_NAME "SPAT") | ||
|
||
FIND_PACKAGE (XercesC REQUIRED) | ||
FIND_PACKAGE (NetSNMP REQUIRED) | ||
FIND_PACKAGE (carma-clock REQUIRED) | ||
|
||
BuildTmxPlugin () | ||
|
||
TARGET_INCLUDE_DIRECTORIES ( ${PROJECT_NAME} PUBLIC ${XercesC_INCLUDE_DIRS} ${NETSNMP_INCLUDE_DIRS}) | ||
TARGET_LINK_LIBRARIES ( ${PROJECT_NAME} tmxutils ::carma-clock rdkafka++ jsoncpp ${XercesC_LIBRARY} ${NETSNMP_LIBRARIES}) | ||
|
||
################################ | ||
# GTest | ||
################################ | ||
enable_testing() | ||
|
||
add_library(${PROJECT_NAME}_spat_lib src/NTCIP1202.cpp src/signalController.cpp src/PedestrianDetectionForSPAT.cpp) | ||
target_include_directories( ${PROJECT_NAME}_spat_lib PUBLIC | ||
${PROJECT_SOURCE_DIR}/src | ||
${XercesC_INCLUDE_DIRS} ${NETSNMP_INCLUDE_DIRS}) | ||
target_link_libraries(${PROJECT_NAME}_spat_lib PUBLIC | ||
tmxutils ::carma-clock ${XercesC_LIBRARY} ${NETSNMP_LIBRARIES}) | ||
project( SpatPlugin VERSION 7.6.0 LANGUAGES CXX ) | ||
set(TMX_PLUGIN_NAME "SPAT") | ||
set(CMAKE_CXX_STANDARD 17) | ||
find_package(carma-clock REQUIRED) | ||
BuildTmxPlugin() | ||
target_link_libraries(${PROJECT_NAME} tmxutils ::carma-clock) | ||
add_library(${PROJECT_NAME}_lib src/NTCIP1202.cpp | ||
src/SignalControllerConnection.cpp) | ||
target_link_libraries(${PROJECT_NAME}_lib PUBLIC tmxutils ::carma-clock ) | ||
############# | ||
## Testing ## | ||
############# | ||
enable_testing() | ||
set(BINARY ${PROJECT_NAME}_test) | ||
|
||
file(GLOB_RECURSE TEST_SOURCES LIST_DIRECTORIES false test/*.h test/*.cpp) | ||
|
||
set(SOURCES ${TEST_SOURCES} | ||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/test) | ||
|
||
set(SOURCES ${TEST_SOURCES} WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/test) | ||
add_executable(${BINARY} ${TEST_SOURCES}) | ||
|
||
add_test(NAME ${BINARY} COMMAND ${BINARY}) | ||
target_link_libraries(${BINARY} PUBLIC ${PROJECT_NAME}_spat_lib ${TMXAPI_LIBRARIES} | ||
${ASN_J2735_LIBRARIES} | ||
${MYSQL_LIBRARIES} | ||
${MYSQLCPPCONN_LIBRARIES} | ||
tmxutils | ||
${UUID_LIBRARY} | ||
gtest) | ||
target_include_directories(${BINARY} PUBLIC src/) | ||
target_link_libraries(${BINARY} PUBLIC ${PROJECT_NAME}_lib gtest) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# SPaT Plugin Documentation | ||
|
||
## Introduction | ||
|
||
The SPaT Plugin is responsible for receiving information from the Traffic Signal Controller (TSC or SC) necessary for broadcasting Signal Phase and Timing (SPaT) messages. This includes querying any SNMP objects to determine TSC state and listen for any broadcast SPaT information from the TSC. | ||
|
||
## Related Plugins | ||
|
||
A list of plugins related to the SPaT Plugin. | ||
|
||
### Immediate Forward Plugin | ||
|
||
For RSU Immediate Message Forwarding (IMF) functionality forward SPaT (Signal Phase and Timing Messages). | ||
|
||
### Map Plugin | ||
|
||
The SPaT and MAP messages are strongly related in that MAP messages are required to be able to understand SPaT messages. Map | ||
messages offer data about which signal groups impact which lanes in a given intersection. | ||
|
||
## Configuration/Deployment | ||
|
||
This plugin has several configuration parameters. Below these are listed out as together with descriptions on how to set them. | ||
|
||
**Intersection_ID**: The intersection id for SPAT generated by this plugin (Note Only used in SPAT MODE = BINARY). | ||
|
||
**Intersection_Name**: The intersection name for SPAT generated by this plugin (Note Only used in SPAT MODE = BINARY). | ||
|
||
**SignalGroupMapping**: JSON data defining a list of SignalGroups and phases (Note Only used in SPAT MODE = BINARY). | ||
|
||
**Local_IP**: The IPv4 address of the local computer for receiving Traffic Signal Controller Broadcast Messages. | ||
|
||
**Local_UDP_Port**: The local UDP port for reception of Traffic Signal Controller Broadcast Messages from the TSC. | ||
|
||
**TSC_IP**: The IPv4 address of the destination Traffic Signal Controller (TSC). | ||
|
||
**TSC_SNMP_Port**: The destination port on the Traffic Signal Controller (TSC) for SNMP NTCIP 1202 communication." | ||
|
||
**TSC_SNMP_Community**: The SNMP Community used for sending SNMP NTCIP 1202 communication to Traffic Signal Controller (TSC). Please refer TSC vendor documentation for SNMP Community. | ||
|
||
**SPAT_Mode**: The format of received SPAT from Traffic Signal Controller (TSC). Acceptance values are BINARY and J2735_HEX. | ||
> [!NOTE] | ||
> **J2735_HEX** is a new added SPAT format. If your TSC is able to send UPER SPAT directly to an RSU, this is the format in which it is being sent. Below is a screen shot of J2735_HEX SPaT via TCP Dump | ||
![Alt text](docs/hex_tcpdump.png) | ||
|
||
## Design | ||
|
||
![Alt text](docs/spat_plugin_design.png) | ||
The diagram above illustrates roughly how the SPaT Plugin functions. The SPaT Plugin is able to get and set Traffic Signal Controller (TSC or SC) configuration via SNMP requests. The defined objects and behaviour are standardize via NTCIP 1202, the National Transportation Communications for ITS Protocol Object Definitions for Actuated Signal Controllers (ASC) Interface. It also receives live Signal Phase and Timing Data from the TSC via UDP packets. Using this information, the SPaT plugin generates J2725 SPaT messags which are eventually forwarded to and Road Side Unit (RSU) radio for broadcast to actors at or near the intersection. | ||
|
||
### Messages | ||
|
||
**SPAT**: This message contains information from the traffic signal controller about Signal Phase and Timing (SPaT). To use this information for vehicle control the MAP message is also required for mapping signal phase to lanes in an intersection. | ||
|
||
## Functionality Testing | ||
|
||
Testing the functionality of a configured instance of the SPaT plugin requires access to a Traffic Signal Controller (TSC) or Virtual Traffic Signal Controller. | ||
|
||
1) Configure the TSC to broadcast SPAT to an open port your edge device. | ||
1) Take note of the format of this data. This can be done by consulting the TSC manual or by inspecting it using `tcpdump -i any port <open_port> -X`.**BINARY** payloads will be complete human unreadable collection of bytes and **J2735_HEX** will include human readable header information like `Type=SPAT`, `PSID=0x8002`, and a `Payload` followed by string HEX of the UPER encoded J2735 SPaT message. | ||
2) Inspect the configurations of your TSC to determine Signal Group to phase mapping and the SNMP port. This can be found either at the **Channel Table** or the **Load Switch Configuration** on the TSC. Using these configurations create your signal group mapping JSON (Example shown below) | ||
```json | ||
|
||
{"SignalGroups": | ||
[ | ||
{"SignalGroupId":1,"Phase":1,"Type":"vehicle"}, | ||
{"SignalGroupId":2,"Phase":2,"Type":"vehicle"}, | ||
{"SignalGroupId":3,"Phase":3,"Type":"vehicle"}, | ||
{"SignalGroupId":4,"Phase":4,"Type":"vehicle"}, | ||
{"SignalGroupId":5,"Phase":5,"Type":"vehicle"}, | ||
{"SignalGroupId":6,"Phase":6,"Type":"vehicle"}, | ||
{"SignalGroupId":7,"Phase":7,"Type":"vehicle"}, | ||
{"SignalGroupId":8,"Phase":8,"Type":"vehicle"}, | ||
{"SignalGroupId":9,"Phase":2,"Type":"pedestrian"}, | ||
{"SignalGroupId":10,"Phase":4,"Type":"pedestrian"}, | ||
{"SignalGroupId":11,"Phase":6,"Type":"pedestrian"}, | ||
{"SignalGroupId":12,"Phase":8,"Type":"pedestrian"} | ||
] | ||
} | ||
``` | ||
|
||
3) Configure your SPaT Plugin with the information gathers in steps 1 and 2. | ||
4) Check the Status and Messages tabs on the plugin after enabling it. Once enabled the SPAT Plugin should be receive SPAT messages at 10Hz (visible in the Messages tab) and have a status of "CONNECTED" |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.