forked from thomastech/PixelRadio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.cpp
851 lines (724 loc) · 28.2 KB
/
commands.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
/*
File: commands.cpp
Project: PixelRadio, an RBDS/RDS FM Transmitter (QN8027 Digital FM IC)
Version: 1.1.0
Creation: Dec-16-2021
Revised: Jun-13-2022
Revision History: See PixelRadio.cpp
Project Leader: T. Black (thomastech)
Contributors: thomastech, dkulp
(c) copyright T. Black 2021-2022, Licensed under GNU GPL 3.0 and later, under this
license absolutely no warranty is given.
This Code was formatted with the uncrustify extension.
Note 1: The command functions are shared by the three remote controllers: Serial, MQTT, HTTP.
*/
// *************************************************************************************************************************
#include <ArduinoLog.h>
#include "config.h"
#include "PixelRadio.h"
#include "globals.h"
#include "language.h"
#include "QN8027Radio.h"
// *************************************************************************************************************************
// Radio
extern QN8027Radio radio;
// *************************************************************************************************************************
// getControllerStatus(): Returns Hex formatted value that represents which controllers are enabled and which are
// currently sending RadioText.
// Bit D7: Serial Controller is Enabled.
// Bit D6: MQTT Controller is Enabled.
// Bit D5: HTTP Controller is Enabled.
// Bit D4: Local Controller is Enabled.
// Bit D3: Serial Controller is Sending RDS.
// Bit D2: MQTT Controller is Sending RDS.
// Bit D1: HTTP Controller is Sending RDS.
// Bit D0: Local Controller is Sending RDS.
//
uint8_t getControllerStatus(void)
{
uint8_t status = 0;
if (ctrlSerialFlg()) {
status = status | 0x80; // Set Bit D7.
}
if (ctrlMqttFlg) {
status = status | 0x40; // Set Bit D6.
}
if (ctrlHttpFlg) {
status = status | 0x20; // Set Bit D5.
}
if (checkLocalRdsAvail()) {
status = status | 0x10; // Set Bit D4.
}
if (activeTextSerialFlg) {
status = status | 0x08; // Set Bit D3.
}
if (activeTextMqttFlg) {
status = status | 0x04; // Set Bit D2.
}
if (activeTextHttpFlg) {
status = status | 0x02; // Set Bit D1.
}
if (activeTextLocalFlg) {
status = status | 0x01; // Set Bit D0.
}
return status;
}
// *************************************************************************************************************************
// AudioModeCmd(): Set the Mono/Stereo Audio Mode using the Payload String. On exit, return true if success.
bool audioModeCmd(String payloadStr, uint8_t controller)
{
char logBuff[100];
const uint8_t maxSize = CMD_AUD_MAX_SZ;
String controllerStr;
controllerStr = getControllerName(controller);
if (controllerStr.length() == 0) {
Log.errorln("-> audioModeCmd: Undefined Controller!");
return false;
}
payloadStr.trim();
payloadStr.toLowerCase();
if (payloadStr.length() > maxSize) {
payloadStr = payloadStr.substring(0, maxSize);
}
if (payloadStr == CMD_MODE_STER_STR) {
stereoEnbFlg = true;
newAudioModeFlg = true;
updateUiAudioMode();
}
else if (payloadStr == CMD_MODE_MONO_STR) {
stereoEnbFlg = false;
newAudioModeFlg = true;
updateUiAudioMode();
}
else {
sprintf(logBuff, "-> %s Controller: Invalid Audio Mode Payload (%s), Ignored.", controllerStr.c_str(), payloadStr.c_str());
Log.errorln(logBuff);
return false;
}
payloadStr.toUpperCase();
sprintf(logBuff, "-> %s Controller: Audio Mode Set to %s.", controllerStr.c_str(), payloadStr.c_str());
Log.verboseln(logBuff);
return true;
}
// *************************************************************************************************************************
bool frequencyCmd(String payloadStr, uint8_t controller)
{
char logBuff[100];
const uint8_t maxSize = CMD_FREQ_MAX_SZ;
int16_t freq;
String controllerStr;
controllerStr = getControllerName(controller);
if (controllerStr.length() == 0) {
Log.errorln("-> frequencyCmd: Undefined Controller!");
return false;
}
payloadStr.trim();
if (payloadStr.length() > maxSize) {
payloadStr = payloadStr.substring(0, maxSize);
}
freq = payloadStr.toInt();
if ((!strIsUint(payloadStr)) ||
(freq < FM_FREQ_MIN_X10) || (freq > FM_FREQ_MAX_X10)) {
sprintf(logBuff, "-> %s Controller: Invalid Radio Frequency Payload (%s), Ignored.", controllerStr.c_str(), payloadStr.c_str());
Log.errorln(logBuff);
return false;
}
fmFreqX10 = freq;
newFreqFlg = true;
updateUiFrequency();
sprintf(logBuff, "-> %s Controller: Transmit Frequency Set to %2.1fMhz.", controllerStr.c_str(), (float(fmFreqX10)) / 10.0f);
Log.verboseln(logBuff);
return true;
}
// *************************************************************************************************************************
// getControllerName(): Return the Controller's Name. If controller type is invalid then return empty String.
String getControllerName(uint8_t controller)
{
String controllerStr;
if (controller == SERIAL_CNTRL) {
controllerStr = "Serial";
}
else if (controller == MQTT_CNTRL) {
controllerStr = "MQTT";
}
else if (controller == HTTP_CNTRL) {
controllerStr = "HTTP";
}
else if (controller == LOCAL_CNTRL) {
controllerStr = "Local";
}
else {
controllerStr = ""; // Return empty String if invalid controller type.
}
return controllerStr;
}
// *************************************************************************************************************************
// gpioCmd(): Read/Write the User's GPIO Pin States. On exit, return true if success.
bool gpioCmd(String payloadStr, uint8_t controller, uint8_t pin)
{
char logBuff[110];
const uint8_t maxSize = CMD_GPIO_MAX_SZ;
String controllerStr;
String gpioPinStr;
payloadStr.trim();
payloadStr.toLowerCase();
controllerStr = getControllerName(controller);
if (controllerStr.length() == 0) {
Log.errorln("-> gpioCmd: Undefined Controller!");
return false;
}
if (!((pin == GPIO19_PIN) || (pin == GPIO23_PIN) || (pin == GPIO33_PIN))) {
sprintf(logBuff, "-> gpioCmd: %s Controller Used Invalid GPIO Pin (%d), Command Ignored.", controllerStr.c_str(), pin);
Log.errorln(logBuff);
return false;
}
if (payloadStr.length() > maxSize) {
payloadStr = payloadStr.substring(0, maxSize);
}
if (payloadStr == CMD_GPIO_READ_STR) {
sprintf(logBuff, "-> %s Controller: Read GPIO Pin-%d, Value= %d.", controllerStr.c_str(), pin, digitalRead(pin));
Log.infoln(logBuff);
return true;
}
else if (payloadStr == CMD_GPIO_OUT_HIGH_STR) {
if (pin == GPIO19_PIN) {
if ((gpio19BootStr == GPIO_OUT_HI_STR) || (gpio19BootStr == GPIO_OUT_LO_STR)) {
digitalWrite(GPIO19_PIN, HIGH);
gpio19CtrlStr = CMD_GPIO_OUT_HIGH_STR;
sprintf(logBuff, "-> %s Controller: Setting GPIO Pin-%d to %s.", controllerStr.c_str(), pin, CMD_GPIO_OUT_HIGH_STR);
Log.infoln(logBuff);
updateUiGpioMsg(pin, controller);
}
else {
sprintf(logBuff, "-> %s Controller: Cannot Write to GPIO Pin-%d (it is Input Pin).", controllerStr.c_str(), pin);
Log.warningln(logBuff);
return false;
}
}
else if (pin == GPIO23_PIN) {
if ((gpio23BootStr == GPIO_OUT_HI_STR) || (gpio23BootStr == GPIO_OUT_LO_STR)) {
digitalWrite(GPIO23_PIN, HIGH);
gpio23CtrlStr = CMD_GPIO_OUT_HIGH_STR;
sprintf(logBuff, "-> %s Controller: Setting GPIO Pin-%d to %s.", controllerStr.c_str(), pin, CMD_GPIO_OUT_HIGH_STR);
Log.infoln(logBuff);
updateUiGpioMsg(pin, controller);
}
else {
sprintf(logBuff, "-> %s Controller: Cannot Write to GPIO Pin-%d (it is Input Pin).", controllerStr.c_str(), pin);
Log.warningln(logBuff);
return false;
}
}
else if (pin == GPIO33_PIN) {
if ((gpio33BootStr == GPIO_OUT_HI_STR) || (gpio33BootStr == GPIO_OUT_LO_STR)) {
digitalWrite(GPIO33_PIN, HIGH);
gpio33CtrlStr = CMD_GPIO_OUT_HIGH_STR;
sprintf(logBuff, "-> %s Controller: Setting GPIO Pin-%d to %s.", controllerStr.c_str(), pin, CMD_GPIO_OUT_HIGH_STR);
Log.infoln(logBuff);
updateUiGpioMsg(pin, controller);
}
else {
sprintf(logBuff, "-> %s Controller: Cannot Write to GPIO Pin-%d (it is Input Pin).", controllerStr.c_str(), pin);
Log.warningln(logBuff);
return false;
}
}
}
else if (payloadStr == CMD_GPIO_OUT_LOW_STR) {
if (pin == GPIO19_PIN) {
if ((gpio19BootStr == GPIO_OUT_HI_STR) || (gpio19BootStr == GPIO_OUT_LO_STR)) {
digitalWrite(GPIO19_PIN, LOW);
gpio19CtrlStr = CMD_GPIO_OUT_LOW_STR;
sprintf(logBuff, "-> %s Controller: Setting GPIO Pin-%d to %s.", controllerStr.c_str(), pin, CMD_GPIO_OUT_LOW_STR);
Log.infoln(logBuff);
updateUiGpioMsg(pin, controller);
}
else {
sprintf(logBuff, "-> %s Controller: Cannot Write to GPIO Pin-%d (it is Input Pin).", controllerStr.c_str(), pin);
Log.warningln(logBuff);
return false;
}
}
else if (pin == GPIO23_PIN) {
if ((gpio23BootStr == GPIO_OUT_HI_STR) || (gpio23BootStr == GPIO_OUT_LO_STR)) {
digitalWrite(GPIO23_PIN, LOW);
gpio23CtrlStr = CMD_GPIO_OUT_LOW_STR;
sprintf(logBuff, "-> %s Controller: Setting GPIO Pin-%d to %s.", controllerStr.c_str(), pin, CMD_GPIO_OUT_LOW_STR);
Log.infoln(logBuff);
updateUiGpioMsg(pin, controller);
}
else {
sprintf(logBuff, "-> %s Controller: Cannot Write to GPIO Pin-%d (it is Input Pin).", controllerStr.c_str(), pin);
Log.warningln(logBuff);
return false;
}
}
else if (pin == GPIO33_PIN) {
if ((gpio33BootStr == GPIO_OUT_HI_STR) || (gpio33BootStr == GPIO_OUT_LO_STR)) {
digitalWrite(GPIO33_PIN, LOW);
gpio33CtrlStr = CMD_GPIO_OUT_LOW_STR;
sprintf(logBuff, "-> %s Controller: Setting GPIO Pin-%d to %s.", controllerStr.c_str(), pin, CMD_GPIO_OUT_LOW_STR);
Log.infoln(logBuff);
updateUiGpioMsg(pin, controller);
}
else {
sprintf(logBuff, "-> %s Controller: Cannot Write to GPIO Pin-%d (it is Input Pin).", controllerStr.c_str(), pin);
Log.warningln(logBuff);
return false;
}
}
}
else {
sprintf(logBuff, "-> %s Controller: Invalid GPIO Payload (%s), Ignored.", controllerStr.c_str(), payloadStr.c_str());
Log.errorln(logBuff);
return false;
}
return true;
}
// *************************************************************************************************************************
bool infoCmd(String payloadStr, uint8_t controller)
{
char logBuff[100];
const uint8_t maxSize = CMD_SYS_MAX_SZ;
String controllerStr;
controllerStr = getControllerName(controller);
if (controllerStr.length() == 0) {
Log.errorln("-> infoCmd: Undefined Controller!");
return false;
}
payloadStr.trim();
payloadStr.toLowerCase();
if (payloadStr.length() > maxSize) {
payloadStr = payloadStr.substring(0, maxSize);
}
if (payloadStr == CMD_SYS_CODE_STR) {
sprintf(logBuff, "-> %s Controller: Info Command.", controllerStr.c_str());
Log.verboseln(logBuff);
}
else {
sprintf(logBuff, "-> %s Controller: Invalid INFO Payload (%s), Ignored.", controllerStr.c_str(), payloadStr.c_str());
Log.errorln(logBuff);
return false;
}
return true;
}
// *************************************************************************************************************************
// logCmd(): Set the Serial Log Level to Silent or reset back to system (Web UI) setting.
// This command is only used by the Serial Controller; The MQTT and HTTP controllers do not observe this command.
bool logCmd(String payloadStr, uint8_t controller)
{
char logBuff[100];
const uint8_t maxSize = CMD_LOG_MAX_SZ;
String controllerStr;
controllerStr = getControllerName(controller);
if (controllerStr.length() == 0) {
Log.errorln("-> logCmd: Undefined Controller!");
return false;
}
payloadStr.trim();
payloadStr.toLowerCase();
if (payloadStr.length() > maxSize) {
payloadStr = payloadStr.substring(0, maxSize);
}
if (payloadStr == CMD_LOG_SIL_STR) {
sprintf(logBuff, "-> %s Controller: Log Level Set to LOG_LEVEL_SILENT.", controllerStr.c_str());
Log.verboseln(logBuff);
Serial.flush();
Log.begin(LOG_LEVEL_SILENT, &Serial);
Log.setShowLevel(false); // Do not show loglevel, we will do this in the prefix
}
else if (payloadStr == CMD_LOG_RST_STR) {
sprintf(logBuff, "-> %s Controller: Log Level Restored to %s.", controllerStr.c_str(), logLevelStr.c_str());
Log.verboseln(logBuff);
Serial.flush();
Log.begin(getLogLevel(), &Serial);
Log.setShowLevel(false); // Do not show loglevel, we will do this in the prefix
}
else {
sprintf(logBuff, "-> %s Controller: Invalid LOG Payload (%s), Ignored.", controllerStr.c_str(), payloadStr.c_str());
Log.errorln(logBuff);
return false;
}
Serial.flush();
return true;
}
// *************************************************************************************************************************
bool muteCmd(String payloadStr, uint8_t controller)
{
char logBuff[100];
const uint8_t maxSize = CMD_MUTE_MAX_SZ;
String controllerStr;
controllerStr = getControllerName(controller);
if (controllerStr.length() == 0) {
Log.errorln("-> muteCmd: Undefined Controller!");
return false;
}
payloadStr.trim();
payloadStr.toLowerCase();
if (payloadStr.length() > maxSize) {
payloadStr = payloadStr.substring(0, maxSize);
}
if (payloadStr == CMD_MUTE_ON_STR) {
sprintf(logBuff, "-> %s Controller: Mute Set to ON (Audio Off).", controllerStr.c_str());
Log.verboseln(logBuff);
muteFlg = true;
newMuteFlg = true;
updateUiAudioMute();
}
else if (payloadStr == CMD_MUTE_OFF_STR) {
sprintf(logBuff, "-> %s Controller: Mute Set to OFF (Audio On).", controllerStr.c_str());
Log.verboseln(logBuff);
muteFlg = false;
newMuteFlg = true;
updateUiAudioMute();
}
else {
sprintf(logBuff, "-> %s Controller: Invalid MUTE Payload (%s), Ignored.", controllerStr.c_str(), payloadStr.c_str());
Log.errorln(logBuff);
return false;
}
return true;
}
// *************************************************************************************************************************
bool piCodeCmd(String payloadStr, uint8_t controller)
{
char logBuff[100];
const uint8_t maxSize = CMD_PI_MAX_SZ;
uint32_t tempPiCode;
String controllerStr;
controllerStr = getControllerName(controller);
if (controllerStr.length() == 0) {
Log.errorln("-> piCodeCmd: Undefined Controller!");
return false;
}
payloadStr.trim();
if (payloadStr.length() > maxSize) {
payloadStr = payloadStr.substring(0, maxSize);
}
tempPiCode = strtol(payloadStr.c_str(), NULL, HEX);
if ((tempPiCode < RDS_PI_CODE_MIN) || (tempPiCode > RDS_PI_CODE_MAX)) {
sprintf(logBuff, "-> %s Controller: Invalid RDS PI Code Value (%s), Ignored.", controllerStr.c_str(), payloadStr.c_str());
Log.errorln(logBuff);
return false;
}
else {
if (radio.getPiCode() != (uint16_t)(tempPiCode)) { // New PI Code.
if (controller == SERIAL_CNTRL) {
rdsSerialPiCode = tempPiCode;
textSerialFlg = true; // Reload Serial RDS values
}
else if (controller == MQTT_CNTRL) {
rdsMqttPiCode = tempPiCode;
textMqttFlg = true; // Reload MQTT RDS values
}
else if (controller == HTTP_CNTRL) {
rdsHttpPiCode = tempPiCode;
textHttpFlg = true; // Reload HTTP RDS values
}
displaySaveWarning();
sprintf(logBuff, "-> %s Controller: PI Code Set to 0x%04X.", controllerStr.c_str(), tempPiCode);
}
else {
sprintf(logBuff, "-> %s Controller: PI Code Unchanged (0x%04X).", controllerStr.c_str(), tempPiCode);
}
Log.verboseln(logBuff);
}
return true;
}
// *************************************************************************************************************************
bool ptyCodeCmd(String payloadStr, uint8_t controller)
{
char logBuff[100];
const uint8_t maxSize = CMD_PTY_MAX_SZ;
int16_t tempPtyCode;
String controllerStr;
controllerStr = getControllerName(controller);
if (controllerStr.length() == 0) {
Log.errorln("-> ptyCodeCmd: Undefined Controller!");
return false;
}
payloadStr.trim();
if (payloadStr.length() > maxSize) {
payloadStr = payloadStr.substring(0, maxSize);
}
tempPtyCode = payloadStr.toInt();
if ((strIsUint(payloadStr) == false) ||
(tempPtyCode < RDS_PTY_CODE_MIN) ||
(tempPtyCode > RDS_PTY_CODE_MAX)) {
sprintf(logBuff, "-> %s Controller: Invalid RDS PTY Code Value (%s), Ignored.", controllerStr.c_str(), payloadStr.c_str());
Log.errorln(logBuff);
return false;
}
else {
if (radio.getPTYCode() != (uint8_t)(tempPtyCode)) { // New PTY Code.
if (controller == SERIAL_CNTRL) {
rdsSerialPtyCode = (uint8_t)(tempPtyCode);
textSerialFlg = true; // Reload Serial RDS values
}
else if (controller == MQTT_CNTRL) {
rdsMqttPtyCode = (uint8_t)(tempPtyCode);
textMqttFlg = true; // Reload MQTT RDS values
}
else if (controller == HTTP_CNTRL) {
rdsHttpPtyCode = (uint8_t)(tempPtyCode);
textHttpFlg = true; // Reload HTTP RDS values
}
displaySaveWarning();
sprintf(logBuff, "-> %s Controller: PTY Code Set to %d.", controllerStr.c_str(), tempPtyCode);
}
else {
sprintf(logBuff, "-> %s Controller: PTY Code Unchanged (%d).", controllerStr.c_str(), tempPtyCode);
}
Log.verboseln(logBuff);
}
return true;
}
// *************************************************************************************************************************
bool programServiceNameCmd(String payloadStr, uint8_t controller)
{
char logBuff[100];
const uint8_t maxSize = CMD_PSN_MAX_SZ;
String controllerStr;
controllerStr = getControllerName(controller);
if (controllerStr.length() == 0) {
Log.errorln("-> programServiceNameCmd: Undefined Controller!");
return false;
}
payloadStr.trim();
if (payloadStr.length() > maxSize) {
payloadStr = payloadStr.substring(0, maxSize);
}
if (controller == SERIAL_CNTRL) {
rdsSerialPsnStr = payloadStr;
textSerialFlg = true; // Reload Serial RDS values
}
else if (controller == MQTT_CNTRL) {
rdsMqttPsnStr = payloadStr;
textMqttFlg = true; // Reload MQTT RDS values
}
else if (controller == HTTP_CNTRL) {
rdsHttpPsnStr = payloadStr;
textHttpFlg = true; // Reload HTTP RDS values
}
sprintf(logBuff, "-> %s Controller: RDS PSN Set to %s", controllerStr.c_str(), payloadStr.c_str());
Log.verboseln(logBuff);
return true;
}
// *************************************************************************************************************************
bool radioTextCmd(String payloadStr, uint8_t controller)
{
char logBuff[100 + CMD_RT_MAX_SZ];
const uint8_t maxSize = CMD_RT_MAX_SZ;
String controllerStr;
controllerStr = getControllerName(controller);
if (controllerStr.length() == 0) {
Log.errorln("-> radioTextCmd: Undefined Controller!");
return false;
}
payloadStr.trim();
if (payloadStr.length() > maxSize) {
payloadStr = payloadStr.substring(0, maxSize);
}
if (controller == SERIAL_CNTRL) {
textSerialFlg = true; // Reload Serial RDS values
rdsSerialTextStr = payloadStr;
}
else if (controller == MQTT_CNTRL) {
textMqttFlg = true; // Reload MQTT RDS values
rdsMqttTextStr = payloadStr;
}
else if (controller == HTTP_CNTRL) {
textHttpFlg = true; // Reload HTTP RDS values
rdsHttpTextStr = payloadStr;
}
sprintf(logBuff, "-> %s Controller: RadioText Changed to %s", controllerStr.c_str(), payloadStr.c_str());
Log.verboseln(logBuff);
return true;
}
// *************************************************************************************************************************
// rdsTimePeriodCmd(): Set the RadioText Message Display Time. Input value is in seconds.
bool rdsTimePeriodCmd(String payloadStr, uint8_t controller)
{
bool capFlg = false;
char logBuff[100];
int32_t rtTime = 0;
String controllerStr;
controllerStr = getControllerName(controller);
if (controllerStr.length() == 0) {
Log.errorln("-> rdsTimePeriodCmd: Undefined Controller!");
return false;
}
payloadStr.trim();
rtTime = strtol(payloadStr.c_str(), NULL, 10);
if ((payloadStr.length() > CMD_TIME_MAX_SZ) || (rtTime <= 0)) {
Log.errorln("-> RDS Time Period Value is Invalid, Ignored.");
return false;
}
else if (rtTime > RDS_DSP_TM_MAX) {
capFlg = true;
rtTime = RDS_DSP_TM_MAX;
}
else if (rtTime < RDS_DSP_TM_MIN) {
capFlg = true;
rtTime = RDS_DSP_TM_MIN;
}
if (controller == SERIAL_CNTRL) {
textSerialFlg = true; // Restart Serial Controller's RDS.
rdsSerialMsgTime = rtTime * 1000;
}
else if (controller == MQTT_CNTRL) {
textMqttFlg = true; // Restart MQTT Controller's RDS.
rdsMqttMsgTime = rtTime * 1000;
}
else if (controller == HTTP_CNTRL) {
textHttpFlg = true; // Restart HTTP Controller's RDS.
rdsHttpMsgTime = rtTime * 1000;
}
if (capFlg) {
sprintf(logBuff, "-> %s Controller: RDS Time Period Value out-of-range, set to %d secs.", controllerStr.c_str(), rtTime);
}
else {
sprintf(logBuff, "-> %s Controller: RDS Time Period Set to %d Secs.", controllerStr.c_str(), rtTime);
}
Log.verboseln(logBuff);
return true;
}
// *************************************************************************************************************************
bool rebootCmd(String payloadStr, uint8_t controller)
{
char logBuff[100];
const uint8_t maxSize = CMD_SYS_MAX_SZ;
String controllerStr;
controllerStr = getControllerName(controller);
if (controllerStr.length() == 0) {
Log.errorln("-> rebootCmd: Undefined Controller!");
return false;
}
payloadStr.trim();
payloadStr.toLowerCase();
if (payloadStr.length() > maxSize) {
payloadStr = payloadStr.substring(0, maxSize);
}
if (payloadStr == CMD_SYS_CODE_STR) {
sprintf(logBuff, "-> %s Controller: System Rebooted.", controllerStr.c_str());
Log.verboseln(logBuff);
rebootFlg = true; // Request system reboot.
}
else {
sprintf(logBuff, "-> %s Controller: Invalid REBOOT Payload (%s), Ignored.", controllerStr.c_str(), payloadStr.c_str());
Log.errorln(logBuff);
return false;
}
return true;
}
// *************************************************************************************************************************
bool rfCarrierCmd(String payloadStr, uint8_t controller)
{
char logBuff[100];
const uint8_t maxSize = CMD_RF_MAX_SZ;
String controllerStr;
controllerStr = getControllerName(controller);
if (controllerStr.length() == 0) {
Log.errorln("-> rfCarrierCmd: Undefined Controller!");
return false;
}
payloadStr.trim();
payloadStr.toLowerCase();
if (payloadStr.length() > maxSize) {
payloadStr = payloadStr.substring(0, maxSize);
}
if (payloadStr == CMD_RF_ON_STR) {
sprintf(logBuff, "-> %s Controller: RF Carrier Set to ON.", controllerStr.c_str());
Log.verboseln(logBuff);
rfCarrierFlg = true;
newCarrierFlg = true;
updateUiRfCarrier();
}
else if (payloadStr == CMD_RF_OFF_STR) {
sprintf(logBuff, "-> %s Controller: RF Carrier Set to OFF.", controllerStr.c_str());
Log.verboseln(logBuff);
rfCarrierFlg = false;
newCarrierFlg = true;
updateUiRfCarrier();
}
else {
sprintf(logBuff, "-> %s Controller: Invalid RF Carrier Payload (%s), Ignored.", controllerStr.c_str(), payloadStr.c_str());
Log.errorln(logBuff);
return false;
}
return true;
}
// *************************************************************************************************************************
bool startCmd(String payloadStr, uint8_t controller)
{
char logBuff[100];
const uint8_t maxSize = CMD_RDS_MAX_SZ;
String controllerStr;
controllerStr = getControllerName(controller);
if (controllerStr.length() == 0) {
Log.errorln("-> startCmd: Undefined Controller!");
return false;
}
payloadStr.trim();
payloadStr.toLowerCase();
if (payloadStr.length() > maxSize) {
payloadStr = payloadStr.substring(0, maxSize);
}
if (payloadStr == CMD_RDS_CODE_STR) {
sprintf(logBuff, "-> %s Controller: Start RDS.", controllerStr.c_str());
Log.verboseln(logBuff);
if (controller == SERIAL_CNTRL) {
textSerialFlg = true; // Restart Serial Controller's RadioText.
}
else if (controller == MQTT_CNTRL) {
textMqttFlg = true; // Restart MQTT Controller's RadioText.
}
else if (controller == HTTP_CNTRL) {
textHttpFlg = true; // Restart HTTP Controller's RadioText.
}
}
else {
sprintf(logBuff, "-> %s Controller: Invalid START Payload (%s), Ignored.", controllerStr.c_str(), payloadStr.c_str());
Log.errorln(logBuff);
return false;
}
return true;
}
// *************************************************************************************************************************
bool stopCmd(String payloadStr, uint8_t controller)
{
char logBuff[100];
const uint8_t maxSize = CMD_RDS_MAX_SZ;
String controllerStr;
controllerStr = getControllerName(controller);
if (controllerStr.length() == 0) {
Log.errorln("-> stopCmd: Undefined Controller!");
return false;
}
payloadStr.trim();
payloadStr.toLowerCase();
if (payloadStr.length() > maxSize) {
payloadStr = payloadStr.substring(0, maxSize);
}
if (payloadStr == CMD_RDS_CODE_STR) {
sprintf(logBuff, "-> %s Controller: Stop RDS.", controllerStr.c_str());
Log.verboseln(logBuff);
if (controller == SERIAL_CNTRL) {
stopSerialFlg = true; // Restart Serial Controller's RadioText.
}
else if (controller == MQTT_CNTRL) {
stopMqttFlg = true; // Restart MQTT Controller's RadioText.
}
else if (controller == HTTP_CNTRL) {
stopHttpFlg = true; // Restart HTTP Controller's RadioText.
}
}
else {
sprintf(logBuff, "-> %s Controller: Invalid STOP Payload (%s), Ignored.", controllerStr.c_str(), payloadStr.c_str());
Log.errorln(logBuff);
return false;
}
return true;
}
// *************************************************************************************************************************
// EOF