mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-02 20:24:32 +02:00
refactor smartconfig
move wifi part to wifi lib and lwip part to idf
This commit is contained in:
Submodule components/esp32/lib updated: ab80b0b980...efae38d4d6
@@ -12,8 +12,8 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#ifndef SMARTCONFIG_H
|
#ifndef SMARTCONFIG_ACK_H
|
||||||
#define SMARTCONFIG_H
|
#define SMARTCONFIG_ACK_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
26
components/smartconfig/smartconfig.c → components/smartconfig_ack/smartconfig_ack.c
Normal file → Executable file
26
components/smartconfig/smartconfig.c → components/smartconfig_ack/smartconfig_ack.c
Normal file → Executable file
@@ -25,7 +25,7 @@
|
|||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "esp_wifi.h"
|
#include "esp_wifi.h"
|
||||||
#include "esp_smartconfig.h"
|
#include "esp_smartconfig.h"
|
||||||
#include "smartconfig.h"
|
#include "smartconfig_ack.h"
|
||||||
|
|
||||||
static const char *TAG = "smartconfig";
|
static const char *TAG = "smartconfig";
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ static void sc_ack_send_task(void *pvParameters)
|
|||||||
int remote_port = (ack->type == SC_ACK_TYPE_ESPTOUCH) ? SC_ACK_TOUCH_SERVER_PORT : SC_ACK_AIRKISS_SERVER_PORT;
|
int remote_port = (ack->type == SC_ACK_TYPE_ESPTOUCH) ? SC_ACK_TOUCH_SERVER_PORT : SC_ACK_AIRKISS_SERVER_PORT;
|
||||||
struct sockaddr_in server_addr;
|
struct sockaddr_in server_addr;
|
||||||
socklen_t sin_size = sizeof(server_addr);
|
socklen_t sin_size = sizeof(server_addr);
|
||||||
int send_sock = 0;
|
int send_sock = -1;
|
||||||
int optval = 1;
|
int optval = 1;
|
||||||
int sendlen;
|
int sendlen;
|
||||||
int ack_len = (ack->type == SC_ACK_TYPE_ESPTOUCH) ? SC_ACK_TOUCH_LEN : SC_ACK_AIRKISS_LEN;
|
int ack_len = (ack->type == SC_ACK_TYPE_ESPTOUCH) ? SC_ACK_TOUCH_LEN : SC_ACK_AIRKISS_LEN;
|
||||||
@@ -78,10 +78,9 @@ static void sc_ack_send_task(void *pvParameters)
|
|||||||
|
|
||||||
/* Create UDP socket. */
|
/* Create UDP socket. */
|
||||||
send_sock = socket(AF_INET, SOCK_DGRAM, 0);
|
send_sock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
if (send_sock < 0) {
|
if ((send_sock < LWIP_SOCKET_OFFSET) || (send_sock > (FD_SETSIZE - 1))) {
|
||||||
ESP_LOGE(TAG, "Creat udp socket failed");
|
ESP_LOGE(TAG, "Creat udp socket failed");
|
||||||
free(ack);
|
goto _end;
|
||||||
vTaskDelete(NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setsockopt(send_sock, SOL_SOCKET, SO_BROADCAST | SO_REUSEADDR, &optval, sizeof(int));
|
setsockopt(send_sock, SOL_SOCKET, SO_BROADCAST | SO_REUSEADDR, &optval, sizeof(int));
|
||||||
@@ -100,9 +99,7 @@ static void sc_ack_send_task(void *pvParameters)
|
|||||||
if (ack->cb) {
|
if (ack->cb) {
|
||||||
ack->cb(SC_STATUS_LINK_OVER, remote_ip);
|
ack->cb(SC_STATUS_LINK_OVER, remote_ip);
|
||||||
}
|
}
|
||||||
close(send_sock);
|
goto _end;
|
||||||
free(ack);
|
|
||||||
vTaskDelete(NULL);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -112,9 +109,7 @@ static void sc_ack_send_task(void *pvParameters)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ESP_LOGE(TAG, "send failed, errno %d", err);
|
ESP_LOGE(TAG, "send failed, errno %d", err);
|
||||||
close(send_sock);
|
goto _end;
|
||||||
free(ack);
|
|
||||||
vTaskDelete(NULL);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -123,6 +118,10 @@ static void sc_ack_send_task(void *pvParameters)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_end:
|
||||||
|
if ((send_sock >= LWIP_SOCKET_OFFSET) && (send_sock <= (FD_SETSIZE - 1))) {
|
||||||
|
close(send_sock);
|
||||||
|
}
|
||||||
free(ack);
|
free(ack);
|
||||||
vTaskDelete(NULL);
|
vTaskDelete(NULL);
|
||||||
}
|
}
|
||||||
@@ -145,7 +144,10 @@ void sc_ack_send(sc_ack_t *param)
|
|||||||
|
|
||||||
s_sc_ack_send = true;
|
s_sc_ack_send = true;
|
||||||
|
|
||||||
xTaskCreate(sc_ack_send_task, "sc_ack_send_task", SC_ACK_TASK_STACK_SIZE, ack, SC_ACK_TASK_PRIORITY, NULL);
|
if (xTaskCreate(sc_ack_send_task, "sc_ack_send_task", SC_ACK_TASK_STACK_SIZE, ack, SC_ACK_TASK_PRIORITY, NULL) != pdPASS) {
|
||||||
|
ESP_LOGE(TAG, "Create sending smartconfig ACK task fail");
|
||||||
|
free(ack);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sc_ack_send_stop(void)
|
void sc_ack_send_stop(void)
|
Reference in New Issue
Block a user