mirror of
https://github.com/Show-maket/IR-protocol.git
synced 2025-06-28 05:09:40 +00:00
refactor
This commit is contained in:
36
IR_config.h
36
IR_config.h
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
#define IRDEBUG_INFO
|
||||
#include <list>
|
||||
// #define IRDEBUG_INFO
|
||||
/*//////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Для работы в паре положить декодер в энкодер
|
||||
@ -140,8 +140,12 @@ typedef uint16_t crc_t;
|
||||
#define bitTakts (bitActiveTakts+bitPauseTakts) // Общая длительность бита в тактах
|
||||
#define bitTime (bitTakts*carrierPeriod) // Общая длительность бита
|
||||
#define tolerance 300U
|
||||
|
||||
|
||||
|
||||
class IR_FOX {
|
||||
public:
|
||||
|
||||
struct PackOffsets {
|
||||
uint8_t msgOffset;
|
||||
uint8_t addrFromOffset;
|
||||
@ -172,32 +176,14 @@ public:
|
||||
uint16_t rTime = 0;
|
||||
};
|
||||
|
||||
static void checkAddressRuleApply(uint16_t address, uint16_t id, bool& flag) {
|
||||
flag = false;
|
||||
flag |= id == 0;
|
||||
flag |= address == id;
|
||||
flag |= address >= IR_Broadcast;
|
||||
}
|
||||
|
||||
uint16_t getId() { return id; }
|
||||
void setId(uint16_t id) { this->id = id; }
|
||||
inline uint16_t getId() { return id; }
|
||||
inline void setId(uint16_t id) { this->id = id; }
|
||||
static void checkAddressRuleApply(uint16_t address, uint16_t id, bool& flag);
|
||||
|
||||
protected:
|
||||
ErrorsStruct errors;
|
||||
uint16_t id;
|
||||
uint8_t crc8(uint8_t* data, uint8_t start, uint8_t end, uint8_t poly) { //TODO: сделать возможность межбайтовой проверки
|
||||
uint8_t crc = 0xff;
|
||||
size_t i, j;
|
||||
for (i = start; i < end; i++) {
|
||||
crc ^= data[i];
|
||||
for (j = 0; j < 8; j++) {
|
||||
if ((crc & 0x80) != 0)
|
||||
crc = (uint8_t)((crc << 1) ^ poly);
|
||||
else
|
||||
crc <<= 1;
|
||||
}
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
ErrorsStruct errors;
|
||||
uint8_t crc8(uint8_t* data, uint8_t start, uint8_t end, uint8_t poly);
|
||||
|
||||
};
|
||||
|
Reference in New Issue
Block a user