11
11
#error This example is only available for Arduino Portenta, Arduino Teensy41 and STM32F4
12
12
#endif
13
13
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
+
14
21
rcl_publisher_t publisher;
15
22
std_msgs__msg__Int32 msg;
16
23
rclc_support_t support;
@@ -22,30 +29,24 @@ rcl_node_t node;
22
29
#define RCCHECK (fn ) { rcl_ret_t temp_rc = fn; if ((temp_rc != RCL_RET_OK)){error_loop ();}}
23
30
#define RCSOFTCHECK (fn ) { rcl_ret_t temp_rc = fn; if ((temp_rc != RCL_RET_OK)){}}
24
31
25
-
26
-
27
32
void error_loop (){
28
33
while (1 ){
29
34
digitalWrite (LED_PIN, !digitalRead (LED_PIN));
30
35
delay (100 );
31
36
}
32
37
}
33
38
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
-
43
39
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
+
45
46
IPAddress arduino_ip (192 , 168 , 1 , 177 );
46
47
IPAddress agent_ip (192 , 168 , 1 , 113 );
47
48
set_microros_native_ethernet_udp_transports (arduino_mac, arduino_ip, agent_ip, 9999 );
48
-
49
+
49
50
pinMode (LED_PIN, OUTPUT);
50
51
digitalWrite (LED_PIN, HIGH);
51
52
@@ -73,4 +74,4 @@ void loop() {
73
74
RCSOFTCHECK (rcl_publish (&publisher, &msg, NULL ));
74
75
msg.data ++;
75
76
delay (100 );
76
- }
77
+ }
0 commit comments