Update hwUniqueID() function (#921)

This commit is contained in:
Olivier
2017-09-04 23:37:11 +02:00
committed by Henrik Ekblad
parent d74e9bd212
commit a9ef29fa67
4 changed files with 20 additions and 8 deletions
+4 -2
View File
@@ -1,4 +1,4 @@
/*
/*
* The MySensors Arduino library handles the wireless radio link and protocol
* between your home built sensors/actuators and HA controller of choice.
* The sensors forms a self healing radio network with optional repeaters. Each
@@ -26,6 +26,8 @@
#ifndef MyHw_h
#define MyHw_h
#define MY_HWID_PADDING_BYTE (0xAAu)
// Implement these as functions or macros
/*
#define hwInit() MY_SERIALDEVICE.begin(BAUD_RATE)
@@ -83,7 +85,7 @@ int8_t hwSleep(uint8_t interrupt1, uint8_t mode1, uint8_t interrupt2, uint8_t mo
unsigned long ms);
/**
* Retrieve unique ID
* Retrieve unique hardware ID
* @param uniqueID unique ID
* @return True if unique ID successfully retrieved
*/
+13 -3
View File
@@ -18,6 +18,7 @@
*/
#include "MyHwAVR.h"
#include "avr/boot.h"
bool hwInit(void)
{
@@ -239,9 +240,18 @@ inline void hwRandomNumberInit()
bool hwUniqueID(unique_id_t* uniqueID)
{
// not implemented yet
(void)uniqueID;
return false;
// padding
(void)memset(uniqueID, MY_HWID_PADDING_BYTE, sizeof(unique_id_t));
// no unique ID for non-PB AVR, use HW specifics for diversification
*((uint8_t*)uniqueID) = boot_signature_byte_get(0x00);
*((uint8_t*)uniqueID + 1) = boot_signature_byte_get(0x02);
*((uint8_t*)uniqueID + 2) = boot_signature_byte_get(0x04);
*((uint8_t*)uniqueID + 3) = boot_signature_byte_get(0x01); //OSCCAL
// ATMEGA328PB specifics, has unique ID
//for(uint8_t idx = 0; idx < 10; idx++) {
// *((uint8_t*)uniqueID + 4 + idx) = boot_signature_byte_get(0xE + idx);
//}
return false; // false, since no unique ID returned
}
uint16_t hwCPUVoltage()
+1 -1
View File
@@ -65,7 +65,7 @@ void hwWriteConfig(const int addr, uint8_t value)
bool hwUniqueID(unique_id_t *uniqueID)
{
// padding
memset((uint8_t*)uniqueID, 0x0A, sizeof(unique_id_t));
(void)memset((uint8_t*)uniqueID, MY_HWID_PADDING_BYTE, sizeof(unique_id_t));
uint32_t val = ESP.getChipId();
(void)memcpy((uint8_t*)uniqueID, &val, 4);
val = ESP.getFlashChipId();
+2 -2
View File
@@ -1,4 +1,4 @@
/**
/**
* The MySensors Arduino library handles the wireless radio link and protocol
* between your home built sensors/actuators and HA controller of choice.
* The sensors forms a self healing radio network with optional repeaters. Each
@@ -92,7 +92,7 @@ bool hwUniqueID(unique_id_t *uniqueID)
{
#if defined(__MKL26Z64__)
(void)memcpy((uint8_t*)uniqueID, &SIM_UIDMH, 12);
(void)memset((uint8_t*)uniqueID + 12, 0, 4);
(void)memset((uint8_t*)uniqueID + 12, MY_HWID_PADDING_BYTE, 4);
#else
(void)memcpy((uint8_t*)uniqueID, &SIM_UIDH, 16);
#endif