brewco/brewco.h

Wed, 25 Nov 2015 22:49:35 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 25 Nov 2015 22:49:35 +0100
changeset 434
eb724767860d
parent 410
e3f8a51b566a
child 435
4b1ed6897d80
permissions
-rw-r--r--

Brewco first phase development configuration structure.

#ifndef _BREWCO_H
#define	_BREWCO_H

#define TRUE 1
#define FALSE 0

#include "../config.h"
#include "pid.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/socket.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>
#include <math.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>

/*
 * Thread locks
 */
#define LOCK_DEVICES            0
#define LOCK_LCD                1
#define LOCK_MENU               2
#define LOCK_SPARE2             3


#endif

/*
 * 1-Wire devices
 */
#define W1_FAMILY_DEFAULT       0
#define W1_FAMILY_SMEM_01       0x01
#define W1_FAMILY_SMEM_81       0x81
#define W1_THERM_DS18S20        0x10
#define W1_FAMILY_DS28E04       0x1C
#define W1_COUNTER_DS2423       0x1D
#define W1_THERM_DS1822         0x22
#define W1_EEPROM_DS2433        0x23
#define W1_THERM_DS18B20        0x28
#define W1_FAMILY_DS2408        0x29
#define W1_EEPROM_DS2431        0x2D
#define W1_FAMILY_DS2760        0x30
#define W1_FAMILY_DS2780        0x32
#define W1_FAMILY_DS2413        0x3A
#define W1_THERM_DS1825         0x3B
#define W1_FAMILY_DS2781        0x3D
#define W1_THERM_DS28EA00       0x42


#define MBSE_SS(x) (x)?(x):"(null)"



/*
 * Brewing units. The sensors of the units are connected via the 1-wire bus.
 * The heaters, pumps (or mixer) are connected on the Pi GPIO. The hardware
 * is configured in the devices lists.
 */
typedef struct _units_list {
    struct _units_list  *next;
    int                 version;                /* Record version               */
    char		*uuid;			/* uuid code			*/
    char                *name;                  /* Unit name                    */
    char                *hlt_sensor_address;    /* HLT sensor address           */
    int                 hlt_sensor_state;       /* HLT sensor state             */
    int                 hlt_sensor_value;       /* HLT sensor value             */
    char		*hlt_heater_address;	/* HLT heater address		*/
    int			hlt_heater_state;	/* HLT heater state 0..100	*/
    int			hlt_heater_delay;	/* HLT heater delay / 15 sec	*/
    int			hlt_heater_mltfirst;	/* HLT heater MLT high priority	*/
    char                *mlt_sensor_address;    /* MLT sensor address           */
    int                 mlt_sensor_state;       /* MLT sensor state             */
    int                 mlt_sensor_value;       /* MLT sensor value             */
    char		*mlt_heater_address;	/* MLT heater address		*/
    int			mlt_heater_state;	/* MLT heater state 0..100	*/
    int			mlt_heater_delay;	/* MLT heater delay / 15 sec	*/
    char		*mlt_pump_address;	/* MLT pump address		*/
    int			mlt_pump_state;		/* MLT pump state 0..100	*/
    int			mlt_pump_delay;		/* MLT_pump_delay		*/
    pid_var		*PID_hlt;		/* HLT PID			*/
    pid_var		*PID_mlt;		/* MLT PID			*/
} units_list;



/*
 * External devices like sensors, relays, SSR.
 */
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                 offset;                 /* Device offset 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_I2C             3               /* I2C bus device               */
#define DEVTYPE_SPI             4               /* SPI bus device               */
#ifdef USE_SIMULATOR
#define DEVTYPE_SIM             5               /* Simulated device             */
#endif

#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            */


#ifdef USE_SIMULATOR

/*
 * Simulate a HLT and MLT.
 */
typedef struct _simulator {
    struct _simulator   *next;
    int                 version;                /* Version of this record       */
    char                *uuid;                  /* Simulator uuid               */
    char                *name;                  /* Simulator name               */
    double		room_temperature;	/* Simulated envionment temp	*/
    double		hlt_temperature;	/* Simulated HLT temperature	*/
    double		hlt_heater_temp;	/* Maximum heater temp		*/
    int			hlt_heater_time;	/* Time to reach temperature	*/
    float		hlt_heater_size;	/* Size of the heater		*/
    int			hlt_heater_state;	/* Heater status		*/
    double		mlt_temperature;	/* Simulated MLT temperature	*/
    double		mlt_heater_temp;	/* Maximum heater temp		*/
    int			mlt_heater_time;	/* Time to reach temperature	*/
    float		mlt_heater_size;	/* Size of the heater		*/
    int			mlt_heater_state;	/* Heater status		*/
    /*
     * Status values, maintained by the simulator but stored
     * here so they don't get lost over program restarts.
     */
    double		s_hlt_temp;		/* Temp HLT			*/
    double		s_mlt_temp;		/* Temp MLT			*/
} simulator_list;

#endif



typedef struct _sys_config {
    char		*name;			/* Configuration name		*/
    int			my_port;		/* my client/server port	*/
    unsigned char	tempFormat;		/* Temperature format, C or F	*/
    char                *temp_address;          /* Environment temperature      */
    int                 temp_state;             /* 0=ok, 1=missing, 2=error     */
    int                 temp_value;             /* Air temperature in C * 1000  */
    char                *hum_address;           /* Environment huminity         */
    int                 hum_state;              /* 0=ok, 1=missing, 2=error     */
    int                 hum_value;              /* Huminity in % * 1000         */
    int			lcd_cols;		/* LCD display columns		*/
    int			lcd_rows;		/* LCD display rows		*/
    int			lcd_address;		/* LCD display i2c address	*/
    units_list		*units;			/* Brewing units		*/
    devices_list	*devices;		/* Sensors and switches		*/
#ifdef USE_SIMULATOR
    simulator_list      *simulators;            /* Simulators                   */
#endif
} sys_config;



#endif

mercurial