This commit is contained in:
DashyFox 2024-02-20 15:00:42 +03:00
parent 27dd448cb0
commit ff7b5dcaa4
3 changed files with 44 additions and 55 deletions

View File

@ -106,7 +106,46 @@ void IR_Encoder::sendRequest(uint16_t addrTo, uint8_t addInfo) {
rawSend(sendBuffer, msgBytes + addrBytes + addrBytes + crcBytes); 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() { void IR_Encoder::setDecoder_isSending() {
if (decodersCount) { if (decodersCount) {

View File

@ -43,17 +43,19 @@ public:
} }
void IR_Encoder::setBlindDecoders(IR_Decoder* decoders [], uint8_t count); void IR_Encoder::setBlindDecoders(IR_Decoder* decoders [], uint8_t count);
// template<typename T> void rawSend(uint8_t* ptr, uint8_t len);
// void sendData(uint16_t addrTo, T& data, bool needAccept = false);
void sendData(uint16_t addrTo, uint8_t* data, uint8_t len, bool needAccept = false); 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 sendACK(uint16_t addrTo, uint8_t addInfo = 0, bool forAll = false);
void sendRequest(uint16_t addrTo, uint8_t addInfo = 0); 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(); void isr();
~IR_Encoder(); ~IR_Encoder();
volatile bool ir_out_virtual; volatile bool ir_out_virtual;
private: private:
void IR_Encoder::_sendBack(bool isAdressed, uint16_t addrTo, uint8_t* data, uint8_t len);
void IR_Encoder::setDecoder_isSending(); void IR_Encoder::setDecoder_isSending();
void sendByte(uint8_t byte, bool* prev, bool LOW_FIRST); void sendByte(uint8_t byte, bool* prev, bool LOW_FIRST);
void addSync(bool* prev, bool* next); void addSync(bool* prev, bool* next);
@ -101,24 +103,10 @@ private:
(bitPauseTakts) * 2 - 1 (bitPauseTakts) * 2 - 1
}; };
uint8_t* currentBitSequence = bitLow; uint8_t* currentBitSequence = bitLow;
// uint8_t bitSequence[2];
volatile SignalPart signal; volatile SignalPart signal;
}; };
////////////////////////////////////////////////////////////////////////////////////////////////
// template<typename T>
// 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);
// }

View File

@ -194,42 +194,4 @@ protected:
return crc; 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;
// }
}; };