/* Offline inspection of the two owned bench sectors with the canonical storage decoder. */ #include "nxs_storage.h" #include #include #include static uint8_t sectors[NXS_STORAGE_SLOT_COUNT * NXS_STORAGE_SECTOR_BYTES]; static bool read_slot(void *context, unsigned int slot, nxs_storage_record_t *record) { (void)context; if (slot >= NXS_STORAGE_SLOT_COUNT) return false; memcpy(record->bytes, sectors + slot * NXS_STORAGE_SECTOR_BYTES, sizeof(record->bytes)); return true; } int main(int count, char **arguments) { if (count != 2) return 2; FILE *file = fopen(arguments[1], "rb"); if (!file || fread(sectors, 1, sizeof(sectors), file) != sizeof(sectors) || fgetc(file) != EOF) return 1; fclose(file); for (unsigned int slot = 0; slot < NXS_STORAGE_SLOT_COUNT; ++slot) { nxs_storage_record_t record; nxs_stored_state_t state; read_slot(NULL, slot, &record); bool valid = nxs_storage_record_decode(&record, &state); printf("{\"slot\":%u,\"valid\":%s", slot, valid ? "true" : "false"); if (valid) printf(",\"generation\":%u,\"muted\":%u,\"attenuation_db\":%.9g", state.generation, state.snapshot.muted, state.snapshot.attenuation_db); puts("}"); } const nxs_storage_io_t io = {.read = read_slot}; nxs_stored_state_t selected; unsigned int slot; nxs_storage_load_result_t result = nxs_storage_read(&io, &selected, &slot); printf("{\"load_result\":%u", (unsigned int)result); if (result == NXS_STORAGE_LOADED) printf(",\"selected_slot\":%u,\"generation\":%u,\"muted\":%u,\"attenuation_db\":%.9g", slot, selected.generation, selected.snapshot.muted, selected.snapshot.attenuation_db); puts("}"); return 0; }