Skip to content

Commit

Permalink
Merge pull request #158 from 107-systems/register-api
Browse files Browse the repository at this point in the history
Implement OpenCyphal Register API for `OpenCyphal-ToF-Distance-Sensor-Node`.
  • Loading branch information
aentinger committed Sep 28, 2022
2 parents d95b861 + b5b7bc4 commit 2ead22b
Show file tree
Hide file tree
Showing 30 changed files with 1,596 additions and 197 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ Node node_hdl([](CanardFrame const & frame) { /* ... */ });
Heartbeat_1_0 hb;
/* ... */
void loop() {
/* Process all pending OpenCyphal actions. */
node_hdl.spinSome();

/* Update the heartbeat object */
hb.uptime(millis() / 1000);
hb.mode = Heartbeat_1_0::Mode::OPERATIONAL;
Expand All @@ -49,9 +52,6 @@ void loop() {
node_hdl.publish(hb);
prev = now;
}

/* Transmit all enqeued CAN frames */
while(node_hdl.transmitCanFrame()) { }
}
```
Expand Down
7 changes: 4 additions & 3 deletions examples/OpenCyphal-Blink/OpenCyphal-Blink.ino
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ void setup()

void loop()
{
/* Process all pending OpenCyphal actions.
*/
node_hdl.spinSome();

/* Update the heartbeat object */
hb.data.uptime = millis() / 1000;
hb = Heartbeat_1_0<>::Mode::OPERATIONAL;
Expand All @@ -127,9 +131,6 @@ void loop()
node_hdl.publish(hb);
prev = now;
}

/* Transmit all enqeued CAN frames */
while(node_hdl.transmitCanFrame()) { }
}

/**************************************************************************************
Expand Down
7 changes: 4 additions & 3 deletions examples/OpenCyphal-GNSS-Node/OpenCyphal-GNSS-Node.ino
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ void setup()

void loop()
{
/* Process all pending OpenCyphal actions.
*/
node_hdl.spinSome();

/* Handle actions common to all states.
*/
unsigned long const now = millis();
Expand All @@ -169,9 +173,6 @@ void loop()
}

node_data.mode = next_mode;

/* Transmit all enqeued CAN frames */
while(node_hdl.transmitCanFrame()) { }
}

/**************************************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ void setup()

void loop()
{
/* Process all pending OpenCyphal actions.
*/
node_hdl.spinSome();

/* Update the heartbeat object */
hb.data.uptime = millis() / 1000;
hb = Heartbeat_1_0<>::Mode::OPERATIONAL;
Expand All @@ -86,7 +90,4 @@ void loop()
node_hdl.publish(hb);
prev = now;
}

/* Transmit all enqeued CAN frames */
while(node_hdl.transmitCanFrame()) { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ void setup()

void loop()
{

/* Process all pending OpenCyphal actions.
*/
node_hdl.spinSome();
}

/**************************************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ void setup()

void loop()
{
/* Transmit all enqeued CAN frames */
while(node_hdl.transmitCanFrame()) { }
/* Process all pending OpenCyphal actions.
*/
node_hdl.spinSome();
}

/**************************************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ void setup()

void loop()
{
/* Transmit all enqeued CAN frames */
while(node_hdl.transmitCanFrame()) { }
/* Process all pending OpenCyphal actions.
*/
node_hdl.spinSome();
}

/**************************************************************************************
Expand Down
76 changes: 76 additions & 0 deletions examples/OpenCyphal-ToF-Distance-Sensor-Node/NodeInfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* This software is distributed under the terms of the MIT License.
* Copyright (c) 2020 LXRobotics.
* Author: Alexander Entinger <alexander.entinger@lxrobotics.com>
* Contributors: https://github.com/107-systems/107-Arduino-Cyphal/graphs/contributors.
*/

#ifndef NODE_INFO_H_
#define NODE_INFO_H_

/**************************************************************************************
* INCLUDES
**************************************************************************************/

#include <107-Arduino-Cyphal.h>

/**************************************************************************************
* DEFINES
**************************************************************************************/

#define ATSAMD21G18_SERIAL_NUMBER_WORD_0 *(volatile uint32_t*)(0x0080A00C)
#define ATSAMD21G18_SERIAL_NUMBER_WORD_1 *(volatile uint32_t*)(0x0080A040)
#define ATSAMD21G18_SERIAL_NUMBER_WORD_2 *(volatile uint32_t*)(0x0080A044)
#define ATSAMD21G18_SERIAL_NUMBER_WORD_3 *(volatile uint32_t*)(0x0080A048)

/**************************************************************************************
* TYPEDEF
**************************************************************************************/

union UniqueId
{
struct __attribute__((packed))
{
uint32_t w0, w1, w2, w3;
} word_buf;
uint8_t byte_buf[16];
};

/**************************************************************************************
* CONSTANTS
**************************************************************************************/

UniqueId const UNIQUE_ID = []()
{
UniqueId uid;
uid.word_buf.w0 = ATSAMD21G18_SERIAL_NUMBER_WORD_0;
uid.word_buf.w1 = ATSAMD21G18_SERIAL_NUMBER_WORD_1;
uid.word_buf.w2 = ATSAMD21G18_SERIAL_NUMBER_WORD_2;
uid.word_buf.w3 = ATSAMD21G18_SERIAL_NUMBER_WORD_3;
return uid;
} ();

static const uavcan_node_GetInfo_Response_1_0 NODE_INFO = {
/* uavcan.node.Version.1.0 protocol_version */
{1, 0},
/* uavcan.node.Version.1.0 hardware_version */
{1, 0},
/* uavcan.node.Version.1.0 software_version */
{0, 1},
/* saturated uint64 software_vcs_revision_id */
NULL,
/* saturated uint8[16] unique_id */
{
UNIQUE_ID.byte_buf[ 0], UNIQUE_ID.byte_buf[ 1], UNIQUE_ID.byte_buf[ 2], UNIQUE_ID.byte_buf[ 3],
UNIQUE_ID.byte_buf[ 4], UNIQUE_ID.byte_buf[ 5], UNIQUE_ID.byte_buf[ 6], UNIQUE_ID.byte_buf[ 7],
UNIQUE_ID.byte_buf[ 8], UNIQUE_ID.byte_buf[ 9], UNIQUE_ID.byte_buf[10], UNIQUE_ID.byte_buf[11],
UNIQUE_ID.byte_buf[12], UNIQUE_ID.byte_buf[13], UNIQUE_ID.byte_buf[14], UNIQUE_ID.byte_buf[15]
},
/* saturated uint8[<=50] name */
{
"107-systems.tof-sensor-node",
strlen("107-systems.tof-sensor-node")
},
};

#endif /* NODE_INFO_H_ */
Loading

0 comments on commit 2ead22b

Please sign in to comment.