add Accept logic

This commit is contained in:
DashyFox 2024-02-27 11:38:23 +03:00
parent 4d92acf15b
commit 9643237465
4 changed files with 29 additions and 16 deletions

View File

@ -1,16 +1,23 @@
#pragma once
#include "IR_DecoderRaw.h"
#include "PacketTypes.h"
#include "IR_Encoder.h"
class IR_Decoder : public IR_DecoderRaw {
uint32_t acceptSendTimer;
bool isWaitingAcceptSend;
uint16_t addrAcceptSendTo;
public:
PacketTypes::Data gotData;
PacketTypes::DataBack gotBackData;
PacketTypes::Accept gotAccept;
PacketTypes::Request gotRequest;
IR_Decoder(const uint8_t isrPin, uint16_t addr, IR_Encoder* encPair = nullptr) : IR_DecoderRaw(isrPin, addr, encPair) {
}
IR_Decoder(const uint8_t isrPin, uint16_t addr, IR_Encoder* encPair = nullptr) : IR_DecoderRaw(isrPin, addr, encPair) {}
void tick() {
IR_DecoderRaw::tick();
@ -18,10 +25,9 @@ public:
#ifdef IRDEBUG_INFO
Serial.println("PARSING RAW DATA");
#endif
bool isNeenAccept = false;
isWaitingAcceptSend = false;
switch (packInfo.buffer[0] >> 5 & IR_MASK_MSG_TYPE) {
case IR_MSG_DATA_ACCEPT:
isNeenAccept = true;
case IR_MSG_DATA_NOACCEPT:
gotData.set(&packInfo, id);
break;
@ -39,8 +45,15 @@ public:
default:
break;
}
if (gotData.isAvailable && (gotData.getMsgType() == IR_MSG_DATA_ACCEPT)) {
acceptSendTimer = millis();
addrAcceptSendTo = gotData.getAddrFrom();
if(addrAcceptSendTo && addrAcceptSendTo < IR_Broadcast) isWaitingAcceptSend = true;
}
}
if (isWaitingAcceptSend && millis() - acceptSendTimer > 75) {
encoder->sendAccept(addrAcceptSendTo);
isWaitingAcceptSend = false;
}
}
};

View File

@ -45,12 +45,12 @@ public:
protected:
PackInfo packInfo;
uint16_t id;
IR_Encoder* encoder; // Указатель на парный передатчик
private:
ErrorsStruct errors;
bool isAvailable = false;
uint16_t packSize;
uint16_t crcValue;
IR_Encoder* encoder; // Указатель на парный передатчик
volatile uint16_t isPairSending = 0; // Флаг передачи парного передатчика
volatile bool isRecive = false; // Флаг приёма
volatile bool isPreamb = false; // флаг начальной последовости

View File

@ -72,17 +72,17 @@ void IR_Encoder::sendData(uint16_t addrTo, uint8_t* data, uint8_t len, bool need
rawSend(sendBuffer, packSize);
}
void IR_Encoder::sendAccept(uint16_t addrTo, uint8_t addInfo) {
void IR_Encoder::sendAccept(uint16_t addrTo) {
memset(sendBuffer, 0x00, dataByteSizeMax);
sendBuffer[0] = IR_MSG_ACCEPT << 5;
sendBuffer[0] |= addInfo & IR_MASK_MSG_INFO;
sendBuffer[0] |= msgBytes + addrBytes + crcBytes & IR_MASK_MSG_INFO; // размер пакета
// addr_self
sendBuffer[1] = id >> 8 & 0xFF;
sendBuffer[2] = id & 0xFF;
Serial.print("\nRAW Accept to ");
Serial.println(addrTo);
// Serial.print("\nRAW Accept to ");
// Serial.println(addrTo);
// data crc
@ -92,10 +92,10 @@ void IR_Encoder::sendAccept(uint16_t addrTo, uint8_t addInfo) {
rawSend(sendBuffer, msgBytes + addrBytes + crcBytes);
}
void IR_Encoder::sendRequest(uint16_t addrTo, uint8_t addInfo) {
void IR_Encoder::sendRequest(uint16_t addrTo) {
memset(sendBuffer, 0x00, dataByteSizeMax);
sendBuffer[0] = IR_MSG_REQUEST << 5;
sendBuffer[0] |= addInfo & IR_MASK_MSG_INFO;
sendBuffer[0] |= msgBytes + addrBytes + addrBytes + crcBytes & IR_MASK_MSG_INFO;
// addr_self
sendBuffer[1] = id >> 8 & 0xFF;
@ -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 msgType =
((isAdressed ? IR_MSG_BACK_TO : IR_MSG_BACK)<<5) | ((packSize) & (IR_MASK_MSG_INFO >> 1));
((isAdressed ? IR_MSG_BACK_TO : IR_MSG_BACK) << 5) | ((packSize) & (IR_MASK_MSG_INFO >> 1));
// формирование массива
// msg_type

View File

@ -45,8 +45,8 @@ public:
void IR_Encoder::setBlindDecoders(IR_DecoderRaw* decoders [], uint8_t count);
void rawSend(uint8_t* ptr, uint8_t len);
void sendData(uint16_t addrTo, uint8_t* data, uint8_t len, bool needAccept = false);
void sendAccept(uint16_t addrTo, uint8_t addInfo = 0);
void sendRequest(uint16_t addrTo, uint8_t addInfo = 0);
void sendAccept(uint16_t addrTo);
void sendRequest(uint16_t addrTo);
void sendBack(uint8_t* data = nullptr, uint8_t len = 0);
void sendBackTo(uint16_t addrTo, uint8_t* data = nullptr, uint8_t len = 0);
void isr();