Skip to content

Commit

Permalink
reorganize library configuration - use more templates
Browse files Browse the repository at this point in the history
  • Loading branch information
pa-pa committed Mar 5, 2017
1 parent d9ba555 commit bb0ae9a
Show file tree
Hide file tree
Showing 22 changed files with 583 additions and 726 deletions.
4 changes: 2 additions & 2 deletions Activity.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Idle {
}

template <class Hal>
static void powerSave (Hal& hal) {
static void powerSave (__attribute__((unused)) Hal& hal) {
LowPower.idle(SLEEP_FOREVER,ADC_OFF,TIMER2_OFF,TIMER1_ON,TIMER0_OFF,SPI_ON,USART0_ON,TWI_OFF);
}

Expand Down Expand Up @@ -90,7 +90,7 @@ class Activity : public Alarm {

virtual ~Activity () {}

virtual void trigger (AlarmClock& clock) {
virtual void trigger (__attribute__((unused)) AlarmClock& clock) {
awake = false;
}

Expand Down
13 changes: 10 additions & 3 deletions AskSinPP.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
#ifndef __ASKSINPP_h__
#define __ASKSINPP_h__

#define ASKSIN_PLUS_PLUS_VERSION "1.0.0"
#define ASKSIN_PLUS_PLUS_VERSION "1.0.1"

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

// configure EnableInterrupt library
// #define EI_NOTEXTERNAL

#include <Debug.h>
#include <Activity.h>
Expand Down Expand Up @@ -42,6 +40,15 @@ class AskSin {
}
}

static uint16_t crc16 (uint16_t crc,uint8_t d) {
crc ^= d;
for( uint8_t i = 8; i != 0; --i ) {
crc = (crc >> 1) ^ ((crc & 1) ? 0xA001 : 0 );
}
return crc;
}


};

}
Expand Down
8 changes: 4 additions & 4 deletions Button.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ class Button: public Alarm {
};

protected:
uint8_t stat;
uint16_t longpresstime;
uint8_t stat : 3;
uint8_t pinstate : 1;
uint8_t pin;
uint8_t pinstate;
uint16_t longpresstime;

public:
Button() :
Alarm(0), stat(none), longpresstime(millis2ticks(400)), pin(0), pinstate(HIGH) {
Alarm(0), stat(none), pinstate(HIGH), pin(0), longpresstime(millis2ticks(400)) {
}
virtual ~Button() {
}
Expand Down
14 changes: 7 additions & 7 deletions Channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#define __CHANNEL_H__

#include "Peer.h"
#include "EEProm.h"
#include "Storage.h"

namespace as {

Expand Down Expand Up @@ -67,14 +67,14 @@ class Channel {
Peer result;
uint16_t paddr = peerAddress(idx);
if( paddr != 0 ) {
eeprom.getData(paddr,&result);
storage.getData(paddr,&result);
}
return result;
}


bool peer (uint8_t idx,const Peer& p) const {
return eeprom.setData(peerAddress(idx),p);
return storage.setData(peerAddress(idx),p);
}

uint8_t findpeer () const {
Expand All @@ -96,7 +96,7 @@ class Channel {
}

void firstinit () {
eeprom.clearData(address(),size());
storage.clearData(address(),size());
List1Type cl = getList1();
cl.defaults();
}
Expand Down Expand Up @@ -156,15 +156,15 @@ class Channel {
return List4Type::size() > 0;
}

bool process (const ActionSetMsg& msg) {
bool process (__attribute__((unused)) const ActionSetMsg& msg) {
return false;
}

bool process (const RemoteEventMsg& msg) {
bool process (__attribute__((unused)) const RemoteEventMsg& msg) {
return false;
}

bool process (const SensorEventMsg& msg) {
bool process (__attribute__((unused)) const SensorEventMsg& msg) {
return false;
}

Expand Down
24 changes: 12 additions & 12 deletions ChannelList.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#ifndef __CHANNELLIST_H__
#define __CHANNELLIST_H__

#include "EEProm.h"
#include "Storage.h"
#include "HMID.h"

namespace as {
Expand All @@ -22,15 +22,15 @@ class BaseList {
bool valid () const { return addr != 0; }

uint8_t getByte (uint8_t offset) const {
return eeprom.getByte(addr + offset);
return storage.getByte(addr + offset);
}

uint8_t getByte (uint8_t offset, uint8_t mask, uint8_t shift) const {
return (getByte(offset) & mask) >> shift;
}

bool setByte (uint8_t offset, uint8_t data) const {
return eeprom.setByte(addr + offset, data);
return storage.setByte(addr + offset, data);
}

bool setByte (uint8_t offset, uint8_t data, uint8_t mask, uint8_t shift) const {
Expand All @@ -40,22 +40,22 @@ class BaseList {
}

bool isBitSet (uint8_t offset, uint8_t bit) const {
return (eeprom.getByte(addr + offset) & bit) == bit;
return (storage.getByte(addr + offset) & bit) == bit;
}

bool setBit (uint8_t offset, uint8_t bit, bool value) const {
if( value == true ) {
return eeprom.setBits(addr + offset, bit);
return storage.setBits(addr + offset, bit);
}
return eeprom.clearBits(addr + offset, bit);
return storage.clearBits(addr + offset, bit);
}

bool setData (uint8_t offset,uint8_t* buf,uint16_t size) const {
return eeprom.setData(addr + offset,buf,size);
return storage.setData(addr + offset,buf,size);
}

bool getData (uint8_t offset,uint8_t* buf,uint16_t size) const {
return eeprom.getData(addr + offset,buf,size);
return storage.getData(addr + offset,buf,size);
}
};

Expand Down Expand Up @@ -100,7 +100,7 @@ class GenericList : public BaseList {
void dump () const {
DHEX(address());
DPRINT(F(" - "));
eeprom.dump(address(),getSize());
storage.dump(address(),getSize());
}


Expand Down Expand Up @@ -146,7 +146,7 @@ class ChannelList : public BaseList {
void dump () const {
DHEX(address());
DPRINT(F(" - "));
eeprom.dump(address(),size());
storage.dump(address(),size());
}

operator GenericList () const {
Expand All @@ -157,8 +157,8 @@ class ChannelList : public BaseList {

class EmptyListData {
public:
static uint8_t getOffset(uint8_t reg) { return 0xff; }
static uint8_t getRegister(uint8_t reg) { return 0xff; }
static uint8_t getOffset(__attribute__((unused)) uint8_t reg) { return 0xff; }
static uint8_t getRegister(__attribute__((unused)) uint8_t reg) { return 0xff; }
};

class EmptyList : public ChannelList<EmptyListData> {
Expand Down
5 changes: 3 additions & 2 deletions Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class Device {
KeyStore& keystore () { return this->kstore; }
Activity& activity () { return hal->activity; }

Message& message () { return msg; }

bool isRepeat(const Message& m) {
if( m.isRepeated() && lastdev == m.from() && lastmsg == m.count() ) {
Expand All @@ -109,7 +110,7 @@ class Device {
model[1] = m2;
}

const uint8_t* const getModel () const {
const uint8_t* getModel () const {
return model;
}

Expand Down Expand Up @@ -213,7 +214,7 @@ class Device {
return ++msgcount;
}

virtual void process(Message& msg) {}
virtual void process(__attribute__((unused)) Message& msg) {}

bool isBoardcastMsg(Message msg) {
return msg.isPairSerial();
Expand Down
4 changes: 2 additions & 2 deletions Message.h
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ class InfoPeerListMsg : public Message {

class DeviceInfoMsg : public Message {
public:
void init (const HMID& to,uint8_t count) {
void init (__attribute__((unused)) const HMID& to,uint8_t count) {
Message::init(0x1a,count,0x00,0x00,0x00,0x00);
}
uint8_t* data() { return Message::data()-2; }
Expand All @@ -559,7 +559,7 @@ class DeviceInfoMsg : public Message {

class SerialInfoMsg : public Message {
public:
void init (const HMID& to,uint8_t count) {
void init (__attribute__((unused)) const HMID& to,uint8_t count) {
Message::init(0x14,count,0x10,0x00,0x00,0x00);
}
uint8_t* data() { return Message::data()-4; }
Expand Down
14 changes: 7 additions & 7 deletions MultiChannelDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,27 @@ class MultiChannelDevice : public Device<HalType> {
uint16_t checksum () {
uint16_t crc = 0;
// size of keystore data
crc = EEProm::crc16(crc,DeviceType::keystore().size());
crc = HalType::crc16(crc,DeviceType::keystore().size());
// add register of list0
for( uint8_t i=0; i<list0.size(); ++i ) {
crc = EEProm::crc16(crc,list0.getRegister(i));
crc = HalType::crc16(crc,list0.getRegister(i));
}
// add number of channels
crc = EEProm::crc16(crc,ChannelCount);
crc = HalType::crc16(crc,ChannelCount);
// add register list 1
for( uint8_t i=0; i<ChannelType::List1::size(); ++i ) {
crc = EEProm::crc16(crc,ChannelType::List1::getRegister(i));
crc = HalType::crc16(crc,ChannelType::List1::getRegister(i));
}
// add register list 3
for( uint8_t i=0; i<ChannelType::List3::size(); ++i ) {
crc = EEProm::crc16(crc,ChannelType::List3::getRegister(i));
crc = HalType::crc16(crc,ChannelType::List3::getRegister(i));
}
// add register list 4
for( uint8_t i=0; i<ChannelType::List4::size(); ++i ) {
crc = EEProm::crc16(crc,ChannelType::List4::getRegister(i));
crc = HalType::crc16(crc,ChannelType::List4::getRegister(i));
}
// add number of peers
crc = EEProm::crc16(crc,channel(1).peers());
crc = HalType::crc16(crc,channel(1).peers());
return crc;
}

Expand Down
3 changes: 1 addition & 2 deletions Peer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ class Peer : public HMID {
Peer (const HMID& id,uint8_t ch) : HMID(id), chan(ch) {}
Peer (uint8_t i1, uint8_t i2, uint8_t i3, uint8_t ch) : HMID(i1,i2,i3), chan(ch) {}
Peer (uint8_t* ptr) : HMID(*ptr,*(ptr+1),*(ptr+2)), chan(*(ptr+4)) {}
Peer (const Peer& other) {
*(HMID*)this = (const HMID&)other;
Peer (const Peer& other) : HMID(other) {
chan = other.chan;
}

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

#Please use V1 Branch for your devices. The master branch is currently not stable#

#AskSin++#

C++ implementation of the AskSin protocol
Expand All @@ -9,10 +11,9 @@ C++ implementation of the AskSin protocol

Required Arduino libraries:
- TimerOne - https://github.com/PaulStoffregen/TimerOne
- PinChangeInt - https://github.com/GreyGnome/PinChangeInt
- EnableInterrupt - https://github.com/GreyGnome/EnableInterrupt
- Low-Power - https://github.com/rocketscream/Low-Power.git


## Enable AES Support

To enable the AES signature support **USE_AES** needs to be
Expand Down
Loading

0 comments on commit bb0ae9a

Please sign in to comment.