brewco/brewco.h

changeset 487
d5bc44183aa4
parent 486
5a237a99a793
child 488
bee1f70fb42b
equal deleted inserted replaced
486:5a237a99a793 487:d5bc44183aa4
1 #ifndef _BREWCO_H
2 #define _BREWCO_H
3
4 #define TRUE 1
5 #define FALSE 0
6
7 #include "../config.h"
8 #include "pid.h"
9
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <stdint.h>
13 #include <stdarg.h>
14 #include <string.h>
15 #include <ctype.h>
16 #include <sys/types.h>
17 #include <sys/socket.h>
18 #include <sys/stat.h>
19 #include <sys/time.h>
20 #include <time.h>
21 #include <utime.h>
22 #include <fcntl.h>
23 #include <syslog.h>
24 #include <unistd.h>
25 #include <errno.h>
26 #include <signal.h>
27 #include <getopt.h>
28 #include <limits.h>
29 #include <sys/socket.h>
30 #include <arpa/inet.h>
31 #include <netdb.h>
32 #include <poll.h>
33 #include <dirent.h>
34 #include <uuid/uuid.h>
35 #include <math.h>
36 #include <zlib.h>
37
38
39 #ifndef HAVE_WIRINGPI_H
40 #include <pthread.h>
41 #endif
42 #include <libxml/xmlmemory.h>
43 #include <libxml/parser.h>
44 #include <libxml/encoding.h>
45 #include <libxml/xmlwriter.h>
46
47 #ifdef HAVE_WIRINGPI_H
48 /* wiringPi */
49 #include <wiringPi.h>
50 #include <pcf8574.h>
51 #include <lcd.h>
52
53 /*
54 * Thread locks
55 */
56 #define LOCK_DEVICES 0
57 #define LOCK_LCD 1
58 #define LOCK_MENU 2
59 #define LOCK_SPARE2 3
60
61
62 #endif
63
64 /*
65 * 1-Wire devices
66 */
67 #define W1_FAMILY_DEFAULT 0
68 #define W1_FAMILY_SMEM_01 0x01
69 #define W1_FAMILY_SMEM_81 0x81
70 #define W1_THERM_DS18S20 0x10
71 #define W1_FAMILY_DS28E04 0x1C
72 #define W1_COUNTER_DS2423 0x1D
73 #define W1_THERM_DS1822 0x22
74 #define W1_EEPROM_DS2433 0x23
75 #define W1_THERM_DS18B20 0x28
76 #define W1_FAMILY_DS2408 0x29
77 #define W1_EEPROM_DS2431 0x2D
78 #define W1_FAMILY_DS2760 0x30
79 #define W1_FAMILY_DS2780 0x32
80 #define W1_FAMILY_DS2413 0x3A
81 #define W1_THERM_DS1825 0x3B
82 #define W1_FAMILY_DS2781 0x3D
83 #define W1_THERM_DS28EA00 0x42
84
85
86 #define MBSE_SS(x) (x)?(x):"(null)"
87
88
89
90
91 /*
92 * Sensor strcuture
93 */
94 typedef struct _sensor_var {
95 char *uuid; /* sensor uuid */
96 int state; /* sensor state */
97 int value; /* sensor value */
98 } sensor_var;
99
100
101
102 /*
103 * Switch structure
104 */
105 typedef struct _switch_var {
106 char *uuid; /* switch uuid */
107 int value; /* switch value (0..100) */
108 int delay; /* switch delay */
109 } switch_var;
110
111
112
113 /*
114 * Brewing units. The sensors of the units are connected via the 1-wire bus.
115 * The heaters, pumps (or mixer) are connected on the Pi GPIO. The hardware
116 * is configured in the devices lists.
117 */
118 typedef struct _units_list {
119 struct _units_list *next;
120 int version; /* Record version */
121 char *uuid; /* uuid code */
122 char *name; /* Unit name */
123 int number; /* Unit number */
124 int active; /* 0/1 active unit */
125 sensor_var hlt_sensor; /* HLT sensor */
126 switch_var hlt_heater; /* HLT heater */
127 int hlt_heater_mltfirst; /* HLT heater MLT high priority */
128 sensor_var mlt_sensor; /* MLT sensor */
129 switch_var mlt_heater; /* MLT heater */
130 switch_var mlt_pump; /* MLT pump */
131 int pump_cycle; /* 5..15 minutes */
132 int pump_rest; /* 1..5 minutes */
133 int pump_premash; /* 0/1 */
134 int pump_onmash; /* 0/1 */
135 int pump_mashout; /* 0/1 */
136 int pump_onboil; /* 0/1 pump during boiling */
137 float pump_stop; /* 80..105 C */
138 int skip_add; /* 0/1 skip Add phase */
139 int skip_remove; /* 0/1 skip Remove phase */
140 int skip_iodine; /* 0/1 skip Iodine test */
141 int iodine_time; /* 0..90 minutes */
142 int whirlpool; /* off/cold/hot */
143 pid_var *PID_hlt; /* HLT PID */
144 pid_var *PID_mlt; /* MLT PID */
145 } units_list;
146
147
148
149 /*
150 * External devices like sensors, relays, SSR.
151 */
152 typedef struct _dev_list {
153 struct _dev_list *next;
154 int version; /* Version 1 */
155 char *uuid; /* UUID of this device */
156 int type; /* Device type */
157 int direction; /* Device direction */
158 int value; /* Device value */
159 int offset; /* Device offset value */
160 int present; /* Device present */
161 char *address; /* Device address */
162 int subdevice; /* Device sub address */
163 int gpiopin; /* Device GPIO pin or -1 */
164 char *description; /* Device description */
165 int inuse; /* In use counter */
166 char *comment; /* What we think it is */
167 time_t timestamp; /* Last updated */
168 } devices_list;
169
170
171 #define DEVTYPE_NA 0 /* Unknown device type */
172 #define DEVTYPE_W1 1 /* 1-Wire bus */
173 #define DEVTYPE_GPIO 2 /* GPIO I/O device */
174 #define DEVTYPE_I2C 3 /* I2C bus device */
175 #define DEVTYPE_SPI 4 /* SPI bus device */
176 #ifdef USE_SIMULATOR
177 #define DEVTYPE_SIM 5 /* Simulated device */
178 #endif
179
180 #define DEVPRESENT_UNDEF 0 /* Precence not testable */
181 #define DEVPRESENT_NO 1 /* Device is missing */
182 #define DEVPRESENT_YES 2 /* Device is detected */
183 #define DEVPRESENT_ERROR 3 /* Device is in error */
184
185 #define DEVDIR_UNDEF 0 /* Undefined */
186 #define DEVDIR_IN_BIN 1 /* Binary input */
187 #define DEVDIR_OUT_BIN 2 /* Binary output */
188 #define DEVDIR_IN_ANALOG 3 /* Temperature input etc. */
189 #define DEVDIR_OUT_ANALOG 4 /* Analog steering */
190 #define DEVDIR_OUT_PWM 5 /* PWM outout */
191 #define DEVDIR_INTERN 6 /* Internal function */
192
193
194
195 /*
196 * Recipes.
197 */
198 typedef struct _mash_step {
199 char *name; /* Step name */
200 int min; /* Minimum temperature */
201 int max; /* Maximum temperature */
202 int canskip; /* 0/1 can we skip this step */
203 float setpoint; /* Temperature setpoint */
204 int skip; /* Skip this step */
205 int duration; /* Step duration */
206 } mash_step;
207
208 typedef struct _hop_stand {
209 char *name; /* Hop stand name */
210 int min; /* Minimum temperature */
211 int max; /* Maximum temperature */
212 int hold; /* Hold temperature at */
213 float setpoint; /* Hold temperature setpoint */
214 int skip; /* Skip this one */
215 int duration; /* Hold time */
216 } hop_stand;
217
218 typedef struct _hop_addition {
219 char *name; /* Hop name */
220 int skip; /* Skip addition */
221 int boiltime; /* -1=fwh, 0..boiltime */
222 } hop_addition;
223
224 typedef struct _a_recipe {
225 struct _a_recipe *next;
226 char *uuid; /* Recipe uuid */
227 char *code; /* Recipe code */
228 char *name; /* Recipe name */
229 int boiltime; /* 1..240 minutes */
230 float coolto; /* Cooling target */
231 time_t starttime; /* Start time */
232 time_t endtime; /* Ending time */
233 mash_step mash[8]; /* 8 mash steps */
234 hop_addition hops[10]; /* 10 hop additions */
235 hop_stand hopstand[3]; /* 3 hopstand slots */
236 } a_recipe;
237
238
239
240
241 #ifdef USE_SIMULATOR
242
243 /*
244 * Simulate a HLT and MLT.
245 */
246 typedef struct _simulator {
247 double room_temperature; /* Simulated envionment temp */
248 double hlt_temperature; /* Simulated HLT temperature */
249 double hlt_heater_temp; /* Maximum heater temp */
250 int hlt_heater_volume; /* Water volume */
251 int hlt_heater_power; /* Power of the heater */
252 int hlt_heater_state; /* Heater status */
253 double mlt_temperature; /* Simulated MLT temperature */
254 double mlt_heater_temp; /* Maximum heater temp */
255 int mlt_heater_volume; /* Water volume */
256 int mlt_heater_power; /* Power of the heater */
257 int mlt_heater_state; /* Heater status */
258 } simulator_var;
259
260 #endif
261
262
263
264 typedef struct _sys_config {
265 char *name; /* Configuration name */
266 int my_port; /* my client/server port */
267 unsigned char tempFormat; /* Temperature format, C or F */
268 sensor_var *roomtemp; /* Environment temperature */
269 int lcd_cols; /* LCD display columns */
270 int lcd_rows; /* LCD display rows */
271 int lcd_address; /* LCD display i2c address */
272 units_list *units; /* Brewing units */
273 devices_list *devices; /* Sensors and switches */
274 #ifdef USE_SIMULATOR
275 simulator_var *simulator; /* Simulator */
276 #endif
277 } sys_config;
278
279
280
281 /*
282 * Brewing state file ~/.brewco/var/brewing.xml
283 * If present a brew session is running
284 */
285 #define STEP_NA 0 /* Not in any step yet */
286 #define STEP_BREWINIT 1 /* Initialize brew */
287 #define STEP_WATERCHECK 2 /* Water added? */
288 #define STEP_PUMPPRIME 3 /* Pump Prime */
289 #define STEP_WAITSTART 4 /* Wait for starttime */
290 #define STEP_PREMASH 5 /* Pre-mash */
291 #define STEP_MASHING 6 /* Mash steps */
292 #define STEP_MASHREMOVE 7 /* Remove mash */
293 #define STEP_PREBOIL 8 /* Heating before boil */
294 #define STEP_BOILING 9 /* Boil */
295 #define STEP_BOILDONE 10 /* Boil done, hopstand */
296 #define STEP_COOLING 11 /* Cooling */
297 #define STEP_HOPSTAND 12 /* Hopstand */
298 #define STEP_WHIRLPOOL 13 /* Final whirlpool */
299 #define STEP_CLEANUP 14 /* Cleanup */
300 #define STEP_BREWDONE 15 /* Final step */
301
302 #define MASH_NA 0 /* Not in any state yet */
303 #define MASH_PROMPT 1 /* Prompt for mash */
304 #define MASH_IODINE 2 /* Prompt for iodine test */
305 #define MASH_HEATING 3 /* Heating phase */
306 #define MASH_REST 4 /* Rest phase */
307 #define MASH_DONE 5 /* This step is done */
308
309
310
311 typedef struct _brew_session {
312 char *uuid_recipe; /* Brewing this recipe */
313 char *uuid_unit; /* Brewing unit */
314 char *name; /* Session name */
315 int brewstep; /* Main steps */
316 int mashstep; /* Mash step */
317 int timeout; /* Generic time downcouner */
318 int boiltimer; /* Boiling downcount */
319 time_t starttime; /* Start of brew */
320 time_t endtime; /* End of brew */
321 } brew_session;
322
323
324 #endif

mercurial