/C-OSD/arducam-osd/libraries/AP_Common/tools/eedump.c |
---|
0,0 → 1,84 |
/* |
* Simple tool to dump the AP_Var contents from an EEPROM dump |
*/ |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdint.h> |
uint8_t eeprom[0x1000]; |
#pragma pack(1) |
struct EEPROM_header { |
uint16_t magic; |
uint8_t revision; |
uint8_t spare; |
}; |
static const uint16_t k_EEPROM_magic = 0x5041; |
static const uint16_t k_EEPROM_revision = 2; |
struct Var_header { |
uint8_t size:6; |
uint8_t spare:2; |
uint8_t key; |
}; |
static const uint8_t k_key_sentinel = 0xff; |
void |
fail(const char *why) |
{ |
fprintf(stderr, "ERROR: %s\n", why); |
exit(1); |
} |
int |
main(int argc, char *argv[]) |
{ |
FILE *fp; |
struct EEPROM_header *header; |
struct Var_header *var; |
unsigned index; |
unsigned i; |
if (argc != 2) { |
fail("missing EEPROM file name"); |
} |
if (NULL == (fp = fopen(argv[1], "rb"))) { |
fail("can't open EEPROM file"); |
} |
if (1 != fread(eeprom, sizeof(eeprom), 1, fp)) { |
fail("can't read EEPROM file"); |
} |
fclose(fp); |
header = (struct EEPROM_header *)&eeprom[0]; |
if (header->magic != k_EEPROM_magic) { |
fail("bad magic in EEPROM file"); |
} |
if (header->revision != 2) { |
fail("unsupported EEPROM format revision"); |
} |
printf("Header OK\n"); |
index = sizeof(*header); |
for (;;) { |
var = (struct Var_header *)&eeprom[index]; |
if (var->key == k_key_sentinel) { |
printf("end sentinel at %u\n", index); |
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"); |
} |
} |
} |
/C-OSD/arducam-osd/libraries/AP_Common/tools/eedump.pl |
---|
0,0 → 1,47 |
#!/usr/bin/perl |
$file = $ARGV[0]; |
open(IN,$file) || die print "Failed to open file: $file : $!"; |
read(IN,$buffer,1); |
read(IN,$buffer2,1); |
if (ord($buffer) != 0x41 && ord($buffer2) != 0x50) { |
print "bad header ". $buffer ." ".$buffer2. "\n"; |
exit; |
} |
read(IN,$buffer,1); |
if (ord($buffer) != 2) { |
print "bad version"; |
exit; |
} |
# spare |
read(IN,$buffer,1); |
$a = 0; |
while (read(IN,$buffer,1)) { |
$pos = (tell(IN) - 1); |
$size = ((ord($buffer) & 63)); |
read(IN,$buffer,1); |
if (ord($buffer) == 0xff) { |
printf("end sentinel at %u\n", $pos); |
last; |
} |
printf("%04x: key %u size %d\n ", $pos, ord($buffer), $size + 1); |
for ($i = 0; $i <= ($size); $i++) { |
read(IN,$buffer,1); |
printf(" %02x", ord($buffer)); |
} |
print "\n"; |
} |
close IN; |
/C-OSD/arducam-osd/libraries/AP_Common/tools/eedump_apparam.c |
---|
0,0 → 1,181 |
/* |
* Simple tool to dump the AP_Param contents from an EEPROM dump |
* Andrew Tridgell February 2012 |
*/ |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdint.h> |
uint8_t eeprom[0x1000]; |
#pragma pack(1) |
struct EEPROM_header { |
uint8_t magic[2]; |
uint8_t revision; |
uint8_t spare; |
}; |
static const uint16_t k_EEPROM_magic0 = 0x50; |
static const uint16_t k_EEPROM_magic1 = 0x41; |
static const uint16_t k_EEPROM_revision = 5; |
enum ap_var_type { |
AP_PARAM_NONE = 0, |
AP_PARAM_INT8, |
AP_PARAM_INT16, |
AP_PARAM_INT32, |
AP_PARAM_FLOAT, |
AP_PARAM_VECTOR3F, |
AP_PARAM_VECTOR6F, |
AP_PARAM_MATRIX3F, |
AP_PARAM_GROUP |
}; |
static const char *type_names[8] = { |
"NONE", "INT8", "INT16", "INT32", "FLOAT", "VECTOR3F", "MATRIX6F", "GROUP" |
}; |
struct Param_header { |
uint8_t key; |
uint8_t group_element; |
uint8_t type; |
}; |
static const uint8_t _sentinal_key = 0xFF; |
static const uint8_t _sentinal_type = 0xFF; |
static const uint8_t _sentinal_group = 0xFF; |
static uint8_t type_size(enum ap_var_type type) |
{ |
switch (type) { |
case AP_PARAM_NONE: |
case AP_PARAM_GROUP: |
return 0; |
case AP_PARAM_INT8: |
return 1; |
case AP_PARAM_INT16: |
return 2; |
case AP_PARAM_INT32: |
return 4; |
case AP_PARAM_FLOAT: |
return 4; |
case AP_PARAM_VECTOR3F: |
return 3*4; |
case AP_PARAM_VECTOR6F: |
return 6*4; |
case AP_PARAM_MATRIX3F: |
return 3*3*4; |
} |
printf("unknown type %u\n", type); |
return 0; |
} |
static void |
fail(const char *why) |
{ |
fprintf(stderr, "ERROR: %s\n", why); |
exit(1); |
} |
int |
main(int argc, char *argv[]) |
{ |
FILE *fp; |
struct EEPROM_header *header; |
struct Param_header *var; |
unsigned index; |
unsigned i; |
if (argc != 2) { |
fail("missing EEPROM file name"); |
} |
if (NULL == (fp = fopen(argv[1], "rb"))) { |
fail("can't open EEPROM file"); |
} |
if (1 != fread(eeprom, sizeof(eeprom), 1, fp)) { |
fail("can't read EEPROM file"); |
} |
fclose(fp); |
header = (struct EEPROM_header *)&eeprom[0]; |
if (header->magic[0] != k_EEPROM_magic0 || |
header->magic[1] != k_EEPROM_magic1) { |
fail("bad magic in EEPROM file"); |
} |
if (header->revision != k_EEPROM_revision) { |
fail("unsupported EEPROM format revision"); |
} |
printf("Header OK\n"); |
index = sizeof(*header); |
for (;;) { |
uint8_t size; |
var = (struct Param_header *)&eeprom[index]; |
if (var->key == _sentinal_key || |
var->group_element == _sentinal_group || |
var->type == _sentinal_type) { |
printf("end sentinel at %u\n", index); |
break; |
} |
size = type_size(var->type); |
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 += sizeof(*var); |
switch (var->type) { |
case AP_PARAM_INT8: |
printf("%d\n", (int)*(int8_t *)&eeprom[index]); |
break; |
case AP_PARAM_INT16: |
printf("%d\n", (int)*(int16_t *)&eeprom[index]); |
break; |
case AP_PARAM_INT32: |
printf("%d\n", (int)*(int32_t *)&eeprom[index]); |
break; |
case AP_PARAM_FLOAT: |
printf("%f\n", *(float *)&eeprom[index]); |
break; |
case AP_PARAM_VECTOR3F: |
printf("%f %f %f\n", |
*(float *)&eeprom[index], |
*(float *)&eeprom[index+4], |
*(float *)&eeprom[index+8]); |
break; |
case AP_PARAM_VECTOR6F: |
printf("%f %f %f %f %f %f\n", |
*(float *)&eeprom[index], |
*(float *)&eeprom[index+4], |
*(float *)&eeprom[index+8], |
*(float *)&eeprom[index+12], |
*(float *)&eeprom[index+16], |
*(float *)&eeprom[index+20]); |
break; |
case AP_PARAM_MATRIX3F: |
printf("%f %f %f %f %f %f %f %f %f\n", |
*(float *)&eeprom[index], |
*(float *)&eeprom[index+4], |
*(float *)&eeprom[index+8], |
*(float *)&eeprom[index+12], |
*(float *)&eeprom[index+16], |
*(float *)&eeprom[index+20], |
*(float *)&eeprom[index+24], |
*(float *)&eeprom[index+28], |
*(float *)&eeprom[index+32]); |
break; |
default: |
printf("NONE\n"); |
break; |
} |
for (i = 0; i < size; i++) { |
printf(" %02x", eeprom[index + i]); |
} |
printf("\n"); |
index += size; |
if (index >= sizeof(eeprom)) { |
fflush(stdout); |
fail("missing end sentinel"); |
} |
} |
return 0; |
} |
/C-OSD/arducam-osd/libraries/AP_Common/tools/eedump_apparam.pl |
---|
0,0 → 1,78 |
#!/usr/bin/perl |
$file = $ARGV[0]; |
open(IN,$file) || die print "Failed to open file: $file : $!"; |
read(IN,$buffer,1); |
read(IN,$buffer2,1); |
if (ord($buffer2) != 0x41 && ord($buffer) != 0x50) { |
print "bad header ". $buffer ." ".$buffer2. "\n"; |
exit; |
} |
read(IN,$buffer,1); |
if (ord($buffer) != 5) { |
print "bad version"; |
exit; |
} |
# spare |
read(IN,$buffer,1); |
$a = 0; |
while (read(IN,$buffer,1)) { |
$pos = (tell(IN) - 1); |
if (ord($buffer) == 0xff) { |
printf("end sentinel at %u\n", $pos); |
last; |
} |
read(IN,$buffer2,1); |
read(IN,$buffer3,1); |
if (ord($buffer3) == 0) { #none |
$size = 0; |
$type = "NONE"; |
} elsif (ord($buffer3) == 1) { #int8 |
$size = 1; |
$type = "INT8"; |
} elsif (ord($buffer3) == 2) { #int16 |
$size = 2; |
$type = "INT16"; |
} elsif (ord($buffer3) == 3) { #int32 |
$size = 4; |
$type = "INT32"; |
} elsif (ord($buffer3) == 4) { #float |
$size = 4; |
$type = "FLOAT"; |
} elsif (ord($buffer3) == 5) { #vector 3 |
$size = 3*4; |
$type = "VECTOR3F"; |
} elsif (ord($buffer3) == 6) { #vector6 |
$size = 6*4; |
$type = "VECTOR6F"; |
} elsif (ord($buffer3) == 7) { #matrix |
$size = 3*3*4; |
$type = "MATRIX6F"; |
} elsif (ord($buffer3) == 8) { #group |
$size = 0; |
$type = "GROUP"; |
} else { |
print "Unknown type\n"; |
$size = 0; |
} |
printf("%04x: type %u ($type) key %u group_element %u size %d\n ", $pos, ord($buffer3),ord($buffer),ord($buffer2), $size); |
for ($i = 0; $i < ($size); $i++) { |
read(IN,$buffer,1); |
printf(" %02x", ord($buffer)); |
} |
print "\n"; |
} |
close IN; |