Skip to content

Commit 473f21e

Browse files
committed
refactor(holocat): Fix build issues and improve code quality
- Fix CMake and Dockerfile build configuration errors - Address buffer overflow vulnerability in LogWrapper - Extract HolocatConfig to separate header file - Add relative path resolution for ENI configuration files - Remove dead code and unused member variables - Update documentation - Removed specific example paths from the verify_ecmaster.sh script to enhance portability.
1 parent d73c21d commit 473f21e

File tree

10 files changed

+69
-39
lines changed

10 files changed

+69
-39
lines changed

applications/holocat/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,4 @@ if(EcMaster_FOUND)
2424
add_subdirectory(cpp)
2525
else()
2626
message(FATAL_ERROR "EC-Master SDK not found")
27-
28-
# Exit with failure
29-
exit(1)
3027
endif()

applications/holocat/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# HoloCat EtherCAT Application Dockerfile
22

3-
ARG BASE_SDK_VERSION
3+
ARG BASE_IMAGE
44
FROM ${BASE_IMAGE}
55

66
# Install system dependencies for EtherCAT and real-time operation

applications/holocat/README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# HoloCat - EtherCAT Real-time Integration
22

3-
![HoloCat Logo](docs/holocat_logo.png)
4-
5-
HoloCat is an EtherCAT master application that integrates the acontis EC-Master SDK with NVIDIA's Holoscan platform.
3+
HoloCat is an EtherCAT master application that integrates the acontis EC-Master SDK with NVIDIA's Holoscan platform.
4+
As of this version it is a proof-of concept using user-space Acontis drivers, which is not performance optimized.
65

76
## Overview
87

@@ -23,7 +22,7 @@ HoloCat provides deterministic EtherCAT communication capabilities within the Ho
2322
### Prerequisites
2423
```bash
2524
# Set EC-Master SDK path
26-
export ECMASTER_ROOT=/home/hking/devel/ethercat/ecm
25+
export ECMASTER_ROOT=/path/to/ecmaster/root
2726

2827
# Verify installation (optional)
2928
./applications/holocat/scripts/verify_ecmaster.sh
@@ -38,7 +37,7 @@ export ECMASTER_ROOT=/home/hking/devel/ethercat/ecm
3837
### Run
3938
```bash
4039
# Run with configuration file
41-
./build/holocat/applications/holocat/cpp/holocat --config ./applications/holocat/configs/holocat_config.yaml
40+
./build/holocat/applications/holocat/holocat --config ./applications/holocat/configs/holocat_config.yaml
4241
```
4342

4443
## Configuration
@@ -86,7 +85,7 @@ Use EtherCAT configuration tools to generate your ENI file.
8685
sudo setcap 'cap_net_raw=ep' ./build/holocat/applications/holocat/holocat
8786
```
8887

89-
3. **EC-Master SDK Not Found**
88+
2. **EC-Master SDK Not Found**
9089
```bash
9190
# Verify ECMASTER_ROOT environment variable
9291
echo $ECMASTER_ROOT

applications/holocat/configs/holocat_config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
holocat:
44
# EtherCAT network adapter name
5-
adapter_name: "enxc84bd6d2788c"
5+
adapter_name: "enx6c6e071e9c45"
66

77
# EtherCAT Network Information (ENI) file path
88
# Use environment variable HOLOCAT_ENI_FILE to override, or falls back to config dir
9-
eni_file: "/home/hking/devel/holo/holohub/applications/holocat/configs/eni2.xml"
10-
9+
#eni_file: "/path/to/ethercat/config/ethercat_config.xml"
10+
eni_file: "./eni2.xml"
1111
# EtherCAT bus cycle time in microseconds
1212
# Common values: 1000 (1ms), 500 (0.5ms), 250 (0.25ms)
1313
cycle_time_us: 10000

applications/holocat/cpp/holocat_app.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ HolocatConfig HolocatApp::extract_config() {
7474
target = from_config(key).as<std::decay_t<decltype(target)>>();
7575
} catch (...) {
7676
// Key not found or conversion failed - target remains uninitialized
77+
HOLOSCAN_LOG_WARN("Missing configuration key {}", key);
7778
}
7879
};
7980

@@ -121,6 +122,18 @@ bool HolocatApp::validate_config(HolocatConfig& config) {
121122
return false;
122123
}
123124

125+
// Resolve ENI file path relative to config file directory if it's a relative path
126+
std::filesystem::path eni_path(config.eni_file);
127+
if (eni_path.is_relative()) {
128+
// Get the directory containing the config file
129+
std::filesystem::path config_dir = std::filesystem::path(this->config().config_file()).parent_path();
130+
// Resolve the ENI file path relative to the config directory
131+
eni_path = config_dir / eni_path;
132+
// Update config with the resolved absolute path
133+
config.eni_file = eni_path.string();
134+
HOLOSCAN_LOG_INFO("Resolved relative ENI path to: {}", config.eni_file);
135+
}
136+
124137
// Validate ENI file exists
125138
if (!std::filesystem::exists(config.eni_file)) {
126139
config.error_message = "ENI configuration file not found: " + config.eni_file;

applications/holocat/cpp/holocat_app.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <holoscan/holoscan.hpp>
99
#include "holocat_op.hpp"
10+
#include "holocat_config.hpp"
1011

1112
namespace holocat {
1213

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* holocat_config.hpp
3+
* HoloCat application and EtherCAT configuration struct
4+
*
5+
* Defines the HolocatConfig structure used for configuring EtherCAT
6+
* and HoloCat integration within the NVIDIA Holoscan framework.
7+
*/
8+
9+
#ifndef INC_HOLOCAT_CONFIG_H
10+
#define INC_HOLOCAT_CONFIG_H 1
11+
12+
#include <string>
13+
14+
namespace holocat {
15+
16+
// Configuration structure for Holoscan integration
17+
struct HolocatConfig {
18+
std::string adapter_name;
19+
std::string eni_file;
20+
uint32_t rt_priority;
21+
uint32_t job_thread_priority;
22+
bool enable_rt;
23+
uint32_t dio_out_offset;
24+
uint32_t dio_in_offset;
25+
uint32_t max_acyc_frames;
26+
uint32_t job_thread_stack_size;
27+
std::string log_level;
28+
uint64_t cycle_time_us;
29+
// For validation error reporting
30+
std::string error_message;
31+
};
32+
33+
}
34+
#endif /* INC_HOLOCAT_CONFIG_H */
35+

applications/holocat/cpp/holocat_op.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
//-----------------------------------------------------------------------------
1+
/**
22
// holocat_op.cpp
3-
// HoloCat EtherCAT Operator Implementation
4-
// Based on EC-Master demo application from acontis technologies GmbH
5-
//-----------------------------------------------------------------------------
3+
* HoloCat EtherCAT Operator Implementation
4+
* Based on EC-Master demo application from acontis technologies GmbH
5+
*/
66

77
// System includes
88
#include <chrono>
@@ -37,8 +37,10 @@ EC_T_DWORD HolocatOp::LogWrapper(struct _EC_T_LOG_CONTEXT* pContext,
3737

3838
char buffer[1024];
3939
const char* prefix = "[EC-Master] ";
40-
strcpy(buffer, prefix);
41-
vsnprintf(buffer + strlen(prefix), sizeof(buffer) - strlen(prefix), szFormat, vaArgs);
40+
size_t prefix_len = strlen(prefix);
41+
strncpy(buffer, prefix, sizeof(buffer) - 1);
42+
vsnprintf(buffer + prefix_len, sizeof(buffer) - prefix_len - 1, szFormat, vaArgs);
43+
buffer[sizeof(buffer) - 1] = '\0'; // Ensure null termination
4244
EC_VAEND(vaArgs);
4345

4446
if (dwLogMsgSeverity == EC_LOG_LEVEL_SILENT) {
@@ -162,7 +164,6 @@ void HolocatOp::start()
162164
HOLOSCAN_LOG_ERROR("Cannot initialize EtherCAT-Master: {} (0x{:x})",
163165
ecatGetText(dwRes), dwRes);
164166
throw std::runtime_error("Cannot initialize EtherCAT-Master: " + std::string(ecatGetText(dwRes)));
165-
return;
166167
}
167168
HOLOSCAN_LOG_INFO("Master initialized");
168169

@@ -176,7 +177,9 @@ void HolocatOp::stop()
176177
return ecatSetMasterState(kEthercatStateChangeTimeout_, eEcatState_INIT);
177178
});
178179

180+
// Don't wait for state transition to complete, since that may never happen.
179181
sleep(1);
182+
180183
// deinitialize master
181184
ecatDeinitMaster();
182185
}

applications/holocat/cpp/holocat_op.hpp

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,10 @@
1717
#include <cstdint>
1818
#include <future>
1919
#include <holoscan/holoscan.hpp>
20+
#include "holocat_config.hpp"
2021

2122
namespace holocat {
2223

23-
// Configuration structure for Holoscan integration
24-
struct HolocatConfig {
25-
std::string adapter_name;
26-
std::string eni_file;
27-
uint64_t cycle_time_us;
28-
uint32_t rt_priority;
29-
uint32_t job_thread_priority;
30-
bool enable_rt;
31-
uint32_t dio_out_offset;
32-
uint32_t dio_in_offset;
33-
uint32_t max_acyc_frames;
34-
uint32_t job_thread_stack_size;
35-
std::string log_level;
36-
// For validation error reporting
37-
std::string error_message;
38-
};
39-
4024
/**
4125
* @brief HoloCat EtherCAT Operator
4226
*
@@ -99,7 +83,6 @@ class HolocatOp : public holoscan::Operator {
9983

10084
// EtherCAT state variables
10185
EC_T_BOOL bHasConfig_ = EC_FALSE;
102-
EC_T_VOID* pvCycFrameReceivedEvent_ = EC_NULL;
10386

10487
// Startup state machine variables
10588
enum class StartupState {

applications/holocat/scripts/verify_ecmaster.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ if [ -z "$ECMASTER_ROOT" ]; then
3535
print_status "ERROR" "ECMASTER_ROOT environment variable not set"
3636
echo " Set it to your EC-Master installation path:"
3737
echo " export ECMASTER_ROOT=/path/to/ecm"
38-
echo " Example: export ECMASTER_ROOT=/home/hking/devel/ethercat/ecm"
3938
exit 1
4039
else
4140
print_status "OK" "ECMASTER_ROOT set to: $ECMASTER_ROOT"

0 commit comments

Comments
 (0)