mirror of
https://github.com/Show-maket/IR-protocol.git
synced 2025-05-04 07:10:16 +00:00
no template
This commit is contained in:
parent
882bd56d49
commit
408fea84ac
@ -31,10 +31,40 @@ IR_Encoder::~IR_Encoder() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void IR_Encoder::sendData(uint16_t addrTo, uint8_t* data, uint8_t len, bool needAccept = false) {
|
void IR_Encoder::sendData(uint16_t addrTo, uint8_t* data, uint8_t len, bool needAccept = false) {
|
||||||
|
constexpr uint8_t dataStart = msgBytes + addrBytes + addrBytes;
|
||||||
|
memset(sendBuffer, 0x00, dataByteSizeMax);
|
||||||
uint8_t packSize = msgBytes + addrBytes + addrBytes + len + crcBytes;
|
uint8_t packSize = msgBytes + addrBytes + addrBytes + len + crcBytes;
|
||||||
uint8_t msgType =
|
uint8_t msgType =
|
||||||
((needAccept ? IR_MSG_DATA_ACCEPT : IR_MSG_DATA_NOACCEPT) << 5) | ((packSize - crcBytes) & IR_MASK_MSG_INFO);
|
((needAccept ? IR_MSG_DATA_ACCEPT : IR_MSG_DATA_NOACCEPT) << 5) | ((packSize - crcBytes) & IR_MASK_MSG_INFO);
|
||||||
_sendData(addrTo, data, len, msgType);
|
|
||||||
|
// формирование массива
|
||||||
|
// msg_type
|
||||||
|
sendBuffer[0] = msgType;
|
||||||
|
|
||||||
|
// addr_self
|
||||||
|
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;
|
||||||
|
|
||||||
|
if (decPair != nullptr) {
|
||||||
|
decPair->isWaitingAccept = ((msgType >> 5) & IR_MASK_MSG_TYPE == IR_MSG_DATA_ACCEPT);
|
||||||
|
if (decPair->isWaitingAccept) {
|
||||||
|
decPair->addrWaitingFrom = addrTo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// отправка
|
||||||
|
rawSend(sendBuffer, packSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IR_Encoder::sendACK(uint16_t addrTo, uint8_t addInfo, bool forAll = false) {
|
void IR_Encoder::sendACK(uint16_t addrTo, uint8_t addInfo, bool forAll = false) {
|
||||||
@ -75,42 +105,7 @@ 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::_sendData(uint16_t addrTo, uint8_t* data, uint8_t len, uint8_t msgType) {
|
|
||||||
memset(sendBuffer, 0x00, dataByteSizeMax);
|
|
||||||
|
|
||||||
uint8_t packSize = msgBytes + addrBytes + addrBytes + len + crcBytes;
|
|
||||||
uint8_t dataStart = msgBytes + addrBytes + addrBytes;
|
|
||||||
|
|
||||||
// формирование массива
|
|
||||||
// msg_type
|
|
||||||
sendBuffer[0] = msgType;
|
|
||||||
|
|
||||||
// addr_self
|
|
||||||
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;
|
|
||||||
|
|
||||||
if (decPair != nullptr) {
|
|
||||||
decPair->isWaitingAccept = ((msgType >> 5) & IR_MASK_MSG_TYPE == IR_MSG_DATA_ACCEPT);
|
|
||||||
if (decPair->isWaitingAccept) {
|
|
||||||
decPair->addrWaitingFrom = addrTo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// отправка
|
|
||||||
rawSend(sendBuffer, packSize);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void IR_Encoder::setDecoder_isSending() {
|
void IR_Encoder::setDecoder_isSending() {
|
||||||
if (decodersCount) {
|
if (decodersCount) {
|
||||||
|
20
IR_Encoder.h
20
IR_Encoder.h
@ -44,8 +44,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void IR_Encoder::setBlindDecoders(IR_Decoder* decoders [], uint8_t count);
|
void IR_Encoder::setBlindDecoders(IR_Decoder* decoders [], uint8_t count);
|
||||||
template<typename T>
|
// template<typename T>
|
||||||
void sendData(uint16_t addrTo, T& data, bool needAccept = false);
|
// 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);
|
||||||
@ -113,14 +113,14 @@ private:
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
template<typename T>
|
// template<typename T>
|
||||||
void IR_Encoder::sendData(uint16_t addrTo, T& data, bool needAccept = false) { // TODO: переделать логику LOW_FIRST
|
// void IR_Encoder::sendData(uint16_t addrTo, T& data, bool needAccept = false) { // TODO: переделать логику LOW_FIRST
|
||||||
uint8_t len = sizeof(T);
|
// uint8_t len = sizeof(T);
|
||||||
uint8_t packSize = msgBytes + addrBytes + addrBytes + len + crcBytes;
|
// uint8_t packSize = msgBytes + addrBytes + addrBytes + len + crcBytes;
|
||||||
|
|
||||||
uint8_t msgType =
|
// uint8_t msgType =
|
||||||
((needAccept ? IR_MSG_DATA_ACCEPT : IR_MSG_DATA_NOACCEPT) << 5) | ((packSize - crcBytes) & IR_MASK_MSG_INFO);
|
// ((needAccept ? IR_MSG_DATA_ACCEPT : IR_MSG_DATA_NOACCEPT) << 5) | ((packSize - crcBytes) & IR_MASK_MSG_INFO);
|
||||||
|
|
||||||
_sendData(addrTo, data, len, msgType);
|
// _sendData(addrTo, data, len, msgType);
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user