Skip to content

Commit 5d4e584

Browse files
authored
Merge pull request #10 from openDAQ/improvements-for-gui
Improvements for GUI. Brief: - reworking of FBs properties; - reworking of FBs statuses; - merging two FB - Raw and JSON to MQTTSubscriberFb; - preview signals for publisher and subscriber FBs; - arrays for JSON decoder FB; - arrays for Single mode in publisher FB; - common improvements and bugfixing;
2 parents bc97b26 + 42176a5 commit 5d4e584

83 files changed

Lines changed: 4522 additions & 3296 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Build and Test
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, synchronize, ready_for_review]
6+
7+
jobs:
8+
build-and-test:
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
include:
13+
- os: ubuntu-latest
14+
generator: Ninja
15+
- os: windows-latest
16+
generator: "Visual Studio 17 2022"
17+
18+
runs-on: ${{ matrix.os }}
19+
20+
steps:
21+
- name: Install additional dependencies
22+
if: matrix.os == 'ubuntu-latest'
23+
run: |
24+
sudo apt-get install -y --no-install-recommends mono-runtime libmono-system-json-microsoft4.0-cil libmono-system-data4.0-cil
25+
26+
- name: Checkout project repo
27+
uses: actions/checkout@v4
28+
with:
29+
ref: ${{ github.event.inputs.branch || github.event.client_payload.branch || github.ref }}
30+
31+
- name: Configure project with CMake
32+
run: cmake -B build/output -S . -G "${{ matrix.generator }}" -DOPENDAQ_MQTT_ENABLE_TESTS=ON -DCMAKE_BUILD_TYPE=Debug
33+
34+
- name: Build project with CMake
35+
run: cmake --build build/output --config Debug
36+
37+
- name: Install and run mosquitto Linux
38+
if: matrix.os == 'ubuntu-latest'
39+
run: |
40+
sudo apt-get install -y --no-install-recommends mosquitto
41+
42+
- name: Run project tests with CMake
43+
if: matrix.os == 'ubuntu-latest'
44+
run: ctest --test-dir build/output --output-on-failure -C Debug

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ include/*
5353
lib/*
5454
bin/*
5555
test/test_runner
56+
docker/*
57+
build*/*
5658

5759
CMakeLists.txt.user
5860
.vscode
5961
.clang-format
62+
.dockerignore
63+

CMakeLists.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,15 @@ if(OPENDAQ_MQTT_MODULE_ENABLE_SSL)
6161
add_compile_definitions(OPENDAQ_MQTT_MODULE_ENABLE_SSL)
6262
endif()
6363

64+
set(MQTT_MODULE_VERSION "0.1.0" CACHE STRING "MQTT module version" FORCE)
65+
66+
if(OPENDAQ_MQTT_ENABLE_TESTS)
67+
enable_testing()
68+
endif()
69+
6470
add_subdirectory(external)
65-
add_subdirectory(helper_utils)
66-
add_subdirectory(mqtt_streaming_protocol)
67-
add_subdirectory(mqtt_streaming_module)
71+
add_subdirectory(shared)
72+
add_subdirectory(modules)
6873

6974
if(OPENDAQ_DEVICE_EXAMPLE_ENABLE_EXAMPLE_APPS)
7075
message(STATUS "Example applications have been enabled")

README.md

Lines changed: 47 additions & 53 deletions
Large diffs are not rendered by default.

examples/custom-mqtt-sub/src/custom-mqtt-sub.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ std::string to_string(daq::DataPacketPtr packet)
4646
case SampleType::Int64:
4747
data = std::to_string(*(static_cast<int64_t*>(packet.getData())));
4848
break;
49+
case SampleType::String:
4950
case SampleType::Binary:
5051
data = '\"' + std::string(static_cast<char*>(packet.getData()), packet.getDataSize()) + '\"';
5152
break;
@@ -123,24 +124,24 @@ int main(int argc, char* argv[])
123124

124125
// Create OpenDAQ instance and add MQTT broker FB
125126
const InstancePtr instance = InstanceBuilder().addModulePath(MODULE_PATH).build();
126-
const std::string rootFbName = "RootMqttFb";
127-
auto rootFbConfig = instance.getAvailableFunctionBlockTypes().get(rootFbName).createDefaultConfig();
128-
rootFbConfig.setPropertyValue("MqttBrokerAddress", appConfig.brokerAddress);
129-
auto brokerFB = instance.addFunctionBlock(rootFbName, rootFbConfig);
127+
const std::string clientFbName = "MQTTClientFB";
128+
auto clientFbConfig = instance.getAvailableFunctionBlockTypes().get(clientFbName).createDefaultConfig();
129+
clientFbConfig.setPropertyValue("BrokerAddress", appConfig.brokerAddress);
130+
auto brokerFB = instance.addFunctionBlock(clientFbName, clientFbConfig);
130131
auto availableFbs = brokerFB.getAvailableFunctionBlockTypes();
131132

132-
const std::string jsonFbName = "JsonSubscriberMqttFb";
133-
std::cout << "Try to add the " << jsonFbName << std::endl;
133+
const std::string subFbName = "MQTTSubscriberFB";
134+
std::cout << "Try to add the " << subFbName << std::endl;
134135

135-
auto config = availableFbs.get(jsonFbName).createDefaultConfig();
136-
config.setPropertyValue("JsonConfigFile", appConfig.configFilePath);
136+
auto config = availableFbs.get(subFbName).createDefaultConfig();
137+
config.setPropertyValue("JSONConfigFile", appConfig.configFilePath);
137138

138-
// Add the JSON function block to the broker FB
139-
daq::FunctionBlockPtr jsonFb = brokerFB.addFunctionBlock(jsonFbName, config);
139+
// Add the subscriber function block to the broker FB
140+
daq::FunctionBlockPtr subFb = brokerFB.addFunctionBlock(subFbName, config);
140141

141142
// Create packet readers for all signals
142143
auto signals = List<daq::ISignal>();
143-
const auto fbs = jsonFb.getFunctionBlocks();
144+
const auto fbs = subFb.getFunctionBlocks();
144145
for (const auto& fb : fbs)
145146
{
146147
const auto sig = fb.getSignals();

examples/raw-mqtt-sub/src/raw-mqtt-sub.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,24 +55,26 @@ int main(int argc, char* argv[])
5555

5656
// Create OpenDAQ instance and add MQTT broker FB
5757
const InstancePtr instance = InstanceBuilder().addModulePath(MODULE_PATH).build();
58-
const std::string rootFbName = "RootMqttFb";
59-
auto rootFbConfig = instance.getAvailableFunctionBlockTypes().get(rootFbName).createDefaultConfig();
60-
rootFbConfig.setPropertyValue("MqttBrokerAddress", appConfig.brokerAddress);
61-
auto brokerFB = instance.addFunctionBlock(rootFbName, rootFbConfig);
58+
const std::string clientFbName = "MQTTClientFB";
59+
auto clientFbConfig = instance.getAvailableFunctionBlockTypes().get(clientFbName).createDefaultConfig();
60+
clientFbConfig.setPropertyValue("BrokerAddress", appConfig.brokerAddress);
61+
auto brokerFB = instance.addFunctionBlock(clientFbName, clientFbConfig);
6262
auto availableFbs = brokerFB.getAvailableFunctionBlockTypes();
6363

64-
const std::string fbName = "RawSubscriberMqttFb";
64+
const std::string fbName = "MQTTSubscriberFB";
6565
std::cout << "Try to add the " << fbName << std::endl;
6666

67-
// Create RAW function block configuration
67+
// Create subscriber function block configuration
6868
auto config = availableFbs.get(fbName).createDefaultConfig();
6969
config.setPropertyValue("Topic", appConfig.topic);
70+
config.setPropertyValue("EnablePreviewSignal", True);
71+
config.setPropertyValue("MessageIsString", True);
7072

71-
// Add the RAW function block to the broker FB
72-
daq::FunctionBlockPtr rawFb = brokerFB.addFunctionBlock(fbName, config);
73+
// Add the subscriber function block to the broker FB
74+
daq::FunctionBlockPtr subFb = brokerFB.addFunctionBlock(fbName, config);
7375

7476
// Create packet readers for a signal
75-
const auto signal = rawFb.getSignals()[0];
77+
const auto signal = subFb.getSignals()[0];
7678
PacketReaderPtr reader = daq::PacketReader(signal);
7779

7880
// Start a thread to read packets from the reader

examples/ref-dev-mqtt-pub/src/ref-dev-mqtt-pub.cpp

Lines changed: 36 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
using namespace daq;
77

88
enum class Mode {
9-
ATOMIC_SIGNAL_ATOMIC_SAMPLE = 0,
10-
ATOMIC_SIGNAL_SAMPLE_ARRAY,
11-
SIGNAL_ARRAY_ATOMIC_SAMPLE,
12-
GROUP_SIGNAL_ATOMIC_SAMPLE_SHARED_TS,
9+
TopicPerSignal = 0,
10+
SingleTopic,
1311
_COUNT
1412
};
1513

1614
struct ConfigStruct {
1715
std::string brokerAddress;
1816
Mode mode;
17+
bool useArray = false;
18+
size_t arraySize = 0;
1919
bool exit = true;
2020
int error = 0;
2121
};
@@ -27,12 +27,11 @@ ConfigStruct StartUp(int argc, char* argv[])
2727
args.addArg("--help", "Show help message");
2828
args.addArg("--address", "MQTT broker address", true);
2929
args.addArg("--mode", "publisher FB mode", true);
30+
args.addArg("--array", "pablish samples as arrays with specified size", true);
3031
args.setUsageHelp(APP_NAME " [options]\n"
3132
"Available modes:\n"
32-
" 0 - ATOMIC_SIGNAL_ATOMIC_SAMPLE\n"
33-
" 1 - ATOMIC_SIGNAL_SAMPLE_ARRAY\n"
34-
" 2 - SIGNAL_ARRAY_ATOMIC_SAMPLE\n"
35-
" 3 - GROUP_SIGNAL_ATOMIC_SAMPLE_SHARED_TS");
33+
" 0 - Topic per signal\n"
34+
" 1 - Single topic\n");
3635
args.parse(argc, argv);
3736

3837
if (args.hasArg("--help") || args.hasUnknownArgs())
@@ -54,6 +53,19 @@ ConfigStruct StartUp(int argc, char* argv[])
5453
return config;
5554
}
5655
config.mode = static_cast<Mode>(mode);
56+
if (args.hasArg("--array"))
57+
{
58+
config.useArray = true;
59+
config.arraySize = std::stoi(args.getArgValue("--array", "0"));
60+
if (config.arraySize == 0)
61+
{
62+
std::cout << "Invalid array size value. It must be greater than 0." << std::endl;
63+
args.printHelp();
64+
config.error = -1;
65+
config.exit = true;
66+
return config;
67+
}
68+
}
5769
return config;
5870
}
5971

@@ -73,59 +85,38 @@ int main(int argc, char* argv[])
7385

7486
// Configure channels
7587
const auto channels = refDevice.getChannelsRecursive();
76-
channels[0].setPropertyValue("UseGlobalSampleRate", appConfig.mode == Mode::GROUP_SIGNAL_ATOMIC_SAMPLE_SHARED_TS);
88+
channels[0].setPropertyValue("UseGlobalSampleRate", appConfig.mode == Mode::SingleTopic);
7789
channels[0].setPropertyValue("SampleRate", 10);
7890
channels[0].setPropertyValue("Frequency", 1);
7991
channels[0].setPropertyValue("Waveform", 1);
80-
channels[1].setPropertyValue("UseGlobalSampleRate", appConfig.mode == Mode::GROUP_SIGNAL_ATOMIC_SAMPLE_SHARED_TS);
92+
channels[1].setPropertyValue("UseGlobalSampleRate", appConfig.mode == Mode::SingleTopic);
8193
channels[1].setPropertyValue("SampleRate", 20);
8294
channels[1].setPropertyValue("Frequency", 1);
8395
channels[1].setPropertyValue("Waveform", 3);
84-
channels[2].setPropertyValue("UseGlobalSampleRate", appConfig.mode == Mode::GROUP_SIGNAL_ATOMIC_SAMPLE_SHARED_TS);
96+
channels[2].setPropertyValue("UseGlobalSampleRate", appConfig.mode == Mode::SingleTopic);
8597
channels[2].setPropertyValue("SampleRate", 50);
8698
channels[2].setPropertyValue("Frequency", 4);
87-
channels[3].setPropertyValue("UseGlobalSampleRate", appConfig.mode == Mode::GROUP_SIGNAL_ATOMIC_SAMPLE_SHARED_TS);
99+
channels[3].setPropertyValue("UseGlobalSampleRate", appConfig.mode == Mode::SingleTopic);
88100
channels[3].setPropertyValue("SampleRate", 100);
89101
channels[3].setPropertyValue("Frequency", 20);
90102

91103
// Create and configure MQTT server
92-
const std::string rootFbName = "RootMqttFb";
93-
auto rootFbConfig = instance.getAvailableFunctionBlockTypes().get(rootFbName).createDefaultConfig();
94-
rootFbConfig.setPropertyValue("MqttBrokerAddress", appConfig.brokerAddress);
95-
auto brokerFB = instance.addFunctionBlock(rootFbName, rootFbConfig);
104+
const std::string clientFbName = "MQTTClientFB";
105+
auto clientFbConfig = instance.getAvailableFunctionBlockTypes().get(clientFbName).createDefaultConfig();
106+
clientFbConfig.setPropertyValue("BrokerAddress", appConfig.brokerAddress);
107+
auto brokerFB = instance.addFunctionBlock(clientFbName, clientFbConfig);
96108
auto availableFbs = brokerFB.getAvailableFunctionBlockTypes();
97-
const std::string fbName = "PublisherMqttFb";
109+
const std::string fbName = "MQTTJSONPublisherFB";
98110
std::cout << "Try to add the " << fbName << std::endl;
99111

100112
auto config = availableFbs.get(fbName).createDefaultConfig();
101-
config.setPropertyValue("MqttQoS", 1);
102-
config.setPropertyValue("ReaderPeriod", 20);
103-
config.setPropertyValue("UseSignalNames", True);
104-
switch (appConfig.mode) {
105-
case Mode::ATOMIC_SIGNAL_ATOMIC_SAMPLE:
106-
config.setPropertyValue("SharedTimestamp", False);
107-
config.setPropertyValue("TopicMode", 0);
108-
config.setPropertyValue("GroupValues", False);
109-
break;
110-
case Mode::ATOMIC_SIGNAL_SAMPLE_ARRAY:
111-
config.setPropertyValue("SharedTimestamp", False);
112-
config.setPropertyValue("TopicMode", 0);
113-
config.setPropertyValue("GroupValues", True);
114-
config.setPropertyValue("GroupValuesPackSize", 3);
115-
break;
116-
case Mode::SIGNAL_ARRAY_ATOMIC_SAMPLE:
117-
config.setPropertyValue("SharedTimestamp", False);
118-
config.setPropertyValue("TopicMode", 1);
119-
config.setPropertyValue("GroupValues", False);
120-
break;
121-
case Mode::GROUP_SIGNAL_ATOMIC_SAMPLE_SHARED_TS:
122-
config.setPropertyValue("SharedTimestamp", True);
123-
config.setPropertyValue("TopicMode", 1);
124-
config.setPropertyValue("GroupValues", False);
125-
break;
126-
default:
127-
break;
128-
}
113+
config.setPropertyValue("QoS", 1);
114+
config.setPropertyValue("ReaderWaitPeriod", 20);
115+
config.setPropertyValue("SignalValueJSONKey", 2);
116+
config.setPropertyValue("TopicMode", (appConfig.mode == Mode::TopicPerSignal) ? 0 : 1);
117+
config.setPropertyValue("GroupValues", (appConfig.useArray) ? True : False);
118+
config.setPropertyValue("SamplesPerMessage", appConfig.arraySize);
119+
config.setPropertyValue("Topic", "opendaq/test/values");
129120

130121

131122
// Add the publisher function block to the broker device

external/opendaq/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set(OPENDAQ_ENABLE_TESTS false)
33
FetchContent_Declare(
44
opendaq
55
GIT_REPOSITORY https://github.com/openDAQ/openDAQ.git
6-
GIT_TAG origin/main
6+
GIT_TAG 41396d19a1567ab6aecacfe7e381ea616dfdad6c
77
GIT_PROGRESS ON
88
EXCLUDE_FROM_ALL
99
SYSTEM

modules/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
list(APPEND CMAKE_MESSAGE_CONTEXT modules)
3+
4+
add_subdirectory(mqtt_streaming_module)

mqtt_streaming_module/CMakeLists.txt renamed to modules/mqtt_streaming_module/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
cmake_minimum_required(VERSION 3.10)
22
set_cmake_folder_context(TARGET_FOLDER_NAME)
33

4-
set(MQTT_MODULE_VERSION ${OPENDAQ_PACKAGE_VERSION})
54
set(MQTT_MODULE_PRJ_NAME "OpenDaqMqttModule")
65

76
message(STATUS "${MQTT_MODULE_PRJ_NAME} version: ${MQTT_MODULE_VERSION}")

0 commit comments

Comments
 (0)