more nuanced failure mode tracking
This commit is contained in:
parent
3882af3659
commit
f4c91891e0
|
@ -47,15 +47,17 @@ void Message::read(const std::vector<uint8_t> &buffer)
|
|||
/// Short Message - This field shall be incremented any time the message terminates (either
|
||||
/// due to a BREAK or timeout condition occurring) before a complete Destination UID has
|
||||
/// been received.
|
||||
if (buffer.size() < 9)
|
||||
short_message = true;
|
||||
short_message = !(buffer.size() >= 9);
|
||||
buffer_underrun = !(buffer.size() >= MESSAGE_MINIMUM_LENGTH+2);
|
||||
|
||||
if (short_message)
|
||||
return;
|
||||
|
||||
/// \cite RDM 6.2.1 START Code
|
||||
/// This field shall contain the defined RDM START Code (SC_RDM). Controllers
|
||||
/// and Responders shall always send SC_RDM in this slot, and any packet
|
||||
/// containing a value other than SC_RDM is outside the scope of this standard.
|
||||
if (buffer[0] != SC_RDM)
|
||||
incorrect_sc = true;
|
||||
incorrect_sc = !(buffer[0] == SC_RDM);
|
||||
|
||||
/// \cite RDM 6.2.2 Sub START Code
|
||||
/// This field shall contain the Sub-START Code within RDM that defines this
|
||||
|
@ -64,8 +66,7 @@ void Message::read(const std::vector<uint8_t> &buffer)
|
|||
/// identify the packet structure being used.
|
||||
/// Controllers shall always send SC_SUB_MESSAGE in this slot, and Responders
|
||||
/// shall ignore any packets containing other values.
|
||||
if (buffer[1] != SC_SUB_MESSAGE)
|
||||
incorrect_sub_sc = true;
|
||||
incorrect_sub_sc = !(buffer[1] == SC_SUB_MESSAGE);
|
||||
|
||||
/// \cite RDM 6.2.3 Message Length
|
||||
/// The Message Length value is defined as the number of slots in the RDM
|
||||
|
@ -73,20 +74,16 @@ void Message::read(const std::vector<uint8_t> &buffer)
|
|||
/// an 8-bit value.
|
||||
/// The Message Length field points to the Checksum High Slot.
|
||||
uint8_t length = buffer[2];
|
||||
if (length + 2 != buffer.size())
|
||||
length_mismatch = true;
|
||||
|
||||
if (buffer.size() < 26) // RDM 6.2 Message Format w/ 0 parameter data length
|
||||
{
|
||||
do_not_send = true;
|
||||
return;
|
||||
}
|
||||
length_mismatch = !(buffer.size() == length+2);
|
||||
|
||||
/// \cite RDM 6.2.4 Destination UID
|
||||
/// The Destination UID is the UID of the target device(s).
|
||||
destination.manufacturer = readType<uint16_t>(buffer, 3);
|
||||
destination.device = readType<uint32_t>(buffer, 5);
|
||||
|
||||
if (buffer_underrun)
|
||||
return;
|
||||
|
||||
/// \cite RDM 6.2.5 Source UID
|
||||
/// The Source UID is the UID of the device originating this packet.
|
||||
source.manufacturer = readType<uint16_t>(buffer, 9);
|
||||
|
@ -142,19 +139,19 @@ void Message::read(const std::vector<uint8_t> &buffer)
|
|||
/// Parameter Data area that it precedes. When this field is set to 0x00 it
|
||||
/// indicates that there is no Parameter Data following.
|
||||
uint8_t pdl = buffer[23];
|
||||
pdl_mismatch = !(buffer.size() == MESSAGE_MINIMUM_LENGTH+pdl+2);
|
||||
|
||||
/// \cite RDM 6.2.10.4 Parameter Data (PD)
|
||||
/// The Parameter Data is of variable length.
|
||||
if (pdl && buffer.size() >= 26 + pdl)
|
||||
for (int i = 0; i < pdl; i++)
|
||||
if (pdl && !pdl_mismatch)
|
||||
for (uint i = 0; i < pdl; i++)
|
||||
appendParameterData(buffer[24+i]);
|
||||
|
||||
/// \cite RDM 6.2.11 Checksum
|
||||
/// If the checksum field in the packet does not match the calculated checksum,
|
||||
/// then the packet shall be discarded and no response sent.
|
||||
auto chksum = readType<uint16_t>(buffer, buffer.size() - 2);
|
||||
if (chksum != checksum())
|
||||
checksum_fail = true;
|
||||
auto chksum = readType<uint16_t>(buffer, buffer[2]);
|
||||
checksum_fail = !(chksum == checksum());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "rdm.h"
|
||||
#include "uid.h"
|
||||
|
||||
namespace RDM {
|
||||
|
@ -72,11 +71,13 @@ struct Message
|
|||
union {
|
||||
uint8_t failure_mode;
|
||||
struct {
|
||||
bool short_message : 1; //!< undersized buffer
|
||||
bool short_message : 1; //!< buffer underrun before destination
|
||||
bool buffer_underrun : 1; //!< message below minimum length
|
||||
bool length_mismatch : 1; //!< message longer than adervertised
|
||||
bool checksum_fail : 1; //!< message did not match checksum
|
||||
bool incorrect_sc : 1; //!< invalid StartCode
|
||||
bool incorrect_sub_sc: 1; //!< invalid sub-StartCode
|
||||
bool pdl_mismatch : 1; //!< PDL length and message length disagree
|
||||
bool do_not_send : 1; //!< message does not require transmission
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue