mirror of https://github.com/ArduPilot/ardupilot
uncrustify libraries/AP_Common/tools/eedump.c
This commit is contained in:
parent
4a50e56a48
commit
3a26b94af2
|
@ -5,23 +5,23 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
uint8_t eeprom[0x1000];
|
uint8_t eeprom[0x1000];
|
||||||
|
|
||||||
#pragma pack(1)
|
#pragma pack(1)
|
||||||
|
|
||||||
struct EEPROM_header {
|
struct EEPROM_header {
|
||||||
uint16_t magic;
|
uint16_t magic;
|
||||||
uint8_t revision;
|
uint8_t revision;
|
||||||
uint8_t spare;
|
uint8_t spare;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint16_t k_EEPROM_magic = 0x5041;
|
static const uint16_t k_EEPROM_magic = 0x5041;
|
||||||
static const uint16_t k_EEPROM_revision = 2;
|
static const uint16_t k_EEPROM_revision = 2;
|
||||||
|
|
||||||
struct Var_header {
|
struct Var_header {
|
||||||
uint8_t size:6;
|
uint8_t size : 6;
|
||||||
uint8_t spare:2;
|
uint8_t spare : 2;
|
||||||
uint8_t key;
|
uint8_t key;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint8_t k_key_sentinel = 0xff;
|
static const uint8_t k_key_sentinel = 0xff;
|
||||||
|
@ -29,56 +29,56 @@ static const uint8_t k_key_sentinel = 0xff;
|
||||||
void
|
void
|
||||||
fail(const char *why)
|
fail(const char *why)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "ERROR: %s\n", why);
|
fprintf(stderr, "ERROR: %s\n", why);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
struct EEPROM_header *header;
|
struct EEPROM_header *header;
|
||||||
struct Var_header *var;
|
struct Var_header *var;
|
||||||
unsigned index;
|
unsigned index;
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
|
||||||
if (argc != 2) {
|
if (argc != 2) {
|
||||||
fail("missing EEPROM file name");
|
fail("missing EEPROM file name");
|
||||||
}
|
}
|
||||||
if (NULL == (fp = fopen(argv[1], "rb"))) {
|
if (NULL == (fp = fopen(argv[1], "rb"))) {
|
||||||
fail("can't open EEPROM file");
|
fail("can't open EEPROM file");
|
||||||
}
|
}
|
||||||
if (1 != fread(eeprom, sizeof(eeprom), 1, fp)) {
|
if (1 != fread(eeprom, sizeof(eeprom), 1, fp)) {
|
||||||
fail("can't read EEPROM file");
|
fail("can't read EEPROM file");
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
header = (struct EEPROM_header *)&eeprom[0];
|
header = (struct EEPROM_header *)&eeprom[0];
|
||||||
if (header->magic != k_EEPROM_magic) {
|
if (header->magic != k_EEPROM_magic) {
|
||||||
fail("bad magic in EEPROM file");
|
fail("bad magic in EEPROM file");
|
||||||
}
|
}
|
||||||
if (header->revision != 2) {
|
if (header->revision != 2) {
|
||||||
fail("unsupported EEPROM format revision");
|
fail("unsupported EEPROM format revision");
|
||||||
}
|
}
|
||||||
printf("Header OK\n");
|
printf("Header OK\n");
|
||||||
|
|
||||||
index = sizeof(*header);
|
index = sizeof(*header);
|
||||||
for (;;) {
|
for (;; ) {
|
||||||
var = (struct Var_header *)&eeprom[index];
|
var = (struct Var_header *)&eeprom[index];
|
||||||
if (var->key == k_key_sentinel) {
|
if (var->key == k_key_sentinel) {
|
||||||
printf("end sentinel at %u\n", index);
|
printf("end sentinel at %u\n", index);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
printf("%04x: key %u size %d\n ", index, var->key, var->size + 1);
|
||||||
|
index += sizeof(*var);
|
||||||
|
for (i = 0; i <= var->size; i++) {
|
||||||
|
printf(" %02x", eeprom[index + i]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
index += var->size + 1;
|
||||||
|
if (index >= sizeof(eeprom)) {
|
||||||
|
fflush(stdout);
|
||||||
|
fail("missing end sentinel");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
printf("%04x: key %u size %d\n ", index, var->key, var->size + 1);
|
|
||||||
index += sizeof(*var);
|
|
||||||
for (i = 0; i <= var->size; i++) {
|
|
||||||
printf(" %02x", eeprom[index + i]);
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
index += var->size + 1;
|
|
||||||
if (index >= sizeof(eeprom)) {
|
|
||||||
fflush(stdout);
|
|
||||||
fail("missing end sentinel");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue