diff --git a/flight/PiOS/STM32F10x/pios_sys.c b/flight/PiOS/STM32F10x/pios_sys.c index 04d79c45b..6b59afbad 100644 --- a/flight/PiOS/STM32F10x/pios_sys.c +++ b/flight/PiOS/STM32F10x/pios_sys.c @@ -118,8 +118,8 @@ uint32_t PIOS_SYS_getCPUFlashSize(void) /** * Returns the serial number as a string -* param[out] str pointer to a string which can store at least 32 digits + zero terminator! -* (24 digits returned for STM32) +* param[out] uint8_t pointer to a string which can store at least 12 bytes +* (12 bytes returned for STM32) * return < 0 if feature not supported */ int32_t PIOS_SYS_SerialNumberGetBinary(uint8_t *array) @@ -127,7 +127,7 @@ int32_t PIOS_SYS_SerialNumberGetBinary(uint8_t *array) int i; /* Stored in the so called "electronic signature" */ - for (i = 0; i < 12; ++i) { + for (i = 0; i < PIOS_SYS_SERIAL_NUM_BINARY_LEN; ++i) { uint8_t b = MEM8(0x1ffff7e8 + i); array[i] = b; @@ -148,7 +148,7 @@ int32_t PIOS_SYS_SerialNumberGet(char *str) int i; /* Stored in the so called "electronic signature" */ - for (i = 0; i < 24; ++i) { + for (i = 0; i < PIOS_SYS_SERIAL_NUM_ASCII_LEN; ++i) { uint8_t b = MEM8(0x1ffff7e8 + (i / 2)); if (!(i & 1)) b >>= 4; diff --git a/flight/PiOS/inc/pios_sys.h b/flight/PiOS/inc/pios_sys.h index 9407fa720..7f183a892 100644 --- a/flight/PiOS/inc/pios_sys.h +++ b/flight/PiOS/inc/pios_sys.h @@ -32,12 +32,15 @@ #ifndef PIOS_SYS_H #define PIOS_SYS_H +#define PIOS_SYS_SERIAL_NUM_BINARY_LEN 12 +#define PIOS_SYS_SERIAL_NUM_ASCII_LEN (PIOS_SYS_SERIAL_NUM_BINARY_LEN * 2) + /* Public Functions */ extern void PIOS_SYS_Init(void); extern int32_t PIOS_SYS_Reset(void); extern uint32_t PIOS_SYS_getCPUFlashSize(void); -extern int32_t PIOS_SYS_SerialNumberGetBinary(uint8_t *array); -extern int32_t PIOS_SYS_SerialNumberGet(char *str); +extern int32_t PIOS_SYS_SerialNumberGetBinary(uint8_t array[PIOS_SYS_SERIAL_NUM_BINARY_LEN]); +extern int32_t PIOS_SYS_SerialNumberGet(char str[PIOS_SYS_SERIAL_NUM_ASCII_LEN+1]); #endif /* PIOS_SYS_H */