thermferm/server.c

Mon, 16 Feb 2015 20:41:09 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 16 Feb 2015 20:41:09 +0100
changeset 313
8448fcf3d799
parent 312
7b0f819a3805
child 325
35b6f6605ae3
permissions
-rw-r--r--

Code cleanup

42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /*****************************************************************************
306
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
2 * Copyright (C) 2008-2015
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 *
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * Michiel Broek <mbroek at mbse dot eu>
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 *
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * This file is part of the mbsePi-apps
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 *
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 * This is free software; you can redistribute it and/or modify it
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * under the terms of the GNU General Public License as published by the
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * Free Software Foundation; either version 2, or (at your option) any
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * later version.
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 *
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 * mbsePi-apps is distributed in the hope that it will be useful, but
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 * General Public License for more details.
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 *
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
19 * along with ThermFerm; see the file COPYING. If not, write to the Free
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 *****************************************************************************/
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22
106
1bd9a16f5061 Added .h files
Michiel Broek <mbroek@mbse.eu>
parents: 101
diff changeset
23 #include "rdconfig.h"
46
000399c64d3f More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
24 #include "thermferm.h"
155
0d86f3c0a07b Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents: 140
diff changeset
25 #include "logger.h"
184
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
26 #include "devices.h"
106
1bd9a16f5061 Added .h files
Michiel Broek <mbroek@mbse.eu>
parents: 101
diff changeset
27 #include "server.h"
245
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
28 #include "lcd-buffer.h"
106
1bd9a16f5061 Added .h files
Michiel Broek <mbroek@mbse.eu>
parents: 101
diff changeset
29 #include "xutil.h"
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30
58
e8e7b46b705b Fixed compilation without wiringpi
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
31
75
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 74
diff changeset
32 extern int my_shutdown;
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 74
diff changeset
33 extern int debug;
245
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
34 extern int run_pause;
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
35 extern int run_hold;
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
36 extern sys_config Config;
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
37 extern const char UNITMODE[5][8];
101
1302abe92eb1 Made temperature sensors working in the units
Michiel Broek <mbroek@mbse.eu>
parents: 100
diff changeset
38 extern const char TEMPSTATE[3][8];
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
39 extern const char DEVTYPE[8][6];
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
40 extern const char DEVPRESENT[4][6];
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
41 extern const char DEVDIR[7][11];
217
2922d439ff63 Added profile state ABORT
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
42 extern const char PROFSTATE[5][6];
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
43
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
45 int s; /* connected socket */
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
46 int ls; /* listen socket */
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
48 struct sockaddr_in myaddr_in; /* for local socket address */
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
49 struct sockaddr_in peeraddr_in; /* for peer socket address */
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
50
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
51 struct hostent *hp;
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
52
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
53 #define SS_BUFSIZE 1024
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
54 #define SS_TIMEOUT 300
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55
300
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
56 #define MAX_INTERVALS 6
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
57 const int GRAPH_INTERVAL[MAX_INTERVALS] = { 0, 1, 5, 15, 30, 60, };
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
58 const int GRAPH_DATALINES[MAX_INTERVALS] = { 0, 800, 3200, 12000, 24000, 48000, };
46
000399c64d3f More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
59
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
60 /*
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
61 * Send message to client
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
62 */
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
63 int srv_send(const char *format, ...)
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
64 {
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
65 char out[SS_BUFSIZE];
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
66 va_list va_ptr;
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
67
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
68 if (s == -1)
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
69 return -1;
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
71 va_start(va_ptr, format);
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
72 vsnprintf(out, SS_BUFSIZE-1, format, va_ptr);
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
73 va_end(va_ptr);
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
74
48
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
75 if (debug) {
80
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
76 syslog(LOG_NOTICE, "send: \"%s\"", out);
45
053c4657105f Mirror LCD display on the webpage works
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
77 fprintf(stdout, "send: \"%s\"\n", out);
48
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
78 }
44
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
79
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
80 if (send(s, out, strlen(out), 0) != strlen(out)) {
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 266
diff changeset
81 syslog(LOG_NOTICE, "srv_send failed");
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
82 return -1;
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
83 }
80
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
84
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
85 if (send(s, (char *)"\r\n", 2, 0) != 2) {
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 266
diff changeset
86 syslog(LOG_NOTICE, "srv_send failed");
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
87 return -1;
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
88 }
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
89
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
90 return 0;
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
91 }
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
92
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
93
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
94
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
95 /*
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
96 * Update the device inuse counter.
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
97 */
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
98 void device_count(int plus, char *uuid)
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
99 {
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
100 devices_list *device;
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
101
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
102 for (device = Config.devices; device; device = device->next) {
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
103 if (strcmp(device->uuid, uuid) == 0) {
240
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 237
diff changeset
104 #ifdef HAVE_WIRINGPI_H
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 237
diff changeset
105 piLock(LOCK_DEVICES);
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 237
diff changeset
106 #endif
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
107 if (plus == TRUE) {
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
108 device->inuse++;
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
109 } else {
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
110 if (device->inuse)
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
111 device->inuse--;
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
112 }
240
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 237
diff changeset
113 #ifdef HAVE_WIRINGPI_H
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 237
diff changeset
114 piUnlock(LOCK_DEVICES);
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 237
diff changeset
115 #endif
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
116 }
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
117 }
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
118 }
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
119
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
120
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
121
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
122 int delete_Profile(char *uuid)
138
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
123 {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
124 profiles_list *current = Config.profiles;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
125 profiles_list *previous = NULL;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
126 prof_step *step, *olds;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
127
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
128 while (current) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
129 if (strcmp(current->uuid, uuid) == 0) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
130 if (previous == NULL) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
131 Config.profiles = current->next;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
132 free(current->uuid);
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
133 current->uuid = NULL;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
134 free(current->name);
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
135 current->name = NULL;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
136 if (current->steps) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
137 for (step = current->steps; step; step = olds) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
138 olds = step->next;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
139 free(step);
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
140 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
141 current->steps = NULL;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
142 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
143 free(current);
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
144 return 1;
138
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
145 } else {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
146 free(current->uuid);
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
147 current->uuid = NULL;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
148 free(current->name);
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
149 current->name = NULL;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
150 if (current->steps) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
151 for (step = current->steps; step; step = olds) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
152 olds = step->next;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
153 free(step);
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
154 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
155 current->steps = NULL;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
156 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
157 previous->next = current->next;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
158 free(current);
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
159 current = previous->next;
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
160 return 1;
138
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
161 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
162 } else {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
163 previous = current;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
164 current = current->next;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
165 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
166 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
167
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
168 return 0;
138
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
169 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
170
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
171
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
172
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
173 int delete_Device(char *uuid)
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
174 {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
175 devices_list *current = Config.devices;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
176 devices_list *previous = NULL;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
177
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
178 while (current) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
179 if (strcmp(current->uuid, uuid) == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
180 if (previous == NULL) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
181 Config.devices = current->next;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
182 free(current->uuid);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
183 current->uuid = NULL;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
184 free(current->address);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
185 current->address = NULL;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
186 free(current->description);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
187 current->description = NULL;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
188 free(current->comment);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
189 current->comment = NULL;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
190 free(current);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
191 return 1;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
192 } else {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
193 free(current->uuid);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
194 current->uuid = NULL;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
195 free(current->address);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
196 current->address = NULL;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
197 free(current->description);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
198 current->description = NULL;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
199 free(current->comment);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
200 current->comment = NULL;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
201 previous->next = current->next;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
202 free(current);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
203 current = previous->next;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
204 return 1;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
205 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
206 } else {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
207 previous = current;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
208 current = current->next;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
209 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
210 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
211 return 0;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
212 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
213
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
214
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
215
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
216 /*
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
217 * DEVICE ADD type
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
218 * DEVICE DEL uuid
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
219 * DEVICE LIST
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
220 * DEVICE GET uuid
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
221 * DEVICE PUT uuid
157
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
222 */
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
223 int cmd_device(char *buf)
157
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
224 {
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
225 char *opt, *param, *kwd, *val, ibuf[SS_BUFSIZE];
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
226 devices_list *device, *tmpd;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
227 socklen_t fromlen;
240
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 237
diff changeset
228 int i, rc, rlen, ival;
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
229 uuid_t uu;
157
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
230
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
231 opt = strtok(buf, " \0");
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
232 opt = strtok(NULL, " \0");
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
233
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
234 if (opt == NULL) {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
235 srv_send((char *)"501 Subcommand missing");
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
236 return 1;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
237 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
238 param = strtok(NULL, "\0");
157
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
239
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
240 if (strcmp(opt, (char *)"LIST") == 0) {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
241 srv_send((char *)"212 Devices list follows:");
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
242 for (device = Config.devices; device; device = device->next) {
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
243 srv_send((char *)"%s,%s,%d,%d,%s,%s", device->uuid, device->address, device->subdevice, device->inuse, device->comment, DEVDIR[device->direction]);
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
244 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
245 srv_send((char *)".");
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
246 return 1;
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
247 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
248
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
249 if (param == NULL) {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
250 srv_send((char *)"502 Parameter missing");
157
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
251 return 1;
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
252 }
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
253
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
254 if (strcmp(opt, (char *)"ADD") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
255 if ((strcmp(param, (char *)"RC433") == 0) || (strcmp(param, (char *)"DHT") == 0) ||
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
256 (strcmp(param, (char *)"I2C") == 0) || (strcmp(param, (char *)"SPI") == 0)) {
170
3cb99272b84b A bit of code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 167
diff changeset
257
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
258 device = (devices_list *)malloc(sizeof(devices_list));
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
259 device->next = NULL;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
260 device->version = 1;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
261 device->uuid = malloc(37);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
262 uuid_generate(uu);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
263 uuid_unparse(uu, device->uuid);
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
264 for (i = 0; i < 8; i++) {
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
265 if (strcmp(param, DEVTYPE[i]) == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
266 device->type = i;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
267 break;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
268 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
269 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
270 device->direction = DEVDIR_UNDEF;
209
c5b1dfd83e81 Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents: 208
diff changeset
271 device->value = device->offset = device->subdevice = device->inuse = 0;
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
272 device->present = DEVPRESENT_UNDEF;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
273 device->address = xstrcpy((char *)"Enter address here");
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
274 device->gpiopin = -1;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
275 device->description = xstrcpy((char *)"Describe me here");
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
276 device->comment = xstrcpy((char *)"Comment here");
170
3cb99272b84b A bit of code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 167
diff changeset
277
240
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 237
diff changeset
278 #ifdef HAVE_WIRINGPI_H
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 237
diff changeset
279 piLock(LOCK_DEVICES);
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 237
diff changeset
280 #endif
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
281 if (Config.devices == NULL) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
282 Config.devices = device;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
283 } else {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
284 for (tmpd = Config.devices; tmpd; tmpd = tmpd->next) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
285 if (tmpd->next == NULL) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
286 tmpd->next = device;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
287 break;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
288 }
157
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
289 }
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
290 }
240
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 237
diff changeset
291 #ifdef HAVE_WIRINGPI_H
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 237
diff changeset
292 piUnlock(LOCK_DEVICES);
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 237
diff changeset
293 #endif
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
294 syslog(LOG_NOTICE, "Device %s added", device->uuid);
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
295 srv_send((char *)"211 Device %s added", device->uuid);
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
296 return 0;
157
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
297
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
298 } else {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
299 srv_send((char *)"503 Parameter error");
157
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
300 return 1;
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
301 }
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
302 }
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
303
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
304 if (strcmp(opt, (char *)"DEL") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
305
240
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 237
diff changeset
306 #ifdef HAVE_WIRINGPI_H
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 237
diff changeset
307 piLock(LOCK_DEVICES);
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 237
diff changeset
308 #endif
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 237
diff changeset
309 rc = delete_Device(param);
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 237
diff changeset
310 #ifdef HAVE_WIRINGPI_H
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 237
diff changeset
311 piUnlock(LOCK_DEVICES);
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 237
diff changeset
312 #endif
6bdda35b4a13 Added thread locks for device processing
Michiel Broek <mbroek@mbse.eu>
parents: 237
diff changeset
313 if (rc) {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
314 syslog(LOG_NOTICE, "Device %s deleted", param);
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
315 srv_send((char *)"211 Device %s deleted", param);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
316 return 0;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
317 } else {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
318 srv_send((char *)"440 No such device");
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
319 return 1;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
320 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
321 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
322
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
323 if (strcmp(opt, (char *)"GET") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
324 for (device = Config.devices; device; device = device->next) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
325 if (strcmp(device->uuid, param) == 0) {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
326 srv_send((char *)"213 Device record follows:");
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
327 srv_send((char *)"TYPE,%s", DEVTYPE[device->type]);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
328 srv_send((char *)"DIRECTION,%s", DEVDIR[device->direction]);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
329 srv_send((char *)"VALUE,%d", device->value);
209
c5b1dfd83e81 Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents: 208
diff changeset
330 srv_send((char *)"OFFSET,%d", device->offset);
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
331 srv_send((char *)"PRESENT,%s", DEVPRESENT[device->present]);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
332 srv_send((char *)"ADDRESS,%s", device->address);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
333 srv_send((char *)"SUBDEVICE,%d", device->subdevice);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
334 srv_send((char *)"GPIOPIN,%d", device->gpiopin);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
335 srv_send((char *)"DESCRIPTION,%s", device->description);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
336 srv_send((char *)"INUSE,%d", device->inuse);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
337 srv_send((char *)"COMMENT,%s", device->comment);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
338 srv_send((char *)"TIMESTAMP,%d", (int)device->timestamp);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
339 srv_send((char *)".");
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
340 return 1;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
341 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
342 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
343 srv_send((char *)"440 No such device");
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
344 return 1;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
345 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
346
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
347 if (strcmp(opt, (char *)"PUT") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
348 for (device = Config.devices; device; device = device->next) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
349 if (strcmp(device->uuid, param) == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
350 while (1) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
351 memset((char *)&ibuf, 0, SS_BUFSIZE);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
352 fromlen = sizeof(peeraddr_in);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
353 rlen = recvfrom(s, ibuf, sizeof(ibuf) -1, 0, (struct sockaddr *)&peeraddr_in, &fromlen);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
354 if (rlen == -1) {
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 266
diff changeset
355 syslog(LOG_NOTICE, "recvfrom(): %s", strerror(errno));
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
356 srv_send((char *)"518 recfrom(): %s", strerror(errno));
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
357 return 1;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
358 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
359 for (i = 0; i < strlen(ibuf); i++) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
360 if (ibuf[i] == '\n')
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
361 ibuf[i] = '\0';
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
362 if (ibuf[i] == '\r')
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
363 ibuf[i] = '\0';
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
364 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
365 for (i = strlen(ibuf) -1; i > 0; i--) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
366 if (ibuf[i] == ' ')
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
367 ibuf[i] = '\0';
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
368 else
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
369 break;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
370 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
371 if (strlen(ibuf)) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
372 if (debug) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
373 syslog(LOG_NOTICE, "recv: \"%s\"", ibuf);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
374 fprintf(stdout, "recv: \"%s\"\n", ibuf);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
375 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
376 if (strcmp(ibuf, (char *)".") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
377 srv_send((char *)"219 Accepted Device record");
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
378 return 0;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
379 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
380 kwd = strtok(ibuf, ",\0");
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
381 val = strtok(NULL, "\0");
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
382 if (kwd && val) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
383 if (strcmp(kwd, (char *)"TYPE") == 0) {
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
384 for (i = 0; i < 8; i++) {
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
385 if (strcmp(val, DEVTYPE[i]) == 0) {
276
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 274
diff changeset
386 if (device->type != i)
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 274
diff changeset
387 syslog(LOG_NOTICE, "Device %s changed type %s to %s", device->uuid, DEVTYPE[device->type], DEVTYPE[i]);
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
388 device->type = i;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
389 break;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
390 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
391 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
392
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
393 } else if (strcmp(kwd, (char *)"DIRECTION") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
394 for (i = 0; i < 7; i++) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
395 if (strcmp(val, DEVDIR[i]) == 0) {
276
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 274
diff changeset
396 if (device->direction != i)
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 274
diff changeset
397 syslog(LOG_NOTICE, "Device %s changed direction %s to %s", device->uuid, DEVDIR[device->type], DEVDIR[i]);
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
398 device->direction = i;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
399 break;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
400 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
401 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
402
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
403 } else if (strcmp(kwd, (char *)"VALUE") == 0) {
276
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 274
diff changeset
404 if (sscanf(val, "%d", &ival) == 1) {
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 274
diff changeset
405 if (device->value != ival)
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 274
diff changeset
406 syslog(LOG_NOTICE, "Device %s changed value %d to %d", device->uuid, device->value, ival);
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
407 device->value = ival;
276
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 274
diff changeset
408 }
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
409
209
c5b1dfd83e81 Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents: 208
diff changeset
410 } else if (strcmp(kwd, (char *)"OFFSET") == 0) {
276
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 274
diff changeset
411 if (sscanf(val, "%d", &ival) == 1) {
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 274
diff changeset
412 if (device->offset != ival)
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 274
diff changeset
413 syslog(LOG_NOTICE, "Device %s changed offset %d to %d", device->uuid, device->offset, ival);
209
c5b1dfd83e81 Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents: 208
diff changeset
414 device->offset = ival;
276
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 274
diff changeset
415 }
209
c5b1dfd83e81 Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents: 208
diff changeset
416
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
417 } else if (strcmp(kwd, (char *)"PRESENT") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
418 for (i = 0; i < 4; i++) {
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
419 if (strcmp(val, DEVPRESENT[i]) == 0) {
276
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 274
diff changeset
420 if (device->present != i)
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 274
diff changeset
421 syslog(LOG_NOTICE, "Device %s changed present %s to %s", device->uuid, DEVPRESENT[device->present], DEVPRESENT[i]);
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
422 device->present = i;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
423 break;
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
424 }
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
425 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
426
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
427 } else if (strcmp(kwd, (char *)"ADDRESS") == 0) {
276
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 274
diff changeset
428 if (device->address) {
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 274
diff changeset
429 if (strcmp(device->address, val))
278
76c8a6f18e4d GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
430 syslog(LOG_NOTICE, "Device %s changed address `%s' to `%s'", device->uuid, device->address, val);
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
431 free(device->address);
276
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 274
diff changeset
432 }
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
433 device->address = xstrcpy(val);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
434
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
435 } else if (strcmp(kwd, (char *)"SUBDEVICE") == 0) {
276
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 274
diff changeset
436 if (sscanf(val, "%d", &ival) == 1) {
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 274
diff changeset
437 if (device->subdevice != ival)
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 274
diff changeset
438 syslog(LOG_NOTICE, "Device %s changed subdevice %d to %d", device->uuid, device->subdevice, ival);
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
439 device->subdevice = ival;
276
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 274
diff changeset
440 }
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
441
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
442 } else if (strcmp(kwd, (char *)"GPIOPIN") == 0) {
276
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 274
diff changeset
443 if (sscanf(val, "%d", &ival) == 1) {
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 274
diff changeset
444 if (device->gpiopin != ival)
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 274
diff changeset
445 syslog(LOG_NOTICE, "Device %s changed gpiopin %d to %d", device->uuid, device->gpiopin, ival);
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
446 device->gpiopin = ival;
276
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 274
diff changeset
447 }
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
448
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
449 } else if (strcmp(kwd, (char *)"DESCRIPTION") == 0) {
276
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 274
diff changeset
450 if (device->description) {
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 274
diff changeset
451 if (strcmp(device->description, val))
278
76c8a6f18e4d GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
452 syslog(LOG_NOTICE, "Device %s changed description `%s' to `%s'", device->uuid, device->description, val);
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
453 free(device->description);
276
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 274
diff changeset
454 }
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
455 device->description = xstrcpy(val);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
456
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
457 } else if (strcmp(kwd, (char *)"COMMENT") == 0) {
276
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 274
diff changeset
458 if (device->comment) {
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 274
diff changeset
459 if (strcmp(device->comment, val))
278
76c8a6f18e4d GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
460 syslog(LOG_NOTICE, "Device %s changed comment `%s' to `%s'", device->uuid, device->comment, val);
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
461 free(device->comment);
276
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 274
diff changeset
462 }
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
463 device->comment = xstrcpy(val);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
464
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
465 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
466 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
467 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
468 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
469 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
470 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
471 srv_send((char *)"440 No such device");
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
472 return 1;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
473 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
474
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
475 srv_send((char *)"504 Subcommand error");
157
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
476 return 1;
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
477 }
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
478
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
479
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
480
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
481 /*
206
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
482 * GLOBAL GET
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
483 * GLOBAL PUT
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
484 */
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
485 int cmd_global(char *buf)
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
486 {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
487 char *opt, *kwd, *val, ibuf[SS_BUFSIZE];
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
488 int ival, i, rlen;
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
489 socklen_t fromlen;
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
490
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
491 opt = strtok(buf, " \0");
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
492 opt = strtok(NULL, "\0");
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
493
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
494 if (opt == NULL) {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
495 srv_send((char *)"501 Subcommand missing");
206
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
496 return 1;
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
497 }
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
498
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
499 if (strcmp(opt, (char *)"GET") == 0) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
500 srv_send((char *)"213 Global Settings record follows:");
269
dc88583a068d All web screens now show the program name and version
Michiel Broek <mbroek@mbse.eu>
parents: 268
diff changeset
501 srv_send((char *)"RELEASE,%s", VERSION);
206
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
502 srv_send((char *)"NAME,%s", Config.name);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
503 srv_send((char *)"PORT,%d", Config.my_port);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
504 srv_send((char *)"TEMPFORMAT,%c", Config.tempFormat);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
505 srv_send((char *)"TEMP_ADDRESS,%s", Config.temp_address);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
506 srv_send((char *)"TEMP_STATE,%s", TEMPSTATE[Config.temp_state]);
208
934d45d9751d Added room temperature and humidity to the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
507 srv_send((char *)"TEMP_VALUE,%.1f", Config.temp_value / 1000.0);
206
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
508 srv_send((char *)"HUM_ADDRESS,%s", Config.hum_address);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
509 srv_send((char *)"HUM_STATE,%s", TEMPSTATE[Config.hum_state]);
208
934d45d9751d Added room temperature and humidity to the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
510 srv_send((char *)"HUM_VALUE,%.0f", Config.hum_value / 1000.0);
206
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
511 #ifdef HAVE_WIRINGPI_H
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
512 srv_send((char *)"LCD_COLS,%d", Config.lcd_cols);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
513 srv_send((char *)"LCD_ROWS,%d", Config.lcd_rows);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
514 #endif
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
515 srv_send((char *)".");
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
516 return 1;
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
517 }
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
518
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
519 if (strcmp(opt, (char *)"PUT") == 0) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
520 while (1) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
521 memset((char *)&ibuf, 0, SS_BUFSIZE);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
522 fromlen = sizeof(peeraddr_in);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
523 rlen = recvfrom(s, ibuf, sizeof(ibuf) -1, 0, (struct sockaddr *)&peeraddr_in, &fromlen);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
524 if (rlen == -1) {
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 266
diff changeset
525 syslog(LOG_NOTICE, "recvfrom(): %s", strerror(errno));
206
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
526 srv_send((char *)"518 recfrom(): %s", strerror(errno));
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
527 return 1;
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
528 }
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
529 for (i = 0; i < strlen(ibuf); i++) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
530 if (ibuf[i] == '\n')
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
531 ibuf[i] = '\0';
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
532 if (ibuf[i] == '\r')
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
533 ibuf[i] = '\0';
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
534 }
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
535 for (i = strlen(ibuf) -1; i > 0; i--) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
536 if (ibuf[i] == ' ')
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
537 ibuf[i] = '\0';
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
538 else
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
539 break;
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
540 }
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
541 if (strlen(ibuf)) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
542 if (debug) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
543 syslog(LOG_NOTICE, "recv: \"%s\"", ibuf);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
544 fprintf(stdout, "recv: \"%s\"\n", ibuf);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
545 }
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
546 if (strcmp(ibuf, (char *)".") == 0) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
547 srv_send((char *)"219 Accepted Global record");
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
548 return 0;
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
549 }
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
550 kwd = strtok(ibuf, ",\0");
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
551 val = strtok(NULL, "\0");
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
552 if (kwd) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
553 if (strcmp(kwd, (char *)"NAME") == 0) {
278
76c8a6f18e4d GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
554 if (val && Config.name && strcmp(val, Config.name))
76c8a6f18e4d GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
555 syslog(LOG_NOTICE, "Global name `%s' to `%s'", Config.name, val);
206
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
556 if (Config.name)
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
557 free(Config.name);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
558 if (val)
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
559 Config.name = xstrcpy(val);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
560 else
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
561 Config.name = NULL;
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
562
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
563 } else if (val && (strcmp(kwd, (char *)"PORT") == 0)) {
278
76c8a6f18e4d GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
564 if (sscanf(val, "%d", &ival) == 1) {
76c8a6f18e4d GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
565 if (Config.my_port != ival)
76c8a6f18e4d GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
566 syslog(LOG_NOTICE, "Global port %d to %d", Config.my_port, ival);
206
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
567 Config.my_port = ival;
278
76c8a6f18e4d GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
568 }
206
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
569
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
570 } else if (val && (strcmp(kwd, (char *)"TEMPFORMAT") == 0)) {
278
76c8a6f18e4d GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
571 if ((val[0] == 'C') || (val[0] == 'F')) {
76c8a6f18e4d GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
572 if (Config.tempFormat != val[0])
76c8a6f18e4d GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
573 syslog(LOG_NOTICE, "Global port %c to %c", Config.tempFormat, val[0]);
206
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
574 Config.tempFormat = val[0];
278
76c8a6f18e4d GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
575 }
206
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
576
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
577 } else if (strcmp(kwd, (char *)"TEMP_ADDRESS") == 0) {
278
76c8a6f18e4d GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
578 if (val && Config.temp_address && (strcmp(val, Config.temp_address)))
76c8a6f18e4d GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
579 syslog(LOG_NOTICE, "Global temperature address `%s' to `%s'", Config.temp_address, val);
206
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
580 if (Config.temp_address) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
581 device_count(FALSE, Config.temp_address);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
582 free(Config.temp_address);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
583 }
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
584 if (val) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
585 Config.temp_address = xstrcpy(val);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
586 device_count(TRUE, Config.temp_address);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
587 } else
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
588 Config.temp_address = NULL;
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
589
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
590 } else if (strcmp(kwd, (char *)"HUM_ADDRESS") == 0) {
278
76c8a6f18e4d GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
591 if (val && Config.hum_address && (strcmp(val, Config.hum_address)))
76c8a6f18e4d GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
592 syslog(LOG_NOTICE, "Global humidity address `%s' to `%s'", Config.hum_address, val);
206
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
593 if (Config.hum_address) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
594 device_count(FALSE, Config.hum_address);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
595 free(Config.hum_address);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
596 }
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
597 if (val) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
598 Config.hum_address = xstrcpy(val);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
599 device_count(TRUE, Config.hum_address);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
600 } else
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
601 Config.hum_address = NULL;
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
602
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
603 #ifdef HAVE_WIRINGPI_H
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
604 } else if (val && (strcmp(kwd, (char *)"LCD_COLS") == 0)) {
278
76c8a6f18e4d GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
605 if (sscanf(val, "%d", &ival) == 1) {
76c8a6f18e4d GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
606 if (Config.lcd_cols != ival)
76c8a6f18e4d GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
607 syslog(LOG_NOTICE, "Global LCD columns %d to %d", Config.lcd_cols, ival);
206
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
608 Config.lcd_cols = ival;
278
76c8a6f18e4d GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
609 }
206
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
610
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
611 } else if (val && (strcmp(kwd, (char *)"LCD_ROWS") == 0)) {
278
76c8a6f18e4d GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
612 if (sscanf(val, "%d", &ival) == 1) {
76c8a6f18e4d GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
613 if (Config.lcd_rows != ival)
76c8a6f18e4d GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
614 syslog(LOG_NOTICE, "Global LCD rows %d to %d", Config.lcd_rows, ival);
206
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
615 Config.lcd_rows = ival;
278
76c8a6f18e4d GLOBAL PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
616 }
206
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
617 #endif
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
618 }
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
619 }
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
620 }
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
621 }
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
622 }
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
623
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
624 srv_send((char *)"504 Subcommand error");
206
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
625 return 1;
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
626 }
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
627
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
628
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
629
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
630 /*
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
631 * LIST
120
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
632 * LIST LOG
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
633 */
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
634 int cmd_list(char *buf)
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
635 {
299
d1c52fb43e30 Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents: 293
diff changeset
636 char *opt, *param, *filename, q[5], buffer[256], outbuf[256];
d1c52fb43e30 Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents: 293
diff changeset
637 char *date_n, *mode_n, *air_n, *beer_n, *target_n, *heater_n, *cooler_n;
d1c52fb43e30 Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents: 293
diff changeset
638 char *heater_u, *cooler_u;
300
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
639 int heater_l = 0, cooler_l = 0, h = 0, c = 0, heat_used = 0, cool_used = 0, lines = 0, graphstep = 0;
84
ef4c0032b51f Can list the 1-wire bus
Michiel Broek <mbroek@mbse.eu>
parents: 81
diff changeset
640 units_list *unit;
120
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
641 FILE *fp;
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
642
87
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
643 opt = strtok(buf, " \0");
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
644 opt = strtok(NULL, " \0");
84
ef4c0032b51f Can list the 1-wire bus
Michiel Broek <mbroek@mbse.eu>
parents: 81
diff changeset
645
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
646 if (opt == NULL) {
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
647 /*
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
648 * Default, list available units
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
649 */
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
650 srv_send((char *)"212 Fermenter list follows:");
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
651 for (unit = Config.units; unit; unit = unit->next) {
131
528dc0bb81ab Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents: 125
diff changeset
652 srv_send((char *)"%s,%s,%s", unit->uuid, unit->name, UNITMODE[unit->mode]);
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
653 }
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
654 srv_send((char *)".");
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
655 return 1;
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
656
120
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
657 } else if (strcmp(opt, (char *)"LOG") == 0) {
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
658
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
659 param = strtok(NULL, "\0");
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
660 if (param == NULL) {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
661 srv_send((char *)"502 Parameter missing");
120
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
662 return 1;
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
663 }
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
664
266
07819a7ad3c1 Better log output for web graphs. Webgraphs can now display heater and cooler usage.
Michiel Broek <mbroek@mbse.eu>
parents: 264
diff changeset
665 q[0] = q[1] = q[2] = q[3] = q[4] = 'a';
120
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
666 for (unit = Config.units; unit; unit = unit->next) {
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
667 if (strcmp(param, unit->uuid) == 0)
120
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
668 break;
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
669 }
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
670
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
671 srv_send((char *)"212 Logfile list follows:");
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
672 if (getenv((char *)"USER") == NULL) {
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
673 filename = xstrcpy((char *)"/root");
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
674 } else {
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
675 filename = xstrcpy(getenv((char *)"HOME"));
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
676 }
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
677 filename = xstrcat(filename, (char *)"/.thermferm/log/");
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
678 filename = xstrcat(filename, unit->name);
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
679 filename = xstrcat(filename, (char *)".log");
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
680 if ((fp = fopen(filename, "r"))) {
300
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
681
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
682 /*
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
683 * Count the lines in the logfile
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
684 */
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
685 lines = 0;
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
686 while (fgets(buffer, sizeof(buffer)-1, fp) != NULL) {
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
687 lines++;
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
688 }
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
689 fseek(fp, 0L, SEEK_SET);
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
690 /*
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
691 * We have counted the lines in the logfile including the header lines.
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
692 * The header lines should be ignored but there are so few of them, we
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
693 * just include them in the total.
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
694 * Now find a reasonable interval of lines to sent to the client.
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
695 */
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
696 for (graphstep = 1; graphstep <= MAX_INTERVALS; graphstep++) {
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
697 if (lines < GRAPH_DATALINES[graphstep]) {
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
698 break;
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
699 }
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
700 }
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
701 syslog(LOG_NOTICE, "LIST LOG %s: lines=%d, interval=%d, graphstep=%d", unit->name, lines, GRAPH_INTERVAL[graphstep], graphstep);
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
702
120
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
703 while (fgets(buffer, sizeof(buffer)-1, fp) != NULL) {
299
d1c52fb43e30 Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents: 293
diff changeset
704 /*
d1c52fb43e30 Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents: 293
diff changeset
705 * 2014-11-15 18:39,BEER,20.312,19.750,20.0,0,NA,NA,NA,78105,NA,NA
d1c52fb43e30 Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents: 293
diff changeset
706 */
300
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
707 q[0] = buffer[11];
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
708 q[1] = buffer[12];
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
709 q[2] = buffer[14];
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
710 q[3] = buffer[15];
120
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
711 buffer[strlen(buffer) -1] = '\0';
299
d1c52fb43e30 Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents: 293
diff changeset
712 date_n = strtok(buffer, ",\0"); /* timestamp */
d1c52fb43e30 Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents: 293
diff changeset
713 mode_n = strtok(NULL, ",\0"); /* unit mode */
d1c52fb43e30 Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents: 293
diff changeset
714 air_n = strtok(NULL, ",\0"); /* air temp */
d1c52fb43e30 Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents: 293
diff changeset
715 beer_n = strtok(NULL, ",\0"); /* beer temp */
d1c52fb43e30 Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents: 293
diff changeset
716 target_n = strtok(NULL, ",\0"); /* target temp */
d1c52fb43e30 Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents: 293
diff changeset
717 heater_n = strtok(NULL, ",\0"); /* current heater state */
d1c52fb43e30 Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents: 293
diff changeset
718 cooler_n = strtok(NULL, ",\0"); /* current cooler state */
d1c52fb43e30 Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents: 293
diff changeset
719 heater_u = strtok(NULL, ",\0"); /* current fan state */
d1c52fb43e30 Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents: 293
diff changeset
720 heater_u = strtok(NULL, ",\0"); /* current door state */
d1c52fb43e30 Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents: 293
diff changeset
721 heater_u = strtok(NULL, ",\0"); /* heater use counter */
d1c52fb43e30 Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents: 293
diff changeset
722 cooler_u = strtok(NULL, ",\0"); /* cooler use counter */
264
91c358556ecf LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents: 261
diff changeset
723
91c358556ecf LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents: 261
diff changeset
724 if (strncmp(mode_n, (char *)"Mode", 4)) {
266
07819a7ad3c1 Better log output for web graphs. Webgraphs can now display heater and cooler usage.
Michiel Broek <mbroek@mbse.eu>
parents: 264
diff changeset
725 /*
300
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
726 * Output a line at the right intervals
266
07819a7ad3c1 Better log output for web graphs. Webgraphs can now display heater and cooler usage.
Michiel Broek <mbroek@mbse.eu>
parents: 264
diff changeset
727 */
300
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
728 if (((graphstep == 1)) ||
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
729 ((graphstep == 2) && (q[3] == '0' || q[3] == '5')) ||
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
730 ((graphstep == 3) && ((q[2] == '0' && q[3] == '0') || (q[2] == '1' && q[3] == '5') || (q[2] == '3' && q[3] == '0') || (q[2] == '4' && q[3] == '5'))) ||
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
731 ((graphstep == 4) && ((q[2] == '0' && q[3] == '0') || (q[2] == '3' && q[3] == '0'))) ||
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
732 ((graphstep == 5) && (q[2] == '0' && q[3] == '0')) ) {
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
733 heat_used = cool_used = 0;
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
734 if (strcmp(heater_u, "NA") && (sscanf(heater_u, "%d", &h) == 1)) {
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
735 if (h && heater_l) {
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
736 heat_used = ((h - heater_l) * 100) / (GRAPH_INTERVAL[graphstep] * 60);
299
d1c52fb43e30 Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents: 293
diff changeset
737 }
300
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
738 }
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
739 if (strcmp(cooler_u, "NA") && (sscanf(cooler_u, "%d", &c) == 1)) {
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
740 if (c && cooler_l) {
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
741 cool_used = ((c - cooler_l) * 100) / (GRAPH_INTERVAL[graphstep] * 60);
299
d1c52fb43e30 Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents: 293
diff changeset
742 }
300
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
743 }
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
744 snprintf(outbuf, 255, "%s,%s,%s,%s,%s,%s,%s,%d,%d",
299
d1c52fb43e30 Show heater/cooler usgae in percent on the web page. Bunped to version 0.2.5
Michiel Broek <mbroek@mbse.eu>
parents: 293
diff changeset
745 date_n, mode_n, air_n, beer_n, target_n, heater_n, cooler_n, heat_used, cool_used);
300
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
746 srv_send(outbuf);
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
747 if (h && strcmp(heater_u, "NA"))
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
748 heater_l = h;
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
749 if (c & strcmp(cooler_u, "NA"))
4ce46ff3e37d The LIST LOG command now automatic adjusts the number of output lines and resolution by calculating a reasonable interval between 1 and 60 minutes. Bumped to version 0.2.6
Michiel Broek <mbroek@mbse.eu>
parents: 299
diff changeset
750 cooler_l = c;
120
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
751 }
266
07819a7ad3c1 Better log output for web graphs. Webgraphs can now display heater and cooler usage.
Michiel Broek <mbroek@mbse.eu>
parents: 264
diff changeset
752 }
120
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
753 }
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
754 }
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
755 free(filename);
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
756 filename = NULL;
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
757 srv_send((char *)".");
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
758 return 1;
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
759 }
120
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
760
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
761 srv_send((char *)"504 Subcommand error");
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
762 return 1;
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
763 }
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
764
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
765
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
766
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
767 /*
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
768 * PROFILE ADD name Add a new profile
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
769 * PROFILE DEL uuid Delete profile with uuid
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
770 * PROFILE LIST List available profiles
258
e02393b29733 Updated web dashboard layout
Michiel Broek <mbroek@mbse.eu>
parents: 249
diff changeset
771 * PROFILE GET uuid Get profile record
e02393b29733 Updated web dashboard layout
Michiel Broek <mbroek@mbse.eu>
parents: 249
diff changeset
772 * PROFILE PUT uuid Put profile record
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
773 * PROFILE GETS uuid Get profile steps list
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
774 * PROFILE PUTS uuid Put profile steps list
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
775 */
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
776 int cmd_profile(char *buf)
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
777 {
192
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
778 char ibuf[SS_BUFSIZE], *sstep, *rest, *targ, *param, *kwd, *val;
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
779 int i, j, rlen, istep, irest;
192
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
780 float ftarg, fval;
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
781 socklen_t fromlen;
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
782 char *opt;
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
783 profiles_list *profile, *tmpp;
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
784 prof_step *step, *olds;
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
785 uuid_t uu;
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
786
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
787 opt = strtok(buf, " \0");
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
788 opt = strtok(NULL, " \0");
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
789
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
790 if (opt == NULL) {
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
791 srv_send((char *)"501 Subcommand missing");
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
792 return 1;
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
793 }
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
794
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
795 if (strcmp(opt, (char *)"LIST") == 0) {
86
3d7a241329e2 Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents: 85
diff changeset
796 /*
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
797 * Fermenting profiles
86
3d7a241329e2 Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents: 85
diff changeset
798 */
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
799 srv_send((char *)"212 Profiles list follows:");
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
800 for (profile = Config.profiles; profile; profile = profile->next) {
124
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
801 j = 0;
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
802 for (step = profile->steps; step; step = step->next)
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
803 j++;
136
264e5ee5abfc Profiles now have a busy state
Michiel Broek <mbroek@mbse.eu>
parents: 133
diff changeset
804 srv_send((char *)"%s,%s,%d,%d", profile->uuid, profile->name, j, profile->busy);
86
3d7a241329e2 Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents: 85
diff changeset
805 }
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
806 srv_send((char *)".");
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
807 return 1;
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
808 }
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
809
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
810 param = strtok(NULL, "\0");
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
811 if (param == NULL) {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
812 srv_send((char *)"502 Parameter missing");
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
813 return 1;
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
814 }
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
815
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
816 if (strcmp(opt, (char *)"ADD") == 0) {
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
817 profile = (profiles_list *)malloc(sizeof(profiles_list));
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
818 profile->next = NULL;
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
819 profile->version = 1;
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
820 profile->uuid = malloc(37);
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
821 uuid_generate(uu);
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
822 uuid_unparse(uu, profile->uuid);
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
823 profile->name = xstrcpy(param);
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
824 profile->busy = 0;
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
825 profile->inittemp = 20.0;
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
826 profile->steps = NULL;
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
827 if (Config.profiles == NULL) {
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
828 Config.profiles = profile;
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
829 } else {
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
830 for (tmpp = Config.profiles; tmpp; tmpp = tmpp->next) {
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
831 if (tmpp->next == NULL) {
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
832 tmpp->next = profile;
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
833 break;
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
834 }
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
835 }
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
836 }
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
837
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
838 syslog(LOG_NOTICE, "Profile %s added", profile->uuid);
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
839 srv_send((char *)"211 Profile %s added", profile->uuid);
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
840 return 0;
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
841
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
842
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
843 } else if (strcmp(opt, (char *)"DEL") == 0) {
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
844 if (delete_Profile(param)) {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
845 syslog(LOG_NOTICE, "Profile %s deleted", param);
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
846 srv_send((char *)"211 Profile %s deleted", param);
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
847 return 0;
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
848 } else {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
849 srv_send((char *)"440 No such profile");
132
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
850 return 1;
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
851 }
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
852
192
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
853 } else if (strcmp(opt, (char *)"GET") == 0) {
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
854 for (profile = Config.profiles; profile; profile = profile->next) {
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
855 if (strcmp(profile->uuid, param) == 0) {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
856 srv_send((char *)"213 Profile record follows:");
192
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
857 srv_send((char *)"UUID,%s", profile->uuid);
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
858 srv_send((char *)"NAME,%s", profile->name);
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
859 srv_send((char *)"INITTEMP,%.1f", profile->inittemp);
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
860 srv_send((char *)".");
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
861 return 1;
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
862 }
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
863 }
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
864 srv_send((char *)"440 No such profile");
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
865 return 1;
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
866
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
867 } else if (strcmp(opt, (char *)"PUT") == 0) {
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
868 for (profile = Config.profiles; profile; profile = profile->next) {
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
869 if (strcmp(profile->uuid, param) == 0) {
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
870 while (1) {
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
871 memset((char *)&ibuf, 0, SS_BUFSIZE);
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
872 fromlen = sizeof(peeraddr_in);
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
873 rlen = recvfrom(s, ibuf, sizeof(ibuf) -1, 0, (struct sockaddr *)&peeraddr_in, &fromlen);
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
874 if (rlen == -1) {
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 266
diff changeset
875 syslog(LOG_NOTICE, "recvfrom(): %s", strerror(errno));
192
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
876 srv_send((char *)"518 recfrom(): %s", strerror(errno));
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
877 return 1;
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
878 }
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
879 for (i = 0; i < strlen(ibuf); i++) {
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
880 if (ibuf[i] == '\n')
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
881 ibuf[i] = '\0';
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
882 if (ibuf[i] == '\r')
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
883 ibuf[i] = '\0';
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
884 }
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
885 for (i = strlen(ibuf) -1; i > 0; i--) {
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
886 if (ibuf[i] == ' ')
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
887 ibuf[i] = '\0';
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
888 else
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
889 break;
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
890 }
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
891 if (strlen(ibuf)) {
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
892 if (debug) {
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
893 syslog(LOG_NOTICE, "recv: \"%s\"", ibuf);
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
894 fprintf(stdout, "recv: \"%s\"\n", ibuf);
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
895 }
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
896 if (strcmp(ibuf, (char *)".") == 0) {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
897 srv_send((char *)"219 Accepted Profile record");
192
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
898 return 0;
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
899 }
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
900 kwd = strtok(ibuf, ",\0");
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
901 val = strtok(NULL, "\0");
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
902 if (kwd && val) {
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
903 if (strcmp(kwd, (char *)"NAME") == 0) {
279
4c505414435c PROFILE PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 278
diff changeset
904 if (profile->name) {
4c505414435c PROFILE PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 278
diff changeset
905 if (strcmp(profile->name, val))
4c505414435c PROFILE PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 278
diff changeset
906 syslog(LOG_NOTICE, "Profile %s name `%s' to `%s'", profile->uuid, profile->name, val);
192
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
907 free(profile->name);
279
4c505414435c PROFILE PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 278
diff changeset
908 }
192
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
909 profile->name = xstrcpy(val);
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
910 } else if (strcmp(kwd, (char *)"INITTEMP") == 0) {
279
4c505414435c PROFILE PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 278
diff changeset
911 if (sscanf(val, "%f", &fval) == 1) {
4c505414435c PROFILE PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 278
diff changeset
912 if (profile->inittemp != fval)
4c505414435c PROFILE PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 278
diff changeset
913 syslog(LOG_NOTICE, "Profile %s initial temperature %.1f to %.1f", profile->uuid, profile->inittemp, fval);
192
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
914 profile->inittemp = fval;
279
4c505414435c PROFILE PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 278
diff changeset
915 }
192
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
916 }
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
917 }
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
918 }
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
919 }
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
920 }
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
921 }
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
922 srv_send((char *)"440 No such profile");
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
923 return 1;
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
924
140
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
925 } else if (strcmp(opt, (char *)"GETS") == 0) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
926
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
927 for (profile = Config.profiles; profile; profile = profile->next) {
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
928 if (strcmp(profile->uuid, param) == 0) {
140
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
929 srv_send((char *)"215 Profile steps follow:");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
930 for (step = profile->steps; step; step = step->next) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
931 srv_send((char *)"%d,%d,%.1f", step->steptime, step->resttime, step->target);
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
932 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
933 srv_send((char *)".");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
934 return 1;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
935 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
936 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
937
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
938 srv_send((char *)"440 No such profile");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
939 return 1;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
940
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
941 } else if (strcmp(opt, (char *)"PUTS") == 0) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
942
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
943 for (profile = Config.profiles; profile; profile = profile->next) {
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
944 if (strcmp(profile->uuid, param) == 0) {
140
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
945
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
946 if (profile->steps) {
280
de3dc781ba65 PROFILE PUTS command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 279
diff changeset
947 syslog(LOG_NOTICE, "PROFILE PUTS %s erased all old steps", profile->uuid);
140
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
948 for (step = profile->steps; step; step = olds) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
949 olds = step->next;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
950 free(step);
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
951 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
952 profile->steps = NULL;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
953 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
954
280
de3dc781ba65 PROFILE PUTS command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 279
diff changeset
955 j = 0;
140
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
956 while (1) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
957 memset((char *)&ibuf, 0, SS_BUFSIZE);
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
958 fromlen = sizeof(peeraddr_in);
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
959 rlen = recvfrom(s, ibuf, sizeof(ibuf) -1, 0, (struct sockaddr *)&peeraddr_in, &fromlen);
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
960 if (rlen == -1) {
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 266
diff changeset
961 syslog(LOG_NOTICE, "recvfrom(): %s", strerror(errno));
140
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
962 srv_send((char *)"518 recfrom(): %s", strerror(errno));
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
963 return 1;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
964 } else {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
965 for (i = 0; i < strlen(ibuf); i++) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
966 if (ibuf[i] == '\n')
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
967 ibuf[i] = '\0';
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
968 if (ibuf[i] == '\r')
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
969 ibuf[i] = '\0';
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
970 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
971 for (i = strlen(ibuf) -1; i > 0; i--) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
972 if (ibuf[i] == ' ')
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
973 ibuf[i] = '\0';
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
974 else
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
975 break;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
976 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
977 if (strlen(ibuf)) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
978 if (debug) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
979 syslog(LOG_NOTICE, "recv: \"%s\"", ibuf);
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
980 fprintf(stdout, "recv: \"%s\"\n", ibuf);
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
981 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
982 if (strcmp(ibuf, (char *)".") == 0) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
983
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
984 srv_send((char *)"219 Accepted Profile steps");
140
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
985 return 0;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
986 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
987 sstep = strtok(ibuf, ",\0");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
988 rest = strtok(NULL, ",\0");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
989 targ = strtok(NULL, "\0");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
990
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
991 if ((sscanf(sstep, "%d", &istep) == 1) &&
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
992 (sscanf(rest, "%d", &irest) == 1) &&
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
993 (sscanf(targ, "%f", &ftarg) == 1)) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
994
280
de3dc781ba65 PROFILE PUTS command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 279
diff changeset
995 j++;
de3dc781ba65 PROFILE PUTS command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 279
diff changeset
996 syslog(LOG_NOTICE, "PROFILE PUTS %s add step %d: steptime=%d resttime=%d target=%.1f",
de3dc781ba65 PROFILE PUTS command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 279
diff changeset
997 profile->uuid, j, istep, irest, ftarg);
140
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
998 step = (prof_step *)malloc(sizeof(prof_step));
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
999 step->next = NULL;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
1000 step->version = 1;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
1001 step->steptime = istep;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
1002 step->resttime = irest;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
1003 step->target = ftarg;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
1004
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
1005 if (profile->steps == NULL) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
1006 profile->steps = step;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
1007 } else {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
1008 for (olds = profile->steps; olds; olds = olds->next) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
1009 if (olds->next == NULL) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
1010 olds->next = step;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
1011 break;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
1012 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
1013 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
1014 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
1015 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
1016 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
1017 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
1018 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
1019 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
1020 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
1021
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
1022 srv_send((char *)"440 No such profile");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
1023 return 1;
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
1024 }
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
1025
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
1026 srv_send((char *)"504 Subcommand error");
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
1027 return 1;
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
1028 }
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
1029
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
1030
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
1031
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1032 #ifdef USE_SIMULATOR
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1033 int delete_Simulator(char *uuid)
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1034 {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1035 simulator_list *current = Config.simulators;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1036 simulator_list *previous = NULL;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1037
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1038 while (current) {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1039 if (strcmp(current->uuid, uuid) == 0) {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1040 if (previous == NULL) {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1041 Config.simulators = current->next;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1042 free(current->uuid);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1043 current->uuid = NULL;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1044 free(current->name);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1045 current->name = NULL;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1046 free(current);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1047 return 1;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1048 } else {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1049 free(current->uuid);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1050 current->uuid = NULL;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1051 free(current->name);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1052 current->name = NULL;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1053 previous->next = current->next;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1054 free(current);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1055 current = previous->next;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1056 return 1;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1057 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1058 } else {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1059 previous = current;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1060 current = current->next;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1061 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1062 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1063 return 0;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1064 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1065
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1066
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1067
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1068 /*
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1069 * SIMULATOR ADD name
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1070 * SIMULATOR DEL uuid
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1071 * SIMULATOR LIST
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1072 * SIMULATOR GET uuid
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1073 * SIMULATOR PUT uuid
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1074 */
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1075 int cmd_simulator(char *buf)
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1076 {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1077 char *opt, *param, *kwd, *val, ibuf[SS_BUFSIZE];
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1078 simulator_list *simulator, *tmps;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1079 socklen_t fromlen;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1080 int i, rc, rlen, ival;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1081 float fval;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1082 uuid_t uu;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1083
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1084 opt = strtok(buf, " \0");
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1085 opt = strtok(NULL, " \0");
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1086
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1087 if (opt == NULL) {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1088 srv_send((char *)"501 Subcommand missing");
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1089 return 1;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1090 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1091 param = strtok(NULL, "\0");
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1092
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1093 if (strcmp(opt, (char *)"LIST") == 0) {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1094 srv_send((char *)"212 Simulators list follows:");
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1095 for (simulator = Config.simulators; simulator; simulator = simulator->next) {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1096 srv_send((char *)"%s,%s", simulator->uuid, simulator->name);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1097 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1098 srv_send((char *)".");
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1099 return 1;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1100 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1101
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1102 if (param == NULL) {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1103 srv_send((char *)"502 Parameter missing");
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1104 return 1;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1105 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1106
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1107 if (strcmp(opt, (char *)"ADD") == 0) {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1108
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1109 /*
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1110 * For now, only one simulator is allowed.
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1111 */
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1112 if (Config.simulators) {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1113 srv_send((char *)"441 Maximum simulators reached");
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1114 return 1;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1115 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1116
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1117 simulator = (simulator_list *)malloc(sizeof(simulator_list));
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1118 simulator->next = NULL;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1119 simulator->version = 1;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1120 simulator->uuid = malloc(37);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1121 uuid_generate(uu);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1122 uuid_unparse(uu, simulator->uuid);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1123 simulator->name = xstrcpy(param);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1124 simulator->volume_air = 150;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1125 simulator->volume_beer = 50;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1126 simulator->room_temperature = simulator->air_temperature = simulator->beer_temperature = simulator->s_cool_temp = simulator->s_heat_temp = 20.0;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1127 simulator->cooler_temp = -3.0; /* Cooling temperature */
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1128 simulator->cooler_time = 720; /* About 12 minutes for the cooler plate */
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1129 simulator->cooler_size = 0.8; /* 0.8 square meter cooler plate */
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1130 simulator->heater_temp = 150.0; /* Heating temperature */
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1131 simulator->heater_time = 3; /* 3 seconds to heat-up */
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1132 simulator->heater_size = 0.01; /* 0.01 square meter heater plate */
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1133 simulator->heater_state = simulator->cooler_state = 0;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1134 simulator->frigo_isolation = 0.002;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1135 simulator->s_yeast_heat = 0.0;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1136 simulator->s_yeast_started = simulator->s_cool_changed = simulator->s_heat_changed = (int)0;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1137
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1138 if (Config.simulators == NULL) {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1139 Config.simulators = simulator;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1140 } else {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1141 for (tmps = Config.simulators; tmps; tmps = tmps->next) {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1142 if (tmps->next == NULL) {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1143 tmps->next = simulator;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1144 break;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1145 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1146 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1147 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1148
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1149 syslog(LOG_NOTICE, "Simulator %s added", simulator->uuid);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1150 srv_send((char *)"211 Simulator %s added", simulator->uuid);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1151 return 0;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1152 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1153
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1154 if (strcmp(opt, (char *)"DEL") == 0) {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1155 rc = delete_Simulator(param);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1156 if (rc) {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1157 syslog(LOG_NOTICE, "Simulator %s deleted", param);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1158 srv_send((char *)"211 Simulator %s deleted", param);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1159 return 0;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1160 } else {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1161 srv_send((char *)"440 No such simulator");
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1162 return 1;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1163 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1164 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1165
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1166 if (strcmp(opt, (char *)"GET") == 0) {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1167 for (simulator = Config.simulators; simulator; simulator = simulator->next) {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1168 if (strcmp(simulator->uuid, param) == 0) {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1169 srv_send((char *)"213 Simulator record follows:");
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1170 srv_send((char *)"NAME,%s", simulator->name);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1171 srv_send((char *)"VOLUME_AIR,%d", simulator->volume_air);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1172 srv_send((char *)"VOLUME_BEER,%d", simulator->volume_beer);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1173 srv_send((char *)"ROOM_TEMPERATURE,%.1f", simulator->room_temperature);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1174 srv_send((char *)"AIR_TEMPERATURE,%.3f", simulator->air_temperature);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1175 srv_send((char *)"BEER_TEMPERATURE,%.3f", simulator->beer_temperature);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1176 srv_send((char *)"COOLER_TEMP,%.1f", simulator->cooler_temp);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1177 srv_send((char *)"COOLER_TIME,%d", simulator->cooler_time);
261
e4341cfbc2a8 Fixed cooler_size bug
Michiel Broek <mbroek@mbse.eu>
parents: 259
diff changeset
1178 srv_send((char *)"COOLER_SIZE,%.3f", simulator->cooler_size);
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1179 srv_send((char *)"HEATER_TEMP,%.1f", simulator->heater_temp);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1180 srv_send((char *)"HEATER_TIME,%d", simulator->heater_time);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1181 srv_send((char *)"HEATER_SIZE,%.3f", simulator->heater_size);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1182 srv_send((char *)"HEATER_STATE,%d", simulator->heater_state);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1183 srv_send((char *)"COOLER_STATE,%d", simulator->cooler_state);
261
e4341cfbc2a8 Fixed cooler_size bug
Michiel Broek <mbroek@mbse.eu>
parents: 259
diff changeset
1184 srv_send((char *)"FRIGO_ISOLATION,%.3f", simulator->frigo_isolation);
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1185 srv_send((char *)".");
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1186 return 1;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1187 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1188 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1189 srv_send((char *)"440 No such simulator");
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1190 return 1;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1191 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1192
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1193 if (strcmp(opt, (char *)"PUT") == 0) {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1194 for (simulator = Config.simulators; simulator; simulator = simulator->next) {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1195 if (strcmp(simulator->uuid, param) == 0) {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1196 while (1) {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1197 memset((char *)&ibuf, 0, SS_BUFSIZE);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1198 fromlen = sizeof(peeraddr_in);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1199 rlen = recvfrom(s, ibuf, sizeof(ibuf) -1, 0, (struct sockaddr *)&peeraddr_in, &fromlen);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1200 if (rlen == -1) {
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 266
diff changeset
1201 syslog(LOG_NOTICE, "recvfrom(): %s", strerror(errno));
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1202 srv_send((char *)"518 recfrom(): %s", strerror(errno));
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1203 return 1;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1204 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1205 for (i = 0; i < strlen(ibuf); i++) {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1206 if (ibuf[i] == '\n')
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1207 ibuf[i] = '\0';
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1208 if (ibuf[i] == '\r')
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1209 ibuf[i] = '\0';
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1210 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1211 for (i = strlen(ibuf) -1; i > 0; i--) {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1212 if (ibuf[i] == ' ')
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1213 ibuf[i] = '\0';
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1214 else
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1215 break;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1216 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1217 if (strlen(ibuf)) {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1218 if (debug) {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1219 syslog(LOG_NOTICE, "recv: \"%s\"", ibuf);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1220 fprintf(stdout, "recv: \"%s\"\n", ibuf);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1221 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1222 if (strcmp(ibuf, (char *)".") == 0) {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1223 srv_send((char *)"219 Accepted Simulator record");
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1224 return 0;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1225 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1226 kwd = strtok(ibuf, ",\0");
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1227 val = strtok(NULL, "\0");
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1228 if (kwd && val) {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1229
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1230 if (strcmp(kwd, (char *)"NAME") == 0) {
281
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1231 if (simulator->name) {
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1232 if (strcmp(simulator->name, val))
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1233 syslog(LOG_NOTICE, "Simulator %s name `%s' to `%s'", simulator->uuid, simulator->name, val);
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1234 free(simulator->name);
281
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1235 }
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1236 simulator->name = xstrcpy(val);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1237
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1238 } else if (strcmp(kwd, (char *)"VOLUME_AIR") == 0) {
281
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1239 if (sscanf(val, "%d", &ival) == 1) {
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1240 if (simulator->volume_air != ival)
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1241 syslog(LOG_NOTICE, "Simulator %s volume air %d to %d", simulator->uuid, simulator->volume_air, ival);
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1242 simulator->volume_air = ival;
281
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1243 }
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1244
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1245 } else if (strcmp(kwd, (char *)"VOLUME_BEER") == 0) {
281
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1246 if (sscanf(val, "%d", &ival) == 1) {
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1247 if (simulator->volume_beer != ival)
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1248 syslog(LOG_NOTICE, "Simulator %s volume beer %d to %d", simulator->uuid, simulator->volume_beer, ival);
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1249 simulator->volume_beer = ival;
281
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1250 }
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1251
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1252 } else if (strcmp(kwd, (char *)"ROOM_TEMPERATURE") == 0) {
281
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1253 if (sscanf(val, "%f", &fval) == 1) {
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1254 if (simulator->room_temperature != fval)
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1255 syslog(LOG_NOTICE, "Simulator %s room temperature %.1f to %.1f", simulator->uuid, simulator->room_temperature, fval);
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1256 simulator->room_temperature = fval;
281
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1257 }
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1258
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1259 } else if (strcmp(kwd, (char *)"AIR_TEMPERATURE") == 0) {
281
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1260 if (sscanf(val, "%f", &fval) == 1) {
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1261 if (simulator->air_temperature != fval)
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1262 syslog(LOG_NOTICE, "Simulator %s air temperature %.1f to %.1f", simulator->uuid, simulator->air_temperature, fval);
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1263 simulator->air_temperature = fval;
281
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1264 }
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1265
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1266 } else if (strcmp(kwd, (char *)"BEER_TEMPERATURE") == 0) {
281
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1267 if (sscanf(val, "%f", &fval) == 1) {
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1268 if (simulator->beer_temperature != fval)
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1269 syslog(LOG_NOTICE, "Simulator %s beer temperature %.1f to %.1f", simulator->uuid, simulator->beer_temperature, fval);
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1270 simulator->beer_temperature = fval;
281
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1271 }
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1272
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1273 } else if (strcmp(kwd, (char *)"COOLER_TEMP") == 0) {
281
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1274 if (sscanf(val, "%f", &fval) == 1) {
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1275 if (simulator->cooler_temp != fval)
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1276 syslog(LOG_NOTICE, "Simulator %s cooler temperature %.1f to %.1f", simulator->uuid, simulator->cooler_temp, fval);
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1277 simulator->cooler_temp = fval;
281
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1278 }
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1279
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1280 } else if (strcmp(kwd, (char *)"COOLER_TIME") == 0) {
281
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1281 if (sscanf(val, "%d", &ival) == 1) {
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1282 if (simulator->cooler_time != ival)
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1283 syslog(LOG_NOTICE, "Simulator %s cooler time %d to %d", simulator->uuid, simulator->cooler_time, ival);
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1284 simulator->cooler_time = ival;
281
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1285 }
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1286
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1287 } else if (strcmp(kwd, (char *)"COOLER_SIZE") == 0) {
281
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1288 if (sscanf(val, "%f", &fval) == 1) {
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1289 if (simulator->cooler_size != fval)
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1290 syslog(LOG_NOTICE, "Simulator %s cooler size %.1f to %.1f", simulator->uuid, simulator->cooler_size, fval);
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1291 simulator->cooler_size = fval;
281
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1292 }
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1293
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1294 } else if (strcmp(kwd, (char *)"HEATER_TEMP") == 0) {
281
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1295 if (sscanf(val, "%f", &fval) == 1) {
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1296 if (simulator->heater_temp != fval)
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1297 syslog(LOG_NOTICE, "Simulator %s heater temperature %.1f to %.1f", simulator->uuid, simulator->heater_temp, fval);
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1298 simulator->heater_temp = fval;
281
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1299 }
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1300
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1301 } else if (strcmp(kwd, (char *)"HEATER_TIME") == 0) {
281
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1302 if (sscanf(val, "%d", &ival) == 1) {
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1303 if (simulator->heater_time != ival)
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1304 syslog(LOG_NOTICE, "Simulator %s heater time %d to %d", simulator->uuid, simulator->heater_time, ival);
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1305 simulator->heater_time = ival;
281
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1306 }
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1307
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1308 } else if (strcmp(kwd, (char *)"HEATER_SIZE") == 0) {
281
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1309 if (sscanf(val, "%f", &fval) == 1) {
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1310 if (simulator->heater_size != fval)
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1311 syslog(LOG_NOTICE, "Simulator %s heater size %.1f to %.1f", simulator->uuid, simulator->heater_size, fval);
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1312 simulator->heater_size = fval;
281
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1313 }
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1314
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1315 } else if (strcmp(kwd, (char *)"HEATER_STATE") == 0) {
281
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1316 if (sscanf(val, "%d", &ival) == 1) {
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1317 if (simulator->heater_state != ival)
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1318 syslog(LOG_NOTICE, "Simulator %s heater state %d to %d", simulator->uuid, simulator->heater_state, ival);
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1319 simulator->heater_state = ival;
281
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1320 }
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1321
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1322 } else if (strcmp(kwd, (char *)"COOLER_STATE") == 0) {
281
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1323 if (sscanf(val, "%d", &ival) == 1) {
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1324 if (simulator->cooler_state != ival)
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1325 syslog(LOG_NOTICE, "Simulator %s cooler state %d to %d", simulator->uuid, simulator->cooler_state, ival);
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1326 simulator->cooler_state = ival;
281
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1327 }
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1328
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1329 } else if (strcmp(kwd, (char *)"FRIGO_ISOLATION") == 0) {
281
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1330 if (sscanf(val, "%f", &fval) == 1) {
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1331 if (simulator->frigo_isolation != fval)
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1332 syslog(LOG_NOTICE, "Simulator %s frigo isolation %.1f to %.1f", simulator->uuid, simulator->frigo_isolation, fval);
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1333 simulator->frigo_isolation = fval;
281
12a5dbbfd0e3 SIMULATOR PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 280
diff changeset
1334 }
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1335
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1336 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1337 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1338 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1339 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1340 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1341 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1342 srv_send((char *)"440 No such simulator");
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1343 return 1;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1344 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1345
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1346 srv_send((char *)"504 Subcommand error");
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1347 return 1;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1348 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1349 #endif
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1350
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1351
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
1352
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1353 int delete_Unit(char *uuid)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1354 {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1355 units_list *current = Config.units;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1356 units_list *previous = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1357
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1358 while (current) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1359 if (strcmp(current->uuid, uuid) == 0) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1360 if (previous == NULL) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1361 Config.units = current->next;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1362 free(current->uuid);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1363 current->uuid = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1364 free(current->name);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1365 current->name = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1366 if (current->air_address)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1367 free(current->air_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1368 current->air_address = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1369 if (current->beer_address)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1370 free(current->beer_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1371 current->beer_address = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1372 if (current->heater_address)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1373 free(current->heater_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1374 current->heater_address = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1375 if (current->cooler_address)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1376 free(current->cooler_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1377 current->cooler_address = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1378 if (current->fan_address)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1379 free(current->fan_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1380 current->fan_address = NULL;
306
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1381 if (current->light_address)
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1382 free(current->light_address);
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1383 current->light_address = NULL;
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1384 if (current->door_address)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1385 free(current->door_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1386 current->door_address = NULL;
306
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1387 if (current->psu_address)
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1388 free(current->psu_address);
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1389 current->psu_address = NULL;
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1390 if (current->profile)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1391 free(current->profile);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1392 current->profile = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1393 free(current);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1394 return 1;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1395 } else {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1396 free(current->uuid);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1397 current->uuid = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1398 free(current->name);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1399 current->name = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1400 if (current->air_address)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1401 free(current->air_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1402 current->air_address = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1403 if (current->beer_address)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1404 free(current->beer_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1405 current->beer_address = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1406 if (current->heater_address)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1407 free(current->heater_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1408 current->heater_address = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1409 if (current->cooler_address)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1410 free(current->cooler_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1411 current->cooler_address = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1412 if (current->fan_address)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1413 free(current->fan_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1414 current->fan_address = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1415 if (current->door_address)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1416 free(current->door_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1417 current->door_address = NULL;
306
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1418 if (current->light_address)
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1419 free(current->light_address);
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1420 current->light_address = NULL;
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1421 if (current->psu_address)
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1422 free(current->psu_address);
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1423 current->psu_address = NULL;
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1424 if (current->profile)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1425 free(current->profile);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1426 current->profile = NULL;
245
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1427 previous->next = current->next;
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1428 free(current);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1429 current = previous->next;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1430 return 1;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1431 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1432 } else {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1433 previous = current;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1434 current = current->next;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1435 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1436 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1437 return 0;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1438 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1439
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1440
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1441
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
1442 /*
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1443 * UNIT ADD name
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1444 * UNIT DEL uuid
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1445 * UNIT LIST
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1446 * UNIT GET uuid
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1447 * UNIT PUT uuid
87
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1448 */
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1449 int cmd_unit(char *buf)
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1450 {
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1451 char *opt, *param = NULL, *kwd, *val, ibuf[SS_BUFSIZE];
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1452 units_list *unit, *tmpu;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1453 uuid_t uu;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1454 socklen_t fromlen;
245
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1455 int ival, i, rc, rlen;
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1456 float fval;
87
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1457
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1458 opt = strtok(buf, " \0");
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1459 opt = strtok(NULL, " \0");
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1460
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1461 if (opt == NULL) {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
1462 srv_send((char *)"501 Subcommand missing");
87
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1463 return 1;
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1464 }
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1465 param = strtok(NULL, "\0");
87
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1466
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1467 if ((strcmp(opt, (char *)"LIST") == 0) && (param == NULL)) {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
1468 srv_send((char *)"212 Fermenter list follows:");
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1469 for (unit = Config.units; unit; unit = unit->next) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1470 srv_send((char *)"%s,%s,%s", unit->uuid, unit->name, UNITMODE[unit->mode]);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1471 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1472 srv_send((char *)".");
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1473 return 1;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1474 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1475
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1476 if (param == NULL) {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
1477 srv_send((char *)"502 Parameter missing");
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1478 return 1;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1479 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1480
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1481 if (strcmp(opt, (char *)"ADD") == 0) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1482 unit = (units_list *)malloc(sizeof(units_list));
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1483 unit->next = NULL;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1484 unit->version = 1;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1485 unit->uuid = malloc(37);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1486 uuid_generate(uu);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1487 uuid_unparse(uu, unit->uuid);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1488 unit->name = xstrcpy(param);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1489 unit->air_address = unit->beer_address = unit->heater_address = unit->cooler_address = \
306
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1490 unit->fan_address = unit->door_address = unit->light_address = \
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1491 unit->psu_address = unit->profile = NULL;
289
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 285
diff changeset
1492 unit->volume = unit->prof_peak_abs = unit->prof_peak_rel = 0.0;
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1493 unit->air_state = unit->beer_state = 1;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1494 unit->air_temperature = unit->beer_temperature = 20000;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1495 unit->beer_set = unit->fridge_set = 20.0;
306
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1496 unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->mode = \
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1497 unit->light_state = unit->psu_state = unit->prof_state = 0;
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1498 unit->heater_delay = unit->cooler_delay = unit->fan_delay = 20; /* 5 minutes delay */
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1499 unit->light_delay = 1; /* 15 seconds delay */
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1500 unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0;
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1501 unit->heater_usage = unit->cooler_usage = unit->fan_usage = unit->light_usage = 0;
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1502 unit->temp_set_min = 1.0;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1503 unit->temp_set_max = 30.0;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1504 unit->idle_rangeH = 1.0;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1505 unit->idle_rangeL = -1.0;
289
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 285
diff changeset
1506 unit->prof_started = unit->prof_paused = unit->prof_primary_done = (time_t)0;
284
9e6fb5aed618 Profile progress is visible in the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 282
diff changeset
1507 unit->prof_percent = 0;
313
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1508 unit->PID_dState = unit->PID_iState = unit->PID_Kp = unit->PID_Kd = unit->PID_Ki = 0.0;
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1509
245
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1510 /*
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1511 * Block main process
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1512 */
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1513 run_pause = TRUE;
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1514 for (;;) {
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1515 usleep(100000);
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1516 if (run_hold)
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1517 break;
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1518 }
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1519
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1520 if (Config.units == NULL) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1521 Config.units = unit;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1522 } else {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1523 for (tmpu = Config.units; tmpu; tmpu = tmpu->next) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1524 if (tmpu->next == NULL) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1525 tmpu->next = unit;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1526 break;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1527 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1528 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1529 }
249
1ce52a38080e Fixed conditional compile
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
1530 #ifdef HAVE_WIRINGPI_H
245
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1531 lcd_buf_reset();
249
1ce52a38080e Fixed conditional compile
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
1532 #endif
245
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1533 run_pause = FALSE;
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1534
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
1535 syslog(LOG_NOTICE, "Unit %s added", unit->uuid);
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
1536 srv_send((char *)"211 Unit %s added", unit->uuid);
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1537 return 0;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1538 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1539
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1540 if (strcmp(opt, (char *)"DEL") == 0) {
245
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1541 /*
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1542 * Block main process.
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1543 */
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1544 run_pause = TRUE;
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1545 for (;;) {
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1546 usleep(100000);
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1547 if (run_hold)
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1548 break;
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1549 }
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1550
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1551 rc = delete_Unit(param);
249
1ce52a38080e Fixed conditional compile
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
1552 #ifdef HAVE_WIRINGPI_H
245
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1553 lcd_buf_reset();
249
1ce52a38080e Fixed conditional compile
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
1554 #endif
245
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1555 run_pause = FALSE;
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1556
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1557 if (rc) {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
1558 syslog(LOG_NOTICE, "Unit %s deleted", param);
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1559 srv_send((char *)"211 Unit %s deleted", param);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1560 return 0;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1561 } else {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
1562 srv_send((char *)"440 No such unit");
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1563 return 1;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1564 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1565 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1566
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1567 if (strcmp(opt, (char *)"GET") == 0) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1568 for (unit = Config.units; unit; unit = unit->next) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1569 if (strcmp(param, unit->uuid) == 0) {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
1570 srv_send((char *)"213 Unit listing follows:");
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1571 srv_send((char *)"NAME,%s", unit->name);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1572 srv_send((char *)"UUID,%s", unit->uuid);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1573 srv_send((char *)"VOLUME,%2f", unit->volume);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1574 srv_send((char *)"AIR_ADDRESS,%s", unit->air_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1575 srv_send((char *)"AIR_STATE,%s", TEMPSTATE[unit->air_state]);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1576 srv_send((char *)"AIR_TEMPERATURE,%.3f", unit->air_temperature / 1000.0);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1577 srv_send((char *)"BEER_ADDRESS,%s", MBSE_SS(unit->beer_address));
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1578 srv_send((char *)"BEER_STATE,%s", TEMPSTATE[unit->beer_state]);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1579 srv_send((char *)"BEER_TEMPERATURE,%.3f", unit->beer_temperature / 1000.0);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1580 srv_send((char *)"HEATER_ADDRESS,%s", unit->heater_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1581 srv_send((char *)"HEATER_STATE,%d", unit->heater_state);
270
df81d583c2c3 The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents: 269
diff changeset
1582 srv_send((char *)"HEATER_DELAY,%d", unit->heater_delay);
293
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1583 srv_send((char *)"HEATER_USAGE,%d", unit->heater_usage);
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1584 srv_send((char *)"COOLER_ADDRESS,%s", unit->cooler_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1585 srv_send((char *)"COOLER_STATE,%d", unit->cooler_state);
270
df81d583c2c3 The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents: 269
diff changeset
1586 srv_send((char *)"COOLER_DELAY,%d", unit->cooler_delay);
293
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1587 srv_send((char *)"COOLER_USAGE,%d", unit->cooler_usage);
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1588 srv_send((char *)"FAN_ADDRESS,%s", unit->fan_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1589 srv_send((char *)"FAN_STATE,%d", unit->fan_state);
270
df81d583c2c3 The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents: 269
diff changeset
1590 srv_send((char *)"FAN_DELAY,%d", unit->fan_delay);
293
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1591 srv_send((char *)"FAN_USAGE,%d", unit->fan_usage);
306
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1592 srv_send((char *)"LIGHT_ADDRESS,%s", unit->light_address);
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1593 srv_send((char *)"LIGHT_STATE,%d", unit->light_state);
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1594 srv_send((char *)"LIGHT_DELAY,%d", unit->light_delay);
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1595 srv_send((char *)"LIGHT_USAGE,%d", unit->light_usage);
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1596 srv_send((char *)"DOOR_ADDRESS,%s", unit->door_address);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1597 srv_send((char *)"DOOR_STATE,%d", unit->door_state);
306
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1598 srv_send((char *)"PSU_ADDRESS,%s", unit->psu_address);
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1599 srv_send((char *)"PSU_STATE,%d", unit->psu_state);
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1600 srv_send((char *)"MODE,%s", UNITMODE[unit->mode]);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1601 srv_send((char *)"FRIDGE_SET,%.1f", unit->fridge_set);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1602 srv_send((char *)"BEER_SET,%.1f", unit->beer_set);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1603 srv_send((char *)"PROFILE,%s", unit->profile);
217
2922d439ff63 Added profile state ABORT
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
1604 srv_send((char *)"PROF_STARTED,%d", (int)unit->prof_started);
284
9e6fb5aed618 Profile progress is visible in the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 282
diff changeset
1605 if (unit->prof_state == PROFILE_RUN) {
9e6fb5aed618 Profile progress is visible in the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 282
diff changeset
1606 srv_send((char *)"PROF_STATE,%s %d%%", PROFSTATE[unit->prof_state], unit->prof_percent);
9e6fb5aed618 Profile progress is visible in the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 282
diff changeset
1607 } else {
9e6fb5aed618 Profile progress is visible in the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 282
diff changeset
1608 srv_send((char *)"PROF_STATE,%s", PROFSTATE[unit->prof_state]);
9e6fb5aed618 Profile progress is visible in the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 282
diff changeset
1609 }
217
2922d439ff63 Added profile state ABORT
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
1610 srv_send((char *)"PROF_TARGET,%.3f", unit->prof_target);
289
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 285
diff changeset
1611 srv_send((char *)"PROF_PEAK_ABS,%.3f", unit->prof_peak_abs);
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 285
diff changeset
1612 srv_send((char *)"PROF_PEAK_REL,%.3f", unit->prof_peak_rel);
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 285
diff changeset
1613 srv_send((char *)"PROF_PRIMARY_DONE,%d", (int)unit->prof_primary_done);
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1614 srv_send((char *)"TEMP_SET_MIN,%.1f", unit->temp_set_min);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1615 srv_send((char *)"TEMP_SET_MAX,%.1f", unit->temp_set_max);
312
7b0f819a3805 Added more precision to the unit low and high black window margins. Switched to PID routine from Pid without a PhD. The PID compute routine is now in the one second loop. The switch delay times are now in seconds, 0..720.
Michiel Broek <mbroek@mbse.eu>
parents: 311
diff changeset
1616 srv_send((char *)"IDLE_RANGE_L,%.2f", unit->idle_rangeL);
7b0f819a3805 Added more precision to the unit low and high black window margins. Switched to PID routine from Pid without a PhD. The PID compute routine is now in the one second loop. The switch delay times are now in seconds, 0..720.
Michiel Broek <mbroek@mbse.eu>
parents: 311
diff changeset
1617 srv_send((char *)"IDLE_RANGE_H,%.2f", unit->idle_rangeH);
310
53774295e14a Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents: 306
diff changeset
1618 srv_send((char *)"PID_KP,%.2f", unit->PID_Kp);
311
f3b0e9ac9bcb PID changes and algorithm tuning.
Michiel Broek <mbroek@mbse.eu>
parents: 310
diff changeset
1619 srv_send((char *)"PID_KI,%.2f", unit->PID_Ki);
310
53774295e14a Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents: 306
diff changeset
1620 srv_send((char *)"PID_KD,%.2f", unit->PID_Kd);
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1621 srv_send((char *)".");
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1622 return 1;
87
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1623 }
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1624 }
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
1625 srv_send((char *)"440 No such unit");
87
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1626 return 1;
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1627 }
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1628
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1629 if (strcmp(opt, (char *)"PUT") == 0) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1630 for (unit = Config.units ; unit; unit = unit->next) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1631 if (strcmp(unit->uuid, param) == 0) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1632 while (1) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1633 memset((char *)&ibuf, 0, SS_BUFSIZE);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1634 fromlen = sizeof(peeraddr_in);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1635 rlen = recvfrom(s, ibuf, sizeof(ibuf) -1, 0, (struct sockaddr *)&peeraddr_in, &fromlen);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1636 if (rlen == -1) {
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 266
diff changeset
1637 syslog(LOG_NOTICE, "recvfrom(): %s", strerror(errno));
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1638 srv_send((char *)"518 recfrom(): %s", strerror(errno));
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1639 return 1;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1640 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1641 for (i = 0; i < strlen(ibuf); i++) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1642 if (ibuf[i] == '\n')
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1643 ibuf[i] = '\0';
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1644 if (ibuf[i] == '\r')
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1645 ibuf[i] = '\0';
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1646 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1647 for (i = strlen(ibuf) -1; i > 0; i--) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1648 if (ibuf[i] == ' ')
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1649 ibuf[i] = '\0';
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1650 else
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1651 break;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1652 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1653 if (strlen(ibuf)) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1654 if (debug) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1655 syslog(LOG_NOTICE, "recv: \"%s\"", ibuf);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1656 fprintf(stdout, "recv: \"%s\"\n", ibuf);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1657 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1658 if (strcmp(ibuf, (char *)".") == 0) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1659 srv_send((char *)"219 Accepted Unit record");
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1660 return 0;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1661 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1662 kwd = strtok(ibuf, ",\0");
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1663 val = strtok(NULL, "\0");
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1664 if (kwd) {
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1665 /*
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1666 * Accept writable data. The client can sent just one line,
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1667 * but may also sent everything. Simply ignore things we
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1668 * don't understand.
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1669 */
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1670 if (val && (strcmp(kwd, (char *)"NAME") == 0)) {
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1671 if (unit->name) {
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1672 if (strcmp(unit->name, val))
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1673 syslog(LOG_NOTICE, "Fermenter unit %s name `%s' to `%s'", unit->uuid, unit->name, val);
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1674 free(unit->name);
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1675 }
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1676 unit->name = xstrcpy(val);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1677
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1678 } else if (val && (strcmp(kwd, (char *)"VOLUME") == 0)) {
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1679 if (sscanf(val, "%f", &fval) == 1) {
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1680 if (unit->volume != fval)
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1681 syslog(LOG_NOTICE, "Fermenter unit %s volume %.3f to %.3f", unit->uuid, unit->volume, fval);
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1682 unit->volume = fval;
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1683 }
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1684
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1685 } else if (strcmp(kwd, (char *)"AIR_ADDRESS") == 0) {
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1686 if (val && unit->air_address && (strcmp(val, unit->air_address)))
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1687 syslog(LOG_NOTICE, "Fermenter unit %s air address `%s' to `%s'", unit->uuid, unit->air_address, val);
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1688 if (unit->air_address) {
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1689 device_count(FALSE, unit->air_address);
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1690 free(unit->air_address);
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1691 }
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1692 if (val) {
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1693 unit->air_address = xstrcpy(val);
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1694 device_count(TRUE, unit->air_address);
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1695 } else
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1696 unit->air_address = NULL;
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1697
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1698 } else if (strcmp(kwd, (char *)"BEER_ADDRESS") == 0) {
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1699 if (val && unit->beer_address && (strcmp(val, unit->beer_address)))
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1700 syslog(LOG_NOTICE, "Fermenter unit %s beer address `%s' to `%s'", unit->uuid, unit->beer_address, val);
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1701 if (unit->beer_address) {
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1702 device_count(FALSE, unit->beer_address);
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1703 free(unit->beer_address);
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1704 }
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1705 if (val) {
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1706 unit->beer_address = xstrcpy(val);
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1707 device_count(TRUE, unit->beer_address);
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1708 } else
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1709 unit->beer_address = NULL;
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1710
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1711 } else if (strcmp(kwd, (char *)"HEATER_ADDRESS") == 0) {
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1712 if (val && unit->heater_address && (strcmp(val, unit->heater_address)))
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1713 syslog(LOG_NOTICE, "Fermenter unit %s heater address `%s' to `%s'", unit->uuid, unit->heater_address, val);
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1714 if (unit->heater_address) {
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1715 device_count(FALSE, unit->heater_address);
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1716 free(unit->heater_address);
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1717 }
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1718 if (val) {
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1719 unit->heater_address = xstrcpy(val);
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1720 device_count(TRUE, unit->heater_address);
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1721 } else
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1722 unit->heater_address = NULL;
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1723
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1724 } else if (val && (strcmp(kwd, (char *)"HEATER_STATE") == 0)) {
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1725 if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) {
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1726 if (unit->heater_state != ival)
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1727 syslog(LOG_NOTICE, "Fermenter unit %s heater state %d to %d", unit->uuid, unit->heater_state, ival);
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1728 unit->heater_state = ival;
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1729 }
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1730
270
df81d583c2c3 The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents: 269
diff changeset
1731 } else if (val && (strcmp(kwd, (char *)"HEATER_DELAY") == 0)) {
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1732 if (sscanf(val, "%d", &ival) == 1) {
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1733 if (unit->heater_delay != ival)
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1734 syslog(LOG_NOTICE, "Fermenter unit %s heater delay %d to %d", unit->uuid, unit->heater_delay, ival);
270
df81d583c2c3 The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents: 269
diff changeset
1735 unit->heater_delay = ival;
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1736 }
270
df81d583c2c3 The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents: 269
diff changeset
1737
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1738 } else if (strcmp(kwd, (char *)"COOLER_ADDRESS") == 0) {
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1739 if (val && unit->cooler_address && (strcmp(val, unit->cooler_address)))
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1740 syslog(LOG_NOTICE, "Fermenter unit %s cooler address `%s' to `%s'", unit->uuid, unit->cooler_address, val);
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1741 if (unit->cooler_address) {
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1742 device_count(FALSE, unit->cooler_address);
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1743 free(unit->cooler_address);
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1744 }
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1745 if (val) {
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1746 unit->cooler_address = xstrcpy(val);
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1747 device_count(TRUE, unit->cooler_address);
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1748 } else
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1749 unit->cooler_address = NULL;
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1750
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1751 } else if (val && (strcmp(kwd, (char *)"COOLER_STATE") == 0)) {
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1752 if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) {
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1753 if (unit->cooler_state != ival)
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1754 syslog(LOG_NOTICE, "Fermenter unit %s cooler state %d to %d", unit->uuid, unit->cooler_state, ival);
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1755 unit->cooler_state = ival;
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1756 }
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1757
270
df81d583c2c3 The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents: 269
diff changeset
1758 } else if (val && (strcmp(kwd, (char *)"COOLER_DELAY") == 0)) {
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1759 if (sscanf(val, "%d", &ival) == 1) {
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1760 if (unit->cooler_delay != ival)
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1761 syslog(LOG_NOTICE, "Fermenter unit %s cooler delay %d to %d", unit->uuid, unit->cooler_delay, ival);
270
df81d583c2c3 The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents: 269
diff changeset
1762 unit->cooler_delay = ival;
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1763 }
270
df81d583c2c3 The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents: 269
diff changeset
1764
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1765 } else if (strcmp(kwd, (char *)"FAN_ADDRESS") == 0) {
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1766 if (val && unit->fan_address && (strcmp(val, unit->fan_address)))
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1767 syslog(LOG_NOTICE, "Fermenter unit %s fan address `%s' to `%s'", unit->uuid, unit->fan_address, val);
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1768 if (unit->fan_address) {
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1769 device_count(FALSE, unit->fan_address);
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1770 free(unit->fan_address);
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1771 }
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1772 if (val) {
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1773 unit->fan_address = xstrcpy(val);
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1774 device_count(TRUE, unit->fan_address);
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1775 } else
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1776 unit->fan_address = NULL;
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1777
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1778 } else if (val && (strcmp(kwd, (char *)"FAN_STATE") == 0)) {
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1779 if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) {
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1780 if (unit->fan_state != ival)
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1781 syslog(LOG_NOTICE, "Fermenter unit %s fan state %d to %d", unit->uuid, unit->fan_state, ival);
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1782 unit->fan_state = ival;
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1783 }
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1784
270
df81d583c2c3 The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents: 269
diff changeset
1785 } else if (val && (strcmp(kwd, (char *)"FAN_DELAY") == 0)) {
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1786 if (sscanf(val, "%d", &ival) == 1) {
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1787 if (unit->fan_delay != ival)
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1788 syslog(LOG_NOTICE, "Fermenter unit %s fan delay %d to %d", unit->uuid, unit->fan_delay, ival);
270
df81d583c2c3 The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents: 269
diff changeset
1789 unit->fan_delay = ival;
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1790 }
270
df81d583c2c3 The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents: 269
diff changeset
1791
306
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1792 } else if (strcmp(kwd, (char *)"LIGHT_ADDRESS") == 0) {
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1793 if (val && unit->light_address && (strcmp(val, unit->light_address)))
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1794 syslog(LOG_NOTICE, "Fermenter unit %s light address `%s' to `%s'", unit->uuid, unit->light_address, val);
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1795 if (unit->light_address) {
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1796 device_count(FALSE, unit->light_address);
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1797 free(unit->light_address);
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1798 }
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1799 if (val) {
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1800 unit->light_address = xstrcpy(val);
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1801 device_count(TRUE, unit->light_address);
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1802 } else
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1803 unit->light_address = NULL;
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1804
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1805 } else if (val && (strcmp(kwd, (char *)"LIGHT_STATE") == 0)) {
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1806 if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) {
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1807 if (unit->light_state != ival)
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1808 syslog(LOG_NOTICE, "Fermenter unit %s light state %d to %d", unit->uuid, unit->light_state, ival);
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1809 unit->light_state = ival;
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1810 }
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1811
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1812 } else if (val && (strcmp(kwd, (char *)"LIGHT_DELAY") == 0)) {
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1813 if (sscanf(val, "%d", &ival) == 1) {
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1814 if (unit->light_delay != ival)
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1815 syslog(LOG_NOTICE, "Fermenter unit %s light delay %d to %d", unit->uuid, unit->light_delay, ival);
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1816 unit->light_delay = ival;
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1817 }
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1818
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1819 } else if (strcmp(kwd, (char *)"DOOR_ADDRESS") == 0) {
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1820 if (val && unit->door_address && (strcmp(val, unit->door_address)))
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1821 syslog(LOG_NOTICE, "Fermenter unit %s door address `%s' to `%s'", unit->uuid, unit->door_address, val);
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1822 if (unit->door_address) {
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1823 device_count(FALSE, unit->door_address);
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1824 free(unit->door_address);
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1825 }
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1826 if (val) {
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1827 unit->door_address = xstrcpy(val);
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1828 device_count(TRUE, unit->door_address);
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1829 } else
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1830 unit->door_address = NULL;
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1831
306
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1832 } else if (strcmp(kwd, (char *)"PSU_ADDRESS") == 0) {
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1833 if (val && unit->psu_address && (strcmp(val, unit->psu_address)))
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1834 syslog(LOG_NOTICE, "Fermenter unit %s psu address `%s' to `%s'", unit->uuid, unit->psu_address, val);
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1835 if (unit->psu_address) {
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1836 device_count(FALSE, unit->psu_address);
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1837 free(unit->psu_address);
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1838 }
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1839 if (val) {
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1840 unit->psu_address = xstrcpy(val);
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1841 device_count(TRUE, unit->psu_address);
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1842 } else
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1843 unit->psu_address = NULL;
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1844
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1845 } else if (val && (strcmp(kwd, (char *)"MODE") == 0)) {
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1846 for (i = 0; i < 5; i++) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1847 if (strcmp(val, UNITMODE[i]) == 0) {
189
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 185
diff changeset
1848 /* Initialize log if the unit is turned on */
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 185
diff changeset
1849 if ((unit->mode == UNITMODE_OFF) && (i != UNITMODE_OFF))
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 185
diff changeset
1850 initlog(unit->name);
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1851 syslog(LOG_NOTICE, "Fermenter unit %s mode %s to %s", unit->uuid, UNITMODE[unit->mode], UNITMODE[i]);
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1852 unit->mode = i;
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1853 /* Allways turn everything off after a mode change */
313
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1854 unit->PID_iState = unit->PID_dState = 0.0;
306
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1855 unit->heater_state = unit->cooler_state = unit->fan_state = unit->light_state = 0;
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1856 unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0;
184
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1857 device_out(unit->heater_address, unit->heater_state);
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1858 device_out(unit->cooler_address, unit->cooler_state);
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1859 device_out(unit->fan_address, unit->fan_state);
306
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1860 device_out(unit->light_address, unit->light_state);
237
51a294d683cd Add a sane default for profile precessing.
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
1861 if (unit->mode == UNITMODE_PROFILE) {
51a294d683cd Add a sane default for profile precessing.
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
1862 /*
51a294d683cd Add a sane default for profile precessing.
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
1863 * Set a sane default until it will be overruled by the
51a294d683cd Add a sane default for profile precessing.
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
1864 * main processing loop.
51a294d683cd Add a sane default for profile precessing.
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
1865 */
51a294d683cd Add a sane default for profile precessing.
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
1866 unit->prof_target = 20.0;
51a294d683cd Add a sane default for profile precessing.
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
1867 }
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1868 break;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1869 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1870 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1871
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1872 } else if (val && (strcmp(kwd, (char *)"FRIDGE_SET") == 0)) {
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
1873 if ((sscanf(val, "%f", &fval) == 1) && (fval >= unit->temp_set_min) && (fval <= unit->temp_set_max)) {
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1874 if (unit->fridge_set != fval)
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1875 syslog(LOG_NOTICE, "Fermenter unit %s fridge temperature %.1f to %.1f", unit->uuid, unit->fridge_set, fval);
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1876 unit->fridge_set = fval;
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
1877 }
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1878
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1879 } else if (val && (strcmp(kwd, (char *)"BEER_SET") == 0)) {
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
1880 if ((sscanf(val, "%f", &fval) == 1) && (fval >= unit->temp_set_min) && (fval <= unit->temp_set_max)) {
310
53774295e14a Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents: 306
diff changeset
1881 if (unit->beer_set != fval)
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1882 syslog(LOG_NOTICE, "Fermenter unit %s beer temperature %.1f to %.1f", unit->uuid, unit->beer_set, fval);
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1883 unit->beer_set = fval;
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
1884 }
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1885
310
53774295e14a Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents: 306
diff changeset
1886 } else if (val && (strcmp(kwd, (char *)"PID_KP") == 0)) {
53774295e14a Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents: 306
diff changeset
1887 if ((sscanf(val, "%f", &fval) == 1) && (fval >= 0.0)) {
53774295e14a Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents: 306
diff changeset
1888 if (unit->PID_Kp != fval)
53774295e14a Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents: 306
diff changeset
1889 syslog(LOG_NOTICE, "Fermenter unit %s PID Kp %.2f to %.2f", unit->uuid, unit->PID_Kp, fval);
53774295e14a Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents: 306
diff changeset
1890 unit->PID_Kp = fval;
53774295e14a Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents: 306
diff changeset
1891 }
53774295e14a Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents: 306
diff changeset
1892
53774295e14a Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents: 306
diff changeset
1893 } else if (val && (strcmp(kwd, (char *)"PID_KD") == 0)) {
53774295e14a Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents: 306
diff changeset
1894 if ((sscanf(val, "%f", &fval) == 1) && (fval >= 0.0)) {
53774295e14a Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents: 306
diff changeset
1895 if (unit->PID_Kd != fval)
53774295e14a Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents: 306
diff changeset
1896 syslog(LOG_NOTICE, "Fermenter unit %s PID Kd %.2f to %.2f", unit->uuid, unit->PID_Kd, fval);
53774295e14a Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents: 306
diff changeset
1897 unit->PID_Kd = fval;
53774295e14a Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents: 306
diff changeset
1898 }
53774295e14a Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents: 306
diff changeset
1899
53774295e14a Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents: 306
diff changeset
1900 } else if (val && (strcmp(kwd, (char *)"PID_KI") == 0)) {
53774295e14a Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents: 306
diff changeset
1901 if ((sscanf(val, "%f", &fval) == 1) && (fval >= 0.0)) {
53774295e14a Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents: 306
diff changeset
1902 if (unit->PID_Ki != fval)
53774295e14a Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents: 306
diff changeset
1903 syslog(LOG_NOTICE, "Fermenter unit %s PID Ki %.2f to %.2f", unit->uuid, unit->PID_Ki, fval);
53774295e14a Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents: 306
diff changeset
1904 unit->PID_Ki = fval;
53774295e14a Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents: 306
diff changeset
1905 }
53774295e14a Added Kp, Kd and Ki settings to the units. Bumped to version 0.2.9
Michiel Broek <mbroek@mbse.eu>
parents: 306
diff changeset
1906
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1907 } else if (strcmp(kwd, (char *)"PROFILE") == 0) {
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1908 if (unit->prof_state == PROFILE_OFF) {
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1909 /*
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1910 * Only change profile if it is not active, else drop this one.
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1911 */
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1912 if (unit->profile && val && strcmp(unit->profile, val))
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1913 syslog(LOG_NOTICE, "Fermenter unit %s profile name `%s' to `%s'", unit->uuid, unit->profile, val);
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1914 if (unit->profile)
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1915 free(unit->profile);
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1916
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1917 if (val)
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1918 unit->profile = xstrcpy(val);
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1919 else
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1920 unit->profile = NULL;
195
b34a1b2421fb Reset output when a different profile is selected. Better startup logging about the unit state. Added Beer, Fridge and partial Profile settings from the liveview weeb screen.
Michiel Broek <mbroek@mbse.eu>
parents: 194
diff changeset
1921 /*
b34a1b2421fb Reset output when a different profile is selected. Better startup logging about the unit state. Added Beer, Fridge and partial Profile settings from the liveview weeb screen.
Michiel Broek <mbroek@mbse.eu>
parents: 194
diff changeset
1922 * Reset all output devices
b34a1b2421fb Reset output when a different profile is selected. Better startup logging about the unit state. Added Beer, Fridge and partial Profile settings from the liveview weeb screen.
Michiel Broek <mbroek@mbse.eu>
parents: 194
diff changeset
1923 */
313
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1924 unit->PID_iState = unit->PID_dState = 0.0;
306
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1925 unit->heater_state = unit->cooler_state = unit->fan_state = unit->light_state = 0;
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1926 unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0;
195
b34a1b2421fb Reset output when a different profile is selected. Better startup logging about the unit state. Added Beer, Fridge and partial Profile settings from the liveview weeb screen.
Michiel Broek <mbroek@mbse.eu>
parents: 194
diff changeset
1927 device_out(unit->heater_address, unit->heater_state);
b34a1b2421fb Reset output when a different profile is selected. Better startup logging about the unit state. Added Beer, Fridge and partial Profile settings from the liveview weeb screen.
Michiel Broek <mbroek@mbse.eu>
parents: 194
diff changeset
1928 device_out(unit->cooler_address, unit->cooler_state);
b34a1b2421fb Reset output when a different profile is selected. Better startup logging about the unit state. Added Beer, Fridge and partial Profile settings from the liveview weeb screen.
Michiel Broek <mbroek@mbse.eu>
parents: 194
diff changeset
1929 device_out(unit->fan_address, unit->fan_state);
306
97602274eb58 Updated to add support for lights in a fermenter unit and a Power Supply status.
Michiel Broek <mbroek@mbse.eu>
parents: 303
diff changeset
1930 device_out(unit->light_address, unit->light_state);
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1931 }
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1932
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1933 } else if (val && (strcmp(kwd, (char *)"PROF_STATE") == 0)) {
217
2922d439ff63 Added profile state ABORT
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
1934 for (i = 0; i < 5; i++) {
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1935 if (strcmp(val, PROFSTATE[i]) == 0) {
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1936 switch (i) {
274
111b0e9663dc Added logging if profile state is changed via the web interface. Log profile progress each half hour in syslog. Profile resttime steps 0 hours is allowed, meaning resttime or steptime must be set for a valid step. Updated the helptext on the web page.
Michiel Broek <mbroek@mbse.eu>
parents: 273
diff changeset
1937 case PROFILE_OFF: if (unit->prof_state == PROFILE_DONE) {
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1938 unit->prof_state = PROFILE_OFF;
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1939 syslog(LOG_NOTICE, "Fermenter unit %s profile to OFF", unit->uuid);
274
111b0e9663dc Added logging if profile state is changed via the web interface. Log profile progress each half hour in syslog. Profile resttime steps 0 hours is allowed, meaning resttime or steptime must be set for a valid step. Updated the helptext on the web page.
Michiel Broek <mbroek@mbse.eu>
parents: 273
diff changeset
1940 }
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1941 break;
274
111b0e9663dc Added logging if profile state is changed via the web interface. Log profile progress each half hour in syslog. Profile resttime steps 0 hours is allowed, meaning resttime or steptime must be set for a valid step. Updated the helptext on the web page.
Michiel Broek <mbroek@mbse.eu>
parents: 273
diff changeset
1942 case PROFILE_PAUSE: if (unit->prof_state == PROFILE_RUN) {
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1943 unit->prof_state = PROFILE_PAUSE;
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1944 syslog(LOG_NOTICE, "Fermenter unit %s profile PAUSE", unit->uuid);
274
111b0e9663dc Added logging if profile state is changed via the web interface. Log profile progress each half hour in syslog. Profile resttime steps 0 hours is allowed, meaning resttime or steptime must be set for a valid step. Updated the helptext on the web page.
Michiel Broek <mbroek@mbse.eu>
parents: 273
diff changeset
1945 } else if (unit->prof_state == PROFILE_PAUSE) {
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1946 unit->prof_state = PROFILE_RUN;
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1947 syslog(LOG_NOTICE, "Fermenter unit %s profile RESUME", unit->uuid);
274
111b0e9663dc Added logging if profile state is changed via the web interface. Log profile progress each half hour in syslog. Profile resttime steps 0 hours is allowed, meaning resttime or steptime must be set for a valid step. Updated the helptext on the web page.
Michiel Broek <mbroek@mbse.eu>
parents: 273
diff changeset
1948 }
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1949 break;
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1950 case PROFILE_RUN: if (unit->prof_state == PROFILE_OFF) {
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1951 unit->prof_state = PROFILE_RUN;
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1952 unit->prof_started = time(NULL);
289
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 285
diff changeset
1953 unit->prof_paused = unit->prof_primary_done = 0;
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 285
diff changeset
1954 unit->prof_peak_abs = unit->prof_peak_rel = 0.0;
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1955 syslog(LOG_NOTICE, "Fermenter unit %s profile to RUN", unit->uuid);
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1956 }
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1957 break;
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1958 case PROFILE_DONE: break; /* Command is illegal */
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1959 case PROFILE_ABORT: if ((unit->prof_state == PROFILE_RUN) || (unit->prof_state == PROFILE_PAUSE)) {
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1960 unit->prof_state = PROFILE_OFF;
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1961 unit->prof_started = 0;
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1962 syslog(LOG_NOTICE, "Fermenter unit %s profile ABORT", unit->uuid);
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1963 }
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1964 break;
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1965 }
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1966 break;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1967 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1968 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1969
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1970 } else if (val && (strcmp(kwd, (char *)"TEMP_SET_MIN") == 0)) {
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1971 if (sscanf(val, "%f", &fval) == 1) {
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1972 if (unit->temp_set_min != fval)
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1973 syslog(LOG_NOTICE, "Fermenter unit %s temperature set minimum %.1f to %.1f", unit->uuid, unit->temp_set_min, fval);
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1974 unit->temp_set_min = fval;
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1975 }
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1976
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1977 } else if (val && (strcmp(kwd, (char *)"TEMP_SET_MAX") == 0)) {
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1978 if (sscanf(val, "%f", &fval) == 1) {
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1979 if (unit->temp_set_max != fval)
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1980 syslog(LOG_NOTICE, "Fermenter unit %s temperature set maximum %.1f to %.1f", unit->uuid, unit->temp_set_max, fval);
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1981 unit->temp_set_max = fval;
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1982 }
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1983
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1984 } else if (val && (strcmp(kwd, (char *)"IDLE_RANGE_L") == 0)) {
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1985 if (sscanf(val, "%f", &fval) == 1) {
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1986 if (unit->idle_rangeL != fval)
312
7b0f819a3805 Added more precision to the unit low and high black window margins. Switched to PID routine from Pid without a PhD. The PID compute routine is now in the one second loop. The switch delay times are now in seconds, 0..720.
Michiel Broek <mbroek@mbse.eu>
parents: 311
diff changeset
1987 syslog(LOG_NOTICE, "Fermenter unit %s idle range low %.2f to %.2f", unit->uuid, unit->idle_rangeL, fval);
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1988 unit->idle_rangeL = fval;
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1989 }
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1990
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1991 } else if (val && (strcmp(kwd, (char *)"IDLE_RANGE_H") == 0)) {
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1992 if (sscanf(val, "%f", &fval) == 1) {
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1993 if (unit->idle_rangeH != fval)
312
7b0f819a3805 Added more precision to the unit low and high black window margins. Switched to PID routine from Pid without a PhD. The PID compute routine is now in the one second loop. The switch delay times are now in seconds, 0..720.
Michiel Broek <mbroek@mbse.eu>
parents: 311
diff changeset
1994 syslog(LOG_NOTICE, "Fermenter unit %s idle range high %.2f to %.2f", unit->uuid, unit->idle_rangeH, fval);
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1995 unit->idle_rangeH = fval;
282
885e5243bb50 UNIT PUT command logging added.
Michiel Broek <mbroek@mbse.eu>
parents: 281
diff changeset
1996 }
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1997
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1998 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1999 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
2000 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
2001 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
2002 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
2003 }
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
2004 srv_send((char *)"440 No such unit");
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
2005 return 1;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
2006 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
2007
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
2008 srv_send((char *)"504 Subcommand error");
87
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
2009 return 1;
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
2010 }
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
2011
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
2012
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
2013
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2014 void cmd_server(void)
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2015 {
132
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
2016 char buf[SS_BUFSIZE];
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
2017 int i, rlen;
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2018 socklen_t fromlen;
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2019
48
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
2020 memset((char *)&buf, 0, SS_BUFSIZE);
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
2021 fromlen = sizeof(peeraddr_in);
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
2022 rlen = recvfrom(s, buf, sizeof(buf) -1, 0, (struct sockaddr *)&peeraddr_in, &fromlen);
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
2023 if (rlen == -1) {
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 266
diff changeset
2024 syslog(LOG_NOTICE, "recvfrom(): %s", strerror(errno));
48
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
2025 } else {
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
2026 for (i = 0; i < strlen(buf); i++) {
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
2027 if (buf[i] == '\n')
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
2028 buf[i] = '\0';
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
2029 if (buf[i] == '\r')
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
2030 buf[i] = '\0';
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
2031 }
80
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
2032 for (i = strlen(buf) -1; i > 0; i--) {
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
2033 if (buf[i] == ' ')
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
2034 buf[i] = '\0';
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
2035 else
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
2036 break;
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
2037 }
48
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
2038 if (strlen(buf)) {
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
2039 if (debug) {
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
2040 syslog(LOG_NOTICE, "recv: \"%s\"", buf);
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
2041 fprintf(stdout, "recv: \"%s\"\n", buf);
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2042 }
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2043
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2044 /*
48
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
2045 * Process commands from the client
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2046 */
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
2047 if (strncmp(buf, "DEVICE", 6) == 0) {
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
2048 if (cmd_device(buf) == 0)
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
2049 wrconfig();
206
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
2050 } else if (strncmp(buf, "GLOBAL", 6) == 0) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
2051 if (cmd_global(buf) == 0)
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
2052 wrconfig();
80
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
2053 } else if (strncmp(buf, "HELP", 4) == 0) {
68
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
2054 srv_send((char *)"100 Help text follows");
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
2055 srv_send((char *)"Recognized commands:");
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
2056 srv_send((char *)"");
132
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
2057 // 12345678901234567890123456789012345678901234567890123456789012345678901234567890
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
2058 srv_send((char *)"DEVICE ADD type Add new Device type");
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
2059 srv_send((char *)"DEVICE DEL uuid Delete Device by uuid");
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
2060 srv_send((char *)"DEVICE LIST List Devices");
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
2061 srv_send((char *)"DEVICE GET uuid Get Device record by uuid");
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
2062 srv_send((char *)"DEVICE PUT uuid Put Device record by uuid");
206
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
2063 srv_send((char *)"GLOBAL GET Get global settings");
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
2064 srv_send((char *)"GLOBAL PUT Put global settings");
132
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
2065 srv_send((char *)"LIST List all fermenter units");
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
2066 srv_send((char *)"LIST LOG uuid List logfile data in 1 hour lines");
132
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
2067 srv_send((char *)"PROFILE uuid,name Profile rename");
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
2068 srv_send((char *)"PROFILE ADD name Add new Profile with name");
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
2069 srv_send((char *)"PROFILE DEL uuid Delete Profile by uuid");
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
2070 srv_send((char *)"PROFILE LIST List available profiles");
192
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
2071 srv_send((char *)"PROFILE GET uuid Get Profile record by uuid");
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
2072 srv_send((char *)"PROFILE PUT uuid Put Profile record by uuid");
140
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
2073 srv_send((char *)"PROFILE GETS uuid Profile get steps list");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
2074 srv_send((char *)"PROFILE PUTS uuid Profile put steps list");
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
2075 #ifdef USE_SIMULATOR
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
2076 srv_send((char *)"SIMULATOR ADD name Add a new Simulator with name");
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
2077 srv_send((char *)"SIMULATOR DEL uuid Delete Simulator by uuid");
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
2078 srv_send((char *)"SIMULATOR LIST List all Simulators");
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
2079 srv_send((char *)"SIMULATOR GET uuid Get Simulator record by uuid");
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
2080 srv_send((char *)"SIMULATOR PUT uuid Put Simulator record by uuid");
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
2081 #endif
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
2082 srv_send((char *)"UNIT ADD name Add a new Unit with name");
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
2083 srv_send((char *)"UNIT DEL uuid Delete Unit by uuid");
206
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
2084 srv_send((char *)"UNIT LIST List all Units");
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
2085 srv_send((char *)"UNIT GET uuid Get Unit record by uuid");
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
2086 srv_send((char *)"UNIT PUT uuid Put Unit record by uuid");
68
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
2087 srv_send((char *)".");
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
2088 } else if (strncmp(buf, "LIST", 4) == 0) {
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
2089 cmd_list(buf);
303
19a9a3912d03 Added PING/PONG command to the server. Bumped to version 0.2.7
Michiel Broek <mbroek@mbse.eu>
parents: 300
diff changeset
2090 } else if (strncmp(buf, "PING", 4) == 0) {
19a9a3912d03 Added PING/PONG command to the server. Bumped to version 0.2.7
Michiel Broek <mbroek@mbse.eu>
parents: 300
diff changeset
2091 srv_send((char *)"101 PONG");
132
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
2092 } else if (strncmp(buf, "PROFILE", 7) == 0) {
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
2093 if (cmd_profile(buf) == 0)
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
2094 wrconfig();
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
2095 #ifdef USE_SIMULATOR
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
2096 } else if (strncmp(buf, "SIMULATOR", 9) == 0) {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
2097 if (cmd_simulator(buf) == 0)
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
2098 wrconfig();
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 258
diff changeset
2099 #endif
87
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
2100 } else if (strncmp(buf, "UNIT", 4) == 0) {
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
2101 if (cmd_unit(buf) == 0)
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
2102 wrconfig();
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2103 } else {
132
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
2104 srv_send((char *)"500 Unknown command");
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2105 }
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2106 }
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2107 }
44
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2108
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2109 close(s);
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2110 }
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2111
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2112
132
8bd209d1c020 Added some profile commands to the server. Profile names can be changed from the web interface. Removed obsolete commands.
Michiel Broek <mbroek@mbse.eu>
parents: 131
diff changeset
2113
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 62
diff changeset
2114 #ifdef HAVE_WIRINGPI_H
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2115 PI_THREAD (my_server_loop)
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 62
diff changeset
2116 #else
74
879bd09e2b96 Reinstalled threads
Michiel Broek <mbroek@mbse.eu>
parents: 71
diff changeset
2117 void *my_server_loop(void *threadid)
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 62
diff changeset
2118 #endif
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2119 {
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2120 socklen_t addrlen;
44
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2121 int optval = 1;
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2122
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2123 syslog(LOG_NOTICE, "Thread my_server_loop started");
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2124 if (debug)
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2125 fprintf(stdout, "Thread my_server_loop started\n");
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2126
44
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2127 memset((char *)&myaddr_in, 0, sizeof(struct sockaddr_in));
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2128 memset((char *)&peeraddr_in, 0, sizeof(struct sockaddr_in));
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2129 myaddr_in.sin_family = AF_INET;
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2130 myaddr_in.sin_addr.s_addr = INADDR_ANY;
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2131 myaddr_in.sin_port = htons(Config.my_port);
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2132
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2133 ls = socket(AF_INET, SOCK_STREAM, 0);
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2134 if (ls == -1) {
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 266
diff changeset
2135 syslog(LOG_NOTICE, "Can't create listen socket: %s", strerror(errno));
44
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2136 fprintf(stderr, "Can't create listen socket: %s\n", strerror(errno));
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2137 return 0;
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2138 }
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2139
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2140 if (setsockopt(ls, SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof(optval)) == -1) {
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 266
diff changeset
2141 syslog(LOG_NOTICE, "Can't setsockopt SO_KEEPALIVE socket: %s", strerror(errno));
44
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2142 close(ls);
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2143 return 0;
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2144 }
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2145
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2146 if (setsockopt(ls, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) == -1) {
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 266
diff changeset
2147 syslog(LOG_NOTICE, "Can't setsockopt SO_REUSEADDR socket: %s", strerror(errno));
44
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2148 close(ls);
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 62
diff changeset
2149 return 0;
44
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2150 }
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2151
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2152 if (bind(ls, (struct sockaddr *)&myaddr_in, sizeof(struct sockaddr_in)) == -1) {
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 266
diff changeset
2153 syslog(LOG_NOTICE, "Can't bind to listen socket: %s", strerror(errno));
44
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2154 close(ls);
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 62
diff changeset
2155 return 0;
44
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2156 }
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2157
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2158 if (listen(ls, 5) == -1) {
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 266
diff changeset
2159 syslog(LOG_NOTICE, "Can't listen on listen socket: %s", strerror(errno));
44
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2160 close(ls);
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 62
diff changeset
2161 return 0;
44
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2162 }
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2163
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2164 syslog(LOG_NOTICE, "listen socket created %d", ls);
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2165
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2166
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2167 /*
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2168 * Loop forever until the external shutdown variable is set.
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2169 */
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2170 for (;;) {
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2171
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2172 addrlen = sizeof(struct sockaddr_in);
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2173 /*
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2174 * This call will block until a new connection
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2175 * arrives. Then it will return the address of
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2176 * the connecting peer, and a new socket
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2177 * descriptor, s, for that connection.
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2178 */
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2179 s = accept(ls, (struct sockaddr *)&peeraddr_in, &addrlen);
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2180 if (s == -1) {
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 266
diff changeset
2181 syslog(LOG_NOTICE, "my_server_loop accept failed %s", strerror(errno));
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2182 if (debug)
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2183 fprintf(stdout, "my_server_loop accept failed %s\n", strerror(errno));
44
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
2184 return 0;
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2185 }
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2186
48
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
2187 cmd_server();
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2188
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2189 if (my_shutdown) {
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2190 syslog(LOG_NOTICE, "Thread my_server_loop stopped");
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2191 if (debug)
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2192 fprintf(stdout, "Thread my_server_loop stopped\n");
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2193 return 0;
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2194 }
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2195
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2196 }
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2197 }
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2198
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
2199

mercurial