libdisplay-info/di-edid-decode.c
Simon Ser 225ec04a54 di-edid-decode: print block checksum
While this isn't particularly interesting to print, this reduces
the diff between di-edid-decode and edid-decode.

This is not exposed via the low-level EDID library because callers
wouldn't have a use for it.

Signed-off-by: Simon Ser <contact@emersion.fr>
2022-06-06 11:01:55 +00:00

105 lines
2.6 KiB
C

#include <inttypes.h>
#include <stdio.h>
#include <libdisplay-info/edid.h>
#include <libdisplay-info/info.h>
static const char *
ext_tag_name(enum di_edid_ext_tag tag)
{
static char name[256];
switch (tag) {
case DI_EDID_EXT_CEA:
return "CTA-861 Extension Block";
case DI_EDID_EXT_VTB:
return "Video Timing Extension Block";
case DI_EDID_EXT_DI:
return "Display Information Extension Block";
case DI_EDID_EXT_LS:
return "Localized String Extension Block";
case DI_EDID_EXT_BLOCK_MAP:
return "Block Map Extension Block";
case DI_EDID_EXT_VENDOR:
return "Manufacturer-Specific Extension Block";
default:
snprintf(name, sizeof(name),
"Unknown EDID Extension Block 0x%02x", tag);
return name;
}
}
static void
print_ext(const struct di_edid_ext *ext, size_t ext_index)
{
const char *tag_name = ext_tag_name(di_edid_ext_get_tag(ext));
printf("\n----------------\n\n");
printf("Block %zu, %s:\n", ext_index + 1, tag_name);
}
static size_t
edid_checksum_index(size_t block_index)
{
return 128 * (block_index + 1) - 1;
}
int
main(void)
{
static uint8_t raw[32 * 1024];
size_t size = 0;
const struct di_edid *edid;
struct di_info *info;
const struct di_edid_vendor_product *vendor_product;
const struct di_edid_ext *const *exts;
size_t i;
while (!feof(stdin)) {
size += fread(&raw[size], 1, sizeof(raw) - size, stdin);
if (ferror(stdin)) {
perror("fread failed");
return 1;
}
}
info = di_info_parse_edid(raw, size);
if (!info) {
perror("di_edid_parse failed");
return 1;
}
edid = di_info_get_edid(info);
printf("Block 0, Base EDID:\n");
printf(" EDID Structure Version & Revision: %d.%d\n",
di_edid_get_version(edid), di_edid_get_revision(edid));
vendor_product = di_edid_get_vendor_product(edid);
printf(" Vendor & Product Identification:\n");
printf(" Manufacturer: %.3s\n", vendor_product->manufacturer);
printf(" Model: %" PRIu16 "\n", vendor_product->product);
printf(" Serial Number: %" PRIu32 "\n", vendor_product->serial);
if (vendor_product->model_year != 0) {
printf(" Model year: %d\n", vendor_product->model_year);
} else {
printf(" Made in: week %d of %d\n",
vendor_product->manufacture_week,
vendor_product->manufacture_year);
}
exts = di_edid_get_extensions(edid);
for (i = 0; exts[i] != NULL; i++);
if (i > 0) {
printf(" Extension blocks: %zu\n", i);
}
printf("Checksum: 0x%02hhx\n", raw[edid_checksum_index(0)]);
for (i = 0; exts[i] != NULL; i++) {
print_ext(exts[i], i);
printf("Checksum: 0x%02hhx\n", raw[edid_checksum_index(i + 1)]);
}
di_info_destroy(info);
return 0;
}