// read config from uSD int8_t configReadFile(char *fname) { char *fileBuf; int8_t fh; int ret; int p1; if (fname == 0) fname = CONFIG_FILE_NAME; if ((fh = filerGetHandle(fname)) < 0) { AQ_NOTICE("config: cannot get read file handle\n"); return -1; } fileBuf = (char *)aqCalloc(CONFIG_FILE_BUF_SIZE, sizeof(char)); p1 = 0; while ((ret = filerRead(fh, fileBuf, -1, CONFIG_FILE_BUF_SIZE)) > 0) p1 = configParseParams((char *)fileBuf, ret, p1); filerClose(fh); if (fileBuf) aqFree(fileBuf, CONFIG_FILE_BUF_SIZE, sizeof(char)); return ret; }
static void dIMUReadCalib(void) { #ifdef DIMU_HAVE_EEPROM uint8_t *buf; int size; int p1 = 0; buf = eepromOpenRead(); if (buf == 0) { AQ_NOTICE("DIMU: cannot read EEPROM parameters!\n"); } else { while ((size = eepromRead(DIMU_EEPROM_BLOCK_SIZE)) != 0) p1 = configParseParams((char *)buf, size, p1); AQ_NOTICE("DIMU: read calibration parameters from EEPROM\n"); } #endif }
// read config from uSD int8_t configReadFile(char *fname) { char *fileBuf; int8_t fh; int ret; int p1; if (fname == 0) fname = CONFIG_FILE_NAME; if ((fh = filerGetHandle(fname)) < 0) { AQ_NOTICE("config: cannot get read file handle\n"); return -1; } if (!(fileBuf = (char *)aqCalloc(CONFIG_FILE_BUF_SIZE, sizeof(char)))) { AQ_NOTICE("config: Error reading from file, cannot allocate memory.\n"); filerClose(fh); return -1; } p1 = 0; while ((ret = filerRead(fh, fileBuf, -1, CONFIG_FILE_BUF_SIZE)) > 0) { p1 = configParseParams((char *)fileBuf, ret, p1); if (p1 < 0) { ret = -1; break; } } filerClose(fh); if (fileBuf) aqFree(fileBuf, CONFIG_FILE_BUF_SIZE, sizeof(char)); if (ret > -1) AQ_NOTICE("config: Parameters loaded from local storage file.\n"); else AQ_NOTICE("config: Failed to read parameters from local file."); return ret; }