MCPcopy Create free account
hub / github.com/UtilitechAS/amsreader-firmware / load

Method load

lib/AmsDataStorage/src/AmsDataStorage.cpp:472–527  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

470}
471
472bool AmsDataStorage::load() {
473 if(!LittleFS.begin()) {
474 return false;
475 }
476
477 bool ret = false;
478 if(LittleFS.exists(FILE_DAYPLOT)) {
479 File file = LittleFS.open(FILE_DAYPLOT, "r");
480 char buf[file.size()];
481 file.readBytes(buf, file.size());
482 if(buf[0] > 5) {
483 DayDataPoints* day = (DayDataPoints*) buf;
484 ret = setDayData(*day);
485 } else {
486 DayDataPoints5* old = (DayDataPoints5*) buf;
487 DayDataPoints day = { old->version };
488 day.lastMeterReadTime = old->lastMeterReadTime;
489 day.activeImport = old->activeImport;
490 day.activeExport = old->activeExport;
491 day.accuracy = old->accuracy;
492 for(uint8_t i = 0; i < 24; i++) {
493 day.hImport[i] = old->hImport[i];
494 day.hExport[i] = old->hExport[i];
495 }
496
497 ret = setDayData(day);
498 }
499 file.close();
500 }
501
502 if(LittleFS.exists(FILE_MONTHPLOT)) {
503 File file = LittleFS.open(FILE_MONTHPLOT, "r");
504 char buf[file.size()];
505 file.readBytes(buf, file.size());
506 if(buf[0] > 6) {
507 MonthDataPoints* month = (MonthDataPoints*) buf;
508 ret &= setMonthData(*month);
509 } else {
510 MonthDataPoints6* old = (MonthDataPoints6*) buf;
511 MonthDataPoints month = { old->version };
512 month.lastMeterReadTime = old->lastMeterReadTime;
513 month.activeImport = old->activeImport;
514 month.activeExport = old->activeExport;
515 month.accuracy = old->accuracy;
516 for(uint8_t i = 0; i < 31; i++) {
517 month.dImport[i] = old->dImport[i];
518 month.dExport[i] = old->dExport[i];
519 }
520
521 ret &= setMonthData(month);
522 }
523 file.close();
524 }
525
526 return ret;
527}
528
529bool AmsDataStorage::save() {

Callers

nothing calls this directly

Calls 1

beginMethod · 0.80

Tested by

no test coverage detected