mirror of
https://github.com/Show-maket/IR-protocol.git
synced 2025-05-04 07:10:16 +00:00
add listen and fix
This commit is contained in:
parent
63e8328755
commit
791d90ee00
@ -35,7 +35,6 @@ void IR_Decoder::writeToBuffer(bool bit) {
|
||||
//const auto testval = bufferBitSizeMax;
|
||||
if ((bufBitPos >= (8 * msgBytes) - syncBits) && !isMsgAvaliable) {
|
||||
switch ((rawBuffer[0] >> 5) & IR_MASK_MSG_TYPE) {
|
||||
|
||||
case IR_MSG_ACCEPT:
|
||||
if (bufBitPos >= ((msgBytes + addrBytes + crcBytes) * (8 + 3)) - syncBits) {
|
||||
const uint8_t dataSize = msgBytes + addrBytes;
|
||||
@ -67,11 +66,9 @@ void IR_Decoder::writeToBuffer(bool bit) {
|
||||
const uint8_t dataSize = (rawBuffer[0] & IR_MASK_MSG_INFO);
|
||||
isRawAvaliable = true;
|
||||
isMsgAvaliable = crcCheck(dataSize);
|
||||
if (isMsgAvaliable && checkAddr(3, 4)
|
||||
) {
|
||||
if (isMsgAvaliable && checkAddr(3, 4)) {
|
||||
gotData._isAvaliable = true;
|
||||
gotData._set(dataBuffer, (dataSize)+crcBytes, crcValue, errorCounter, riseSyncTime);
|
||||
|
||||
} else {
|
||||
gotRawData._isAvaliable = true;
|
||||
gotRawData._set(dataBuffer, (dataSize)+crcBytes, crcValue, errorCounter, riseSyncTime);
|
||||
@ -171,6 +168,10 @@ uint16_t IR_Decoder::ceil_div(uint16_t val, uint16_t divider) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
void IR_Decoder::listen(){
|
||||
if(isRecive && micros()-prevRise > IR_timeout*2) {isRecive = false;}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////// isr ///////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -180,6 +181,7 @@ void IR_Decoder::isr() { // в прерывании вызываем isr()
|
||||
if (isPairSending) return;
|
||||
|
||||
if (micros() - prevRise > IR_timeout) { // первый
|
||||
isRecive = true;
|
||||
isPreamb = true;
|
||||
frontCounter = preambFronts - 1U;
|
||||
errorCounter = 0;
|
||||
|
28
IR_Decoder.h
28
IR_Decoder.h
@ -36,6 +36,8 @@ public:
|
||||
|
||||
// @return Буффер переполнился
|
||||
bool isOverflow() { return isBufferOverflow; };
|
||||
bool isReciving() { return isRecive; };
|
||||
void listen();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -43,15 +45,15 @@ public:
|
||||
friend IR_Decoder;
|
||||
protected:
|
||||
bool _isAvaliable = false;
|
||||
uint8_t _msgType;
|
||||
uint8_t _msgType = 0;
|
||||
uint16_t _addrFrom = 0;
|
||||
uint16_t _addrTo = 0;
|
||||
uint8_t* _data = nullptr;
|
||||
uint8_t _dataRawSize = 0;
|
||||
uint16_t _crcPackVal;
|
||||
uint16_t _crcCalcVal;
|
||||
uint16_t _errCount;
|
||||
uint16_t _bitPeriod;
|
||||
uint16_t _crcPackVal = 0;
|
||||
uint16_t _crcCalcVal = 0;
|
||||
uint16_t _errCount = 0;
|
||||
uint16_t _bitPeriod = 0;
|
||||
|
||||
void _set(uint8_t* ptr, uint8_t len, uint16_t crc, uint16_t err, uint16_t rTime) {
|
||||
_crcCalcVal = crc;
|
||||
@ -65,6 +67,7 @@ public:
|
||||
ini();
|
||||
_isAvaliable = true;
|
||||
}
|
||||
|
||||
private:
|
||||
virtual void ini();
|
||||
|
||||
@ -97,6 +100,7 @@ public:
|
||||
String printData(uint8_t mode = 10) {
|
||||
return printBytes(data(), dataSize(), mode);
|
||||
}
|
||||
~Data(){};
|
||||
private:
|
||||
void ini() override {
|
||||
_addrFrom = (_data[1] << 8) | _data[2];
|
||||
@ -105,9 +109,9 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class RawData : public Data {
|
||||
// class RawData : public Data {
|
||||
|
||||
};
|
||||
// };
|
||||
|
||||
class Accept : public InputData {
|
||||
public:
|
||||
@ -135,10 +139,12 @@ public:
|
||||
friend IR_Decoder;
|
||||
private:
|
||||
bool _isAvaliable = false;
|
||||
uint16_t _tune;
|
||||
uint16_t _errCount = 0;
|
||||
uint16_t _tune = 0;
|
||||
public:
|
||||
bool avaliable() { return _isAvaliable; };
|
||||
uint16_t getTune() { return _tune; };
|
||||
uint16_t errorCount() { return _errCount; };
|
||||
void resetAvaliable() { _isAvaliable = false; };
|
||||
private:
|
||||
void _set(uint16_t val) {
|
||||
@ -148,7 +154,8 @@ public:
|
||||
};
|
||||
|
||||
Data gotData;
|
||||
RawData gotRawData;
|
||||
Data gotRawData;
|
||||
// RawData gotRawData;
|
||||
Accept gotAccept;
|
||||
Request gotRequest;
|
||||
RawTune gotTune;
|
||||
@ -159,6 +166,9 @@ private:
|
||||
bool isPairSending = false;
|
||||
bool IsPairSendLOW = false;
|
||||
|
||||
|
||||
volatile bool isRecive = false;
|
||||
|
||||
bool isWaitingAccept = false;
|
||||
uint16_t addrWaitingFrom = 0;
|
||||
|
||||
|
56
IR_config.h
56
IR_config.h
@ -37,7 +37,7 @@ msg type:
|
||||
#define IR_MSG_ 4U // | 100..... | = */ /* = ??
|
||||
#define IR_MSG_ 5U // | 101..... | = */ /* = ??
|
||||
#define IR_MSG_DATA_NOACCEPT 6U // | 110..... | = */ /* = данные, не требующие подтверждения
|
||||
// // | \\\xxxxx | = = L длина данных
|
||||
// // | \\\xxxxx | = = L длина данных
|
||||
#define IR_MSG_DATA_ACCEPT 7U // | 111..... | = */ /* = данные требующие подтверждения
|
||||
// // | \\\xxxxx | = = L длина данных
|
||||
/* // ----------
|
||||
@ -84,7 +84,7 @@ typedef uint16_t crc_t;
|
||||
#define syncBits 3U // количество битов синхронизации
|
||||
|
||||
#define dataByteSizeMax (msgBytes + addrBytes + addrBytes + bytePerPack + crcBytes)
|
||||
// размер msg в битах // размер короткой посылки в битах
|
||||
// размер msg в битах // размер короткой посылки в битах
|
||||
#define dataBitSize ((8 + syncBits) * dataByteSizeMax) // размер посылки с данными в битах
|
||||
#define bufferBitSizeMax (dataBitSize) // Размер буффера в битах
|
||||
|
||||
@ -106,7 +106,7 @@ const auto viewValue = bitTime;
|
||||
class IR_FOX {
|
||||
private:
|
||||
bool isSending = false;
|
||||
public:
|
||||
protected:
|
||||
uint8_t crc8(uint8_t* data, uint8_t start, uint8_t end, uint8_t poly) { //TODO: сделать возможность межбайтовой проверки
|
||||
uint8_t crc = 0xff;
|
||||
size_t i, j;
|
||||
@ -121,34 +121,36 @@ public:
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
String printBytes(uint8_t* d ,uint8_t s , uint8_t mode = 10) {
|
||||
String str = "";
|
||||
uint8_t control = bitPerByte;
|
||||
uint8_t* _data = d;
|
||||
switch (mode) {
|
||||
case 2:
|
||||
for (size_t i = 0; i < s * 8; i++) {
|
||||
if (i == control) {
|
||||
str += " ";
|
||||
control += bitPerByte;
|
||||
}
|
||||
|
||||
str += _data[(i / 8)] >> (7 - (i % 8)) & 1;
|
||||
}
|
||||
break;
|
||||
case 10:
|
||||
for (size_t i = 0; i < s; i++) {
|
||||
str += _data[i];
|
||||
public:
|
||||
String printBytes(uint8_t* d, uint8_t s, uint8_t mode = 10) {
|
||||
String str = "";
|
||||
uint8_t control = bitPerByte;
|
||||
uint8_t* _data = d;
|
||||
switch (mode) {
|
||||
case 2:
|
||||
for (size_t i = 0; i < s * 8; i++) {
|
||||
if (i == control) {
|
||||
str += " ";
|
||||
control += bitPerByte;
|
||||
}
|
||||
|
||||
break;
|
||||
str += _data[(i / 8)] >> (7 - (i % 8)) & 1;
|
||||
}
|
||||
break;
|
||||
case 10:
|
||||
for (size_t i = 0; i < s; i++) {
|
||||
str += _data[i];
|
||||
str += " ";
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
str += " ";
|
||||
return str;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
str += " ";
|
||||
return str;
|
||||
}
|
||||
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user