diff --git a/libuavcan/include/uavcan/node/node.hpp b/libuavcan/include/uavcan/node/node.hpp index d80c05124f..6ea59a2244 100644 --- a/libuavcan/include/uavcan/node/node.hpp +++ b/libuavcan/include/uavcan/node/node.hpp @@ -150,10 +150,11 @@ public: int start(const TransferPriority node_status_transfer_priority = TransferPriority::Default); /** - * Sets the node name, e.g. "com.example.product_name". The node name can be set only once. - * Must be executed before the node is started, otherwise the node will refuse to start up. + * Gets/sets the node name, e.g. "com.example.product_name". The node name can be set only once. + * The name must be set before the node is started, otherwise the node will refuse to start up. */ - void setName(const char* name) { proto_nsp_.setName(name); } + const NodeStatusProvider::NodeName& getName() const { return proto_nsp_.getName(); } + void setName(const NodeStatusProvider::NodeName& name) { proto_nsp_.setName(name); } /** * Node health code helpers. @@ -187,11 +188,14 @@ public: } /** - * Sets the node version information. + * Gets/sets the node version information. */ void setSoftwareVersion(const protocol::SoftwareVersion& version) { proto_nsp_.setSoftwareVersion(version); } void setHardwareVersion(const protocol::HardwareVersion& version) { proto_nsp_.setHardwareVersion(version); } + const protocol::SoftwareVersion& getSoftwareVersion() const { return proto_nsp_.getSoftwareVersion(); } + const protocol::HardwareVersion& getHardwareVersion() const { return proto_nsp_.getHardwareVersion(); } + NodeStatusProvider& getNodeStatusProvider() { return proto_nsp_; } #if !UAVCAN_TINY diff --git a/libuavcan/include/uavcan/protocol/node_status_provider.hpp b/libuavcan/include/uavcan/protocol/node_status_provider.hpp index 14f0c7cbe9..6a5bb1faaf 100644 --- a/libuavcan/include/uavcan/protocol/node_status_provider.hpp +++ b/libuavcan/include/uavcan/protocol/node_status_provider.hpp @@ -51,6 +51,8 @@ public: typedef typename StorageType::Type VendorSpecificStatusCode; + typedef typename StorageType::Type NodeName; + explicit NodeStatusProvider(INode& node) : TimerBase(node) , creation_timestamp_(node.getMonotonicTime()) @@ -119,8 +121,8 @@ public: * Can be set only once before the provider is started. * The provider will refuse to start if the node name is not set. */ - const typename protocol::GetNodeInfo::Response::FieldTypes::name& getName() const { return node_info_.name; } - void setName(const char* name); + const NodeName& getName() const { return node_info_.name; } + void setName(const NodeName& name); /** * Node version information. diff --git a/libuavcan/src/protocol/uc_node_status_provider.cpp b/libuavcan/src/protocol/uc_node_status_provider.cpp index 52dfe0290b..7f4b188939 100644 --- a/libuavcan/src/protocol/uc_node_status_provider.cpp +++ b/libuavcan/src/protocol/uc_node_status_provider.cpp @@ -124,11 +124,11 @@ void NodeStatusProvider::setVendorSpecificStatusCode(VendorSpecificStatusCode co node_info_.status.vendor_specific_status_code = code; } -void NodeStatusProvider::setName(const char* name) +void NodeStatusProvider::setName(const NodeName& name) { - if ((name != NULL) && (*name != '\0') && (node_info_.name.empty())) + if (node_info_.name.empty()) { - node_info_.name = name; // The string contents will be copied, not just pointer. + node_info_.name = name; } }