From ff7b5dcaa4cd8e583af87d05823528c0c9bb6373 Mon Sep 17 00:00:00 2001 From: DashyFox Date: Tue, 20 Feb 2024 15:00:42 +0300 Subject: [PATCH] add back --- IR_Encoder.cpp | 39 +++++++++++++++++++++++++++++++++++++++ IR_Encoder.h | 22 +++++----------------- IR_config.h | 38 -------------------------------------- 3 files changed, 44 insertions(+), 55 deletions(-) diff --git a/IR_Encoder.cpp b/IR_Encoder.cpp index 0eaf6b3..64a9837 100644 --- a/IR_Encoder.cpp +++ b/IR_Encoder.cpp @@ -106,7 +106,46 @@ void IR_Encoder::sendRequest(uint16_t addrTo, uint8_t addInfo) { rawSend(sendBuffer, msgBytes + addrBytes + addrBytes + crcBytes); } +void IR_Encoder::sendBack(uint8_t* data = nullptr, uint8_t len = 0){ + _sendBack(false, 0, data, len); +} +void IR_Encoder::sendBackTo(uint16_t addrTo, uint8_t* data = nullptr, uint8_t len = 0){ + _sendBack(true, addrTo, data, len); +} + +void IR_Encoder::_sendBack(bool isAdressed ,uint16_t addrTo,uint8_t* data, uint8_t len){ + if (len > bytePerPack) { return; } + memset(sendBuffer, 0x00, dataByteSizeMax); + constexpr uint8_t dataStart = msgBytes + addrBytes; + + uint8_t packSize = msgBytes + addrBytes + len + crcBytes; + uint8_t msgType = + (IR_MSG_BACK << 5) | (isAdressed << 4U) | ((packSize - crcBytes) & (IR_MASK_MSG_INFO>>1)); + + // формирование массива + // msg_type + sendBuffer[0] = msgType; + + // addr_from or data + sendBuffer[1] = id >> 8 & 0xFF; + sendBuffer[2] = id & 0xFF; + + // addr_to + sendBuffer[3] = addrTo >> 8 & 0xFF; + sendBuffer[4] = addrTo & 0xFF; + + for (uint16_t i = dataStart; i < dataStart + len; i++) { + sendBuffer[i] = ((uint8_t*)data)[i - dataStart]; + } + + // data crc + sendBuffer[packSize - crcBytes] = crc8(sendBuffer, 0, packSize - crcBytes, poly1) & 0xFF; + sendBuffer[packSize - crcBytes + 1] = crc8(sendBuffer, 0, packSize - crcBytes + 1, poly2) & 0xFF; + + // отправка + rawSend(sendBuffer, packSize); +} void IR_Encoder::setDecoder_isSending() { if (decodersCount) { diff --git a/IR_Encoder.h b/IR_Encoder.h index 8d86781..2712b3b 100644 --- a/IR_Encoder.h +++ b/IR_Encoder.h @@ -43,17 +43,19 @@ public: } void IR_Encoder::setBlindDecoders(IR_Decoder* decoders [], uint8_t count); - // template - // void sendData(uint16_t addrTo, T& data, bool needAccept = false); + void rawSend(uint8_t* ptr, uint8_t len); void sendData(uint16_t addrTo, uint8_t* data, uint8_t len, bool needAccept = false); void sendACK(uint16_t addrTo, uint8_t addInfo = 0, bool forAll = false); void sendRequest(uint16_t addrTo, uint8_t addInfo = 0); - void rawSend(uint8_t* ptr, uint8_t len); + 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(); ~IR_Encoder(); volatile bool ir_out_virtual; private: + void IR_Encoder::_sendBack(bool isAdressed, uint16_t addrTo, uint8_t* data, uint8_t len); + void IR_Encoder::setDecoder_isSending(); void sendByte(uint8_t byte, bool* prev, bool LOW_FIRST); void addSync(bool* prev, bool* next); @@ -101,24 +103,10 @@ private: (bitPauseTakts) * 2 - 1 }; uint8_t* currentBitSequence = bitLow; - - // uint8_t bitSequence[2]; - volatile SignalPart signal; }; -//////////////////////////////////////////////////////////////////////////////////////////////// -// template -// void IR_Encoder::sendData(uint16_t addrTo, T& data, bool needAccept = false) { // TODO: переделать логику LOW_FIRST -// uint8_t len = sizeof(T); -// uint8_t packSize = msgBytes + addrBytes + addrBytes + len + crcBytes; - -// uint8_t msgType = -// ((needAccept ? IR_MSG_DATA_ACCEPT : IR_MSG_DATA_NOACCEPT) << 5) | ((packSize - crcBytes) & IR_MASK_MSG_INFO); - -// _sendData(addrTo, data, len, msgType); -// } diff --git a/IR_config.h b/IR_config.h index 885be00..cc0ccfd 100644 --- a/IR_config.h +++ b/IR_config.h @@ -194,42 +194,4 @@ protected: return crc; } - - // public: - // /// @brief Вывод массива байт в строковом формате - // /// @param d Указатель на массив - // /// @param s Размер массива - // /// @param mode Формат вывода DEC, BIN - // /// @return Готовая для вывода строка - // 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]; - // str += " "; - // } - - // break; - - // default: - // break; - // } - - // str += " "; - // return str; - // } - };