fix:修改UDP通讯中,取电变化上报机制
1、问题点:当RCU网络状态异常的情况下,网络还处于协商状态下,还未进入正常通讯环节时,取电变化不会进行判断。这会导致取电变化上报与实际产生取电状态时间点对不上。 2、将BLV_C1F_Module代码上传至Gitea,之前代码修改记录请查看 .\BasicCode\Readme.txt
This commit is contained in:
219
BasicCode/Drive/BLE/HAL/KEY.c
Normal file
219
BasicCode/Drive/BLE/HAL/KEY.c
Normal file
@@ -0,0 +1,219 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : KEY.c
|
||||
* Author : WCH
|
||||
* Version : V1.0
|
||||
* Date : 2014/05/12
|
||||
* Description :
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
/* ͷ<>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD> */
|
||||
#include "CH57x_common.h"
|
||||
#include "HAL.h"
|
||||
|
||||
|
||||
/**************************************************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
**************************************************************************************************/
|
||||
|
||||
uint8 Hal_KeyIntEnable; /* interrupt enable/disable flag */
|
||||
|
||||
// Registered keys task ID, initialized to NOT USED.
|
||||
static uint8 registeredKeysTaskID = TASK_NO_TASK;
|
||||
static uint8 halKeySavedKeys; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD>ѯ<EFBFBD>Ƿ<EFBFBD><C7B7>м<EFBFBD>ֵ<EFBFBD>仯 */
|
||||
static uint8 KeyConfigFlag; /* <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ñ<EFBFBD>־λ */
|
||||
|
||||
|
||||
/**************************************************************************************************
|
||||
* FUNCTIONS - Local
|
||||
**************************************************************************************************/
|
||||
static halKeyCBack_t pHalKeyProcessFunction; /* callback function */
|
||||
|
||||
|
||||
/**************************************************************************************************
|
||||
* @fn HAL_KeyInit
|
||||
*
|
||||
* @brief Initilize Key Service
|
||||
*
|
||||
* @param none
|
||||
*
|
||||
* @return None
|
||||
**************************************************************************************************/
|
||||
void HAL_KeyInit( void )
|
||||
{
|
||||
/* Initialize previous key to 0 */
|
||||
halKeySavedKeys = 0;
|
||||
/* Initialize callback function */
|
||||
pHalKeyProcessFunction = NULL;
|
||||
/* Start with key is not configured */
|
||||
KeyConfigFlag = FALSE;
|
||||
KEY1_DIR; //IO<49><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
KEY1_PU; //<2F><><EFBFBD><EFBFBD>
|
||||
HalKeyConfig( HAL_KEY_INTERRUPT_DISABLE, HalKeyCallback );
|
||||
}
|
||||
|
||||
void HAL_KEY_RegisterForKeys( tmosTaskID id )
|
||||
{
|
||||
registeredKeysTaskID = id;
|
||||
}
|
||||
|
||||
/**************************************************************************************************
|
||||
* @fn HalKeyConfig
|
||||
*
|
||||
* @brief Configure the Key serivce
|
||||
*
|
||||
* @param interruptEnable - TRUE/FALSE, enable/disable interrupt
|
||||
* cback - pointer to the CallBack function
|
||||
*
|
||||
* @return None
|
||||
**************************************************************************************************/
|
||||
void HalKeyConfig (uint8 interruptEnable, halKeyCBack_t cback)
|
||||
{
|
||||
/* Enable/Disable Interrupt or */
|
||||
Hal_KeyIntEnable = interruptEnable;
|
||||
/* Register the callback fucntion */
|
||||
pHalKeyProcessFunction = cback;
|
||||
/* Determine if interrupt is enable or not */
|
||||
if (Hal_KeyIntEnable){
|
||||
/* Do this only after the hal_key is configured - to work with sleep stuff */
|
||||
if (KeyConfigFlag == TRUE){
|
||||
tmos_stop_task( halTaskID, HAL_KEY_EVENT ); /* Cancel polling if active */
|
||||
}
|
||||
}
|
||||
else{ /* Interrupts NOT enabled */
|
||||
tmos_start_task( halTaskID, HAL_KEY_EVENT, HAL_KEY_POLLING_VALUE); /* Kick off polling <20><>ʼ<EFBFBD><CABC>ѵ*/
|
||||
}
|
||||
/* Key now is configured */
|
||||
KeyConfigFlag = TRUE;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn OnBoard_SendKeys
|
||||
*
|
||||
* @brief Send "Key Pressed" message to application.
|
||||
* <09><>Ӧ<EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͡<EFBFBD><CDA1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>
|
||||
* @param keys - keys that were pressed
|
||||
* state - shifted
|
||||
*
|
||||
* @return status
|
||||
*********************************************************************/
|
||||
uint8 OnBoard_SendKeys( uint8 keys, uint8 state )
|
||||
{
|
||||
keyChange_t *msgPtr;
|
||||
|
||||
if ( registeredKeysTaskID != TASK_NO_TASK ){
|
||||
// Send the address to the task
|
||||
msgPtr = (keyChange_t *)tmos_msg_allocate( sizeof(keyChange_t) );
|
||||
if ( msgPtr ){
|
||||
msgPtr->hdr.event = KEY_CHANGE;
|
||||
msgPtr->state = state;
|
||||
msgPtr->keys = keys;
|
||||
tmos_msg_send( registeredKeysTaskID, (uint8 *)msgPtr );
|
||||
}
|
||||
return ( SUCCESS );
|
||||
}
|
||||
else{
|
||||
return ( FAILURE );
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn OnBoard_KeyCallback
|
||||
*
|
||||
* @brief Callback service for keys
|
||||
*
|
||||
* @param keys - keys that were pressed
|
||||
* state - shifted
|
||||
*
|
||||
* @return void
|
||||
*********************************************************************/
|
||||
void HalKeyCallback ( uint8 keys, uint8 state )
|
||||
{
|
||||
(void)state;
|
||||
if ( OnBoard_SendKeys( keys, state ) != SUCCESS ){
|
||||
// Process SW1 here
|
||||
if ( keys & HAL_KEY_SW_1 ){ // Switch 1
|
||||
}
|
||||
// Process SW2 here
|
||||
if ( keys & HAL_KEY_SW_2 ){ // Switch 2
|
||||
}
|
||||
// Process SW3 here
|
||||
if ( keys & HAL_KEY_SW_3 ){ // Switch 3
|
||||
}
|
||||
// Process SW4 here
|
||||
if ( keys & HAL_KEY_SW_4 ){ // Switch 4
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************************************
|
||||
* @fn HalKeyRead
|
||||
*
|
||||
* @brief Read the current value of a key
|
||||
*
|
||||
* @param None
|
||||
*
|
||||
* @return keys - current keys status
|
||||
**************************************************************************************************/
|
||||
uint8 HalKeyRead ( void )
|
||||
{
|
||||
uint8 keys = 0;
|
||||
|
||||
if (HAL_PUSH_BUTTON1()){ //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1
|
||||
keys |= HAL_KEY_SW_1;
|
||||
}
|
||||
if (HAL_PUSH_BUTTON2()){ //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1
|
||||
keys |= HAL_KEY_SW_2;
|
||||
}
|
||||
if (HAL_PUSH_BUTTON3()){ //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1
|
||||
keys |= HAL_KEY_SW_3;
|
||||
}
|
||||
if (HAL_PUSH_BUTTON4()){ //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1
|
||||
keys |= HAL_KEY_SW_4;
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************************************
|
||||
* @fn HAL_KeyPoll
|
||||
*
|
||||
* @brief Called by hal_driver to poll the keys
|
||||
*
|
||||
* @param None
|
||||
*
|
||||
* @return None
|
||||
**************************************************************************************************/
|
||||
void HAL_KeyPoll (void)
|
||||
{
|
||||
uint8 keys = 0;
|
||||
|
||||
if( HAL_PUSH_BUTTON1() ){
|
||||
keys |= HAL_KEY_SW_1;
|
||||
}
|
||||
if( HAL_PUSH_BUTTON2() ){
|
||||
keys |= HAL_KEY_SW_2;
|
||||
}
|
||||
if( HAL_PUSH_BUTTON3() ){
|
||||
keys |= HAL_KEY_SW_3;
|
||||
}
|
||||
if( HAL_PUSH_BUTTON4() ){
|
||||
keys |= HAL_KEY_SW_4;
|
||||
}
|
||||
if (!Hal_KeyIntEnable){ /* <20>ж<EFBFBD>δʹ<CEB4><CAB9> */
|
||||
if(keys == halKeySavedKeys){ /* Exit - since no keys have changed */
|
||||
return;
|
||||
}
|
||||
halKeySavedKeys = keys; /* Store the current keys for comparation next time */
|
||||
}
|
||||
/* Invoke Callback if new keys were depressed */
|
||||
if (keys && (pHalKeyProcessFunction)){
|
||||
(pHalKeyProcessFunction) (keys, HAL_KEY_STATE_NORMAL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/******************************** endfile @ key ******************************/
|
||||
316
BasicCode/Drive/BLE/HAL/LED.c
Normal file
316
BasicCode/Drive/BLE/HAL/LED.c
Normal file
@@ -0,0 +1,316 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : LED.c
|
||||
* Author : WCH
|
||||
* Version : V1.0
|
||||
* Date : 2014/05/12
|
||||
* Description :
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
/* ͷ<>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD> */
|
||||
#include "CH57x_common.h"
|
||||
#include "HAL.h"
|
||||
|
||||
|
||||
|
||||
/* LED control structure */
|
||||
typedef struct {
|
||||
uint8 mode; /* Operation mode */
|
||||
uint8 todo; /* Blink cycles left */
|
||||
uint8 onPct; /* On cycle percentage */
|
||||
uint16 time; /* On/off cycle time (msec) */
|
||||
uint32 next; /* Time for next change */
|
||||
} HalLedControl_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
HalLedControl_t HalLedControlTable[HAL_LED_DEFAULT_MAX_LEDS];
|
||||
uint8 sleepActive;
|
||||
} HalLedStatus_t;
|
||||
|
||||
/***************************************************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
***************************************************************************************************/
|
||||
static uint8 HalLedState; // LED state at last set/clr/blink update
|
||||
|
||||
static uint8 preBlinkState; // Original State before going to blink mode
|
||||
// bit 0, 1, 2, 3 represent led 0, 1, 2, 3
|
||||
static HalLedStatus_t HalLedStatusControl;
|
||||
|
||||
/***************************************************************************************************
|
||||
* LOCAL FUNCTION
|
||||
***************************************************************************************************/
|
||||
void HalLedOnOff (uint8 leds, uint8 mode);
|
||||
|
||||
/***************************************************************************************************
|
||||
* FUNCTIONS - API
|
||||
***************************************************************************************************/
|
||||
|
||||
/***************************************************************************************************
|
||||
* @fn : HAL_LedInit
|
||||
*
|
||||
* @brief : Initialize LED Service
|
||||
*
|
||||
* @param : None
|
||||
*
|
||||
* @return : None
|
||||
*/
|
||||
void HAL_LedInit (void)
|
||||
{
|
||||
/* Initialize all LEDs to OFF */
|
||||
LED1_DDR;
|
||||
HalLedSet(HAL_LED_ALL, HAL_LED_MODE_OFF);
|
||||
// just test
|
||||
HalLedBlink( HAL_LED_1, 10, 30 , 4000);
|
||||
/* Initialize sleepActive to FALSE */
|
||||
HalLedStatusControl.sleepActive = FALSE;
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
* @fn <20><>HalLedSet
|
||||
*
|
||||
* @brief <20><>Tun ON/OFF/TOGGLE given LEDs
|
||||
*
|
||||
* @param <20><>led - bit mask value of leds to be turned ON/OFF/TOGGLE
|
||||
* mode - BLINK, FLASH, TOGGLE, ON, OFF
|
||||
*
|
||||
* @return <20><>None
|
||||
*/
|
||||
uint8 HalLedSet (uint8 leds, uint8 mode)
|
||||
{
|
||||
uint8 led;
|
||||
HalLedControl_t *sts;
|
||||
|
||||
switch (mode){
|
||||
case HAL_LED_MODE_BLINK:
|
||||
/* Default blink, 1 time, D% duty cycle */
|
||||
HalLedBlink (leds, 1, HAL_LED_DEFAULT_DUTY_CYCLE, HAL_LED_DEFAULT_FLASH_TIME);
|
||||
break;
|
||||
|
||||
case HAL_LED_MODE_FLASH:
|
||||
/* Default flash, N times, D% duty cycle */
|
||||
HalLedBlink (leds, HAL_LED_DEFAULT_FLASH_COUNT, HAL_LED_DEFAULT_DUTY_CYCLE, HAL_LED_DEFAULT_FLASH_TIME);
|
||||
break;
|
||||
|
||||
case HAL_LED_MODE_ON:
|
||||
case HAL_LED_MODE_OFF:
|
||||
case HAL_LED_MODE_TOGGLE:
|
||||
led = HAL_LED_1;
|
||||
leds &= HAL_LED_ALL;
|
||||
sts = HalLedStatusControl.HalLedControlTable;
|
||||
while (leds){
|
||||
if (leds & led){
|
||||
if (mode != HAL_LED_MODE_TOGGLE){
|
||||
sts->mode = mode; /* ON or OFF */
|
||||
}
|
||||
else{
|
||||
sts->mode ^= HAL_LED_MODE_ON; /* Toggle */
|
||||
}
|
||||
HalLedOnOff (led, sts->mode);
|
||||
leds ^= led;
|
||||
}
|
||||
led <<= 1;
|
||||
sts++;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ( NULL );
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
* @fn : HalLedBlink
|
||||
*
|
||||
* @brief : Blink the leds
|
||||
*
|
||||
* @param : leds - bit mask value of leds to be blinked
|
||||
* numBlinks - number of blinks
|
||||
* percent - the percentage in each period where the led will be on
|
||||
* period - length of each cycle in milliseconds
|
||||
*
|
||||
* @return : None
|
||||
*/
|
||||
void HalLedBlink (uint8 leds, uint8 numBlinks, uint8 percent, uint16 period)
|
||||
{
|
||||
uint8 led;
|
||||
HalLedControl_t *sts;
|
||||
|
||||
if (leds && percent && period){
|
||||
if (percent < 100){
|
||||
led = HAL_LED_1;
|
||||
leds &= HAL_LED_ALL;
|
||||
sts = HalLedStatusControl.HalLedControlTable;
|
||||
while (leds){
|
||||
if (leds & led){
|
||||
/* Store the current state of the led before going to blinking */
|
||||
preBlinkState |= (led & HalLedState);
|
||||
sts->mode = HAL_LED_MODE_OFF; /* Stop previous blink */
|
||||
sts->time = period; /* Time for one on/off cycle */
|
||||
sts->onPct = percent; /* % of cycle LED is on */
|
||||
sts->todo = numBlinks; /* Number of blink cycles */
|
||||
if (!numBlinks) sts->mode |= HAL_LED_MODE_FLASH; /* Continuous */
|
||||
sts->next = TMOS_GetSystemClock(); /* Start now */
|
||||
sts->mode |= HAL_LED_MODE_BLINK; /* Enable blinking */
|
||||
leds ^= led;
|
||||
}
|
||||
led <<= 1;
|
||||
sts++;
|
||||
}
|
||||
tmos_start_task( halTaskID, LED_BLINK_EVENT, NULL);
|
||||
}
|
||||
else{
|
||||
HalLedSet (leds, HAL_LED_MODE_ON); /* >= 100%, turn on */
|
||||
}
|
||||
}
|
||||
else{
|
||||
HalLedSet (leds, HAL_LED_MODE_OFF); /* No on time, turn off */
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
* @fn : HalLedUpdate
|
||||
*
|
||||
* @brief : Update leds to work with blink
|
||||
*
|
||||
* @param : none
|
||||
*
|
||||
* @return : none
|
||||
*/
|
||||
void HalLedUpdate (void)
|
||||
{
|
||||
uint8 led,pct,leds;
|
||||
uint16 next,wait;
|
||||
uint32 time;
|
||||
HalLedControl_t *sts;
|
||||
|
||||
next = 0;
|
||||
led = HAL_LED_1;
|
||||
leds = HAL_LED_ALL;
|
||||
sts = HalLedStatusControl.HalLedControlTable;
|
||||
|
||||
/* Check if sleep is active or not */
|
||||
if (!HalLedStatusControl.sleepActive){
|
||||
while (leds){
|
||||
if (leds & led){
|
||||
if(sts->mode & HAL_LED_MODE_BLINK){
|
||||
time = TMOS_GetSystemClock();
|
||||
if (time >= sts->next){
|
||||
if (sts->mode & HAL_LED_MODE_ON){
|
||||
pct = 100 - sts->onPct; /* Percentage of cycle for off */
|
||||
sts->mode &= ~HAL_LED_MODE_ON; /* Say it's not on */
|
||||
HalLedOnOff (led, HAL_LED_MODE_OFF); /* Turn it off */
|
||||
if (!(sts->mode & HAL_LED_MODE_FLASH)){
|
||||
if( sts->todo != 0xff ) sts->todo--; /* Not continuous, reduce count */
|
||||
if (!sts->todo){
|
||||
sts->mode ^= HAL_LED_MODE_BLINK; /* No more blinks */
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
pct = sts->onPct; /* Percentage of cycle for on */
|
||||
sts->mode |= HAL_LED_MODE_ON; /* Say it's on */
|
||||
HalLedOnOff(led, HAL_LED_MODE_ON); /* Turn it on */
|
||||
}
|
||||
if (sts->mode & HAL_LED_MODE_BLINK){
|
||||
wait = (((uint32)pct * (uint32)sts->time) / 100);
|
||||
sts->next = time + wait;
|
||||
}
|
||||
else{
|
||||
/* no more blink, no more wait */
|
||||
wait = 0;
|
||||
/* After blinking, set the LED back to the state before it blinks */
|
||||
HalLedSet (led, ((preBlinkState & led)!=0)?HAL_LED_MODE_ON:HAL_LED_MODE_OFF);
|
||||
/* Clear the saved bit */
|
||||
preBlinkState &= (led ^ 0xFF);
|
||||
}
|
||||
}
|
||||
else{
|
||||
wait = sts->next - time; /* Time left */
|
||||
}
|
||||
if (!next || ( wait && (wait < next) )){
|
||||
next = wait;
|
||||
}
|
||||
}
|
||||
leds ^= led;
|
||||
}
|
||||
led <<= 1;
|
||||
sts++;
|
||||
}
|
||||
if (next){
|
||||
tmos_start_task( halTaskID, LED_BLINK_EVENT, next); /* Schedule event */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
* @fn : HalLedOnOff
|
||||
*
|
||||
* @brief : Turns specified LED ON or OFF
|
||||
*
|
||||
* @param : leds - LED bit mask
|
||||
* mode - LED_ON,LED_OFF,
|
||||
*
|
||||
* @return : none
|
||||
*/
|
||||
void HalLedOnOff (uint8 leds, uint8 mode)
|
||||
{
|
||||
if (leds & HAL_LED_1){
|
||||
if (mode == HAL_LED_MODE_ON){
|
||||
HAL_TURN_ON_LED1();
|
||||
}
|
||||
else{
|
||||
HAL_TURN_OFF_LED1();
|
||||
}
|
||||
}
|
||||
if (leds & HAL_LED_2){
|
||||
if (mode == HAL_LED_MODE_ON){
|
||||
HAL_TURN_ON_LED2();
|
||||
}
|
||||
else{
|
||||
HAL_TURN_OFF_LED2();
|
||||
}
|
||||
}
|
||||
if (leds & HAL_LED_3){
|
||||
if (mode == HAL_LED_MODE_ON){
|
||||
HAL_TURN_ON_LED3();
|
||||
}
|
||||
else{
|
||||
HAL_TURN_OFF_LED3();
|
||||
}
|
||||
}
|
||||
if (leds & HAL_LED_4){
|
||||
if (mode == HAL_LED_MODE_ON){
|
||||
HAL_TURN_ON_LED4();
|
||||
}
|
||||
else{
|
||||
HAL_TURN_OFF_LED4();
|
||||
}
|
||||
}
|
||||
/* Remember current state */
|
||||
if (mode){
|
||||
HalLedState |= leds;
|
||||
}
|
||||
else{
|
||||
HalLedState &= (leds ^ 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************************************************
|
||||
* @fn HalGetLedState
|
||||
*
|
||||
* @brief Dim LED2 - Dim (set level) of LED2
|
||||
*
|
||||
* @param none
|
||||
*
|
||||
* @return led state
|
||||
***************************************************************************************************/
|
||||
uint8 HalLedGetState ()
|
||||
{
|
||||
return HalLedState;
|
||||
}
|
||||
|
||||
/******************************** endfile @ led ******************************/
|
||||
273
BasicCode/Drive/BLE/HAL/MCU.c
Normal file
273
BasicCode/Drive/BLE/HAL/MCU.c
Normal file
@@ -0,0 +1,273 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : MCU.c
|
||||
* Author : WCH
|
||||
* Version : V1.1
|
||||
* Date : 2019/11/05
|
||||
* Description : Ӳ<><D3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>BLE<4C><45>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
||||
*******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* ͷ<>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD> */
|
||||
#include "CH57x_common.h"
|
||||
#include "HAL.h"
|
||||
|
||||
tmosTaskID halTaskID;
|
||||
|
||||
#if BLE_CODE_EN
|
||||
__align(4) u32 MEM_BUF[BLE_MEMHEAP_SIZE/4]; //<2F><><EFBFBD><EFBFBD>Э<EFBFBD><D0AD>ջ<EFBFBD><D5BB>Ҫ<EFBFBD><D2AA><EFBFBD>ڴ<EFBFBD>
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn Lib_Calibration_LSI
|
||||
*
|
||||
* @brief <20>ڲ<EFBFBD>32kУ
|
||||
*
|
||||
* input parameters
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* output parameters
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void Lib_Calibration_LSI( void )
|
||||
{
|
||||
if( Calibration_LSI() > 2 )
|
||||
{
|
||||
Calibration_LSI();
|
||||
}
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn CH57X_BLEInit
|
||||
*
|
||||
* @brief BLE <20><><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
||||
*
|
||||
* input parameters
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* output parameters
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
#if BLE_CODE_EN
|
||||
|
||||
void CH57X_BLEInit( void )
|
||||
{
|
||||
uint8 i;
|
||||
bleConfig_t cfg;
|
||||
|
||||
if( tmos_memcmp( VER_LIB,VER_FILE,strlen(VER_FILE)) == FALSE ){
|
||||
PRINT("head file error...\n");
|
||||
while(1);
|
||||
}
|
||||
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1; //д<><D0B4>0x57
|
||||
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2; //<2F><>д<EFBFBD><D0B4>0xA8<41><38><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ16<31><36><EFBFBD><EFBFBD><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>밲ȫ<EBB0B2><C8AB><EFBFBD><EFBFBD>ģʽ
|
||||
R16_CLK_SYS_CFG = RB_CLK_OSC32M_XT|(2<<6)|0x08; // 32M -> Fsys <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳʱ<CDB3>ӣ<EFBFBD><D3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>32M<32><4D>Ϊϵͳ<CFB5><CDB3>Ƶ<EFBFBD><C6B5>
|
||||
R8_SAFE_ACCESS_SIG = 0; //<2F>˳<EFBFBD><CBB3><EFBFBD>ȫģʽ
|
||||
// SysTick_Config( SysTick_LOAD_RELOAD_Msk ); //<2F><><EFBFBD>õδ<C3B5><CEB4><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
// SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk ; /* disable SysTick IRQ */
|
||||
tmos_memset(&cfg,0,sizeof(bleConfig_t));
|
||||
cfg.MEMAddr = (u32)MEM_BUF;
|
||||
cfg.MEMLen = (u32)BLE_MEMHEAP_SIZE; //<2F><><EFBFBD><EFBFBD>Э<EFBFBD><D0AD>ջʹ<D5BB>õ<EFBFBD>RAM<41><4D>С<EFBFBD><D0A1><EFBFBD><EFBFBD>С<EFBFBD><D0A1>6K
|
||||
cfg.BufMaxLen = (u32)BLE_BUFF_MAX_LEN; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
cfg.BufNumber = (u32)BLE_BUFF_NUM; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>İ<EFBFBD><C4B0><EFBFBD><EFBFBD><EFBFBD>
|
||||
cfg.TxNumEvent = (u32)BLE_TX_NUM_EVENT; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Է<EFBFBD><D4B7><EFBFBD><EFBFBD>ٸ<EFBFBD><D9B8><EFBFBD><EFBFBD>ݰ<EFBFBD>
|
||||
cfg.TxPower = (u32)BLE_TX_POWER; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>书<EFBFBD><E4B9A6>
|
||||
#if (defined (BLE_SNV)) && (BLE_SNV == TRUE)
|
||||
cfg.SNVAddr = (u32)BLE_SNV_ADDR;
|
||||
#endif
|
||||
#if( CLK_OSC32K )
|
||||
cfg.SelRTCClock = (u32)CLK_OSC32K;
|
||||
#endif
|
||||
cfg.ConnectNumber = (PERIPHERAL_MAX_CONNECTION&3)|(CENTRAL_MAX_CONNECTION<<2); //
|
||||
cfg.srandCB = SYS_GetSysTickCnt; //ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵij<D3B5><C4B3><EFBFBD>
|
||||
#if (defined TEM_SAMPLE) && (TEM_SAMPLE == TRUE)
|
||||
cfg.tsCB = HAL_GetInterTempValue; // <20><><EFBFBD><EFBFBD><EFBFBD>¶ȱ仯УRF<52><46><EFBFBD>ڲ<EFBFBD>RC( <20><><EFBFBD><EFBFBD>7<EFBFBD><37><EFBFBD>϶<EFBFBD> )
|
||||
#if( CLK_OSC32K )
|
||||
cfg.rcCB = Lib_Calibration_LSI; // <20>ڲ<EFBFBD>32Kʱ<4B><CAB1>У
|
||||
#endif
|
||||
#endif
|
||||
#if (defined (HAL_SLEEP)) && (HAL_SLEEP == TRUE)
|
||||
cfg.WakeUpTime = WAKE_UP_RTC_MAX_TIME;
|
||||
cfg.sleepCB = CH57X_LowPower; // <20><><EFBFBD><EFBFBD>˯<EFBFBD><CBAF>
|
||||
#endif
|
||||
#if (defined (BLE_MAC)) && (BLE_MAC == TRUE)
|
||||
for(i=0;i<6;i++) cfg.MacAddr[i] = MACAddr[5-i]; //MAC<41><43>ַ
|
||||
#endif
|
||||
if( !cfg.MEMAddr || cfg.MEMLen < 4*1024 )while(1);
|
||||
#if (defined HAL_SLEEP) && (HAL_SLEEP == TRUE)
|
||||
if( (u32)MEM_BUF < (u32)0x20003800 ){
|
||||
PRINT("RAM config error...\n");
|
||||
PRINT("MEM_BUF<EFBFBD><EFBFBD>%p\n", MEM_BUF);
|
||||
PRINT("BLE_MEMHEAP_SIZE<EFBFBD><EFBFBD>%d\n", BLE_MEMHEAP_SIZE);
|
||||
|
||||
while(1);
|
||||
}
|
||||
#endif
|
||||
i = BLE_LibInit( &cfg );
|
||||
if(i){
|
||||
PRINT("LIB init error code: %x ...\n",i);
|
||||
while(1);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn HAL_ProcessEvent
|
||||
*
|
||||
* @brief Ӳ<><D3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*
|
||||
* input parameters
|
||||
*
|
||||
* @param task_id.
|
||||
* @param events.
|
||||
*
|
||||
* output parameters
|
||||
*
|
||||
* @param events.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
tmosEvents HAL_ProcessEvent( tmosTaskID task_id, tmosEvents events )
|
||||
{
|
||||
uint8 * msgPtr;
|
||||
|
||||
if( events & SYS_EVENT_MSG ){ // <20><><EFBFBD><EFBFBD>HAL<41><4C><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>tmos_msg_receive<76><65>ȡ<EFBFBD><C8A1>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɺ<EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>
|
||||
msgPtr = tmos_msg_receive(task_id); //receive a msg
|
||||
if( msgPtr ){
|
||||
/* De-allocate */
|
||||
tmos_msg_deallocate( msgPtr ); //delete a msg
|
||||
}
|
||||
return events ^ SYS_EVENT_MSG;
|
||||
}
|
||||
if ( events & LED_BLINK_EVENT ){
|
||||
#if (defined HAL_LED) && (HAL_LED == TRUE)
|
||||
HalLedUpdate( );
|
||||
#endif // HAL_LED
|
||||
return events ^ LED_BLINK_EVENT;
|
||||
}
|
||||
if( events & HAL_KEY_EVENT ){
|
||||
#if (defined HAL_KEY) && (HAL_KEY == TRUE)
|
||||
HAL_KeyPoll(); /* Check for keys */
|
||||
if (!Hal_KeyIntEnable){
|
||||
tmos_start_task( halTaskID, HAL_KEY_EVENT, MS1_TO_SYSTEM_TIME(100) );
|
||||
}
|
||||
return events ^ HAL_KEY_EVENT;
|
||||
#endif
|
||||
}
|
||||
if( events & HAL_REG_INIT_EVENT ){
|
||||
#if (defined BLE_CALIBRATION_ENABLE) && (BLE_CALIBRATION_ENABLE == TRUE) // У<D0A3><D7BC><EFBFBD><EFBFBD><F1A3ACB5><EFBFBD>У<D0A3><D7BC>ʱС<CAB1><D0A1>10ms
|
||||
BLE_RegInit(); // УRF
|
||||
#if( CLK_OSC32K )
|
||||
Lib_Calibration_LSI(); // У<D0A3>ڲ<EFBFBD>RC
|
||||
#endif
|
||||
tmos_start_task( halTaskID , HAL_REG_INIT_EVENT ,MS1_TO_SYSTEM_TIME(BLE_CALIBRATION_PERIOD) );
|
||||
return events ^ HAL_REG_INIT_EVENT;
|
||||
#endif
|
||||
}
|
||||
if( events & HAL_TEST_EVENT ){
|
||||
PRINT("* ");
|
||||
tmos_start_task( halTaskID , HAL_TEST_EVENT ,MS1_TO_SYSTEM_TIME(10000) );
|
||||
return events ^ HAL_TEST_EVENT;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn HAL_Init
|
||||
*
|
||||
* @brief Ӳ<><D3B2><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
||||
*
|
||||
* input parameters
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* output parameters
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void HAL_Init( )
|
||||
{
|
||||
halTaskID = TMOS_ProcessEventRegister( HAL_ProcessEvent ); //ע<><D7A2>һ<EFBFBD><D2BB> TMOS <20>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ID
|
||||
HAL_TimeInit( );
|
||||
#if (defined HAL_SLEEP) && (HAL_SLEEP == TRUE)
|
||||
HAL_SleepInit( );
|
||||
#endif
|
||||
#if (defined HAL_LED) && (HAL_LED == TRUE)
|
||||
HAL_LedInit( );
|
||||
#endif
|
||||
#if (defined HAL_KEY) && (HAL_KEY == TRUE)
|
||||
HAL_KeyInit( );
|
||||
#endif
|
||||
__enable_irq();
|
||||
#if (defined BLE_CALIBRATION_ENABLE) && (BLE_CALIBRATION_ENABLE == TRUE)
|
||||
tmos_start_task( halTaskID , HAL_REG_INIT_EVENT ,MS1_TO_SYSTEM_TIME(BLE_CALIBRATION_PERIOD) ); // <20><><EFBFBD><EFBFBD>У<D0A3><D7BC><EFBFBD><EFBFBD><F1A3ACB5><EFBFBD>У<D0A3><D7BC>ʱС<CAB1><D0A1>10ms
|
||||
#endif
|
||||
// tmos_start_task( halTaskID , HAL_TEST_EVENT ,1000 ); // <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn LLE_IRQHandler
|
||||
*
|
||||
* @brief LLE interrupt function
|
||||
*
|
||||
* input parameters
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* output parameters
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void LLE_IRQHandler(void)
|
||||
{
|
||||
BLE_IRQHandler();
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn HAL_GetInterTempValue
|
||||
*
|
||||
* @brief None.
|
||||
*
|
||||
* input parameters
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* output parameters
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
uint16 HAL_GetInterTempValue( void )
|
||||
{
|
||||
uint8 sensor,channel,config;
|
||||
uint16 adc_data;
|
||||
|
||||
sensor = R8_TEM_SENSOR;
|
||||
channel = R8_ADC_CHANNEL;
|
||||
config = R8_ADC_CFG;
|
||||
R8_TEM_SENSOR |= RB_TEM_SEN_PWR_ON;
|
||||
R8_ADC_CHANNEL = CH_INTE_VTEMP;
|
||||
R8_ADC_CFG = RB_ADC_POWER_ON|( 2<<4 ) ;
|
||||
R8_ADC_CONVERT |= RB_ADC_START;
|
||||
while( R8_ADC_CONVERT & RB_ADC_START );
|
||||
adc_data = R16_ADC_DATA;
|
||||
R8_TEM_SENSOR = sensor;
|
||||
R8_ADC_CHANNEL = channel;
|
||||
R8_ADC_CFG = config;
|
||||
return( adc_data );
|
||||
}
|
||||
|
||||
/******************************** endfile @ mcu ******************************/
|
||||
92
BasicCode/Drive/BLE/HAL/RTC.c
Normal file
92
BasicCode/Drive/BLE/HAL/RTC.c
Normal file
@@ -0,0 +1,92 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : RTC.c
|
||||
* Author : WCH
|
||||
* Version : V1.1
|
||||
* Date : 2019/11/05
|
||||
* Description : RTC<54><43><EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
||||
*******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* ͷ<>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD> */
|
||||
#include "CH57x_common.h"
|
||||
#include "HAL.h"
|
||||
|
||||
/*********************************************************************
|
||||
* CONSTANTS
|
||||
*/
|
||||
#define RTC_INIT_TIME_HOUR 0
|
||||
#define RTC_INIT_TIME_MINUTE 0
|
||||
#define RTC_INIT_TIME_SECEND 0
|
||||
|
||||
/***************************************************
|
||||
* Global variables
|
||||
*/
|
||||
u32V RTCTigFlag;
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : RTC_SetTignTime
|
||||
* Description : <20><><EFBFBD><EFBFBD>RTC<54><43><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
* Input :
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
void RTC_SetTignTime( u32 time )
|
||||
{
|
||||
if( time&0xffff ) time += (1<<16);
|
||||
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
|
||||
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
|
||||
R32_RTC_TRIG = time;
|
||||
RTCTigFlag = 0;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn RTC_IRQHandler
|
||||
*
|
||||
* @brief RTC<54>жϴ<D0B6><CFB4><EFBFBD>
|
||||
*
|
||||
* input parameters
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* output parameters
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void RTC_IRQHandler( void )
|
||||
{
|
||||
R8_RTC_FLAG_CTRL =(RB_RTC_TMR_CLR|RB_RTC_TRIG_CLR);
|
||||
RTCTigFlag = 1;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn HAL_Time0Init
|
||||
*
|
||||
* @brief ϵͳ<CFB5><CDB3>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
||||
*
|
||||
* input parameters
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* output parameters
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void HAL_TimeInit( void )
|
||||
{
|
||||
#if( CLK_OSC32K )
|
||||
Calibration_LSI();
|
||||
#else
|
||||
R8_SAFE_ACCESS_SIG = 0x57;
|
||||
R8_SAFE_ACCESS_SIG = 0xa8;
|
||||
R8_CK32K_CONFIG |= RB_CLK_OSC32K_XT | RB_CLK_INT32K_PON | RB_CLK_XT32K_PON; // 4 | 2 | 1
|
||||
R8_SAFE_ACCESS_SIG = 0;
|
||||
#endif
|
||||
RTC_InitTime( RTC_INIT_TIME_HOUR, RTC_INIT_TIME_MINUTE, RTC_INIT_TIME_SECEND ); //RTCʱ<43>ӳ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>ǰʱ<C7B0><CAB1>
|
||||
TMOS_TimerInit( 0 ); //ϵͳʱ<CDB3>ӳ<EFBFBD>ʼ<EFBFBD><CABC>
|
||||
}
|
||||
|
||||
/******************************** endfile @ time ******************************/
|
||||
85
BasicCode/Drive/BLE/HAL/SLEEP.c
Normal file
85
BasicCode/Drive/BLE/HAL/SLEEP.c
Normal file
@@ -0,0 +1,85 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : SLEEP.c
|
||||
* Author : WCH
|
||||
* Version : V1.1
|
||||
* Date : 2019/11/05
|
||||
* Description : ˯<><CBAF><EFBFBD><EFBFBD><EFBFBD>ü<EFBFBD><C3BC><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
||||
*******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* ͷ<>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD> */
|
||||
#include "CH57x_common.h"
|
||||
#include "HAL.h"
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn CH57X_LowPower
|
||||
*
|
||||
* @brief <20><><EFBFBD><EFBFBD>˯<EFBFBD><CBAF>
|
||||
*
|
||||
* input parameters
|
||||
*
|
||||
* @param time-<2D><><EFBFBD>ѵ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>㣨RTC<54><43><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>
|
||||
*
|
||||
* output parameters
|
||||
*
|
||||
* @param
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
u32 CH57X_LowPower( u32 time )
|
||||
{
|
||||
#if (defined (HAL_SLEEP)) && (HAL_SLEEP == TRUE)
|
||||
u32 tmp,irq_status;
|
||||
|
||||
SYS_DisableAllIrq( &irq_status );
|
||||
tmp = RTC_GetCycle32k();
|
||||
if( (time < tmp) || ((time - tmp) < 30) ){ // <20><><EFBFBD><EFBFBD>˯<EFBFBD>ߵ<EFBFBD><DFB5><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||||
SYS_RecoverIrq( irq_status );
|
||||
return 2;
|
||||
}
|
||||
RTC_SetTignTime( time );
|
||||
SYS_RecoverIrq( irq_status );
|
||||
#if( DEBUG == Debug_UART1 )
|
||||
while((R8_UART1_LSR&RB_LSR_TX_ALL_EMP)== 0 ) __nop();// ʹ<><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӡ<EFBFBD><D3A1>Ϣ<EFBFBD><CFA2>Ҫ<EFBFBD><EFBFBD><DEB8><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD>
|
||||
#endif
|
||||
// LOW POWER-sleepģʽ
|
||||
if( !RTCTigFlag ){
|
||||
LowPower_Sleep(RB_PWR_RAM2K|RB_PWR_RAM14K|RB_PWR_EXTEND );
|
||||
SetSysClock( CLK_SOURCE_HSI_32MHz );
|
||||
DelayUs(1500);
|
||||
SetSysClock( CLK_SOURCE_HSE_32MHz );
|
||||
}
|
||||
else{
|
||||
return 3;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* @fn HAL_SleepInit
|
||||
*
|
||||
* @brief <20><><EFBFBD><EFBFBD>˯<EFBFBD><EFBFBD><DFBB>ѵķ<D1B5>ʽ-RTC<54><43><EFBFBD>ѣ<EFBFBD><D1A3><EFBFBD><EFBFBD><EFBFBD>ģʽ
|
||||
*
|
||||
* input parameters
|
||||
*
|
||||
* @param None.
|
||||
*
|
||||
* output parameters
|
||||
*
|
||||
* @param
|
||||
*
|
||||
* @return None.
|
||||
*/
|
||||
void HAL_SleepInit( void )
|
||||
{
|
||||
#if (defined (HAL_SLEEP)) && (HAL_SLEEP == TRUE)
|
||||
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG1;
|
||||
R8_SAFE_ACCESS_SIG = SAFE_ACCESS_SIG2;
|
||||
R8_SLP_WAKE_CTRL |= RB_SLP_RTC_WAKE; // RTC<54><43><EFBFBD><EFBFBD>
|
||||
R8_RTC_MODE_CTRL |= RB_RTC_TRIG_EN; // <20><><EFBFBD><EFBFBD>ģʽ
|
||||
R8_SAFE_ACCESS_SIG = 0; //
|
||||
NVIC_EnableIRQ(RTC_IRQn);
|
||||
#endif
|
||||
}
|
||||
67
BasicCode/Drive/BLE/HAL/include/HAL.h
Normal file
67
BasicCode/Drive/BLE/HAL/include/HAL.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : HAL.h
|
||||
* Author : WCH
|
||||
* Version : V1.0
|
||||
* Date : 2016/05/05
|
||||
* Description :
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
#ifndef __HAL_H
|
||||
#define __HAL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "RTC.h"
|
||||
#include "SLEEP.h"
|
||||
#include "LED.h"
|
||||
#include "KEY.h"
|
||||
|
||||
/* hal task Event */
|
||||
#define LED_BLINK_EVENT 0x0001
|
||||
#define HAL_KEY_EVENT 0x0002
|
||||
#define HAL_REG_INIT_EVENT 0x2000
|
||||
#define HAL_TEST_EVENT 0x4000
|
||||
|
||||
// hal sys_message
|
||||
#define MESSAGE_UART 0xA0 // UART message
|
||||
#define UART0_MESSAGE (MESSAGE_UART|0 ) // UART0 message
|
||||
#define UART1_MESSAGE (MESSAGE_UART|1 ) // UART1 message
|
||||
|
||||
#define USB_MESSAGE 0xB0 // USB message
|
||||
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
*/
|
||||
extern tmosTaskID halTaskID;
|
||||
|
||||
typedef struct tag_uart_package
|
||||
{
|
||||
tmos_event_hdr_t hdr;
|
||||
uint8 *pData;
|
||||
} uartPacket_t;
|
||||
|
||||
/*********************************************************************
|
||||
* GLOBAL FUNCTIONS
|
||||
*/
|
||||
extern void HAL_Init( void );
|
||||
extern tmosEvents HAL_ProcessEvent( tmosTaskID task_id, tmosEvents events );
|
||||
extern void CH57X_BLEInit( void );
|
||||
extern uint16 HAL_GetInterTempValue( void );
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
*********************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
146
BasicCode/Drive/BLE/HAL/include/KEY.h
Normal file
146
BasicCode/Drive/BLE/HAL/include/KEY.h
Normal file
@@ -0,0 +1,146 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : KEY.h
|
||||
* Author : WCH
|
||||
* Version : V1.0
|
||||
* Date : 2016/04/12
|
||||
* Description :
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
#ifndef __KEY_H
|
||||
#define __KEY_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
/**************************************************************************************************
|
||||
* MACROS
|
||||
**************************************************************************************************/
|
||||
#define KEY_CHANGE 0xC0 // Key message
|
||||
|
||||
#define HAL_KEY_RISING_EDGE 0
|
||||
#define HAL_KEY_FALLING_EDGE 1
|
||||
|
||||
#define HAL_KEY_DEBOUNCE_VALUE 25
|
||||
#define HAL_KEY_POLLING_VALUE 100
|
||||
|
||||
/* Interrupt option - Enable or disable */
|
||||
#define HAL_KEY_INTERRUPT_DISABLE 0x00
|
||||
#define HAL_KEY_INTERRUPT_ENABLE 0x01
|
||||
|
||||
/* Key state - shift or nornal */
|
||||
#define HAL_KEY_STATE_NORMAL 0x00
|
||||
#define HAL_KEY_STATE_SHIFT 0x01
|
||||
|
||||
/* Switches (keys) */
|
||||
#define HAL_KEY_SW_1 0x01 // key1
|
||||
#define HAL_KEY_SW_2 0x02 // key2
|
||||
#define HAL_KEY_SW_3 0x04 // key3
|
||||
#define HAL_KEY_SW_4 0x08 // key4
|
||||
#define HAL_KEY_SW_5 0x10 // key5
|
||||
|
||||
/* Joystick */
|
||||
#define HAL_KEY_UP 0x01 // Joystick up
|
||||
#define HAL_KEY_RIGHT 0x02 // Joystick right
|
||||
#define HAL_KEY_CENTER 0x04 // Joystick center
|
||||
#define HAL_KEY_LEFT 0x08 // Joystick left
|
||||
#define HAL_KEY_DOWN 0x10 // Joystick down
|
||||
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
|
||||
/* 1 - KEY */
|
||||
#define KEY1_BV BV(22)
|
||||
#define KEY2_BV
|
||||
#define KEY3_BV
|
||||
#define KEY4_BV
|
||||
|
||||
#define KEY1_PU (R32_PB_PU |= KEY1_BV)
|
||||
#define KEY2_PU ()
|
||||
#define KEY3_PU ()
|
||||
#define KEY4_PU ()
|
||||
|
||||
#define KEY1_DIR (R32_PB_DIR &= ~KEY1_BV)
|
||||
#define KEY2_PU ()
|
||||
#define KEY3_PU ()
|
||||
#define KEY4_PU ()
|
||||
|
||||
#define KEY1_IN (ACTIVE_LOW(R32_PB_PIN&KEY1_BV))
|
||||
#define KEY2_IN ()
|
||||
#define KEY3_IN ()
|
||||
#define KEY4_IN ()
|
||||
|
||||
#define HAL_PUSH_BUTTON1() ( KEY1_IN ) //<2F><><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6>尴<EFBFBD><E5B0B4>
|
||||
#define HAL_PUSH_BUTTON2() ( 0 )
|
||||
#define HAL_PUSH_BUTTON3() ( 0 )
|
||||
#define HAL_PUSH_BUTTON4() ( 0 )
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**************************************************************************************************
|
||||
* TYPEDEFS
|
||||
**************************************************************************************************/
|
||||
typedef void (*halKeyCBack_t) (uint8 keys, uint8 state);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
tmos_event_hdr_t hdr;
|
||||
uint8 state; // shift
|
||||
uint8 keys; // keys
|
||||
} keyChange_t;
|
||||
|
||||
/**************************************************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
**************************************************************************************************/
|
||||
extern uint8 Hal_KeyIntEnable;
|
||||
|
||||
/*********************************************************************
|
||||
* FUNCTIONS
|
||||
*/
|
||||
|
||||
/*
|
||||
* Initialize the Key Service
|
||||
*/
|
||||
void HAL_KeyInit( void );
|
||||
|
||||
/*
|
||||
* This is for internal used by hal_driver
|
||||
*/
|
||||
void HAL_KeyPoll( void );
|
||||
|
||||
/*
|
||||
* Register the Key Service
|
||||
*/
|
||||
void HAL_KEY_RegisterForKeys( tmosTaskID id );
|
||||
|
||||
/*
|
||||
* Configure the Key Service
|
||||
*/
|
||||
void HalKeyConfig( uint8 interruptEnable, const halKeyCBack_t cback);
|
||||
|
||||
/*
|
||||
* Read the Key callback
|
||||
*/
|
||||
void HalKeyCallback ( uint8 keys, uint8 state );
|
||||
|
||||
/*
|
||||
* Read the Key status
|
||||
*/
|
||||
uint8 HalKeyRead( void);
|
||||
|
||||
/**************************************************************************************************
|
||||
**************************************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
128
BasicCode/Drive/BLE/HAL/include/LED.h
Normal file
128
BasicCode/Drive/BLE/HAL/include/LED.h
Normal file
@@ -0,0 +1,128 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : LED.h
|
||||
* Author : WCH
|
||||
* Version : V1.0
|
||||
* Date : 2016/04/12
|
||||
* Description :
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
#ifndef __LED_H
|
||||
#define __LED_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* CONSTANTS
|
||||
*/
|
||||
|
||||
/* LEDS - The LED number is the same as the bit position */
|
||||
#define HAL_LED_1 0x01
|
||||
#define HAL_LED_2 0x02
|
||||
#define HAL_LED_3 0x04
|
||||
#define HAL_LED_4 0x08
|
||||
#define HAL_LED_ALL (HAL_LED_1 | HAL_LED_2 | HAL_LED_3 | HAL_LED_4)
|
||||
|
||||
/* Modes */
|
||||
#define HAL_LED_MODE_OFF 0x00
|
||||
#define HAL_LED_MODE_ON 0x01
|
||||
#define HAL_LED_MODE_BLINK 0x02
|
||||
#define HAL_LED_MODE_FLASH 0x04
|
||||
#define HAL_LED_MODE_TOGGLE 0x08
|
||||
|
||||
/* Defaults */
|
||||
#define HAL_LED_DEFAULT_MAX_LEDS 4
|
||||
#define HAL_LED_DEFAULT_DUTY_CYCLE 5
|
||||
#define HAL_LED_DEFAULT_FLASH_COUNT 50
|
||||
#define HAL_LED_DEFAULT_FLASH_TIME 1000
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* TYPEDEFS
|
||||
*/
|
||||
|
||||
/* <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>LED<45><44><EFBFBD>ڼ<EFBFBD><DABC><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD>Ľ<EFBFBD><C4BD><EFBFBD>,<2C>͵<EFBFBD>ƽLED<45><44> */
|
||||
|
||||
/* 1 - LED */
|
||||
#define LED1_BV BV(0)
|
||||
#define LED2_BV
|
||||
#define LED3_BV
|
||||
|
||||
#define LED1_OUT (R32_PB_OUT)
|
||||
#define LED2_OUT 0
|
||||
#define LED3_OUT 0
|
||||
#define LED4_OUT 0
|
||||
|
||||
#define LED1_DDR (R32_PB_DIR|=LED1_BV)
|
||||
#define LED2_DDR 0
|
||||
#define LED3_DDR 0
|
||||
|
||||
#define HAL_TURN_OFF_LED1() (LED1_OUT |= LED1_BV)
|
||||
#define HAL_TURN_OFF_LED2()
|
||||
#define HAL_TURN_OFF_LED3()
|
||||
#define HAL_TURN_OFF_LED4()
|
||||
|
||||
#define HAL_TURN_ON_LED1() (LED1_OUT &= (~LED1_BV))
|
||||
#define HAL_TURN_ON_LED2()
|
||||
#define HAL_TURN_ON_LED3()
|
||||
#define HAL_TURN_ON_LED4()
|
||||
|
||||
#define HAL_STATE_LED1() 0
|
||||
#define HAL_STATE_LED2() 0
|
||||
#define HAL_STATE_LED3() 0
|
||||
#define HAL_STATE_LED4() 0
|
||||
|
||||
/*********************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
*/
|
||||
|
||||
/*
|
||||
* Initialize LED Service.
|
||||
*/
|
||||
void HAL_LedInit( void );
|
||||
|
||||
|
||||
/*
|
||||
* update time LED Service.
|
||||
*/
|
||||
void HalLedUpdate (void);
|
||||
|
||||
/*
|
||||
* Set the LED ON/OFF/TOGGLE.
|
||||
*/
|
||||
extern uint8 HalLedSet( uint8 led, uint8 mode );
|
||||
|
||||
/*
|
||||
* Blink the LED.
|
||||
*/
|
||||
extern void HalLedBlink( uint8 leds, uint8 cnt, uint8 duty, uint16 time );
|
||||
|
||||
/*
|
||||
* Put LEDs in sleep state - store current values
|
||||
*/
|
||||
extern void HalLedEnterSleep( void );
|
||||
|
||||
/*
|
||||
* Retore LEDs from sleep state
|
||||
*/
|
||||
extern void HalLedExitSleep( void );
|
||||
|
||||
/*
|
||||
* Return LED state
|
||||
*/
|
||||
extern uint8 HalLedGetState ( void );
|
||||
|
||||
/*********************************************************************
|
||||
*********************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
40
BasicCode/Drive/BLE/HAL/include/RTC.h
Normal file
40
BasicCode/Drive/BLE/HAL/include/RTC.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : RTC.h
|
||||
* Author : WCH
|
||||
* Version : V1.0
|
||||
* Date : 2016/04/12
|
||||
* Description :
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
#ifndef __RTC_H
|
||||
#define __RTC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#define RTC_TIMER_MAX_VALUE 0xa8c00000
|
||||
|
||||
extern u32V RTCTigFlag;
|
||||
|
||||
/*
|
||||
* Initialize time Service.
|
||||
*/
|
||||
void HAL_TimeInit( void );
|
||||
|
||||
/*
|
||||
* System Clock Service.
|
||||
*/
|
||||
extern void RTC_SetTignTime( u32 time );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
38
BasicCode/Drive/BLE/HAL/include/SLEEP.h
Normal file
38
BasicCode/Drive/BLE/HAL/include/SLEEP.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : SLEEP.h
|
||||
* Author : WCH
|
||||
* Version : V1.0
|
||||
* Date : 2018/11/12
|
||||
* Description :
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
#ifndef __SLEEP_H
|
||||
#define __SLEEP_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* FUNCTIONS
|
||||
*/
|
||||
extern void HAL_SleepInit( void );
|
||||
|
||||
extern u32 CH57X_LowPower( u32 time );
|
||||
/*********************************************************************
|
||||
*********************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
128
BasicCode/Drive/BLE/HAL/include/config.h
Normal file
128
BasicCode/Drive/BLE/HAL/include/config.h
Normal file
@@ -0,0 +1,128 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : CONFIG.h
|
||||
* Author : WCH
|
||||
* Version : V1.10
|
||||
* Date : 2019/11/05
|
||||
* Description : <20><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڹ<EFBFBD><DAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><D4A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<DEB8>ǰֵ
|
||||
*******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
#ifndef __CONFIG_H
|
||||
#define __CONFIG_H
|
||||
|
||||
#define ID_CH577 0x77
|
||||
#define ID_CH578 0x78
|
||||
#define ID_CH579 0x79
|
||||
|
||||
#define CHIP_ID ID_CH579
|
||||
|
||||
#ifdef CH57xBLE_ROM
|
||||
#include "CH57xBLE_ROM.H"
|
||||
#else
|
||||
#include "CH57xBLE_LIB.H"
|
||||
#endif
|
||||
/*********************************************************************
|
||||
<EFBFBD><EFBFBD>MAC<EFBFBD><EFBFBD>
|
||||
BLE_MAC - <20>Ƿ<EFBFBD><C7B7>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Mac<61><63>ַ ( Ĭ<><C4AC>:FALSE - ʹ<><CAB9>оƬMac<61><63>ַ )<29><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>main.c<><EFBFBD>Mac<61><63>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>
|
||||
|
||||
<EFBFBD><EFBFBD>SLEEP<EFBFBD><EFBFBD>
|
||||
HAL_SLEEP - <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>˯<EFBFBD>߹<EFBFBD><DFB9><EFBFBD> ( Ĭ<><C4AC>:FALSE )
|
||||
WAKE_UP_RTC_MAX_TIME - ˯<><EFBFBD><DFBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>䣬<EFBFBD><E4A3AC><EFBFBD>ݲ<EFBFBD>ͬ˯<CDAC><CBAF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡֵ<C8A1>ɷ<EFBFBD>Ϊ<EFBFBD><CEAA>˯<EFBFBD><CBAF>ģʽ/<2F>µ<EFBFBD>ģʽ - 65(Ĭ<><C4AC>)
|
||||
<09><>ͣģʽ - 65
|
||||
<09><><EFBFBD><EFBFBD>ģʽ - 5
|
||||
|
||||
<EFBFBD><EFBFBD>TEMPERATION<EFBFBD><EFBFBD>
|
||||
TEM_SAMPLE - <20>Ƿ<EFBFBD><C7B7><EFBFBD><F2BFAAB8><EFBFBD><EFBFBD>¶ȱ仯У<D0A3>Ĺ<EFBFBD><C4B9>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD>У<D0A3><D7BC>ʱС<CAB1><D0A1>10ms( Ĭ<><C4AC>:TRUE )
|
||||
|
||||
<EFBFBD><EFBFBD>CALIBRATION<EFBFBD><EFBFBD>
|
||||
BLE_CALIBRATION_ENABLE - <20>Ƿ<EFBFBD><C7B7><EFBFBD>ʱУ<D0A3>Ĺ<EFBFBD><C4B9>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD><EFBFBD>У<D0A3><D7BC>ʱС<CAB1><D0A1>10ms( Ĭ<><C4AC>:TRUE )
|
||||
BLE_CALIBRATION_PERIOD - <20><>ʱУ<D0A3><D7BC><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD>λms( Ĭ<><C4AC>:120000 )
|
||||
|
||||
<EFBFBD><EFBFBD>SNV<EFBFBD><EFBFBD>
|
||||
BLE_SNV - <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>SNV<4E><56><EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ( Ĭ<><C4AC>:TRUE )
|
||||
BLE_SNV_ADDR - SNV<4E><56>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>ʹ<EFBFBD><CAB9>data flash<73><68><EFBFBD><EFBFBD>( Ĭ<><C4AC>:0x3EC00 )
|
||||
|
||||
<EFBFBD><EFBFBD>RTC<EFBFBD><EFBFBD>
|
||||
CLK_OSC32K - RTCʱ<43><CAB1>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD>ⲿ32K( Ĭ<><C4AC>:0 <20>ⲿ(32768Hz)<29><>1<EFBFBD><31><EFBFBD>ڲ<EFBFBD>(32000Hz)<29><>2<EFBFBD><32><EFBFBD>ڲ<EFBFBD>(32768Hz) )
|
||||
|
||||
<EFBFBD><EFBFBD>MEMORY<EFBFBD><EFBFBD>
|
||||
BLE_MEMHEAP_SIZE - <20><><EFBFBD><EFBFBD>Э<EFBFBD><D0AD>ջʹ<D5BB>õ<EFBFBD>RAM<41><4D>С<EFBFBD><D0A1><EFBFBD><EFBFBD>С<EFBFBD><D0A1>6K ( Ĭ<><C4AC>:(1024*8) )
|
||||
|
||||
<EFBFBD><EFBFBD>DATA<EFBFBD><EFBFBD>
|
||||
BLE_BUFF_MAX_LEN - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>( Ĭ<><C4AC>:27 (ATT_MTU=23)<29><>ȡֵ<C8A1><D6B5>Χ[27~251] )
|
||||
BLE_BUFF_NUM - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>İ<EFBFBD><C4B0><EFBFBD><EFBFBD><EFBFBD>( Ĭ<><C4AC>:5 )
|
||||
BLE_TX_NUM_EVENT - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Է<EFBFBD><D4B7><EFBFBD><EFBFBD>ٸ<EFBFBD><D9B8><EFBFBD><EFBFBD>ݰ<EFBFBD>( Ĭ<><C4AC>:1 )
|
||||
BLE_TX_POWER - <20><><EFBFBD>书<EFBFBD><E4B9A6>( Ĭ<><C4AC>:LL_TX_POWEER_0_DBM (0dBm) )
|
||||
|
||||
<EFBFBD><EFBFBD>MULTICONN<EFBFBD><EFBFBD>
|
||||
PERIPHERAL_MAX_CONNECTION - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬʱ<CDAC><CAB1><EFBFBD><EFBFBD><EFBFBD>ٴӻ<D9B4><D3BB><EFBFBD>ɫ( Ĭ<><C4AC>:1 )
|
||||
CENTRAL_MAX_CONNECTION - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬʱ<CDAC><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ( Ĭ<><C4AC>:3 )
|
||||
**********************************************************************/
|
||||
|
||||
/*********************************************************************
|
||||
* Ĭ<><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
||||
*/
|
||||
#ifndef BLE_MAC
|
||||
#define BLE_MAC /*FALSE*/TRUE
|
||||
#endif
|
||||
#ifndef HAL_SLEEP
|
||||
#define HAL_SLEEP FALSE
|
||||
#endif
|
||||
#ifndef WAKE_UP_RTC_MAX_TIME
|
||||
#define WAKE_UP_RTC_MAX_TIME 65
|
||||
#endif
|
||||
#ifndef HAL_KEY
|
||||
#define HAL_KEY FALSE
|
||||
#endif
|
||||
#ifndef HAL_LED
|
||||
#define HAL_LED FALSE
|
||||
#endif
|
||||
#ifndef TEM_SAMPLE
|
||||
#define TEM_SAMPLE TRUE
|
||||
#endif
|
||||
#ifndef BLE_CALIBRATION_ENABLE
|
||||
#define BLE_CALIBRATION_ENABLE TRUE
|
||||
#endif
|
||||
#ifndef BLE_CALIBRATION_PERIOD
|
||||
#define BLE_CALIBRATION_PERIOD 120000
|
||||
#endif
|
||||
#ifndef BLE_SNV
|
||||
#define BLE_SNV TRUE
|
||||
#endif
|
||||
#ifndef BLE_SNV_ADDR
|
||||
#define BLE_SNV_ADDR 0x3EC00
|
||||
#endif
|
||||
#ifndef CLK_OSC32K
|
||||
#define CLK_OSC32K 2 // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڹ<EFBFBD><DAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><D4A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<DEB8><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD>ⲿ32K
|
||||
#endif
|
||||
#ifndef BLE_MEMHEAP_SIZE
|
||||
#define BLE_MEMHEAP_SIZE (1024*8)
|
||||
#endif
|
||||
#ifndef BLE_BUFF_MAX_LEN
|
||||
#define BLE_BUFF_MAX_LEN 145
|
||||
#endif
|
||||
#ifndef BLE_BUFF_NUM
|
||||
#define BLE_BUFF_NUM 5
|
||||
#endif
|
||||
#ifndef BLE_TX_NUM_EVENT
|
||||
#define BLE_TX_NUM_EVENT 1
|
||||
#endif
|
||||
#ifndef BLE_TX_POWER
|
||||
#define BLE_TX_POWER LL_TX_POWEER_0_DBM
|
||||
#endif
|
||||
#ifndef PERIPHERAL_MAX_CONNECTION
|
||||
#define PERIPHERAL_MAX_CONNECTION 1
|
||||
#endif
|
||||
#ifndef CENTRAL_MAX_CONNECTION
|
||||
#define CENTRAL_MAX_CONNECTION 3
|
||||
#endif
|
||||
|
||||
#if BLE_CODE_EN
|
||||
extern u32 MEM_BUF[BLE_MEMHEAP_SIZE/4];
|
||||
#endif
|
||||
|
||||
extern u8 MACAddr[6];
|
||||
|
||||
#endif
|
||||
|
||||
/******************************* endfile @ config ******************************/
|
||||
631
BasicCode/Drive/BLE/PROFILE/devinfoservice.c
Normal file
631
BasicCode/Drive/BLE/PROFILE/devinfoservice.c
Normal file
@@ -0,0 +1,631 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : devinfoservice.c
|
||||
* Author : WCH
|
||||
* Version : V1.0
|
||||
* Date : 2018/12/10
|
||||
* Description : <20>豸<EFBFBD><E8B1B8>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
/*********************************************************************
|
||||
* INCLUDES
|
||||
*/
|
||||
#include "CONFIG.h"
|
||||
#include "devinfoservice.h"
|
||||
|
||||
/*********************************************************************
|
||||
* MACROS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* CONSTANTS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* TYPEDEFS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
*/
|
||||
// Device information service
|
||||
CONST uint8 devInfoServUUID[ATT_BT_UUID_SIZE] =
|
||||
{
|
||||
LO_UINT16(DEVINFO_SERV_UUID), HI_UINT16(DEVINFO_SERV_UUID)
|
||||
};
|
||||
|
||||
// System ID
|
||||
CONST uint8 devInfoSystemIdUUID[ATT_BT_UUID_SIZE] =
|
||||
{
|
||||
LO_UINT16(SYSTEM_ID_UUID), HI_UINT16(SYSTEM_ID_UUID)
|
||||
};
|
||||
|
||||
// Model Number String
|
||||
CONST uint8 devInfoModelNumberUUID[ATT_BT_UUID_SIZE] =
|
||||
{
|
||||
LO_UINT16(MODEL_NUMBER_UUID), HI_UINT16(MODEL_NUMBER_UUID)
|
||||
};
|
||||
|
||||
// Serial Number String
|
||||
CONST uint8 devInfoSerialNumberUUID[ATT_BT_UUID_SIZE] =
|
||||
{
|
||||
LO_UINT16(SERIAL_NUMBER_UUID), HI_UINT16(SERIAL_NUMBER_UUID)
|
||||
};
|
||||
|
||||
// Firmware Revision String
|
||||
CONST uint8 devInfoFirmwareRevUUID[ATT_BT_UUID_SIZE] =
|
||||
{
|
||||
LO_UINT16(FIRMWARE_REV_UUID), HI_UINT16(FIRMWARE_REV_UUID)
|
||||
};
|
||||
|
||||
// Hardware Revision String
|
||||
CONST uint8 devInfoHardwareRevUUID[ATT_BT_UUID_SIZE] =
|
||||
{
|
||||
LO_UINT16(HARDWARE_REV_UUID), HI_UINT16(HARDWARE_REV_UUID)
|
||||
};
|
||||
|
||||
// Software Revision String
|
||||
CONST uint8 devInfoSoftwareRevUUID[ATT_BT_UUID_SIZE] =
|
||||
{
|
||||
LO_UINT16(SOFTWARE_REV_UUID), HI_UINT16(SOFTWARE_REV_UUID)
|
||||
};
|
||||
|
||||
// Manufacturer Name String
|
||||
CONST uint8 devInfoMfrNameUUID[ATT_BT_UUID_SIZE] =
|
||||
{
|
||||
LO_UINT16(MANUFACTURER_NAME_UUID), HI_UINT16(MANUFACTURER_NAME_UUID)
|
||||
};
|
||||
|
||||
// IEEE 11073-20601 Regulatory Certification Data List
|
||||
CONST uint8 devInfo11073CertUUID[ATT_BT_UUID_SIZE] =
|
||||
{
|
||||
LO_UINT16(IEEE_11073_CERT_DATA_UUID), HI_UINT16(IEEE_11073_CERT_DATA_UUID)
|
||||
};
|
||||
|
||||
// PnP ID
|
||||
CONST uint8 devInfoPnpIdUUID[ATT_BT_UUID_SIZE] =
|
||||
{
|
||||
LO_UINT16(PNP_ID_UUID), HI_UINT16(PNP_ID_UUID)
|
||||
};
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* EXTERNAL VARIABLES
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* EXTERNAL FUNCTIONS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* LOCAL VARIABLES
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* Profile Attributes - variables
|
||||
*/
|
||||
|
||||
// Device Information Service attribute
|
||||
static CONST gattAttrType_t devInfoService = { ATT_BT_UUID_SIZE, devInfoServUUID };
|
||||
|
||||
// System ID characteristic
|
||||
static uint8 devInfoSystemIdProps = GATT_PROP_READ;
|
||||
static uint8 devInfoSystemId[DEVINFO_SYSTEM_ID_LEN] = {0, 0, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
// Model Number String characteristic
|
||||
static uint8 devInfoModelNumberProps = GATT_PROP_READ;
|
||||
static const uint8 devInfoModelNumber[] = "Model Number";
|
||||
|
||||
// Serial Number String characteristic
|
||||
static uint8 devInfoSerialNumberProps = GATT_PROP_READ;
|
||||
static const uint8 devInfoSerialNumber[] = "Serial Number";
|
||||
|
||||
// Firmware Revision String characteristic
|
||||
static uint8 devInfoFirmwareRevProps = GATT_PROP_READ;
|
||||
static const uint8 devInfoFirmwareRev[] = "Firmware Revision";
|
||||
|
||||
// Hardware Revision String characteristic
|
||||
static uint8 devInfoHardwareRevProps = GATT_PROP_READ;
|
||||
static const uint8 devInfoHardwareRev[] = "Hardware Revision";
|
||||
|
||||
// Software Revision String characteristic
|
||||
static uint8 devInfoSoftwareRevProps = GATT_PROP_READ;
|
||||
static const uint8 devInfoSoftwareRev[] = "Software Revision";
|
||||
|
||||
// Manufacturer Name String characteristic
|
||||
static uint8 devInfoMfrNameProps = GATT_PROP_READ;
|
||||
static const uint8 devInfoMfrName[] = "Manufacturer Name";
|
||||
|
||||
// IEEE 11073-20601 Regulatory Certification Data List characteristic
|
||||
static uint8 devInfo11073CertProps = GATT_PROP_READ;
|
||||
static const uint8 devInfo11073Cert[] =
|
||||
{
|
||||
DEVINFO_11073_BODY_EXP, // authoritative body type
|
||||
0x00, // authoritative body structure type
|
||||
// authoritative body data follows below:
|
||||
'e', 'x', 'p', 'e', 'r', 'i', 'm', 'e', 'n', 't', 'a', 'l'
|
||||
};
|
||||
|
||||
// System ID characteristic
|
||||
static uint8 devInfoPnpIdProps = GATT_PROP_READ;
|
||||
static uint8 devInfoPnpId[DEVINFO_PNP_ID_LEN] =
|
||||
{
|
||||
1, // Vendor ID source (1=Bluetooth SIG)
|
||||
LO_UINT16(0x07D7), HI_UINT16(0x07D7), // Vendor ID (WCH)
|
||||
LO_UINT16(0x0000), HI_UINT16(0x0000), // Product ID (vendor-specific)
|
||||
LO_UINT16(0x0110), HI_UINT16(0x0110) // Product version (JJ.M.N)
|
||||
};
|
||||
|
||||
/*********************************************************************
|
||||
* Profile Attributes - Table
|
||||
*/
|
||||
|
||||
static gattAttribute_t devInfoAttrTbl[] =
|
||||
{
|
||||
// Device Information Service
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, primaryServiceUUID }, /* type */
|
||||
GATT_PERMIT_READ, /* permissions */
|
||||
0, /* handle */
|
||||
(uint8 *)&devInfoService /* pValue */
|
||||
},
|
||||
|
||||
// System ID Declaration
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, characterUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
&devInfoSystemIdProps
|
||||
},
|
||||
|
||||
// System ID Value
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, devInfoSystemIdUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
(uint8 *) devInfoSystemId
|
||||
},
|
||||
|
||||
// Model Number String Declaration
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, characterUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
&devInfoModelNumberProps
|
||||
},
|
||||
|
||||
// Model Number Value
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, devInfoModelNumberUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
(uint8 *) devInfoModelNumber
|
||||
},
|
||||
|
||||
// Serial Number String Declaration
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, characterUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
&devInfoSerialNumberProps
|
||||
},
|
||||
|
||||
// Serial Number Value
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, devInfoSerialNumberUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
(uint8 *) devInfoSerialNumber
|
||||
},
|
||||
|
||||
// Firmware Revision String Declaration
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, characterUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
&devInfoFirmwareRevProps
|
||||
},
|
||||
|
||||
// Firmware Revision Value
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, devInfoFirmwareRevUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
(uint8 *) devInfoFirmwareRev
|
||||
},
|
||||
|
||||
// Hardware Revision String Declaration
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, characterUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
&devInfoHardwareRevProps
|
||||
},
|
||||
|
||||
// Hardware Revision Value
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, devInfoHardwareRevUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
(uint8 *) devInfoHardwareRev
|
||||
},
|
||||
|
||||
// Software Revision String Declaration
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, characterUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
&devInfoSoftwareRevProps
|
||||
},
|
||||
|
||||
// Software Revision Value
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, devInfoSoftwareRevUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
(uint8 *) devInfoSoftwareRev
|
||||
},
|
||||
|
||||
// Manufacturer Name String Declaration
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, characterUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
&devInfoMfrNameProps
|
||||
},
|
||||
|
||||
// Manufacturer Name Value
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, devInfoMfrNameUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
(uint8 *) devInfoMfrName
|
||||
},
|
||||
|
||||
// IEEE 11073-20601 Regulatory Certification Data List Declaration
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, characterUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
&devInfo11073CertProps
|
||||
},
|
||||
|
||||
// IEEE 11073-20601 Regulatory Certification Data List Value
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, devInfo11073CertUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
(uint8 *) devInfo11073Cert
|
||||
},
|
||||
|
||||
// PnP ID Declaration
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, characterUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
&devInfoPnpIdProps
|
||||
},
|
||||
|
||||
// PnP ID Value
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, devInfoPnpIdUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
(uint8 *) devInfoPnpId
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* LOCAL FUNCTIONS
|
||||
*/
|
||||
static bStatus_t devInfo_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
|
||||
uint8 *pValue, uint16 *pLen, uint16 offset, uint16 maxLen,uint8 method );
|
||||
|
||||
/*********************************************************************
|
||||
* PROFILE CALLBACKS
|
||||
*/
|
||||
// Device Info Service Callbacks
|
||||
gattServiceCBs_t devInfoCBs =
|
||||
{
|
||||
devInfo_ReadAttrCB, // Read callback function pointer
|
||||
NULL, // Write callback function pointer
|
||||
NULL // Authorization callback function pointer
|
||||
};
|
||||
|
||||
/*********************************************************************
|
||||
* NETWORK LAYER CALLBACKS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* PUBLIC FUNCTIONS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* @fn DevInfo_AddService
|
||||
*
|
||||
* @brief Initializes the Device Information service by registering
|
||||
* GATT attributes with the GATT server.
|
||||
*
|
||||
* @return Success or Failure
|
||||
*/
|
||||
bStatus_t DevInfo_AddService( void )
|
||||
{
|
||||
// Register GATT attribute list and CBs with GATT Server App
|
||||
return GATTServApp_RegisterService( devInfoAttrTbl,
|
||||
GATT_NUM_ATTRS( devInfoAttrTbl ),
|
||||
GATT_MAX_ENCRYPT_KEY_SIZE,
|
||||
&devInfoCBs );
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn DevInfo_SetParameter
|
||||
*
|
||||
* @brief Set a Device Information parameter.
|
||||
*
|
||||
* @param param - Profile parameter ID
|
||||
* @param len - length of data to write
|
||||
* @param value - pointer to data to write. This is dependent on
|
||||
* the parameter ID and WILL be cast to the appropriate
|
||||
* data type (example: data type of uint16 will be cast to
|
||||
* uint16 pointer).
|
||||
*
|
||||
* @return bStatus_t
|
||||
*/
|
||||
bStatus_t DevInfo_SetParameter( uint8 param, uint8 len, void *value )
|
||||
{
|
||||
bStatus_t ret = SUCCESS;
|
||||
|
||||
switch ( param )
|
||||
{
|
||||
case DEVINFO_SYSTEM_ID:
|
||||
tmos_memcpy(devInfoSystemId, value, len);
|
||||
break;
|
||||
|
||||
default:
|
||||
ret = INVALIDPARAMETER;
|
||||
break;
|
||||
}
|
||||
|
||||
return ( ret );
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn DevInfo_GetParameter
|
||||
*
|
||||
* @brief Get a Device Information parameter.
|
||||
*
|
||||
* @param param - Profile parameter ID
|
||||
* @param value - pointer to data to get. This is dependent on
|
||||
* the parameter ID and WILL be cast to the appropriate
|
||||
* data type (example: data type of uint16 will be cast to
|
||||
* uint16 pointer).
|
||||
*
|
||||
* @return bStatus_t
|
||||
*/
|
||||
bStatus_t DevInfo_GetParameter( uint8 param, void *value )
|
||||
{
|
||||
bStatus_t ret = SUCCESS;
|
||||
|
||||
switch ( param )
|
||||
{
|
||||
case DEVINFO_SYSTEM_ID:
|
||||
tmos_memcpy(value, devInfoSystemId, sizeof(devInfoSystemId));
|
||||
break;
|
||||
|
||||
case DEVINFO_MODEL_NUMBER:
|
||||
tmos_memcpy(value, devInfoModelNumber, sizeof(devInfoModelNumber));
|
||||
break;
|
||||
case DEVINFO_SERIAL_NUMBER:
|
||||
tmos_memcpy(value, devInfoSerialNumber, sizeof(devInfoSerialNumber));
|
||||
break;
|
||||
|
||||
case DEVINFO_FIRMWARE_REV:
|
||||
tmos_memcpy(value, devInfoFirmwareRev, sizeof(devInfoFirmwareRev));
|
||||
break;
|
||||
|
||||
case DEVINFO_HARDWARE_REV:
|
||||
tmos_memcpy(value, devInfoHardwareRev, sizeof(devInfoHardwareRev));
|
||||
break;
|
||||
|
||||
case DEVINFO_SOFTWARE_REV:
|
||||
tmos_memcpy(value, devInfoSoftwareRev, sizeof(devInfoSoftwareRev));
|
||||
break;
|
||||
|
||||
case DEVINFO_MANUFACTURER_NAME:
|
||||
tmos_memcpy(value, devInfoMfrName, sizeof(devInfoMfrName));
|
||||
break;
|
||||
|
||||
case DEVINFO_11073_CERT_DATA:
|
||||
tmos_memcpy(value, devInfo11073Cert, sizeof(devInfo11073Cert));
|
||||
break;
|
||||
|
||||
case DEVINFO_PNP_ID:
|
||||
tmos_memcpy(value, devInfoPnpId, sizeof(devInfoPnpId));
|
||||
break;
|
||||
|
||||
default:
|
||||
ret = INVALIDPARAMETER;
|
||||
break;
|
||||
}
|
||||
|
||||
return ( ret );
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn devInfo_ReadAttrCB
|
||||
*
|
||||
* @brief Read an attribute.
|
||||
*
|
||||
* @param connHandle - connection message was received on
|
||||
* @param pAttr - pointer to attribute
|
||||
* @param pValue - pointer to data to be read
|
||||
* @param pLen - length of data to be read
|
||||
* @param offset - offset of the first octet to be read
|
||||
* @param maxLen - maximum length of data to be read
|
||||
*
|
||||
* @return Success or Failure
|
||||
*/
|
||||
static bStatus_t devInfo_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
|
||||
uint8 *pValue, uint16 *pLen, uint16 offset, uint16 maxLen,uint8 method )
|
||||
{
|
||||
bStatus_t status = SUCCESS;
|
||||
uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
|
||||
|
||||
switch (uuid)
|
||||
{
|
||||
case SYSTEM_ID_UUID:
|
||||
// verify offset
|
||||
if (offset >= sizeof(devInfoSystemId))
|
||||
{
|
||||
status = ATT_ERR_INVALID_OFFSET;
|
||||
}
|
||||
else
|
||||
{
|
||||
// determine read length
|
||||
*pLen = MIN(maxLen, (sizeof(devInfoSystemId) - offset));
|
||||
|
||||
// copy data
|
||||
tmos_memcpy(pValue, &devInfoSystemId[offset], *pLen);
|
||||
}
|
||||
break;
|
||||
|
||||
case MODEL_NUMBER_UUID:
|
||||
// verify offset
|
||||
if (offset >= (sizeof(devInfoModelNumber) - 1))
|
||||
{
|
||||
status = ATT_ERR_INVALID_OFFSET;
|
||||
}
|
||||
else
|
||||
{
|
||||
// determine read length (exclude null terminating character)
|
||||
*pLen = MIN(maxLen, ((sizeof(devInfoModelNumber) - 1) - offset));
|
||||
|
||||
// copy data
|
||||
tmos_memcpy(pValue, &devInfoModelNumber[offset], *pLen);
|
||||
}
|
||||
break;
|
||||
|
||||
case SERIAL_NUMBER_UUID:
|
||||
// verify offset
|
||||
if (offset >= (sizeof(devInfoSerialNumber) - 1))
|
||||
{
|
||||
status = ATT_ERR_INVALID_OFFSET;
|
||||
}
|
||||
else
|
||||
{
|
||||
// determine read length (exclude null terminating character)
|
||||
*pLen = MIN(maxLen, ((sizeof(devInfoSerialNumber) - 1) - offset));
|
||||
|
||||
// copy data
|
||||
tmos_memcpy(pValue, &devInfoSerialNumber[offset], *pLen);
|
||||
}
|
||||
break;
|
||||
|
||||
case FIRMWARE_REV_UUID:
|
||||
// verify offset
|
||||
if (offset >= (sizeof(devInfoFirmwareRev) - 1))
|
||||
{
|
||||
status = ATT_ERR_INVALID_OFFSET;
|
||||
}
|
||||
else
|
||||
{
|
||||
// determine read length (exclude null terminating character)
|
||||
*pLen = MIN(maxLen, ((sizeof(devInfoFirmwareRev) - 1) - offset));
|
||||
|
||||
// copy data
|
||||
tmos_memcpy(pValue, &devInfoFirmwareRev[offset], *pLen);
|
||||
}
|
||||
break;
|
||||
|
||||
case HARDWARE_REV_UUID:
|
||||
// verify offset
|
||||
if (offset >= (sizeof(devInfoHardwareRev) - 1))
|
||||
{
|
||||
status = ATT_ERR_INVALID_OFFSET;
|
||||
}
|
||||
else
|
||||
{
|
||||
// determine read length (exclude null terminating character)
|
||||
*pLen = MIN(maxLen, ((sizeof(devInfoHardwareRev) - 1) - offset));
|
||||
|
||||
// copy data
|
||||
tmos_memcpy(pValue, &devInfoHardwareRev[offset], *pLen);
|
||||
}
|
||||
break;
|
||||
|
||||
case SOFTWARE_REV_UUID:
|
||||
// verify offset
|
||||
if (offset >= (sizeof(devInfoSoftwareRev) - 1))
|
||||
{
|
||||
status = ATT_ERR_INVALID_OFFSET;
|
||||
}
|
||||
else
|
||||
{
|
||||
// determine read length (exclude null terminating character)
|
||||
*pLen = MIN(maxLen, ((sizeof(devInfoSoftwareRev) - 1) - offset));
|
||||
|
||||
// copy data
|
||||
tmos_memcpy(pValue, &devInfoSoftwareRev[offset], *pLen);
|
||||
}
|
||||
break;
|
||||
|
||||
case MANUFACTURER_NAME_UUID:
|
||||
// verify offset
|
||||
if (offset >= (sizeof(devInfoMfrName) - 1))
|
||||
{
|
||||
status = ATT_ERR_INVALID_OFFSET;
|
||||
}
|
||||
else
|
||||
{
|
||||
// determine read length (exclude null terminating character)
|
||||
*pLen = MIN(maxLen, ((sizeof(devInfoMfrName) - 1) - offset));
|
||||
|
||||
// copy data
|
||||
tmos_memcpy(pValue, &devInfoMfrName[offset], *pLen);
|
||||
}
|
||||
break;
|
||||
|
||||
case IEEE_11073_CERT_DATA_UUID:
|
||||
// verify offset
|
||||
if (offset >= sizeof(devInfo11073Cert))
|
||||
{
|
||||
status = ATT_ERR_INVALID_OFFSET;
|
||||
}
|
||||
else
|
||||
{
|
||||
// determine read length
|
||||
*pLen = MIN(maxLen, (sizeof(devInfo11073Cert) - offset));
|
||||
|
||||
// copy data
|
||||
tmos_memcpy(pValue, &devInfo11073Cert[offset], *pLen);
|
||||
}
|
||||
break;
|
||||
|
||||
case PNP_ID_UUID:
|
||||
// verify offset
|
||||
if (offset >= sizeof(devInfoPnpId))
|
||||
{
|
||||
status = ATT_ERR_INVALID_OFFSET;
|
||||
}
|
||||
else
|
||||
{
|
||||
// determine read length
|
||||
*pLen = MIN(maxLen, (sizeof(devInfoPnpId) - offset));
|
||||
|
||||
// copy data
|
||||
tmos_memcpy(pValue, &devInfoPnpId[offset], *pLen);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
*pLen = 0;
|
||||
status = ATT_ERR_ATTR_NOT_FOUND;
|
||||
break;
|
||||
}
|
||||
|
||||
return ( status );
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*********************************************************************/
|
||||
886
BasicCode/Drive/BLE/PROFILE/gattprofile.c
Normal file
886
BasicCode/Drive/BLE/PROFILE/gattprofile.c
Normal file
@@ -0,0 +1,886 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : gattprofile.C
|
||||
* Author : WCH
|
||||
* Version : V1.0
|
||||
* Date : 2018/12/10
|
||||
* Description : <20>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֲ<EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD>Եķ<D4B5><C4B7><EFBFBD><F1A3ACB0><EFBFBD><EFBFBD>ɶ<EFBFBD><C9B6><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4>֪ͨ<CDA8><D6AA><EFBFBD>ɶ<EFBFBD><C9B6><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>ȫ<EFBFBD>ɶ<EFBFBD>
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
/*********************************************************************
|
||||
* INCLUDES
|
||||
*/
|
||||
//#include "CONFIG.h"
|
||||
#include "gattprofile.h"
|
||||
#include "net.h"
|
||||
#include "peripheral.h"
|
||||
#include "aLiYun.h"
|
||||
#include "SPI_SRAM.h"
|
||||
/*********************************************************************
|
||||
* MACROS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* CONSTANTS
|
||||
*/
|
||||
|
||||
// Position of simpleProfilechar4 value in attribute array
|
||||
#define SIMPLEPROFILE_CHAR4_VALUE_POS 11
|
||||
|
||||
/*********************************************************************
|
||||
* TYPEDEFS
|
||||
*/
|
||||
BLE_SEND_INFO ble_send_info = {0};
|
||||
|
||||
BLE_DEVICE_CONFIG* Ble_Device_Info_Ptr = NULL; //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD>ٷ<EFBFBD><D9B7><EFBFBD>
|
||||
|
||||
/*********************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
*/
|
||||
// Simple GATT Profile Service UUID: 0xFFF0
|
||||
CONST uint8 simpleProfileServUUID[ATT_BT_UUID_SIZE] =
|
||||
{
|
||||
LO_UINT16(SIMPLEPROFILE_SERV_UUID), HI_UINT16(SIMPLEPROFILE_SERV_UUID)
|
||||
};
|
||||
|
||||
// Characteristic 1 UUID: 0xFFF1
|
||||
CONST uint8 simpleProfilechar1UUID[ATT_BT_UUID_SIZE] =
|
||||
{
|
||||
LO_UINT16(SIMPLEPROFILE_CHAR1_UUID), HI_UINT16(SIMPLEPROFILE_CHAR1_UUID)
|
||||
};
|
||||
|
||||
// Characteristic 2 UUID: 0xFFF2
|
||||
CONST uint8 simpleProfilechar2UUID[ATT_BT_UUID_SIZE] =
|
||||
{
|
||||
LO_UINT16(SIMPLEPROFILE_CHAR2_UUID), HI_UINT16(SIMPLEPROFILE_CHAR2_UUID)
|
||||
};
|
||||
|
||||
// Characteristic 3 UUID: 0xFFF3
|
||||
CONST uint8 simpleProfilechar3UUID[ATT_BT_UUID_SIZE] =
|
||||
{
|
||||
LO_UINT16(SIMPLEPROFILE_CHAR3_UUID), HI_UINT16(SIMPLEPROFILE_CHAR3_UUID)
|
||||
};
|
||||
|
||||
// Characteristic 4 UUID: 0xFFF4
|
||||
CONST uint8 simpleProfilechar4UUID[ATT_BT_UUID_SIZE] =
|
||||
{
|
||||
LO_UINT16(SIMPLEPROFILE_CHAR4_UUID), HI_UINT16(SIMPLEPROFILE_CHAR4_UUID)
|
||||
};
|
||||
|
||||
// Characteristic 5 UUID: 0xFFF5
|
||||
CONST uint8 simpleProfilechar5UUID[ATT_BT_UUID_SIZE] =
|
||||
{
|
||||
LO_UINT16(SIMPLEPROFILE_CHAR5_UUID), HI_UINT16(SIMPLEPROFILE_CHAR5_UUID)
|
||||
};
|
||||
|
||||
|
||||
|
||||
// GAP GATT Attributes
|
||||
uint8 attDeviceName[BLE_DEVICE_NAME_LEN] = "BLV-C1 RCU:8888";
|
||||
|
||||
|
||||
static simpleProfileCBs_t *simpleProfile_AppCBs = NULL;
|
||||
|
||||
/*********************************************************************
|
||||
* Profile Attributes - variables
|
||||
*/
|
||||
|
||||
// Simple Profile Service attribute
|
||||
static CONST gattAttrType_t simpleProfileService = { ATT_BT_UUID_SIZE, simpleProfileServUUID };
|
||||
|
||||
|
||||
// Simple Profile Characteristic 1 Properties
|
||||
static uint8 simpleProfileChar1Props = GATT_PROP_WRITE;
|
||||
|
||||
// Characteristic 1 Value
|
||||
static uint8 simpleProfileChar1[SIMPLEPROFILE_CHAR1_LEN] = { 0 };
|
||||
|
||||
// Simple Profile Characteristic 1 User Description
|
||||
static uint8 simpleProfileChar1UserDesp[] = "Characteristic 1\0";
|
||||
|
||||
|
||||
// Simple Profile Characteristic 2 Properties
|
||||
//static uint8 simpleProfileChar2Props = GATT_PROP_READ;
|
||||
static uint8 simpleProfileChar2Props = GATT_PROP_READ | GATT_PROP_WRITE;
|
||||
|
||||
// Characteristic 2 Value
|
||||
static uint8 simpleProfileChar2[SIMPLEPROFILE_CHAR2_LEN] = {192,168,1,202};
|
||||
|
||||
// Simple Profile Characteristic 2 User Description
|
||||
static uint8 simpleProfileChar2UserDesp[] = "Characteristic 2, R/W ip addr\0";
|
||||
|
||||
|
||||
// Simple Profile Characteristic 3 Properties
|
||||
static uint8 simpleProfileChar3Props = GATT_PROP_READ | GATT_PROP_WRITE;
|
||||
|
||||
// Characteristic 3 Value
|
||||
//static uint8 simpleProfileChar3[SIMPLEPROFILE_CHAR3_LEN] = { 0 };
|
||||
|
||||
// Simple Profile Characteristic 3 User Description
|
||||
static uint8 simpleProfileChar3UserDesp[] = "Characteristic 3 R/W dev_name MAXlen:20\0";
|
||||
|
||||
|
||||
// Simple Profile Characteristic 4 Properties
|
||||
static uint8 simpleProfileChar4Props = GATT_PROP_NOTIFY;
|
||||
|
||||
// Characteristic 4 Value
|
||||
static uint8 simpleProfileChar4[SIMPLEPROFILE_CHAR4_LEN] = { 0 };
|
||||
|
||||
// Simple Profile Characteristic 4 Configuration Each client has its own
|
||||
// instantiation of the Client Characteristic Configuration. Reads of the
|
||||
// Client Characteristic Configuration only shows the configuration for
|
||||
// that client and writes only affect the configuration of that client.
|
||||
static gattCharCfg_t simpleProfileChar4Config[4];
|
||||
|
||||
// Simple Profile Characteristic 4 User Description
|
||||
static uint8 simpleProfileChar4UserDesp[] = "Characteristic 4\0";
|
||||
|
||||
|
||||
// Simple Profile Characteristic 5 Properties
|
||||
static uint8 simpleProfileChar5Props = GATT_PROP_READ | GATT_PROP_WRITE;
|
||||
|
||||
// Characteristic 5 Value
|
||||
static uint8 simpleProfileChar5[SIMPLEPROFILE_CHAR5_LEN] = { 0 };
|
||||
|
||||
// Simple Profile Characteristic 5 User Description
|
||||
static uint8 simpleProfileChar5UserDesp[] = "Characteristic 5 R/W DHCP ENABLE\0";
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* Profile Attributes - Table
|
||||
*/
|
||||
|
||||
static gattAttribute_t simpleProfileAttrTbl[] =
|
||||
{
|
||||
/*******************<2A><><EFBFBD><EFBFBD>**************************************************************************************************/
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, primaryServiceUUID }, /* type */
|
||||
GATT_PERMIT_READ, /* permissions */
|
||||
0, /* handle */
|
||||
(uint8 *)&simpleProfileService /* pValue */ //FFE0
|
||||
},
|
||||
|
||||
/*****************<2A><><EFBFBD><EFBFBD>1*************************************************************/
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, characterUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
&simpleProfileChar1Props //ֻд
|
||||
},
|
||||
|
||||
// Characteristic Value 1
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, simpleProfilechar1UUID }, //FFE1
|
||||
GATT_PERMIT_WRITE,
|
||||
0,
|
||||
simpleProfileChar1 //<2F><>Ҫд<D2AA><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
},
|
||||
|
||||
// Characteristic 1 User Description
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, charUserDescUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar1UserDesp //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
|
||||
},
|
||||
|
||||
/*****************<2A><><EFBFBD><EFBFBD>2*************************************************************/
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, characterUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
&simpleProfileChar2Props //<2F><>д<EFBFBD><D0B4><EFBFBD><EFBFBD>
|
||||
},
|
||||
|
||||
// Characteristic Value 2
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, simpleProfilechar2UUID }, //0xFFE2
|
||||
GATT_PERMIT_READ | GATT_PERMIT_WRITE,
|
||||
0,
|
||||
simpleProfileChar2 //<2F><>Ҫ<EFBFBD><D2AA>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD>ip<69><70>ַ)
|
||||
},
|
||||
|
||||
// Characteristic 2 User Description
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, charUserDescUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar2UserDesp //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
|
||||
},
|
||||
|
||||
/*****************<2A><><EFBFBD><EFBFBD>3*************************************************************/
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, characterUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
&simpleProfileChar3Props //<2F><>д<EFBFBD><D0B4><EFBFBD><EFBFBD>
|
||||
},
|
||||
|
||||
// Characteristic Value 3
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, simpleProfilechar3UUID }, //0xFFE3
|
||||
GATT_PERMIT_READ | GATT_PERMIT_WRITE,
|
||||
0,
|
||||
attDeviceName //<2F><>Ҫд<D2AA><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// &dataFlash_save_t.scanRspData[2]
|
||||
},
|
||||
|
||||
// Characteristic 3 User Description
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, charUserDescUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar3UserDesp //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
|
||||
},
|
||||
|
||||
/*****************<2A><><EFBFBD><EFBFBD>4*************************************************************/
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, characterUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
&simpleProfileChar4Props //֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD>
|
||||
},
|
||||
|
||||
// Characteristic Value 4
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, simpleProfilechar4UUID }, //0xFFE4
|
||||
0,
|
||||
0,
|
||||
simpleProfileChar4 //<2F><>Ҫ֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
},
|
||||
|
||||
// Characteristic 4 configuration
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, clientCharCfgUUID },
|
||||
GATT_PERMIT_READ | GATT_PERMIT_WRITE,
|
||||
0,
|
||||
(uint8 *)simpleProfileChar4Config //<2F><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
},
|
||||
|
||||
// Characteristic 4 User Description
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, charUserDescUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar4UserDesp //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>4<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
|
||||
},
|
||||
|
||||
/*****************<2A><><EFBFBD><EFBFBD>5*************************************************************/
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, characterUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
&simpleProfileChar5Props //<2F><>д<EFBFBD><D0B4><EFBFBD><EFBFBD>
|
||||
},
|
||||
|
||||
// Characteristic Value 5
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, simpleProfilechar5UUID }, //0xFFE5
|
||||
GATT_PERMIT_READ | GATT_PERMIT_WRITE, //<2F><>д
|
||||
0,
|
||||
simpleProfileChar5 //<2F><>Ҫ<EFBFBD><D2AA>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
},
|
||||
|
||||
// Characteristic 5 User Description
|
||||
{
|
||||
{ ATT_BT_UUID_SIZE, charUserDescUUID },
|
||||
GATT_PERMIT_READ,
|
||||
0,
|
||||
simpleProfileChar5UserDesp //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>5<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
|
||||
},
|
||||
};
|
||||
|
||||
/*********************************************************************
|
||||
* LOCAL FUNCTIONS
|
||||
*/
|
||||
static bStatus_t simpleProfile_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
|
||||
uint8 *pValue, uint16 *pLen, uint16 offset, uint16 maxLen,uint8 method );
|
||||
static bStatus_t simpleProfile_WriteAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
|
||||
uint8 *pValue, uint16 len, uint16 offset,uint8 method );
|
||||
|
||||
static void simpleProfile_HandleConnStatusCB( uint16 connHandle, uint8 changeType );
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* PROFILE CALLBACKS
|
||||
*/
|
||||
// Simple Profile Service Callbacks
|
||||
gattServiceCBs_t simpleProfileCBs =
|
||||
{
|
||||
simpleProfile_ReadAttrCB, // Read callback function pointer
|
||||
simpleProfile_WriteAttrCB, // Write callback function pointer
|
||||
NULL // Authorization callback function pointer
|
||||
};
|
||||
|
||||
/*********************************************************************
|
||||
* PUBLIC FUNCTIONS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* @fn SimpleProfile_AddService
|
||||
*
|
||||
* @brief Initializes the Simple Profile service by registering
|
||||
* GATT attributes with the GATT server.
|
||||
*
|
||||
* @param services - services to add. This is a bit map and can
|
||||
* contain more than one service.
|
||||
*
|
||||
* @return Success or Failure
|
||||
*/
|
||||
bStatus_t SimpleProfile_AddService( uint32 services )
|
||||
{
|
||||
uint8 status = SUCCESS;
|
||||
|
||||
// Initialize Client Characteristic Configuration attributes
|
||||
//<2F><>ʼ<EFBFBD><CABC><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
GATTServApp_InitCharCfg( INVALID_CONNHANDLE, simpleProfileChar4Config );
|
||||
|
||||
// Register with Link DB to receive link status change callback
|
||||
linkDB_Register( simpleProfile_HandleConnStatusCB ); //ʹ<>ô˺<C3B4><CBBA><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ջص<D5BB><D8B5><EFBFBD>
|
||||
|
||||
if ( services & SIMPLEPROFILE_SERVICE )
|
||||
{
|
||||
// Register GATT attribute list and CBs with GATT Server App
|
||||
status = GATTServApp_RegisterService( simpleProfileAttrTbl,
|
||||
GATT_NUM_ATTRS( simpleProfileAttrTbl ),
|
||||
GATT_MAX_ENCRYPT_KEY_SIZE,
|
||||
&simpleProfileCBs );
|
||||
}
|
||||
|
||||
return ( status );
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* @fn SimpleProfile_RegisterAppCBs
|
||||
*
|
||||
* @brief Registers the application callback function. Only call
|
||||
* this function once.
|
||||
*
|
||||
* @param callbacks - pointer to application callbacks.
|
||||
*
|
||||
* @return SUCCESS or bleAlreadyInRequestedMode
|
||||
*/
|
||||
bStatus_t SimpleProfile_RegisterAppCBs( simpleProfileCBs_t *appCallbacks )
|
||||
{
|
||||
if ( appCallbacks )
|
||||
{
|
||||
simpleProfile_AppCBs = appCallbacks;
|
||||
|
||||
return ( SUCCESS );
|
||||
}
|
||||
else
|
||||
{
|
||||
return ( bleAlreadyInRequestedMode );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* @fn SimpleProfile_SetParameter
|
||||
*
|
||||
* @brief Set a Simple Profile parameter.
|
||||
*
|
||||
* @param param - Profile parameter ID
|
||||
* @param len - length of data to right
|
||||
* @param value - pointer to data to write. This is dependent on
|
||||
* the parameter ID and WILL be cast to the appropriate
|
||||
* data type (example: data type of uint16 will be cast to
|
||||
* uint16 pointer).
|
||||
*
|
||||
* @return bStatus_t
|
||||
*/
|
||||
bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value )
|
||||
{
|
||||
bStatus_t ret = SUCCESS;
|
||||
switch ( param )
|
||||
{
|
||||
case SIMPLEPROFILE_CHAR1:
|
||||
if ( len == SIMPLEPROFILE_CHAR1_LEN )
|
||||
{
|
||||
tmos_memcpy( simpleProfileChar1, value, SIMPLEPROFILE_CHAR1_LEN );
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = bleInvalidRange;
|
||||
}
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR2:
|
||||
if ( len == SIMPLEPROFILE_CHAR2_LEN )
|
||||
{
|
||||
tmos_memcpy( simpleProfileChar2, value, SIMPLEPROFILE_CHAR2_LEN );
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = bleInvalidRange;
|
||||
}
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR3:
|
||||
if ( len < BLE_DEVICE_NAME_LEN )
|
||||
{
|
||||
// tmos_memcpy( &dataFlash_save_t.scanRspData[2], value, len ); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
tmos_memcpy( attDeviceName, value, len ); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
else
|
||||
{
|
||||
// tmos_memcpy( &dataFlash_save_t.scanRspData[2], value, BLE_DEVICE_NAME_LEN ); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
tmos_memcpy( attDeviceName, value, BLE_DEVICE_NAME_LEN ); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR4:
|
||||
if ( len == SIMPLEPROFILE_CHAR4_LEN )
|
||||
{
|
||||
tmos_memcpy( simpleProfileChar4, value, SIMPLEPROFILE_CHAR4_LEN );
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = bleInvalidRange;
|
||||
}
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR5:
|
||||
if ( len == SIMPLEPROFILE_CHAR5_LEN )
|
||||
{
|
||||
tmos_memcpy( simpleProfileChar5, value, SIMPLEPROFILE_CHAR5_LEN );
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = bleInvalidRange;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
ret = INVALIDPARAMETER;
|
||||
break;
|
||||
}
|
||||
|
||||
return ( ret );
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn SimpleProfile_GetParameter
|
||||
*
|
||||
* @brief Get a Simple Profile parameter.
|
||||
*
|
||||
* @param param - Profile parameter ID
|
||||
* @param value - pointer to data to put. This is dependent on
|
||||
* the parameter ID and WILL be cast to the appropriate
|
||||
* data type (example: data type of uint16 will be cast to
|
||||
* uint16 pointer).
|
||||
*
|
||||
* @return bStatus_t
|
||||
*/
|
||||
bStatus_t SimpleProfile_GetParameter( uint8 param, void *value )
|
||||
{
|
||||
bStatus_t ret = SUCCESS;
|
||||
switch ( param )
|
||||
{
|
||||
case SIMPLEPROFILE_CHAR1:
|
||||
tmos_memcpy( value, simpleProfileChar1, SIMPLEPROFILE_CHAR1_LEN );
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR2:
|
||||
tmos_memcpy( value, simpleProfileChar2, SIMPLEPROFILE_CHAR2_LEN );
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR3:
|
||||
// tmos_memcpy( value, &dataFlash_save_t.scanRspData[2], dataFlash_save_t.bleName_len ); //<2F><>ȡ<EFBFBD>豸<EFBFBD><E8B1B8>
|
||||
tmos_memcpy( value, attDeviceName, strlen((char*)attDeviceName) ); //<2F><>ȡ<EFBFBD>豸<EFBFBD><E8B1B8>
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR4:
|
||||
tmos_memcpy( value, simpleProfileChar4, SIMPLEPROFILE_CHAR4_LEN );
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR5:
|
||||
tmos_memcpy( value, simpleProfileChar5, SIMPLEPROFILE_CHAR5_LEN );
|
||||
break;
|
||||
|
||||
default:
|
||||
ret = INVALIDPARAMETER;
|
||||
break;
|
||||
}
|
||||
|
||||
return ( ret );
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn simpleProfile_Notify
|
||||
*
|
||||
* @brief Send a notification containing a heart rate
|
||||
* measurement.
|
||||
*
|
||||
* @param connHandle - connection handle
|
||||
* @param pNoti - pointer to notification structure
|
||||
*
|
||||
* @return Success or Failure
|
||||
*/
|
||||
bStatus_t simpleProfile_Notify( uint16 connHandle, attHandleValueNoti_t *pNoti )
|
||||
{
|
||||
uint16 value = GATTServApp_ReadCharCfg( connHandle, simpleProfileChar4Config );
|
||||
|
||||
// If notifications enabled
|
||||
if ( value & GATT_CLIENT_CFG_NOTIFY )
|
||||
{
|
||||
// Set the handle
|
||||
pNoti->handle = simpleProfileAttrTbl[SIMPLEPROFILE_CHAR4_VALUE_POS].handle;
|
||||
|
||||
// Send the notification
|
||||
return GATT_Notification( connHandle, pNoti, FALSE );
|
||||
}
|
||||
return bleIncorrectMode;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn simpleProfile_ReadAttrCB
|
||||
*
|
||||
* @brief Read an attribute.
|
||||
*
|
||||
* @param connHandle - connection message was received on
|
||||
* @param pAttr - pointer to attribute
|
||||
* @param pValue - pointer to data to be read
|
||||
* @param pLen - length of data to be read
|
||||
* @param offset - offset of the first octet to be read
|
||||
* @param maxLen - maximum length of data to be read
|
||||
*
|
||||
* @return Success or Failure
|
||||
*/
|
||||
static bStatus_t simpleProfile_ReadAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
|
||||
uint8 *pValue, uint16 *pLen, uint16 offset, uint16 maxLen,uint8 method )
|
||||
{
|
||||
bStatus_t status = SUCCESS;
|
||||
|
||||
// If attribute permissions require authorization to read, return error
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȩ<EFBFBD><C8A8><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>Ȩ<EFBFBD><C8A8><EFBFBD>ܶ<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>ش<F2B7B5BB><D8B4><EFBFBD>
|
||||
if ( gattPermitAuthorRead( pAttr->permissions ) )
|
||||
{
|
||||
// Insufficient authorization
|
||||
return ( ATT_ERR_INSUFFICIENT_AUTHOR );
|
||||
}
|
||||
|
||||
// Make sure it's not a blob operation (no attributes in the profile are long)
|
||||
if ( offset > 0 )
|
||||
{
|
||||
return ( ATT_ERR_ATTR_NOT_LONG );
|
||||
}
|
||||
|
||||
if ( pAttr->type.len == ATT_BT_UUID_SIZE )
|
||||
{
|
||||
// 16-bit UUID
|
||||
uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
|
||||
switch ( uuid )
|
||||
{
|
||||
// No need for "GATT_SERVICE_UUID" or "GATT_CLIENT_CHAR_CFG_UUID" cases;
|
||||
// gattserverapp handles those reads
|
||||
|
||||
// characteristics 1 and 2 have read permissions
|
||||
// characteritisc 3 does not have read permissions; therefore it is not
|
||||
// included here
|
||||
// characteristic 4 does not have read permissions, but because it
|
||||
// can be sent as a notification, it is included here
|
||||
case SIMPLEPROFILE_CHAR1_UUID:
|
||||
*pLen = SIMPLEPROFILE_CHAR1_LEN;
|
||||
tmos_memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR1_LEN );
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR2_UUID:
|
||||
*pLen = SIMPLEPROFILE_CHAR2_LEN;
|
||||
tmos_memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR2_LEN );
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR3_UUID:
|
||||
*pLen = strlen((char*)attDeviceName);
|
||||
// *pLen = dataFlash_save_t.bleName_len;
|
||||
tmos_memcpy( pValue, pAttr->pValue, *pLen );
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR4_UUID:
|
||||
*pLen = SIMPLEPROFILE_CHAR4_LEN;
|
||||
tmos_memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR4_LEN );
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR5_UUID:
|
||||
*pLen = SIMPLEPROFILE_CHAR5_LEN;
|
||||
tmos_memcpy( pValue, pAttr->pValue, SIMPLEPROFILE_CHAR5_LEN );
|
||||
break;
|
||||
|
||||
default:
|
||||
// Should never get here! (characteristics 3 and 4 do not have read permissions)
|
||||
*pLen = 0;
|
||||
status = ATT_ERR_ATTR_NOT_FOUND;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 128-bit UUID
|
||||
*pLen = 0;
|
||||
status = ATT_ERR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
return ( status );
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn simpleProfile_WriteAttrCB
|
||||
*
|
||||
* @brief Validate attribute data prior to a write operation
|
||||
*
|
||||
* @param connHandle - connection message was received on
|
||||
* @param pAttr - pointer to attribute
|
||||
* @param pValue - pointer to data to be written
|
||||
* @param len - length of data
|
||||
* @param offset - offset of the first octet to be written
|
||||
*
|
||||
* @return Success or Failure
|
||||
*/
|
||||
static bStatus_t simpleProfile_WriteAttrCB( uint16 connHandle, gattAttribute_t *pAttr,
|
||||
uint8 *pValue, uint16 len, uint16 offset,uint8 method )
|
||||
{
|
||||
bStatus_t status = SUCCESS;
|
||||
uint8 notifyApp = 0xFF;
|
||||
|
||||
// If attribute permissions require authorization to write, return error
|
||||
if ( gattPermitAuthorWrite( pAttr->permissions ) )
|
||||
{
|
||||
// Insufficient authorization
|
||||
return ( ATT_ERR_INSUFFICIENT_AUTHOR );
|
||||
}
|
||||
|
||||
if ( pAttr->type.len == ATT_BT_UUID_SIZE )
|
||||
{
|
||||
// 16-bit UUID
|
||||
uint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);
|
||||
switch ( uuid )
|
||||
{
|
||||
case SIMPLEPROFILE_CHAR1_UUID:
|
||||
//Validate the value
|
||||
// Make sure it's not a blob oper
|
||||
if ( offset == 0 )
|
||||
{
|
||||
if ( len > SIMPLEPROFILE_CHAR1_LEN )
|
||||
{
|
||||
status = ATT_ERR_INVALID_VALUE_SIZE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
status = ATT_ERR_ATTR_NOT_LONG;
|
||||
}
|
||||
|
||||
//Write the value
|
||||
if ( status == SUCCESS )
|
||||
{
|
||||
tmos_memcpy( pAttr->pValue, pValue, SIMPLEPROFILE_CHAR1_LEN );
|
||||
if(ble_send_info.BLE_WriteAddr != NULL )
|
||||
{
|
||||
SRAM_Write_Byte(len, ble_send_info.BLE_WriteAddr); //<2F><><EFBFBD>ճ<EFBFBD><D5B3><EFBFBD>
|
||||
SRAM_Write_Buff(pValue, len, ble_send_info.BLE_WriteAddr +1); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
ble_send_info.BLE_WriteAddr += BLE_BUFF_MAX_LEN;
|
||||
if(ble_send_info.BLE_WriteAddr >= SRAM_BLE_RECEIVE_END)
|
||||
{
|
||||
ble_send_info.BLE_WriteAddr = SRAM_BLE_RECEIVE_START;
|
||||
}
|
||||
}
|
||||
notifyApp = SIMPLEPROFILE_CHAR1;
|
||||
}
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR2_UUID:
|
||||
if ( offset == 0 )
|
||||
{
|
||||
if ( len > SIMPLEPROFILE_CHAR2_LEN )
|
||||
{
|
||||
status = ATT_ERR_INVALID_VALUE_SIZE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
status = ATT_ERR_ATTR_NOT_LONG;
|
||||
}
|
||||
|
||||
//Write the value
|
||||
if ( status == SUCCESS )
|
||||
{
|
||||
// if(server_info.ip_auto_flg == 1) //<2F><><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>ip
|
||||
// {
|
||||
// //tmos_memcpy( pAttr->pValue, pValue, SIMPLEPROFILE_CHAR2_LEN );
|
||||
// if(memcmp(net_info.local_ip, pValue, SIMPLEPROFILE_CHAR2_LEN) != 0) //ble<6C><EFBFBD>ip<69><70><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// {
|
||||
// memcpy(net_info.local_ip, pValue, SIMPLEPROFILE_CHAR2_LEN);
|
||||
// Dbg_Print(DBG_BIT_NET_STATUS_bit,"ble, NetWork_Restart!\n");
|
||||
// NetWork_Restart(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// server_info.ble_setip_flg = 1; //<2F><><EFBFBD><EFBFBD>ble<6C><EFBFBD>ip
|
||||
// }
|
||||
// notifyApp = SIMPLEPROFILE_CHAR2;
|
||||
// }
|
||||
// else status = ATT_ERR_WRITE_NOT_PERMITTED;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR3_UUID:
|
||||
//Validate the value
|
||||
// Make sure it's not a blob oper
|
||||
if ( offset == 0 )
|
||||
{
|
||||
// if ( len > BLE_DEVICE_NAME_LEN )
|
||||
// {
|
||||
// status = ATT_ERR_INVALID_VALUE_SIZE;
|
||||
// }
|
||||
}
|
||||
else
|
||||
{
|
||||
status = ATT_ERR_ATTR_NOT_LONG;
|
||||
}
|
||||
|
||||
//Write the value
|
||||
if ( status == SUCCESS )
|
||||
{
|
||||
if ( len >= BLE_DEVICE_NAME_LEN )
|
||||
{
|
||||
tmos_memcpy( pAttr->pValue, pValue, BLE_DEVICE_NAME_LEN );
|
||||
// Set_BleDevice_Name(pValue, BLE_DEVICE_NAME_LEN);
|
||||
}
|
||||
else
|
||||
{
|
||||
tmos_memset(pAttr->pValue, 0, BLE_DEVICE_NAME_LEN);
|
||||
tmos_memcpy( pAttr->pValue, pValue, len );
|
||||
|
||||
// Set_BleDevice_Name(pValue, len);
|
||||
}
|
||||
|
||||
notifyApp = SIMPLEPROFILE_CHAR3;
|
||||
}
|
||||
break;
|
||||
|
||||
case SIMPLEPROFILE_CHAR5_UUID:
|
||||
if ( offset == 0 )
|
||||
{
|
||||
if ( len > SIMPLEPROFILE_CHAR5_LEN )
|
||||
{
|
||||
status = ATT_ERR_INVALID_VALUE_SIZE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
status = ATT_ERR_ATTR_NOT_LONG;
|
||||
}
|
||||
|
||||
//Write the value
|
||||
if ( status == SUCCESS )
|
||||
{
|
||||
// tmos_memcpy( pAttr->pValue, pValue, SIMPLEPROFILE_CHAR5_LEN ); //<2F><EFBFBD>ip<69><70>ȡ<EFBFBD><C8A1>ʽ
|
||||
// server_info.ip_auto_flg = *pValue;
|
||||
notifyApp = SIMPLEPROFILE_CHAR5;
|
||||
}
|
||||
break;
|
||||
|
||||
case GATT_CLIENT_CHAR_CFG_UUID:
|
||||
status = GATTServApp_ProcessCCCWriteReq( connHandle, pAttr, pValue, len,
|
||||
offset, GATT_CLIENT_CFG_NOTIFY );
|
||||
break;
|
||||
|
||||
default:
|
||||
// Should never get here! (characteristics 2 and 4 do not have write permissions)
|
||||
status = ATT_ERR_ATTR_NOT_FOUND;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 128-bit UUID
|
||||
status = ATT_ERR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
// If a charactersitic value changed then callback function to notify application of change
|
||||
if ( (notifyApp != 0xFF ) && simpleProfile_AppCBs && simpleProfile_AppCBs->pfnSimpleProfileChange )
|
||||
{
|
||||
simpleProfile_AppCBs->pfnSimpleProfileChange( notifyApp );
|
||||
}
|
||||
|
||||
return ( status );
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn simpleProfile_HandleConnStatusCB
|
||||
*
|
||||
* @brief Simple Profile link status change handler function.
|
||||
*
|
||||
* @param connHandle - connection handle
|
||||
* @param changeType - type of change
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
static void simpleProfile_HandleConnStatusCB( uint16 connHandle, uint8 changeType )
|
||||
{
|
||||
// Make sure this is not loopback connection
|
||||
//ȷ<><C8B7><EFBFBD>ⲻ<EFBFBD>ǻ<EFBFBD><C7BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if ( connHandle != LOOPBACK_CONNHANDLE )
|
||||
{
|
||||
// Reset Client Char Config if connection has dropped
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѶϿ<D1B6><CFBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿͻ<C3BF><CDBB><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>
|
||||
if ( ( changeType == LINKDB_STATUS_UPDATE_REMOVED ) ||
|
||||
( ( changeType == LINKDB_STATUS_UPDATE_STATEFLAGS ) &&
|
||||
( !linkDB_Up( connHandle ) ) ) )
|
||||
{
|
||||
GATTServApp_InitCharCfg( connHandle, simpleProfileChar4Config );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************
|
||||
*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ble_Parameter_Init
|
||||
*<2A><> <20>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
||||
*<2A><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>
|
||||
*****************************************/
|
||||
void Ble_Parameter_Init()
|
||||
{
|
||||
ble_send_info.BLE_WriteAddr = SRAM_BLE_RECEIVE_START;
|
||||
ble_send_info.BLE_ReadAddr = SRAM_BLE_RECEIVE_START;
|
||||
ble_send_info.BLE_SendAddr = SRAM_BLE_SEND_START;
|
||||
}
|
||||
|
||||
/*****************************************
|
||||
*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ble_Recive_Task
|
||||
*<2A><> <20>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>մ<EFBFBD><D5B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*<2A><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>
|
||||
*****************************************/
|
||||
void Ble_Recive_Task(void)
|
||||
{
|
||||
if(ble_send_info.BLE_ReadAddr != ble_send_info.BLE_WriteAddr)
|
||||
{
|
||||
uint8_t len = SRAM_Read_Byte(ble_send_info.BLE_ReadAddr);
|
||||
uint8_t* data = malloc(len);
|
||||
if(data == NULL) return;
|
||||
SRAM_Read_Buff(data, len, ble_send_info.BLE_ReadAddr +1); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
PRINT("Ble Recive data: %s, len: %d\r\n", data, len); //<2F><><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>
|
||||
|
||||
// if(mqtt_info.con_flag) //<2F><><EFBFBD><EFBFBD><EFBFBD>Ӱ<EFBFBD><D3B0><EFBFBD><EFBFBD><EFBFBD>
|
||||
// MQTT_Publish(mqtt_info.mqtt_socket, mqtt_info.pub_topic, (uint8*)data, len, 0); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݷ<EFBFBD><DDB7>͵<EFBFBD><CDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
free(data);
|
||||
// if(ble_send_info.send_flg == 0)
|
||||
// {
|
||||
// memcpy(ble_send_info.sendDATA, &BLE_ReadAddr[1], BLE_ReadAddr[0]); //<2F><><EFBFBD><EFBFBD><CDB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӻ<EFBFBD>
|
||||
// ble_send_info.sendLEN = BLE_ReadAddr[0];
|
||||
// ble_send_info.ble_type = BLE_TYPE_PERIPHERAL;
|
||||
// ble_send_info.device_type = 0x01; //<2F>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>
|
||||
// ble_send_info.device_addr = 0x00; //<2F>豸<EFBFBD><E8B1B8>ַ
|
||||
// ble_send_info.char_uuid = SIMPLEPROFILE_CHAR1_UUID;
|
||||
// ble_send_info.send_flg = 1;
|
||||
// }
|
||||
|
||||
ble_send_info.BLE_ReadAddr += BLE_BUFF_MAX_LEN;
|
||||
if(ble_send_info.BLE_ReadAddr > SRAM_BLE_RECEIVE_END)
|
||||
{
|
||||
ble_send_info.BLE_ReadAddr = SRAM_BLE_RECEIVE_START;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*********************************************************************/
|
||||
108
BasicCode/Drive/BLE/PROFILE/include/devinfoservice.h
Normal file
108
BasicCode/Drive/BLE/PROFILE/include/devinfoservice.h
Normal file
@@ -0,0 +1,108 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : devinfoservice.h
|
||||
* Author : WCH
|
||||
* Version : V1.0
|
||||
* Date : 2018/12/11
|
||||
* Description :
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef DEVINFOSERVICE_H
|
||||
#define DEVINFOSERVICE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
* INCLUDES
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* CONSTANTS
|
||||
*/
|
||||
|
||||
// Device Information Service Parameters
|
||||
#define DEVINFO_SYSTEM_ID 0
|
||||
#define DEVINFO_MODEL_NUMBER 1
|
||||
#define DEVINFO_SERIAL_NUMBER 2
|
||||
#define DEVINFO_FIRMWARE_REV 3
|
||||
#define DEVINFO_HARDWARE_REV 4
|
||||
#define DEVINFO_SOFTWARE_REV 5
|
||||
#define DEVINFO_MANUFACTURER_NAME 6
|
||||
#define DEVINFO_11073_CERT_DATA 7
|
||||
#define DEVINFO_PNP_ID 8
|
||||
|
||||
// IEEE 11073 authoritative body values
|
||||
#define DEVINFO_11073_BODY_EMPTY 0
|
||||
#define DEVINFO_11073_BODY_IEEE 1
|
||||
#define DEVINFO_11073_BODY_CONTINUA 2
|
||||
#define DEVINFO_11073_BODY_EXP 254
|
||||
|
||||
// System ID length
|
||||
#define DEVINFO_SYSTEM_ID_LEN 8
|
||||
|
||||
// PnP ID length
|
||||
#define DEVINFO_PNP_ID_LEN 7
|
||||
|
||||
/*********************************************************************
|
||||
* TYPEDEFS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* MACROS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* Profile Callbacks
|
||||
*/
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* API FUNCTIONS
|
||||
*/
|
||||
|
||||
/*
|
||||
* DevInfo_AddService- Initializes the Device Information service by registering
|
||||
* GATT attributes with the GATT server.
|
||||
*
|
||||
*/
|
||||
|
||||
extern bStatus_t DevInfo_AddService( void );
|
||||
|
||||
/*********************************************************************
|
||||
* @fn DevInfo_SetParameter
|
||||
*
|
||||
* @brief Set a Device Information parameter.
|
||||
*
|
||||
* @param param - Profile parameter ID
|
||||
* @param len - length of data to right
|
||||
* @param value - pointer to data to write. This is dependent on
|
||||
* the parameter ID and WILL be cast to the appropriate
|
||||
* data type (example: data type of uint16 will be cast to
|
||||
* uint16 pointer).
|
||||
*
|
||||
* @return bStatus_t
|
||||
*/
|
||||
bStatus_t DevInfo_SetParameter( uint8 param, uint8 len, void *value );
|
||||
|
||||
/*
|
||||
* DevInfo_GetParameter - Get a Device Information parameter.
|
||||
*
|
||||
* param - Profile parameter ID
|
||||
* value - pointer to data to write. This is dependent on
|
||||
* the parameter ID and WILL be cast to the appropriate
|
||||
* data type (example: data type of uint16 will be cast to
|
||||
* uint16 pointer).
|
||||
*/
|
||||
extern bStatus_t DevInfo_GetParameter( uint8 param, void *value );
|
||||
|
||||
/*********************************************************************
|
||||
*********************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* DEVINFOSERVICE_H */
|
||||
226
BasicCode/Drive/BLE/PROFILE/include/gattprofile.h
Normal file
226
BasicCode/Drive/BLE/PROFILE/include/gattprofile.h
Normal file
@@ -0,0 +1,226 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : gattprofile.h
|
||||
* Author : WCH
|
||||
* Version : V1.0
|
||||
* Date : 2018/12/11
|
||||
* Description :
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef GATTPROFILE_H
|
||||
#define GATTPROFILE_H
|
||||
#include "CONFIG.h"
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
* INCLUDES
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* CONSTANTS
|
||||
*/
|
||||
|
||||
// Profile Parameters
|
||||
#define SIMPLEPROFILE_CHAR1 0 // RW uint8 - Profile Characteristic 1 value
|
||||
#define SIMPLEPROFILE_CHAR2 1 // RW uint8 - Profile Characteristic 2 value
|
||||
#define SIMPLEPROFILE_CHAR3 2 // RW uint8 - Profile Characteristic 3 value
|
||||
#define SIMPLEPROFILE_CHAR4 3 // RW uint8 - Profile Characteristic 4 value
|
||||
#define SIMPLEPROFILE_CHAR5 4 // RW uint8 - Profile Characteristic 4 value
|
||||
|
||||
// Simple Profile Service UUID
|
||||
#define SIMPLEPROFILE_SERV_UUID 0xFFE0
|
||||
|
||||
// Key Pressed UUID
|
||||
#define SIMPLEPROFILE_CHAR1_UUID 0xFFE1
|
||||
#define SIMPLEPROFILE_CHAR2_UUID 0xFFE2
|
||||
#define SIMPLEPROFILE_CHAR3_UUID 0xFFE3
|
||||
#define SIMPLEPROFILE_CHAR4_UUID 0xFFE4
|
||||
#define SIMPLEPROFILE_CHAR5_UUID 0xFFE5
|
||||
|
||||
// Simple Keys Profile Services bit fields
|
||||
#define SIMPLEPROFILE_SERVICE 0x00000001
|
||||
|
||||
// Length of characteristic in bytes ( Default MTU is 23 )
|
||||
#define SIMPLEPROFILE_CHAR1_LEN BLE_BUFF_MAX_LEN-4
|
||||
#define SIMPLEPROFILE_CHAR2_LEN 4
|
||||
//#define SIMPLEPROFILE_CHAR3_LEN 1
|
||||
#define SIMPLEPROFILE_CHAR4_LEN BLE_BUFF_MAX_LEN-4
|
||||
#define SIMPLEPROFILE_CHAR5_LEN 1
|
||||
|
||||
#define BLE_DEVICE_NAME_LEN (GAP_DEVICE_NAME_LEN - 1) //<2F><><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD>Ƴ<EFBFBD><C6B3><EFBFBD>
|
||||
#define BLE_INFO_NUM 5 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
#define SRAM_BLE_RECEIVE_START 0x031000 //BLE<4C><45><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ
|
||||
#define SRAM_BLE_RECEIVE_END (0x031000 + BLE_BUFF_MAX_LEN*BLE_INFO_NUM -1) //BLE<4C><45><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
||||
#define SRAM_BLE_SEND_START (SRAM_BLE_RECEIVE_END+1) //BLE<4C><45><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ
|
||||
#define SRAM_BLE_SEND_END (SRAM_BLE_SEND_START+BLE_BUFF_MAX_LEN-1) //BLE<4C><45><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ
|
||||
#define SRAM_BLE_SAVE_START (SRAM_BLE_SEND_END+ 1) //BLE<4C><45><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ
|
||||
#define SRAM_BLE_END 0x0313FF //BLE<4C><45><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
||||
|
||||
typedef struct DEVICE_CONFIG* DEVICE_CONFIG_Ptr; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣָ<CFA2><D6B8>
|
||||
|
||||
typedef struct DEVICE_CONFIG{
|
||||
|
||||
uint8 device_type; //<2F>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>
|
||||
uint8 device_addr; //<2F>豸<EFBFBD><E8B1B8>ַ
|
||||
uint8 ble_type:1; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD>0:<3A><><EFBFBD><EFBFBD>/1:<3A>ӻ<EFBFBD>
|
||||
uint8 connect_sta:1; //<2F><><EFBFBD><EFBFBD>״̬<D7B4><CCAC> 1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0<><30>δ<EFBFBD><CEB4><EFBFBD><EFBFBD>
|
||||
uint8 uuid_type:1; //UUID<49><44><EFBFBD>ͣ<EFBFBD>1:128bit<69><74> 0:16bit
|
||||
uint8 connecting:1; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӱ<EFBFBD><D3B1>ǣ<EFBFBD> 1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0<><30>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
uint8 addr_type:3; //<2F><><EFBFBD><EFBFBD>mac<61><63>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>
|
||||
uint8 mac[6]; //<2F><>Ӧ<EFBFBD><D3A6>mac<61><63>ַ
|
||||
uint16 server_uuid; //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>uuid
|
||||
uint16 char_uuid; //<2F><><EFBFBD><EFBFBD>uuid
|
||||
uint8 uuid_128bit[16]; //128bit UUID,<2C><>uuid<69><64><EFBFBD><EFBFBD>Ϊ128bitʱʹ<CAB1><CAB9>
|
||||
DEVICE_CONFIG_Ptr next; //<2F><>һ<EFBFBD><D2BB><EFBFBD>ڵ<EFBFBD>
|
||||
|
||||
}__attribute__ ((__packed__))BLE_DEVICE_CONFIG; //<2F><><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
|
||||
#define BLE_TYPE_CENTRAL 0 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define BLE_TYPE_PERIPHERAL 1 //<2F><><EFBFBD><EFBFBD><EFBFBD>ӻ<EFBFBD>
|
||||
|
||||
#define UUID_TYPE_16BIT 0 //16bit UUID
|
||||
#define UUID_TYPE_128BIT 1 //128bit UUID
|
||||
|
||||
#define BLE_DATA_TYPE_DATA 0 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define BLE_DATA_TYPE_CMD 1 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//typedef struct{
|
||||
//
|
||||
// uint8 ble_type:1; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD><EFBFBD>/<2F>ӻ<EFBFBD>
|
||||
// uint8
|
||||
// uint8 addr:5; //<2F>豸<EFBFBD><E8B1B8>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// uint16 server_uuid; //<2F><><EFBFBD><EFBFBD>uuid
|
||||
// uint16 char_uuid; //<2F><><EFBFBD><EFBFBD>uuid
|
||||
//
|
||||
//}BLE_DEVICE_INFO;
|
||||
typedef enum{
|
||||
BLE_ERR_SUCCESS = 0, //<2F><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>
|
||||
BLE_ERR_WAITING_CONNECT = 1, //<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD>
|
||||
BLE_ERR_WAITING_SEND = 2, //<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD>
|
||||
BLE_ERR_CONNECT_FAIL = 3, //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
|
||||
BLE_ERR_DEVICE_Not_EXIST = 4, //<2F>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
BLE_ERR_FAIL = 5, //<2F><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
|
||||
BLE_ERR_INVALID = 6, //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч
|
||||
|
||||
}BLE_STA;
|
||||
|
||||
#pragma pack(1)
|
||||
typedef struct{
|
||||
|
||||
uint8 ble_type:1; //Ŀ<><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD>0:<3A><><EFBFBD><EFBFBD>/1:<3A>ӻ<EFBFBD>
|
||||
uint8 send_flg:1; //<2F><><EFBFBD>ͱ<EFBFBD>־
|
||||
uint8 wait_connected:1; //<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD>ӱ<EFBFBD>־ 1:<3A>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD>
|
||||
uint8 wait_send:1; //<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD>ͱ<EFBFBD>־ 1:<3A>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD>
|
||||
uint8 data_type:1; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,0:<3A><><EFBFBD><EFBFBD>; 1:<3A><><EFBFBD><EFBFBD>رմӻ<D5B4> NOTIFY<46><59>
|
||||
uint8 send_state:3; //<2F><><EFBFBD><EFBFBD>״̬
|
||||
uint16 wait_count; //<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD>Ӽ<EFBFBD><D3BC><EFBFBD> <20><><EFBFBD><EFBFBD>ֻ<EFBFBD>ܵ<EFBFBD>
|
||||
uint8 device_type; //<2F>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>
|
||||
uint8 device_addr; //<2F>豸<EFBFBD><E8B1B8>ַ
|
||||
// uint8 sendDATA[BLE_BUFF_MAX_LEN]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>
|
||||
// uint8 sendLEN; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
|
||||
uint16 server_handle; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
uint16 char_handle; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
uint8 notify_id:4; //֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD>id(<28><><EFBFBD><EFBFBD>)
|
||||
uint8 write_id:4; //д<><D0B4><EFBFBD><EFBFBD>id(<28><><EFBFBD><EFBFBD>)
|
||||
uint32 BLE_SendAddr; //<2F><><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD>ַ
|
||||
uint32 BLE_WriteAddr; //<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>д<EFBFBD><D0B4>ַ
|
||||
uint32 BLE_ReadAddr; //<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
||||
}BLE_SEND_INFO;
|
||||
|
||||
|
||||
#pragma pack()
|
||||
|
||||
extern BLE_SEND_INFO ble_send_info;
|
||||
extern BLE_DEVICE_CONFIG* Ble_Device_Info_Ptr;
|
||||
/*********************************************************************
|
||||
* TYPEDEFS
|
||||
*/
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* MACROS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* Profile Callbacks
|
||||
*/
|
||||
|
||||
// Callback when a characteristic value has changed
|
||||
typedef void (*simpleProfileChange_t)( uint8 paramID );
|
||||
|
||||
typedef struct
|
||||
{
|
||||
simpleProfileChange_t pfnSimpleProfileChange; // Called when characteristic value changes
|
||||
} simpleProfileCBs_t;
|
||||
|
||||
extern unsigned char attDeviceName[BLE_DEVICE_NAME_LEN];
|
||||
|
||||
/*********************************************************************
|
||||
* API FUNCTIONS
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* SimpleProfile_AddService- Initializes the Simple GATT Profile service by registering
|
||||
* GATT attributes with the GATT server.
|
||||
*
|
||||
* @param services - services to add. This is a bit map and can
|
||||
* contain more than one service.
|
||||
*/
|
||||
|
||||
extern bStatus_t SimpleProfile_AddService( uint32 services );
|
||||
|
||||
/*
|
||||
* SimpleProfile_RegisterAppCBs - Registers the application callback function.
|
||||
* Only call this function once.
|
||||
*
|
||||
* appCallbacks - pointer to application callbacks.
|
||||
*/
|
||||
extern bStatus_t SimpleProfile_RegisterAppCBs( simpleProfileCBs_t *appCallbacks );
|
||||
|
||||
/*
|
||||
* SimpleProfile_SetParameter - Set a Simple GATT Profile parameter.
|
||||
*
|
||||
* param - Profile parameter ID
|
||||
* len - length of data to right
|
||||
* value - pointer to data to write. This is dependent on
|
||||
* the parameter ID and WILL be cast to the appropriate
|
||||
* data type (example: data type of uint16 will be cast to
|
||||
* uint16 pointer).
|
||||
*/
|
||||
extern bStatus_t SimpleProfile_SetParameter( uint8 param, uint8 len, void *value );
|
||||
|
||||
/*
|
||||
* SimpleProfile_GetParameter - Get a Simple GATT Profile parameter.
|
||||
*
|
||||
* param - Profile parameter ID
|
||||
* value - pointer to data to write. This is dependent on
|
||||
* the parameter ID and WILL be cast to the appropriate
|
||||
* data type (example: data type of uint16 will be cast to
|
||||
* uint16 pointer).
|
||||
*/
|
||||
extern bStatus_t SimpleProfile_GetParameter( uint8 param, void *value );
|
||||
|
||||
/*
|
||||
* simpleProfile_Notify - Send notification.
|
||||
*
|
||||
* connHandle - connect handle
|
||||
* pNoti - pointer to structure to notify.
|
||||
*/
|
||||
extern bStatus_t simpleProfile_Notify( uint16 connHandle, attHandleValueNoti_t *pNoti );
|
||||
|
||||
/*********************************************************************
|
||||
*********************************************************************/
|
||||
|
||||
void Ble_Parameter_Init(void);
|
||||
void Ble_Recive_Task(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
107
BasicCode/Drive/BLE/data_save.c
Normal file
107
BasicCode/Drive/BLE/data_save.c
Normal file
@@ -0,0 +1,107 @@
|
||||
#include "data_save.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
DataFlash_Save_T dataFlash_save_t={
|
||||
.flash_save_flg = 0, //<2F><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
|
||||
.flash_save_head = 0, //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ
|
||||
.bleName_len = 15, //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
.scanRspData = {
|
||||
// complete name
|
||||
0x10, // length of this data
|
||||
GAP_ADTYPE_LOCAL_NAME_COMPLETE,
|
||||
'B',
|
||||
'L',
|
||||
'V',
|
||||
'-',
|
||||
'C',
|
||||
'1',
|
||||
' ',
|
||||
'R',
|
||||
'C',
|
||||
'U',
|
||||
':',
|
||||
'8',
|
||||
'8',
|
||||
'8',
|
||||
'8',
|
||||
// connection interval range
|
||||
0x05, // length of this data
|
||||
GAP_ADTYPE_SLAVE_CONN_INTERVAL_RANGE,
|
||||
LO_UINT16( DEFAULT_DESIRED_MIN_CONN_INTERVAL ), // 100ms
|
||||
HI_UINT16( DEFAULT_DESIRED_MIN_CONN_INTERVAL ),
|
||||
LO_UINT16( DEFAULT_DESIRED_MAX_CONN_INTERVAL ), // 1s
|
||||
HI_UINT16( DEFAULT_DESIRED_MAX_CONN_INTERVAL ),
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
void DataFlash_Save_Init()
|
||||
{
|
||||
//DataFlash_Save_T save_t = {0};
|
||||
PRINT("flash head:%X, %X\n", (*(uint8*)DATAFLASH_SAVE_START_ADDR & 3), *(uint8*)DATAFLASH_SAVE_START_ADDR);
|
||||
if( (*(uint8*)DATAFLASH_SAVE_START_ADDR & 3) == FALSH_SAVE_HEAD) //<2F><>ͷ<EFBFBD><CDB7><EFBFBD>ǣ<EFBFBD><C7A3><EFBFBD>flash<73><68><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
PRINT("Read flash\n");
|
||||
memset(&dataFlash_save_t, 0, sizeof(DataFlash_Save_T));
|
||||
memcpy((uint8*)&dataFlash_save_t, (uint8*)DATAFLASH_SAVE_START_ADDR, sizeof(DataFlash_Save_T));
|
||||
|
||||
PRINT("bleName_len:%d\n", dataFlash_save_t.bleName_len);
|
||||
for(int i = 0; i< dataFlash_save_t.bleName_len ; i++)
|
||||
{
|
||||
PRINT("%c", (char)dataFlash_save_t.scanRspData[i+2]);
|
||||
}
|
||||
PRINT("\n");
|
||||
|
||||
}
|
||||
else //<2F><>flashдĬ<D0B4>ϲ<EFBFBD><CFB2><EFBFBD>
|
||||
{
|
||||
dataFlash_save_t.flash_save_flg = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
|
||||
void DataFlash_Save_Task()
|
||||
{
|
||||
if(dataFlash_save_t.flash_save_flg)
|
||||
{
|
||||
PRINT("Write flash\n");
|
||||
dataFlash_save_t.flash_save_flg = 0;
|
||||
dataFlash_save_t.flash_save_head = FALSH_SAVE_HEAD; //дͷ<D0B4><CDB7><EFBFBD><EFBFBD>
|
||||
|
||||
uint8 err = FlashBlockErase(DATAFLASH_SAVE_START_ADDR); //512<31><32><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>
|
||||
if(err) PRINT("Erase flash err:%d\n", err);
|
||||
|
||||
int len = 0;
|
||||
|
||||
if( sizeof(DataFlash_Save_T) %4 != 0) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>4<EFBFBD>ֽڶ<D6BD><DAB6><EFBFBD>
|
||||
{
|
||||
len = sizeof(DataFlash_Save_T) / 4 + 1;
|
||||
}
|
||||
else len = sizeof(DataFlash_Save_T) / 4;
|
||||
|
||||
// PRINT("buff size:%d\n", len);
|
||||
|
||||
uint32* buff = malloc(len);
|
||||
if(buff == NULL) return;
|
||||
|
||||
for(int i = 0; i< len; i++)
|
||||
{
|
||||
buff[i] = 0x00000000;
|
||||
}
|
||||
|
||||
memcpy((uint8*)buff, (uint8*)&dataFlash_save_t, sizeof(DataFlash_Save_T));
|
||||
|
||||
err = FlashWriteBuf(DATAFLASH_SAVE_START_ADDR, buff, len*4);
|
||||
|
||||
if(err) PRINT("Write flash err:%d\n", err);
|
||||
|
||||
free(buff);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
46
BasicCode/Drive/BLE/include/data_save.h
Normal file
46
BasicCode/Drive/BLE/include/data_save.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifndef _DATA_SAVE_H
|
||||
#define _DATA_SAVE_H
|
||||
|
||||
#include "CH57x_common.h" //CH57X <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD>
|
||||
#include "gattprofile.h"
|
||||
#include "PC_DeviceTest_Fun.h"
|
||||
|
||||
#define DATAFLASH_SAVE_START_ADDR FLASH_MCU_BLE_START_ADDRESS //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ dataflash <20><>2K
|
||||
|
||||
// Minimum connection interval (units of 1.25ms, 20=25ms)
|
||||
#define DEFAULT_DESIRED_MIN_CONN_INTERVAL 20
|
||||
|
||||
// Maximum connection interval (units of 1.25ms, 100=125ms)
|
||||
#define DEFAULT_DESIRED_MAX_CONN_INTERVAL 100
|
||||
|
||||
#define FALSH_SAVE_HEAD 2 //flash<73><68><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8 flash_save_head:2; //<2F><><EFBFBD><EFBFBD>flash<73><68><EFBFBD>ݵ<EFBFBD>ͷ
|
||||
uint8 flash_save_flg:1; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
|
||||
uint8 bleName_len:5; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
uint8 scanRspData[31]; //ɨ<><C9A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
}DataFlash_Save_T;
|
||||
|
||||
#pragma pack()
|
||||
|
||||
|
||||
extern DataFlash_Save_T dataFlash_save_t;
|
||||
|
||||
void DataFlash_Save_Init(void);
|
||||
void DataFlash_Save_Task(void);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
97
BasicCode/Drive/BLE/include/multiCentral.h
Normal file
97
BasicCode/Drive/BLE/include/multiCentral.h
Normal file
@@ -0,0 +1,97 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : multiCentral.h
|
||||
* Author : WCH
|
||||
* Version : V1.0
|
||||
* Date : 2018/11/12
|
||||
* Description :
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef MULTICENTRAL_H
|
||||
#define MULTICENTRAL_H
|
||||
#include "gattprofile.h"
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
* INCLUDES
|
||||
*/
|
||||
#define PERIPHERAL_DEVICE_MAX_NUM 30
|
||||
/*********************************************************************
|
||||
* CONSTANTS
|
||||
*/
|
||||
|
||||
// Simple BLE Observer Task Events
|
||||
#define START_DEVICE_EVT 0x0001
|
||||
#define START_DISCOVERY_EVT 0x0002
|
||||
#define START_SCAN_EVT 0x0004
|
||||
#define START_SVC_DISCOVERY_EVT 0x0008
|
||||
#define START_PARAM_UPDATE_EVT 0x0010
|
||||
#define START_READ_OR_WRITE_EVT 0x0020
|
||||
#define START_READ_RSSI_EVT 0x0040
|
||||
#define ESTABLISH_LINK_TIMEOUT_EVT 0x0080
|
||||
|
||||
#define CONNECT0_ITEM 0
|
||||
#define CONNECT1_ITEM 1
|
||||
#define CONNECT2_ITEM 2
|
||||
|
||||
/*********************************************************************
|
||||
* MACROS
|
||||
*/
|
||||
|
||||
#define CENTRAL_CONNECTING 1 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define CENTRAL_IDLE 0 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8 taskID; // Task ID for internal task/event processing
|
||||
uint16 connHandle; // Connection handle of current connection
|
||||
uint8 state; // Application state
|
||||
//uint8 connecting; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӱ<EFBFBD>־
|
||||
uint8 peerAddr[B_ADDR_LEN];
|
||||
uint8 discState; // Discovery state
|
||||
uint8 procedureInProgress; // GATT read/write procedure state
|
||||
uint16 svcStartHdl; // Discovered service start handle
|
||||
uint16 svcEndHdl; // Discovered service end handle
|
||||
uint16 charHdl; // Discovered characteristic handle
|
||||
} centralConnItem_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8 peerAddr[B_ADDR_LEN];
|
||||
} peerAddrDefItem_t;
|
||||
|
||||
extern BLE_DEVICE_CONFIG* Ble_Device_Head;
|
||||
|
||||
/*********************************************************************
|
||||
* FUNCTIONS
|
||||
*/
|
||||
|
||||
/*
|
||||
* Task Initialization for the BLE Application
|
||||
*/
|
||||
extern void Central_Init( void );
|
||||
|
||||
/*
|
||||
* Task Event Processor for the BLE Application
|
||||
*/
|
||||
extern uint16 Central_ProcessEvent( uint8 task_id, uint16 events );
|
||||
|
||||
void Clear_Connecting_flg(u8* addr);
|
||||
void Set_Connecting_flg(u8* addr);
|
||||
|
||||
void BLE_Send_Task(void);
|
||||
void Device_Add_List(BLE_DEVICE_CONFIG* Device_node); //<2F><><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD>ӽ<EFBFBD><D3BD><EFBFBD><EFBFBD><EFBFBD>
|
||||
uint8 IS_Empty_Connection(u8 device_type, u8 device_addr); //<2F><>ѯָ<D1AF><D6B8><EFBFBD>豸<EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
uint8 Connect_Peripheral_Device(u8 device_type, u8 device_addr); //<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>豸
|
||||
uint8 Disconnect_Peripheral_Device(u8 device_type, u8 device_addr); //<2F>Ͽ<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>豸
|
||||
void Peripheral_Notify_Control(u8 device_type, u8 device_addr, u8 notify_id, u8 state); //<2F><EFBFBD><F2BFAABB>ر<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>ӻ<EFBFBD><D3BB>豸<EFBFBD><E8B1B8>֪ͨ
|
||||
/*********************************************************************
|
||||
*********************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* MULTICENTRAL_H */
|
||||
71
BasicCode/Drive/BLE/include/peripheral.h
Normal file
71
BasicCode/Drive/BLE/include/peripheral.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : peripheral.h
|
||||
* Author : WCH
|
||||
* Version : V1.0
|
||||
* Date : 2018/12/11
|
||||
* Description :
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef PERIPHERAL_H
|
||||
#define PERIPHERAL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
#include "CH57x_common.h" //CH57X <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>ļ<EFBFBD>
|
||||
//#include "data_save.h"
|
||||
|
||||
#define BLE_PERIPHERAL_EN 0
|
||||
#define BLE_CENTRAL_EN 1
|
||||
/*********************************************************************
|
||||
* INCLUDES
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* CONSTANTS
|
||||
*/
|
||||
|
||||
// Peripheral Task Events
|
||||
#define SBP_START_DEVICE_EVT 0x0001
|
||||
#define SBP_PERIODIC_EVT 0x0002
|
||||
#define SBP_READ_RSSI_EVT 0x0004
|
||||
#define SBP_PARAM_UPDATE_EVT 0x0008
|
||||
|
||||
/*********************************************************************
|
||||
* MACROS
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint16 connHandle; // Connection handle of current connection
|
||||
uint16 connInterval;
|
||||
uint16 connSlaveLatency;
|
||||
uint16 connTimeout;
|
||||
} peripheralConnItem_t;
|
||||
|
||||
extern peripheralConnItem_t peripheralConnList;
|
||||
/*********************************************************************
|
||||
* FUNCTIONS
|
||||
*/
|
||||
//uint8 Set_BleDevice_Name(uint8* name, u8 len);
|
||||
/*
|
||||
* Task Initialization for the BLE Application
|
||||
*/
|
||||
extern void Peripheral_Init( void );
|
||||
|
||||
/*
|
||||
* Task Event Processor for the BLE Application
|
||||
*/
|
||||
extern uint16 Peripheral_ProcessEvent( uint8 task_id, uint16 events );
|
||||
|
||||
void peripheralChar4Notify( uint8 *pValue, uint16 len );
|
||||
|
||||
/*********************************************************************
|
||||
*********************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
1620
BasicCode/Drive/BLE/multiCentral.c
Normal file
1620
BasicCode/Drive/BLE/multiCentral.c
Normal file
File diff suppressed because it is too large
Load Diff
53
BasicCode/Drive/BLE/multiCentral_main.c
Normal file
53
BasicCode/Drive/BLE/multiCentral_main.c
Normal file
@@ -0,0 +1,53 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : main.c
|
||||
* Author : WCH
|
||||
* Version : V1.1
|
||||
* Date : 2019/11/05
|
||||
* Description :
|
||||
*******************************************************************************/
|
||||
|
||||
/******************************************************************************/
|
||||
/* ͷ<>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD> */
|
||||
#include "CONFIG.h"
|
||||
#include "CH57x_common.h"
|
||||
#include "HAL.h"
|
||||
#include "peripheral.h"
|
||||
#include "multiCentral.h"
|
||||
|
||||
/*********************************************************************
|
||||
* GLOBAL TYPEDEFS
|
||||
*/
|
||||
__align(4) u32 MEM_BUF[BLE_MEMHEAP_SIZE/4];
|
||||
|
||||
#if (defined (BLE_MAC)) && (BLE_MAC == TRUE)
|
||||
u8C MacAddr[6] = {0x84,0xC2,0xE4,0x03,0x02,0x02};
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
* Function Name : main
|
||||
* Description : <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* Input : None
|
||||
* Output : None
|
||||
* Return : None
|
||||
*******************************************************************************/
|
||||
int main( void )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
GPIOA_SetBits(bTXD1);
|
||||
GPIOA_ModeCfg(bTXD1, GPIO_ModeOut_PP_5mA);
|
||||
UART1_DefInit( );
|
||||
#endif
|
||||
PRINT("%s\n",VER_LIB);
|
||||
CH57X_BLEInit( );
|
||||
HAL_Init( );
|
||||
GAPRole_PeripheralInit( );
|
||||
GAPRole_CentralInit( );
|
||||
|
||||
Peripheral_Init( );
|
||||
Central_Init( );
|
||||
while(1){
|
||||
TMOS_SystemProcess( );
|
||||
}
|
||||
}
|
||||
|
||||
/******************************** endfile @ main ******************************/
|
||||
688
BasicCode/Drive/BLE/peripheral.c
Normal file
688
BasicCode/Drive/BLE/peripheral.c
Normal file
@@ -0,0 +1,688 @@
|
||||
/********************************** (C) COPYRIGHT *******************************
|
||||
* File Name : peripheral.C
|
||||
* Author : WCH
|
||||
* Version : V1.0
|
||||
* Date : 2018/12/10
|
||||
* Description : <20><><EFBFBD><EFBFBD><EFBFBD>ӻ<EFBFBD><D3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ó<EFBFBD><C3B3><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>㲥<EFBFBD><E3B2A5><EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD><EFBFBD>Ȼ<EFBFBD><C8BB><EFBFBD>㲥<EFBFBD><E3B2A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*******************************************************************************/
|
||||
|
||||
/*********************************************************************
|
||||
* INCLUDES
|
||||
*/
|
||||
#include "CONFIG.h"
|
||||
#include "CH57x_common.h"
|
||||
#include "devinfoservice.h"
|
||||
#include "gattprofile.h"
|
||||
#include "peripheral.h"
|
||||
|
||||
/*********************************************************************
|
||||
* MACROS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* CONSTANTS
|
||||
*/
|
||||
|
||||
// How often to perform periodic event
|
||||
#define SBP_PERIODIC_EVT_PERIOD 1600
|
||||
|
||||
// How often to perform read rssi event
|
||||
#define SBP_READ_RSSI_EVT_PERIOD /*3200*/4800
|
||||
|
||||
// Parameter update delay
|
||||
#define SBP_PARAM_UPDATE_DELAY 6400
|
||||
|
||||
// What is the advertising interval when device is discoverable (units of 625us, 80=50ms)
|
||||
#define DEFAULT_ADVERTISING_INTERVAL 80
|
||||
|
||||
// Limited discoverable mode advertises for 30.72s, and then stops
|
||||
// General discoverable mode advertises indefinitely
|
||||
#define DEFAULT_DISCOVERABLE_MODE GAP_ADTYPE_FLAGS_GENERAL
|
||||
|
||||
// Minimum connection interval (units of 1.25ms, 20=25ms)
|
||||
#define DEFAULT_DESIRED_MIN_CONN_INTERVAL 20
|
||||
|
||||
// Maximum connection interval (units of 1.25ms, 100=125ms)
|
||||
#define DEFAULT_DESIRED_MAX_CONN_INTERVAL 100
|
||||
|
||||
|
||||
|
||||
// Slave latency to use parameter update
|
||||
#define DEFAULT_DESIRED_SLAVE_LATENCY 0
|
||||
|
||||
// Supervision timeout value (units of 10ms, 100=1s)
|
||||
#define DEFAULT_DESIRED_CONN_TIMEOUT 50
|
||||
|
||||
// Company Identifier: WCH
|
||||
#define WCH_COMPANY_ID 0x07D7
|
||||
|
||||
/*********************************************************************
|
||||
* TYPEDEFS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* EXTERNAL VARIABLES
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* EXTERNAL FUNCTIONS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* LOCAL VARIABLES
|
||||
*/
|
||||
static uint8 Peripheral_TaskID = INVALID_TASK_ID; // Task ID for internal task/event processing
|
||||
|
||||
|
||||
static uint8 advertData[] =
|
||||
{
|
||||
// Flags; this sets the device to use limited discoverable
|
||||
// mode (advertises for 30 seconds at a time) instead of general
|
||||
// discoverable mode (advertises indefinitely)
|
||||
0x02, // length of this data
|
||||
GAP_ADTYPE_FLAGS,
|
||||
DEFAULT_DISCOVERABLE_MODE | GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED,
|
||||
|
||||
// service UUID, to notify central devices what services are included
|
||||
// in this peripheral
|
||||
0x03, // length of this data
|
||||
GAP_ADTYPE_16BIT_MORE, // some of the UUID's, but not all
|
||||
LO_UINT16( SIMPLEPROFILE_SERV_UUID ),
|
||||
HI_UINT16( SIMPLEPROFILE_SERV_UUID )
|
||||
};
|
||||
|
||||
// GAP - SCAN RSP data (max size = 31 bytes)
|
||||
static uint8 scanRspData[31] =
|
||||
{
|
||||
// complete name
|
||||
0x10, // length of this data
|
||||
GAP_ADTYPE_LOCAL_NAME_COMPLETE,
|
||||
'B',
|
||||
'L',
|
||||
'V',
|
||||
'-',
|
||||
'C',
|
||||
'1',
|
||||
' ',
|
||||
'R',
|
||||
'C',
|
||||
'U',
|
||||
':',
|
||||
'8',
|
||||
'8',
|
||||
'8',
|
||||
'8',
|
||||
// connection interval range
|
||||
0x05, // length of this data
|
||||
GAP_ADTYPE_SLAVE_CONN_INTERVAL_RANGE,
|
||||
LO_UINT16( DEFAULT_DESIRED_MIN_CONN_INTERVAL ), // 100ms
|
||||
HI_UINT16( DEFAULT_DESIRED_MIN_CONN_INTERVAL ),
|
||||
LO_UINT16( DEFAULT_DESIRED_MAX_CONN_INTERVAL ), // 1s
|
||||
HI_UINT16( DEFAULT_DESIRED_MAX_CONN_INTERVAL ),
|
||||
|
||||
// Tx power level
|
||||
// 0x02, // length of this data
|
||||
// GAP_ADTYPE_POWER_LEVEL,
|
||||
// 0 // 0dBm
|
||||
};
|
||||
|
||||
|
||||
/************
|
||||
**<2A><> <20><><EFBFBD><EFBFBD>Set_BleDevice_Name
|
||||
**<2A><> <20>ã<EFBFBD><C3A3><EFBFBD><DEB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
**<2A><> <20><><EFBFBD><EFBFBD>rspData: <20><><EFBFBD><EFBFBD>ɨ<EFBFBD><C9A8><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>buff name<6D><65>Ҫ<EFBFBD>ĵ<DEB8><C4B5><EFBFBD><EFBFBD>֣<EFBFBD> len<65><6E><EFBFBD><EFBFBD><EFBFBD>ֵij<D6B5><C4B3><EFBFBD>
|
||||
**<2A><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0<EFBFBD>ɹ<EFBFBD>
|
||||
*************/
|
||||
//uint8 Set_BleDevice_Name(uint8* name, u8 len)
|
||||
//{
|
||||
// if(name == NULL || len == 0) return 1; //<2F><><EFBFBD>ֲ<EFBFBD><D6B2><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>
|
||||
// if(dataFlash_save_t.bleName_len == len && memcmp(name, &dataFlash_save_t.scanRspData[2], len) == 0) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD>ı<EFBFBD>
|
||||
// {
|
||||
// return 2; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ
|
||||
// }
|
||||
// memset(dataFlash_save_t.scanRspData, 0, 31);
|
||||
// //memset(attDeviceName, 0, BLE_DEVICE_NAME_LEN);
|
||||
// if(len < BLE_DEVICE_NAME_LEN)
|
||||
// {
|
||||
// memcpy(&dataFlash_save_t.scanRspData[2], name, len);
|
||||
// //memcpy(attDeviceName, name, len);
|
||||
// dataFlash_save_t.scanRspData[0] = len +1;
|
||||
// dataFlash_save_t.bleName_len = len;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// memcpy(&dataFlash_save_t.scanRspData[2], name, BLE_DEVICE_NAME_LEN);
|
||||
// //memcpy(attDeviceName, name, BLE_DEVICE_NAME_LEN);
|
||||
// dataFlash_save_t.scanRspData[0] = BLE_DEVICE_NAME_LEN + 1;
|
||||
// dataFlash_save_t.bleName_len = BLE_DEVICE_NAME_LEN;
|
||||
// }
|
||||
// dataFlash_save_t.scanRspData[1] = GAP_ADTYPE_LOCAL_NAME_COMPLETE;
|
||||
// dataFlash_save_t.scanRspData[dataFlash_save_t.scanRspData[0]+1] = 0x05; // length of this data
|
||||
// dataFlash_save_t.scanRspData[dataFlash_save_t.scanRspData[0]+2] = GAP_ADTYPE_SLAVE_CONN_INTERVAL_RANGE;
|
||||
// dataFlash_save_t.scanRspData[dataFlash_save_t.scanRspData[0]+3] = LO_UINT16( DEFAULT_DESIRED_MIN_CONN_INTERVAL );
|
||||
// dataFlash_save_t.scanRspData[dataFlash_save_t.scanRspData[0]+4] = HI_UINT16( DEFAULT_DESIRED_MIN_CONN_INTERVAL );
|
||||
// dataFlash_save_t.scanRspData[dataFlash_save_t.scanRspData[0]+5] = LO_UINT16( DEFAULT_DESIRED_MAX_CONN_INTERVAL );
|
||||
// dataFlash_save_t.scanRspData[dataFlash_save_t.scanRspData[0]+6] = HI_UINT16( DEFAULT_DESIRED_MAX_CONN_INTERVAL );
|
||||
// dataFlash_save_t.scanRspData[dataFlash_save_t.scanRspData[0]+7] = 0x02; // length of this data
|
||||
// dataFlash_save_t.scanRspData[dataFlash_save_t.scanRspData[0]+8] = GAP_ADTYPE_POWER_LEVEL;
|
||||
// dataFlash_save_t.scanRspData[dataFlash_save_t.scanRspData[0]+9] = 0; // 0dBm
|
||||
// // Set the GAP Characteristics д GAP <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// GGS_SetParameter( GGS_DEVICE_NAME_ATT, BLE_DEVICE_NAME_LEN, &dataFlash_save_t.scanRspData[2] );
|
||||
// GAPRole_SetParameter( GAPROLE_SCAN_RSP_DATA, sizeof ( dataFlash_save_t.scanRspData ), dataFlash_save_t.scanRspData );
|
||||
//
|
||||
// dataFlash_save_t.flash_save_flg = 1; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>
|
||||
// return 0;
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Connection item list
|
||||
/*static*/ peripheralConnItem_t peripheralConnList;
|
||||
|
||||
/*********************************************************************
|
||||
* LOCAL FUNCTIONS
|
||||
*/
|
||||
static void Peripheral_ProcessTMOSMsg( tmos_event_hdr_t *pMsg );
|
||||
static void peripheralStateNotificationCB( gapRole_States_t newState ,gapRoleEvent_t * pEvent);
|
||||
static void performPeriodicTask( void );
|
||||
static void simpleProfileChangeCB( uint8 paramID );
|
||||
static void peripheralParamUpdateCB( uint16 connHandle, uint16 connInterval,
|
||||
uint16 connSlaveLatency, uint16 connTimeout );
|
||||
static void peripheralInitConnItem( peripheralConnItem_t* peripheralConnList );
|
||||
static void peripheralRssiCB( uint16 connHandle, int8 rssi );
|
||||
//static void peripheralChar4Notify( uint8 *pValue, uint16 len );
|
||||
|
||||
/*********************************************************************
|
||||
* PROFILE CALLBACKS
|
||||
*/
|
||||
|
||||
// GAP Role Callbacks
|
||||
static gapRolesCBs_t Peripheral_PeripheralCBs =
|
||||
{
|
||||
peripheralStateNotificationCB, // Profile State Change Callbacks
|
||||
peripheralRssiCB, // When a valid RSSI is read from controller (not used by application)
|
||||
peripheralParamUpdateCB //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɻص<C9BB>
|
||||
};
|
||||
|
||||
// GAP Bond Manager Callbacks
|
||||
static gapBondCBs_t Peripheral_BondMgrCBs =
|
||||
{
|
||||
NULL, // Passcode callback (not used by application)
|
||||
NULL // Pairing / Bonding state Callback (not used by application)
|
||||
};
|
||||
|
||||
// Simple GATT Profile Callbacks
|
||||
static simpleProfileCBs_t Peripheral_SimpleProfileCBs =
|
||||
{
|
||||
simpleProfileChangeCB // Charactersitic value change callback
|
||||
};
|
||||
/*********************************************************************
|
||||
* PUBLIC FUNCTIONS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* @fn Peripheral_Init
|
||||
*
|
||||
* @brief Initialization function for the Peripheral App Task.
|
||||
* This is called during initialization and should contain
|
||||
* any application specific initialization (ie. hardware
|
||||
* initialization/setup, table initialization, power up
|
||||
* notificaiton ... ).
|
||||
*
|
||||
* @param task_id - the ID assigned by TMOS. This ID should be
|
||||
* used to send messages and set timers.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
void Peripheral_Init( )
|
||||
{
|
||||
Peripheral_TaskID = TMOS_ProcessEventRegister( Peripheral_ProcessEvent );
|
||||
|
||||
// Setup the GAP Peripheral Role Profile <20><><EFBFBD><EFBFBD>GAP<41><50>Χ<EFBFBD><CEA7>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
|
||||
{
|
||||
uint8 initial_advertising_enable = TRUE;
|
||||
uint16 desired_min_interval = DEFAULT_DESIRED_MIN_CONN_INTERVAL; //<2F><>С<EFBFBD><D0A1><EFBFBD>Ӽ<EFBFBD><D3BC><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD>λΪ1.25ms<EFBFBD><EFBFBD>20=25ms<6D><73>
|
||||
uint16 desired_max_interval = DEFAULT_DESIRED_MAX_CONN_INTERVAL; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӽ<EFBFBD><D3BC><EFBFBD>5<EFBFBD><35><EFBFBD><EFBFBD>λΪ1.25ms<EFBFBD><EFBFBD>100=25ms<6D><73>
|
||||
|
||||
// GAP - Advertisement data (max size = 31 bytes, though this is
|
||||
// best kept short to conserve power while advertisting)
|
||||
|
||||
|
||||
// Set the GAP Role Parameters д GAP Role <20><><EFBFBD><EFBFBD>
|
||||
GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &initial_advertising_enable );
|
||||
|
||||
// GAPRole_SetParameter( GAPROLE_SCAN_RSP_DATA, sizeof ( dataFlash_save_t.scanRspData ), dataFlash_save_t.scanRspData );
|
||||
GAPRole_SetParameter( GAPROLE_SCAN_RSP_DATA, sizeof ( scanRspData ), scanRspData );
|
||||
GAPRole_SetParameter( GAPROLE_ADVERT_DATA, sizeof( advertData ), advertData );
|
||||
GAPRole_SetParameter( GAPROLE_MIN_CONN_INTERVAL, sizeof( uint16 ), &desired_min_interval );
|
||||
GAPRole_SetParameter( GAPROLE_MAX_CONN_INTERVAL, sizeof( uint16 ), &desired_max_interval );
|
||||
}
|
||||
|
||||
// Set the GAP Characteristics д GAP <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// GGS_SetParameter( GGS_DEVICE_NAME_ATT, dataFlash_save_t.bleName_len, &dataFlash_save_t.scanRspData[2] );
|
||||
GGS_SetParameter( GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, attDeviceName );
|
||||
|
||||
// Set advertising interval
|
||||
{
|
||||
uint16 advInt = DEFAULT_ADVERTISING_INTERVAL; //<2F>㲥<EFBFBD><E3B2A5><EFBFBD><EFBFBD>
|
||||
//д GAP <20><><EFBFBD><EFBFBD>
|
||||
GAP_SetParamValue( TGAP_DISC_ADV_INT_MIN, advInt );
|
||||
GAP_SetParamValue( TGAP_DISC_ADV_INT_MAX, advInt );
|
||||
}
|
||||
|
||||
// Setup the GAP Bond Manager
|
||||
{
|
||||
uint32 passkey = 0; // passkey "000000"
|
||||
uint8 pairMode = GAPBOND_PAIRING_MODE_WAIT_FOR_REQ; //<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD>
|
||||
uint8 mitm = TRUE;
|
||||
uint8 bonding = TRUE;
|
||||
uint8 ioCap = GAPBOND_IO_CAP_DISPLAY_ONLY; ////<2F><><EFBFBD><EFBFBD>ʾ<EFBFBD>豸
|
||||
//д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD><D8B2><EFBFBD>
|
||||
GAPBondMgr_SetParameter( GAPBOND_PERI_DEFAULT_PASSCODE, sizeof ( uint32 ), &passkey ); //MITM<54><4D><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC><EFBFBD><EFBFBD><EFBFBD>롣<EFBFBD><EBA1A3><EFBFBD><EFBFBD>Ϊuint32<33><32><EFBFBD><EFBFBD>Χ<EFBFBD><CEA7>0-999999<39><39>Ĭ<EFBFBD><C4AC>ֵΪ0<CEAA><30>
|
||||
GAPBondMgr_SetParameter( GAPBOND_PERI_PAIRING_MODE, sizeof ( uint8 ), &pairMode ); //<2F><><EFBFBD><EFBFBD>ģʽ<C4A3><CABD>@ref GAPBOND_Pairing_Mode_defined<65><64><EFBFBD><EFBFBD>/д<><D0B4><EFBFBD><EFBFBD>С<EFBFBD><D0A1>uint8<74><38>Ĭ<EFBFBD><C4AC>ΪGAPBOND_PAIRING_MODE_WAIT_REQ<45>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
GAPBondMgr_SetParameter( GAPBOND_PERI_MITM_PROTECTION, sizeof ( uint8 ), &mitm ); //<2F><>Կ<EFBFBD><D4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/д<><D0B4><EFBFBD><EFBFBD>С<EFBFBD><D0A1>uint8<74><38>Ĭ<EFBFBD><C4AC>ֵΪ0<CEAA><30><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD>˴<EFBFBD><CBB4><EFBFBD><EFBFBD><EFBFBD>
|
||||
GAPBondMgr_SetParameter( GAPBOND_PERI_IO_CAPABILITIES, sizeof ( uint8 ), &ioCap ); //I/O<><4F><EFBFBD>ܡ<EFBFBD><DCA1><EFBFBD>/д<><D0B4><EFBFBD><EFBFBD>С<EFBFBD><D0A1>uint8<74><38>Ĭ<EFBFBD><C4AC>ֵΪ<D6B5><CEAA><EFBFBD><EFBFBD>ʾ<EFBFBD>豸
|
||||
GAPBondMgr_SetParameter( GAPBOND_PERI_BONDING_ENABLED, sizeof ( uint8 ), &bonding ); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Թ<EFBFBD><D4B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><F3B6A8A1><EFBFBD>/д<><D0B4><EFBFBD>ߴ<EFBFBD><DFB4><EFBFBD>uint8<74><38>Ĭ<EFBFBD><C4AC>ֵΪ0<CEAA><30><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD>˴<EFBFBD><CBB4><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
// Initialize GATT attributes
|
||||
GGS_AddService( GATT_ALL_SERVICES ); // GAP
|
||||
GATTServApp_AddService( GATT_ALL_SERVICES ); // GATT attributes
|
||||
DevInfo_AddService(); // Device Information Service
|
||||
SimpleProfile_AddService( GATT_ALL_SERVICES ); // Simple GATT Profile
|
||||
|
||||
// Setup the SimpleProfile Characteristic Values
|
||||
{
|
||||
// uint8 charValue1[SIMPLEPROFILE_CHAR1_LEN] = { 1 };
|
||||
// uint8 charValue2[SIMPLEPROFILE_CHAR2_LEN] = {192,168,1,94};
|
||||
//uint8 charValue3[SIMPLEPROFILE_CHAR3_LEN] = { 3 };
|
||||
// uint8 charValue4[SIMPLEPROFILE_CHAR4_LEN] = { 4 };
|
||||
// uint8 charValue5[SIMPLEPROFILE_CHAR5_LEN] = { 1, 2, 3, 4, 5 };
|
||||
|
||||
// SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR1, SIMPLEPROFILE_CHAR1_LEN, charValue1 );
|
||||
// SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR2, SIMPLEPROFILE_CHAR2_LEN, charValue2 );
|
||||
//SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR3, SIMPLEPROFILE_CHAR3_LEN, charValue3 );
|
||||
// SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR4, SIMPLEPROFILE_CHAR4_LEN, charValue4 );
|
||||
// SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR5, SIMPLEPROFILE_CHAR5_LEN, charValue5 );
|
||||
}
|
||||
|
||||
// Init Connection Item
|
||||
peripheralInitConnItem( &peripheralConnList );
|
||||
|
||||
// Register callback with SimpleGATTprofile //ע<><D7A2><EFBFBD>ص<EFBFBD>
|
||||
SimpleProfile_RegisterAppCBs( &Peripheral_SimpleProfileCBs );
|
||||
|
||||
// Setup a delayed profile startup //<2F><><EFBFBD><EFBFBD><EFBFBD>ӳٵ<D3B3><D9B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
|
||||
tmos_set_event( Peripheral_TaskID, SBP_START_DEVICE_EVT );
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn peripheralInitConnItem
|
||||
*
|
||||
* @brief Init Connection Item
|
||||
*
|
||||
* @param peripheralConnList -
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
static void peripheralInitConnItem( peripheralConnItem_t* peripheralConnList )
|
||||
{
|
||||
peripheralConnList->connHandle = GAP_CONNHANDLE_INIT;
|
||||
peripheralConnList->connInterval = 0;
|
||||
peripheralConnList->connSlaveLatency = 0;
|
||||
peripheralConnList->connTimeout = 0;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn Peripheral_ProcessEvent
|
||||
*
|
||||
* @brief Peripheral Application Task event processor. This function
|
||||
* is called to process all events for the task. Events
|
||||
* include timers, messages and any other user defined events.
|
||||
*
|
||||
* @param task_id - The TMOS assigned task ID.
|
||||
* @param events - events to process. This is a bit map and can
|
||||
* contain more than one event.
|
||||
*
|
||||
* @return events not processed
|
||||
*/
|
||||
uint16 Peripheral_ProcessEvent( uint8 task_id, uint16 events )
|
||||
{
|
||||
|
||||
// VOID task_id; // TMOS required parameter that isn't used in this function
|
||||
|
||||
if ( events & SYS_EVENT_MSG ){
|
||||
uint8 *pMsg;
|
||||
|
||||
if ( (pMsg = tmos_msg_receive( Peripheral_TaskID )) != NULL ){
|
||||
Peripheral_ProcessTMOSMsg( (tmos_event_hdr_t *)pMsg );
|
||||
// Release the TMOS message
|
||||
tmos_msg_deallocate( pMsg );
|
||||
}
|
||||
// return unprocessed events
|
||||
return (events ^ SYS_EVENT_MSG);
|
||||
}
|
||||
|
||||
if ( events & SBP_START_DEVICE_EVT ){
|
||||
// Start the Device
|
||||
GAPRole_PeripheralStartDevice( Peripheral_TaskID, &Peripheral_BondMgrCBs, &Peripheral_PeripheralCBs );
|
||||
return ( events ^ SBP_START_DEVICE_EVT );
|
||||
}
|
||||
|
||||
if ( events & SBP_PERIODIC_EVT )
|
||||
{
|
||||
// Restart timer
|
||||
// if ( SBP_PERIODIC_EVT_PERIOD ){
|
||||
// tmos_start_task( Peripheral_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD );
|
||||
// }
|
||||
// Perform periodic application task ִ<>ж<EFBFBD><D0B6><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//performPeriodicTask(); //<2F><><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD>֪ͨ
|
||||
return (events ^ SBP_PERIODIC_EVT);
|
||||
}
|
||||
|
||||
if ( events & SBP_PARAM_UPDATE_EVT ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
// Send connect param update request //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
GAPRole_PeripheralConnParamUpdateReq( peripheralConnList.connHandle,
|
||||
DEFAULT_DESIRED_MIN_CONN_INTERVAL,
|
||||
DEFAULT_DESIRED_MAX_CONN_INTERVAL,
|
||||
DEFAULT_DESIRED_SLAVE_LATENCY,
|
||||
DEFAULT_DESIRED_CONN_TIMEOUT,
|
||||
Peripheral_TaskID);
|
||||
|
||||
return (events ^ SBP_PARAM_UPDATE_EVT);
|
||||
}
|
||||
|
||||
if ( events & SBP_READ_RSSI_EVT )
|
||||
{
|
||||
GAPRole_ReadRssiCmd(peripheralConnList.connHandle);
|
||||
tmos_start_task( Peripheral_TaskID, SBP_READ_RSSI_EVT, SBP_READ_RSSI_EVT_PERIOD );
|
||||
return (events ^ SBP_READ_RSSI_EVT);
|
||||
}
|
||||
|
||||
// Discard unknown events
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn Peripheral_ProcessTMOSMsg
|
||||
*
|
||||
* @brief Process an incoming task message.
|
||||
*
|
||||
* @param pMsg - message to process
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
static void Peripheral_ProcessTMOSMsg( tmos_event_hdr_t *pMsg )
|
||||
{
|
||||
switch ( pMsg->event ){
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn Peripheral_LinkEstablished
|
||||
*
|
||||
* @brief Process link established.
|
||||
*
|
||||
* @param pEvent - event to process
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
static void Peripheral_LinkEstablished( gapRoleEvent_t * pEvent )
|
||||
{
|
||||
gapEstLinkReqEvent_t *event = (gapEstLinkReqEvent_t *) pEvent;
|
||||
|
||||
// See if already connected
|
||||
if( peripheralConnList.connHandle != GAP_CONNHANDLE_INIT )
|
||||
{
|
||||
GAPRole_TerminateLink( pEvent->linkCmpl.connectionHandle );
|
||||
PRINT( "Connection max...\n" );
|
||||
}
|
||||
else
|
||||
{
|
||||
peripheralConnList.connHandle = event->connectionHandle;
|
||||
peripheralConnList.connInterval = event->connInterval;
|
||||
peripheralConnList.connSlaveLatency = event->connLatency;
|
||||
peripheralConnList.connTimeout = event->connTimeout;
|
||||
|
||||
// Set timer for periodic event
|
||||
tmos_start_task( Peripheral_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD );
|
||||
|
||||
// Set timer for param update event
|
||||
tmos_start_task( Peripheral_TaskID, SBP_PARAM_UPDATE_EVT, SBP_PARAM_UPDATE_DELAY );
|
||||
|
||||
// Start read rssi
|
||||
tmos_start_task( Peripheral_TaskID, SBP_READ_RSSI_EVT, SBP_READ_RSSI_EVT_PERIOD );
|
||||
|
||||
printf("Conn %x - Int %x \n", event->connectionHandle, event->connInterval);
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn Peripheral_LinkTerminated
|
||||
*
|
||||
* @brief Process link terminated.
|
||||
*
|
||||
* @param pEvent - event to process
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
static void Peripheral_LinkTerminated( gapRoleEvent_t * pEvent )
|
||||
{
|
||||
gapTerminateLinkEvent_t *event = (gapTerminateLinkEvent_t *) pEvent;
|
||||
|
||||
if( event->connectionHandle == peripheralConnList.connHandle )
|
||||
{
|
||||
peripheralConnList.connHandle = GAP_CONNHANDLE_INIT;
|
||||
peripheralConnList.connInterval = 0;
|
||||
peripheralConnList.connSlaveLatency = 0;
|
||||
peripheralConnList.connTimeout = 0;
|
||||
tmos_stop_task( Peripheral_TaskID, SBP_PERIODIC_EVT );
|
||||
tmos_stop_task( Peripheral_TaskID, SBP_READ_RSSI_EVT );
|
||||
|
||||
// Restart advertising
|
||||
{
|
||||
uint8 advertising_enable = TRUE;
|
||||
GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &advertising_enable );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PRINT("ERR..\n");
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn peripheralRssiCB
|
||||
*
|
||||
* @brief RSSI callback.
|
||||
*
|
||||
* @param connHandle - connection handle
|
||||
* @param rssi - RSSI
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
static void peripheralRssiCB( uint16 connHandle, int8 rssi )
|
||||
{
|
||||
PRINT( "RSSI -%d dB Conn %x \n", -rssi, connHandle);
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn peripheralParamUpdateCB
|
||||
*
|
||||
* @brief Parameter update complete callback
|
||||
*
|
||||
* @param connHandle - connect handle
|
||||
* connInterval - connect interval
|
||||
* connSlaveLatency - connect slave latency
|
||||
* connTimeout - connect timeout
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
static void peripheralParamUpdateCB( uint16 connHandle, uint16 connInterval,
|
||||
uint16 connSlaveLatency, uint16 connTimeout )
|
||||
{
|
||||
if( connHandle == peripheralConnList.connHandle )
|
||||
{
|
||||
peripheralConnList.connInterval = connInterval;
|
||||
peripheralConnList.connSlaveLatency = connSlaveLatency;
|
||||
peripheralConnList.connTimeout = connTimeout;
|
||||
|
||||
printf("Update %x - Int %x \n", connHandle, connInterval);
|
||||
}
|
||||
else
|
||||
{
|
||||
PRINT("ERR..\n");
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn peripheralStateNotificationCB
|
||||
*
|
||||
* @brief Notification from the profile of a state change.
|
||||
*
|
||||
* @param newState - new state
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
static void peripheralStateNotificationCB( gapRole_States_t newState, gapRoleEvent_t * pEvent )
|
||||
{
|
||||
switch ( newState )
|
||||
{
|
||||
case GAPROLE_STARTED:
|
||||
PRINT( "Initialized..\n" );
|
||||
break;
|
||||
|
||||
case GAPROLE_ADVERTISING:
|
||||
if( pEvent->gap.opcode == GAP_LINK_TERMINATED_EVENT ) //gap<61><70><EFBFBD>ӽ<EFBFBD><D3BD><EFBFBD>
|
||||
{
|
||||
Peripheral_LinkTerminated( pEvent );
|
||||
PRINT( "Disconnected..Reason:%x\n", pEvent->linkTerminate.reason );
|
||||
}
|
||||
PRINT( "Advertising..\n" );
|
||||
break;
|
||||
|
||||
case GAPROLE_CONNECTED:
|
||||
if( pEvent->gap.opcode == GAP_LINK_ESTABLISHED_EVENT ) //GAP<41><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
Peripheral_LinkEstablished( pEvent );
|
||||
}
|
||||
PRINT( "Connected..\n" );
|
||||
break;
|
||||
|
||||
case GAPROLE_CONNECTED_ADV: //
|
||||
PRINT( "Connected Advertising..\n" );
|
||||
break;
|
||||
|
||||
case GAPROLE_WAITING:
|
||||
if( pEvent->gap.opcode == GAP_END_DISCOVERABLE_DONE_EVENT )
|
||||
{
|
||||
PRINT( "Waiting for advertising..\n" );
|
||||
}
|
||||
else if( pEvent->gap.opcode == GAP_LINK_TERMINATED_EVENT )
|
||||
{
|
||||
Peripheral_LinkTerminated( pEvent );
|
||||
PRINT( "Disconnected..Reason:%x\n", pEvent->linkTerminate.reason );
|
||||
}
|
||||
break;
|
||||
|
||||
case GAPROLE_ERROR:
|
||||
PRINT( "Error..\n" );
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn performPeriodicTask
|
||||
*
|
||||
* @brief Perform a periodic application task. This function gets
|
||||
* called every five seconds as a result of the SBP_PERIODIC_EVT
|
||||
* TMOS event. In this example, the value of the third
|
||||
* characteristic in the SimpleGATTProfile service is retrieved
|
||||
* from the profile, and then copied into the value of the
|
||||
* the fourth characteristic.
|
||||
* <09><>ʱ֪ͨ<CDA8><D6AA><EFBFBD><EFBFBD>
|
||||
* @param none
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
static void performPeriodicTask( void )
|
||||
{
|
||||
static uint8 count = 0;
|
||||
uint8 notiData[SIMPLEPROFILE_CHAR4_LEN] = "Notify:";
|
||||
sprintf((char*)¬iData[7], "%d", ++count);
|
||||
peripheralChar4Notify( notiData, strlen((char*)notiData) );
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn peripheralChar4Notify
|
||||
*
|
||||
* @brief Prepare and send simpleProfileChar4 notification
|
||||
*
|
||||
* @param pValue - data to notify
|
||||
* len - length of data
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
/*static*/ void peripheralChar4Notify( uint8 *pValue, uint16 len )
|
||||
{
|
||||
attHandleValueNoti_t noti;
|
||||
noti.len = len;
|
||||
noti.pValue = GATT_bm_alloc( peripheralConnList.connHandle, ATT_HANDLE_VALUE_NOTI, noti.len, NULL, 0 );
|
||||
tmos_memcpy( noti.pValue, pValue, noti.len );
|
||||
if( simpleProfile_Notify( peripheralConnList.connHandle, ¬i ) != SUCCESS )
|
||||
{
|
||||
GATT_bm_free( (gattMsg_t *)¬i, ATT_HANDLE_VALUE_NOTI );
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* @fn simpleProfileChangeCB
|
||||
*
|
||||
* @brief Callback from SimpleBLEProfile indicating a value change
|
||||
*
|
||||
* @param paramID - parameter ID of the value that was changed.
|
||||
*
|
||||
* @return none
|
||||
*/
|
||||
static void simpleProfileChangeCB( uint8 paramID )
|
||||
{
|
||||
|
||||
switch( paramID )
|
||||
{
|
||||
case SIMPLEPROFILE_CHAR1:
|
||||
{
|
||||
uint8 newValue[SIMPLEPROFILE_CHAR1_LEN];
|
||||
SimpleProfile_GetParameter( SIMPLEPROFILE_CHAR1, newValue );
|
||||
PRINT("profile ChangeCB CHAR1.. \n");
|
||||
break;
|
||||
}
|
||||
|
||||
case SIMPLEPROFILE_CHAR3:
|
||||
{
|
||||
uint8 newValue[GAP_DEVICE_NAME_LEN];
|
||||
SimpleProfile_GetParameter( SIMPLEPROFILE_CHAR3, newValue );
|
||||
PRINT("profile ChangeCB CHAR3..\n");
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
// should not reach here!
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*********************************************************************/
|
||||
Reference in New Issue
Block a user