Skip to content

Commit

Permalink
lazy config handling added
Browse files Browse the repository at this point in the history
  • Loading branch information
pa-pa committed Jan 24, 2017
1 parent 6b376fc commit 9cce2b8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
10 changes: 8 additions & 2 deletions Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,14 @@ class Device {
}


void sendAck (Message& msg) {
msg.ack().init();
void sendAck (Message& msg,uint8_t flag=0x00) {
msg.ack().init(flag);
kstore.addAuth(msg);
send(msg,msg.from());
}

void sendAck2 (Message& msg,uint8_t flag=0x00) {
msg.ack2().init(flag);
kstore.addAuth(msg);
send(msg,msg.from());
}
Expand Down
21 changes: 17 additions & 4 deletions Message.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class ConfigEndMsg;
class ConfigWriteIndexMsg;

class AckMsg;
class Ack2Msg;
class AckStatusMsg;
class NackMsg;
class AckAesMsg;
Expand Down Expand Up @@ -244,6 +245,10 @@ class Message {
flag |= RPTEN;
}

bool isWakeMeUp () const {
return (flag & WKMEUP) == WKMEUP;
}

bool isRepeated () const {
return (flag & RPTED) == RPTED;
}
Expand Down Expand Up @@ -301,6 +306,7 @@ class Message {

// cast to write message types
AckMsg& ack () { return *(AckMsg*)this; }
Ack2Msg& ack2 () { return *(Ack2Msg*)this; }
AckStatusMsg& ackStatus () { return *(AckStatusMsg*)this; }
NackMsg& nack () { return *(NackMsg*)this; }
AckAesMsg& ackAes () { return *(AckAesMsg*)this; }
Expand Down Expand Up @@ -408,8 +414,15 @@ class ActionSetMsg : public ActionMsg {

class AckMsg : public Message {
public:
void init() {
initWithCount(0x0a,AS_MESSAGE_RESPONSE,0x00,AS_RESPONSE_ACK);
void init(uint8_t flags=0x00) {
initWithCount(0x0a,AS_MESSAGE_RESPONSE,flags,AS_RESPONSE_ACK);
}
};

class Ack2Msg : public Message {
public:
void init(uint8_t flags=0x00) {
initWithCount(0x0a,AS_MESSAGE_RESPONSE,flags,AS_RESPONSE_ACK2);
}
};

Expand Down Expand Up @@ -487,7 +500,7 @@ class InfoActuatorStatusMsg : public Message {
public:
template <class ChannelType>
void init (uint8_t count,const ChannelType& ch,uint8_t rssi) {
Message::init(0x0e,count,0x10,Message::BIDI,0x06,ch.number());
Message::init(0x0e,count,0x10,BIDI,0x06,ch.number());
pload[0] = ch.status();
pload[1] = ch.flags();
pload[2] = rssi;
Expand All @@ -497,7 +510,7 @@ class InfoActuatorStatusMsg : public Message {
class InfoParamResponsePairsMsg : public Message {
public:
void init (uint8_t count) {
initWithCount(0x0b-1+(8*2),0x10,Message::BIDI,0x02);
initWithCount(0x0b-1+(8*2),0x10,BIDI,0x02);
cnt = count;
}
uint8_t* data() { return Message::data()-1; }
Expand Down
11 changes: 11 additions & 0 deletions MultiChannelDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ class MultiChannelDevice : public Device {
cfgList = findList(cfgChannel,pm.peer(),pm.list());
// TODO setup alarm to disable after 2000ms
sendAck(msg);
activity.stayAwake(seconds2ticks(2));
}
}
// CONFIG_END
Expand All @@ -245,6 +246,7 @@ class MultiChannelDevice : public Device {
cfgChannel = 0xff;
// TODO cancel alarm
sendAck(msg);
activity.stayAwake(millis2ticks(500));
}
else if( msubc == AS_CONFIG_WRITE_INDEX ) {
const ConfigWriteIndexMsg& pm = msg.configWriteIndex();
Expand All @@ -261,6 +263,7 @@ class MultiChannelDevice : public Device {
}
sendAck(msg);
}
activity.stayAwake(millis2ticks(500));
}
// default - send Nack if answer is requested
else {
Expand Down Expand Up @@ -312,6 +315,11 @@ class MultiChannelDevice : public Device {
else sendNack(msg);
}
}
else if( mtype == AS_MESSAGE_HAVE_DATA ) {
DPRINTLN(F("HAVE DATA"));
activity.stayAwake(millis2ticks(500));
sendAck(msg);
}
else if (mtype == AS_MESSAGE_REMOTE_EVENT || mtype == AS_MESSAGE_SENSOR_EVENT) {
const RemoteEventMsg& pm = msg.remoteEvent();
uint8_t cdx = channelForPeer(pm.peer());
Expand Down Expand Up @@ -390,6 +398,9 @@ class MultiChannelDevice : public Device {
// we send only to peers if there is no config message pending
if( cfgChannel != 0xff ) {
Device::sendPeerEvent(msg,ch);
if( msg.isWakeMeUp() == true ) {
activity.stayAwake(millis2ticks(500));
}
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion examples/HM-SEC-MDIR/HM-SEC-MDIR.ino
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ BatterySensor battery;
class MotionEventMsg : public Message {
public:
void init(uint8_t msgcnt,uint8_t ch,uint8_t counter,uint8_t brightness,uint8_t next) {
Message::init(0xd,msgcnt,0x41,Message::BIDI,ch & 0x3f,counter);
Message::init(0xd,msgcnt,0x41,Message::BIDI|Message::WKMEUP,ch & 0x3f,counter);
pload[0] = brightness;
pload[1] = (next+4) << 4;
}
Expand Down

0 comments on commit 9cce2b8

Please sign in to comment.