Skip to content

Commit

Permalink
try to fix receive problems
Browse files Browse the repository at this point in the history
  • Loading branch information
pa-pa committed Jul 6, 2017
1 parent aaa02b1 commit 4b8aa9f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 12 deletions.
2 changes: 1 addition & 1 deletion HMID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
#include "HMID.h"

namespace as {
HMID HMID::boardcast;
HMID HMID::broadcast;
}
2 changes: 1 addition & 1 deletion HMID.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class HMID {
DHEX(id2());
}

static HMID boardcast;
static HMID broadcast;
};

}
Expand Down
14 changes: 12 additions & 2 deletions Message.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "Debug.h"

//#define MaxDataLen 60 // maximum length of received bytes
#define MaxDataLen 25
#define MaxDataLen 50

namespace as {

Expand Down Expand Up @@ -51,7 +51,7 @@ class Message {
enum Flags {
WKUP = 0x01, // send initially to keep the device awake
WKMEUP = 0x02, // awake - hurry up to send messages
CFG = 0x04, // Device in Config mode
BCAST = 0x04, // Device in Config mode
BURST = 0x10, // set if burst is required by device
BIDI = 0x20, // response is expected
RPTED = 0x40, // repeated (repeater operation)
Expand Down Expand Up @@ -170,6 +170,12 @@ class Message {

void to(const HMID& hmid) {
toID = hmid;
if( hmid == HMID::broadcast ) {
flag |= BCAST;
}
else {
flag &= ~BCAST;
}
}

const HMID& to () const {
Expand Down Expand Up @@ -282,6 +288,10 @@ class Message {
flag |= WKMEUP;
}

void setBroadcast () {
flag |= BCAST;
}

bool isRepeated () const {
return (flag & RPTED) == RPTED;
}
Expand Down
6 changes: 3 additions & 3 deletions MultiChannelDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class ChannelDevice : public Device<HalType> {
void process(Message& msg) {
HMID devid;
this->getDeviceID(devid);
if( msg.to() == devid || (msg.to() == HMID::boardcast && this->isBoardcastMsg(msg))) {
if( msg.to() == devid || (msg.to() == HMID::broadcast && this->isBoardcastMsg(msg))) {
DPRINT(F("-> "));
msg.dump();
// ignore repeated messages
Expand Down Expand Up @@ -294,7 +294,7 @@ class ChannelDevice : public Device<HalType> {
cfgChannel = pm.channel();
cfgList = findList(cfgChannel,pm.peer(),pm.list());
// TODO setup alarm to disable after 2000ms
this->sendAck(msg,Message::CFG);
this->sendAck(msg);
}
else {
this->sendNack(msg);
Expand All @@ -321,7 +321,7 @@ class ChannelDevice : public Device<HalType> {
if( cfgChannel == pm.channel() && cfgList.valid() == true ) {
this->writeList(cfgList,pm.data(),pm.datasize());
}
this->sendAck(msg,Message::CFG);
this->sendAck(msg);
}
else {
this->sendNack(msg);
Expand Down
27 changes: 22 additions & 5 deletions Radio.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,18 @@ class Radio {
// add to system clock
sysclock.add(*this);
}

void setTimeout () {
// cancel possible old timeout
sysclock.cancel(*this);
// set to 100ms
set(millis2ticks(100));
// signal new wait cycle
wait = true;
// add to system clock
sysclock.add(*this);
}

virtual void trigger(__attribute__ ((unused)) AlarmClock& clock) {
// signal wait cycle over
wait = false;
Expand All @@ -363,7 +375,6 @@ class Radio {
volatile bool idle;
volatile bool sending;
Message buffer;
Message sbuffer;

public: //---------------------------------------------------------------------------------------------------------
void setIdle () {
Expand Down Expand Up @@ -520,10 +531,10 @@ class Radio {

// simple send the message
bool write (const Message& msg, uint8_t burst) {
memcpy(sbuffer.buffer(),msg.buffer(),msg.length());
sbuffer.length(msg.length());
sbuffer.encode();
return sndData(sbuffer.buffer(),sbuffer.length(),burst);
memcpy(buffer.buffer(),msg.buffer(),msg.length());
buffer.length(msg.length());
buffer.encode();
return sndData(buffer.buffer(),buffer.length(),burst);
}

bool readAck (const Message& msg) {
Expand Down Expand Up @@ -609,6 +620,12 @@ class Radio {
// DPRINTLN("CRC OK");
rxBytes = packetBytes;
}
else {
DPRINTLN("CRC Failed");
}
}
else {
DPRINT("Packet too big: ");DDECLN(packetBytes);
}
}
// DPRINT("-> ");
Expand Down

0 comments on commit 4b8aa9f

Please sign in to comment.