From 92347f7e2911fb40c492df54ef3560b8e0f24b15 Mon Sep 17 00:00:00 2001 From: Liu_Weichao Date: Mon, 11 Oct 2021 10:13:01 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81support=20adapter=5Fbluetooth=20and?= =?UTF-8?q?=20hc08=20device=EF=BC=9B2=E3=80=81fix=20adapter=20at=20agent?= =?UTF-8?q?=20bug=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Framework/connection/4G/EC200T/ec200t.c | 4 +- .../Framework/connection/4G/adapter_4G.c | 4 +- .../Framework/connection/adapter_agent.c | 58 ++-- APP_Framework/Framework/connection/at_agent.h | 4 + .../connection/bluetooth/HC08/Kconfig | 8 + .../connection/bluetooth/HC08/hc08.c | 300 ++++++++++++++++-- .../connection/bluetooth/adapter_bluetooth.c | 93 ++++++ .../Framework/connection/wifi/HFA21/hfa21.c | 2 +- .../Framework/connection/wifi/adapter_wifi.c | 4 +- .../third_party_driver/uart/Kconfig | 2 +- 10 files changed, 435 insertions(+), 44 deletions(-) diff --git a/APP_Framework/Framework/connection/4G/EC200T/ec200t.c b/APP_Framework/Framework/connection/4G/EC200T/ec200t.c index cace6f29..1185fc59 100644 --- a/APP_Framework/Framework/connection/4G/EC200T/ec200t.c +++ b/APP_Framework/Framework/connection/4G/EC200T/ec200t.c @@ -28,7 +28,7 @@ static void Ec200tPowerSet(void) struct PinParam pin_param; pin_param.cmd = GPIO_CONFIG_MODE; - pin_param.mode = GPIO_CFG_INPUT_PULLUP; + pin_param.mode = GPIO_CFG_OUTPUT; pin_param.pin = ADAPTER_EC200T_PWRKEY; struct PrivIoctlCfg ioctl_cfg; @@ -250,7 +250,7 @@ static const struct IpProtocolDone ec200t_done = AdapterProductInfoType Ec200tAttach(struct Adapter *adapter) { - struct AdapterProductInfo *product_info = malloc(sizeof(struct AdapterProductInfo)); + struct AdapterProductInfo *product_info = PrivMalloc(sizeof(struct AdapterProductInfo)); if (!product_info) { printf("Ec200tAttach malloc product_info error\n"); PrivFree(product_info); diff --git a/APP_Framework/Framework/connection/4G/adapter_4G.c b/APP_Framework/Framework/connection/4G/adapter_4G.c index aaab4424..c8728ee4 100644 --- a/APP_Framework/Framework/connection/4G/adapter_4G.c +++ b/APP_Framework/Framework/connection/4G/adapter_4G.c @@ -49,12 +49,14 @@ int Adapter4GInit(void) { int ret = 0; - struct Adapter *adapter = malloc(sizeof(struct Adapter)); + struct Adapter *adapter = PrivMalloc(sizeof(struct Adapter)); if (!adapter) { free(adapter); return -1; } + memset(adapter, 0, sizeof(struct Adapter)); + ret = Adapter4GRegister(adapter); if (ret < 0) { printf("Adapter4GInit register 4G adapter error\n"); diff --git a/APP_Framework/Framework/connection/adapter_agent.c b/APP_Framework/Framework/connection/adapter_agent.c index a22899b0..874dd6e3 100755 --- a/APP_Framework/Framework/connection/adapter_agent.c +++ b/APP_Framework/Framework/connection/adapter_agent.c @@ -73,7 +73,7 @@ void SwapStr(char *str, int begin, int end) char *IpTstr(unsigned int ipint) { int LEN = 16; - char *new = (char *)malloc(LEN); + char *new = (char *)PrivMalloc(LEN); memset(new, '\0', LEN); new[0] = '.'; char token[4]; @@ -120,7 +120,7 @@ int ParseATReply(char *str, const char *format, ...) uint32 ATSprintf(int fd, const char *format, va_list params) { last_cmd_len = vsnprintf(send_buf, sizeof(send_buf), format, params); - printf("ATSprintf send %s\n",send_buf); + printf("ATSprintf send %s len %u\n",send_buf, last_cmd_len); PrivWrite(fd, send_buf, last_cmd_len); } @@ -180,6 +180,28 @@ char *GetReplyText(ATReplyType reply) return reply->reply_buffer; } +int AtSetReplyEndChar(ATAgentType agent, char ch) +{ + if (!agent) { + return -ERROR; + } + + agent->reply_end_char = ch; + + return EOK; +} + +int AtSetReplyCharNum(ATAgentType agent, unsigned int num) +{ + if (!agent) { + return -ERROR; + } + + agent->reply_char_num = num; + + return EOK; +} + int EntmSend(ATAgentType agent, const char *data, int len) { char send_buf[128]; @@ -200,13 +222,15 @@ int EntmRecv(ATAgentType agent, char *rev_buffer, int buffer_len, int timeout_s) abstime.tv_sec = timeout_s; + agent->receive_mode = ENTM_MODE; + PrivTaskDelay(1000); memset(agent->entm_recv_buf, 0, ENTM_RECV_MAX); agent->entm_recv_len = 0; if (PrivSemaphoreObtainWait(&agent->entm_rx_notice, &abstime)){ - return ERROR; + return -ERROR; } if (buffer_len < agent->entm_recv_len){ @@ -233,7 +257,7 @@ static int GetCompleteATReply(ATAgentType agent) while (1){ PrivRead(agent->fd, &ch, 1); - printf(" %c(0x%x)\n", ch, ch); + printf(" %c (0x%x)\n", ch, ch); if (agent->receive_mode == ENTM_MODE){ if (agent->entm_recv_len < ENTM_RECV_MAX){ @@ -260,14 +284,16 @@ static int GetCompleteATReply(ATAgentType agent) is_full = true; } - if ((ch == '\n' && last_ch == '\r')){ + if ((ch == '\n' && last_ch == '\r') || + ((ch == agent->reply_end_char) && (agent->reply_end_char)) || + ((read_len == agent->reply_char_num) && (agent->reply_char_num))){ if (is_full){ printf("read line failed. The line data length is out of buffer size(%d)!", agent->maintain_max); memset(agent->maintain_buffer, 0x00, agent->maintain_max); agent->maintain_len = 0; return -ERROR; } - printf("GetCompleteATReply get n r ...\n"); + printf("GetCompleteATReply done\n"); break; } last_ch = ch; @@ -349,13 +375,15 @@ static int ATAgentInit(ATAgentType agent) UtaskType at_utask; agent->maintain_len = 0; - agent->maintain_buffer = (char *)malloc(agent->maintain_max); + agent->maintain_buffer = (char *)PrivMalloc(agent->maintain_max); if (agent->maintain_buffer == NONE){ printf("ATAgentInit malloc maintain_buffer error\n"); goto __out; } + memset(agent->maintain_buffer, 0, agent->maintain_max); + result = PrivSemaphoreCreate(&agent->entm_rx_notice, 0, 0); if (result < 0){ printf("ATAgentInit create entm sem error\n"); @@ -381,11 +409,6 @@ static int ATAgentInit(ATAgentType agent) PrivTaskCreate(&agent->at_handler, &attr, ATAgentReceiveProcess, agent); - // 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 result; __out: @@ -437,7 +460,7 @@ ATReplyType CreateATReply(uint32 reply_max_len) { ATReplyType reply = NULL; - reply = (ATReplyType)malloc(sizeof(struct ATReply)); + reply = (ATReplyType)PrivMalloc(sizeof(struct ATReply)); if (reply == NULL){ printf("no more memory\n"); return NULL; @@ -445,13 +468,15 @@ ATReplyType CreateATReply(uint32 reply_max_len) reply->reply_max_len = reply_max_len; - reply->reply_buffer = (char *)malloc(reply_max_len); + reply->reply_buffer = (char *)PrivMalloc(reply_max_len); if (reply->reply_buffer == NULL){ printf("no more memory\n"); PrivFree(reply); return NULL; } - memset(reply->reply_buffer,0,reply_max_len); + + memset(reply->reply_buffer, 0, reply_max_len); + return reply; } @@ -469,6 +494,3 @@ void DeleteATReply(ATReplyType reply) reply = NULL; } } - - - diff --git a/APP_Framework/Framework/connection/at_agent.h b/APP_Framework/Framework/connection/at_agent.h index 4d5b5fd5..d9acd71e 100755 --- a/APP_Framework/Framework/connection/at_agent.h +++ b/APP_Framework/Framework/connection/at_agent.h @@ -52,6 +52,8 @@ struct ATAgent int lock; ATReplyType reply; + char reply_end_char; + uint32 reply_char_num; int rsp_sem; pthread_t at_handler; @@ -67,6 +69,8 @@ typedef struct ATAgent *ATAgentType; int EntmSend(ATAgentType agent, const char *data, int len); int EntmRecv(ATAgentType agent, char *rev_buffer, int buffer_len, int timeout_s); char *GetReplyText(ATReplyType reply); +int AtSetReplyEndChar(ATAgentType agent, char ch); +int AtSetReplyCharNum(ATAgentType agent, unsigned int num); ATReplyType CreateATReply(uint32 reply_max_len); uint IpTint(char *ipstr); void SwapStr(char *str, int begin, int end); diff --git a/APP_Framework/Framework/connection/bluetooth/HC08/Kconfig b/APP_Framework/Framework/connection/bluetooth/HC08/Kconfig index d8b858a6..0a220dad 100644 --- a/APP_Framework/Framework/connection/bluetooth/HC08/Kconfig +++ b/APP_Framework/Framework/connection/bluetooth/HC08/Kconfig @@ -3,6 +3,14 @@ config ADAPTER_BLUETOOTH_HC08 default "hc08" if ADD_XIUOS_FETURES + config ADAPTER_HC08_RECV_BUFFER_SIZE + int "HC08 recv data buffer size" + default "128" + + config ADAPTER_HC08_WORK_ROLE + string "HC08 work role M(MASTER) or S(SLAVER)" + default "M" + config ADAPTER_HC08_DRIVER_EXTUART bool "Using extra uart to support bluetooth" default n diff --git a/APP_Framework/Framework/connection/bluetooth/HC08/hc08.c b/APP_Framework/Framework/connection/bluetooth/HC08/hc08.c index e99a499e..d2d94ee0 100644 --- a/APP_Framework/Framework/connection/bluetooth/HC08/hc08.c +++ b/APP_Framework/Framework/connection/bluetooth/HC08/hc08.c @@ -21,20 +21,174 @@ #include #include -static int rx_sem; -static sem_t *hc08_sem; -static pthread_t hc08_recv_thread; +#define HC08_DETECT_CMD "AT" +#define HC08_DEFAULT_CMD "AT+DEFAULT" +#define HC08_RESET_CMD "AT+RESET" +#define HC08_CLEAR_CMD "AT+CLEAR" +#define HC08_GET_DEVICE_INFO "AT+RX" -void Hc08RecvThreadEntry(void *parameter) +#define HC08_GET_BAUDRATE_CMD "AT+BAUD=?" +#define HC08_SET_BAUDRATE_CMD "AT+BAUD=%u" +#define HC08_GET_CONNECTABLE "AT+CONT=?" +#define HC08_SET_CONNECTABLE "AT+CONT=%s" +#define HC08_GET_ROLE_CMD "AT+ROLE=?" +#define HC08_SET_ROLE_CMD "AT+ROLE=%s" +#define HC08_GET_ADDR_CMD "AT+ADDR=?" +#define HC08_SET_ADDR_CMD "AT+ADDR=%s" +#define HC08_GET_NAME_CMD "AT+NAME=%s" +#define HC08_SET_NAME_CMD "AT+NAME=?" + +#define HC08_OK_RESP "OK" + +#define HC08_CMD_STR_DEFAULT_SIZE 64 +#define HC08_RESP_DEFAULT_SIZE 64 + +enum Hc08AtCmd { + HC08_AT_CMD_DETECT = 0, + HC08_AT_CMD_DEFAULT, + HC08_AT_CMD_RESET, + HC08_AT_CMD_CLEAR, + HC08_AT_CMD_GET_DEVICE_INFO, + HC08_AT_CMD_GET_BAUDRATE, + HC08_AT_CMD_SET_BAUDRATE, + HC08_AT_CMD_SET_CONNECTABLE, + HC08_AT_CMD_GET_CONNECTABLE, + HC08_AT_CMD_SET_ROLE, + HC08_AT_CMD_GET_ROLE, + HC08_AT_CMD_SET_ADDR, + HC08_AT_CMD_GET_ADDR, + HC08_AT_CMD_SET_NAME, + HC08_AT_CMD_GET_NAME, + HC08_AT_CMD_END, +}; - while (1) +static int Hc08CheckMacHex(char *hex, int len) +{ + int i = 0; + while (i < len) { - PrivRead(adapter->fd, buf, len); - - UserSemaphoreAbandon(rx_sem); - + if ((hex[i] >= 'A' && hex[i] <= 'F') || + (hex[i] >= 'a' && hex[i] <= 'f') || + (hex[i] >= '0' && hex[i] <= '9')) + { + i++; + continue; + } + return -1; } + return 0; +} + +//HC08 AT cmd function +static int Hc08AtConfigure(ATAgentType agent, enum Hc08AtCmd hc08_at_cmd, void *param, char *reply_info) +{ + const char *result_buf; + char *connectable, *role; + unsigned int baudrate; + char reply_ok_flag = 1; + char cmd_str[HC08_CMD_STR_DEFAULT_SIZE] = {0}; + + ATReplyType reply = CreateATReply(64); + if (NULL == reply) { + printf("Hc08AtConfigure CreateATReply failed !\n"); + return -ENOMEMORY; + } + + switch (hc08_at_cmd) + { + case HC08_AT_CMD_DETECT: + AtSetReplyEndChar(agent, 0x4B); + ATOrderSend(agent, REPLY_TIME_OUT, reply, HC08_DETECT_CMD); + break; + case HC08_AT_CMD_DEFAULT: + AtSetReplyEndChar(agent, 0x4B); + ATOrderSend(agent, REPLY_TIME_OUT, reply, HC08_DEFAULT_CMD); + break; + case HC08_AT_CMD_RESET: + AtSetReplyEndChar(agent, 0x4B); + ATOrderSend(agent, REPLY_TIME_OUT, reply, HC08_RESET_CMD); + break; + case HC08_AT_CMD_CLEAR: + AtSetReplyEndChar(agent, 0x4B); + ATOrderSend(agent, REPLY_TIME_OUT, reply, HC08_CLEAR_CMD); + break; + case HC08_AT_CMD_GET_DEVICE_INFO: + ATOrderSend(agent, REPLY_TIME_OUT, reply, HC08_GET_DEVICE_INFO); + reply_ok_flag = 0; + break; + case HC08_AT_CMD_SET_BAUDRATE: + baudrate = *(unsigned int *)param; + sprintf(cmd_str, HC08_SET_BAUDRATE_CMD, baudrate); + strcat(cmd_str, ",N"); + AtSetReplyEndChar(agent, 0x45); + ATOrderSend(agent, REPLY_TIME_OUT, reply, cmd_str); + reply_ok_flag = 0; + break; + case HC08_AT_CMD_GET_BAUDRATE: + AtSetReplyEndChar(agent, 0x4E); + ATOrderSend(agent, REPLY_TIME_OUT, reply, HC08_GET_BAUDRATE_CMD); + reply_ok_flag = 0; + break; + case HC08_AT_CMD_SET_CONNECTABLE: + connectable = (char *)param; + sprintf(cmd_str, HC08_SET_CONNECTABLE, connectable); + AtSetReplyEndChar(agent, 0x4B); + ATOrderSend(agent, REPLY_TIME_OUT, reply, cmd_str); + break; + case HC08_AT_CMD_GET_CONNECTABLE: + AtSetReplyEndChar(agent, 0x65); + ATOrderSend(agent, REPLY_TIME_OUT, reply, HC08_GET_CONNECTABLE); + reply_ok_flag = 0; + break; + case HC08_AT_CMD_SET_ROLE: + role = (char *)param; + sprintf(cmd_str, HC08_SET_ROLE_CMD, role); + AtSetReplyCharNum(agent, 1); + ATOrderSend(agent, REPLY_TIME_OUT, reply, cmd_str); + break; + case HC08_AT_CMD_GET_ROLE: + AtSetReplyCharNum(agent, 1); + ATOrderSend(agent, REPLY_TIME_OUT, reply, HC08_GET_ROLE_CMD); + reply_ok_flag = 0; + break; + // case HC08_AT_CMD_SET_ADDR: + // ATOrderSend(agent, REPLY_TIME_OUT, reply, HC08_SET_ROLE_CMD); + // break; + // case HC08_AT_CMD_GET_ADDR: + // ATOrderSend(agent, REPLY_TIME_OUT, reply, HC08_GET_ROLE_CMD); + // reply_ok_flag = 0; + // break; + // case HC08_AT_CMD_SET_NAME: + // ATOrderSend(agent, REPLY_TIME_OUT, reply, HC08_SET_NAME_CMD); + // break; + // case HC08_AT_CMD_GET_NAME: + // ATOrderSend(agent, REPLY_TIME_OUT, reply, HC08_GET_NAME_CMD); + // reply_ok_flag = 0; + // break; + default: + printf("hc08 do not support no.%d cmd\n", hc08_at_cmd); + DeleteATReply(reply); + return -1; + } + + PrivTaskDelay(200); + + result_buf = GetReplyText(reply); + + if (reply_ok_flag) { + if (!strstr(HC08_OK_RESP, result_buf)) { + printf("%u cmd get reply OK failed:get reply %s\n", hc08_at_cmd, result_buf); + } + } + + if (reply_info) { + strncpy(reply_info, result_buf, reply->reply_len); + } + + DeleteATReply(reply); + + return 0; } static int Hc08Open(struct Adapter *adapter) @@ -44,16 +198,17 @@ static int Hc08Open(struct Adapter *adapter) return 0; } - /*step1: open hc08 serial port*/ + //step1: open hc08 serial port adapter->fd = PrivOpen(ADAPTER_HC08_DRIVER, O_RDWR); if (adapter->fd < 0) { printf("Hc08Open get serial %s fd error\n", ADAPTER_HC08_DRIVER); return -1; } - /*step2: init AT agent*/ + //step2: init AT agent if (!adapter->agent) { char *agent_name = "bluetooth_uart_client"; + printf("InitATAgent agent_name %s fd %u\n", agent_name, adapter->fd); if (EOK != InitATAgent(agent_name, adapter->fd, 512)) { printf("at agent init failed !\n"); return -1; @@ -61,14 +216,15 @@ static int Hc08Open(struct Adapter *adapter) ATAgentType at_agent = GetATAgent(agent_name); adapter->agent = at_agent; + + printf("Hc08Open adapter agent %p\n", adapter->agent); } - /*step3: create bluetooth receive task*/ - PrivSemaphoreCreate(hc08_sem, 0, rx_sem); - - PrivTaskCreate(&hc08_recv_thread, NULL, Hc08RecvThreadEntry, NULL); + PrivTaskDelay(200); ADAPTER_DEBUG("Hc08 open done\n"); + + return 0; } static int Hc08Close(struct Adapter *adapter) @@ -83,6 +239,7 @@ static int Hc08Ioctl(struct Adapter *adapter, int cmd, void *args) return -1; } + char hc08_baudrate[HC08_RESP_DEFAULT_SIZE] = {0}; uint32_t baud_rate = *((uint32_t *)args); struct SerialDataCfg serial_cfg; @@ -104,6 +261,24 @@ static int Hc08Ioctl(struct Adapter *adapter, int cmd, void *args) ioctl_cfg.args = &serial_cfg; PrivIoctl(adapter->fd, OPE_INT, &ioctl_cfg); + //Step1 : detect hc08 serial function + if (Hc08AtConfigure(adapter->agent, HC08_AT_CMD_DETECT, NULL, NULL) < 0) { + return -1; + } + + //Step2 : set hc08 device serial baud, hc08_set_baud send "AT+BAUD=%s" + if (Hc08AtConfigure(adapter->agent, HC08_AT_CMD_SET_BAUDRATE, args, NULL) < 0) { + return -1; + } + + PrivTaskDelay(200); + + //Step3 : show hc08 device info, hc08_get send "AT+RX" response device info + char device_info[HC08_RESP_DEFAULT_SIZE * 2] = {0}; + if (Hc08AtConfigure(adapter->agent, HC08_AT_CMD_GET_DEVICE_INFO, NULL, device_info) < 0) { + return -1; + } + ADAPTER_DEBUG("Hc08 ioctl done\n"); return 0; @@ -111,28 +286,105 @@ static int Hc08Ioctl(struct Adapter *adapter, int cmd, void *args) static int Hc08SetAddr(struct Adapter *adapter, const char *ip, const char *gateway, const char *netmask) { + char mac_addr[HC08_RESP_DEFAULT_SIZE] = {0}; + + //Step1 : hc08_get_addr send "AT+ADDR=?" response mac "XX,XX,XX,XX,XX,XX" + if (Hc08AtConfigure(adapter->agent, HC08_AT_CMD_GET_ADDR, NULL, mac_addr) < 0) { + return -1; + } + printf("HC08 old mac addr: %s\n", mac_addr); + + //Step2 : hc08_set_addr send "AT+ADDR=%s" response "OK" + if (!Hc08CheckMacHex((char *)gateway, 12)) { + if (Hc08AtConfigure(adapter->agent, HC08_AT_CMD_SET_ADDR, (void *)gateway, NULL) < 0) { + return -1; + } + } + + //Step3 : check mac addr, hc08_get_addr send "AT+ADDR=?" response mac "XX,XX,XX,XX,XX,XX" + if (Hc08AtConfigure(adapter->agent, HC08_AT_CMD_GET_ADDR, NULL, mac_addr) < 0) { + return -1; + } + + printf("HC08 new mac addr: %s\n", mac_addr); + + return 0; } static int Hc08Connect(struct Adapter *adapter, enum NetRoleType net_role, const char *ip, const char *port, enum IpType ip_type) -{ +{ + char connect_status[HC08_RESP_DEFAULT_SIZE] = {0}; + + //Step1 : hc08_detect send "AT" response "OK" + if (Hc08AtConfigure(adapter->agent, HC08_AT_CMD_DETECT, NULL, NULL) < 0) { + return -1; + } + //Step2 : hc08_set_role send "AT+ROLE=%s" response "OK" + if (Hc08AtConfigure(adapter->agent, HC08_AT_CMD_SET_ROLE, ADAPTER_HC08_WORK_ROLE, NULL) < 0) { + return -1; + } + + //Step3 : hc08_connectable send "AT+CONT=0" response "OK" + if (Hc08AtConfigure(adapter->agent, HC08_AT_CMD_SET_CONNECTABLE, "0", NULL) < 0) { + return -1; + } + + //Step4 : check connectable status,hc08_connectable send "AT+CONT=?" response "Connectable" + if (Hc08AtConfigure(adapter->agent, HC08_AT_CMD_GET_CONNECTABLE, NULL, connect_status) < 0) { + return -1; + } + + printf("Hc08Connect status %s\n", connect_status); + + return 0; } static int Hc08Send(struct Adapter *adapter, const void *buf, size_t len) { - PrivWrite(adapter->fd, buf, len); + x_err_t result = EOK; + if (adapter->agent) { + EntmSend(adapter->agent, (const char *)buf, len); + }else { + printf("Hc08Send can not find agent\n"); + } return 0; } static int Hc08Recv(struct Adapter *adapter, void *buf, size_t len) { - return 0; + if (adapter->agent) { + return EntmRecv(adapter->agent, (char *)buf, len, 40000); + } else { + printf("Hc08Recv can not find agent\n"); + } + + return -1; } static int Hc08Disconnect(struct Adapter *adapter) { + char connect_status[HC08_RESP_DEFAULT_SIZE] = {0}; + //Step1 : hc08_detect send "AT" response "OK" + if (Hc08AtConfigure(adapter->agent, HC08_AT_CMD_DETECT, NULL, NULL) < 0) { + return -1; + } + + //Step2 : hc08_connectable send "AT+CONT=1" response "OK" + if (Hc08AtConfigure(adapter->agent, HC08_AT_CMD_SET_CONNECTABLE, "1", NULL) < 0) { + return -1; + } + + //Step3 : check connectable status,hc08_connectable send "AT+CONT=?" response "Not-Connectable" + if (Hc08AtConfigure(adapter->agent, HC08_AT_CMD_GET_CONNECTABLE, NULL, connect_status) < 0) { + return -1; + } + + printf("Hc08Disconnect status %s\n", connect_status); + + return 0; } static const struct IpProtocolDone hc08_done = @@ -155,14 +407,22 @@ static const struct IpProtocolDone hc08_done = AdapterProductInfoType Hc08Attach(struct Adapter *adapter) { - struct AdapterProductInfo *product_info = malloc(sizeof(struct AdapterProductInfo)); + struct AdapterProductInfo *product_info = PrivMalloc(sizeof(struct AdapterProductInfo)); if (!product_info) { printf("Hc08Attach malloc product_info error\n"); free(product_info); return NULL; } + + if ("M" == ADAPTER_HC08_WORK_ROLE) { + adapter->net_role = MASTER; + } else if ("S" == ADAPTER_HC08_WORK_ROLE) { + adapter->net_role = SLAVE; + } else { + adapter->net_role = ROLE_NONE; + } - product_info->model_name = ADAPTER_BLUETOOTH_HC08; + strcpy(product_info->model_name, ADAPTER_BLUETOOTH_HC08); product_info->model_done = (void *)&hc08_done; diff --git a/APP_Framework/Framework/connection/bluetooth/adapter_bluetooth.c b/APP_Framework/Framework/connection/bluetooth/adapter_bluetooth.c index 9ac60d27..f75bd377 100644 --- a/APP_Framework/Framework/connection/bluetooth/adapter_bluetooth.c +++ b/APP_Framework/Framework/connection/bluetooth/adapter_bluetooth.c @@ -17,3 +17,96 @@ * @author AIIT XUOS Lab * @date 2021.06.25 */ + +#include + +#ifdef ADAPTER_HC08 +extern AdapterProductInfoType Hc08Attach(struct Adapter *adapter); +#endif + +#define ADAPTER_BLUETOOTH_NAME "BlueTooth" + +static int AdapterBlueToothRegister(struct Adapter *adapter) +{ + int ret = 0; + + strncpy(adapter->name, ADAPTER_BLUETOOTH_NAME, NAME_NUM_MAX); + + adapter->net_protocol = IP_PROTOCOL; + adapter->adapter_status = UNREGISTERED; + + ret = AdapterDeviceRegister(adapter); + if (ret < 0) { + printf("AdapterBlueToothRegister register error\n"); + return -1; + } + + return ret; +} + +int AdapterBlueToothInit(void) +{ + int ret = 0; + + struct Adapter *adapter = PrivMalloc(sizeof(struct Adapter)); + if (!adapter) { + free(adapter); + return -1; + } + + memset(adapter, 0, sizeof(struct Adapter)); + + ret = AdapterBlueToothRegister(adapter); + if (ret < 0) { + printf("AdapterBlueToothInit register BT adapter error\n"); + free(adapter); + return -1; + } + +#ifdef ADAPTER_HC08 + AdapterProductInfoType product_info = Hc08Attach(adapter); + if (!product_info) { + printf("AdapterBlueToothInit hc08 attach error\n"); + free(adapter); + return -1; + } + + adapter->product_info_flag = 1; + adapter->info = product_info; + adapter->done = product_info->model_done; + +#endif + + return ret; +} + +/******************4G TEST*********************/ +int AdapterBlueToothTest(void) +{ + const char *bluetooth_msg = "BT Adapter Test"; + char bluetooth_recv_msg[128]; + char recv_msg[128]; + int len; + int baud_rate = BAUD_RATE_115200; + + struct Adapter *adapter = AdapterDeviceFindByName(ADAPTER_BLUETOOTH_NAME); + +#ifdef ADAPTER_HC08 + AdapterDeviceOpen(adapter); + AdapterDeviceControl(adapter, OPE_INT, &baud_rate); + + len = strlen(bluetooth_msg); + + while (1) { + AdapterDeviceRecv(adapter, bluetooth_recv_msg, 128); + printf("bluetooth_recv_msg %s\n", bluetooth_recv_msg); + AdapterDeviceSend(adapter, bluetooth_msg, len); + printf("send %s after recv\n", bluetooth_msg); + PrivTaskDelay(100); + } + +#endif + + return 0; +} +SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, AdapterBlueToothTest, AdapterBlueToothTest, show adapter BT information); diff --git a/APP_Framework/Framework/connection/wifi/HFA21/hfa21.c b/APP_Framework/Framework/connection/wifi/HFA21/hfa21.c index 5a002945..0d1d18e3 100755 --- a/APP_Framework/Framework/connection/wifi/HFA21/hfa21.c +++ b/APP_Framework/Framework/connection/wifi/HFA21/hfa21.c @@ -501,7 +501,7 @@ static const struct IpProtocolDone hfa21_done = */ AdapterProductInfoType Hfa21Attach(struct Adapter *adapter) { - struct AdapterProductInfo *product_info = malloc(sizeof(struct AdapterProductInfo)); + struct AdapterProductInfo *product_info = PrivMalloc(sizeof(struct AdapterProductInfo)); if (!product_info) { printf("Hfa21Attach Attach malloc product_info error\n"); PrivFree(product_info); diff --git a/APP_Framework/Framework/connection/wifi/adapter_wifi.c b/APP_Framework/Framework/connection/wifi/adapter_wifi.c index 2f329d0c..379c7e3f 100644 --- a/APP_Framework/Framework/connection/wifi/adapter_wifi.c +++ b/APP_Framework/Framework/connection/wifi/adapter_wifi.c @@ -49,13 +49,15 @@ int AdapterWifiInit(void) { int ret = 0; - struct Adapter *adapter = malloc(sizeof(struct Adapter)); + struct Adapter *adapter = PrivMalloc(sizeof(struct Adapter)); if (!adapter) { printf("AdapterWifiInit malloc error\n"); free(adapter); return -1; } + memset(adapter, 0, sizeof(struct Adapter)); + ret = AdapterWifiRegister(adapter); if (ret < 0) { printf("AdapterWifiInit register wifi adapter error\n"); diff --git a/Ubiquitous/XiUOS/board/stm32f407-st-discovery/third_party_driver/uart/Kconfig b/Ubiquitous/XiUOS/board/stm32f407-st-discovery/third_party_driver/uart/Kconfig index 9ad064d6..79ce0890 100644 --- a/Ubiquitous/XiUOS/board/stm32f407-st-discovery/third_party_driver/uart/Kconfig +++ b/Ubiquitous/XiUOS/board/stm32f407-st-discovery/third_party_driver/uart/Kconfig @@ -52,7 +52,7 @@ menuconfig BSP_USING_UART4 default "uart4" config SERIAL_DRV_NAME_4 string "serial bus 4 driver name" - default "uart4drv" + default "uart4_drv" config SERIAL_4_DEVICE_NAME_0 string "serial bus 4 device 0 name" default "uart4_dev4"