From b063120bc5d88546f1ffa2406c25826b2ed0e626 Mon Sep 17 00:00:00 2001 From: Zhao_Jiasheng <18535861947@163.com> Date: Fri, 30 Apr 2021 15:43:17 +0800 Subject: [PATCH 1/2] Add connection NB-IoT --- applications/Makefile | 4 + .../connection_demo/nbiot_demo/Makefile | 3 + .../connection_demo/nbiot_demo/nbiot_demo.c | 56 +++ framework/connection/Adapter/Makefile | 11 +- .../connection/Adapter/include/xs_adapter.h | 2 +- .../Adapter/include/xs_adapter_at_nbiot.h | 54 +++ .../Adapter/include/xs_adapter_def.h | 1 + framework/connection/Adapter/nbiot/Makefile | 3 + .../connection/Adapter/nbiot/bc28/Makefile | 3 + .../Adapter/nbiot/bc28/xs_adapter_at_nbiot.c | 336 ++++++++++++++++++ .../nbiot/bc28/xs_adapter_at_nbiot_register.c | 69 ++++ .../Adapter/src/xs_adapter_at_agent.c | 17 +- 12 files changed, 549 insertions(+), 10 deletions(-) create mode 100644 applications/connection_demo/nbiot_demo/Makefile create mode 100644 applications/connection_demo/nbiot_demo/nbiot_demo.c create mode 100644 framework/connection/Adapter/include/xs_adapter_at_nbiot.h create mode 100644 framework/connection/Adapter/nbiot/Makefile create mode 100644 framework/connection/Adapter/nbiot/bc28/Makefile create mode 100644 framework/connection/Adapter/nbiot/bc28/xs_adapter_at_nbiot.c create mode 100644 framework/connection/Adapter/nbiot/bc28/xs_adapter_at_nbiot_register.c diff --git a/applications/Makefile b/applications/Makefile index 5d7dd8f2..521796d0 100644 --- a/applications/Makefile +++ b/applications/Makefile @@ -41,6 +41,10 @@ ifeq ($(CONFIG_CONNECTION_COMMUNICATION_WIFI), y) SRC_DIR += connection_demo/wifi_demo endif +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 diff --git a/applications/connection_demo/nbiot_demo/Makefile b/applications/connection_demo/nbiot_demo/Makefile new file mode 100644 index 00000000..d897a9be --- /dev/null +++ b/applications/connection_demo/nbiot_demo/Makefile @@ -0,0 +1,3 @@ +SRC_FILES :=nbiot_demo.c + +include $(KERNEL_ROOT)/compiler.mk diff --git a/applications/connection_demo/nbiot_demo/nbiot_demo.c b/applications/connection_demo/nbiot_demo/nbiot_demo.c new file mode 100644 index 00000000..272a6aaf --- /dev/null +++ b/applications/connection_demo/nbiot_demo/nbiot_demo.c @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2020 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** + * @file nbiot_demo.c + * @brief Demo for NBIoT function + * @version 1.0 + * @author AIIT XUOS Lab + * @date 2021.04.22 + */ + +#include +#include +#include +#include +#include + +void NbiotEnable(void) +{ + RegisterAdapterNBIoT(); + + struct AdapterAT* at_adapter = ATAdapterFind(NBIOT_ADAPTER_ID); + + UserTaskDelay(5000); + + at_adapter->parent.done.NetAiitOpen(&at_adapter->parent); + + printf("Waiting for msg...\n"); + + at_adapter->atdone.ATSocketCreate(at_adapter, 1, SOCKET_TYPE_STREAM, NET_TYPE_AF_INET); + UserTaskDelay(1000); + + struct ADDRESS_IPV4 addr; + addr.ipv4 = IpTint("115.236.53.226"); + at_adapter->atdone.ATSocketConnect(at_adapter, 1, addr, 8989, 0); + + int socket_fd = 1; + int count = 0; + + while (1) { + UserTaskDelay(1000); + at_adapter->parent.done.NetAiitSend((struct Adapter *)at_adapter, "AB30313233", 5, 0, 0, 0, 0, 0, &socket_fd); + count++; + if (count == 10) + break; + } +} diff --git a/framework/connection/Adapter/Makefile b/framework/connection/Adapter/Makefile index 4c50469e..ec542a61 100644 --- a/framework/connection/Adapter/Makefile +++ b/framework/connection/Adapter/Makefile @@ -1,3 +1,6 @@ + +SRC_DIR := src + # ifeq ($(CONFIG_CONNECTION_COMMUNICATION_LORA), y) # SRC_DIR += lora # endif @@ -14,9 +17,9 @@ ifeq ($(CONFIG_CONNECTION_COMMUNICATION_ZIGBEE), y) SRC_DIR += zigbee endif -# ifeq ($(CONFIG_CONNECTION_COMMUNICATION_NB_IOT), y) -# SRC_DIR += nbiot -# endif +ifeq ($(CONFIG_CONNECTION_COMMUNICATION_NB_IOT), y) + SRC_DIR += nbiot +endif # ifeq ($(CONFIG_CONNECTION_COMMUNICATION_4G), y) # SRC_DIR += 4G @@ -30,6 +33,6 @@ endif # SRC_DIR += rs485 # endif -SRC_DIR += src + include $(KERNEL_ROOT)/compiler.mk \ No newline at end of file diff --git a/framework/connection/Adapter/include/xs_adapter.h b/framework/connection/Adapter/include/xs_adapter.h index 85958f3f..5a0a89bd 100644 --- a/framework/connection/Adapter/include/xs_adapter.h +++ b/framework/connection/Adapter/include/xs_adapter.h @@ -30,7 +30,7 @@ enum AdapterType { ADAPTER_LORA = 0, /* Lora */ ADAPTER_4G , /* 4G */ - ADAPTER_NBIOT , /* _NBIot */ + ADAPTER_NBIOT , /* NBIot */ ADAPTER_WIFI , /* WIFI */ ADAPTER_ETHERNET , /* ETHERNET */ ADAPTER_BLUETOOTH , /* BLUETOOTH */ diff --git a/framework/connection/Adapter/include/xs_adapter_at_nbiot.h b/framework/connection/Adapter/include/xs_adapter_at_nbiot.h new file mode 100644 index 00000000..5e7e4d8b --- /dev/null +++ b/framework/connection/Adapter/include/xs_adapter_at_nbiot.h @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2020 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** + * @file xs_adapter_at_nbiot.h + * @brief Structure and function declarations of the connection NBIoT + * @version 1.0 + * @author AIIT XUOS Lab + * @date 2021.04.22 + */ + +#ifndef XS_ADAPTER_AT_NBIOT_H +#define XS_ADAPTER_AT_NBIOT_H + +#include "xs_adapter.h" +#include "xs_adapter_at.h" +#include "xs_adapter_at_agent.h" +#include "xs_adapter_def.h" +#include "../../../applications/user_api/switch_api/user_api.h" + +#define MAX_SOCKET_NUM 8 + +#define SOCKET_STATUS_UNUSED (0) +#define SOCKET_STATUS_INIT (1) +#define SOCKET_STATUS_CONNECT (2) + +struct AdapterNBIoT { + struct AdapterAT parent; /* inherit from Adapter */ + + char vendor_name[NAME_LEN_MAX]; + char product_ID_ethernet[NAME_LEN_MAX]; + + struct SingleLinklistNode link; +}; + +int NbiotOpen(struct Adapter *padapter); + +int NbiotSend(struct Adapter *padapter, const char* data, int len, bool block, int time_out, int delay, send_success cb, void* param, void* reserved); +int NBIotRecv(struct Adapter *padapter, char *rev_buffer, int buffer_len, int time_out, bool block); + +int NBIoTSocketConnect(struct AdapterAT *adapterAT , uint8_t socket_fd , struct ADDRESS_IPV4 dst_ip , uint16_t dst_port, uint8 is_client); +int NBIoTSocketCreate(struct AdapterAT *adapterAT, uint8_t socket_fd, uint8_t type, uint8_t af_type ); +int NBIoTSocketClose(struct AdapterAT *adapterAT, uint8_t socket_fd ); + +#endif \ No newline at end of file diff --git a/framework/connection/Adapter/include/xs_adapter_def.h b/framework/connection/Adapter/include/xs_adapter_def.h index fba4ae9c..dd053347 100644 --- a/framework/connection/Adapter/include/xs_adapter_def.h +++ b/framework/connection/Adapter/include/xs_adapter_def.h @@ -67,6 +67,7 @@ struct PingResult void *user_data; /* user-specific data */ }; +#define NBIOT_ADAPTER_ID 0x02U #define ETHERNET_ADAPTER_ID 0x03U #define WIFI_ADAPTER_ID 0x04U #define fourG_ADAPTER_ID 0x05U diff --git a/framework/connection/Adapter/nbiot/Makefile b/framework/connection/Adapter/nbiot/Makefile new file mode 100644 index 00000000..36a6f4c5 --- /dev/null +++ b/framework/connection/Adapter/nbiot/Makefile @@ -0,0 +1,3 @@ +SRC_DIR := bc28 + +include $(KERNEL_ROOT)/compiler.mk \ No newline at end of file diff --git a/framework/connection/Adapter/nbiot/bc28/Makefile b/framework/connection/Adapter/nbiot/bc28/Makefile new file mode 100644 index 00000000..88ac0d61 --- /dev/null +++ b/framework/connection/Adapter/nbiot/bc28/Makefile @@ -0,0 +1,3 @@ +SRC_FILES := xs_adapter_at_nbiot.c xs_adapter_at_nbiot_register.c + +include $(KERNEL_ROOT)/compiler.mk \ No newline at end of file diff --git a/framework/connection/Adapter/nbiot/bc28/xs_adapter_at_nbiot.c b/framework/connection/Adapter/nbiot/bc28/xs_adapter_at_nbiot.c new file mode 100644 index 00000000..89248230 --- /dev/null +++ b/framework/connection/Adapter/nbiot/bc28/xs_adapter_at_nbiot.c @@ -0,0 +1,336 @@ +/* +* Copyright (c) 2020 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** + * @file xs_adapter_at_nbiot.c + * @brief BC28 NBIoT driver base connection framework + * @version 1.0 + * @author AIIT XUOS Lab + * @date 2021.04.22 + */ + +#include +#include +#include +#include + +#define NBIOT_DEVICE_NAME "/dev/usart2_dev2" + +#define SOCKET_TYPE_DGRAM (0) +#define SOCKET_TYPE_STREAM (1) + +#define SOCKET_PROTOCOL_TCP (6) +#define SOCKET_PROTOCOL_UDP (17) + +#define NET_TYPE_AF_INET (0) +#define NET_TYPE_AF_INET6 (1) + +/** + * @description: Open NBIoT device + * @param padapter - NBIoT adapter + * @return success: EOK, failure: -ERROR + */ +int NbiotOpen(struct Adapter *padapter) +{ + char *agent_name = "urat2_client"; + const char *device_name = NBIOT_DEVICE_NAME; + + struct SerialCfgParam cfg; + cfg.data_cfg.serial_baud_rate = BAUD_RATE_9600; + cfg.data_cfg.serial_bit_order = 0; + cfg.data_cfg.serial_buffer_size = SERIAL_RB_BUFSZ; + cfg.data_cfg.serial_data_bits = DATA_BITS_8; + cfg.data_cfg.serial_invert_mode = 0; + cfg.data_cfg.serial_parity_mode = PARITY_NONE; + cfg.data_cfg.serial_stop_bits = STOP_BITS_1; + + if (InitATAgent(agent_name, device_name, 512, &cfg)) { + printf("NBIoT open failed!\n"); + return -ERROR; + } + + ATAgentType at_agent = GetATAgent(agent_name); + if (NULL == at_agent) { + printf("Get AT agent failed!\n"); + return -ERROR; + } + + UserTaskDelay(3000); + struct AdapterAT *nbiot = (struct AdapterAT *)padapter; + nbiot->agent = at_agent; + + return EOK; +} + +/** + * @description: NBIoT device create a socket connection + * @param adapterAT - NBIoT adapter AT + * @param socket_fd - socket file description + * @param type - socket type + * @param af_type - IPv4 or IPv6 + * @return success: EOK, failure: -ERROR + */ +int NBIoTSocketCreate(struct AdapterAT *adapterAT, uint8_t socket_fd, uint8_t type, uint8_t af_type ) +{ + int32 result; + + ATReplyType reply = CreateATReply(64); + if (NULL == reply) { + printf("at create failed ! \n"); + result = -ERROR; + goto __exit; + } + + if ( af_type == NET_TYPE_AF_INET6) { + printf("IPv6 not surport !\n"); + return -1; + } + + char *str_af_type = "AF_INET"; + char *str_type; + char str_fd[3] = {0}; + char *str_protocol ; + char at_cmd[64] = {0}; + char *linsten_port = "0"; + struct Socket socket = {0}; + socket.status = SOCKET_STATUS_INIT; + socket.af_type = NET_TYPE_AF_INET; + + if (type == SOCKET_TYPE_STREAM) { //tcp = AT+NSOCR=STREAM,6,0,1,AF_INET + socket.type = SOCKET_TYPE_STREAM; + socket.protocal = SOCKET_PROTOCOL_TCP; + str_type = "STREAM"; + char *str_protocol = "6"; + if (socket_fd > 0 && socket_fd < 8) { + str_fd[0] = socket_fd + '0'; + } else + str_fd[0] = '0'; + + memcpy(at_cmd, "AT+NSOCR=", 9); + strcat(at_cmd, str_type); + strcat(at_cmd, ","); + strcat(at_cmd, str_protocol); + strcat(at_cmd, ","); + strcat(at_cmd, linsten_port); + strcat(at_cmd, ","); + strcat(at_cmd, str_fd); + strcat(at_cmd, ","); + strcat(at_cmd, str_af_type); + strcat(at_cmd, "\n"); + + }else if ( type == SOCKET_TYPE_DGRAM ){ //udp + socket.type = SOCKET_TYPE_DGRAM; + socket.protocal = SOCKET_PROTOCOL_UDP; + str_type = "DGRAM"; + char *str_protocol = "17"; + if (socket_fd > 0 && socket_fd < 8){ + str_fd[0] = socket_fd + '0'; + }else + str_fd[0] = '0'; + + memcpy(at_cmd, "AT+NSOCR=", 9); + strcat(at_cmd, str_type); + strcat(at_cmd, ","); + strcat(at_cmd, str_protocol); + strcat(at_cmd, ","); + strcat(at_cmd, linsten_port); + strcat(at_cmd, ","); + strcat(at_cmd, str_fd); + strcat(at_cmd, ","); + strcat(at_cmd, str_af_type); + strcat(at_cmd, "\n"); + + }else{ + printf("error socket type \n"); + return -1 ; + } + + printf("cmd : %s\n", at_cmd); + ATOrderSend(adapterAT->agent, REPLY_TIME_OUT, reply, at_cmd); + MdelayKTask(3000); + printf("bak : %s\n", adapterAT->agent->maintain_buffer); + + struct Socket (*socketlist)[MAX_SOCKET_NUM] = &adapterAT->socket; + memset(socketlist[socket_fd], 0, sizeof(struct Socket)); + memcpy(socketlist[socket_fd], &socket , sizeof(struct Socket)); + +__exit: + if (reply) { + DeleteATReply(reply); + } + + return result; +} + +/** + * @description: NBIoT device create a socket connection + * @param adapterAT - NBIoT adapter AT + * @param socket_fd - socket file description + * @param dst_ip - ip address + * @param dst_port - ip port + * @param is_client - whether it is a client + * @return success: EOK, failure: -ERROR + */ +int NBIoTSocketConnect(struct AdapterAT *adapterAT , uint8_t socket_fd , struct ADDRESS_IPV4 dst_ip , uint16_t dst_port, uint8 is_client) +{ + int result; + + ATReplyType reply = CreateATReply(64); + if (NULL == reply) { + printf("at create failed ! \n"); + result = -ERROR; + goto __exit; + } + + if (socket_fd < 1 || socket_fd > 8) { + printf("socket fd error \n"); + return -1 ; + } + struct Socket (*socketlist)[SOCKET_MAX] = &adapterAT->socket; + + if (socketlist[socket_fd]->status != SOCKET_STATUS_INIT || socketlist[socket_fd]->type != SOCKET_TYPE_STREAM) { + printf("socket type error \n"); + } + + char at_cmd[64] = {0}; + char str_fd[2] = {0}; + char str_port[6] = {0}; + + str_fd[0] = socket_fd + '0'; + char *str_ip = IpTstr(dst_ip.ipv4) ; + sprintf(str_port, "%u", dst_port); + + memcpy(at_cmd, "AT+NSOCO=", 9); + strcat(at_cmd, str_fd); + strcat(at_cmd, ","); + strcat(at_cmd, str_ip); + strcat(at_cmd, ","); + strcat(at_cmd, str_port); + strcat(at_cmd, "\n"); + + printf("cmd : %s\n", at_cmd); + ATOrderSend(adapterAT->agent, REPLY_TIME_OUT, reply, at_cmd); + MdelayKTask(300); + + socketlist[socket_fd]->dst_ip = dst_ip; + socketlist[socket_fd]->dst_port = dst_port; + socketlist[socket_fd]->status = SOCKET_STATUS_CONNECT; + +__exit: + if (reply) { + DeleteATReply(reply); + } + + return result; +} + +/** + * @description: NBIoT device close a socket connection + * @param adapterAT - NBIoT adapter AT + * @param socket_fd - socket file description + * @return success: EOK, failure: -ERROR + */ +int NBIoTSocketClose(struct AdapterAT *adapterAT, uint8_t socket_fd ) +{ + int result; + + ATReplyType reply = CreateATReply(64); + if (NULL == reply) { + printf("at create failed ! \n"); + result = -ERROR; + goto __exit; + } + + if (socket_fd < 1 || socket_fd > 7) { + printf("socket fd error \n"); + return -1 ; + } + + struct Socket (*socketlist)[SOCKET_MAX] = &adapterAT->socket; + + char str_fd[2] = {0}; + char at_cmd[16] = {0}; + str_fd[0] = socket_fd + '0'; + + memcpy(at_cmd, "AT+NSOCL=", 9); + strcat(at_cmd, str_fd); + strcat(at_cmd, "\n"); + + printf("cmd : %s\n", at_cmd); + ATOrderSend(adapterAT->agent, REPLY_TIME_OUT, reply, at_cmd); + MdelayKTask(300); + + memset(socketlist[socket_fd], 0, sizeof(struct Socket)); + +__exit: + if (reply) { + DeleteATReply(reply); + } + + return result; +} + +/** + * @description: NBIoT socket send a message + * @param padapter - NBIoT adapter + * @param data - send data buffer + * @param len - send data length + * @param block - block + * @param time_out - timeout + * @param delay - delay time + * @param cb - send callback function + * @param param - send callback function parameter + * @param reserved - reserved parameter + * @return success: EOK, failure: -ERROR + */ +int NbiotSend(struct Adapter *padapter, const char* data, int len, bool block, int time_out, int delay, send_success cb, void* param, void* reserved) +{ + uint32_t result; + + ATReplyType reply = CreateATReply(64); + if (NULL == reply) { + printf("at create failed ! \n"); + result = -ERROR; + goto __exit; + } + + struct AdapterAT *adapterAT = (struct AdapterAT *)padapter; + int socket_fd = *(int*)reserved; + + struct Socket (*socketlist)[SOCKET_MAX] = &adapterAT->socket; + + char at_cmd[64] = {0}; + char str_fd[2] = {0}; + char size[2] = {0}; + + str_fd[0] = socket_fd + '0'; + size[0] = len + '0'; + + memcpy(at_cmd, "AT+NSOSD=", 9); + strcat(at_cmd, str_fd); + strcat(at_cmd, ","); + strcat(at_cmd, size); + strcat(at_cmd, ","); + strcat(at_cmd, data); + strcat(at_cmd, "\n"); + + printf("cmd : %s\n", at_cmd); + ATOrderSend(adapterAT->agent, REPLY_TIME_OUT, reply, at_cmd); + MdelayKTask(300); + +__exit: + if (reply) { + DeleteATReply(reply); + } + + return result; +} \ No newline at end of file diff --git a/framework/connection/Adapter/nbiot/bc28/xs_adapter_at_nbiot_register.c b/framework/connection/Adapter/nbiot/bc28/xs_adapter_at_nbiot_register.c new file mode 100644 index 00000000..26164aa8 --- /dev/null +++ b/framework/connection/Adapter/nbiot/bc28/xs_adapter_at_nbiot_register.c @@ -0,0 +1,69 @@ +/* +* Copyright (c) 2020 AIIT XUOS Lab +* XiUOS is licensed under Mulan PSL v2. +* You can use this software according to the terms and conditions of the Mulan PSL v2. +* You may obtain a copy of Mulan PSL v2 at: +* http://license.coscl.org.cn/MulanPSL2 +* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +* See the Mulan PSL v2 for more details. +*/ + +/** + * @file xs_adapter_at_nbiot_register.c + * @brief BC28 nbiot driver register to connection framework + * @version 1.0 + * @author AIIT XUOS Lab + * @date 2021.04.22 + */ + +#include +#include + +const struct AdapterDone bc28_done = +{ + NONE, + NbiotOpen, + NONE, + NbiotSend, + NONE, + NONE, +}; + +const struct ATDone bc28_at_done = +{ + NONE, + NONE, + NONE, + NONE, + NONE, + NONE, + NONE, + NONE, + NBIoTSocketCreate, + NBIoTSocketConnect, + NBIoTSocketClose, +}; + +/** + * @description: Register nbiot device + * @return success: EOK, failure: ERROR + */ +int RegisterAdapterNBIoT(void) +{ + static struct AdapterNBIoT nbiot_adapter; + + struct AdapterAT *nbiot_at_adapter = (struct AdapterAT *)&nbiot_adapter; + struct Adapter *adapter = (struct Adapter *)&nbiot_adapter; + + nbiot_adapter.parent.atdone = bc28_at_done; + nbiot_adapter.parent.parent.done = bc28_done; + + nbiot_at_adapter->at_adapter_id = NBIOT_ADAPTER_ID; + + ATAdapterInit(); + ATAdapterRegister(nbiot_at_adapter); + + return 0; +} \ No newline at end of file diff --git a/framework/connection/Adapter/src/xs_adapter_at_agent.c b/framework/connection/Adapter/src/xs_adapter_at_agent.c index 50815774..2193537c 100644 --- a/framework/connection/Adapter/src/xs_adapter_at_agent.c +++ b/framework/connection/Adapter/src/xs_adapter_at_agent.c @@ -389,14 +389,21 @@ static int ATAgentInit(ATAgentType agent) static int SerialBusCheck(struct ATAgent *agent, const char *device_name, struct SerialCfgParam *pserial_cfg) { int ret = EOK; - struct SerialDataCfg data_cfg; - memset(&data_cfg, 0, sizeof(struct SerialDataCfg)); agent->fd = open(device_name,O_RDWR); - data_cfg.serial_baud_rate = 57600; - ioctl(agent->fd, OPE_INT, &data_cfg); + if (!pserial_cfg) { + struct SerialDataCfg data_cfg; + memset(&data_cfg, 0, sizeof(struct SerialDataCfg)); + data_cfg.serial_baud_rate = 57600; + ioctl(agent->fd, OPE_INT, &data_cfg); + return EOK; + } + + ioctl(agent->fd, OPE_INT, &pserial_cfg->data_cfg); + + return EOK; } int InitATAgent(const char *agent_name, const char *device_name, uint32 maintain_max, struct SerialCfgParam *pserial_cfg) @@ -415,7 +422,7 @@ int InitATAgent(const char *agent_name, const char *device_name, uint32 maintain } if (i >= AT_AGENT_MAX) { - printf("agent buffer(%d) is full .", AT_AGENT_MAX); + printf("agent buffer(%d) is full.", AT_AGENT_MAX); result = -ERROR; return result; } From d155d5e6726f2447a684b593b1b66e89614d765a Mon Sep 17 00:00:00 2001 From: Zhao_Jiasheng <18535861947@163.com> Date: Fri, 30 Apr 2021 15:51:45 +0800 Subject: [PATCH 2/2] Repair NBIoT changed interfaces --- applications/connection_demo/nbiot_demo/nbiot_demo.c | 4 +++- framework/connection/Adapter/include/xs_adapter_at_nbiot.h | 2 +- framework/connection/Adapter/nbiot/bc28/xs_adapter_at_nbiot.c | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/applications/connection_demo/nbiot_demo/nbiot_demo.c b/applications/connection_demo/nbiot_demo/nbiot_demo.c index 272a6aaf..40219762 100644 --- a/applications/connection_demo/nbiot_demo/nbiot_demo.c +++ b/applications/connection_demo/nbiot_demo/nbiot_demo.c @@ -24,6 +24,8 @@ #include #include +extern void RegisterAdapterNBIoT(void); + void NbiotEnable(void) { RegisterAdapterNBIoT(); @@ -39,7 +41,7 @@ void NbiotEnable(void) at_adapter->atdone.ATSocketCreate(at_adapter, 1, SOCKET_TYPE_STREAM, NET_TYPE_AF_INET); UserTaskDelay(1000); - struct ADDRESS_IPV4 addr; + struct AddressIpv4 addr; addr.ipv4 = IpTint("115.236.53.226"); at_adapter->atdone.ATSocketConnect(at_adapter, 1, addr, 8989, 0); diff --git a/framework/connection/Adapter/include/xs_adapter_at_nbiot.h b/framework/connection/Adapter/include/xs_adapter_at_nbiot.h index 5e7e4d8b..ed1f0763 100644 --- a/framework/connection/Adapter/include/xs_adapter_at_nbiot.h +++ b/framework/connection/Adapter/include/xs_adapter_at_nbiot.h @@ -47,7 +47,7 @@ int NbiotOpen(struct Adapter *padapter); int NbiotSend(struct Adapter *padapter, const char* data, int len, bool block, int time_out, int delay, send_success cb, void* param, void* reserved); int NBIotRecv(struct Adapter *padapter, char *rev_buffer, int buffer_len, int time_out, bool block); -int NBIoTSocketConnect(struct AdapterAT *adapterAT , uint8_t socket_fd , struct ADDRESS_IPV4 dst_ip , uint16_t dst_port, uint8 is_client); +int NBIoTSocketConnect(struct AdapterAT *adapterAT , uint8_t socket_fd , struct AddressIpv4 dst_ip , uint16_t dst_port, uint8 is_client); int NBIoTSocketCreate(struct AdapterAT *adapterAT, uint8_t socket_fd, uint8_t type, uint8_t af_type ); int NBIoTSocketClose(struct AdapterAT *adapterAT, uint8_t socket_fd ); diff --git a/framework/connection/Adapter/nbiot/bc28/xs_adapter_at_nbiot.c b/framework/connection/Adapter/nbiot/bc28/xs_adapter_at_nbiot.c index 89248230..44e37d09 100644 --- a/framework/connection/Adapter/nbiot/bc28/xs_adapter_at_nbiot.c +++ b/framework/connection/Adapter/nbiot/bc28/xs_adapter_at_nbiot.c @@ -153,7 +153,7 @@ int NBIoTSocketCreate(struct AdapterAT *adapterAT, uint8_t socket_fd, uint8_t ty printf("error socket type \n"); return -1 ; } - + printf("cmd : %s\n", at_cmd); ATOrderSend(adapterAT->agent, REPLY_TIME_OUT, reply, at_cmd); MdelayKTask(3000); @@ -180,7 +180,7 @@ __exit: * @param is_client - whether it is a client * @return success: EOK, failure: -ERROR */ -int NBIoTSocketConnect(struct AdapterAT *adapterAT , uint8_t socket_fd , struct ADDRESS_IPV4 dst_ip , uint16_t dst_port, uint8 is_client) +int NBIoTSocketConnect(struct AdapterAT *adapterAT , uint8_t socket_fd , struct AddressIpv4 dst_ip , uint16_t dst_port, uint8 is_client) { int result;