1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

socket_zep: avoid explicit cast to netdev

This commit is contained in:
Jose Alamos 2021-06-22 10:07:07 +02:00
parent 9aa832f077
commit 686c81caf7
No known key found for this signature in database
GPG Key ID: F483EB800EF89DD9
2 changed files with 18 additions and 12 deletions

View File

@ -104,7 +104,8 @@ static size_t _prep_vector(socket_zep_t *dev, const iolist_t *iolist,
static int _send(netdev_t *netdev, const iolist_t *iolist)
{
socket_zep_t *dev = (socket_zep_t *)netdev;
netdev_ieee802154_t *netdev_ieee802154 = container_of(netdev, netdev_ieee802154_t, netdev);
socket_zep_t *dev = container_of(netdev_ieee802154, socket_zep_t, netdev);
unsigned n = iolist_count(iolist);
struct iovec v[n + 2];
int res;
@ -179,7 +180,8 @@ static inline bool _dst_not_me(socket_zep_t *dev, const void *buf)
static int _recv(netdev_t *netdev, void *buf, size_t len, void *info)
{
socket_zep_t *dev = (socket_zep_t *)netdev;
netdev_ieee802154_t *netdev_ieee802154 = container_of(netdev, netdev_ieee802154_t, netdev);
socket_zep_t *dev = container_of(netdev_ieee802154, socket_zep_t, netdev);
int size = 0;
DEBUG("socket_zep::recv(%p, %p, %u, %p)\n", (void *)netdev, buf,
@ -263,7 +265,8 @@ static int _recv(netdev_t *netdev, void *buf, size_t len, void *info)
static void _isr(netdev_t *netdev)
{
if (netdev->event_callback) {
socket_zep_t *dev = (socket_zep_t *)netdev;
netdev_ieee802154_t *netdev_ieee802154 = container_of(netdev, netdev_ieee802154_t, netdev);
socket_zep_t *dev = container_of(netdev_ieee802154, socket_zep_t, netdev);
DEBUG("socket_zep::isr: firing %u\n", (unsigned)dev->last_event);
netdev->event_callback(netdev, dev->last_event);
@ -275,7 +278,7 @@ static void _socket_isr(int fd, void *arg)
{
(void)fd;
(void)arg;
netdev_t *netdev = (netdev_t *)arg;
netdev_t *netdev = arg;
DEBUG("socket_zep::_socket_isr: %d, %p (netdev == %p)\n",
fd, arg, (void *)netdev);
@ -283,7 +286,8 @@ static void _socket_isr(int fd, void *arg)
return;
}
if (netdev->event_callback) {
socket_zep_t *dev = (socket_zep_t *)netdev;
netdev_ieee802154_t *netdev_ieee802154 = container_of(netdev, netdev_ieee802154_t, netdev);
socket_zep_t *dev = container_of(netdev_ieee802154, socket_zep_t, netdev);
dev->last_event = NETDEV_EVENT_RX_COMPLETE;
netdev_trigger_event_isr(netdev);
@ -292,7 +296,8 @@ static void _socket_isr(int fd, void *arg)
static int _init(netdev_t *netdev)
{
socket_zep_t *dev = (socket_zep_t *)netdev;
netdev_ieee802154_t *netdev_ieee802154 = container_of(netdev, netdev_ieee802154_t, netdev);
socket_zep_t *dev = container_of(netdev_ieee802154, socket_zep_t, netdev);
netdev_ieee802154_reset(&dev->netdev);
@ -305,14 +310,15 @@ static int _init(netdev_t *netdev)
static int _get(netdev_t *netdev, netopt_t opt, void *value, size_t max_len)
{
assert(netdev != NULL);
return netdev_ieee802154_get((netdev_ieee802154_t *)netdev, opt, value, max_len);
return netdev_ieee802154_get(container_of(netdev, netdev_ieee802154_t, netdev),
opt, value, max_len);
}
static int _set(netdev_t *netdev, netopt_t opt, const void *value,
size_t value_len)
{
assert(netdev != NULL);
return netdev_ieee802154_set((netdev_ieee802154_t *)netdev, opt,
return netdev_ieee802154_set(container_of(netdev, netdev_ieee802154_t, netdev), opt,
value, value_len);
}

View File

@ -48,7 +48,7 @@ static void _print_info(netdev_t *netdev);
static void test_init(void)
{
const socket_zep_params_t *p = &socket_zep_params[0];
netdev_t *netdev = (netdev_t *)(&_dev);
netdev_t *netdev = &_dev.netdev.netdev;
printf("Initializing socket ZEP with (local: [%s]:%s, remote: [%s]:%s)\n",
p->local_addr, p->local_port, p->remote_addr, p->remote_port);
@ -60,7 +60,7 @@ static void test_init(void)
static void test_send__iolist_NULL(void)
{
netdev_t *netdev = (netdev_t *)(&_dev);
netdev_t *netdev = &_dev.netdev.netdev;
puts("Send zero-length packet");
int res = netdev->driver->send(netdev, NULL);
@ -77,7 +77,7 @@ static void test_send__iolist_not_NULL(void)
iolist[0].iol_next = &iolist[1];
netdev_t *netdev = (netdev_t *)(&_dev);
netdev_t *netdev = &_dev.netdev.netdev;
puts("Send 'Hello\\0World\\0'");
int res = netdev->driver->send(netdev, iolist);
@ -91,7 +91,7 @@ static void test_recv(void)
{
puts("Waiting for an incoming message (use `make test`)");
while (1) {
netdev_t *netdev = (netdev_t *)(&_dev);
netdev_t *netdev = &_dev.netdev.netdev;
msg_t msg;
msg_receive(&msg);