Question
I'm currently working with ESP-NOW with the esp-idf. Below is a snippet from their espnow examples. I need some help in identifying what does this line means, but I'm not quite sure what to google. Can someone point me in the correct direction?
example_espnow_data_t *buf = (example_espnow_data_t *)send_param->buffer;
What I tried so far
I can't seem to find any guide online since I'm not sure what to google. Based on what I could find, my guess is that the send_param
buffer parameter is parsed to the buf
pointer of example_espnow_data_t
. Is my understanding correct?
Sample code
example_espnow_send_param_t
is a typdef struct
with buffer
as one of the parameters. The send parameters are then allocated and filled to the send_param
memory block. This then get passed to the data prepare function.
// code is truncated
typedef struct { // from header files
bool unicast; //Send unicast ESPNOW data.
bool broadcast; //Send broadcast ESPNOW data.
.
.
} example_espnow_send_param_t;
typedef struct { // from header files
uint8_t type; //Broadcast or unicast ESPNOW data.
.
.
} __attribute__((packed)) example_espnow_data_t;
send_param = malloc(sizeof(example_espnow_send_param_t));
memset(send_param, 0, sizeof(example_espnow_send_param_t));
send_param->unicast = false;
send_param->broadcast = false;
.
.
example_espnow_data_prepare(send_param);
void example_espnow_data_prepare(example_espnow_send_param_t *send_param)
{
example_espnow_data_t *buf = (example_espnow_data_t *)send_param->buffer;
assert(send_param->len >= sizeof(example_espnow_data_t));
.
.
}
ESP32 repo
question from:
https://stackoverflow.com/questions/66061238/c-buffer-pointer 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…