merge from TX and RX

This commit is contained in:
2023-10-10 18:06:13 +03:00
parent a4105021ce
commit e812f97f37
5 changed files with 107 additions and 24 deletions

View File

@ -4,12 +4,12 @@
//#define IRDEBUG
#ifdef IRDEBUG
#define wrHigh 3 // Запись HIGH инициирована // green
#define wrLow 4 // Запись LOW инициирована // blue
#define writeOp 6 // Операция записи, 1 пульс для 0 и 2 для 1 // orange
#define wrHigh A3 // Запись HIGH инициирована // green
#define wrLow A3 // Запись LOW инициирована // blue
#define writeOp 13 // Операция записи, 1 пульс для 0 и 2 для 1 // orange
// Исправленные ошибки // purle
// 1 пульс: fix
#define errOut 5
#define errOut A3
#endif
/////////////////////////////////////////////////////////////////////////////////////////////////
@ -39,7 +39,7 @@ public:
//////////////////////////////////////////////////////////////////////////
class InputData {
class InputData : protected IR_FOX {
friend IR_Decoder;
protected:
bool _isAvaliable = false;
@ -51,11 +51,13 @@ public:
uint16_t _crcPackVal;
uint16_t _crcCalcVal;
uint16_t _errCount;
uint16_t _bitPeriod;
void _set(uint8_t* ptr, uint8_t len, uint16_t crc, uint16_t err) {
void _set(uint8_t* ptr, uint8_t len, uint16_t crc, uint16_t err, uint16_t rTime) {
_crcCalcVal = crc;
_dataRawSize = len;
_errCount = err;
_bitPeriod = rTime;
if (_data != nullptr) { delete _data; _data = nullptr; }
_data = new uint8_t[len];
for (uint8_t i = 0; i < len; i++) { _data[i] = ptr[i]; }
@ -74,6 +76,7 @@ public:
uint16_t errorCount() { return _errCount; };
uint16_t crcIN() { return _crcPackVal; };
uint16_t crcCALC() { return _crcCalcVal; };
uint16_t tunerTime() { return _bitPeriod; };
void resetAvaliable() { _isAvaliable = false; };
};
@ -88,12 +91,21 @@ public:
uint8_t dataRawSize() { return _dataRawSize; };
uint8_t* dataRaw() { return _data; };
bool isNeedAccept() { return ((_msgType >> 5) & IR_MASK_MSG_TYPE) == IR_MSG_DATA_ACCEPT; };
String printRawData(uint8_t mode = 10) {
return printBytes(dataRaw(), dataRawSize(), mode);
}
String printData(uint8_t mode = 10) {
return printBytes(data(), dataSize(), mode);
}
private:
void ini() override {
_addrFrom = (_data[1] << 8) | _data[2];
_addrTo = (_data[3] << 8) | _data[4];
_crcPackVal = (_data[_dataRawSize - 2] << 8) | _data[_dataRawSize - 1];
}
};
class RawData : public Data {
};
@ -120,6 +132,7 @@ public:
};
Data gotData;
RawData gotRawData;
Accept gotAccept;
Request gotRequest;
@ -176,6 +189,31 @@ private:
//TODO: Сделать функцию медианы
void medi(uint16_t);
// class Medi {
// public:
// uint16_t* arr;
// uint8_t size;
// uint8_t center;
// Medi(uint8_t _size) : size(_size - 1) {
// arr = new uint16_t[size] { 0 };
// center = size / 2;
// };
// void add(uint16_t newVal) {
// _add(newVal, center);
// }
// void _add(uint16_t newVal, int8_t pos, bool f) {
// if (pos < 0 || pos > size) return;
// if (newVal < arr[pos]) _add(newVal, pos-1, f);
// if (newVal > arr[pos]) _add(newVal, pos+1, f);
// }
// ~Medi() { delete arr; }
// };
#ifdef IRDEBUG
inline void errPulse(uint8_t pin, uint8_t count);