diff --git a/APP_Framework/Framework/connection/SConscript b/APP_Framework/Framework/connection/SConscript new file mode 100644 index 000000000..8b47a1a5d --- /dev/null +++ b/APP_Framework/Framework/connection/SConscript @@ -0,0 +1,21 @@ +import os +Import('RTT_ROOT') +Import('rtconfig') +from building import * + +cwd = GetCurrentDir() +SOURCES = [] +if GetDepend(['SUPPORT_CONNECTION_FRAMEWORK']): + SOURCES = ['adapter.c'] +['adapter_agent.c']+ SOURCES +path = [cwd] +objs = [] +group = DefineGroup('connection', SOURCES, depend = [], CPPPATH = [cwd]) +objs = objs + group +list = os.listdir(cwd) + +for d in list: + path = os.path.join(cwd, d) + if os.path.isfile(os.path.join(path, 'SConscript')): + objs = objs + SConscript(os.path.join(path, 'SConscript')) + +Return('objs') diff --git a/APP_Framework/Framework/connection/adapter.c b/APP_Framework/Framework/connection/adapter.c index 6d3d8f227..96d93c828 100644 --- a/APP_Framework/Framework/connection/adapter.c +++ b/APP_Framework/Framework/connection/adapter.c @@ -22,7 +22,7 @@ static DoublelistType adapter_list; -static int adapter_list_lock; +static pthread_mutex_t adapter_list_lock; /** * @description: Init adapter framework @@ -481,6 +481,7 @@ int AdapterDeviceDisconnect(struct Adapter *adapter, unsigned char *priv_net_gro */ int AdapterDeviceSetUp(struct Adapter *adapter) { + if (!adapter) return -1; @@ -488,10 +489,10 @@ int AdapterDeviceSetUp(struct Adapter *adapter) struct IpProtocolDone *ip_done = NULL; struct PrivProtocolDone *priv_done = NULL; - switch (adapter->net_protocol) { case PRIVATE_PROTOCOL: + priv_done = (struct PrivProtocolDone *)adapter->done; if (NULL == priv_done->setup) return 0; @@ -515,6 +516,7 @@ int AdapterDeviceSetUp(struct Adapter *adapter) return 0; result = ip_done->setup(adapter); + if (0 == result) { printf("Device %s setup success.\n", adapter->name); adapter->adapter_status = INSTALL; diff --git a/APP_Framework/Framework/connection/adapter_agent.c b/APP_Framework/Framework/connection/adapter_agent.c index 8d75767ee..bd86c43ee 100755 --- a/APP_Framework/Framework/connection/adapter_agent.c +++ b/APP_Framework/Framework/connection/adapter_agent.c @@ -29,6 +29,10 @@ #ifdef ADD_XIZI_FETURES # include #endif +#ifdef ADD_RTTHREAD_FETURES +#include +#endif + #define AT_CMD_MAX_LEN 128 #define AT_AGENT_MAX 2 @@ -139,7 +143,7 @@ int ATOrderSend(ATAgentType agent, uint32 timeout_s, ATReplyType reply, const ch PrivMutexObtain(&agent->lock); agent->receive_mode = AT_MODE; - + memset(agent->maintain_buffer, 0x00, agent->maintain_max); agent->maintain_len = 0; @@ -298,7 +302,7 @@ int EntmRecv(ATAgentType agent, char *rev_buffer, int buffer_len, int timeout_s) // PrivTaskDelay(1000); if (PrivSemaphoreObtainWait(&agent->entm_rx_notice, &abstime)) { printf("wait sem[%d] timeout\n",agent->entm_rx_notice); - return -ERROR; + return -1; } PrivMutexObtain(&agent->lock); @@ -382,7 +386,7 @@ static int GetCompleteATReply(ATAgentType agent) memset(agent->maintain_buffer, 0x00, agent->maintain_max); agent->maintain_len = 0; PrivMutexAbandon(&agent->lock); - return -ERROR; + return -1; } printf("GetCompleteATReply done\n"); @@ -424,20 +428,20 @@ int DeleteATAgent(ATAgentType agent) PrivClose(agent->fd); } - if (agent->lock) { - printf("delete agent lock = %d\n",agent->lock); - PrivMutexDelete(&agent->lock); - } + // if (agent->lock) { + // printf("delete agent lock = %d\n",agent->lock); + // PrivMutexDelete(&agent->lock); + // } if (agent->entm_rx_notice) { printf("delete agent entm_rx_notice = %d\n",agent->entm_rx_notice); PrivSemaphoreDelete(&agent->entm_rx_notice); } - if (agent->rsp_sem) { - printf("delete agent rsp_sem = %d\n",agent->rsp_sem); - PrivSemaphoreDelete(&agent->rsp_sem); - } + // if (agent->rsp_sem) { + // printf("delete agent rsp_sem = %d\n",agent->rsp_sem); + // PrivSemaphoreDelete(&agent->rsp_sem); + // } if (agent->maintain_buffer) { PrivFree(agent->maintain_buffer); diff --git a/APP_Framework/Framework/connection/at_agent.h b/APP_Framework/Framework/connection/at_agent.h index 3267698cf..b6641cff4 100755 --- a/APP_Framework/Framework/connection/at_agent.h +++ b/APP_Framework/Framework/connection/at_agent.h @@ -42,7 +42,6 @@ struct ATReply uint32 reply_len; }; typedef struct ATReply *ATReplyType; - struct ATAgent { char agent_name[64]; @@ -53,14 +52,14 @@ struct ATAgent uint32 maintain_len; uint32 maintain_max; - int lock; + pthread_mutex_t lock; ATReplyType reply; char reply_lr_end; char reply_end_last_char; char reply_end_char; uint32 reply_char_num; - int rsp_sem; + sem_t rsp_sem; pthread_t at_handler; diff --git a/APP_Framework/Framework/connection/bluetooth/SConscript b/APP_Framework/Framework/connection/bluetooth/SConscript new file mode 100644 index 000000000..3fecfb61c --- /dev/null +++ b/APP_Framework/Framework/connection/bluetooth/SConscript @@ -0,0 +1,18 @@ +import os +Import('RTT_ROOT') +from building import * +SOURCES = [] +SOURCES = ['adapter_bluetooth.c'] + SOURCES +objs = [] +cwd = GetCurrentDir() +path = [cwd] +group = DefineGroup('bluetooth', SOURCES, depend = [], CPPPATH = [cwd]) +objs = objs + group +list = os.listdir(cwd) + +for d in list: + path = os.path.join(cwd, d) + if os.path.isfile(os.path.join(path, 'SConscript')): + objs = objs + SConscript(os.path.join(path, 'SConscript')) + +Return('objs') \ No newline at end of file diff --git a/APP_Framework/Framework/connection/bluetooth/hc08/Kconfig b/APP_Framework/Framework/connection/bluetooth/hc08/Kconfig index 49a84ed96..8b17e83dd 100644 --- a/APP_Framework/Framework/connection/bluetooth/hc08/Kconfig +++ b/APP_Framework/Framework/connection/bluetooth/hc08/Kconfig @@ -36,5 +36,9 @@ if ADD_NUTTX_FETURES endif if ADD_RTTHREAD_FETURES - + config ADAPTER_HC08_DRIVER + string "HC08 device uart driver path" + default "/dev/uart4" + config ADAPTER_HC08_WORK_ROLE + string "HC08 work role M(MASTER) or S(SLAVER)" endif diff --git a/APP_Framework/Framework/connection/bluetooth/hc08/SConscript b/APP_Framework/Framework/connection/bluetooth/hc08/SConscript new file mode 100644 index 000000000..5f904f361 --- /dev/null +++ b/APP_Framework/Framework/connection/bluetooth/hc08/SConscript @@ -0,0 +1,10 @@ +from building import * +import os + +cwd = GetCurrentDir() +src = [] +if GetDepend(['ADAPTER_HC08']): + src += ['hc08.c'] +group = DefineGroup('connection bluetooth hc08', src, depend = [], CPPPATH = [cwd]) + +Return('group') \ No newline at end of file diff --git a/APP_Framework/Framework/connection/wifi/SConscript b/APP_Framework/Framework/connection/wifi/SConscript new file mode 100644 index 000000000..49378ad9f --- /dev/null +++ b/APP_Framework/Framework/connection/wifi/SConscript @@ -0,0 +1,18 @@ +import os +Import('RTT_ROOT') +from building import * +SOURCES = [] +SOURCES = ['adapter_wifi.c'] + SOURCES +objs = [] +cwd = GetCurrentDir() +path = [cwd] +group = DefineGroup('wifi', SOURCES, depend = [], CPPPATH = [cwd]) +objs = objs + group +list = os.listdir(cwd) + +for d in list: + path = os.path.join(cwd, d) + if os.path.isfile(os.path.join(path, 'SConscript')): + objs = objs + SConscript(os.path.join(path, 'SConscript')) + +Return('objs') \ No newline at end of file diff --git a/APP_Framework/Framework/connection/wifi/adapter_wifi.c b/APP_Framework/Framework/connection/wifi/adapter_wifi.c index ab6ea8ca6..dc3884b5d 100644 --- a/APP_Framework/Framework/connection/wifi/adapter_wifi.c +++ b/APP_Framework/Framework/connection/wifi/adapter_wifi.c @@ -19,13 +19,14 @@ */ #include -#include +#include + #ifdef ADAPTER_HFA21_WIFI extern AdapterProductInfoType Hfa21WifiAttach(struct Adapter *adapter); #endif -#define ADAPTER_WIFI_NAME "wifi" +#define ADAPTER_WIFI_NAME "hfa21_wifi" static int AdapterWifiRegister(struct Adapter *adapter) { @@ -92,30 +93,30 @@ int AdapterWifiTest(void) #ifdef ADAPTER_HFA21_DRIVER_EXT_PORT - // static BusType ch438_pin; - // ch438_pin = PinBusInitGet(); - // struct PinParam pin_cfg; - // int ret = 0; + static BusType ch438_pin; + ch438_pin = PinBusInitGet(); + struct PinParam pin_cfg; + int ret = 0; - // struct BusConfigureInfo configure_info; - // configure_info.configure_cmd = OPE_CFG; - // configure_info.private_data = (void *)&pin_cfg; + struct BusConfigureInfo configure_info; + configure_info.configure_cmd = OPE_CFG; + configure_info.private_data = (void *)&pin_cfg; - // pin_cfg.cmd = GPIO_CONFIG_MODE; - // pin_cfg.pin = 22; - // pin_cfg.mode = GPIO_CFG_OUTPUT; + pin_cfg.cmd = GPIO_CONFIG_MODE; + pin_cfg.pin = 22; + pin_cfg.mode = GPIO_CFG_OUTPUT; - // ret = BusDrvConfigure(ch438_pin->owner_driver, &configure_info); + ret = BusDrvConfigure(ch438_pin->owner_driver, &configure_info); - // struct PinStat pin_stat; - // struct BusBlockWriteParam write_param; - // struct BusBlockReadParam read_param; - // write_param.buffer = (void *)&pin_stat; + struct PinStat pin_stat; + struct BusBlockWriteParam write_param; + struct BusBlockReadParam read_param; + write_param.buffer = (void *)&pin_stat; - // pin_stat.val = GPIO_HIGH; + pin_stat.val = GPIO_HIGH; - // pin_stat.pin = 22; - // BusDevWriteData(ch438_pin->owner_haldev, &write_param); + pin_stat.pin = 22; + BusDevWriteData(ch438_pin->owner_haldev, &write_param); int pin_fd; pin_fd = PrivOpen("/dev/pin_dev", O_RDWR); @@ -153,7 +154,7 @@ int AdapterWifiTest(void) enum IpType ip_type = IPV4; AdapterDeviceConnect(adapter, net_role, ip, port, ip_type); - const char *wifi_msg = "LiuKai Test"; + const char *wifi_msg = "Wifi Test"; int len = strlen(wifi_msg); for(int i = 0;i < 10; ++i) { AdapterDeviceSend(adapter, wifi_msg, len); @@ -161,9 +162,15 @@ int AdapterWifiTest(void) } char wifi_recv_msg[128]; - while (1) { + for(int j=0;j<10;++j){ AdapterDeviceRecv(adapter, wifi_recv_msg, 128); + PrivTaskDelay(1000); } } +#ifdef ADD_RTTHREAD_FETURES +MSH_CMD_EXPORT(AdapterWifiTest,a wifi adpter sample); +#endif +#ifdef ADD_XIZI_FETURES SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, AdapterWifiTest, AdapterWifiTest, show adapter wifi information); +#endif diff --git a/APP_Framework/Framework/connection/wifi/hfa21_wifi/Kconfig b/APP_Framework/Framework/connection/wifi/hfa21_wifi/Kconfig index b4fff97ac..cc248bd79 100755 --- a/APP_Framework/Framework/connection/wifi/hfa21_wifi/Kconfig +++ b/APP_Framework/Framework/connection/wifi/hfa21_wifi/Kconfig @@ -29,5 +29,7 @@ if ADD_NUTTX_FETURES endif if ADD_RTTHREAD_FETURES - + config ADAPTER_HFA21_DRIVER + string "HFA21 device uart driver path" + default "/dev/uart3" endif diff --git a/APP_Framework/Framework/connection/wifi/hfa21_wifi/SConscript b/APP_Framework/Framework/connection/wifi/hfa21_wifi/SConscript new file mode 100644 index 000000000..093664350 --- /dev/null +++ b/APP_Framework/Framework/connection/wifi/hfa21_wifi/SConscript @@ -0,0 +1,10 @@ +from building import * +import os + +cwd = GetCurrentDir() +src = [] +if GetDepend(['ADAPTER_HFA21_WIFI']): + src += ['hfa21_wifi.c'] +group = DefineGroup('connection wifi hfa21', src, depend = [], CPPPATH = [cwd]) + +Return('group') \ No newline at end of file diff --git a/APP_Framework/Framework/connection/wifi/hfa21_wifi/hfa21_wifi.c b/APP_Framework/Framework/connection/wifi/hfa21_wifi/hfa21_wifi.c index 1d1ad2df4..2cc263416 100755 --- a/APP_Framework/Framework/connection/wifi/hfa21_wifi/hfa21_wifi.c +++ b/APP_Framework/Framework/connection/wifi/hfa21_wifi/hfa21_wifi.c @@ -20,7 +20,8 @@ #include #include - +#include +#include #define LEN_PARA_BUF 128 static int Hfa21WifiSetDown(struct Adapter *adapter_at); @@ -28,10 +29,11 @@ static int Hfa21WifiSetDown(struct Adapter *adapter_at); /** * @description: enter AT command mode * @param at_agent - wifi device agent pointer - * @return success: EOK + * @return success: 0 */ static int Hfa21WifiInitAtCmd(ATAgentType at_agent) { + ATOrderSend(at_agent, REPLY_TIME_OUT, NULL, "+++"); PrivTaskDelay(100); @@ -44,7 +46,7 @@ static int Hfa21WifiInitAtCmd(ATAgentType at_agent) /** * @description: Open wifi * @param adapter - wifi device pointer - * @return success: EOK, failure: ENOMEMORY + * @return success: 0, failure: 5 */ static int Hfa21WifiOpen(struct Adapter *adapter) { @@ -58,7 +60,7 @@ static int Hfa21WifiOpen(struct Adapter *adapter) /*step2: init AT agent*/ if (!adapter->agent) { char *agent_name = "wifi_uart_client"; - if (EOK != InitATAgent(agent_name, adapter->fd, 512)) { + if (0 != InitATAgent(agent_name, adapter->fd, 512)) { printf("at agent init failed !\n"); return -1; } @@ -75,7 +77,7 @@ static int Hfa21WifiOpen(struct Adapter *adapter) /** * @description: Close wifi * @param adapter - wifi device pointer - * @return success: EOK + * @return success: 0 */ static int Hfa21WifiClose(struct Adapter *adapter) { @@ -87,11 +89,11 @@ static int Hfa21WifiClose(struct Adapter *adapter) * @param adapter - wifi device pointer * @param data - data buffer * @param data - data length - * @return success: EOK + * @return success: 0 */ static int Hfa21WifiSend(struct Adapter *adapter, const void *data, size_t len) { - x_err_t result = EOK; + long result = 0; if (adapter->agent) { EntmSend(adapter->agent, (const char *)data, len); }else { @@ -108,11 +110,11 @@ __exit: * @param adapter - wifi device pointer * @param data - data buffer * @param data - data length - * @return success: EOK + * @return success: 0 */ static int Hfa21WifiReceive(struct Adapter *adapter, void *rev_buffer, size_t buffer_len) { - x_err_t result = EOK; + long result = 0; printf("hfa21 receive waiting ... \n"); if (adapter->agent) { @@ -129,20 +131,19 @@ __exit: /** * @description: connnect wifi to internet * @param adapter - wifi device pointer - * @return success: EOK + * @return success: 0 */ static int Hfa21WifiSetUp(struct Adapter *adapter) { uint8 wifi_ssid[LEN_PARA_BUF] = "AIIT-Guest"; uint8 wifi_pwd[LEN_PARA_BUF] = ""; char cmd[LEN_PARA_BUF]; - + struct ATAgent *agent = adapter->agent; - + /* wait hfa21 device startup finish */ PrivTaskDelay(5000); - - Hfa21WifiInitAtCmd(agent); + Hfa21WifiInitAtCmd(agent);//err memset(cmd,0,sizeof(cmd)); strcpy(cmd,"AT+FCLR\r"); @@ -181,7 +182,7 @@ static int Hfa21WifiSetUp(struct Adapter *adapter) /** * @description: disconnnect wifi from internet * @param adapter - wifi device pointer - * @return success: EOK + * @return success: 0 */ static int Hfa21WifiSetDown(struct Adapter *adapter) { @@ -199,7 +200,7 @@ static int Hfa21WifiSetDown(struct Adapter *adapter) * @param ip - ip address * @param gateway - gateway address * @param netmask - netmask address - * @return success: EOK, failure: ENOMEMORY + * @return success: 0, failure: 5 */ static int Hfa21WifiSetAddr(struct Adapter *adapter, const char *ip, const char *gateway, const char *netmask) { @@ -216,12 +217,12 @@ static int Hfa21WifiSetAddr(struct Adapter *adapter, const char *ip, const char Hfa21WifiInitAtCmd(adapter->agent); - x_err_t result = EOK; + long result = 0; ATReplyType reply = CreateATReply(64); if (NULL == reply) { printf("at_create_resp failed ! \n"); - result = ENOMEMORY; + result = 5; goto __exit; } @@ -253,12 +254,12 @@ __exit: * @description: wifi ping function * @param adapter - wifi device pointer * @param destination - domain name or ip address - * @return success: EOK, failure: ENOMEMORY + * @return success: 0, failure: 5 */ static int Hfa21WifiPing(struct Adapter *adapter, const char *destination) { - char *ping_result = NONE; - char *dst = NONE; + char *ping_result = (0); + char *dst = (0); ping_result = (char *) PrivCalloc(1, 17); dst = (char *) PrivCalloc(1, 17); strcpy(dst, destination); @@ -266,12 +267,12 @@ static int Hfa21WifiPing(struct Adapter *adapter, const char *destination) Hfa21WifiInitAtCmd(adapter->agent); - uint32 result = EOK; + uint32 result = 0; ATReplyType reply = CreateATReply(64); if (NULL == reply) { printf("at_create_resp failed ! \n"); - result = ENOMEMORY; + result = 5; goto __exit; } @@ -302,7 +303,7 @@ __exit: /** * @description: display wifi network configuration * @param adapter - wifi device pointer - * @return success: EOK, failure: ENOMEMORY + * @return success: 0, failure: 5 */ static int Hfa21WifiNetstat(struct Adapter *adapter) { @@ -334,7 +335,7 @@ static int Hfa21WifiNetstat(struct Adapter *adapter) reply = CreateATReply(HFA21_NETSTAT_RESP_SIZE); if (reply == NULL) { - result = ENOMEMORY; + result = 5; goto __exit; } @@ -384,7 +385,7 @@ static int Hfa21WifiNetstat(struct Adapter *adapter) else printf("local ip: %s\nnetmask: %s\n", local_ipaddr, netmask); - return EOK; + return 0; __exit: if (reply) @@ -410,15 +411,15 @@ __exit: */ static int Hfa21WifiConnect(struct Adapter *adapter, enum NetRoleType net_role, const char *ip, const char *port, enum IpType ip_type) { - int result = EOK; - ATReplyType reply = NONE; + int result = 0; + ATReplyType reply = (0); char cmd[LEN_PARA_BUF]; struct ATAgent *agent = adapter->agent; reply = CreateATReply(64); - if (reply == NONE) { + if (reply == (0)) { printf("no memory for reply struct."); - return ENOMEMORY; + return 5; } Hfa21WifiInitAtCmd(adapter->agent); @@ -505,7 +506,7 @@ static const struct IpProtocolDone hfa21_wifi_done = /** * @description: Register wifi device hfa21 - * @return success: EOK, failure: ERROR + * @return success: 0, failure: ERROR */ AdapterProductInfoType Hfa21WifiAttach(struct Adapter *adapter) {