thermferm/thermferm.h

Tue, 24 Jun 2014 22:38:46 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 24 Jun 2014 22:38:46 +0200
changeset 75
4b976601737d
parent 74
879bd09e2b96
child 76
d2c7b32f27d6
permissions
-rw-r--r--

Writes a basic xml configuration next to the plain ascii config file

#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>
#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)"

/* rdconfig.c */
typedef struct _key_list {
    char		*key;
    int			(*prc)(char **);
    char		**dest;
} key_list;

/*
 * 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 DS2408 for 8 bits I/O to read status, turn heater/cooler on/off etc.
 */
typedef struct _units_list {
    struct _units_list	*next;
    char		*uid;			/* uid code			*/
    char		*name;			/* friendly name		*/
    float		volume;			/* Volume of this unit		*/
    char		*air_address;		/* DS18B20 address		*/
    float		air_temp;		/* Air temperature		*/
    char		*beer_address;		/* DS18B20 address		*/
    float		beer_temp;		/* Beer temperature		*/
    char		*io_address;		/* DS2408 address		*/
    unsigned char	io_read;		/* I/O ports read state		*/
    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			light_available;	/* Door sensor and int. light	*/
    int			light_state;		/* Door and light status	*/
    int			mode;			/* Unit mode			*/
    char		*profile;		/* Active profile		*/
    time_t		prof_started;		/* Profile start time		*/
} units_list;

#define	UNITMODE_NA		0		/* Unit is missing		*/
#define	UNITMODE_OFF		1		/* Unit turned off		*/
#define	UNITMODE_NONE		2		/* Unit on but does nothing	*/
#define	UNITMODE_FRIDGE		3		/* Unit acts as a fridge	*/
#define	UNITMODE_BEER		4		/* Unit acts as beer cooler	*/
#define	UNITMODE_PROFILE	5		/* Unit runs in profile mode	*/

#define	UNITIO_HEATER		0x01		/* Heater bit			*/
#define	UNITIO_COOLER		0x02		/* Cooler bit			*/
#define	UNITIO_FAN		0x04		/* Fan bit			*/
#define	UNITIO_LIGHT		0x08		/* Light bit			*/
#define	UNITIO_DOOR		0x10		/* Door status			*/

typedef struct _w1_therm {
    struct _w1_therm    *next;
    char                *master;                /* Master for this device       */
    int                 bus;                    /* Reserved for ds2482-800      */
    char                *name;                  /* Name of this device          */
    char                *alias;                 /* Friendly name                */
    int                 present;                /* 1=present, 0=absent          */
    int                 lastval;                /* Last valid value             */
    int			update;			/* Value updated		*/
} w1_therm;

typedef struct _sys_config {
    char		*name;			/* Configuration name		*/
    int			my_port;		/* my client/server port	*/
    w1_therm		*w1therms;		/* 1-wire temp sensors		*/
#ifdef HAVE_WIRINGPI_H
    int			lcd_cols;		/* LCD display columns		*/
    int			lcd_rows;		/* LCD display rows		*/
#endif
    units_list		*units;			/* Fermenter units		*/
    						/* ControlSettings:		*/
    unsigned char	cs_mode;		/* mode				*/
    float		cs_beerSet;		/* beer temperature		*/
    float		cs_fridgeSet;		/* fridge temperature		*/
    float		cs_heatEstimator;
    float		cs_coolEstimator;
    						/* ControlConstants		*/
    unsigned char	cc_tempFormat;
    float		cc_tempSetMin;
    float		cc_tempSetMax;
    float		cc_idleRangeH;
    float		cc_idleRangeL;
} sys_config;


void killconfig(void);
int  rdconfig(char *);
int  wrconfig(char *, char *);


/* lock.c */
int  lockprog(char *);
void ulockprog(char *);


/* xutil.c */
char *xmalloc(size_t);
char *xstrcpy(char *);
char *xstrcat(char *, char *);


#ifdef HAVE_WIRINGPI_H

/* lcd-pcf8574.c */
// Defines for the pcf8574 Pi LCD interface board
#define AF_BASE         100

#define AF_RS           (AF_BASE + 0)
#define AF_RW           (AF_BASE + 1)
#define AF_E            (AF_BASE + 2)
#define AF_BACKLIGHT    (AF_BASE + 3)
#define AF_DB4          (AF_BASE + 4)
#define AF_DB5          (AF_BASE + 5)
#define AF_DB6          (AF_BASE + 6)
#define AF_DB7          (AF_BASE + 7)

void setBacklight (int);
int  initLCD (int, int);
void mb_lcdPutchar(const int, unsigned char);
void mb_lcdPuts(const int, const char *);
void mb_lcdClear(const int);

#endif

/* logger.c */
void logger(char *, char *, char *);

#ifdef HAVE_WIRINGPI_H
PI_THREAD (my_sensors_loop);
#else
void *my_sensors_loop(void *);
#endif

/* server.c */
void defaultControlSettings(void);
void defaultControlConstants(void);
#ifdef HAVE_WIRINGPI_H
PI_THREAD (my_server_loop);
#else
void *my_server_loop(void *);
#endif


#endif

mercurial