Browse Source

No raw queueing to avoid data section overflow

i18n
Rene Hexel 7 years ago
committed by Rene Hexel
parent
commit
3a3a06dc4d
1 changed files with 11 additions and 41 deletions
  1. +11
    -41
      code/espurna/rfbridge.ino

+ 11
- 41
code/espurna/rfbridge.ino View File

@ -16,12 +16,7 @@ Copyright (C) 2017 by Xose Pérez <xose dot perez at gmail dot com>
// -----------------------------------------------------------------------------
#define RF_MESSAGE_SIZE 9
#ifndef RF_RAW_SUPPORT
# define RF_MAX_MESSAGE_SIZE RF_MESSAGE_SIZE
#else
# undef RF_MAX_MESSAGE_SIZE
# define RF_MAX_MESSAGE_SIZE 16 // (112+4)
#endif
#define RF_MAX_MESSAGE_SIZE (112+4)
#define RF_CODE_START 0xAA
#define RF_CODE_ACK 0xA0
#define RF_CODE_LEARN 0xA1
@ -49,11 +44,8 @@ bool _learnStatus = true;
bool _rfbin = false;
typedef struct {
byte code[RF_MAX_MESSAGE_SIZE];
byte code[RF_MESSAGE_SIZE];
byte times;
#ifdef RF_RAW_SUPPORT
byte length;
#endif
} rfb_message_t;
std::vector<rfb_message_t> _rfb_message_queue;
Ticker _rfbTicker;
@ -136,15 +128,6 @@ void _rfbSend() {
_rfb_message_queue.erase(_rfb_message_queue.begin());
// Send the message
#ifdef RF_RAW_SUPPORT
bool sendRaw = message.times < 0;
int length = sendRaw ? -message.times : message.times;
if (sendRaw) {
_rfbSendRaw(message.code, message.length);
Serial.flush();
}
else
#endif
_rfbSend(message.code);
// If it should be further sent, push it to the stack again
@ -152,12 +135,6 @@ void _rfbSend() {
message.times = message.times - 1;
_rfb_message_queue.push_back(message);
}
#ifdef RF_RAW_SUPPORT
else if (message.times < -1) {
message.times = message.times + 1;
_rfb_message_queue.push_back(message);
}
#endif
// if there are still messages in the queue...
if (_rfb_message_queue.size() > 0) {
@ -175,26 +152,18 @@ void _rfbSend(byte * code, int times) {
rfb_message_t message;
memcpy(message.code, code, RF_MESSAGE_SIZE);
message.times = times;
#ifdef RF_RAW_SUPPORT
message.length = RF_MESSAGE_SIZE;
#endif
_rfb_message_queue.push_back(message);
_rfbSend();
}
#ifdef RF_RAW_SUPPORT
void _rfbSendRawRepeated(byte *code, int length, int times) {
char buffer[RF_MESSAGE_SIZE*2];
void _rfbSendRawOnce(byte *code, int length) {
char buffer[length*2];
_rfbToChar(code, buffer);
DEBUG_MSG_P(PSTR("[RFBRIDGE] Sending raw MESSAGE '%s' %d time(s)\n"), buffer, times);
DEBUG_MSG_P(PSTR("[RFBRIDGE] Sending raw MESSAGE '%s'\n"), buffer);
rfb_message_t message;
memcpy(message.code, code, length);
message.times = -times;
message.length = length;
_rfb_message_queue.push_back(message);
_rfbSend();
_rfbSendRaw(code, length);
}
#endif
@ -386,12 +355,13 @@ void _rfbMqttCallback(unsigned int type, const char * topic, const char * payloa
bool isRFOut = t.equals(MQTT_TOPIC_RFOUT);
bool isRFRaw = !isRFOut && t.equals(MQTT_TOPIC_RFRAW);
if (isRFOut || isRFRaw) {
byte message[RF_MAX_MESSAGE_SIZE];
#else
if (t.equals(MQTT_TOPIC_RFOUT)) {
byte message[RF_MESSAGE_SIZE];
#endif
// The payload may be a code in HEX format ([0-9A-Z]{18}) or
// the code comma the number of times to transmit it.
byte message[RF_MAX_MESSAGE_SIZE];
char * tok = strtok((char *) payload, ",");
// Check if a switch is linked to that message
@ -406,16 +376,16 @@ void _rfbMqttCallback(unsigned int type, const char * topic, const char * payloa
return;
}
const char *tok2 = strtok(NULL, ",");
byte times = (t != NULL) ? atoi(tok2) : 1;
#ifdef RF_RAW_SUPPORT
int len = _rfbToArray(tok, message, 0);
if (len > 0 && (isRFRaw || len != RF_MESSAGE_SIZE)) {
_rfbSendRawRepeated(message, len, times);
_rfbSendRawOnce(message, len);
} else {
#else
if (_rfbToArray(tok, message)) {
#endif
tok = strtok(NULL, ",");
byte times = (tok != NULL) ? atoi(tok) : 1;
_rfbSend(message, times);
}


Loading…
Cancel
Save