-
Notifications
You must be signed in to change notification settings - Fork 21
/
test_library.c
139 lines (105 loc) · 2.4 KB
/
test_library.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
/*
* wattsup - Program for controlling the Watts Up? Pro Device
*
*
* Copyright (c) 2005 Patrick Mochel
*
* This program is released under the GPLv2
*
*
* Compiled with:
*
* gcc -O2 -Wall -o wattsup wattsup.c
*
*/
#define _GNU_SOURCE
#include <unistd.h>
#include "util.h"
#include "wattsup_common.h"
#include "globals.h"
int main(int argc, char ** argv)
{
int ret;
int fd = 0;
ret = parse_args(argc, argv);
if (ret)
return 0;
/*
* Try to enable debugging early
*/
if ((ret = wu_check_store(wu_option_debug, 0)))
goto Close;
ret = open_device(wu_device, &fd);
if (ret)
return ret;
dbg("%s: Open for business", wu_device);
ret = setup_serial_device(fd);
if (ret)
goto Close;
wu_clear(fd);
wu_fd = fd;
/*
* Set delimeter before we print out any fields.
*/
if ((ret = wu_check_store(wu_option_delim, fd)))
goto Close;
/*
* Ditto for 'label' and 'newline' flags.
*/
if ((ret = wu_check_store(wu_option_label, fd)))
goto Close;
if ((ret = wu_check_store(wu_option_newline, fd)))
goto Close;
if ((ret = wu_check_store(wu_option_suppress, fd)))
goto Close;
if ((ret = wu_check_store(wu_option_localtime, fd)))
goto Close;
if ((ret = wu_check_store(wu_option_gmtime, fd)))
goto Close;
if ((ret = wu_check_store(wu_option_set_only, fd)))
goto Close;
if ((ret = wu_check_store(wu_option_no_data, fd)))
goto Close;
if ((ret = wu_check_store(wu_option_info_all, fd)))
goto Close;
/*
* Options to set device parameters.
*/
if ((ret = wu_check_store(wu_option_interval, fd)))
goto Close;
if ((ret = wu_check_store(wu_option_mode, fd)))
goto Close;
if ((ret = wu_check_store(wu_option_user, fd)))
goto Close;
/*
* Check for options to print device info
*/
if (wu_info_all) {
wu_show(wu_option_cal, fd);
wu_show(wu_option_header, fd);
wu_show(wu_option_interval, fd);
wu_show(wu_option_mode, fd);
wu_show(wu_option_user, fd);
} else {
wu_check_show(wu_option_cal, fd);
wu_check_show(wu_option_header, fd);
if (!wu_set_only) {
wu_check_show(wu_option_interval, fd);
wu_check_show(wu_option_mode, fd);
wu_check_show(wu_option_user, fd);
}
}
if (!wu_no_data) {
if ((ret = wu_check_store(wu_option_count, fd)))
goto Close;
if ((ret = wu_check_store(wu_option_final, fd)))
goto Close;
if ((ret = wu_start_log()))
goto Close;
wu_read_data(fd);
wu_stop_log();
}
Close:
close(fd);
return ret;
}