66using namespace daq ;
77
88enum 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
1614struct 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
0 commit comments