mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-02-22 15:53:56 -04:00
uncrustify libraries/AP_Common/tools/eedump_apparam.c
This commit is contained in:
parent
3e4507a4a2
commit
4a50e56a48
@ -6,19 +6,19 @@
|
|||||||
#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 {
|
||||||
uint8_t magic[2];
|
uint8_t magic[2];
|
||||||
uint8_t revision;
|
uint8_t revision;
|
||||||
uint8_t spare;
|
uint8_t spare;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint16_t k_EEPROM_magic0 = 0x50;
|
static const uint16_t k_EEPROM_magic0 = 0x50;
|
||||||
static const uint16_t k_EEPROM_magic1 = 0x41;
|
static const uint16_t k_EEPROM_magic1 = 0x41;
|
||||||
static const uint16_t k_EEPROM_revision = 6;
|
static const uint16_t k_EEPROM_revision = 6;
|
||||||
|
|
||||||
enum ap_var_type {
|
enum ap_var_type {
|
||||||
AP_PARAM_NONE = 0,
|
AP_PARAM_NONE = 0,
|
||||||
@ -33,19 +33,19 @@ enum ap_var_type {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static const char *type_names[8] = {
|
static const char *type_names[8] = {
|
||||||
"NONE", "INT8", "INT16", "INT32", "FLOAT", "VECTOR3F", "MATRIX6F", "GROUP"
|
"NONE", "INT8", "INT16", "INT32", "FLOAT", "VECTOR3F", "MATRIX6F", "GROUP"
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Param_header {
|
struct Param_header {
|
||||||
uint32_t key:8;
|
uint32_t key : 8;
|
||||||
uint32_t type:6;
|
uint32_t type : 6;
|
||||||
uint32_t group_element:18;
|
uint32_t group_element : 18;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static const uint8_t _sentinal_key = 0xFF;
|
static const uint8_t _sentinal_key = 0xFF;
|
||||||
static const uint8_t _sentinal_type = 0xFF;
|
static const uint8_t _sentinal_type = 0xFF;
|
||||||
static const uint8_t _sentinal_group = 0xFF;
|
static const uint8_t _sentinal_group = 0xFF;
|
||||||
|
|
||||||
static uint8_t type_size(enum ap_var_type type)
|
static uint8_t type_size(enum ap_var_type type)
|
||||||
{
|
{
|
||||||
@ -75,107 +75,107 @@ static uint8_t type_size(enum ap_var_type type)
|
|||||||
static void
|
static 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 Param_header *var;
|
struct Param_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[0] != k_EEPROM_magic0 ||
|
if (header->magic[0] != k_EEPROM_magic0 ||
|
||||||
header->magic[1] != k_EEPROM_magic1) {
|
header->magic[1] != k_EEPROM_magic1) {
|
||||||
fail("bad magic in EEPROM file");
|
fail("bad magic in EEPROM file");
|
||||||
}
|
}
|
||||||
if (header->revision != k_EEPROM_revision) {
|
if (header->revision != k_EEPROM_revision) {
|
||||||
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 (;; ) {
|
||||||
uint8_t size;
|
uint8_t size;
|
||||||
var = (struct Param_header *)&eeprom[index];
|
var = (struct Param_header *)&eeprom[index];
|
||||||
if (var->key == _sentinal_key ||
|
if (var->key == _sentinal_key ||
|
||||||
var->group_element == _sentinal_group ||
|
var->group_element == _sentinal_group ||
|
||||||
var->type == _sentinal_type) {
|
var->type == _sentinal_type) {
|
||||||
printf("end sentinel at %u\n", index);
|
printf("end sentinel at %u\n", index);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
size = type_size(var->type);
|
size = type_size(var->type);
|
||||||
printf("%04x: type %u (%s) key %u group_element %u size %d value ",
|
printf("%04x: type %u (%s) key %u group_element %u size %d value ",
|
||||||
index, var->type, type_names[var->type], var->key, var->group_element, size);
|
index, var->type, type_names[var->type], var->key, var->group_element, size);
|
||||||
index += sizeof(*var);
|
index += sizeof(*var);
|
||||||
switch (var->type) {
|
switch (var->type) {
|
||||||
case AP_PARAM_INT8:
|
case AP_PARAM_INT8:
|
||||||
printf("%d\n", (int)*(int8_t *)&eeprom[index]);
|
printf("%d\n", (int)*(int8_t *)&eeprom[index]);
|
||||||
break;
|
break;
|
||||||
case AP_PARAM_INT16:
|
case AP_PARAM_INT16:
|
||||||
printf("%d\n", (int)*(int16_t *)&eeprom[index]);
|
printf("%d\n", (int)*(int16_t *)&eeprom[index]);
|
||||||
break;
|
break;
|
||||||
case AP_PARAM_INT32:
|
case AP_PARAM_INT32:
|
||||||
printf("%d\n", (int)*(int32_t *)&eeprom[index]);
|
printf("%d\n", (int)*(int32_t *)&eeprom[index]);
|
||||||
break;
|
break;
|
||||||
case AP_PARAM_FLOAT:
|
case AP_PARAM_FLOAT:
|
||||||
printf("%f\n", *(float *)&eeprom[index]);
|
printf("%f\n", *(float *)&eeprom[index]);
|
||||||
break;
|
break;
|
||||||
case AP_PARAM_VECTOR3F:
|
case AP_PARAM_VECTOR3F:
|
||||||
printf("%f %f %f\n",
|
printf("%f %f %f\n",
|
||||||
*(float *)&eeprom[index],
|
*(float *)&eeprom[index],
|
||||||
*(float *)&eeprom[index+4],
|
*(float *)&eeprom[index+4],
|
||||||
*(float *)&eeprom[index+8]);
|
*(float *)&eeprom[index+8]);
|
||||||
break;
|
break;
|
||||||
case AP_PARAM_VECTOR6F:
|
case AP_PARAM_VECTOR6F:
|
||||||
printf("%f %f %f %f %f %f\n",
|
printf("%f %f %f %f %f %f\n",
|
||||||
*(float *)&eeprom[index],
|
*(float *)&eeprom[index],
|
||||||
*(float *)&eeprom[index+4],
|
*(float *)&eeprom[index+4],
|
||||||
*(float *)&eeprom[index+8],
|
*(float *)&eeprom[index+8],
|
||||||
*(float *)&eeprom[index+12],
|
*(float *)&eeprom[index+12],
|
||||||
*(float *)&eeprom[index+16],
|
*(float *)&eeprom[index+16],
|
||||||
*(float *)&eeprom[index+20]);
|
*(float *)&eeprom[index+20]);
|
||||||
break;
|
break;
|
||||||
case AP_PARAM_MATRIX3F:
|
case AP_PARAM_MATRIX3F:
|
||||||
printf("%f %f %f %f %f %f %f %f %f\n",
|
printf("%f %f %f %f %f %f %f %f %f\n",
|
||||||
*(float *)&eeprom[index],
|
*(float *)&eeprom[index],
|
||||||
*(float *)&eeprom[index+4],
|
*(float *)&eeprom[index+4],
|
||||||
*(float *)&eeprom[index+8],
|
*(float *)&eeprom[index+8],
|
||||||
*(float *)&eeprom[index+12],
|
*(float *)&eeprom[index+12],
|
||||||
*(float *)&eeprom[index+16],
|
*(float *)&eeprom[index+16],
|
||||||
*(float *)&eeprom[index+20],
|
*(float *)&eeprom[index+20],
|
||||||
*(float *)&eeprom[index+24],
|
*(float *)&eeprom[index+24],
|
||||||
*(float *)&eeprom[index+28],
|
*(float *)&eeprom[index+28],
|
||||||
*(float *)&eeprom[index+32]);
|
*(float *)&eeprom[index+32]);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("NONE\n");
|
printf("NONE\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
for (i = 0; i < size; i++) {
|
for (i = 0; i < size; i++) {
|
||||||
printf(" %02x", eeprom[index + i]);
|
printf(" %02x", eeprom[index + i]);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
index += size;
|
index += size;
|
||||||
if (index >= sizeof(eeprom)) {
|
if (index >= sizeof(eeprom)) {
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
fail("missing end sentinel");
|
fail("missing end sentinel");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user