zongqiang.zhang | 0c6a088 | 2019-08-07 14:48:21 +0800 | [diff] [blame] | 1 | #include "sp_data.h" |
| 2 | #include "sp_util.h" |
| 3 | #include "sp_flash.h" |
| 4 | #include "sp_constant.h" |
| 5 | #include "sp_display.h" |
| 6 | |
guangcheng.qin | 0066884 | 2019-08-19 09:45:25 +0800 | [diff] [blame] | 7 | #define record_behalf_len 19 |
| 8 | #define record_below_len 13 |
zongqiang.zhang | 0c6a088 | 2019-08-07 14:48:21 +0800 | [diff] [blame] | 9 | |
| 10 | //Ñ»·¼Ç¼ÿһ±ÊÁ÷Ë®¼Ç¼µÄµØÖ· |
| 11 | static uint16 sp_write_last_record(sp_pos_t* pos) |
| 12 | { |
| 13 | uint8 crc[2]; |
| 14 | uint8 buff[sizeof(sp_last_transdtl_t)]; |
zongqiang.zhang | 0c6a088 | 2019-08-07 14:48:21 +0800 | [diff] [blame] | 15 | |
| 16 | pos->last_transdtl.this_offset += sizeof(sp_last_transdtl_t); |
| 17 | if(pos->last_transdtl.this_offset >= DEF_FLASH_PageSize) |
| 18 | { |
| 19 | sp_flash_erase(ADDR_LAST_TRANSNO); |
| 20 | pos->last_transdtl.this_offset = 0; |
| 21 | } |
zongqiang.zhang | a1f6a4e | 2019-12-09 10:27:28 +0800 | [diff] [blame] | 22 | sp_protocol_crc((uint8*)&pos->last_transdtl, sizeof(sp_last_transdtl_t)-2, pos->last_transdtl.crc); |
zongqiang.zhang | 0c6a088 | 2019-08-07 14:48:21 +0800 | [diff] [blame] | 23 | sp_flash_write(pos->last_transdtl.this_offset+ADDR_LAST_TRANSNO, |
zongqiang.zhang | a1f6a4e | 2019-12-09 10:27:28 +0800 | [diff] [blame] | 24 | (uint8*)&pos->last_transdtl, sizeof(sp_last_transdtl_t)); |
zongqiang.zhang | 0c6a088 | 2019-08-07 14:48:21 +0800 | [diff] [blame] | 25 | |
| 26 | sp_flash_read(pos->last_transdtl.this_offset+ADDR_LAST_TRANSNO, buff, sizeof(buff)); |
| 27 | sp_protocol_crc(buff, sizeof(buff)-2, crc); |
| 28 | if(MEMCMP(pos->last_transdtl.crc,crc,2)!=0) |
| 29 | { |
| 30 | pos->load_para_status = RC_FLASH_ERR; |
| 31 | return RC_FLASH_ERR; |
| 32 | } |
| 33 | return 0; |
| 34 | } |
| 35 | |
| 36 | static uint16 sp_write_behalf_record(sp_pos_t* pos, sp_transdtl_t* record) |
| 37 | { |
zongqiang.zhang | 0c6a088 | 2019-08-07 14:48:21 +0800 | [diff] [blame] | 38 | pos->last_transdtl.transaddr += sizeof(sp_transdtl_t); |
| 39 | if(pos->last_transdtl.transaddr % DEF_FLASH_PageSize == 0) |
| 40 | { |
| 41 | if(pos->last_transdtl.transaddr >= ADDR_TRANSDTL_END) |
| 42 | { |
| 43 | pos->last_transdtl.transaddr = ADDR_TRANSDTL_BEGIN; |
| 44 | } |
| 45 | sp_flash_erase(pos->last_transdtl.transaddr); |
| 46 | } |
zongqiang.zhang | a1f6a4e | 2019-12-09 10:27:28 +0800 | [diff] [blame] | 47 | sp_flash_write(pos->last_transdtl.transaddr, (uint8*)record, record_behalf_len); |
zongqiang.zhang | 0c6a088 | 2019-08-07 14:48:21 +0800 | [diff] [blame] | 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | static uint16 sp_write_below_record(sp_pos_t* pos, sp_transdtl_t* record) |
| 52 | { |
| 53 | uint8 crc[2]; |
| 54 | uint8 buff[sizeof(sp_transdtl_t)]; |
zongqiang.zhang | 0c6a088 | 2019-08-07 14:48:21 +0800 | [diff] [blame] | 55 | |
zongqiang.zhang | a1f6a4e | 2019-12-09 10:27:28 +0800 | [diff] [blame] | 56 | sp_protocol_crc((uint8*)record, sizeof(sp_transdtl_t)-2, record->crc); |
zongqiang.zhang | 0c6a088 | 2019-08-07 14:48:21 +0800 | [diff] [blame] | 57 | sp_flash_write(pos->last_transdtl.transaddr+record_behalf_len, |
| 58 | (uint8*)record+record_behalf_len, record_below_len); |
| 59 | sp_flash_read(pos->last_transdtl.transaddr, buff, sizeof(buff)); |
| 60 | sp_protocol_crc(buff, sizeof(buff)-2, crc); |
| 61 | if(MEMCMP(record->crc, crc, 2) != 0) |
| 62 | { |
| 63 | pos->load_para_status = RC_FLASH_ERR; |
| 64 | return RC_FLASH_ERR; |
| 65 | } |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | //Ïû·Ñ³õʼ»¯ºó´æ´¢Éϰ벿·ÖÁ÷Ë®£¬·ÀÖ¹Ïû·Ñʧ°ÜÎÞÁ÷Ë®ÐÅÏ¢ |
zongqiang.zhang | a1f6a4e | 2019-12-09 10:27:28 +0800 | [diff] [blame] | 70 | uint16 sp_prepare_behalf_transdtl(sp_pos_t* pos, sp_card_t* card) |
zongqiang.zhang | 0c6a088 | 2019-08-07 14:48:21 +0800 | [diff] [blame] | 71 | { |
zongqiang.zhang | 0c6a088 | 2019-08-07 14:48:21 +0800 | [diff] [blame] | 72 | uint8 ctime[6]; |
zongqiang.zhang | a1f6a4e | 2019-12-09 10:27:28 +0800 | [diff] [blame] | 73 | sp_transdtl_t record; |
| 74 | MEMCLEAR(&record, sizeof(record)); |
zongqiang.zhang | 0c6a088 | 2019-08-07 14:48:21 +0800 | [diff] [blame] | 75 | |
| 76 | sp_get_bcdtime(ctime); |
zongqiang.zhang | a1f6a4e | 2019-12-09 10:27:28 +0800 | [diff] [blame] | 77 | memcpy(record.devphyid, pos->devphyid, sizeof(pos->devphyid)); |
| 78 | memcpy(record.transdate, ctime, 3); |
| 79 | memcpy(record.transtime, ctime+3, 3); |
| 80 | record.cobillno = card->cobillno; |
| 81 | memcpy(record.cardphyid, card->cardphyid, sizeof(card->cardphyid)); |
zongqiang.zhang | 0c6a088 | 2019-08-07 14:48:21 +0800 | [diff] [blame] | 82 | if(pos->paymode == PAYMODE_QRCODE) |
| 83 | { |
zongqiang.zhang | a1f6a4e | 2019-12-09 10:27:28 +0800 | [diff] [blame] | 84 | record.transway = 2; |
zongqiang.zhang | 0c6a088 | 2019-08-07 14:48:21 +0800 | [diff] [blame] | 85 | } |
| 86 | else |
| 87 | { |
zongqiang.zhang | a1f6a4e | 2019-12-09 10:27:28 +0800 | [diff] [blame] | 88 | record.transway = 1; |
zongqiang.zhang | 0c6a088 | 2019-08-07 14:48:21 +0800 | [diff] [blame] | 89 | } |
zongqiang.zhang | a1f6a4e | 2019-12-09 10:27:28 +0800 | [diff] [blame] | 90 | sp_write_behalf_record(pos, &record); |
zongqiang.zhang | 0c6a088 | 2019-08-07 14:48:21 +0800 | [diff] [blame] | 91 | return sp_write_last_record(pos); |
| 92 | } |
| 93 | |
| 94 | //ÈôÏû·Ñ³É¹¦£¬´æ´¢Ï°벿·ÖÁ÷Ë®ÐÅÏ¢ |
zongqiang.zhang | a1f6a4e | 2019-12-09 10:27:28 +0800 | [diff] [blame] | 95 | uint16 sp_prepare_below_transdtl(sp_pos_t* pos, sp_card_t* card) |
zongqiang.zhang | 0c6a088 | 2019-08-07 14:48:21 +0800 | [diff] [blame] | 96 | { |
zongqiang.zhang | a1f6a4e | 2019-12-09 10:27:28 +0800 | [diff] [blame] | 97 | sp_transdtl_t record; |
| 98 | MEMCLEAR(&record, sizeof(record)); |
zongqiang.zhang | 0c6a088 | 2019-08-07 14:48:21 +0800 | [diff] [blame] | 99 | |
zongqiang.zhang | 5e9ad58 | 2019-12-10 09:11:13 +0800 | [diff] [blame] | 100 | sp_flash_read(pos->last_transdtl.transaddr, (uint8*)&record, record_behalf_len); |
zongqiang.zhang | a1f6a4e | 2019-12-09 10:27:28 +0800 | [diff] [blame] | 101 | record.amount = pos->purchase.paid_sum; |
zongqiang.zhang | 0c6a088 | 2019-08-07 14:48:21 +0800 | [diff] [blame] | 102 | if(pos->paymode == PAYMODE_QRCODE) |
| 103 | { |
zongqiang.zhang | a1f6a4e | 2019-12-09 10:27:28 +0800 | [diff] [blame] | 104 | record.paidAmount = card->qrcode.paidAmount; |
zongqiang.zhang | 0c6a088 | 2019-08-07 14:48:21 +0800 | [diff] [blame] | 105 | } |
| 106 | else |
| 107 | { |
zongqiang.zhang | a1f6a4e | 2019-12-09 10:27:28 +0800 | [diff] [blame] | 108 | record.paidAmount = 0; |
zongqiang.zhang | 0c6a088 | 2019-08-07 14:48:21 +0800 | [diff] [blame] | 109 | } |
zongqiang.zhang | a1f6a4e | 2019-12-09 10:27:28 +0800 | [diff] [blame] | 110 | record.flowsensors = pos->purchase.paid_num; |
| 111 | record.transtatus = 1; |
zongqiang.zhang | a1f6a4e | 2019-12-09 10:27:28 +0800 | [diff] [blame] | 112 | return sp_write_below_record(pos, &record); |
zongqiang.zhang | 0c6a088 | 2019-08-07 14:48:21 +0800 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | //Ñ»·´æ´¢Ã¿Ò»±ÊδÉÏ´«Á÷Ë®¼Ç¼µÄµØÖ· |
| 116 | uint16 sp_write_unconfirm_record(sp_pos_t* pos) |
| 117 | { |
| 118 | uint8 crc[2]; |
| 119 | uint8 buff[sizeof(sp_unconfirm_transdtl_t)]; |
zongqiang.zhang | 0c6a088 | 2019-08-07 14:48:21 +0800 | [diff] [blame] | 120 | |
zongqiang.zhang | a1f6a4e | 2019-12-09 10:27:28 +0800 | [diff] [blame] | 121 | pos->unconfirm_transdtl.this_offset += sizeof(sp_unconfirm_transdtl_t); |
zongqiang.zhang | 0c6a088 | 2019-08-07 14:48:21 +0800 | [diff] [blame] | 122 | if(pos->unconfirm_transdtl.this_offset >= DEF_FLASH_PageSize) |
| 123 | { |
| 124 | sp_flash_erase(ADDR_UNCONFIRM_TRANSNO); |
| 125 | pos->unconfirm_transdtl.this_offset = 0; |
| 126 | } |
zongqiang.zhang | a1f6a4e | 2019-12-09 10:27:28 +0800 | [diff] [blame] | 127 | sp_protocol_crc((uint8*)&pos->unconfirm_transdtl, sizeof(sp_unconfirm_transdtl_t)-2, |
zongqiang.zhang | 0c6a088 | 2019-08-07 14:48:21 +0800 | [diff] [blame] | 128 | pos->unconfirm_transdtl.crc); |
| 129 | sp_flash_write(pos->unconfirm_transdtl.this_offset+ADDR_UNCONFIRM_TRANSNO, |
zongqiang.zhang | a1f6a4e | 2019-12-09 10:27:28 +0800 | [diff] [blame] | 130 | (uint8*)&pos->unconfirm_transdtl, sizeof(sp_unconfirm_transdtl_t)); |
zongqiang.zhang | 0c6a088 | 2019-08-07 14:48:21 +0800 | [diff] [blame] | 131 | |
| 132 | sp_flash_read(pos->unconfirm_transdtl.this_offset+ADDR_UNCONFIRM_TRANSNO, buff, |
| 133 | sizeof(buff)); |
| 134 | sp_protocol_crc(buff, sizeof(buff)-2, crc); |
| 135 | if(MEMCMP(pos->unconfirm_transdtl.crc, crc, 2) !=0) |
| 136 | { |
| 137 | pos->load_para_status = RC_FLASH_ERR; |
| 138 | return RC_FLASH_ERR; |
| 139 | } |
| 140 | return 0; |
| 141 | } |
| 142 | |
| 143 | static uint16 sp_init_last_transdtl_ptr(sp_last_transdtl_t* record) |
| 144 | { |
| 145 | record->transaddr = ADDR_TRANSDTL_BEGIN -sizeof(sp_transdtl_t); |
| 146 | record->this_offset = 0; |
| 147 | sp_protocol_crc((uint8*)record,sizeof(sp_last_transdtl_t) -2,record->crc); |
| 148 | return sp_flash_page_write(ADDR_LAST_TRANSNO,(uint8*)record,sizeof(sp_last_transdtl_t)); |
| 149 | } |
| 150 | |
| 151 | static uint16 sp_init_unconfirm_transdtl_ptr(sp_unconfirm_transdtl_t* record) |
| 152 | { |
| 153 | record->transaddr = ADDR_TRANSDTL_BEGIN; |
| 154 | record->this_offset = 0; |
| 155 | sp_protocol_crc((uint8*)record,sizeof(sp_unconfirm_transdtl_t) -2,record->crc); |
| 156 | return sp_flash_page_write(ADDR_UNCONFIRM_TRANSNO,(uint8*)record, |
| 157 | sizeof(sp_unconfirm_transdtl_t)); |
| 158 | } |
| 159 | |
| 160 | static uint8 sp_load_last_transdtl_ptr(sp_pos_t* pos) |
| 161 | { |
| 162 | uint8 crc[2]; |
| 163 | sp_flash_page_read(ADDR_LAST_TRANSNO,(uint8*)&pos->last_transdtl, |
| 164 | sizeof(sp_last_transdtl_t)); |
| 165 | sp_protocol_crc((uint8*)&pos->last_transdtl,sizeof(sp_last_transdtl_t) -2,crc); |
| 166 | if(MEMCMP(pos->last_transdtl.crc,crc,2) != 0) |
| 167 | { |
| 168 | sp_init_last_transdtl_ptr(&pos->last_transdtl); |
| 169 | } |
| 170 | return 0; |
| 171 | } |
| 172 | static uint8 sp_load_unconfirm_transdtl_ptr(sp_pos_t* pos) |
| 173 | { |
| 174 | uint8 crc[2]; |
| 175 | sp_flash_page_read(ADDR_UNCONFIRM_TRANSNO,(uint8*)&pos->unconfirm_transdtl, |
| 176 | sizeof(sp_unconfirm_transdtl_t)); |
| 177 | sp_protocol_crc((uint8*)&pos->unconfirm_transdtl,sizeof(sp_unconfirm_transdtl_t) -2,crc); |
| 178 | if(MEMCMP(pos->unconfirm_transdtl.crc,crc,2) != 0) |
| 179 | { |
| 180 | sp_init_unconfirm_transdtl_ptr(&pos->unconfirm_transdtl); |
| 181 | } |
| 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | static uint16 sp_parse_config(sp_pos_t* pos, sp_config_t* config) |
| 186 | { |
| 187 | pos->sysconf.dev_offline_maxhour = config->offline_work_hour; |
| 188 | if(pos->sysconf.dev_offline_maxhour == 0) |
| 189 | { |
| 190 | pos->sysconf.dev_offline_maxhour = DEV_OFFLINE_DEFAULT_HOUR; |
| 191 | } |
| 192 | pos->sysconf.flowsensor_unit = config->flowsensor_unit; |
| 193 | pos->deviceno = config->deviceno; |
| 194 | pos->devlogin.login_flag = config->login_flag; |
| 195 | MEMCPY(pos->devphyid,config->devphyid,4); |
| 196 | return 0; |
| 197 | } |
| 198 | static uint16 sp_read_config(sp_pos_t* pos, sp_config_t* config) |
| 199 | { |
| 200 | uint8 crc[2]; |
| 201 | sp_flash_read(ADDR_CONFIG_PARA,(uint8*)config,sizeof(sp_config_t)); |
| 202 | sp_protocol_crc((uint8*)config,sizeof(sp_config_t) -2,crc); |
| 203 | if(memcmp(config->crc,crc,2) != 0) |
| 204 | { |
| 205 | return RC_CONFPARA_CRC_ERR; |
| 206 | } |
| 207 | sp_parse_config(pos, config); |
| 208 | return 0; |
| 209 | } |
| 210 | |
| 211 | uint16 sp_clear_transdtl(sp_pos_t* pos) |
| 212 | { |
| 213 | uint32 i; |
zongqiang.zhang | a1f6a4e | 2019-12-09 10:27:28 +0800 | [diff] [blame] | 214 | uint16 ret; |
| 215 | ret = sp_flash_erase(ADDR_LAST_TRANSNO); |
zongqiang.zhang | 0c6a088 | 2019-08-07 14:48:21 +0800 | [diff] [blame] | 216 | ret |= sp_flash_erase(ADDR_UNCONFIRM_TRANSNO); |
| 217 | for(i = ADDR_TRANSDTL_BEGIN; i < ADDR_TRANSDTL_END; i += DEF_FLASH_PageSize) |
| 218 | { |
| 219 | ret |= sp_flash_erase(i); |
| 220 | } |
| 221 | return ret; |
| 222 | } |
| 223 | |
| 224 | static uint16 sp_init_device(sp_pos_t* pos) |
| 225 | { |
zongqiang.zhang | 0c6a088 | 2019-08-07 14:48:21 +0800 | [diff] [blame] | 226 | disp_hint_info_two(pos,"É豸³õʼ»¯","Çå¿ÕÁ÷Ë®",0); |
zongqiang.zhang | a1f6a4e | 2019-12-09 10:27:28 +0800 | [diff] [blame] | 227 | return sp_clear_transdtl(pos); |
zongqiang.zhang | 0c6a088 | 2019-08-07 14:48:21 +0800 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | void sp_reset_factory(sp_pos_t* pos) |
| 231 | { |
| 232 | uint16 ret; |
| 233 | disp_hint_info_two(pos,"»Ö¸´³ö³§ÖÐ","ÇëÉÔµÈ...",0); |
| 234 | ret = sp_flash_erase(ADDR_CONFIG_PARA); |
| 235 | ret |=sp_clear_transdtl(pos); |
| 236 | if(!ret) |
| 237 | { |
| 238 | disp_hint_info_two(pos,"³õʼ»¯³É¹¦","µÈ´ýÖØÆô",0); |
| 239 | } |
| 240 | else |
| 241 | { |
| 242 | disp_hint_info_two(pos,"³õʼ»¯Ê§°Ü","µÈ´ýÖØÆô",0); |
| 243 | } |
| 244 | sp_reset(); |
| 245 | } |
| 246 | |
| 247 | uint16 sp_load_config(sp_pos_t* pos) |
| 248 | { |
| 249 | uint16 ret; |
| 250 | sp_config_t config; |
| 251 | MEMCLEAR(&config,sizeof config); |
| 252 | ret |= sp_read_config(pos, &config); |
| 253 | if(ret) |
| 254 | { |
| 255 | sp_config_init(pos); |
| 256 | sp_init_device(pos); |
| 257 | } |
| 258 | ret |= sp_load_last_transdtl_ptr(pos); |
| 259 | ret |= sp_load_unconfirm_transdtl_ptr(pos); |
| 260 | return ret; |
| 261 | } |
| 262 | |
| 263 | uint16 sp_save_config(sp_pos_t* pos, sp_config_t* config) |
| 264 | { |
| 265 | uint8 buffer[sizeof(sp_config_t)]; |
| 266 | uint8 crc[2]; |
| 267 | sp_protocol_crc((uint8*)config,sizeof(sp_config_t)-2,config->crc); |
| 268 | sp_flash_erase(ADDR_CONFIG_PARA); |
| 269 | sp_flash_write(ADDR_CONFIG_PARA,(uint8*)config,sizeof(sp_config_t)); |
| 270 | sp_flash_read(ADDR_CONFIG_PARA,buffer,sizeof buffer); |
| 271 | sp_protocol_crc(buffer,sizeof(buffer)-2,crc); |
| 272 | if(memcmp(config->crc,crc,2) != 0) |
| 273 | { |
| 274 | return RC_CONFPARA_CRC_ERR; |
| 275 | } |
| 276 | sp_parse_config(pos, config); |
| 277 | return 0; |
| 278 | } |
| 279 | |
| 280 | uint16 sp_save_deviceno(sp_pos_t* pos, uint8 deviceno) |
| 281 | { |
| 282 | uint16 ret; |
| 283 | sp_config_t config; |
| 284 | MEMCLEAR(&config, sizeof config); |
| 285 | ret = sp_read_config(pos, &config); |
| 286 | if(ret) |
| 287 | { |
| 288 | return ret; |
| 289 | } |
| 290 | config.deviceno = deviceno; |
| 291 | return sp_save_config(pos, &config); |
| 292 | } |
| 293 | uint16 sp_save_devphyid(sp_pos_t* pos, uint8 devphyid[4]) |
| 294 | { |
| 295 | uint16 ret; |
| 296 | sp_config_t config; |
| 297 | MEMCLEAR(&config, sizeof config); |
| 298 | ret = sp_read_config(pos, &config); |
| 299 | if(ret) |
| 300 | { |
| 301 | return ret; |
| 302 | } |
| 303 | MEMCPY(config.devphyid,devphyid,4); |
| 304 | return sp_save_config(pos, &config); |
| 305 | } |
| 306 | uint16 sp_save_login_info(sp_pos_t* pos, uint8 flag, uint8 unit, uint8 offline_maxhour) |
| 307 | { |
| 308 | uint16 ret; |
| 309 | sp_config_t config; |
| 310 | MEMCLEAR(&config, sizeof config); |
| 311 | ret = sp_read_config(pos, &config); |
| 312 | if(ret) |
| 313 | { |
| 314 | return ret; |
| 315 | } |
| 316 | config.login_flag = flag; |
| 317 | config.flowsensor_unit = unit; |
| 318 | config.offline_work_hour = offline_maxhour; |
| 319 | return sp_save_config(pos, &config); |
| 320 | } |
| 321 | |
| 322 | uint16 sp_save_heartbeat_info(sp_pos_t* pos, uint8 flag) |
| 323 | { |
| 324 | uint16 ret; |
| 325 | sp_config_t config; |
| 326 | MEMCLEAR(&config, sizeof config); |
| 327 | ret = sp_read_config(pos, &config); |
| 328 | if(ret) |
| 329 | { |
| 330 | return ret; |
| 331 | } |
| 332 | config.login_flag = flag; |
| 333 | return sp_save_config(pos, &config); |
| 334 | |
| 335 | } |
| 336 | |
| 337 | uint16 sp_config_init(sp_pos_t* pos) |
| 338 | { |
zongqiang.zhang | 0c6a088 | 2019-08-07 14:48:21 +0800 | [diff] [blame] | 339 | uint8 crc[2]; |
| 340 | sp_config_t config; |
zongqiang.zhang | cb1f269 | 2019-11-26 17:17:14 +0800 | [diff] [blame] | 341 | disp_hint_info_two(pos,"É豸²ÎÊý³õʼ»¯", "ÇëÉÔµÈ...",0); |
zongqiang.zhang | 039d01e | 2019-12-03 17:27:54 +0800 | [diff] [blame] | 342 | MEMCLEAR(&config, sizeof(config)); |
| 343 | config.deviceno = 1; |
| 344 | MEMCPY(config.devphyid,"\x40\x12\x01\x00",4); |
zongqiang.zhang | 0c6a088 | 2019-08-07 14:48:21 +0800 | [diff] [blame] | 345 | sp_protocol_crc((uint8*)&config,sizeof(sp_config_t)-2,config.crc); |
| 346 | sp_flash_erase(ADDR_CONFIG_PARA); |
| 347 | sp_flash_write(ADDR_CONFIG_PARA,(uint8*)&config,sizeof(sp_config_t)); |
| 348 | sp_flash_read(ADDR_CONFIG_PARA,(uint8*)&config,sizeof(config)); |
| 349 | sp_protocol_crc((uint8*)&config,sizeof(sp_config_t)-2,crc); |
| 350 | if(memcmp(config.crc,crc,2) != 0) |
| 351 | { |
| 352 | return RC_CONFPARA_CRC_ERR; |
| 353 | } |
zongqiang.zhang | b8d5c27 | 2019-12-03 17:34:46 +0800 | [diff] [blame] | 354 | return sp_parse_config(pos,&config); |
zongqiang.zhang | 0c6a088 | 2019-08-07 14:48:21 +0800 | [diff] [blame] | 355 | } |