phase 2
This commit is contained in:
11
tools/CMakeLists.txt
Normal file
11
tools/CMakeLists.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
add_executable(cmd_sender cmd_sender.cpp)
|
||||
target_link_libraries(cmd_sender PRIVATE
|
||||
softbus_core softbus_api softbus_transport softbus_registry asio
|
||||
)
|
||||
softbus_apply_platform_libs(cmd_sender)
|
||||
|
||||
add_executable(topic_watcher topic_watcher.cpp)
|
||||
target_link_libraries(topic_watcher PRIVATE
|
||||
softbus_bus softbus_core
|
||||
)
|
||||
softbus_apply_platform_libs(topic_watcher)
|
||||
45
tools/cmd_sender.cpp
Normal file
45
tools/cmd_sender.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#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;
|
||||
}
|
||||
15
tools/topic_watcher.cpp
Normal file
15
tools/topic_watcher.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include <softbus_bus/Bus.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
int main()
|
||||
{
|
||||
auto& bus = softbus::bus::Bus::instance();
|
||||
bus.subscribe("#", [](const softbus::bus::BusMessage& msg) {
|
||||
std::cout << "[topic] " << msg.topic << std::endl;
|
||||
});
|
||||
std::cout << "topic_watcher: attach to daemon process is standalone demo only." << std::endl;
|
||||
std::cout << "Use daemon logs or integrate watcher via shared bus in-process." << std::endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user