From e639d173a089f81d2d25302161b5ad44a5debc42 Mon Sep 17 00:00:00 2001 From: Brian Webb Date: Sat, 7 Apr 2012 19:41:23 -0700 Subject: [PATCH] Create ID from a hashed CPU serial number. --- flight/PiOS/inc/pios_rfm22b_priv.h | 1 - flight/PipXtreme/System/pios_board.c | 12 ++++++++++++ flight/board_hw_defs/pipxtreme/board_hw_defs.c | 2 -- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/flight/PiOS/inc/pios_rfm22b_priv.h b/flight/PiOS/inc/pios_rfm22b_priv.h index f3a5b5bf8..56a91acdf 100644 --- a/flight/PiOS/inc/pios_rfm22b_priv.h +++ b/flight/PiOS/inc/pios_rfm22b_priv.h @@ -48,7 +48,6 @@ struct pios_rfm22b_cfg { uint8_t minPacketSize; uint8_t txWinSize; uint8_t maxConnections; - uint32_t id; }; extern int32_t PIOS_RFM22B_Init(uint32_t *rfb22b_id, const struct pios_rfm22b_cfg *cfg); diff --git a/flight/PipXtreme/System/pios_board.c b/flight/PipXtreme/System/pios_board.c index 14be4293c..d081db44f 100755 --- a/flight/PipXtreme/System/pios_board.c +++ b/flight/PipXtreme/System/pios_board.c @@ -99,6 +99,18 @@ void PIOS_Board_Init(void) { #endif /* PIOS_INCLUDE_TIM */ #if defined(PIOS_INCLUDE_PACKET_HANDLER) + // Create our (hopefully) unique 32 bit id from the processor serial number. + uint32_t crc32 = 0; + { + char serial_no_str[33]; + PIOS_SYS_SerialNumberGet(serial_no_str); + // Create a 32 bit value using 4 8 bit CRC values. + crc32 = PIOS_CRC_updateCRC(0, (uint8_t*)serial_no_str, 8) << 24; + crc32 |= PIOS_CRC_updateCRC(0, (uint8_t*)serial_no_str + 8, 8) << 16; + crc32 |= PIOS_CRC_updateCRC(0, (uint8_t*)serial_no_str + 16, 8) << 8; + crc32 |= PIOS_CRC_updateCRC(0, (uint8_t*)serial_no_str + 24, 8); + } + pios_ph_cfg.id = crc32; pios_packet_handler = PHInitialize(&pios_ph_cfg); #endif /* PIOS_INCLUDE_PACKET_HANDLER */ diff --git a/flight/board_hw_defs/pipxtreme/board_hw_defs.c b/flight/board_hw_defs/pipxtreme/board_hw_defs.c index 61cd73413..3f631375a 100644 --- a/flight/board_hw_defs/pipxtreme/board_hw_defs.c +++ b/flight/board_hw_defs/pipxtreme/board_hw_defs.c @@ -488,7 +488,6 @@ const struct pios_rfm22b_cfg pios_rfm22b_cfg = { .minPacketSize = 50, .txWinSize = 4, .maxConnections = 1, - .id = 0x36249acb }; #endif /* PIOS_INCLUDE_RFM22B */ @@ -500,7 +499,6 @@ const struct pios_rfm22b_cfg pios_rfm22b_cfg = { PacketHandlerConfig pios_ph_cfg = { .txWinSize = PIOS_PH_TX_WIN_SIZE, .maxConnections = PIOS_PH_MAX_CONNECTIONS, - .id = 0x36249acb, }; #endif /* PIOS_INCLUDE_PACKET_HANDLER */