diff --git a/communication/message/livedatamessage.cpp b/communication/message/livedatamessage.cpp index a1dfbc6..4f0753d 100644 --- a/communication/message/livedatamessage.cpp +++ b/communication/message/livedatamessage.cpp @@ -12,4 +12,14 @@ void LiveDataCommandMessage::appendSignalArg(LiveDataValueType valueType) { arg->valueType = valueType; } +void LiveDataSetValueMessage::appendSetValue(LiveDataValueType valueType, const LiveDataValue& value) { + auto& arg = args.emplace_back(std::make_shared()); + arg->objectType = LiveDataObjectType::MISC; + arg->objectIndex = 0u; + arg->signalIndex = 0u; + arg->valueType = valueType; + + values.push_back(std::make_shared(value)); +} + } // namespace icsneo diff --git a/examples/cpp/livedata/src/LiveDataExample.cpp b/examples/cpp/livedata/src/LiveDataExample.cpp index cb46ae7..f5a790e 100644 --- a/examples/cpp/livedata/src/LiveDataExample.cpp +++ b/examples/cpp/livedata/src/LiveDataExample.cpp @@ -35,6 +35,8 @@ int main() { msg->appendSignalArg(icsneo::LiveDataValueType::GPS_LATITUDE); msg->appendSignalArg(icsneo::LiveDataValueType::GPS_LONGITUDE); msg->appendSignalArg(icsneo::LiveDataValueType::GPS_ACCURACY); + msg->appendSignalArg(icsneo::LiveDataValueType::DAQ_OVERRIDE); + msg->appendSignalArg(icsneo::LiveDataValueType::MANUAL_TRIGGER); msg->cmd = icsneo::LiveDataCommand::SUBSCRIBE; msg->handle = icsneo::LiveDataUtil::getNewHandle(); msg->updatePeriod = std::chrono::milliseconds(100); @@ -77,6 +79,34 @@ int main() { })); // Run handler for three seconds to observe the signal data std::this_thread::sleep_for(std::chrono::seconds(3)); + auto setValMsg = std::make_shared(); + setValMsg->cmd = icsneo::LiveDataCommand::SET_VALUE; + setValMsg->handle = msg->handle; + bool onOff = true; + for (unsigned int i = 0; i < 10; ++i) + { + setValMsg->args.clear(); + setValMsg->values.clear(); + double val; + if (onOff) + { + val = 1; + } + else + { + val = 0; + } + onOff = !onOff; + icsneo::LiveDataValue ldValue; + if (icsneo::LiveDataUtil::liveDataDoubleToValue(ldValue, val) < 0) + { + break; + } + setValMsg->appendSetValue(icsneo::LiveDataValueType::DAQ_OVERRIDE, ldValue); + device->setValueLiveData(setValMsg); + // Test setting values + std::this_thread::sleep_for(std::chrono::seconds(3)); + } // Unsubscribe from the GPS signals and run handler for one more second // Unsubscription only requires a valid in-use handle, in this case from our previous subscription ret = device->unsubscribeLiveData(msg->handle); diff --git a/include/icsneo/communication/livedata.h b/include/icsneo/communication/livedata.h index d879f67..31cd8d1 100644 --- a/include/icsneo/communication/livedata.h +++ b/include/icsneo/communication/livedata.h @@ -156,6 +156,7 @@ namespace LiveDataUtil LiveDataHandle getNewHandle(); double liveDataValueToDouble(const LiveDataValue& val); +int liveDataDoubleToValue(LiveDataValue& value, const double& dFloat); static constexpr uint32_t LiveDataVersion = 1; } // namespace LiveDataUtil diff --git a/include/icsneo/communication/message/livedatamessage.h b/include/icsneo/communication/message/livedatamessage.h index 7dc208d..cb739c3 100644 --- a/include/icsneo/communication/message/livedatamessage.h +++ b/include/icsneo/communication/message/livedatamessage.h @@ -43,6 +43,7 @@ public: LiveDataSetValueMessage() {} std::vector> args; std::vector> values; + void appendSetValue(LiveDataValueType valueType, const LiveDataValue& value); }; } // namespace icsneo