diff --git a/APP_Framework/Applications/framework_init.c b/APP_Framework/Applications/framework_init.c index d0915952..d21aeb7a 100644 --- a/APP_Framework/Applications/framework_init.c +++ b/APP_Framework/Applications/framework_init.c @@ -17,6 +17,7 @@ extern int SensorFrameworkInit(void); extern int AdapterFrameworkInit(void); extern int Adapter4GInit(void); +extern int AdapterNbiotInit(void); extern int AdapterBlueToothInit(void); extern int AdapterWifiInit(void); extern int AdapterZigbeeInit(void); @@ -94,6 +95,9 @@ static struct InitDesc connection_desc[] = #ifdef CONNECTION_ADAPTER_4G { "4G adpter", Adapter4GInit}, #endif +#ifdef CONNECTION_ADAPTER_NB + { "NB adpter", AdapterNbiotInit}, +#endif #ifdef CONNECTION_ADAPTER_ZIGBEE { "zigbee adpter", AdapterZigbeeInit}, #endif diff --git a/APP_Framework/Framework/connection/at_agent.h b/APP_Framework/Framework/connection/at_agent.h index d9acd71e..f686e954 100755 --- a/APP_Framework/Framework/connection/at_agent.h +++ b/APP_Framework/Framework/connection/at_agent.h @@ -81,6 +81,6 @@ int ParseATReply(char* str, const char *format, ...); void DeleteATReply(ATReplyType reply); int ATOrderSend(ATAgentType agent, uint32 timeout_s, ATReplyType reply, const char *cmd_expr, ...); -#define REPLY_TIME_OUT 3000 +#define REPLY_TIME_OUT 3 #endif \ No newline at end of file diff --git a/APP_Framework/Framework/connection/bluetooth/HC08/hc08.c b/APP_Framework/Framework/connection/bluetooth/HC08/hc08.c index d2d94ee0..1ad4595e 100644 --- a/APP_Framework/Framework/connection/bluetooth/HC08/hc08.c +++ b/APP_Framework/Framework/connection/bluetooth/HC08/hc08.c @@ -355,7 +355,7 @@ static int Hc08Send(struct Adapter *adapter, const void *buf, size_t len) static int Hc08Recv(struct Adapter *adapter, void *buf, size_t len) { if (adapter->agent) { - return EntmRecv(adapter->agent, (char *)buf, len, 40000); + return EntmRecv(adapter->agent, (char *)buf, len, 40); } else { printf("Hc08Recv can not find agent\n"); } diff --git a/APP_Framework/Framework/connection/nbiot/BC28/Kconfig b/APP_Framework/Framework/connection/nbiot/BC28/Kconfig index 3b034198..b4224090 100644 --- a/APP_Framework/Framework/connection/nbiot/BC28/Kconfig +++ b/APP_Framework/Framework/connection/nbiot/BC28/Kconfig @@ -3,8 +3,8 @@ config ADAPTER_NBIOT_BC28 default "bc28" if ADD_XIUOS_FETURES - config ADAPTER_BC28_PWRKEY - int "BC28 PWRKEY pin number" + config ADAPTER_BC28_RESETPIN + int "BC28 RESET pin number" default "100" config ADAPTER_BC28_PIN_DRIVER @@ -23,11 +23,11 @@ if ADD_XIUOS_FETURES if ADAPTER_BC28_DRIVER_EXTUART config ADAPTER_BC28_DRIVER string "BC28 device extra uart driver path" - default "/dev/extuart_dev0" + default "/dev/extuart_dev5" config ADAPTER_BC28_DRIVER_EXT_PORT int "if BC28 device using extuart, choose port" - default "0" + default "5" endif endif diff --git a/APP_Framework/Framework/connection/nbiot/BC28/bc28.c b/APP_Framework/Framework/connection/nbiot/BC28/bc28.c index 4c9ca13d..142d6587 100644 --- a/APP_Framework/Framework/connection/nbiot/BC28/bc28.c +++ b/APP_Framework/Framework/connection/nbiot/BC28/bc28.c @@ -30,6 +30,38 @@ #define SOCKET_INVALID_ID (-1) +static int AtCmdConfigAndCheck(ATAgentType agent, char *cmd, char *check) +{ + char *result = NULL; + if (NULL == agent || NULL == cmd || NULL == check ) { + return -1; + } + + ATReplyType reply = CreateATReply(64); + if (NULL == reply) { + printf("%s %d at_create_resp failed!\n",__func__,__LINE__); + return -1; + } + + ATOrderSend(agent, REPLY_TIME_OUT, reply, cmd); + PrivTaskDelay(300); + + result = GetReplyText(reply); + if (!result) { + printf("%s %n get reply failed.\n",__func__,__LINE__); + goto __exit; + } + if(0 != strncmp(result, check, strlen(check))) { + printf("%s %d check[%s] reply[%s] failed.\n",__func__,__LINE__,check,result); + goto __exit; + } + return 0; + +__exit: + DeleteATReply(reply); + return -1; +} + static int BC28UartOpen(struct Adapter *adapter) { if (NULL == adapter) { @@ -80,7 +112,7 @@ static void BC28PowerSet(void) struct PinParam pin_param; pin_param.cmd = GPIO_CONFIG_MODE; pin_param.mode = GPIO_CFG_OUTPUT; - pin_param.pin = ADAPTER_BC28_PWRKEY; + pin_param.pin = ADAPTER_BC28_RESETPIN; struct PrivIoctlCfg ioctl_cfg; ioctl_cfg.ioctl_driver_type = PIN_TYPE; @@ -88,7 +120,7 @@ static void BC28PowerSet(void) PrivIoctl(pin_fd, OPE_CFG, &ioctl_cfg); struct PinStat pin_stat; - pin_stat.pin = ADAPTER_BC28_PWRKEY; + pin_stat.pin = ADAPTER_BC28_RESETPIN; pin_stat.val = GPIO_HIGH; PrivWrite(pin_fd, &pin_stat, 1); @@ -115,22 +147,15 @@ int NBIoTSocketCreate(struct Adapter *adapter, struct Socket *socket ) return -1; } - ATReplyType reply = CreateATReply(64); - if (NULL == reply) { - printf("at create failed ! \n"); - result = -1; - goto __exit; - } - if ( socket->af_type == NET_TYPE_AF_INET6 ) { printf("IPv6 not surport !\n"); result = -1; - goto __exit; + goto out; } char *str_af_type = "AF_INET"; char *str_type; - char str_fd[3] = {0}; + char str_fd[3] = {1}; char *str_protocol ; char at_cmd[64] = {0}; char listen_port[] = {0}; @@ -141,7 +166,7 @@ int NBIoTSocketCreate(struct Adapter *adapter, struct Socket *socket ) } else { printf("surport max 0-6, socket_id = [%d] is error!\n",socket->socket_id); result = -1; - goto __exit; + goto out; } if( socket->listen_port >= 0 && socket->listen_port <= 65535){ @@ -154,18 +179,18 @@ int NBIoTSocketCreate(struct Adapter *adapter, struct Socket *socket ) adapter->socket.protocal = SOCKET_PROTOCOL_TCP; adapter->socket.type = SOCKET_TYPE_STREAM; str_type = "STREAM"; - char *str_protocol = "6"; + str_protocol = "6"; } else if ( socket->type == SOCKET_TYPE_DGRAM ){ //udp adapter->socket.type = SOCKET_TYPE_DGRAM; adapter->socket.protocal = SOCKET_PROTOCOL_UDP; str_type = "DGRAM"; - char *str_protocol = "17"; + str_protocol = "17"; } else { printf("error socket type \n"); result = -1; - goto __exit; + goto out; } memcpy(at_cmd, "AT+NSOCR=", 9); @@ -181,18 +206,13 @@ int NBIoTSocketCreate(struct Adapter *adapter, struct Socket *socket ) strcat(at_cmd, "\n"); printf("cmd : %s\n", at_cmd); - ATOrderSend(adapter->agent, REPLY_TIME_OUT, reply, at_cmd); - PrivTaskDelay(3000); - printf("bak : "); - for(int i = 0; i < strlen(reply->reply_buffer); i++) - printf(" 0x%02x", reply->reply_buffer[i]); - printf("\n"); - -__exit: - if (reply) { - DeleteATReply(reply); + result = AtCmdConfigAndCheck(adapter->agent, at_cmd, "OK"); + if(result < 0) { + printf("%s %d cmd[%s] config failed!\n",__func__,__LINE__,at_cmd); + result = -1; } +out: return result; } @@ -204,23 +224,14 @@ __exit: */ int NBIoTSocketDelete(struct Adapter *adapter ) { - int result = 0; - if (!adapter){ + if (!adapter) { return -1; } - ATReplyType reply = CreateATReply(64); - if (NULL == reply) { - printf("at create failed ! \n"); - result = -1; - goto __exit; - } - if (adapter->socket.socket_id >= 7) { printf("socket fd error \n"); - result = -1; - goto __exit; + return -1; } char str_fd[2] = {0}; @@ -232,17 +243,12 @@ int NBIoTSocketDelete(struct Adapter *adapter ) strcat(at_cmd, "\n"); printf("cmd : %s\n", at_cmd); - ATOrderSend(adapter->agent, REPLY_TIME_OUT, reply, at_cmd); + ATOrderSend(adapter->agent, REPLY_TIME_OUT, NULL, at_cmd); PrivTaskDelay(300); adapter->socket.socket_id = SOCKET_INVALID_ID; -__exit: - if (reply) { - DeleteATReply(reply); - } - - return result; + return 0; } static int BC28Open(struct Adapter *adapter) @@ -322,13 +328,6 @@ static int BC28Connect(struct Adapter *adapter, enum NetRoleType net_role, const { int result = 0; - ATReplyType reply = CreateATReply(64); - if (NULL == reply) { - printf("at create failed ! \n"); - result = -1; - goto __exit; - } - if (adapter->socket.socket_id > 6) { printf("socket fd error \n"); result = -1; @@ -337,6 +336,8 @@ static int BC28Connect(struct Adapter *adapter, enum NetRoleType net_role, const if ( ip_type != SOCKET_TYPE_STREAM) { printf("socket type error \n"); + result = -1; + goto __exit; } char at_cmd[64] = {0}; @@ -353,32 +354,25 @@ static int BC28Connect(struct Adapter *adapter, enum NetRoleType net_role, const strcat(at_cmd, "\n"); printf("cmd : %s\n", at_cmd); - ATOrderSend(adapter->agent, REPLY_TIME_OUT, reply, at_cmd); - PrivTaskDelay(300); - -__exit: - if (reply) { - DeleteATReply(reply); + result = AtCmdConfigAndCheck(adapter->agent, at_cmd, "OK"); + if(result < 0) { + printf("%s %d cmd[%s] config failed!\n",__func__,__LINE__,at_cmd); + result = -1; } +__exit: return result; } static int BC28Send(struct Adapter *adapter, const void *buf, size_t len) { uint32_t result = 0; + char at_cmd[64] = {0}; + char str_fd[2] = {0}; - ATReplyType reply = CreateATReply(64); - if (NULL == reply) { - printf("at create failed ! \n"); - result = -ERROR; - goto __exit; - } if (adapter->socket.type == SOCKET_TYPE_STREAM ) { - - char at_cmd[64] = {0}; - char str_fd[2] = {0}; + char size[2] = {0}; itoa(adapter->socket.socket_id, str_fd, 10); @@ -392,13 +386,8 @@ static int BC28Send(struct Adapter *adapter, const void *buf, size_t len) strcat(at_cmd, buf); strcat(at_cmd, "\n"); - printf("cmd : %s\n", at_cmd); - ATOrderSend(adapter->agent, REPLY_TIME_OUT, reply, at_cmd); - PrivTaskDelay(300); - } else if(adapter->socket.type == SOCKET_TYPE_DGRAM ) { - char at_cmd[64] = {0}; - char str_fd[2] = {0}; + char listen_port[] = {0}; itoa(adapter->socket.socket_id, str_fd, 10); @@ -415,14 +404,13 @@ static int BC28Send(struct Adapter *adapter, const void *buf, size_t len) strcat(at_cmd, buf); strcat(at_cmd, "\n"); - printf("cmd : %s\n", at_cmd); - ATOrderSend(adapter->agent, REPLY_TIME_OUT, reply, at_cmd); - PrivTaskDelay(300); } -__exit: - if (reply) { - DeleteATReply(reply); + printf("cmd : %s\n", at_cmd); + result = AtCmdConfigAndCheck(adapter->agent, at_cmd, "OK"); + if(result < 0) { + printf("%s %d cmd[%s] config failed!\n",__func__,__LINE__,at_cmd); + result = -1; } return result; diff --git a/APP_Framework/Framework/connection/nbiot/adapter_nbiot.c b/APP_Framework/Framework/connection/nbiot/adapter_nbiot.c index 645469a8..a48eb93f 100644 --- a/APP_Framework/Framework/connection/nbiot/adapter_nbiot.c +++ b/APP_Framework/Framework/connection/nbiot/adapter_nbiot.c @@ -79,66 +79,93 @@ int AdapterNbiotInit(void) } /******************TEST*********************/ -// int openzigbee(void) -// { -// int ret = 0; +int opennb(void) +{ + int ret = 0; -// struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_ZIGBEE_NAME); + struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_NBIOT_NAME); -// #ifdef ADAPTER_E18 -// ret = AdapterDeviceOpen(adapter); -// if(ret < 0){ -// printf("open adapter failed\n"); -// return -1; -// } +#ifdef ADAPTER_BC28 + ret = AdapterDeviceOpen(adapter); + if(ret < 0){ + printf("open adapter failed\n"); + return -1; + } -// adapter->info->work_mode = 1; -// ret = AdapterDeviceControl(adapter, CONFIG_ZIGBEE_NET_MODE,NULL); -// if(ret < 0){ -// printf("control adapter failed\n"); -// return -1; -// } -// ret = AdapterDeviceJoin(adapter, NULL); -// if(ret < 0){ -// printf("join adapter failed\n"); -// return -1; -// } -// #endif +#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, openzigbee, openzigbee, show adapter zigbee information); + 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, opennb, opennb, show adapter nb information); +int closenb(void) +{ + int ret = 0; -// int sendzigbee(int argc, char *argv[]) -// { -// const char *send_msg = argv[1]; -// int ret = 0; + struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_NBIOT_NAME); -// struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_ZIGBEE_NAME); +#ifdef ADAPTER_BC28 + ret = AdapterDeviceClose(adapter); + if(ret < 0){ + printf("open adapter failed\n"); + return -1; + } -// printf("send argv1 %s\n",argv[1]); -// ret = AdapterDeviceSend(adapter, send_msg, strlen(send_msg)); -// if(ret < 0){ -// printf(" adapter send failed\n"); -// return -1; -// } -// printf("zigbee send msg %s\n", send_msg); +#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, closenb, closenb, show adapter nb information); + + int connectnb(int argc, char *argv[]) + { + const char *send_msg = argv[1]; + int ret = 0; + + struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_NBIOT_NAME); + + + ret = AdapterDeviceConnect(adapter, 1, "192.168.131.20","3333",1); + if(ret < 0){ + printf(" adapter send failed\n"); + return -1; + } -// return 0; -// } -// SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(2)|SHELL_CMD_DISABLE_RETURN, sendzigbee, sendzigbee, show adapter zigbee information); -// int recvzigbee(void) -// { -// char recv_msg[128]; -// struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_ZIGBEE_NAME); -// memset(recv_msg,0,128); -// AdapterDeviceRecv(adapter, recv_msg, 128); -// PrivTaskDelay(2000); -// printf("zigbee recv msg %s\n", recv_msg); - -// 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, recvzigbee, recvzigbee, show adapter zigbee information); + return 0; + } + SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(2)|SHELL_CMD_DISABLE_RETURN, connectnb, connectnb, show adapter nb information); + + int sendnb(int argc, char *argv[]) + { + const char *send_msg = argv[1]; + int ret = 0; + + struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_NBIOT_NAME); + + printf("send argv1 %s\n",argv[1]); + ret = AdapterDeviceSend(adapter, send_msg, strlen(send_msg)); + if(ret < 0){ + printf(" adapter send failed\n"); + return -1; + } + printf("nb send msg %s\n", send_msg); + + + return 0; + } + SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(2)|SHELL_CMD_DISABLE_RETURN, sendnb, sendnb, show adapter nb information); + + int recvnb(void) + { + char recv_msg[128]; + struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_NBIOT_NAME); + memset(recv_msg,0,128); + AdapterDeviceRecv(adapter, recv_msg, 128); + PrivTaskDelay(2000); + printf("nb recv msg %s\n", recv_msg); + + 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, recvnb, recvnb, show adapter nb information); diff --git a/APP_Framework/Framework/connection/wifi/HFA21/hfa21.c b/APP_Framework/Framework/connection/wifi/HFA21/hfa21.c index 0d1d18e3..31a12652 100755 --- a/APP_Framework/Framework/connection/wifi/HFA21/hfa21.c +++ b/APP_Framework/Framework/connection/wifi/HFA21/hfa21.c @@ -116,7 +116,7 @@ static int Hfa21Receive(struct Adapter *adapter, void *rev_buffer, size_t buffer printf("hfa21 receive waiting ... \n"); if (adapter->agent) { - return EntmRecv(adapter->agent, (char *)rev_buffer, buffer_len, 40000); + return EntmRecv(adapter->agent, (char *)rev_buffer, buffer_len, 40); } else { printf("Can not find agent \n"); } diff --git a/APP_Framework/Framework/connection/zigbee/E18/e18.c b/APP_Framework/Framework/connection/zigbee/E18/e18.c index b0169588..94049cac 100644 --- a/APP_Framework/Framework/connection/zigbee/E18/e18.c +++ b/APP_Framework/Framework/connection/zigbee/E18/e18.c @@ -388,7 +388,7 @@ static int E18Recv(struct Adapter *adapter, void *buf, size_t len) if(!adapter->agent){ PrivRead(adapter->fd, buf, len); } else { - EntmRecv(adapter->agent, buf, len, 3000);/* wait timeout 3000ms*/ + EntmRecv(adapter->agent, buf, len, 3);/* wait timeout 3000ms*/ } break; case STT_MODE2: