【修改】完善日志处理,修改 at_device_list 链表处理方式

Signed-off-by: chenyong <1521761801@qq.com>
This commit is contained in:
chenyong 2019-09-10 12:26:31 +08:00
parent 500896f3ba
commit 9587a1fc2f
22 changed files with 514 additions and 585 deletions

View File

@ -29,7 +29,7 @@
#include <at_device_ec20.h>
#define LOG_TAG "at.dev"
#define LOG_TAG "at.dev.ec20"
#include <at_log.h>
#ifdef AT_DEVICE_USING_EC20
@ -43,6 +43,7 @@ static char *QICSGP_CHINA_MOBILE = "AT+QICSGP=1,1,\"CMNET\",\"\",\"\",0";
static char *QICSGP_CHINA_UNICOM = "AT+QICSGP=1,1,\"UNINET\",\"\",\"\",0";
static char *QICSGP_CHINA_TELECOM = "AT+QICSGP=1,1,\"CTNET\",\"\",\"\",0";
#ifdef EC20_USING_CME
static void at_cme_errcode_parse(int result)
{
switch(result)
@ -129,7 +130,9 @@ static void at_cms_errcode_parse(int result)
default : LOG_E("%d : Unknown err code", result); break;
}
}
#endif /* EC20_USING_CME */
#ifdef EC20_USING_MMS
static void at_mms_errcode_parse(int result)//MMS
{
switch(result)
@ -164,6 +167,7 @@ static void at_mms_errcode_parse(int result)//MMS
default : LOG_E("%d : Unknown err code", result); break;
}
}
#endif /* EC20_USING_MMS */
static void ec20_power_on(struct at_device *device)
{
@ -230,16 +234,12 @@ static int ec20_netdev_set_info(struct netdev *netdev)
at_response_t resp = RT_NULL;
struct at_device *device = RT_NULL;
if (netdev == RT_NULL)
{
LOG_E("input network interface device is NULL.");
return -RT_ERROR;
}
RT_ASSERT(netdev);
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get ec20 device by netdev name(%s) failed.", netdev->name);
LOG_E("get device(%s) failed.", netdev->name);
return -RT_ERROR;
}
@ -251,7 +251,7 @@ static int ec20_netdev_set_info(struct netdev *netdev)
resp = at_create_resp(EC20_IEMI_RESP_SIZE, 0, EC20_INFO_RESP_TIMO);
if (resp == RT_NULL)
{
LOG_E("no memory for ec20 device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
result = -RT_ENOMEM;
goto __exit;
}
@ -273,12 +273,12 @@ static int ec20_netdev_set_info(struct netdev *netdev)
if (at_resp_parse_line_args(resp, 2, "%s", iemi) <= 0)
{
LOG_E("ec20 device(%s) prase \"AT+GSN\" commands resposne data error.", device->name);
LOG_E("%s device prase \"AT+GSN\" cmd error.", device->name);
result = -RT_ERROR;
goto __exit;
}
LOG_D("ec20 deevice(%s) IEMI number: %s", device->name, iemi);
LOG_D("%s device IEMI number: %s", device->name, iemi);
netdev->hwaddr_len = EC20_NETDEV_HWADDR_LEN;
/* get hardware address by IEMI */
@ -312,12 +312,12 @@ static int ec20_netdev_set_info(struct netdev *netdev)
/* parse response data "+QIACT: 1,<context_state>,<context_type>[,<IP_address>]" */
if (at_resp_parse_line_args_by_kw(resp, "+QIACT:", "+QIACT: %*[^\"]\"%[^\"]", ipaddr) <= 0)
{
LOG_E("Prase \"AT+QIACT?\" commands resposne data error!");
LOG_E("%s device \"AT+QIACT?\" cmd error.", device->name);
result = -RT_ERROR;
goto __exit;
}
LOG_D("ec20 device(%s) IP address: %s", device->name, ipaddr);
LOG_D("%s device IP address: %s", device->name, ipaddr);
/* set network interface address information */
inet_aton(ipaddr, &addr);
@ -342,13 +342,13 @@ static int ec20_netdev_set_info(struct netdev *netdev)
if (at_resp_parse_line_args_by_kw(resp, "+QIDNSCFG:", "+QIDNSCFG: 1,\"%[^\"]\",\"%[^\"]\"",
dns_server1, dns_server2) <= 0)
{
LOG_E("ec20 device(%s) prase \"AT+QIDNSCFG=1\" commands resposne data error.", device->name);
LOG_E("%s device prase \"AT+QIDNSCFG=1\" cmd error.", device->name);
result = -RT_ERROR;
goto __exit;
}
LOG_D("ec20 device(%s) primary DNS server address: %s", device->name, dns_server1);
LOG_D("ec20 devcie(%s) secondary DNS server address: %s", device->name, dns_server2);
LOG_D("%s device primary DNS server address: %s", device->name, dns_server1);
LOG_D("%s device secondary DNS server address: %s", device->name, dns_server2);
inet_aton(dns_server1, &addr);
netdev_low_level_set_dns_server(netdev, 0, &addr);
@ -380,14 +380,14 @@ static void ec20_check_link_status_entry(void *parameter)
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get ec20 device by netdev name(%s) failed.", netdev->name);
LOG_E("get device(%s) failed.", netdev->name);
return;
}
resp = at_create_resp(EC20_LINK_RESP_SIZE, 0, EC20_LINK_RESP_TIMO);
if (resp == RT_NULL)
{
LOG_E("no memory for ec20 device(%s) response structure.", device->name);
LOG_E("no memory for resp ceate.");
return;
}
@ -437,11 +437,7 @@ static int ec20_netdev_check_link_status(struct netdev *netdev)
rt_thread_t tid;
if (netdev == RT_NULL)
{
LOG_E("input network interface device is NULL.\n");
return -RT_ERROR;
}
RT_ASSERT(netdev);
/* create ec20 link status polling thread */
tid = rt_thread_create("ec20_link", ec20_check_link_status_entry, (void *)netdev,
@ -463,7 +459,7 @@ static int ec20_netdev_set_up(struct netdev *netdev)
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get ec20 device by netdev name(%s) failed.", netdev->name);
LOG_E("get device(%s) failed.", netdev->name);
return -RT_ERROR;
}
@ -473,7 +469,7 @@ static int ec20_netdev_set_up(struct netdev *netdev)
device->is_init = RT_TRUE;
netdev_low_level_set_status(netdev, RT_TRUE);
LOG_D("the network interface device(%s) set up status.", netdev->name);
LOG_D("network interface device(%s) set up status.", netdev->name);
}
return RT_EOK;
@ -486,7 +482,7 @@ static int ec20_netdev_set_down(struct netdev *netdev)
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get ec20 device by netdev name(%s) failed.", netdev->name);
LOG_E("get device(%s) failed.", netdev->name);
return -RT_ERROR;
}
@ -496,7 +492,7 @@ static int ec20_netdev_set_down(struct netdev *netdev)
device->is_init = RT_FALSE;
netdev_low_level_set_status(netdev, RT_FALSE);
LOG_D("the network interface device(%s) set down status.", netdev->name);
LOG_D("network interface device(%s) set down status.", netdev->name);
}
return RT_EOK;
@ -517,14 +513,14 @@ static int ec20_netdev_set_dns_server(struct netdev *netdev, uint8_t dns_num, ip
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get ec20 device by netdev name(%s) failed.", netdev->name);
LOG_E("get device(%s) failed.", netdev->name);
return -RT_ERROR;
}
resp = at_create_resp(EC20_DNS_RESP_LEN, 0, EC20_DNS_RESP_TIMEO);
if (resp == RT_NULL)
{
LOG_D("no memory for ec20 device(%s) response structure.", device->name);
LOG_D("no memory for resp create.");
result = -RT_ENOMEM;
goto __exit;
}
@ -568,14 +564,14 @@ static int ec20_netdev_ping(struct netdev *netdev, const char *host,
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get ec20 device by netdev name(%s) failed.", netdev->name);
LOG_E("get device(%s) failed.", netdev->name);
return -RT_ERROR;
}
resp = at_create_resp(EC20_PING_RESP_SIZE, 4, EC20_PING_TIMEO);
if (resp == RT_NULL)
{
LOG_E("no memory for ec20 device(%s) response structure.", device->name);
LOG_E("no memory for resp create");
return -RT_ENOMEM;
}
@ -626,12 +622,7 @@ __exit:
}
#endif /* NETDEV_USING_PING */
#ifdef NETDEV_USING_NETSTAT
static void ec20_netdev_netstat(struct netdev *netdev)
{
// TODO
}
#endif /* NETDEV_USING_NETSTAT */
const struct netdev_ops ec20_netdev_ops =
{
@ -645,9 +636,7 @@ const struct netdev_ops ec20_netdev_ops =
#ifdef NETDEV_USING_PING
ec20_netdev_ping,
#endif
#ifdef NETDEV_USING_NETSTAT
ec20_netdev_netstat,
#endif
RT_NULL,
};
static struct netdev *ec20_netdev_add(const char *netdev_name)
@ -659,7 +648,7 @@ static struct netdev *ec20_netdev_add(const char *netdev_name)
netdev = (struct netdev *)rt_calloc(1, sizeof(struct netdev));
if (netdev == RT_NULL)
{
LOG_E("no memory for ec20 device(%s) netdev structure.", netdev->name);
LOG_E("no memory for netdev create.");
return RT_NULL;
}
@ -710,11 +699,11 @@ static void ec20_init_thread_entry(void *parameter)
resp = at_create_resp(128, 0, rt_tick_from_millisecond(300));
if (resp == RT_NULL)
{
LOG_E("no memory for ec20 device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return;
}
LOG_D("start initializing the ec20 device(%s).", device->name);
LOG_D("start init %s device.", device->name);
while (retry_num--)
{
@ -738,7 +727,7 @@ static void ec20_init_thread_entry(void *parameter)
/* Get the baudrate */
AT_SEND_CMD(client, resp, 0, 300, "AT+IPR?");
at_resp_parse_line_args_by_kw(resp, "+IPR:", "+IPR: %d", &i);
LOG_D("ec20 device(%s) baudrate %d", device->name, i);
LOG_D("%s device baudrate %d", device->name, i);
/* get module version */
AT_SEND_CMD(client, resp, 0, 300, "ATI");
/* show module version */
@ -753,7 +742,7 @@ static void ec20_init_thread_entry(void *parameter)
AT_SEND_CMD(client, resp, 2, 5 * 1000, "AT+CPIN?");
if (!at_resp_get_line_by_kw(resp, "READY"))
{
LOG_E("ec20 device(%s) SIM card detection failed.", device->name);
LOG_E("%s device SIM card detection failed.", device->name);
result = -RT_ERROR;
goto __exit;
}
@ -770,7 +759,7 @@ static void ec20_init_thread_entry(void *parameter)
i++;
if(i > CIMI_RETRY)
{
LOG_E("ec20 device(%s) read CIMI failed.", device->name);
LOG_E("%s device read CIMI failed.", device->name);
result = -RT_ERROR;
goto __exit;
}
@ -786,7 +775,7 @@ static void ec20_init_thread_entry(void *parameter)
at_resp_parse_line_args_by_kw(resp, "+CSQ:", "+CSQ: %d,%d", &qi_arg[0], &qi_arg[1]);
if (qi_arg[0] != 99)
{
LOG_D("ec20 device(%s) signal strength: %d, channel bit error rate: %d",
LOG_D("%s device signal strength: %d, channel bit error rate: %d",
device->name, qi_arg[0], qi_arg[1]);
break;
}
@ -794,7 +783,7 @@ static void ec20_init_thread_entry(void *parameter)
}
if (i == CSQ_RETRY)
{
LOG_E("ec20 device(%s) signal strength check failed (%s)", device->name, parsed_data);
LOG_E("%s device signal strength check failed (%s)", device->name, parsed_data);
result = -RT_ERROR;
goto __exit;
}
@ -806,14 +795,14 @@ static void ec20_init_thread_entry(void *parameter)
if (!rt_strncmp(parsed_data, "0,1", sizeof(parsed_data)) ||
!rt_strncmp(parsed_data, "0,5", sizeof(parsed_data)))
{
LOG_D("ec20 device(%s) GSM network is registered(%s)", device->name, parsed_data);
LOG_D("%s device GSM is registered(%s)", device->name, parsed_data);
break;
}
rt_thread_mdelay(1000);
}
if (i == CREG_RETRY)
{
LOG_E("ec20 device(%s) GSM network is register failed (%s)", device->name, parsed_data);
LOG_E("%s device GSM is register failed (%s)", device->name, parsed_data);
result = -RT_ERROR;
goto __exit;
}
@ -825,14 +814,14 @@ static void ec20_init_thread_entry(void *parameter)
if (!rt_strncmp(parsed_data, "0,1", sizeof(parsed_data)) ||
!rt_strncmp(parsed_data, "0,5", sizeof(parsed_data)))
{
LOG_D("ec20 device(%s) GPRS network is registered(%s)", device->name, parsed_data);
LOG_D("%s device GPRS is registered(%s)", device->name, parsed_data);
break;
}
rt_thread_mdelay(1000);
}
if (i == CGREG_RETRY)
{
LOG_E("ec20 device(%s) GPRS network is register failed (%s)", device->name, parsed_data);
LOG_E("%s device GPRS is register failed (%s)", device->name, parsed_data);
result = -RT_ERROR;
goto __exit;
}
@ -844,19 +833,19 @@ static void ec20_init_thread_entry(void *parameter)
if(rt_strcmp(parsed_data,"CHINA MOBILE") == 0)
{
/* "CMCC" */
LOG_I("ec20 device(%s) network operator: %s", device->name, parsed_data);
LOG_I("%s device network operator: %s", device->name, parsed_data);
AT_SEND_CMD(client, resp, 0, 300, QICSGP_CHINA_MOBILE);
}
else if(strcmp(parsed_data,"CHN-UNICOM") == 0)
{
/* "UNICOM" */
LOG_I("ec20 device(%s) network operator: %s", device->name, parsed_data);
LOG_I("%s device network operator: %s", device->name, parsed_data);
AT_SEND_CMD(client, resp, 0, 300, QICSGP_CHINA_UNICOM);
}
else if(rt_strcmp(parsed_data,"CHN-CT") == 0)
{
/* "CT" */
LOG_I("ec20 device(%s) network operator: %s", device->name, parsed_data);
LOG_I("%s device network operator: %s", device->name, parsed_data);
AT_SEND_CMD(client, resp, 0, 300, QICSGP_CHINA_TELECOM);
}
/* Enable automatic time zone update via NITZ and update LOCAL time to RTC */
@ -871,21 +860,20 @@ static void ec20_init_thread_entry(void *parameter)
/* Query the status of the context profile */
AT_SEND_CMD(client, resp, 0, 150 * 1000, "AT+QIACT?");
at_resp_parse_line_args_by_kw(resp, "+QIACT:", "+QIACT: %*[^\"]\"%[^\"]", &parsed_data);
LOG_I("ec20 device(%s) IP address: %s", device->name, parsed_data);
LOG_I("%s device IP address: %s", device->name, parsed_data);
/* initialize successfully */
result = RT_EOK;
break;
__exit:
if (result == RT_EOK)
{
break;
}
else
if (result != RT_EOK)
{
/* power off the ec20 device */
ec20_power_off(device);
rt_thread_mdelay(1000);
LOG_I("ec20 device(%s) initialize retry...", device->name);
LOG_I("%s device initialize retry...", device->name);
}
}
@ -900,11 +888,11 @@ static void ec20_init_thread_entry(void *parameter)
ec20_netdev_set_info(device->netdev);
ec20_netdev_check_link_status(device->netdev);
LOG_I("ec20 device(%s) network initialize success.", device->name);
LOG_I("%s device network initialize success.", device->name);
}
else
{
LOG_E("ec20 device(%s) network initialize failed(%d).", device->name, result);
LOG_E("%s device network initialize failed(%d).", device->name, result);
}
}
@ -914,7 +902,8 @@ static int ec20_net_init(struct at_device *device)
{
#ifdef AT_DEVICE_EC20_INIT_ASYN
rt_thread_t tid;
tid = rt_thread_create("ec20_net_init", ec20_init_thread_entry, (void *) device,
tid = rt_thread_create("ec20_net", ec20_init_thread_entry, (void *)device,
EC20_THREAD_STACK_SIZE, EC20_THREAD_PRIORITY, 20);
if (tid)
{
@ -922,7 +911,7 @@ static int ec20_net_init(struct at_device *device)
}
else
{
LOG_E("create ec20 device(%s) initialization thread failed.", device->name);
LOG_E("create %s device init thread failed.", device->name);
return -RT_ERROR;
}
#else
@ -942,7 +931,7 @@ static int ec20_init(struct at_device *device)
device->client = at_client_get(ec20->client_name);
if (device->client == RT_NULL)
{
LOG_E("ec20 device(%s) initialize failed, get AT client(%s) failed.", ec20->device_name, ec20->client_name);
LOG_E("get AT client(%s) failed.", ec20->client_name);
return -RT_ERROR;
}
@ -955,7 +944,7 @@ static int ec20_init(struct at_device *device)
device->netdev = ec20_netdev_add(ec20->device_name);
if (device->netdev == RT_NULL)
{
LOG_E("ec20 device(%s) initialize failed, get network interface device failed.", ec20->device_name);
LOG_E("add netdev(%s) failed.", ec20->device_name);
return -RT_ERROR;
}
@ -995,7 +984,7 @@ static int ec20_control(struct at_device *device, int cmd, void *arg)
case AT_DEVICE_CTRL_GET_SIGNAL:
case AT_DEVICE_CTRL_GET_GPS:
case AT_DEVICE_CTRL_GET_VER:
LOG_W("ec20 not support the control command(%d).", cmd);
LOG_W("not support the control command(%d).", cmd);
break;
default:
LOG_E("input error control command(%d).", cmd);
@ -1019,7 +1008,7 @@ static int ec20_device_class_register(void)
class = (struct at_device_class *) rt_calloc(1, sizeof(struct at_device_class));
if (class == RT_NULL)
{
LOG_E("no memory for ec20 device class create.");
LOG_E("no memory for device class create.");
return -RT_ENOMEM;
}

View File

@ -29,7 +29,7 @@
#include <at_device_ec20.h>
#define LOG_TAG "at.skt"
#define LOG_TAG "at.skt.ec20"
#include <at_log.h>
#if defined(AT_DEVICE_USING_EC20) && defined(AT_USING_SOCKET)
@ -88,6 +88,7 @@ static void at_tcp_ip_errcode_parse(int result)//TCP/IP_QIGETERROR
}
}
#ifdef EC20_USING_HTTP
static void at_http_errcode_parse(int result)//HTTP
{
switch(result)
@ -142,7 +143,9 @@ static void at_http_rsponsecode_parse(int result)//HTTP
default : LOG_E("%d : Unknown err code", result); break;
}
}
#endif /* EC20_USING_HTTP */
#ifdef EC20_USING_FTP
static void at_ftp_errcode_parse(int result)//FTP
{
switch(result)
@ -207,7 +210,9 @@ static void at_ftp_protocol_errcode_parse(int result)//FTP_Protocol
default : LOG_E("%d : Unknown err code", result); break;
}
}
#endif /* EC20_USING_FTP */
#ifdef EC20_USING_SMTP
static void at_smtp_errcode_parse(int result)//Email
{
switch(result)
@ -272,6 +277,7 @@ static void at_smtp_protocol_errcode_parse(int result)//Email_Protocol
default : LOG_E("%d : Unknown err code", result); break;
}
}
#endif /* EC20_USING_SMTP */
static int ec20_socket_event_send(struct at_device *device, uint32_t event)
{
@ -312,7 +318,7 @@ static int ec20_socket_close(struct at_socket *socket)
resp = at_create_resp(64, 0, 5 * RT_TICK_PER_SECOND);
if (resp == RT_NULL)
{
LOG_E("no memory for ec20 device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
@ -357,7 +363,7 @@ static int ec20_socket_connect(struct at_socket *socket, char *ip, int32_t port,
resp = at_create_resp(128, 0, 5 * RT_TICK_PER_SECOND);
if (resp == RT_NULL)
{
LOG_E("no memory for ec20 device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
@ -394,7 +400,7 @@ __retry:
break;
default:
LOG_E("ec20 device(%s) not supported connect type : %d.", device->name, type);
LOG_E("not supported connect type : %d.", type);
return -RT_ERROR;
}
}
@ -402,7 +408,7 @@ __retry:
/* waiting result event from AT URC, the device default connection timeout is 75 seconds, but it set to 10 seconds is convenient to use.*/
if (ec20_socket_event_recv(device, SET_EVENT(device_socket, 0), 10 * RT_TICK_PER_SECOND, RT_EVENT_FLAG_OR) < 0)
{
LOG_E("ec20 device(%s) socket(%d) connect failed, wait connect result timeout.", device->name, device_socket);
LOG_E("%s device socket(%d) wait connect URC timeout.", device->name, device_socket);
result = -RT_ETIMEOUT;
goto __exit;
}
@ -411,7 +417,7 @@ __retry:
EC20_EVENT_CONN_OK | EC20_EVENT_CONN_FAIL, 1 * RT_TICK_PER_SECOND, RT_EVENT_FLAG_OR);
if (event_result < 0)
{
LOG_E("ec20 device(%s) socket(%d) connect failed, wait connect OK|FAIL timeout.", device->name, device_socket);
LOG_E("%s device socket(%d) wait connect OK|FAIL timeout.", device->name, device_socket);
result = -RT_ETIMEOUT;
goto __exit;
}
@ -420,7 +426,7 @@ __retry:
{
if (retryed == RT_FALSE)
{
LOG_D("ec20 device(%s) socket(%d) connect failed, maybe the socket was not be closed at the last time and now will retry.",
LOG_D("%s device socket(%d) connect failed, the socket was not be closed and now will connect retey.",
device->name, device_socket);
/* default connection timeout is 10 seconds, but it set to 1 seconds is convenient to use.*/
if (ec20_socket_close(socket) < 0)
@ -431,7 +437,7 @@ __retry:
retryed = RT_TRUE;
goto __retry;
}
LOG_E("ec20 device(%s) socket(%d) connect failed.", device->name, device_socket);
LOG_E("%s device socket(%d) connect failed.", device->name, device_socket);
result = -RT_ERROR;
goto __exit;
}
@ -455,7 +461,7 @@ static int at_get_send_size(struct at_socket *socket, size_t *size, size_t *acke
resp = at_create_resp(128, 0, 5 * RT_TICK_PER_SECOND);
if (resp == RT_NULL)
{
LOG_E("no memory for ec20 device(%s) response structure.", device->name);
LOG_E("no memory for resp create.", device->name);
result = -RT_ENOMEM;
goto __exit;
}
@ -530,7 +536,7 @@ static int ec20_socket_send(struct at_socket *socket, const char *buff, size_t b
resp = at_create_resp(128, 2, 5 * RT_TICK_PER_SECOND);
if (resp == RT_NULL)
{
LOG_E("no memory for ec20 device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
@ -583,14 +589,14 @@ static int ec20_socket_send(struct at_socket *socket, const char *buff, size_t b
EC20_EVENT_SEND_OK | EC20_EVENT_SEND_FAIL, 1 * RT_TICK_PER_SECOND, RT_EVENT_FLAG_OR);
if (event_result < 0)
{
LOG_E("ec20 device(%s) socket (%d) send failed, wait connect OK|FAIL timeout.", device->name, device_socket);
LOG_E("%s device socket(%d) wait sned OK|FAIL timeout.", device->name, device_socket);
result = -RT_ETIMEOUT;
goto __exit;
}
/* check result */
if (event_result & EC20_EVENT_SEND_FAIL)
{
LOG_E("ec20 device(%s) socket (%d) send failed.", device->name, device_socket);
LOG_E("%s device socket(%d) send failed.", device->name, device_socket);
result = -RT_ERROR;
goto __exit;
}
@ -643,7 +649,7 @@ static int ec20_domain_resolve(const char *name, char ip[16])
device = at_device_get_first_initialized();
if (device == RT_NULL)
{
LOG_E("get first initialization ec20 device failed.");
LOG_E("get first init device failed.");
return -RT_ERROR;
}
@ -651,7 +657,7 @@ static int ec20_domain_resolve(const char *name, char ip[16])
resp = at_create_resp(128, 0, 10 * RT_TICK_PER_SECOND);
if (!resp)
{
LOG_E("no memory for ec20 device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
@ -737,7 +743,7 @@ static void urc_connect_func(struct at_client *client, const char *data, rt_size
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_CLIENT, client_name);
if (device == RT_NULL)
{
LOG_E("get ec20 device by client name(%s) failed.", client_name);
LOG_E("get device(%s) failed.", client_name);
return;
}
@ -766,7 +772,7 @@ static void urc_send_func(struct at_client *client, const char *data, rt_size_t
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_CLIENT, client_name);
if (device == RT_NULL)
{
LOG_E("get ec20 device by client name(%s) failed.", client_name);
LOG_E("get device(%s) failed.", client_name);
return;
}
ec20 = (struct at_device_ec20 *) device->user_data;
@ -794,7 +800,7 @@ static void urc_close_func(struct at_client *client, const char *data, rt_size_t
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_CLIENT, client_name);
if (device == RT_NULL)
{
LOG_E("get ec20 device by client name(%s) failed.", client_name);
LOG_E("get device(%s) failed.", client_name);
return;
}
@ -824,7 +830,7 @@ static void urc_recv_func(struct at_client *client, const char *data, rt_size_t
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_CLIENT, client_name);
if (device == RT_NULL)
{
LOG_E("get ec20 device by client name(%s) failed.", client_name);
LOG_E("get device(%s) failed.", client_name);
return;
}
@ -841,7 +847,7 @@ static void urc_recv_func(struct at_client *client, const char *data, rt_size_t
recv_buf = (char *) rt_calloc(1, bfsz);
if (recv_buf == RT_NULL)
{
LOG_E("no memory for ec20 device(%s) URC receive buffer (%d).", device->name, bfsz);
LOG_E("no memory for URC receive buffer(%d).", bfsz);
/* read and clean the coming data */
while (temp_size < bfsz)
{
@ -861,7 +867,7 @@ static void urc_recv_func(struct at_client *client, const char *data, rt_size_t
/* sync receive data */
if (at_client_obj_recv(client, recv_buf, bfsz, timeout) != bfsz)
{
LOG_E("ec20 device(%s) receive size(%d) data failed.", device->name, bfsz);
LOG_E("%s device receive size(%d) data failed.", device->name, bfsz);
rt_free(recv_buf);
return;
}
@ -901,7 +907,7 @@ static void urc_dnsqip_func(struct at_client *client, const char *data, rt_size_
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_CLIENT, client_name);
if (device == RT_NULL)
{
LOG_E("get ec20 device by client name(%s) failed.", client_name);
LOG_E("get device(%s) failed.", client_name);
return;
}
ec20 = (struct at_device_ec20 *) device->user_data;

View File

@ -28,7 +28,7 @@
#include <at_device_esp8266.h>
#define LOG_TAG "at.dev"
#define LOG_TAG "at.dev.esp"
#include <at_log.h>
@ -71,7 +71,7 @@ static void esp8266_get_netdev_info(struct rt_work *work, void *work_data)
resp = at_create_resp(512, 0, rt_tick_from_millisecond(300));
if (resp == RT_NULL)
{
LOG_E("no memory for esp8266 device(%d) response structure.", device->name);
LOG_E("no memory for resp create.");
return;
}
@ -83,14 +83,14 @@ static void esp8266_get_netdev_info(struct rt_work *work, void *work_data)
if (at_resp_parse_line_args_by_kw(resp, "STAMAC", resp_expr, mac) <= 0)
{
LOG_E("esp8266 device(%s) parse \"AT+CIFSR\" command response data error.", device->name);
LOG_E("%s device parse \"AT+CIFSR\" cmd error.", device->name);
goto __exit;
}
/* send addr info query commond "AT+CIPSTA?" and wait response */
if (at_obj_exec_cmd(client, resp, "AT+CIPSTA?") < 0)
{
LOG_E("esp8266 device(%s) send \"AT+CIPSTA?\" commands error.", device->name);
LOG_E("%s device send \"AT+CIPSTA?\" cmd error.", device->name);
goto __exit;
}
@ -98,7 +98,7 @@ static void esp8266_get_netdev_info(struct rt_work *work, void *work_data)
at_resp_parse_line_args_by_kw(resp, "gateway", resp_expr, gateway) <= 0 ||
at_resp_parse_line_args_by_kw(resp, "netmask", resp_expr, netmask) <= 0)
{
LOG_E("esp8266 device(%s) prase \"AT+CIPSTA?\" command resposne data error.", device->name);
LOG_E("%s device prase \"AT+CIPSTA?\" cmd error.", device->name);
goto __exit;
}
@ -119,14 +119,14 @@ static void esp8266_get_netdev_info(struct rt_work *work, void *work_data)
/* send dns server query commond "AT+CIPDNS_CUR?" and wait response */
if (at_obj_exec_cmd(device->client, resp, "AT+CIPDNS_CUR?") < 0)
{
LOG_W("please check and update device(%s) firmware to support the \"AT+CIPDNS_CUR?\" command.", device->name);
LOG_W("please check and update %s device firmware to support the \"AT+CIPDNS_CUR?\" cmd.", device->name);
goto __exit;
}
if (at_resp_parse_line_args(resp, 1, resp_dns, dns_server1) <= 0 &&
at_resp_parse_line_args(resp, 2, resp_dns, dns_server2) <= 0)
{
LOG_E("esp8266 device(%d) prase \"AT+CIPDNS_CUR?\" commands resposne data error.", device->name);
LOG_E("%d device prase \"AT+CIPDNS_CUR?\" cmd error.", device->name);
goto __exit;
}
@ -159,7 +159,7 @@ static void esp8266_get_netdev_info(struct rt_work *work, void *work_data)
/* parse response data, get the DHCP status */
if (at_resp_parse_line_args_by_kw(resp, "+CWDHCP_CUR:", "+CWDHCP_CUR:%d", &dhcp_stat) < 0)
{
LOG_E("esp8266 device(%s) get DHCP status failed.", device->name);
LOG_E("%s device prase DHCP status error.", device->name);
goto __exit;
}
@ -182,7 +182,7 @@ static int esp8266_netdev_set_up(struct netdev *netdev)
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get esp8266 device by netdev name(%s) failed.", netdev->name);
LOG_E("get device(%s) failed.", netdev->name);
return -RT_ERROR;
}
@ -190,7 +190,7 @@ static int esp8266_netdev_set_up(struct netdev *netdev)
{
esp8266_net_init(device);
netdev_low_level_set_status(netdev, RT_TRUE);
LOG_D("the network interface device(%s) set up status", netdev->name);
LOG_D("network interface device(%s) set up status", netdev->name);
}
return RT_EOK;
@ -203,7 +203,7 @@ static int esp8266_netdev_set_down(struct netdev *netdev)
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get esp8266 device by netdev name(%s) failed.", netdev->name);
LOG_E("get device by netdev(%s) failed.", netdev->name);
return -RT_ERROR;
}
@ -211,7 +211,7 @@ static int esp8266_netdev_set_down(struct netdev *netdev)
{
device->is_init = RT_FALSE;
netdev_low_level_set_status(netdev, RT_FALSE);
LOG_D("the network interface device(%s) set down status", netdev->name);
LOG_D("network interface device(%s) set down status", netdev->name);
}
return RT_EOK;
@ -225,9 +225,9 @@ static int esp8266_netdev_set_addr_info(struct netdev *netdev, ip_addr_t *ip_add
int result = RT_EOK;
at_response_t resp = RT_NULL;
struct at_device *device = RT_NULL;
char esp8266_ip_addr[IPADDR_SIZE] = {0};
char esp8266_gw_addr[IPADDR_SIZE] = {0};
char esp8266_netmask_addr[IPADDR_SIZE] = {0};
char ip_str[IPADDR_SIZE] = {0};
char gw_str[IPADDR_SIZE] = {0};
char netmask_str[IPADDR_SIZE] = {0};
RT_ASSERT(netdev);
RT_ASSERT(ip_addr || netmask || gw);
@ -235,39 +235,39 @@ static int esp8266_netdev_set_addr_info(struct netdev *netdev, ip_addr_t *ip_add
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get esp8266 device by netdev name(%s) failed.", netdev->name);
LOG_E("get device(%s) failed.", netdev->name);
return -RT_ERROR;
}
resp = at_create_resp(IPADDR_RESP_SIZE, 0, rt_tick_from_millisecond(300));
if (resp == RT_NULL)
{
LOG_E("no memory for esp8266 device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
result = -RT_ENOMEM;
goto __exit;
}
/* Convert numeric IP address into decimal dotted ASCII representation. */
if (ip_addr)
rt_memcpy(esp8266_ip_addr, inet_ntoa(*ip_addr), IPADDR_SIZE);
rt_memcpy(ip_str, inet_ntoa(*ip_addr), IPADDR_SIZE);
else
rt_memcpy(esp8266_ip_addr, inet_ntoa(netdev->ip_addr), IPADDR_SIZE);
rt_memcpy(ip_str, inet_ntoa(netdev->ip_addr), IPADDR_SIZE);
if (gw)
rt_memcpy(esp8266_gw_addr, inet_ntoa(*gw), IPADDR_SIZE);
rt_memcpy(gw_str, inet_ntoa(*gw), IPADDR_SIZE);
else
rt_memcpy(esp8266_gw_addr, inet_ntoa(netdev->gw), IPADDR_SIZE);
rt_memcpy(gw_str, inet_ntoa(netdev->gw), IPADDR_SIZE);
if (netmask)
rt_memcpy(esp8266_netmask_addr, inet_ntoa(*netmask), IPADDR_SIZE);
rt_memcpy(netmask_str, inet_ntoa(*netmask), IPADDR_SIZE);
else
rt_memcpy(esp8266_netmask_addr, inet_ntoa(netdev->netmask), IPADDR_SIZE);
rt_memcpy(netmask_str, inet_ntoa(netdev->netmask), IPADDR_SIZE);
/* send addr info set commond "AT+CIPSTA_CUR=<ip>[,<gateway>,<netmask>]" and wait response */
if (at_obj_exec_cmd(device->client, resp, "AT+CIPSTA_CUR=\"%s\",\"%s\",\"%s\"",
esp8266_ip_addr, esp8266_gw_addr, esp8266_netmask_addr) < 0)
ip_str, gw_str, netmask_str) < 0)
{
LOG_E("esp8266 device(%s) set address information failed.", device->name);
LOG_E("%s device set address failed.", device->name);
result = -RT_ERROR;
}
else
@ -282,7 +282,7 @@ static int esp8266_netdev_set_addr_info(struct netdev *netdev, ip_addr_t *ip_add
if (netmask)
netdev_low_level_set_netmask(netdev, netmask);
LOG_D("esp8266 device(%s) set address information successfully.", device->name);
LOG_D("%s device set address success.", device->name);
}
__exit:
@ -308,27 +308,27 @@ static int esp8266_netdev_set_dns_server(struct netdev *netdev, uint8_t dns_num,
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get esp8266 device by netdev name(%s) failed.", netdev->name);
LOG_E("get device by netdev(%s) failed.", netdev->name);
return -RT_ERROR;
}
resp = at_create_resp(DNS_RESP_SIZE, 0, rt_tick_from_millisecond(300));
if (resp == RT_NULL)
{
LOG_E("no memory for esp8266 device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
/* send dns server set commond "AT+CIPDNS_CUR=<enable>[,<DNS server0>,<DNS server1>]" and wait response */
if (at_obj_exec_cmd(device->client, resp, "AT+CIPDNS_CUR=1,\"%s\"", inet_ntoa(*dns_server)) < 0)
{
LOG_E("esp8266 device(%s) set DNS server(%s) failed.", device->name, inet_ntoa(*dns_server));
LOG_E("%s device set DNS failed.", device->name);
result = -RT_ERROR;
}
else
{
netdev_low_level_set_dns_server(netdev, dns_num, dns_server);
LOG_D("esp8266 device(%s) set DNS server(%s) successfully.", device->name, inet_ntoa(*dns_server));
LOG_D("%s device set DNS(%s) success.", device->name, inet_ntoa(*dns_server));
}
if (resp)
@ -353,28 +353,28 @@ static int esp8266_netdev_set_dhcp(struct netdev *netdev, rt_bool_t is_enabled)
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get AT device by netdev name(%s) failed.", netdev->name);
LOG_E("get device by netdev(%s) failed.", netdev->name);
return -RT_ERROR;
}
resp = at_create_resp(RESP_SIZE, 0, rt_tick_from_millisecond(300));
if (resp == RT_NULL)
{
LOG_E("no memory for esp8266 device(%s) response structure.",device->name);
LOG_E("no memory for resp struct.");
return -RT_ENOMEM;
}
/* send dhcp set commond "AT+CWDHCP_CUR=<mode>,<en>" and wait response */
if (at_obj_exec_cmd(device->client, resp, "AT+CWDHCP_CUR=%d,%d", ESP8266_STATION, is_enabled) < 0)
{
LOG_E("esp8266 device(%s) set DHCP status(%d) failed.", device->name, is_enabled);
LOG_E("%s device set DHCP status(%d) failed.", device->name, is_enabled);
result = -RT_ERROR;
goto __exit;
}
else
{
netdev_low_level_set_dhcp_status(netdev, is_enabled);
LOG_D("esp8266 device(%d) set DHCP status(%d) successfully.", device->name, is_enabled);
LOG_D("%s device set DHCP status(%d) ok.", device->name, is_enabled);
}
__exit:
@ -405,14 +405,14 @@ static int esp8266_netdev_ping(struct netdev *netdev, const char *host,
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get esp8266 device by netdev name(%s) failed.", netdev->name);
LOG_E("get device(%s) failed.", netdev->name);
return -RT_ERROR;
}
resp = at_create_resp(64, 0, timeout);
if (resp == RT_NULL)
{
LOG_E("no memory for esp8266 device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
@ -478,7 +478,7 @@ void esp8266_netdev_netstat(struct netdev *netdev)
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get esp8266 device by netdev name(%s) failed.", netdev->name);
LOG_E("get device(%s) failed.", netdev->name);
return;
}
@ -486,14 +486,14 @@ void esp8266_netdev_netstat(struct netdev *netdev)
ipaddr = (char *) rt_calloc(1, ESP8266_NETSTAT_IPADDR_SIZE);
if ((type && ipaddr) == RT_NULL)
{
LOG_E("no memory for esp8266 device(%s) response structure.", device->name);
LOG_E("no memory for ipaddr create.");
goto __exit;
}
resp = at_create_resp(ESP8266_NETSTAT_RESP_SIZE, 0, 5 * RT_TICK_PER_SECOND);
if (resp == RT_NULL)
{
LOG_E("no memory for esp8266 device(%s) response structure.", device->name);
LOG_E("no memory for resp create.", device->name);
goto __exit;
}
@ -565,7 +565,7 @@ static struct netdev *esp8266_netdev_add(const char *netdev_name)
netdev = (struct netdev *) rt_calloc(1, sizeof(struct netdev));
if (netdev == RT_NULL)
{
LOG_E("no memory for esp8266 device(%s) netdev structure.", netdev_name);
LOG_E("no memory for netdev create.");
return RT_NULL;
}
@ -621,7 +621,7 @@ static void esp8266_init_thread_entry(void *parameter)
rt_size_t i = 0, retry_num = INIT_RETRY;
rt_bool_t wifi_is_conn = RT_FALSE;
LOG_D("esp8266 device(%s) initialize start.", device->name);
LOG_D("%s device initialize start.", device->name);
/* wait esp8266 device startup finish */
if (at_client_obj_wait_connect(client, ESP8266_WAIT_CONNECT_TIME))
@ -632,7 +632,7 @@ static void esp8266_init_thread_entry(void *parameter)
resp = at_create_resp(128, 0, 5 * RT_TICK_PER_SECOND);
if (resp == RT_NULL)
{
LOG_E("no memory for esp8266 device(%d) response structure.", device->name);
LOG_E("no memory for resp create.");
return;
}
@ -656,15 +656,15 @@ static void esp8266_init_thread_entry(void *parameter)
AT_SEND_CMD(client, resp, "AT+CIPMUX=1");
__exit:
if (result == RT_EOK)
{
/* initialize successfully */
result = RT_EOK;
break;
}
else
__exit:
if (result != RT_EOK)
{
rt_thread_mdelay(1000);
LOG_I("esp8266 device(%s) initialize retry...", device->name);
LOG_I("%s device initialize retry...", device->name);
}
}
@ -672,7 +672,7 @@ static void esp8266_init_thread_entry(void *parameter)
if (at_obj_exec_cmd(client, at_resp_set_info(resp, 128, 0, 20 * RT_TICK_PER_SECOND),
"AT+CWJAP=\"%s\",\"%s\"", esp8266->wifi_ssid, esp8266->wifi_password) != RT_EOK)
{
LOG_W("AT device(%s) network initialize failed, check ssid(%s) and password(%s).",
LOG_W("%s device wifi connect failed, check ssid(%s) and password(%s).",
device->name, esp8266->wifi_ssid, esp8266->wifi_password);
}
else
@ -680,7 +680,6 @@ static void esp8266_init_thread_entry(void *parameter)
wifi_is_conn = RT_TRUE;
}
if (resp)
{
at_delete_resp(resp);
@ -689,7 +688,7 @@ static void esp8266_init_thread_entry(void *parameter)
if (result != RT_EOK)
{
netdev_low_level_set_status(device->netdev, RT_FALSE);
LOG_E("esp8266 device(%s) network initialize failed(%d).", device->name, result);
LOG_E("%s device network initialize failed(%d).", device->name, result);
}
else
{
@ -700,7 +699,7 @@ static void esp8266_init_thread_entry(void *parameter)
netdev_low_level_set_link_status(device->netdev, RT_TRUE);
}
esp8266_netdev_start_delay_work(device);
LOG_I("esp8266 device(%s) network initialize successfully.", device->name);
LOG_I("%s device network initialize successfully.", device->name);
}
}
@ -709,7 +708,7 @@ static int esp8266_net_init(struct at_device *device)
#ifdef AT_DEVICE_ESP8266_INIT_ASYN
rt_thread_t tid;
tid = rt_thread_create("esp8266_net_init", esp8266_init_thread_entry, (void *) device,
tid = rt_thread_create("esp_net", esp8266_init_thread_entry, (void *) device,
ESP8266_THREAD_STACK_SIZE, ESP8266_THREAD_PRIORITY, 20);
if (tid)
{
@ -717,7 +716,7 @@ static int esp8266_net_init(struct at_device *device)
}
else
{
LOG_E("create esp8266 device(%s) initialize thread failed.", device->name);
LOG_E("create %s device init thread failed.", device->name);
return -RT_ERROR;
}
#else
@ -729,12 +728,12 @@ static int esp8266_net_init(struct at_device *device)
static void urc_busy_p_func(struct at_client *client, const char *data, rt_size_t size)
{
LOG_D("system is processing a commands and it cannot respond to the current commands.");
LOG_D("system is processing a commands...");
}
static void urc_busy_s_func(struct at_client *client, const char *data, rt_size_t size)
{
LOG_D("system is sending data and it cannot respond to the current commands.");
LOG_D("system is sending data...");
}
static void urc_func(struct at_client *client, const char *data, rt_size_t size)
@ -747,13 +746,13 @@ static void urc_func(struct at_client *client, const char *data, rt_size_t size)
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_CLIENT, client_name);
if (device == RT_NULL)
{
LOG_E("get esp8266 device by client name(%s) failed.", client_name);
LOG_E("get device(%s) failed.", client_name);
return;
}
if (rt_strstr(data, "WIFI CONNECTED"))
{
LOG_I("esp8266 device(%s) WIFI is connected.", device->name);
LOG_I("%s device wifi is connected.", device->name);
if (device->is_init)
{
@ -764,7 +763,7 @@ static void urc_func(struct at_client *client, const char *data, rt_size_t size)
}
else if (rt_strstr(data, "WIFI DISCONNECT"))
{
LOG_I("esp8266 device(%s) WIFI is disconnect.", device->name);
LOG_I("%s device wifi is disconnect.", device->name);
if (device->is_init)
{
@ -791,8 +790,7 @@ static int esp8266_init(struct at_device *device)
device->client = at_client_get(esp8266->client_name);
if (device->client == RT_NULL)
{
LOG_E("esp8266 device(%s) initialize failed, get AT client(%s) failed.",
esp8266->device_name, esp8266->client_name);
LOG_E("get AT client(%s) failed.", esp8266->client_name);
return -RT_ERROR;
}
@ -807,7 +805,7 @@ static int esp8266_init(struct at_device *device)
device->netdev = esp8266_netdev_add(esp8266->device_name);
if (device->netdev == RT_NULL)
{
LOG_E("esp8266 device(%s) initialize failed, get network interface device failed.", esp8266->device_name);
LOG_E("add netdev(%s) failed.", esp8266->device_name);
return -RT_ERROR;
}
@ -853,21 +851,21 @@ static int esp8266_wifi_info_set(struct at_device *device, struct at_device_ssid
if (info->ssid == RT_NULL || info->password == RT_NULL)
{
LOG_E("input esp8266 wifi ssid(%s) and password(%s) error.", info->ssid, info->password);
LOG_E("input wifi ssid(%s) and password(%s) error.", info->ssid, info->password);
return -RT_ERROR;
}
resp = at_create_resp(128, 0, 20 * RT_TICK_PER_SECOND);
if (resp == RT_NULL)
{
LOG_E("no memory for esp8266 device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
/* connect to input wifi ap */
if (at_obj_exec_cmd(device->client, resp, "AT+CWJAP=\"%s\",\"%s\"", info->ssid, info->password) != RT_EOK)
{
LOG_E("esp8266 device(%s) wifi connect failed, check ssid(%s) and password(%s).",
LOG_E("%s device wifi connect failed, check ssid(%s) and password(%s).",
device->name, info->ssid, info->password);
result = -RT_ERROR;
}
@ -898,7 +896,7 @@ static int esp8266_control(struct at_device *device, int cmd, void *arg)
case AT_DEVICE_CTRL_GET_SIGNAL:
case AT_DEVICE_CTRL_GET_GPS:
case AT_DEVICE_CTRL_GET_VER:
LOG_W("esp8266 not support the control command(%d).", cmd);
LOG_W("not support the control cmd(%d).", cmd);
break;
case AT_DEVICE_CTRL_RESET:
result = esp8266_reset(device);
@ -907,7 +905,7 @@ static int esp8266_control(struct at_device *device, int cmd, void *arg)
result = esp8266_wifi_info_set(device, (struct at_device_ssid_pwd *) arg);
break;
default:
LOG_E("input error control command(%d).", cmd);
LOG_E("input error control cmd(%d).", cmd);
break;
}
@ -928,7 +926,7 @@ static int esp8266_device_class_register(void)
class = (struct at_device_class *) rt_calloc(1, sizeof(struct at_device_class));
if (class == RT_NULL)
{
LOG_E("no memory for esp8266 device class create.");
LOG_E("no memory for class create.");
return -RT_ENOMEM;
}

View File

@ -28,7 +28,7 @@
#include <at_device_esp8266.h>
#define LOG_TAG "at.skt"
#define LOG_TAG "at.skt.esp"
#include <at_log.h>
#if defined(AT_DEVICE_USING_ESP8266) && defined(AT_USING_SOCKET)
@ -89,7 +89,7 @@ static int esp8266_socket_close(struct at_socket *socket)
resp = at_create_resp(64, 0, rt_tick_from_millisecond(300));
if (resp == RT_NULL)
{
LOG_E("no memory for esp8266 device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
@ -131,7 +131,7 @@ static int esp8266_socket_connect(struct at_socket *socket, char *ip, int32_t po
resp = at_create_resp(128, 0, 5 * RT_TICK_PER_SECOND);
if (resp == RT_NULL)
{
LOG_E("no memory for esp8266 device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
@ -158,7 +158,7 @@ __retry:
break;
default:
LOG_E("esp8266 device(%s) not supported connect type %d.", device->name, type);
LOG_E("not supported connect type %d.", type);
result = -RT_ERROR;
goto __exit;
}
@ -166,7 +166,7 @@ __retry:
if (result != RT_EOK && retryed == RT_FALSE)
{
LOG_D("esp8266 device(%s) socket (%d) connect failed, maybe the socket was not be closed at the last time and now will retry.",
LOG_D("%s device socket (%d) connect failed, the socket was not be closed and now will connect retry.",
device->name, device_socket);
if (esp8266_socket_close(socket) < 0)
{
@ -216,7 +216,7 @@ static int esp8266_socket_send(struct at_socket *socket, const char *buff, size_
resp = at_create_resp(128, 2, 5 * RT_TICK_PER_SECOND);
if (resp == RT_NULL)
{
LOG_E("no memory for esp8266 device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
@ -255,9 +255,10 @@ static int esp8266_socket_send(struct at_socket *socket, const char *buff, size_
}
/* waiting result event from AT URC */
if (esp8266_socket_event_recv(device, SET_EVENT(device_socket, 0), 10 * RT_TICK_PER_SECOND, RT_EVENT_FLAG_OR) < 0)
if (esp8266_socket_event_recv(device, SET_EVENT(device_socket, 0),
10 * RT_TICK_PER_SECOND, RT_EVENT_FLAG_OR) < 0)
{
LOG_E("esp8266 device(%s) socket(%d) send failed, wait connect result timeout.", device->name, device_socket);
LOG_E("%s device socket(%d) wait connect result timeout.", device->name, device_socket);
result = -RT_ETIMEOUT;
goto __exit;
}
@ -266,14 +267,14 @@ static int esp8266_socket_send(struct at_socket *socket, const char *buff, size_
5 * RT_TICK_PER_SECOND, RT_EVENT_FLAG_OR);
if (event_result < 0)
{
LOG_E("esp8266 device(%s) socket(%d) send failed, wait connect OK|FAIL timeout.", device->name, device_socket);
LOG_E("%s device socket(%d) wait connect OK|FAIL timeout.", device->name, device_socket);
result = -RT_ETIMEOUT;
goto __exit;
}
/* check result */
if (event_result & ESP8266_EVENT_SEND_FAIL)
{
LOG_E("esp8266 device(%s) socket(%d) send failed.", device->name, device_socket);
LOG_E("%s device socket(%d) send failed.", device->name, device_socket);
result = -RT_ERROR;
goto __exit;
}
@ -320,14 +321,14 @@ static int esp8266_domain_resolve(const char *name, char ip[16])
device = at_device_get_first_initialized();
if (device == RT_NULL)
{
LOG_E("get first initialization esp8266 device failed.");
LOG_E("get first init device failed.");
return -RT_ERROR;
}
resp = at_create_resp(128, 0, 20 * RT_TICK_PER_SECOND);
if (resp == RT_NULL)
{
LOG_E("no memory for esp8266 device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
@ -406,7 +407,7 @@ static void urc_send_func(struct at_client *client, const char *data, rt_size_t
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_CLIENT, client_name);
if (device == RT_NULL)
{
LOG_E("get esp8266 device by client name(%s) failed.", client_name);
LOG_E("get device(%s) failed.", client_name);
return;
}
esp8266 = (struct at_device_esp8266 *) device->user_data;
@ -443,7 +444,7 @@ static void urc_close_func(struct at_client *client, const char *data, rt_size_t
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_CLIENT, client_name);
if (device == RT_NULL)
{
LOG_E("get esp8266 device by client name(%s) failed.", client_name);
LOG_E("get device(%s) failed.", client_name);
return;
}
@ -472,7 +473,7 @@ static void urc_recv_func(struct at_client *client, const char *data, rt_size_t
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_CLIENT, client_name);
if (device == RT_NULL)
{
LOG_E("get esp8266 device by client name(%s) failed.", client_name);
LOG_E("get device(%s) failed.", client_name);
return;
}
@ -488,7 +489,7 @@ static void urc_recv_func(struct at_client *client, const char *data, rt_size_t
recv_buf = (char *) rt_calloc(1, bfsz);
if (recv_buf == RT_NULL)
{
LOG_E("no memory for esp8266 device(%s) URC receive buffer(%d).", device->name, bfsz);
LOG_E("no memory receive buffer(%d).", bfsz);
/* read and clean the coming data */
while (temp_size < bfsz)
{
@ -508,7 +509,7 @@ static void urc_recv_func(struct at_client *client, const char *data, rt_size_t
/* sync receive data */
if (at_client_obj_recv(client, recv_buf, bfsz, timeout) != bfsz)
{
LOG_E("esp8266 device(%s) receive size(%d) data failed.", device->name, bfsz);
LOG_E("%s device receive size(%d) data failed.", device->name, bfsz);
rt_free(recv_buf);
return;
}

View File

@ -28,7 +28,7 @@
#include <at_device_m26.h>
#define LOG_TAG "at.dev"
#define LOG_TAG "at.dev.m26"
#include <at_log.h>
#ifdef AT_DEVICE_USING_M26
@ -103,16 +103,12 @@ static int m26_netdev_set_info(struct netdev *netdev)
struct at_device *device = RT_NULL;
struct at_client *client = RT_NULL;
if (netdev == RT_NULL)
{
LOG_E("input network interface device is NULL.");
return -RT_ERROR;
}
RT_ASSERT(netdev);
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get m26 deivce by netdev name failed.", netdev->name);
LOG_E("get device(%s) failed.", netdev->name);
return -RT_ERROR;
}
client = device->client;
@ -124,7 +120,7 @@ static int m26_netdev_set_info(struct netdev *netdev)
resp = at_create_resp(M26_IEMI_RESP_SIZE, 0, M26_INFO_RESP_TIMO);
if (resp == RT_NULL)
{
LOG_E("no memory for m26 device(%s) response structure.", netdev->name);
LOG_E("no memory for resp create.");
result = -RT_ENOMEM;
goto __exit;
}
@ -146,12 +142,12 @@ static int m26_netdev_set_info(struct netdev *netdev)
if (at_resp_parse_line_args(resp, 2, "%s", iemi) <= 0)
{
LOG_E("m26 device(%s) prase \"AT+GSN\" commands resposne data error.", device->name);
LOG_E("%s device prase \"AT+GSN\" cmd error.", device->name);
result = -RT_ERROR;
goto __exit;
}
LOG_D("m26 device(%s) IEMI number: %s", device->name, iemi);
LOG_D("%s device IEMI number: %s", device->name, iemi);
netdev->hwaddr_len = M26_NETDEV_HWADDR_LEN;
/* get hardware address by IEMI */
@ -184,12 +180,12 @@ static int m26_netdev_set_info(struct netdev *netdev)
if (at_resp_parse_line_args_by_kw(resp, ".", "%s", ipaddr) <= 0)
{
LOG_E("m26 device(%s) prase \"AT+QILOCIP\" commands resposne data error.", device->name);
LOG_E("%s device prase \"AT+QILOCIP\" cmd error.", device->name);
result = -RT_ERROR;
goto __exit;
}
LOG_D("m26 device(%s) IP address: %s", device->name, ipaddr);
LOG_D("%s device IP address: %s", device->name, ipaddr);
/* set network interface address information */
inet_aton(ipaddr, &addr);
@ -213,13 +209,13 @@ static int m26_netdev_set_info(struct netdev *netdev)
if (at_resp_parse_line_args_by_kw(resp, "PrimaryDns:", "PrimaryDns:%s", dns_server1) <= 0 ||
at_resp_parse_line_args_by_kw(resp, "SecondaryDns:", "SecondaryDns:%s", dns_server2) <= 0)
{
LOG_E("Prase \"AT+QIDNSCFG?\" commands resposne data error!");
LOG_E("%s device prase \"AT+QIDNSCFG?\" cmd error.", device->name);
result = -RT_ERROR;
goto __exit;
}
LOG_D("m26 device(%s) primary DNS server address: %s", device->name, dns_server1);
LOG_D("m26 device(%s) secondary DNS server address: %s", device->name, dns_server2);
LOG_D("%s device primary DNS server address: %s", device->name, dns_server1);
LOG_D("%s device secondary DNS server address: %s", device->name, dns_server2);
inet_aton(dns_server1, &addr);
netdev_low_level_set_dns_server(netdev, 0, &addr);
@ -252,14 +248,14 @@ static void check_link_status_entry(void *parameter)
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get m26 deivce by netdev name failed.", netdev->name);
LOG_E("get device(%s) failed.", netdev->name);
return;
}
resp = at_create_resp(M26_LINK_RESP_SIZE, 0, M26_LINK_RESP_TIMO);
if (resp == RT_NULL)
{
LOG_E("no memory for m26 device(%s) response object.", netdev->name);
LOG_E("no memory for resp create.");
return;
}
@ -296,11 +292,7 @@ static int m26_netdev_check_link_status(struct netdev *netdev)
rt_thread_t tid;
char tname[RT_NAME_MAX] = {0};
if (netdev == RT_NULL)
{
LOG_E("input network interface device is NULL.");
return -RT_ERROR;
}
RT_ASSERT(netdev);
rt_snprintf(tname, RT_NAME_MAX, "%s_link", netdev->name);
@ -323,7 +315,7 @@ static int m26_netdev_set_up(struct netdev *netdev)
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get m26 device by netdev name(%s) failed.", netdev->name);
LOG_E("get device(%s) failed.", netdev->name);
return -RT_ERROR;
}
@ -333,7 +325,7 @@ static int m26_netdev_set_up(struct netdev *netdev)
device->is_init = RT_TRUE;
netdev_low_level_set_status(netdev, RT_TRUE);
LOG_D("the network interface device(%s) set up status.", netdev->name);
LOG_D("network interface device(%s) set up status.", netdev->name);
}
return RT_EOK;
@ -346,7 +338,7 @@ static int m26_netdev_set_down(struct netdev *netdev)
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get m26 device by netdev name(%s) failed.", netdev->name);
LOG_E("get device(%s) failed.", netdev->name);
return -RT_ERROR;
}
@ -356,7 +348,7 @@ static int m26_netdev_set_down(struct netdev *netdev)
device->is_init = RT_FALSE;
netdev_low_level_set_status(netdev, RT_FALSE);
LOG_D("the network interface device(%s) set down status.", netdev->name);
LOG_D("network interface device(%s) set down status.", netdev->name);
}
return RT_EOK;
@ -377,14 +369,14 @@ static int m26_netdev_set_dns_server(struct netdev *netdev, uint8_t dns_num, ip_
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get m26 deivce by netdev name failed.", netdev->name);
LOG_E("get device(%s) failed.", netdev->name);
return - RT_ERROR;
}
resp = at_create_resp(M26_DNS_RESP_LEN, 0, M26_DNS_RESP_TIMEO);
if (resp == RT_NULL)
{
LOG_E("no memory for m26 device(%s) response object.", netdev->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
@ -426,14 +418,14 @@ static int m26_netdev_ping(struct netdev *netdev, const char *host,
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get m26 deivce by netdev name failed.", netdev->name);
LOG_E("get device(%s) failed.", netdev->name);
return - RT_ERROR;
}
resp = at_create_resp(M26_PING_RESP_SIZE, 5, M26_PING_TIMEO);
if (resp == RT_NULL)
{
LOG_E("no memory for m26 device(%s) response object.", netdev->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
/* send "AT+QPING="<host>"[,[<timeout>][,<pingnum>]]" commond to send ping request */
@ -483,13 +475,6 @@ static int m26_netdev_ping(struct netdev *netdev, const char *host,
}
#endif /* NETDEV_USING_PING */
#ifdef NETDEV_USING_NETSTAT
static void m26_netdev_netstat(struct netdev *netdev)
{
// TODO netstat support
}
#endif /* NETDEV_USING_NETSTAT */
const struct netdev_ops m26_netdev_ops =
{
m26_netdev_set_up,
@ -502,9 +487,7 @@ const struct netdev_ops m26_netdev_ops =
#ifdef NETDEV_USING_PING
m26_netdev_ping,
#endif
#ifdef NETDEV_USING_NETSTAT
m26_netdev_netstat,
#endif
RT_NULL,
};
static struct netdev *m26_netdev_add(const char *netdev_name)
@ -518,7 +501,7 @@ static struct netdev *m26_netdev_add(const char *netdev_name)
netdev = (struct netdev *) rt_calloc(1, sizeof(struct netdev));
if (netdev == RT_NULL)
{
LOG_E("no memory for m26 device(%s) netdev structure.", netdev_name);
LOG_E("no memory for netdev ceate.");
return RT_NULL;
}
@ -568,11 +551,11 @@ static void m26_init_thread_entry(void *parameter)
resp = at_create_resp(128, 0, rt_tick_from_millisecond(300));
if (resp == RT_NULL)
{
LOG_E("no memory for m26 device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return;
}
LOG_D("start initializing the m26/mc20 device(%s)", device->name);
LOG_D("start init m26/mc20 device(%s)", device->name);
while (retry_num--)
{
@ -603,7 +586,7 @@ static void m26_init_thread_entry(void *parameter)
if (at_resp_get_line_by_kw(resp, "READY"))
{
LOG_D("m26 device(%s) SIM card detection success.", device->name);
LOG_D("%s device SIM card detection success.", device->name);
break;
}
rt_thread_mdelay(1000);
@ -623,14 +606,14 @@ static void m26_init_thread_entry(void *parameter)
at_resp_parse_line_args_by_kw(resp, "+CSQ:", "+CSQ: %s", &parsed_data);
if (rt_strncmp(parsed_data, "99,99", sizeof(parsed_data)))
{
LOG_D("m26 device(%s) signal strength: %s", device->name, parsed_data);
LOG_D("%s device signal strength: %s", device->name, parsed_data);
break;
}
rt_thread_mdelay(1000);
}
if (i == CSQ_RETRY)
{
LOG_E("m26 device(%s) signal strength check failed(%s).", device->name, parsed_data);
LOG_E("%s device signal strength check failed(%s).", device->name, parsed_data);
result = -RT_ERROR;
goto __exit;
}
@ -642,14 +625,14 @@ static void m26_init_thread_entry(void *parameter)
if (!rt_strncmp(parsed_data, "0,1", sizeof(parsed_data)) ||
!rt_strncmp(parsed_data, "0,5", sizeof(parsed_data)))
{
LOG_D("m26 device(%s) GSM network is registered(%s).", device->name, parsed_data);
LOG_D("%s device GSM is registered(%s).", device->name, parsed_data);
break;
}
rt_thread_mdelay(1000);
}
if (i == CREG_RETRY)
{
LOG_E("m26 device(%s) GSM network is register failed(%s)", device->name, parsed_data);
LOG_E("%s device GSM is register failed(%s)", device->name, parsed_data);
result = -RT_ERROR;
goto __exit;
}
@ -661,14 +644,14 @@ static void m26_init_thread_entry(void *parameter)
if (!rt_strncmp(parsed_data, "0,1", sizeof(parsed_data)) ||
!rt_strncmp(parsed_data, "0,5", sizeof(parsed_data)))
{
LOG_D("m26 device(%s) GPRS network is registered(%s).", device->name, parsed_data);
LOG_D("%s device GPRS is registered(%s).", device->name, parsed_data);
break;
}
rt_thread_mdelay(1000);
}
if (i == CGREG_RETRY)
{
LOG_E("m26 device(%s) GPRS network is register failed(%s).", device->name, parsed_data);
LOG_E("%s device GPRS is register failed(%s).", device->name, parsed_data);
result = -RT_ERROR;
goto __exit;
}
@ -700,20 +683,19 @@ static void m26_init_thread_entry(void *parameter)
AT_SEND_CMD(client, resp, 0, 20 * 1000, "AT+QIACT");
AT_SEND_CMD(client, resp, 2, 300, "AT+QILOCIP");
/* initialize successfully */
result = RT_EOK;
break;
__exit:
if (result == RT_EOK)
{
break;
}
else
if (result != RT_EOK)
{
/* power off the m26 device */
m26_power_off(device);
rt_thread_mdelay(1000);
LOG_I("m26 device(%s) initialize retry...", device->name);
LOG_I("%s device initialize retry...", device->name);
}
}
@ -727,11 +709,11 @@ static void m26_init_thread_entry(void *parameter)
m26_netdev_set_info(device->netdev);
m26_netdev_check_link_status(device->netdev);
LOG_I("m26 device(%s) network initialize successfully.", device->name);
LOG_I("%s device network initialize success.", device->name);
}
else
{
LOG_E("m26 device(%s) network initialize failed(%d).", device->name, result);
LOG_E("%s device network initialize failed(%d).", device->name, result);
}
}
@ -740,7 +722,7 @@ static int m26_net_init(struct at_device *device)
#ifdef AT_DEVICE_M26_INIT_ASYN
rt_thread_t tid;
tid = rt_thread_create("m26_net_init", m26_init_thread_entry, (void *)device,
tid = rt_thread_create("m26_net", m26_init_thread_entry, (void *)device,
M26_THREAD_STACK_SIZE, M26_THREAD_PRIORITY, 20);
if (tid)
{
@ -748,7 +730,7 @@ static int m26_net_init(struct at_device *device)
}
else
{
LOG_E("create m26 device(%s) initialization thread failed.", device->name);
LOG_E("create %s device init thread failed.", device->name);
return -RT_ERROR;
}
#else
@ -782,7 +764,7 @@ static int m26_init(struct at_device *device)
device->client = at_client_get(m26->client_name);
if (device->client == RT_NULL)
{
LOG_E("m26 device(%s) initialize failed, get AT client(%s) failed.", m26->device_name, m26->client_name);
LOG_E("get AT client(%s) failed.", m26->client_name);
return -RT_ERROR;
}
@ -797,7 +779,7 @@ static int m26_init(struct at_device *device)
device->netdev = m26_netdev_add(m26->device_name);
if (device->netdev == RT_NULL)
{
LOG_E("m26 device(%s) initialize failed, get network interface device failed.", m26->device_name);
LOG_E("get netdev(%s) failed.", m26->device_name);
return -RT_ERROR;
}
@ -837,7 +819,7 @@ static int m26_control(struct at_device *device, int cmd, void *arg)
case AT_DEVICE_CTRL_GET_SIGNAL:
case AT_DEVICE_CTRL_GET_GPS:
case AT_DEVICE_CTRL_GET_VER:
LOG_W("m26 not support the control command(%d).", cmd);
LOG_W("not support the control command(%d).", cmd);
break;
default:
LOG_E("input error control command(%d).", cmd);
@ -860,7 +842,7 @@ static int m26_device_class_register(void)
class = (struct at_device_class *) rt_calloc(1, sizeof(struct at_device_class));
if (class == RT_NULL)
{
LOG_E("no memory for m26 device class create.");
LOG_E("no memory for device class create.");
return -RT_ENOMEM;
}

View File

@ -28,7 +28,7 @@
#include <at_device_m26.h>
#define LOG_TAG "at.dev"
#define LOG_TAG "at.skt.m26"
#include <at_log.h>
#if defined(AT_DEVICE_USING_M26) && defined(AT_USING_SOCKET)
@ -91,7 +91,7 @@ static int m26_socket_close(struct at_socket *socket)
resp = at_create_resp(64, 0, rt_tick_from_millisecond(300));
if (resp == RT_NULL)
{
LOG_E("no memory for m26 device(%s) response structure.", device->name);
LOG_E("no memory for resp create.", device->name);
return -RT_ENOMEM;
}
@ -107,7 +107,7 @@ static int m26_socket_close(struct at_socket *socket)
if (m26_socket_event_recv(device, SET_EVENT(device_socke, M26_EVNET_CLOSE_OK),
rt_tick_from_millisecond(300 * 3), RT_EVENT_FLAG_AND) < 0)
{
LOG_E("m26 device(%s) socket(%d) close failed, wait close OK timeout.", device->name, device_socke);
LOG_E("%s device socket(%d) close failed, wait close OK timeout.", device->name, device_socke);
result = -RT_ETIMEOUT;
goto __exit;
}
@ -146,7 +146,7 @@ static int m26_socket_connect(struct at_socket *socket, char *ip, int32_t port,
resp = at_create_resp(128, 0, rt_tick_from_millisecond(300));
if (resp == RT_NULL)
{
LOG_E("no memory for m26 device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
@ -183,7 +183,7 @@ __retry:
break;
default:
LOG_E("m26 device(%s) not supported connect type : %d.", device->name, type);
LOG_E("%s device not supported connect type : %d.", device->name, type);
return -RT_ERROR;
}
}
@ -191,7 +191,7 @@ __retry:
/* waiting result event from AT URC, the device default connection timeout is 75 seconds, but it set to 10 seconds is convenient to use.*/
if (m26_socket_event_recv(device, SET_EVENT(device_socket, 0), 10 * RT_TICK_PER_SECOND, RT_EVENT_FLAG_OR) < 0)
{
LOG_E("m26 device(%s) socket(%d) connect failed, wait connect result timeout.", device->name, device_socket);
LOG_E("%s device socket(%d) wait connect result timeout.", device->name, device_socket);
result = -RT_ETIMEOUT;
goto __exit;
}
@ -199,7 +199,7 @@ __retry:
if ((event_result = m26_socket_event_recv(device, M26_EVENT_CONN_OK | M26_EVENT_CONN_FAIL,
1 * RT_TICK_PER_SECOND, RT_EVENT_FLAG_OR)) < 0)
{
LOG_E("m26 device(%s) socket(%d) connect failed, wait connect OK|FAIL timeout.", device->name, device_socket);
LOG_E("%s device socket(%d) wait connect OK|FAIL timeout.", device->name, device_socket);
result = -RT_ETIMEOUT;
goto __exit;
}
@ -208,7 +208,7 @@ __retry:
{
if (retryed == RT_FALSE)
{
LOG_D("m26 device(%s) socket(%d) connect failed, maybe the socket was not be closed and now will retry.",
LOG_D("%s device socket(%d) connect failed, the socket was not be closed and now will retry.",
device->name, device_socket);
if (m26_socket_close(socket) < 0)
{
@ -217,7 +217,7 @@ __retry:
retryed = RT_TRUE;
goto __retry;
}
LOG_E("m26 device(%s) socket(%d) connect failed, failed to establish a connection.", device->name, device_socket);
LOG_E("%s device socket(%d) connect failed.", device->name, device_socket);
result = -RT_ERROR;
goto __exit;
}
@ -241,7 +241,7 @@ static int at_get_send_size(struct at_socket *socket, size_t *size, size_t *acke
resp = at_create_resp(64, 0, 5 * RT_TICK_PER_SECOND);
if (resp == RT_NULL)
{
LOG_E("no memory for m26 device(%s) response structure!", device->name);
LOG_E("no memory for resp create.");
result = -RT_ENOMEM;
goto __exit;
}
@ -254,7 +254,7 @@ static int at_get_send_size(struct at_socket *socket, size_t *size, size_t *acke
if (at_resp_parse_line_args_by_kw(resp, "+QISACK:", "+QISACK: %d, %d, %d", size, acked, nacked) <= 0)
{
LOG_E("m26 device(%s) prase \"AT+QISACK\" commands resposne data error!", device->name);
LOG_E("%s device prase \"AT+QISACK\" cmd error.", device->name);
result = -RT_ERROR;
goto __exit;
}
@ -316,7 +316,7 @@ static int m26_socket_send(struct at_socket *socket, const char *buff, size_t bf
resp = at_create_resp(128, 2, 5 * RT_TICK_PER_SECOND);
if (resp == RT_NULL)
{
LOG_E("no memory for m26 device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
@ -360,7 +360,7 @@ static int m26_socket_send(struct at_socket *socket, const char *buff, size_t bf
/* waiting result event from AT URC */
if (m26_socket_event_recv(device, SET_EVENT(device_socket, 0), 15 * RT_TICK_PER_SECOND, RT_EVENT_FLAG_OR) < 0)
{
LOG_E("m26 device(%s) socket(%d) send failed, wait connect result timeout.", device->name, device_socket);
LOG_E("%s device socket(%d) wait send result timeout.", device->name, device_socket);
result = -RT_ETIMEOUT;
goto __exit;
}
@ -368,14 +368,14 @@ static int m26_socket_send(struct at_socket *socket, const char *buff, size_t bf
if ((event_result = m26_socket_event_recv(device, M26_EVENT_SEND_OK | M26_EVENT_SEND_FAIL,
1 * RT_TICK_PER_SECOND, RT_EVENT_FLAG_OR)) < 0)
{
LOG_E("m26 device(%s) socket(%d) send failed, wait connect OK|FAIL timeout.", device->name, device_socket);
LOG_E("%s device socket(%d) wait send OK|FAIL timeout.", device->name, device_socket);
result = -RT_ETIMEOUT;
goto __exit;
}
/* check result */
if (event_result & M26_EVENT_SEND_FAIL)
{
LOG_E("m26 device(%s) socket(%d) send failed.", device->name, device_socket);
LOG_E("%s device socket(%d) send failed.", device->name, device_socket);
result = -RT_ERROR;
goto __exit;
}
@ -428,7 +428,7 @@ static int m26_domain_resolve(const char *name, char ip[16])
device = at_device_get_first_initialized();
if (device == RT_NULL)
{
LOG_E("get first initialization m26 device failed.");
LOG_E("get first init device failed.");
return -RT_ERROR;
}
@ -436,7 +436,7 @@ static int m26_domain_resolve(const char *name, char ip[16])
resp = at_create_resp(128, 4, 14 * RT_TICK_PER_SECOND);
if (resp == RT_NULL)
{
LOG_E("no memory for m26 device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
@ -506,7 +506,7 @@ static void urc_connect_func(struct at_client *client, const char *data, rt_size
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_CLIENT, client_name);
if (device == RT_NULL)
{
LOG_E("get m26 device by client name(%s) failed.", client_name);
LOG_E("get device(%s) failed.", client_name);
return;
}
@ -534,7 +534,7 @@ static void urc_send_func(struct at_client *client, const char *data, rt_size_t
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_CLIENT, client_name);
if (device == RT_NULL)
{
LOG_E("get m26 device by client name(%s) failed.", client_name);
LOG_E("get device(%s) failed.", client_name);
return;
}
m26 = (struct at_device_m26 *) device->user_data;
@ -561,7 +561,7 @@ static void urc_close_func(struct at_client *client, const char *data, rt_size_t
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_CLIENT, client_name);
if (device == RT_NULL)
{
LOG_E("get m26 device by client name(%s) failed.", client_name);
LOG_E("get device(%s) failed.", client_name);
return;
}
@ -601,7 +601,7 @@ static void urc_recv_func(struct at_client *client, const char *data, rt_size_t
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_CLIENT, client_name);
if (device == RT_NULL)
{
LOG_E("get m26 device by client name(%s) failed.", client_name);
LOG_E("get device(%s) failed.", client_name);
return;
}
@ -619,7 +619,7 @@ static void urc_recv_func(struct at_client *client, const char *data, rt_size_t
recv_buf = (char *) rt_calloc(1, bfsz);
if (recv_buf == RT_NULL)
{
LOG_E("no memory for m26 device(%s) urc receive buffer (%d).", device->name, bfsz);
LOG_E("no memory for receive buffer (%d).", device->name, bfsz);
/* read and clean the coming data */
while (temp_size < bfsz)
{
@ -639,7 +639,7 @@ static void urc_recv_func(struct at_client *client, const char *data, rt_size_t
/* sync receive data */
if (at_client_obj_recv(client, recv_buf, bfsz, timeout) != bfsz)
{
LOG_E("m26 device(%s) receive size(%d) data failed.", device->name, bfsz);
LOG_E("%s device receive size(%d) data failed.", device->name, bfsz);
rt_free(recv_buf);
return;
}

View File

@ -27,7 +27,7 @@
#include <at_device_mw31.h>
#define LOG_TAG "at.dev"
#define LOG_TAG "at.dev.mw31"
#include <at_log.h>
@ -70,7 +70,7 @@ static void mw31_get_netdev_info(struct rt_work *work, void *work_data)
resp = at_create_resp(512, 0, rt_tick_from_millisecond(300));
if (resp == RT_NULL)
{
LOG_E("no memory for mw31 device(%d) response structure.", device->name);
LOG_E("no memory for resp create.");
return;
}
@ -82,20 +82,21 @@ static void mw31_get_netdev_info(struct rt_work *work, void *work_data)
if (at_resp_parse_line_args_by_kw(resp, "+WMAC:", "+WMAC:%s", mac) <= 0)
{
LOG_E("mw31 device(%s) parse \"AT+WMAC\" command response data error.", device->name);
LOG_E("%s device parse \"AT+WMAC\" cmd error.", device->name);
goto __exit;
}
/* send addr info query commond "AT+CIPSTA?" and wait response */
if (at_obj_exec_cmd(client, resp, "AT+WJAPIP?") < 0)
{
LOG_E("mw31 device(%s) send \"AT+WJAPIP?\" commands error.", device->name);
LOG_E("%s device send \"AT+WJAPIP?\" cmd error.", device->name);
goto __exit;
}
if (at_resp_parse_line_args_by_kw(resp, "+WJAPIP?:", "+WJAPIP?:%[^,],%[^,],%[^,],%s", mw31_ip_addr, mw31_netmask_addr, mw31_gw_addr, dns_server1) < 0)
if (at_resp_parse_line_args_by_kw(resp, "+WJAPIP?:", "+WJAPIP?:%[^,],%[^,],%[^,],%s",
mw31_ip_addr, mw31_netmask_addr, mw31_gw_addr, dns_server1) < 0)
{
LOG_E("mw31 device(%s) prase \"AT+WJAPIP?\" command resposne data error.", device->name);
LOG_E("%s device prase \"AT+WJAPIP?\" cmd error.", device->name);
goto __exit;
}
@ -129,7 +130,7 @@ static void mw31_get_netdev_info(struct rt_work *work, void *work_data)
/* parse response data, get the DHCP status */
if (at_resp_parse_line_args_by_kw(resp, "+WDHCP:", "+WDHCP:%s", dhcp_stat_buf) < 0)
{
LOG_E("mw31 device(%s) get DHCP status failed.", device->name);
LOG_E("%s device get DHCP status failed.", device->name);
goto __exit;
}
@ -156,7 +157,7 @@ static int mw31_netdev_set_up(struct netdev *netdev)
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get mw31 device by netdev name(%s) failed.", netdev->name);
LOG_E("get device(%s) failed.", netdev->name);
return -RT_ERROR;
}
@ -164,7 +165,7 @@ static int mw31_netdev_set_up(struct netdev *netdev)
{
mw31_net_init(device);
netdev_low_level_set_status(netdev, RT_TRUE);
LOG_D("the network interface device(%s) set up status", netdev->name);
LOG_D("network interface device(%s) set up status", netdev->name);
}
return RT_EOK;
@ -177,7 +178,7 @@ static int mw31_netdev_set_down(struct netdev *netdev)
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get mw31 device by netdev name(%s) failed.", netdev->name);
LOG_E("get device(%s) failed.", netdev->name);
return -RT_ERROR;
}
@ -185,7 +186,7 @@ static int mw31_netdev_set_down(struct netdev *netdev)
{
device->is_init = RT_FALSE;
netdev_low_level_set_status(netdev, RT_FALSE);
LOG_D("the network interface device(%s) set down status", netdev->name);
LOG_D("network interface device(%s) set down status", netdev->name);
}
return RT_EOK;
@ -203,14 +204,14 @@ static int mw31_netdev_set_addr_info(struct netdev *netdev, ip_addr_t *ip_addr,
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get mw31 device by netdev name(%s) failed.", netdev->name);
LOG_E("get device(%s) failed.", netdev->name);
return -RT_ERROR;
}
resp = at_create_resp(IPADDR_RESP_SIZE, 0, rt_tick_from_millisecond(300));
if (resp == RT_NULL)
{
LOG_E("no memory for mw31 device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
result = -RT_ENOMEM;
goto __exit;
}
@ -235,7 +236,7 @@ static int mw31_netdev_set_addr_info(struct netdev *netdev, ip_addr_t *ip_addr,
if (at_obj_exec_cmd(device->client, resp, "AT+WJAPIP=%s,%s,%s",
mw31_ip_addr, mw31_netmask_addr, mw31_gw_addr) < 0)
{
LOG_E("mw31 device(%s) set address information failed.", device->name);
LOG_E("%s device set address failed.", device->name);
result = -RT_ERROR;
}
else
@ -250,7 +251,7 @@ static int mw31_netdev_set_addr_info(struct netdev *netdev, ip_addr_t *ip_addr,
if (netmask)
netdev_low_level_set_netmask(netdev, netmask);
LOG_D("mw31 device(%s) set address information successfully.", device->name);
LOG_D("%s device set address success.", device->name);
}
__exit:
@ -276,14 +277,14 @@ static int mw31_netdev_set_dns_server(struct netdev *netdev, uint8_t dns_num, ip
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get mw31 device by netdev name(%s) failed.", netdev->name);
LOG_E("get device(%s) failed.");
return -RT_ERROR;
}
resp = at_create_resp(DNS_RESP_SIZE, 0, rt_tick_from_millisecond(300));
if (resp == RT_NULL)
{
LOG_E("no memory for mw31 device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
@ -291,13 +292,13 @@ static int mw31_netdev_set_dns_server(struct netdev *netdev, uint8_t dns_num, ip
if (at_obj_exec_cmd(device->client, resp, "AT+WJAPIP=%s,%s,%s,%s",
mw31_ip_addr, mw31_netmask_addr, mw31_gw_addr, inet_ntoa(*dns_server)) < 0)
{
LOG_E("mw31 device(%s) set DNS server(%s) failed.", device->name, inet_ntoa(*dns_server));
LOG_E("%s device set DNS(%s) failed.", device->name, inet_ntoa(*dns_server));
result = -RT_ERROR;
}
else
{
netdev_low_level_set_dns_server(netdev, dns_num, dns_server);
LOG_D("mw31 device(%s) set DNS server(%s) successfully.", device->name, inet_ntoa(*dns_server));
LOG_D("%s device set DNS(%s) success.", device->name, inet_ntoa(*dns_server));
}
if (resp)
@ -323,14 +324,14 @@ static int mw31_netdev_set_dhcp(struct netdev *netdev, rt_bool_t is_enabled)
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get AT device by netdev name(%s) failed.", netdev->name);
LOG_E("get device(%s) failed.");
return -RT_ERROR;
}
resp = at_create_resp(RESP_SIZE, 0, rt_tick_from_millisecond(300));
if (resp == RT_NULL)
{
LOG_E("no memory for mw31 device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
@ -345,14 +346,14 @@ static int mw31_netdev_set_dhcp(struct netdev *netdev, rt_bool_t is_enabled)
/* send dhcp set commond "AT+WDHCP=" and wait response */
if (at_obj_exec_cmd(device->client, resp, send_buf) < 0)
{
LOG_E("mw31 device(%s) set DHCP status(%d) failed.", device->name, is_enabled);
LOG_E("%s device set DHCP status(%d) failed.", device->name, is_enabled);
result = -RT_ERROR;
goto __exit;
}
else
{
netdev_low_level_set_dhcp_status(netdev, is_enabled);
LOG_D("mw31 device(%d) set DHCP status(%d) successfully.", device->name, is_enabled);
LOG_D("%s device set DHCP status(%d) success.", device->name, is_enabled);
}
__exit:
@ -392,7 +393,7 @@ static struct netdev *mw31_netdev_add(const char *netdev_name)
netdev = (struct netdev *) rt_calloc(1, sizeof(struct netdev));
if (netdev == RT_NULL)
{
LOG_E("no memory for mw31 device(%s) netdev structure.", netdev_name);
LOG_E("no memory for resp create.");
return RT_NULL;
}
@ -447,7 +448,7 @@ static void mw31_init_thread_entry(void *parameter)
rt_err_t result = RT_EOK;
rt_size_t i = 0, retry_num = INIT_RETRY;
LOG_D("mw31 device(%s) initialize start.", device->name);
LOG_D("%s device initialize start.", device->name);
/* wait mw31 device startup finish */
if (at_client_obj_wait_connect(client, MW31_WAIT_CONNECT_TIME))
@ -458,7 +459,7 @@ static void mw31_init_thread_entry(void *parameter)
resp = at_create_resp(128, 0, 5 * RT_TICK_PER_SECOND);
if (resp == RT_NULL)
{
LOG_E("no memory for mw31 device(%d) response structure.", device->name);
LOG_E("no memory for resp create.");
return;
}
@ -488,15 +489,15 @@ static void mw31_init_thread_entry(void *parameter)
goto __exit;
}
__exit:
if (result == RT_EOK)
{
/* initialize successfully */
result = RT_EOK;
break;
}
else
__exit:
if (result != RT_EOK)
{
rt_thread_mdelay(1000);
LOG_I("mw31 device(%s) initialize retry...", device->name);
LOG_I("%s device initialize retry...", device->name);
}
}
@ -508,7 +509,7 @@ __exit:
if (result != RT_EOK)
{
netdev_low_level_set_status(device->netdev, RT_FALSE);
LOG_E("mw31 device(%s) network initialize failed(%d).", device->name, result);
LOG_E("%s device network initialize failed(%d).", device->name, result);
}
else
{
@ -516,7 +517,7 @@ __exit:
netdev_low_level_set_status(device->netdev, RT_TRUE);
netdev_low_level_set_link_status(device->netdev, RT_TRUE);
LOG_I("mw31 device(%s) network initialize successfully.", device->name);
LOG_I("%s device network initialize successfully.", device->name);
}
}
@ -533,7 +534,7 @@ static int mw31_net_init(struct at_device *device)
}
else
{
LOG_E("create mw31 device(%s) initialize thread failed.", device->name);
LOG_E("create %s device initialize thread failed.", device->name);
return -RT_ERROR;
}
#else
@ -553,13 +554,13 @@ static void urc_func(struct at_client *client, const char *data, rt_size_t size)
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_CLIENT, client_name);
if (device == RT_NULL)
{
LOG_E("get mw31 device by client name(%s) failed.", client_name);
LOG_E("get device(%s) failed.", client_name);
return;
}
if (rt_strstr(data, "STATION_UP"))
{
LOG_I("mw31 device(%s) WIFI is connected.", device->name);
LOG_I("%s device wifi is connected.", device->name);
if (device->is_init)
{
@ -570,7 +571,7 @@ static void urc_func(struct at_client *client, const char *data, rt_size_t size)
}
else if (rt_strstr(data, "STATION_DOWN"))
{
LOG_I("mw31 device(%s) WIFI is disconnect.", device->name);
LOG_I("%s device wifi is disconnect.", device->name);
if (device->is_init)
{
@ -594,8 +595,7 @@ static int mw31_init(struct at_device *device)
device->client = at_client_get(mw31->client_name);
if (device->client == RT_NULL)
{
LOG_E("mw31 device(%s) initialize failed, get AT client(%s) failed.",
mw31->device_name, mw31->client_name);
LOG_E("get AT client(%s) failed.", mw31->client_name);
return -RT_ERROR;
}
@ -610,7 +610,7 @@ static int mw31_init(struct at_device *device)
device->netdev = mw31_netdev_add(mw31->device_name);
if (device->netdev == RT_NULL)
{
LOG_E("mw31 device(%s) initialize failed, get network interface device failed.", mw31->device_name);
LOG_E("get netdev(%s) failed.", mw31->device_name);
return -RT_ERROR;
}
@ -656,21 +656,21 @@ static int mw31_wifi_info_set(struct at_device *device, struct at_device_ssid_pw
if (info->ssid == RT_NULL || info->password == RT_NULL)
{
LOG_E("input mw31 wifi ssid(%s) and password(%s) error.", info->ssid, info->password);
LOG_E("input wifi ssid(%s) and password(%s) error.", info->ssid, info->password);
return -RT_ERROR;
}
resp = at_create_resp(128, 0, 20 * RT_TICK_PER_SECOND);
if (resp == RT_NULL)
{
LOG_E("no memory for mw31 device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
/* connect to input wifi ap */
if (at_obj_exec_cmd(device->client, resp, "AT+CWJAP=\"%s\",\"%s\"", info->ssid, info->password) != RT_EOK)
{
LOG_E("mw31 device(%s) wifi connect failed, check ssid(%s) and password(%s).",
LOG_E("wifi connect failed, check ssid(%s) and password(%s).",
device->name, info->ssid, info->password);
result = -RT_ERROR;
}
@ -701,7 +701,7 @@ static int mw31_control(struct at_device *device, int cmd, void *arg)
case AT_DEVICE_CTRL_GET_SIGNAL:
case AT_DEVICE_CTRL_GET_GPS:
case AT_DEVICE_CTRL_GET_VER:
LOG_W("mw31 not support the control command(%d).", cmd);
LOG_W("not support the control command(%d).", cmd);
break;
case AT_DEVICE_CTRL_RESET:
result = mw31_reset(device);
@ -731,7 +731,7 @@ static int mw31_device_class_register(void)
class = (struct at_device_class *) rt_calloc(1, sizeof(struct at_device_class));
if (class == RT_NULL)
{
LOG_E("no memory for mw31 device class create.");
LOG_E("no memory for device class create.");
return -RT_ENOMEM;
}

View File

@ -27,7 +27,7 @@
#include <at_device_mw31.h>
#define LOG_TAG "at.skt"
#define LOG_TAG "at.skt.mw31"
#include <at_log.h>
#if defined(AT_DEVICE_USING_MW31) && defined(AT_USING_SOCKET)
@ -72,7 +72,7 @@ static int mw31_socket_close(struct at_socket *socket)
resp = at_create_resp(64, 0, rt_tick_from_millisecond(300));
if (resp == RT_NULL)
{
LOG_E("no memory for mw31 device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
@ -127,7 +127,7 @@ static int mw31_socket_connect(struct at_socket *socket, char *ip, int32_t port,
resp = at_create_resp(128, 0, 5 * RT_TICK_PER_SECOND);
if (resp == RT_NULL)
{
LOG_E("no memory for mw31 device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
@ -154,7 +154,7 @@ __retry:
break;
default:
LOG_E("mw31 device(%s) not supported connect type %d.", device->name, type);
LOG_E("not supported connect type %d.", type);
result = -RT_ERROR;
goto __exit;
}
@ -162,7 +162,7 @@ __retry:
if (result != RT_EOK && retryed == RT_FALSE)
{
LOG_D("mw31 device(%s) socket (%d) connect failed, maybe the socket was not be closed at the last time and now will retry.",
LOG_D("%s device socket (%d) connect failed, the socket was not be closed and now will connect retry.",
device->name, device_socket);
if (mw31_socket_close(socket) < 0)
{
@ -212,7 +212,7 @@ static int mw31_socket_send(struct at_socket *socket, const char *buff, size_t b
resp = at_create_resp(128, 0, 5 * RT_TICK_PER_SECOND);
if (resp == RT_NULL)
{
LOG_E("no memory for mw31 device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
@ -292,14 +292,14 @@ static int mw31_domain_resolve(const char *name, char ip[16])
device = at_device_get_first_initialized();
if (device == RT_NULL)
{
LOG_E("get first initialization mw31 device failed.");
LOG_E("get first init device failed.");
return -RT_ERROR;
}
resp = at_create_resp(128, 0, 20 * RT_TICK_PER_SECOND);
if (resp == RT_NULL)
{
LOG_E("no memory for mw31 device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
@ -384,7 +384,7 @@ static void urc_recv_func(struct at_client *client, const char *data, rt_size_t
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_CLIENT, client_name);
if (device == RT_NULL)
{
LOG_E("get mw31 device by client name(%s) failed.", client_name);
LOG_E("get device(%s) failed.", client_name);
return;
}
@ -409,7 +409,7 @@ static void urc_recv_func(struct at_client *client, const char *data, rt_size_t
recv_buf = (char *) rt_calloc(1, bfsz);
if (recv_buf == RT_NULL)
{
LOG_E("no memory for mw31 device(%s) URC receive buffer(%d).", device->name, bfsz);
LOG_E("no memory for receive buffer(%d).", bfsz);
/* read and clean the coming data */
while (temp_size < bfsz)
{
@ -429,7 +429,7 @@ static void urc_recv_func(struct at_client *client, const char *data, rt_size_t
/* sync receive data */
if (at_client_obj_recv(client, recv_buf, bfsz, timeout) != bfsz)
{
LOG_E("mw31 device(%s) receive size(%d) data failed.", device->name, bfsz);
LOG_E("%s device receive size(%d) data failed.", device->name, bfsz);
rt_free(recv_buf);
return;
}

View File

@ -28,7 +28,7 @@
#include <at_device_rw007.h>
#define LOG_TAG "at.dev"
#define LOG_TAG "at.dev.rw007"
#include <at_log.h>
@ -108,7 +108,7 @@ static void rw007_init_thread_entry(void *parameter)
resp = at_create_resp(128, 0, 5 * RT_TICK_PER_SECOND);
if (resp == RT_NULL)
{
LOG_E("no memory for rw007 device(%d) response structure.", device->name);
LOG_E("no memory for resp create.");
return;
}
@ -133,7 +133,7 @@ static void rw007_init_thread_entry(void *parameter)
if (at_obj_exec_cmd(client, at_resp_set_info(resp, 128, 0, 20 * RT_TICK_PER_SECOND),
"AT+CWJAP=\"%s\",\"%s\"", rw007->wifi_ssid, rw007->wifi_password) != RT_EOK)
{
LOG_E("rw007 device(%s) network initialize failed, check ssid(%s) and password(%s).",
LOG_E("%s device wifi connect failed, check ssid(%s) and password(%s).",
device->name, rw007->wifi_ssid, rw007->wifi_password);
result = -RT_ERROR;
goto __exit;
@ -141,15 +141,15 @@ static void rw007_init_thread_entry(void *parameter)
AT_SEND_CMD(client, resp, "AT+CIPMUX=1");
__exit:
if (result == RT_EOK)
{
/* initialize successfully */
result = RT_EOK;
break;
}
else
__exit:
if (result != RT_EOK)
{
rt_thread_mdelay(1000);
LOG_I("rw007 device(%s) initialize retry...", device->name);
LOG_I("%s device initialize retry...", device->name);
}
}
@ -161,12 +161,12 @@ static void rw007_init_thread_entry(void *parameter)
if (result != RT_EOK)
{
netdev_low_level_set_status(device->netdev, RT_FALSE);
LOG_E("rw007 device(%s) network initialize failed(%d).", device->name, result);
LOG_E("%s device network initialize failed(%d).", device->name, result);
}
else
{
netdev_low_level_set_status(device->netdev, RT_TRUE);
LOG_I("rw007 device(%s) network initialize successfully.", device->name);
LOG_I("%s device network initialize success.", device->name);
}
}
@ -175,7 +175,7 @@ int rw007_net_init(struct at_device *device)
#ifdef AT_DEVICE_RW007_INIT_ASYN
rt_thread_t tid;
tid = rt_thread_create("rw007_net_init", rw007_init_thread_entry,
tid = rt_thread_create("rw007_net", rw007_init_thread_entry,
(void *)device, RW007_THREAD_STACK_SIZE, RW007_THREAD_PRIORITY, 20);
if (tid)
{
@ -183,7 +183,7 @@ int rw007_net_init(struct at_device *device)
}
else
{
LOG_E("create rw007 device(%s) initialization thread failed.", device->name);
LOG_E("create %s device initialization thread failed.", device->name);
return -RT_ERROR;
}
#else
@ -195,12 +195,12 @@ int rw007_net_init(struct at_device *device)
static void urc_busy_p_func(struct at_client *client, const char *data, rt_size_t size)
{
LOG_D("system is processing a commands and it cannot respond to the current commands.");
LOG_D("system is processing a commands...");
}
static void urc_busy_s_func(struct at_client *client, const char *data, rt_size_t size)
{
LOG_D("system is sending data and it cannot respond to the current commands.");
LOG_D("system is sending data...");
}
static void urc_func(struct at_client *client, const char *data, rt_size_t size)
@ -213,17 +213,17 @@ static void urc_func(struct at_client *client, const char *data, rt_size_t size)
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_CLIENT, client_name);
if (device == RT_NULL)
{
LOG_E("get rw007 device by client name(%s) failed.", client_name);
LOG_E("get device(%s) failed.", client_name);
return;
}
if (rt_strstr(data, "WIFI CONNECTED"))
{
LOG_I("rw007 device(%s) WIFI is connected.", device->name);
LOG_I("%s device wifi is connected.", device->name);
}
else if (rt_strstr(data, "WIFI DISCONNECT"))
{
LOG_I("rw007 device(%s) WIFI is disconnect.", device->name);
LOG_I("%s device wifi is disconnect.", device->name);
}
}
@ -244,8 +244,7 @@ static int rw007_init(struct at_device *device)
device->client = at_client_get(rw007->client_name);
if (device->client == RT_NULL)
{
LOG_E("rw007 device(%s) initialize failed, get AT client(%s) failed.",
rw007->device_name, rw007->client_name);
LOG_E("get AT client(%s) failed.", rw007->client_name);
return -RT_ERROR;
}
@ -260,7 +259,7 @@ static int rw007_init(struct at_device *device)
device->netdev = rw007_netdev_add(rw007->device_name);
if (device->netdev == RT_NULL)
{
LOG_E("rw007 device(%s) initialize failed, get network interface device failed.", rw007->device_name);
LOG_E("get netdev(%s) failed.", rw007->device_name);
return -RT_ERROR;
}
@ -308,21 +307,21 @@ static int rw007_wifi_info_set(struct at_device *device, struct at_device_ssid_p
if (info->ssid == RT_NULL || info->password == RT_NULL)
{
LOG_E("input rwoo7 wifi ssid(%s) and password(%s) error.", info->ssid, info->password);
LOG_E("input wifi ssid(%s) and password(%s) error.", info->ssid, info->password);
return -RT_ERROR;
}
resp = at_create_resp(128, 0, 20 * RT_TICK_PER_SECOND);
if (resp == RT_NULL)
{
LOG_E("no memory for rw007 device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
/* connect to input wifi ap */
if (at_obj_exec_cmd(device->client, resp, "AT+CWJAP=\"%s\",\"%s\"", info->ssid, info->password) != RT_EOK)
{
LOG_E("rw007 device(%s) wifi connect failed, check ssid(%s) and password(%s).",
LOG_E("%s device wifi connect failed, check ssid(%s) and password(%s).",
device->name, info->ssid, info->password);
result = -RT_ERROR;
}
@ -352,7 +351,7 @@ static int rw007_control(struct at_device *device, int cmd, void *arg)
case AT_DEVICE_CTRL_GET_SIGNAL:
case AT_DEVICE_CTRL_GET_GPS:
case AT_DEVICE_CTRL_GET_VER:
LOG_W("rw007 not support the control command(%d).", cmd);
LOG_W("not support the control command(%d).", cmd);
break;
case AT_DEVICE_CTRL_RESET:
result = rw007_reset(device);
@ -382,7 +381,7 @@ static int rw007_device_class_register(void)
class = (struct at_device_class *) rt_calloc(1, sizeof(struct at_device_class));
if (class == RT_NULL)
{
LOG_E("no memory for rw007 device class create.");
LOG_E("no memory for device class create.");
return -RT_ENOMEM;
}

View File

@ -28,7 +28,7 @@
#include <at_device_rw007.h>
#define LOG_TAG "at.skt"
#define LOG_TAG "at.skt.rw007"
#include <at_log.h>
#if defined(AT_DEVICE_USING_RW007) && defined(AT_USING_SOCKET)
@ -89,7 +89,7 @@ static int rw007_socket_close(struct at_socket *socket)
resp = at_create_resp(64, 0, RT_TICK_PER_SECOND);
if (resp == RT_NULL)
{
LOG_E("no memory for rw007 device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
@ -131,7 +131,7 @@ static int rw007_socket_connect(struct at_socket *socket, char *ip, int32_t port
resp = at_create_resp(128, 0, 5 * RT_TICK_PER_SECOND);
if (resp == RT_NULL)
{
LOG_E("no memory for rw007 device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
@ -158,7 +158,7 @@ __retry:
break;
default:
LOG_E("rw007 device(%s) not supported connect type %d.", device->name, type);
LOG_E("not supported connect type %d.", type);
result = -RT_ERROR;
goto __exit;
}
@ -166,7 +166,7 @@ __retry:
if (result != RT_EOK && retryed == RT_FALSE)
{
LOG_D("rw007 device(%s) socket (%d) connect failed, maybe the socket was not be closed at the last time and now will retry.",
LOG_D("%s device socket(%d) connect failed, the socket was not be closed and now will connect retry.",
device->name, socket);
if (rw007_socket_close(socket) < 0)
{
@ -216,7 +216,7 @@ static int rw007_socket_send(struct at_socket *socket, const char *buff, size_t
resp = at_create_resp(128, 2, 5 * RT_TICK_PER_SECOND);
if (resp == RT_NULL)
{
LOG_E("no memory for rw007 device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
@ -257,7 +257,7 @@ static int rw007_socket_send(struct at_socket *socket, const char *buff, size_t
/* waiting result event from AT URC */
if (rw007_socket_event_recv(device, SET_EVENT(device_socket, 0), 10 * RT_TICK_PER_SECOND, RT_EVENT_FLAG_OR) < 0)
{
LOG_E("rw007 device(%s) socket (%d) send failed, wait connect result timeout.", device->name, device_socket);
LOG_E("%s device socket(%d) wait send result timeout.", device->name, device_socket);
result = -RT_ETIMEOUT;
goto __exit;
}
@ -266,14 +266,14 @@ static int rw007_socket_send(struct at_socket *socket, const char *buff, size_t
5 * RT_TICK_PER_SECOND, RT_EVENT_FLAG_OR);
if (event_result < 0)
{
LOG_E("rw007 device(%s) socket (%d) send failed, wait connect OK|FAIL timeout.", device->name, device_socket);
LOG_E("%s device socket(%d) wait send OK|FAIL timeout.", device->name, device_socket);
result = -RT_ETIMEOUT;
goto __exit;
}
/* check result */
if (event_result & RW007_EVENT_SEND_FAIL)
{
LOG_E("rw007 device(%s) socket (%d) send failed.", device->name, device_socket);
LOG_E("%s device socket(%d) send failed.", device->name, device_socket);
result = -RT_ERROR;
goto __exit;
}
@ -320,14 +320,14 @@ static int rw007_domain_resolve(const char *name, char ip[16])
device = at_device_get_first_initialized();
if (device == RT_NULL)
{
LOG_E("get first initialization rw007 device failed.");
LOG_E("get first init device failed.");
return -RT_ERROR;
}
resp = at_create_resp(128, 0, 20 * RT_TICK_PER_SECOND);
if (resp == RT_NULL)
{
LOG_E("no memory for rw007 device response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
@ -406,7 +406,7 @@ static void urc_send_func(struct at_client *client, const char *data, rt_size_t
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_CLIENT, client_name);
if (device == RT_NULL)
{
LOG_E("get rw007 device by client name(%s) failed.", client_name);
LOG_E("get device(%s) failed.", client_name);
return;
}
rw007 = (struct at_device_rw007 *) device->user_data;
@ -443,7 +443,7 @@ static void urc_close_func(struct at_client *client, const char *data, rt_size_t
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_CLIENT, client_name);
if (device == RT_NULL)
{
LOG_E("get rw007 device by client name(%s) failed.", client_name);
LOG_E("get device(%s) failed.", client_name);
return;
}
@ -473,7 +473,7 @@ static void urc_recv_func(struct at_client *client, const char *data, rt_size_t
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_CLIENT, client_name);
if (device == RT_NULL)
{
LOG_E("get rw007 device by client name(%s) failed.", client_name);
LOG_E("get device(%s) failed.", client_name);
return;
}
@ -490,7 +490,7 @@ static void urc_recv_func(struct at_client *client, const char *data, rt_size_t
recv_buf = (char *) rt_calloc(1, bfsz);
if (recv_buf == RT_NULL)
{
LOG_E("no memory for rw007 device(%s) URC receive buffer (%d).", device->name, bfsz);
LOG_E("no memory for receive buffer (%d).", bfsz);
/* read and clean the coming data */
while (temp_size < bfsz)
{
@ -510,7 +510,7 @@ static void urc_recv_func(struct at_client *client, const char *data, rt_size_t
/* sync receive data */
if (at_client_obj_recv(client, recv_buf, bfsz, timeout) != bfsz)
{
LOG_E("rw007 device(%s) receive size(%d) data failed.", device->name, bfsz);
LOG_E("%s device receive size(%d) data failed.", device->name, bfsz);
rt_free(recv_buf);
return;
}

View File

@ -31,7 +31,7 @@
#include <at_device_sim76xx.h>
#define LOG_TAG "at.dev"
#define LOG_TAG "at.dev.sim76"
#include <at_log.h>
#ifdef AT_DEVICE_USING_SIM76XX
@ -107,16 +107,12 @@ static int sim76xx_netdev_set_info(struct netdev *netdev)
at_response_t resp = RT_NULL;
struct at_device *device = RT_NULL;
if (netdev == RT_NULL)
{
LOG_E("input network interface device is NULL.");
return -RT_ERROR;
}
RT_ASSERT(netdev);
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get sim76xx device by netdev name(%s) failed.", netdev->name);
LOG_E("get device(%s) failed.", netdev->name);
return -RT_ERROR;
}
@ -128,7 +124,7 @@ static int sim76xx_netdev_set_info(struct netdev *netdev)
resp = at_create_resp(SIM76XX_IEMI_RESP_SIZE, 0, SIM76XX_INFO_RESP_TIMO);
if (resp == RT_NULL)
{
LOG_E("sim76xx device(%s) set IP address failed, no memory for response object.", device->name);
LOG_E("no memory for resp create.");
result = -RT_ENOMEM;
goto __exit;
}
@ -150,12 +146,12 @@ static int sim76xx_netdev_set_info(struct netdev *netdev)
if (at_resp_parse_line_args_by_kw(resp, "IMEI:", "IMEI: %s", iemi) <= 0)
{
LOG_E("sim76xx device(%s) prase \"ATI\" commands resposne data error.", device->name);
LOG_E("%s device prase \"ATI\" cmd error.", device->name);
result = -RT_ERROR;
goto __exit;
}
LOG_D("sim76xx device(%s) IEMI number: %s", device->name, iemi);
LOG_D("%s device IEMI number: %s", device->name, iemi);
netdev->hwaddr_len = SIM76XX_NETDEV_HWADDR_LEN;
/* get hardware address by IEMI */
@ -188,12 +184,12 @@ static int sim76xx_netdev_set_info(struct netdev *netdev)
if (at_resp_parse_line_args_by_kw(resp, "+IPADDR:", "+IPADDR: %s", ipaddr) <= 0)
{
LOG_E("sim76xx device(%s) prase \"AT+IPADDR\" commands resposne data error!", device->name);
LOG_E("%s device prase \"AT+IPADDR\" cmd error!", device->name);
result = -RT_ERROR;
goto __exit;
}
LOG_D("sim76xx device(%s) IP address: %s", device->name, ipaddr);
LOG_D("%s device IP address: %s", device->name, ipaddr);
/* set network interface address information */
inet_aton(ipaddr, &addr);
@ -236,14 +232,14 @@ static void check_link_status_entry(void *parameter)
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get sim76xx device by netdev name(%s) failed.", netdev->name);
LOG_E("get device(%s) failed.", netdev->name);
return;
}
resp = at_create_resp(SIM76XX_LINK_RESP_SIZE, 0, SIM76XX_LINK_RESP_TIMO);
if (resp == RT_NULL)
{
LOG_E("sim76xx device(%s) set check link status failed, no memory for response object.", device->name);
LOG_E("no memory for resp create.");
return;
}
@ -279,11 +275,7 @@ static int sim76xx_netdev_check_link_status(struct netdev *netdev)
rt_thread_t tid;
char tname[RT_NAME_MAX] = {0};
if (netdev == RT_NULL)
{
LOG_E("input network interface device is NULL.\n");
return -RT_ERROR;
}
RT_ASSERT(netdev);
rt_snprintf(tname, RT_NAME_MAX, "%s_link", netdev->name);
@ -307,7 +299,7 @@ static int sim76xx_netdev_set_up(struct netdev *netdev)
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get sim76xx device by netdev name(%s) failed.", netdev->name);
LOG_E("get device(%s) failed.", netdev->name);
return -RT_ERROR;
}
@ -317,7 +309,7 @@ static int sim76xx_netdev_set_up(struct netdev *netdev)
device->is_init = RT_TRUE;
netdev_low_level_set_status(netdev, RT_TRUE);
LOG_D("the network intterface device(%s) set up status.", netdev->name);
LOG_D("network intterface device(%s) set up status.", netdev->name);
}
return RT_EOK;
@ -331,7 +323,7 @@ static int sim76xx_netdev_set_down(struct netdev *netdev)
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get sim76xx device by netdev name(%s) failed.", netdev->name);
LOG_E("get device(%s) failed.", netdev->name);
return -RT_ERROR;
}
@ -341,7 +333,7 @@ static int sim76xx_netdev_set_down(struct netdev *netdev)
device->is_init = RT_FALSE;
netdev_low_level_set_status(netdev, RT_FALSE);
LOG_D("the network interface device(%s) set down status.", netdev->name);
LOG_D("network interface device(%s) set down status.", netdev->name);
}
return RT_EOK;
@ -369,14 +361,14 @@ static int sim76xx_netdev_ping(struct netdev *netdev, const char *host,
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get sim76xx device by netdev name(%s) failed.", netdev->name);
LOG_E("get device(%s) failed.", netdev->name);
return -RT_ERROR;
}
resp = at_create_resp(SIM76XX_PING_RESP_SIZE, 6, SIM76XX_PING_TIMEO);
if (resp == RT_NULL)
{
LOG_E("sim76xx device(%s) set dns server failed, no memory for response object.", device->name);
LOG_E("no memory for resp create.");
result = -RT_ERROR;
goto __exit;
}
@ -447,7 +439,7 @@ static struct netdev *sim76xx_netdev_add(const char *netdev_name)
netdev = (struct netdev *)rt_calloc(1, sizeof(struct netdev));
if (netdev == RT_NULL)
{
LOG_E("no memory for sim76xx device(%s) netdev structure.", netdev_name);
LOG_E("no memory for netdev create.");
return RT_NULL;
}
@ -500,11 +492,11 @@ static void sim76xx_init_thread_entry(void *parameter)
resp = at_create_resp(128, 0, rt_tick_from_millisecond(300));
if (resp == RT_NULL)
{
LOG_E("no memory for sim76xx device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return;
}
LOG_D("start initializing the sim76xx device(%s).", device->name);
LOG_D("start init %s device.", device->name);
while (retry_num--)
{
@ -537,7 +529,7 @@ static void sim76xx_init_thread_entry(void *parameter)
at_obj_exec_cmd(client, resp, "AT+CPIN?");
if (at_resp_get_line_by_kw(resp, "READY"))
{
LOG_D("sim76xx device(%s) SIM card detection failed.", device->name);
LOG_D("%s device SIM card detection failed.", device->name);
break;
}
LOG_I("\"AT+CPIN\" commands send retry...");
@ -559,7 +551,7 @@ static void sim76xx_init_thread_entry(void *parameter)
at_resp_parse_line_args_by_kw(resp, "+CSQ:", "+CSQ: %d,%d", &qi_arg[0], &qi_arg[1]);
if (qi_arg[0] != 99)
{
LOG_D("sim76xx device(%s) signal strength: %d Channel bit error rate: %d", device->name, qi_arg[0], qi_arg[1]);
LOG_D("%s device signal strength: %d Channel bit error rate: %d", device->name, qi_arg[0], qi_arg[1]);
break;
}
rt_thread_mdelay(1000);
@ -567,7 +559,7 @@ static void sim76xx_init_thread_entry(void *parameter)
if (i == CSQ_RETRY)
{
LOG_E("sim76xx device(%s) signal strength check failed (%s).", device->name, parsed_data);
LOG_E("%s device signal strength check failed (%s).", device->name, parsed_data);
result = -RT_ERROR;
goto __exit;
}
@ -582,14 +574,14 @@ static void sim76xx_init_thread_entry(void *parameter)
at_resp_parse_line_args_by_kw(resp, "+CREG:", "+CREG: %s", &parsed_data);
if (!strncmp(parsed_data, "0,1", sizeof(parsed_data)) || !strncmp(parsed_data, "0,5", sizeof(parsed_data)))
{
LOG_D("sim76xx device(%s) GSM network is registered(%s).", device->name, parsed_data);
LOG_D("%s device GSM is registered(%s).", device->name, parsed_data);
break;
}
rt_thread_mdelay(1000);
}
if (i == CREG_RETRY)
{
LOG_E("sim76xx device(%s) GSM network is register failed(%s).", device->name, parsed_data);
LOG_E("%s device GSM is register failed(%s).", device->name, parsed_data);
result = -RT_ERROR;
goto __exit;
}
@ -601,7 +593,7 @@ static void sim76xx_init_thread_entry(void *parameter)
at_resp_parse_line_args_by_kw(resp, "+CGREG:", "+CGREG: %s", &parsed_data);
if (!strncmp(parsed_data, "0,1", sizeof(parsed_data)) || !strncmp(parsed_data, "0,5", sizeof(parsed_data)))
{
LOG_D("sim76xx device(%s) GPRS network is registered(%s).", device->name, parsed_data);
LOG_D("%s device GPRS is registered(%s).", device->name, parsed_data);
break;
}
rt_thread_mdelay(1000);
@ -609,7 +601,7 @@ static void sim76xx_init_thread_entry(void *parameter)
if (i == CGREG_RETRY)
{
LOG_E("sim76xx device(%s) GPRS network is register failed(%s).", device->name, parsed_data);
LOG_E("%s device GPRS is register failed(%s).", device->name, parsed_data);
result = -RT_ERROR;
goto __exit;
}
@ -621,7 +613,7 @@ static void sim76xx_init_thread_entry(void *parameter)
at_resp_parse_line_args_by_kw(resp, "+CGATT:", "+CGATT: %s", &parsed_data);
if (!strncmp(parsed_data, "1", 1))
{
LOG_D("sim76xx device(%s) Packet domain attach.", device->name);
LOG_D("%s device Packet domain attach.", device->name);
break;
}
@ -630,7 +622,7 @@ static void sim76xx_init_thread_entry(void *parameter)
if (i == CGATT_RETRY)
{
LOG_E("sim76xx device(%s) GPRS network attach failed.", device->name);
LOG_E("%s device GPRS attach failed.", device->name);
result = -RT_ERROR;
goto __exit;
}
@ -667,7 +659,8 @@ static void sim76xx_init_thread_entry(void *parameter)
}
/* +CCLK: "18/12/22,18:33:12+32" */
if (at_resp_parse_line_args_by_kw(resp, "+CCLK:", "+CCLK: \"%d/%d/%d,%d:%d:%d", &year, &month, &day, &hour, &min, &sec) < 0)
if (at_resp_parse_line_args_by_kw(resp, "+CCLK:", "+CCLK: \"%d/%d/%d,%d:%d:%d",
&year, &month, &day, &hour, &min, &sec) < 0)
{
rt_thread_mdelay(500);
continue;
@ -681,7 +674,7 @@ static void sim76xx_init_thread_entry(void *parameter)
if (i == CCLK_RETRY)
{
LOG_E("sim76xx device(%s) GPRS network attach failed.", device->name);
LOG_E("%s device GPRS attach failed.", device->name);
result = -RT_ERROR;
goto __exit;
}
@ -698,7 +691,7 @@ static void sim76xx_init_thread_entry(void *parameter)
sim76xx_power_off(device);
rt_thread_mdelay(1000);
LOG_I("sim76xx device(%s) initialize retry...", device->name);
LOG_I("%s device initialize retry...", device->name);
}
}
@ -713,11 +706,11 @@ static void sim76xx_init_thread_entry(void *parameter)
sim76xx_netdev_set_info(device->netdev);
sim76xx_netdev_check_link_status(device->netdev);
LOG_I("sim76xx devuce(%s) network initialize success!", device->name);
LOG_I("%s device network initialize success!", device->name);
}
else
{
LOG_E("sim76xx device(%s) network initialize failed(%d)!", device->name, result);
LOG_E("%s device network initialize failed(%d)!", device->name, result);
}
}
@ -726,7 +719,7 @@ int sim76xx_net_init(struct at_device *device)
#ifdef AT_DEVICE_SIM76XX_INIT_ASYN
rt_thread_t tid;
tid = rt_thread_create("sim76xx_net_init", sim76xx_init_thread_entry, (void *)device,
tid = rt_thread_create("sim76_net", sim76xx_init_thread_entry, (void *)device,
SIM76XX_THREAD_STACK_SIZE, SIM76XX_THREAD_PRIORITY, 20);
if (tid)
{
@ -734,7 +727,7 @@ int sim76xx_net_init(struct at_device *device)
}
else
{
LOG_E("create sim76xx device(%s) initialization thread failed.", device->name);
LOG_E("create %s device init thread failed.", device->name);
return -RT_ERROR;
}
#else
@ -760,7 +753,7 @@ static int sim76xx_init(struct at_device *device)
device->client = at_client_get(sim76xx->client_name);
if (device->client == RT_NULL)
{
LOG_E("sim76xx device(%s) initialize failed, get AT client(%s) failed.", sim76xx->device_name, sim76xx->client_name);
LOG_E("get AT client(%s) failed.", sim76xx->client_name);
return -RT_ERROR;
}
@ -772,7 +765,7 @@ static int sim76xx_init(struct at_device *device)
device->netdev = sim76xx_netdev_add(sim76xx->device_name);
if (device->netdev == RT_NULL)
{
LOG_E("sim76xx device(%s) initialize failed, get network interface device failed.", sim76xx->device_name);
LOG_E("get netdev(%s) failed.", sim76xx->device_name);
return -RT_ERROR;
}
@ -814,7 +807,7 @@ static int sim76xx_control(struct at_device *device, int cmd, void *arg)
case AT_DEVICE_CTRL_GET_SIGNAL:
case AT_DEVICE_CTRL_GET_GPS:
case AT_DEVICE_CTRL_GET_VER:
LOG_W("sim76xx not support the control command(%d).", cmd);
LOG_W("not support the control command(%d).", cmd);
break;
default:
LOG_E("input error control command(%d).", cmd);
@ -839,7 +832,7 @@ static int sim76xx_device_class_register(void)
class = (struct at_device_class *)rt_calloc(1, sizeof(struct at_device_class));
if (class == RT_NULL)
{
LOG_E("no memory for sim76xx device class create.");
LOG_E("no memory for device class create.");
return -RT_ENOMEM;
}

View File

@ -31,7 +31,7 @@
#include <at_device_sim76xx.h>
#define LOG_TAG "at.skt"
#define LOG_TAG "at.skt.sim76"
#include <at_log.h>
#ifdef AT_DEVICE_USING_SIM76XX
@ -121,7 +121,7 @@ static int sim76xx_socket_close(struct at_socket *socket)
resp = at_create_resp(64, 0, RT_TICK_PER_SECOND);
if (resp == RT_NULL)
{
LOG_E("no memory for sim76xx device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
@ -212,7 +212,7 @@ static int sim76xx_socket_connect(struct at_socket *socket, char *ip, int32_t po
resp = at_create_resp(128, 0, 5 * RT_TICK_PER_SECOND);
if (resp == RT_NULL)
{
LOG_E("no memory for sim76xx device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
@ -244,7 +244,7 @@ __retry:
break;
default:
LOG_E("Not supported connect type : %d.", type);
LOG_E("not supported connect type : %d.", type);
result = -RT_ERROR;
goto __exit;
}
@ -253,7 +253,7 @@ __retry:
/* waiting result event from AT URC, the device default connection timeout is 75 seconds, but it set to 10 seconds is convenient to use.*/
if (sim76xx_socket_event_recv(device, SET_EVENT(device_socket, 0), 10 * RT_TICK_PER_SECOND, RT_EVENT_FLAG_OR) < 0)
{
LOG_E("sim76xx device(%s) socket(%d) connect failed, wait connect result timeout.", device->name, device_socket);
LOG_E("%s device socket(%d) wait connect result timeout.", device->name, device_socket);
result = -RT_ETIMEOUT;
goto __exit;
}
@ -262,7 +262,7 @@ __retry:
1 * RT_TICK_PER_SECOND, RT_EVENT_FLAG_OR);
if (event_result < 0)
{
LOG_E("sim76xx device(%s) socket(%d) connect failed, wait connect OK|FAIL timeout.", device->name, device_socket);
LOG_E("%s device socket(%d) wait connect OK|FAIL timeout.", device->name, device_socket);
result = -RT_ETIMEOUT;
goto __exit;
}
@ -271,7 +271,7 @@ __retry:
{
if (retryed == RT_FALSE)
{
LOG_D("socket (%d) connect failed, maybe the socket was not be closed at the last time and now will retry.", device_socket);
LOG_D("socket(%d) connect failed, the socket was not be closed and now will connect retry.", device_socket);
if (sim76xx_socket_close(socket) < 0)
{
result = -RT_ERROR;
@ -280,7 +280,7 @@ __retry:
retryed = RT_TRUE;
goto __retry;
}
LOG_E("socket (%d) connect failed, failed to establish a connection.", device_socket);
LOG_E("%s device socket(%d) connect failed.", device->name, device_socket);
result = -RT_ERROR;
goto __exit;
}
@ -326,7 +326,7 @@ static int sim76xx_socket_send(struct at_socket *socket, const char *buff, size_
resp = at_create_resp(128, 2, 5 * RT_TICK_PER_SECOND);
if (resp == RT_NULL)
{
LOG_E("no memory for sim76xx device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
@ -383,7 +383,7 @@ static int sim76xx_socket_send(struct at_socket *socket, const char *buff, size_
/* waiting result event from AT URC */
if (sim76xx_socket_event_recv(device, SET_EVENT(device_socket, 0), 5 * RT_TICK_PER_SECOND, RT_EVENT_FLAG_OR) < 0)
{
LOG_E("sim76xx device(%s) socket (%d) send failed, wait connect result timeout.", device->name, device_socket);
LOG_E("%s device socket (%d) wait send result timeout.", device->name, device_socket);
result = -RT_ETIMEOUT;
goto __exit;
}
@ -392,14 +392,14 @@ static int sim76xx_socket_send(struct at_socket *socket, const char *buff, size_
5 * RT_TICK_PER_SECOND, RT_EVENT_FLAG_OR);
if (event_result < 0)
{
LOG_E("sim76xx device(%s) socket(%d) send failed, wait connect OK|FAIL timeout.", device->name, device_socket);
LOG_E("%s device socket(%d) wait send OK|FAIL timeout.", device->name, device_socket);
result = -RT_ETIMEOUT;
goto __exit;
}
/* check result */
if (event_result & SIM76XX_EVENT_SEND_FAIL)
{
LOG_E("sim76xx device(%s) socket(%d) send failed.", device->name, device_socket);
LOG_E("%s device socket(%d) send failed.", device->name, device_socket);
result = -RT_ERROR;
goto __exit;
}
@ -447,14 +447,14 @@ static int sim76xx_domain_resolve(const char *name, char ip[16])
device = at_device_get_first_initialized();
if (device == RT_NULL)
{
LOG_E("get first initialized sim76xx device failed.");
LOG_E("get first init device failed.");
return -RT_ERROR;
}
resp = at_create_resp(128, 0, 5 * RT_TICK_PER_SECOND);
if (resp == RT_NULL)
{
LOG_E("no memory for sim76xx device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
@ -528,7 +528,7 @@ static void urc_send_func(struct at_client *client, const char *data, rt_size_t
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_CLIENT, client_name);
if (device == RT_NULL)
{
LOG_E("get sim76xx device by client name(%s) failed.", client_name);
LOG_E("get device(%s) failed.");
return;
}
@ -547,7 +547,7 @@ static void urc_connect_func(struct at_client *client, const char *data, rt_size
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_CLIENT, client_name);
if (device == RT_NULL)
{
LOG_E("get sim76xx device by client name(%s) failed.", client_name);
LOG_E("get device(%s) failed.", client_name);
return;
}
@ -576,7 +576,7 @@ static void urc_close_func(struct at_client *client, const char *data, rt_size_t
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_CLIENT, client_name);
if (device == RT_NULL)
{
LOG_E("get sim76xx device by client name(%s) failed.", device->name);
LOG_E("get device(%s) failed.", device->name);
return;
}
@ -607,7 +607,7 @@ static void urc_recv_func(struct at_client *client, const char *data, rt_size_t
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_CLIENT, client_name);
if (device == RT_NULL)
{
LOG_E("get sim76xx device by client name(%s) failed.", client_name);
LOG_E("get device(%s) failed.", client_name);
return;
}
sim76xx = (struct at_device_sim76xx *) device->user_data;
@ -624,7 +624,7 @@ static void urc_recv_func(struct at_client *client, const char *data, rt_size_t
recv_buf = (char *) rt_calloc(1, bfsz);
if (recv_buf == RT_NULL)
{
LOG_E("no memory for sim76xx device(%s) URC receive buffer(%d).", device->name, bfsz);
LOG_E("no memory for receive buffer(%d).", bfsz);
/* read and clean the coming data */
while (temp_size < bfsz)
{
@ -646,7 +646,7 @@ static void urc_recv_func(struct at_client *client, const char *data, rt_size_t
/* sync receive data */
if (at_client_obj_recv(client, recv_buf, bfsz, timeout) != bfsz)
{
LOG_E("sim76xx device(%s) receive size(%d) data failed.", device->name, bfsz);
LOG_E("%s device receive size(%d) data failed.", device->name, bfsz);
rt_free(recv_buf);
return;
}

View File

@ -29,7 +29,7 @@
#include <at_device_sim800c.h>
#define LOG_TAG "at.dev"
#define LOG_TAG "at.dev.sim800"
#include <at_log.h>
#ifdef AT_DEVICE_USING_SIM800C
@ -108,16 +108,12 @@ static int sim800c_netdev_set_info(struct netdev *netdev)
at_response_t resp = RT_NULL;
struct at_device *device = RT_NULL;
if (netdev == RT_NULL)
{
LOG_E("input network interface device is NULL.");
return -RT_ERROR;
}
RT_ASSERT(netdev);
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get sim800c device by netdev name(%s) failed.", netdev->name);
LOG_E("get device(%s) failed.");
return -RT_ERROR;
}
@ -129,7 +125,7 @@ static int sim800c_netdev_set_info(struct netdev *netdev)
resp = at_create_resp(SIM800C_IEMI_RESP_SIZE, 0, SIM800C_INFO_RESP_TIMO);
if (resp == RT_NULL)
{
LOG_E("sim800c device(%s) set IP address failed, no memory for response object.", device->name);
LOG_E("no memory for resp create.");
result = -RT_ENOMEM;
goto __exit;
}
@ -151,12 +147,12 @@ static int sim800c_netdev_set_info(struct netdev *netdev)
if (at_resp_parse_line_args(resp, 2, "%s", iemi) <= 0)
{
LOG_E("sim800c device(%s) prase \"AT+GSN\" commands resposne data error.", device->name);
LOG_E("%s device prase \"AT+GSN\" cmd error.", device->name);
result = -RT_ERROR;
goto __exit;
}
LOG_D("sim800c device(%s) IEMI number: %s", device->name, iemi);
LOG_D("%s device IEMI number: %s", device->name, iemi);
netdev->hwaddr_len = SIM800C_NETDEV_HWADDR_LEN;
/* get hardware address by IEMI */
@ -189,12 +185,12 @@ static int sim800c_netdev_set_info(struct netdev *netdev)
if (at_resp_parse_line_args_by_kw(resp, ".", "%s", ipaddr) <= 0)
{
LOG_E("sim800c device(%s) prase \"AT+CIFSR\" commands resposne data error!", device->name);
LOG_E("%s device prase \"AT+CIFSR\" cmd error.", device->name);
result = -RT_ERROR;
goto __exit;
}
LOG_D("sim800c device(%s) IP address: %s", device->name, ipaddr);
LOG_D("%s device IP address: %s", device->name, ipaddr);
/* set network interface address information */
inet_aton(ipaddr, &addr);
@ -218,13 +214,13 @@ static int sim800c_netdev_set_info(struct netdev *netdev)
if (at_resp_parse_line_args_by_kw(resp, "PrimaryDns:", "PrimaryDns:%s", dns_server1) <= 0 ||
at_resp_parse_line_args_by_kw(resp, "SecondaryDns:", "SecondaryDns:%s", dns_server2) <= 0)
{
LOG_E("Prase \"AT+CDNSCFG?\" commands resposne data error!");
LOG_E("%s device prase \"AT+CDNSCFG?\" cmd error.", device->name);
result = -RT_ERROR;
goto __exit;
}
LOG_D("sim800c device(%s) primary DNS server address: %s", device->name, dns_server1);
LOG_D("sim800c device(%s) secondary DNS server address: %s", device->name, dns_server2);
LOG_D("%s device primary DNS server address: %s", device->name, dns_server1);
LOG_D("%s device secondary DNS server address: %s", device->name, dns_server2);
inet_aton(dns_server1, &addr);
netdev_low_level_set_dns_server(netdev, 0, &addr);
@ -257,14 +253,14 @@ static void check_link_status_entry(void *parameter)
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get sim800c device by netdev name(%s) failed.", netdev->name);
LOG_E("get device(%s) failed.", netdev->name);
return;
}
resp = at_create_resp(SIM800C_LINK_RESP_SIZE, 0, SIM800C_LINK_RESP_TIMO);
if (resp == RT_NULL)
{
LOG_E("sim800c device(%s) set check link status failed, no memory for response object.", device->name);
LOG_E("no memory for resp create.");
return;
}
@ -300,11 +296,7 @@ static int sim800c_netdev_check_link_status(struct netdev *netdev)
rt_thread_t tid;
char tname[RT_NAME_MAX] = {0};
if (netdev == RT_NULL)
{
LOG_E("input network interface device is NULL.\n");
return -RT_ERROR;
}
RT_ASSERT(netdev);
rt_snprintf(tname, RT_NAME_MAX, "%s_link", netdev->name);
@ -327,7 +319,7 @@ static int sim800c_netdev_set_up(struct netdev *netdev)
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get sim800c device by netdev name(%s) failed.", netdev->name);
LOG_E("get device(%s) failed.", netdev->name);
return -RT_ERROR;
}
@ -337,7 +329,7 @@ static int sim800c_netdev_set_up(struct netdev *netdev)
device->is_init = RT_TRUE;
netdev_low_level_set_status(netdev, RT_TRUE);
LOG_D("the network interface device(%s) set up status.", netdev->name);
LOG_D("network interface device(%s) set up status.", netdev->name);
}
return RT_EOK;
@ -350,7 +342,7 @@ static int sim800c_netdev_set_down(struct netdev *netdev)
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get sim800c device by netdev name(%s) failed.", netdev->name);
LOG_E("get device(%s) failed.", netdev->name);
return -RT_ERROR;
}
@ -360,7 +352,7 @@ static int sim800c_netdev_set_down(struct netdev *netdev)
device->is_init = RT_FALSE;
netdev_low_level_set_status(netdev, RT_FALSE);
LOG_D("the network interface device(%s) set down status.", netdev->name);
LOG_D("network interface device(%s) set down status.", netdev->name);
}
return RT_EOK;
@ -381,14 +373,14 @@ static int sim800c_netdev_set_dns_server(struct netdev *netdev, uint8_t dns_num,
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get sim800c device by netdev name(%s) failed.", netdev->name);
LOG_E("get device(%s) failed.", netdev->name);
return -RT_ERROR;
}
resp = at_create_resp(SIM800C_DNS_RESP_LEN, 0, SIM800C_DNS_RESP_TIMEO);
if (resp == RT_NULL)
{
LOG_D("sim800c set dns server failed, no memory for response object.");
LOG_D("no memory for resp create.");
result = -RT_ENOMEM;
goto __exit;
}
@ -421,7 +413,7 @@ static int sim800c_ping_domain_resolve(struct at_device *device, const char *nam
resp = at_create_resp(128, 4, 14 * RT_TICK_PER_SECOND);
if (resp == RT_NULL)
{
LOG_E("no memory for sim800c device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
@ -482,7 +474,7 @@ static int sim800c_netdev_ping(struct netdev *netdev, const char *host,
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_NETDEV, netdev->name);
if (device == RT_NULL)
{
LOG_E("get sim800c device by netdev name(%s) failed.", netdev->name);
LOG_E("get device(%s) failed.", netdev->name);
return -RT_ERROR;
}
@ -501,7 +493,7 @@ static int sim800c_netdev_ping(struct netdev *netdev, const char *host,
resp = at_create_resp(SIM800C_PING_RESP_SIZE, 0, SIM800C_PING_TIMEO);
if (resp == RT_NULL)
{
LOG_E("sim800c device(%s) set dns server failed, no memory for response object.", device->name);
LOG_E("no memory for resp create.");
result = -RT_ERROR;
goto __exit;
}
@ -555,13 +547,6 @@ static int sim800c_netdev_ping(struct netdev *netdev, const char *host,
}
#endif /* NETDEV_USING_PING */
#ifdef NETDEV_USING_NETSTAT
void sim800c_netdev_netstat(struct netdev *netdev)
{
// TODO netstat support
}
#endif /* NETDEV_USING_NETSTAT */
const struct netdev_ops sim800c_netdev_ops =
{
sim800c_netdev_set_up,
@ -574,9 +559,7 @@ const struct netdev_ops sim800c_netdev_ops =
#ifdef NETDEV_USING_PING
sim800c_netdev_ping,
#endif
#ifdef NETDEV_USING_NETSTAT
sim800c_netdev_netstat,
#endif
RT_NULL,
};
static struct netdev *sim800c_netdev_add(const char *netdev_name)
@ -589,7 +572,7 @@ static struct netdev *sim800c_netdev_add(const char *netdev_name)
netdev = (struct netdev *) rt_calloc(1, sizeof(struct netdev));
if (netdev == RT_NULL)
{
LOG_E("no memory for sim800c device(%s) netdev structure.", netdev_name);
LOG_E("no memory for netdev create.");
return RT_NULL;
}
@ -638,11 +621,11 @@ static void sim800c_init_thread_entry(void *parameter)
resp = at_create_resp(128, 0, rt_tick_from_millisecond(300));
if (resp == RT_NULL)
{
LOG_E("no memory for sim800c device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return;
}
LOG_D("start initializing the sim800c device(%s)", device->name);
LOG_D("start init %s device", device->name);
while (retry_num--)
{
@ -674,14 +657,14 @@ static void sim800c_init_thread_entry(void *parameter)
if (at_resp_get_line_by_kw(resp, "READY"))
{
LOG_D("sim800c device(%s) SIM card detection success.", device->name);
LOG_D("%s device SIM card detection success.", device->name);
break;
}
rt_thread_mdelay(1000);
}
if (i == CPIN_RETRY)
{
LOG_E("sim800c device(%s) SIM card detection failed.", device->name);
LOG_E("%s device SIM card detection failed.", device->name);
result = -RT_ERROR;
goto __exit;
}
@ -696,14 +679,14 @@ static void sim800c_init_thread_entry(void *parameter)
if (!strncmp(parsed_data, "0,1", sizeof(parsed_data)) ||
!strncmp(parsed_data, "0,5", sizeof(parsed_data)))
{
LOG_D("sim800c device(%s) GSM network is registered(%s),", device->name, parsed_data);
LOG_D("%s device GSM is registered(%s),", device->name, parsed_data);
break;
}
rt_thread_mdelay(1000);
}
if (i == CREG_RETRY)
{
LOG_E("sim800c device(%s) GSM network is register failed(%s).", device->name, parsed_data);
LOG_E("%s device GSM is register failed(%s).", device->name, parsed_data);
result = -RT_ERROR;
goto __exit;
}
@ -715,14 +698,14 @@ static void sim800c_init_thread_entry(void *parameter)
if (!strncmp(parsed_data, "0,1", sizeof(parsed_data)) ||
!strncmp(parsed_data, "0,5", sizeof(parsed_data)))
{
LOG_D("sim800c device(%s) GPRS network is registered(%s).", device->name, parsed_data);
LOG_D("%s device GPRS is registered(%s).", device->name, parsed_data);
break;
}
rt_thread_mdelay(1000);
}
if (i == CGREG_RETRY)
{
LOG_E("sim800c device(%s) GPRS network is register failed(%s).", device->name, parsed_data);
LOG_E("%s device GPRS is register failed(%s).", device->name, parsed_data);
result = -RT_ERROR;
goto __exit;
}
@ -734,14 +717,14 @@ static void sim800c_init_thread_entry(void *parameter)
at_resp_parse_line_args_by_kw(resp, "+CSQ:", "+CSQ: %s", &parsed_data);
if (strncmp(parsed_data, "99,99", sizeof(parsed_data)))
{
LOG_D("sim800c device(%s) signal strength: %s", device->name, parsed_data);
LOG_D("%s device signal strength: %s", device->name, parsed_data);
break;
}
rt_thread_mdelay(1000);
}
if (i == CSQ_RETRY)
{
LOG_E("sim800c device(%s) signal strength check failed (%s)", device->name, parsed_data);
LOG_E("%s device signal strength check failed (%s)", device->name, parsed_data);
result = -RT_ERROR;
goto __exit;
}
@ -762,20 +745,20 @@ static void sim800c_init_thread_entry(void *parameter)
if (rt_strcmp(parsed_data, "CHINA MOBILE") == 0)
{
/* "CMCC" */
LOG_I("sim800c device(%s) network operator: %s", device->name, parsed_data);
LOG_I("%s device network operator: %s", device->name, parsed_data);
AT_SEND_CMD(client, resp, 0, 300, CSTT_CHINA_MOBILE);
}
else if (rt_strcmp(parsed_data, "CHN-UNICOM") == 0)
{
/* "UNICOM" */
LOG_I("sim800c device(%s) network operator: %s", device->name, parsed_data);
LOG_I("%s device network operator: %s", device->name, parsed_data);
AT_SEND_CMD(client, resp, 0, 300, CSTT_CHINA_UNICOM);
}
else if (rt_strcmp(parsed_data, "CHN-CT") == 0)
{
AT_SEND_CMD(client, resp, 0, 300, CSTT_CHINA_TELECOM);
/* "CT" */
LOG_I("sim800c device(%s) network operator: %s", device->name, parsed_data);
LOG_I("%s device network operator: %s", device->name, parsed_data);
}
/* the device default response timeout is 150 seconds, but it set to 20 seconds is convenient to use. */
@ -784,24 +767,23 @@ static void sim800c_init_thread_entry(void *parameter)
AT_SEND_CMD(client, resp, 2, 300, "AT+CIFSR");
if (at_resp_get_line_by_kw(resp, "ERROR") != RT_NULL)
{
LOG_E("sim800c device(%s) get the local address failed.", device->name);
LOG_E("%s device get the local address failed.", device->name);
result = -RT_ERROR;
goto __exit;
}
/* initialize successfully */
result = RT_EOK;
break;
__exit:
if (result == RT_EOK)
{
break;
}
else
if (result != RT_EOK)
{
/* power off the sim800c device */
sim800c_power_off(device);
rt_thread_mdelay(1000);
LOG_I("sim800c device(%s) initialize retry...", device->name);
LOG_I("%s device initialize retry...", device->name);
}
}
@ -816,12 +798,12 @@ static void sim800c_init_thread_entry(void *parameter)
sim800c_netdev_set_info(device->netdev);
sim800c_netdev_check_link_status(device->netdev);
LOG_I("sim800c device(%s) network initialize success!", device->name);
LOG_I("%s device network initialize success!", device->name);
}
else
{
LOG_E("sim800c device(%s) network initialize failed(%d)!", device->name, result);
LOG_E("%s device network initialize failed(%d)!", device->name, result);
}
}
@ -830,7 +812,7 @@ static int sim800c_net_init(struct at_device *device)
#ifdef AT_DEVICE_SIM800C_INIT_ASYN
rt_thread_t tid;
tid = rt_thread_create("sim800c_net_init", sim800c_init_thread_entry, (void *)device,
tid = rt_thread_create("sim800c_net", sim800c_init_thread_entry, (void *)device,
SIM800C_THREAD_STACK_SIZE, SIM800C_THREAD_PRIORITY, 20);
if (tid)
{
@ -838,7 +820,7 @@ static int sim800c_net_init(struct at_device *device)
}
else
{
LOG_E("create sim800c device(%s) initialization thread failed.", device->name);
LOG_E("create %s device init thread failed.", device->name);
return -RT_ERROR;
}
#else
@ -871,7 +853,7 @@ static int sim800c_init(struct at_device *device)
device->client = at_client_get(sim800c->client_name);
if (device->client == RT_NULL)
{
LOG_E("sim800c device(%s) initialize failed, get AT client(%s) failed.", sim800c->device_name, sim800c->client_name);
LOG_E("get AT client(%s) failed.", sim800c->client_name);
return -RT_ERROR;
}
@ -886,7 +868,7 @@ static int sim800c_init(struct at_device *device)
device->netdev = sim800c_netdev_add(sim800c->device_name);
if (device->netdev == RT_NULL)
{
LOG_E("sim800c device(%s) initialize failed, get network interface device failed.", sim800c->device_name);
LOG_E("get netdev(%s) failed.", sim800c->device_name);
return -RT_ERROR;
}
@ -926,7 +908,7 @@ static int sim800c_control(struct at_device *device, int cmd, void *arg)
case AT_DEVICE_CTRL_GET_SIGNAL:
case AT_DEVICE_CTRL_GET_GPS:
case AT_DEVICE_CTRL_GET_VER:
LOG_W("sim800c not support the control command(%d).", cmd);
LOG_W("not support the control command(%d).", cmd);
break;
default:
LOG_E("input error control command(%d).", cmd);
@ -950,7 +932,7 @@ static int sim800c_device_class_register(void)
class = (struct at_device_class *) rt_calloc(1, sizeof(struct at_device_class));
if (class == RT_NULL)
{
LOG_E("no memory for sim800c device class create.");
LOG_E("no memory for device class create.");
return -RT_ENOMEM;
}

View File

@ -28,7 +28,7 @@
#include <at_device_sim800c.h>
#define LOG_TAG "at.skt"
#define LOG_TAG "at.skt.sim800"
#include <at_log.h>
#if defined(AT_DEVICE_USING_SIM800C) && defined(AT_USING_SOCKET)
@ -91,7 +91,7 @@ static int sim800c_socket_close(struct at_socket *socket)
resp = at_create_resp(64, 0, rt_tick_from_millisecond(300));
if (resp == RT_NULL)
{
LOG_E("no memory for sim800c device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
@ -107,7 +107,7 @@ static int sim800c_socket_close(struct at_socket *socket)
if (sim800c_socket_event_recv(device, event, rt_tick_from_millisecond(300*3), RT_EVENT_FLAG_AND) < 0)
{
LOG_E("sim800c device(%s) socket(%d) close failed, wait close OK timeout.", device->name, device_socket);
LOG_E("%s device socket(%d) wait close OK timeout.", device->name, device_socket);
result = -RT_ETIMEOUT;
goto __exit;
}
@ -151,7 +151,7 @@ static int sim800c_socket_connect(struct at_socket *socket, char *ip, int32_t po
resp = at_create_resp(128, 0, 5 * RT_TICK_PER_SECOND);
if (resp == RT_NULL)
{
LOG_E("no memory for sim800c device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
@ -185,7 +185,7 @@ __retry:
break;
default:
LOG_E("sim800c device(%s) not supported connect type : %d.", device->name, type);
LOG_E("%s device not supported connect type : %d.", device->name, type);
result = -RT_ERROR;
goto __exit;
}
@ -194,7 +194,7 @@ __retry:
/* waiting result event from AT URC, the device default connection timeout is 75 seconds, but it set to 10 seconds is convenient to use */
if (sim800c_socket_event_recv(device, SET_EVENT(device_socket, 0), 10 * RT_TICK_PER_SECOND, RT_EVENT_FLAG_OR) < 0)
{
LOG_E("sim800c device(%s) socket(%d) connect failed, wait connect result timeout.",device->name, device_socket);
LOG_E("%s device socket(%d) wait connect result timeout.", device->name, device_socket);
result = -RT_ETIMEOUT;
goto __exit;
}
@ -203,7 +203,7 @@ __retry:
SIM800C_EVENT_CONN_OK | SIM800C_EVENT_CONN_FAIL, 1 * RT_TICK_PER_SECOND, RT_EVENT_FLAG_OR);
if (event_result < 0)
{
LOG_E("sim800c device(%s) socket(%d) connect failed, wait connect OK|FAIL timeout.", device->name, device_socket);
LOG_E("%s device socket(%d) wait connect OK|FAIL timeout.", device->name, device_socket);
result = -RT_ETIMEOUT;
goto __exit;
}
@ -212,7 +212,7 @@ __retry:
{
if (retryed == RT_FALSE)
{
LOG_D("sim800c device(%s) socket(%d) connect failed, maybe the socket was not be closed at the last time and now will retry.",
LOG_D("%s device socket(%d) connect failed, the socket was not be closedand now will connect retry.",
device->name, device_socket);
if (sim800c_socket_close(socket) < 0)
{
@ -222,7 +222,7 @@ __retry:
retryed = RT_TRUE;
goto __retry;
}
LOG_E("sim800c device(%s) socket(%d) connect failed.", device->name, device_socket);
LOG_E("%s device socket(%d) connect failed.", device->name, device_socket);
result = -RT_ERROR;
goto __exit;
}
@ -264,7 +264,7 @@ static int sim800c_socket_send(struct at_socket *socket, const char *buff, size_
resp = at_create_resp(128, 2, 5 * RT_TICK_PER_SECOND);
if (resp == RT_NULL)
{
LOG_E("no memory for sim800c device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
@ -306,7 +306,7 @@ static int sim800c_socket_send(struct at_socket *socket, const char *buff, size_
/* waiting result event from AT URC */
if (sim800c_socket_event_recv(device, SET_EVENT(device_socket, 0), 15 * RT_TICK_PER_SECOND, RT_EVENT_FLAG_OR) < 0)
{
LOG_E("sim800c device(%s) socket(%d) send failed, wait connect result timeout.", device->name, device_socket);
LOG_E("%s device socket(%d) wait send result timeout.", device->name, device_socket);
result = -RT_ETIMEOUT;
goto __exit;
}
@ -315,14 +315,14 @@ static int sim800c_socket_send(struct at_socket *socket, const char *buff, size_
SIM800C_EVENT_SEND_OK | SIM800C_EVENT_SEND_FAIL, 5 * RT_TICK_PER_SECOND, RT_EVENT_FLAG_OR);
if (event_result < 0)
{
LOG_E("simm800c device(%s) socket(%d) send failed, wait connect OK|FAIL timeout.", device->name, device_socket);
LOG_E("%s device socket(%d) wait send connect OK|FAIL timeout.", device->name, device_socket);
result = -RT_ETIMEOUT;
goto __exit;
}
/* check result */
if (event_result & SIM800C_EVENT_SEND_FAIL)
{
LOG_E("simm800c device(%s) socket(%d) send failed.",device->name, device_socket);
LOG_E("%s device socket(%d) send failed.", device->name, device_socket);
result = -RT_ERROR;
goto __exit;
}
@ -370,7 +370,7 @@ static int sim800c_domain_resolve(const char *name, char ip[16])
device = at_device_get_first_initialized();
if (device == RT_NULL)
{
LOG_E("get first initialization sim800c device failed.");
LOG_E("get first init device failed.");
return -RT_ERROR;
}
@ -378,7 +378,7 @@ static int sim800c_domain_resolve(const char *name, char ip[16])
resp = at_create_resp(128, 4, 14 * RT_TICK_PER_SECOND);
if (resp == RT_NULL)
{
LOG_E("no memory for sim800c device(%s) response structure.", device->name);
LOG_E("no memory for resp create.");
return -RT_ENOMEM;
}
@ -461,7 +461,7 @@ static void urc_connect_func(struct at_client *client, const char *data, rt_size
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_CLIENT, client_name);
if (device == RT_NULL)
{
LOG_E("get sim800c device by client name(%s) failed.", client_name);
LOG_E("get device(%s) failed.", client_name);
return;
}
@ -489,7 +489,7 @@ static void urc_send_func(struct at_client *client, const char *data, rt_size_t
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_CLIENT, client_name);
if (device == RT_NULL)
{
LOG_E("get sim800c device by client name(%s) failed.", client_name);
LOG_E("get device(%s) failed.", client_name);
return;
}
@ -517,7 +517,7 @@ static void urc_close_func(struct at_client *client, const char *data, rt_size_t
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_CLIENT, client_name);
if (device == RT_NULL)
{
LOG_E("get sim800c device by client name(%s) failed.", client_name);
LOG_E("get device(%s) failed.", client_name);
return;
}
@ -568,14 +568,14 @@ static void urc_recv_func(struct at_client *client, const char *data, rt_size_t
device = at_device_get_by_name(AT_DEVICE_NAMETYPE_CLIENT, client_name);
if (device == RT_NULL)
{
LOG_E("get m26 device by client name(%s) failed.", client_name);
LOG_E("get device(%s) failed.", client_name);
return;
}
recv_buf = (char *) rt_calloc(1, bfsz);
if (recv_buf == RT_NULL)
{
LOG_E("no memory for sim800c device(%s) URC receive buffer (%d).", device->name, bfsz);
LOG_E("no memory for receive buffer(%d).", bfsz);
/* read and clean the coming data */
while (temp_size < bfsz)
{
@ -595,7 +595,7 @@ static void urc_recv_func(struct at_client *client, const char *data, rt_size_t
/* sync receive data */
if (at_client_obj_recv(client, recv_buf, bfsz, timeout) != bfsz)
{
LOG_E("sim800c device(%s) receive size(%d) data failed.", device->name, bfsz);
LOG_E("%s device receive size(%d) data failed.", device->name, bfsz);
rt_free(recv_buf);
return;
}

View File

@ -24,7 +24,7 @@
#include <at_device_ec20.h>
#define LOG_TAG "at.sample"
#define LOG_TAG "at.sample.ec20"
#include <at_log.h>
#define EC20_SAMPLE_DEIVCE_NAME "e0"

View File

@ -24,7 +24,7 @@
#include <at_device_esp8266.h>
#define LOG_TAG "at.sample"
#define LOG_TAG "at.sample.esp"
#include <at_log.h>
#define ESP8266_SAMPLE_DEIVCE_NAME "esp0"

View File

@ -24,7 +24,7 @@
#include <at_device_m26.h>
#define LOG_TAG "at.sample"
#define LOG_TAG "at.sample.m26"
#include <at_log.h>
#define M26_SAMPLE_DEIVCE_NAME "m0"

View File

@ -24,7 +24,7 @@
#include <at_device_mw31.h>
#define LOG_TAG "at.sample"
#define LOG_TAG "at.sample.mw31"
#include <at_log.h>
#define MW31_SAMPLE_DEIVCE_NAME "mw0"

View File

@ -24,7 +24,7 @@
#include <at_device_rw007.h>
#define LOG_TAG "at.sample"
#define LOG_TAG "at.sample.rw007"
#include <at_log.h>
#define RW007_SAMPLE_DEIVCE_NAME "r0"

View File

@ -24,7 +24,7 @@
#include <at_device_sim76xx.h>
#define LOG_TAG "at.sample"
#define LOG_TAG "at.sample.sim76"
#include <at_log.h>
#define SIM76XX_SAMPLE_DEIVCE_NAME "sim1"

View File

@ -24,7 +24,7 @@
#include <at_device_sim800c.h>
#define LOG_TAG "at.sample"
#define LOG_TAG "at.sample.sim800"
#include <at_log.h>
#define SIM800C_SAMPLE_DEIVCE_NAME "sim0"

View File

@ -32,9 +32,9 @@
#include <rtdbg.h>
/* The global list of at device */
static struct at_device *at_device_list = RT_NULL;
static rt_slist_t at_device_list = RT_SLIST_OBJECT_INIT(at_device_list);
/* The global list of at device class */
static struct at_device_class *at_device_class_list = RT_NULL;
static rt_slist_t at_device_class_list = RT_SLIST_OBJECT_INIT(at_device_class_list);
/**
* This function will get the first initialized AT device.
@ -49,7 +49,7 @@ struct at_device *at_device_get_first_initialized(void)
level = rt_hw_interrupt_disable();
for (node = &(at_device_list->list); node; node = rt_slist_next(node))
rt_slist_for_each(node, &at_device_list)
{
device = rt_slist_entry(node, struct at_device, list);
if (device && device->is_init == RT_TRUE)
@ -82,7 +82,7 @@ struct at_device *at_device_get_by_name(int type, const char *name)
level = rt_hw_interrupt_disable();
for (node = &(at_device_list->list); node; node = rt_slist_next(node))
rt_slist_for_each(node, &at_device_list)
{
device = rt_slist_entry(node, struct at_device, list);
if (device)
@ -124,7 +124,7 @@ struct at_device *at_device_get_by_ipaddr(ip_addr_t *ip_addr)
level = rt_hw_interrupt_disable();
for (node = &(at_device_list->list); node; node = rt_slist_next(node))
rt_slist_for_each(node, &at_device_list)
{
device = rt_slist_entry(node, struct at_device, list);
if (device && ip_addr_cmp(ip_addr, &(device->netdev->ip_addr)))
@ -188,15 +188,7 @@ int at_device_class_register(struct at_device_class *class, uint16_t class_id)
level = rt_hw_interrupt_disable();
/* Add current AT device class to list */
if (at_device_class_list == RT_NULL)
{
at_device_class_list = class;
}
else
{
/* Tail insertion */
rt_slist_append(&(at_device_class_list->list), &(class->list));
}
rt_slist_append(&at_device_class_list, &(class->list));
rt_hw_interrupt_enable(level);
@ -210,15 +202,10 @@ static struct at_device_class *at_device_class_get(uint16_t class_id)
rt_slist_t *node = RT_NULL;
struct at_device_class *class = RT_NULL;
if (at_device_class_list == RT_NULL)
{
return RT_NULL;
}
level = rt_hw_interrupt_disable();
/* Get AT device class by class ID */
for (node = (&at_device_class_list->list); node; node = rt_slist_next(node))
rt_slist_for_each(node, &at_device_class_list)
{
class = rt_slist_entry(node, struct at_device_class, list);
if (class && class->class_id == class_id)
@ -297,15 +284,7 @@ int at_device_register(struct at_device *device, const char *device_name,
level = rt_hw_interrupt_disable();
/* Add current AT device to device list */
if (at_device_list == RT_NULL)
{
at_device_list = device;
}
else
{
/* Tail insertion */
rt_slist_append(&(at_device_list->list), &(device->list));
}
rt_slist_append(&at_device_list, &(device->list));
rt_hw_interrupt_enable(level);