17 return; |
17 return; |
18 } |
18 } |
19 |
19 |
20 size_t bytes = fwrite(dst, 1, sizeof(config), f); |
20 size_t bytes = fwrite(dst, 1, sizeof(config), f); |
21 fclose(f); |
21 fclose(f); |
22 ESP_LOGI(TAG, "/spiffs/etc/config.conf written %d bytes", bytes); |
22 if (bytes != sizeof(config)) { |
|
23 ESP_LOGE(TAG, "/spiffs/etc/config.conf written %d/%d bytes", bytes, sizeof(config)); |
|
24 } else { |
|
25 ESP_LOGD(TAG, "/spiffs/etc/config.conf written %d bytes", bytes); |
|
26 } |
23 } |
27 } |
24 |
28 |
25 |
29 |
26 |
30 |
27 void read_config() { |
31 void read_config() { |
56 write_config(); |
60 write_config(); |
57 } else { |
61 } else { |
58 dst = (uint8_t*)&config; |
62 dst = (uint8_t*)&config; |
59 size_t bytes = fread(dst, 1, sizeof(config), f); |
63 size_t bytes = fread(dst, 1, sizeof(config), f); |
60 fclose(f); |
64 fclose(f); |
61 ESP_LOGI(TAG, "/spiffs/etc/config.conf read %d bytes", bytes); |
65 ESP_LOGD(TAG, "/spiffs/etc/config.conf read %d bytes", bytes); |
62 if (config.AskIodine && ! config.IodineTime) { |
66 if (config.AskIodine && ! config.IodineTime) { |
63 config.IodineTime = 30; |
67 config.IodineTime = 30; |
64 write_config(); |
68 write_config(); |
65 } |
69 } |
66 if (strlen(config.uuid) !=36) { |
70 if (strlen(config.uuid) !=36) { |
121 dst = (uint8_t*)&equipment; |
125 dst = (uint8_t*)&equipment; |
122 while (1) { |
126 while (1) { |
123 size_t bytes = fread(dst, 1, sizeof(equipment), f); |
127 size_t bytes = fread(dst, 1, sizeof(equipment), f); |
124 if (bytes && equipment.Record == RecNo) { |
128 if (bytes && equipment.Record == RecNo) { |
125 fclose(f); |
129 fclose(f); |
126 ESP_LOGI(TAG, "/spiffs/etc/equipments.conf read %d bytes, record %d: %s", bytes, RecNo, equipment.Name); |
130 ESP_LOGD(TAG, "/spiffs/etc/equipments.conf read %d bytes, record %d: %s", bytes, RecNo, equipment.Name); |
127 return; |
131 return; |
128 } |
132 } |
129 if (bytes == 0) |
133 if (bytes == 0) |
130 break; |
134 break; |
131 } |
135 } |
132 fclose(f); |
136 fclose(f); |
133 ESP_LOGI(TAG, "/spiffs/etc/equipments.conf read error, record %d not found", RecNo); |
137 ESP_LOGE(TAG, "/spiffs/etc/equipments.conf read error, record %d not found", RecNo); |
134 } |
138 } |
135 } |
139 } |
136 |
140 |
137 |
141 |
138 |
142 |
333 return; |
337 return; |
334 } |
338 } |
335 |
339 |
336 size_t bytes = fwrite(dst, 1, sizeof(runtime), f); |
340 size_t bytes = fwrite(dst, 1, sizeof(runtime), f); |
337 fclose(f); |
341 fclose(f); |
338 ESP_LOGD(TAG, "/spiffs/etc/runtime.conf written %d bytes", bytes); |
342 if (bytes != sizeof(runtime)) { |
|
343 ESP_LOGE(TAG, "/spiffs/etc/runtime.conf written %d/%d bytes", bytes, sizeof(runtime)); |
|
344 } else { |
|
345 ESP_LOGD(TAG, "/spiffs/etc/runtime.conf written %d bytes", bytes); |
|
346 } |
339 } |
347 } |
340 |
348 |
341 |
349 |
342 |
350 |
343 void read_runtime() |
351 void read_runtime() |
361 write_runtime(); |
369 write_runtime(); |
362 } else { |
370 } else { |
363 dst = (uint8_t*)&runtime; |
371 dst = (uint8_t*)&runtime; |
364 size_t bytes = fread(dst, 1, sizeof(runtime), f); |
372 size_t bytes = fread(dst, 1, sizeof(runtime), f); |
365 fclose(f); |
373 fclose(f); |
366 ESP_LOGI(TAG, "/spiffs/etc/runtime.conf read %d bytes", bytes); |
374 if (bytes != sizeof(runtime)) { |
|
375 ESP_LOGE(TAG, "/spiffs/etc/runtime.conf read %d/%d bytes", bytes, sizeof(runtime)); |
|
376 } |
367 #if 0 |
377 #if 0 |
368 printf("Auto started %s\n", runtime.AutoModeStarted ? "yes":"no"); |
378 printf("Auto started %s\n", runtime.AutoModeStarted ? "yes":"no"); |
369 printf("Stage resume %d\n", runtime.StageResume); |
379 printf("Stage resume %d\n", runtime.StageResume); |
370 printf("Stage time left %d\n", runtime.StageTimeLeft); |
380 printf("Stage time left %d\n", runtime.StageTimeLeft); |
371 printf("Hop addition %d\n", runtime.HopAddition); |
381 printf("Hop addition %d\n", runtime.HopAddition); |
406 } |
416 } |
407 |
417 |
408 fseek(f, (RecNo - 1) * sizeof(recipe), SEEK_SET); |
418 fseek(f, (RecNo - 1) * sizeof(recipe), SEEK_SET); |
409 size_t bytes = fwrite(dst, 1, sizeof(recipe), f); |
419 size_t bytes = fwrite(dst, 1, sizeof(recipe), f); |
410 fclose(f); |
420 fclose(f); |
411 ESP_LOGI(TAG, "/spiffs/etc/recipe.conf written record %d, %d bytes", RecNo, bytes); |
421 if (bytes != sizeof(recipe)) { |
|
422 ESP_LOGE(TAG, "/spiffs/etc/recipe.conf write record %d, %d/%d bytes", RecNo, bytes, sizeof(recipe)); |
|
423 } |
412 } |
424 } |
413 |
425 |
414 |
426 |
415 |
427 |
416 void read_recipe(int RecNo) |
428 void read_recipe(int RecNo) |
459 } else { |
471 } else { |
460 dst = (uint8_t*)&recipe; |
472 dst = (uint8_t*)&recipe; |
461 fseek(f, (RecNo - 1) * sizeof(recipe), SEEK_SET); |
473 fseek(f, (RecNo - 1) * sizeof(recipe), SEEK_SET); |
462 size_t bytes = fread(dst, 1, sizeof(recipe), f); |
474 size_t bytes = fread(dst, 1, sizeof(recipe), f); |
463 fclose(f); |
475 fclose(f); |
464 ESP_LOGI(TAG, "/spiffs/etc/recipe.conf read record %d, %d bytes", RecNo, bytes); |
476 if (bytes != sizeof(recipe)) { |
|
477 ESP_LOGE(TAG, "/spiffs/etc/recipe.conf read record %d, %d/%d bytes", RecNo, bytes, sizeof(recipe)); |
|
478 } |
465 } |
479 } |
466 } |
480 } |
467 |
481 |
468 |
482 |
469 |
483 |