Skip to content

Commit

Permalink
wifilink:support 8-channel esp-now
Browse files Browse the repository at this point in the history
  • Loading branch information
liangshuzhi5193 committed Nov 23, 2023
1 parent 12da2c4 commit 008739f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
10 changes: 7 additions & 3 deletions components/core/crazyflie/hal/interface/espnow_ctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ typedef struct {
int left_y_value_f;
int right_x_value_f;
int right_y_value_f;
int channel_one_value_i;
int channel_two_value_i;
};

struct {
Expand Down Expand Up @@ -134,7 +136,9 @@ typedef void (* espnow_ctrl_data_cb_t)(espnow_attribute_t initiator_attribute,
int lx_value,
int ly_value,
int rx_value,
int ry_value);
int ry_value,
int channel_one_value,
int channel_two_value);

/**
* @brief The raw control data callback function
Expand Down Expand Up @@ -169,8 +173,8 @@ esp_err_t espnow_ctrl_initiator_bind(espnow_attribute_t initiator_attribute, boo
* - ESP_OK: succeed
* - others: fail
*/
esp_err_t espnow_ctrl_initiator_send(espnow_attribute_t initiator_attribute, espnow_attribute_t responder_attribute, uint32_t responder_value, int status, int x_value, int y_value, int rx_value, int ry_value);

esp_err_t espnow_ctrl_initiator_send(espnow_attribute_t initiator_attribute, espnow_attribute_t responder_attribute, uint32_t responder_value, int status,
int x_value, int y_value, int rx_value, int ry_value, int channel_one_value, int channel_two_value);
/**
* @brief The responder creates a bind task to process the received bind frame
*
Expand Down
14 changes: 10 additions & 4 deletions components/core/crazyflie/hal/src/espnow_ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,10 @@ static esp_err_t espnow_ctrl_responder_data_process(uint8_t *src_addr, void *dat
ESP_PARAM_CHECK(rx_ctrl);

espnow_ctrl_data_t *ctrl_data = (espnow_ctrl_data_t *)data;
ESP_LOGD(TAG, "src_addr: "MACSTR", espnow_ctrl_responder_recv, value: s1 = %d, s2 = %d, lx = %d, ly = %d, rx = %d, ry = %d",
ESP_LOGD(TAG, "src_addr: "MACSTR", espnow_ctrl_responder_recv, value: s1 = %d, s2 = %d, lx = %d, ly = %d, rx = %d, ry = %d, ch1 = %d, ch2 = %d",
MAC2STR(src_addr), ctrl_data->responder_value_i, ctrl_data->status_value_i, ctrl_data->left_x_value_f,
ctrl_data->left_y_value_f, ctrl_data->right_x_value_f, ctrl_data->right_y_value_f);
ctrl_data->left_y_value_f, ctrl_data->right_x_value_f, ctrl_data->right_y_value_f,
ctrl_data->channel_one_value_i, ctrl_data->channel_two_value_i);

#ifdef CONFIG_ESPNOW_CONTROL_AUTO_CHANNEL_SENDING
if (ctrl_data->frame_head.ack) {
Expand All @@ -289,7 +290,8 @@ static esp_err_t espnow_ctrl_responder_data_process(uint8_t *src_addr, void *dat
g_bindlist.data_cb(ctrl_data->initiator_attribute, ctrl_data->responder_attribute, ctrl_data->responder_value_i,
ctrl_data->status_value_i,
ctrl_data->left_x_value_f, ctrl_data->left_y_value_f,
ctrl_data->right_x_value_f, ctrl_data->right_y_value_f);
ctrl_data->right_x_value_f, ctrl_data->right_y_value_f,
ctrl_data->channel_one_value_i, ctrl_data->channel_two_value_i);
}

if (g_bindlist.data_raw_cb) {
Expand Down Expand Up @@ -449,7 +451,9 @@ esp_err_t espnow_ctrl_initiator_send(espnow_attribute_t initiator_attribute,
int lx_value,
int ly_value,
int rx_value,
int ry_value)
int ry_value,
int channel_one_value,
int channel_two_value)
{
esp_err_t ret = ESP_OK;
espnow_ctrl_data_t data = {
Expand All @@ -461,6 +465,8 @@ esp_err_t espnow_ctrl_initiator_send(espnow_attribute_t initiator_attribute,
.left_y_value_f = ly_value,
.right_x_value_f = rx_value,
.right_y_value_f = ry_value,
.channel_one_value_i = channel_one_value,
.channel_two_value_i = channel_two_value,
};

ret = espnow_send(ESPNOW_DATA_TYPE_CONTROL_DATA, ESPNOW_ADDR_BROADCAST, &data,
Expand Down
20 changes: 11 additions & 9 deletions components/drivers/general/wifi/wifi_esp32.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static void wifi_event_handler(void *arg, esp_event_base_t event_base,
} else if (event_id == WIFI_EVENT_AP_STADISCONNECTED) {
wifi_event_ap_stadisconnected_t *event = (wifi_event_ap_stadisconnected_t *) event_data;
DEBUG_PRINT_LOCAL("station" MACSTR "leave, AID=%d", MAC2STR(event->mac), event->aid);
}
}
}

bool wifiTest(void)
Expand Down Expand Up @@ -110,11 +110,11 @@ bool wifiSendData(uint32_t size, uint8_t *data)
};

static esp_err_t udp_server_create(void *arg)
{
{
if (isUDPInit){
return ESP_OK;
}

struct sockaddr_in *pdest_addr = &dest_addr;
pdest_addr->sin_addr.s_addr = htonl(INADDR_ANY);
pdest_addr->sin_family = AF_INET;
Expand All @@ -141,7 +141,7 @@ static void udp_server_rx_task(void *pvParameters)
{
uint8_t cksum = 0;
socklen_t socklen = sizeof(source_addr);

while (true) {
if(isUDPInit == false) {
vTaskDelay(20);
Expand Down Expand Up @@ -186,8 +186,8 @@ static void udp_server_tx_task(void *pvParameters)
vTaskDelay(20);
continue;
}
if ((xQueueReceive(udpDataTx, &outPacket, 5) == pdTRUE) && isUDPConnected) {
memcpy(tx_buffer, outPacket.data, outPacket.size);
if ((xQueueReceive(udpDataTx, &outPacket, 5) == pdTRUE) && isUDPConnected) {
memcpy(tx_buffer, outPacket.data, outPacket.size);
tx_buffer[outPacket.size] = calculate_cksum(tx_buffer, outPacket.size);
tx_buffer[outPacket.size + 1] = 0;

Expand All @@ -202,7 +202,7 @@ static void udp_server_tx_task(void *pvParameters)
DEBUG_PRINT_LOCAL(" data_send[%d] = %02X ", i, tx_buffer[i]);
}
#endif
}
}
}
}

Expand All @@ -213,7 +213,9 @@ static void espnow_ctrl_data_cb(espnow_attribute_t initiator_attribute,
int lx_value,
int ly_value,
int rx_value,
int ry_value)
int ry_value,
int channel_one_value,
int channel_two_value)
{
UDPPacket inPacket;
inPacket.size = 7;
Expand Down Expand Up @@ -320,7 +322,7 @@ void wifiInit(void)
DEBUG_PRINT_LOCAL("UDP server create socket failed");
} else {
DEBUG_PRINT_LOCAL("UDP server create socket succeed");
}
}
xTaskCreate(udp_server_tx_task, UDP_TX_TASK_NAME, UDP_TX_TASK_STACKSIZE, NULL, UDP_TX_TASK_PRI, NULL);
xTaskCreate(udp_server_rx_task, UDP_RX_TASK_NAME, UDP_RX_TASK_STACKSIZE, NULL, UDP_RX_TASK_PRI, NULL);
isInit = true;
Expand Down

0 comments on commit 008739f

Please sign in to comment.