#include "database.h" #include "usart.h" uint16_t PDA_pushArr[1024]; extern TipsFlag tipsflag; extern Menu_table menu; DatabaseLoc dbloc; DatabaseEvent dbeve; DatabaseLoc *dblocptr = &dbloc; DatabaseEvent *dbeveptr = &dbeve; /** * @breaf 数据库初始化 * @Explanation 向各头部写入关键信息 */ void Database_init(uint16_t pushsize_loc, uint16_t pullsize_loc,uint16_t pushsize_eve, uint16_t pullsize_eve) { Flash_ReadBytes((uint16_t*)&(dblocptr->temp.loc_pushIndex),LocDbHeadStart,4);//读取loc头部是否发生写入 if(dblocptr->temp.loc_pullIndex == 0xFFFF && dblocptr->temp.loc_pushIndex==0xFFFF)//未写入 { dblocptr->headinfo.loc_pushIndex = 0; dblocptr->headinfo.loc_pullIndex = 0; dblocptr->headinfo.loc_pushSize = pushsize_loc; dblocptr->headinfo.loc_pullSize = pullsize_loc; Flash_WriteBytes((uint16_t*)&(dblocptr->headinfo),LocDbHeadStart,4); } else { //*高地址字节在前 dblocptr->headinfo.loc_pushIndex = dblocptr->temp.loc_pushIndex; dblocptr->headinfo.loc_pullIndex = dblocptr->temp.loc_pushIndex; dblocptr->headinfo.loc_pushSize = dblocptr->temp.loc_pushSize; dblocptr->headinfo.loc_pullSize = dblocptr->temp.loc_pullSize; } Flash_ReadBytes((uint16_t*)&(dbeveptr->temp),EveDbHeadStart,4);//读取loc头部是否发生写入 if(dbeveptr->temp.eve_pushIndex == 0xFFFF && dbeveptr->temp.eve_pullIndex ==0xFFFF)//未写入 { dbeveptr->headinfo.eve_pushIndex = 0; dbeveptr->headinfo.eve_pullIndex = 0; dbeveptr->headinfo.eve_pushSize = pushsize_loc; dbeveptr->headinfo.eve_pullSize = pullsize_loc; Flash_WriteBytes((uint16_t*)&(dbeveptr->headinfo),EveDbHeadStart,4); } else { //*高地址字节在前 dbeveptr->headinfo.eve_pushIndex = dbeveptr->temp.eve_pushIndex; dbeveptr->headinfo.eve_pullIndex = dbeveptr->temp.eve_pullIndex; dbeveptr->headinfo.eve_pushSize = dbeveptr->temp.eve_pushSize; dbeveptr->headinfo.eve_pullSize = dbeveptr->temp.eve_pullSize; } } HAL_StatusTypeDef PushSta; //***************定位信息入库 void Database_Push(uint8_t ptr) { if(ptr==0)//位置信息写入 { if(dblocptr->headinfo.loc_pushIndex!=0) { if(dblocptr->temp.latitude != dblocptr->location.latitude && dblocptr->temp.longitude != dblocptr->location.longitude)//相同纬度参数(包含未获取定位为0) { Flash_WriteBytes((uint16_t*)&(dblocptr->location.alarmFlag),LocDbBodyStart + (dblocptr->headinfo.loc_pushIndex*34),17); Flash_ReadBytes((uint16_t*)&(dblocptr->temp.alarmFlag),LocDbBodyStart + ((dblocptr->headinfo.loc_pushIndex-1)*34),17);//读取body信息 TestPrintStruct(dblocptr,1);//读取Temp dblocptr->headinfo.loc_pushIndex+=1; Flash_WriteBytes((uint16_t*)&(dblocptr->headinfo),LocDbHeadStart,4);//更新刻度 } } else if(dblocptr->location.latitude!=0 && dblocptr->headinfo.loc_pushIndex==0)//判断定位是否正常工作 { Flash_WriteBytes((uint16_t*)&(dblocptr->location.alarmFlag),LocDbBodyStart,17);//34 dblocptr->headinfo.loc_pushIndex+=1; Flash_WriteBytes((uint16_t*)&(dblocptr->headinfo),LocDbHeadStart,4);//更新刻度 } } TestPrintStruct(dblocptr,0);//读取Work Flash_ReadBytes((uint16_t*)&(dblocptr->temp.loc_pushIndex),LocDbHeadStart,4);//读取loc头部写入信息 if(dblocptr->temp.loc_pushIndex == dblocptr->headinfo.loc_pushSize)//入库结束(返回 { dblocptr->headinfo.loc_pushIndex=0; Flash_WriteBytes((uint16_t*)&(dblocptr->headinfo),LocDbHeadStart,4);//更新刻度 } } void TestPrintStruct(DatabaseLoc *ptr,uint8_t temp) { if(temp) { printf("temp:%08X%08X%08X%08X%04X%04X%04X%d%d%d%d%d%d%02X%02X%02X%02X%02X%02X\r\n", \ ptr->temp.alarmFlag, \ ptr->temp.statusFlag, \ ptr->temp.latitude, \ ptr->temp.longitude, \ ptr->temp.height, \ ptr->temp.speed, \ ptr->temp.direction, \ ptr->temp.timeBCD[0], \ ptr->temp.timeBCD[1], \ ptr->temp.timeBCD[2], \ ptr->temp.timeBCD[3], \ ptr->temp.timeBCD[4], \ ptr->temp.timeBCD[5], \ ptr->temp.signalCmd, \ ptr->temp.signalCmd_len, \ ptr->temp.CSQ, \ ptr->temp.atellitesCmd, \ ptr->temp.atellitesCmd_len, \ ptr->temp.satellitesNum); } else { printf("now :%08X%08X%08X%08X%04X%04X%04X%d%d%d%d%d%d%02X%02X%02X%02X%02X%02X\r\n", \ ptr->location.alarmFlag, \ ptr->location.statusFlag, \ ptr->location.latitude, \ ptr->location.longitude, \ ptr->location.height, \ ptr->location.speed, \ ptr->location.direction, \ ptr->location.timeBCD[0], \ ptr->location.timeBCD[1], \ ptr->location.timeBCD[2], \ ptr->location.timeBCD[3], \ ptr->location.timeBCD[4], \ ptr->location.timeBCD[5], \ ptr->location.signalCmd, \ ptr->location.signalCmd_len, \ ptr->location.CSQ, \ ptr->location.atellitesCmd, \ ptr->location.atellitesCmd_len, \ ptr->location.satellitesNum); } }