1--管天管地的大结构体 一切协议都是它
第一个是C 第二个是GO
现在不是很方便 因为第一个图C的这个数组是固定的 导致100个后面有很多空余的 实际是需要尾巴的0X0D 0X0A紧紧跟着的!那就修改C一下!!!!
m_ble_node_state senddata;
memset(&senddata,0,sizeof(m_ble_node_state));
senddata.Cmd=0xB002;
senddata.Data_len=sizeof(m_ble_node_state_data);
m_ble_node_state_data data=
{
{0X11,0X22,0X33,0X44,0X55,0X66},
81,
0,
{1,2,3,4},
1,
2,
3,
4,
0,
0,
0X0D0A
};
memcpy(senddata.Data,&data,sizeof(m_ble_node_state_data));
实际测试
0X0A0D可以成功!!!
继续修改
CMD也不对 需要对调一下
继续修改
长度不对
也就是长度是结构体 是你中间data【100】的真实有效的数目 而我自己加入了2个endbyte
所以我要自己del
此时测试成功!!
换一个协议 测试有问题 准备看开发板原理图 找LOG
/**
****************************************************************************************
*
* @file user_accelerometer.c
*
* @brief Accelerometer project source code.
*
* Copyright (C) 2018 Dialog Semiconductor. This computer program or computer programs included in this package ("Software") include confidential, proprietary information of Dialog Semiconductor. All Rights Reserved.
*
* THIS SOFTWARE IS AN UNOFFICIAL RELEASE FROM DIALOG SEMICONDUCTOR (慏IALOG? AND MAY ONLY BE USED BY RECIPIENT AT ITS OWN RISK AND WITHOUT SUPPORT OF ANY KIND. THIS SOFTWARE IS SOLELY FOR USE ON AUTHORIZED DIALOG PRODUCTS AND PLATFORMS. RECIPIENT SHALL NOT TRANSMIT ANY SOFTWARE SOURCE CODE TO ANY THIRD PARTY WITHOUT DIALOG扴 PRIOR WRITTEN PERMISSION.
*
* UNLESS SET FORTH IN A SEPARATE AGREEMENT, RECIPIENT ACKNOWLEDGES AND UNDERSTANDS THAT TO THE FULLEST EXTENT PERMITTED BY LAW, THE SOFTWARE IS DELIVERED 揂S IS? WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT, AND ALL WARRANTIES THAT MAY ARISE FROM COURSE OF DEALING, CUSTOM OR USAGE IN TRADE. FOR THE SAKE OF CLARITY, DIALOG AND ITS AFFILIATES AND ITS AND THEIR SUPPLIERS DO NOT WARRANT, GUARANTEE OR MAKE ANY REPRESENTATIONS (A) REGARDING THE USE, OR THE RESULTS OF THE USE, OF THE LICENSED SOFTWARE IN TERMS OF CORRECTNESS, COMPLETENESS, ACCURACY, RELIABILITY OR OTHERWISE, AND (B) THAT THE LICENSED SOFTWARE HAS BEEN TESTED FOR COMPLIANCE WITH ANY REGULATORY OR INDUSTRY STANDARD, INCLUDING, WITHOUT LIMITATION, ANY SUCH STANDARDS PROMULGATED BY THE FCC OR OTHER LIKE AGENCIES.
*
* IN NO EVENT SHALL DIALOG BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
****************************************************************************************
*/
/**
****************************************************************************************
* @addtogroup APP
* @{
****************************************************************************************
*/
/*
* INCLUDE FILES
****************************************************************************************
*/
#include "rwip_config.h" // SW configuration
#include "gap.h"
#include "app_easy_timer.h"
#include "user_accelerometer.h"
#include "co_bt.h"
#include "gpio.h"
#include "app_api.h"
#include "app.h"
#include "prf_utils.h"
#include "custs1.h"
#include "user_custs1_def.h"
#include "user_periph_setup.h"
#include "custs1_task.h"
#include "m_drv_mc36xx.h"
#include <math.h>
/*
* TYPE DEFINITIONS
****************************************************************************************
*/
#define NOTIFICATION_DELAY 50 //The time interval between sent notifications
// Manufacturer Specific Data ADV structure type
struct mnf_specific_data_ad_structure
{
uint8_t ad_structure_size;
uint8_t ad_structure_type;
uint8_t company_id[APP_AD_MSD_COMPANY_ID_LEN];
uint8_t proprietary_data[APP_AD_MSD_DATA_LEN];
};
typedef struct {
short RawData[FIFO_DEEP][M_DRV_MC_UTL_AXES_NUM];
float fRawData[FIFO_DEEP][M_DRV_MC_UTL_AXES_NUM];
short DataLen;
uint32_t TimeStamp[FIFO_DEEP]; //ms
}AccData; //FIFO DEEP
static AccData GensorData;
#ifdef SNIFF_DEMO
static uint8_t m_polling_counter = 0;
static uint8_t sniff_delay = 1;
#endif
/*
* GLOBAL VARIABLE DEFINITIONS
****************************************************************************************
*/
uint8_t app_connection_idx __attribute__((section("retention_mem_area0"), zero_init)); //@RETENTION MEMORY
timer_hnd app_adv_data_update_timer_used __attribute__((section("retention_mem_area0"), zero_init)); //@RETENTION MEMORY
timer_hnd app_param_update_request_timer_used __attribute__((section("retention_mem_area0"), zero_init)); //@RETENTION MEMORY
timer_hnd app_send_data_timer_used __attribute__((section("retention_mem_area0"), zero_init)); //@RETENTION MEMORY
int16_t X_data __attribute__((section("retention_mem_area0"), zero_init)); //@RETENTION MEMORY
int16_t Y_data __attribute__((section("retention_mem_area0"), zero_init)); //@RETENTION MEMORY
int16_t Z_data __attribute__((section("retention_mem_area0"), zero_init)); //@RETENTION MEMORY
uint8_t X_string[8] __attribute__((section("retention_mem_area0"), zero_init)); //@RETENTION MEMORY
uint8_t Y_string[8] __attribute__((section("retention_mem_area0"), zero_init)); //@RETENTION MEMORY
uint8_t Z_string[8] __attribute__((section("retention_mem_area0"), zero_init)); //@RETENTION MEMORY
uint8_t X_timer __attribute__((section("retention_mem_area0"), zero_init)); //@RETENTION MEMORY
uint8_t Y_timer __attribute__((section("retention_mem_area0"), zero_init)); //@RETENTION MEMORY
uint8_t Z_timer __attribute__((section("retention_mem_area0"), zero_init)); //@RETENTION MEMORY
uint8_t g_timer __attribute__((section("retention_mem_area0"), zero_init)); //@RETENTION MEMORY
uint8_t s_timer __attribute__((section("retention_mem_area0"), zero_init)); //@RETENTION MEMORY
// Retained variables
struct mnf_specific_data_ad_structure mnf_data __attribute__((section("retention_mem_area0"), zero_init)); //@RETENTION MEMORY
// Index of manufacturer data in advertising data or scan response data (when MSB is 1)
uint8_t mnf_data_index __attribute__((section("retention_mem_area0"), zero_init)); //@RETENTION MEMORY
uint8_t stored_adv_data_len __attribute__((section("retention_mem_area0"), zero_init)); //@RETENTION MEMORY
uint8_t stored_scan_rsp_data_len __attribute__((section("retention_mem_area0"), zero_init)); //@RETENTION MEMORY
uint8_t stored_adv_data[ADV_DATA_LEN] __attribute__((section("retention_mem_area0"), zero_init)); //@RETENTION MEMORY
uint8_t stored_scan_rsp_data[SCAN_RSP_DATA_LEN] __attribute__((section("retention_mem_area0"), zero_init)); //@RETENTION MEMORY
/*
* FUNCTION DEFINITIONS
****************************************************************************************
*/
uint8_t user_int_to_string(int16_t input, uint8_t *s){
uint8_t length = 1;
if(input < 0){
s[0] = '-';
} else {
s[0] = ' ';
}
input = abs(input);
if(input >= 10000){
s[length++] = '0' + ((input / 10000) % 10);
}
if(input >= 1000){
s[length++] = '0' + ((input / 1000) % 10);
}
if(input >= 100){
s[length++] = '0' + ((input / 100) % 10);
}
if(input >= 10){
s[length++] = '0' + ((input / 10) % 10);
}
s[length++] = '0' + (input% 10);
return length;
}
/**
****************************************************************************************
* @brief Initialize Manufacturer Specific Data
* @return void
****************************************************************************************
*/
static void mnf_data_init()
{
mnf_data.ad_structure_size = sizeof(struct mnf_specific_data_ad_structure ) - sizeof(uint8_t); // minus the size of the ad_structure_size field
mnf_data.ad_structure_type = GAP_AD_TYPE_MANU_SPECIFIC_DATA;
mnf_data.company_id[0] = APP_AD_MSD_COMPANY_ID & 0xFF; // LSB
mnf_data.company_id[1] = (APP_AD_MSD_COMPANY_ID >> 8 )& 0xFF; // MSB
mnf_data.proprietary_data[0] = 0;
mnf_data.proprietary_data[1] = 0;
}
/**
****************************************************************************************
* @brief Update Manufacturer Specific Data
* @return void
****************************************************************************************
*/
static void mnf_data_update()
{
uint8_t fifo_size = 1;
#ifdef FIFO_DEMO
fifo_size = FIFO_THRESHOLD;
#endif
M_DRV_MC36XX_ReadRawData(GensorData.RawData, fifo_size);
#ifdef SNIFF_DEMO //Set sensor into sniff mode after data is updated.
if(m_polling_counter<(32*sniff_delay)) {
m_polling_counter++;
} else {
M_DRV_MC36XX_SetMode(E_M_DRV_MC36XX_MODE_STANDBY); // Set MC36XX to stanby mode
M_DRV_MC36XX_SetGain(E_M_DRV_MC36XX_WAKE_GAIN_LOW, E_M_DRV_MC36XX_SNIFF_GAIN_HIGH);
/* Orion 2X SNIFF threshold*/
M_DRV_MC36XX_SetSniffThreshold(M_DRV_MC36XX_AXIS_X, 3);
M_DRV_MC36XX_SetSniffThreshold(M_DRV_MC36XX_AXIS_Y, 3);
M_DRV_MC36XX_SetSniffThreshold(M_DRV_MC36XX_AXIS_Z, 3);
/* Sniff count set */
M_DRV_MC36XX_SetSniffDetectCount(M_DRV_MC36XX_AXIS_X, 1);
M_DRV_MC36XX_SetSniffDetectCount(M_DRV_MC36XX_AXIS_Y, 1);
M_DRV_MC36XX_SetSniffDetectCount(M_DRV_MC36XX_AXIS_Z, 1);
M_DRV_MC36XX_SetSampleRate(E_M_DRV_MC36XX_CWAKE_SR_UL_26Hz, E_M_DRV_MC36XX_SNIFF_SR_DEFAULT_6Hz);
M_DRV_MC36XX_ConfigINT(0,0,0,0,1);
M_DRV_MC36XX_SetMode(E_M_DRV_MC36XX_MODE_SNIFF); // Initialize MC36XX
m_polling_counter = 0;
}
#endif
}
/**
****************************************************************************************
* @brief Add an AD structure in the Advertising or Scan Response Data of the
* GAPM_START_ADVERTISE_CMD parameter struct.
* @param[in] cmd GAPM_START_ADVERTISE_CMD parameter struct
* @param[in] ad_struct_data AD structure buffer
* @param[in] ad_struct_len AD structure length
* @param[in] adv_connectable Connectable advertising event or not. It controls whether
* the advertising data use the full 31 bytes length or only
* 28 bytes (Document CCSv6 - Part 1.3 Flags).
* @return void
*/
static void app_add_ad_struct(struct gapm_start_advertise_cmd *cmd, void *ad_struct_data, uint8_t ad_struct_len, uint8_t adv_connectable)
{
uint8_t adv_data_max_size = (adv_connectable) ? (ADV_DATA_LEN - 3) : (ADV_DATA_LEN);
if ((adv_data_max_size - cmd->info.host.adv_data_len) >= ad_struct_len)
{
// Append manufacturer data to advertising data
memcpy(&cmd->info.host.adv_data[cmd->info.host.adv_data_len], ad_struct_data, ad_struct_len);
// Update Advertising Data Length
cmd->info.host.adv_data_len += ad_struct_len;
// Store index of manufacturer data which are included in the advertising data
mnf_data_index = cmd->info.host.adv_data_len - sizeof(struct mnf_specific_data_ad_structure);
}
else if ((SCAN_RSP_DATA_LEN - cmd->info.host.scan_rsp_data_len) >= ad_struct_len)
{
// Append manufacturer data to scan response data
memcpy(&cmd->info.host.scan_rsp_data[cmd->info.host.scan_rsp_data_len], ad_struct_data, ad_struct_len);
// Update Scan Response Data Length
cmd->info.host.scan_rsp_data_len += ad_struct_len;
// Store index of manufacturer data which are included in the scan response data
mnf_data_index = cmd->info.host.scan_rsp_data_len - sizeof(struct mnf_specific_data_ad_structure);
// Mark that manufacturer data is in scan response and not advertising data
mnf_data_index |= 0x80;
}
else
{
// Manufacturer Specific Data do not fit in either Advertising Data or Scan Response Data
ASSERT_WARNING(0);
}
// Store advertising data length
stored_adv_data_len = cmd->info.host.adv_data_len;
// Store advertising data
memcpy(stored_adv_data, cmd->info.host.adv_data, stored_adv_data_len);
// Store scan response data length
stored_scan_rsp_data_len = cmd->info.host.scan_rsp_data_len;
// Store scan_response data
memcpy(stored_scan_rsp_data, cmd->info.host.scan_rsp_data, stored_scan_rsp_data_len);
}
/**
****************************************************************************************
* @brief Advertisement data update timer callback function.
* @return void
****************************************************************************************
*/
static void adv_data_update_timer_cb()
{
// If mnd_data_index has MSB set, manufacturer data is stored in scan response
uint8_t *mnf_data_storage = (mnf_data_index & 0x80) ? stored_scan_rsp_data : stored_adv_data;
// Update manufacturer data
mnf_data_update();
// Update the selected fields of the advertising data (manufacturer data)
memcpy(mnf_data_storage + (mnf_data_index & 0x7F), &mnf_data, sizeof(struct mnf_specific_data_ad_structure));
// Update advertising data on the fly
app_easy_gap_update_adv_data(stored_adv_data, stored_adv_data_len, stored_scan_rsp_data, stored_scan_rsp_data_len);
// Restart timer for the next advertising update
app_adv_data_update_timer_used = app_easy_timer(APP_ADV_DATA_UPDATE_TO, adv_data_update_timer_cb);
}
/**
****************************************************************************************
* @brief Parameter update request timer callback function.
* @return void
****************************************************************************************
*/
static void param_update_request_timer_cb()
{
app_easy_gap_param_update_start(app_connection_idx);
app_param_update_request_timer_used = EASY_TIMER_INVALID_TIMER;
}
//extern void platform_reset_func(uint32_t error);
void my_reset_func(void)
{
uint16_t tmp;
// Trigger SW reset
tmp = GetWord16(SYS_CTRL_REG);
tmp = (tmp & ~REMAP_ADR0) | 0; // Map ROM at address 0
tmp |= SW_RESET;
SetWord16(SYS_CTRL_REG, tmp);
}
int16_t cnt __attribute__((section("retention_mem_area0"), zero_init));
#define PHONEAPP 1
#if PHONEAPP
typedef struct {
uint8_t BLE_mac[6];
uint8_t Batt_level;
uint8_t Audio_exist;
uint8_t Node_sys_version[4];
uint16_t A_odr;
uint16_t G_odr;
uint16_t M_odr;
uint16_t T_period;
uint8_t Status;
uint8_t Resv;
uint16_t End_byte;
}m_ble_node_state_data;
typedef struct {
uint16_t data_counter;
uint16_t resv;
uint8_t data[128];
uint32_t CRC32;
uint16_t End_byte;
}m_hex_data;
typedef struct {// PACK_DATA //ParseByteArray
uint16_t Cmd;
uint16_t Data_len;
uint8_t Data[150];//这里面是独立的结构体
//uint8_t End_byte[2];
}m_ble_node_state;
static void send_data_timer_cb()
{
#define uint16_t_CHANGE_BIT_MODE(x) (((x>>8)&0x00ff)| ((x << 8)&0xff00))
struct custs1_val_ntf_ind_req *req;
m_ble_node_state senddata;
memset(&senddata,0,sizeof(m_ble_node_state));
#if 0 //NODE 状态
senddata.Cmd=0xB002;
senddata.Cmd=uint16_t_CHANGE_BIT_MODE(senddata.Cmd);
senddata.Data_len=sizeof(m_ble_node_state_data)-2;
m_ble_node_state_data data=
{
{0X11,0X22,0X33,0X44,0X55,0X66},
0X81,
0,
{1,2,3,4},
1,
2,
3,
4,
0,
0,
0X0A0D
};
memcpy(senddata.Data,&data,sizeof(m_ble_node_state_data));
#else //HEXDATA
senddata.Cmd=0xB101;
senddata.Cmd=uint16_t_CHANGE_BIT_MODE(senddata.Cmd);
senddata.Data_len=sizeof(m_hex_data)-2;
m_hex_data data=
{
//uint16_t data_counter;
//uint16_t resv;
//uint8_t data[128];
//uint32_t CRC32;
//uint16_t End_byte;
1,
0X0000,
{1,2,3,4,5},
0X12345678,
0X0A0D
};
memcpy(senddata.Data,&data,sizeof(m_hex_data));
#endif
//static uint8_t nusdata_buf[]={'A'};
//static int cnt=0;
req = KE_MSG_ALLOC_DYN(CUSTS1_VAL_NTF_REQ,
prf_get_task_from_id(TASK_ID_CUSTS1),
TASK_APP,
custs1_val_ntf_ind_req,
DEF_SVC1_TX_CTRL_CHAR_LEN);
req->handle = SVC1_IDX_TX_CTRL_VAL;
//req->length = sizeof(nusdata_buf);
req->length = sizeof(m_ble_node_state_data)+4;//前面2个U16
req->notification = true;
memcpy(req->value, &senddata, sizeof(uint8_t)* req->length );
ke_msg_send(req);
Z_timer = app_easy_timer(500, send_data_timer_cb);
}
#else
uint16_t crc16_calculate(uint8_t const * array, uint8_t size){
uint16_t crc16 = 0x0000;
uint16_t ret1 = 0;
for(int n = 0; n < size; n++){/*???6 -- ???????6?*/
crc16 = array[n] ^ crc16;
for(int i = 0;i < 8;i++){ /*???8 -- ????char???8bit,?bit????*/
if(crc16 & 0x01){
crc16 = crc16 >> 1;
crc16 = crc16 ^ 0xa001;
}
else{
crc16 = crc16 >> 1;
}
}
}
ret1 = crc16 >> 8;
ret1 = ret1 | (crc16 << 8);
return (crc16);
}
struct custs1_val_ntf_ind_req *req=NULL;
static void send_data_timer_cb()
{
//static int cnt=0;
static uint8_t nusdata_buf[50+4]={
0x4D,0x51,0x42,0x8D,0x04,0x00,0x70,0xCB,0xEA,0x80,0x01\
,0x24,0x1D,0x19,0xE5,0x19,0x98,0x00, 0x15,0x06,0x0C,0x00\
,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00\
,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00\
,0x00,0x00,0x00,0x00,0xED,0x6B,0x1,0x1,0x1,0x1};
uint16_t crc = crc16_calculate(&nusdata_buf[11],37);
memcpy(&nusdata_buf[11 + 1* 37],&crc, sizeof(uint16_t));
if (req !=NULL)
KE_MSG_FREE(req);
req = KE_MSG_ALLOC_DYN(CUSTS1_VAL_NTF_REQ,
prf_get_task_from_id(TASK_ID_CUSTS1),
TASK_APP,
custs1_val_ntf_ind_req,
DEF_SVC1_TX_CTRL_CHAR_LEN);
req->handle = SVC1_IDX_TX_CTRL_VAL;
req->length = sizeof(nusdata_buf);
req->notification = true;
memcpy(req->value, nusdata_buf, sizeof(uint8_t)* req->length );
ke_msg_send(req);
nusdata_buf[22]+=1;
Z_timer = app_easy_timer(500, send_data_timer_cb);
if(++cnt>=3)
{
cnt=0;
my_reset_func();
}
}
#endif
void user_app_init(void)
{
app_param_update_request_timer_used = EASY_TIMER_INVALID_TIMER;
// Initialize Manufacturer Specific Data
mnf_data_init();
// Initialize Advertising and Scan Response Data
memcpy(stored_adv_data, USER_ADVERTISE_DATA, USER_ADVERTISE_DATA_LEN);
stored_adv_data_len = USER_ADVERTISE_DATA_LEN;
memcpy(stored_scan_rsp_data, USER_ADVERTISE_SCAN_RESPONSE_DATA, USER_ADVERTISE_SCAN_RESPONSE_DATA_LEN);
stored_scan_rsp_data_len = USER_ADVERTISE_SCAN_RESPONSE_DATA_LEN;
X_timer = EASY_TIMER_INVALID_TIMER; //Initialise timer handlers
Y_timer = EASY_TIMER_INVALID_TIMER; //Initialise timer handlers
Z_timer = EASY_TIMER_INVALID_TIMER; //Initialise timer handlers
g_timer = EASY_TIMER_INVALID_TIMER; //Initialise timer handlers
default_app_on_init();
}
void user_app_adv_start(void)
{
// Schedule the next advertising data update
app_adv_data_update_timer_used = app_easy_timer(APP_ADV_DATA_UPDATE_TO, adv_data_update_timer_cb);
struct gapm_start_advertise_cmd* cmd;
cmd = app_easy_gap_undirected_advertise_get_active();
// Add manufacturer data to initial advertising or scan response data, if there is enough space
app_add_ad_struct(cmd, &mnf_data, sizeof(struct mnf_specific_data_ad_structure), 1);
app_easy_gap_undirected_advertise_start();
}
void user_app_connection(uint8_t connection_idx, struct gapc_connection_req_ind const *param)
{
if (app_env[connection_idx].conidx != GAP_INVALID_CONIDX)
{
app_connection_idx = connection_idx;
// Stop the advertising data update timer
app_easy_timer_cancel(app_adv_data_update_timer_used);
// Check if the parameters of the established connection are the preferred ones.
// If not then schedule a connection parameter update request.
if ((param->con_interval < user_connection_param_conf.intv_min) ||
(param->con_interval > user_connection_param_conf.intv_max) ||
(param->con_latency != user_connection_param_conf.latency) ||
(param->sup_to != user_connection_param_conf.time_out))
{
// Connection params are not these that we expect
app_param_update_request_timer_used = app_easy_timer(APP_PARAM_UPDATE_REQUEST_TO, param_update_request_timer_cb);
}
}
else
{
// No connection has been established, restart advertising
user_app_adv_start();
}
default_app_on_connection(connection_idx, param);
}
void user_app_adv_undirect_complete(uint8_t status)
{
// If advertising was canceled then update advertising data and start advertising again
if (status == GAP_ERR_CANCELED)
{
user_app_adv_start();
}
}
void user_app_disconnect(struct gapc_disconnect_ind const *param)
{
//app_easy_timer_cancel(Z_timer);
}
uint8_t val[100]={0};
//B001080016010B02082B2E000D0A
void user_svc1_rx_wr_ind_handler(ke_msg_id_t const msgid,
struct custs1_val_write_ind const *param,
ke_task_id_t const dest_id,
ke_task_id_t const src_id)
{
//uint8_t val[100]={0};
memcpy(val,param->value,param->length);
}
void user_svc1_tx_ntf_cfg_ind_handler(ke_msg_id_t const msgid,
struct custs1_val_write_ind const *param,
ke_task_id_t const dest_id,
ke_task_id_t const src_id)
{
uint8_t val = param->value[0];
if(val)//1--开 0--关
{
Z_timer = app_easy_timer(100, send_data_timer_cb);
}
else
{
app_easy_timer_cancel(Z_timer);
}
}
void user_svc1_rest_att_info_req_handler(ke_msg_id_t const msgid,
struct custs1_att_info_req const *param,
ke_task_id_t const dest_id,
ke_task_id_t const src_id)
{
struct custs1_att_info_rsp *rsp = KE_MSG_ALLOC(CUSTS1_ATT_INFO_RSP,
src_id,
dest_id,
custs1_att_info_rsp);
// Provide the connection index.
rsp->conidx = app_env[param->conidx].conidx;
// Provide the attribute index.
rsp->att_idx = param->att_idx;
// Force current length to zero.
rsp->length = 0;
// Provide the ATT error code.
rsp->status = ATT_ERR_WRITE_NOT_PERMITTED;
ke_msg_send(rsp);
}
//核心接口
void user_catch_rest_hndl(ke_msg_id_t const msgid,
void const *param,
ke_task_id_t const dest_id,
ke_task_id_t const src_id)
{
switch(msgid)
{
case CUSTS1_VAL_WRITE_IND:
{
struct custs1_val_write_ind const *msg_param = (struct custs1_val_write_ind const *)(param);
switch (msg_param->handle)
{
case SVC1_IDX_RX_CONTROL_VAL:
user_svc1_rx_wr_ind_handler(msgid, msg_param, dest_id, src_id);
break;
case SVC1_IDX_TX_CTRL_NTF_CFG:
user_svc1_tx_ntf_cfg_ind_handler(msgid, msg_param, dest_id, src_id);
break;
default:
break;
}
} break;
case CUSTS1_VAL_NTF_CFM:
{
struct custs1_val_ntf_cfm const *msg_param = (struct custs1_val_ntf_cfm const *)(param);
switch (msg_param->handle)
{
case SVC1_IDX_TX_CTRL_VAL:
break;
default:
break;
}
} break;
case CUSTS1_VAL_IND_CFM:
{
struct custs1_val_ind_cfm const *msg_param = (struct custs1_val_ind_cfm const *)(param);
switch (msg_param->handle)
{
default:
break;
}
} break;
case CUSTS1_ATT_INFO_REQ:
{
struct custs1_att_info_req const *msg_param = (struct custs1_att_info_req const *)param;
switch (msg_param->att_idx)
{
default:
user_svc1_rest_att_info_req_handler(msgid, msg_param, dest_id, src_id);
break;
}
} break;
case GAPC_PARAM_UPDATED_IND:
{
// Cast the "param" pointer to the appropriate message structure
struct gapc_param_updated_ind const *msg_param = (struct gapc_param_updated_ind const *)(param);
// Check if updated Conn Params filled to preferred ones
if ((msg_param->con_interval >= user_connection_param_conf.intv_min) &&
(msg_param->con_interval <= user_connection_param_conf.intv_max) &&
(msg_param->con_latency == user_connection_param_conf.latency) &&
(msg_param->sup_to == user_connection_param_conf.time_out))
{
}
} break;
case CUSTS1_VALUE_REQ_IND:
{
struct custs1_value_req_ind const *msg_param = (struct custs1_value_req_ind const *) param;
switch (msg_param->att_idx)
{
default:
{
// Send Error message
struct custs1_value_req_rsp *rsp = KE_MSG_ALLOC(CUSTS1_VALUE_REQ_RSP,
src_id,
dest_id,
custs1_value_req_rsp);
// Provide the connection index.
rsp->conidx = app_env[msg_param->conidx].conidx;
// Provide the attribute index.
rsp->att_idx = msg_param->att_idx;
// Force current length to zero.
rsp->length = 0;
// Set Error status
rsp->status = ATT_ERR_APP_ERROR;
// Send message
ke_msg_send(rsp);
} break;
}
} break;
default:
break;
}
}