Commit 211a15bde3cb9f54a3d71dd39d6efcbe740734b2
1 parent
7ae804762e
Exists in
master
and in
2 other branches
dirtylevel 관련 FRAM 저장 변경
Showing
1 changed file
with
28 additions
and
8 deletions
Show diff stats
app/gui/oven_control/servicedata.cpp
| ... | ... | @@ -3,6 +3,7 @@ |
| 3 | 3 | #include <QDebug> |
| 4 | 4 | #include <fcntl.h> |
| 5 | 5 | #include <unistd.h> // write(), close() |
| 6 | +#include <dirtylevel.h> | |
| 6 | 7 | |
| 7 | 8 | #define FRAM_SIZE 2048 |
| 8 | 9 | #define FRAM_TEST_PROCESS 0 |
| ... | ... | @@ -18,6 +19,8 @@ ServiceData::ServiceData() |
| 18 | 19 | memset((void*)err_log.data,0x00,sizeof(error_log)); |
| 19 | 20 | memset((void*)use_log.data,0x00,sizeof(use_statics_log)); |
| 20 | 21 | memset((void*)sensor_log.data,0x00, sizeof(sensor_statics_log)); |
| 22 | + DirtyLevel::setCookingCount(0); | |
| 23 | + DirtyLevel::setCookingTime(0); | |
| 21 | 24 | #if INIT_FRAM == 1 |
| 22 | 25 | saveServiceData(); |
| 23 | 26 | #else |
| ... | ... | @@ -29,7 +32,12 @@ ServiceData::ServiceData() |
| 29 | 32 | |
| 30 | 33 | bool ServiceData::loadServiceData(void){ |
| 31 | 34 | uint8_t buffs[FRAM_SIZE]; |
| 35 | + uint8_t* pBuff; | |
| 32 | 36 | int fd; |
| 37 | + qint64 temp_cookingTime = 0; | |
| 38 | + int temp_cookingCount = 0; | |
| 39 | + pBuff = buffs; | |
| 40 | + | |
| 33 | 41 | |
| 34 | 42 | #if FRAM_TEST_PROCESS == 1 |
| 35 | 43 | int i; |
| ... | ... | @@ -75,15 +83,20 @@ bool ServiceData::loadServiceData(void){ |
| 75 | 83 | if(fd>0){ |
| 76 | 84 | memset(buffs,0x00,FRAM_SIZE); |
| 77 | 85 | read(fd,buffs,FRAM_SIZE); |
| 78 | - if(buffs[sizeof(error_log) + sizeof(use_statics_log) + sizeof(sensor_statics_log)] != 0x9C){ | |
| 86 | + if(buffs[sizeof(error_log) + sizeof(use_statics_log) + sizeof(sensor_statics_log) + sizeof(qint64) + sizeof(int)] != 0x9C){ | |
| 87 | + qDebug() << "service data read incorrected!"; | |
| 79 | 88 | close(fd); |
| 80 | 89 | return saveServiceData(); |
| 81 | 90 | } |
| 82 | 91 | |
| 83 | 92 | qDebug() << "FRAM Read, Write Size is " << sizeof(error_log)+sizeof(use_statics_log); |
| 84 | - memcpy((void*)err_log.data,buffs,sizeof(error_log)); | |
| 85 | - memcpy((void*)use_log.data, (void*)(&buffs[sizeof(error_log)]),sizeof(use_statics_log)); | |
| 86 | - memcpy((void*)sensor_log.data,(void*)(&buffs[sizeof(error_log) + sizeof(use_statics_log)]),sizeof(sensor_statics_log)); | |
| 93 | + memcpy((void*)err_log.data,pBuff,sizeof(error_log)); pBuff += sizeof(error_log); | |
| 94 | + memcpy((void*)use_log.data, pBuff,sizeof(use_statics_log));pBuff += sizeof(use_statics_log); | |
| 95 | + memcpy((void*)sensor_log.data,pBuff,sizeof(sensor_statics_log)); pBuff+= sizeof(sensor_statics_log); | |
| 96 | + memcpy(&temp_cookingTime,pBuff, sizeof(qint64)); pBuff += sizeof(qint64); | |
| 97 | + memcpy(&temp_cookingCount,pBuff, sizeof(int)); | |
| 98 | + DirtyLevel::setCookingCount(temp_cookingCount); | |
| 99 | + DirtyLevel::setCookingTime(temp_cookingTime); | |
| 87 | 100 | close(fd); |
| 88 | 101 | }else{ |
| 89 | 102 | qDebug()<<"FRAM FILE Open fail!!"; |
| ... | ... | @@ -93,14 +106,21 @@ bool ServiceData::loadServiceData(void){ |
| 93 | 106 | |
| 94 | 107 | bool ServiceData::saveServiceData(void){ |
| 95 | 108 | uint8_t buffs[FRAM_SIZE]; |
| 109 | + uint8_t* pBuff; | |
| 96 | 110 | int fd; |
| 111 | + qint64 temp_cookingTime = DirtyLevel::cookingTime(); | |
| 112 | + int temp_cookingCount = DirtyLevel::cookingCount(); | |
| 113 | + pBuff = buffs; | |
| 97 | 114 | fd = open(fRam_path, O_RDWR | O_SYNC); |
| 98 | 115 | if(fd>0){ |
| 99 | 116 | memset(buffs,0x00,FRAM_SIZE); |
| 100 | - memcpy(buffs,(void*)err_log.data,sizeof(error_log)); | |
| 101 | - memcpy((void*)(&buffs[sizeof(error_log)]),(void*)use_log.data,sizeof(use_statics_log)); | |
| 102 | - memcpy((void*)(&buffs[sizeof(error_log) + sizeof(use_statics_log)]),(void*)sensor_log.data,sizeof(sensor_statics_log)); | |
| 103 | - buffs[sizeof(error_log) + sizeof(use_statics_log) + sizeof(sensor_statics_log)] = 0x9C; | |
| 117 | + memcpy(pBuff,(void*)err_log.data,sizeof(error_log)); pBuff += sizeof(err_log); | |
| 118 | + memcpy(pBuff,(void*)use_log.data,sizeof(use_statics_log)); pBuff += sizeof(use_statics_log); | |
| 119 | + memcpy(pBuff,(void*)sensor_log.data,sizeof(sensor_statics_log)); pBuff += sizeof(sensor_statics_log); | |
| 120 | + memcpy(pBuff, &temp_cookingTime, sizeof(qint64)); pBuff += sizeof(qint64); | |
| 121 | + memcpy(pBuff, &temp_cookingCount, sizeof(int)); pBuff += sizeof(int); | |
| 122 | + *pBuff = 0x9C; | |
| 123 | + | |
| 104 | 124 | write(fd,buffs,FRAM_SIZE); |
| 105 | 125 | close(fd); |
| 106 | 126 | }else{ | ... | ... |