Skip to content

Commit

Permalink
Added Teensy 4.1 mac address getter to Ethernet publisher example (#1074
Browse files Browse the repository at this point in the history
) (#1079)

* Added Teensy 4.1 mac address getter to Ethernet publisher example
Signed-off-by: Aditya Kamath <adityakamath@live.com>

* Update examples/micro-ros_publisher_ethernet/micro-ros_publisher_ethernet.ino

Co-authored-by: Pablo Garrido <pablogs9@gmail.com>

Co-authored-by: Pablo Garrido <pablogs9@gmail.com>
(cherry picked from commit 48833b3)

Co-authored-by: Aditya Kamath <adityakamath@live.com>
  • Loading branch information
mergify[bot] and adityakamath committed Jul 12, 2022
1 parent 15a3939 commit be72c14
Showing 1 changed file with 15 additions and 14 deletions.
Expand Up @@ -11,6 +11,13 @@
#error This example is only available for Arduino Portenta, Arduino Teensy41 and STM32F4
#endif

#if defined(ARDUINO_TEENSY41)
void get_teensy_mac(uint8_t *mac) {
for(uint8_t by=0; by<2; by++) mac[by]=(HW_OCOTP_MAC1 >> ((1-by)*8)) & 0xFF;
for(uint8_t by=0; by<4; by++) mac[by+2]=(HW_OCOTP_MAC0 >> ((3-by)*8)) & 0xFF;
}
#endif

rcl_publisher_t publisher;
std_msgs__msg__Int32 msg;
rclc_support_t support;
Expand All @@ -22,30 +29,24 @@ rcl_node_t node;
#define RCCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){error_loop();}}
#define RCSOFTCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){}}



void error_loop(){
while(1){
digitalWrite(LED_PIN, !digitalRead(LED_PIN));
delay(100);
}
}

void timer_callback(rcl_timer_t * timer, int64_t last_call_time)
{
RCLC_UNUSED(last_call_time);
if (timer != NULL) {
RCSOFTCHECK(rcl_publish(&publisher, &msg, NULL));
msg.data++;
}
}

void setup() {
byte arduino_mac[] = { 0xAA, 0xBB, 0xCC, 0xEE, 0xDD, 0xFF };
byte arduino_mac[] = { 0xAA, 0xBB, 0xCC, 0xEE, 0xDD, 0xFF };

#if defined(ARDUINO_TEENSY41)
get_teensy_mac(arduino_mac);
#endif

IPAddress arduino_ip(192, 168, 1, 177);
IPAddress agent_ip(192, 168, 1, 113);
set_microros_native_ethernet_udp_transports(arduino_mac, arduino_ip, agent_ip, 9999);

pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, HIGH);

Expand Down Expand Up @@ -73,4 +74,4 @@ void loop() {
RCSOFTCHECK(rcl_publish(&publisher, &msg, NULL));
msg.data++;
delay(100);
}
}

0 comments on commit be72c14

Please sign in to comment.