diff --git a/libraries/MySensors/MyGateway.cpp b/libraries/MySensors/MyGateway.cpp index f3c7936..9040bbc 100644 --- a/libraries/MySensors/MyGateway.cpp +++ b/libraries/MySensors/MyGateway.cpp @@ -181,16 +181,6 @@ void MyGateway::setInclusionMode(boolean newMode) { } } - -// Override normal validate to add error blink if crc check fails -uint8_t MyGateway::validate(MyMessage &message) { - uint8_t res = MySensor::validate(message); - if (res == VALIDATE_BAD_CRC) { - errBlink(1); - } - return res; -} - void MyGateway::processRadioMessage() { if (process()) { // A new message was received from one of the sensors diff --git a/libraries/MySensors/MyGateway.h b/libraries/MySensors/MyGateway.h index 8b520e5..185d933 100644 --- a/libraries/MySensors/MyGateway.h +++ b/libraries/MySensors/MyGateway.h @@ -70,7 +70,6 @@ class MyGateway : public MySensor void serial(const char *fmt, ... ); void serial(MyMessage &msg); - uint8_t validate(MyMessage &message); void interruptStartInclusion(); void checkButtonTriggeredInclusion(); void setInclusionMode(boolean newMode); diff --git a/libraries/MySensors/MyMessage.h b/libraries/MySensors/MyMessage.h index 08acf63..c401870 100644 --- a/libraries/MySensors/MyMessage.h +++ b/libraries/MySensors/MyMessage.h @@ -60,11 +60,6 @@ typedef enum { P_STRING, P_BYTE, P_INT16, P_UINT16, P_LONG32, P_ULONG32, P_CUSTOM } payload; -// Possible return values by validate() when doing crc check of received message. -typedef enum { - VALIDATE_OK, VALIDATE_BAD_CRC, VALIDATE_BAD_VERSION -} validationResult; - #define BIT(n) ( 1<<(n) ) @@ -148,12 +143,11 @@ public: uint8_t command_ack_payload; // 3 bit - Command type // 1 bit - Indicator that receiver should send an ack back. // 4 bit - Payload data type - uint8_t type; // 8 bit - Type varies depending on command - uint8_t sensor; // 8 bit - Id of sensor that this message concerns. uint8_t sender; // 8 bit - Id of sender node uint8_t last; // 8 bit - Id of last node this message passed uint8_t destination; // 8 bit - Id of destination node - uint8_t crc; // 8 bit - Message checksum + uint8_t type; // 8 bit - Type varies depending on command + uint8_t sensor; // 8 bit - Id of sensor that this message concerns. // Each message can transfer a payload. We add one extra byte for string // terminator \0 to be "printable" this is not transferred OTA diff --git a/libraries/MySensors/MySensor.cpp b/libraries/MySensors/MySensor.cpp index ad4e055..d999617 100644 --- a/libraries/MySensors/MySensor.cpp +++ b/libraries/MySensors/MySensor.cpp @@ -202,7 +202,6 @@ boolean MySensor::sendWrite(uint8_t next, MyMessage &message, bool broadcast) { uint8_t length = mGetLength(message); message.last = nc.nodeId; mSetVersion(message, PROTOCOL_VERSION); - message.crc = crc8Message(message); // Make sure radio has powered up RF24::powerUp(); RF24::stopListening(); @@ -262,16 +261,15 @@ boolean MySensor::process() { RF24::read(&msg, len); RF24::writeAckPayload(pipe,&pipe, 1 ); - uint8_t valid = validate(msg); - boolean ok = valid == VALIDATE_OK; - // Add termination, good for string messages. msg.data[mGetLength(msg)] = '\0'; - debug(PSTR("read: %d-%d-%d s=%d,c=%d,t=%d,pt=%d,l=%d,cr=%s:%s\n"), - msg.sender, msg.last, msg.destination, msg.sensor, mGetCommand(msg), msg.type, mGetPayloadType(msg), mGetLength(msg), valid==0?"ok":valid==1?"ec":"ev", msg.getString(convBuf)); + debug(PSTR("read: %d-%d-%d s=%d,c=%d,t=%d,pt=%d,l=%d:%s\n"), + msg.sender, msg.last, msg.destination, msg.sensor, mGetCommand(msg), msg.type, mGetPayloadType(msg), mGetLength(msg), msg.getString(convBuf)); - if (!ok) + if(!(mGetVersion(msg) == PROTOCOL_VERSION)) { + debug(PSTR("version mismatch")); return false; + } uint8_t command = mGetCommand(msg); uint8_t type = msg.type; @@ -405,10 +403,7 @@ boolean MySensor::process() { // Add this child to our "routing table" if it not already exist addChildRoute(sender, last); } - } - - return false; } @@ -418,61 +413,6 @@ MyMessage& MySensor::getLastMessage() { } -/* - * calculate CRC8 on MyMessage data taking care of data structure and protocol version - */ -uint8_t MySensor::crc8Message(MyMessage &message) { - uint8_t len = mGetLength(message); - uint8_t crc = 0x00; - uint8_t loop_count; - uint8_t bit_counter; - uint8_t data; - uint8_t feedback_bit; - uint8_t number_of_bytes_to_read = (uint8_t)sizeof(MyMessage); - - // Must set crc to a constant value. - message.crc = 0; - - // fill unused space by zeroes for string data only - if(len>=0 && len < sizeof(message.data)) { - memset(&message.data[len], 0, sizeof(message.data) - len); - } - - for (loop_count = 0; loop_count != number_of_bytes_to_read; loop_count++) - { - data = ((uint8_t*)&message)[loop_count]; - - bit_counter = 8; - do { - feedback_bit = (crc ^ data) & 0x01; - - if ( feedback_bit == 0x01 ) { - crc = crc ^ 0x18; //0X18 = X^8+X^5+X^4+X^0 - } - crc = (crc >> 1) & 0x7F; - if ( feedback_bit == 0x01 ) { - crc = crc | 0x80; - } - - data = data >> 1; - bit_counter--; - - } while (bit_counter > 0); - } - return crc; -} - - -uint8_t MySensor::validate(MyMessage &message) { - uint8_t oldCrc = message.crc; - uint8_t newCrc = crc8Message(message); - - if(!(mGetVersion(message) == PROTOCOL_VERSION)) return VALIDATE_BAD_VERSION; - - if(!(oldCrc == newCrc)) return VALIDATE_BAD_CRC; - return VALIDATE_OK; -} - void MySensor::saveState(uint8_t pos, uint8_t value) { if (loadState(pos) != value) { eeprom_write_byte((uint8_t*)(EEPROM_LOCAL_CONFIG_ADDRESS+pos), value); diff --git a/libraries/MySensors/MySensor.h b/libraries/MySensors/MySensor.h index b141837..2ff9cab 100644 --- a/libraries/MySensors/MySensor.h +++ b/libraries/MySensors/MySensor.h @@ -245,7 +245,6 @@ class MySensor : public RF24 void setupRadio(rf24_pa_dbm_e paLevel, uint8_t channel, rf24_datarate_e dataRate); boolean sendRoute(MyMessage &message); boolean sendWrite(uint8_t dest, MyMessage &message, bool broadcast=false); - uint8_t validate(MyMessage &message); private: #ifdef DEBUG