add broadcast pack

This commit is contained in:
DashyFox 2023-10-06 16:46:42 +03:00
parent f41348fb6b
commit a4105021ce
2 changed files with 12 additions and 7 deletions

View File

@ -1,5 +1,10 @@
#include "IR_Decoder.h"
#include "IR_Encoder.h"
#define checkAddr(h, l) (\
((uint16_t)((dataBuffer[h] << 8) | dataBuffer[l]) == addrSelf) || \
((uint16_t)((dataBuffer[h] << 8) | dataBuffer[l]) >= IR_Broadcast)\
)
IR_Decoder::IR_Decoder(uint16_t addr, IR_Encoder* encPair = nullptr) : addrSelf(addr), encoder(encPair) {
rawBuffer = new uint8_t[bufferRawSize] { 0 };
@ -36,7 +41,7 @@ void IR_Decoder::writeToBuffer(bool bit) {
const uint8_t dataSize = msgBytes + addrBytes;
isRawAvaliable = true;
isMsgAvaliable = crcCheck(dataSize);
if (isMsgAvaliable && (addrWaitingFrom == ((dataBuffer[1] << 8) | dataBuffer[2]))) {
if (isMsgAvaliable && checkAddr(1, 2)) {
gotAccept._set(dataBuffer, msgBytes + addrBytes + crcBytes, crcValue, errorCounter);
gotAccept._isAvaliable = true;
}
@ -48,7 +53,7 @@ void IR_Decoder::writeToBuffer(bool bit) {
const uint8_t dataSize = msgBytes + addrBytes + addrBytes;
isRawAvaliable = true;
isMsgAvaliable = (crcCheck(dataSize));
if (isMsgAvaliable && ((uint16_t)((dataBuffer[3] << 8) | dataBuffer[4]) == addrSelf)) {
if (isMsgAvaliable && checkAddr(3, 4)) {
gotRequest._isAvaliable = true;
gotRequest._set(dataBuffer, msgBytes + addrBytes + addrBytes + crcBytes, crcValue, errorCounter);
}
@ -62,7 +67,7 @@ void IR_Decoder::writeToBuffer(bool bit) {
const uint8_t dataSize = (rawBuffer[0] & IR_MASK_MSG_INFO);
isRawAvaliable = true;
isMsgAvaliable = crcCheck(dataSize);
if (isMsgAvaliable && ((uint16_t)((dataBuffer[3] << 8) | dataBuffer[4]) == addrSelf)
if (isMsgAvaliable && checkAddr(3, 4)
) {
gotData._isAvaliable = true;
gotData._set(dataBuffer, (dataSize)+crcBytes, crcValue, errorCounter);

View File

@ -2,10 +2,10 @@
#include <Arduino.h>
/*//////////////////////////////////////////////////////////////////////////////////////
Адресация с 1 до 65 499
65 500 ~ 65 535 - широковещательные пакеты (всем), возможно разделить на 35 типов
Адрес 0 запрещен и зарезервирован под NULL
*/// Адресация с 1 до 65 499
#define IR_Broadcast 6500 // 65 500 ~ 65 535 - широковещательные пакеты (всем), возможно разделить на 35 типов
/*
Адрес 0 запрещен и зарезервирован под NULL, либо тесты
IR_MSG_ACCEPT с адреса 0 воспринимается всеми устройствами