Implicit messaging: sending multiple messages
chruetli opened this issue · 4 comments
The device I have to control uses implicit messaging to change runtime parameters. This is a multi stage process:
- send message to enable write
- send the parameter
- send message to disable write
I do not understand how I have to modify the ImplicitMessagingExample.cpp
example to send multiple messages. Any ideas?
You use setDataToSend() to send data to your adapter. Is that what you're asking?
Hi Adam
It's part of...
Having the following block from the ImplicitMessagingExample.cpp
file.
auto io = connectionManager.forwardOpen(si, parameters);
if (auto ptr = io.lock()) {
ptr->setDataToSend(std::vector<uint8_t>{0x00, 0x00, 0x10, 0x05, 0x0, 0x0, 0x80, 0x0});
ptr->setReceiveDataListener([](auto realTimeHeader, auto sequence, auto data) {
std::ostringstream ss;
ss << "secNum=" << sequence << " data=";
for (auto &byte : data) {
ss << "[" << std::hex << (int) byte << "]";
}
Logger(LogLevel::INFO) << "Received: " << ss.str();
});
ptr->setCloseListener([]() {
Logger(LogLevel::INFO) << "Closed";
});
}
int count = 20;
while (connectionManager.hasOpenConnections() && count-- > 0) {
connectionManager.handleConnections(std::chrono::milliseconds(100));
}
Here we do:
- open a connection
- send data
- receive data
- close the connection
What I need is:
- open a connection
- send data
- receive data
- send other data
- receive again
- ...
- close the connection
I do not see how this fits into the schema above...
Seems to me like you have the order of operations down, so I don't understand the issue.
It's just an example and will not perfectly work with your application out of the box. You'll need to program your application's logic yourself.
Try handling the logic in your listener callback, then close the connection when you want
ptr->setDataToSend(std::vector<uint8_t>{0x00, 0x00, 0x10, 0x05, 0x0, 0x0, 0x80, 0x0}); // first send
ptr->setReceiveDataListener([](auto realTimeHeader, auto sequence, auto data) { // listener
if(data == 'something') // listen and handle logic
setReceiveDataListener(); // send data again
else if(data == 'close'){
setCloseListener([]() {
Logger(LogLevel::INFO) << "Closed";
});
}
});
I finally got it... Thank you!