Optimize working mode configuration, fix the bug of socket connection, optimize socket send processing

This commit is contained in:
qiyongzhong0 2020-01-02 12:57:10 +08:00
parent b0695cb485
commit c0a6d6baea
2 changed files with 44 additions and 14 deletions

View File

@ -104,10 +104,21 @@ static int bc26_sleep(struct at_device *device)
LOG_D("no memory for resp create."); LOG_D("no memory for resp create.");
return(-RT_ERROR); return(-RT_ERROR);
} }
/* enable sleep mode */
if (at_obj_exec_cmd(device->client, resp, "AT+QSCLK=1") != RT_EOK) if (at_obj_exec_cmd(device->client, resp, "AT+QSCLK=1") != RT_EOK)
{ {
LOG_D("enable sleep fail."); LOG_D("enable sleep fail.\"AT+QSCLK=1\" execute fail.");
at_delete_resp(resp);
return(-RT_ERROR);
}
/* enable PSM mode */
if (at_obj_exec_cmd(device->client, resp, "AT+CPSMS=1,,,\"01000011\",\"00000001\"") != RT_EOK)
{
LOG_D("enable sleep fail.\"AT+CPSMS=1...\" execute fail.");
at_delete_resp(resp); at_delete_resp(resp);
return(-RT_ERROR); return(-RT_ERROR);
} }
@ -156,9 +167,18 @@ static int bc26_wakeup(struct at_device *device)
rt_thread_mdelay(200); rt_thread_mdelay(200);
} }
/* disable sleep mode */
if (at_obj_exec_cmd(device->client, resp, "AT+QSCLK=0") != RT_EOK) if (at_obj_exec_cmd(device->client, resp, "AT+QSCLK=0") != RT_EOK)
{ {
LOG_D("wake up fail."); LOG_D("wake up fail. \"AT+QSCLK=0\" execute fail.");
at_delete_resp(resp);
return(-RT_ERROR);
}
/* disable PSM mode */
if (at_obj_exec_cmd(device->client, resp, "AT+CPSMS=0") != RT_EOK)
{
LOG_D("wake up fail.\"AT+CPSMS=0\" execute fail.");
at_delete_resp(resp); at_delete_resp(resp);
return(-RT_ERROR); return(-RT_ERROR);
} }
@ -680,12 +700,26 @@ static void bc26_init_thread_entry(void *parameter)
goto __exit; goto __exit;
} }
/* disable low power mode */ /* disable sleep mode */
if (at_obj_exec_cmd(device->client, resp, "AT+QSCLK=0") != RT_EOK) if (at_obj_exec_cmd(device->client, resp, "AT+QSCLK=0") != RT_EOK)
{ {
result = -RT_ERROR; result = -RT_ERROR;
goto __exit; goto __exit;
} }
/* disable eDRX mode */
if (at_obj_exec_cmd(device->client, resp, "AT+CEDRXS=0") != RT_EOK)
{
result = -RT_ERROR;
goto __exit;
}
/* disable PSM mode */
if (at_obj_exec_cmd(device->client, resp, "AT+CPSMS=0") != RT_EOK)
{
result = -RT_ERROR;
goto __exit;
}
/* Get the baudrate */ /* Get the baudrate */
if (at_obj_exec_cmd(device->client, resp, "AT+IPR?") != RT_EOK) if (at_obj_exec_cmd(device->client, resp, "AT+IPR?") != RT_EOK)
@ -920,18 +954,14 @@ static int bc26_control(struct at_device *device, int cmd, void *arg)
switch (cmd) switch (cmd)
{ {
case AT_DEVICE_CTRL_POWER_ON:
result = bc26_power_on(device);
break;
case AT_DEVICE_CTRL_POWER_OFF:
result = bc26_power_off(device);
break;
case AT_DEVICE_CTRL_SLEEP: case AT_DEVICE_CTRL_SLEEP:
result = bc26_sleep(device); result = bc26_sleep(device);
break; break;
case AT_DEVICE_CTRL_WAKEUP: case AT_DEVICE_CTRL_WAKEUP:
result = bc26_wakeup(device); result = bc26_wakeup(device);
break; break;
case AT_DEVICE_CTRL_POWER_ON:
case AT_DEVICE_CTRL_POWER_OFF:
case AT_DEVICE_CTRL_RESET: case AT_DEVICE_CTRL_RESET:
case AT_DEVICE_CTRL_LOW_POWER: case AT_DEVICE_CTRL_LOW_POWER:
case AT_DEVICE_CTRL_NET_CONN: case AT_DEVICE_CTRL_NET_CONN:

View File

@ -154,7 +154,7 @@ static int bc26_socket_close(struct at_socket *socket)
static int bc26_socket_connect(struct at_socket *socket, char *ip, int32_t port, static int bc26_socket_connect(struct at_socket *socket, char *ip, int32_t port,
enum at_socket_type type, rt_bool_t is_client) enum at_socket_type type, rt_bool_t is_client)
{ {
#define CONN_RETRY 3 #define CONN_RETRY 2
int i = 0; int i = 0;
const char *type_str = RT_NULL; const char *type_str = RT_NULL;
@ -241,6 +241,7 @@ static int bc26_socket_connect(struct at_socket *socket, char *ip, int32_t port,
if (i == CONN_RETRY) if (i == CONN_RETRY)
{ {
LOG_E("%s device socket(%d) connect failed.", device->name, device_socket); LOG_E("%s device socket(%d) connect failed.", device->name, device_socket);
result = -RT_ERROR;
} }
if (resp) if (resp)
@ -300,7 +301,7 @@ static int at_wait_send_finish(struct at_socket *socket, size_t settings_size)
{ {
return RT_EOK; return RT_EOK;
} }
rt_thread_mdelay(50); rt_thread_mdelay(100);
} }
return -RT_ETIMEOUT; return -RT_ETIMEOUT;
@ -407,8 +408,7 @@ static int bc26_socket_send(struct at_socket *socket, const char *buff, size_t b
if (type == AT_SOCKET_TCP) if (type == AT_SOCKET_TCP)
{ {
at_wait_send_finish(socket, cur_pkt_size); at_wait_send_finish(socket, 2*cur_pkt_size);
//rt_thread_mdelay(10);
} }
sent_size += cur_pkt_size; sent_size += cur_pkt_size;