1
0
Fork 0

BCD encode/decode the serial number

This commit is contained in:
Kevin Matz 2023-04-09 19:26:41 -04:00
parent c89f55c107
commit 55317f7513
1 changed files with 13 additions and 3 deletions

View File

@ -23,6 +23,8 @@
*/
#include "dmx.h"
#include <limits.h>
#include <math.h>
#include "pro.h"
namespace ENTTEC::Pro {
@ -158,7 +160,7 @@ void MsgOutputOnlySendDMX::oStream(std::shared_ptr<bufferstream> stream) const
{
stream->write(data.data(), std::min(data.size(), DMX::E111_LAST_SLOT + 1));
for (size_t i = data.size(); i <= DMX_LAST_SLOT_MIN; i++)
*stream << (uint8_t) 0;
*stream << (uint8_t)0;
};
@ -212,13 +214,21 @@ void MsgRecievedDMXChanged::oStream(std::shared_ptr<bufferstream> stream) const
void MsgGetWidgetSerialReply::iStream(std::shared_ptr<bufferstream> stream)
{
*stream >> serial;
const uint8_t NIBBLE_BIT = CHAR_BIT / 2;
auto bcd = stream->readType<uint32_t>();
serial = bcd & 0xf;
for(size_t i = 1; i * NIBBLE_BIT < sizeof(bcd) * CHAR_BIT; i++)
serial += ((bcd >> (i * NIBBLE_BIT)) & 0xf) * pow(10,i);
};
void MsgGetWidgetSerialReply::oStream(std::shared_ptr<bufferstream> stream) const
{
*stream << serial;
const uint8_t NIBBLE_BIT = CHAR_BIT / 2;
uint32_t bcd = serial & 0xf;
for(size_t i = 1; i * NIBBLE_BIT < sizeof(bcd) * CHAR_BIT; i++)
bcd += ((uint32_t)(serial / pow(10,i)) & 0xf) << (i * NIBBLE_BIT);
*stream << bcd;
};