46 lines
1.6 KiB
C++
46 lines
1.6 KiB
C++
#include <softbus_api/ExecuteCommand.h>
|
|
#include <softbus_core/identity/DeviceIdentity.h>
|
|
#include <softbus_transport/TcpUplinkClient.h>
|
|
|
|
#include <iostream>
|
|
#include <string>
|
|
|
|
int main(int argc, char* argv[])
|
|
{
|
|
std::string host = "127.0.0.1";
|
|
uint16_t port = 9000;
|
|
std::string objectRef = "DemoSite/DemoSystem/DemoAsset/EdgeDevice_01/ValveOpening";
|
|
double value = 60.0;
|
|
|
|
for (int i = 1; i < argc; ++i) {
|
|
const std::string arg = argv[i];
|
|
if (arg == "--daemon" && i + 1 < argc) {
|
|
const std::string endpoint = argv[++i];
|
|
const auto pos = endpoint.find(':');
|
|
if (pos != std::string::npos) {
|
|
host = endpoint.substr(0, pos);
|
|
port = static_cast<uint16_t>(std::stoi(endpoint.substr(pos + 1)));
|
|
}
|
|
} else if (arg == "--object-ref" && i + 1 < argc) {
|
|
objectRef = argv[++i];
|
|
} else if (arg == "--value" && i + 1 < argc) {
|
|
value = std::stod(argv[++i]);
|
|
}
|
|
}
|
|
|
|
softbus::api::ExecuteCommand cmd;
|
|
cmd.requestId = "req-cli-" + softbus::core::DeviceIdentity::generateTraceId();
|
|
cmd.traceId = softbus::core::DeviceIdentity::generateTraceId();
|
|
cmd.objectRef = objectRef;
|
|
cmd.command = "write";
|
|
cmd.params = {{"value", value}};
|
|
|
|
std::cout << cmd.toJson().dump() << std::endl;
|
|
std::cout << "Use OPC UA ExecuteCommand or: softbus_daemon --self-test" << std::endl;
|
|
std::cout << "Note: uplink port " << host << ":" << port
|
|
<< " is reserved for edge agent connection." << std::endl;
|
|
(void)host;
|
|
(void)port;
|
|
return 0;
|
|
}
|