mirror of
https://github.com/Show-maket/IR-protocol.git
synced 2025-05-04 15:20:16 +00:00
add broadcast pack
This commit is contained in:
parent
f41348fb6b
commit
a4105021ce
@ -1,6 +1,11 @@
|
|||||||
#include "IR_Decoder.h"
|
#include "IR_Decoder.h"
|
||||||
#include "IR_Encoder.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) {
|
IR_Decoder::IR_Decoder(uint16_t addr, IR_Encoder* encPair = nullptr) : addrSelf(addr), encoder(encPair) {
|
||||||
rawBuffer = new uint8_t[bufferRawSize] { 0 };
|
rawBuffer = new uint8_t[bufferRawSize] { 0 };
|
||||||
prevRise = prevFall = prevPrevFall = prevPrevRise = 0;
|
prevRise = prevFall = prevPrevFall = prevPrevRise = 0;
|
||||||
@ -36,7 +41,7 @@ void IR_Decoder::writeToBuffer(bool bit) {
|
|||||||
const uint8_t dataSize = msgBytes + addrBytes;
|
const uint8_t dataSize = msgBytes + addrBytes;
|
||||||
isRawAvaliable = true;
|
isRawAvaliable = true;
|
||||||
isMsgAvaliable = crcCheck(dataSize);
|
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._set(dataBuffer, msgBytes + addrBytes + crcBytes, crcValue, errorCounter);
|
||||||
gotAccept._isAvaliable = true;
|
gotAccept._isAvaliable = true;
|
||||||
}
|
}
|
||||||
@ -48,7 +53,7 @@ void IR_Decoder::writeToBuffer(bool bit) {
|
|||||||
const uint8_t dataSize = msgBytes + addrBytes + addrBytes;
|
const uint8_t dataSize = msgBytes + addrBytes + addrBytes;
|
||||||
isRawAvaliable = true;
|
isRawAvaliable = true;
|
||||||
isMsgAvaliable = (crcCheck(dataSize));
|
isMsgAvaliable = (crcCheck(dataSize));
|
||||||
if (isMsgAvaliable && ((uint16_t)((dataBuffer[3] << 8) | dataBuffer[4]) == addrSelf)) {
|
if (isMsgAvaliable && checkAddr(3, 4)) {
|
||||||
gotRequest._isAvaliable = true;
|
gotRequest._isAvaliable = true;
|
||||||
gotRequest._set(dataBuffer, msgBytes + addrBytes + addrBytes + crcBytes, crcValue, errorCounter);
|
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);
|
const uint8_t dataSize = (rawBuffer[0] & IR_MASK_MSG_INFO);
|
||||||
isRawAvaliable = true;
|
isRawAvaliable = true;
|
||||||
isMsgAvaliable = crcCheck(dataSize);
|
isMsgAvaliable = crcCheck(dataSize);
|
||||||
if (isMsgAvaliable && ((uint16_t)((dataBuffer[3] << 8) | dataBuffer[4]) == addrSelf)
|
if (isMsgAvaliable && checkAddr(3, 4)
|
||||||
) {
|
) {
|
||||||
gotData._isAvaliable = true;
|
gotData._isAvaliable = true;
|
||||||
gotData._set(dataBuffer, (dataSize)+crcBytes, crcValue, errorCounter);
|
gotData._set(dataBuffer, (dataSize)+crcBytes, crcValue, errorCounter);
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
/*//////////////////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Адресация с 1 до 65 499
|
*/// Адресация с 1 до 65 499
|
||||||
65 500 ~ 65 535 - широковещательные пакеты (всем), возможно разделить на 35 типов
|
#define IR_Broadcast 6500 // 65 500 ~ 65 535 - широковещательные пакеты (всем), возможно разделить на 35 типов
|
||||||
Адрес 0 запрещен и зарезервирован под NULL
|
/*
|
||||||
|
Адрес 0 запрещен и зарезервирован под NULL, либо тесты
|
||||||
IR_MSG_ACCEPT с адреса 0 воспринимается всеми устройствами
|
IR_MSG_ACCEPT с адреса 0 воспринимается всеми устройствами
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user