-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #165 from 107-systems/unique-id
Provide a UniqueId service to provide a unique ID for the NodeInfo service.
- Loading branch information
Showing
11 changed files
with
433 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* This software is distributed under the terms of the MIT License. | ||
* Copyright (c) 2020 LXRobotics. | ||
* Author: Alexander Entinger <[email protected]> | ||
* Contributors: https://github.com/107-systems/107-Arduino-Cyphal/graphs/contributors. | ||
*/ | ||
|
||
/************************************************************************************** | ||
* INCLUDE | ||
**************************************************************************************/ | ||
|
||
#include <107-Arduino-Cyphal.h> | ||
|
||
/************************************************************************************** | ||
* SETUP/LOOP | ||
**************************************************************************************/ | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
while (!Serial) { } | ||
|
||
Serial.println(OpenCyphalUniqueId); | ||
} | ||
|
||
void loop() | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* This software is distributed under the terms of the MIT License. | ||
* Copyright (c) 2020 LXRobotics. | ||
* Author: Alexander Entinger <[email protected]> | ||
* Contributors: https://github.com/107-systems/107-Arduino-Cyphal/graphs/contributors. | ||
*/ | ||
|
||
/************************************************************************************** | ||
* INCLUDES | ||
**************************************************************************************/ | ||
|
||
#include "NodeInfo.h" | ||
|
||
/************************************************************************************** | ||
* CTOR/DTOR | ||
**************************************************************************************/ | ||
|
||
NodeInfo::NodeInfo(uint8_t const protocol_major, uint8_t const protocol_minor, | ||
uint8_t const hardware_major, uint8_t const hardware_minor, | ||
uint8_t const software_major, uint8_t const software_minor, | ||
uint64_t const software_vcs_revision_id, | ||
UniqueId16Array const unique_id, | ||
std::string const & name) | ||
{ | ||
_node_info.protocol_version.major = protocol_major; | ||
_node_info.protocol_version.minor = protocol_minor; | ||
|
||
_node_info.hardware_version.major = hardware_major; | ||
_node_info.hardware_version.minor = hardware_minor; | ||
|
||
_node_info.software_version.major = software_major; | ||
_node_info.software_version.minor = software_minor; | ||
|
||
_node_info.software_vcs_revision_id = software_vcs_revision_id; | ||
|
||
memcpy(_node_info.unique_id, unique_id.data(), sizeof(_node_info.unique_id)); | ||
|
||
_node_info.name.count = std::min(name.length(), uavcan_node_GetInfo_Response_1_0_name_ARRAY_CAPACITY_); | ||
memcpy(_node_info.name.elements, name.c_str(), _node_info.name.count); | ||
} | ||
|
||
/************************************************************************************** | ||
* PUBLIC MEMBER FUNCTIONS | ||
**************************************************************************************/ | ||
|
||
void NodeInfo::subscribe(Node & node_hdl) | ||
{ | ||
node_hdl.subscribe<uavcan::node::GetInfo_1_0::Request<>> | ||
([this](CanardRxTransfer const & transfer, Node & node_hdl) { this->onGetInfo_1_0_Request_Received(transfer, node_hdl); }); | ||
} | ||
|
||
/************************************************************************************** | ||
* PRIVATE MEMBER FUNCTIONS | ||
**************************************************************************************/ | ||
|
||
void NodeInfo::onGetInfo_1_0_Request_Received(CanardRxTransfer const & transfer, Node & node_hdl) | ||
{ | ||
uavcan::node::GetInfo_1_0::Response<> rsp = uavcan::node::GetInfo_1_0::Response<>(); | ||
memcpy(&rsp.data, &_node_info, sizeof(uavcan_node_GetInfo_Response_1_0)); | ||
node_hdl.respond(rsp, transfer.metadata.remote_node_id, transfer.metadata.transfer_id); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* This software is distributed under the terms of the MIT License. | ||
* Copyright (c) 2020 LXRobotics. | ||
* Author: Alexander Entinger <[email protected]> | ||
* Contributors: https://github.com/107-systems/107-Arduino-Cyphal/graphs/contributors. | ||
*/ | ||
|
||
#ifndef ARDUINO_OPENCYPHAL_NODE_INFO_H_ | ||
#define ARDUINO_OPENCYPHAL_NODE_INFO_H_ | ||
|
||
/************************************************************************************** | ||
* INCLUDES | ||
**************************************************************************************/ | ||
|
||
#include <string> | ||
|
||
#include "Node.h" | ||
#include "utility/UniqueId16.h" | ||
|
||
/************************************************************************************** | ||
* CLASS DECLARATION | ||
**************************************************************************************/ | ||
|
||
class NodeInfo | ||
{ | ||
public: | ||
|
||
NodeInfo(uint8_t const protocol_major, uint8_t const protocol_minor, | ||
uint8_t const hardware_major, uint8_t const hardware_minor, | ||
uint8_t const software_major, uint8_t const software_minor, | ||
uint64_t const software_vcs_revision_id, | ||
UniqueId16Array const unique_id, | ||
std::string const & name); | ||
|
||
|
||
void subscribe(Node & node_hdl); | ||
|
||
|
||
private: | ||
uavcan_node_GetInfo_Response_1_0 _node_info; | ||
|
||
void onGetInfo_1_0_Request_Received(CanardRxTransfer const & transfer, Node & node_hdl); | ||
}; | ||
|
||
#endif /* ARDUINO_OPENCYPHAL_NODE_INFO_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* This software is distributed under the terms of the MIT License. | ||
* Copyright (c) 2020 LXRobotics. | ||
* Author: Alexander Entinger <[email protected]> | ||
* Contributors: https://github.com/107-systems/107-Arduino-Cyphal/graphs/contributors. | ||
*/ | ||
|
||
/************************************************************************************** | ||
* INCLUDE | ||
**************************************************************************************/ | ||
|
||
#include "UniqueId16.h" | ||
|
||
#if defined(ARDUINO_ARCH_ESP32) | ||
|
||
#include <Arduino.h> | ||
|
||
/************************************************************************************** | ||
* NAMESPACE | ||
**************************************************************************************/ | ||
|
||
namespace impl | ||
{ | ||
|
||
/************************************************************************************** | ||
* CTOR/DTOR | ||
**************************************************************************************/ | ||
|
||
UniqueId16::UniqueId16() | ||
: _unique_id{0} | ||
{ | ||
size_t constexpr CHIP_ID_SIZE = 6; | ||
uint64_t const chipid = ESP.getEfuseMac(); | ||
memcpy(_unique_id, &chipid, CHIP_ID_SIZE); | ||
} | ||
|
||
/************************************************************************************** | ||
* NAMESPACE | ||
**************************************************************************************/ | ||
|
||
} /* impl */ | ||
|
||
#endif /* defined(ARDUINO_ARCH_ESP32) */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* This software is distributed under the terms of the MIT License. | ||
* Copyright (c) 2020 LXRobotics. | ||
* Author: Alexander Entinger <[email protected]> | ||
* Contributors: https://github.com/107-systems/107-Arduino-Cyphal/graphs/contributors. | ||
*/ | ||
|
||
/************************************************************************************** | ||
* INCLUDE | ||
**************************************************************************************/ | ||
|
||
#include "UniqueId16.h" | ||
|
||
#if defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED) | ||
|
||
#include <cstring> | ||
#include <pico/unique_id.h> | ||
|
||
/************************************************************************************** | ||
* NAMESPACE | ||
**************************************************************************************/ | ||
|
||
namespace impl | ||
{ | ||
|
||
/************************************************************************************** | ||
* CTOR/DTOR | ||
**************************************************************************************/ | ||
|
||
UniqueId16::UniqueId16() | ||
: _unique_id{0} | ||
{ | ||
pico_unique_board_id_t pico_id; | ||
pico_get_unique_board_id(&pico_id); | ||
|
||
memcpy(_unique_id, pico_id.id, PICO_UNIQUE_BOARD_ID_SIZE_BYTES); | ||
} | ||
|
||
/************************************************************************************** | ||
* NAMESPACE | ||
**************************************************************************************/ | ||
|
||
} /* impl */ | ||
|
||
#endif /* defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARDUINO_NANO_RP2040_CONNECT) */ |
Oops, something went wrong.