This commit is contained in:
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);
}
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) {