reconstruct: restore brave-tape3 packet types stage

This commit is contained in:
2026-08-28 14:30:44 +03:00
parent 96ffb91b97
commit e25feb6824
2 changed files with 103 additions and 21 deletions

View File

@ -2,12 +2,49 @@
namespace PacketTypes
{
bool BasePack::checkAddress() { return true; };
void BasePack::set(IR_FOX::PackInfo *packInfo, uint16_t id)
uint8_t minimumPacketSize(uint8_t msgType)
{
switch (msgType)
{
case IR_MSG_DATA_ACCEPT:
case IR_MSG_DATA_NOACCEPT:
case IR_MSG_BACK_TO:
case IR_MSG_REQUEST:
return uint8_t(msgBytes + addrBytes + addrBytes + crcBytes);
case IR_MSG_BACK:
return uint8_t(msgBytes + addrBytes + crcBytes);
case IR_MSG_ACCEPT:
return uint8_t(msgBytes + addrBytes + 1U + crcBytes);
default:
return 0;
}
}
bool isTypedPacketSizeValid(uint8_t msgType, uint8_t packSize)
{
const uint8_t minimum = minimumPacketSize(msgType);
return minimum != 0 && packSize >= minimum;
}
bool BasePack::checkAddress() { return true; }
bool BasePack::set(IR_FOX::PackInfo *packInfo, uint16_t id, bool requireTypedSize)
{
isAvailable = false;
isRawAvailable = false;
this->packInfo = packInfo;
this->id = id;
if (packInfo == nullptr || packInfo->buffer == nullptr)
{
return false;
}
const uint8_t msgType = (packInfo->buffer[msgOffset] >> 5) & IR_MASK_MSG_TYPE;
if (requireTypedSize && !isTypedPacketSizeValid(msgType, packInfo->packSize))
{
return false;
}
if (checkAddress())
{
isAvailable = true;
@ -23,29 +60,65 @@ namespace PacketTypes
Serial.print(" NOT-OK ");
#endif
}
return isAvailable;
}
uint16_t BasePack::_getAddrFrom(BasePack *obj)
{
if (obj == nullptr || obj->packInfo == nullptr || obj->packInfo->buffer == nullptr ||
obj->packInfo->packSize < crcBytes ||
uint16_t(obj->addressFromOffset) + 1U >= uint16_t(obj->packInfo->packSize - crcBytes))
{
return 0;
}
return (obj->packInfo->buffer[obj->addressFromOffset] << 8) | obj->packInfo->buffer[obj->addressFromOffset + 1];
};
}
uint16_t BasePack::_getAddrTo(BasePack *obj)
{
if (obj == nullptr || obj->packInfo == nullptr || obj->packInfo->buffer == nullptr ||
obj->packInfo->packSize < crcBytes ||
uint16_t(obj->addressToOffset) + 1U >= uint16_t(obj->packInfo->packSize - crcBytes))
{
return 0;
}
return (obj->packInfo->buffer[obj->addressToOffset] << 8) | obj->packInfo->buffer[obj->addressToOffset + 1];
};
}
uint8_t BasePack::_getDataSize(BasePack *obj)
{
return obj->packInfo->packSize - crcBytes - obj->DataOffset;
};
if (obj == nullptr || obj->packInfo == nullptr || obj->packInfo->buffer == nullptr)
{
return 0;
}
const uint16_t frameOverhead = uint16_t(crcBytes) + uint16_t(obj->DataOffset);
if (uint16_t(obj->packInfo->packSize) <= frameOverhead)
{
return 0;
}
return uint8_t(uint16_t(obj->packInfo->packSize) - frameOverhead);
}
uint8_t *BasePack::_getDataPrt(BasePack *obj)
{
if (obj == nullptr || obj->packInfo == nullptr || obj->packInfo->buffer == nullptr ||
obj->packInfo->packSize < crcBytes)
{
return nullptr;
}
const uint16_t dataEnd = uint16_t(obj->packInfo->packSize) - uint16_t(crcBytes);
if (uint16_t(obj->DataOffset) > dataEnd)
{
return nullptr;
}
return obj->packInfo->buffer + obj->DataOffset;
};
}
uint8_t BasePack::_getDataRawSize(BasePack *obj)
{
if (obj == nullptr || obj->packInfo == nullptr)
{
return 0;
}
return obj->packInfo->packSize;
};
}
bool BasePack::available()
{
@ -59,7 +132,7 @@ namespace PacketTypes
{
return false;
}
};
}
bool BasePack::availableRaw()
{
if (isRawAvailable)
@ -71,7 +144,7 @@ namespace PacketTypes
{
return false;
}
};
}
bool Data::checkAddress()
{
@ -104,4 +177,4 @@ namespace PacketTypes
IR_FOX::checkAddressRuleApply(getAddrTo(), this->id, ret);
return ret;
}
}
}