@@ -303,15 +303,50 @@ namespace mros2
303
303
}
304
304
}
305
305
306
- void setIPAddrRTPS (std::array<uint8_t , 4 > ipaddr)
306
+ /* implementation for mros2-mbed */
307
+ #ifdef __MBED__
308
+ int setIPAddrRTPS (std::array<uint8_t , 4 > ipaddr)
307
309
{
310
+ /* check whether IP address has been obtained */
311
+ if (!(ipaddr[0 ] + ipaddr[1 ] + ipaddr[2 ] + ipaddr[3 ]))
312
+ {
313
+ MROS2_ERROR (" IP address has not been obtained!" );
314
+ return 0 ;
315
+ }
316
+
308
317
rtps::Config::IP_ADDRESS = ipaddr;
318
+ MROS2_DEBUG (" [MROS2LIB] set \" %d.%d.%d.%d\" for RTPS communication" ,
319
+ rtps::Config::IP_ADDRESS[0 ], rtps::Config::IP_ADDRESS[1 ], rtps::Config::IP_ADDRESS[2 ], rtps::Config::IP_ADDRESS[3 ]);
309
320
310
- MROS2_DEBUG ( " [MROS2LIB] set IP address for RTPS communication " ) ;
321
+ return 1 ;
311
322
}
323
+ #endif /* __MBED__ */
312
324
313
325
} /* namespace mros2 */
314
326
327
+ /* implementation for mros2-esp32 */
328
+ #ifndef __MBED__
329
+ extern " C" int mros2_setIPAddrRTPS (uint32_t ipaddr)
330
+ {
331
+ /* check whether IP address has been obtained */
332
+ if (!ipaddr)
333
+ {
334
+ MROS2_ERROR (" IP address has not been obtained!" );
335
+ return 0 ;
336
+ }
337
+
338
+ std::array<uint8_t , 4 > rtps_ipaddr;
339
+ for (int i = 0 ; i < 4 ; i++)
340
+ rtps_ipaddr[i] = ipaddr >> (i * 8 );
341
+
342
+ rtps::Config::IP_ADDRESS = rtps_ipaddr;
343
+ MROS2_DEBUG (" [MROS2LIB] set \" %d.%d.%d.%d\" for RTPS communication" ,
344
+ rtps::Config::IP_ADDRESS[0 ], rtps::Config::IP_ADDRESS[1 ], rtps::Config::IP_ADDRESS[2 ], rtps::Config::IP_ADDRESS[3 ]);
345
+
346
+ return 1 ;
347
+ }
348
+ #endif /* __MBED__ */
349
+
315
350
/*
316
351
* Declaration for embeddedRTPS participants
317
352
*/
0 commit comments