forked from ka87/cpsumon
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcpsufancli.c
153 lines (138 loc) · 4.13 KB
/
cpsufancli.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
#include <stdlib.h>
#include <string.h>
#include "dongle.h"
#include "psu.h"
#include "cpsumoncli.h"
void about() {
printf("Corsair AXi Series PSU Monitor\n");
printf("(c) 2014 Andras Kovacs - [email protected]\n");
printf("additional work by Paige Thompson [email protected] / [email protected]\n");
printf("-------------------------------------------\n\n");
}
void usage(char **argv) {
printf("usage: %s <serial port device> <fan speed>\n", argv[0]);
}
void msg(char *msg) {
printf("%s\n", msg);
}
int main (int argc, char * argv[]) {
int fd;
struct termios tio;
int i;
float f;
_psu_type = TYPE_AX1200;
about();
if (argc < 2) {
usage(argv);
return 0;
}
fd = open_usb(argv[1]);
if(fd == -1) {
msg("couldn't open serial port");
return -1;
}
// initialize serial port and buffer
memset(&tio, 0, sizeof(tio));
tio.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
tio.c_iflag = IGNPAR;
tio.c_oflag = 0;
tio.c_lflag = 0;
tio.c_cc[VTIME]= 0;
tio.c_cc[VMIN] = 1;
tcsetattr(fd, TCSANOW, &tio);
tcflush(fd, TCIOFLUSH);
if (setup_dongle(fd) == -1) {
msg("couldn't setup dongle");
return -1;
}
if(strcmp(argv[2], "auto") == 0) {
msg("setting fan mode to auto");
set_psu_fan_mode(fd, FANMODE_AUTO);
}
else {
f = atof(argv[2]);
printf("setting fan speed percentage to: %0.2f\n", f);
set_psu_fan_mode(fd, FANMODE_FIXED);
set_psu_fan_fixed_percent(fd, f);
}
if (read_psu_fan_mode(fd, &i) == -1) {
msg("failed to read fan mode");
return -1;
}
if (i == FANMODE_AUTO) {
msg("Fan mode: Auto");
}
else if (i == FANMODE_FIXED) {
msg("Fan mode: Fixed");
if (read_psu_fan_fixed_percent(fd, &i) == -1) {
printf("failed to read fan fixed percent");
}
printf("Fan speed percentage: %d %%\n", i);
}
msg("waiting 3 seconds for fan speed (RPM) to catch up...");
sleep(3);
if (read_psu_fan_speed(fd, &f) == -1) {
msg("failed to read fan speed");
return -1;
}
printf("Fan speed: %0.2f RPM\n", f);
/*
if (read_psu_temp(fd, &f) == -1) {
msg("failed to read temp");
return -1;
}
printf("Temperature: %0.2f °C\n", f);
if (read_psu_main_power(fd) == -1) {
msg("failed to read main power");
return -1;
}
printf("Voltage: %0.2f V\n", _psumain.voltage);
printf("Current: %0.2f A\n", _psumain.current);
printf("Input power: %0.2f W\n", _psumain.inputpower);
printf("Output power: %0.2f W\n", _psumain.outputpower);
if (_psu_type == TYPE_AX1500) {
printf("Cable type: %s\n", (_psumain.cabletype ? "20 A" : "15 A"));
printf("Efficiency: %0.2f %%\n", _psumain.efficiency);
}
if (read_psu_rail12v(fd) == -1) {
msg("failed to read 12v rail");
return -1;
}
int chnnum = (_psu_type == TYPE_AX1500 ? 10 : ((_psu_type == TYPE_AX1200) ? 8 : 6));
for (i = 0; i < chnnum; i++) {
printf("PCIe %02d Rail: %0.2f V, %0.2f A, %0.2f W, OCP %s (Limit: %0.2f A)\n",
i,
_rail12v.pcie[i].voltage,
_rail12v.pcie[i].current,
_rail12v.pcie[i].power,
(_rail12v.pcie[i].ocp_enabled ? "enabled " : "disabled"),
_rail12v.pcie[i].ocp_limit);
}
printf("ATX Rail: %0.2f V, %0.2f A, %0.2f W, OCP %s (Limit: %0.2f A)\n",
_rail12v.atx.voltage,
_rail12v.atx.current,
_rail12v.atx.power,
(_rail12v.atx.ocp_enabled ? "enabled " : "disabled"),
_rail12v.atx.ocp_limit);
printf("Peripheral Rail: %0.2f V, %0.2f A, %0.2f W, OCP %s (Limit: %0.2f A)\n",
_rail12v.peripheral.voltage,
_rail12v.peripheral.current,
_rail12v.peripheral.power,
(_rail12v.peripheral.ocp_enabled ? "enabled " : "disabled"),
_rail12v.peripheral.ocp_limit);
if(read_psu_railmisc(fd) == -1) {
msg("failed to read psu rail misc");
return -1;
}
printf("5V Rail: %0.2f V, %0.2f A, %0.2f W\n",
_railmisOBc.rail_5v.voltage,
_railmisc.rail_5v.current,
_railmisc.rail_5v.power);
printf("3.3V Rail: %0.2f V, %0.2f A, %0.2f W\n",
_railmisc.rail_3_3v.voltage,
_railmisc.rail_3_3v.current,
_railmisc.rail_3_3v.power);
*/
close(fd);
return 0;
}