diff --git a/app/gui/oven_control/servicedata.cpp b/app/gui/oven_control/servicedata.cpp index 96a83c9..d9eb245 100644 --- a/app/gui/oven_control/servicedata.cpp +++ b/app/gui/oven_control/servicedata.cpp @@ -3,6 +3,7 @@ #include #include #include // write(), close() +#include #define FRAM_SIZE 2048 #define FRAM_TEST_PROCESS 0 @@ -18,6 +19,8 @@ ServiceData::ServiceData() memset((void*)err_log.data,0x00,sizeof(error_log)); memset((void*)use_log.data,0x00,sizeof(use_statics_log)); memset((void*)sensor_log.data,0x00, sizeof(sensor_statics_log)); + DirtyLevel::setCookingCount(0); + DirtyLevel::setCookingTime(0); #if INIT_FRAM == 1 saveServiceData(); #else @@ -29,7 +32,12 @@ ServiceData::ServiceData() bool ServiceData::loadServiceData(void){ uint8_t buffs[FRAM_SIZE]; + uint8_t* pBuff; int fd; + qint64 temp_cookingTime = 0; + int temp_cookingCount = 0; + pBuff = buffs; + #if FRAM_TEST_PROCESS == 1 int i; @@ -75,15 +83,20 @@ bool ServiceData::loadServiceData(void){ if(fd>0){ memset(buffs,0x00,FRAM_SIZE); read(fd,buffs,FRAM_SIZE); - if(buffs[sizeof(error_log) + sizeof(use_statics_log) + sizeof(sensor_statics_log)] != 0x9C){ + if(buffs[sizeof(error_log) + sizeof(use_statics_log) + sizeof(sensor_statics_log) + sizeof(qint64) + sizeof(int)] != 0x9C){ + qDebug() << "service data read incorrected!"; close(fd); return saveServiceData(); } qDebug() << "FRAM Read, Write Size is " << sizeof(error_log)+sizeof(use_statics_log); - memcpy((void*)err_log.data,buffs,sizeof(error_log)); - memcpy((void*)use_log.data, (void*)(&buffs[sizeof(error_log)]),sizeof(use_statics_log)); - memcpy((void*)sensor_log.data,(void*)(&buffs[sizeof(error_log) + sizeof(use_statics_log)]),sizeof(sensor_statics_log)); + memcpy((void*)err_log.data,pBuff,sizeof(error_log)); pBuff += sizeof(error_log); + memcpy((void*)use_log.data, pBuff,sizeof(use_statics_log));pBuff += sizeof(use_statics_log); + memcpy((void*)sensor_log.data,pBuff,sizeof(sensor_statics_log)); pBuff+= sizeof(sensor_statics_log); + memcpy(&temp_cookingTime,pBuff, sizeof(qint64)); pBuff += sizeof(qint64); + memcpy(&temp_cookingCount,pBuff, sizeof(int)); + DirtyLevel::setCookingCount(temp_cookingCount); + DirtyLevel::setCookingTime(temp_cookingTime); close(fd); }else{ qDebug()<<"FRAM FILE Open fail!!"; @@ -93,14 +106,21 @@ bool ServiceData::loadServiceData(void){ bool ServiceData::saveServiceData(void){ uint8_t buffs[FRAM_SIZE]; + uint8_t* pBuff; int fd; + qint64 temp_cookingTime = DirtyLevel::cookingTime(); + int temp_cookingCount = DirtyLevel::cookingCount(); + pBuff = buffs; fd = open(fRam_path, O_RDWR | O_SYNC); if(fd>0){ memset(buffs,0x00,FRAM_SIZE); - memcpy(buffs,(void*)err_log.data,sizeof(error_log)); - memcpy((void*)(&buffs[sizeof(error_log)]),(void*)use_log.data,sizeof(use_statics_log)); - memcpy((void*)(&buffs[sizeof(error_log) + sizeof(use_statics_log)]),(void*)sensor_log.data,sizeof(sensor_statics_log)); - buffs[sizeof(error_log) + sizeof(use_statics_log) + sizeof(sensor_statics_log)] = 0x9C; + memcpy(pBuff,(void*)err_log.data,sizeof(error_log)); pBuff += sizeof(err_log); + memcpy(pBuff,(void*)use_log.data,sizeof(use_statics_log)); pBuff += sizeof(use_statics_log); + memcpy(pBuff,(void*)sensor_log.data,sizeof(sensor_statics_log)); pBuff += sizeof(sensor_statics_log); + memcpy(pBuff, &temp_cookingTime, sizeof(qint64)); pBuff += sizeof(qint64); + memcpy(pBuff, &temp_cookingCount, sizeof(int)); pBuff += sizeof(int); + *pBuff = 0x9C; + write(fd,buffs,FRAM_SIZE); close(fd); }else{