Skip to content

Commit ecc3629

Browse files
authored
Merge pull request #118 from luhuadong/develop
[BC28] optimize bc28 class functions
2 parents 1b84dd0 + 8be01ca commit ecc3629

File tree

3 files changed

+385
-215
lines changed

3 files changed

+385
-215
lines changed

class/bc28/at_device_bc28.c

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ static int bc28_check_link_status(struct at_device *device)
6666
int result = -RT_ERROR;
6767

6868
bc28 = (struct at_device_bc28 *)device->user_data;
69+
6970
if ( ! bc28->power_status) // power off
7071
{
7172
LOG_E("the power is off.");
@@ -181,7 +182,6 @@ static int bc28_netdev_set_info(struct netdev *netdev)
181182

182183
/* set network interface device IP address */
183184
{
184-
#define IP_ADDR_SIZE_MAX 16
185185
char ipaddr[IP_ADDR_SIZE_MAX] = {0};
186186

187187
/* send "AT+CGPADDR" commond to get IP address */
@@ -376,9 +376,7 @@ static int bc28_netdev_set_dns_server(struct netdev *netdev, uint8_t dns_num, ip
376376
goto __exit;
377377
}
378378

379-
/* send "AT+QIDNSCFG=<pri_dns>[,<sec_dns>]" commond to set dns servers */
380-
if (at_obj_exec_cmd(device->client, resp, "AT+QIDNSCFG=%d,%s",
381-
dns_num, inet_ntoa(*dns_server)) != RT_EOK)
379+
if (at_obj_exec_cmd(device->client, resp, "AT+QIDNSCFG=%s", inet_ntoa(*dns_server)) != RT_EOK)
382380
{
383381
result = -RT_ERROR;
384382
goto __exit;
@@ -439,7 +437,11 @@ static int bc28_netdev_ping(struct netdev *netdev, const char *host,
439437
#ifdef AT_USING_SOCKET
440438
else
441439
{
442-
bc28_domain_resolve(host, ip_addr);
440+
if(0 > bc28_domain_resolve(host, ip_addr))
441+
{
442+
LOG_E("can not resolve domain");
443+
goto __exit;
444+
}
443445
}
444446
#endif
445447

@@ -613,8 +615,8 @@ static void bc28_init_thread_entry(void *parameter)
613615
goto __exit;
614616
}
615617

616-
/* search band 8 */
617-
if (at_obj_exec_cmd(device->client, resp, "AT+NBAND=8") != RT_EOK)
618+
/* search band */
619+
if (at_obj_exec_cmd(device->client, resp, "AT+NBAND=%d", AT_DEVICE_BC28_OP_BAND) != RT_EOK)
618620
{
619621
result = -RT_ERROR;
620622
LOG_E(">> AT+NBAND=8");
@@ -765,7 +767,6 @@ static void bc28_init_thread_entry(void *parameter)
765767
rt_thread_mdelay(1000);
766768
if (at_obj_exec_cmd(device->client, resp, "AT+CGPADDR") == RT_EOK)
767769
{
768-
#define IP_ADDR_SIZE_MAX 16
769770
char ipaddr[IP_ADDR_SIZE_MAX] = {0};
770771

771772
/* parse response data "+CGPADDR: 0,<IP_address>" */
@@ -849,6 +850,19 @@ static int bc28_init(struct at_device *device)
849850
{
850851
struct at_device_bc28 *bc28 = (struct at_device_bc28 *)device->user_data;
851852

853+
/* configure AT client */
854+
rt_device_t serial = rt_device_find(bc28->client_name);
855+
struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT;
856+
857+
config.baud_rate = BC28_AT_CLIENT_BAUD_RATE;
858+
config.data_bits = DATA_BITS_8;
859+
config.stop_bits = STOP_BITS_1;
860+
config.bufsz = bc28->recv_bufsz;
861+
config.parity = PARITY_NONE;
862+
863+
rt_device_control(serial, RT_DEVICE_CTRL_CONFIG, &config);
864+
rt_device_close(serial);
865+
852866
/* initialize AT client */
853867
at_client_init(bc28->client_name, bc28->recv_bufsz);
854868

@@ -950,4 +964,4 @@ static int bc28_device_class_register(void)
950964
}
951965
INIT_DEVICE_EXPORT(bc28_device_class_register);
952966

953-
#endif /* AT_DEVICE_USING_BC28 */
967+
#endif /* AT_DEVICE_USING_BC28 */

class/bc28/at_device_bc28.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ extern "C" {
3535

3636
/* The maximum number of sockets supported by the BC28 device */
3737
#define AT_DEVICE_BC28_SOCKETS_NUM 7
38+
#define IP_ADDR_SIZE_MAX 16
39+
40+
#define AT_DEVICE_BC28_MIN_SOCKET BC28_SAMPLE_MIN_SOCKET
41+
#define BC28_AT_CLIENT_BAUD_RATE BC28_SAMPLE_BAUD_RATE
3842

3943
struct at_device_bc28
4044
{

0 commit comments

Comments
 (0)