Skip to content

Commit

Permalink
return true if the message was handled
Browse files Browse the repository at this point in the history
  • Loading branch information
pa-pa committed Sep 1, 2017
1 parent 562d364 commit 8f79ea2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
6 changes: 3 additions & 3 deletions Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ class Device {
bool pollRadio () {
uint8_t num = radio().read(msg);
if( num > 0 ) {
process(msg);
return process(msg);
}
return num > 0;
return false;
}

uint8_t nextcount () {
Expand All @@ -172,7 +172,7 @@ class Device {

virtual void configChanged () {}

virtual void process(__attribute__((unused)) Message& msg) {}
virtual bool process(__attribute__((unused)) Message& msg) { return false; }

bool isBoardcastMsg(Message msg) {
return msg.isPairSerial();
Expand Down
18 changes: 8 additions & 10 deletions MultiChannelDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,24 +201,20 @@ class ChannelDevice : public Device<HalType> {
return true;
}

void process(Message& msg) {
bool process(Message& msg) {
HMID devid;
this->getDeviceID(devid);
if( msg.to() == devid || (msg.to() == HMID::broadcast && this->isBoardcastMsg(msg))) {
DPRINT(F("-> "));
msg.dump();
// ignore repeated messages
if( this->isRepeat(msg) == true ) {
if( msg.ackRequired() == true ) {
this->sendNack(msg);
}
return;
return false;
}
uint8_t mtype = msg.type();
uint8_t mcomm = msg.command();
uint8_t msubc = msg.subcommand();
if( mtype == AS_MESSAGE_CONFIG ) {
this->activity().stayAwake(millis2ticks(500));
// PAIR_SERIAL
if( msubc == AS_CONFIG_PAIR_SERIAL && this->isDeviceSerial(msg.data())==true ) {
this->led().set(LedStates::pairing);
Expand Down Expand Up @@ -331,7 +327,6 @@ class ChannelDevice : public Device<HalType> {
else {
this->sendNack(msg);
}
this->activity().stayAwake(millis2ticks(500));
}
else if( msubc == AS_CONFIG_SERIAL_REQ ) {
this->sendSerialInfo(msg.from(),msg.count());
Expand Down Expand Up @@ -384,7 +379,6 @@ class ChannelDevice : public Device<HalType> {
}
else if( mtype == AS_MESSAGE_HAVE_DATA ) {
DPRINTLN(F("HAVE DATA"));
this->activity().stayAwake(millis2ticks(500));
this->sendAck(msg);
}
else if (mtype == AS_MESSAGE_REMOTE_EVENT || mtype == AS_MESSAGE_SENSOR_EVENT) {
Expand Down Expand Up @@ -425,9 +419,13 @@ class ChannelDevice : public Device<HalType> {
}
}
else {
// DPRINT(F("ignore "));
// msg.dump();
DPRINT(F("ignore "));
msg.dump();
return false;
}
// we always stay awake after valid communication
this->activity().stayAwake(millis2ticks(500));
return true;
}

uint8_t channelForPeer (const Peer& p) {
Expand Down

0 comments on commit 8f79ea2

Please sign in to comment.