23
23
// IRSENDAC,'{"protocol":"COOLIX","power":"on","mode":"dry","fanspeed":"auto","temp":22,"swingv":"max","swingh":"off"}'
24
24
25
25
/* * Changelog:
26
+ * 2024-01-26 uwekaditz: Decode type UNKNOWN was not added to the web settings
27
+ * Decode types UNKNOWN and UNUSED were mixed up
28
+ * Workaround for decode type UNKNOWN is not necessary
29
+ * Initalisation of the variables with decode type UNUSED
30
+ * 2024-01-23 uwekaditz: Use the new property addToQueue in ExecuteCommand_all() due to the lack of resources
31
+ * Using strformat() for the debug messages
32
+ * Heap and memory can be reported (P016_CHECK_HEAP)
33
+ * 2023-12-11 uwekaditz: Add protocol RAW to UI if 'Accept DecodeType UNKNOWN' is set
34
+ * Note: for decoding a RAW message DECODE_HASH must be set
35
+ * uint64ToString() in debug message in PLUGIN_TEN_PER_SECOND can not handle decode_type_t::UNKNOWN (-1),
36
+ * changed to ll2String()
26
37
* 2022-08-08 tonhuisman: Optionally (compile-time) disable command handling by setting #define P016_FEATURE_COMMAND_HDNLING 0
27
38
* Make reserved buffer size for receiver configurable 100..1024 uint16_t = 200-2048 bytes
28
39
* Change UI to show buffer size in bytes instead of 'units' to avoid confusion.
42
53
# ifdef P016_P035_Extended_AC
43
54
# include < IRac.h>
44
55
# endif // ifdef P016_P035_Extended_AC
56
+ # ifdef P016_CHECK_HEAP
57
+ # include " src/Helpers/Memory.h"
58
+ # endif // ifdef P016_CHECK_HEAP
45
59
46
60
# define PLUGIN_016
47
61
# define PLUGIN_ID_016 16
56
70
# endif // ifndef P016_SEND_IR_TO_CONTROLLER
57
71
58
72
// History
73
+ // @uwekaditz: 2024-01-23
74
+ // CHG: Use the new property addToQueue in ExecuteCommand_all() due to the lack of resources
75
+ // NEW: Heap and memory can be reported (P016_CHECK_HEAP)
76
+ // MSG: Using strformat() for the debug messages
77
+ // @uwekaditz: 2023-12-11
78
+ // NEW: Add protocol RAW to UI if 'Accept DecodeType UNKNOWN' is set
79
+ // MSG: for decoding a RAW message DECODE_HASH must be set
80
+ // FIX: uint64ToString() in debug message in PLUGIN_TEN_PER_SECOND can not handle decode_type_t::UNKNOWN (-1), changed to ll2String()
59
81
// @tonhuisman: 2022-08-08
60
82
// FIX: Resolve high memory use bu having the default buffer size reduced from 1024 to 100, and make that a setting
61
83
// @tonhuisman: 2021-08-05
@@ -145,6 +167,12 @@ const uint16_t kMinUnknownSize = 12;
145
167
146
168
IRrecv *irReceiver = nullptr ;
147
169
bool bEnableIRcodeAdding = false ;
170
+
171
+ # ifdef P016_CHECK_HEAP
172
+ uint32_t fMem = 0 ;
173
+ uint32_t fFreeStack = 0 ;
174
+ # endif // ifdef P016_CHECK_HEAP
175
+
148
176
# ifdef P016_P035_USE_RAW_RAW2
149
177
150
178
/* *INDENT-OFF* */
@@ -155,17 +183,9 @@ boolean displayRawToReadableB32Hex(String& outputStr, decode_results results);
155
183
# ifdef PLUGIN_016_DEBUG
156
184
void P016_infoLogMemory (const __FlashStringHelper *text) {
157
185
if (loglevelActiveFor (LOG_LEVEL_INFO)) {
158
- String log ;
159
-
160
- if (log .reserve (40 + strlen_P ((PGM_P)text))) {
161
- log += F (" P016: Free memory " );
162
- log += text;
163
- log += F (" : " );
164
- log += FreeMem ();
165
- log += F (" stack: " );
166
- log += getCurrentFreeStack ();
167
- addLogMove (LOG_LEVEL_INFO, log );
168
- }
186
+ addLogMove (LOG_LEVEL_INFO, strformat (
187
+ F (" P016: %s FreeMem: %d FreeStack:%d" ),
188
+ text, FreeMem (), getCurrentFreeStack ()));
169
189
}
170
190
}
171
191
@@ -181,11 +201,11 @@ boolean Plugin_016(uint8_t function, struct EventStruct *event, String& string)
181
201
{
182
202
Device[++deviceCount].Number = PLUGIN_ID_016;
183
203
Device[deviceCount].Type = DEVICE_TYPE_SINGLE;
184
- # if P016_SEND_IR_TO_CONTROLLER
185
- Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_STRING;
186
- # else
187
- Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_ULONG;
188
- # endif
204
+ # if P016_SEND_IR_TO_CONTROLLER
205
+ Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_STRING;
206
+ # else // if P016_SEND_IR_TO_CONTROLLER
207
+ Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_ULONG;
208
+ # endif // if P016_SEND_IR_TO_CONTROLLER
189
209
Device[deviceCount].Ports = 0 ;
190
210
Device[deviceCount].PullUpOption = true ;
191
211
Device[deviceCount].InverseLogicOption = true ;
@@ -357,8 +377,12 @@ boolean Plugin_016(uint8_t function, struct EventStruct *event, String& string)
357
377
358
378
int protocolCount = 0 ;
359
379
360
- for (int i = 0 ; i < size; i++) {
361
- const String protocol = typeToString (static_cast <decode_type_t >(i), false );
380
+ for (int i = static_cast <int >(decode_type_t ::UNKNOWN); i < size; i++) {
381
+ const String protocol = typeToString (static_cast <decode_type_t >(i), false );
382
+
383
+ if ((!bAcceptUnknownType) && (static_cast <decode_type_t >(i) == UNKNOWN)) {
384
+ continue ;
385
+ }
362
386
363
387
if (protocol.length () > 1 ) {
364
388
decodeTypeOptions.push_back (i);
@@ -371,13 +395,7 @@ boolean Plugin_016(uint8_t function, struct EventStruct *event, String& string)
371
395
}
372
396
373
397
if (loglevelActiveFor (LOG_LEVEL_INFO)) {
374
- String log ; // Log this always
375
-
376
- if (log .reserve (30 )) {
377
- log += F (" IR: available decodetypes: " );
378
- log += protocolCount;
379
- addLogMove (LOG_LEVEL_INFO, log );
380
- }
398
+ addLogMove (LOG_LEVEL_INFO, strformat (F (" IR: available decodetypes: %d" ), protocolCount));
381
399
}
382
400
383
401
const String P016_HEX_INPUT_PATTERN = F (" (0x)?[0-9a-fA-F]{0,16}" ); // 16 nibbles = 64 bit, 0x prefix is allowed but not added by
@@ -391,7 +409,7 @@ boolean Plugin_016(uint8_t function, struct EventStruct *event, String& string)
391
409
html_table_header (F (" Alt. Decode type" ));
392
410
html_table_header (F (" Repeat" ));
393
411
html_table_header (F (" Alt. Code [Hex]" ));
394
- html_TR (); // added to make "tworow" work
412
+ html_TR (); // added to make "tworow" work
395
413
396
414
int rowCnt = 0 ;
397
415
@@ -597,8 +615,14 @@ boolean Plugin_016(uint8_t function, struct EventStruct *event, String& string)
597
615
{
598
616
decode_results results;
599
617
618
+ # ifdef P016_CHECK_HEAP
619
+ fMem = FreeMem ();
620
+ fFreeStack = getCurrentFreeStack ();
621
+ # endif // ifdef P016_CHECK_HEAP
622
+
600
623
if (irReceiver->decode (&results))
601
624
{
625
+ success = true ;
602
626
yield (); // Feed the WDT after a time expensive decoding procedure
603
627
604
628
if (results.overflow )
@@ -612,34 +636,29 @@ boolean Plugin_016(uint8_t function, struct EventStruct *event, String& string)
612
636
if ((results.decode_type != decode_type_t ::UNKNOWN) || (bitRead (PCONFIG_LONG (0 ), P016_BitAcceptUnknownType)))
613
637
{
614
638
{
615
- String output;
616
- output.reserve (100 ); // Length of expected string, needed for strings > 11 chars
617
639
// String output = String(F("IRSEND,")) + typeToString(results.decode_type, results.repeat) + ',' +
618
640
// resultToHexidecimal(&results)
619
641
// + ',' + uint64ToString(results.bits);
620
642
// addLog(LOG_LEVEL_INFO, output); //Show the appropriate command to the user, so he can replay the message via P035 // Old
621
643
// style
622
644
// command
623
- output += F (" {\" protocol\" :\" " );
624
- output += typeToString (results.decode_type , results.repeat );
625
- output += F (" \" ,\" data\" :\" " );
626
- output += resultToHexidecimal (&results);
627
- output += F (" \" ,\" bits\" :" );
628
- output += uint64ToString (results.bits );
629
- output += ' }' ;
645
+ event->String2 = strformat (
646
+ F (" {\" protocol\" :\" %s\" ,\" data\" :\" %s\" ,\" bits\" :%s}" ),
647
+ typeToString (results.decode_type , results.repeat ).c_str (),
648
+ resultToHexidecimal (&results).c_str (),
649
+ uint64ToString (results.bits ).c_str ());
630
650
631
651
if (loglevelActiveFor (LOG_LEVEL_INFO)) {
632
652
String Log;
633
653
634
- if (Log.reserve (output .length () + 22 )) {
654
+ if (Log.reserve (event-> String2 .length () + 22 )) {
635
655
Log += F (" IRSEND,\' " );
636
- Log += output ;
637
- Log += F (" \' type: 0x " );
638
- Log += uint64ToString (results.decode_type );
656
+ Log += event-> String2 ;
657
+ Log += F (" \' type as int: " );
658
+ Log += ll2String (results.decode_type );
639
659
addLogMove (LOG_LEVEL_INFO, Log); // JSON representation of the command
640
660
}
641
661
}
642
- event->String2 = std::move (output);
643
662
}
644
663
645
664
# if P016_FEATURE_COMMAND_HANDLING
@@ -659,17 +678,22 @@ boolean Plugin_016(uint8_t function, struct EventStruct *event, String& string)
659
678
if (strCode.length () <= P16_Cchars) {
660
679
iCode += hexToULL (strCode);
661
680
662
- if (iCodeDecodeType == decode_type_t ::UNKNOWN) {
663
- // set iCodeDecodeType UNKNOWN to RAW, otherwise AddCode() or ExecuteCode() will fail
664
- iCodeDecodeType = decode_type_t ::RAW;
665
- }
666
-
667
681
if (bitRead (PCONFIG_LONG (0 ), P016_BitAddNewCode) && bEnableIRcodeAdding) {
668
682
P016_data->AddCode (iCode, iCodeDecodeType, iCodeFlags); // add code if not saved so far
669
683
}
670
684
685
+ # ifdef P016_CHECK_HEAP
686
+
687
+ if (loglevelActiveFor (LOG_LEVEL_INFO)) {
688
+ addLogMove (LOG_LEVEL_INFO, strformat (
689
+ F (" Before decode: FreeMem: %d FreeStack:%d / After: FreeMem: %d FreeStack:%d" ),
690
+ fMem , fFreeStack ,
691
+ FreeMem (), getCurrentFreeStack ()));
692
+ }
693
+ # endif // ifdef P016_CHECK_HEAP
694
+
671
695
if (bitRead (PCONFIG_LONG (0 ), P016_BitExecuteCmd)) {
672
- P016_data->ExecuteCode (iCode, iCodeDecodeType, iCodeFlags); // execute command for code if available
696
+ success = P016_data->ExecuteCode (iCode, iCodeDecodeType, iCodeFlags); // execute command for code if available
673
697
}
674
698
}
675
699
}
@@ -725,18 +749,12 @@ boolean Plugin_016(uint8_t function, struct EventStruct *event, String& string)
725
749
state.sleep = -1 ;
726
750
state.clock = -1 ;
727
751
728
- String description = IRAcUtils::resultAcToString (&results);
752
+ if (loglevelActiveFor (LOG_LEVEL_INFO)) {
753
+ String description = IRAcUtils::resultAcToString (&results);
729
754
730
- if (!description.isEmpty ()) {
731
- if (loglevelActiveFor (LOG_LEVEL_INFO)) {
755
+ if (!description.isEmpty ()) {
732
756
// If we got a human-readable description of the message, display it.
733
- String log ;
734
-
735
- if (log .reserve (10 + description.length ())) {
736
- log += F (" AC State: " );
737
- log += description;
738
- addLogMove (LOG_LEVEL_INFO, log );
739
- }
757
+ addLogMove (LOG_LEVEL_INFO, strformat (F (" AC State: %s" ), description.c_str ()));
740
758
}
741
759
}
742
760
@@ -824,16 +842,15 @@ boolean Plugin_016(uint8_t function, struct EventStruct *event, String& string)
824
842
}
825
843
# endif // P016_P035_Extended_AC
826
844
827
- # if !P016_SEND_IR_TO_CONTROLLER
845
+ # if !P016_SEND_IR_TO_CONTROLLER
828
846
{
829
847
unsigned long IRcode = results.value ;
830
848
UserVar.setSensorTypeLong (event->TaskIndex , IRcode);
831
849
}
832
- # endif
850
+ # endif // if !P016_SEND_IR_TO_CONTROLLER
833
851
sendData (event);
852
+ break ;
834
853
}
835
- success = true ;
836
- break ;
837
854
}
838
855
}
839
856
return success;
@@ -1041,7 +1058,7 @@ unsigned int storeB32Hex(char out[], unsigned int iOut, unsigned int val)
1041
1058
1042
1059
void enableIR_RX (boolean enable)
1043
1060
{
1044
- #ifdef PLUGIN_016
1061
+ #ifdef PLUGIN_016
1045
1062
1046
1063
if (irReceiver == 0 ) { return ; }
1047
1064
@@ -1050,5 +1067,5 @@ void enableIR_RX(boolean enable)
1050
1067
} else {
1051
1068
irReceiver->disableIRIn (); // Stop the receiver
1052
1069
}
1053
- #endif // PLUGIN_016
1070
+ #endif // PLUGIN_016
1054
1071
}
0 commit comments