Skip to content

Commit cbbccf6

Browse files
Merge pull request #29 from OpenDDS/igtd/mc-sel-priority
Priority in Microgrid Controller Selection
2 parents a0ac40e + 96ba18b commit cbbccf6

File tree

19 files changed

+640
-307
lines changed

19 files changed

+640
-307
lines changed

.github/workflows/TMS.yml

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,24 @@ jobs:
5858
fetch-depth: 1
5959
submodules: true
6060

61+
# Setup stacktrace
62+
- name: install gdb
63+
if: runner.os == 'Linux'
64+
run: |
65+
sudo apt-get update
66+
sudo apt-get install gdb
67+
echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
68+
- name: change core file pattern
69+
if: runner.os == 'Linux'
70+
run: |
71+
sudo sysctl -w kernel.core_pattern=core.%e.%p
72+
echo Core file pattern set to:
73+
cat /proc/sys/kernel/core_pattern
74+
6175
# Get 3rd-party Dependencies
6276
- name: 'Install openssl, xerces (Linux)'
6377
if: runner.os == 'Linux'
6478
run: |-
65-
sudo apt-get update
6679
sudo apt-get -y install libssl-dev libxerces-c-dev
6780
- name: 'Install xerces (macOS)'
6881
if: runner.os == 'macOS'
@@ -226,7 +239,7 @@ jobs:
226239
cd OpenDDS
227240
. setenv.sh
228241
cd ../tactical-microgrid-standard
229-
cmake -B build_static
242+
cmake -B build_static -D BUILD_TESTING=TRUE
230243
cmake --build build_static
231244
- name: 'Build TMS application with shared libs (Linux /macOS)'
232245
if: runner.os == 'Linux' || runner.os == 'macOS'
@@ -235,7 +248,7 @@ jobs:
235248
cd OpenDDS
236249
. setenv.sh
237250
cd ../tactical-microgrid-standard
238-
cmake -DBUILD_SHARED_LIBS=yes -B build_shared
251+
cmake -DBUILD_SHARED_LIBS=yes -B build_shared -D BUILD_TESTING=TRUE
239252
cmake --build build_shared
240253
- name: 'Build TMS application with static libs (Windows)'
241254
if: runner.os == 'Windows'
@@ -244,7 +257,7 @@ jobs:
244257
cd OpenDDS
245258
call setenv.cmd
246259
cd ..\tactical-microgrid-standard
247-
cmake -B build_static
260+
cmake -B build_static -D BUILD_TESTING=TRUE
248261
cmake --build build_static
249262
- name: 'Build TMS application with shared libs (Windows)'
250263
if: runner.os == 'Windows'
@@ -253,5 +266,37 @@ jobs:
253266
cd OpenDDS
254267
call setenv.cmd
255268
cd ..\tactical-microgrid-standard
256-
cmake -DBUILD_SHARED_LIBS=yes -B build_shared
269+
cmake -DBUILD_SHARED_LIBS=yes -B build_shared -D BUILD_TESTING=TRUE
257270
cmake --build build_shared
271+
- name: 'Run tests with static libs (Linux)'
272+
if: runner.os == 'Linux'
273+
run: |-
274+
ulimit -c unlimited
275+
cd OpenDDS
276+
. setenv.sh
277+
cd ../tactical-microgrid-standard/build_static
278+
ctest --verbose --output-on-failure
279+
- name: 'Run tests with shared libs (Linux)'
280+
if: runner.os == 'Linux'
281+
run: |-
282+
ulimit -c unlimited
283+
cd OpenDDS
284+
. setenv.sh
285+
cd ../tactical-microgrid-standard/build_shared
286+
ctest --verbose --output-on-failure
287+
- name: 'Run tests with static libs (Windows)'
288+
if: runner.os == 'Windows'
289+
shell: cmd
290+
run: |-
291+
cd OpenDDS
292+
call setenv.cmd
293+
cd ..\tactical-microgrid-standard\build_static
294+
ctest --verbose --output-on-failure -C Debug
295+
- name: 'Run tests with shared libs (Windows)'
296+
if: runner.os == 'Windows'
297+
shell: cmd
298+
run: |-
299+
cd OpenDDS
300+
call setenv.cmd
301+
cd ..\tactical-microgrid-standard\build_shared
302+
ctest --verbose --output-on-failure -C Debug

tactical-microgrid-standard/CMakeLists.txt

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ opendds_target_sources(TMS_Common
2424
target_link_libraries(TMS_Common PUBLIC OpenDDS::Rtps_Udp)
2525
target_compile_features(TMS_Common PUBLIC cxx_std_17)
2626
opendds_bigobj(TMS_Common)
27+
# Generated code with complete type objects enabled for the TMS IDL file
28+
# causes stack overflow on Windows.
29+
# Increase the stack size to 2MB (default is 1MB).
30+
if (MSVC)
31+
target_link_options(TMS_Common PUBLIC "/STACK:2097152")
32+
endif()
2733

2834
add_library(Commands_Idl)
2935
opendds_target_sources(Commands_Idl
@@ -87,16 +93,6 @@ add_executable(Distribution
8793
target_include_directories(Distribution PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
8894
target_link_libraries(Distribution PRIVATE PowerSim_Idl)
8995

90-
# Generated code with complete type objects enabled for the TMS IDL file
91-
# causes stack overflow on Windows.
92-
# Increase the stack size to 2MB (default is 1MB).
93-
if (MSVC)
94-
target_link_options(Controller PRIVATE "/STACK:2097152")
95-
target_link_options(CLI PRIVATE "/STACK:2097152")
96-
target_link_options(Source PRIVATE "/STACK:2097152")
97-
target_link_options(Load PRIVATE "/STACK:2097152")
98-
target_link_options(Distribution PRIVATE "/STACK:2097152")
96+
if(BUILD_TESTING)
97+
add_subdirectory(tests)
9998
endif()
100-
101-
102-
add_subdirectory(tests)

tactical-microgrid-standard/README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ cmake --build <build_dir>
3232
- `cli/`: Command-line interface implementation
3333
- `cli_idl/`: Interface definition files for CLI commands
3434
- `common/`: Shared libraries and utilities
35-
- TMS data model definitions (mil-std-3071_data_model.idl)
35+
- TMS data model definitions (`mil-std-3071_data_model.idl`)
3636
- TMS Handshaking function
3737
- TMS microgrid controller selection
3838
- TMS QoS profiles
@@ -46,13 +46,27 @@ cmake --build <build_dir>
4646

4747
## Testing
4848

49-
Tests can be run using CTest after building the project:
49+
Tests can be run using CTest after building the project with `-D BUILD_TESTING=TRUE`:
5050

5151
```bash
5252
cd <build_dir>
5353
ctest
5454
```
5555

56+
## Configuration
57+
58+
These programs support the following OpenDDS configuration properties. There
59+
are multiple ways to set these, see
60+
[OpenDDS runtime configuration](https://opendds.readthedocs.io/en/master/devguide/run_time_configuration.html)
61+
for more info.
62+
63+
- `TMS_SELECTOR_DEBUG=<boolean>`
64+
- Enables debug logging of the microgrid controller selection process of power devices.
65+
- Command line option example: `-OpenDDS-tms-selector-debug true`
66+
- `TMS_CONTROLLER_DEBUG=<boolean>`
67+
- Enables debug logging of what devices the controller has learned about.
68+
- Command line option example: `-OpenDDS-tms-controller-debug true`
69+
5670
## References
5771

5872
- [Tactical Microgrid Standard (MIL-STD-3071)](https://quicksearch.dla.mil/qsDocDetails.aspx?ident_number=285095)
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#ifndef TMS_COMMON_CONFIGURABLE
2+
#define TMS_COMMON_CONFIGURABLE
3+
4+
#include <dds/DCPS/ConfigStoreImpl.h>
5+
#include <dds/DCPS/InternalDataReaderListener.h>
6+
#include <dds/DCPS/Service_Participant.h>
7+
8+
#include <mutex>
9+
10+
class Configurable {
11+
public:
12+
using Mutex = std::recursive_mutex;
13+
using Guard = std::lock_guard<Mutex>;
14+
15+
Configurable(const std::string& prefix)
16+
: config_prefix_(prefix)
17+
{
18+
}
19+
20+
virtual ~Configurable()
21+
{
22+
Guard g(config_lock_);
23+
24+
if (config_reader_) {
25+
TheServiceParticipant->config_topic()->disconnect(config_reader_);
26+
}
27+
}
28+
29+
void setup_config()
30+
{
31+
Guard g(config_lock_);
32+
33+
if (!config_reader_) {
34+
config_listener_ = OpenDDS::DCPS::make_rch<ConfigListener>(this, config_prefix_ + "_");
35+
config_reader_ = OpenDDS::DCPS::make_rch<OpenDDS::DCPS::ConfigReader>(
36+
TheServiceParticipant->config_store()->datareader_qos(), config_listener_);
37+
TheServiceParticipant->config_topic()->connect(config_reader_);
38+
}
39+
}
40+
41+
const std::string& config_prefix() const
42+
{
43+
return config_prefix_;
44+
}
45+
46+
static bool convert_bool(const OpenDDS::DCPS::ConfigPair& pair, bool& value)
47+
{
48+
DDS::Boolean x = 0;
49+
if (pair.value() == "true") {
50+
value = true;
51+
return true;
52+
} else if (pair.value() == "false") {
53+
value = false;
54+
return true;
55+
} else if (OpenDDS::DCPS::convertToInteger(pair.value(), x)) {
56+
value = x;
57+
return true;
58+
} else {
59+
ACE_ERROR((LM_WARNING, "(%P|%t) WARNING: Configurable::convert_bool: failed to parse boolean for %C=%C\n",
60+
pair.key().c_str(), pair.value().c_str()));
61+
return false;
62+
}
63+
}
64+
65+
virtual bool got_config(const std::string& name, const OpenDDS::DCPS::ConfigPair& pair) = 0;
66+
67+
private:
68+
class ConfigListener : public OpenDDS::DCPS::ConfigListener {
69+
public:
70+
explicit ConfigListener(Configurable* configurable, const std::string& prefix)
71+
: OpenDDS::DCPS::ConfigListener(TheServiceParticipant->job_queue())
72+
, configurable_(*configurable)
73+
, prefix_(prefix)
74+
{
75+
}
76+
77+
void on_data_available(InternalDataReader_rch reader) override
78+
{
79+
OpenDDS::DCPS::ConfigReader::SampleSequence samples;
80+
OpenDDS::DCPS::InternalSampleInfoSequence infos;
81+
reader->read(samples, infos, DDS::LENGTH_UNLIMITED,
82+
DDS::NOT_READ_SAMPLE_STATE, DDS::ANY_VIEW_STATE, DDS::ANY_INSTANCE_STATE);
83+
for (size_t idx = 0; idx != samples.size(); ++idx) {
84+
const auto& info = infos[idx];
85+
if (info.valid_data) {
86+
const auto& pair = samples[idx];
87+
// Match key to prefix and pass rest of key as a short name
88+
if (pair.key().substr(0, prefix_.length()) == prefix_) {
89+
const auto name = pair.key().substr(prefix_.length());
90+
if (!configurable_.got_config(name, pair)) {
91+
ACE_ERROR((LM_WARNING, "(%P|%t) WARNING: Configurable::ConfigListener::on_data_available: "
92+
"%C is not a valid property for %C\n",
93+
name.c_str(), configurable_.config_prefix().c_str()));
94+
}
95+
}
96+
}
97+
}
98+
}
99+
100+
private:
101+
Configurable& configurable_;
102+
const std::string prefix_;
103+
};
104+
105+
mutable Mutex config_lock_;
106+
const std::string config_prefix_;
107+
OpenDDS::DCPS::RcHandle<OpenDDS::DCPS::ConfigReader> config_reader_;
108+
OpenDDS::DCPS::RcHandle<ConfigListener> config_listener_;
109+
};
110+
111+
#endif

0 commit comments

Comments
 (0)