transform connection framework api from user-api to priv-api

This commit is contained in:
Liu_Weichao 2021-09-24 16:07:22 +08:00
parent 4a07f534d8
commit dd5a68916e
11 changed files with 123 additions and 146 deletions

View File

@ -17,6 +17,7 @@ extern int SensorFrameworkInit(void);
extern int AdapterFrameworkInit(void);
extern int Adapter4GInit(void);
extern int AdapterBlueToothInit(void);
extern int AdapterWifiInit(void);
extern int D124VoiceInit(void);
@ -89,10 +90,13 @@ static struct InitDesc sensor_desc[] =
static struct InitDesc connection_desc[] =
{
#ifdef ADAPTER_4G
#ifdef CONNECTION_ADAPTER_4G
{ "4G adpter", Adapter4GInit},
#endif
#ifdef ADAPTER_WIFI
#ifdef CONNECTION_ADAPTER_BLUETOOTH
{ "BlueTooth adpter", AdapterBlueToothInit},
#endif
#ifdef CONNECTION_ADAPTER_WIFI
{ "Wifi adpter", AdapterWifiInit},
#endif
{ "NULL", NULL },

View File

@ -253,11 +253,11 @@ AdapterProductInfoType Ec200tAttach(struct Adapter *adapter)
struct AdapterProductInfo *product_info = malloc(sizeof(struct AdapterProductInfo));
if (!product_info) {
printf("Ec200tAttach malloc product_info error\n");
free(product_info);
PrivFree(product_info);
return NULL;
}
product_info->model_name = ADAPTER_4G_EC200T;
strcpy(product_info->model_name, ADAPTER_4G_EC200T);
product_info->model_done = (void *)&ec200t_done;

View File

@ -1,14 +1,8 @@
config ADAPTER_4G
bool "Using 4G adapter function"
config ADAPTER_EC200T
bool "Using 4G adapter device EC200T"
default y
if ADAPTER_4G
config ADAPTER_EC200T
bool "Using 4G adapter device EC200T"
default y
if ADAPTER_EC200T
source "$APP_DIR/Framework/connection/4G/EC200T/Kconfig"
endif
if ADAPTER_EC200T
source "$APP_DIR/Framework/connection/4G/EC200T/Kconfig"
endif
endif

View File

@ -1,34 +1,34 @@
SRC_FILES := adapter.c adapter_agent.c
ifeq ($(CONFIG_ADAPTER_LORA),y)
ifeq ($(CONFIG_CONNECTION_ADAPTER_LORA),y)
SRC_DIR += lora
endif
ifeq ($(CONFIG_ADAPTER_4G),y)
ifeq ($(CONFIG_CONNECTION_ADAPTER_4G),y)
SRC_DIR += 4G
endif
ifeq ($(CONFIG_ADAPTER_NB),y)
ifeq ($(CONFIG_CONNECTION_ADAPTER_NB),y)
SRC_DIR += nbiot
endif
ifeq ($(CONFIG_ADAPTER_WIFI),y)
ifeq ($(CONFIG_CONNECTION_ADAPTER_WIFI),y)
SRC_DIR += wifi
endif
ifeq ($(CONFIG_ADAPTER_ETHERNET),y)
ifeq ($(CONFIG_CONNECTION_ADAPTER_ETHERNET),y)
SRC_DIR += ethernet
endif
ifeq ($(CONFIG_ADAPTER_BLUETOOTH),y)
ifeq ($(CONFIG_CONNECTION_ADAPTER_BLUETOOTH),y)
SRC_DIR += bluetooth
endif
ifeq ($(CONFIG_ADAPTER_ZIGBEE),y)
ifeq ($(CONFIG_CONNECTION_ADAPTER_ZIGBEE),y)
SRC_DIR += zigbee
endif
ifeq ($(CONFIG_ADAPTER_5G),y)
ifeq ($(CONFIG_CONNECTION_ADAPTER_5G),y)
SRC_DIR += 5G
endif

View File

@ -39,15 +39,6 @@ extern "C" {
#define ADAPTER_LWIP_OPERATION 2
#define ADAPTER_RAWIP_OPERATION 3
#define ADAPTER_LORA_FUNC ((uint32_t)(1 << ATAPTER_LORA))
#define ADAPTER_4G_FUNC ((uint32_t)(1 << ADAPTER_4G))
#define ADAPTER_NBIOT_FUNC ((uint32_t)(1 << ADAPTER_NBIOT))
#define ADAPTER_WIFI_FUNC ((uint32_t)(1 << ADAPTER_WIFI))
#define ADAPTER_ETHERNET_FUNC ((uint32_t)(1 << ADAPTER_ETHERNET))
#define ADAPTER_BLUETOOTH_FUNC ((uint32_t)(1 << ADAPTER_BLUETOOTH))
#define ADAPTER_ZIGBEE_FUNC ((uint32_t)(1 << ADAPTER_ZIGBEE))
#define ADAPTER_5G_FUNC ((uint32_t)(1 << ADAPTER_5G))
#ifdef CONNECTION_FRAMEWORK_DEBUG
#define ADAPTER_DEBUG printf
#else
@ -110,8 +101,8 @@ enum IpType
struct AdapterProductInfo
{
uint32_t functions;
const char *vendor_name;
const char *model_name;
char vendor_name[NAME_NUM_MAX];
char model_name[NAME_NUM_MAX];
void *model_done;
};
@ -154,7 +145,7 @@ struct PrivProtocolDone
struct Adapter
{
char *name;
char name[NAME_NUM_MAX];
int fd;
int product_info_flag;

View File

@ -27,7 +27,6 @@
#include <stdlib.h>
#include <string.h>
#include <user_api.h>
#include <bus.h>
#define AT_CMD_MAX_LEN 128
#define AT_AGENT_MAX 2
@ -36,12 +35,13 @@ static uint32 last_cmd_len = 0;
static struct ATAgent at_agent_table[AT_AGENT_MAX] = {0};
uint IpTint(char *ipstr){
unsigned int IpTint(char *ipstr)
{
if (ipstr == NULL)
return 0;
char *token;
uint i = 3, total = 0, cur;
unsigned int i = 3, total = 0, cur;
token = strtok(ipstr, ".");
@ -70,7 +70,7 @@ void SwapStr(char *str, int begin, int end)
}
}
char *IpTstr(uint ipint)
char *IpTstr(unsigned int ipint)
{
int LEN = 16;
char *new = (char *)malloc(LEN);
@ -124,13 +124,17 @@ uint32 ATSprintf(int fd, const char *format, va_list params)
PrivWrite(fd, send_buf, last_cmd_len);
}
int ATOrderSend(ATAgentType agent, uint32 timeout, ATReplyType reply, const char *cmd_expr, ...)
int ATOrderSend(ATAgentType agent, uint32 timeout_s, ATReplyType reply, const char *cmd_expr, ...)
{
if (agent == NULL){
printf("ATAgent is null");
return -ERROR;
}
struct timespec abstime;
abstime.tv_sec = timeout_s;
agent->receive_mode = AT_MODE;
memset(agent->maintain_buffer, 0x00, agent->maintain_max);
@ -152,7 +156,7 @@ int ATOrderSend(ATAgentType agent, uint32 timeout, ATReplyType reply, const char
va_start(params, cmd_expr);
ATSprintf(agent->fd, cmd_expr, params);
va_end(params);
if (UserSemaphoreObtain(agent->rsp_sem, timeout) != EOK){
if (PrivSemaphoreObtainWait(&agent->rsp_sem, &abstime) != EOK){
result = -ETIMEOUT;
goto __out;
}
@ -185,21 +189,23 @@ int EntmSend(ATAgentType agent, const char *data, int len)
memcpy(send_buf, data, len);
memcpy(send_buf + len, "!@", 2);
write(agent->fd, send_buf, len + 2);
PrivWrite(agent->fd, send_buf, len + 2);
return EOK;
}
int EntmRecv(ATAgentType agent, char *rev_buffer, int buffer_len, int time_out)
int EntmRecv(ATAgentType agent, char *rev_buffer, int buffer_len, int timeout_s)
{
UserTaskDelay(1000);
struct timespec abstime;
abstime.tv_sec = timeout_s;
PrivTaskDelay(1000);
memset(agent->entm_recv_buf, 0, ENTM_RECV_MAX);
agent->entm_recv_len = 0;
UserSemaphoreSetValue(agent->entm_rx_notice, 0);
if (UserSemaphoreObtain(agent->entm_rx_notice, time_out)){
if (PrivSemaphoreObtainWait(&agent->entm_rx_notice, &abstime)){
return ERROR;
}
@ -225,16 +231,17 @@ static int GetCompleteATReply(ATAgentType agent)
agent->maintain_len = 0;
while (1){
read(agent->fd, &ch, 1);
PrivRead(agent->fd, &ch, 1);
printf(" %c(0x%x)\n", ch, ch);
if (agent->receive_mode == ENTM_MODE){
if (agent->entm_recv_len < ENTM_RECV_MAX){
agent->entm_recv_buf[agent->entm_recv_len++] = ch;
agent->entm_recv_buf[agent->entm_recv_len] = ch;
agent->entm_recv_len++;
if (last_ch == '!' && ch == '@'){
UserSemaphoreAbandon(agent->entm_rx_notice);
PrivSemaphoreAbandon(&agent->entm_rx_notice);
}
last_ch = ch;
@ -245,7 +252,8 @@ static int GetCompleteATReply(ATAgentType agent)
}
else if (agent->receive_mode == AT_MODE){
if (read_len < agent->maintain_max){
agent->maintain_buffer[read_len++] = ch;
agent->maintain_buffer[read_len] = ch;
read_len++;
agent->maintain_len = read_len;
}else{
printf("maintain_len is_full ...\n");
@ -289,25 +297,25 @@ static int DeleteATAgent(ATAgentType agent)
}
if (agent->entm_rx_notice){
UserSemaphoreDelete(agent->entm_rx_notice);
PrivSemaphoreDelete(&agent->entm_rx_notice);
}
if (agent->fd > 0){
close(agent->fd);
PrivClose(agent->fd);
}
if (agent->rsp_sem){
UserSemaphoreDelete(agent->rsp_sem);
PrivSemaphoreDelete(&agent->rsp_sem);
}
if (agent->maintain_buffer){
free(agent->maintain_buffer);
PrivFree(agent->maintain_buffer);
}
memset(agent, 0x00, sizeof(struct ATAgent));
}
static void ATAgentReceiveProcess(void *param)
static void *ATAgentReceiveProcess(void *param)
{
ATAgentType agent = (ATAgentType)param;
const struct at_urc *urc;
@ -329,7 +337,7 @@ static void ATAgentReceiveProcess(void *param)
}
agent->reply = NULL;
UserSemaphoreAbandon(agent->rsp_sem);
PrivSemaphoreAbandon(&agent->rsp_sem);
}
}
}
@ -339,56 +347,51 @@ static int ATAgentInit(ATAgentType agent)
{
int result = EOK;
UtaskType at_utask;
do
{
agent->maintain_len = 0;
agent->maintain_buffer = (char *)malloc(agent->maintain_max);
if (agent->maintain_buffer == NONE){
break;
}
agent->maintain_len = 0;
agent->maintain_buffer = (char *)malloc(agent->maintain_max);
agent->entm_rx_notice = UserSemaphoreCreate(0);
if (agent->entm_rx_notice == 0){
break;
}
if (agent->maintain_buffer == NONE){
printf("ATAgentInit malloc maintain_buffer error\n");
goto __out;
}
agent->rsp_sem = UserSemaphoreCreate(0);
if (agent->rsp_sem == 0){
break;
}
if(PrivMutexCreate(&agent->lock, 0) < 0) {
printf("AdapterFrameworkInit mutex create failed.\n");
}
if (agent->lock == 0){
break;
}
result = PrivSemaphoreCreate(&agent->entm_rx_notice, 0, 0);
if (result < 0){
printf("ATAgentInit create entm sem error\n");
goto __out;
}
agent->receive_mode = ENTM_MODE;
result = PrivSemaphoreCreate(&agent->rsp_sem, 0, 0);
if (result < 0){
printf("ATAgentInit create rsp sem error\n");
goto __out;
}
strncpy(at_utask.name, "recv_task", strlen("recv_task"));
at_utask.func_entry = ATAgentReceiveProcess;
at_utask.func_param = agent;
at_utask.stack_size = 1024;
at_utask.prio = 18;
if(PrivMutexCreate(&agent->lock, 0) < 0) {
printf("AdapterFrameworkInit mutex create failed.\n");
goto __out;
}
agent->at_handler = UserTaskCreate(at_utask);
agent->receive_mode = ENTM_MODE;
// struct SerialDataCfg data_cfg;
// memset(&data_cfg, 0, sizeof(struct SerialDataCfg));
// data_cfg.serial_baud_rate = 57600;
// ioctl(agent->fd, OPE_INT, &data_cfg);
pthread_attr_t attr;
attr.schedparam.sched_priority = 18;
attr.stacksize = 1024;
if (agent->at_handler == 0) {
break;
}
PrivTaskCreate(&agent->at_handler, &attr, ATAgentReceiveProcess, agent);
result = EOK;
return result;
} while (1);
// struct SerialDataCfg data_cfg;
// memset(&data_cfg, 0, sizeof(struct SerialDataCfg));
// data_cfg.serial_baud_rate = 57600;
// ioctl(agent->fd, OPE_INT, &data_cfg);
return result;
__out:
DeleteATAgent(agent);
result = -ERROR;
return result;
}
@ -424,7 +427,7 @@ int InitATAgent(const char *agent_name, int agent_fd, uint32 maintain_max)
result = ATAgentInit(agent);
if (result == EOK)
{
UserTaskStartup(agent->at_handler);
PrivTaskStartup(&agent->at_handler);
}
return result;
@ -445,7 +448,7 @@ ATReplyType CreateATReply(uint32 reply_max_len)
reply->reply_buffer = (char *)malloc(reply_max_len);
if (reply->reply_buffer == NULL){
printf("no more memory\n");
free(reply);
PrivFree(reply);
return NULL;
}
@ -456,13 +459,13 @@ void DeleteATReply(ATReplyType reply)
{
if (reply){
if (reply->reply_buffer){
free(reply->reply_buffer);
PrivFree(reply->reply_buffer);
reply->reply_buffer = NULL;
}
}
if (reply){
free(reply);
PrivFree(reply);
reply = NULL;
}
}

View File

@ -54,7 +54,7 @@ struct ATAgent
ATReplyType reply;
int rsp_sem;
int32 at_handler;
pthread_t at_handler;
#define ENTM_RECV_MAX 256
char entm_recv_buf[ENTM_RECV_MAX];
@ -65,7 +65,7 @@ struct ATAgent
typedef struct ATAgent *ATAgentType;
int EntmSend(ATAgentType agent, const char *data, int len);
int EntmRecv(ATAgentType agent, char *rev_buffer, int buffer_len, int time_out);
int EntmRecv(ATAgentType agent, char *rev_buffer, int buffer_len, int timeout_s);
char *GetReplyText(ATReplyType reply);
ATReplyType CreateATReply(uint32 reply_max_len);
uint IpTint(char *ipstr);
@ -75,7 +75,7 @@ ATAgentType GetATAgent(const char *agent_name);
int InitATAgent(const char *agent_name, int fd, uint32 maintain_max);
int ParseATReply(char* str, const char *format, ...);
void DeleteATReply(ATReplyType reply);
int ATOrderSend(ATAgentType agent, uint32 timeout, ATReplyType reply, const char *cmd_expr, ...);
int ATOrderSend(ATAgentType agent, uint32 timeout_s, ATReplyType reply, const char *cmd_expr, ...);
#define REPLY_TIME_OUT 3000

View File

@ -1,14 +1,7 @@
config ADAPTER_BLUETOOTH
bool "Using bluetooth adapter function"
config ADAPTER_HC08
bool "Using bluetooth adapter device HC08"
default y
if ADAPTER_BLUETOOTH
config ADAPTER_HC08
bool "Using bluetooth adapter device HC08"
default y
if ADAPTER_HC08
source "$APP_DIR/Framework/connection/bluetooth/HC08/Kconfig"
endif
endif
if ADAPTER_HC08
source "$APP_DIR/Framework/connection/bluetooth/HC08/Kconfig"
endif

View File

@ -210,10 +210,10 @@ static int Hfa21SetAddr(struct Adapter *adapter, const char *ip, const char *gat
char *gw_str = NULL;
char *mask_str = NULL;
dhcp_mode = (char *) UserCalloc(1, 8);
ip_str = (char *) UserCalloc(1, 17);
gw_str = (char *) UserCalloc(1, 17);
mask_str = (char *) UserCalloc(1, 17);
dhcp_mode = (char *) PrivCalloc(1, 8);
ip_str = (char *) PrivCalloc(1, 17);
gw_str = (char *) PrivCalloc(1, 17);
mask_str = (char *) PrivCalloc(1, 17);
Hfa21InitAtCmd(adapter->agent);
@ -260,8 +260,8 @@ static int Hfa21Ping(struct Adapter *adapter, const char *destination)
{
char *ping_result = NONE;
char *dst = NONE;
ping_result = (char *) UserCalloc(1, 17);
dst = (char *) UserCalloc(1, 17);
ping_result = (char *) PrivCalloc(1, 17);
dst = (char *) PrivCalloc(1, 17);
strcpy(dst, destination);
strcat(dst, "\r");
@ -327,11 +327,11 @@ static int Hfa21Netstat(struct Adapter *adapter)
char *local_ipaddr = NULL;
char *gateway = NULL;
char *netmask = NULL;
local_ipaddr = (char *) UserCalloc(1, HFA21_NETSTAT_IPADDR_SIZE);
gateway = (char *) UserCalloc(1, HFA21_NETSTAT_IPADDR_SIZE);
netmask = (char *) UserCalloc(1, HFA21_NETSTAT_IPADDR_SIZE);
work_mode = (char *) UserCalloc(1, HFA21_NETSTAT_IPADDR_SIZE);
ip_mode = (char *) UserCalloc(1, HFA21_NETSTAT_IPADDR_SIZE);
local_ipaddr = (char *) PrivCalloc(1, HFA21_NETSTAT_IPADDR_SIZE);
gateway = (char *) PrivCalloc(1, HFA21_NETSTAT_IPADDR_SIZE);
netmask = (char *) PrivCalloc(1, HFA21_NETSTAT_IPADDR_SIZE);
work_mode = (char *) PrivCalloc(1, HFA21_NETSTAT_IPADDR_SIZE);
ip_mode = (char *) PrivCalloc(1, HFA21_NETSTAT_IPADDR_SIZE);
reply = CreateATReply(HFA21_NETSTAT_RESP_SIZE);
if (reply == NULL) {
@ -391,13 +391,13 @@ __exit:
if (reply)
DeleteATReply(reply);
if (local_ipaddr)
UserFree(local_ipaddr);
PrivFree(local_ipaddr);
if (netmask)
UserFree(netmask);
PrivFree(netmask);
if (gateway)
UserFree(gateway);
PrivFree(gateway);
if (work_mode)
UserFree(work_mode);
PrivFree(work_mode);
}
static int Hfa21Connect(struct Adapter *adapter, enum NetRoleType net_role, const char *ip, const char *port, enum IpType ip_type)
@ -504,11 +504,11 @@ AdapterProductInfoType Hfa21Attach(struct Adapter *adapter)
struct AdapterProductInfo *product_info = malloc(sizeof(struct AdapterProductInfo));
if (!product_info) {
printf("Hfa21Attach Attach malloc product_info error\n");
free(product_info);
PrivFree(product_info);
return NULL;
}
product_info->model_name = ADAPTER_WIFI_HFA21;
strcpy(product_info->model_name, ADAPTER_WIFI_HFA21);
product_info->model_done = (void *)&hfa21_done;

View File

@ -1,14 +1,7 @@
config ADAPTER_WIFI
bool "Using WIFI adapter function"
config ADAPTER_HFA21
bool "Using wifi adapter device HFA21"
default y
if ADAPTER_WIFI
config ADAPTER_HFA21
bool "Using wifi adapter device HFA21"
default y
if ADAPTER_HFA21
source "$APP_DIR/Framework/connection/wifi/HFA21/Kconfig"
endif
endif
if ADAPTER_HFA21
source "$APP_DIR/Framework/connection/wifi/HFA21/Kconfig"
endif

View File

@ -24,9 +24,8 @@
int sem_init(sem_t *sem, int pshared, unsigned int value)
{
int32 ret = 0;
ret = UserSemaphoreCreate(value);
if (ret < 0) {
*sem = UserSemaphoreCreate(value);
if (*sem < 0) {
return -1;
}