Fri, 01 Aug 2014 16:13:55 +0200
A bit of code cleanup
#ifndef _MBSELIB_H #define _MBSELIB_H #define TRUE 1 #define FALSE 0 #include "../config.h" #include <stdlib.h> #include <stdio.h> #include <stdint.h> #include <stdarg.h> #include <string.h> #include <ctype.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/time.h> #include <time.h> #include <fcntl.h> #include <syslog.h> #include <unistd.h> #include <errno.h> #include <signal.h> #include <getopt.h> #include <limits.h> #include <sys/socket.h> #include <arpa/inet.h> #include <netdb.h> #include <poll.h> #include <dirent.h> #include <uuid/uuid.h> #ifndef HAVE_WIRINGPI_H #include <pthread.h> #endif #include <libxml/xmlmemory.h> #include <libxml/parser.h> #include <libxml/encoding.h> #include <libxml/xmlwriter.h> #ifdef HAVE_WIRINGPI_H /* wiringPi */ #include <wiringPi.h> #include <pcf8574.h> #include <lcd.h> #endif #define TRUE 1 #define FALSE 0 #define MBSE_SS(x) (x)?(x):"(null)" /* * Fermenter units. These units are connected via the 1-wire bus. * Each unit can have: * a DS18B20 sensor to measure the air temperature inside the unit. * a DS18B20 sensor to measure the beer temperature. * a DS2413 to turn the cooler and heater on or off. * a DS2413 to switch the fan and sense the door. */ typedef struct _units_list { struct _units_list *next; int version; /* Record version */ char *uuid; /* uid code */ char *name; /* friendly name */ float volume; /* Volume of this unit */ char *air_address; /* DS18B20 address */ int air_state; /* 0=ok, 1=missing, 2=error */ int air_temperature; /* Air temperature in C * 1000 */ char *beer_address; /* DS18B20 address */ int beer_state; /* 0=ok, 1=missing, 2=error */ int beer_temperature; /* Beer temperature in C * 1000 */ char *io1_address; /* DS2413 address */ char *io2_address; /* DS2413 address */ int heater_available; /* Heater available */ int heater_state; /* Heater status */ int cooler_available; /* Cooler available */ int cooler_state; /* Cooler status */ int fan_available; /* Fan available */ int fan_state; /* Fan status */ int door_state; /* Door and light status */ int mode; /* Unit mode */ float beer_set; /* Beer temperature setting */ float fridge_set; /* Fridge temperature setting */ float temp_set_min; /* Minimum temperature */ float temp_set_max; /* Maximum temperature */ float idle_rangeL; /* Idle temperature low */ float idle_rangeH; /* Idle range high */ char *profile; /* Active profile uuid */ time_t prof_started; /* Profile start time */ int prof_state; /* Profile OFF|PAUSE|RUN|DONE */ float prof_target; /* Profile current target temp */ } units_list; #define UNITMODE_OFF 0 /* Unit turned off */ #define UNITMODE_NONE 1 /* Unit on but does nothing */ #define UNITMODE_FRIDGE 2 /* Unit acts as a fridge */ #define UNITMODE_BEER 3 /* Unit acts as beer cooler */ #define UNITMODE_PROFILE 4 /* Unit runs in profile mode */ /* * Fermenting steps */ typedef struct _prof_step { struct _prof_step *next; int version; /* Version 1 */ int steptime; /* Step time to target in hours */ int resttime; /* Rest time on target in hours */ float target; /* Target temperature */ } prof_step; /* * Fermenting profiles */ typedef struct _prof_list { struct _prof_list *next; int version; /* Version 1 */ char *uuid; /* Profile uuid */ char *name; /* Profile name */ int busy; /* Profile busy == 1, free == 0 */ prof_step *steps; /* Profile steps */ } profiles_list; #define PROFILE_OFF 0 /* Profile not active */ #define PROFILE_PAUSE 1 /* Profile pause */ #define PROFILE_RUN 2 /* Profile is running */ #define PROFILE_DONE 3 /* Profile is finished */ /* * External devices like sensors, relays. */ typedef struct _dev_list { struct _dev_list *next; int version; /* Version 1 */ char *uuid; /* UUID of this device */ int type; /* Device type */ int direction; /* Device direction */ int value; /* Device value */ int present; /* Device present */ char *address; /* Device address */ int subdevice; /* Device sub address */ int gpiopin; /* Device GPIO pin or -1 */ char *description; /* Device description */ int inuse; /* In use counter */ char *comment; /* What we think it is */ time_t timestamp; /* Last updated */ } devices_list; #define DEVTYPE_NA 0 /* Unknown device type */ #define DEVTYPE_W1 1 /* 1-Wire bus */ #define DEVTYPE_GPIO 2 /* GPIO I/O device */ #define DEVTYPE_RC433 3 /* 433 MHz device */ #define DEVTYPE_DHT 4 /* DHT type device on GPIO */ #define DEVTYPE_I2C 5 /* I2C bus device */ #define DEVTYPE_SPI 6 /* SPI bus device */ #define DEVPRESENT_UNDEF 0 /* Precence not testable */ #define DEVPRESENT_NO 1 /* Device is missing */ #define DEVPRESENT_YES 2 /* Device is detected */ #define DEVPRESENT_ERROR 3 /* Device is in error */ #define DEVDIR_UNDEF 0 /* Undefined */ #define DEVDIR_IN_BIN 1 /* Binary input */ #define DEVDIR_OUT_BIN 2 /* Binary output */ #define DEVDIR_IN_ANALOG 3 /* Temperature input etc. */ #define DEVDIR_OUT_ANALOG 4 /* Analog steering */ #define DEVDIR_OUT_PWM 5 /* PWM outout */ #define DEVDIR_INTERN 6 /* Internal function */ typedef struct _sys_config { char *name; /* Configuration name */ int my_port; /* my client/server port */ unsigned char tempFormat; /* Temperature format, C or F */ char *air_address; /* 1-wire environment sensor */ int air_state; /* 0=ok, 1=missing, 2=error */ int air_temperature; /* Air temperature in C * 1000 */ #ifdef HAVE_WIRINGPI_H int lcd_cols; /* LCD display columns */ int lcd_rows; /* LCD display rows */ int lcd_address; /* LCD display i2c address */ #endif units_list *units; /* Fermenter units */ profiles_list *profiles; /* Ferment profiles */ devices_list *devices; /* Sensors and switches */ } sys_config; #endif