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,6 +3,7 @@ | ||
3 | #include <QDebug> | 3 | #include <QDebug> |
4 | #include <fcntl.h> | 4 | #include <fcntl.h> |
5 | #include <unistd.h> // write(), close() | 5 | #include <unistd.h> // write(), close() |
6 | +#include <dirtylevel.h> | ||
6 | 7 | ||
7 | #define FRAM_SIZE 2048 | 8 | #define FRAM_SIZE 2048 |
8 | #define FRAM_TEST_PROCESS 0 | 9 | #define FRAM_TEST_PROCESS 0 |
@@ -18,6 +19,8 @@ ServiceData::ServiceData() | @@ -18,6 +19,8 @@ ServiceData::ServiceData() | ||
18 | memset((void*)err_log.data,0x00,sizeof(error_log)); | 19 | memset((void*)err_log.data,0x00,sizeof(error_log)); |
19 | memset((void*)use_log.data,0x00,sizeof(use_statics_log)); | 20 | memset((void*)use_log.data,0x00,sizeof(use_statics_log)); |
20 | memset((void*)sensor_log.data,0x00, sizeof(sensor_statics_log)); | 21 | memset((void*)sensor_log.data,0x00, sizeof(sensor_statics_log)); |
22 | + DirtyLevel::setCookingCount(0); | ||
23 | + DirtyLevel::setCookingTime(0); | ||
21 | #if INIT_FRAM == 1 | 24 | #if INIT_FRAM == 1 |
22 | saveServiceData(); | 25 | saveServiceData(); |
23 | #else | 26 | #else |
@@ -29,7 +32,12 @@ ServiceData::ServiceData() | @@ -29,7 +32,12 @@ ServiceData::ServiceData() | ||
29 | 32 | ||
30 | bool ServiceData::loadServiceData(void){ | 33 | bool ServiceData::loadServiceData(void){ |
31 | uint8_t buffs[FRAM_SIZE]; | 34 | uint8_t buffs[FRAM_SIZE]; |
35 | + uint8_t* pBuff; | ||
32 | int fd; | 36 | int fd; |
37 | + qint64 temp_cookingTime = 0; | ||
38 | + int temp_cookingCount = 0; | ||
39 | + pBuff = buffs; | ||
40 | + | ||
33 | 41 | ||
34 | #if FRAM_TEST_PROCESS == 1 | 42 | #if FRAM_TEST_PROCESS == 1 |
35 | int i; | 43 | int i; |
@@ -75,15 +83,20 @@ bool ServiceData::loadServiceData(void){ | @@ -75,15 +83,20 @@ bool ServiceData::loadServiceData(void){ | ||
75 | if(fd>0){ | 83 | if(fd>0){ |
76 | memset(buffs,0x00,FRAM_SIZE); | 84 | memset(buffs,0x00,FRAM_SIZE); |
77 | read(fd,buffs,FRAM_SIZE); | 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 | close(fd); | 88 | close(fd); |
80 | return saveServiceData(); | 89 | return saveServiceData(); |
81 | } | 90 | } |
82 | 91 | ||
83 | qDebug() << "FRAM Read, Write Size is " << sizeof(error_log)+sizeof(use_statics_log); | 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 | close(fd); | 100 | close(fd); |
88 | }else{ | 101 | }else{ |
89 | qDebug()<<"FRAM FILE Open fail!!"; | 102 | qDebug()<<"FRAM FILE Open fail!!"; |
@@ -93,14 +106,21 @@ bool ServiceData::loadServiceData(void){ | @@ -93,14 +106,21 @@ bool ServiceData::loadServiceData(void){ | ||
93 | 106 | ||
94 | bool ServiceData::saveServiceData(void){ | 107 | bool ServiceData::saveServiceData(void){ |
95 | uint8_t buffs[FRAM_SIZE]; | 108 | uint8_t buffs[FRAM_SIZE]; |
109 | + uint8_t* pBuff; | ||
96 | int fd; | 110 | int fd; |
111 | + qint64 temp_cookingTime = DirtyLevel::cookingTime(); | ||
112 | + int temp_cookingCount = DirtyLevel::cookingCount(); | ||
113 | + pBuff = buffs; | ||
97 | fd = open(fRam_path, O_RDWR | O_SYNC); | 114 | fd = open(fRam_path, O_RDWR | O_SYNC); |
98 | if(fd>0){ | 115 | if(fd>0){ |
99 | memset(buffs,0x00,FRAM_SIZE); | 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 | write(fd,buffs,FRAM_SIZE); | 124 | write(fd,buffs,FRAM_SIZE); |
105 | close(fd); | 125 | close(fd); |
106 | }else{ | 126 | }else{ |