added includes
diff --git a/includes/gpio.c b/includes/gpio.c
new file mode 100644
index 0000000..221441b
--- /dev/null
+++ b/includes/gpio.c
@@ -0,0 +1,136 @@
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <argp.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+
+#include "gpio.h"
+
+
+void gpio_writec(GPIO* gpio, char value)
+{
+ char buf[1];
+ buf[0] = value;
+ if (write(gpio->fd, buf, 1) != 1)
+ {
+ //TODO: error handling
+ printf("Write error\n");
+ }
+}
+
+void gpio_write(GPIO* gpio, uint8_t value)
+{
+ char buf[1];
+ buf[0] = '0';
+ if (value==1)
+ {
+ buf[0]='1';
+ }
+ if (write(gpio->fd, buf, 1) != 1)
+ {
+ //TODO: error handling
+ printf("write error\n");
+ }
+}
+
+uint8_t gpio_read(GPIO* gpio)
+{
+ char buf[1];
+ if (read(gpio->fd,&buf,1) != 1)
+ {
+ //TODO: error hjandling
+ printf("read error\n");
+ }
+ if (buf[0]=='1') {
+ return 1;
+ }
+ return 0;
+
+}
+void gpio_clock_cycle(GPIO* gpio, int num_clks) {
+ int i=0;
+ for (i=0;i<num_clks;i++) {
+ gpio_writec(gpio,'0');
+ gpio_writec(gpio,'1');
+ }
+}
+
+// Gets the gpio device path from gpio manager object
+void gpio_init(GDBusConnection *connection, GPIO* gpio)
+{
+ GDBusProxy *proxy;
+ GError *error;
+ GVariant *result;
+
+ error = NULL;
+ g_assert_no_error (error);
+ error = NULL;
+ proxy = g_dbus_proxy_new_sync (connection,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL, /* GDBusInterfaceInfo */
+ "org.openbmc.managers.Gpios", /* name */
+ "/org/openbmc/managers/Gpios", /* object path */
+ "org.openbmc.managers.Gpios", /* interface */
+ NULL, /* GCancellable */
+ &error);
+ g_assert_no_error (error);
+
+ result = g_dbus_proxy_call_sync (proxy,
+ "init",
+ g_variant_new ("(s)", gpio->name),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ g_assert_no_error (error);
+ g_assert (result != NULL);
+ g_variant_get (result, "(&si&s)", &gpio->dev,&gpio->num,&gpio->direction);
+ g_print("GPIO Lookup: %s = %d,%s\n",gpio->name,gpio->num,gpio->direction);
+
+ //export and set direction
+ char dev[254];
+ char data[4];
+ sprintf(dev,"%s/export",gpio->dev);
+ int fd = open(dev, O_WRONLY);
+ sprintf(data,"%d",gpio->num);
+ write(fd,data,strlen(data));
+ close(fd);
+
+ sprintf(dev,"%s/gpio%d/direction",gpio->dev,gpio->num);
+ fd = open(dev,O_WRONLY);
+ write(fd,gpio->direction,strlen(gpio->direction));
+ close(fd);
+
+
+}
+int gpio_open(GPIO* gpio)
+{
+ // open gpio for writing or reading
+ char buf[254];
+ if (strcmp(gpio->direction,"in")==0)
+ {
+ sprintf(buf, "%s/gpio%d/value", gpio->dev, gpio->num);
+ gpio->fd = open(buf, O_RDONLY);
+ }
+ else
+ {
+ sprintf(buf, "%s/gpio%d/value", gpio->dev, gpio->num);
+ gpio->fd = open(buf, O_WRONLY);
+
+ }
+ if (gpio->fd == -1)
+ {
+ printf("error opening: %s\n",buf);
+ }
+ return gpio->fd;
+}
+
+void gpio_close(GPIO* gpio)
+{
+ close(gpio->fd);
+}
diff --git a/includes/gpio.h b/includes/gpio.h
new file mode 100644
index 0000000..68d01bd
--- /dev/null
+++ b/includes/gpio.h
@@ -0,0 +1,25 @@
+#ifndef __OBJECTS_GPIO_UTILITIES_H__
+#define __OBJECTS_GPIO_UTILITIES_H__
+
+#include <stdint.h>
+#include <gio/gio.h>
+
+typedef struct {
+ gchar* name;
+ gchar* dev;
+ uint16_t num;
+ gchar* direction;
+ int fd;
+} GPIO;
+
+
+//gpio functions
+void gpio_init(GDBusConnection*, GPIO*);
+void gpio_close(GPIO*);
+int gpio_open(GPIO*);
+void gpio_write(GPIO*, uint8_t);
+void gpio_writec(GPIO*, char);
+void gpio_clock_cycle(GPIO*, int);
+uint8_t gpio_read(GPIO*);
+
+#endif
diff --git a/includes/openbmc.h b/includes/openbmc.h
new file mode 100644
index 0000000..775e225
--- /dev/null
+++ b/includes/openbmc.h
@@ -0,0 +1,12 @@
+#ifndef __OPENBMC_H__
+#define __OPENBMC_H__
+
+#include <stdint.h>
+
+typedef struct {
+ gint argc;
+ gchar **argv;
+
+} cmdline;
+
+#endif
diff --git a/includes/sensor_threshold.c b/includes/sensor_threshold.c
new file mode 100644
index 0000000..68c7ad7
--- /dev/null
+++ b/includes/sensor_threshold.c
@@ -0,0 +1,81 @@
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <argp.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+
+#include "interfaces/sensor2.h"
+#include "sensor_threshold.h"
+
+
+gboolean
+get_threshold_state (SensorIntegerThreshold *sen,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
+{
+ guint state = sensor_integer_threshold_get_state(sen);
+ sensor_integer_threshold_complete_get_state(sen,invocation,state);
+ return TRUE;
+}
+
+
+gboolean
+set_thresholds (SensorIntegerThreshold *sen,
+ GDBusMethodInvocation *invocation,
+ guint lc,
+ guint lw,
+ guint uw,
+ guint uc,
+ gpointer user_data)
+{
+ sensor_integer_threshold_set_lower_critical(sen,lc);
+ sensor_integer_threshold_set_lower_warning(sen,lw);
+ sensor_integer_threshold_set_upper_warning(sen,uw);
+ sensor_integer_threshold_set_upper_critical(sen,uc);
+ sensor_integer_threshold_complete_set(sen,invocation);
+ sensor_integer_threshold_set_state(sen,NORMAL);
+ return TRUE;
+}
+
+
+void check_thresholds(SensorIntegerThreshold* sensor,guint value)
+{
+ threshold_states current_state = sensor_integer_threshold_get_state(sensor);
+ if (current_state != NOT_SET)
+ {
+ threshold_states state = NORMAL;
+
+ if (value < sensor_integer_threshold_get_lower_critical(sensor)) {
+ state = LOWER_CRITICAL;
+ }
+ else if(value < sensor_integer_threshold_get_lower_warning(sensor)) {
+ state = LOWER_WARNING;
+ }
+ else if(value > sensor_integer_threshold_get_upper_critical(sensor)) {
+ state = UPPER_CRITICAL;
+ }
+ else if(value > sensor_integer_threshold_get_upper_warning(sensor)) {
+ state = UPPER_WARNING;
+ }
+ // only emit signal if threshold state changes
+ if (state != sensor_integer_threshold_get_state(sensor))
+ {
+ sensor_integer_threshold_set_state(sensor,state);
+ if (state == LOWER_CRITICAL || state == UPPER_CRITICAL)
+ {
+ sensor_integer_threshold_emit_critical(sensor);
+ g_print("Critical\n");
+ }
+ else if (state == LOWER_WARNING || state == UPPER_WARNING)
+ {
+ sensor_integer_threshold_emit_warning(sensor);
+ g_print("Warning\n");
+ }
+ }
+ }
+}
+
diff --git a/includes/sensor_threshold.h b/includes/sensor_threshold.h
new file mode 100644
index 0000000..0e0991c
--- /dev/null
+++ b/includes/sensor_threshold.h
@@ -0,0 +1,16 @@
+#ifndef __SENSOR_THRESHOLDS_H__
+#define __SENSOR_THRESHOLDS_H__
+
+#include <stdint.h>
+
+typedef enum { NOT_SET,NORMAL,LOWER_CRITICAL,LOWER_WARNING,UPPER_WARNING,UPPER_CRITICAL } threshold_states;
+
+gboolean get_threshold_state(SensorIntegerThreshold*,
+ GDBusMethodInvocation*,gpointer);
+
+gboolean set_thresholds(SensorIntegerThreshold*,
+ GDBusMethodInvocation*,guint,guint,guint,guint,gpointer);
+void check_thresholds(SensorIntegerThreshold*,guint);
+
+
+#endif