From 6809ce8467941cbfdf16e41bdf3e84273c2057cb Mon Sep 17 00:00:00 2001 From: Liu Kai Date: Mon, 10 May 2021 23:57:20 +0800 Subject: [PATCH] add multi-line parse support for at_agent and 4g adapter framework --- applications/Makefile | 6 +- .../connection_demo/4g_demo/4g_demo.c | 145 ++++++++ applications/connection_demo/4g_demo/Makefile | 3 + applications/framework_init.c | 5 + board/aiit-arm32-board/Kconfig | 5 + framework/connection/Adapter/4g/Makefile | 4 + .../connection/Adapter/4g/xs_adapter_at_4g.c | 348 ++++++++++++++++++ .../Adapter/4g/xs_adapter_at_4g_register.c | 53 +++ framework/connection/Adapter/Makefile | 6 +- .../Adapter/include/xs_adapter_at_4g.h | 34 ++ .../Adapter/include/xs_adapter_at_agent.h | 4 +- .../Adapter/include/xs_adapter_def.h | 2 +- .../Adapter/src/xs_adapter_at_agent.c | 14 +- 13 files changed, 614 insertions(+), 15 deletions(-) create mode 100644 applications/connection_demo/4g_demo/4g_demo.c create mode 100644 applications/connection_demo/4g_demo/Makefile create mode 100644 framework/connection/Adapter/4g/Makefile create mode 100644 framework/connection/Adapter/4g/xs_adapter_at_4g.c create mode 100644 framework/connection/Adapter/4g/xs_adapter_at_4g_register.c create mode 100644 framework/connection/Adapter/include/xs_adapter_at_4g.h diff --git a/applications/Makefile b/applications/Makefile index 22d87b219..77e0247eb 100644 --- a/applications/Makefile +++ b/applications/Makefile @@ -45,9 +45,9 @@ ifeq ($(CONFIG_CONNECTION_COMMUNICATION_NB_IOT), y) SRC_DIR += connection_demo/nbiot_demo endif -# ifeq ($(CONFIG_CONNECTION_COMMUNICATION_4G), y) -# SRC_DIR += connection_demo/4G_demo -# endif +ifeq ($(CONFIG_CONNECTION_COMMUNICATION_4G), y) + SRC_DIR += connection_demo/4g_demo +endif ifeq ($(CONFIG_APPLICATION_SENSOR),y) SRC_DIR += sensor_app diff --git a/applications/connection_demo/4g_demo/4g_demo.c b/applications/connection_demo/4g_demo/4g_demo.c new file mode 100644 index 000000000..f70ef37e1 --- /dev/null +++ b/applications/connection_demo/4g_demo/4g_demo.c @@ -0,0 +1,145 @@ +#include +#include +#include +#include + +void send_cellular_4g_msg(int argc, char *argv[]) +{ + char cellular_4g_msg[128]; + if (argc >= 1) + { + memset(cellular_4g_msg, 0, 128); + strncpy(cellular_4g_msg, argv[1], strlen(argv[1])); + printf("send_4G_msg(%s).\n", cellular_4g_msg); + } + + struct AdapterAT *at_adapter = ATAdapterFind(CELLULAR_4G_ADAPTER_ID); + if (!at_adapter) + { + printf("ATAdapterFind failed .\n"); + } + at_adapter->parent.done.NetAiitOpen(&at_adapter->parent); + + at_adapter->parent.done.NetAiitSend(&at_adapter->parent, cellular_4g_msg, strlen(cellular_4g_msg), true, 1000, 0, NULL, NULL, NULL); +} + +void recv_cellular_4g_msg() +{ + char cellular_4g_recv_msg[128]; + memset(cellular_4g_recv_msg, 0, sizeof(cellular_4g_recv_msg)); + struct AdapterAT *at_adapter = ATAdapterFind(CELLULAR_4G_ADAPTER_ID); + if (!at_adapter) + { + printf("ATAdapterFind failed .\n"); + } + + at_adapter->parent.done.NetAiitOpen(&at_adapter->parent); + + while (1) + { + if (EOK == at_adapter->parent.done.NetAiitReceive(&at_adapter->parent, cellular_4g_recv_msg, 128, 40000, true, NULL)) + { + printf("4G_recv_msg (%s)\n", cellular_4g_recv_msg); + } + else + { + printf("4G_recv_msg failed .\n"); + } + } +} + +void ping_cellular_4g() +{ + char cellular_4g_recv_msg[128]; + memset(cellular_4g_recv_msg, 0, sizeof(cellular_4g_recv_msg)); + + struct AdapterAT *at_adapter = ATAdapterFind(CELLULAR_4G_ADAPTER_ID); + if (!at_adapter) + { + printf("ATAdapterFind failed .\n"); + } + + printf("Waiting for msg...\n"); + struct PingResult result; + char *ip_str = "www.baidu.com"; + + at_adapter->parent.done.NetAiitOpen(&at_adapter->parent); + + at_adapter->atdone.ATPing(at_adapter, ip_str, &result); + +} + +void dns_cellular_4g() +{ + char cellular_4g_recv_msg[128]; + memset(cellular_4g_recv_msg, 0, sizeof(cellular_4g_recv_msg)); + + struct AdapterAT *at_adapter = ATAdapterFind(CELLULAR_4G_ADAPTER_ID); + if (!at_adapter) + { + printf("ATAdapterFind failed .\n"); + } + + printf("Waiting for msg...\n"); + + struct AddressIpv4 dns_addr; + memset(&dns_addr, 0, sizeof(dns_addr)); + dns_addr.ipv4 = IpTint("2.2.2.2"); + + at_adapter->parent.done.NetAiitOpen(&at_adapter->parent); + + at_adapter->atdone.ATOperateDns(at_adapter, &dns_addr, 0); + +} + +void set_up_cellular_4g() +{ + char cellular_4g_recv_msg[128]; + memset(cellular_4g_recv_msg, 0, sizeof(cellular_4g_recv_msg)); + + struct AdapterAT* at_adapter = ATAdapterFind(CELLULAR_4G_ADAPTER_ID); + if(!at_adapter) + { + printf("ATAdapterFind failed .\n"); + } + + printf("Waiting for msg...\n"); + struct PingResult result; + + at_adapter->parent.done.NetAiitOpen(&at_adapter->parent); + + if(EOK == at_adapter->atdone.ATOperateUp(at_adapter)) + { + printf("4G_set_up success (%s)\n", result.ip_addr.ipv4); + } + else + { + printf("4G_set_up failed \n"); + } +} + +void at_test_cmd_cellular_4g(int argc, char *argv[]) +{ + char cmd[64]; + int line_num; + if (argc >= 1) + { + memset(cmd, 0, sizeof(cmd)); + strncpy(cmd, argv[1], strlen(argv[1])); + line_num = argv[2][0]='0'; + printf("AT cmd send(%s).\n", cmd); + } + + strcat(cmd,"\r"); + struct AdapterAT* at_adapter = ATAdapterFind(CELLULAR_4G_ADAPTER_ID); + at_adapter->parent.done.NetAiitOpen(&at_adapter->parent); + + printf("Waiting for msg...\n"); + + ATReplyType resp = NONE; + resp = CreateATReply(64); + + ATOrderSend(at_adapter->agent, REPLY_TIME_OUT, resp, line_num, cmd); + MdelayKTask(2500); + +} diff --git a/applications/connection_demo/4g_demo/Makefile b/applications/connection_demo/4g_demo/Makefile new file mode 100644 index 000000000..fc90b8f80 --- /dev/null +++ b/applications/connection_demo/4g_demo/Makefile @@ -0,0 +1,3 @@ +SRC_FILES :=4g_demo.c + +include $(KERNEL_ROOT)/compiler.mk diff --git a/applications/framework_init.c b/applications/framework_init.c index 80b530926..c5c484214 100644 --- a/applications/framework_init.c +++ b/applications/framework_init.c @@ -16,6 +16,7 @@ extern int SensorFrameworkInit(void); extern int RegisterAdapterEthernet(void); extern int RegisterAdapterWifi(void); +extern int RegisterAdaptercellular_4g(void); extern int RegisterAdapterZigbee(void); extern int RegisterAdapterNBIoT(void); extern int LoraSx12xxSpiDeviceInit(); @@ -94,6 +95,10 @@ static struct InitDesc connection_desc[] = { "wifi adpter", RegisterAdapterWifi }, #endif +#ifdef CONNECTION_COMMUNICATION_4G + { "4g adpter", RegisterAdaptercellular_4g }, +#endif + #ifdef CONNECTION_COMMUNICATION_LORA { "lora adpter", LoraSx12xxSpiDeviceInit}, #endif diff --git a/board/aiit-arm32-board/Kconfig b/board/aiit-arm32-board/Kconfig index 5ded0a288..fe1a9d028 100644 --- a/board/aiit-arm32-board/Kconfig +++ b/board/aiit-arm32-board/Kconfig @@ -49,6 +49,11 @@ menu "aiit-arm32-board feature" string "lora spi name" default "/dev/spi2_lora" endif + if CONNECTION_COMMUNICATION_4G + config cellular_4g_UART_NAME + string "4g uart name" + default "/dev/usart2_dev2" + endif endmenu endmenu diff --git a/framework/connection/Adapter/4g/Makefile b/framework/connection/Adapter/4g/Makefile new file mode 100644 index 000000000..34b0f3b62 --- /dev/null +++ b/framework/connection/Adapter/4g/Makefile @@ -0,0 +1,4 @@ +SRC_FILES := xs_adapter_at_4g.c \ + xs_adapter_at_4g_register.c + +include $(KERNEL_ROOT)/compiler.mk diff --git a/framework/connection/Adapter/4g/xs_adapter_at_4g.c b/framework/connection/Adapter/4g/xs_adapter_at_4g.c new file mode 100644 index 000000000..520f1f352 --- /dev/null +++ b/framework/connection/Adapter/4g/xs_adapter_at_4g.c @@ -0,0 +1,348 @@ +#include +#include +#include +#include +#include +#include +#include + + +int cellular_4g_set_down(struct AdapterAT *adapterAT); +void cellular_4g_close(struct Adapter *padapter) +{ + cellular_4g_set_down((struct AdapterAT *)padapter); +} + +int cellular_4g_open(struct Adapter *padapter) +{ + uint32 result; + char *agent_name = "uart2_client"; + const char *device_name = cellular_4g_UART_NAME; + + struct SerialDataCfg data_cfg; + data_cfg.serial_baud_rate = BAUD_RATE_115200; + data_cfg.serial_data_bits = DATA_BITS_8; + data_cfg.serial_stop_bits = STOP_BITS_1; + data_cfg.serial_parity_mode = PARITY_NONE; + data_cfg.serial_bit_order = BIT_ORDER_LSB; + data_cfg.serial_invert_mode = NRZ_NORMAL; + data_cfg.serial_buffer_size = 128; + + struct SerialCfgParam pserial_cfg; + memset(&pserial_cfg, 0, sizeof(struct SerialCfgParam)); + pserial_cfg.data_cfg = data_cfg; + + if (InitATAgent(agent_name, device_name, 512, &pserial_cfg)) { + printf("at_client_init failed ! \n"); + result = -ERROR; + return result; + } + + ATAgentType at_agent = GetATAgent(agent_name); + if (NULL == at_agent) + { + printf("GetATAgent failed ! \n"); + return -ERROR; + } + UserTaskDelay(5000); + struct AdapterAT *cellular_4g_at_adapter = (struct AdapterAT *)padapter; + cellular_4g_at_adapter->agent = at_agent; +} + +int cellular_4g_send(struct Adapter *padapter, const char *data, int len, bool block, int time_out, int delay, send_success cb, void *param, void* p) +{ + struct AdapterAT *cellular_4g_at_adapter = (struct AdapterAT *)padapter; + + if (cellular_4g_at_adapter->agent) + { + EntmSend(cellular_4g_at_adapter->agent, data, len); + } +} + +int cellular_4g_receive(struct Adapter *padapter, char *rev_buffer, int buffer_len, int time_out, bool block, void* p) +{ + printf("4G receive waiting ... \n"); + + struct AdapterAT *cellular_4g_at_adapter = (struct AdapterAT *)padapter; + if (cellular_4g_at_adapter->agent) + { + return EntmRecv(cellular_4g_at_adapter->agent, rev_buffer, buffer_len, 40000); + } + else + { + printf("Can not find agent \n"); + } +} + +void cellular_4g_power_on() +{ + + static BusType cellular_4g_pin; + + struct PinParam pin_cfg; + struct PinStat pin_stat; + + struct BusConfigureInfo configure_info; + configure_info.configure_cmd = OPE_CFG; + configure_info.private_data = (void *)&pin_cfg; + + struct BusBlockWriteParam write_param; + write_param.buffer = (void *)&pin_stat; + + cellular_4g_pin = PinBusInitGet(); + + pin_cfg.cmd = GPIO_CONFIG_MODE; + pin_cfg.pin = cellular_4g_PWR_KWY; + pin_cfg.mode = GPIO_CFG_OUTPUT; + BusDrvConfigure(cellular_4g_pin->owner_driver, &configure_info); + + pin_stat.val = GPIO_HIGH; + pin_stat.pin = cellular_4g_PWR_KWY; + BusDevWriteData(cellular_4g_pin->owner_haldev,&write_param); + + UserTaskDelay(1000); + + pin_stat.val = GPIO_LOW; + pin_stat.pin = cellular_4g_PWR_KWY; + BusDevWriteData(cellular_4g_pin->owner_haldev,&write_param); +} + +static void cellular_4g_set_up_(void *parameter) +{ + + #define RESP_SIZE 128 + #define INIT_RETRY 1 + #define CPIN_RETRY 10 + #define CSQ_RETRY 20 + #define CGREG_RETRY 50 + #define IPADDR_RETRY 10 + #define LEN_PARA_BUF 128 + + char * result_buf = NULL; + // result_buf = (char *) x_calloc(1, 64); + char * str = NULL; + int i=0; + + char *baudrate = NULL; + baudrate = (char *) x_calloc(1, 10); + // char *signal_strength = NULL; + // signal_strength = (char *) x_calloc(1, 10); + // char *err_rate = NULL; + // err_rate = (char *) x_calloc(1, 10); + // char *link_stat = NULL; + // link_stat = (char *) x_calloc(1, 10); + int signal_strength; + int err_rate; + int link_stat; + char *IMEI = NULL; + IMEI = (char *) x_calloc(1, 20); + + char cmd[LEN_PARA_BUF]; + + struct AdapterAT *adapterAT = (struct AdapterAT *) parameter; + + struct ATAgent *agent = adapterAT->agent; + ATReplyType reply = NONE; + x_err_t result = EOK; + x_size_t retry_num = INIT_RETRY; + + /* wait 4G device startup finish */ + // UserTaskDelay(10000); + + reply = CreateATReply(64); + if (reply == NONE) + { + SYS_ERR("no memory for reply create."); + return; + } + // ATOrderSend(agent, REPLY_TIME_OUT, NULL, "ATE1"); + // UserTaskDelay(2500); + + // ATOrderSend(agent, REPLY_TIME_OUT, NULL, "ATE0"); + // UserTaskDelay(5000); + + do + { + ATOrderSend(agent, REPLY_TIME_OUT, reply, 4, "AT+CGSN\r"); + UserTaskDelay(5000); + result_buf = GetReplyText(reply); + ParseATReply(result_buf, "%*s %s\r", IMEI); + retry_num--; + } + while(result_buf == NULL && retry_num); + + /* Get the baudrate */ + ATOrderSend(agent, REPLY_TIME_OUT, reply, 3, "AT+IPR?\r"); + UserTaskDelay(2500); + result_buf = GetReplyText(reply); + str = strstr(result_buf, "+IPR:"); + ParseATReply(str, "+IPR: %s", baudrate); + + retry_num = INIT_RETRY; + do + { + ATOrderSend(agent, REPLY_TIME_OUT, reply, 2, "AT+QICSGP=1,1,\"CMNET\",\"\",\"\",1\r"); + UserTaskDelay(5000); + result_buf = GetReplyText(reply); + str = strstr(result_buf, "OK"); + retry_num--; + } + while(str == NULL && retry_num); + + retry_num = INIT_RETRY; + do + { + ATOrderSend(agent, REPLY_TIME_OUT, reply, 4, "AT+CPIN?\r"); + UserTaskDelay(5000); + result_buf = GetReplyText(reply); + str = strstr(result_buf, "OK"); + retry_num--; + } + while(str == NULL && retry_num); + + retry_num = INIT_RETRY; + do + { + ATOrderSend(agent, REPLY_TIME_OUT, reply, 4, "AT+CSQ\r"); + UserTaskDelay(2500); + result_buf = GetReplyText(reply); + str = strstr(result_buf, "+CSQ:"); + ParseATReply(str, "+CSQ: %d,%d", &signal_strength, &err_rate); + retry_num--; + } + while(str == NULL && retry_num); + + retry_num = INIT_RETRY; + do + { + ATOrderSend(agent, REPLY_TIME_OUT, reply, 4, "AT+CGREG?\r"); + UserTaskDelay(2500); + result_buf = GetReplyText(reply); + str = strstr(result_buf, "+CGREG:"); + ParseATReply(str, "+CGREG: %*d,%d", &link_stat); + retry_num--; + } + while(str == NULL && retry_num); + + retry_num = INIT_RETRY; + do + { + ATOrderSend(agent, REPLY_TIME_OUT, reply, 2, "AT+QIDEACT=1\r"); + UserTaskDelay(2500); + result_buf = GetReplyText(reply); + str = strstr(result_buf, "OK"); + retry_num--; + } + while(str == NULL && retry_num); + + retry_num = INIT_RETRY; + do + { + ATOrderSend(agent, REPLY_TIME_OUT, reply, 2, "AT+QIACT=1\r"); + UserTaskDelay(2500); + result_buf = GetReplyText(reply); + str = strstr(result_buf, "OK"); + retry_num--; + } + while(str == NULL && retry_num); + + printf("device IMEI: %s\n", IMEI); + printf("device baudrate: %s\n", baudrate); + printf("signal strength: %d\nerror rate: %d\n", signal_strength, err_rate); + printf("link status: %d\n", link_stat); + /* initialize successfully */ + result = EOK; + + if (reply) + { + DeleteATReply(reply); + } +} + +int cellular_4g_set_down(struct AdapterAT *adapterAT) +{ + cellular_4g_power_on(); + UserTaskDelay(10000); +} + +int cellular_4g_set_up(struct AdapterAT *adapterAT) +{ + cellular_4g_set_up_(adapterAT); + + return EOK; +} + +int cellular_4g_ping(struct AdapterAT *adapterAT, const char *destination,struct PingResult *ping_resp) +{ + char * str = NULL; + + uint32 result = EOK; + uint32 response; + uint32 recv_data_len; + uint32 ping_time; + uint32 ttl; + char ip_addr[17]; + + ATReplyType reply = CreateATReply(128); + if (NULL == reply) + { + printf("CreateATReply failed ! \n"); + result = -ERROR; + goto __exit; + } + + //ping baidu.com + ATOrderSend(adapterAT->agent, REPLY_TIME_OUT, reply, 6, "AT+QPING=1,%s,4,1\r", destination); + + UserTaskDelay(2500); + + char * result_buf = GetReplyText(reply); + if(!result_buf) + { + printf("send_dhcp_at_cmd AT+ result_buf = NULL"); + result = -ERROR; + goto __exit; + } + + str = strstr(result_buf, "+QPING:"); + int i=0; + for(i=0;iagent, REPLY_TIME_OUT, reply, 6, "AT+QPDNSCFG=1,%s\r", IpTstr(*(uint*)dns_addr)); + +__exit: + if (reply) + { + DeleteATReply(reply); + } + + return result; +} \ No newline at end of file diff --git a/framework/connection/Adapter/4g/xs_adapter_at_4g_register.c b/framework/connection/Adapter/4g/xs_adapter_at_4g_register.c new file mode 100644 index 000000000..e4b8b6cea --- /dev/null +++ b/framework/connection/Adapter/4g/xs_adapter_at_4g_register.c @@ -0,0 +1,53 @@ +#include +#include +#include +#include +#include + +const struct AdapterDone cellular_4gAdapterDone = +{ + cellular_4g_close, + cellular_4g_open, + NULL, + cellular_4g_send, + cellular_4g_receive, + NULL, +}; + +const struct ATDone cellular_4gATDone = +{ + cellular_4g_set_up, + cellular_4g_set_down, + NULL, + cellular_4g_dns, + NULL, + cellular_4g_ping, + NULL, + NULL, +}; + +int RegisterAdaptercellular_4g(void) +{ + printf("RegisterAdaptercellular_4g enter \n"); + + struct Adaptercellular_4g *cellular_4g_adapter = malloc(sizeof(struct Adaptercellular_4g)); + if (cellular_4g_adapter == NULL) + { + printf("out of memory\n"); + return ERROR; + } + + struct AdapterAT *cellular_4gAT_adapter = (struct AdapterAT *)cellular_4g_adapter; + struct Adapter *adapter = (struct Adapter *)cellular_4g_adapter; + + cellular_4g_adapter->parent.atdone = cellular_4gATDone; + cellular_4g_adapter->parent.parent.done = cellular_4gAdapterDone; + + cellular_4gAT_adapter->at_adapter_id = CELLULAR_4G_ADAPTER_ID; + + ATAdapterInit(); + ATAdapterRegister(cellular_4gAT_adapter); + + return EOK; + +} \ No newline at end of file diff --git a/framework/connection/Adapter/Makefile b/framework/connection/Adapter/Makefile index 78a7ea35a..86db42943 100644 --- a/framework/connection/Adapter/Makefile +++ b/framework/connection/Adapter/Makefile @@ -21,9 +21,9 @@ ifeq ($(CONFIG_CONNECTION_COMMUNICATION_NB_IOT), y) SRC_DIR += nbiot endif -# ifeq ($(CONFIG_CONNECTION_COMMUNICATION_4G), y) -# SRC_DIR += 4G -# endif +ifeq ($(CONFIG_CONNECTION_COMMUNICATION_4G), y) +SRC_DIR += 4g +endif # ifeq ($(CONFIG_CONNECTION_COMMUNICATION_BLUETOOTH), y) # SRC_DIR += bluetooth diff --git a/framework/connection/Adapter/include/xs_adapter_at_4g.h b/framework/connection/Adapter/include/xs_adapter_at_4g.h new file mode 100644 index 000000000..562c4a740 --- /dev/null +++ b/framework/connection/Adapter/include/xs_adapter_at_4g.h @@ -0,0 +1,34 @@ +#ifndef XS_ADAPTER_AT_4G_H +#define XS_ADAPTER_AT_4G_H + +#include "xs_adapter.h" +#include "xs_adapter_at.h" +#include "xs_adapter_def.h" +#include "xs_klist.h" + +#define cellular_4g_PWR_KWY 97 +#define cellular_4g_STATUS 100 + +struct Adaptercellular_4g { + struct AdapterAT parent; /* inherit from Adapter */ + + char vendor_name[NAME_LEN_MAX]; // + char product_ID_cellular_4g[NAME_LEN_MAX]; //air 720 + int pin_power; + int pin_power_status; + int uart_x; + + struct SingleLinklistNode link; +}; + +void cellular_4g_close(struct Adapter *padapter); +int cellular_4g_open(struct Adapter *padapter); +int cellular_4g_send(struct Adapter *padapter, const char *data, int len, bool block, int time_out, int delay, send_success cb, void *param, void *p); +int cellular_4g_receive(struct Adapter *padapter, char *rev_buffer, int buffer_len, int time_out, bool block, void *p); + +int cellular_4g_set_up(struct AdapterAT *adapterAT); +int cellular_4g_set_down(struct AdapterAT *adapterAT); +int cellular_4g_ping(struct AdapterAT *adapterAT, const char *destination,struct PingResult *ping_resp); +int cellular_4g_dns(struct AdapterAT *adapterAT, struct AddressIpv4 *dns_addr, uint8 dns_count); + +#endif \ No newline at end of file diff --git a/framework/connection/Adapter/include/xs_adapter_at_agent.h b/framework/connection/Adapter/include/xs_adapter_at_agent.h index 71f1ee2ec..832db6543 100644 --- a/framework/connection/Adapter/include/xs_adapter_at_agent.h +++ b/framework/connection/Adapter/include/xs_adapter_at_agent.h @@ -35,6 +35,7 @@ struct ATReply { char *reply_buffer; uint32 reply_max_len; + uint32 reply_line_num; uint32 reply_len; }; typedef struct ATReply *ATReplyType; @@ -51,6 +52,7 @@ struct ATAgent int32 lock; ATReplyType reply; + int recv_line_num; int rsp_sem; int32 at_handler; @@ -74,7 +76,7 @@ ATAgentType GetATAgent(const char *agent_name); int InitATAgent(const char *agent_name, const char *device_name, uint32 maintain_max, struct SerialCfgParam* pserial_cfg); int ParseATReply(char* str, const char *format, ...); void DeleteATReply(ATReplyType reply); -int ATOrderSend(ATAgentType agent, uint32 timeout, ATReplyType reply, const char *cmd_expr, ...); +int ATOrderSend(ATAgentType agent, uint32 timeout, ATReplyType reply, int line_num, const char *cmd_expr, ...); #define REPLY_TIME_OUT 3000 diff --git a/framework/connection/Adapter/include/xs_adapter_def.h b/framework/connection/Adapter/include/xs_adapter_def.h index dd0533476..d86769d03 100644 --- a/framework/connection/Adapter/include/xs_adapter_def.h +++ b/framework/connection/Adapter/include/xs_adapter_def.h @@ -70,7 +70,7 @@ struct PingResult #define NBIOT_ADAPTER_ID 0x02U #define ETHERNET_ADAPTER_ID 0x03U #define WIFI_ADAPTER_ID 0x04U -#define fourG_ADAPTER_ID 0x05U +#define CELLULAR_4G_ADAPTER_ID 0x05U diff --git a/framework/connection/Adapter/src/xs_adapter_at_agent.c b/framework/connection/Adapter/src/xs_adapter_at_agent.c index 2193537c2..08fb9db22 100644 --- a/framework/connection/Adapter/src/xs_adapter_at_agent.c +++ b/framework/connection/Adapter/src/xs_adapter_at_agent.c @@ -122,7 +122,7 @@ uint32 ATSprintf(int fd, const char *format, va_list params) return write(fd, send_buf, last_cmd_len); } -int ATOrderSend(ATAgentType agent, uint32 timeout, ATReplyType reply, const char *cmd_expr, ...) +int ATOrderSend(ATAgentType agent, uint32 timeout, ATReplyType reply, int line_num, const char *cmd_expr, ...) { if (agent == NULL){ printf("ATAgent is null"); @@ -130,6 +130,7 @@ int ATOrderSend(ATAgentType agent, uint32 timeout, ATReplyType reply, const char } agent->receive_mode = AT_MODE; + agent->recv_line_num = line_num; memset(agent->maintain_buffer, 0x00, agent->maintain_max); agent->maintain_len = 0; @@ -221,7 +222,7 @@ static int GetCompleteATReply(ATAgentType agent) memset(agent->maintain_buffer, 0x00, agent->maintain_max); agent->maintain_len = 0; - + while (1){ read(agent->fd, &ch, 1); @@ -257,8 +258,9 @@ static int GetCompleteATReply(ATAgentType agent) agent->maintain_len = 0; return -ERROR; } - printf("GetCompleteATReply get n r ...\n"); - break; + // printf("GetCompleteATReply get line %d ...\n",agent->recv_line_num - line_count+1); + if(!(--(agent->recv_line_num))) + break; } last_ch = ch; } @@ -400,8 +402,7 @@ static int SerialBusCheck(struct ATAgent *agent, const char *device_name, struct return EOK; } - - ioctl(agent->fd, OPE_INT, &pserial_cfg->data_cfg); + ioctl(agent->fd, OPE_INT, &(pserial_cfg->data_cfg)); return EOK; } @@ -428,7 +429,6 @@ int InitATAgent(const char *agent_name, const char *device_name, uint32 maintain } agent = &at_agent_table[i]; - SerialBusCheck(agent, device_name, pserial_cfg); strcpy(agent->agent_name, agent_name);