Permalink
Browse files

Merge branch 'split'

Conflicts:
	makefile
  • Loading branch information...
pyrovski committed Feb 21, 2014
2 parents 575afed + 0284fbf commit eb613992d4c33da95012737960f90ad850bac99b
Showing with 1,965 additions and 1,784 deletions.
  1. +3 −0 .gitignore
  2. +100 −0 config.c
  3. +15 −0 config.h
  4. +5 −0 globals.c
  5. +10 −0 globals.h
  6. +14 −3 makefile
  7. +136 −0 test_library.c
  8. +1,554 −0 util.c
  9. +4 −0 util.h
  10. +2 −1,781 wattsup.c
  11. +122 −0 wattsup_common.h
View
@@ -1,4 +1,7 @@
TAGS
*~
*.o
wattsup
html
test_library
*.so
View
100 config.c
@@ -0,0 +1,100 @@
#include "wattsup_common.h"
const char * wu_version = "0.03";
const char * prog_name = "wattsup";
const char * sysfs_path_start = "/sys/class/tty";
struct wu_field wu_fields[wu_num_fields] = {
[wu_field_watts] = {
.name = "watts",
.descr = "Watt Consumption",
},
[wu_field_min_watts] = {
.name = "min-watts",
.descr = "Minimum Watts Consumed",
},
[wu_field_max_watts] = {
.name = "max-watts",
.descr = "Maxium Watts Consumed",
},
[wu_field_volts] = {
.name = "volts",
.descr = "Volts Consumption",
},
[wu_field_min_volts] = {
.name = "max-volts",
.descr = "Minimum Volts Consumed",
},
[wu_field_max_volts] = {
.name = "min-volts",
.descr = "Maximum Volts Consumed",
},
[wu_field_amps] = {
.name = "amps",
.descr = "Amp Consumption",
},
[wu_field_min_amps] = {
.name = "min-amps",
.descr = "Minimum Amps Consumed",
},
[wu_field_max_amps] = {
.name = "max-amps",
.descr = "Maximum Amps Consumed",
},
[wu_field_watt_hours] = {
.name = "kwh",
.descr = "Average KWH",
},
[wu_field_mo_kwh] = {
.name = "mo-kwh",
.descr = "Average monthly KWH",
},
[wu_field_cost] = {
.name = "cost",
.descr = "Cost per watt",
},
[wu_field_mo_cost] = {
.name = "mo-cost",
.descr = "Monthly Cost",
},
[wu_field_power_factor] = {
.name = "power-factor",
.descr = "Ratio of Watts vs. Volt Amps",
},
[wu_field_duty_cycle] = {
.name = "duty-cycle",
.descr = "Percent of the Time On vs. Time Off",
},
[wu_field_power_cycle] = {
.name = "power-cycle",
.descr = "Indication of power cycle",
},
[wu_field_frequency] = {
.name = "frequency",
.descr = "AC frequency (HZ)",
},
[wu_field_va] = {
.name = "VA",
.descr = "VA",
},
};
View
@@ -0,0 +1,15 @@
#ifndef CONFIG_H
#define CONFIG_H
#include "wattsup_common.h"
#include "config.h"
extern const char * wu_version,
*prog_name,
*sysfs_path_start;
#define wu_num_options ARRAY_SIZE(wu_options)
extern struct wu_field wu_fields[];
#endif
View
@@ -0,0 +1,5 @@
char * wu_device = "ttyUSB0";
int wu_fd = 0;
int wu_info_all = 0;
int wu_no_data = 0;
int wu_set_only = 0;
View
@@ -0,0 +1,10 @@
#ifndef GLOBALS_H
#define GLOBALS_H
extern char *wu_device;
extern int wu_fd;
extern int wu_info_all;
extern int wu_no_data;
extern int wu_set_only;
#endif
View
@@ -1,7 +1,18 @@
all: wattsup
targets=wattsup libwattsup.so test_library
all: $(targets)
wattsup: wattsup.c util.c config.c globals.c
libwattsup.so: util.c config.c globals.c
$(CC) -fPIC -shared -Wl,-soname,$@ -o $@ $^
test_library: test_library.c libwattsup.so
$(CC) -fPIC test_library.c -o $@ -L./ -lwattsup
install: all
install -m 0555 wattsup /usr/local/bin
install -m 0555 wattsup /usr/local/bin/
install -m 0444 libwattsup.so /usr/local/lib/
clean:
rm -f wattsup
rm -f *~ $(targets)
View
@@ -0,0 +1,136 @@
/*
* 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 "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;
}
Oops, something went wrong.

0 comments on commit eb61399

Please sign in to comment.