Tue, 25 Dec 2018 13:42:36 +0100
Import from brouwhulp fix style color ranges. Added calcSVG and calcABV calculation. Added batch size, time, efficiency and og change actions. Added style select and redesigned the first tab to fit this in. When equipment is changed, recalculate the recipe. Added print button.
0 | 1 | /** |
2 | * @file bms.h | |
3 | */ | |
4 | ||
5 | #ifndef _BMS_H | |
6 | #define _BMS_H | |
7 | ||
8 | #define TRUE 1 | |
9 | #define FALSE 0 | |
10 | ||
11 | #include "../config.h" | |
12 | ||
13 | #include <stdlib.h> | |
14 | #include <stdio.h> | |
15 | #include <stdint.h> | |
16 | #include <stdarg.h> | |
17 | #include <string.h> | |
18 | #include <ctype.h> | |
19 | #include <sys/types.h> | |
20 | #include <sys/socket.h> | |
21 | #include <sys/stat.h> | |
22 | #include <sys/time.h> | |
23 | #include <sys/un.h> | |
24 | #include <sys/utsname.h> | |
25 | #include <pwd.h> | |
26 | #include <time.h> | |
27 | #include <fcntl.h> | |
28 | #include <syslog.h> | |
29 | #include <unistd.h> | |
30 | #include <errno.h> | |
31 | #include <signal.h> | |
32 | #include <getopt.h> | |
33 | #include <limits.h> | |
34 | #include <sys/socket.h> | |
35 | #include <arpa/inet.h> | |
36 | #include <netdb.h> | |
37 | #include <poll.h> | |
38 | #include <dirent.h> | |
39 | #include <uuid/uuid.h> | |
40 | #include <math.h> | |
41 | #include <assert.h> | |
42 | #include <libgen.h> | |
43 | #include <libxml/xmlmemory.h> | |
44 | #include <libxml/parser.h> | |
45 | #include <libxml/encoding.h> | |
46 | #include <libxml/xmlwriter.h> | |
47 | #include <mosquitto.h> | |
48 | #include <mysql/mysql.h> | |
49 | #include <json-c/json.h> | |
50 | ||
51 | ||
52 | #define MBSE_SS(x) (x)?(x):"(null)" | |
53 | ||
54 | ||
55 | #define MQTT_NODE_CONTROL 0x0001 ///< Show node control | |
56 | ||
57 | ||
58 | ||
59 | /** | |
60 | * @brief Configuration structure. Stored in a flat ascii file ~/.bms/bms.config | |
61 | */ | |
62 | typedef struct _sys_config { | |
63 | char *bms_name; ///< Brewery name | |
64 | char *bms_uuid; ///< Brewery uuid | |
65 | char *mysql_host; ///< MySQL host | |
66 | int mysql_port; ///< MySQL port | |
67 | char *mysql_user; ///< MySQL user name | |
68 | char *mysql_pass; ///< MySQL password | |
69 | char *mysql_database; ///< MySQL database | |
70 | char *mqtt_host; ///< MQTT host | |
71 | int mqtt_port; ///< MQTT port | |
72 | char *mqtt_user; ///< MQTT username of NULL | |
73 | char *mqtt_pass; ///< MQTT password of NULL | |
74 | } sys_config; | |
75 | ||
76 | ||
77 | /** | |
78 | * @brief Structure for the nodes. Database table 'nodes'. | |
79 | */ | |
80 | typedef struct _sys_node_list { | |
81 | struct _sys_node_list *next; | |
82 | char *uuid; ///< uuid string | |
83 | char *node; ///< nodename | |
84 | bool online; ///< on-line state | |
85 | char *group_id; ///< group type | |
86 | char *hardwaremake; ///< hardware make | |
87 | char *hardwaremodel; ///< hardware model | |
88 | char *os; ///< os type | |
89 | char *os_version; ///< os version | |
90 | char *firmware; ///< application version | |
91 | time_t firstseen; ///< First seen this session | |
92 | time_t lastseen; ///< Last seen this session | |
93 | float temperature; ///< environment temperature | |
94 | float humidity; ///< environment humidity | |
95 | float barometer; ///< environment barometer pressure | |
96 | float gps_latitude; ///< GPS latitude | |
97 | float gps_longitude; ///< GPS longitude | |
98 | float gps_altitude; ///< GPS altitude | |
99 | char *net_address; ///< IPv4 or IPv6 address | |
100 | char *net_ifname; ///< Interface name | |
101 | int net_rssi; ///< RSSI value if wireless. | |
102 | } sys_node_list; | |
103 | ||
104 | ||
105 | /** | |
106 | * @brief Fermenting profile steps | |
107 | */ | |
108 | typedef struct _prof_step { | |
109 | struct _prof_step *next; | |
110 | int steptime; ///< Step time to target in hours | |
111 | int resttime; ///< Rest time on target in hours | |
112 | float target_lo; ///< Low Target temperature | |
113 | float target_hi; ///< High target temperature | |
114 | int fridge_mode; ///< Fridge or beer mode | |
115 | } prof_step; | |
116 | ||
117 | ||
118 | typedef enum | |
119 | { | |
120 | FERMENTER_MODE_OFF = 0, ///< Fermenter is off. | |
121 | FERMENTER_MODE_NONE, ///< Fermenter on but does nothing. | |
122 | FERMENTER_MODE_FRIDGE, ///< Fermenter acts as a fridge. | |
123 | FERMENTER_MODE_BEER, ///< Fermenter acts as beer cooler. | |
124 | FERMENTER_MODE_PROFILE, ///< Fermenter runs in profile mode. | |
125 | } FERMENTER_MODE; | |
126 | ||
127 | typedef enum | |
128 | { | |
129 | FERMENTER_STAGE_PRIMARY = 0, ///< Fermentation primage stage. | |
130 | FERMENTER_STAGE_SECONDARY, ///< Fermenter secondary stage. | |
131 | FERMENTER_STAGE_TERTIARY, ///< Fermenter tertiary stage. | |
34 | 132 | FERMENTER_STAGE_CARBONATION, ///< Fermenter carbonation stage. |
0 | 133 | } FERMENTER_STAGE; |
134 | ||
135 | typedef enum | |
136 | { | |
137 | DEVPRESENT_UNDEF = 0, ///< Precence not detectable. | |
138 | DEVPRESENT_NO, ///< Device is missing. | |
139 | DEVPRESENT_YES, ///< Device is present and Ok. | |
140 | DEVPRESENT_ERROR, ///< Device is present but in error state. | |
141 | } DEVPRESENT_STATE; | |
142 | ||
143 | ||
144 | typedef enum | |
145 | { | |
146 | ALARM_FLAG_DOOR = 0x0001, ///< Door open | |
147 | ALARM_FLAG_PSU = 0x0002, ///< PSU problem | |
148 | ALARM_FLAG_CHILLER = 0x0100, ///< Chiller too warm | |
149 | } ALARM_FLAGS; | |
150 | ||
151 | ||
152 | /** | |
153 | * @brief Structure for the fermenters. Stored in database table 'fermenters'. | |
154 | */ | |
155 | typedef struct _fermenter_list { | |
156 | struct _fermenter_list *next; | |
157 | char *uuid; ///< Fixed uuid string | |
158 | char *alias; ///< Fixed short name | |
159 | char *node; ///< Fixed node name | |
160 | bool online; ///< Online status | |
161 | char *beercode; ///< Beer unique code | |
162 | char *beername; ///< Beer name in fermenter | |
163 | char *air_address; ///< Air sensor address | |
164 | char *air_state; ///< Air sensor state | |
165 | float air_temperature; ///< Air temperature | |
166 | char *beer_address; ///< Beer sensor address | |
167 | char *beer_state; ///< Beer sensor state | |
168 | float beer_temperature; ///< Beer temperature | |
169 | char *chiller_address; ///< Chiller sensor address | |
170 | char *chiller_state; ///< Chiller sensor state | |
171 | float chiller_temperature; ///< Chiller temperature | |
172 | char *heater_address; ///< Heater address | |
173 | int heater_state; ///< Heater state | |
174 | uint64_t heater_usage; ///< Heater usage | |
175 | char *cooler_address; ///< Cooler address | |
176 | int cooler_state; ///< Cooler state | |
177 | uint64_t cooler_usage; ///> Cooler usage | |
178 | char *fan_address; ///< Fan address | |
179 | int fan_state; ///< Fan state | |
180 | uint64_t fan_usage; ///< Fan usage | |
181 | char *light_address; ///< Light address | |
182 | int light_state; ///< Light state | |
183 | uint64_t light_usage; ///< Light usage | |
184 | char *door_address; ///< Door address | |
185 | int door_state; ///< Door state | |
186 | char *psu_address; ///< PSU address | |
187 | int psu_state; ///< PSU state | |
188 | char *mode; ///< Fermenter mode | |
189 | char *stage; ///< Fermentation stage | |
190 | uint32_t alarm; ///< Alarm flag | |
191 | float setpoint_high; ///< Setpoint high | |
192 | float setpoint_low; ///< Setpoint low | |
193 | char *profile_uuid; ///< Profile uuid | |
194 | char *profile_name; ///< Profile name | |
195 | char *profile_state; ///< Profile state | |
196 | int profile_percent; ///< Profile percent done | |
197 | float profile_inittemp_high; ///< Profile init temp high | |
198 | float profile_inittemp_low; ///< Profile init temp low | |
199 | char *profile_steps; ///< Profile steps in JSON | |
200 | } sys_fermenter_list; | |
201 | ||
202 | ||
203 | ||
204 | typedef enum | |
205 | { | |
206 | PROFILE_OFF = 0, ///< Profile not active | |
207 | PROFILE_PAUSE, ///< Profile pause | |
208 | PROFILE_RUN, ///< Profile is running | |
209 | PROFILE_DONE, ///< Profile is finished | |
210 | PROFILE_ABORT, ///< Profile abort | |
211 | } PROFILE_STATE; | |
212 | ||
213 | ||
214 | ||
215 | /** | |
216 | * @brief Strcuture holding a fermentation log entry. | |
217 | */ | |
218 | typedef struct fermenting_log { | |
219 | char *datetime; ///< Date/time stamp | |
220 | char *product_uuid; ///< Product uuid | |
221 | char *product_code; ///< Product code | |
222 | char *product_name; ///< Product name | |
223 | float temperature_air; ///< Temperature air | |
224 | float temperature_beer; ///< Temperature beer | |
225 | float temperature_chiller; ///< Temperature chiller (if pressent) | |
226 | float temperature_room; ///< Temperature room | |
227 | int heater_power; ///< Heater power 0..100 | |
228 | uint64_t heater_usage; ///< Heater usage counter in seconds. | |
229 | int cooler_power; ///< Cooler power 0..100 | |
230 | uint64_t cooler_usage; ///< Cooler usage counter in seconds. | |
231 | int fan_power; ///< Fan power 0 or 100 | |
232 | uint64_t fan_usage; ///< Fan usage counter in seconds | |
233 | float setpoint_low; ///< Target temperature low | |
234 | float setpoint_high; ///< Tarhet temperature high | |
235 | char *mode; ///< Working mode. | |
236 | char *stage; ///< Fermentation stage | |
237 | char *event; ///< Optional event | |
238 | char *fermenter_uuid; ///< Fermenter in use | |
239 | char *fermenter_node; ///< Fermenter node | |
240 | char *fermenter_alias; ///< Fermenter_alias | |
241 | } fermentation_log; | |
242 | ||
243 | ||
244 | ||
245 | /** | |
246 | * @brief Brew computer controllers. Must have hardware + installation + recipe data. | |
247 | */ | |
248 | typedef struct _brewer_list { | |
249 | struct _brewer_list *next; | |
250 | char *uuid; | |
251 | } brewer_list; | |
252 | ||
253 | ||
254 | // Make it universal and make it connectable with a fermenter. | |
255 | typedef struct _ispindel_list { | |
256 | struct _ispindel_list *next; | |
257 | char *uuid; ///< Fixed uuid string | |
258 | char *name; ///< Name or description (Red iSpindle). | |
259 | char *beercode; ///< Beer code if in use. | |
260 | float temperature; ///< Temperature of the beer. | |
261 | float gravity; ///< Measured gravity | |
262 | // What nore, battery? | |
263 | } ispindel_list; | |
264 | ||
265 | ||
266 | // Hergisting meters. | |
267 | ||
268 | /** | |
269 | * @brief Standalone temperature loggers. (Freezers, refrigerators, chambers). | |
270 | */ | |
271 | typedef struct _thb_list { | |
272 | struct _thb_list *next; | |
273 | char *uuit; ///< Fixed uuid string | |
274 | char *name; ///< Name or description | |
275 | char *beercode; ///< Beer code if needed. | |
276 | float temperature; ///< Temperature in Celcius | |
277 | float humidity; ///< Humidity in % | |
278 | float barometer; ///< Air pressure. | |
279 | float gps_latitude; ///< GPS latitude | |
280 | float gps_longitude; ///< GPS longitide | |
281 | float gps_altitude; ///< GPS altitude | |
282 | } thb_list; | |
283 | ||
284 | ||
285 | #endif |