-
Notifications
You must be signed in to change notification settings - Fork 3
/
fetchwattson.c
executable file
·53 lines (40 loc) · 1.33 KB
/
fetchwattson.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
/* openwattson - fetchwattson.c
*
* Version 0.1
*
* Control Wattson Power meter
*
* Copyright 2010, Kary Främling, Jan Nyman
* This program is published under the GNU General Public license
*/
#include "rwwattson.h"
/********** MAIN PROGRAM ************************************************
*
*
* It takes one parameter which is the config file name with path
* If this parameter is omitted the program will look at the default paths
* See the openwattson.conf-dist file for info
*
***********************************************************************/
int main(int argc, char *argv[])
{
WATTSON wattson;
char logline[100] = "";
char datestring[50]; //used to hold the date stamp for the log file
struct config_type config;
int current_power;
time_t basictime;
get_configuration(&config, argv[1]);
wattson = open_wattson(config.serial_device_name);
/* READ CURRENT POWER CONSUMPTION */
current_power = get_current_power_with_retry(wattson);
sprintf(logline, "%sPower %d\n", logline, current_power);
/* GET DATE AND TIME FOR LOG FILE, PLACE BEFORE ALL DATA IN LOG LINE */
time(&basictime);
strftime(datestring,sizeof(datestring),"Date %Y-%b-%d\nTime %H:%M:%S\n",
localtime(&basictime));
// Print out and leave
printf("%s%s", datestring, logline);
close_wattson(wattson);
return(0);
}