forked from xuos/xiuos
sync the upstream
This commit is contained in:
@@ -7,7 +7,7 @@ menu "Applications"
|
||||
config MAIN_KTASK_PRIORITY
|
||||
int
|
||||
default 4 if KTASK_PRIORITY_8
|
||||
default 10 if KTASK_PRIORITY_32
|
||||
default 16 if KTASK_PRIORITY_32
|
||||
default 85 if KTASK_PRIORITY_256
|
||||
endmenu
|
||||
|
||||
|
||||
7
APP_Framework/Framework/connection/4g/Make.defs
Normal file
7
APP_Framework/Framework/connection/4g/Make.defs
Normal file
@@ -0,0 +1,7 @@
|
||||
############################################################################
|
||||
# APP_Framework/Framework/connection/4g/Make.defs
|
||||
############################################################################
|
||||
ifneq ($(CONFIG_CONNECTION_ADAPTER_4G),)
|
||||
CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Framework/connection/4g
|
||||
endif
|
||||
include $(wildcard $(APPDIR)/../../../APP_Framework/Framework/connection/4g/*/Make.defs)
|
||||
@@ -1,7 +1,17 @@
|
||||
SRC_FILES := adapter_4g.c
|
||||
include $(KERNEL_ROOT)/.config
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
||||
include $(APPDIR)/Make.defs
|
||||
CSRCS += adapter_4g.c
|
||||
include $(APPDIR)/Application.mk
|
||||
|
||||
ifeq ($(CONFIG_ADAPTER_EC200T),y)
|
||||
SRC_DIR += ec200t
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
|
||||
SRC_FILES := adapter_4g.c
|
||||
|
||||
ifeq ($(CONFIG_ADAPTER_EC200T),y)
|
||||
SRC_DIR += ec200t
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
endif
|
||||
@@ -24,8 +24,6 @@
|
||||
extern AdapterProductInfoType Ec200tAttach(struct Adapter *adapter);
|
||||
#endif
|
||||
|
||||
#define ADAPTER_4G_NAME "4G"
|
||||
|
||||
static int Adapter4GRegister(struct Adapter *adapter)
|
||||
{
|
||||
int ret = 0;
|
||||
@@ -92,8 +90,8 @@ int Adapter4GTest(void)
|
||||
|
||||
#ifdef ADAPTER_EC200T
|
||||
//Using Hang Xiao server to test 4G Socket connection
|
||||
uint8 server_addr[64] = "101.68.82.219";
|
||||
uint8 server_port[64] = "9898";
|
||||
uint8 server_addr[64] = "120.76.100.197";
|
||||
uint8 server_port[64] = "10002";
|
||||
|
||||
adapter->socket.socket_id = 0;
|
||||
|
||||
|
||||
@@ -32,6 +32,9 @@ if ADD_XIZI_FETURES
|
||||
endif
|
||||
|
||||
if ADD_NUTTX_FETURES
|
||||
config ADAPTER_EC200T_DRIVER
|
||||
string "EC200T device uart driver path"
|
||||
default "/dev/ttyS8"
|
||||
|
||||
endif
|
||||
|
||||
|
||||
6
APP_Framework/Framework/connection/4g/ec200t/Make.defs
Normal file
6
APP_Framework/Framework/connection/4g/ec200t/Make.defs
Normal file
@@ -0,0 +1,6 @@
|
||||
############################################################################
|
||||
# APP_Framework/Framework/connection/4g/ec200t/Make.defs
|
||||
############################################################################
|
||||
ifneq ($(CONFIG_ADAPTER_4G_EC200T),)
|
||||
CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Framework/connection/4g/ec200t
|
||||
endif
|
||||
@@ -1,3 +1,14 @@
|
||||
SRC_FILES := ec200t.c
|
||||
include $(KERNEL_ROOT)/.config
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
||||
include $(APPDIR)/Make.defs
|
||||
CSRCS += ec200t.c
|
||||
include $(APPDIR)/Application.mk
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
|
||||
SRC_FILES := ec200t.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
||||
endif
|
||||
|
||||
@@ -36,6 +36,11 @@
|
||||
#define EC200T_CREG_REPLY ",1"
|
||||
#define EC200T_CONNECT_REPLY "CONNECT"
|
||||
|
||||
#define TRY_TIMES 10
|
||||
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
static void Ec200tPowerSet(void){ return; }
|
||||
#else
|
||||
static void Ec200tPowerSet(void)
|
||||
{
|
||||
int pin_fd;
|
||||
@@ -69,6 +74,7 @@ static void Ec200tPowerSet(void)
|
||||
|
||||
PrivTaskDelay(10000);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int Ec200tOpen(struct Adapter *adapter)
|
||||
{
|
||||
@@ -82,7 +88,7 @@ static int Ec200tOpen(struct Adapter *adapter)
|
||||
/*step2: init AT agent*/
|
||||
if (!adapter->agent) {
|
||||
char *agent_name = "4G_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;
|
||||
}
|
||||
@@ -116,6 +122,7 @@ static int Ec200tClose(struct Adapter *adapter)
|
||||
/*step2: serial write "AT+QICLOSE", close socket connect before open socket*/
|
||||
memset(ec200t_cmd, 0, sizeof(ec200t_cmd));
|
||||
sprintf(ec200t_cmd, EC200T_CLOSE_SOCKET_CMD, adapter->socket.socket_id);
|
||||
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, ec200t_cmd, EC200T_OK_REPLY);
|
||||
if (ret < 0) {
|
||||
goto out;
|
||||
@@ -137,6 +144,10 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
static int Ec200tIoctl(struct Adapter *adapter, int cmd, void *args){ return 0;}
|
||||
#else
|
||||
static int Ec200tIoctl(struct Adapter *adapter, int cmd, void *args)
|
||||
{
|
||||
if (OPE_INT != cmd) {
|
||||
@@ -169,10 +180,12 @@ static int Ec200tIoctl(struct Adapter *adapter, int cmd, void *args)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int Ec200tConnect(struct Adapter *adapter, enum NetRoleType net_role, const char *ip, const char *port, enum IpType ip_type)
|
||||
{
|
||||
int ret = 0;
|
||||
int try = 0;
|
||||
uint8_t ec200t_cmd[64];
|
||||
|
||||
AtSetReplyEndChar(adapter->agent, 0x4F, 0x4B);
|
||||
@@ -181,19 +194,34 @@ static int Ec200tConnect(struct Adapter *adapter, enum NetRoleType net_role, con
|
||||
ATOrderSend(adapter->agent, REPLY_TIME_OUT, NULL, "+++");
|
||||
|
||||
/*step2: serial write "AT+CCID", get SIM ID*/
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, EC200T_GET_CCID_CMD, EC200T_OK_REPLY);
|
||||
for(try = 0; try < TRY_TIMES; try++){
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, EC200T_GET_CCID_CMD, EC200T_OK_REPLY);
|
||||
if (ret == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ret < 0) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*step3: serial write "AT+CPIN?", check SIM status*/
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, EC200T_GET_CPIN_CMD, EC200T_READY_REPLY);
|
||||
for(try = 0; try < TRY_TIMES; try++){
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, EC200T_GET_CPIN_CMD, EC200T_READY_REPLY);
|
||||
if (ret == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ret < 0) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*step4: serial write "AT+CREG?", check whether registered to GSM net*/
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, EC200T_GET_CREG_CMD, EC200T_CREG_REPLY);
|
||||
for(try = 0; try < TRY_TIMES; try++){
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, EC200T_GET_CREG_CMD, EC200T_CREG_REPLY);
|
||||
if (ret == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ret < 0) {
|
||||
goto out;
|
||||
}
|
||||
@@ -207,7 +235,12 @@ static int Ec200tConnect(struct Adapter *adapter, enum NetRoleType net_role, con
|
||||
strcpy(ec200t_cmd, "AT+QICSGP=1,2,\"CMNET\",\"\",\"\",1\r\n");
|
||||
}
|
||||
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, ec200t_cmd, EC200T_OK_REPLY);
|
||||
for(try = 0; try < TRY_TIMES; try++){
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, ec200t_cmd, EC200T_OK_REPLY);
|
||||
if (ret == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ret < 0) {
|
||||
goto out;
|
||||
}
|
||||
@@ -215,19 +248,34 @@ static int Ec200tConnect(struct Adapter *adapter, enum NetRoleType net_role, con
|
||||
/*step6: serial write "AT+QICLOSE", close socket connect before open socket*/
|
||||
memset(ec200t_cmd, 0, sizeof(ec200t_cmd));
|
||||
sprintf(ec200t_cmd, EC200T_CLOSE_SOCKET_CMD, adapter->socket.socket_id);
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, ec200t_cmd, EC200T_OK_REPLY);
|
||||
for(try = 0; try < TRY_TIMES; try++){
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, ec200t_cmd, EC200T_OK_REPLY);
|
||||
if (ret == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ret < 0) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*step7: serial write "AT+QIDEACT", close TCP net before open socket*/
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, EC200T_DEACTIVE_PDP_CMD, EC200T_OK_REPLY);
|
||||
for(try = 0; try < TRY_TIMES; try++){
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, EC200T_DEACTIVE_PDP_CMD, EC200T_OK_REPLY);
|
||||
if (ret == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ret < 0) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*step8: serial write "AT+QIACT", open TCP net*/
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, EC200T_ACTIVE_PDP_CMD, EC200T_OK_REPLY);
|
||||
for(try = 0; try < TRY_TIMES; try++){
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, EC200T_ACTIVE_PDP_CMD, EC200T_OK_REPLY);
|
||||
if (ret == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ret < 0) {
|
||||
goto out;
|
||||
}
|
||||
@@ -243,7 +291,12 @@ static int Ec200tConnect(struct Adapter *adapter, enum NetRoleType net_role, con
|
||||
|
||||
AtSetReplyEndChar(adapter->agent, 0x43, 0x54);
|
||||
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, ec200t_cmd, EC200T_CONNECT_REPLY);
|
||||
for(try = 0; try < TRY_TIMES; try++){
|
||||
ret = AtCmdConfigAndCheck(adapter->agent, ec200t_cmd, EC200T_CONNECT_REPLY);
|
||||
if (ret == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ret < 0) {
|
||||
goto out;
|
||||
}
|
||||
@@ -260,7 +313,6 @@ out:
|
||||
|
||||
static int Ec200tSend(struct Adapter *adapter, const void *buf, size_t len)
|
||||
{
|
||||
x_err_t result = EOK;
|
||||
if (adapter->agent) {
|
||||
EntmSend(adapter->agent, (const char *)buf, len);
|
||||
} else {
|
||||
|
||||
21
APP_Framework/Framework/connection/SConscript
Normal file
21
APP_Framework/Framework/connection/SConscript
Normal file
@@ -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)
|
||||
if GetDepend(['SUPPORT_CONNECTION_FRAMEWORK']):
|
||||
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')
|
||||
@@ -21,9 +21,11 @@
|
||||
#include <adapter.h>
|
||||
|
||||
static DoublelistType adapter_list;
|
||||
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
static int adapter_list_lock;
|
||||
|
||||
#else
|
||||
static pthread_mutex_t adapter_list_lock;
|
||||
#endif
|
||||
/**
|
||||
* @description: Init adapter framework
|
||||
* @return 0
|
||||
@@ -481,6 +483,7 @@ int AdapterDeviceDisconnect(struct Adapter *adapter, unsigned char *priv_net_gro
|
||||
*/
|
||||
int AdapterDeviceSetUp(struct Adapter *adapter)
|
||||
{
|
||||
|
||||
if (!adapter)
|
||||
return -1;
|
||||
|
||||
@@ -488,10 +491,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 +518,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;
|
||||
|
||||
@@ -45,6 +45,15 @@ extern "C" {
|
||||
#define ADAPTER_DEBUG
|
||||
#endif
|
||||
|
||||
#define ADAPTER_4G_NAME "4G"
|
||||
#define ADAPTER_BLUETOOTH_NAME "bluetooth"
|
||||
#define ADAPTER_ETHERNET_NAME "ethernet"
|
||||
#define ADAPTER_ETHERCAT_NAME "ethercat"
|
||||
#define ADAPTER_LORA_NAME "lora"
|
||||
#define ADAPTER_NBIOT_NAME "nbiot"
|
||||
#define ADAPTER_WIFI_NAME "wifi"
|
||||
#define ADAPTER_ZIGBEE_NAME "zigbee"
|
||||
|
||||
struct Adapter;
|
||||
struct AdapterProductInfo;
|
||||
typedef struct Adapter *AdapterType;
|
||||
@@ -108,6 +117,12 @@ enum IpType
|
||||
IPV6,
|
||||
};
|
||||
|
||||
struct AdapterData
|
||||
{
|
||||
uint32 len;
|
||||
uint8 *buffer;
|
||||
};
|
||||
|
||||
struct AdapterProductInfo
|
||||
{
|
||||
uint32_t functions;
|
||||
@@ -175,6 +190,9 @@ struct Adapter
|
||||
void *done;
|
||||
void *adapter_param;
|
||||
|
||||
sem_t sem;
|
||||
pthread_mutex_t lock;
|
||||
|
||||
struct DoublelistNode link;
|
||||
};
|
||||
|
||||
|
||||
@@ -29,7 +29,9 @@
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
# include <user_api.h>
|
||||
#endif
|
||||
|
||||
#ifdef ADD_RTTHREAD_FETURES
|
||||
#include <rtthread.h>
|
||||
#endif
|
||||
#define AT_CMD_MAX_LEN 128
|
||||
#define AT_AGENT_MAX 2
|
||||
static char send_buf[AT_CMD_MAX_LEN];
|
||||
@@ -139,7 +141,7 @@ int ATOrderSend(ATAgentType agent, uint32_t timeout_s, ATReplyType reply, const
|
||||
|
||||
PrivMutexObtain(&agent->lock);
|
||||
agent->receive_mode = AT_MODE;
|
||||
|
||||
|
||||
memset(agent->maintain_buffer, 0x00, agent->maintain_max);
|
||||
agent->maintain_len = 0;
|
||||
|
||||
@@ -194,13 +196,15 @@ int AtCmdConfigAndCheck(ATAgentType agent, char *cmd, char *check)
|
||||
ret = -1;
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
ret = ATOrderSend(agent, REPLY_TIME_OUT, reply, cmd);
|
||||
if(ret < 0){
|
||||
printf("%s %d ATOrderSend failed.\n",__func__,__LINE__);
|
||||
ret = -1;
|
||||
goto __exit;
|
||||
}
|
||||
// PrivTaskDelay(3000);
|
||||
|
||||
//PrivTaskDelay(3000);
|
||||
|
||||
result = GetReplyText(reply);
|
||||
if (!result) {
|
||||
@@ -295,10 +299,10 @@ int EntmRecv(ATAgentType agent, char *rev_buffer, int buffer_len, int timeout_s)
|
||||
agent->receive_mode = ENTM_MODE;
|
||||
agent->read_len = buffer_len;
|
||||
PrivMutexAbandon(&agent->lock);
|
||||
// PrivTaskDelay(1000);
|
||||
//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);
|
||||
|
||||
@@ -388,7 +392,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");
|
||||
@@ -430,21 +434,29 @@ int DeleteATAgent(ATAgentType agent)
|
||||
PrivClose(agent->fd);
|
||||
}
|
||||
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
if (agent->lock.sem.semcount > 0) {
|
||||
printf("delete agent lock = %d\n",agent->lock.sem.semcount);
|
||||
PrivMutexDelete(&agent->lock);
|
||||
}
|
||||
#elif defined ADD_RTTHREAD_FETURES
|
||||
#else
|
||||
if (agent->lock) {
|
||||
printf("delete agent lock = %d\n",agent->lock);
|
||||
PrivMutexDelete(&agent->lock);
|
||||
}
|
||||
#endif
|
||||
|
||||
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);
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
if (agent->rsp_sem) {
|
||||
printf("delete agent rsp_sem = %d\n",agent->rsp_sem);
|
||||
PrivSemaphoreDelete(&agent->rsp_sem);
|
||||
}
|
||||
|
||||
#endif
|
||||
if (agent->maintain_buffer) {
|
||||
PrivFree(agent->maintain_buffer);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,6 @@ struct ATReply
|
||||
uint32 reply_len;
|
||||
};
|
||||
typedef struct ATReply *ATReplyType;
|
||||
|
||||
struct ATAgent
|
||||
{
|
||||
char agent_name[64];
|
||||
@@ -52,16 +51,23 @@ struct ATAgent
|
||||
char *maintain_buffer;
|
||||
uint32 maintain_len;
|
||||
uint32 maintain_max;
|
||||
|
||||
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
int lock;
|
||||
#else
|
||||
pthread_mutex_t lock;
|
||||
#endif
|
||||
|
||||
ATReplyType reply;
|
||||
char reply_lr_end;
|
||||
char reply_end_last_char;
|
||||
char reply_end_char;
|
||||
uint32 reply_char_num;
|
||||
int rsp_sem;
|
||||
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
int rsp_sem;
|
||||
#else
|
||||
sem_t rsp_sem;
|
||||
#endif
|
||||
pthread_t at_handler;
|
||||
|
||||
#define ENTM_RECV_MAX 256
|
||||
|
||||
18
APP_Framework/Framework/connection/bluetooth/SConscript
Normal file
18
APP_Framework/Framework/connection/bluetooth/SConscript
Normal file
@@ -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')
|
||||
@@ -24,8 +24,6 @@
|
||||
extern AdapterProductInfoType Hc08Attach(struct Adapter *adapter);
|
||||
#endif
|
||||
|
||||
#define ADAPTER_BLUETOOTH_NAME "bluetooth"
|
||||
|
||||
static int AdapterBlueToothRegister(struct Adapter *adapter)
|
||||
{
|
||||
int ret = 0;
|
||||
@@ -80,13 +78,13 @@ int AdapterBlueToothInit(void)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/******************4G TEST*********************/
|
||||
/******************BT TEST*********************/
|
||||
int AdapterBlueToothTest(void)
|
||||
{
|
||||
const char *bluetooth_msg = "BT Adapter Test";
|
||||
char bluetooth_recv_msg[128];
|
||||
int len;
|
||||
int baud_rate = BAUD_RATE_115200;
|
||||
int baud_rate = BAUD_RATE_9600;
|
||||
|
||||
struct Adapter *adapter = AdapterDeviceFindByName(ADAPTER_BLUETOOTH_NAME);
|
||||
|
||||
@@ -101,7 +99,7 @@ int AdapterBlueToothTest(void)
|
||||
printf("bluetooth_recv_msg %s\n", bluetooth_recv_msg);
|
||||
AdapterDeviceSend(adapter, bluetooth_msg, len);
|
||||
printf("send %s after recv\n", bluetooth_msg);
|
||||
PrivTaskDelay(100);
|
||||
PrivTaskDelay(1000);
|
||||
memset(bluetooth_recv_msg, 0, 128);
|
||||
}
|
||||
|
||||
@@ -109,4 +107,9 @@ int AdapterBlueToothTest(void)
|
||||
|
||||
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);
|
||||
#ifdef ADD_RTTHREAD_FETURES
|
||||
MSH_CMD_EXPORT(AdapterBlueToothTest,a bt 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
|
||||
@@ -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
|
||||
|
||||
10
APP_Framework/Framework/connection/bluetooth/hc08/SConscript
Normal file
10
APP_Framework/Framework/connection/bluetooth/hc08/SConscript
Normal file
@@ -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')
|
||||
@@ -92,7 +92,7 @@ static int Hc08AtConfigure(ATAgentType agent, enum Hc08AtCmd hc08_at_cmd, void *
|
||||
ATReplyType reply = CreateATReply(64);
|
||||
if (NULL == reply) {
|
||||
printf("Hc08AtConfigure CreateATReply failed !\n");
|
||||
return -ENOMEMORY;
|
||||
return -5;
|
||||
}
|
||||
|
||||
switch (hc08_at_cmd)
|
||||
@@ -152,20 +152,20 @@ static int Hc08AtConfigure(ATAgentType agent, enum Hc08AtCmd hc08_at_cmd, void *
|
||||
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;
|
||||
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);
|
||||
@@ -209,7 +209,7 @@ static int Hc08Open(struct Adapter *adapter)
|
||||
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)) {
|
||||
if (0 != InitATAgent(agent_name, adapter->fd, 512)) {
|
||||
printf("at agent init failed !\n");
|
||||
return -1;
|
||||
}
|
||||
@@ -343,7 +343,7 @@ static int Hc08Connect(struct Adapter *adapter, enum NetRoleType net_role, const
|
||||
|
||||
static int Hc08Send(struct Adapter *adapter, const void *buf, size_t len)
|
||||
{
|
||||
x_err_t result = EOK;
|
||||
long result = 0;
|
||||
if (adapter->agent) {
|
||||
EntmSend(adapter->agent, (const char *)buf, len);
|
||||
} else {
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
extern AdapterProductInfoType Hfa21EthernetAttach(struct Adapter *adapter);
|
||||
#endif
|
||||
|
||||
#define ADAPTER_ETHERNET_NAME "ethernet"
|
||||
|
||||
static int AdapterEthernetRegister(struct Adapter *adapter)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
extern AdapterProductInfoType Hfa21EthercatAttach(struct Adapter *adapter);
|
||||
#endif
|
||||
|
||||
#define ADAPTER_ETHERCAT_NAME "ethercat"
|
||||
|
||||
/**
|
||||
* @description: clear the datagram in ethercat frame, do not free the frame itself, since it may be a memory space on stack
|
||||
* @param frame - ethercat frame pointer
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
// therefore, only the TCP/UDP datagrams are considered,
|
||||
// here EtherCAT is in fact an application layer protocol.
|
||||
|
||||
#define ADAPTER_ETHERNET_NAME "ethernet" //"wifi"
|
||||
// #define ADAPTER_ETHERNET_NAME "ethernet" //"wifi"
|
||||
EcatFrame ecat_data;
|
||||
static struct Adapter *ethernet;
|
||||
uint32_t self_address;
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
config ADAPTER_SX1278
|
||||
bool "Using lora adapter device SX1278"
|
||||
default y
|
||||
default n
|
||||
|
||||
config ADAPTER_E220
|
||||
bool "Using lora adapter device E220-400T22S"
|
||||
default n
|
||||
|
||||
choice
|
||||
prompt "Lora device adapter select net role type "
|
||||
@@ -13,18 +17,26 @@ choice
|
||||
bool "config as a client"
|
||||
endchoice
|
||||
|
||||
config ADAPTER_LORA_CLIENT_NUM
|
||||
int "Lora net client num"
|
||||
default "20"
|
||||
|
||||
if AS_LORA_GATEWAY_ROLE
|
||||
config ADAPTER_LORA_NET_ROLE_ID
|
||||
hex "if Lora device config as a gateway, set gateway net id"
|
||||
default "0x10"
|
||||
hex "if Lora device config as a gateway, set gateway net id"
|
||||
default "0xFF"
|
||||
endif
|
||||
|
||||
if AS_LORA_CLIENT_ROLE
|
||||
config ADAPTER_LORA_NET_ROLE_ID
|
||||
hex "if Lora device config as a client, set client net id"
|
||||
default "0x01"
|
||||
hex "if Lora device config as a client, set client net id"
|
||||
default "0x01"
|
||||
endif
|
||||
|
||||
if ADAPTER_SX1278
|
||||
source "$APP_DIR/Framework/connection/lora/sx1278/Kconfig"
|
||||
endif
|
||||
|
||||
if ADAPTER_E220
|
||||
source "$APP_DIR/Framework/connection/lora/e220/Kconfig"
|
||||
endif
|
||||
|
||||
@@ -8,9 +8,14 @@ endif
|
||||
|
||||
ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
|
||||
SRC_FILES := adapter_lora.c
|
||||
|
||||
ifeq ($(CONFIG_ADAPTER_SX1278),y)
|
||||
SRC_DIR += sx1278
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ADAPTER_E220),y)
|
||||
SRC_DIR += e220
|
||||
endif
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
||||
endif
|
||||
|
||||
@@ -24,10 +24,19 @@
|
||||
extern AdapterProductInfoType Sx1278Attach(struct Adapter *adapter);
|
||||
#endif
|
||||
|
||||
#define ADAPTER_LORA_NAME "lora"
|
||||
#define ADAPTER_LORA_CLIENT_NUM 6
|
||||
#define ADAPTER_LORA_DATA_LENGTH 128
|
||||
#define ADAPTER_LORA_RECV_DATA_LENGTH 256
|
||||
#ifdef ADAPTER_E220
|
||||
extern AdapterProductInfoType E220Attach(struct Adapter *adapter);
|
||||
#endif
|
||||
|
||||
//#define CLIENT_UPDATE_MODE
|
||||
#define GATEWAY_CMD_MODE
|
||||
|
||||
//Client num index 1-ADAPTER_LORA_CLIENT_NUM
|
||||
//#define ADAPTER_LORA_CLIENT_NUM 20
|
||||
|
||||
//LORA single transfer data max size 128 bytes: data format 16 bytes and user data 112 bytes
|
||||
#define ADAPTER_LORA_DATA_LENGTH 112
|
||||
#define ADAPTER_LORA_TRANSFER_DATA_LENGTH ADAPTER_LORA_DATA_LENGTH + 16
|
||||
|
||||
#define ADAPTER_LORA_DATA_HEAD 0x3C
|
||||
#define ADAPTER_LORA_NET_PANID 0x0102
|
||||
@@ -37,6 +46,9 @@ extern AdapterProductInfoType Sx1278Attach(struct Adapter *adapter);
|
||||
#define ADAPTER_LORA_DATA_TYPE_QUIT_REPLY 0x0D
|
||||
#define ADAPTER_LORA_DATA_TYPE_USERDATA 0x0E
|
||||
#define ADAPTER_LORA_DATA_TYPE_CMD 0x0F
|
||||
#define ADAPTER_LORA_DATA_END 0x5A
|
||||
|
||||
#define ADAPTER_LORA_RECEIVE_ERROR_CNT 1
|
||||
|
||||
//need to change status if the lora client wants to quit the net when timeout or a certain event
|
||||
//eg.can also use sem to trigger quit function
|
||||
@@ -63,28 +75,26 @@ enum LoraGatewayState {
|
||||
LORA_RECV_DATA,
|
||||
};
|
||||
|
||||
static uint8 LoraGatewayState = LORA_STATE_IDLE;
|
||||
|
||||
struct LoraGatewayParam
|
||||
{
|
||||
uint8 gateway_id;
|
||||
uint16 panid;
|
||||
uint8 client_id[ADAPTER_LORA_CLIENT_NUM];
|
||||
uint8_t gateway_id;
|
||||
uint16_t panid;
|
||||
uint8_t client_id[ADAPTER_LORA_CLIENT_NUM];
|
||||
int client_num;
|
||||
int receive_data_sem;
|
||||
};
|
||||
|
||||
struct LoraClientParam
|
||||
{
|
||||
uint8 client_id;
|
||||
uint16 panid;
|
||||
uint8_t client_id;
|
||||
uint16_t panid;
|
||||
enum ClientState client_state;
|
||||
|
||||
uint8 gateway_id;
|
||||
uint8_t gateway_id;
|
||||
};
|
||||
|
||||
/*LoraDataFormat:
|
||||
**flame_head : 0x3C
|
||||
**flame_head : 0x3C3C
|
||||
**length : sizeof(struct LoraDataFormat)
|
||||
**panid : 0x0102
|
||||
**client_id : 0x01、0x02、0x03...
|
||||
@@ -92,23 +102,31 @@ struct LoraClientParam
|
||||
**data_type : 0x0A(join net, client->gateway)、0x0B(join net reply, gateway->client)、
|
||||
0x0C(user data, client->gateway)、0x0D(user data cmd, gateway->client)
|
||||
**data : user data
|
||||
**crc16 : CRC 16 check data
|
||||
**flame_end : 0x5A5A
|
||||
*/
|
||||
struct LoraDataFormat
|
||||
{
|
||||
uint8 flame_head;
|
||||
uint8 reserved[3];
|
||||
uint32 length;
|
||||
uint16 panid;
|
||||
uint8 client_id;
|
||||
uint8 gateway_id;
|
||||
uint16_t flame_head;
|
||||
uint16_t flame_index;
|
||||
uint32_t length;
|
||||
uint16_t panid;
|
||||
uint8_t client_id;
|
||||
uint8_t gateway_id;
|
||||
|
||||
uint16 data_type;
|
||||
uint8 data[ADAPTER_LORA_DATA_LENGTH];
|
||||
uint16_t data_type;
|
||||
uint8_t data[ADAPTER_LORA_DATA_LENGTH];
|
||||
|
||||
uint16 crc16;
|
||||
uint16_t flame_end;
|
||||
};
|
||||
|
||||
uint8_t lora_recv_data[ADAPTER_LORA_TRANSFER_DATA_LENGTH];
|
||||
struct LoraDataFormat client_recv_data_format[ADAPTER_LORA_CLIENT_NUM];
|
||||
|
||||
static sem_t gateway_recv_data_sem;
|
||||
struct LoraDataFormat gateway_recv_data_format;
|
||||
|
||||
static int recv_error_cnt = 0;
|
||||
|
||||
/*******************LORA MESH FUNCTION***********************/
|
||||
|
||||
/**
|
||||
@@ -116,10 +134,10 @@ struct LoraDataFormat
|
||||
* @param data input data buffer
|
||||
* @param length input data buffer minus check code
|
||||
*/
|
||||
static uint16 LoraCrc16(uint8 *data, uint16 length)
|
||||
static uint16_t LoraCrc16(uint8_t *data, uint16_t length)
|
||||
{
|
||||
int j;
|
||||
uint16 crc_data = 0xFFFF;
|
||||
uint16_t crc_data = 0xFFFF;
|
||||
|
||||
while (length--) {
|
||||
crc_data ^= *data++;
|
||||
@@ -139,10 +157,10 @@ static uint16 LoraCrc16(uint8 *data, uint16 length)
|
||||
* @param data input data buffer
|
||||
* @param length input data buffer minus check code
|
||||
*/
|
||||
static int LoraCrc16Check(uint8 *data, uint16 length)
|
||||
static int LoraCrc16Check(uint8_t *data, uint16_t length)
|
||||
{
|
||||
uint16 crc_data;
|
||||
uint16 input_data = (((uint16)data[length - 1] << 8) & 0xFF00) | ((uint16)data[length - 2] & 0x00FF);
|
||||
uint16_t crc_data;
|
||||
uint16_t input_data = (((uint16_t)data[length - 1] << 8) & 0xFF00) | ((uint16_t)data[length - 2] & 0x00FF);
|
||||
|
||||
crc_data = LoraCrc16(data, length - 2);
|
||||
|
||||
@@ -152,35 +170,6 @@ static int LoraCrc16Check(uint8 *data, uint16 length)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Lora receive data check
|
||||
* @param data receive data buffer
|
||||
* @param length receive data length
|
||||
* @param recv_data LoraDataFormat data
|
||||
*/
|
||||
static int LoraReceiveDataCheck(uint8 *data, uint16 length, struct LoraDataFormat *recv_data)
|
||||
{
|
||||
int i;
|
||||
uint32 recv_data_length = 0;
|
||||
for ( i = 0; i < length; i ++) {
|
||||
if (ADAPTER_LORA_DATA_HEAD == data[i]) {
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
/*Big-Endian*/
|
||||
recv_data_length = (data[i + 4] & 0xFF) | ((data[i + 5] & 0xFF) << 8) | ((data[i + 6] & 0xFF) << 16) | ((data[i + 7] & 0xFF) << 24);
|
||||
#else
|
||||
/*Little-Endian*/
|
||||
recv_data_length = ((data[i + 4] & 0xFF) << 24) | ((data[i + 5] & 0xFF) << 16) | ((data[i + 6] & 0xFF) << 8) | (data[i + 7] & 0xFF);
|
||||
#endif
|
||||
if (sizeof(struct LoraDataFormat) == recv_data_length) {
|
||||
memcpy(recv_data, (uint8 *)(data + i), sizeof(struct LoraDataFormat));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Lora Gateway reply connect request to Client
|
||||
* @param adapter Lora adapter pointer
|
||||
@@ -190,10 +179,13 @@ static int LoraGatewayReply(struct Adapter *adapter, struct LoraDataFormat *gate
|
||||
{
|
||||
int i;
|
||||
int client_join_flag = 0;
|
||||
uint16_t gateway_data_type;
|
||||
uint32_t gateway_reply_length = ADAPTER_LORA_TRANSFER_DATA_LENGTH;
|
||||
struct LoraGatewayParam *gateway = (struct LoraGatewayParam *)adapter->adapter_param;
|
||||
struct LoraDataFormat gateway_reply_data;
|
||||
|
||||
memset(&gateway_reply_data, 0, sizeof(struct LoraDataFormat));
|
||||
uint8_t gateway_reply_data[ADAPTER_LORA_TRANSFER_DATA_LENGTH];
|
||||
|
||||
memset(gateway_reply_data, 0, ADAPTER_LORA_TRANSFER_DATA_LENGTH);
|
||||
|
||||
if (ADAPTER_LORA_DATA_TYPE_JOIN == gateway_recv_data->data_type) {
|
||||
|
||||
@@ -206,23 +198,35 @@ static int LoraGatewayReply(struct Adapter *adapter, struct LoraDataFormat *gate
|
||||
}
|
||||
|
||||
if (!client_join_flag) {
|
||||
if (gateway->client_num > 6) {
|
||||
printf("Lora gateway only support 6(max) client\n");
|
||||
if (gateway->client_num > ADAPTER_LORA_CLIENT_NUM) {
|
||||
printf("Lora gateway only support %u(max) client\n", ADAPTER_LORA_CLIENT_NUM);
|
||||
gateway->client_num = 0;
|
||||
}
|
||||
gateway->client_id[gateway->client_num] = gateway_recv_data->client_id;
|
||||
gateway->client_num ++;
|
||||
}
|
||||
|
||||
gateway_reply_data.flame_head = ADAPTER_LORA_DATA_HEAD;
|
||||
gateway_reply_data.length = sizeof(struct LoraDataFormat);
|
||||
gateway_reply_data.panid = gateway->panid;
|
||||
gateway_reply_data.data_type = ADAPTER_LORA_DATA_TYPE_JOIN_REPLY;
|
||||
gateway_reply_data.client_id = gateway_recv_data->client_id;
|
||||
gateway_reply_data.gateway_id = gateway->gateway_id;
|
||||
gateway_reply_data.crc16 = LoraCrc16((uint8 *)&gateway_reply_data, sizeof(struct LoraDataFormat) - 2);
|
||||
|
||||
if (AdapterDeviceSend(adapter, (uint8 *)&gateway_reply_data, gateway_reply_data.length) < 0) {
|
||||
gateway_data_type = ADAPTER_LORA_DATA_TYPE_JOIN_REPLY;
|
||||
|
||||
gateway_reply_data[0] = ADAPTER_LORA_DATA_HEAD;
|
||||
gateway_reply_data[1] = ADAPTER_LORA_DATA_HEAD;
|
||||
gateway_reply_data[2] = 0;
|
||||
gateway_reply_data[3] = 0;
|
||||
gateway_reply_data[4] = (gateway_reply_length >> 24) & 0xFF;
|
||||
gateway_reply_data[5] = (gateway_reply_length >> 16) & 0xFF;
|
||||
gateway_reply_data[6] = (gateway_reply_length >> 8) & 0xFF;
|
||||
gateway_reply_data[7] = gateway_reply_length & 0xFF;
|
||||
gateway_reply_data[8] = (gateway->panid >> 8) & 0xFF;
|
||||
gateway_reply_data[9] = gateway->panid & 0xFF;
|
||||
gateway_reply_data[10] = gateway_recv_data->client_id;
|
||||
gateway_reply_data[11] = gateway->gateway_id;
|
||||
gateway_reply_data[12] = (gateway_data_type >> 8) & 0xFF;
|
||||
gateway_reply_data[13] = gateway_data_type & 0xFF;
|
||||
|
||||
gateway_reply_data[ADAPTER_LORA_TRANSFER_DATA_LENGTH - 2] = ADAPTER_LORA_DATA_END;
|
||||
gateway_reply_data[ADAPTER_LORA_TRANSFER_DATA_LENGTH - 1] = ADAPTER_LORA_DATA_END;
|
||||
|
||||
if (AdapterDeviceSend(adapter, gateway_reply_data, ADAPTER_LORA_TRANSFER_DATA_LENGTH) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -236,15 +240,27 @@ static int LoraGatewayReply(struct Adapter *adapter, struct LoraDataFormat *gate
|
||||
}
|
||||
}
|
||||
|
||||
gateway_reply_data.flame_head = ADAPTER_LORA_DATA_HEAD;
|
||||
gateway_reply_data.length = sizeof(struct LoraDataFormat);
|
||||
gateway_reply_data.panid = gateway->panid;
|
||||
gateway_reply_data.data_type = ADAPTER_LORA_DATA_TYPE_QUIT_REPLY;
|
||||
gateway_reply_data.client_id = gateway_recv_data->client_id;
|
||||
gateway_reply_data.gateway_id = gateway->gateway_id;
|
||||
gateway_reply_data.crc16 = LoraCrc16((uint8 *)&gateway_reply_data, sizeof(struct LoraDataFormat) - 2);
|
||||
|
||||
if (AdapterDeviceSend(adapter, (uint8 *)&gateway_reply_data, gateway_reply_data.length) < 0) {
|
||||
gateway_data_type = ADAPTER_LORA_DATA_TYPE_QUIT_REPLY;
|
||||
|
||||
gateway_reply_data[0] = ADAPTER_LORA_DATA_HEAD;
|
||||
gateway_reply_data[1] = ADAPTER_LORA_DATA_HEAD;
|
||||
gateway_reply_data[2] = 0;
|
||||
gateway_reply_data[3] = 0;
|
||||
gateway_reply_data[4] = (gateway_reply_length >> 24) & 0xFF;
|
||||
gateway_reply_data[5] = (gateway_reply_length >> 16) & 0xFF;
|
||||
gateway_reply_data[6] = (gateway_reply_length >> 8) & 0xFF;
|
||||
gateway_reply_data[7] = gateway_reply_length & 0xFF;
|
||||
gateway_reply_data[8] = (gateway->panid >> 8) & 0xFF;
|
||||
gateway_reply_data[9] = gateway->panid & 0xFF;
|
||||
gateway_reply_data[10] = gateway_recv_data->client_id;
|
||||
gateway_reply_data[11] = gateway->gateway_id;
|
||||
gateway_reply_data[12] = (gateway_data_type >> 8) & 0xFF;
|
||||
gateway_reply_data[13] = gateway_data_type & 0xFF;
|
||||
|
||||
gateway_reply_data[ADAPTER_LORA_TRANSFER_DATA_LENGTH - 2] = ADAPTER_LORA_DATA_END;
|
||||
gateway_reply_data[ADAPTER_LORA_TRANSFER_DATA_LENGTH - 1] = ADAPTER_LORA_DATA_END;
|
||||
|
||||
if (AdapterDeviceSend(adapter, gateway_reply_data, ADAPTER_LORA_TRANSFER_DATA_LENGTH) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -260,22 +276,36 @@ static int LoraGatewayReply(struct Adapter *adapter, struct LoraDataFormat *gate
|
||||
* @param client_id Lora Client id
|
||||
* @param cmd Lora cmd
|
||||
*/
|
||||
static int LoraGatewaySendCmd(struct Adapter *adapter, unsigned char client_id, int cmd)
|
||||
static int LoraGatewaySendCmd(struct Adapter *adapter, uint8_t client_id, uint16_t cmd)
|
||||
{
|
||||
struct LoraGatewayParam *gateway = (struct LoraGatewayParam *)adapter->adapter_param;
|
||||
struct LoraDataFormat gateway_cmd_data;
|
||||
uint16_t gateway_cmd_type;
|
||||
uint32_t gateway_cmd_length = ADAPTER_LORA_TRANSFER_DATA_LENGTH;
|
||||
uint8_t gateway_cmd_data[ADAPTER_LORA_TRANSFER_DATA_LENGTH];
|
||||
|
||||
memset(&gateway_cmd_data, 0, sizeof(struct LoraDataFormat));
|
||||
memset(gateway_cmd_data, 0, sizeof(struct LoraDataFormat));
|
||||
|
||||
gateway_cmd_data.flame_head = ADAPTER_LORA_DATA_HEAD;
|
||||
gateway_cmd_data.length = sizeof(struct LoraDataFormat);
|
||||
gateway_cmd_data.panid = gateway->panid;
|
||||
gateway_cmd_data.data_type = cmd;
|
||||
gateway_cmd_data.client_id = client_id;
|
||||
gateway_cmd_data.gateway_id = gateway->gateway_id;
|
||||
gateway_cmd_data.crc16 = LoraCrc16((uint8 *)&gateway_cmd_data, sizeof(struct LoraDataFormat) - 2);
|
||||
gateway_cmd_type = cmd;
|
||||
|
||||
gateway_cmd_data[0] = ADAPTER_LORA_DATA_HEAD;
|
||||
gateway_cmd_data[1] = ADAPTER_LORA_DATA_HEAD;
|
||||
gateway_cmd_data[2] = 0;
|
||||
gateway_cmd_data[3] = 0;
|
||||
gateway_cmd_data[4] = (gateway_cmd_length >> 24) & 0xFF;
|
||||
gateway_cmd_data[5] = (gateway_cmd_length >> 16) & 0xFF;
|
||||
gateway_cmd_data[6] = (gateway_cmd_length >> 8) & 0xFF;
|
||||
gateway_cmd_data[7] = gateway_cmd_length & 0xFF;
|
||||
gateway_cmd_data[8] = (gateway->panid >> 8) & 0xFF;
|
||||
gateway_cmd_data[9] = gateway->panid & 0xFF;
|
||||
gateway_cmd_data[10] = client_id;
|
||||
gateway_cmd_data[11] = gateway->gateway_id;
|
||||
gateway_cmd_data[12] = (gateway_cmd_type >> 8) & 0xFF;
|
||||
gateway_cmd_data[13] = gateway_cmd_type & 0xFF;
|
||||
|
||||
gateway_cmd_data[ADAPTER_LORA_TRANSFER_DATA_LENGTH - 2] = ADAPTER_LORA_DATA_END;
|
||||
gateway_cmd_data[ADAPTER_LORA_TRANSFER_DATA_LENGTH - 1] = ADAPTER_LORA_DATA_END;
|
||||
|
||||
if (AdapterDeviceSend(adapter, (uint8 *)&gateway_cmd_data, gateway_cmd_data.length) < 0) {
|
||||
if (AdapterDeviceSend(adapter, gateway_cmd_data, ADAPTER_LORA_TRANSFER_DATA_LENGTH) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -292,6 +322,8 @@ static int LoraGatewayHandleData(struct Adapter *adapter, struct LoraDataFormat
|
||||
/*User needs to handle client data depends on the requirement*/
|
||||
printf("Lora Gateway receive Client %d data:\n", gateway_recv_data->client_id);
|
||||
printf("%s\n", gateway_recv_data->data);
|
||||
|
||||
PrivSemaphoreAbandon(&gateway_recv_data_sem);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -324,8 +356,9 @@ static int LoraClientUpdate(struct Adapter *adapter, struct LoraDataFormat *clie
|
||||
* @param adapter Lora adapter pointer
|
||||
* @param send_buf Lora Client send user data buf
|
||||
* @param length user data length (max size is ADAPTER_LORA_DATA_LENGTH)
|
||||
* @param send_index user data index, max size ADAPTER_LORA_DATA_LENGTH single index
|
||||
*/
|
||||
static int LoraClientSendData(struct Adapter *adapter, void *send_buf, int length)
|
||||
static int LoraClientSendData(struct Adapter *adapter, void *send_buf, int length, uint16_t send_index)
|
||||
{
|
||||
struct LoraClientParam *client = (struct LoraClientParam *)adapter->adapter_param;
|
||||
|
||||
@@ -339,22 +372,35 @@ static int LoraClientSendData(struct Adapter *adapter, void *send_buf, int lengt
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct LoraDataFormat client_user_data;
|
||||
uint16_t client_user_type;
|
||||
uint32_t client_user_length = ADAPTER_LORA_TRANSFER_DATA_LENGTH;
|
||||
uint8_t client_user_data[ADAPTER_LORA_TRANSFER_DATA_LENGTH];
|
||||
|
||||
memset(&client_user_data, 0, sizeof(struct LoraDataFormat));
|
||||
memset(client_user_data, 0, ADAPTER_LORA_TRANSFER_DATA_LENGTH);
|
||||
|
||||
client_user_data.flame_head = ADAPTER_LORA_DATA_HEAD;
|
||||
client_user_data.length = sizeof(struct LoraDataFormat);
|
||||
client_user_data.panid = client->panid;
|
||||
client_user_data.data_type = ADAPTER_LORA_DATA_TYPE_USERDATA;
|
||||
client_user_data.client_id = client->client_id;
|
||||
client_user_data.gateway_id = client->gateway_id;
|
||||
client_user_type = ADAPTER_LORA_DATA_TYPE_USERDATA;
|
||||
|
||||
memcpy(client_user_data.data, (uint8 *)send_buf, length);
|
||||
client_user_data[0] = ADAPTER_LORA_DATA_HEAD;
|
||||
client_user_data[1] = ADAPTER_LORA_DATA_HEAD;
|
||||
client_user_data[2] = (send_index >> 8) & 0xFF;
|
||||
client_user_data[3] = send_index & 0xFF;
|
||||
client_user_data[4] = (client_user_length >> 24) & 0xFF;
|
||||
client_user_data[5] = (client_user_length >> 16) & 0xFF;
|
||||
client_user_data[6] = (client_user_length >> 8) & 0xFF;
|
||||
client_user_data[7] = client_user_length & 0xFF;
|
||||
client_user_data[8] = (client->panid >> 8) & 0xFF;
|
||||
client_user_data[9] = client->panid & 0xFF;
|
||||
client_user_data[10] = client->client_id;
|
||||
client_user_data[11] = client->gateway_id;
|
||||
client_user_data[12] = (client_user_type >> 8) & 0xFF;
|
||||
client_user_data[13] = client_user_type & 0xFF;
|
||||
|
||||
client_user_data.crc16 = LoraCrc16((uint8 *)&client_user_data, sizeof(struct LoraDataFormat) - 2);
|
||||
memcpy((uint8_t *)(client_user_data + 14), (uint8_t *)send_buf, length);
|
||||
|
||||
client_user_data[ADAPTER_LORA_TRANSFER_DATA_LENGTH - 2] = ADAPTER_LORA_DATA_END;
|
||||
client_user_data[ADAPTER_LORA_TRANSFER_DATA_LENGTH - 1] = ADAPTER_LORA_DATA_END;
|
||||
|
||||
if (AdapterDeviceSend(adapter, (uint8 *)&client_user_data, client_user_data.length) < 0) {
|
||||
if (AdapterDeviceSend(adapter, client_user_data, ADAPTER_LORA_TRANSFER_DATA_LENGTH) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -364,35 +410,32 @@ static int LoraClientSendData(struct Adapter *adapter, void *send_buf, int lengt
|
||||
/**
|
||||
* @description: Lora Gateway receive data analyzing
|
||||
* @param adapter Lora adapter pointer
|
||||
* @param gateway_recv_data Lora gateway receive data pointer
|
||||
*/
|
||||
static int LoraGateWayDataAnalyze(struct Adapter *adapter, struct LoraDataFormat *gateway_recv_data)
|
||||
static int LoraGateWayDataAnalyze(struct Adapter *adapter)
|
||||
{
|
||||
int ret = 0;
|
||||
printf("%s:gateway_recv_data\n",__func__);
|
||||
printf("head 0x%x length %d panid 0x%x data_type 0x%x client_id 0x%x gateway_id 0x%x crc 0x%x\n",
|
||||
gateway_recv_data->flame_head, gateway_recv_data->length, gateway_recv_data->panid, gateway_recv_data->data_type,
|
||||
gateway_recv_data->client_id, gateway_recv_data->gateway_id, gateway_recv_data->crc16);
|
||||
|
||||
if (LoraCrc16Check((uint8 *)gateway_recv_data, sizeof(struct LoraDataFormat)) < 0) {
|
||||
printf("LoraGateWayDataAnalyze CRC check error\n");
|
||||
return -1;
|
||||
}
|
||||
if (ADAPTER_LORA_NET_PANID == gateway_recv_data_format.panid) {
|
||||
|
||||
if ((ADAPTER_LORA_DATA_HEAD == gateway_recv_data->flame_head) &&
|
||||
(ADAPTER_LORA_NET_PANID == gateway_recv_data->panid)) {
|
||||
switch (gateway_recv_data->data_type)
|
||||
printf("%s: gateway_recv_data\n", __func__);
|
||||
printf("head 0x%x length %d panid 0x%x data_type 0x%x client_id 0x%x gateway_id 0x%x end 0x%x\n",
|
||||
gateway_recv_data_format.flame_head, gateway_recv_data_format.length, gateway_recv_data_format.panid, gateway_recv_data_format.data_type,
|
||||
gateway_recv_data_format.client_id, gateway_recv_data_format.gateway_id, gateway_recv_data_format.flame_end);
|
||||
|
||||
switch (gateway_recv_data_format.data_type)
|
||||
{
|
||||
case ADAPTER_LORA_DATA_TYPE_JOIN :
|
||||
case ADAPTER_LORA_DATA_TYPE_QUIT :
|
||||
ret = LoraGatewayReply(adapter, gateway_recv_data);
|
||||
ret = LoraGatewayReply(adapter, &gateway_recv_data_format);
|
||||
break;
|
||||
case ADAPTER_LORA_DATA_TYPE_USERDATA :
|
||||
ret = LoraGatewayHandleData(adapter, gateway_recv_data);
|
||||
ret = LoraGatewayHandleData(adapter, &gateway_recv_data_format);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -403,58 +446,44 @@ static int LoraGateWayDataAnalyze(struct Adapter *adapter, struct LoraDataFormat
|
||||
* @param adapter Lora adapter pointer
|
||||
* @param send_buf Lora Client send user data buf
|
||||
* @param length user data length (max size is ADAPTER_LORA_DATA_LENGTH)
|
||||
* @param index user data index, max size ADAPTER_LORA_DATA_LENGTH single index
|
||||
*/
|
||||
static int LoraClientDataAnalyze(struct Adapter *adapter, void *send_buf, int length)
|
||||
static int LoraClientDataAnalyze(struct Adapter *adapter, void *send_buf, int length, uint16_t index)
|
||||
{
|
||||
int ret = 0;
|
||||
uint8 lora_recv_data[ADAPTER_LORA_RECV_DATA_LENGTH] = {0};
|
||||
|
||||
struct LoraDataFormat *client_recv_data = PrivMalloc(sizeof(struct LoraDataFormat));
|
||||
|
||||
memset(client_recv_data, 0, sizeof(struct LoraDataFormat));
|
||||
|
||||
ret = AdapterDeviceRecv(adapter, lora_recv_data, ADAPTER_LORA_RECV_DATA_LENGTH);
|
||||
if (ret <= 0) {
|
||||
printf("LoraClientDataAnalyze recv error.Just return\n");
|
||||
PrivFree(client_recv_data);
|
||||
return -1;
|
||||
}
|
||||
|
||||
LoraReceiveDataCheck(lora_recv_data, ADAPTER_LORA_RECV_DATA_LENGTH, client_recv_data);
|
||||
|
||||
printf("%s:client_recv_data\n",__func__);
|
||||
printf("head 0x%x length %d panid 0x%x data_type 0x%x client_id 0x%x gateway_id 0x%x crc 0x%x\n",
|
||||
client_recv_data->flame_head, client_recv_data->length, client_recv_data->panid, client_recv_data->data_type,
|
||||
client_recv_data->client_id, client_recv_data->gateway_id, client_recv_data->crc16);
|
||||
|
||||
if ((ADAPTER_LORA_DATA_HEAD == client_recv_data->flame_head) &&
|
||||
(ADAPTER_LORA_NET_PANID == client_recv_data->panid)) {
|
||||
if (LoraCrc16Check((uint8 *)client_recv_data, sizeof(struct LoraDataFormat)) < 0) {
|
||||
printf("LoraClientDataAnalyze CRC check error\n");
|
||||
PrivFree(client_recv_data);
|
||||
return -1;
|
||||
}
|
||||
uint8_t client_id = adapter->net_role_id;
|
||||
|
||||
ret = PrivSemaphoreObtainWait(&adapter->sem, NULL);
|
||||
if (0 == ret) {
|
||||
//only handle this client_id information from gateway
|
||||
if (client_recv_data->client_id == adapter->net_role_id) {
|
||||
switch (client_recv_data->data_type)
|
||||
if ((client_recv_data_format[client_id - 1].client_id == adapter->net_role_id) &&
|
||||
(ADAPTER_LORA_NET_PANID == client_recv_data_format[client_id - 1].panid)) {
|
||||
|
||||
printf("%s: 0x%x client_recv_data\n", __func__, client_recv_data_format[client_id - 1].client_id);
|
||||
printf("head 0x%x length %d panid 0x%x data_type 0x%x client_id 0x%x gateway_id 0x%x end 0x%x\n",
|
||||
client_recv_data_format[client_id - 1].flame_head, client_recv_data_format[client_id - 1].length, client_recv_data_format[client_id - 1].panid, client_recv_data_format[client_id - 1].data_type,
|
||||
client_recv_data_format[client_id - 1].client_id, client_recv_data_format[client_id - 1].gateway_id, client_recv_data_format[client_id - 1].flame_end);
|
||||
|
||||
switch (client_recv_data_format[client_id - 1].data_type)
|
||||
{
|
||||
case ADAPTER_LORA_DATA_TYPE_JOIN_REPLY :
|
||||
case ADAPTER_LORA_DATA_TYPE_QUIT_REPLY :
|
||||
ret = LoraClientUpdate(adapter, client_recv_data);
|
||||
ret = LoraClientUpdate(adapter, &client_recv_data_format[client_id - 1]);
|
||||
break;
|
||||
case ADAPTER_LORA_DATA_TYPE_CMD :
|
||||
if (send_buf) {
|
||||
ret = LoraClientSendData(adapter, send_buf, length);
|
||||
ret = LoraClientSendData(adapter, send_buf, length, index);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
//Client operation done
|
||||
memset(&client_recv_data_format[client_id - 1], 0 , sizeof(struct LoraDataFormat));
|
||||
}
|
||||
}
|
||||
|
||||
PrivFree(client_recv_data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -465,26 +494,43 @@ static int LoraClientDataAnalyze(struct Adapter *adapter, void *send_buf, int le
|
||||
*/
|
||||
static int LoraClientJoinNet(struct Adapter *adapter, unsigned short panid)
|
||||
{
|
||||
struct LoraDataFormat client_join_data;
|
||||
struct AdapterData priv_lora_net;
|
||||
|
||||
memset(&client_join_data, 0, sizeof(struct LoraDataFormat));
|
||||
uint16_t client_join_type;
|
||||
uint32_t client_join_length = ADAPTER_LORA_TRANSFER_DATA_LENGTH;
|
||||
uint8_t client_join_data[ADAPTER_LORA_TRANSFER_DATA_LENGTH];
|
||||
|
||||
client_join_data.flame_head = ADAPTER_LORA_DATA_HEAD;
|
||||
client_join_data.length = sizeof(struct LoraDataFormat);
|
||||
client_join_data.panid = panid;
|
||||
client_join_data.data_type = ADAPTER_LORA_DATA_TYPE_JOIN;
|
||||
client_join_data.client_id = adapter->net_role_id;
|
||||
client_join_data.crc16 = LoraCrc16((uint8 *)&client_join_data, sizeof(struct LoraDataFormat) - 2);
|
||||
memset(client_join_data, 0, ADAPTER_LORA_TRANSFER_DATA_LENGTH);
|
||||
|
||||
printf("%s:client_join_data\n",__func__);
|
||||
printf("head 0x%x length %d panid 0x%x data_type 0x%x client_id 0x%x gateway_id 0x%x crc 0x%x\n",
|
||||
client_join_data.flame_head, client_join_data.length, client_join_data.panid, client_join_data.data_type,
|
||||
client_join_data.client_id, client_join_data.gateway_id, client_join_data.crc16);
|
||||
|
||||
if (AdapterDeviceJoin(adapter, (uint8 *)&client_join_data) < 0) {
|
||||
client_join_type = ADAPTER_LORA_DATA_TYPE_JOIN;
|
||||
|
||||
client_join_data[0] = ADAPTER_LORA_DATA_HEAD;
|
||||
client_join_data[1] = ADAPTER_LORA_DATA_HEAD;
|
||||
client_join_data[2] = 0;
|
||||
client_join_data[3] = 0;
|
||||
client_join_data[4] = (client_join_length >> 24) & 0xFF;
|
||||
client_join_data[5] = (client_join_length >> 16) & 0xFF;
|
||||
client_join_data[6] = (client_join_length >> 8) & 0xFF;
|
||||
client_join_data[7] = client_join_length & 0xFF;
|
||||
client_join_data[8] = (panid >> 8) & 0xFF;
|
||||
client_join_data[9] = panid & 0xFF;
|
||||
client_join_data[10] = adapter->net_role_id & 0xFF;
|
||||
client_join_data[11] = 0;
|
||||
client_join_data[12] = (client_join_type >> 8) & 0xFF;
|
||||
client_join_data[13] = client_join_type & 0xFF;
|
||||
|
||||
client_join_data[ADAPTER_LORA_TRANSFER_DATA_LENGTH - 2] = ADAPTER_LORA_DATA_END;
|
||||
client_join_data[ADAPTER_LORA_TRANSFER_DATA_LENGTH - 1] = ADAPTER_LORA_DATA_END;
|
||||
|
||||
priv_lora_net.len = ADAPTER_LORA_TRANSFER_DATA_LENGTH;
|
||||
priv_lora_net.buffer = client_join_data;
|
||||
|
||||
if (AdapterDeviceJoin(adapter, (uint8_t *)&priv_lora_net) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("%s:client_join_data panid 0x%x client_id 0x%x\n", __func__, panid, adapter->net_role_id);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -495,21 +541,135 @@ static int LoraClientJoinNet(struct Adapter *adapter, unsigned short panid)
|
||||
*/
|
||||
static int LoraClientQuitNet(struct Adapter *adapter, unsigned short panid)
|
||||
{
|
||||
struct LoraDataFormat client_join_data;
|
||||
struct AdapterData priv_lora_net;
|
||||
|
||||
memset(&client_join_data, 0, sizeof(struct LoraDataFormat));
|
||||
uint16_t client_quit_type;
|
||||
uint32_t client_quit_length = ADAPTER_LORA_TRANSFER_DATA_LENGTH;
|
||||
uint8_t client_quit_data[ADAPTER_LORA_TRANSFER_DATA_LENGTH];
|
||||
|
||||
client_join_data.flame_head = ADAPTER_LORA_DATA_HEAD;
|
||||
client_join_data.length = sizeof(struct LoraDataFormat);
|
||||
client_join_data.panid = panid;
|
||||
client_join_data.data_type = ADAPTER_LORA_DATA_TYPE_QUIT;
|
||||
client_join_data.client_id = adapter->net_role_id;
|
||||
client_join_data.crc16 = LoraCrc16((uint8 *)&client_join_data, sizeof(struct LoraDataFormat) - 2);
|
||||
|
||||
if (AdapterDeviceDisconnect(adapter, (uint8 *)&client_join_data) < 0) {
|
||||
memset(client_quit_data, 0, ADAPTER_LORA_TRANSFER_DATA_LENGTH);
|
||||
|
||||
client_quit_type = ADAPTER_LORA_DATA_TYPE_QUIT;
|
||||
|
||||
client_quit_data[0] = ADAPTER_LORA_DATA_HEAD;
|
||||
client_quit_data[1] = ADAPTER_LORA_DATA_HEAD;
|
||||
client_quit_data[2] = 0;
|
||||
client_quit_data[3] = 0;
|
||||
client_quit_data[4] = (client_quit_length >> 24) & 0xFF;
|
||||
client_quit_data[5] = (client_quit_length >> 16) & 0xFF;
|
||||
client_quit_data[6] = (client_quit_length >> 8) & 0xFF;
|
||||
client_quit_data[7] = client_quit_length & 0xFF;
|
||||
client_quit_data[8] = (panid >> 8) & 0xFF;
|
||||
client_quit_data[9] = panid & 0xFF;
|
||||
client_quit_data[10] = adapter->net_role_id & 0xFF;
|
||||
client_quit_data[11] = 0;
|
||||
client_quit_data[12] = (client_quit_type >> 8) & 0xFF;
|
||||
client_quit_data[13] = client_quit_type & 0xFF;
|
||||
|
||||
client_quit_data[ADAPTER_LORA_TRANSFER_DATA_LENGTH - 2] = ADAPTER_LORA_DATA_END;
|
||||
client_quit_data[ADAPTER_LORA_TRANSFER_DATA_LENGTH - 1] = ADAPTER_LORA_DATA_END;
|
||||
|
||||
priv_lora_net.len = ADAPTER_LORA_TRANSFER_DATA_LENGTH;
|
||||
priv_lora_net.buffer = client_quit_data;
|
||||
|
||||
if (AdapterDeviceDisconnect(adapter, (uint8_t *)&priv_lora_net) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("%s:client_quit_data panid 0x%x client_id 0x%x\n", __func__, panid, adapter->net_role_id);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Lora receive data check
|
||||
* @param adapter Lora adapter pointer
|
||||
* @param recv_data receive data buffer
|
||||
* @param length receive data length
|
||||
*/
|
||||
static int LoraReceiveDataCheck(struct Adapter *adapter, uint8_t *recv_data, uint16_t length)
|
||||
{
|
||||
int ret;
|
||||
uint8_t client_id;
|
||||
|
||||
if ((ADAPTER_LORA_DATA_HEAD == recv_data[0]) && (ADAPTER_LORA_DATA_HEAD == recv_data[1]) &&
|
||||
(ADAPTER_LORA_DATA_END == recv_data[length - 1]) && (ADAPTER_LORA_DATA_END == recv_data[length - 2])) {
|
||||
|
||||
#ifdef AS_LORA_GATEWAY_ROLE
|
||||
gateway_recv_data_format.flame_head = ((recv_data[0] << 8) & 0xFF00) | recv_data[1];
|
||||
gateway_recv_data_format.flame_index = ((recv_data[2] << 8) & 0xFF00) | recv_data[3];
|
||||
gateway_recv_data_format.length = ((recv_data[4] << 24) & 0xFF000000) | ((recv_data[5] << 16) & 0xFF0000) |
|
||||
((recv_data[6] << 8) & 0xFF00) | (recv_data[7] & 0xFF);
|
||||
gateway_recv_data_format.panid = ((recv_data[8] << 8) & 0xFF00) | recv_data[9];
|
||||
gateway_recv_data_format.client_id = recv_data[10];
|
||||
gateway_recv_data_format.gateway_id = recv_data[11];
|
||||
gateway_recv_data_format.data_type = ((recv_data[12] << 8) & 0xFF00) | recv_data[13];
|
||||
|
||||
gateway_recv_data_format.flame_end = ((recv_data[length - 2] << 8) & 0xFF00) | recv_data[length - 1];
|
||||
|
||||
memcpy(gateway_recv_data_format.data, (uint8_t *)(recv_data + 14), ADAPTER_LORA_DATA_LENGTH);
|
||||
|
||||
ret = LoraGateWayDataAnalyze(adapter);
|
||||
|
||||
return ret;
|
||||
#else
|
||||
client_id = recv_data[10];
|
||||
|
||||
if (client_id == adapter->net_role_id) {
|
||||
printf("client_id 0x%x recv data\n", client_id);
|
||||
client_recv_data_format[client_id - 1].flame_head = ((recv_data[0] << 8) & 0xFF00) | recv_data[1];
|
||||
client_recv_data_format[client_id - 1].flame_index = ((recv_data[2] << 8) & 0xFF00) | recv_data[3];
|
||||
client_recv_data_format[client_id - 1].length = ((recv_data[4] << 24) & 0xFF000000) | ((recv_data[5] << 16) & 0xFF0000) |
|
||||
((recv_data[6] << 8) & 0xFF00) | (recv_data[7] & 0xFF);
|
||||
client_recv_data_format[client_id - 1].panid = ((recv_data[8] << 8) & 0xFF00) | recv_data[9];
|
||||
client_recv_data_format[client_id - 1].client_id = recv_data[10];
|
||||
client_recv_data_format[client_id - 1].gateway_id = recv_data[11];
|
||||
client_recv_data_format[client_id - 1].data_type = ((recv_data[12] << 8) & 0xFF00) | recv_data[13];
|
||||
|
||||
client_recv_data_format[client_id - 1].flame_end = ((recv_data[length - 2] << 8) & 0xFF00) | recv_data[length - 1];
|
||||
|
||||
memcpy(client_recv_data_format[client_id - 1].data, (uint8_t *)(recv_data + 14), ADAPTER_LORA_DATA_LENGTH);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Lora data receive task
|
||||
* @param parameter - Lora adapter pointer
|
||||
*/
|
||||
static void *LoraReceiveTask(void *parameter)
|
||||
{
|
||||
int ret = 0;
|
||||
struct Adapter *lora_adapter = (struct Adapter *)parameter;
|
||||
|
||||
while (1) {
|
||||
memset(lora_recv_data, 0, ADAPTER_LORA_TRANSFER_DATA_LENGTH);
|
||||
|
||||
ret = AdapterDeviceRecv(lora_adapter, lora_recv_data, ADAPTER_LORA_TRANSFER_DATA_LENGTH);
|
||||
if (ret <= 0) {
|
||||
printf("AdapterDeviceRecv error.Just return\n");
|
||||
recv_error_cnt++;
|
||||
if (recv_error_cnt > ADAPTER_LORA_RECEIVE_ERROR_CNT) {
|
||||
recv_error_cnt = 0;
|
||||
#ifdef AS_LORA_GATEWAY_ROLE
|
||||
PrivSemaphoreAbandon(&gateway_recv_data_sem);
|
||||
#endif
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
ret = LoraReceiveDataCheck(lora_adapter, lora_recv_data, ADAPTER_LORA_TRANSFER_DATA_LENGTH);
|
||||
if (ret < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
PrivSemaphoreAbandon(&lora_adapter->sem);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -517,81 +677,30 @@ static int LoraClientQuitNet(struct Adapter *adapter, unsigned short panid)
|
||||
* @description: Lora Gateway Process function
|
||||
* @param lora_adapter Lora adapter pointer
|
||||
* @param gateway Lora gateway pointer
|
||||
* @param gateway_recv_data Lora gateway receive data pointer
|
||||
*/
|
||||
int LoraGatewayProcess(struct Adapter *lora_adapter, struct LoraGatewayParam *gateway, struct LoraDataFormat *gateway_recv_data)
|
||||
void LoraGatewayProcess(struct Adapter *lora_adapter, struct LoraGatewayParam *gateway)
|
||||
{
|
||||
int i, ret = 0;
|
||||
uint8 lora_recv_data[ADAPTER_LORA_RECV_DATA_LENGTH];
|
||||
switch (LoraGatewayState)
|
||||
{
|
||||
case LORA_STATE_IDLE:
|
||||
memset(lora_recv_data, 0, ADAPTER_LORA_RECV_DATA_LENGTH);
|
||||
|
||||
ret = AdapterDeviceRecv(lora_adapter, lora_recv_data, ADAPTER_LORA_RECV_DATA_LENGTH);
|
||||
if (ret <= 0) {
|
||||
printf("LoraGatewayProcess IDLE recv error.Just return\n");
|
||||
break;
|
||||
}
|
||||
#ifdef GATEWAY_CMD_MODE
|
||||
for (i = 0; i < gateway->client_num; i ++) {
|
||||
if (gateway->client_id[i]) {
|
||||
printf("LoraGatewayProcess send to client %d for data\n", gateway->client_id[i]);
|
||||
ret = LoraGatewaySendCmd(lora_adapter, gateway->client_id[i], ADAPTER_LORA_DATA_TYPE_CMD);
|
||||
if (ret < 0) {
|
||||
printf("LoraGatewaySendCmd client ID %d error\n", gateway->client_id[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
LoraReceiveDataCheck(lora_recv_data, ADAPTER_LORA_RECV_DATA_LENGTH, gateway_recv_data);
|
||||
|
||||
if (ADAPTER_LORA_DATA_TYPE_JOIN == gateway_recv_data->data_type) {
|
||||
LoraGatewayState = LORA_JOIN_NET;
|
||||
} else if (ADAPTER_LORA_DATA_TYPE_QUIT == gateway_recv_data->data_type) {
|
||||
LoraGatewayState = LORA_QUIT_NET;
|
||||
} else {
|
||||
LoraGatewayState = LORA_STATE_IDLE;
|
||||
}
|
||||
break;
|
||||
case LORA_JOIN_NET:
|
||||
case LORA_QUIT_NET:
|
||||
ret = LoraGateWayDataAnalyze(lora_adapter, gateway_recv_data);
|
||||
if (ret < 0) {
|
||||
printf("LoraGateWayDataAnalyze state %d error, re-send data cmd to client\n", LoraGatewayState);
|
||||
PrivTaskDelay(500);
|
||||
}
|
||||
LoraGatewayState = LORA_RECV_DATA;
|
||||
break;
|
||||
case LORA_RECV_DATA:
|
||||
for (i = 0; i < gateway->client_num; i ++) {
|
||||
if (gateway->client_id[i]) {
|
||||
printf("LoraGatewayProcess send to client %d for data\n", gateway->client_id[i]);
|
||||
ret = LoraGatewaySendCmd(lora_adapter, gateway->client_id[i], ADAPTER_LORA_DATA_TYPE_CMD);
|
||||
if (ret < 0) {
|
||||
printf("LoraGatewaySendCmd client ID %d error\n", gateway->client_id[i]);
|
||||
PrivTaskDelay(500);
|
||||
continue;
|
||||
}
|
||||
|
||||
memset(lora_recv_data, 0, ADAPTER_LORA_RECV_DATA_LENGTH);
|
||||
ret = AdapterDeviceRecv(lora_adapter, lora_recv_data, ADAPTER_LORA_RECV_DATA_LENGTH);
|
||||
if (ret <= 0) {
|
||||
printf("LoraGatewayProcess recv error.Just return\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
LoraReceiveDataCheck(lora_recv_data, ADAPTER_LORA_RECV_DATA_LENGTH, gateway_recv_data);
|
||||
|
||||
if (ADAPTER_LORA_DATA_TYPE_JOIN == gateway_recv_data->data_type) {
|
||||
LoraGatewayState = LORA_JOIN_NET;
|
||||
} else if (ADAPTER_LORA_DATA_TYPE_QUIT == gateway_recv_data->data_type) {
|
||||
LoraGatewayState = LORA_QUIT_NET;
|
||||
} else {
|
||||
ret = LoraGateWayDataAnalyze(lora_adapter, gateway_recv_data);
|
||||
if (ret < 0) {
|
||||
printf("LoraGateWayDataAnalyze error, re-send data cmd to client\n");
|
||||
PrivTaskDelay(500);
|
||||
}
|
||||
}
|
||||
ret = PrivSemaphoreObtainWait(&gateway_recv_data_sem, NULL);
|
||||
if (0 == ret) {
|
||||
printf("LoraGatewayProcess receive client %d data done\n", gateway->client_id[i]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -604,10 +713,16 @@ static void *LoraGatewayTask(void *parameter)
|
||||
int ret = 0;
|
||||
struct Adapter *lora_adapter = (struct Adapter *)parameter;
|
||||
struct LoraGatewayParam *gateway = (struct LoraGatewayParam *)lora_adapter->adapter_param;
|
||||
struct LoraDataFormat gateway_recv_data;
|
||||
|
||||
memset(&gateway_recv_data_format, 0, sizeof(struct LoraDataFormat));
|
||||
|
||||
gateway->client_num = ADAPTER_LORA_CLIENT_NUM;
|
||||
for (i = 0; i < ADAPTER_LORA_CLIENT_NUM;i ++) {
|
||||
gateway->client_id[i] = i + 1;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
LoraGatewayProcess(lora_adapter, gateway, &gateway_recv_data);
|
||||
LoraGatewayProcess(lora_adapter, gateway);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -620,73 +735,39 @@ static void *LoraGatewayTask(void *parameter)
|
||||
static void *LoraClientDataTask(void *parameter)
|
||||
{
|
||||
int i, ret = 0;
|
||||
int join_times = 10;
|
||||
struct Adapter *lora_adapter = (struct Adapter *)parameter;
|
||||
struct LoraClientParam *client = (struct LoraClientParam *)lora_adapter->adapter_param;
|
||||
|
||||
for (i = 0; i < ADAPTER_LORA_CLIENT_NUM; i ++) {
|
||||
memset(&client_recv_data_format[i], 0, sizeof(struct LoraDataFormat));
|
||||
}
|
||||
|
||||
client->gateway_id = 0xFF;
|
||||
client->panid = ADAPTER_LORA_NET_PANID;
|
||||
client->client_state = CLIENT_CONNECT;
|
||||
|
||||
//set lora_send_buf for test
|
||||
uint8 lora_send_buf[ADAPTER_LORA_DATA_LENGTH];
|
||||
uint8_t lora_send_buf[ADAPTER_LORA_DATA_LENGTH];
|
||||
memset(lora_send_buf, 0, ADAPTER_LORA_DATA_LENGTH);
|
||||
sprintf(lora_send_buf, "Lora client %d adapter test\n", client->client_id);
|
||||
|
||||
while (1) {
|
||||
|
||||
PrivTaskDelay(100);
|
||||
|
||||
if ((CLIENT_DISCONNECT == client->client_state) && (!g_adapter_lora_quit_flag)) {
|
||||
ret = LoraClientJoinNet(lora_adapter, client->panid);
|
||||
if (ret < 0) {
|
||||
printf("LoraClientJoinNet error panid 0x%x\n", client->panid);
|
||||
}
|
||||
|
||||
ret = LoraClientDataAnalyze(lora_adapter, NULL, 0);
|
||||
if (ret < 0) {
|
||||
printf("LoraClientDataAnalyze error, reconnect to gateway\n");
|
||||
PrivTaskDelay(500);
|
||||
continue;
|
||||
}
|
||||
//Condition 1: Gateway send user_data cmd, client send user_data after receiving user_data cmd
|
||||
#ifdef GATEWAY_CMD_MODE
|
||||
ret = LoraClientDataAnalyze(lora_adapter, (void *)lora_send_buf, strlen(lora_send_buf), 0);
|
||||
if (ret < 0) {
|
||||
printf("LoraClientDataAnalyze error, wait for next data cmd\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (CLIENT_CONNECT == client->client_state) {
|
||||
ret = LoraClientDataAnalyze(lora_adapter, (void *)lora_send_buf, strlen(lora_send_buf));
|
||||
if (ret < 0) {
|
||||
printf("LoraClientDataAnalyze error, wait for next data cmd\n");
|
||||
PrivTaskDelay(500);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Lora Client quit task
|
||||
* @param parameter - Lora adapter pointer
|
||||
*/
|
||||
static void *LoraClientQuitTask(void *parameter)
|
||||
{
|
||||
int ret = 0;
|
||||
struct Adapter *lora_adapter = (struct Adapter *)parameter;
|
||||
struct LoraClientParam *client = (struct LoraClientParam *)lora_adapter->adapter_param;
|
||||
|
||||
while (1) {
|
||||
PrivTaskDelay(100);
|
||||
|
||||
if ((CLIENT_CONNECT == client->client_state) && (g_adapter_lora_quit_flag)) {
|
||||
ret = LoraClientQuitNet(lora_adapter, client->panid);
|
||||
if (ret < 0) {
|
||||
printf("LoraClientQuitNet error panid 0x%x, re-quit net\n", client->panid);
|
||||
continue;
|
||||
}
|
||||
|
||||
ret = LoraClientDataAnalyze(lora_adapter, NULL, 0);
|
||||
if (ret < 0) {
|
||||
printf("LoraClientQuitTask LoraClientDataAnalyze error\n");
|
||||
PrivTaskDelay(500);
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
//Condition 2: client send user_data automatically
|
||||
#ifdef CLIENT_UPDATE_MODE
|
||||
if (lora_send_buf) {
|
||||
PrivTaskDelay(2000);
|
||||
printf("LoraClientSendData\n");
|
||||
LoraClientSendData(lora_adapter, (void *)lora_send_buf, strlen(lora_send_buf), 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -786,15 +867,35 @@ int AdapterLoraInit(void)
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef ADAPTER_E220
|
||||
AdapterProductInfoType product_info = E220Attach(adapter);
|
||||
if (!product_info) {
|
||||
printf("AdapterLoraInit e220 attach error\n");
|
||||
PrivFree(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
adapter->product_info_flag = 1;
|
||||
adapter->info = product_info;
|
||||
adapter->done = product_info->model_done;
|
||||
#endif
|
||||
|
||||
PrivSemaphoreCreate(&adapter->sem, 0, 0);
|
||||
|
||||
PrivSemaphoreCreate(&gateway_recv_data_sem, 0, 0);
|
||||
|
||||
PrivMutexCreate(&adapter->lock, 0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/******************Lora TEST*********************/
|
||||
static pthread_t lora_recv_data_task;
|
||||
|
||||
#ifdef AS_LORA_GATEWAY_ROLE
|
||||
static pthread_t lora_gateway_task;
|
||||
#else //AS_LORA_CLIENT_ROLE
|
||||
static pthread_t lora_client_data_task;
|
||||
static pthread_t lora_client_quit_task;
|
||||
#endif
|
||||
|
||||
int AdapterLoraTest(void)
|
||||
@@ -815,6 +916,15 @@ int AdapterLoraTest(void)
|
||||
lora_gateway_attr.stacksize = 2048;
|
||||
#endif
|
||||
|
||||
PrivTaskCreate(&lora_recv_data_task, &lora_gateway_attr, &LoraReceiveTask, (void *)adapter);
|
||||
PrivTaskStartup(&lora_recv_data_task);
|
||||
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
lora_gateway_attr.priority = 19;
|
||||
#else
|
||||
lora_gateway_attr.schedparam.sched_priority = 19;
|
||||
#endif
|
||||
|
||||
PrivTaskCreate(&lora_gateway_task, &lora_gateway_attr, &LoraGatewayTask, (void *)adapter);
|
||||
PrivTaskStartup(&lora_gateway_task);
|
||||
|
||||
@@ -828,14 +938,19 @@ int AdapterLoraTest(void)
|
||||
lora_client_attr.schedparam.sched_priority = 20;
|
||||
lora_client_attr.stacksize = 2048;
|
||||
#endif
|
||||
PrivTaskCreate(&lora_recv_data_task, &lora_client_attr, &LoraReceiveTask, (void *)adapter);
|
||||
PrivTaskStartup(&lora_recv_data_task);
|
||||
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
lora_client_attr.priority = 19;
|
||||
#else
|
||||
lora_client_attr.schedparam.sched_priority = 19;
|
||||
#endif
|
||||
|
||||
//create lora client task
|
||||
PrivTaskCreate(&lora_client_data_task, &lora_client_attr, &LoraClientDataTask, (void *)adapter);
|
||||
PrivTaskStartup(&lora_client_data_task);
|
||||
|
||||
lora_client_attr.stacksize = 1024;
|
||||
|
||||
PrivTaskCreate(&lora_client_quit_task, &lora_client_attr, &LoraClientQuitTask, (void *)adapter);
|
||||
PrivTaskStartup(&lora_client_quit_task);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
||||
44
APP_Framework/Framework/connection/lora/e220/Kconfig
Normal file
44
APP_Framework/Framework/connection/lora/e220/Kconfig
Normal file
@@ -0,0 +1,44 @@
|
||||
config ADAPTER_LORA_E220
|
||||
string "E220-400T22S adapter name"
|
||||
default "e220"
|
||||
|
||||
if ADD_XIZI_FETURES
|
||||
config ADAPTER_E220_M0
|
||||
int "E220 M0 pin number"
|
||||
default "11"
|
||||
|
||||
config ADAPTER_E220_M1
|
||||
int "E220 M1 pin number"
|
||||
default "9"
|
||||
|
||||
config ADAPTER_E220_PIN_DRIVER
|
||||
string "E220 device pin driver path"
|
||||
default "/dev/pin_dev"
|
||||
|
||||
config ADAPTER_E220_DRIVER_EXTUART
|
||||
bool "Using extra uart to support lora"
|
||||
default y
|
||||
|
||||
config ADAPTER_E220_DRIVER
|
||||
string "E220 device uart driver path"
|
||||
default "/dev/uart1_dev1"
|
||||
depends on !ADAPTER_E220_DRIVER_EXTUART
|
||||
|
||||
if ADAPTER_E220_DRIVER_EXTUART
|
||||
config ADAPTER_E220_DRIVER
|
||||
string "E220 device extra uart driver path"
|
||||
default "/dev/extuart_dev3"
|
||||
|
||||
config ADAPTER_E220_DRIVER_EXT_PORT
|
||||
int "if E220 device using extuart, choose port"
|
||||
default "3"
|
||||
endif
|
||||
endif
|
||||
|
||||
if ADD_NUTTX_FETURES
|
||||
|
||||
endif
|
||||
|
||||
if ADD_RTTHREAD_FETURES
|
||||
|
||||
endif
|
||||
3
APP_Framework/Framework/connection/lora/e220/Makefile
Normal file
3
APP_Framework/Framework/connection/lora/e220/Makefile
Normal file
@@ -0,0 +1,3 @@
|
||||
SRC_FILES := e220.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
556
APP_Framework/Framework/connection/lora/e220/e220.c
Normal file
556
APP_Framework/Framework/connection/lora/e220/e220.c
Normal file
@@ -0,0 +1,556 @@
|
||||
/*
|
||||
* 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 e220.c
|
||||
* @brief Implement the connection E220-400T22S lora adapter function
|
||||
* @version 2.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2022.4.20
|
||||
*/
|
||||
|
||||
#include <adapter.h>
|
||||
|
||||
#define E220_GATEWAY_ADDRESS 0xFFFF
|
||||
#define E220_CHANNEL 0x04
|
||||
|
||||
#ifdef AS_LORA_GATEWAY_ROLE
|
||||
#define E220_ADDRESS E220_GATEWAY_ADDRESS
|
||||
#endif
|
||||
|
||||
#ifdef AS_LORA_CLIENT_ROLE
|
||||
#define E220_ADDRESS ADAPTER_LORA_NET_ROLE_ID
|
||||
#endif
|
||||
|
||||
#define E220_UART_BAUD_RATE 115200
|
||||
|
||||
enum E220LoraMode
|
||||
{
|
||||
DATA_TRANSFER_MODE = 0, //M1 : M0 = 0 : 0
|
||||
WOR_SEND_MODE, //M1 : M0 = 0 : 1
|
||||
WOR_RECEIVE_MODE, //M1 : M0 = 1 : 0
|
||||
CONFIGURE_MODE_MODE, //M1 : M0 = 1 : 1
|
||||
};
|
||||
|
||||
/**
|
||||
* @description: Config E220 work mode by set M1/M0 pin
|
||||
* @param mode Lora working mode
|
||||
* @return NULL
|
||||
*/
|
||||
static void E220LoraModeConfig(enum E220LoraMode mode)
|
||||
{
|
||||
//delay 1s , wait AUX ready
|
||||
PrivTaskDelay(1000);
|
||||
|
||||
int pin_fd;
|
||||
pin_fd = PrivOpen(ADAPTER_E220_PIN_DRIVER, O_RDWR);
|
||||
if (pin_fd < 0) {
|
||||
printf("open %s error\n", ADAPTER_E220_PIN_DRIVER);
|
||||
return;
|
||||
}
|
||||
|
||||
//Step1: config M0 and M1 GPIO
|
||||
struct PinParam pin_param;
|
||||
pin_param.cmd = GPIO_CONFIG_MODE;
|
||||
pin_param.mode = GPIO_CFG_OUTPUT;
|
||||
pin_param.pin = ADAPTER_E220_M0;
|
||||
|
||||
struct PrivIoctlCfg ioctl_cfg;
|
||||
ioctl_cfg.ioctl_driver_type = PIN_TYPE;
|
||||
ioctl_cfg.args = &pin_param;
|
||||
PrivIoctl(pin_fd, OPE_CFG, &ioctl_cfg);
|
||||
|
||||
pin_param.pin = ADAPTER_E220_M1;
|
||||
ioctl_cfg.args = &pin_param;
|
||||
PrivIoctl(pin_fd, OPE_CFG, &ioctl_cfg);
|
||||
|
||||
//Step2 : set M0 and M1 high or low
|
||||
struct PinStat pin_stat;
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case DATA_TRANSFER_MODE:
|
||||
pin_stat.pin = ADAPTER_E220_M1;
|
||||
pin_stat.val = GPIO_LOW;
|
||||
PrivWrite(pin_fd, &pin_stat, 1);
|
||||
|
||||
pin_stat.pin = ADAPTER_E220_M0;
|
||||
pin_stat.val = GPIO_LOW;
|
||||
PrivWrite(pin_fd, &pin_stat, 1);
|
||||
break;
|
||||
|
||||
case WOR_SEND_MODE:
|
||||
pin_stat.pin = ADAPTER_E220_M1;
|
||||
pin_stat.val = GPIO_LOW;
|
||||
PrivWrite(pin_fd, &pin_stat, 1);
|
||||
|
||||
pin_stat.pin = ADAPTER_E220_M0;
|
||||
pin_stat.val = GPIO_HIGH;
|
||||
PrivWrite(pin_fd, &pin_stat, 1);
|
||||
break;
|
||||
|
||||
case WOR_RECEIVE_MODE:
|
||||
pin_stat.pin = ADAPTER_E220_M1;
|
||||
pin_stat.val = GPIO_HIGH;
|
||||
PrivWrite(pin_fd, &pin_stat, 1);
|
||||
|
||||
pin_stat.pin = ADAPTER_E220_M0;
|
||||
pin_stat.val = GPIO_LOW;
|
||||
PrivWrite(pin_fd, &pin_stat, 1);
|
||||
break;
|
||||
|
||||
case CONFIGURE_MODE_MODE:
|
||||
pin_stat.pin = ADAPTER_E220_M1;
|
||||
pin_stat.val = GPIO_HIGH;
|
||||
PrivWrite(pin_fd, &pin_stat, 1);
|
||||
|
||||
pin_stat.pin = ADAPTER_E220_M0;
|
||||
pin_stat.val = GPIO_HIGH;
|
||||
PrivWrite(pin_fd, &pin_stat, 1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
PrivClose(pin_fd);
|
||||
|
||||
//delay 20ms , wait mode switch done
|
||||
PrivTaskDelay(20);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Switch baud rate to register bit
|
||||
* @param baud_rate - baud_rate
|
||||
* @return baud_rate_bit
|
||||
*/
|
||||
static uint8 E220BaudRateSwitch(uint32 baud_rate)
|
||||
{
|
||||
uint8 baud_rate_bit;
|
||||
|
||||
switch (baud_rate)
|
||||
{
|
||||
case 1200:
|
||||
baud_rate_bit = 0x0;
|
||||
break;
|
||||
|
||||
case 2400:
|
||||
baud_rate_bit = 0x1;
|
||||
break;
|
||||
|
||||
case 4800:
|
||||
baud_rate_bit = 0x2;
|
||||
break;
|
||||
|
||||
case 9600:
|
||||
baud_rate_bit = 0x3;
|
||||
break;
|
||||
|
||||
case 19200:
|
||||
baud_rate_bit = 0x4;
|
||||
break;
|
||||
|
||||
case 38400:
|
||||
baud_rate_bit = 0x5;
|
||||
break;
|
||||
|
||||
case 57600:
|
||||
baud_rate_bit = 0x6;
|
||||
break;
|
||||
|
||||
case 115200:
|
||||
baud_rate_bit = 0x7;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return baud_rate_bit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Set E220 register, such as address、channel、baud rate...
|
||||
* @param adapter - lora adapter
|
||||
* @param address - address
|
||||
* @param channel - channel
|
||||
* @param baud_rate - baud_rate
|
||||
* @return success: 0, failure: -1
|
||||
*/
|
||||
static int E220SetRegisterParam(struct Adapter *adapter, uint16 address, uint8 channel, uint32 baud_rate)
|
||||
{
|
||||
int ret;
|
||||
uint8 buffer[50] = {0};
|
||||
uint8 baud_rate_bit = E220BaudRateSwitch(baud_rate);
|
||||
|
||||
E220LoraModeConfig(CONFIGURE_MODE_MODE);
|
||||
PrivTaskDelay(30);
|
||||
|
||||
buffer[0] = 0xC0; //write register order
|
||||
buffer[1] = 0x00; //register start-address
|
||||
buffer[2] = 0x08; //register length
|
||||
|
||||
buffer[3] = (address >> 8) & 0xFF; //high address
|
||||
buffer[4] = address & 0xFF; //low adderss
|
||||
|
||||
buffer[5] = ((baud_rate_bit << 5) & 0xE0) | 0x04;
|
||||
|
||||
buffer[6] = 0x00;
|
||||
buffer[7] = channel; //channel
|
||||
buffer[8] = 0x03;
|
||||
buffer[9] = 0; //high-cipher
|
||||
buffer[10] = 0; //low-cipher
|
||||
|
||||
ret = PrivWrite(adapter->fd, (void *)buffer, 11);
|
||||
if(ret < 0){
|
||||
printf("E220SetRegisterParam send failed %d!\n", ret);
|
||||
}
|
||||
|
||||
PrivRead(adapter->fd, buffer, 11);
|
||||
|
||||
E220LoraModeConfig(DATA_TRANSFER_MODE);
|
||||
PrivTaskDelay(1000);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Get E220 register, such as address、channel、baud rate...
|
||||
* @param buf - data buf
|
||||
* @return success: 0, failure: -1
|
||||
*/
|
||||
static int E220GetRegisterParam(uint8 *buf)
|
||||
{
|
||||
int ret;
|
||||
uint8 buffer[3] = {0};
|
||||
|
||||
struct Adapter *adapter = AdapterDeviceFindByName(ADAPTER_LORA_NAME);
|
||||
if (NULL == adapter) {
|
||||
printf("E220GetRegisterParam find lora adapter error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
E220LoraModeConfig(CONFIGURE_MODE_MODE);
|
||||
PrivTaskDelay(30);
|
||||
|
||||
buffer[0] = 0xC1; //read register order
|
||||
buffer[1] = 0x00; //register start-address
|
||||
buffer[2] = 0x08; //register length
|
||||
|
||||
ret = PrivWrite(adapter->fd, (void *)buffer, 3);
|
||||
if(ret < 0){
|
||||
printf("E220GetRegisterParam send failed %d!\n", ret);
|
||||
}
|
||||
|
||||
PrivRead(adapter->fd, buf, 11);
|
||||
|
||||
E220LoraModeConfig(DATA_TRANSFER_MODE);
|
||||
PrivTaskDelay(30);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Open E220 uart function
|
||||
* @param adapter - Lora device pointer
|
||||
* @return success: 0, failure: -1
|
||||
*/
|
||||
static int E220Open(struct Adapter *adapter)
|
||||
{
|
||||
/*step1: open e220 uart port*/
|
||||
adapter->fd = PrivOpen(ADAPTER_E220_DRIVER, O_RDWR);
|
||||
if (adapter->fd < 0) {
|
||||
printf("E220Open get uart %s fd error\n", ADAPTER_E220_DRIVER);
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct SerialDataCfg cfg;
|
||||
memset(&cfg, 0 ,sizeof(struct SerialDataCfg));
|
||||
|
||||
cfg.serial_baud_rate = BAUD_RATE_9600;
|
||||
cfg.serial_data_bits = DATA_BITS_8;
|
||||
cfg.serial_stop_bits = STOP_BITS_1;
|
||||
cfg.serial_parity_mode = PARITY_NONE;
|
||||
cfg.serial_bit_order = BIT_ORDER_LSB;
|
||||
cfg.serial_invert_mode = NRZ_NORMAL;
|
||||
cfg.serial_buffer_size = SERIAL_RB_BUFSZ;
|
||||
|
||||
/*aiit board use ch438, so it needs more serial configuration*/
|
||||
#ifdef ADAPTER_E220_DRIVER_EXTUART
|
||||
cfg.ext_uart_no = ADAPTER_E220_DRIVER_EXT_PORT;
|
||||
cfg.port_configure = PORT_CFG_INIT;
|
||||
#endif
|
||||
|
||||
#ifdef AS_LORA_GATEWAY_ROLE
|
||||
//serial receive timeout 10s
|
||||
cfg.serial_timeout = 10000;
|
||||
#endif
|
||||
|
||||
#ifdef AS_LORA_CLIENT_ROLE
|
||||
//serial receive wait forever
|
||||
cfg.serial_timeout = -1;
|
||||
#endif
|
||||
|
||||
struct PrivIoctlCfg ioctl_cfg;
|
||||
ioctl_cfg.ioctl_driver_type = SERIAL_TYPE;
|
||||
ioctl_cfg.args = &cfg;
|
||||
|
||||
PrivIoctl(adapter->fd, OPE_INT, &ioctl_cfg);
|
||||
|
||||
E220SetRegisterParam(adapter, E220_ADDRESS, E220_CHANNEL, E220_UART_BAUD_RATE);
|
||||
|
||||
cfg.serial_baud_rate = E220_UART_BAUD_RATE;
|
||||
ioctl_cfg.args = &cfg;
|
||||
|
||||
PrivIoctl(adapter->fd, OPE_INT, &ioctl_cfg);
|
||||
|
||||
ADAPTER_DEBUG("E220Open done\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Close E220 uart function
|
||||
* @param adapter - Lora device pointer
|
||||
* @return success: 0, failure: -1
|
||||
*/
|
||||
static int E220Close(struct Adapter *adapter)
|
||||
{
|
||||
/*step1: close e220 uart port*/
|
||||
int ret;
|
||||
ret = PrivClose(adapter->fd);
|
||||
if(ret < 0) {
|
||||
printf("E220 close failed: %d!\n", ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ADAPTER_DEBUG("E220 Close done\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: E220 ioctl function
|
||||
* @param adapter - Lora device pointer
|
||||
* @param cmd - ioctl cmd
|
||||
* @param args - iotl params
|
||||
* @return success: 0, failure: -1
|
||||
*/
|
||||
static int E220Ioctl(struct Adapter *adapter, int cmd, void *args)
|
||||
{
|
||||
/*to do*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: E220 join lora net group function
|
||||
* @param adapter - Lora device pointer
|
||||
* @param priv_net_group - priv_net_group params
|
||||
* @return success: 0, failure: -1
|
||||
*/
|
||||
static int E220Join(struct Adapter *adapter, unsigned char *priv_net_group)
|
||||
{
|
||||
int ret;
|
||||
struct AdapterData *priv_net_group_data = (struct AdapterData *)priv_net_group;
|
||||
|
||||
ret = PrivWrite(adapter->fd, (void *)priv_net_group_data->buffer, priv_net_group_data->len);
|
||||
if(ret < 0) {
|
||||
printf("E220 Join net group failed: %d!\n", ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: E220 send data function
|
||||
* @param adapter - Lora device pointer
|
||||
* @param buf - data buffers
|
||||
* @param len - data len
|
||||
* @return success: 0, failure: -1
|
||||
*/
|
||||
static int E220Send(struct Adapter *adapter, const void *buf, size_t len)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = PrivWrite(adapter->fd, (void *)buf, len);
|
||||
if(ret < 0){
|
||||
printf("send failed %d!\n", ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: E220 receive data function
|
||||
* @param adapter - Lora device pointer
|
||||
* @param buf - data buffers
|
||||
* @param len - data len
|
||||
* @return success: 0, failure: -1
|
||||
*/
|
||||
static int E220Recv(struct Adapter *adapter, void *buf, size_t len)
|
||||
{
|
||||
int recv_len, recv_len_continue;
|
||||
|
||||
uint8 *recv_buf = PrivMalloc(len);
|
||||
|
||||
recv_len = PrivRead(adapter->fd, recv_buf, len);
|
||||
if (recv_len) {
|
||||
while (recv_len < len) {
|
||||
recv_len_continue = PrivRead(adapter->fd, recv_buf + recv_len, len - recv_len);
|
||||
if (recv_len_continue) {
|
||||
recv_len += recv_len_continue;
|
||||
} else {
|
||||
recv_len = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
memcpy(buf, recv_buf, len);
|
||||
}
|
||||
|
||||
PrivFree(recv_buf);
|
||||
|
||||
return recv_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: E220 quit lora net group function
|
||||
* @param adapter - Lora device pointer
|
||||
* @param priv_net_group - priv_net_group params
|
||||
* @return success: 0, failure: -1
|
||||
*/
|
||||
static int E220Quit(struct Adapter *adapter, unsigned char *priv_net_group)
|
||||
{
|
||||
int ret;
|
||||
|
||||
struct AdapterData *priv_net_group_data = (struct AdapterData *)priv_net_group;
|
||||
|
||||
ret = PrivWrite(adapter->fd, (void *)priv_net_group_data->buffer, priv_net_group_data->len);
|
||||
if(ret < 0){
|
||||
printf("E220 quit net group failed %d!\n", ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const struct PrivProtocolDone e220_done =
|
||||
{
|
||||
.open = E220Open,
|
||||
.close = E220Close,
|
||||
.ioctl = E220Ioctl,
|
||||
.setup = NULL,
|
||||
.setdown = NULL,
|
||||
.setaddr = NULL,
|
||||
.setdns = NULL,
|
||||
.setdhcp = NULL,
|
||||
.ping = NULL,
|
||||
.netstat = NULL,
|
||||
.join = E220Join,
|
||||
.send = E220Send,
|
||||
.recv = E220Recv,
|
||||
.quit = E220Quit,
|
||||
};
|
||||
|
||||
AdapterProductInfoType E220Attach(struct Adapter *adapter)
|
||||
{
|
||||
struct AdapterProductInfo *product_info = malloc(sizeof(struct AdapterProductInfo));
|
||||
if (!product_info) {
|
||||
printf("E220Attach malloc product_info error\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strncpy(product_info->model_name, ADAPTER_LORA_E220,sizeof(product_info->model_name));
|
||||
product_info->model_done = (void *)&e220_done;
|
||||
|
||||
return product_info;
|
||||
}
|
||||
|
||||
//###################TEST####################
|
||||
static void LoraOpen(void)
|
||||
{
|
||||
struct Adapter *adapter = AdapterDeviceFindByName(ADAPTER_LORA_NAME);
|
||||
if (NULL == adapter) {
|
||||
printf("LoraReceive find lora adapter error\n");
|
||||
return;
|
||||
}
|
||||
|
||||
E220Open(adapter);
|
||||
}
|
||||
|
||||
static void LoraRead(void *parameter)
|
||||
{
|
||||
int RevLen;
|
||||
int i, cnt = 0;
|
||||
|
||||
uint8 buffer[256];
|
||||
|
||||
memset(buffer, 0, 256);
|
||||
|
||||
struct Adapter *adapter = AdapterDeviceFindByName(ADAPTER_LORA_NAME);
|
||||
if (NULL == adapter) {
|
||||
printf("LoraRead find lora adapter error\n");
|
||||
return;
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
printf("ready to read lora data\n");
|
||||
|
||||
RevLen = E220Recv(adapter, buffer, 256);
|
||||
if (RevLen) {
|
||||
printf("lora get data %u\n", RevLen);
|
||||
for (i = 0; i < RevLen; i ++) {
|
||||
printf("i %u data 0x%x\n", i, buffer[i]);
|
||||
}
|
||||
|
||||
memset(buffer, 0, 256);
|
||||
|
||||
PrivTaskDelay(1000);
|
||||
|
||||
cnt ++;
|
||||
E220Send(adapter, &cnt, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void LoraTest(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
LoraOpen();
|
||||
|
||||
int task_lora_read = KTaskCreate("task_lora_read", LoraRead, NONE, 2048, 10);
|
||||
ret = StartupKTask(task_lora_read);
|
||||
if (ret != EOK) {
|
||||
KPrintf("StartupKTask task_lora_read failed .\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
||||
LoraTest, LoraTest, lora send and receive message);
|
||||
|
||||
static void LoraSend(int argc, char *argv[])
|
||||
{
|
||||
struct Adapter *adapter = AdapterDeviceFindByName(ADAPTER_LORA_NAME);
|
||||
if (NULL == adapter) {
|
||||
printf("LoraRead find lora adapter error\n");
|
||||
return;
|
||||
}
|
||||
|
||||
char Msg[256] = {0};
|
||||
|
||||
if (argc == 2) {
|
||||
strncpy(Msg, argv[1], 256);
|
||||
|
||||
E220Send(adapter, Msg, strlen(Msg));
|
||||
}
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
||||
LoraSend, LoraSend, lora send message);
|
||||
@@ -108,7 +108,9 @@ static int Sx1278Ioctl(struct Adapter *adapter, int cmd, void *args)
|
||||
static int Sx1278Join(struct Adapter *adapter, unsigned char *priv_net_group)
|
||||
{
|
||||
int ret;
|
||||
ret = Sx127x_Nuttx_Write(adapter->fd, (void *)priv_net_group, 144);
|
||||
struct AdapterData *priv_net_group_data = (struct AdapterData *)priv_net_group;
|
||||
|
||||
ret = Sx127x_Nuttx_Write(adapter->fd, (void *)priv_net_group_data->buffer, priv_net_group_data->len);
|
||||
if(ret < 0){
|
||||
printf("Sx1278 Join net group failed: %d!\n", ret);
|
||||
}
|
||||
@@ -119,7 +121,9 @@ static int Sx1278Join(struct Adapter *adapter, unsigned char *priv_net_group)
|
||||
static int Sx1278Join(struct Adapter *adapter, unsigned char *priv_net_group)
|
||||
{
|
||||
int ret;
|
||||
ret = PrivWrite(adapter->fd, (void *)priv_net_group, 144);
|
||||
struct AdapterData *priv_net_group_data = (struct AdapterData *)priv_net_group;
|
||||
|
||||
ret = PrivWrite(adapter->fd, (void *)priv_net_group_data->buffer, priv_net_group_data->len);
|
||||
if(ret < 0){
|
||||
printf("Sx1278 Join net group failed: %d!\n", ret);
|
||||
}
|
||||
@@ -196,7 +200,9 @@ static int Sx1278Recv(struct Adapter *adapter, void *buf, size_t len)
|
||||
static int Sx1278Quit(struct Adapter *adapter, unsigned char *priv_net_group)
|
||||
{
|
||||
int ret;
|
||||
ret = Sx127x_Nuttx_Write(adapter->fd, (void *)priv_net_group, 144);
|
||||
struct AdapterData *priv_net_group_data = (struct AdapterData *)priv_net_group;
|
||||
|
||||
ret = Sx127x_Nuttx_Write(adapter->fd, (void *)priv_net_group_data->buffer, priv_net_group_data->len);
|
||||
if(ret < 0){
|
||||
printf("Sx1278 quit net group failed %d!\n", ret);
|
||||
}
|
||||
@@ -207,7 +213,9 @@ static int Sx1278Quit(struct Adapter *adapter, unsigned char *priv_net_group)
|
||||
static int Sx1278Quit(struct Adapter *adapter, unsigned char *priv_net_group)
|
||||
{
|
||||
int ret;
|
||||
ret = PrivWrite(adapter->fd, (void *)priv_net_group, 144);
|
||||
struct AdapterData *priv_net_group_data = (struct AdapterData *)priv_net_group;
|
||||
|
||||
ret = PrivWrite(adapter->fd, (void *)priv_net_group_data->buffer, priv_net_group_data->len);
|
||||
if(ret < 0){
|
||||
printf("Sx1278 quit net group failed %d!\n", ret);
|
||||
}
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
extern AdapterProductInfoType BC28Attach(struct Adapter *adapter);
|
||||
#endif
|
||||
|
||||
#define ADAPTER_NBIOT_NAME "nbiot"
|
||||
|
||||
static int AdapterNbiotRegister(struct Adapter *adapter)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
18
APP_Framework/Framework/connection/wifi/SConscript
Normal file
18
APP_Framework/Framework/connection/wifi/SConscript
Normal file
@@ -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')
|
||||
@@ -20,7 +20,9 @@
|
||||
|
||||
#include <adapter.h>
|
||||
#include "adapter_wifi.h"
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
#include <bus_pin.h>
|
||||
#endif
|
||||
|
||||
#ifdef ADAPTER_HFA21_WIFI
|
||||
extern AdapterProductInfoType Hfa21WifiAttach(struct Adapter *adapter);
|
||||
@@ -29,8 +31,6 @@ extern AdapterProductInfoType Hfa21WifiAttach(struct Adapter *adapter);
|
||||
extern AdapterProductInfoType Esp07sWifiAttach(struct Adapter *adapter);
|
||||
#endif
|
||||
|
||||
#define ADAPTER_WIFI_NAME "wifi"
|
||||
|
||||
static int AdapterWifiRegister(struct Adapter *adapter)
|
||||
{
|
||||
int ret = 0;
|
||||
@@ -100,7 +100,7 @@ int AdapterWifiInit(void)
|
||||
}
|
||||
|
||||
/******************wifi TEST*********************/
|
||||
int AdapterwifiTest(void)
|
||||
int AdapterWifiTest(void)
|
||||
{
|
||||
char cmd[64];
|
||||
int baud_rate = BAUD_RATE_57600;
|
||||
@@ -109,30 +109,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);
|
||||
@@ -170,7 +170,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);
|
||||
@@ -178,12 +178,19 @@ 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);
|
||||
}
|
||||
|
||||
}
|
||||
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);
|
||||
|
||||
#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
|
||||
|
||||
int wifiopen(void)
|
||||
{
|
||||
@@ -191,15 +198,18 @@ int wifiopen(void)
|
||||
|
||||
AdapterDeviceOpen(adapter);
|
||||
}
|
||||
#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, wifiopen, wifiopen, open adapter wifi );
|
||||
#endif
|
||||
int wificlose(void)
|
||||
{
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||
|
||||
AdapterDeviceClose(adapter);
|
||||
}
|
||||
#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, wificlose, wificlose, close adapter wifi );
|
||||
|
||||
#endif
|
||||
int wifisetup(int argc, char *argv[])
|
||||
{
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||
@@ -212,7 +222,9 @@ int wifisetup(int argc, char *argv[])
|
||||
|
||||
AdapterDeviceSetUp(adapter);
|
||||
}
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(3)|SHELL_CMD_DISABLE_RETURN, wifisetup, wifisetup, setup adapter wifi );
|
||||
#endif
|
||||
int wifiaddrset(int argc, char *argv[])
|
||||
{
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||
@@ -224,16 +236,18 @@ int wifiaddrset(int argc, char *argv[])
|
||||
AdapterDevicePing(adapter, "36.152.44.95");///< ping www.baidu.com
|
||||
AdapterDeviceNetstat(adapter);
|
||||
}
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(4)|SHELL_CMD_DISABLE_RETURN, wifiaddrset, wifiaddrset, addrset adapter wifi);
|
||||
|
||||
#endif
|
||||
int wifiping(int argc, char *argv[])
|
||||
{
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||
printf("ping %s\n",argv[1]);
|
||||
AdapterDevicePing(adapter, argv[1]);
|
||||
}
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(3), wifiping, wifiping, wifiping adapter );
|
||||
|
||||
#endif
|
||||
int wificonnect(int argc, char *argv[])
|
||||
{
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||
@@ -252,7 +266,9 @@ int wificonnect(int argc, char *argv[])
|
||||
|
||||
AdapterDeviceConnect(adapter, net_role, ip, port, ip_type);
|
||||
}
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(4)|SHELL_CMD_DISABLE_RETURN, wificonnect, wificonnect, wificonnect adapter);
|
||||
#endif
|
||||
int wifisend(int argc, char *argv[])
|
||||
{
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||
@@ -264,7 +280,9 @@ int wifisend(int argc, char *argv[])
|
||||
PrivTaskDelay(1000);
|
||||
}
|
||||
}
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(3)|SHELL_CMD_DISABLE_RETURN, wifisend, wifisend, wifisend adapter wifi information);
|
||||
#endif
|
||||
int wifirecv(int argc, char *argv[])
|
||||
{
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_WIFI_NAME);
|
||||
@@ -276,4 +294,6 @@ int wifirecv(int argc, char *argv[])
|
||||
printf("wifi recv [%s]\n",wifi_recv_msg);
|
||||
}
|
||||
}
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(3)|SHELL_CMD_DISABLE_RETURN, wifirecv, wifirecv, wifirecv adapter wifi information);
|
||||
#endif
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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')
|
||||
@@ -20,7 +20,8 @@
|
||||
|
||||
#include <adapter.h>
|
||||
#include <at_agent.h>
|
||||
|
||||
#include <transform.h>
|
||||
#include <string.h>
|
||||
#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)
|
||||
{
|
||||
|
||||
@@ -26,8 +26,6 @@
|
||||
extern AdapterProductInfoType E18Attach(struct Adapter *adapter);
|
||||
#endif
|
||||
|
||||
#define ADAPTER_ZIGBEE_NAME "zigbee"
|
||||
|
||||
static int AdapterZigbeeRegister(struct Adapter *adapter)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@@ -55,7 +55,15 @@ int PrivSemaphoreDelete(sem_t *sem)
|
||||
|
||||
int PrivSemaphoreObtainWait(sem_t *sem, const struct timespec *abstime)
|
||||
{
|
||||
return sem_timedwait(sem, abstime);
|
||||
struct timespec timeout;
|
||||
clock_gettime(CLOCK_REALTIME, &timeout);
|
||||
timeout.tv_sec += abstime->tv_sec;
|
||||
return sem_timedwait(sem, &timeout);
|
||||
}
|
||||
|
||||
int PrivSemaphoreObtainWaitForever(sem_t *sem)
|
||||
{
|
||||
return sem_wait(sem);
|
||||
}
|
||||
|
||||
int PrivSemaphoreObtainNoWait(sem_t *sem)
|
||||
|
||||
@@ -180,6 +180,7 @@ int PrivMutexAbandon(pthread_mutex_t *p_mutex);
|
||||
int PrivSemaphoreCreate(sem_t *sem, int pshared, unsigned int value);
|
||||
int PrivSemaphoreDelete(sem_t *sem);
|
||||
int PrivSemaphoreObtainWait(sem_t *sem, const struct timespec *abstime);
|
||||
int PrivSemaphoreObtainWaitForever(sem_t *sem);
|
||||
int PrivSemaphoreObtainNoWait(sem_t *sem);
|
||||
int PrivSemaphoreAbandon(sem_t *sem);
|
||||
int32_t PrivSemaphoreSetValue(int32_t sem, uint16_t val);
|
||||
|
||||
@@ -171,6 +171,7 @@ int PrivIoctl(int fd, int cmd, void *args)
|
||||
break;
|
||||
case ADC_TYPE:
|
||||
case DAC_TYPE:
|
||||
case WDT_TYPE:
|
||||
ret = ioctl(fd, cmd, ioctl_cfg->args);
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -35,6 +35,9 @@ extern "C" {
|
||||
#define OPE_INT 0x0000
|
||||
#define OPE_CFG 0x0001
|
||||
|
||||
#define OPER_WDT_SET_TIMEOUT 0x0002
|
||||
#define OPER_WDT_KEEPALIVE 0x0003
|
||||
|
||||
#define NAME_NUM_MAX 32
|
||||
|
||||
/*********************GPIO define*********************/
|
||||
@@ -127,6 +130,7 @@ struct SerialDataCfg
|
||||
uint8_t serial_bit_order;
|
||||
uint8_t serial_invert_mode;
|
||||
uint16_t serial_buffer_size;
|
||||
int32 serial_timeout;
|
||||
|
||||
uint8_t ext_uart_no;
|
||||
enum ExtSerialPortConfigure port_configure;
|
||||
@@ -141,6 +145,7 @@ enum IoctlDriverType
|
||||
LCD_TYPE,
|
||||
ADC_TYPE,
|
||||
DAC_TYPE,
|
||||
WDT_TYPE,
|
||||
DEFAULT_TYPE,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user