forked from sfeakes/AqualinkD
-
Notifications
You must be signed in to change notification settings - Fork 2
/
json_messages.c
984 lines (859 loc) · 39.7 KB
/
json_messages.c
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
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
/*
* Copyright (c) 2017 Shaun Feakes - All rights reserved
*
* You may use redistribute and/or modify this code under the terms of
* the GNU General Public License version 2 as published by the
* Free Software Foundation. For the terms of this license,
* see <http://www.gnu.org/licenses/>.
*
* You are free to use this software under the terms of the GNU General
* Public License, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* https://github.com/sfeakes/aqualinkd
*/
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "aqualink.h"
#include "config.h"
//#include "aq_programmer.h"
#include "utils.h"
//#include "web_server.h"
#include "json_messages.h"
#include "domoticz.h"
#include "aq_mqtt.h"
#include "devices_jandy.h"
#include "version.h"
#include "aq_timer.h"
#include "aq_programmer.h"
#include "rs_msg_utils.h"
//#define test_message "{\"type\": \"status\",\"version\": \"8157 REV MMM\",\"date\": \"09/01/16 THU\",\"time\": \"1:16 PM\",\"temp_units\": \"F\",\"air_temp\": \"96\",\"pool_temp\": \"86\",\"spa_temp\": \" \",\"battery\": \"ok\",\"pool_htr_set_pnt\": \"85\",\"spa_htr_set_pnt\": \"99\",\"freeze_protection\": \"off\",\"frz_protect_set_pnt\": \"0\",\"leds\": {\"pump\": \"on\",\"spa\": \"off\",\"aux1\": \"off\",\"aux2\": \"off\",\"aux3\": \"off\",\"aux4\": \"off\",\"aux5\": \"off\",\"aux6\": \"off\",\"aux7\": \"off\",\"pool_heater\": \"off\",\"spa_heater\": \"off\",\"solar_heater\": \"off\"}}"
//#define test_labels "{\"type\": \"aux_labels\",\"aux1_label\": \"Cleaner\",\"aux2_label\": \"Waterfall\",\"aux3_label\": \"Spa Blower\",\"aux4_label\": \"Pool Light\",\"aux5_label\": \"Spa Light\",\"aux6_label\": \"Unassigned\",\"aux7_label\": \"Unassigned\"}"
//#define test_message "{\"type\": \"status\",\"version\":\"xx\",\"time\":\"xx\",\"air_temp\":\"0\",\"pool_temp\":\"0\",\"spa_temp\":\"0\",\"pool_htr_set_pnt\":\"0\",\"spa_htr_set_pnt\":\"0\",\"frz_protect_set_pnt\":\"0\",\"temp_units\":\"f\",\"battery\":\"ok\",\"leds\":{\"Filter_Pump\": \"on\",\"Spa_Mode\": \"on\",\"Aux_1\": \"on\",\"Aux_2\": \"on\",\"Aux_3\": \"on\",\"Aux_4\": \"on\",\"Aux_5\": \"on\",\"Aux_6\": \"on\",\"Aux_7\": \"on\",\"Pool_Heater\": \"on\",\"Spa_Heater\": \"on\",\"Solar_Heater\": \"on\"}}"
//{"type": "aux_labels","Pool Pump": "Pool Pump","Spa Mode": "Spa Mode","Cleaner": "Aux 1","Waterfall": "Aux 2","Spa Blower": "Aux 2","Pool Light": "Aux 4","Spa Light ": "Aux 5","Aux 6": "Aux 6","Aux 7": "Aux 7","Heater": "Heater","Heater": "Heater","Solar Heater": "Solar Heater","(null)": "(null)"}
//SPA WILL TURN OFF AFTER COOL DOWN CYCLE
int json_chars(char *dest, const char *src, int dest_len, int src_len)
{
int i;
int end = dest_len < src_len ? dest_len:src_len;
for(i=0; i < end; i++) {
if ( (src[i] < 32 || src[i] > 126) ||
src[i] == 123 || // {
src[i] == 125 || // }
src[i] == 34 || // "
src[i] == 92 // backslash
) // only printable chars
dest[i] = ' ';
else
dest[i] = src[i];
}
i--;
/* // Don't delete trailing whitespace
while (dest[i] == ' ')
i--;
*/
if (dest[i] != '\0') {
if (i < (dest_len-1))
i++;
dest[i] = '\0';
}
return i;
}
int build_logmsg_JSON(char *dest, int loglevel, const char *src, int dest_len, int src_len)
{
int length = sprintf(dest, "{\"logmsg\":\"%-7s",elevel2text(loglevel));
length += json_chars(dest+length, src, (dest_len-20), src_len);
length += sprintf(dest+length, "\"}");
dest[length] = '\0';
//dest[length] = '\n';
//dest[length+1] = '\0';
return length;
}
const char* _getStatus(struct aqualinkdata *aqdata, const char *blankmsg)
{
/*
if (aqdata->active_thread.thread_id != 0 && !aqdata->simulate_panel) {
//return JSON_PROGRAMMING;
return programtypeDisplayName(aqdata->active_thread.ptype);
}
*/
if (aqdata->active_thread.thread_id != 0) {
if (!aqdata->is_display_message_programming || rsm_isempy(aqdata->last_display_message,strlen(aqdata->last_display_message))){
return programtypeDisplayName(aqdata->active_thread.ptype);
}
}
//if (aqdata->last_message != NULL && stristr(aqdata->last_message, "SERVICE") != NULL ) {
if (aqdata->service_mode_state == ON) {
return JSON_SERVICE;
} else if (aqdata->service_mode_state == FLASH) {
return JSON_TIMEOUT;
}
// NSF should probably use json_chars here.
if (aqdata->last_display_message[0] != '\0') {
int i;
for(i=0; i < strlen(aqdata->last_display_message); i++ ) {
if (aqdata->last_display_message[i] <= 31 || aqdata->last_display_message[i] >= 127) {
aqdata->last_display_message[i] = ' ';
} else {
switch (aqdata->last_display_message[i]) {
case '"':
case '/':
case '\n':
case '\t':
case '\f':
case '\r':
case '\b':
aqdata->last_display_message[i] = ' ';
break;
}
}
}
//printf("JSON Sending '%s'\n",aqdata->last_display_message);
return aqdata->last_display_message;
}
/*
if (aqdata->display_last_message == true) {
return aqdata->last_message;
}
*/
return blankmsg;
}
const char* getStatus(struct aqualinkdata *aqdata) {
return _getStatus(aqdata, JSON_READY);
}
/* External version of above */
const char* getAqualinkDStatusMessage(struct aqualinkdata *aqdata) {
return _getStatus(aqdata, " ");
}
int build_mqtt_status_JSON(char* buffer, int size, int idx, int nvalue, float tvalue/*char *svalue*/)
{
memset(&buffer[0], 0, size);
int length = 0;
if (tvalue == TEMP_UNKNOWN) {
length = sprintf(buffer, "{\"idx\":%d,\"nvalue\":%d,\"svalue\":\"\"}", idx, nvalue);
} else {
length = sprintf(buffer, "{\"idx\":%d,\"nvalue\":%d,\"stype\":\"SetPoint\",\"svalue\":\"%.2f\"}", idx, nvalue, tvalue);
}
buffer[length] = '\0';
return strlen(buffer);
}
int build_mqtt_status_message_JSON(char* buffer, int size, int idx, int nvalue, char *svalue)
{
memset(&buffer[0], 0, size);
int length = 0;
//json.htm?type=command¶m=udevice&idx=IDX&nvalue=LEVEL&svalue=TEXT
length = sprintf(buffer, "{\"idx\":%d,\"nvalue\":%d,\"svalue\":\"%s\"}", idx, nvalue, svalue);
buffer[length] = '\0';
return strlen(buffer);
}
int build_aqualink_error_status_JSON(char* buffer, int size, char *msg)
{
//return snprintf(buffer, size, "{\"type\": \"error\",\"status\":\"%s\"}", msg);
return snprintf(buffer, size, "{\"type\": \"status\",\"status\":\"%s\",\"version\":\"xx\",\"time\":\"xx\",\"air_temp\":\"0\",\"pool_temp\":\"0\",\"spa_temp\":\"0\",\"pool_htr_set_pnt\":\"0\",\"spa_htr_set_pnt\":\"0\",\"frz_protect_set_pnt\":\"0\",\"temp_units\":\"f\",\"battery\":\"ok\",\"leds\":{\"Filter_Pump\": \"off\",\"Spa_Mode\": \"off\",\"Aux_1\": \"off\",\"Aux_2\": \"off\",\"Aux_3\": \"off\",\"Aux_4\": \"off\",\"Aux_5\": \"off\",\"Aux_6\": \"off\",\"Aux_7\": \"off\",\"Pool_Heater\": \"off\",\"Spa_Heater\": \"off\",\"Solar_Heater\": \"off\"}}", msg);
}
char *LED2text(aqledstate state)
{
switch (state) {
case ON:
return JSON_ON;
break;
case OFF:
return JSON_OFF;
break;
case FLASH:
return JSON_FLASH;
break;
case ENABLE:
return JSON_ENABLED;
break;
case LED_S_UNKNOWN:
default:
return "unknown";
break;
}
}
int LED2int(aqledstate state)
{
switch (state) {
case ON:
return 1;
break;
case OFF:
return 0;
break;
case FLASH:
return 2;
break;
case ENABLE:
return 3;
break;
case LED_S_UNKNOWN:
default:
return 4;
break;
}
}
#define AUX_BUFFER_SIZE 200
char *get_aux_information(aqkey *button, struct aqualinkdata *aqdata, char *buffer)
{
int i;
int length = 0;
buffer[0] = '\0';
if ((button->special_mask & VS_PUMP) == VS_PUMP)
{
//printf("Button %s is VSP\n", button->name);
for (i=0; i < aqdata->num_pumps; i++) {
if (button == aqdata->pumps[i].button) {
length += sprintf(buffer, ",\"type_ext\":\"switch_vsp\",\"Pump_RPM\":\"%d\",\"Pump_GPM\":\"%d\",\"Pump_Watts\":\"%d\",\"Pump_Type\":\"%s\"",
aqdata->pumps[i].rpm,aqdata->pumps[i].gpm,aqdata->pumps[i].watts,
(aqdata->pumps[i].pumpType==VFPUMP?"vfPump":(aqdata->pumps[i].pumpType==VSPUMP?"vsPump":"ePump")));
return buffer;
}
}
}
else if ((button->special_mask & PROGRAM_LIGHT) == PROGRAM_LIGHT)
{
//printf("Button %s is ProgramableLight\n", button->name);
for (i=0; i < aqdata->num_lights; i++) {
if (button == aqdata->lights[i].button) {
length += sprintf(buffer, ",\"type_ext\": \"switch_program\", \"Light_Type\":\"%d\"", aqdata->lights[i].lightType);
return buffer;
}
}
}
//printf("Button %s is Switch\n", button->name);
length += sprintf(buffer, ",\"type_ext\": \"switch_timer\", \"timer_active\":\"%s\"", (((button->special_mask & TIMER_ACTIVE) == TIMER_ACTIVE)?JSON_ON:JSON_OFF) );
if ((button->special_mask & TIMER_ACTIVE) == TIMER_ACTIVE) {
length += sprintf(buffer+length,",\"timer_duration\":\"%d\"", get_timer_left(button));
}
return buffer;
}
//int build_device_JSON(struct aqualinkdata *aqdata, int programable_switch1, int programable_switch2, char* buffer, int size, bool homekit)
int build_device_JSON(struct aqualinkdata *aqdata, char* buffer, int size, bool homekit)
{
char aux_info[AUX_BUFFER_SIZE];
memset(&buffer[0], 0, size);
int length = 0;
int i;
// IF temp units are F assume homekit is using F
bool homekit_f = (homekit && ( aqdata->temp_units==FAHRENHEIT || aqdata->temp_units == UNKNOWN) );
length += sprintf(buffer+length, "{\"type\": \"devices\"");
length += sprintf(buffer+length, ",\"date\":\"%s\"",aqdata->date );//"09/01/16 THU",
length += sprintf(buffer+length, ",\"time\":\"%s\"",aqdata->time );//"1:16 PM",
if ( aqdata->temp_units == FAHRENHEIT )
length += sprintf(buffer+length, ",\"temp_units\":\"%s\"",JSON_FAHRENHEIT );
else if ( aqdata->temp_units == CELSIUS )
length += sprintf(buffer+length, ",\"temp_units\":\"%s\"", JSON_CELSIUS);
else
length += sprintf(buffer+length, ",\"temp_units\":\"%s\"",JSON_UNKNOWN );
length += sprintf(buffer+length, ", \"devices\": [");
for (i=0; i < aqdata->total_buttons; i++)
{
if ( strcmp(BTN_POOL_HTR,aqdata->aqbuttons[i].name) == 0 && (_aqconfig_.force_ps_setpoints || aqdata->pool_htr_set_point != TEMP_UNKNOWN)) {
length += sprintf(buffer+length, "{\"type\": \"setpoint_thermo\", \"id\": \"%s\", \"name\": \"%s\", \"state\": \"%s\", \"status\": \"%s\", \"spvalue\": \"%.*f\", \"value\": \"%.*f\", \"int_status\": \"%d\", \"timer_active\":\"%s\" },",
aqdata->aqbuttons[i].name,
aqdata->aqbuttons[i].label,
aqdata->aqbuttons[i].led->state==ON?JSON_ON:JSON_OFF,
LED2text(aqdata->aqbuttons[i].led->state),
((homekit)?2:0),
((homekit_f)?degFtoC(aqdata->pool_htr_set_point):aqdata->pool_htr_set_point),
((homekit)?2:0),
((homekit_f)?degFtoC(aqdata->pool_temp):aqdata->pool_temp),
LED2int(aqdata->aqbuttons[i].led->state),
((aqdata->aqbuttons[i].special_mask & TIMER_ACTIVE) == TIMER_ACTIVE?JSON_ON:JSON_OFF) );
} else if ( strcmp(BTN_SPA_HTR,aqdata->aqbuttons[i].name)==0 && (_aqconfig_.force_ps_setpoints || aqdata->spa_htr_set_point != TEMP_UNKNOWN)) {
length += sprintf(buffer+length, "{\"type\": \"setpoint_thermo\", \"id\": \"%s\", \"name\": \"%s\", \"state\": \"%s\", \"status\": \"%s\", \"spvalue\": \"%.*f\", \"value\": \"%.*f\", \"int_status\": \"%d\", \"timer_active\":\"%s\" },",
aqdata->aqbuttons[i].name,
aqdata->aqbuttons[i].label,
aqdata->aqbuttons[i].led->state==ON?JSON_ON:JSON_OFF,
LED2text(aqdata->aqbuttons[i].led->state),
((homekit)?2:0),
((homekit_f)?degFtoC(aqdata->spa_htr_set_point):aqdata->spa_htr_set_point),
((homekit)?2:0),
((homekit_f)?degFtoC(aqdata->spa_temp):aqdata->spa_temp),
LED2int(aqdata->aqbuttons[i].led->state),
((aqdata->aqbuttons[i].special_mask & TIMER_ACTIVE) == TIMER_ACTIVE?JSON_ON:JSON_OFF));
} else {
get_aux_information(&aqdata->aqbuttons[i], aqdata, aux_info);
//length += sprintf(buffer+length, "{\"type\": \"switch\", \"type_ext\": \"switch_vsp\", \"id\": \"%s\", \"name\": \"%s\", \"state\": \"%s\", \"status\": \"%s\", \"int_status\": \"%d\" %s},",
length += sprintf(buffer+length, "{\"type\": \"switch\", \"id\": \"%s\", \"name\": \"%s\", \"state\": \"%s\", \"status\": \"%s\", \"int_status\": \"%d\" %s},",
aqdata->aqbuttons[i].name,
aqdata->aqbuttons[i].label,
aqdata->aqbuttons[i].led->state==ON?JSON_ON:JSON_OFF,
LED2text(aqdata->aqbuttons[i].led->state),
LED2int(aqdata->aqbuttons[i].led->state),
aux_info);
}
/*
} else if ( (programable_switch1 > 0 && programable_switch1 == i) ||
(programable_switch2 > 0 && programable_switch2 == i)) {
length += sprintf(buffer+length, "{\"type\": \"switch\", \"type_ext\": \"switch_program\", \"id\": \"%s\", \"name\": \"%s\", \"state\": \"%s\", \"status\": \"%s\", \"int_status\": \"%d\"},",
aqdata->aqbuttons[i].name,
aqdata->aqbuttons[i].label,
aqdata->aqbuttons[i].led->state==ON?JSON_ON:JSON_OFF,
LED2text(aqdata->aqbuttons[i].led->state),
LED2int(aqdata->aqbuttons[i].led->state));
} else {
if ( get_aux_information(&aqdata->aqbuttons[i], aqdata, aux_info)[0] == '\0' ) {
length += sprintf(buffer+length, "{\"type\": \"switch\", \"type_ext\": \"switch\", \"id\": \"%s\", \"name\": \"%s\", \"state\": \"%s\", \"status\": \"%s\", \"int_status\": \"%d\"},",
aqdata->aqbuttons[i].name,
aqdata->aqbuttons[i].label,
aqdata->aqbuttons[i].led->state==ON?JSON_ON:JSON_OFF,
LED2text(aqdata->aqbuttons[i].led->state),
LED2int(aqdata->aqbuttons[i].led->state));
} else {
length += sprintf(buffer+length, "{\"type\": \"switch\", \"type_ext\": \"switch_vsp\", \"id\": \"%s\", \"name\": \"%s\", \"state\": \"%s\", \"status\": \"%s\", \"int_status\": \"%d\" %s},",
aqdata->aqbuttons[i].name,
aqdata->aqbuttons[i].label,
aqdata->aqbuttons[i].led->state==ON?JSON_ON:JSON_OFF,
LED2text(aqdata->aqbuttons[i].led->state),
LED2int(aqdata->aqbuttons[i].led->state),
aux_info);
//get_aux_information(&aqdata->aqbuttons[i], aqdata, aux_info));
}
}*/
}
if ( _aqconfig_.force_frzprotect_setpoints || (aqdata->frz_protect_set_point != TEMP_UNKNOWN && aqdata->air_temp != TEMP_UNKNOWN) ) {
length += sprintf(buffer+length, "{\"type\": \"setpoint_freeze\", \"id\": \"%s\", \"name\": \"%s\", \"state\": \"%s\", \"status\": \"%s\", \"spvalue\": \"%.*f\", \"value\": \"%.*f\", \"int_status\": \"%d\" },",
FREEZE_PROTECT,
"Freeze Protection",
//JSON_OFF,
aqdata->frz_protect_state==ON?JSON_ON:JSON_OFF,
//JSON_ENABLED,
aqdata->frz_protect_state==ON?LED2text(ON):LED2text(ENABLE),
((homekit)?2:0),
((homekit_f)?degFtoC(aqdata->frz_protect_set_point):aqdata->frz_protect_set_point),
((homekit)?2:0),
((homekit_f)?degFtoC(aqdata->air_temp):aqdata->air_temp),
aqdata->frz_protect_state==ON?1:0);
}
if (aqdata->swg_led_state != LED_S_UNKNOWN) {
if ( aqdata->swg_percent != TEMP_UNKNOWN ) {
length += sprintf(buffer+length, "{\"type\": \"setpoint_swg\", \"id\": \"%s\", \"name\": \"%s\", \"state\": \"%s\", \"status\": \"%s\", \"spvalue\": \"%.*f\", \"value\": \"%.*f\", \"int_status\": \"%d\" },",
SWG_TOPIC,
"Salt Water Generator",
//aqdata->ar_swg_status == SWG_STATUS_OFF?JSON_OFF:JSON_ON,
aqdata->swg_led_state == OFF?JSON_OFF:JSON_ON,
//LED2text(get_swg_led_state(aqdata)),
LED2text(aqdata->swg_led_state),
((homekit)?2:0),
((homekit_f)?degFtoC(aqdata->swg_percent):aqdata->swg_percent),
((homekit)?2:0),
((homekit_f)?degFtoC(aqdata->swg_percent):aqdata->swg_percent),
LED2int(aqdata->swg_led_state) );
//aqdata->ar_swg_status == SWG_STATUS_OFF?LED2int(OFF):LED2int(ON));
//length += sprintf(buffer+length, "{\"type\": \"value\", \"id\": \"%s\", \"name\": \"%s\", \"state\": \"%s\", \"value\": \"%d\" },",
length += sprintf(buffer+length, "{\"type\": \"value\", \"id\": \"%s\", \"name\": \"%s\", \"state\": \"%s\", \"value\": \"%.*f\" },",
((homekit_f)?SWG_PERCENT_F_TOPIC:SWG_PERCENT_TOPIC),
"Salt Water Generator Percent",
"on",
((homekit_f)?2:0),
((homekit_f)?degFtoC(aqdata->swg_percent):aqdata->swg_percent));
//if (!homekit) { // For the moment keep boost off homekit
length += sprintf(buffer+length, "{\"type\": \"switch\", \"id\": \"%s\", \"name\": \"%s\", \"state\": \"%s\", \"status\": \"%s\", \"int_status\": \"%d\"},",
SWG_BOOST_TOPIC,
"SWG Boost",
aqdata->boost?JSON_ON:JSON_OFF,
aqdata->boost?JSON_ON:JSON_OFF,
aqdata->boost?LED2int(ON):LED2int(OFF));
//}
}
if ( aqdata->swg_ppm != TEMP_UNKNOWN ) {
length += sprintf(buffer+length, "{\"type\": \"value\", \"id\": \"%s\", \"name\": \"%s\", \"state\": \"%s\", \"value\": \"%.*f\" },",
((homekit_f)?SWG_PPM_F_TOPIC:SWG_PPM_TOPIC),
"Salt Level PPM",
"on",
((homekit)?2:0),
((homekit_f)?roundf(degFtoC(aqdata->swg_ppm)):aqdata->swg_ppm));
/*
length += sprintf(buffer+length, "{\"type\": \"value\", \"id\": \"%s\", \"name\": \"%s\", \"state\": \"%s\", \"value\": \"%d\" },",
SWG_PPM_TOPIC,
"Salt Level PPM",
"on",
aqdata->swg_ppm);
*/
}
}
if ( aqdata->ph != TEMP_UNKNOWN ) {
length += sprintf(buffer+length, "{\"type\": \"value\", \"id\": \"%s\", \"name\": \"%s\", \"state\": \"%s\", \"value\": \"%.*f\" },",
((homekit_f)?CHRM_PH_F_TOPIC:CHEM_PH_TOPIC),
"Water Chemistry pH",
"on",
((homekit)?2:1),
((homekit_f)?(degFtoC(aqdata->ph)):aqdata->ph));
}
if ( aqdata->orp != TEMP_UNKNOWN ) {
length += sprintf(buffer+length, "{\"type\": \"value\", \"id\": \"%s\", \"name\": \"%s\", \"state\": \"%s\", \"value\": \"%.*f\" },",
((homekit_f)?CHRM_ORP_F_TOPIC:CHEM_ORP_TOPIC),
"Water Chemistry ORP",
"on",
((homekit)?2:0),
((homekit_f)?(degFtoC(aqdata->orp)):aqdata->orp));
}
length += sprintf(buffer+length, "{\"type\": \"temperature\", \"id\": \"%s\", \"name\": \"%s\", \"state\": \"%s\", \"value\": \"%.*f\" },",
AIR_TEMP_TOPIC,
/*AIR_TEMPERATURE,*/
"Pool Air Temperature",
"on",
((homekit)?2:0),
((homekit_f)?degFtoC(aqdata->air_temp):aqdata->air_temp));
length += sprintf(buffer+length, "{\"type\": \"temperature\", \"id\": \"%s\", \"name\": \"%s\", \"state\": \"%s\", \"value\": \"%.*f\" },",
POOL_TEMP_TOPIC,
/*POOL_TEMPERATURE,*/
"Pool Water Temperature",
"on",
((homekit)?2:0),
((homekit_f)?degFtoC(aqdata->pool_temp):aqdata->pool_temp));
length += sprintf(buffer+length, "{\"type\": \"temperature\", \"id\": \"%s\", \"name\": \"%s\", \"state\": \"%s\", \"value\": \"%.*f\" }",
SPA_TEMP_TOPIC,
/*SPA_TEMPERATURE,*/
"Spa Water Temperature",
"on",
((homekit)?2:0),
((homekit_f)?degFtoC(aqdata->spa_temp):aqdata->spa_temp));
/*
length += sprintf(buffer+length, "], \"aux_device_detail\": [");
for (i=0; i < MAX_PUMPS; i++) {
}
*/
length += sprintf(buffer+length, "]}");
LOG(NET_LOG,LOG_DEBUG, "JSON: %s used %d of %d\n", homekit?"homebridge":"web", length, size);
buffer[length] = '\0';
return strlen(buffer);
//return length;
}
int logmaskjsonobject(int16_t flag, char* buffer)
{
int length = sprintf(buffer, "{\"name\":\"%s\",\"id\":\"%d\",\"set\":\"%s\"},", logmask2name(flag), flag,(isDebugLogMaskSet(flag)?JSON_ON:JSON_OFF));
return length;
}
int logleveljsonobject(int level, char* buffer)
{
int length = sprintf(buffer, "{\"name\":\"%s\",\"id\":\"%d\",\"set\":\"%s\"},", loglevel2name(level), level,(getSystemLogLevel()==level?JSON_ON:JSON_OFF));
return length;
}
int build_aqualink_aqmanager_JSON(struct aqualinkdata *aqdata, char* buffer, int size)
{
memset(&buffer[0], 0, size);
int length = 0;
length += sprintf(buffer+length, "{\"type\": \"aqmanager\"");
length += sprintf(buffer+length, ",\"deamonized\": \"%s\"", (_aqconfig_.deamonize?JSON_ON:JSON_OFF) );
/*
length += sprintf(buffer+length, ",\"panel_type\":\"%s\"",getPanelString());
length += sprintf(buffer+length, ",\"version\":\"%s\"",aqdata->version );//8157 REV MMM",
length += sprintf(buffer+length, ",\"aqualinkd_version\":\"%s\"", AQUALINKD_VERSION ); //1.0b,
*/
//length += sprintf(buffer+length, ",\"logging2file\": \"%s\"",islogFileReady()?JSON_ON:JSON_OFF);
//length += sprintf(buffer+length, ",\"logfileready\": \"%s\"",islogFileReady()?JSON_ON:JSON_OFF);
//length += sprintf(buffer+length, ",\"logfilename\": \"%s\"",_aqconfig_.log_file);
length += sprintf(buffer+length, ",\"debugmasks\":[");
length += logmaskjsonobject(AQUA_LOG, buffer+length);
length += logmaskjsonobject(NET_LOG, buffer+length);
length += logmaskjsonobject(ALLB_LOG, buffer+length);
length += logmaskjsonobject(ONET_LOG, buffer+length);
length += logmaskjsonobject(IAQT_LOG, buffer+length);
length += logmaskjsonobject(PDA_LOG, buffer+length);
length += logmaskjsonobject(RSSA_LOG, buffer+length);
length += logmaskjsonobject(DJAN_LOG, buffer+length);
length += logmaskjsonobject(DPEN_LOG, buffer+length);
length += logmaskjsonobject(RSSD_LOG, buffer+length);
length += logmaskjsonobject(PROG_LOG, buffer+length);
length += logmaskjsonobject(SCHD_LOG, buffer+length);
length += logmaskjsonobject(RSTM_LOG, buffer+length);
length += logmaskjsonobject(SIM_LOG, buffer+length);
// DBGT_LOG is a compile time only, so don;t include
if (buffer[length-1] == ',')
length--;
length += sprintf(buffer+length, "]");
length += sprintf(buffer+length, ",\"loglevels\":[");
length += logleveljsonobject(LOG_DEBUG_SERIAL, buffer+length);
length += logleveljsonobject(LOG_DEBUG, buffer+length);
length += logleveljsonobject(LOG_INFO, buffer+length);
length += logleveljsonobject(LOG_NOTICE, buffer+length);
length += logleveljsonobject(LOG_WARNING, buffer+length);
length += logleveljsonobject(LOG_ERR, buffer+length);
if (buffer[length-1] == ',')
length--;
length += sprintf(buffer+length, "]");
length += sprintf(buffer+length, "}");
return length;
}
int build_aqualink_status_JSON(struct aqualinkdata *aqdata, char* buffer, int size)
{
//strncpy(buffer, test_message, strlen(test_message)+1);
//return strlen(test_message);
//char buffer2[600];
memset(&buffer[0], 0, size);
int length = 0;
int i;
length += sprintf(buffer+length, "{\"type\": \"status\"");
length += sprintf(buffer+length, ",\"status\":\"%s\"",getStatus(aqdata) );
length += sprintf(buffer+length, ",\"panel_message\":\"%s\"",aqdata->last_message );
length += sprintf(buffer+length, ",\"panel_type\":\"%s\"",getPanelString());
//length += sprintf(buffer+length, ",\"message\":\"%s\"",aqdata->message );
length += sprintf(buffer+length, ",\"version\":\"%s\"",aqdata->version );//8157 REV MMM",
length += sprintf(buffer+length, ",\"aqualinkd_version\":\"%s (rev %s)\"", AQUALINKD_VERSION, GIT_HASH); //1.0b,
length += sprintf(buffer+length, ",\"date\":\"%s\"",aqdata->date );//"09/01/16 THU",
length += sprintf(buffer+length, ",\"time\":\"%s\"",aqdata->time );//"1:16 PM",
//length += sprintf(buffer+length, ",\"air_temp\":\"%d\"",aqdata->air_temp );//"96",
//length += sprintf(buffer+length, ",\"pool_temp\":\"%d\"",aqdata->pool_temp );//"86",
//length += sprintf(buffer+length, ",\"spa_temp\":\"%d\"",aqdata->spa_temp );//" ",
length += sprintf(buffer+length, ",\"pool_htr_set_pnt\":\"%d\"",aqdata->pool_htr_set_point );//"85",
length += sprintf(buffer+length, ",\"spa_htr_set_pnt\":\"%d\"",aqdata->spa_htr_set_point );//"99",
//length += sprintf(buffer+length, ",\"freeze_protection":\"%s\"",aqdata->frz_protect_set_point );//"off",
length += sprintf(buffer+length, ",\"frz_protect_set_pnt\":\"%d\"",aqdata->frz_protect_set_point );//"0",
if ( aqdata->air_temp == TEMP_UNKNOWN )
length += sprintf(buffer+length, ",\"air_temp\":\" \"");
else
length += sprintf(buffer+length, ",\"air_temp\":\"%d\"",aqdata->air_temp );
if ( aqdata->pool_temp == TEMP_UNKNOWN )
length += sprintf(buffer+length, ",\"pool_temp\":\" \"");
else
length += sprintf(buffer+length, ",\"pool_temp\":\"%d\"",aqdata->pool_temp );
if ( aqdata->spa_temp == TEMP_UNKNOWN )
length += sprintf(buffer+length, ",\"spa_temp\":\" \"");
else
length += sprintf(buffer+length, ",\"spa_temp\":\"%d\"",aqdata->spa_temp );
if (aqdata->swg_led_state != LED_S_UNKNOWN) {
if ( aqdata->swg_percent != TEMP_UNKNOWN )
length += sprintf(buffer+length, ",\"swg_percent\":\"%d\"",aqdata->swg_percent );
if ( aqdata->swg_ppm != TEMP_UNKNOWN )
length += sprintf(buffer+length, ",\"swg_ppm\":\"%d\"",aqdata->swg_ppm );
}
if ( aqdata->temp_units == FAHRENHEIT )
length += sprintf(buffer+length, ",\"temp_units\":\"%s\"",JSON_FAHRENHEIT );
else if ( aqdata->temp_units == CELSIUS )
length += sprintf(buffer+length, ",\"temp_units\":\"%s\"", JSON_CELSIUS);
else
length += sprintf(buffer+length, ",\"temp_units\":\"%s\"",JSON_UNKNOWN );
if (aqdata->battery == OK)
length += sprintf(buffer+length, ",\"battery\":\"%s\"",JSON_OK );//"ok",
else
length += sprintf(buffer+length, ",\"battery\":\"%s\"",JSON_LOW );//"ok",
if ( aqdata->swg_percent == 101 )
length += sprintf(buffer+length, ",\"swg_boost_msg\":\"%s\"",aqdata->boost_msg );
if ( aqdata->ph != TEMP_UNKNOWN )
length += sprintf(buffer+length, ",\"chem_ph\":\"%.1f\"",aqdata->ph );
if ( aqdata->orp != TEMP_UNKNOWN )
length += sprintf(buffer+length, ",\"chem_orp\":\"%d\"",aqdata->orp );
//if ( READ_RSDEV_SWG )
length += sprintf(buffer+length, ",\"swg_fullstatus\": \"%d\"", aqdata->ar_swg_device_status);
length += sprintf(buffer+length, ",\"leds\":{" );
for (i=0; i < aqdata->total_buttons; i++)
{
char *state = LED2text(aqdata->aqbuttons[i].led->state);
length += sprintf(buffer+length, "\"%s\": \"%s\"", aqdata->aqbuttons[i].name, state);
if (i+1 < aqdata->total_buttons)
length += sprintf(buffer+length, "," );
}
if ( aqdata->swg_percent != TEMP_UNKNOWN && aqdata->swg_led_state != LED_S_UNKNOWN ) {
//length += sprintf(buffer+length, ", \"%s\": \"%s\"", SWG_TOPIC, LED2text(get_swg_led_state(aqdata)));
length += sprintf(buffer+length, ", \"%s\": \"%s\"", SWG_TOPIC, LED2text(aqdata->swg_led_state));
//length += sprintf(buffer+length, ", \"%s\": \"%s\"", SWG_TOPIC, aqdata->ar_swg_status == SWG_STATUS_OFF?JSON_OFF:JSON_ON);
length += sprintf(buffer+length, ", \"%s\": \"%s\"", SWG_BOOST_TOPIC, aqdata->boost?JSON_ON:JSON_OFF);
}
//NSF Need to come back and read what the display states when Freeze protection is on
if ( aqdata->frz_protect_set_point != TEMP_UNKNOWN || _aqconfig_.force_frzprotect_setpoints ) {
//length += sprintf(buffer+length, ", \"%s\": \"%s\"", FREEZE_PROTECT, aqdata->frz_protect_state==ON?JSON_ON:JSON_ENABLED);
length += sprintf(buffer+length, ", \"%s\": \"%s\"", FREEZE_PROTECT, LED2text(aqdata->frz_protect_state) );
}
//length += sprintf(buffer+length, "}, \"extra\":{" );
length += sprintf(buffer+length, "},");
// NSF Check below needs to be for VSP Pump (any state), not just known state
for (i=0; i < aqdata->num_pumps; i++) {
/* NSF There is a problem here that needs to be fixed.
printf("Loop %d Message '%s'\n",i,buffer);
printf("Pump Label %s\n",aqdata->pumps[i].button->label);
printf("Pump Name %s\n",aqdata->pumps[i].button->name);
printf("Pump RPM %d\n",aqdata->pumps[i].rpm);
printf("Pump GPM %d\n",aqdata->pumps[i].gpm);
printf("Pump GPM %d\n",aqdata->pumps[i].watts);
printf("Pump Type %d\n",aqdata->pumps[i].pumpType);
*/
if (aqdata->pumps[i].pumpType != PT_UNKNOWN && (aqdata->pumps[i].rpm != TEMP_UNKNOWN || aqdata->pumps[i].gpm != TEMP_UNKNOWN || aqdata->pumps[i].watts != TEMP_UNKNOWN)) {
length += sprintf(buffer+length, "\"Pump_%d\":{\"name\":\"%s\",\"id\":\"%s\",\"RPM\":\"%d\",\"GPM\":\"%d\",\"Watts\":\"%d\",\"Pump_Type\":\"%s\"},",
i+1,aqdata->pumps[i].button->label,aqdata->pumps[i].button->name,aqdata->pumps[i].rpm,aqdata->pumps[i].gpm,aqdata->pumps[i].watts,
(aqdata->pumps[i].pumpType==VFPUMP?"vfPump":(aqdata->pumps[i].pumpType==VSPUMP?"vsPump":"ePump")));
}
}
if (buffer[length-1] == ',')
length--;
length += sprintf(buffer+length, ",\"timers\":{" );
for (i=0; i < aqdata->total_buttons; i++)
{
if ((aqdata->aqbuttons[i].special_mask & TIMER_ACTIVE) == TIMER_ACTIVE) {
length += sprintf(buffer+length, "\"%s\": \"on\",", aqdata->aqbuttons[i].name);
//length += sprintf(buffer+length, "\"%s_duration\": \"%d\",", aqdata->aqbuttons[i].name, get_timer_left(&aqdata->aqbuttons[i]) );
}
}
if (buffer[length-1] == ',')
length--;
length += sprintf(buffer+length, "}");
length += sprintf(buffer+length, ",\"timer_durations\":{" );
for (i=0; i < aqdata->total_buttons; i++)
{
if ((aqdata->aqbuttons[i].special_mask & TIMER_ACTIVE) == TIMER_ACTIVE) {
length += sprintf(buffer+length, "\"%s\": \"%d\",", aqdata->aqbuttons[i].name, get_timer_left(&aqdata->aqbuttons[i]) );
}
}
if (buffer[length-1] == ',')
length--;
length += sprintf(buffer+length, "}");
length += sprintf(buffer+length, "}" );
buffer[length] = '\0';
return strlen(buffer);
}
int build_aux_labels_JSON(struct aqualinkdata *aqdata, char* buffer, int size)
{
memset(&buffer[0], 0, size);
int length = 0;
int i;
length += sprintf(buffer+length, "{\"type\": \"aux_labels\"");
for (i=0; i < aqdata->total_buttons; i++)
{
length += sprintf(buffer+length, ",\"%s\": \"%s\"", aqdata->aqbuttons[i].name, aqdata->aqbuttons[i].label);
}
length += sprintf(buffer+length, "}");
return length;
//printf("%s\n",buffer);
//return strlen(buffer);
}
/*
const char* emulationtype2name(emulation_type type) {
switch (type) {
case ALLBUTTON:
return "allbutton";
break;
case RSSADAPTER:
return "allbutton";
break;
case ONETOUCH:
return "onetouch";
break;
case IAQTOUCH:
return "iaqualinktouch";
break;
case AQUAPDA:
return "aquapda";
break;
case JANDY_DEVICE:
return "jandydevice";
break;
case SIMULATOR:
return "allbutton";
break;
default:
return "none";
break;
}
}
*/
int build_aqualink_simulator_packet_JSON(struct aqualinkdata *aqdata, char* buffer, int size)
{
memset(&buffer[0], 0, size);
int length = 0;
int i;
length += sprintf(buffer+length, "{\"type\": \"simpacket\"");
if (aqdata->simulator_packet[PKT_DEST] >= 0x40 && aqdata->simulator_packet[PKT_DEST] <= 0x43) {
length += sprintf(buffer+length, ",\"simtype\": \"onetouch\"");
} else if (aqdata->simulator_packet[PKT_DEST] >= 0x08 && aqdata->simulator_packet[PKT_DEST] <= 0x0a) {
length += sprintf(buffer+length, ",\"simtype\": \"allbutton\"");
} else if (aqdata->simulator_packet[PKT_DEST] >= 0x30 && aqdata->simulator_packet[PKT_DEST] <= 0x33) {
length += sprintf(buffer+length, ",\"simtype\": \"iaqtouch\"");
} else if (aqdata->simulator_packet[PKT_DEST] >= 0x60 && aqdata->simulator_packet[PKT_DEST] <= 0x63) {
length += sprintf(buffer+length, ",\"simtype\": \"aquapda\"");
} else {
length += sprintf(buffer+length, ",\"simtype\": \"unknown\"");
}
//if (aqdata->simulator_packet[i][])
//length += sprintf(buffer+length, ",\"simtype\": \"onetouch\"");
length += sprintf(buffer+length, ",\"raw\": [");
for (i=0; i < aqdata->simulator_packet_length; i++)
{
length += sprintf(buffer+length, "\"0x%02hhx\",", aqdata->simulator_packet[i]);
}
if (buffer[length-1] == ',')
length--;
length += sprintf(buffer+length, "]");
length += sprintf(buffer+length, ",\"dec\": [");
for (i=0; i < aqdata->simulator_packet_length; i++)
{
length += sprintf(buffer+length, "%d,", aqdata->simulator_packet[i]);
}
if (buffer[length-1] == ',')
length--;
length += sprintf(buffer+length, "]");
length += sprintf(buffer+length, "}");
//printf("Buffer=%d, used=%d, OUT='%s'\n",size,length,buffer);
return length;
}
// WS Received '{"parameter":"SPA_HTR","value":99}'
// WS Received '{"command":"KEY_HTR_POOL"}'
// WS Received '{"command":"GET_AUX_LABELS"}'
bool parseJSONrequest(char *buffer, struct JSONkvptr *request)
{
int i=0;
int found=0;
bool reading = false;
request->kv[0].key = NULL;
request->kv[0].value = NULL;
request->kv[1].key = NULL;
request->kv[1].value = NULL;
request->kv[2].key = NULL;
request->kv[2].value = NULL;
request->kv[3].key = NULL;
request->kv[3].value = NULL;
int length = strlen(buffer);
while ( i < length )
{
//printf ("Reading %c",buffer[i]);
switch (buffer[i]) {
case '{':
case '"':
case '}':
case ':':
case ',':
case ' ':
// Ignore space , : if reading a string
if (reading == true && buffer[i] != ' ' && buffer[i] != ',' && buffer[i] != ':'){
//printf (" <- END");
reading = false;
buffer[i] = '\0';
found++;
}
break;
default:
if (reading == false) {
//printf (" <- START");
reading = true;
if ( found%2 == 0 )
request->kv[found / 2].key = &buffer[i];
else
request->kv[(found-1) / 2].value = &buffer[i];
}
break;
}
//printf ("\n");
if (found >= 8)
break;
i++;
}
return true;
}
bool parseJSONwebrequest(char *buffer, struct JSONwebrequest *request)
{
int i=0;
int found=0;
bool reading = false;
request->first.key = NULL;
request->first.value = NULL;
request->second.key = NULL;
request->second.value = NULL;
request->third.key = NULL;
request->third.value = NULL;
int length = strlen(buffer);
while ( i < length )
{
//printf ("Reading %c",buffer[i]);
switch (buffer[i]) {
case '{':
case '"':
case '}':
case ':':
case ',':
case ' ':
// Ignore space , : if reading a string
if (reading == true && buffer[i] != ' ' && buffer[i] != ',' && buffer[i] != ':'){
//printf (" <- END");
reading = false;
buffer[i] = '\0';
found++;
}
break;
default:
if (reading == false) {
//printf (" <- START");
reading = true;
switch(found) {
case 0:
request->first.key = &buffer[i];
break;
case 1:
request->first.value = &buffer[i];
break;
case 2:
request->second.key = &buffer[i];
break;
case 3:
request->second.value = &buffer[i];
break;
case 4:
request->third.key = &buffer[i];
break;
case 5:
request->third.value = &buffer[i];
break;
}
}
break;
}
//printf ("\n");
// if (found >= 4)
if (found >= 6)
break;
i++;
}
return true;
}
bool parseJSONmqttrequest(const char *str, size_t len, int *idx, int *nvalue, char *svalue) {
unsigned int i = 0;
int found = 0;
svalue[0] = '\0';
for (i = 0; i < len && str[i] != '\0'; i++) {
if (str[i] == '"') {
if (strncmp("\"idx\"", (char *)&str[i], 5) == 0) {
i = i + 5;
for (; str[i] != ',' && str[i] != '\0'; i++) {
if (str[i] == ':') {
*idx = atoi(&str[i + 1]);
found++;
}
}
//if (*idx == 45)
// printf("%s\n",str);
} else if (strncmp("\"nvalue\"", (char *)&str[i], 8) == 0) {
i = i + 8;
for (; str[i] != ',' && str[i] != '\0'; i++) {
if (str[i] == ':') {
*nvalue = atoi(&str[i + 1]);
found++;
}
}
} else if (strncmp("\"svalue1\"", (char *)&str[i], 9) == 0) {
i = i + 9;
for (; str[i] != ',' && str[i] != '\0'; i++) {
if (str[i] == ':') {
while(str[i] == ':' || str[i] == ' ' || str[i] == '"' || str[i] == '\'') i++;
int j=i+1;
while(str[j] != '"' && str[j] != '\'' && str[j] != ',' && str[j] != '}') j++;
strncpy(svalue, &str[i], ((j-i)>DZ_SVALUE_LEN?DZ_SVALUE_LEN:(j-i)));
svalue[((j-i)>DZ_SVALUE_LEN?DZ_SVALUE_LEN:(j-i))] = '\0'; // Simply force the last termination
found++;
}
}
}
if (found >= 4) {
return true;
}
}
}
// Just incase svalue is not found, we really don;t care for most devices.
if (found >= 2) {
return true;
}
return false;
}