Skip to content

Commit

Permalink
handling of device info changed
Browse files Browse the repository at this point in the history
  • Loading branch information
pa-pa committed Sep 12, 2017
1 parent 5b7cf04 commit 9806caa
Show file tree
Hide file tree
Showing 16 changed files with 162 additions and 135 deletions.
5 changes: 3 additions & 2 deletions AskSinPP.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@
#ifndef __ASKSINPP_h__
#define __ASKSINPP_h__

#define ASKSIN_PLUS_PLUS_VERSION "2.0.0"
#define ASKSIN_PLUS_PLUS_VERSION "2.1.0"

#define ASKSIN_PLUS_PLUS_IDENTIFIER F("AskSin++ V" ASKSIN_PLUS_PLUS_VERSION " (" __DATE__ " " __TIME__ ")")

#ifdef ARDUINO_ARCH_STM32F1
#define _delay_us(us) delayMicroseconds(us)
inline void _delay_ms(uint32_t ms) { do { delayMicroseconds(1000); } while( (--ms) > 0); }

#define digitalPinToInterrupt(pin) pin
#define digitalPinToInterrupt(pin) (pin)
#define enableInterrupt(pin,handler,mode) attachInterrupt(pin,handler,mode)
#define disableInterrupt(pin) detachInterrupt(pin)
#define memcmp_P(src,dst,count) memcmp((src),(dst),(count))
#else
#ifdef ARDUINO_ARCH_ATMEGA32
inline uint8_t digitalPinToInterrupt(uint8_t pin) { return pin == 11 ? 1 : 0; } // D2 -> 0 && D3 -> 1
Expand Down
32 changes: 20 additions & 12 deletions Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ enum Types {
};
};

struct DeviceInfo {
uint8_t DeviceID[3];
char Serial[11];
uint8_t DeviceModel[2];
uint8_t Firmware;
uint8_t DeviceType;
uint8_t DeviceInfo[3];
};


template <class HalType>
class Device {
Expand All @@ -69,9 +78,10 @@ class Device {
Message msg;
KeyStore kstore;

const DeviceInfo& info;

public:
Device (uint16_t addr,List0& l) : hal(0), list0(l), msgcount(0), lastmsg(0), kstore(addr) {
Device (const DeviceInfo& i,uint16_t addr,List0& l) : hal(0), list0(l), msgcount(0), lastmsg(0), kstore(addr), info(i) {
// TODO init seed
}
virtual ~Device () {}
Expand Down Expand Up @@ -118,36 +128,34 @@ class Device {
#ifdef USE_OTA_BOOTLOADER
HalType::pgm_read((uint8_t*)&id,OTA_HMID_START,sizeof(id));
#else
id = DEVICE_ID;
uint8_t ids[3];
memcpy_P(ids,info.DeviceID,3);
id = HMID(ids);
#endif
}

void getDeviceSerial (uint8_t* serial) {
#ifdef USE_OTA_BOOTLOADER
HalType::pgm_read((uint8_t*)serial,OTA_SERIAL_START,10);
#else
memcpy(serial,DEVICE_SERIAL,10);
memcpy_P(serial,info.Serial,10);
#endif
}

bool isDeviceSerial (const uint8_t* serial) {
uint8_t tmp[10];
getDeviceSerial(tmp);
return memcmp(tmp,serial,10)==0;
return memcmp_P(serial,info.Serial,10);
}

void getDeviceModel (uint8_t* model) {
#ifdef USE_OTA_BOOTLOADER
HalType::pgm_read(model,OTA_MODEL_START,2);
#else
uint8_t dm[2] = {DEVICE_MODEL};
memcpy(model,dm,sizeof(dm));
memcpy_P(model,info.DeviceModel,sizeof(info.DeviceModel));
#endif
}

void getDeviceInfo (uint8_t* info) {
uint8_t di[3] = {DEVICE_INFO};
memcpy(info,di,sizeof(di));
void getDeviceInfo (uint8_t* di) {
memcpy_P(di,info.DeviceInfo,sizeof(info.DeviceInfo));
}

HMID getMasterID () {
Expand Down Expand Up @@ -251,7 +259,7 @@ class Device {
void sendDeviceInfo (const HMID& to,uint8_t count) {
DeviceInfoMsg& pm = msg.deviceInfo();
pm.init(to,count);
pm.fill(DEVICE_FIRMWARE,DEVICE_TYPE);
pm.fill(pgm_read_byte(&info.Firmware),pgm_read_byte(&info.DeviceType));
getDeviceModel(pm.model());
getDeviceSerial(pm.serial());
getDeviceInfo(pm.info());
Expand Down
2 changes: 1 addition & 1 deletion Dimmer.h
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ class DimmerDevice : public MultiChannelDevice<HalType,ChannelType,ChannelCount,
public:
typedef MultiChannelDevice<HalType,ChannelType,ChannelCount,List0Type> DeviceType;

DimmerDevice (uint16_t addr) : DeviceType(addr), pin(0) {}
DimmerDevice (const DeviceInfo& info,uint16_t addr) : DeviceType(info,addr), pin(0) {}
virtual ~DimmerDevice () {}

void firstinit () {
Expand Down
4 changes: 2 additions & 2 deletions MultiChannelDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ChannelDevice : public Device<HalType> {

typedef Device<HalType> DeviceType;

ChannelDevice (uint16_t addr) : Device<HalType>(addr,list0), list0(addr + this->keystore().size()), numChannels(ChannelCount), cfgChannel(0xff) {}
ChannelDevice (const DeviceInfo& i,uint16_t addr) : Device<HalType>(i,addr,list0), list0(addr + this->keystore().size()), numChannels(ChannelCount), cfgChannel(0xff) {}

virtual ~ChannelDevice () {}

Expand Down Expand Up @@ -474,7 +474,7 @@ class MultiChannelDevice : public ChannelDevice<HalType,ChannelType,ChannelCount

typedef ChannelDevice<HalType,ChannelType,ChannelCount,List0Type> DeviceType;

MultiChannelDevice (uint16_t addr) : ChannelDevice<HalType,ChannelType,ChannelCount,List0Type>(addr) {
MultiChannelDevice (const DeviceInfo& i,uint16_t addr) : ChannelDevice<HalType,ChannelType,ChannelCount,List0Type>(i,addr) {
for( uint8_t i=0; i<ChannelCount; ++i ) {
this->registerChannel(cdata[i], i+1);
}
Expand Down
21 changes: 11 additions & 10 deletions examples/HM-ES-TX-WM/HM-ES-TX-WM.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,13 @@
// define this to read the device id, serial and device type from bootloader section
// #define USE_OTA_BOOTLOADER

// define all device properties
#define DEVICE_ID HMID(0x90,0x12,0x34)
#define DEVICE_SERIAL "papa555555"
#define DEVICE_MODEL 0x00,0xde
#define DEVICE_FIRMWARE 0x11
#define DEVICE_TYPE DeviceType::PowerMeter
#define DEVICE_INFO 0x02,0x01,0x00

#define EI_NOTEXTERNAL
#include <EnableInterrupt.h>
#include <AskSinPP.h>
#include <LowPower.h>

#include <MultiChannelDevice.h>


// we use a Pro Mini
// Arduino pin for the LED
// D4 == PIN 4 on Pro Mini
Expand All @@ -42,6 +33,16 @@
// all library classes are placed in the namespace 'as'
using namespace as;

// define all device properties
const struct DeviceInfo PROGMEM devinfo = {
{0x90,0x12,0x34}, // Device ID
"papa555555", // Device Serial
{0x00,0xde}, // Device Model
0x11, // Firmware Version
as::DeviceType::PowerMeter, // Device Type
{0x02,0x01,0x00} // Info Bytes
};

/**
* Configure the used hardware
*/
Expand Down Expand Up @@ -371,7 +372,7 @@ public:
typedef MultiChannelDevice<HalType,MeterChannel,2,MeterList0> MeterType;

HalType hal;
MeterType sdev(0x20);
MeterType sdev(devinfo,0x20);

template <uint8_t pin, void (*isr)(), uint16_t millis>
class ISRWrapper : public Alarm {
Expand Down
22 changes: 11 additions & 11 deletions examples/HM-LC-Dim1PWM-CV/HM-LC-Dim1PWM-CV.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@
// define this to read the device id, serial and device type from bootloader section
// #define USE_OTA_BOOTLOADER

// define all device properties
#define DEVICE_ID HMID(0x11,0x12,0x22)
#define DEVICE_SERIAL "papa111222"
#define DEVICE_MODEL 0x00,0x67
#define DEVICE_FIRMWARE 0x25
#define DEVICE_TYPE DeviceType::Dimmer
#define DEVICE_INFO 0x03,0x01,0x00

#define EI_NOTEXTERNAL
#include <EnableInterrupt.h>
#include <AskSinPP.h>
Expand All @@ -30,16 +22,24 @@
// B0 == PIN 8 on Pro Mini
#define CONFIG_BUTTON_PIN 8


#define DIMMER_PIN 3

// number of available peers per channel
#define PEERS_PER_CHANNEL 4


// all library classes are placed in the namespace 'as'
using namespace as;

// define all device properties
const struct DeviceInfo PROGMEM devinfo = {
{0x11,0x12,0x22}, // Device ID
"papa111222", // Device Serial
{0x00,0x67}, // Device Model
0x25, // Firmware Version
as::DeviceType::Dimmer, // Device Type
{0x03,0x01,0x00} // Info Bytes
};

/**
* Configure the used hardware
*/
Expand All @@ -51,7 +51,7 @@ typedef DimmerChannel<HalType,PEERS_PER_CHANNEL> ChannelType;
typedef DimmerDevice<HalType,ChannelType,3> DimmerType;

HalType hal;
DimmerType sdev(0x20);
DimmerType sdev(devinfo,0x20);
ConfigToggleButton<DimmerType> cfgBtn(sdev);

void setup () {
Expand Down
20 changes: 11 additions & 9 deletions examples/HM-LC-SWX-SM/HM-LC-SWX-SM.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@
#define CFG_LOWACTIVE_ON 0x01
#define CFG_LOWACTIVE_OFF 0x00

// define all device properties
#define DEVICE_ID HMID(0x12,0x34,0x56)
#define DEVICE_SERIAL "papa000000"
#define DEVICE_MODEL HM_LC_SW4_SM
#define DEVICE_FIRMWARE 0x16
#define DEVICE_TYPE DeviceType::Switch
#define DEVICE_INFO 0x04,0x01,0x00
#define DEVICE_CONFIG CFG_LOWACTIVE_OFF


Expand All @@ -42,7 +35,6 @@
// B0 == PIN 8 on Pro Mini
#define CONFIG_BUTTON_PIN 8


// relay output pins compatible to the HM_Relay project
#define RELAY1_PIN 5
#define RELAY2_PIN 6
Expand All @@ -56,6 +48,16 @@
// all library classes are placed in the namespace 'as'
using namespace as;

// define all device properties
const struct DeviceInfo PROGMEM devinfo = {
{0x12,0x34,0x56}, // Device ID
"papa000000", // Device Serial
{HM_LC_SW4_SM}, // Device Model
0x16, // Firmware Version
as::DeviceType::Switch, // Device Type
{0x04,0x01,0x00} // Info Bytes
};

/**
* Configure the used hardware
*/
Expand All @@ -66,7 +68,7 @@ typedef AskSin<StatusLed<4>,NoBattery,Radio<RadioSPI,2> > Hal;
typedef MultiChannelDevice<Hal,SwitchChannel<Hal,PEERS_PER_CHANNEL>,4> SwitchType;

Hal hal;
SwitchType sdev(0x20);
SwitchType sdev(devinfo,0x20);
ConfigToggleButton<SwitchType> cfgBtn(sdev);

// map number of channel to pin
Expand Down
20 changes: 11 additions & 9 deletions examples/HM-RC-4/HM-RC-4.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@
// define this to read the device id, serial and device type from bootloader section
// #define USE_OTA_BOOTLOADER

// define all device properties
#define DEVICE_ID HMID(0x78,0x90,0x12)
#define DEVICE_SERIAL "papa333333"
#define DEVICE_MODEL 0x00,0x08
#define DEVICE_FIRMWARE 0x11
#define DEVICE_TYPE DeviceType::Remote
#define DEVICE_INFO 0x04,0x00,0x00

#define EI_NOTEXTERNAL
#include <EnableInterrupt.h>
#include <SPI.h> // after including SPI Library - we can use LibSPI class
Expand Down Expand Up @@ -46,6 +38,16 @@
// all library classes are placed in the namespace 'as'
using namespace as;

// define all device properties
const struct DeviceInfo PROGMEM devinfo = {
{0x78,0x90,0x12}, // Device ID
"papa333333", // Device Serial
{0x00,0x08}, // Device Model
0x11, // Firmware Version
as::DeviceType::Remote, // Device Type
{0x04,0x00,0x00} // Info Bytes
};

/**
* Configure the used hardware
*/
Expand Down Expand Up @@ -78,7 +80,7 @@ typedef RemoteChannel<Hal,PEERS_PER_CHANNEL> ChannelType;
typedef MultiChannelDevice<Hal,ChannelType,4> RemoteType;

Hal hal;
RemoteType sdev(0x20);
RemoteType sdev(devinfo,0x20);
ConfigButton<RemoteType> cfgBtn(sdev);

void setup () {
Expand Down
20 changes: 11 additions & 9 deletions examples/HM-RC-8/HM-RC-8.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@
// define this to read the device id, serial and device type from bootloader section
// #define USE_OTA_BOOTLOADER

// define all device properties
#define DEVICE_ID HMID(0x00,0xda,0x00)
#define DEVICE_SERIAL "HMRC00da00"
#define DEVICE_MODEL 0x00,0xda
#define DEVICE_FIRMWARE 0x01
#define DEVICE_TYPE DeviceType::Remote
#define DEVICE_INFO 0x08,0x00,0x00

#define EI_NOTEXTERNAL
#include <EnableInterrupt.h>
#include <AskSinPP.h>
Expand Down Expand Up @@ -48,6 +40,16 @@
// all library classes are placed in the namespace 'as'
using namespace as;

// define all device properties
const struct DeviceInfo PROGMEM devinfo = {
{0x00,0xda,0x00}, // Device ID
"HMRC00da00", // Device Serial
{0x00,0xda}, // Device Model
0x01, // Firmware Version
as::DeviceType::Remote, // Device Type
{0x08,0x00,0x00} // Info Bytes
};

/**
* Configure the used hardware
*/
Expand Down Expand Up @@ -80,7 +82,7 @@ typedef RemoteChannel<Hal,PEERS_PER_CHANNEL> ChannelType;
typedef MultiChannelDevice<Hal,ChannelType,8> RemoteType;

Hal hal;
RemoteType sdev(0x20);
RemoteType sdev(devinfo,0x20);
ConfigButton<RemoteType> cfgBtn(sdev);

void setup () {
Expand Down
Loading

0 comments on commit 9806caa

Please sign in to comment.