17 #include <uavcan_posix/basic_file_server_backend.hpp>
18 #include <uavcan_posix/firmware_version_checker.hpp>
28 node->setName(name.c_str());
29 node->getLogger().setLevel(uavcan::protocol::debug::LogLevel::DEBUG);
34 uavcan::protocol::HardwareVersion hwver;
35 std::copy(app_id.begin(), app_id.end(), hwver.unique_id.begin());
36 std::cout << hwver << std::endl;
38 node->setHardwareVersion(hwver);
41 const int start_res =
node->start();
44 node->setModeOperational();
51 uavcan_posix::BasicFileServerBackend backend(*
node);
55 const int server_init_res = server.start();
56 if (server_init_res < 0)
58 throw std::runtime_error(
"Failed to start the server; error " + std::to_string(server_init_res));
66 std::cerr <<
"Spin error: " << res << std::endl;
74 std::vector<std::string> ifaces;
77 Options parseOptions(
int argc,
const char** argv)
79 const char*
const executable_name = *argv++;
82 const auto enforce = [executable_name](
bool condition,
const char* error_text) {
85 std::cerr << error_text <<
"\n"
88 <<
" <node-id> <can-iface-name-1> [can-iface-name-N...]"
94 enforce(argc >= 2,
"Not enough arguments");
100 const int node_id = std::stoi(*argv++);
101 enforce(node_id >= 1 && node_id <= 127,
"Invalid node ID");
108 const std::string token(*argv++);
112 out.ifaces.push_back(token);
116 enforce(
false,
"Unexpected argument");
125 int main(
int argc,
const char** argv)
129 auto options = parseOptions(argc, argv);
131 std::cout <<
"Self node ID: " <<
int(options.node_id.get()) <<
"\n"
132 "Num ifaces: " << options.ifaces.size() <<
"\n"
134 "Build mode: Release"
140 auto node =
initNode(options.ifaces, options.node_id,
"org.uavcan.linux_test_file_server");
144 catch (
const std::exception& ex)
146 std::cerr <<
"Error: " << ex.what() << std::endl;