最近我把arduino下的的开发板管理器中ESP32的版本(esp32 by espressif systems)由2.0.15升级到3.0.4。
程序编译到espnow的esp_now_register_recv_cb注册函数时就会报错,而之前版本为2.0.15时则不会报错;
以下是报错信息:
error: invalid conversion from 'void (*)(const uint8_t*, const uint8_t*, int)' {aka 'void (*)(const unsigned char*, const unsigned char*, int)'} to 'esp_now_recv_cb_t' {aka 'void (*)(const esp_now_recv_info*, const unsigned char*, int)'} [-fpermissive]
817 | esp_now_register_recv_cb(OnDataRecv);
| ^~~~~~~~~~
| |
| void (*)(const uint8_t*, const uint8_t*, int) {aka void (*)(const unsigned char*, const unsigned char*, int)}
In file included from C:\Users\XHJ\Documents\Arduino\ESP_REMOTE_DUAL_STICK_STEP1_fix\ESP_REMOTE_DUAL_STICK_STEP1_fix.ino:4:
C:\Users\XHJ\AppData\Local\Arduino15\packages\esp32\tools\esp32-arduino-libs\idf-release_v5.1-b6b4727c58\esp32s2/include/esp_wifi/include/esp_now.h:157:54: note: initializing argument 1 of 'esp_err_t esp_now_register_recv_cb(esp_now_recv_cb_t)'
157 | esp_err_t esp_now_register_recv_cb(esp_now_recv_cb_t cb);
| ~~~~~~~~~~~~~~~~~~^~
以下是被报错的代码和涉及到具体函数代码:
esp_now_register_recv_cb(OnDataRecv);
void OnDataRecv(const uint8_t * mac_addr, const uint8_t *data, int data_len) {
memcpy(&msg_rx, data, sizeof(msg_rx));
Serial1.printf("\nReceive at:%d\n", millis());
char macStr[18];
short int cond[10] = { 0 };
t_stamp_data_recv = millis();
for (int i = 0; i < 6; i++) {
source_mac = mac_addr;
}
{
cond[0] = 0;
cond[0] = cond[0] + (msg_rx.head[0] == 0xFF) ? 0 : 1;
cond[0] = cond[0] + (msg_rx.head[1] == 0x02) ? 0 : 1;
cond[0] = cond[0] + (msg_rx.head[3] == 0xFF) ? 0 : 1;
cond[0] = cond[0] + (msg_rx.tail[0] == 0xFF) ? 0 : 1;
cond[0] = cond[0] + (msg_rx.tail[1] == 0xFE) ? 0 : 1;
cond[0] = cond[0] + (msg_rx.tail[2] == 0xFF) ? 0 : 1;
}
switch (msg_rx.head[2]) {
case 1:
{
peer_answer = 0;
}
break;
case 2:
{
peer_answer = 0;
}
break;
case 3:
{
peer_answer = 4;
}
break;
case 4:
{
peer_answer = 5;
}
break;
case 5:
{
peer_answer = 3;
Serial1.printf("In OnDataRecv()\n");
for (int i = 0; i < 6; i++) {
ap_mac = msg_rx.data[0 + i];
Serial1.printf("ap_mac[%d]:%02X\n", i, ap_mac);
sta_mac = msg_rx.data[8 + i];
Serial1.printf("sta_mac[%d]:%02X\n", i, sta_mac);
}
}
break;
default:
{
peer_answer = 0;
}
break;
}
if (cond[0] != 0) {
peer_answer = 1;
} else {
Serial1.printf("Received order_num is:\t%d\n", msg_rx.head[2]);
Serial1.printf("Msg come from:\t%02X:%02X:%02X:%02X:%02X:%02X\n", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
}
flag_OnDataRecv_msg_treated = 1;
}
想问问,改怎么修改函数“void OnDataRecv(const uint8_t * mac_addr, const uint8_t *data, int data_len) ”,才能避免报错,谢谢哈
版本升级后esp_now_register_recv_cb函数编译指针问题
Moderator: ESP_Bob
Re: 版本升级后esp_now_register_recv_cb函数编译指针问题
注册回调函数要改成这样:
esp_now_register_recv_cb(esp_now_recv_cb_t(OnDataRecv));
esp_now_register_recv_cb(esp_now_recv_cb_t(OnDataRecv));
Who is online
Users browsing this forum: No registered users and 34 guests