feat(esptouch_v2): support esptouch_v2

This commit is contained in:
chenwen
2020-11-11 18:43:45 +08:00
committed by Dong Heng
parent 48be630192
commit b9628e8608
17 changed files with 179 additions and 43 deletions

View File

@ -35,7 +35,9 @@
#define SC_ACK_TASK_PRIORITY 2 /*!< Priority of sending smartconfig ACK task */
#define SC_ACK_TASK_STACK_SIZE 2048 /*!< Stack size of sending smartconfig ACK task */
#define SC_ACK_TOUCH_DEVICE_PORT 7001 /*!< ESPTOUCH UDP port of server on device */
#define SC_ACK_TOUCH_SERVER_PORT 18266 /*!< ESP touch UDP port of server on cellphone */
#define SC_ACK_TOUCH_V2_SERVER_PORT(i) (18266+i*10000) /*!< ESP touch_v2 UDP port of server on cellphone */
#define SC_ACK_AIRKISS_SERVER_PORT 10000 /*!< Airkiss UDP port of server on cellphone */
#define SC_ACK_AIRKISS_DEVICE_PORT 10001 /*!< Airkiss UDP port of server on device */
#define SC_ACK_AIRKISS_TIMEOUT 1500 /*!< Airkiss read data timout millisecond */
@ -78,7 +80,6 @@ static void sc_ack_send_task(void* pvParameters)
tcpip_adapter_ip_info_t local_ip;
uint8_t remote_ip[4];
memset(remote_ip, 0xFF, sizeof(remote_ip));
int remote_port = (ack->type == SC_TYPE_ESPTOUCH) ? SC_ACK_TOUCH_SERVER_PORT : SC_ACK_AIRKISS_SERVER_PORT;
struct sockaddr_in server_addr;
socklen_t sin_size = sizeof(server_addr);
int send_sock = -1;
@ -88,6 +89,19 @@ static void sc_ack_send_task(void* pvParameters)
uint8_t packet_count = 1;
int err;
int ret;
int remote_port = 0;
if (ack->type == SC_TYPE_ESPTOUCH) {
remote_port = SC_ACK_TOUCH_SERVER_PORT;
} else if (ack->type == SC_TYPE_ESPTOUCH_V2) {
uint8_t port_bit = ack->ctx.token;
if(port_bit > 3) {
port_bit = 0;
}
remote_port = SC_ACK_TOUCH_V2_SERVER_PORT(port_bit);
} else {
remote_port = SC_ACK_AIRKISS_SERVER_PORT;
}
bzero(&server_addr, sizeof(struct sockaddr_in));
server_addr.sin_family = AF_INET;
@ -152,7 +166,7 @@ static void sc_ack_send_task(void* pvParameters)
sendlen = sendto(send_sock, &ack->ctx, ack_len, 0, (struct sockaddr*) &server_addr, sin_size);
if (sendlen > 0) {
/* Totally send 30 smartconfig ACKs. Then smartconfig is successful. */
/* Totally send 60 smartconfig ACKs. Then smartconfig is successful. */
if (packet_count++ >= SC_ACK_MAX_COUNT) {
esp_event_post(SC_EVENT, SC_EVENT_SEND_ACK_DONE, NULL, 0, portMAX_DELAY);
goto _end;