#include "app.h" struct { unsigned char systemtime_minute;//距离上一个整点的分钟数 unsigned char xiema;//鞋码 unsigned char software_ver[2];//软件版本 unsigned char hardware_ver[2];//硬件版本 unsigned char power;//电量 unsigned char time_of_end;//续航时间 unsigned char inner_temperature;//内部温度 unsigned char pressure[4];//压力 }pm; struct { unsigned char power;//电量 unsigned char time_of_end;//续航时间 unsigned char inner_temperature;//内部温度 unsigned char pressure[4];//压力 }pm_other; //。。。。。。。。。。。。。。。。。。。。。。。。。。。。 // const char *fds_err_str(ret_code_t ret) { /* Array to map FDS return values to strings. */ static char const * err_str[] = { "FDS_ERR_OPERATION_TIMEOUT", "FDS_ERR_NOT_INITIALIZED", "FDS_ERR_UNALIGNED_ADDR", "FDS_ERR_INVALID_ARG", "FDS_ERR_NULL_ARG", "FDS_ERR_NO_OPEN_RECORDS", "FDS_ERR_NO_SPACE_IN_FLASH", "FDS_ERR_NO_SPACE_IN_QUEUES", "FDS_ERR_RECORD_TOO_LARGE", "FDS_ERR_NOT_FOUND", "FDS_ERR_NO_PAGES", "FDS_ERR_USER_LIMIT_REACHED", "FDS_ERR_CRC_CHECK_FAILED", "FDS_ERR_BUSY", "FDS_ERR_INTERNAL", }; return err_str[ret - NRF_ERROR_FDS_ERR_BASE]; } typedef struct { uint32_t device_name; unsigned char model_number[64];//设备型号 unsigned char systemtime[8];//系统时间 } configuration_t;//需要写到flish中的数据 /* 出工厂参数 */ static const configuration_t m_dummy_cfg = { .device_name =0x123456, .model_number = "smart shose", }; configuration_t cf; /* A record containing dummy configuration data. */ static fds_record_t const m_dummy_record = { .file_id = CONFIG_FILE, .key = CONFIG_REC_KEY, .data.p_data = &m_dummy_cfg, /* The length of a record is always expressed in 4-byte units (words). */ .data.length_words = (sizeof(m_dummy_cfg) + 3) / sizeof(uint32_t), }; /* Array to map FDS events to strings. */ static char const * fds_evt_str[] = { "FDS_EVT_INIT", "FDS_EVT_WRITE", "FDS_EVT_UPDATE", "FDS_EVT_DEL_RECORD", "FDS_EVT_DEL_FILE", "FDS_EVT_GC", }; extern uint32_t app_uart_put(uint8_t byte); void send_uart(unsigned char *bytes,int len) { for(int i=0;i50) return; buf[L++] = 0xAA; ver += 0xAA; //帧头 buf[L++] = Len; ver += Len; //长度 buf[L++] = ~Len; ver += (~Len);//长度反码 buf[L++] = cmd; ver += cmd; //命令 for(i=0;iresult == NRF_SUCCESS) { flashbusy=0; NRF_LOG_INFO("Event: %s received (NRF_SUCCESS)", fds_evt_str[p_evt->id]); } else { NRF_LOG_INFO("Event: %s received (%s)", fds_evt_str[p_evt->id], fds_err_str(p_evt->result)); } switch (p_evt->id) { case FDS_EVT_INIT: if (p_evt->result == NRF_SUCCESS) { m_fds_initialized = true; } break; case FDS_EVT_WRITE: flashbusy=0; { if (p_evt->result == NRF_SUCCESS) { NRF_LOG_INFO("Record ID:\t0x%04x", p_evt->write.record_id); NRF_LOG_INFO("File ID:\t0x%04x", p_evt->write.file_id); NRF_LOG_INFO("Record key:\t0x%04x", p_evt->write.record_key); } } break; case FDS_EVT_DEL_RECORD: flashbusy=0; { if (p_evt->result == NRF_SUCCESS) { NRF_LOG_INFO("Record ID:\t0x%04x", p_evt->del.record_id); NRF_LOG_INFO("File ID:\t0x%04x", p_evt->del.file_id); NRF_LOG_INFO("Record key:\t0x%04x", p_evt->del.record_key); } // m_delete_all.pending = false; } break; default: break; } } bool record_delete_next(void) { ret_code_t rc; fds_find_token_t tok = {0}; fds_record_desc_t desc = {0}; rc = fds_record_find(CONFIG_FILE, CONFIG_REC_KEY, &desc, &tok);//查找配置文件记录 if (rc == NRF_SUCCESS) { ret_code_t rc = fds_record_delete(&desc); if (rc != NRF_SUCCESS) { return false; } return true; } else { /* No records left to delete. */ return false; } } //每个Record最大保存1019个words 即4076byte //FDS_VIRTUAL_PAGES 宏中记录了整个FDS的空间 = (FDS_VIRTUAL_PAGES - 1)*4076 byte void config_file_init(void) { ret_code_t rc; // uint32_t *data; (void) fds_register(fds_evt_handler);//FDS注册 rc = fds_init();//fds初始化 APP_ERROR_CHECK(rc); while (!m_fds_initialized)//等待初始化完成 { sd_app_evt_wait();//等待过程中待机 } fds_stat_t stat = {0}; rc = fds_stat(&stat);//设置统计数据 APP_ERROR_CHECK(rc); //清风带你学蓝牙下册270页有详细讲解 // NRF_LOG_INFO("\r\n"); // NRF_LOG_INFO("fds info"); // NRF_LOG_INFO("pages_available = %d",stat.pages_available); // NRF_LOG_INFO("open_records = %d",stat.open_records); // NRF_LOG_INFO("valid_records = %d",stat.valid_records); // NRF_LOG_INFO("dirty_records = %d",stat.dirty_records); // NRF_LOG_INFO("words_reserved = %d",stat.words_reserved); // NRF_LOG_INFO("words_used = %d",stat.words_used); // NRF_LOG_INFO("largest_contig = %d",stat.largest_contig); // NRF_LOG_INFO("freeable_words = %d",stat.freeable_words); // NRF_LOG_INFO("done.\r\n"); fds_record_desc_t desc = {0};//用来操作记录的描述符结构清零 fds_find_token_t tok = {0};//保存秘钥的令牌清零 rc = fds_record_find(CONFIG_FILE, CONFIG_REC_KEY, &desc, &tok);//对应KEY记录查找数据 if (rc == NRF_SUCCESS)//如果查找成功 { /* A config file is in flash. Let's update it. */ fds_flash_record_t config = {0};//把配置清零 /* Open the record and read its contents. */ rc = fds_record_open(&desc, &config);//打开记录读取数据 APP_ERROR_CHECK(rc); // NRF_LOG_INFO("Read DataLen = %d,config file len = %d",config.p_header->length_words,(sizeof(configuration_t)+3)/4); if(config.p_header->length_words != (sizeof(configuration_t)+3)/4)//判断一下读出来的参数结构体长度是否正确 { /* Close the record when done reading. */ rc = fds_record_close(&desc);//关闭记录 APP_ERROR_CHECK(rc); // NRF_LOG_INFO("Update config file..."); //参数结构体不正确 record_delete_next();//把所有记录清零 rc = fds_record_write(&desc, &m_dummy_record);//重新写记录 APP_ERROR_CHECK(rc); // NRF_LOG_INFO("Update config file..done."); memcpy(&cf, &m_dummy_cfg,sizeof(configuration_t));//以出厂设置作为当前运行参数 } else//读出来的长度一样,关闭记录 { memcpy(&cf, config.p_data,sizeof(configuration_t)); rc = fds_record_close(&desc);//关闭记录 APP_ERROR_CHECK(rc); // NRF_LOG_INFO("Data = "); // data = (uint32_t *)config.p_data; // for (uint16_t i=0;ilength_words;i++) // { // NRF_LOG_INFO("0x%8x ",data[i]);//打印输出数据 // } // NRF_LOG_INFO("\r\n"); } } else { /* System config not found; write a new one. */ NRF_LOG_INFO("Writing config file..."); rc = fds_record_write(&desc, &m_dummy_record);//重新写记录 APP_ERROR_CHECK(rc); } pm.software_ver[0]=1; pm.software_ver[1]=2; pm.hardware_ver[0]=1; pm.hardware_ver[1]=4; } //。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。 #define sportdatakey_file_id 0x2111 #define sportdatakey_rec_key 0x2323 #define step_number_length 24*30 unsigned short step_journey_cun=0;//总共保存的数据量 unsigned int step_number[step_number_length];//用于记录步数和路程,高16位是步数,低16位是路程 //void write_step_journey(unsigned short step_num,unsigned short jour) //{ // step_number[step_journey_cun] = (unsigned int)jour; // step_number[step_journey_cun] |= ((unsigned int)step_num)<<16; // step_journey_cun++; // if(step_journey_cun >= step_number_length)step_journey_cun=0; //} //以增量方式添加步数和路程 void add_step_journey(unsigned char step_c,unsigned short jour_c) { unsigned short step = (step_number[step_journey_cun]&0xffff0000)>>16; unsigned short journey = step_number[step_journey_cun]&0x0000ffff; step += step_c; journey += jour_c; step_number[step_journey_cun] = (unsigned int)journey; step_number[step_journey_cun] |= ((unsigned int)step)<<16; NRF_LOG_INFO("add_step_journey -> step_number[step_journey_cun]=0x%8x ,step_journey_cun = %d",step_number[step_journey_cun],step_journey_cun); } int update_step_journey_work_statu=0; void update_step_journey_work(void) { ret_code_t rc; fds_record_desc_t desc = {0};//用来操作记录的描述符结构清零 fds_find_token_t tok = {0};//保存秘钥的令牌清零 fds_record_t sportdatakey_record={0}; if(flashbusy==1) { NRF_LOG_INFO("flashbusy.....return "); return;//flish在忙,什么都不做 } if(update_step_journey_work_statu==0)return; NRF_LOG_INFO("update_step_journey_work_statu= %d ",update_step_journey_work_statu); switch(update_step_journey_work_statu) { case 0://状态0,什么都不用做 break; case 1://状态1,需要发送一次查询 rc = fds_record_find(sportdatakey_file_id, sportdatakey_rec_key, &desc, &tok);//对应KEY记录查找数据 switch(rc) { case FDS_ERR_NOT_FOUND: NRF_LOG_INFO("->fds_record_find = FDS_ERR_NOT_FOUND"); update_step_journey_work_statu=2; break; case FDS_ERR_NOT_INITIALIZED: NRF_LOG_INFO("->fds_record_find = FDS_ERR_NOT_INITIALIZED"); break; case FDS_ERR_NULL_ARG: NRF_LOG_INFO("->fds_record_find = FDS_ERR_NULL_ARG"); break; case NRF_SUCCESS: NRF_LOG_INFO("->fds_record_find = NRF_SUCCESS"); flashbusy = 1; rc = fds_record_delete(&desc); APP_ERROR_CHECK(rc); update_step_journey_work_statu=2; break; default:NRF_LOG_INFO("->fds_record_find = 0x%8x \n",rc); break; } break; case 2://状态2,写 memset(&desc,0,sizeof(fds_record_desc_t)); sportdatakey_record.file_id = sportdatakey_file_id; sportdatakey_record.key = sportdatakey_rec_key; sportdatakey_record.data.p_data = (void*)step_number; sportdatakey_record.data.length_words = (unsigned int)step_journey_cun; rc = fds_record_write(&desc, &sportdatakey_record);//重新写记录 switch(rc) { case NRF_SUCCESS: NRF_LOG_INFO("->fds_record_write = NRF_SUCCESS"); update_step_journey_work_statu=3; flashbusy = 1; break; case FDS_ERR_NOT_INITIALIZED: NRF_LOG_INFO("->fds_record_write = FDS_ERR_NOT_INITIALIZED"); break; case FDS_ERR_NULL_ARG: NRF_LOG_INFO("->fds_record_write = FDS_ERR_NULL_ARG"); break; case FDS_ERR_INVALID_ARG: NRF_LOG_INFO("->fds_record_write = FDS_ERR_INVALID_ARG"); break; case FDS_ERR_UNALIGNED_ADDR: NRF_LOG_INFO("->fds_record_write = FDS_ERR_UNALIGNED_ADDR"); update_step_journey_work_statu=3; break; case FDS_ERR_RECORD_TOO_LARGE: NRF_LOG_INFO("->fds_record_write = FDS_ERR_RECORD_TOO_LARGE"); break; case FDS_ERR_NO_SPACE_IN_QUEUES: NRF_LOG_INFO("->fds_record_write = FDS_ERR_NO_SPACE_IN_QUEUES"); break; case FDS_ERR_NO_SPACE_IN_FLASH: NRF_LOG_INFO("->fds_record_write = FDS_ERR_NO_SPACE_IN_FLASH"); update_step_journey_work_statu = 4; break; default:NRF_LOG_INFO("->fds_record_write = 0x%8x \n",rc); break; } break; case 3://状态3,读取写完的结果并校验数据 rc = fds_record_find(sportdatakey_file_id, sportdatakey_rec_key, &desc, &tok);//对应KEY记录查找数据 switch(rc) { case FDS_ERR_NOT_FOUND: NRF_LOG_INFO("->fds_record_find = FDS_ERR_NOT_FOUND"); break; case FDS_ERR_NOT_INITIALIZED: NRF_LOG_INFO("->fds_record_find = FDS_ERR_NOT_INITIALIZED"); break; case FDS_ERR_NULL_ARG: NRF_LOG_INFO("->fds_record_find = FDS_ERR_NULL_ARG"); break; case NRF_SUCCESS: NRF_LOG_INFO("->fds_record_find = NRF_SUCCESS"); { fds_flash_record_t config = {0};//把配置清零 rc = fds_record_open(&desc, &config);//打开记录读取数据 APP_ERROR_CHECK(rc); step_journey_cun = config.p_header->length_words; // memcpy(step_number,config.p_data,step_journey_cun*4); // for(int i=0;ifds_record_find = 0x%8x \n",rc); break; } break; case 4:////状态4,垃圾回收 NRF_LOG_INFO("fds_gc"); rc = fds_gc();//垃圾回收 switch(rc) { case NRF_SUCCESS: NRF_LOG_INFO("->fds_gc = NRF_SUCCESS"); update_step_journey_work_statu=2; flashbusy = 1; break; case FDS_ERR_NOT_INITIALIZED: NRF_LOG_INFO("->fds_gc = FDS_ERR_NOT_INITIALIZED"); break; case FDS_ERR_NO_SPACE_IN_QUEUES: NRF_LOG_INFO("->fds_gc = FDS_ERR_NO_SPACE_IN_QUEUES"); break; default:NRF_LOG_INFO("->fds_gc = 0x%8x \n",rc); break; } break; default : break; } } //把记录保存到中 void update_step_journey(void) { update_step_journey_work_statu=1; } //把flish中的数据加载到内存 void load_step_journey(void) { ret_code_t rc; fds_record_desc_t desc = {0};//用来操作记录的描述符结构清零 fds_find_token_t tok = {0};//保存秘钥的令牌清零 rc = fds_record_find(sportdatakey_file_id, sportdatakey_rec_key, &desc, &tok);//对应KEY记录查找数据 APP_ERROR_CHECK(rc); if (rc == NRF_SUCCESS)//如果查找成功 { // printf("load_step_journey rc == NRF_SUCCESS\n"); /* A config file is in flash. Let's update it. */ fds_flash_record_t config = {0};//把配置清零 /* Open the record and read its contents. */ rc = fds_record_open(&desc, &config);//打开记录读取数据 APP_ERROR_CHECK(rc); step_journey_cun = config.p_header->length_words; memcpy(step_number,config.p_data,step_journey_cun*4); rc = fds_record_close(&desc);//关闭记录 APP_ERROR_CHECK(rc); } else { } } void send_ble_data_A0_0(void) { uint8_t buf[100]; uint8_t L=0; buf[L++] = 0; for(int i=0;i<8;i++) { buf[L++] = cf.systemtime[i]; } send_to_ble_nus(DEX_NUM,0xa0,buf,L); } //发送数据到串口查询压力数据 void send_uart_data_A1_1(void) { uint8_t buf[100]; uint8_t L=0; buf[L++] = 0; for(int i=0;i<8;i++) { buf[L++] = cf.systemtime[i]; } send_to_uart_AABBCC(DEX_NUM,0xa0,buf,L); } void send_ble_data_A1_0(void) { uint8_t buf[100]; uint8_t L=0; buf[L++] = 0; for(int i=0;i<64;i++) { buf[L++] = cf.model_number[i]; } buf[L++] = pm.software_ver[0]; buf[L++] = pm.software_ver[1]; buf[L++] = pm.hardware_ver[0]; buf[L++] = pm.hardware_ver[1]; send_to_ble_nus(DEX_NUM,0xa1,buf,L); } void send_ble_data_A1_1(void) { uint8_t buf[100]; uint8_t L=0; buf[L++] = 1; buf[L++] = pm.power; buf[L++] = pm.time_of_end; buf[L++] = pm.inner_temperature; for(int i=0;i<4;i++) { buf[L++] = pm.pressure[i]; } buf[L++] = pm_other.power; buf[L++] = pm_other.time_of_end; buf[L++] = pm_other.inner_temperature; for(int i=0;i<4;i++) { buf[L++] = pm_other.pressure[i]; } send_to_ble_nus(DEX_NUM,0xa1,buf,L); } #define PAGE_E 50 #define Pagesendtimes 20;//同一条命令最多发送的次数 unsigned char PagesendtimesIndex=0; unsigned char pageindex=0;//标记这次要发的是第几包数据 unsigned char allpagecun=0;//一共要发多少包数据 void send_ble_data_A1_2(void) { uint8_t buf[255]; uint8_t L=0; buf[L++] = 2; buf[L++] = pageindex; if(pageindex >= allpagecun)//表示这次发的是最后一包数据 { for(int i=0;PAGE_E*(pageindex-1)+i <= step_journey_cun ;i++) { buf[L++] = step_number[PAGE_E*(pageindex-1)+i]>>24; buf[L++] = step_number[PAGE_E*(pageindex-1)+i]>>16; buf[L++] = step_number[PAGE_E*(pageindex-1)+i]>>8; buf[L++] = step_number[PAGE_E*(pageindex-1)+i]>>0; NRF_LOG_INFO("send_ble_data_A1_2 -> step_number[step_journey_cun]=0x%8x ,step_journey_cun = %d",step_number[step_journey_cun],step_journey_cun); NRF_LOG_INFO("send_ble_data_A1_2 -> for %d 0x%x",PAGE_E*(pageindex-1)+i,step_number[PAGE_E*(pageindex-1)+i]); } NRF_LOG_INFO("send_ble_data_A1_2 -> end"); } else { for(int i=0;i>24; buf[L++] = step_number[PAGE_E*(pageindex-1)+i]>>16; buf[L++] = step_number[PAGE_E*(pageindex-1)+i]>>8; buf[L++] = step_number[PAGE_E*(pageindex-1)+i]>>0; } NRF_LOG_INFO("send_ble_data_A1_2 -> pageindex"); } send_to_ble_nus(DEX_NUM,0xa1,buf,L); } //发送查询命令的反馈 void send_ble_data_A1_2_0(unsigned char cun) { uint8_t buf[255]; uint8_t L=0; buf[L++] = 2; buf[L++] = 0; for(int i=0;i<8;i++) { buf[L++] = cf.systemtime[i]; } buf[L++] = cun; send_to_ble_nus(DEX_NUM,0xa1,buf,L); NRF_LOG_INFO("send_ble_data_A1_2_0 -> cun == %d",cun); } //处理手机发过来的命令 //串口协议 char anilicedata(const unsigned char *buff,unsigned char *buffout,int len) { int i=0,j=0; unsigned char crc=0; if(len<3)return 0; for(i=0;i4) { if((buff[i]==0xaa)&&(buff[i+1]+buff[i+2]==0xff))//判断桢头和长度 { if(len - i >= buff[i+1])//数据包长度符合 { for(j=i;j < i+buff[i+1]-1;j++)//计算校验 { crc += buff[j]; } if( buff[i + buff[i+1] - 1] == crc) { for(j = 0;j < i+buff[i+1]; j++) { buffout[j] = buff[j+i]; } return 1; } } } } } return 0; } unsigned char uart_command_buff[100]; int uart_command_callback(const unsigned char *data,int length) { memcpy(uart_command_buff,data,length); switch(uart_command_buff[3])//处理命令号 { case CMD_HEART: NRF_LOG_INFO("uart_command_callback -> CMD_HEART"); Send_bytes_to_Ble(uart_command_buff,length); break; case CMD_MOTION: Send_bytes_to_Ble(uart_command_buff,length); NRF_LOG_INFO("uart_command_callback -> CMD_MOTION"); break; case CMD_UPDATA: switch(uart_command_buff[4]) { case UPDATE_NONE: break; case UPDATE_RUN://主机上报步数和路程 ,前1个字节是步数增量,路程两个字节(无符号16位,单位是厘米) { unsigned short temp=(((unsigned short)uart_command_buff[6])<<8) | ((unsigned short)uart_command_buff[7]); add_step_journey(uart_command_buff[5],temp); NRF_LOG_INFO("uart_command_callback -> UPDATE_RUN %d,%d",uart_command_buff[8],temp); }break; case UPDATE_BASEINFO: { int i=5; pm.power = uart_command_buff[i++]; pm.inner_temperature = uart_command_buff[i++]; pm.pressure[0]=uart_command_buff[i++]; pm.pressure[1]=uart_command_buff[i++]; pm.pressure[2]=uart_command_buff[i++]; pm.pressure[3]=uart_command_buff[i++]; pm_other.power = uart_command_buff[i++]; pm_other.inner_temperature = uart_command_buff[i++]; pm_other.pressure[0]=uart_command_buff[i++]; pm_other.pressure[1]=uart_command_buff[i++]; pm_other.pressure[2]=uart_command_buff[i++]; pm_other.pressure[3]=uart_command_buff[i++]; // NRF_LOG_INFO("uart_command_callback -> UPDATE_BASEINFO "); //SEGGER_RTT_printf(0,"%d%%,%d,0x%x 0x%x 0x%x 0x%x ;%d%%,%d,0x%x 0x%x 0x%x 0x%x\n",pm.power,pm.inner_temperature,pm.pressure[0],pm.pressure[1],pm.pressure[2],pm.pressure[3],pm_other.power,pm_other.inner_temperature,pm_other.pressure[0],pm_other.pressure[1],pm_other.pressure[2],pm_other.pressure[3]); }break; default:NRF_LOG_INFO("uart_command_callback -> default %d",uart_command_buff[4]); break; } break; default: break; } return uart_command_buff[3]; } void send_uart_data_UPDATE_BASEINFO(void) { uint8_t buf[100]; uint8_t L=0; buf[L++]=UPDATE_BASEINFO; send_to_uart_AABBCC(DEX_NUM,UPDATE_BASEINFO,buf,L); } unsigned char buffrecdata[100]; int ble_phone_command_callback(const unsigned char *data,int length) { if(anilicedata(data,buffrecdata,length)==0) { return -1; } switch(buffrecdata[3])//处理命令号 { case 0xA1://查询 switch(buffrecdata[4]) { case 0: //查询设备基本信息 NRF_LOG_INFO("ble_phone_command_callback -> 0xA1_0"); send_ble_data_A1_0(); break; case 1: //查询数据 NRF_LOG_INFO("ble_phone_command_callback -> 0xA1_1"); send_ble_data_A1_1();//转发给手机端 break; case 2: //查询步数距离 NRF_LOG_INFO("ble_phone_command_callback -> 0xA1_2_%d",buffrecdata[5]); if(buffrecdata[5]==0)//这是手机发过来的查询请求 { for(int i=0;i<8;i++) { cf.systemtime[i] = buffrecdata[6+i]; } pm.systemtime_minute=buffrecdata[14];//距离上一个整点的分钟数 NRF_LOG_INFO("ble_phone_command_callback -> pm.systemtime_minute = %d",pm.systemtime_minute); if((step_journey_cun==0)&&(step_number[step_journey_cun]==0))//没有数据的时候回一个包的数量为0 { send_ble_data_A1_2_0(0); } else if((step_journey_cun==0)&&(step_number[step_journey_cun]!=0)) { allpagecun=1; send_ble_data_A1_2_0(1); pageindex = 1;//设个标志让定时器发送第一包数据 PagesendtimesIndex = Pagesendtimes; } else { //计算总共要发的包数 if(step_journey_cun%PAGE_E>0) allpagecun = step_journey_cun/PAGE_E + 1; else allpagecun = step_journey_cun/PAGE_E; send_ble_data_A1_2_0(allpagecun); //发送反馈告诉手机一共有多少包数据要发 pageindex = 1;//设个标志让定时器发送第一包数据 PagesendtimesIndex = Pagesendtimes; } } else { if(buffrecdata[5] == pageindex)//判断一下是不是当前发送包的反馈数据 { if(pageindex >= allpagecun) { pageindex = 0;//表示发送已经结束了,这个时候可以清理保存的数据 step_journey_cun = 0;//清理保存的数据 step_number[step_journey_cun]=0; } else { pageindex++;//发送下一包,发送完成后 PagesendtimesIndex = Pagesendtimes; } } } break; default : break; } break; default: break; } return 0; } void send_ble_data_temp(void) { uint8_t buf[255]; uint8_t L=0; buf[L++] = 2; buf[L++] = 1; // for(int i=0;i<8;i++) // { // buf[L++] = 0xff; // } // buf[L++] = 30; send_to_ble_nus(DEX_NUM,0xa1,buf,L); } unsigned short iiiiiii=500; unsigned short timecun=0; void timer_callback_Chen(void) { if(timecun%100 == 0) { update_step_journey_work();//1s } if(timecun%500 == 0)NRF_LOG_INFO("timer_callback_Chen -> step_number[step_journey_cun]=0x%8x ,step_journey_cun = %d",step_number[step_journey_cun],step_journey_cun); // send_ble_data_temp(); if((pageindex > 0) && ( pageindex <= allpagecun) && ( timecun%50 == 0)) { if(PagesendtimesIndex>0) { send_ble_data_A1_2();//发送数据 PagesendtimesIndex--; } else { //在这里报错,发送超时错误 } } if(timecun%6000==0)pm.systemtime_minute++; if(pm.systemtime_minute>=60)//到达一个小时 { step_journey_cun++; step_number[step_journey_cun] = 0;//清0 if(step_journey_cun >= step_number_length)step_journey_cun=0; pm.systemtime_minute=0; NRF_LOG_INFO("timer_callback_Chen -> pm.systemtime_minute>=60 , step_journey_cun = %d",step_journey_cun); } timecun++; }