#include "u_ble.h" #include "u_main.h" //#include "u_fifo.h" #include "u_global.h" //struct pack_info //{ // //uint8_t id; // volatile uint32_t time; // uint16_t len; // uint8_t otime_count; // uint8_t data[PROTO_DATA_MAX_LEN]; //}; //struct pack_info now_send_pack; //#include "co_math.h" uint16_t crc_16(uint8_t *pbuff, uint32_t len) { uint32_t i,j; uint8_t ds; uint16_t crc = 0xffff; static uint16_t poly[2] = {0, 0xa001}; for(j = len; j > 0; j--) { ds = *pbuff++; for(i = 0; i < 8; i++) { crc = (crc >> 1) ^ poly[(crc ^ ds ) & 1]; ds = ds >> 1; } } return crc; } /* 数据长度值 =协议头(1) + 字段类型(1)+数据长度(1)+数据域长度 CRC16双字节 =协议头+ 字段类型+ 数据长度值+数据域数据 */ extern void decode_app_cmd(uint8_t cmd, uint8_t *data, uint8_t len); void u_ble_data_recv(uint8_t *ble_data, uint16_t recv_len) { //uart_send(ble_data, recv_len); //ble_data_send(ble_data, recv_len); uint8_t i = 0; uint16_t crc, tmp; if(recv_len>=4) { tmp = ble_data[recv_len-1]; tmp = (tmp<<8) | ble_data[recv_len-2]; crc = crc_16(ble_data, recv_len - 2); #ifdef DEBUG_DRV_APP U_UART_PRINTF("\r\nrx: "); for(i = 0; i < recv_len; i++) { U_UART_PRINTF("%02X ",ble_data[i]); } U_UART_PRINTF("\r\n"); #endif if(tmp == crc&&ble_data[0]==0xA0&&(recv_len-2)==ble_data[2])//判断crc 数据长度 帧头是否满足 { decode_app_cmd(ble_data[1], &ble_data[3], ble_data[2]); } } } #if 0 //{APP_USER_MESS_IND, (ke_msg_func_t)app_user_mess_handler}, struct app_user_rsp { uint8_t defult; }; void send_xxx_rwip(void *arg) { struct app_user_rsp *rsp = KE_MSG_ALLOC(APP_USER_MESS_IND, //要发送的消息ID TASK_APP, //目标消息ID TASK_NONE, app_user_rsp); //发送消息的ID ,申请的内存大小 rsp->defult = 0; ke_msg_send(rsp); //发送消息 } static int u_xxx_handler(ke_msg_id_t const msgid, void const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id) { struct app_user_rsp *arg = (struct app_user_rsp*)param; UART_PRINTF("param_addr = %d", param); UART_PRINTF("dest_id = %d, src_id = %d \r\n", dest_id, src_id); return KE_MSG_CONSUMED; } #endif