|
@@ -1,5 +1,6 @@
|
|
|
#include "database.h"
|
|
|
#include "usart.h"
|
|
|
+#include "tt808.h"
|
|
|
|
|
|
uint16_t PDA_pushArr[1024];
|
|
|
|
|
@@ -12,6 +13,7 @@ DatabaseEvent dbeve;
|
|
|
DatabaseLoc *dblocptr = &dbloc;
|
|
|
DatabaseEvent *dbeveptr = &dbeve;
|
|
|
|
|
|
+bool MiddleObj =false;
|
|
|
|
|
|
/**
|
|
|
* @breaf 数据库初始化
|
|
@@ -19,8 +21,8 @@ DatabaseEvent *dbeveptr = &dbeve;
|
|
|
*/
|
|
|
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)//未写入
|
|
|
+ Flash_ReadBytes((uint16_t*)&(dblocptr->temppush.loc_pushIndex),LocDbHeadStart,4);//读取loc头部是否发生写入
|
|
|
+ if(dblocptr->temppush.loc_pullIndex == 0xFFFF && dblocptr->temppush.loc_pushIndex==0xFFFF)//未写入
|
|
|
{
|
|
|
dblocptr->headinfo.loc_pushIndex = 0;
|
|
|
dblocptr->headinfo.loc_pullIndex = 0;
|
|
@@ -31,17 +33,17 @@ void Database_init(uint16_t pushsize_loc, uint16_t pullsize_loc,uint16_t pushsiz
|
|
|
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;
|
|
|
+ dblocptr->headinfo.loc_pushIndex = dblocptr->temppush.loc_pushIndex;
|
|
|
+ dblocptr->headinfo.loc_pullIndex = dblocptr->temppush.loc_pushIndex;
|
|
|
+ dblocptr->headinfo.loc_pushSize = dblocptr->temppush.loc_pushSize;
|
|
|
+ dblocptr->headinfo.loc_pullSize = dblocptr->temppush.loc_pullSize;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- Flash_ReadBytes((uint16_t*)&(dbeveptr->temp),EveDbHeadStart,4);//读取loc头部是否发生写入
|
|
|
- if(dbeveptr->temp.eve_pushIndex == 0xFFFF && dbeveptr->temp.eve_pullIndex ==0xFFFF)//未写入
|
|
|
+ Flash_ReadBytes((uint16_t*)&(dbeveptr->temppush),EveDbHeadStart,4);//读取loc头部是否发生写入
|
|
|
+ if(dbeveptr->temppush.eve_pushIndex == 0xFFFF && dbeveptr->temppush.eve_pullIndex ==0xFFFF)//未写入
|
|
|
{
|
|
|
dbeveptr->headinfo.eve_pushIndex = 0;
|
|
|
dbeveptr->headinfo.eve_pullIndex = 0;
|
|
@@ -52,26 +54,27 @@ void Database_init(uint16_t pushsize_loc, uint16_t pullsize_loc,uint16_t pushsiz
|
|
|
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;
|
|
|
+ dbeveptr->headinfo.eve_pushIndex = dbeveptr->temppush.eve_pushIndex;
|
|
|
+ dbeveptr->headinfo.eve_pullIndex = dbeveptr->temppush.eve_pullIndex;
|
|
|
+ dbeveptr->headinfo.eve_pushSize = dbeveptr->temppush.eve_pushSize;
|
|
|
+ dbeveptr->headinfo.eve_pullSize = dbeveptr->temppush.eve_pullSize;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
HAL_StatusTypeDef PushSta;
|
|
|
//***************定位信息入库
|
|
|
-void Database_Push(uint8_t ptr)
|
|
|
+void Database_Push(uint8_t object)
|
|
|
{
|
|
|
- if(ptr==0)//位置信息写入
|
|
|
+ if(object==0)//位置信息写入
|
|
|
{
|
|
|
if(dblocptr->headinfo.loc_pushIndex!=0)
|
|
|
{
|
|
|
- if(dblocptr->temp.latitude != dblocptr->location.latitude && dblocptr->temp.longitude != dblocptr->location.longitude)//相同纬度参数(包含未获取定位为0)
|
|
|
+ if(dblocptr->temppush.latitude != dblocptr->location.latitude && dblocptr->temppush.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信息
|
|
|
+ Flash_ReadBytes((uint16_t*)&(dblocptr->temppush.alarmFlag),LocDbBodyStart + ((dblocptr->headinfo.loc_pushIndex-1)*34),17);//读取body信息
|
|
|
+ printf("入库操作,当前索引%d\r\n",dblocptr->headinfo.loc_pushIndex);
|
|
|
TestPrintStruct(dblocptr,1);//读取Temp
|
|
|
dblocptr->headinfo.loc_pushIndex+=1;
|
|
|
Flash_WriteBytes((uint16_t*)&(dblocptr->headinfo),LocDbHeadStart,4);//更新刻度
|
|
@@ -89,39 +92,67 @@ void Database_Push(uint8_t ptr)
|
|
|
|
|
|
|
|
|
TestPrintStruct(dblocptr,0);//读取Work
|
|
|
- Flash_ReadBytes((uint16_t*)&(dblocptr->temp.loc_pushIndex),LocDbHeadStart,4);//读取loc头部写入信息
|
|
|
- if(dblocptr->temp.loc_pushIndex == dblocptr->headinfo.loc_pushSize)//入库结束(返回
|
|
|
+ Flash_ReadBytes((uint16_t*)&(dblocptr->temppush.loc_pushIndex),LocDbHeadStart,4);//读取loc头部写入信息
|
|
|
+ if(dblocptr->temppush.loc_pushIndex == dblocptr->headinfo.loc_pushSize)//入库结束(返回
|
|
|
{
|
|
|
+ printf("入库操作,当前索引%d,达边界值返回覆写\r\n",dblocptr->headinfo.loc_pushIndex);
|
|
|
dblocptr->headinfo.loc_pushIndex=0;
|
|
|
Flash_WriteBytes((uint16_t*)&(dblocptr->headinfo),LocDbHeadStart,4);//更新刻度
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
-void TestPrintStruct(DatabaseLoc *ptr,uint8_t temp)
|
|
|
+void Database_Pull(uint8_t object)
|
|
|
{
|
|
|
- if(temp)
|
|
|
+ if(object==0)//位置信息出库
|
|
|
+ {
|
|
|
+ Flash_ReadBytes((uint16_t*)&(dblocptr->headinfo.loc_pushIndex),LocDbHeadStart,4);//读取loc头部写入信息
|
|
|
+ printf("出库操作,共出库%d当前索引%d\r\n",dblocptr->headinfo.loc_pushIndex,dblocptr->headinfo.loc_pushIndex);
|
|
|
+
|
|
|
+ if(dblocptr->headinfo.loc_pushIndex!=0 || dblocptr->temppull.alarmFlag!=0xFFFFFFFF)//库内有数据
|
|
|
+ {
|
|
|
+ Flash_ReadBytes((uint16_t*)&(dblocptr->temppull.alarmFlag),LocDbBodyStart,17);//读取出库body信息
|
|
|
+ dblocptr->headinfo.loc_pullIndex+=1;
|
|
|
+ Flash_WriteBytes((uint16_t*)&(dblocptr->headinfo),LocDbHeadStart,4);//更新刻度
|
|
|
+ Retrans = true;
|
|
|
+ }
|
|
|
+ if(dblocptr->temppull.alarmFlag==0xFFFFFFFF)
|
|
|
+ {
|
|
|
+ dblocptr->headinfo.loc_pullIndex=0;
|
|
|
+ dblocptr->headinfo.loc_pushIndex=0;
|
|
|
+ Flash_WriteBytes((uint16_t*)&(dblocptr->headinfo),LocDbHeadStart,4);//更新刻度
|
|
|
+ Retrans = false;
|
|
|
+ }
|
|
|
+ MiddleObj = true;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void TestPrintStruct(DatabaseLoc *ptr,uint8_t temppush)
|
|
|
+{
|
|
|
+ if(temppush)
|
|
|
{
|
|
|
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);
|
|
|
+ ptr->temppush.alarmFlag, \
|
|
|
+ ptr->temppush.statusFlag, \
|
|
|
+ ptr->temppush.latitude, \
|
|
|
+ ptr->temppush.longitude, \
|
|
|
+ ptr->temppush.height, \
|
|
|
+ ptr->temppush.speed, \
|
|
|
+ ptr->temppush.direction, \
|
|
|
+ ptr->temppush.timeBCD[0], \
|
|
|
+ ptr->temppush.timeBCD[1], \
|
|
|
+ ptr->temppush.timeBCD[2], \
|
|
|
+ ptr->temppush.timeBCD[3], \
|
|
|
+ ptr->temppush.timeBCD[4], \
|
|
|
+ ptr->temppush.timeBCD[5], \
|
|
|
+ ptr->temppush.signalCmd, \
|
|
|
+ ptr->temppush.signalCmd_len, \
|
|
|
+ ptr->temppush.CSQ, \
|
|
|
+ ptr->temppush.atellitesCmd, \
|
|
|
+ ptr->temppush.atellitesCmd_len, \
|
|
|
+ ptr->temppush.satellitesNum);
|
|
|
}
|
|
|
else
|
|
|
{
|