Skip to content

Commit

Permalink
add node_id to cyphal init (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
PonomarevDA authored Aug 3, 2024
1 parent 3f65047 commit 8e62079
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 8 deletions.
5 changes: 3 additions & 2 deletions Cyphal/cyphal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ static uint32_t getCurrentMicroseconds();

O1HeapInstance* Cyphal::my_allocator;

int Cyphal::init() {
int Cyphal::init(uint8_t id) {
node_id = id;

heartbeat_pub.msg.health.value = uavcan_node_Health_1_0_NOMINAL;
heartbeat_pub.msg.mode.value = uavcan_node_Mode_1_0_OPERATIONAL;
heartbeat_pub.msg.vendor_specific_status_code = 0;

node_id = static_cast<uint8_t>(paramsGetIntegerValue(IntParamsIndexes::PARAM_NODE_ID));
if (node_id == 0 || node_id > 126) {
node_id = 42;
}
Expand Down
2 changes: 1 addition & 1 deletion Cyphal/cyphal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Cyphal {
execute_cmd_response(this) {
_instance = this;
};
int init();
int init(uint8_t node_id);
void process();
int32_t push(CanardTransferMetadata* metadata, size_t payload_size, const uint8_t* payload);
int8_t subscribe(CyphalSubscriber* sub_info, size_t size, CanardTransferKind kind);
Expand Down
2 changes: 1 addition & 1 deletion Cyphal/params.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
uavcan.node.id:
note: Defines a node-ID. Allowed values [0,127].
type: Integer
enum: PARAM_NODE_ID
enum: PARAM_UAVCAN_NODE_ID
flags: mutable
default: 50
min: 0
Expand Down
2 changes: 1 addition & 1 deletion examples/ubuntu_minimal/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ uint32_t HAL_GetTick() {

int main (int argc, char *argv[]) {
cyphal::Cyphal cyphal;
int init_res = cyphal.init();
int init_res = cyphal.init(42);
if (init_res < 0) {
std::cout << "Error: ";
switch (init_res) {
Expand Down
2 changes: 1 addition & 1 deletion examples/ubuntu_minimal/params.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "storage.h"

enum IntParamsIndexes : ParamIndex_t {
PARAM_NODE_ID,
PARAM_UAVCAN_NODE_ID,

INTEGER_PARAMS_AMOUNT
};
Expand Down
2 changes: 1 addition & 1 deletion examples/ubuntu_publisher_example/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ int Application::init() {
romInit(0, 1);
paramsInit(IntParamsIndexes::INTEGER_PARAMS_AMOUNT, NUM_OF_STR_PARAMS, -1, 1);
paramsLoad();
int init_res = cyphal.init();
int init_res = cyphal.init(42);
if (init_res < 0) {
std::cout << "Error: " << init_res << std::endl;
return -1;
Expand Down
2 changes: 1 addition & 1 deletion examples/ubuntu_publisher_example/params.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "storage.h"

enum IntParamsIndexes : ParamIndex_t {
PARAM_NODE_ID,
PARAM_UAVCAN_NODE_ID,
FEEDBACK,

INTEGER_PARAMS_AMOUNT
Expand Down

0 comments on commit 8e62079

Please sign in to comment.