Skip to content

Commit

Permalink
Update hwUniqueID() function (#921)
Browse files Browse the repository at this point in the history
  • Loading branch information
tekka007 authored and henrikekblad committed Sep 4, 2017
1 parent d74e9bd commit a9ef29f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
6 changes: 4 additions & 2 deletions hal/architecture/MyHw.h
@@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
*/
Expand Down
16 changes: 13 additions & 3 deletions hal/architecture/MyHwAVR.cpp
Expand Up @@ -18,6 +18,7 @@
*/

#include "MyHwAVR.h"
#include "avr/boot.h"

bool hwInit(void)
{
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion hal/architecture/MyHwESP8266.cpp
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions hal/architecture/MyHwTeensy3.cpp
@@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a9ef29f

Please sign in to comment.