-
Notifications
You must be signed in to change notification settings - Fork 0
/
pico_wifi_transport.h
executable file
·69 lines (53 loc) · 1.65 KB
/
pico_wifi_transport.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef MICRO_ROS_PICOSDK
#define MICRO_ROS_PICOSDK
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include "pico/stdlib.h"
#include "pico/cyw43_arch.h"
#include "lwip/pbuf.h"
#include "lwip/udp.h"
#include <uxr/client/profile/transport/custom/custom_transport.h>
bool pico_wifi_transport_open(struct uxrCustomTransport *transport);
bool pico_wifi_transport_close(struct uxrCustomTransport *transport);
size_t pico_wifi_transport_write(struct uxrCustomTransport *transport, const uint8_t *buf, size_t len, uint8_t *err);
size_t pico_wifi_transport_read(struct uxrCustomTransport *transport, uint8_t *buf, size_t len, int timeout, uint8_t *err);
struct micro_ros_agent_locator
{
ip_addr_t address;
int port;
};
static inline bool set_microros_wifi_transports(char *ssid, char *pass, char *agent_ip, uint agent_port)
{
stdio_init_all();
if (cyw43_arch_init())
{
printf("failed to initialise\n");
return 1;
}
cyw43_arch_enable_sta_mode();
sleep_ms(1000);
printf("Connecting to Wi-Fi...\n");
if (cyw43_arch_wifi_connect_timeout_ms(ssid, pass, CYW43_AUTH_WPA2_AES_PSK, 20000))
{
printf("failed to connect.\n");
return 1;
}
else
{
printf("Connected.\n");
}
static struct micro_ros_agent_locator locator;
ipaddr_aton(agent_ip, &locator.address);
locator.port = agent_port;
rmw_uros_set_custom_transport(
false,
(void *)&locator,
pico_wifi_transport_open,
pico_wifi_transport_close,
pico_wifi_transport_write,
pico_wifi_transport_read);
return 0;
}
#endif // MICRO_ROS_PICOSDK