1
0
Fork 0

turn pdu_flags into a POD struct

This commit is contained in:
Kevin Matz 2022-06-04 10:27:25 -04:00
parent a4978c514e
commit 00d825ccf8
3 changed files with 16 additions and 36 deletions

View File

@ -155,7 +155,7 @@ size_t Pdu::streamSize() const
void Pdu::iStream(Stream stream)
{
// get the flags
flags_.set(stream->peek());
flags_._raw = stream->peek();
// get the length
size_t length;
@ -231,7 +231,7 @@ void Pdu::oStream(Stream stream) const
if (flags.hasLength)
{
uint8_t flength[3];
flength[0] = ((length >> 16) & 0x0f) | (uint8_t)flags;
flength[0] = ((length >> 16) & 0x0f) | flags._raw;
flength[1] = length >> 8;
flength[2] = length;
stream->write(flength, sizeof(flength));
@ -239,7 +239,7 @@ void Pdu::oStream(Stream stream) const
else
{
uint8_t flength[2];
flength[0] = ((length >> 8) & 0x0f) | (uint8_t)flags;
flength[0] = ((length >> 8) & 0x0f) | flags._raw;
flength[1] = length;
stream->write(flength, sizeof(flength));
}
@ -277,7 +277,8 @@ void Pdu::oStream(Stream stream) const
*/
void Pdu::setVector (const uint32_t v)
{
vector_ = v; flags_.hasVector = true;
vector_ = v;
flags_.hasVector = true;
}
@ -322,19 +323,5 @@ void Pdu::setInherit(Message<Pdu> pdu)
inherit_ = pdu;
}
/**
* @brief pdu_flags::set
* @param val
*/
void pdu_flags::set(const uint8_t val)
{
hasLength = (val >> 7) & 0b1;
hasVector = (val >> 6) & 0b1;
hasHeader = (val >> 5) & 0b1;
hasData = (val >> 4) & 0b1;
};
} // PDU
} // ACN

View File

@ -118,22 +118,15 @@ struct Block
*/
struct pdu_flags
{
bool hasLength : 1; //!< true if pdu length is > 0x0fff
bool hasVector : 1; //!< false if Pdu inherits it's vector
bool hasHeader : 1; //!< false if Pdu inherits it's header
bool hasData : 1; //!< false if Pdu inherits it's data
pdu_flags() { set(0); }
void set(const uint8_t);
/**
* @brief operator uint8_t
*/
operator uint8_t() const {
uint8_t ret = 0;
if (hasLength) ret |= 0b10000000;
if (hasVector) ret |= 0b01000000;
if (hasHeader) ret |= 0b00100000;
if (hasData) ret |= 0b00010000;
return ret;
union {
uint8_t _raw = 0;
struct {
uint8_t lengthH : 4; //!< hightest 4 bytes of the PDU length, unused here
bool hasData : 1; //!< false if Pdu inherits it's data
bool hasHeader : 1; //!< false if Pdu inherits it's header
bool hasVector : 1; //!< false if Pdu inherits it's vector
bool hasLength : 1; //!< true if pdu length is > 0x0fff
};
};
};

View File

@ -42,7 +42,7 @@ public:
Pdu(size_t vector_size)
: ACN::PDU::Pdu(vector_size)
{
flags_.set(0xF0); // RDMnet PDU flags always 0xF
flags_._raw = 0xF0; // RDMnet PDU flags always 0xF
}
/**
@ -54,7 +54,7 @@ public:
virtual void iStream(ACN::PDU::Stream stream) override
{
ACN::PDU::Pdu::iStream(stream);
if ((uint8_t)flags_ != 0xf0)
if (flags_._raw != 0xf0)
stream_->setstate(std::ios_base::failbit);
};
};