-
Notifications
You must be signed in to change notification settings - Fork 1
/
consolemon.c
144 lines (107 loc) · 4.25 KB
/
consolemon.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
/*****************************************************************************
* Steve Moskovchenko (aka evil wombat) *
* University of Maryland *
* stevenm86 at gmail dot com *
* http://wam.umd.edu/~stevenm/carnetix.html *
* *
* Linux and Mac OS API for the Carnetix P2140 power supply. *
* The program uses libusb, which works on Mac OS X, Linux, and Windows. *
* *
* Released under the BSD License. See License.txt for info. *
* *
* Version 0.2. Enjoy! *
* *
****************************************************************************/
/*
* This is a very small and very simple monitoring program. It runs in a console
* and prints the supply values every second.
*/
#include <stdio.h>
#include <stdlib.h>
#include <usb.h>
#include "ctxapi.h"
int ctxPrintValues(struct ctxValues * val)
{
if(!val)
return -1;
printf("Batt Voltage: %f V\nBatt Current: %f A\n\n", val->battVoltage, val->battCurrent);
printf("Pri Voltage : %f V\nPri Current : %f A\n\n", val->priVoltage, val->priCurrent);
printf("Sec Voltage : %f V\nSec Current : %f A\n\n", val->secVoltage, val->secCurrent);
printf("Temperature : %f C\n", val->temperature);
printf("State: %d (%s)\n", val->state, ctxStateNameToText(val->state));
printf("\nLED State (0x%04X):\n", val->ledValue);
if(val->ledValue & LED_IGNITION)
printf("\tIgnition\n");
if(val->ledValue & LED_PULSESTART)
printf("\tPulse Start\n");
if(val->ledValue & LED_FANFAULT)
printf("\tFan Fault\n");
if(val->ledValue & LED_DELAYON)
printf("\tDelay On\n");
if(val->ledValue & LED_ACPI)
printf("\tACPI\n");
if(val->ledValue & LED_POWERGOOD)
printf("\tPower Good\n");
if(val->ledValue & LED_PS_ON)
printf("\tPower Supply On\n");
if(val->ledValue & LED_FANON)
printf("\tFan On\n");
if(val->ledValue & LED_VOLTAGE_OK)
printf("\tBattery Voltage OK\n");
if(val->ledValue & LED_PRICUR_OK)
printf("\tPrimary Current OK\n");
if(val->ledValue & LED_SECCUR_OK)
printf("\tSecondary Current OK\n");
return 0;
}
int ctxPrintParams(struct ctxParams * prm)
{
if(!prm)
return -1;
printf("SD_DELAY : %.1f sec\n", prm->sd_dly);
printf("DMT : %.1f hr\n", prm->dmt);
printf("DLYON : %.1f sec\n", prm->dlyon);
printf("BU_LO : %.1f sec\n", prm->bu_lo);
printf("SD_LO : %.1f sec\n", prm->sd_lo);
printf("LOBATT : %f V\n", prm->lobatt);
printf("Jumpers : 0x%02X\n", prm->softJumpers);
printf("ACPI Dly : %.1f sec\n", prm->acpiDelay);
printf("ACPI Dur : %.1f sec\n", prm->acpiDuration);
printf("Low Temp : %f C\n", prm->lowTemp);
return 0;
}
int main(int argc, char ** argv)
{
struct ctxValues val;
char buf[25];
printf("Carnetix P2140 Linux Tool\nbrought to you by an evil wombat\nHere goes nothing...\n");
usb_dev_handle * hDev = ctxInit();
if(!hDev)
{
printf("\nNo device!\n");
return -1;
}
printf("\nYou should probably upgrage to Firmware 1.8+ if you haven't already done so.\n\n");
ctxGetFWVersion(hDev, buf, 25);
printf("Firmware Version is: %s\n", buf);
while(1)
{
if(ctxReadValues(hDev, &val) == 0)
{
printf("\n\n***********************************************************\n");
printf("\nPower Supply Readings:\n");
ctxPrintValues(&val);
printf("\nPress Ctrl-C to Exit\n");
} else
{
printf("\nCould not read values! Trying to reconnect...\n");
ctxClose(hDev);
hDev = ctxInit();
if(hDev)
printf("Reconnected OK\n");
}
sleep(1);
}
ctxClose(hDev);
return 0;
}