Add get_hardware_id

This commit is contained in:
fvanroie 2021-04-25 02:13:41 +02:00
parent 079d0630e6
commit 074ad55604
11 changed files with 88 additions and 19 deletions

View File

@ -41,8 +41,11 @@ class BaseDevice {
{ {
return ""; return "";
} }
const char* get_model(); virtual const char* get_model();
virtual const char* get_hardware_id()
{
return "";
}
virtual void init() virtual void init()
{} {}
virtual void show_info() virtual void show_info()

View File

@ -5,6 +5,7 @@
#include "Arduino.h" #include "Arduino.h"
#include <Esp.h> #include <Esp.h>
#include <WiFi.h>
#include "esp_system.h" #include "esp_system.h"
#include "hasp_conf.h" #include "hasp_conf.h"
@ -21,6 +22,24 @@
namespace dev { namespace dev {
Esp32Device::Esp32Device()
{
_hostname = MQTT_NODENAME;
_backlight_invert = (TFT_BACKLIGHT_ON == LOW);
_backlight_power = 1;
_backlight_level = 255;
_backlight_pin = TFT_BCKL;
/* fill unique identifier with wifi mac */
byte mac[6];
WiFi.macAddress(mac);
_hardware_id.reserve(13);
for(int i = 0; i < 6; ++i) {
if(mac[i] < 0x10) _hardware_id += "0";
_hardware_id += String(mac[i], HEX).c_str();
}
}
void Esp32Device::reboot() void Esp32Device::reboot()
{ {
ESP.restart(); ESP.restart();
@ -76,6 +95,11 @@ const char* Esp32Device::get_chip_model()
// model += chip_info.revision; // model += chip_info.revision;
} }
const char* Esp32Device::get_hardware_id()
{
return _hardware_id.c_str();
}
void Esp32Device::set_backlight_pin(uint8_t pin) void Esp32Device::set_backlight_pin(uint8_t pin)
{ {
_backlight_pin = pin; _backlight_pin = pin;

View File

@ -14,14 +14,8 @@ namespace dev {
class Esp32Device : public BaseDevice { class Esp32Device : public BaseDevice {
public: public:
Esp32Device() Esp32Device();
{
_hostname = MQTT_NODENAME;
_backlight_invert = (TFT_BACKLIGHT_ON == LOW);
_backlight_power = 1;
_backlight_level = 255;
_backlight_pin = TFT_BCKL;
}
void reboot() override; void reboot() override;
void show_info() override; void show_info() override;
@ -29,6 +23,7 @@ class Esp32Device : public BaseDevice {
void set_hostname(const char*); void set_hostname(const char*);
const char* get_core_version(); const char* get_core_version();
const char* get_chip_model(); const char* get_chip_model();
const char* get_hardware_id();
void set_backlight_pin(uint8_t pin) override; void set_backlight_pin(uint8_t pin) override;
void set_backlight_level(uint8_t val) override; void set_backlight_level(uint8_t val) override;
@ -45,6 +40,7 @@ class Esp32Device : public BaseDevice {
private: private:
std::string _hostname; std::string _hostname;
std::string _hardware_id;
uint8_t _backlight_pin; uint8_t _backlight_pin;
uint8_t _backlight_level; uint8_t _backlight_level;

View File

@ -5,6 +5,7 @@
#include "Arduino.h" #include "Arduino.h"
#include <Esp.h> #include <Esp.h>
#include <ESP8266WiFi.h>
#include "esp8266.h" #include "esp8266.h"
@ -15,6 +16,25 @@
namespace dev { namespace dev {
Esp8266Device::Esp8266Device()
{
_hostname = MQTT_NODENAME;
_backlight_invert = (TFT_BACKLIGHT_ON == LOW);
_backlight_power = 1;
_backlight_level = 255;
_core_version = ESP.getCoreVersion().c_str();
_backlight_pin = TFT_BCKL;
/* fill unique identifier with wifi mac */
byte mac[6];
WiFi.macAddress(mac);
_hardware_id.reserve(13);
for(int i = 0; i < 6; ++i) {
if(mac[i] < 0x10) _hardware_id += "0";
_hardware_id += String(mac[i], HEX).c_str();
}
}
void Esp8266Device::reboot() void Esp8266Device::reboot()
{ {
ESP.restart(); ESP.restart();
@ -46,6 +66,11 @@ const char* Esp8266Device::get_chip_model()
return "ESP8266"; return "ESP8266";
} }
const char* Esp8266Device::get_hardware_id()
{
return _hardware_id.c_str();
}
void Esp8266Device::set_backlight_pin(uint8_t pin) void Esp8266Device::set_backlight_pin(uint8_t pin)
{ {
_backlight_pin = pin; _backlight_pin = pin;

View File

@ -14,15 +14,7 @@ namespace dev {
class Esp8266Device : public BaseDevice { class Esp8266Device : public BaseDevice {
public: public:
Esp8266Device() Esp8266Device();
{
_hostname = MQTT_NODENAME;
_backlight_invert = (TFT_BACKLIGHT_ON == LOW);
_backlight_power = 1;
_backlight_level = 255;
_core_version = ESP.getCoreVersion().c_str();
_backlight_pin = TFT_BCKL;
}
void reboot() override; void reboot() override;
void show_info() override; void show_info() override;
@ -31,6 +23,7 @@ class Esp8266Device : public BaseDevice {
void set_hostname(const char*); void set_hostname(const char*);
const char* get_core_version(); const char* get_core_version();
const char* get_chip_model(); const char* get_chip_model();
const char* get_hardware_id();
void set_backlight_pin(uint8_t pin) override; void set_backlight_pin(uint8_t pin) override;
void set_backlight_level(uint8_t val) override; void set_backlight_level(uint8_t val) override;
@ -47,6 +40,7 @@ class Esp8266Device : public BaseDevice {
private: private:
std::string _hostname; std::string _hostname;
std::string _hardware_id;
std::string _core_version; std::string _core_version;
uint8_t _backlight_pin; uint8_t _backlight_pin;

View File

@ -66,21 +66,29 @@ const char* PosixDevice::get_hostname()
{ {
return _hostname.c_str(); return _hostname.c_str();
} }
void PosixDevice::set_hostname(const char* hostname) void PosixDevice::set_hostname(const char* hostname)
{ {
_hostname = hostname; _hostname = hostname;
monitor_title(hostname); monitor_title(hostname);
// SDL_SetWindowTitle(monitor.window, hostname); // SDL_SetWindowTitle(monitor.window, hostname);
} }
const char* PosixDevice::get_core_version() const char* PosixDevice::get_core_version()
{ {
return _core_version.c_str(); return _core_version.c_str();
} }
const char* PosixDevice::get_chip_model() const char* PosixDevice::get_chip_model()
{ {
return _chip_model.c_str(); return _chip_model.c_str();
} }
const char* PosixDevice::get_hardware_id()
{
return "223344556677";
}
void PosixDevice::set_backlight_pin(uint8_t pin) void PosixDevice::set_backlight_pin(uint8_t pin)
{ {
// PosixDevice::backlight_pin = pin; // PosixDevice::backlight_pin = pin;

View File

@ -38,6 +38,7 @@ class PosixDevice : public BaseDevice {
void set_hostname(const char*); void set_hostname(const char*);
const char* get_core_version(); const char* get_core_version();
const char* get_chip_model(); const char* get_chip_model();
const char* get_hardware_id();
void set_backlight_pin(uint8_t pin); void set_backlight_pin(uint8_t pin);
void set_backlight_level(uint8_t val); void set_backlight_level(uint8_t val);

View File

@ -30,6 +30,7 @@ const char* Stm32f4Device::get_hostname()
{ {
return _hostname.c_str(); return _hostname.c_str();
} }
void Stm32f4Device::set_hostname(const char* hostname) void Stm32f4Device::set_hostname(const char* hostname)
{ {
_hostname = hostname; _hostname = hostname;
@ -40,6 +41,14 @@ const char* Stm32f4Device::get_core_version()
// return ESP.getCoreVersion().c_str(); // return ESP.getCoreVersion().c_str();
} }
const char* Stm32f4Device::get_hardware_id()
{
// https://stm32duinoforum.com/forum/viewtopic_f_29_t_2909_start_10.html
// Serial.println("UID [HEX] : "+String(*(uint32_t*)(UID_BASE), HEX)+" "+String(*(uint32_t*)(UID_BASE+0x04),
// HEX)+" "+String(*(uint32_t*)(UID_BASE+0x08), HEX));
return _hardware_id.c_str();
}
void Stm32f4Device::set_backlight_pin(uint8_t pin) void Stm32f4Device::set_backlight_pin(uint8_t pin)
{ {
_backlight_pin = pin; _backlight_pin = pin;

View File

@ -30,6 +30,7 @@ class Stm32f4Device : public BaseDevice {
void set_hostname(const char*); void set_hostname(const char*);
const char* get_core_version(); const char* get_core_version();
const char* get_chip_model(); const char* get_chip_model();
const char* get_chip_hardware_id();
void set_backlight_pin(uint8_t pin) override; void set_backlight_pin(uint8_t pin) override;
void set_backlight_level(uint8_t val) override; void set_backlight_level(uint8_t val) override;
@ -46,6 +47,7 @@ class Stm32f4Device : public BaseDevice {
private: private:
std::string _hostname; std::string _hostname;
std::string _hardware_id;
uint8_t _backlight_pin; uint8_t _backlight_pin;
uint8_t _backlight_level; uint8_t _backlight_level;

View File

@ -55,11 +55,17 @@ const char* Win32Device::get_core_version()
{ {
return _core_version.c_str(); return _core_version.c_str();
} }
const char* Win32Device::get_chip_model() const char* Win32Device::get_chip_model()
{ {
return "SDL2"; return "SDL2";
} }
const char* Win32Device::get_hardware_id()
{
return "112233445566";
}
void Win32Device::set_backlight_pin(uint8_t pin) void Win32Device::set_backlight_pin(uint8_t pin)
{ {
// Win32Device::_backlight_pin = pin; // Win32Device::_backlight_pin = pin;

View File

@ -59,6 +59,7 @@ class Win32Device : public BaseDevice {
void set_hostname(const char*); void set_hostname(const char*);
const char* get_core_version(); const char* get_core_version();
const char* get_chip_model(); const char* get_chip_model();
const char* get_hardware_id();
void set_backlight_pin(uint8_t pin); void set_backlight_pin(uint8_t pin);
void set_backlight_level(uint8_t val); void set_backlight_level(uint8_t val);