esp_now_netdev.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Gunar Schorcht
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
9 #pragma once
10 
22 #include "net/netdev.h"
23 #include "mutex.h"
24 #include "net/ethernet/hdr.h"
25 #ifdef MODULE_GNRC
26 #include "net/gnrc/nettype.h"
27 #endif
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
36 #define ESP_NOW_MAX_SIZE_RAW (250)
37 
41 #define ESP_NOW_ADDR_LEN ETHERNET_ADDR_LEN
42 
46 #define ESP_NOW_HEADER_LENGTH (sizeof(esp_now_pkt_hdr_t))
47 
51 #define ESP_NOW_MAX_SIZE (ESP_NOW_MAX_SIZE_RAW - ESP_NOW_HEADER_LENGTH)
52 
58 #ifndef ESP_NOW_BUFSIZE
59 #define ESP_NOW_BUFSIZE (ESP_NOW_MAX_SIZE_RAW + ESP_NOW_ADDR_LEN)
60 #endif
61 
65 extern const netdev_driver_t esp_now_driver;
66 
70 typedef struct __attribute__((packed))
71 {
72  uint8_t flags;
74 
78 #define ESP_NOW_PKT_HDR_FLAG_SIXLO (1)
79 
83 typedef struct
84 {
87  uint8_t addr[ESP_NOW_ADDR_LEN];
89  uint8_t rx_len;
90  uint8_t* rx_mac;
91  uint8_t* rx_data;
93  uint8_t tx_mem[ESP_NOW_MAX_SIZE_RAW];
95 #ifdef MODULE_GNRC
96  gnrc_nettype_t proto;
97 #endif
98 
101  uint8_t scan_event;
104 
111 
118 int esp_now_set_channel(uint8_t channel);
119 
120 #ifdef __cplusplus
121 }
122 #endif
123 
Definitions low-level network driver interface.
const netdev_driver_t esp_now_driver
Reference to the netdev device driver struct.
#define ESP_NOW_MAX_SIZE_RAW
Maximum raw packet size that can be used with ESP-NOW (including headers)
int esp_now_set_channel(uint8_t channel)
Set the channel used by ESP-NOW netdev.
esp_now_netdev_t * netdev_esp_now_setup(void)
ESP-NOW netdev initialization function.
#define ESP_NOW_ADDR_LEN
Length of ESP-NOW addresses.
gnrc_nettype_t
Definition of protocol types in the network stack.
Definition: nettype.h:51
Mutex for thread synchronization.
Ethernet header definitions.
Protocol type definitions.
Device descriptor for ESP-NOW devices.
uint8_t scan_event
ESP-NOW peers have to be scanned.
netdev_t netdev
netdev parent struct
uint8_t * rx_mac
source mac of received data
mutex_t dev_lock
device is already in use
uint8_t rx_len
number of bytes received
uint8_t * rx_data
received
Header with necessary flags for ESP-NOW packets.
uint8_t flags
Flags.
Mutex structure.
Definition: mutex.h:39
Structure to hold driver interface -> function mapping.
Definition: netdev.h:425
Structure to hold driver state.
Definition: netdev.h:364