forked from xuos/xiuos
Merge branch 'wang_weigen_master' of https://git.trustie.net/xuos/xiuos into xiuos_connection
This commit is contained in:
@@ -17,6 +17,7 @@ extern int SensorFrameworkInit(void);
|
||||
extern int AdapterFrameworkInit(void);
|
||||
|
||||
extern int Adapter4GInit(void);
|
||||
extern int AdapterNbiotInit(void);
|
||||
extern int AdapterBlueToothInit(void);
|
||||
extern int AdapterWifiInit(void);
|
||||
extern int AdapterEthernetInit(void);
|
||||
@@ -96,6 +97,9 @@ static struct InitDesc connection_desc[] =
|
||||
#ifdef CONNECTION_ADAPTER_4G
|
||||
{ "4G adapter", Adapter4GInit},
|
||||
#endif
|
||||
#ifdef CONNECTION_ADAPTER_NB
|
||||
{ "NB adpter", AdapterNbiotInit},
|
||||
#endif
|
||||
#ifdef CONNECTION_ADAPTER_ZIGBEE
|
||||
{ "zigbee adapter", AdapterZigbeeInit},
|
||||
#endif
|
||||
|
||||
@@ -9,5 +9,6 @@ menu "knowing app"
|
||||
source "$APP_DIR/Applications/knowing_app/instrusion_detect/Kconfig"
|
||||
source "$APP_DIR/Applications/knowing_app/helmet_detect/Kconfig"
|
||||
source "$APP_DIR/Applications/knowing_app/iris_ml_demo/Kconfig"
|
||||
source "$APP_DIR/Applications/knowing_app/k210_fft_test/Kconfig"
|
||||
endif
|
||||
endmenu
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
config K210_FFT_TEST
|
||||
bool "enable apps/k210 fft test"
|
||||
default n
|
||||
@@ -0,0 +1,9 @@
|
||||
from building import *
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
src = Glob('*.c') + Glob('*.cpp')
|
||||
CPPPATH = [cwd]
|
||||
|
||||
group = DefineGroup('Applications', src, depend = ['K210_FFT_TEST'], LOCAL_CPPPATH = CPPPATH)
|
||||
|
||||
Return('group')
|
||||
@@ -0,0 +1,101 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include "fft_soft.h"
|
||||
|
||||
#define PI 3.14159265358979323846
|
||||
complex add(complex a, complex b)
|
||||
{
|
||||
complex ret = {a.real + b.real, a.imag + b.imag};
|
||||
return ret;
|
||||
}
|
||||
|
||||
complex sub(complex a, complex b)
|
||||
{
|
||||
complex ret = {a.real - b.real, a.imag - b.imag};
|
||||
return ret;
|
||||
}
|
||||
|
||||
complex mul(complex a, complex b)
|
||||
{
|
||||
complex ret = {a.real * b.real - a.imag * b.imag, a.real * b.imag + a.imag * b.real};
|
||||
return ret;
|
||||
}
|
||||
|
||||
void bitrev(complex *data, int n)
|
||||
{
|
||||
int j = 0;
|
||||
int m = 0;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
if (j > i)
|
||||
SWAP(data[i], data[j]);
|
||||
m = n / 2;
|
||||
while (j >= m && m != 0)
|
||||
{
|
||||
j -= m;
|
||||
m >>= 1;
|
||||
}
|
||||
j += m;
|
||||
}
|
||||
}
|
||||
|
||||
void fft_soft(complex *data, int n)
|
||||
{
|
||||
int M = 0;
|
||||
for (int i = n; i > 1; i = i >> 1, M++);
|
||||
|
||||
bitrev(data, n);
|
||||
|
||||
for (int m = 0; m < M; m++)
|
||||
{
|
||||
int K = n >> (m + 1);
|
||||
for (int k = 0; k < K; k++)
|
||||
{
|
||||
int J = 2 << m;
|
||||
int base = k * J;
|
||||
for (int j = 0; j < J / 2; j++)
|
||||
{
|
||||
int t = base + j;
|
||||
complex w = {cos(-2 * PI * j * K / n), sin(-2 * PI * j * K / n)};
|
||||
complex wn = mul(data[t + J / 2], w);
|
||||
complex temp = data[t];
|
||||
data[t] = add(data[t], wn);
|
||||
data[t + J / 2] = sub(temp, wn);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ifft_soft(complex *data, int n)
|
||||
{
|
||||
int M = 0;
|
||||
for (int i = n; i > 1; i = i >> 1, M++);
|
||||
|
||||
bitrev(data, n);
|
||||
|
||||
for (int m = 0; m < M; m++)
|
||||
{
|
||||
int K = n >> (m + 1);
|
||||
for (int k = 0; k < K; k++)
|
||||
{
|
||||
int J = 2 << m;
|
||||
int base = k * J;
|
||||
for (int j = 0; j < J / 2; j++)
|
||||
{
|
||||
int t = base + j;
|
||||
complex w = {cos(2 * PI * j * K / n), sin(2 * PI * j * K / n)};
|
||||
complex wn = mul(data[t + J / 2], w);
|
||||
complex temp = data[t];
|
||||
data[t] = add(data[t], wn);
|
||||
data[t + J / 2] = sub(temp, wn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
data[i].real /= n;
|
||||
data[i].imag /= n;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef _FFT_SOFT_H
|
||||
#define _FFT_SOFT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define SWAP(a, b) do {complex t = (a); (a) = (b); (b) = t;} while(0)
|
||||
|
||||
typedef struct{double real, imag;} complex;
|
||||
|
||||
void fft_soft(complex *data, int n);
|
||||
void ifft_soft(complex *data, int n);
|
||||
void show(complex *data, int n);
|
||||
|
||||
#endif /* _FFT_SOFT_H */
|
||||
@@ -0,0 +1,159 @@
|
||||
/* Copyright 2018 Canaan Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <transform.h>
|
||||
#include <math.h>
|
||||
#include "encoding.h"
|
||||
#include "dmac.h"
|
||||
#include "fft.h"
|
||||
#include "encoding.h"
|
||||
#include "sysctl.h"
|
||||
#include "fft_soft.h"
|
||||
|
||||
#define FFT_N 512U
|
||||
#define FFT_FORWARD_SHIFT 0x0U
|
||||
#define FFT_BACKWARD_SHIFT 0x1ffU
|
||||
#define PI 3.14159265358979323846
|
||||
|
||||
typedef enum _complex_mode
|
||||
{
|
||||
FFT_HARD = 0,
|
||||
FFT_SOFT = 1,
|
||||
FFT_COMPLEX_MAX,
|
||||
} complex_mode_t;
|
||||
|
||||
int16_t real[FFT_N];
|
||||
int16_t imag[FFT_N];
|
||||
float hard_power[FFT_N];
|
||||
float soft_power[FFT_N];
|
||||
float hard_angel[FFT_N];
|
||||
float soft_angel[FFT_N];
|
||||
uint64_t fft_out_data[FFT_N / 2];
|
||||
uint64_t buffer_input[FFT_N];
|
||||
uint64_t buffer_output[FFT_N];
|
||||
uint64_t cycle[FFT_COMPLEX_MAX][FFT_DIR_MAX];
|
||||
|
||||
uint16_t get_bit1_num(uint32_t data)
|
||||
{
|
||||
uint16_t num;
|
||||
for (num = 0; data; num++)
|
||||
data &= data - 1;
|
||||
return num;
|
||||
}
|
||||
|
||||
void k210_fft_test(void)
|
||||
{
|
||||
int32_t i;
|
||||
float tempf1[3];
|
||||
fft_data_t *output_data;
|
||||
fft_data_t *input_data;
|
||||
uint16_t bit1_num = get_bit1_num(FFT_FORWARD_SHIFT);
|
||||
complex_hard_t data_hard[FFT_N] = {0};
|
||||
complex data_soft[FFT_N] = {0};
|
||||
for (i = 0; i < FFT_N; i++)
|
||||
{
|
||||
tempf1[0] = 0.3 * cosf(2 * PI * i / FFT_N + PI / 3) * 256;
|
||||
tempf1[1] = 0.1 * cosf(16 * 2 * PI * i / FFT_N - PI / 9) * 256;
|
||||
tempf1[2] = 0.5 * cosf((19 * 2 * PI * i / FFT_N) + PI / 6) * 256;
|
||||
data_hard[i].real = (int16_t)(tempf1[0] + tempf1[1] + tempf1[2] + 10);
|
||||
data_hard[i].imag = (int16_t)0;
|
||||
data_soft[i].real = data_hard[i].real;
|
||||
data_soft[i].imag = data_hard[i].imag;
|
||||
}
|
||||
for (int i = 0; i < FFT_N / 2; ++i)
|
||||
{
|
||||
input_data = (fft_data_t *)&buffer_input[i];
|
||||
input_data->R1 = data_hard[2 * i].real;
|
||||
input_data->I1 = data_hard[2 * i].imag;
|
||||
input_data->R2 = data_hard[2 * i + 1].real;
|
||||
input_data->I2 = data_hard[2 * i + 1].imag;
|
||||
}
|
||||
cycle[FFT_HARD][FFT_DIR_FORWARD] = read_cycle();
|
||||
fft_complex_uint16_dma(DMAC_CHANNEL0, DMAC_CHANNEL1, FFT_FORWARD_SHIFT, FFT_DIR_FORWARD, buffer_input, FFT_N, buffer_output);
|
||||
cycle[FFT_HARD][FFT_DIR_FORWARD] = read_cycle() - cycle[FFT_HARD][FFT_DIR_FORWARD];
|
||||
cycle[FFT_SOFT][FFT_DIR_FORWARD] = read_cycle();
|
||||
fft_soft(data_soft, FFT_N);
|
||||
cycle[FFT_SOFT][FFT_DIR_FORWARD] = read_cycle() - cycle[FFT_SOFT][FFT_DIR_FORWARD];
|
||||
for (i = 0; i < FFT_N / 2; i++)
|
||||
{
|
||||
output_data = (fft_data_t*)&buffer_output[i];
|
||||
data_hard[2 * i].imag = output_data->I1 ;
|
||||
data_hard[2 * i].real = output_data->R1 ;
|
||||
data_hard[2 * i + 1].imag = output_data->I2 ;
|
||||
data_hard[2 * i + 1].real = output_data->R2 ;
|
||||
}
|
||||
|
||||
for (i = 0; i < FFT_N; i++)
|
||||
{
|
||||
hard_power[i] = sqrt(data_hard[i].real * data_hard[i].real + data_hard[i].imag * data_hard[i].imag) * 2;
|
||||
soft_power[i] = sqrt(data_soft[i].real * data_soft[i].real + data_soft[i].imag * data_soft[i].imag) * 2;
|
||||
}
|
||||
|
||||
printf("\n[hard fft real][soft fft real][hard fft imag][soft fft imag]\n");
|
||||
for (i = 0; i < FFT_N / 2; i++)
|
||||
printf("%3d:%7d %7d %7d %7d\n",
|
||||
i, data_hard[i].real, (int32_t)data_soft[i].real, data_hard[i].imag, (int32_t)data_soft[i].imag);
|
||||
|
||||
printf("\nhard power soft power:\n");
|
||||
printf("%3d : %f %f\n", 0, hard_power[0] / 2 / FFT_N * (1 << bit1_num), soft_power[0] / 2 / FFT_N);
|
||||
for (i = 1; i < FFT_N / 2; i++)
|
||||
printf("%3d : %f %f\n", i, hard_power[i] / FFT_N * (1 << bit1_num), soft_power[i] / FFT_N);
|
||||
|
||||
printf("\nhard phase soft phase:\n");
|
||||
for (i = 0; i < FFT_N / 2; i++)
|
||||
{
|
||||
hard_angel[i] = atan2(data_hard[i].imag, data_hard[i].real);
|
||||
soft_angel[i] = atan2(data_soft[i].imag, data_soft[i].real);
|
||||
printf("%3d : %f %f\n", i, hard_angel[i] * 180 / PI, soft_angel[i] * 180 / PI);
|
||||
}
|
||||
|
||||
for (int i = 0; i < FFT_N / 2; ++i)
|
||||
{
|
||||
input_data = (fft_data_t *)&buffer_input[i];
|
||||
input_data->R1 = data_hard[2 * i].real;
|
||||
input_data->I1 = data_hard[2 * i].imag;
|
||||
input_data->R2 = data_hard[2 * i + 1].real;
|
||||
input_data->I2 = data_hard[2 * i + 1].imag;
|
||||
}
|
||||
cycle[FFT_HARD][FFT_DIR_BACKWARD] = read_cycle();
|
||||
fft_complex_uint16_dma(DMAC_CHANNEL0, DMAC_CHANNEL1, FFT_BACKWARD_SHIFT, FFT_DIR_BACKWARD, buffer_input, FFT_N, buffer_output);
|
||||
cycle[FFT_HARD][FFT_DIR_BACKWARD] = read_cycle() - cycle[FFT_HARD][FFT_DIR_BACKWARD];
|
||||
cycle[FFT_SOFT][FFT_DIR_BACKWARD] = read_cycle();
|
||||
ifft_soft(data_soft, FFT_N);
|
||||
cycle[FFT_SOFT][FFT_DIR_BACKWARD] = read_cycle() - cycle[FFT_SOFT][FFT_DIR_BACKWARD];
|
||||
for (i = 0; i < FFT_N / 2; i++)
|
||||
{
|
||||
output_data = (fft_data_t*)&buffer_output[i];
|
||||
data_hard[2 * i].imag = output_data->I1 ;
|
||||
data_hard[2 * i].real = output_data->R1 ;
|
||||
data_hard[2 * i + 1].imag = output_data->I2 ;
|
||||
data_hard[2 * i + 1].real = output_data->R2 ;
|
||||
}
|
||||
printf("\n[hard ifft real][soft ifft real][hard ifft imag][soft ifft imag]\n");
|
||||
for (i = 0; i < FFT_N / 2; i++)
|
||||
printf("%3d:%7d %7d %7d %7d\n",
|
||||
i, data_hard[i].real, (int32_t)data_soft[i].real, data_hard[i].imag, (int32_t)data_soft[i].imag);
|
||||
|
||||
printf("[hard fft test] [%d bytes] forward time = %ld us, backward time = %ld us\n",
|
||||
FFT_N,
|
||||
cycle[FFT_HARD][FFT_DIR_FORWARD]/(sysctl_clock_get_freq(SYSCTL_CLOCK_CPU)/1000000),
|
||||
cycle[FFT_HARD][FFT_DIR_BACKWARD]/(sysctl_clock_get_freq(SYSCTL_CLOCK_CPU)/1000000));
|
||||
printf("[soft fft test] [%d bytes] forward time = %ld us, backward time = %ld us\n",
|
||||
FFT_N,
|
||||
cycle[FFT_SOFT][FFT_DIR_FORWARD]/(sysctl_clock_get_freq(SYSCTL_CLOCK_CPU)/1000000),
|
||||
cycle[FFT_SOFT][FFT_DIR_BACKWARD]/(sysctl_clock_get_freq(SYSCTL_CLOCK_CPU)/1000000));
|
||||
}
|
||||
#ifdef __RT_THREAD_H__
|
||||
MSH_CMD_EXPORT(k210_fft_test,k210 fft test );
|
||||
#endif
|
||||
@@ -309,9 +309,9 @@ static int GetCompleteATReply(ATAgentType agent)
|
||||
|
||||
while (1) {
|
||||
PrivRead(agent->fd, &ch, 1);
|
||||
|
||||
#ifdef CONNECTION_FRAMEWORK_DEBUG
|
||||
printf(" %c (0x%x)\n", ch, ch);
|
||||
|
||||
#endif
|
||||
if (agent->receive_mode == ENTM_MODE){
|
||||
if (agent->entm_recv_len < ENTM_RECV_MAX) {
|
||||
PrivMutexObtain(&agent->lock);
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#define REPLY_TIME_OUT 3000
|
||||
#define REPLY_TIME_OUT 3
|
||||
|
||||
enum ReceiveMode
|
||||
{
|
||||
|
||||
@@ -355,7 +355,7 @@ static int Hc08Send(struct Adapter *adapter, const void *buf, size_t len)
|
||||
static int Hc08Recv(struct Adapter *adapter, void *buf, size_t len)
|
||||
{
|
||||
if (adapter->agent) {
|
||||
return EntmRecv(adapter->agent, (char *)buf, len, 40000);
|
||||
return EntmRecv(adapter->agent, (char *)buf, len, 40);
|
||||
} else {
|
||||
printf("Hc08Recv can not find agent\n");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
if CONNECTION_ADAPTER_NB
|
||||
config ADAPTER_BC28
|
||||
bool "Using nbiot adapter device BC28"
|
||||
default y
|
||||
|
||||
if ADAPTER_BC28
|
||||
source "$APP_DIR/Framework/connection/nbiot/bc28/Kconfig"
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
SRC_FILES := adapter_nbiot.c
|
||||
|
||||
ifeq ($(CONFIG_ADAPTER_BC28),y)
|
||||
SRC_DIR += bc28
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
||||
@@ -17,3 +17,156 @@
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.06.25
|
||||
*/
|
||||
#include <adapter.h>
|
||||
|
||||
|
||||
#ifdef ADAPTER_BC28
|
||||
extern AdapterProductInfoType BC28Attach(struct Adapter *adapter);
|
||||
#endif
|
||||
|
||||
#define ADAPTER_NBIOT_NAME "nbiot"
|
||||
|
||||
static int AdapterNbiotRegister(struct Adapter *adapter)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
strncpy(adapter->name, ADAPTER_NBIOT_NAME, NAME_NUM_MAX);
|
||||
|
||||
adapter->net_protocol = IP_PROTOCOL;
|
||||
adapter->net_role = CLIENT;
|
||||
|
||||
adapter->adapter_status = UNREGISTERED;
|
||||
|
||||
ret = AdapterDeviceRegister(adapter);
|
||||
if (ret < 0) {
|
||||
printf("AdapterNbiot register error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int AdapterNbiotInit(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
struct Adapter *adapter = malloc(sizeof(struct Adapter));
|
||||
if (!adapter) {
|
||||
printf("malloc adapter failed.\n");
|
||||
return -1;
|
||||
}
|
||||
memset(adapter, 0, sizeof(struct Adapter));
|
||||
ret = AdapterNbiotRegister(adapter);
|
||||
if (ret < 0) {
|
||||
printf("register nbiot adapter error\n");
|
||||
free(adapter);
|
||||
return -1;
|
||||
}
|
||||
#ifdef ADAPTER_BC28
|
||||
AdapterProductInfoType product_info = BC28Attach(adapter);
|
||||
if (!product_info) {
|
||||
printf("bc28 attach error\n");
|
||||
free(adapter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
adapter->product_info_flag = 1;
|
||||
adapter->info = product_info;
|
||||
adapter->done = product_info->model_done;
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/******************TEST*********************/
|
||||
int opennb(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_NBIOT_NAME);
|
||||
|
||||
#ifdef ADAPTER_BC28
|
||||
ret = AdapterDeviceOpen(adapter);
|
||||
if(ret < 0){
|
||||
printf("open adapter failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, opennb, opennb, show adapter nb information);
|
||||
int closenb(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_NBIOT_NAME);
|
||||
|
||||
#ifdef ADAPTER_BC28
|
||||
ret = AdapterDeviceClose(adapter);
|
||||
if(ret < 0){
|
||||
printf("open adapter failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, closenb, closenb, show adapter nb information);
|
||||
|
||||
int connectnb(int argc, char *argv[])
|
||||
{
|
||||
const char *send_msg = argv[1];
|
||||
int ret = 0;
|
||||
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_NBIOT_NAME);
|
||||
|
||||
|
||||
ret = AdapterDeviceConnect(adapter, 1, "101.68.82.219","9898",1);
|
||||
if(ret < 0){
|
||||
printf(" adapter send failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(2)|SHELL_CMD_DISABLE_RETURN, connectnb, connectnb, show adapter nb information);
|
||||
|
||||
int sendnb(int argc, char *argv[])
|
||||
{
|
||||
const char *send_msg = argv[1];
|
||||
int msg_len = atoi(argv[2]);
|
||||
int ret = 0;
|
||||
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_NBIOT_NAME);
|
||||
|
||||
printf("send argv1 %s len = %d\n",argv[1],msg_len);
|
||||
ret = AdapterDeviceSend(adapter, send_msg, msg_len);
|
||||
if(ret < 0){
|
||||
printf(" adapter send failed\n");
|
||||
return -1;
|
||||
}
|
||||
printf("nb send msg %s\n", send_msg);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN)|SHELL_CMD_PARAM_NUM(2)|SHELL_CMD_DISABLE_RETURN, sendnb, sendnb, show adapter nb information);
|
||||
|
||||
int recvnb(void)
|
||||
{
|
||||
char recv_msg[128];
|
||||
struct Adapter* adapter = AdapterDeviceFindByName(ADAPTER_NBIOT_NAME);
|
||||
memset(recv_msg,0,128);
|
||||
AdapterDeviceRecv(adapter, recv_msg, 128);
|
||||
PrivTaskDelay(2000);
|
||||
printf("nb recv msg %s\n", recv_msg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, recvnb, recvnb, show adapter nb information);
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef ADAPTER_NBIOT_H
|
||||
#define ADAPTER_NBIOT_H
|
||||
|
||||
#define CONFIG_NBIOT_RESET (0)
|
||||
#define CONFIG_NBIOT_CREATE_SOCKET (1)
|
||||
#define CONFIG_NBIOT_DELETE_SOCKET (2)
|
||||
|
||||
#define SOCKET_TYPE_DGRAM (0)
|
||||
#define SOCKET_TYPE_STREAM (1)
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,40 @@
|
||||
config ADAPTER_NBIOT_BC28
|
||||
string "BC28 adapter name"
|
||||
default "bc28"
|
||||
|
||||
if ADD_XIUOS_FETURES
|
||||
config ADAPTER_BC28_RESETPIN
|
||||
int "BC28 RESET pin number"
|
||||
default "100"
|
||||
|
||||
config ADAPTER_BC28_PIN_DRIVER
|
||||
string "BC28 device pin driver path"
|
||||
default "/dev/pin_dev"
|
||||
|
||||
config ADAPTER_BC28_DRIVER_EXTUART
|
||||
bool "Using extra uart to support nbiot"
|
||||
default n
|
||||
|
||||
config ADAPTER_BC28_DRIVER
|
||||
string "BC28 device uart driver path"
|
||||
default "/dev/usart2_dev2"
|
||||
depends on !ADAPTER_BC28_DRIVER_EXTUART
|
||||
|
||||
if ADAPTER_BC28_DRIVER_EXTUART
|
||||
config ADAPTER_BC28_DRIVER
|
||||
string "BC28 device extra uart driver path"
|
||||
default "/dev/extuart_dev5"
|
||||
|
||||
config ADAPTER_BC28_DRIVER_EXT_PORT
|
||||
int "if BC28 device using extuart, choose port"
|
||||
default "5"
|
||||
endif
|
||||
endif
|
||||
|
||||
if ADD_NUTTX_FETURES
|
||||
|
||||
endif
|
||||
|
||||
if ADD_RTTHREAD_FETURES
|
||||
|
||||
endif
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
SRC_FILES := bc28.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
@@ -0,0 +1,551 @@
|
||||
/*
|
||||
* 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 bc28.c
|
||||
* @brief Implement the connection nbiot adapter function, using BC28 device
|
||||
* @version 1.1
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021.09.15
|
||||
*/
|
||||
|
||||
#include <adapter.h>
|
||||
#include <at_agent.h>
|
||||
#include "../adapter_nbiot.h"
|
||||
|
||||
#define SOCKET_PROTOCOL_TCP (6)
|
||||
#define SOCKET_PROTOCOL_UDP (17)
|
||||
|
||||
#define NET_TYPE_AF_INET (0)
|
||||
#define NET_TYPE_AF_INET6 (1)
|
||||
|
||||
#define SOCKET_INVALID_ID (-1)
|
||||
|
||||
|
||||
static int BC28UartOpen(struct Adapter *adapter)
|
||||
{
|
||||
if (NULL == adapter) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Open device in read-write mode */
|
||||
adapter->fd = PrivOpen(ADAPTER_BC28_DRIVER,O_RDWR);
|
||||
if (adapter->fd < 0) {
|
||||
printf("BC28UartOpen get serial %s fd error\n", ADAPTER_BC28_DRIVER);
|
||||
return -1;
|
||||
}
|
||||
/* set serial config, serial_baud_rate = 9600 */
|
||||
|
||||
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_BC28_DRIVER_EXTUART
|
||||
cfg.ext_uart_no = ADAPTER_BC28_DRIVER_EXT_PORT;
|
||||
cfg.port_configure = PORT_CFG_INIT;
|
||||
#endif
|
||||
|
||||
struct PrivIoctlCfg ioctl_cfg;
|
||||
ioctl_cfg.ioctl_driver_type = SERIAL_TYPE;
|
||||
ioctl_cfg.args = &cfg;
|
||||
|
||||
PrivIoctl(adapter->fd, OPE_INT, &ioctl_cfg);
|
||||
PrivTaskDelay(1000);
|
||||
|
||||
printf("NBIot uart config ready\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void BC28PowerSet(void)
|
||||
{
|
||||
int pin_fd;
|
||||
pin_fd = PrivOpen(ADAPTER_BC28_PIN_DRIVER, O_RDWR);
|
||||
|
||||
struct PinParam pin_param;
|
||||
pin_param.cmd = GPIO_CONFIG_MODE;
|
||||
pin_param.mode = GPIO_CFG_OUTPUT;
|
||||
pin_param.pin = ADAPTER_BC28_RESETPIN;
|
||||
|
||||
struct PrivIoctlCfg ioctl_cfg;
|
||||
ioctl_cfg.ioctl_driver_type = PIN_TYPE;
|
||||
ioctl_cfg.args = &pin_param;
|
||||
PrivIoctl(pin_fd, OPE_CFG, &ioctl_cfg);
|
||||
|
||||
struct PinStat pin_stat;
|
||||
pin_stat.pin = ADAPTER_BC28_RESETPIN;
|
||||
pin_stat.val = GPIO_HIGH;
|
||||
PrivWrite(pin_fd, &pin_stat, 1);
|
||||
|
||||
PrivTaskDelay(200);//at least 200ms
|
||||
|
||||
pin_stat.val = GPIO_LOW;
|
||||
PrivWrite(pin_fd, &pin_stat, 1);
|
||||
|
||||
PrivClose(pin_fd);
|
||||
}
|
||||
|
||||
int NBIoTStatusCheck(struct Adapter *adapter )
|
||||
{
|
||||
int32 result = 0;
|
||||
|
||||
if (!adapter ){
|
||||
return -1;
|
||||
}
|
||||
|
||||
char at_cmd[64] = {0};
|
||||
|
||||
AtSetReplyEndChar(adapter->agent, 0x4F, 0x4B); /* set receive end flag as 'OK'*/
|
||||
|
||||
memcpy(at_cmd, "AT+CSQ", 6);
|
||||
strcat(at_cmd, "\n");
|
||||
printf("cmd : %s\n", at_cmd);
|
||||
result = AtCmdConfigAndCheck(adapter->agent, at_cmd, "OK");
|
||||
if(result < 0) {
|
||||
printf("%s %d cmd[%s] config failed!\n",__func__,__LINE__,at_cmd);
|
||||
result = -1;
|
||||
}
|
||||
|
||||
memcpy(at_cmd, "AT+CFUN?", 8);
|
||||
strcat(at_cmd, "\n");
|
||||
printf("cmd : %s\n", at_cmd);
|
||||
result = AtCmdConfigAndCheck(adapter->agent, at_cmd, "OK");
|
||||
if(result < 0) {
|
||||
printf("%s %d cmd[%s] config failed!\n",__func__,__LINE__,at_cmd);
|
||||
result = -1;
|
||||
}
|
||||
|
||||
memcpy(at_cmd, "AT+CIMI", 7);
|
||||
strcat(at_cmd, "\n");
|
||||
printf("cmd : %s\n", at_cmd);
|
||||
result = AtCmdConfigAndCheck(adapter->agent, at_cmd, "OK");
|
||||
if(result < 0) {
|
||||
printf("%s %d cmd[%s] config failed!\n",__func__,__LINE__,at_cmd);
|
||||
result = -1;
|
||||
}
|
||||
|
||||
memcpy(at_cmd, "AT+CEREG?", 9);
|
||||
strcat(at_cmd, "\n");
|
||||
printf("cmd : %s\n", at_cmd);
|
||||
result = AtCmdConfigAndCheck(adapter->agent, at_cmd, "OK");
|
||||
if(result < 0) {
|
||||
printf("%s %d cmd[%s] config failed!\n",__func__,__LINE__,at_cmd);
|
||||
result = -1;
|
||||
}
|
||||
|
||||
memcpy(at_cmd, "AT+CGATT?", 9);
|
||||
strcat(at_cmd, "\n");
|
||||
printf("cmd : %s\n", at_cmd);
|
||||
result = AtCmdConfigAndCheck(adapter->agent, at_cmd, "OK");
|
||||
if(result < 0) {
|
||||
printf("%s %d cmd[%s] config failed!\n",__func__,__LINE__,at_cmd);
|
||||
result = -1;
|
||||
}
|
||||
|
||||
memcpy(at_cmd, "AT+CGPADDR", 10);
|
||||
strcat(at_cmd, "\n");
|
||||
printf("cmd : %s\n", at_cmd);
|
||||
result = AtCmdConfigAndCheck(adapter->agent, at_cmd, "OK");
|
||||
if(result < 0) {
|
||||
printf("%s %d cmd[%s] config failed!\n",__func__,__LINE__,at_cmd);
|
||||
result = -1;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: NBIoT device create a socket connection
|
||||
* @param adapter - NBIoT adapter AT
|
||||
* @param socket_fd - socket file description
|
||||
* @param type - socket type
|
||||
* @param af_type - IPv4 or IPv6
|
||||
* @return success: EOK, failure: -ERROR
|
||||
*/
|
||||
int NBIoTSocketCreate(struct Adapter *adapter, struct Socket *socket )
|
||||
{
|
||||
int32 result = 0;
|
||||
|
||||
if (!adapter || !socket){
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ( socket->af_type == NET_TYPE_AF_INET6 ) {
|
||||
printf("IPv6 not surport !\n");
|
||||
result = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
char *str_af_type = "AF_INET";
|
||||
char *str_type;
|
||||
char str_fd[3] = {1};
|
||||
char *str_protocol ;
|
||||
char at_cmd[64] = {0};
|
||||
char listen_port[] = {0};
|
||||
|
||||
if (socket->socket_id >= 0 && socket->socket_id < 7) {
|
||||
itoa(socket->socket_id, str_fd, 10);
|
||||
adapter->socket.socket_id = socket->socket_id;
|
||||
} else {
|
||||
printf("surport max 0-6, socket_id = [%d] is error!\n",socket->socket_id);
|
||||
result = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if( socket->listen_port >= 0 && socket->listen_port <= 65535){
|
||||
itoa(socket->listen_port, listen_port, 10);
|
||||
}
|
||||
|
||||
adapter->socket.af_type = NET_TYPE_AF_INET;
|
||||
|
||||
if (socket->type == SOCKET_TYPE_STREAM) { //tcp = AT+NSOCR=STREAM,6,0,1,AF_INET
|
||||
adapter->socket.protocal = SOCKET_PROTOCOL_TCP;
|
||||
adapter->socket.type = SOCKET_TYPE_STREAM;
|
||||
str_type = "STREAM";
|
||||
str_protocol = "6";
|
||||
|
||||
} else if ( socket->type == SOCKET_TYPE_DGRAM ){ //udp
|
||||
adapter->socket.type = SOCKET_TYPE_DGRAM;
|
||||
adapter->socket.protocal = SOCKET_PROTOCOL_UDP;
|
||||
str_type = "DGRAM";
|
||||
str_protocol = "17";
|
||||
|
||||
} else {
|
||||
printf("error socket type \n");
|
||||
result = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
memcpy(at_cmd, "AT+NSOCR=", 9);
|
||||
strcat(at_cmd, str_type);
|
||||
strcat(at_cmd, ",");
|
||||
strcat(at_cmd, str_protocol);
|
||||
strcat(at_cmd, ",");
|
||||
strcat(at_cmd, listen_port);
|
||||
strcat(at_cmd, ",");
|
||||
strcat(at_cmd, str_fd);
|
||||
strcat(at_cmd, ",");
|
||||
strcat(at_cmd, str_af_type);
|
||||
strcat(at_cmd, "\n");
|
||||
|
||||
printf("cmd : %s\n", at_cmd);
|
||||
|
||||
AtSetReplyEndChar(adapter->agent, 0x4F, 0x4B); /* set receive end flag as 'OK'*/
|
||||
|
||||
result = AtCmdConfigAndCheck(adapter->agent, at_cmd, "OK");
|
||||
if(result < 0) {
|
||||
printf("%s %d cmd[%s] config failed!\n",__func__,__LINE__,at_cmd);
|
||||
result = -1;
|
||||
}
|
||||
|
||||
out:
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: NBIoT device close a socket connection
|
||||
* @param adapter - NBIoT adapter AT
|
||||
* @param socket_fd - socket file description
|
||||
* @return success: EOK, failure: -ERROR
|
||||
*/
|
||||
int NBIoTSocketDelete(struct Adapter *adapter )
|
||||
{
|
||||
|
||||
if (!adapter) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (adapter->socket.socket_id >= 7) {
|
||||
printf("socket fd error \n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
char str_fd[2] = {0};
|
||||
char at_cmd[16] = {0};
|
||||
itoa(adapter->socket.socket_id, str_fd, 10);
|
||||
|
||||
memcpy(at_cmd, "AT+NSOCL=", 9);
|
||||
strcat(at_cmd, str_fd);
|
||||
strcat(at_cmd, "\n");
|
||||
|
||||
printf("cmd : %s\n", at_cmd);
|
||||
AtSetReplyCharNum(adapter->agent, 1);
|
||||
ATOrderSend(adapter->agent, REPLY_TIME_OUT, NULL, at_cmd);
|
||||
PrivTaskDelay(300);
|
||||
|
||||
adapter->socket.socket_id = SOCKET_INVALID_ID;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int BC28Open(struct Adapter *adapter)
|
||||
{
|
||||
int ret = 0;
|
||||
struct Socket create_socket;
|
||||
|
||||
if (NULL == adapter) {
|
||||
return -1;
|
||||
}
|
||||
/*step1: open BC8 serial port*/
|
||||
ret = BC28UartOpen(adapter);
|
||||
if (ret < 0) {
|
||||
printf("bc18 setup failed.\n");
|
||||
return -1;
|
||||
}
|
||||
/*step2: init AT agent*/
|
||||
if (!adapter->agent) {
|
||||
char *agent_name = "niot_device";
|
||||
if (EOK != InitATAgent(agent_name, adapter->fd, 512)) {
|
||||
printf("at agent init failed !\n");
|
||||
return -1;
|
||||
}
|
||||
ATAgentType at_agent = GetATAgent(agent_name);
|
||||
adapter->agent = at_agent;
|
||||
}
|
||||
create_socket.type = SOCKET_TYPE_STREAM;
|
||||
create_socket.listen_port = 0;
|
||||
create_socket.socket_id = 1;
|
||||
create_socket.af_type = NET_TYPE_AF_INET;
|
||||
|
||||
BC28PowerSet(); /* reset bc28 module by set reset pin */
|
||||
PrivTaskDelay(6000);
|
||||
|
||||
NBIoTStatusCheck(adapter); /* ask module status*/
|
||||
|
||||
/*step3: create a tcp socket default */
|
||||
ret = NBIoTSocketCreate(adapter, &create_socket);
|
||||
if(ret < 0){
|
||||
printf("NBIot create tcp socket failed.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("NBiot BC28 open successful\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int BC28Close(struct Adapter *adapter)
|
||||
{
|
||||
NBIoTSocketDelete(adapter);
|
||||
PrivClose(adapter->fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int BC28Ioctl(struct Adapter *adapter, int cmd, void *args)
|
||||
{
|
||||
int ret = 0;
|
||||
switch (cmd)
|
||||
{
|
||||
case CONFIG_NBIOT_RESET: /* reset nbiot */
|
||||
BC28PowerSet();
|
||||
break;
|
||||
case CONFIG_NBIOT_CREATE_SOCKET: /* create tcp/UDP socket */
|
||||
if(!args){
|
||||
return -1;
|
||||
}
|
||||
struct Socket *create_socket = ( struct Socket *) args;
|
||||
ret = NBIoTSocketCreate(adapter, create_socket);
|
||||
break;
|
||||
case CONFIG_NBIOT_DELETE_SOCKET: /* close socket */
|
||||
ret = NBIoTSocketDelete(adapter);
|
||||
break;
|
||||
default:
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int BC28Connect(struct Adapter *adapter, enum NetRoleType net_role, const char *ip, const char *port, enum IpType ip_type)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
if (adapter->socket.socket_id > 6) {
|
||||
printf("socket fd error \n");
|
||||
result = -1;
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
if ( ip_type != SOCKET_TYPE_STREAM) {
|
||||
printf("socket type error \n");
|
||||
result = -1;
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
char at_cmd[64] = {0};
|
||||
char str_fd[2] = {0};
|
||||
|
||||
itoa(adapter->socket.socket_id, str_fd, 10);
|
||||
|
||||
memcpy(at_cmd, "AT+NSOCO=", 9);
|
||||
strcat(at_cmd, str_fd);
|
||||
strcat(at_cmd, ",");
|
||||
strcat(at_cmd, ip);
|
||||
strcat(at_cmd, ",");
|
||||
strcat(at_cmd, port);
|
||||
strcat(at_cmd, "\n");
|
||||
|
||||
printf("cmd : %s\n", at_cmd);
|
||||
AtSetReplyEndChar(adapter->agent, 0x4F, 0x4B);
|
||||
result = AtCmdConfigAndCheck(adapter->agent, at_cmd, "OK");
|
||||
if(result < 0) {
|
||||
printf("%s %d cmd[%s] config failed!\n",__func__,__LINE__,at_cmd);
|
||||
result = -1;
|
||||
}
|
||||
|
||||
__exit:
|
||||
return result;
|
||||
}
|
||||
|
||||
static int BC28Send(struct Adapter *adapter, const void *buf, size_t len)
|
||||
{
|
||||
uint32_t result = 0;
|
||||
char at_cmd[64] = {0};
|
||||
char str_fd[2] = {0};
|
||||
|
||||
|
||||
if (adapter->socket.type == SOCKET_TYPE_STREAM ) {
|
||||
|
||||
char size[2] = {0};
|
||||
|
||||
itoa(adapter->socket.socket_id, str_fd, 10);
|
||||
size[0] = len + '0';
|
||||
|
||||
memcpy(at_cmd, "AT+NSOSD=", 9);
|
||||
strcat(at_cmd, str_fd);
|
||||
strcat(at_cmd, ",");
|
||||
strcat(at_cmd, size);
|
||||
strcat(at_cmd, ",");
|
||||
strcat(at_cmd, buf);
|
||||
strcat(at_cmd, "\n");
|
||||
|
||||
} else if(adapter->socket.type == SOCKET_TYPE_DGRAM ) {
|
||||
|
||||
char listen_port[] = {0};
|
||||
|
||||
itoa(adapter->socket.socket_id, str_fd, 10);
|
||||
|
||||
itoa(adapter->socket.listen_port, listen_port, 10);
|
||||
|
||||
memcpy(at_cmd, "AT+NSOST=", 9);
|
||||
strcat(at_cmd, str_fd);
|
||||
strcat(at_cmd, ",");
|
||||
strcat(at_cmd, adapter->socket.dst_ip_addr);
|
||||
strcat(at_cmd, ",");
|
||||
strcat(at_cmd, listen_port);
|
||||
strcat(at_cmd, ",");
|
||||
strcat(at_cmd, buf);
|
||||
strcat(at_cmd, "\n");
|
||||
|
||||
}
|
||||
|
||||
printf("cmd : %s\n", at_cmd);
|
||||
AtSetReplyEndChar(adapter->agent, 0x4F, 0x4B);
|
||||
result = AtCmdConfigAndCheck(adapter->agent, at_cmd, "OK");
|
||||
if(result < 0) {
|
||||
printf("%s %d cmd[%s] config failed!\n",__func__,__LINE__,at_cmd);
|
||||
result = -1;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static int BC28Recv(struct Adapter *adapter, void *buf, size_t len)
|
||||
{
|
||||
char at_cmd[64] = {0};
|
||||
char str_fd[2] = {0};
|
||||
char size[2] = {0};
|
||||
char *result = NULL;
|
||||
|
||||
ATReplyType reply = CreateATReply(64);
|
||||
if (NULL == reply) {
|
||||
printf("at create failed ! \n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
itoa(adapter->socket.socket_id, str_fd, 10);
|
||||
itoa(len, size, 10);
|
||||
|
||||
memcpy(at_cmd, "AT+NSORF=", 9);
|
||||
strcat(at_cmd, str_fd);
|
||||
strcat(at_cmd, ",");
|
||||
strcat(at_cmd, size);
|
||||
strcat(at_cmd, "\n");
|
||||
|
||||
printf("cmd : %s\n", at_cmd);
|
||||
ATOrderSend(adapter->agent, REPLY_TIME_OUT, reply, at_cmd);
|
||||
PrivTaskDelay(300);
|
||||
|
||||
result = GetReplyText(reply);
|
||||
if (!result) {
|
||||
printf("%s %n get reply failed.\n",__func__,__LINE__);
|
||||
}
|
||||
memcpy(buf, result, reply->reply_len);
|
||||
|
||||
if (reply) {
|
||||
DeleteATReply(reply);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int BC28Disconnect(struct Adapter *adapter)
|
||||
{
|
||||
if (!adapter) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return NBIoTSocketDelete(adapter);
|
||||
}
|
||||
|
||||
static const struct IpProtocolDone BC28_done =
|
||||
{
|
||||
.open = BC28Open,
|
||||
.close = BC28Close,
|
||||
.ioctl = BC28Ioctl,
|
||||
.setup = NULL,
|
||||
.setdown = NULL,
|
||||
.setaddr = NULL,
|
||||
.setdns = NULL,
|
||||
.setdhcp = NULL,
|
||||
.ping = NULL,
|
||||
.netstat = NULL,
|
||||
.connect = BC28Connect,
|
||||
.send = BC28Send,
|
||||
.recv = BC28Recv,
|
||||
.disconnect = BC28Disconnect,
|
||||
};
|
||||
|
||||
AdapterProductInfoType BC28Attach(struct Adapter *adapter)
|
||||
{
|
||||
struct AdapterProductInfo *product_info = malloc(sizeof(struct AdapterProductInfo));
|
||||
if (!product_info) {
|
||||
printf("BC28Attach malloc product_info error\n");
|
||||
return NULL;
|
||||
}
|
||||
memset(product_info, 0, sizeof(struct AdapterProductInfo));
|
||||
|
||||
strncpy(product_info->model_name, ADAPTER_NBIOT_BC28,sizeof(product_info->model_name));
|
||||
product_info->model_done = (void *)&BC28_done;
|
||||
|
||||
return product_info;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ static int Hfa21WifiReceive(struct Adapter *adapter, void *rev_buffer, size_t bu
|
||||
printf("hfa21 receive waiting ... \n");
|
||||
|
||||
if (adapter->agent) {
|
||||
return EntmRecv(adapter->agent, (char *)rev_buffer, buffer_len, 40000);
|
||||
return EntmRecv(adapter->agent, (char *)rev_buffer, buffer_len, 40);
|
||||
} else {
|
||||
printf("Hfa21WifiReceive can not find agent!\n");
|
||||
}
|
||||
|
||||
@@ -211,7 +211,9 @@ static int E18Open(struct Adapter *adapter)
|
||||
ATAgentType at_agent = GetATAgent(agent_name);
|
||||
adapter->agent = at_agent;
|
||||
}
|
||||
|
||||
|
||||
AtSetReplyLrEnd(adapter->agent, 1);
|
||||
|
||||
try_again:
|
||||
while(try_times--){
|
||||
ret = E18NetRoleConfig(adapter);
|
||||
@@ -355,7 +357,7 @@ static int E18Recv(struct Adapter *adapter, void *buf, size_t len)
|
||||
if(!adapter->agent){
|
||||
PrivRead(adapter->fd, buf, len);
|
||||
} else {
|
||||
EntmRecv(adapter->agent, buf, len, 3000);/* wait timeout 3000ms*/
|
||||
EntmRecv(adapter->agent, buf, len, 3);/* wait timeout 3000ms*/
|
||||
}
|
||||
break;
|
||||
case STT_MODE2:
|
||||
@@ -405,7 +407,8 @@ AdapterProductInfoType E18Attach(struct Adapter *adapter)
|
||||
printf("E18Attach malloc product_info error\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(product_info, 0, sizeof(struct AdapterProductInfo));
|
||||
|
||||
strncpy(product_info->model_name, ADAPTER_ZIGBEE_E18,sizeof(product_info->model_name));
|
||||
product_info->model_done = (void *)&E18_done;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user