forked from pyrovski/watts-up
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.c
1560 lines (1323 loc) · 26.9 KB
/
util.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
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <ctype.h>
#include <getopt.h>
#include <signal.h>
#include <time.h>
#include <sys/stat.h>
#include "globals.h"
#include "config.h"
#include "wattsup_common.h"
int wu_count = 0;
int wu_debug = 0;
char *wu_delim = ", ";
int wu_final = 0;
int wu_interval = 1;
int wu_label = 0;
int wu_newline = 0;
int wu_suppress = 0;
int wu_localtime = 0;
int wu_gmtime = 0;
static char * wu_option_value(unsigned int index);
static void msg_start(const char * fmt, ...)
{
va_list(ap);
va_start(ap, fmt);
vprintf(fmt, ap);
va_end(ap);
}
static void msg_end(void)
{
printf("\n");
fflush(stdout);
}
static void msg(const char * fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vprintf(fmt, ap);
va_end(ap);
}
void dbg(const char * fmt, ...)
{
va_list ap;
if (wu_debug) {
va_start(ap, fmt);
msg_start("%s: [debug] ", prog_name);
vprintf(fmt, ap);
msg_end();
va_end(ap);
}
}
static void err(const char * fmt, ...)
{
va_list ap;
va_start(ap, fmt);
fprintf(stderr, "%s: [error] ", prog_name);
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
va_end(ap);
}
static void perr(const char * fmt, ...)
{
char buf[1024];
int n;
va_list ap;
va_start(ap, fmt);
n = sprintf(buf, "%s: [error] ", prog_name);
vsnprintf(buf + n, sizeof(buf) - n, fmt, ap);
perror(buf);
va_end(ap);
}
static int ret_err(int err)
{
errno = err;
return -1;
}
static void print_packet(struct wu_packet * p, char * str)
{
int i;
if (!wu_suppress)
msg_start("Watts Up? %s\n", str);
for (i = 0; i < p->count; i++) {
if (i)
msg("%s", wu_newline ? "\n" : wu_delim);
if (wu_label)
msg("[%s] ", p->label[i]);
msg(p->field[i]);
}
msg_end();
}
static void print_time(void)
{
time_t t;
struct tm * tm;
if (wu_localtime || wu_gmtime) {
time(&t);
if (wu_localtime)
tm = localtime(&t);
else
tm = gmtime(&t);
msg("[%02d:%02d:%02d] ",
tm->tm_hour, tm->tm_min, tm->tm_sec);
}
}
static void print_packet_filter(struct wu_packet * p,
int (*filter_ok)(struct wu_packet * p, int i, char * str))
{
char buf[256];
int printed;
int i;
print_time();
for (i = 0, printed = 0; i < p->count; i++) {
if (!filter_ok(p, i, buf))
continue;
if (printed++)
msg("%s", wu_newline ? "\n" : wu_delim);
if (wu_label)
msg("[%s] ", p->label[i]);
msg(buf);
}
msg_end();
}
/*
* Device should be something like "ttyS0"
*/
int open_device(char * device_name, int * dev_fd)
{
struct stat s;
int ret;
int cur_fd;
cur_fd = open(".", O_RDONLY);
if (cur_fd < 0) {
perr("Could not open current directory.");
return cur_fd;
}
ret = chdir(sysfs_path_start);
if (ret) {
perr(sysfs_path_start);
return ret;
}
// check for leading /dev/
char * lastSlash = rindex(device_name, '/');
if(lastSlash && !strncmp(device_name, "/dev", lastSlash - device_name)){
device_name = lastSlash + 1;
}
/*
* First, check if /sys/class/tty/<name>/ exists.
*/
dbg("Checking sysfs path: %s/%s", sysfs_path_start, device_name);
ret = stat(device_name, &s);
if (ret < 0) {
perr(device_name);
goto Done;
}
if (!S_ISDIR(s.st_mode)) {
ret = errno = -ENODEV;
err("%s is not a TTY device.", device_name);
goto Done;
}
dbg("%s is a registered TTY device", device_name);
fchdir(cur_fd);
/*
* Check if device node exists and is writable
*/
chdir("/dev");
ret = stat(device_name, &s);
if (ret < 0) {
perr("/dev/%s (device node)", device_name);
goto Done;
}
if (!S_ISCHR(s.st_mode)) {
errno = -ENOTTY;
ret = -1;
err("%s is not a TTY character device.", device_name);
goto Done;
}
dbg("%s has a device node", device_name);
ret = access(device_name, R_OK | W_OK);
if (ret) {
perr("%s: Not writable?", device_name);
goto Done;
}
ret = open(device_name, O_RDWR | O_NONBLOCK);
if (ret < 0) {
perr("Could not open %s");
goto Done;
}
*dev_fd = ret;
ret = 0;
Done:
fchdir(cur_fd);
close(cur_fd);
return ret;
}
int setup_serial_device(int dev_fd)
{
struct termios t;
int ret;
ret = tcgetattr(dev_fd, &t);
if (ret)
return ret;
cfmakeraw(&t);
cfsetispeed(&t, B115200);
cfsetospeed(&t, B115200);
tcflush(dev_fd, TCIFLUSH);
t.c_iflag |= IGNPAR;
t.c_cflag &= ~CSTOPB;
ret = tcsetattr(dev_fd, TCSANOW, &t);
if (ret) {
perr("setting terminal attributes");
return ret;
}
return 0;
}
static int wu_write(int fd, struct wu_packet * p)
{
int ret;
int n;
int i;
char * s = p->buf;
memset(p->buf, 0, sizeof(p->buf));
n = sprintf(p->buf, "#%c,%c,%d", p->cmd, p->sub_cmd, p->count);
p->len = n;
s = p->buf + n;
for (i = 0; i < p->count; i++) {
if ((p->len + strlen(p->field[i]) + 4) >= sizeof(p->buf)) {
err("Overflowed command string");
return ret_err(EOVERFLOW);
}
n = sprintf(s, ",%s", p->field[i]);
s += n;
p->len += n;
}
p->buf[p->len++] = ';';
dbg("Writing '%s' (strlen = %d) (len = %d) to device",
p->buf, strlen(p->buf), p->len);
ret = write(fd, p->buf, p->len);
if (ret != p->len)
perr("Writing to device");
return ret >= 0 ? 0 : ret;
}
static void dump_packet(struct wu_packet * p)
{
int i;
dbg("Packet - Command '%c' %d parameters", p->cmd, p->count);
for (i = 0; i < p->count; i++)
dbg("[%2d] [%20s] = \"%s\"", i, p->label[i], p->field[i]);
}
static int parse_packet(struct wu_packet * p)
{
char * s, *next;
int i;
p->buf[p->len] = '\0';
dbg("Parsing Packet, Raw buffer is (%d bytes) [%s]",
p->len, p->buf);
s = p->buf;
/*
* First character should be '#'
*/
if (s) {
s = strchr(s, '#');
if (s)
s++;
else {
dbg("Invalid packet");
return ret_err(EFAULT);
}
} else {
dbg("Invalid packet");
return ret_err(EFAULT);
}
/*
* Command character is first
*/
next = strchr(s, ',');
if (next) {
p->cmd = *s;
s = ++next;
} else {
dbg("Invalid Command field [%s]", s);
return ret_err(EFAULT);
}
/*
* Next character is the subcommand, and should be '-'
* Though, it doesn't matter, because we just
* discard it anyway.
*/
next = strchr(s, ',');
if (next) {
p->sub_cmd = *s;
s = ++next;
} else {
dbg("Invalid 2nd field");
return ret_err(EFAULT);
}
/*
* Next is the number of parameters,
* which should always be > 0.
*/
next = strchr(s, ',');
if (next) {
*next++ = '\0';
p->count = atoi(s);
s = next;
} else {
dbg("Couldn't determine number of parameters");
return ret_err(EFAULT);
}
dbg("Have %d parameter%s (cmd = '%c')",
p->count, p->count > 1 ? "s" : "", p->cmd);
/*
* Now, we loop over the rest of the string,
* storing a pointer to each in p->field[].
*
* The last character was originally a ';', but may have been
* overwritten with a '\0', so we make sure to catch
* that when converting the last parameter.
*/
for (i = 0; i < p->count; i++) {
next = strpbrk(s, ",;");
if (next) {
*next++ = '\0';
} else {
if (i < (p->count - 1)) {
dbg("Malformed parameter string [%s]", s);
return ret_err(EFAULT);
}
}
/*
* Skip leading white space in fields
*/
while (isspace(*s))
s++;
p->field[i] = s;
s = next;
}
dump_packet(p);
return 0;
}
static int wu_read(int fd, struct wu_packet * p)
{
fd_set read_fd;
struct timeval tv;
int ret;
FD_ZERO(&read_fd);
FD_SET(fd, &read_fd);
tv.tv_sec = 2;
tv.tv_usec = 0;
ret = select(fd + 1, &read_fd, NULL, NULL, &tv);
if (ret < 0) {
perr("select on terminal device");
return ret;
} else if (ret > 0) {
ret = read(fd, p->buf, wu_strlen);
if (ret < 0) {
perr("Reading from device");
return ret;
}
p->len = ret;
} else {
dbg("Device timed out while reading");
return ret_err(ETIME);
}
return parse_packet(p);
}
static int wu_show_header(int fd)
{
struct wu_packet p = {
.cmd = 'H',
.sub_cmd = 'R',
.count = 0,
.label = {
[0] = "watts header",
[1] = "volts header",
[2] = "amps header",
[3] = "kWh header",
[4] = "cost header",
[5] = "mo. kWh header",
[6] = "mo. cost header",
[7] = "max watts header",
[8] = "max volts header",
[9] = "max amps header",
[10] = "min watts header",
[11] = "min volts header",
[12] = "min amps header",
[13] = "power factor header",
[14] = "duty cycle header",
[15] = "power cycle header",
[16] = "frequency header",
[17] = "VA header"
}
};
int ret;
ret = wu_write(fd, &p);
if (ret) {
perr("Requesting header strings");
return ret;
}
sleep(1);
ret = wu_read(fd, &p);
if (ret) {
perr("Reading header strings");
return ret;
}
print_packet(&p, "Header Record");
return 0;
}
static int wu_show_cal(int fd)
{
struct wu_packet p = {
.cmd = 'F',
.sub_cmd = 'R',
.count = 0,
.label = {
[0] = "flags",
[1] = "sample count",
[2] = "volts gain",
[3] = "volts bias",
[4] = "amps gain",
[5] = "amps bias",
[6] = "amps offset",
[7] = "low amps gain",
[8] = "low amps bias",
[9] = "low amps offset",
[10] = "watts gain",
[11] = "watts offset",
[12] = "low watts gain",
[13] = "low watts offset",
},
};
int ret;
ret = wu_write(fd, &p);
if (ret) {
perr("Requesting calibration parameters");
return ret;
}
sleep(1);
ret = wu_read(fd, &p);
if (ret) {
perr("Reading header strings");
return ret;
}
print_packet(&p, "Calibration Settings");
return 0;
}
int wu_start_log(void)
{
struct wu_packet p = {
.cmd = 'L',
.sub_cmd = 'W',
.count = 3,
.field = {
[0] = "E",
[1] = "1",
[2] = "1",
},
};
int ret;
/*
* Start up logging
*/
ret = wu_write(wu_fd, &p);
if (!ret)
sleep(1);
else {
perr("Starting External Logging");
return ret;
}
return ret;
}
int wu_stop_log(void)
{
struct wu_packet p = {
.cmd = 'L',
.sub_cmd = 'R',
.count = 0,
.label = {
[0] = "time stamp",
[1] = "interval",
},
};
int ret;
/*
* Stop logging and read time stamp.
*/
ret = wu_write(wu_fd, &p);
if (ret) {
perr("Stopping External Logging");
return ret;
}
sleep(1);
ret = wu_read(wu_fd, &p);
if (ret) {
perr("Reading final time stamp");
return ret;
}
if (wu_final)
print_packet(&p, "Final Time Stamp and Interval");
return ret;
}
static int filter_data(struct wu_packet * p, int i, char * buf)
{
if (i < wu_num_fields) {
if (wu_fields[i].enable) {
double scale;
int digits;
switch(i){
case wu_field_min_amps:
case wu_field_max_amps:
case wu_field_amps:
scale = 1000.0;
digits = 3;
break;
case wu_field_power_factor:
case wu_field_duty_cycle:
scale = 1.0;
digits = 1;
break;
default:
scale = 10.0;
digits = 1;
}
double val = strtod(p->field[i], NULL);
snprintf(buf, 256, "%.*lf", digits, val / scale);
return 1;
}
}
return 0;
}
int wu_clear(int fd)
{
struct wu_packet p = {
.cmd = 'R',
.sub_cmd = 'W',
.count = 0,
};
int ret;
/*
* Clear the memory
*/
ret = wu_write(fd, &p);
if (ret)
perr("Clearing memory");
else
sleep(2);
/*
* Dummy read
*/
wu_read(fd, &p);
return ret;
}
int wu_read_data(int fd)
{
struct wu_packet p = {
.label = {
[0] = "watts",
[1] = "volts",
[2] = "amps",
[3] = "watt hours",
[4] = "cost",
[5] = "mo. kWh",
[6] = "mo. cost",
[7] = "max watts",
[8] = "max volts",
[9] = "max amps",
[10] = "min watts",
[11] = "min volts",
[12] = "min amps",
[13] = "power factor",
[14] = "duty cycle",
[15] = "power cycle",
[16] = "frequency",
[17] = "VA"
},
};
int num_read = 0;
int retry = 0;
int ret;
int i;
static const int wu_max_retry = 2;
i = 0;
while (1) {
ret = wu_read(fd, &p);
if (ret) {
if (++retry < wu_max_retry) {
dbg("Bad record back, retrying\n");
sleep(wu_interval);
continue;
} else if (retry == wu_max_retry) {
dbg("Still couldn't get a good record, resetting\n");
wu_stop_log();
wu_clear(fd);
wu_start_log();
num_read = 0;
sleep(wu_interval);
continue;
}
perr("Blech. Giving up on read");
break;
} else if (retry)
retry = 0;
dbg("[%d] ", num_read);
num_read++;
print_packet_filter(&p, filter_data);
if (wu_count && (++i == wu_count))
break;
sleep(wu_interval);
}
return 0;
}
static int wu_show_interval(int fd)
{
struct wu_packet p = {
.cmd = 'S',
.sub_cmd = 'R',
.count = 0,
.label = {
[0] = "reserved",
[1] = "interval",
},
};
int ret;
ret = wu_write(fd, &p);
if (ret) {
perr("Requesting interval");
return ret;
}
sleep(1);
ret = wu_read(fd, &p);
if (ret) {
perr("Reading interval");
return ret;
}
print_packet(&p, "Interval Settings");
return 0;
}
static int wu_write_interval(int fd, unsigned int seconds,
unsigned int interval)
{
char str_seconds[wu_param_len];
char str_interval[wu_param_len];
struct wu_packet p = {
.cmd = 'S',
.sub_cmd = 'W',
.count = 2,
.field = {
[0] = str_seconds,
[1] = str_interval,
},
};
int ret;
snprintf(str_seconds, wu_param_len, "%ud", seconds);
snprintf(str_interval, wu_param_len, "%ud", interval);
ret = wu_write(fd, &p);
if (ret) {
perr("Setting Sampling Interval");
return ret;
}
sleep(1);
return 0;
}
static int wu_store_interval(int fd)
{
char * s = wu_option_value(wu_option_interval);
char * end;
wu_interval = strtol(s, &end, 0);
if (*end) {
err("Invalid interval: %s", s);
return ret_err(EINVAL);
}
return wu_write_interval(fd, 1, wu_interval);
}
static int wu_show_mode(int fd)
{
struct wu_packet p = {
.cmd = 'M',
.sub_cmd = 'R',
.count = 0,
.label = {
[0] = "display mode",
},
};
int ret;
ret = wu_write(fd, &p);
if (ret) {
perr("Requesting device display mode");
return ret;
}
ret = wu_read(fd, &p);
if (ret) {
perr("Reaing device display mode");
return ret;
}
dump_packet(&p);
return ret;
}
static int wu_write_mode(int fd, int mode)
{
char str_mode[wu_param_len];
struct wu_packet p = {
.cmd = 'M',
.sub_cmd = 'W',
.count = 1,
.field = {
[0] = str_mode,
},
};
int ret;
snprintf(str_mode, wu_param_len, "%ud", mode);
ret = wu_write(fd, &p);
if (ret)
perr("Setting device display mode");
else
sleep(1);
return ret;
}
static int wu_store_mode(int fd)
{
char * s = wu_option_value(wu_option_mode);
char * end;
unsigned int mode;
mode = strtol(s, &end, 0);
if (*end) {
err("Invalid mode: %s", s);
return ret_err(EINVAL);
}
return wu_write_mode(fd, mode);
}
static int wu_show_user(int fd)
{
struct wu_packet p = {
.cmd = 'U',
.sub_cmd = 'R',
.count = 0,
.label = {
[0] = "cost per kWh",
[1] = "2nd tier cost",
[2] = "2nd tier threshold",
[3] = "duty cycle threshold",
},
};
int ret;
ret = wu_write(fd, &p);
if (ret) {
perr("Requesting user parameters");
return ret;
}
sleep(1);
ret = wu_read(fd, &p);
if (ret) {
perr("Reading user parameters");
return ret;
}
print_packet(&p, "User Settings");
return 0;
}
static int wu_write_user(int fd, unsigned int kwh_cost,
unsigned int second_tier_cost,
unsigned int second_tier_threshold,
unsigned int duty_cycle_threshold)
{
char str_kwh_cost[wu_param_len];
char str_2nd_tier_cost[wu_param_len];
char str_2nd_tier_threshold[wu_param_len];
char str_duty_cycle_threshold[wu_param_len];
struct wu_packet p = {
.cmd = 'U',
.sub_cmd = 'R',
.count = 0,
.label = {
[0] = str_kwh_cost,
[1] = str_2nd_tier_cost,
[2] = str_2nd_tier_threshold,
[3] = str_duty_cycle_threshold,
},
};
int ret;
snprintf(str_kwh_cost, wu_param_len, "%ud", kwh_cost);
snprintf(str_2nd_tier_cost, wu_param_len, "%ud",
second_tier_cost);
snprintf(str_2nd_tier_threshold, wu_param_len, "%ud",
second_tier_threshold);
snprintf(str_duty_cycle_threshold, wu_param_len, "%ud",
duty_cycle_threshold);
ret = wu_write(fd, &p);
if (ret)
perr("Writing user parameters");
else
sleep(1);
return ret;
}
static int wu_store_user(int fd)
{
unsigned int kwh_cost;
unsigned int second_tier_cost;
unsigned int second_tier_threshold;
unsigned int duty_cycle_threshold;
char * buf = wu_option_value(wu_option_user);
char * s = buf;
char * next;
if (!buf) {
err("No user parameters?");
return ret_err(EINVAL);
}
kwh_cost = strtoul(s, &next, 0);
if (next == s) {
err("Incomplete user parameters");
return ret_err(EINVAL);
}
s = next;
while (s && !isdigit(*s))
s++;
if (!s) {
err("Incomplete user parameters");
return ret_err(EINVAL);
}
second_tier_cost = strtoul(s, &next, 0);
if (next == s) {
err("Incomplete user parameters");
return ret_err(EINVAL);
}
s = next;
while (s && !isdigit(*s))
s++;
if (!s) {
err("Incomplete user parameters");
return ret_err(EINVAL);
}
second_tier_threshold = strtoul(s, &next, 0);
if (next == s) {
err("Incomplete user parameters");
return ret_err(EINVAL);
}
s = next;
while (s && !isdigit(*s))
s++;
if (!s) {
err("Incomplete user parameters");
return ret_err(EINVAL);
}
duty_cycle_threshold = strtoul(s, &next, 0);
if (next == s) {
err("Incomplete user parameters");
return ret_err(EINVAL);
}
s = next;
while (s && !isdigit(*s))