Skip to content

Commit b52cb28

Browse files
authored
Merge pull request #92 from qiyongzhong0/bc26_fix_optimize
Optimize working mode configuration, fix the bug of socket connection…
2 parents b0695cb + c0a6d6b commit b52cb28

File tree

2 files changed

+44
-14
lines changed

2 files changed

+44
-14
lines changed

class/bc26/at_device_bc26.c

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,21 @@ static int bc26_sleep(struct at_device *device)
104104
LOG_D("no memory for resp create.");
105105
return(-RT_ERROR);
106106
}
107-
107+
108+
/* enable sleep mode */
108109
if (at_obj_exec_cmd(device->client, resp, "AT+QSCLK=1") != RT_EOK)
110+
109111
{
110-
LOG_D("enable sleep fail.");
112+
LOG_D("enable sleep fail.\"AT+QSCLK=1\" execute fail.");
113+
at_delete_resp(resp);
114+
return(-RT_ERROR);
115+
}
116+
117+
/* enable PSM mode */
118+
if (at_obj_exec_cmd(device->client, resp, "AT+CPSMS=1,,,\"01000011\",\"00000001\"") != RT_EOK)
119+
120+
{
121+
LOG_D("enable sleep fail.\"AT+CPSMS=1...\" execute fail.");
111122
at_delete_resp(resp);
112123
return(-RT_ERROR);
113124
}
@@ -156,9 +167,18 @@ static int bc26_wakeup(struct at_device *device)
156167
rt_thread_mdelay(200);
157168
}
158169

170+
/* disable sleep mode */
159171
if (at_obj_exec_cmd(device->client, resp, "AT+QSCLK=0") != RT_EOK)
160172
{
161-
LOG_D("wake up fail.");
173+
LOG_D("wake up fail. \"AT+QSCLK=0\" execute fail.");
174+
at_delete_resp(resp);
175+
return(-RT_ERROR);
176+
}
177+
178+
/* disable PSM mode */
179+
if (at_obj_exec_cmd(device->client, resp, "AT+CPSMS=0") != RT_EOK)
180+
{
181+
LOG_D("wake up fail.\"AT+CPSMS=0\" execute fail.");
162182
at_delete_resp(resp);
163183
return(-RT_ERROR);
164184
}
@@ -680,12 +700,26 @@ static void bc26_init_thread_entry(void *parameter)
680700
goto __exit;
681701
}
682702

683-
/* disable low power mode */
703+
/* disable sleep mode */
684704
if (at_obj_exec_cmd(device->client, resp, "AT+QSCLK=0") != RT_EOK)
685705
{
686706
result = -RT_ERROR;
687707
goto __exit;
688708
}
709+
710+
/* disable eDRX mode */
711+
if (at_obj_exec_cmd(device->client, resp, "AT+CEDRXS=0") != RT_EOK)
712+
{
713+
result = -RT_ERROR;
714+
goto __exit;
715+
}
716+
717+
/* disable PSM mode */
718+
if (at_obj_exec_cmd(device->client, resp, "AT+CPSMS=0") != RT_EOK)
719+
{
720+
result = -RT_ERROR;
721+
goto __exit;
722+
}
689723

690724
/* Get the baudrate */
691725
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)
920954

921955
switch (cmd)
922956
{
923-
case AT_DEVICE_CTRL_POWER_ON:
924-
result = bc26_power_on(device);
925-
break;
926-
case AT_DEVICE_CTRL_POWER_OFF:
927-
result = bc26_power_off(device);
928-
break;
929957
case AT_DEVICE_CTRL_SLEEP:
930958
result = bc26_sleep(device);
931959
break;
932960
case AT_DEVICE_CTRL_WAKEUP:
933961
result = bc26_wakeup(device);
934962
break;
963+
case AT_DEVICE_CTRL_POWER_ON:
964+
case AT_DEVICE_CTRL_POWER_OFF:
935965
case AT_DEVICE_CTRL_RESET:
936966
case AT_DEVICE_CTRL_LOW_POWER:
937967
case AT_DEVICE_CTRL_NET_CONN:

class/bc26/at_socket_bc26.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ static int bc26_socket_close(struct at_socket *socket)
154154
static int bc26_socket_connect(struct at_socket *socket, char *ip, int32_t port,
155155
enum at_socket_type type, rt_bool_t is_client)
156156
{
157-
#define CONN_RETRY 3
157+
#define CONN_RETRY 2
158158

159159
int i = 0;
160160
const char *type_str = RT_NULL;
@@ -241,6 +241,7 @@ static int bc26_socket_connect(struct at_socket *socket, char *ip, int32_t port,
241241
if (i == CONN_RETRY)
242242
{
243243
LOG_E("%s device socket(%d) connect failed.", device->name, device_socket);
244+
result = -RT_ERROR;
244245
}
245246

246247
if (resp)
@@ -300,7 +301,7 @@ static int at_wait_send_finish(struct at_socket *socket, size_t settings_size)
300301
{
301302
return RT_EOK;
302303
}
303-
rt_thread_mdelay(50);
304+
rt_thread_mdelay(100);
304305
}
305306

306307
return -RT_ETIMEOUT;
@@ -407,8 +408,7 @@ static int bc26_socket_send(struct at_socket *socket, const char *buff, size_t b
407408

408409
if (type == AT_SOCKET_TCP)
409410
{
410-
at_wait_send_finish(socket, cur_pkt_size);
411-
//rt_thread_mdelay(10);
411+
at_wait_send_finish(socket, 2*cur_pkt_size);
412412
}
413413

414414
sent_size += cur_pkt_size;

0 commit comments

Comments
 (0)