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