Skip to content

Commit 897048b

Browse files
Added Teensy 4.1 mac address getter to Ethernet publisher example (#1074) (#1078)
* Added Teensy 4.1 mac address getter to Ethernet publisher example Signed-off-by: Aditya Kamath <[email protected]> * Update examples/micro-ros_publisher_ethernet/micro-ros_publisher_ethernet.ino Co-authored-by: Pablo Garrido <[email protected]> Co-authored-by: Pablo Garrido <[email protected]> (cherry picked from commit 48833b3) Co-authored-by: Aditya Kamath <[email protected]>
1 parent 908cc66 commit 897048b

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

examples/micro-ros_publisher_ethernet/micro-ros_publisher_ethernet.ino

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@
1111
#error This example is only available for Arduino Portenta, Arduino Teensy41 and STM32F4
1212
#endif
1313

14+
#if defined(ARDUINO_TEENSY41)
15+
void get_teensy_mac(uint8_t *mac) {
16+
for(uint8_t by=0; by<2; by++) mac[by]=(HW_OCOTP_MAC1 >> ((1-by)*8)) & 0xFF;
17+
for(uint8_t by=0; by<4; by++) mac[by+2]=(HW_OCOTP_MAC0 >> ((3-by)*8)) & 0xFF;
18+
}
19+
#endif
20+
1421
rcl_publisher_t publisher;
1522
std_msgs__msg__Int32 msg;
1623
rclc_support_t support;
@@ -22,30 +29,24 @@ rcl_node_t node;
2229
#define RCCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){error_loop();}}
2330
#define RCSOFTCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){}}
2431

25-
26-
2732
void error_loop(){
2833
while(1){
2934
digitalWrite(LED_PIN, !digitalRead(LED_PIN));
3035
delay(100);
3136
}
3237
}
3338

34-
void timer_callback(rcl_timer_t * timer, int64_t last_call_time)
35-
{
36-
RCLC_UNUSED(last_call_time);
37-
if (timer != NULL) {
38-
RCSOFTCHECK(rcl_publish(&publisher, &msg, NULL));
39-
msg.data++;
40-
}
41-
}
42-
4339
void setup() {
44-
byte arduino_mac[] = { 0xAA, 0xBB, 0xCC, 0xEE, 0xDD, 0xFF };
40+
byte arduino_mac[] = { 0xAA, 0xBB, 0xCC, 0xEE, 0xDD, 0xFF };
41+
42+
#if defined(ARDUINO_TEENSY41)
43+
get_teensy_mac(arduino_mac);
44+
#endif
45+
4546
IPAddress arduino_ip(192, 168, 1, 177);
4647
IPAddress agent_ip(192, 168, 1, 113);
4748
set_microros_native_ethernet_udp_transports(arduino_mac, arduino_ip, agent_ip, 9999);
48-
49+
4950
pinMode(LED_PIN, OUTPUT);
5051
digitalWrite(LED_PIN, HIGH);
5152

@@ -73,4 +74,4 @@ void loop() {
7374
RCSOFTCHECK(rcl_publish(&publisher, &msg, NULL));
7475
msg.data++;
7576
delay(100);
76-
}
77+
}

0 commit comments

Comments
 (0)