mirror of
				https://github.com/Show-maket/IR-protocol.git
				synced 2025-10-31 02:52:36 +00:00 
			
		
		
		
	no template
This commit is contained in:
		| @ -11,15 +11,15 @@ IR_Encoder::IR_Encoder(uint16_t addr, uint8_t pin, IR_Decoder* decPair = nullptr | |||||||
|     signal = noSignal; |     signal = noSignal; | ||||||
|     isSending = false; |     isSending = false; | ||||||
|     #if disablePairDec |     #if disablePairDec | ||||||
|     if(decPair != nullptr){ |     if (decPair != nullptr) { | ||||||
|         blindDecoders = new IR_Decoder*[1]{decPair}; |         blindDecoders = new IR_Decoder * [1] {decPair}; | ||||||
|         decodersCount = 1; |         decodersCount = 1; | ||||||
|     } |     } | ||||||
|     #endif |     #endif | ||||||
| }; | }; | ||||||
| void IR_Encoder::setBlindDecoders(IR_Decoder* decoders[], uint8_t count){ | void IR_Encoder::setBlindDecoders(IR_Decoder* decoders [], uint8_t count) { | ||||||
|     #if disablePairDec |     #if disablePairDec | ||||||
|     if(blindDecoders != nullptr) delete[] blindDecoders; |     if (blindDecoders != nullptr) delete [] blindDecoders; | ||||||
|     #endif |     #endif | ||||||
|     decodersCount = count; |     decodersCount = count; | ||||||
|     blindDecoders = decoders; |     blindDecoders = decoders; | ||||||
| @ -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); | ||||||
| } | // } | ||||||
|  |  | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user