mirror of
https://github.com/Show-maket/IR-protocol.git
synced 2025-05-04 07:10:16 +00:00
refactor
This commit is contained in:
parent
6f5bbac83c
commit
e35bf7ae23
@ -1,4 +1,4 @@
|
|||||||
#include "IR_DecoderRaw.h"
|
#include "IR_Decoder.h"
|
||||||
#include "IR_Encoder.h"
|
#include "IR_Encoder.h"
|
||||||
#include "TimerStatic.h"
|
#include "TimerStatic.h"
|
||||||
#include "MemoryCheck.h"
|
#include "MemoryCheck.h"
|
||||||
@ -19,8 +19,8 @@
|
|||||||
|
|
||||||
//////////////// Var /////////////////
|
//////////////// Var /////////////////
|
||||||
|
|
||||||
IR_DecoderRaw decForward(2, 555);
|
IR_Decoder decForward(2, 555);
|
||||||
IR_DecoderRaw decBackward(3, 777);
|
IR_Decoder decBackward(3, 777);
|
||||||
|
|
||||||
IR_Encoder encForward(42, encForward_PIN, &decBackward);
|
IR_Encoder encForward(42, encForward_PIN, &decBackward);
|
||||||
// IR_Encoder encBackward(321, encBackward_PIN);
|
// IR_Encoder encBackward(321, encBackward_PIN);
|
||||||
@ -226,10 +226,8 @@ void loop() {
|
|||||||
|
|
||||||
|
|
||||||
//test
|
//test
|
||||||
void status(IR_DecoderRaw& dec) {
|
void status(IR_Decoder& dec) {
|
||||||
if (dec.available()) {
|
|
||||||
Serial.println("LOOP RAW DATA");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// IR_DecoderRaw::AnyData* infoArr [] = { &dec.gotData, &dec.gotBackData };
|
// IR_DecoderRaw::AnyData* infoArr [] = { &dec.gotData, &dec.gotBackData };
|
||||||
|
64
IR_Decoder.h
64
IR_Decoder.h
@ -1,33 +1,45 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "IR_config.h"
|
#include "IR_DecoderRaw.h"
|
||||||
|
#include "PacketTypes.h"
|
||||||
// class IR_Decoder
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class IR_Decoder : public IR_DecoderRaw {
|
||||||
|
public:
|
||||||
|
IR_Decoder(const uint8_t isrPin, uint16_t addr, IR_Encoder* encPair = nullptr) :
|
||||||
|
IR_DecoderRaw(isrPin, addr, encPair),
|
||||||
|
gotData(Data(&packInfo)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
Data gotData;
|
||||||
|
|
||||||
|
void tick() {
|
||||||
|
IR_DecoderRaw::tick();
|
||||||
|
if (available()) {
|
||||||
|
Serial.println("PARSING RAW DATA");
|
||||||
|
|
||||||
|
switch (packInfo.buffer[0] & IR_MASK_MSG_TYPE) {
|
||||||
|
case IR_MSG_DATA_NOACCEPT:
|
||||||
|
|
||||||
|
break;
|
||||||
|
case IR_MSG_DATA_ACCEPT:
|
||||||
|
break;
|
||||||
|
case IR_MSG_BACK:
|
||||||
|
break;
|
||||||
|
case IR_MSG_BACK_TO:
|
||||||
|
break;
|
||||||
|
case IR_MSG_REQUEST:
|
||||||
|
break;
|
||||||
|
case IR_MSG_ACCEPT:
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -349,14 +349,21 @@ void IR_DecoderRaw::writeToBuffer(bool bit) {
|
|||||||
|
|
||||||
if (!isAvailable && isData) {
|
if (!isAvailable && isData) {
|
||||||
if (i_dataBuffer == 8 * msgBytes) {// Ппервый байт
|
if (i_dataBuffer == 8 * msgBytes) {// Ппервый байт
|
||||||
packSize = (dataBuffer[0] & IR_MASK_MSG_INFO) + crcBytes;
|
packSize = dataBuffer[0] & IR_MASK_MSG_INFO;
|
||||||
Serial.print(" ["); Serial.print(packSize); Serial.print("] ");
|
Serial.print(" ["); Serial.print(packSize); Serial.print("] ");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packSize && (i_dataBuffer == packSize*bitPerByte)) { // Конец
|
if (packSize && (i_dataBuffer == packSize*bitPerByte)) { // Конец
|
||||||
isAvailable = crcCheck(packSize - crcBytes, crcValue);
|
|
||||||
Serial.print(" END DATA ");
|
Serial.print(" END DATA ");
|
||||||
|
|
||||||
|
packInfo.buffer = dataBuffer;
|
||||||
|
packInfo.crc = crcValue;
|
||||||
|
packInfo.err = errors;
|
||||||
|
packInfo.packSize = packSize;
|
||||||
|
packInfo.rTime = riseSyncTime;
|
||||||
|
|
||||||
isRecive = false;
|
isRecive = false;
|
||||||
|
isAvailable = crcCheck(packSize - crcBytes, crcValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
|
|
||||||
class IR_Encoder;
|
class IR_Encoder;
|
||||||
class IR_DecoderRaw : private IR_FOX {
|
class IR_DecoderRaw : public IR_FOX {
|
||||||
friend IR_Encoder;
|
friend IR_Encoder;
|
||||||
public:
|
public:
|
||||||
const uint8_t isrPin; // Пин прерывания
|
const uint8_t isrPin; // Пин прерывания
|
||||||
@ -42,8 +42,10 @@ public:
|
|||||||
bool isReciving() { return isBufferOverflow; }; // Возвращает true, если происходит приём пакета
|
bool isReciving() { return isBufferOverflow; }; // Возвращает true, если происходит приём пакета
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
protected:
|
||||||
|
PackInfo packInfo;
|
||||||
private:
|
private:
|
||||||
|
ErrorsStruct errors;
|
||||||
uint16_t id;
|
uint16_t id;
|
||||||
bool isAvailable = false;
|
bool isAvailable = false;
|
||||||
uint16_t packSize;
|
uint16_t packSize;
|
||||||
|
@ -39,7 +39,7 @@ void IR_Encoder::sendData(uint16_t addrTo, uint8_t* data, uint8_t len, bool need
|
|||||||
memset(sendBuffer, 0x00, dataByteSizeMax);
|
memset(sendBuffer, 0x00, dataByteSizeMax);
|
||||||
uint8_t packSize = msgBytes + addrBytes + addrBytes + len + crcBytes;
|
uint8_t packSize = msgBytes + addrBytes + addrBytes + len + crcBytes;
|
||||||
uint8_t msgType =
|
uint8_t msgType =
|
||||||
((needAccept ? IR_MSG_DATA_ACCEPT : IR_MSG_DATA_NOACCEPT) << 5) | ((packSize - crcBytes) & IR_MASK_MSG_INFO);
|
((needAccept ? IR_MSG_DATA_ACCEPT : IR_MSG_DATA_NOACCEPT) << 5) | (packSize & IR_MASK_MSG_INFO);
|
||||||
|
|
||||||
// формирование массива
|
// формирование массива
|
||||||
// msg_type
|
// msg_type
|
||||||
@ -127,7 +127,7 @@ void IR_Encoder::_sendBack(bool isAdressed, uint16_t addrTo, uint8_t* data, uint
|
|||||||
|
|
||||||
uint8_t packSize = msgBytes + addrBytes + (isAdressed ? addrBytes : 0) + min(1, len) + crcBytes;
|
uint8_t packSize = msgBytes + addrBytes + (isAdressed ? addrBytes : 0) + min(1, len) + crcBytes;
|
||||||
uint8_t msgType =
|
uint8_t msgType =
|
||||||
(IR_MSG_BACK << 5) | (isAdressed << 4U) | ((packSize - crcBytes) & (IR_MASK_MSG_INFO >> 1));
|
(IR_MSG_BACK << 5) | (isAdressed << 4U) | ((packSize) & (IR_MASK_MSG_INFO >> 1));
|
||||||
|
|
||||||
// формирование массива
|
// формирование массива
|
||||||
// msg_type
|
// msg_type
|
||||||
|
14
IR_config.h
14
IR_config.h
@ -146,9 +146,9 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct ErrorsStruct {
|
struct ErrorsStruct {
|
||||||
uint8_t lowSignal;
|
uint8_t lowSignal = 0;
|
||||||
uint8_t highSignal;
|
uint8_t highSignal= 0;
|
||||||
uint8_t other;
|
uint8_t other= 0;
|
||||||
|
|
||||||
void reset() {
|
void reset() {
|
||||||
lowSignal = 0;
|
lowSignal = 0;
|
||||||
@ -160,11 +160,11 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct PackInfo {
|
struct PackInfo {
|
||||||
uint8_t* ptr;
|
uint8_t* buffer = nullptr;
|
||||||
uint8_t packSize;
|
uint8_t packSize = 0;
|
||||||
uint16_t crc;
|
uint16_t crc= 0;
|
||||||
ErrorsStruct err;
|
ErrorsStruct err;
|
||||||
uint16_t rTime;
|
uint16_t rTime = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
59
PacketTypes.h
Normal file
59
PacketTypes.h
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "IR_config.h"
|
||||||
|
|
||||||
|
class IOffsets {
|
||||||
|
public:
|
||||||
|
uint8_t msgOffset;
|
||||||
|
uint8_t addressFromOffset;
|
||||||
|
uint8_t addressToOffset;
|
||||||
|
uint8_t DataOffset;
|
||||||
|
};
|
||||||
|
|
||||||
|
class IPackInfo {
|
||||||
|
public:
|
||||||
|
IR_FOX::PackInfo* packInfo;
|
||||||
|
};
|
||||||
|
|
||||||
|
class IBaseEmptyPack : virtual public IOffsets, virtual public IPackInfo {};
|
||||||
|
|
||||||
|
class IEmptyPack : virtual protected IBaseEmptyPack {
|
||||||
|
bool isAvailable;
|
||||||
|
|
||||||
|
public:
|
||||||
|
IEmptyPack(IR_FOX::PackInfo* _packInfo) { packInfo = _packInfo; }
|
||||||
|
virtual bool available() { if (isAvailable) { isAvailable = false; return true; } else { return false; } };
|
||||||
|
virtual uint8_t getMsgInfo() { return packInfo->buffer[0] & IR_MASK_MSG_INFO; };
|
||||||
|
virtual uint8_t getMsgType() { return (packInfo->buffer[0] >> 5) & IR_MASK_MSG_TYPE; };
|
||||||
|
virtual uint8_t getMsgRAW() { return packInfo->buffer[0]; };
|
||||||
|
virtual uint16_t getErrorCount() { return packInfo->err.all(); };
|
||||||
|
virtual uint8_t getErrorLowSignal() { return packInfo->err.lowSignal; };
|
||||||
|
virtual uint8_t getErrorHighSignal() { return packInfo->err.highSignal; };
|
||||||
|
virtual uint8_t getErrorOther() { return packInfo->err.other; };
|
||||||
|
virtual uint16_t getTunerTime() { return packInfo->rTime; };
|
||||||
|
};
|
||||||
|
|
||||||
|
class IHasAddresFrom : virtual protected IBaseEmptyPack {
|
||||||
|
virtual uint16_t getAddrFrom() { return packInfo->buffer[addressFromOffset] | packInfo->buffer[addressFromOffset + 1]; };
|
||||||
|
};
|
||||||
|
|
||||||
|
class IHasAddresTo : virtual protected IBaseEmptyPack {
|
||||||
|
virtual uint16_t getAddrTo() { return packInfo->buffer[addressToOffset] | packInfo->buffer[addressToOffset + 1]; };
|
||||||
|
};
|
||||||
|
|
||||||
|
class IHasAddresData : virtual protected IBaseEmptyPack {
|
||||||
|
virtual uint8_t getDataSize() { return /* packInfo->buffer[packInfo->packSize-2] */0; };//TODO:
|
||||||
|
virtual uint8_t* getDataPrt() { return packInfo->buffer + DataOffset; };
|
||||||
|
virtual uint8_t getDataRawSize() { return packInfo->packSize; };
|
||||||
|
virtual uint8_t* getDataRawPtr() { return packInfo->buffer; };
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Data :
|
||||||
|
virtual public IEmptyPack,
|
||||||
|
virtual public IHasAddresFrom {
|
||||||
|
public:
|
||||||
|
Data(IR_FOX::PackInfo* packInfo) : IEmptyPack(packInfo) {
|
||||||
|
msgOffset = 0;
|
||||||
|
}
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user