A36 PCB1.1 软件工程整理
This commit is contained in:
@ -0,0 +1,124 @@
|
||||
#ifndef __AUTONAVI_CONFIG_H__
|
||||
#define __AUTONAVI_CONFIG_H__
|
||||
|
||||
#include "autonavi_profile.h"
|
||||
|
||||
|
||||
#define AUTONAVI_LOG printf
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t msgid:4;
|
||||
uint8_t cmd:4;
|
||||
uint8_t totalframe;
|
||||
uint8_t frame_seq;
|
||||
uint16_t frame_len;
|
||||
uint8_t *buff;
|
||||
// uint16_t data_len;
|
||||
}autonavi_protocol_data_t;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t state;//导航状态
|
||||
int8_t icon;//图标
|
||||
uint8_t text[128];//文本信息
|
||||
uint16_t next_dist;//下个路口距离 米
|
||||
uint16_t remaining_time;//导航剩余时间,单位秒
|
||||
uint16_t remaining_mileage;//剩余里程
|
||||
uint16_t arrival_time;//到达时间
|
||||
uint8_t next_name[128];//下个路口名称
|
||||
int8_t event;//导航事件
|
||||
uint8_t fault_code;//故障码
|
||||
//uint8_t fault_info;//异常信息说明
|
||||
|
||||
}autonavi_payload_t;
|
||||
|
||||
//命令类型
|
||||
enum
|
||||
{
|
||||
CMD_TYPE_UNKNOWN = 0,
|
||||
CMD_TYPE_BIND_DEVICE = 0x01,
|
||||
CMD_TYPE_AUC=0x02,
|
||||
CMD_TYPE_NAVI=0x03,
|
||||
CMD_TYPE_LOOCK = 0x04,//not
|
||||
};
|
||||
|
||||
//导航参数id
|
||||
enum{
|
||||
NAVI_PARAM_ID_UNKNOWN = 0,
|
||||
NAVI_PARAM_ID_STATE=0x01,//导航状态
|
||||
NAVI_PARAM_ID_ICON=0x02,//icon指引箭头
|
||||
NAVI_PARAM_ID_TEXT=0x03,//文字导航信息
|
||||
NAVI_PARAM_ID_DIST=0x04,//距离下个路口的距离 单位米
|
||||
NAVI_PARAM_ID_LEFT_TIME=0x05,//剩余时间
|
||||
NAVI_PARAM_ID_REMAIN_KM=0x06,//剩余里程
|
||||
NAVI_PARAM_ID_ARRIVAL_TIME=0x07,//到达时间
|
||||
NAVI_PARAM_ID_NEXT_NAME=0x08,//下一个路口名称
|
||||
NAVI_PARAM_ID_EVENT_TYPE=0x09,//导航事件类型
|
||||
NAVI_PARAM_ID_FAULT_CODE=0xf0,//故障代码
|
||||
NAVI_PARAM_ID_FAULT_INFO=0xf1,//故障信息
|
||||
NAVI_PARAM_ID_DEBUG_INFO=0xff,//导航调试信息
|
||||
};
|
||||
enum{
|
||||
NAVI_ICON_ID_NULL = 0,
|
||||
NAVI_ICON_ID_CAR=0x01,//自车图标
|
||||
NAVI_ICON_ID_TURN_LEFT=0x02,//左转图标
|
||||
NAVI_ICON_ID_TURN_RIGHT=0x03,//右转图标
|
||||
NAVI_ICON_ID_SLIGHT_LEFT=0x04,//左前方
|
||||
NAVI_ICON_ID_SLIGHT_RIGHT=0x05,//右前方
|
||||
NAVI_ICON_ID_TURN_HARDLEFT=0x06,//左后方
|
||||
NAVI_ICON_ID_TURN_HARDRIGHT=0x07,//右后方
|
||||
NAVI_ICON_ID_UTURN=0x08,//左转掉头
|
||||
NAVI_ICON_ID_CONTINUE=0x09,//直行图标
|
||||
NAVI_ICON_ID_WAY=0x0a,//到达途径点
|
||||
NAVI_ICON_ID_ENTRY_RING=0x0b,//进⼊环岛图标,右侧通⾏地区的逆时针环岛
|
||||
NAVI_ICON_ID_LEAVE_RING=0x0c,//驶出环岛图标,右侧通⾏地区的逆时针环岛
|
||||
NAVI_ICON_ID_SAPA=0x0d,//到达服务区图标 not yet implemented
|
||||
//...
|
||||
NAVI_ICON_ID_UTURN_RIGHT=0x13,//右转掉头图标,左侧通⾏地区的掉头
|
||||
//...
|
||||
NAVI_ICON_ID_CROSS_WALK=0x1d,//通过人行横道
|
||||
NAVI_ICON_ID_OVER_PASS=0x1e,//通过过街天桥
|
||||
NAVI_ICON_ID_UNDER_GROUND=0x1f,//通过地下通道图标
|
||||
NAVI_ICON_ID_SQUARE=0x20,//通过广场
|
||||
NAVI_ICON_ID_PARK=0x21,//通过公园
|
||||
NAVI_ICON_ID_STAIRCASE=0x22,//通过扶梯
|
||||
NAVI_ICON_ID_LIGFT=0x23,//通过直梯
|
||||
NAVI_ICON_ID_CABLEWAY=0x24,//通过索道
|
||||
NAVI_ICON_ID_SKY_CHANNEL=0x25,//通过空中通道
|
||||
NAVI_ICON_ID_CHANNEL=0x26,//通过通道
|
||||
NAVI_ICON_ID_WALKR_ROAD=0x27,//通过行人道路
|
||||
NAVI_ICON_ID_BOAT_LINE=0x28,//通过游船路线
|
||||
NAVI_ICON_ID_SIGHTSEEING_LINE=0x29,//通过观光车路线
|
||||
NAVI_ICON_ID_SKIDWAY=0x2a,//通过滑道
|
||||
NAVI_ICON_ID_LADDER=0x2b,//通过阶梯
|
||||
NAVI_ICON_ID_SLOPE=0x2c,//通过斜坡
|
||||
NAVI_ICON_ID_BRIDGE=0x2d,//通过桥
|
||||
NAVI_ICON_ID_FERRY=0x2e,//通过轮渡
|
||||
NAVI_ICON_ID_SUBEAY=0x2f,//通过地铁通道
|
||||
NAVI_ICON_ID_ENTER_BUILDING=0x30,//通过建筑物
|
||||
NAVI_ICON_ID_LEAVE_BUILDING=0x31,//离开建筑物
|
||||
NAVI_ICON_ID_BY_ELEVATOR=0x32,//电梯换层
|
||||
NAVI_ICON_ID_BY_STAIR=0x33,//楼梯换层
|
||||
NAVI_ICON_ID_BY_ESCALATOR=0x34,//扶梯换层
|
||||
NAVI_ICON_ID_LOW_TRAFFICCROSS=0x35,//非导航段通过红绿灯路口
|
||||
NAVI_ICON_ID_LOW_CROSS=0x36,//非导航段通过普通路口
|
||||
NAVI_ICON_ID_HOSING_ESTATELNNER=0X37,//小区内部路偏航抑制态
|
||||
NAVI_ICON_ID_LEAVE_OVERPASS=0x38,//下天桥
|
||||
NAVI_ICON_ID_LEAVE_UNDERGROUND=0x39,//出地下通道
|
||||
NAVI_ICON_ID_LEAVE_LADDER=0x3a,//出阶梯
|
||||
NAVI_ICON_ID_CROSS_ROAD_DIAGONAL=0x3b,//到马路斜对面
|
||||
NAVI_ICON_ID_RIDE_TAB_START=-7,//骑行导航页顶部栏起点
|
||||
NAVI_ICON_ID_FOOT_TAB_END=-6,//步行导航页顶部栏终点
|
||||
NAVI_ICON_ID_FOOT_START=-5,//步行导航顶部栏起点
|
||||
NAVI_ICON_ID_PREVIEW_TAB_END=-4,//预览页面导航页tab终点
|
||||
NAVI_ICON_ID_TAB_SUBWAY = -11,//步行中地铁标识
|
||||
//NAVI_ICON_ID_DEFAULT,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,235 @@
|
||||
#include "autonavi_handler.h"
|
||||
#include "autonavi_config.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "app_lvgl.h"
|
||||
|
||||
static bool bond_flag=false;
|
||||
void autonavi_data_decode(autonavi_protocol_data_t *msg);
|
||||
|
||||
#define PVER_STR "1"
|
||||
#define NVER_STR "1"
|
||||
#define MANUFACTURE_STR "freqchip"
|
||||
#define DEVICE_STR "G0"
|
||||
#define DID_STR "FR309x"
|
||||
#define SVER_STR "1"
|
||||
#if 0
|
||||
#define KEY_STR "3084f2321ceb3845087220046466a87c"
|
||||
#define SIG_STR "40f62e001f0da15d9d8bec5ba8e8569b"
|
||||
#else
|
||||
#define KEY_STR "3084f2321ceb3845087220046466a87c"
|
||||
#define SIG_STR "32e7c7d5a4164d260402d29d4e6538bd"
|
||||
#endif
|
||||
#define SEED_STR "a1b2c3d4"
|
||||
|
||||
//did=FR309x&key=3084f2321ceb3845087220046466a87c&seed=a1b2c3d4
|
||||
static autonavi_protocol_data_t protocol_msg={0};
|
||||
static autonavi_payload_t autonavi_payload={0};
|
||||
|
||||
uint16_t read_basic_attribute_service(uint8_t *param,uint16_t max_len)
|
||||
{
|
||||
uint16_t dst_len = 0;
|
||||
#if 1
|
||||
if(bond_flag==false)
|
||||
{
|
||||
dst_len = snprintf((char*)param,max_len,"pver=%s&nver=%s&manu=%s&device=%s&did=%s&sver=%s&key=%s&sig=%s&seed=%s",\
|
||||
PVER_STR,NVER_STR,MANUFACTURE_STR,DEVICE_STR,DID_STR,SVER_STR,KEY_STR,SIG_STR,SEED_STR);
|
||||
AUTONAVI_LOG("len:%d src:%s\r\n",dst_len,param);
|
||||
}else{
|
||||
dst_len = snprintf((char*)param,max_len,"pver=%s&nver=%s&manu=%s&device=%s&did=%s&sver=%s&key=%s&sig=%s&seed=%s&status=authed",\
|
||||
PVER_STR,NVER_STR,MANUFACTURE_STR,DEVICE_STR,DID_STR,SVER_STR,KEY_STR,SIG_STR,SEED_STR);
|
||||
AUTONAVI_LOG("len:%d src:%s\r\n",dst_len,param);
|
||||
}
|
||||
#else
|
||||
uint16_t dst_len = snprintf((char*)param,max_len,"pver=%s&nver=%s&manu=%s&device=%s&did=%s&sver=%s&=seed=%s",\
|
||||
PVER_STR,NVER_STR,MANUFACTURE_STR,DEVICE_STR,DID_STR,SVER_STR,SEED_STR);
|
||||
AUTONAVI_LOG("len:%d src:%s\r\n",dst_len,param);
|
||||
#endif
|
||||
return dst_len;
|
||||
}
|
||||
/*
|
||||
msgid|cmd totalframe frame_seq frame_length frame_length
|
||||
1字节 1字节 1字节 1字节 1字节
|
||||
*/
|
||||
void autonavi_data_recv(uint8_t *data,uint16_t len)
|
||||
{
|
||||
static bool first_flag=false;
|
||||
static uint16_t frame_cnt=0;
|
||||
static uint16_t frame_sum=0;
|
||||
static uint8_t last_id=0;
|
||||
protocol_msg.msgid = data[0]&0xf0;
|
||||
protocol_msg.cmd = data[0]&0x0f;
|
||||
uint16_t src_len = ((data[4]<<8)|data[3]);
|
||||
switch(protocol_msg.cmd)
|
||||
{
|
||||
case CMD_TYPE_BIND_DEVICE://绑定
|
||||
{
|
||||
|
||||
AUTONAVI_LOG("CMD_TYPE_BIND_DEVICE :%x\r\n",protocol_msg.cmd);
|
||||
char *param = pvPortMalloc(300);
|
||||
if(param==NULL)return;
|
||||
uint16_t dst_len = snprintf((char*)param,300,"pver=%s&nver=%s&manu=%s&device=%s&did=%s&sver=%s&key=%s&sig=%s&seed=%s&status=authed",\
|
||||
PVER_STR,NVER_STR,MANUFACTURE_STR,DEVICE_STR,DID_STR,SVER_STR,KEY_STR,SIG_STR,SEED_STR);
|
||||
AUTONAVI_LOG("send len:%d data:%s\r\n",dst_len,param);
|
||||
autonavi_send_notify((uint8_t*)param,dst_len);
|
||||
vPortFree(param);
|
||||
bond_flag = true; //绑定成功后需要保存这个状态 下次直接链接
|
||||
}
|
||||
break;
|
||||
|
||||
case CMD_TYPE_AUC:// 鉴权
|
||||
{
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case CMD_TYPE_NAVI:
|
||||
{
|
||||
if(data[1]==0x01) //单包数据
|
||||
{
|
||||
frame_sum = 0;
|
||||
frame_cnt = 0;
|
||||
first_flag = false;
|
||||
if(len>5)
|
||||
{
|
||||
protocol_msg.buff = pvPortMalloc(src_len);
|
||||
if(protocol_msg.buff==NULL)return;
|
||||
protocol_msg.frame_len = (len-5);
|
||||
memcpy(protocol_msg.buff,&data[5],(len-5));
|
||||
}else{
|
||||
protocol_msg.frame_len = 0;
|
||||
protocol_msg.buff = NULL;
|
||||
|
||||
}
|
||||
autonavi_data_decode(&protocol_msg);
|
||||
vPortFree(protocol_msg.buff);
|
||||
}else if(data[1]>0x01){//拼包数据
|
||||
if((first_flag==false) && (data[2]==0x01))
|
||||
{
|
||||
first_flag = true;
|
||||
frame_cnt = 0;
|
||||
frame_sum = (data[1]*src_len);
|
||||
protocol_msg.buff = pvPortMalloc(frame_sum);
|
||||
if(protocol_msg.buff==NULL)return;
|
||||
memset(protocol_msg.buff,0,frame_sum);
|
||||
}
|
||||
memcpy(&protocol_msg.buff[frame_cnt],&data[5],src_len);
|
||||
frame_cnt+=src_len;
|
||||
AUTONAVI_LOG("cnt:%d sum:%d\r\n",frame_cnt,frame_sum);
|
||||
if((data[2] == data[1]) && (frame_cnt <= frame_sum)) //接收最后一帧拼包
|
||||
{
|
||||
protocol_msg.frame_len=frame_cnt;
|
||||
autonavi_data_decode(&protocol_msg);
|
||||
//aicare_app_data_decode(data[1],data[2],data[3],src_len,frame_recving_buffer);
|
||||
vPortFree(protocol_msg.buff);
|
||||
protocol_msg.buff=NULL;
|
||||
frame_sum = 0;
|
||||
frame_cnt = 0;
|
||||
first_flag = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void autonavi_data_handler(uint8_t *data)
|
||||
{
|
||||
uint8_t len = data[1];
|
||||
printf("len:%d\r\n",len);
|
||||
switch(data[0])
|
||||
{
|
||||
case NAVI_PARAM_ID_STATE://导航状态
|
||||
autonavi_payload.state = data[2];
|
||||
AUTONAVI_LOG("autonavi_payload.state:0x%x\r\n",autonavi_payload.state);
|
||||
break;
|
||||
|
||||
case NAVI_PARAM_ID_ICON://icon指引箭头
|
||||
autonavi_payload.icon = data[2];
|
||||
AUTONAVI_LOG("autonavi_payload.icon:0x%x %d\r\n",autonavi_payload.icon,(int)autonavi_payload.icon);
|
||||
break;
|
||||
|
||||
case NAVI_PARAM_ID_TEXT://文字导航信息
|
||||
if(len>0)
|
||||
{
|
||||
memset(autonavi_payload.text,0,sizeof(autonavi_payload.text));
|
||||
memcpy(autonavi_payload.text,&data[2],len);
|
||||
AUTONAVI_LOG("autonavi_payload.text:%s\r\n",autonavi_payload.text);
|
||||
}
|
||||
break;
|
||||
|
||||
case NAVI_PARAM_ID_DIST://距离下个路口的距离 单位米
|
||||
memcpy((void*)&autonavi_payload.next_dist,&data[2],len);
|
||||
AUTONAVI_LOG("autonavi_payload.next_dist:%d\r\n",autonavi_payload.next_dist);
|
||||
break;
|
||||
case NAVI_PARAM_ID_LEFT_TIME://剩余时间
|
||||
memcpy((void*)&autonavi_payload.remaining_time,&data[2],len);
|
||||
AUTONAVI_LOG("autonavi_payload.remaining_time:%d\r\n",autonavi_payload.remaining_time);
|
||||
break;
|
||||
|
||||
case NAVI_PARAM_ID_REMAIN_KM://剩余里程
|
||||
//= (data[2]<<8|data[3]);
|
||||
memcpy((void*)&autonavi_payload.remaining_mileage,&data[2],len);
|
||||
AUTONAVI_LOG("autonavi_payload.remaining_mileage:%d\r\n",autonavi_payload.remaining_mileage);
|
||||
break;
|
||||
|
||||
case NAVI_PARAM_ID_ARRIVAL_TIME://到达时间
|
||||
// autonavi_payload.arrival_time = (data[2]<<8|data[3]);
|
||||
memcpy((void*)&autonavi_payload.arrival_time,&data[2],len);
|
||||
AUTONAVI_LOG("autonavi_payload.arrival_time:%d\r\n",autonavi_payload.arrival_time);
|
||||
break;
|
||||
|
||||
|
||||
case NAVI_PARAM_ID_NEXT_NAME://下一个路口名称
|
||||
if(len>0)
|
||||
{
|
||||
memset(autonavi_payload.next_name,0,sizeof(autonavi_payload.next_name));
|
||||
memcpy(autonavi_payload.next_name,&data[2],len);
|
||||
AUTONAVI_LOG("autonavi_payload.next_name:%s\r\n",autonavi_payload.next_name);
|
||||
}
|
||||
break;
|
||||
|
||||
case NAVI_PARAM_ID_EVENT_TYPE://导航事件类型
|
||||
autonavi_payload.event = data[2];
|
||||
AUTONAVI_LOG("autonavi_payload.event:0x%x\r\n",autonavi_payload.event);
|
||||
break;
|
||||
case NAVI_PARAM_ID_FAULT_CODE://故障代码
|
||||
autonavi_payload.fault_code = data[2];
|
||||
AUTONAVI_LOG("autonavi_payload.fault_code:0x%x\r\n",autonavi_payload.fault_code);
|
||||
break;
|
||||
|
||||
case NAVI_PARAM_ID_FAULT_INFO://故障信息
|
||||
AUTONAVI_LOG("fault_info:%s\r\n",&data[2]);
|
||||
|
||||
break;
|
||||
case NAVI_PARAM_ID_DEBUG_INFO://导航调试信息
|
||||
AUTONAVI_LOG("autonavi_debug:%s\r\n",&data[2]);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void autonavi_data_decode(autonavi_protocol_data_t *msg)
|
||||
{
|
||||
uint8_t sver = msg->buff[0];
|
||||
printf("sver:%d\r\n",sver);
|
||||
for(uint16_t i = 1;i<msg->frame_len;)
|
||||
{
|
||||
autonavi_data_handler(&msg->buff[i]);
|
||||
i+=msg->buff[i+1]+2;
|
||||
}
|
||||
// gui_task_msg_send(AUTONAVI_MSG_IN_EVT,NULL,0,NULL,0,NULL);
|
||||
}
|
||||
|
||||
void autonavi_msg_clear(void)
|
||||
{
|
||||
memset((void*)&autonavi_payload,0,sizeof(autonavi_payload_t));
|
||||
}
|
||||
|
||||
autonavi_payload_t *get_autonavi_msg(void)
|
||||
{
|
||||
return &autonavi_payload;
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
#ifndef __AUTONAVI_HANDLER_H__
|
||||
#define __AUTONAVI_HANDLER_H__
|
||||
|
||||
#include "autonavi_profile.h"
|
||||
#include "autonavi_config.h"
|
||||
|
||||
|
||||
uint16_t read_basic_attribute_service(uint8_t *param,uint16_t max_len);
|
||||
void autonavi_data_recv(uint8_t *data,uint16_t len);
|
||||
void autonavi_msg_clear(void);
|
||||
autonavi_payload_t *get_autonavi_msg(void);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,433 @@
|
||||
#include "autonavi_profile.h"
|
||||
#include "autonavi_config.h"
|
||||
#include "autonavi_handler.h"
|
||||
|
||||
static const uint8_t sp_autonavi_uuid[] = SP_AUTONAVI_UUID;
|
||||
static uint8_t conn_svc_idx = 0;
|
||||
|
||||
/******************************* Characteristic 1 defination *******************************/
|
||||
|
||||
#define AUTONAVI_CHAR1_VALUE_LEN 512
|
||||
static uint8_t autonavi_char1_value[AUTONAVI_CHAR1_VALUE_LEN] = {0};
|
||||
|
||||
//#define SP_CHAR1_USER_DESC_LEN 17
|
||||
|
||||
static uint8_t desc_data[2] = {0};
|
||||
|
||||
/******************************* Characteristic 2 defination *******************************/
|
||||
#define AUTONAVI_CHAR2_VALUE_LEN 512
|
||||
static uint8_t autonavi_char2_value[AUTONAVI_CHAR2_VALUE_LEN] = {0x11, 0x22, 0x33, 0x44, 0x55};
|
||||
|
||||
//#define SP_CHAR2_USER_DESC_LEN 17
|
||||
static uint16_t ble_mtu = 0;
|
||||
|
||||
|
||||
static const gatt_attribute_t simple_profile_att_table[] =
|
||||
{
|
||||
// Simple gatt Service Declaration
|
||||
[AUTONAVI_IDX_SERVICE] = { // autonvio read
|
||||
{ UUID_SIZE_2, UUID16_ARR(GATT_PRIMARY_SERVICE_UUID) }, /* UUID */
|
||||
GATT_PROP_READ, /* Permissions */
|
||||
UUID_SIZE_16, /* Max size of the value */ /* Service UUID size in service declaration */
|
||||
(uint8_t*)sp_autonavi_uuid, /* Value of the attribute */ /* Service UUID value in service declaration */
|
||||
},
|
||||
|
||||
/******************************* Characteristic 1 defination *******************************/
|
||||
// Characteristic 1 Declaration
|
||||
[AUTONAVI_IDX_CHAR1_DECLARATION] = {
|
||||
{ UUID_SIZE_2, UUID16_ARR(GATT_CHARACTER_UUID) }, /* UUID */
|
||||
GATT_PROP_READ, /* Permissions */
|
||||
0, /* Max size of the value */
|
||||
NULL, /* Value of the attribute */
|
||||
},
|
||||
// Characteristic 1 Value
|
||||
[AUTONAVI_IDX_CHAR1_VALUE] = {
|
||||
{ UUID_SIZE_16, SP_AUTONAVI_CHAR1_UUID }, /* UUID */
|
||||
GATT_PROP_READ | GATT_PROP_NOTI , /* Permissions */
|
||||
AUTONAVI_CHAR1_VALUE_LEN, /* Max size of the value */
|
||||
NULL, /* Value of the attribute */ /* Can assign a buffer here, or can be assigned in the application by user */
|
||||
/* When the buffer is null, if a read request is received,
|
||||
* the lower layer will report a read event to the gatt callback.
|
||||
* The user must assign a value to the data pointer in the callback event
|
||||
* to reply to the read request
|
||||
*/
|
||||
},
|
||||
|
||||
// Characteristic 1 client characteristic configuration
|
||||
[AUTONAVI_IDX_CHAR1_CFG] = {
|
||||
{ UUID_SIZE_2, UUID16_ARR(GATT_CLIENT_CHAR_CFG_UUID) }, /* UUID */
|
||||
GATT_PROP_WRITE_REQ, /* Permissions */
|
||||
2, /* Max size of the value */
|
||||
desc_data, /* Value of the attribute */ /* Can assign a buffer here, or can be assigned in the application by user */
|
||||
},
|
||||
|
||||
// // Characteristic 1 User Description
|
||||
// [SP_IDX_CHAR1_USER_DESCRIPTION] = {
|
||||
// { UUID_SIZE_2, UUID16_ARR(GATT_CHAR_USER_DESC_UUID) }, /* UUID */
|
||||
// GATT_PROP_READ, /* Permissions */
|
||||
// SP_CHAR1_USER_DESC_LEN, /* Max size of the value */
|
||||
// (uint8_t *)sp_char1_user_desc_data, /* Value of the attribute */
|
||||
// },
|
||||
|
||||
/******************************* Characteristic 2 defination *******************************/
|
||||
// Characteristic 2 Declaration
|
||||
[AUTONAVI_IDX_CHAR2_DECLARATION] = {
|
||||
{ UUID_SIZE_2, UUID16_ARR(GATT_CHARACTER_UUID) }, /* UUID */
|
||||
GATT_PROP_WRITE_CMD, /* Permissions */
|
||||
0, /* Max size of the value */
|
||||
NULL, /* Value of the attribute */
|
||||
},
|
||||
|
||||
// Characteristic 2 Value
|
||||
[AUTONAVI_IDX_CHAR2_VALUE] = {
|
||||
{ UUID_SIZE_16, SP_AUTONAVI_CHAR2_UUID }, /* UUID */
|
||||
GATT_PROP_WRITE_CMD , /* Permissions */
|
||||
AUTONAVI_CHAR2_VALUE_LEN, /* Max size of the value */
|
||||
autonavi_char2_value, /* Value of the attribute */ /* Can assign a buffer here, or can be assigned in the application by user */
|
||||
/* When the buffer is null, if a read request is received,
|
||||
* the lower layer will report a read event to the gatt callback.
|
||||
* The user must assign a value to the data pointer in the callback event
|
||||
* to reply to the read request
|
||||
*/
|
||||
},
|
||||
|
||||
// Characteristic 2 User Description
|
||||
// [SP_IDX_CHAR2_USER_DESCRIPTION] = {
|
||||
// { UUID_SIZE_2, UUID16_ARR(GATT_CHAR_USER_DESC_UUID) }, /* UUID */
|
||||
// GATT_PROP_READ, /* Permissions */
|
||||
// SP_CHAR2_USER_DESC_LEN, /* Max size of the value */
|
||||
// (uint8_t *)sp_char2_user_desc_data, /* Value of the attribute */
|
||||
// },
|
||||
};
|
||||
|
||||
static void app_ble_start_advertising(void);
|
||||
|
||||
static char local_device_name[] = "AutoNavi";
|
||||
static adv_handle adv;
|
||||
static uint8_t service_id;
|
||||
/*
|
||||
* Advertising data, max size is 28 bytes
|
||||
*/
|
||||
//61 75 12 76-fd d6-11 ed-be 56-02 42 ac 12 00 02
|
||||
static uint8_t adv_data[] = {
|
||||
/* gatt service information */
|
||||
#if 1
|
||||
0x11, //length of this AD
|
||||
GAP_ADVTYPE_128BIT_MORE, //128bit service uuid AD type
|
||||
0x02,0x00,0x12, 0xac,0x42,0x02,0x56,0xbe,0xed,0x11,0xd6,0xfd,0x76,0x12,0x75,0x61,//value.service uuid:0xFFF0
|
||||
#else
|
||||
0x03,
|
||||
GAP_ADVTYPE_16BIT_COMPLETE,
|
||||
0xf1,0xfe,
|
||||
#endif
|
||||
/* local device name information */
|
||||
0x09, //length of this AD
|
||||
GAP_ADVTYPE_LOCAL_NAME_COMPLETE, //complete name AD type
|
||||
'A','u','t','o','N','a','v','i', //value.local device name
|
||||
};
|
||||
|
||||
/*
|
||||
* Advertising scan response data, max size is 31 bytes
|
||||
*/
|
||||
static uint8_t adv_scan_rsp_data[] = {
|
||||
/* local device name information */
|
||||
0x09, //length of this AD
|
||||
GAP_ADVTYPE_LOCAL_NAME_COMPLETE, //complete name AD type
|
||||
'A','u','t','o','N','a','v','i', //value.local device name
|
||||
};
|
||||
|
||||
|
||||
|
||||
static uint16_t gap_callback(struct gap_event *event)
|
||||
{
|
||||
// AUTONAVI_LOG("gap_callback: type = %d\r\n", event->type);
|
||||
|
||||
switch(event->type) {
|
||||
case GATT_EVT_PROFILE_ADDED:
|
||||
{
|
||||
AUTONAVI_LOG("gap_callback: GATT_EVT_PROFILE_ADDED: 0x%02X\r\n", event->param.profile_added_status);
|
||||
|
||||
/* service profile has been added successfully, then the advertising can be started */
|
||||
app_ble_start_advertising();
|
||||
}
|
||||
break;
|
||||
|
||||
case GAP_EVT_ADV_SET_PARAM:
|
||||
AUTONAVI_LOG("adv param set: 0x%02X\r\n", event->param.adv_set_param.status);
|
||||
break;
|
||||
|
||||
case GAP_EVT_ADV_SET_ADV_DATA:
|
||||
AUTONAVI_LOG("adv data set: 0x%02X\r\n", event->param.adv_set_adv_data.status);
|
||||
break;
|
||||
|
||||
case GAP_EVT_ADV_SET_SCAN_RSP:
|
||||
AUTONAVI_LOG("adv scan rsp data set: 0x%02X\r\n", event->param.adv_set_scan_rsp.status);
|
||||
break;
|
||||
|
||||
case GAP_EVT_ADV_START:
|
||||
AUTONAVI_LOG("adv start :0x%02X\r\n", event->param.adv_start.status);
|
||||
break;
|
||||
|
||||
case GAP_EVT_ADV_END:
|
||||
AUTONAVI_LOG("adv end: 0x%02X\r\n", event->param.adv_end.status);
|
||||
break;
|
||||
|
||||
case GAP_EVT_SLAVE_CONNECT:
|
||||
{
|
||||
//gap_get_link_version(event->param.connect.conidx);
|
||||
//gap_get_link_rssi(event->param.connect.conidx);
|
||||
//gap_get_link_features(event->param.connect.conidx);
|
||||
AUTONAVI_LOG("slave connect[%d], connect num: %d\r\n", event->param.connect.conidx, gap_get_connect_num());
|
||||
//gatt_mtu_exchange_req(service_id, event->param.connect.conidx, 23);
|
||||
gatt_mtu_exchange_req(service_id, event->param.connect.conidx, 247);
|
||||
autonavi_msg_clear();
|
||||
}
|
||||
break;
|
||||
|
||||
case GAP_EVT_DISCONNECT:
|
||||
{
|
||||
AUTONAVI_LOG("gap_callback: GAP_EVT_DISCONNECT, conidx:%d, reason:0x%02X\r\n", event->param.disconnect.conidx,
|
||||
event->param.disconnect.reason);
|
||||
gap_adv_start(adv, 0, 0);
|
||||
}
|
||||
break;
|
||||
|
||||
case GATT_EVT_MTU:
|
||||
AUTONAVI_LOG("gap_callback: conidx: %d, GATT_EVT_MTU: %d\r\n", event->param.mtu_ind.conidx, event->param.mtu_ind.mtu);
|
||||
break;
|
||||
|
||||
case GAP_EVT_NAME_REQ:
|
||||
{
|
||||
gap_name_req_rsp(event->param.name_req.conidx,
|
||||
event->param.name_req.token,
|
||||
sizeof(local_device_name),
|
||||
(uint8_t *)local_device_name);
|
||||
}
|
||||
break;
|
||||
|
||||
case GAP_EVT_APPEARANCE_REQ:
|
||||
{
|
||||
gap_appearance_req_rsp(event->param.appearance_req.conidx,
|
||||
event->param.appearance_req.token,
|
||||
GAP_APPEARE_UNKNOWN);
|
||||
}
|
||||
break;
|
||||
|
||||
case GAP_EVT_LINK_PARAM_REQ:
|
||||
{
|
||||
struct gap_link_param_update_rsp rsp;
|
||||
rsp.accept = true;
|
||||
rsp.conidx = event->param.link_param_update_req.conidx;
|
||||
rsp.ce_len_max = 2;
|
||||
rsp.ce_len_min = 2;
|
||||
gap_param_update_rsp(&rsp);
|
||||
}
|
||||
break;
|
||||
|
||||
case GAP_EVT_LINK_PARAM_UPDATE:
|
||||
{
|
||||
AUTONAVI_LOG("conn param update,conidx:%d, con_int:%d, latency:%d, timeout%d\r\n", event->param.link_param_update.conidx,
|
||||
event->param.link_param_update.con_interval,
|
||||
event->param.link_param_update.con_latency,
|
||||
event->param.link_param_update.sup_to);
|
||||
}
|
||||
break;
|
||||
|
||||
case GAP_EVT_LINK_RSSI:
|
||||
AUTONAVI_LOG("gap_callback: conidx: %d, GAP_EVT_LINK_RSSI: %d\r\n", event->param.gap_link_rssi.conidx, event->param.gap_link_rssi.link_rssi);
|
||||
break;
|
||||
|
||||
case GAP_EVT_PHY_IND:
|
||||
AUTONAVI_LOG("gap_callback: conidx: %d, GAP_EVT_PHY_IND: %d\r\n", event->param.gap_phy_ind.conidx, event->param.gap_phy_ind.tx_phy);
|
||||
break;
|
||||
|
||||
case GAP_EVT_PHY_REJECT:
|
||||
AUTONAVI_LOG("gap_callback: conidx: %d, GAP_EVT_PHY_REJECT, status: %d\r\n", event->param.gap_phy_update_reject.conidx, event->param.gap_phy_update_reject.status);
|
||||
break;
|
||||
|
||||
case GAP_EVT_LINK_VER:
|
||||
AUTONAVI_LOG("gap_callback: conidx: %d, GAP_EVT_LINK_VER\r\n", event->param.gap_link_ver.conidx);
|
||||
break;
|
||||
|
||||
case GAP_EVT_LINK_FEATURE:
|
||||
AUTONAVI_LOG("gap_callback: conidx: %d, GAP_EVT_LINK_FEATURE:%d\r\n", event->param.gap_link_feature.conidx, event->param.gap_link_feature.features[0]);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static uint16_t gatt_callback(struct gatt_msg *p_msg)
|
||||
{
|
||||
uint8_t uuid_temp[16];
|
||||
conn_svc_idx = p_msg->conn_idx;
|
||||
switch(p_msg->msg_evt) {
|
||||
case GATTC_MSG_CMP_EVT:
|
||||
{
|
||||
switch(p_msg->param.gatt_op_cmp.operation) {
|
||||
case GATT_OP_NOTIFY:
|
||||
/*opearation of notification is complete */
|
||||
AUTONAVI_LOG("notify cmp, conidx:%d, status:0x%02X\r\n", p_msg->conn_idx, p_msg->param.gatt_op_cmp.status);
|
||||
break;
|
||||
|
||||
default:
|
||||
AUTONAVI_LOG("notify cmp, default\r\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
/* Received a read request from the peer device */
|
||||
case GATTS_MSG_READ_REQ:
|
||||
{
|
||||
AUTONAVI_LOG("GATTS_MSG_READ_REQ, conidx:%d, att idx:%d\r\n", p_msg->conn_idx, p_msg->att_idx);
|
||||
if(p_msg->att_idx == AUTONAVI_IDX_CHAR1_VALUE)
|
||||
{
|
||||
/*
|
||||
* Because the buffer pointer of SP_IDX_CHAR1_VALUE is NULL,
|
||||
* read requests will be report to the application layer for user response
|
||||
*/
|
||||
//uint8_t read_rsp_data[] = {0x00, 0x01, 0x02, 0x03, 0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15};
|
||||
//memcpy(p_msg->param.gatt_data.p_msg_data, read_rsp_data, sizeof(read_rsp_data));
|
||||
|
||||
/* Return the length of response data */
|
||||
return read_basic_attribute_service(p_msg->param.gatt_data.p_msg_data,AUTONAVI_CHAR1_VALUE_LEN);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
/* Received a write request from the peer device */
|
||||
case GATTS_MSG_WRITE_REQ:
|
||||
{
|
||||
AUTONAVI_LOG("GATTS_MSG_WRITE_REQ, conidx:%d, att idx:%d\r\n", p_msg->conn_idx, p_msg->att_idx);
|
||||
if(p_msg->att_idx == AUTONAVI_IDX_CHAR1_VALUE)
|
||||
{
|
||||
AUTONAVI_LOG("recv data: 0x");
|
||||
for(uint8_t i=0; i<p_msg->param.gatt_data.msg_len; i++)
|
||||
AUTONAVI_LOG("%02X", p_msg->param.gatt_data.p_msg_data[i]);
|
||||
AUTONAVI_LOG("\r\n");
|
||||
}
|
||||
else if(p_msg->att_idx == AUTONAVI_IDX_CHAR2_VALUE) //write data cmd
|
||||
{
|
||||
AUTONAVI_LOG("recv data: ");
|
||||
for(uint8_t i=0; i<p_msg->param.gatt_data.msg_len; i++)
|
||||
AUTONAVI_LOG("%02X ", p_msg->param.gatt_data.p_msg_data[i]);
|
||||
AUTONAVI_LOG(" \r\n");
|
||||
autonavi_data_recv(p_msg->param.gatt_data.p_msg_data,p_msg->param.gatt_data.msg_len);
|
||||
}
|
||||
else if(p_msg->att_idx == AUTONAVI_IDX_CHAR1_CFG) //config notify
|
||||
{
|
||||
uint8_t data[2];
|
||||
memcpy(data, p_msg->param.gatt_data.p_msg_data, 2);
|
||||
if(data[0] & 0x01)
|
||||
{
|
||||
|
||||
/* peer device enable notify */
|
||||
AUTONAVI_LOG("ntf enable, att_idx:%d\r\n", p_msg->att_idx);
|
||||
// uint8_t send_data[5] = {0x01, 0x02, 0x03, 0x04, 0x05};
|
||||
// struct gatt_send_event ntf;
|
||||
// ntf.conidx = p_msg->conn_idx;
|
||||
// ntf.att_idx = AUTONAVI_IDX_CHAR1_VALUE;
|
||||
// ntf.p_data = send_data;
|
||||
// ntf.data_len = sizeof(send_data);
|
||||
// ntf.svc_id = service_id;
|
||||
// /* Send a notification to the peer device */
|
||||
// gatt_notification(&ntf);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case GATTC_MSG_LINK_CREATE:
|
||||
AUTONAVI_LOG("gatt linkk create, conidx:%d\r\n", p_msg->conn_idx);
|
||||
break;
|
||||
|
||||
case GATTC_MSG_LINK_LOST:
|
||||
AUTONAVI_LOG("gatt linkk lost, conidx:%d\r\n", p_msg->conn_idx);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
void autonavi_send_notify(uint8_t *p_data,uint16_t len)
|
||||
{
|
||||
// if(user_ntf_enable_flag)
|
||||
{
|
||||
struct gatt_send_event ntf;
|
||||
ntf.conidx = conn_svc_idx;
|
||||
ntf.att_idx = AUTONAVI_IDX_CHAR1_VALUE;
|
||||
ntf.p_data = p_data;
|
||||
ntf.data_len = len;
|
||||
ntf.svc_id = service_id;
|
||||
/* Send a notification to the peer device */
|
||||
gatt_notification(&ntf);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
static void autonavi_ble_add_service(void)
|
||||
{
|
||||
struct gatt_service service;
|
||||
service.att_nb = AUTONAVI_IDX_NB;
|
||||
service.p_att_tb = simple_profile_att_table;
|
||||
service.gatt_msg_handler = gatt_callback; //set GATT event callback
|
||||
|
||||
service_id = gatt_add_service(&service);
|
||||
}
|
||||
|
||||
static void app_ble_start_advertising(void)
|
||||
{
|
||||
/* creat a handle of advertising*/
|
||||
adv = gap_adv_create();
|
||||
|
||||
gap_adv_param_t adv_param = {
|
||||
.own_addr_type = GAP_ADDR_TYPE_STATIC, //own address type
|
||||
.adv_mode = GAP_ADV_MODE_UNDIRECT,
|
||||
.disc_mode = GAP_ADV_DISC_MODE_GEN_DISC,
|
||||
.adv_chnl_map = GAP_ADV_CHAN_ALL,
|
||||
.filt_policy = GAP_ADV_FILTER_SCAN_ANY_CON_ANY, //Policy for filtering scanning or connection requests from peer devices
|
||||
.phy_mode = GAP_PHY_TYPE_LE_1M,
|
||||
.adv_intv_min = 160, //advertising min interval, in unit of 0.625ms
|
||||
.adv_intv_max = 160, //advertising max interval, in unit of 0.625ms
|
||||
};
|
||||
|
||||
/* set advertising param */
|
||||
gap_adv_set_param(adv, &adv_param);
|
||||
/* set advertising data */
|
||||
gap_adv_set_adv_data(adv, adv_data, sizeof(adv_data));
|
||||
/* set advertising scan response data */
|
||||
gap_adv_set_scan_rsp(adv, adv_scan_rsp_data, sizeof(adv_scan_rsp_data));
|
||||
/* start sadvertising */
|
||||
gap_adv_start(adv, 0, 0);
|
||||
}
|
||||
|
||||
void autonavi_ble_init(void)
|
||||
{
|
||||
AUTONAVI_LOG("app_ble_init\r\n");
|
||||
|
||||
/* set GAP event callback*/
|
||||
gap_set_cb_func(gap_callback);
|
||||
|
||||
/* set security param */
|
||||
struct gap_security_param smp_param;
|
||||
smp_param.mitm = true;
|
||||
smp_param.secure_connection = false;
|
||||
smp_param.bond = true;
|
||||
smp_param.rsp_mode = ENABLE_AUTO_RSP;
|
||||
smp_param.oob_used = GAP_OOB_AUTH_DATA_NOT_PRESENT;
|
||||
smp_param.io_cap = GAP_IO_CAP_NO_INPUT_NO_OUTPUT;
|
||||
|
||||
gap_security_param_init(&smp_param);
|
||||
|
||||
/* add service profile, The GAP callback event is GATT_EVT_PROFILE_ADDED*/
|
||||
autonavi_ble_add_service();
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,40 @@
|
||||
#ifndef __AUTONAVI_PROFILE_H__
|
||||
#define __AUTONAVI_PROFILE_H__
|
||||
|
||||
/*
|
||||
* INCLUDES (包含头文件)
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "gap_api.h"
|
||||
#include "gatt_api.h"
|
||||
#include "gatt_sig_uuid.h"
|
||||
|
||||
#define SP_AUTONAVI_UUID {0x02,0x00,0x12, 0xac,0x42,0x02,0x56,0xbe,0xed,0x11,0xd6,0xfd,0x76,0x12,0x75,0x61}
|
||||
#define SP_AUTONAVI_CHAR2_UUID {0x02,0x00,0x12, 0xac,0x42,0x02,0x56,0xbe,0xed,0x11,0xda,0xfd,0xe2,0x30,0xea,0x99}
|
||||
#define SP_AUTONAVI_CHAR1_UUID {0x02,0x00,0x12, 0xac,0x42,0x02,0x56,0xbe,0xed,0x11,0xc4,0xfb,0xea,0x84,0xe4,0x7e}
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
AUTONAVI_IDX_SERVICE,
|
||||
|
||||
AUTONAVI_IDX_CHAR1_DECLARATION,
|
||||
AUTONAVI_IDX_CHAR1_VALUE,
|
||||
AUTONAVI_IDX_CHAR1_CFG,
|
||||
// SP_IDX_CHAR1_USER_DESCRIPTION,
|
||||
|
||||
AUTONAVI_IDX_CHAR2_DECLARATION,
|
||||
AUTONAVI_IDX_CHAR2_VALUE,
|
||||
AUTONAVI_IDX_NB,
|
||||
};
|
||||
|
||||
/*
|
||||
* MACROS (宏定义)
|
||||
*/
|
||||
|
||||
|
||||
void autonavi_ble_init(void);
|
||||
void autonavi_send_notify(uint8_t *p_data,uint16_t len);
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user