thermferm/server.c

Mon, 11 Aug 2014 18:38:57 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 11 Aug 2014 18:38:57 +0200
changeset 219
ae720212accc
parent 217
2922d439ff63
child 223
14700edd2a67
permissions
-rw-r--r--

Added profile running and steps handling.

42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /*****************************************************************************
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * Copyright (C) 2008-2014
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"
1bd9a16f5061 Added .h files
Michiel Broek <mbroek@mbse.eu>
parents: 101
diff changeset
28 #include "xutil.h"
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29
58
e8e7b46b705b Fixed compilation without wiringpi
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
30
75
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 74
diff changeset
31 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
32 extern int debug;
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 62
diff changeset
33 #ifdef HAVE_WIRINGPI_H
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34 extern int lcdHandle;
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35 extern unsigned char lcdbuf[MAX_LCDS][20][4];
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 62
diff changeset
36 #endif
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
37 extern sys_config Config;
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
38 extern const char UNITMODE[5][8];
95
2c28afc329a5 Removed old brewPi settings
Michiel Broek <mbroek@mbse.eu>
parents: 92
diff changeset
39 extern const char UNITmode[5];
101
1302abe92eb1 Made temperature sensors working in the units
Michiel Broek <mbroek@mbse.eu>
parents: 100
diff changeset
40 extern const char TEMPSTATE[3][8];
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
41 extern const char DEVTYPE[7][6];
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
42 extern const char DEVPRESENT[4][6];
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
43 extern const char DEVDIR[7][11];
217
2922d439ff63 Added profile state ABORT
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
44 extern const char PROFSTATE[5][6];
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
45
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
47 int s; /* connected socket */
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
48 int ls; /* listen socket */
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
50 struct sockaddr_in myaddr_in; /* for local socket address */
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
51 struct sockaddr_in peeraddr_in; /* for peer socket address */
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 struct hostent *hp;
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
54
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
55 #define SS_BUFSIZE 1024
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
56 #define SS_TIMEOUT 300
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57
48
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
58
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)) {
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
81 syslog(LOG_NOTICE, "srv_send failed");
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) {
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
86 syslog(LOG_NOTICE, "srv_send failed");
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) {
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
104 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
105 device->inuse++;
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
106 } else {
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
107 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
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 }
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
110 }
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
111 }
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
112 }
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
113
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
114
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
115
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
116 int delete_Profile(char *uuid)
138
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
117 {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
118 profiles_list *current = Config.profiles;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
119 profiles_list *previous = NULL;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
120 prof_step *step, *olds;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
121
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
122 while (current) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
123 if (strcmp(current->uuid, uuid) == 0) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
124 if (previous == NULL) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
125 Config.profiles = current->next;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
126 free(current->uuid);
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
127 current->uuid = NULL;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
128 free(current->name);
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
129 current->name = NULL;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
130 if (current->steps) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
131 for (step = current->steps; step; step = olds) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
132 olds = step->next;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
133 free(step);
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
134 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
135 current->steps = NULL;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
136 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
137 free(current);
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
138 return 1;
138
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
139 } else {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
140 free(current->uuid);
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
141 current->uuid = NULL;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
142 free(current->name);
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
143 current->name = NULL;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
144 if (current->steps) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
145 for (step = current->steps; step; step = olds) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
146 olds = step->next;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
147 free(step);
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
148 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
149 current->steps = NULL;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
150 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
151 previous->next = current->next;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
152 free(current);
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
153 current = previous->next;
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
154 return 1;
138
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
155 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
156 } else {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
157 previous = current;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
158 current = current->next;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
159 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
160 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
161
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
162 return 0;
138
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
163 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
164
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
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
167 int delete_Device(char *uuid)
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
168 {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
169 devices_list *current = Config.devices;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
170 devices_list *previous = NULL;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
171
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
172 while (current) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
173 if (strcmp(current->uuid, uuid) == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
174 if (previous == NULL) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
175 Config.devices = current->next;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
176 free(current->uuid);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
177 current->uuid = NULL;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
178 free(current->address);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
179 current->address = NULL;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
180 free(current->description);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
181 current->description = NULL;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
182 free(current->comment);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
183 current->comment = NULL;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
184 free(current);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
185 return 1;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
186 } else {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
187 free(current->uuid);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
188 current->uuid = NULL;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
189 free(current->address);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
190 current->address = NULL;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
191 free(current->description);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
192 current->description = NULL;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
193 free(current->comment);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
194 current->comment = NULL;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
195 previous->next = current->next;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
196 free(current);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
197 current = previous->next;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
198 return 1;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
199 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
200 } else {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
201 previous = current;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
202 current = current->next;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
203 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
204 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
205 return 0;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
206 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
207
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
208
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
209
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
210 /*
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
211 * DEVICE ADD type
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
212 * DEVICE DEL uuid
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
213 * DEVICE LIST
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
214 * DEVICE GET uuid
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
215 * DEVICE PUT uuid
157
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
216 */
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
217 int cmd_device(char *buf)
157
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
218 {
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
219 char *opt, *param, *kwd, *val, ibuf[SS_BUFSIZE];
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
220 devices_list *device, *tmpd;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
221 socklen_t fromlen;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
222 int i, rlen, ival;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
223 uuid_t uu;
157
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
224
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
225 opt = strtok(buf, " \0");
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
226 opt = strtok(NULL, " \0");
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
227
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
228 if (opt == NULL) {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
229 srv_send((char *)"501 Subcommand missing");
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
230 return 1;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
231 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
232 param = strtok(NULL, "\0");
157
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
233
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
234 if (strcmp(opt, (char *)"LIST") == 0) {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
235 srv_send((char *)"212 Devices list follows:");
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
236 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
237 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
238 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
239 srv_send((char *)".");
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
240 return 0;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
241 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
242
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
243 if (param == NULL) {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
244 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
245 return 1;
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
246 }
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
247
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
248 if (strcmp(opt, (char *)"ADD") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
249 if ((strcmp(param, (char *)"RC433") == 0) || (strcmp(param, (char *)"DHT") == 0) ||
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
250 (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
251
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
252 device = (devices_list *)malloc(sizeof(devices_list));
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
253 device->next = NULL;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
254 device->version = 1;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
255 device->uuid = malloc(37);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
256 uuid_generate(uu);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
257 uuid_unparse(uu, device->uuid);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
258 for (i = 0; i < 7; i++) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
259 if (strcmp(param, DEVTYPE[i]) == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
260 device->type = i;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
261 break;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
262 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
263 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
264 device->direction = DEVDIR_UNDEF;
209
c5b1dfd83e81 Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents: 208
diff changeset
265 device->value = device->offset = device->subdevice = device->inuse = 0;
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
266 device->present = DEVPRESENT_UNDEF;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
267 device->address = xstrcpy((char *)"Enter address here");
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
268 device->gpiopin = -1;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
269 device->description = xstrcpy((char *)"Describe me here");
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
270 device->comment = xstrcpy((char *)"Comment here");
170
3cb99272b84b A bit of code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 167
diff changeset
271
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
272 if (Config.devices == NULL) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
273 Config.devices = device;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
274 } else {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
275 for (tmpd = Config.devices; tmpd; tmpd = tmpd->next) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
276 if (tmpd->next == NULL) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
277 tmpd->next = device;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
278 break;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
279 }
157
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
280 }
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
281 }
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
282 syslog(LOG_NOTICE, "Device %s added", device->uuid);
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
283 srv_send((char *)"211 Device %s added", device->uuid);
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
284 return 0;
157
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
285
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
286 } else {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
287 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
288 return 1;
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 }
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
291
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
292 if (strcmp(opt, (char *)"DEL") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
293
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
294 if (delete_Device(param)) {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
295 syslog(LOG_NOTICE, "Device %s deleted", param);
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
296 srv_send((char *)"211 Device %s deleted", param);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
297 return 0;
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 *)"440 No such device");
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
300 return 1;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
301 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
302 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
303
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
304 if (strcmp(opt, (char *)"GET") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
305 for (device = Config.devices; device; device = device->next) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
306 if (strcmp(device->uuid, param) == 0) {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
307 srv_send((char *)"213 Device record follows:");
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
308 srv_send((char *)"TYPE,%s", DEVTYPE[device->type]);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
309 srv_send((char *)"DIRECTION,%s", DEVDIR[device->direction]);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
310 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
311 srv_send((char *)"OFFSET,%d", device->offset);
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
312 srv_send((char *)"PRESENT,%s", DEVPRESENT[device->present]);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
313 srv_send((char *)"ADDRESS,%s", device->address);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
314 srv_send((char *)"SUBDEVICE,%d", device->subdevice);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
315 srv_send((char *)"GPIOPIN,%d", device->gpiopin);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
316 srv_send((char *)"DESCRIPTION,%s", device->description);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
317 srv_send((char *)"INUSE,%d", device->inuse);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
318 srv_send((char *)"COMMENT,%s", device->comment);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
319 srv_send((char *)"TIMESTAMP,%d", (int)device->timestamp);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
320 srv_send((char *)".");
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
321 return 1;
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 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
324 srv_send((char *)"440 No such device");
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
325 return 1;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
326 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
327
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
328 if (strcmp(opt, (char *)"PUT") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
329 for (device = Config.devices; device; device = device->next) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
330 if (strcmp(device->uuid, param) == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
331 while (1) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
332 memset((char *)&ibuf, 0, SS_BUFSIZE);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
333 fromlen = sizeof(peeraddr_in);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
334 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
335 if (rlen == -1) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
336 syslog(LOG_NOTICE, "recvfrom(): %s", strerror(errno));
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
337 srv_send((char *)"518 recfrom(): %s", strerror(errno));
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
338 return 1;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
339 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
340 for (i = 0; i < strlen(ibuf); i++) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
341 if (ibuf[i] == '\n')
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
342 ibuf[i] = '\0';
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
343 if (ibuf[i] == '\r')
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
344 ibuf[i] = '\0';
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 for (i = strlen(ibuf) -1; i > 0; i--) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
347 if (ibuf[i] == ' ')
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
348 ibuf[i] = '\0';
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
349 else
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
350 break;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
351 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
352 if (strlen(ibuf)) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
353 if (debug) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
354 syslog(LOG_NOTICE, "recv: \"%s\"", ibuf);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
355 fprintf(stdout, "recv: \"%s\"\n", ibuf);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
356 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
357 if (strcmp(ibuf, (char *)".") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
358 srv_send((char *)"219 Accepted Device record");
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
359 return 0;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
360 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
361 kwd = strtok(ibuf, ",\0");
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
362 val = strtok(NULL, "\0");
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
363 if (kwd && val) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
364 if (strcmp(kwd, (char *)"TYPE") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
365 for (i = 0; i < 7; i++) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
366 if (strcmp(val, DEVTYPE[i]) == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
367 device->type = i;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
368 break;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
369 }
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
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
372 } else if (strcmp(kwd, (char *)"DIRECTION") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
373 for (i = 0; i < 7; i++) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
374 if (strcmp(val, DEVDIR[i]) == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
375 device->direction = i;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
376 break;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
377 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
378 }
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 } else if (strcmp(kwd, (char *)"VALUE") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
381 if (sscanf(val, "%d", &ival) == 1)
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
382 device->value = ival;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
383
209
c5b1dfd83e81 Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents: 208
diff changeset
384 } else if (strcmp(kwd, (char *)"OFFSET") == 0) {
c5b1dfd83e81 Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents: 208
diff changeset
385 if (sscanf(val, "%d", &ival) == 1)
c5b1dfd83e81 Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents: 208
diff changeset
386 device->offset = ival;
c5b1dfd83e81 Added offset value for sensor that need it
Michiel Broek <mbroek@mbse.eu>
parents: 208
diff changeset
387
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
388 } else if (strcmp(kwd, (char *)"PRESENT") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
389 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
390 if (strcmp(val, DEVPRESENT[i]) == 0) {
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
391 device->present = i;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
392 break;
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
393 }
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
394 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
395
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
396 } else if (strcmp(kwd, (char *)"ADDRESS") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
397 if (device->address)
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
398 free(device->address);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
399 device->address = xstrcpy(val);
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 } else if (strcmp(kwd, (char *)"SUBDEVICE") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
402 if (sscanf(val, "%d", &ival) == 1)
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
403 device->subdevice = ival;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
404
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
405 } else if (strcmp(kwd, (char *)"GPIOPIN") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
406 if (sscanf(val, "%d", &ival) == 1)
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
407 device->gpiopin = ival;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
408
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
409 } else if (strcmp(kwd, (char *)"DESCRIPTION") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
410 if (device->description)
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
411 free(device->description);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
412 device->description = xstrcpy(val);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
413
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
414 } else if (strcmp(kwd, (char *)"COMMENT") == 0) {
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
415 if (device->comment)
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
416 free(device->comment);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
417 device->comment = xstrcpy(val);
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
418
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
419 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
420 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
421 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
422 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
423 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
424 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
425 srv_send((char *)"440 No such device");
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
426 return 1;
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
427 }
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
428
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
429 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
430 return 1;
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
431 }
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
432
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
433
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
434
259a018758f9 Added GET AIR, GET BEER, GET TARGET commands
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
435 /*
206
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
436 * GLOBAL GET
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
437 * GLOBAL PUT
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
438 */
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
439 int cmd_global(char *buf)
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
440 {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
441 char *opt, *kwd, *val, ibuf[SS_BUFSIZE];
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
442 int ival, i, rlen;
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
443 socklen_t fromlen;
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
444
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
445 opt = strtok(buf, " \0");
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
446 opt = strtok(NULL, "\0");
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
447
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
448 if (opt == NULL) {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
449 srv_send((char *)"501 Subcommand missing");
206
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
450 return 1;
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
451 }
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
452
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
453 if (strcmp(opt, (char *)"GET") == 0) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
454 srv_send((char *)"213 Global Settings record follows:");
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
455 srv_send((char *)"NAME,%s", Config.name);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
456 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
457 srv_send((char *)"TEMPFORMAT,%c", Config.tempFormat);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
458 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
459 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
460 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
461 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
462 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
463 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
464 #ifdef HAVE_WIRINGPI_H
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
465 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
466 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
467 #endif
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
468 srv_send((char *)".");
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
469 return 1;
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
470 }
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
471
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
472 if (strcmp(opt, (char *)"PUT") == 0) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
473 while (1) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
474 memset((char *)&ibuf, 0, SS_BUFSIZE);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
475 fromlen = sizeof(peeraddr_in);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
476 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
477 if (rlen == -1) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
478 syslog(LOG_NOTICE, "recvfrom(): %s", strerror(errno));
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
479 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
480 return 1;
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
481 }
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
482 for (i = 0; i < strlen(ibuf); i++) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
483 if (ibuf[i] == '\n')
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
484 ibuf[i] = '\0';
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
485 if (ibuf[i] == '\r')
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
486 ibuf[i] = '\0';
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
487 }
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
488 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
489 if (ibuf[i] == ' ')
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
490 ibuf[i] = '\0';
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
491 else
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
492 break;
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 (strlen(ibuf)) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
495 if (debug) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
496 syslog(LOG_NOTICE, "recv: \"%s\"", ibuf);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
497 fprintf(stdout, "recv: \"%s\"\n", ibuf);
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(ibuf, (char *)".") == 0) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
500 srv_send((char *)"219 Accepted Global record");
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
501 return 0;
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
502 }
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
503 kwd = strtok(ibuf, ",\0");
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
504 val = strtok(NULL, "\0");
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
505 if (kwd) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
506 if (strcmp(kwd, (char *)"NAME") == 0) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
507 if (Config.name)
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
508 free(Config.name);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
509 if (val)
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
510 Config.name = xstrcpy(val);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
511 else
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
512 Config.name = NULL;
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
513
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
514 } else if (val && (strcmp(kwd, (char *)"PORT") == 0)) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
515 if (sscanf(val, "%d", &ival) == 1)
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
516 Config.my_port = ival;
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 } else if (val && (strcmp(kwd, (char *)"TEMPFORMAT") == 0)) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
519 if ((val[0] == 'C') || (val[0] == 'F'))
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
520 Config.tempFormat = val[0];
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
521
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
522 } else if (strcmp(kwd, (char *)"TEMP_ADDRESS") == 0) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
523 if (Config.temp_address) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
524 device_count(FALSE, Config.temp_address);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
525 free(Config.temp_address);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
526 }
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
527 if (val) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
528 Config.temp_address = xstrcpy(val);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
529 device_count(TRUE, Config.temp_address);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
530 } else
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
531 Config.temp_address = NULL;
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
532
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
533 } else if (strcmp(kwd, (char *)"HUM_ADDRESS") == 0) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
534 if (Config.hum_address) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
535 device_count(FALSE, Config.hum_address);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
536 free(Config.hum_address);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
537 }
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
538 if (val) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
539 Config.hum_address = xstrcpy(val);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
540 device_count(TRUE, Config.hum_address);
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
541 } else
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
542 Config.hum_address = NULL;
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
543
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
544 #ifdef HAVE_WIRINGPI_H
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
545 } else if (val && (strcmp(kwd, (char *)"LCD_COLS") == 0)) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
546 if (sscanf(val, "%d", &ival) == 1)
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
547 Config.lcd_cols = ival;
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
548
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
549 } else if (val && (strcmp(kwd, (char *)"LCD_ROWS") == 0)) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
550 if (sscanf(val, "%d", &ival) == 1)
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
551 Config.lcd_rows = ival;
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
552 #endif
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
553 }
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
554 }
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
555 }
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
556 }
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
557 }
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
558
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
559 srv_send((char *)"504 Subcommand error");
206
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
560 return 1;
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
561 }
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
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
564
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
565 /*
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
566 * LIST
120
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
567 * LIST LOG
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
568 */
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
569 int cmd_list(char *buf)
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
570 {
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
571 char *opt, *param, *filename, *p, q[2], buffer[256];
84
ef4c0032b51f Can list the 1-wire bus
Michiel Broek <mbroek@mbse.eu>
parents: 81
diff changeset
572 units_list *unit;
120
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
573 FILE *fp;
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
574
87
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
575 opt = strtok(buf, " \0");
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
576 opt = strtok(NULL, " \0");
84
ef4c0032b51f Can list the 1-wire bus
Michiel Broek <mbroek@mbse.eu>
parents: 81
diff changeset
577
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
578 if (opt == NULL) {
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
579 /*
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
580 * Default, list available units
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
581 */
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
582 srv_send((char *)"212 Fermenter list follows:");
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
583 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
584 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
585 }
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
586 srv_send((char *)".");
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
587 return 0;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
588
120
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
589 } 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
590
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
591 param = strtok(NULL, "\0");
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
592 if (param == NULL) {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
593 srv_send((char *)"502 Parameter missing");
120
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
594 return 1;
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
595 }
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
596
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
597 q[0] = q[1] = 'a';
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
598 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
599 if (strcmp(param, unit->uuid) == 0)
120
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
600 break;
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
601 }
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
602
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
603 srv_send((char *)"212 Logfile list follows:");
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
604 if (getenv((char *)"USER") == NULL) {
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
605 filename = xstrcpy((char *)"/root");
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
606 } else {
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
607 filename = xstrcpy(getenv((char *)"HOME"));
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
608 }
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
609 filename = xstrcat(filename, (char *)"/.thermferm/log/");
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
610 filename = xstrcat(filename, unit->name);
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
611 filename = xstrcat(filename, (char *)".log");
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
612 if ((fp = fopen(filename, "r"))) {
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
613 while (fgets(buffer, sizeof(buffer)-1, fp) != NULL) {
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
614 buffer[strlen(buffer) -1] = '\0';
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
615 p = buffer + 17;
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
616 if (strncmp(p, (char *)"Mode", 4)) {
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
617 if ((q[0] != buffer[11]) || (q[1] != buffer[12])) {
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
618 q[0] = buffer[11];
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
619 q[1] = buffer[12];
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
620 srv_send(buffer);
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
621 }
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
622 }
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
623 }
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
624 }
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
625 free(filename);
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
626 filename = NULL;
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
627 srv_send((char *)".");
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
628 return 0;
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
629 }
120
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
630
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
631 srv_send((char *)"504 Subcommand error");
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
632 return 1;
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
633 }
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
634
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
635
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
636
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
637 /*
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
638 * PROFILE ADD name Add a new profile
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
639 * PROFILE DEL uuid Delete profile with uuid
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
640 * PROFILE LIST List available profiles
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
641 * PROFILE GETS uuid Get profile steps list
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
642 * PROFILE PUTS uuid Put profile steps list
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
643 */
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
644 int cmd_profile(char *buf)
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
645 {
192
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
646 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
647 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
648 float ftarg, fval;
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
649 socklen_t fromlen;
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
650 char *opt;
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
651 profiles_list *profile, *tmpp;
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
652 prof_step *step, *olds;
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
653 uuid_t uu;
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
654
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
655 opt = strtok(buf, " \0");
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
656 opt = strtok(NULL, " \0");
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
657
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
658 if (opt == NULL) {
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
659 srv_send((char *)"501 Subcommand missing");
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
660 return 1;
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
661 }
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
662
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
663 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
664 /*
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
665 * Fermenting profiles
86
3d7a241329e2 Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents: 85
diff changeset
666 */
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
667 srv_send((char *)"212 Profiles list follows:");
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
668 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
669 j = 0;
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
670 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
671 j++;
136
264e5ee5abfc Profiles now have a busy state
Michiel Broek <mbroek@mbse.eu>
parents: 133
diff changeset
672 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
673 }
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
674 srv_send((char *)".");
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
675 return 1;
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
676 }
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
677
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
678 param = strtok(NULL, "\0");
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
679 if (param == NULL) {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
680 srv_send((char *)"502 Parameter missing");
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
681 return 1;
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
682 }
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
683
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
684 if (strcmp(opt, (char *)"ADD") == 0) {
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
685 profile = (profiles_list *)malloc(sizeof(profiles_list));
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
686 profile->next = NULL;
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
687 profile->version = 1;
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
688 profile->uuid = malloc(37);
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
689 uuid_generate(uu);
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
690 uuid_unparse(uu, profile->uuid);
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
691 profile->name = xstrcpy(param);
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
692 profile->busy = 0;
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
693 profile->inittemp = 20.0;
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
694 profile->steps = NULL;
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
695 if (Config.profiles == NULL) {
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
696 Config.profiles = profile;
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
697 } else {
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
698 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
699 if (tmpp->next == NULL) {
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
700 tmpp->next = profile;
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
701 break;
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
702 }
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
703 }
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
704 }
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
705
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
706 syslog(LOG_NOTICE, "Profile %s added", profile->uuid);
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
707 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
708 return 0;
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
709
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
710
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
711 } else if (strcmp(opt, (char *)"DEL") == 0) {
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
712 if (delete_Profile(param)) {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
713 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
714 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
715 return 0;
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
716 } else {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
717 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
718 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
719 }
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
720
192
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
721 } 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
722 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
723 if (strcmp(profile->uuid, param) == 0) {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
724 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
725 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
726 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
727 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
728 srv_send((char *)".");
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
729 return 1;
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
730 }
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
731 }
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
732 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
733 return 1;
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
734
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
735 } 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
736 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
737 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
738 while (1) {
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
739 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
740 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
741 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
742 if (rlen == -1) {
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
743 syslog(LOG_NOTICE, "recvfrom(): %s", strerror(errno));
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
744 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
745 return 1;
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
746 }
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
747 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
748 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
749 ibuf[i] = '\0';
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
750 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
751 ibuf[i] = '\0';
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
752 }
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
753 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
754 if (ibuf[i] == ' ')
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
755 ibuf[i] = '\0';
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
756 else
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
757 break;
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
758 }
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
759 if (strlen(ibuf)) {
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
760 if (debug) {
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
761 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
762 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
763 }
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
764 if (strcmp(ibuf, (char *)".") == 0) {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
765 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
766 return 0;
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
767 }
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
768 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
769 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
770 if (kwd && val) {
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
771 if (strcmp(kwd, (char *)"NAME") == 0) {
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
772 if (profile->name)
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
773 free(profile->name);
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
774 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
775 } else if (strcmp(kwd, (char *)"INITTEMP") == 0) {
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
776 if (sscanf(val, "%f", &fval) == 1)
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
777 profile->inittemp = fval;
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
778 }
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
779 }
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
780 }
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
781 }
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
782 }
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
783 }
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
784 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
785 return 1;
5d013b4a9138 Added PROFILE GET and PROFILE PUT commands. Adjusted the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 191
diff changeset
786
140
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
787 } else if (strcmp(opt, (char *)"GETS") == 0) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
788
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
789 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
790 if (strcmp(profile->uuid, param) == 0) {
140
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
791 srv_send((char *)"215 Profile steps follow:");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
792 for (step = profile->steps; step; step = step->next) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
793 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
794 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
795 srv_send((char *)".");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
796 return 1;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
797 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
798 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
799
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
800 srv_send((char *)"440 No such profile");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
801 return 1;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
802
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
803 } else if (strcmp(opt, (char *)"PUTS") == 0) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
804
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
805 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
806 if (strcmp(profile->uuid, param) == 0) {
140
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
807
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
808 if (profile->steps) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
809 for (step = profile->steps; step; step = olds) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
810 olds = step->next;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
811 free(step);
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
812 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
813 profile->steps = NULL;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
814 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
815
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
816 while (1) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
817 memset((char *)&ibuf, 0, SS_BUFSIZE);
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
818 fromlen = sizeof(peeraddr_in);
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
819 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
820 if (rlen == -1) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
821 syslog(LOG_NOTICE, "recvfrom(): %s", strerror(errno));
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
822 srv_send((char *)"518 recfrom(): %s", strerror(errno));
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
823 return 1;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
824 } else {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
825 for (i = 0; i < strlen(ibuf); i++) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
826 if (ibuf[i] == '\n')
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
827 ibuf[i] = '\0';
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
828 if (ibuf[i] == '\r')
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
829 ibuf[i] = '\0';
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
830 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
831 for (i = strlen(ibuf) -1; i > 0; i--) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
832 if (ibuf[i] == ' ')
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
833 ibuf[i] = '\0';
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
834 else
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
835 break;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
836 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
837 if (strlen(ibuf)) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
838 if (debug) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
839 syslog(LOG_NOTICE, "recv: \"%s\"", ibuf);
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
840 fprintf(stdout, "recv: \"%s\"\n", ibuf);
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
841 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
842 if (strcmp(ibuf, (char *)".") == 0) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
843
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
844 srv_send((char *)"219 Accepted Profile steps");
140
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
845 return 0;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
846 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
847 sstep = strtok(ibuf, ",\0");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
848 rest = strtok(NULL, ",\0");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
849 targ = strtok(NULL, "\0");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
850
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
851 if ((sscanf(sstep, "%d", &istep) == 1) &&
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
852 (sscanf(rest, "%d", &irest) == 1) &&
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
853 (sscanf(targ, "%f", &ftarg) == 1)) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
854
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
855 step = (prof_step *)malloc(sizeof(prof_step));
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
856 step->next = NULL;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
857 step->version = 1;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
858 step->steptime = istep;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
859 step->resttime = irest;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
860 step->target = ftarg;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
861
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
862 if (profile->steps == NULL) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
863 profile->steps = step;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
864 } else {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
865 for (olds = profile->steps; olds; olds = olds->next) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
866 if (olds->next == NULL) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
867 olds->next = step;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
868 break;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
869 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
870 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
871 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
872 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
873 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
874 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
875 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
876 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
877 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
878
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
879 srv_send((char *)"440 No such profile");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
880 return 1;
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
881 }
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
882
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
883 srv_send((char *)"504 Subcommand error");
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
884 return 1;
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
885 }
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
886
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
887
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
888
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
889 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
890 {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
891 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
892 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
893
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
894 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
895 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
896 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
897 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
898 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
899 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
900 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
901 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
902 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
903 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
904 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
905 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
906 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
907 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
908 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
909 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
910 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
911 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
912 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
913 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
914 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
915 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
916 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
917 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
918 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
919 current->door_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
920 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
921 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
922 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
923 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
924 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
925 } 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
926 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
927 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
928 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
929 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
930 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
931 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
932 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
933 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
934 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
935 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
936 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
937 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
938 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
939 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
940 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
941 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
942 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
943 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
944 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
945 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
946 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
947 current->door_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
948 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
949 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
950 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
951 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
952 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
953 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
954 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
955 } 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
956 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
957 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
958 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
959 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
960 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
961 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
962
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
963
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
964
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
965 /*
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
966 * 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
967 * 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
968 * 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
969 * 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
970 * UNIT PUT uuid
87
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
971 */
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
972 int cmd_unit(char *buf)
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
973 {
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
974 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
975 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
976 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
977 socklen_t fromlen;
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
978 int ival, i, 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
979 float fval;
87
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
980
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
981 opt = strtok(buf, " \0");
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
982 opt = strtok(NULL, " \0");
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
983
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
984 if (opt == NULL) {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
985 srv_send((char *)"501 Subcommand missing");
87
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
986 return 1;
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
987 }
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
988 param = strtok(NULL, "\0");
87
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
989
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
990 if ((strcmp(opt, (char *)"LIST") == 0) && (param == NULL)) {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
991 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
992 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
993 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
994 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
995 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
996 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
997 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
998
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
999 if (param == NULL) {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
1000 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
1001 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
1002 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1003
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1004 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
1005 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
1006 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
1007 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
1008 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
1009 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
1010 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
1011 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
1012 unit->air_address = unit->beer_address = unit->heater_address = 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
1013 unit->fan_address = unit->door_address = unit->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
1014 unit->volume = 0.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
1015 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
1016 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
1017 unit->beer_set = unit->fridge_set = 20.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
1018 unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->mode = unit->prof_state = 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
1019 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
1020 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
1021 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
1022 unit->idle_rangeL = -1.0;
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 192
diff changeset
1023 unit->prof_started = unit->prof_paused = (time_t)0;
185
4f34271cf1e7 PID finetuning
Michiel Broek <mbroek@mbse.eu>
parents: 184
diff changeset
1024 unit->PID_err_old = unit->PID_I_err = 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
1025
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1026 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
1027 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
1028 } 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
1029 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
1030 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
1031 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
1032 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
1033 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1034 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1035 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1036
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
1037 syslog(LOG_NOTICE, "Unit %s added", unit->uuid);
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
1038 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
1039 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
1040 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1041
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1042 if (strcmp(opt, (char *)"DEL") == 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
1043 if (delete_Unit(param)) {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
1044 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
1045 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
1046 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
1047 } else {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
1048 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
1049 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
1050 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1051 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1052
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1053 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
1054 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
1055 if (strcmp(param, unit->uuid) == 0) {
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
1056 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
1057 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
1058 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
1059 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
1060 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
1061 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
1062 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
1063 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
1064 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
1065 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
1066 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
1067 srv_send((char *)"HEATER_STATE,%d", unit->heater_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
1068 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
1069 srv_send((char *)"COOLER_STATE,%d", unit->cooler_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
1070 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
1071 srv_send((char *)"FAN_STATE,%d", unit->fan_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
1072 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
1073 srv_send((char *)"DOOR_STATE,%d", unit->door_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
1074 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
1075 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
1076 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
1077 srv_send((char *)"PROFILE,%s", unit->profile);
217
2922d439ff63 Added profile state ABORT
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
1078 srv_send((char *)"PROF_STARTED,%d", (int)unit->prof_started);
2922d439ff63 Added profile state ABORT
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
1079 srv_send((char *)"PROF_STATE,%s", PROFSTATE[unit->prof_state]);
2922d439ff63 Added profile state ABORT
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
1080 srv_send((char *)"PROF_TARGET,%.3f", unit->prof_target);
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
1081 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
1082 srv_send((char *)"TEMP_SET_MAX,%.1f", unit->temp_set_max);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1083 srv_send((char *)"IDLE_RANGE_L,%.1f", unit->idle_rangeL);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1084 srv_send((char *)"IDLE_RANGE_H,%.1f", unit->idle_rangeH);
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1085 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
1086 return 1;
87
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1087 }
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1088 }
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
1089 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
1090 return 1;
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1091 }
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1092
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
1093 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
1094 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
1095 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
1096 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
1097 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
1098 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
1099 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
1100 if (rlen == -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
1101 syslog(LOG_NOTICE, "recvfrom(): %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
1102 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
1103 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
1104 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1105 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
1106 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
1107 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
1108 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
1109 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
1110 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1111 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
1112 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
1113 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
1114 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
1115 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
1116 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1117 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
1118 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
1119 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
1120 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
1121 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1122 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
1123 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
1124 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
1125 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1126 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
1127 val = strtok(NULL, "\0");
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1128 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
1129 /*
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1130 * 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
1131 * 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
1132 * 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
1133 */
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1134 if (val && (strcmp(kwd, (char *)"NAME") == 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
1135 if (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
1136 free(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
1137 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
1138
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1139 } else if (val && (strcmp(kwd, (char *)"VOLUME") == 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
1140 if (sscanf(val, "%f", &fval) == 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
1141 unit->volume = fval;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1142
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1143 } else if (strcmp(kwd, (char *)"AIR_ADDRESS") == 0) {
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1144 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
1145 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
1146 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
1147 }
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1148 if (val) {
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1149 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
1150 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
1151 } else
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1152 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
1153
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1154 } else if (strcmp(kwd, (char *)"BEER_ADDRESS") == 0) {
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1155 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
1156 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
1157 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
1158 }
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1159 if (val) {
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1160 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
1161 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
1162 } else
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1163 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
1164
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1165 } else if (strcmp(kwd, (char *)"HEATER_ADDRESS") == 0) {
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1166 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
1167 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
1168 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
1169 }
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1170 if (val) {
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1171 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
1172 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
1173 } else
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1174 unit->heater_address = NULL;
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1175
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1176 } else if (val && (strcmp(kwd, (char *)"HEATER_STATE") == 0)) {
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1177 if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100)))
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1178 unit->heater_state = ival;
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
1179
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1180 } else if (strcmp(kwd, (char *)"COOLER_ADDRESS") == 0) {
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1181 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
1182 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
1183 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
1184 }
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1185 if (val) {
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1186 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
1187 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
1188 } else
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1189 unit->cooler_address = NULL;
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1190
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1191 } else if (val && (strcmp(kwd, (char *)"COOLER_STATE") == 0)) {
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1192 if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100)))
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1193 unit->cooler_state = ival;
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
1194
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1195 } else if (strcmp(kwd, (char *)"FAN_ADDRESS") == 0) {
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1196 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
1197 device_count(FALSE, unit->fan_address);
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1198 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
1199 }
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1200 if (val) {
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1201 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
1202 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
1203 } else
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1204 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
1205
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1206 } else if (val && (strcmp(kwd, (char *)"FAN_STATE") == 0)) {
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1207 if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100)))
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1208 unit->fan_state = ival;
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1209
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
1210 } else if (strcmp(kwd, (char *)"DOOR_ADDRESS") == 0) {
179
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1211 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
1212 device_count(FALSE, unit->door_address);
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1213 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
1214 }
417ee898fb02 Added PID implementation and 433 MHz radio control switches. Not reliable yet.
Michiel Broek <mbroek@mbse.eu>
parents: 178
diff changeset
1215 if (val) {
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1216 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
1217 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
1218 } else
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1219 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
1220
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1221 } 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
1222 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
1223 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
1224 /* 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
1225 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
1226 initlog(unit->name);
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
1227 syslog(LOG_NOTICE, "Mode from %s to %s via web interface", 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
1228 unit->mode = i;
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1229 /* Allways turn everything off after a mode change */
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
1230 unit->PID_I_err = unit->PID_err_old = 0.0;
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1231 unit->heater_state = unit->cooler_state = unit->fan_state = 0;
184
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1232 device_out(unit->heater_address, unit->heater_state);
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1233 device_out(unit->cooler_address, unit->cooler_state);
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1234 device_out(unit->fan_address, unit->fan_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
1235 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
1236 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1237 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1238
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1239 } else if (val && (strcmp(kwd, (char *)"FRIDGE_SET") == 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
1240 if (sscanf(val, "%f", &fval) == 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
1241 unit->fridge_set = fval;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1242
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1243 } else if (val && (strcmp(kwd, (char *)"BEER_SET") == 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
1244 if (sscanf(val, "%f", &fval) == 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
1245 unit->beer_set = fval;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1246
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1247 } 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
1248 if (unit->prof_state == PROFILE_OFF) {
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1249 /*
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1250 * 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
1251 */
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1252 if (unit->profile)
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1253 free(unit->profile);
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1254 if (val)
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1255 unit->profile = xstrcpy(val);
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1256 else
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1257 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
1258 /*
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
1259 * 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
1260 */
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
1261 unit->PID_I_err = unit->PID_err_old = 0.0;
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
1262 unit->heater_state = unit->cooler_state = unit->fan_state = 0;
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
1263 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
1264 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
1265 device_out(unit->fan_address, unit->fan_state);
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1266 }
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
1267
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1268 } else if (val && (strcmp(kwd, (char *)"PROF_STATE") == 0)) {
217
2922d439ff63 Added profile state ABORT
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
1269 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
1270 if (strcmp(val, PROFSTATE[i]) == 0) {
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1271 switch (i) {
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1272 case PROFILE_OFF: if (unit->prof_state == PROFILE_DONE)
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1273 unit->prof_state = PROFILE_OFF;
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1274 break;
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1275 case PROFILE_PAUSE: if (unit->prof_state == PROFILE_RUN)
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1276 unit->prof_state = PROFILE_PAUSE;
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1277 else if (unit->prof_state == PROFILE_PAUSE)
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1278 unit->prof_state = PROFILE_RUN;
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1279 break;
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1280 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
1281 unit->prof_state = PROFILE_RUN;
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1282 unit->prof_started = time(NULL);
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1283 unit->prof_paused = 0;
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1284 }
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1285 break;
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1286 case PROFILE_DONE: break; /* Command is illegal */
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1287 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
1288 unit->prof_state = PROFILE_OFF;
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1289 unit->prof_started = 0;
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1290 }
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1291 break;
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 217
diff changeset
1292 }
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
1293 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
1294 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1295 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1296
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1297 } else if (val && (strcmp(kwd, (char *)"TEMP_SET_MIN") == 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
1298 if (sscanf(val, "%f", &fval) == 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
1299 unit->temp_set_min = fval;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1300
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1301 } else if (val && (strcmp(kwd, (char *)"TEMP_SET_MAX") == 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
1302 if (sscanf(val, "%f", &fval) == 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
1303 unit->temp_set_max = fval;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1304
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1305 } else if (val && (strcmp(kwd, (char *)"IDLE_RANGE_L") == 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
1306 if (sscanf(val, "%f", &fval) == 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
1307 unit->idle_rangeL = fval;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1308
178
988a898974f3 Web - server communication for switches improved.
Michiel Broek <mbroek@mbse.eu>
parents: 176
diff changeset
1309 } else if (val && (strcmp(kwd, (char *)"IDLE_RANGE_H") == 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
1310 if (sscanf(val, "%f", &fval) == 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
1311 unit->idle_rangeH = fval;
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1312
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1313 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1314 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1315 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1316 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1317 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1318 }
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
1319 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
1320 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
1321 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1322
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
1323
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
1324 srv_send((char *)"504 Subcommand error");
87
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1325 return 1;
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1326 }
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1327
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1328
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1329
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1330 void cmd_server(void)
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1331 {
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
1332 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
1333 int i, rlen;
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1334 socklen_t fromlen;
68
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1335 #ifdef HAVE_WIRINGPI_H
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1336 int j;
133
345307762220 Fixed compiling on systems with wiringpi libs
Michiel Broek <mbroek@mbse.eu>
parents: 132
diff changeset
1337 char obuf[SS_BUFSIZE];
68
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1338 #endif
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1339
48
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1340 memset((char *)&buf, 0, SS_BUFSIZE);
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1341 fromlen = sizeof(peeraddr_in);
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1342 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
1343 if (rlen == -1) {
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1344 syslog(LOG_NOTICE, "recvfrom(): %s", strerror(errno));
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1345 } else {
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1346 for (i = 0; i < strlen(buf); i++) {
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1347 if (buf[i] == '\n')
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1348 buf[i] = '\0';
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1349 if (buf[i] == '\r')
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1350 buf[i] = '\0';
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1351 }
80
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
1352 for (i = strlen(buf) -1; i > 0; i--) {
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
1353 if (buf[i] == ' ')
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
1354 buf[i] = '\0';
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
1355 else
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
1356 break;
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
1357 }
48
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1358 if (strlen(buf)) {
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1359 if (debug) {
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1360 syslog(LOG_NOTICE, "recv: \"%s\"", buf);
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1361 fprintf(stdout, "recv: \"%s\"\n", buf);
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1362 }
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1363
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1364 /*
48
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1365 * Process commands from the client
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1366 */
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1367 if (strncmp(buf, "DEVICE", 6) == 0) {
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
1368 if (cmd_device(buf) == 0)
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
1369 wrconfig();
206
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
1370 } else if (strncmp(buf, "GLOBAL", 6) == 0) {
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
1371 if (cmd_global(buf) == 0)
78fb6f99e473 Added GLOBAL GET and GLOBAL PUT commands.
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
1372 wrconfig();
80
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
1373 } 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
1374 srv_send((char *)"100 Help text follows");
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1375 srv_send((char *)"Recognized commands:");
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1376 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
1377 // 12345678901234567890123456789012345678901234567890123456789012345678901234567890
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
1378 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
1379 srv_send((char *)"DEVICE DEL uuid Delete Device by uuid");
174
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
1380 srv_send((char *)"DEVICE LIST List Devices");
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
1381 srv_send((char *)"DEVICE GET uuid Get Device record by uuid");
244de612c572 Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 170
diff changeset
1382 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
1383 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
1384 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
1385 srv_send((char *)"LCD Get LCD screen (allways 4 rows of 20 characters)");
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
1386 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
1387 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
1388 srv_send((char *)"PROFILE uuid,name Profile rename");
191
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1389 srv_send((char *)"PROFILE ADD name Add new profile with name");
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1390 srv_send((char *)"PROFILE DEL uuid Delete profile by uuid");
c74bbc24a1c8 Client/Server communication is now almost final
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1391 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
1392 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
1393 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
1394 srv_send((char *)"PROFILE GETS uuid Profile get steps list");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
1395 srv_send((char *)"PROFILE PUTS uuid Profile put steps list");
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
1396 srv_send((char *)"UNIT ADD name Add a new unit with 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
1397 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
1398 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
1399 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
1400 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
1401 srv_send((char *)".");
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1402 } else if (strncmp(buf, "LCD", 3) == 0) {
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1403 #ifdef HAVE_WIRINGPI_H
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
1404 srv_send((char *)"201 Information follows");
68
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1405 for (j = 0; j < 4; j++) {
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1406 sprintf(obuf, " ");
70
920eface3ec5 Small fix for LCD output
Michiel Broek <mbroek@mbse.eu>
parents: 68
diff changeset
1407 obuf[20] = '\0';
68
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1408 for (i = 0; i < 20; i++)
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1409 obuf[i] = lcdbuf[lcdHandle][i][j];
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1410 srv_send(obuf);
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1411 }
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1412 srv_send((char *)".");
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1413 #else
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1414 srv_send((char *)"403 LCD not available");
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
1415 #endif
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
1416 } else if (strncmp(buf, "LIST", 4) == 0) {
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
1417 cmd_list(buf);
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
1418 } 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
1419 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
1420 wrconfig();
87
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
1421 } 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
1422 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
1423 wrconfig();
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1424 } 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
1425 srv_send((char *)"500 Unknown command");
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1426 }
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1427 }
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1428 }
44
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1429
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1430 close(s);
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1431 }
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1432
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1433
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
1434
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 62
diff changeset
1435 #ifdef HAVE_WIRINGPI_H
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1436 PI_THREAD (my_server_loop)
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 62
diff changeset
1437 #else
74
879bd09e2b96 Reinstalled threads
Michiel Broek <mbroek@mbse.eu>
parents: 71
diff changeset
1438 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
1439 #endif
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1440 {
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1441 socklen_t addrlen;
44
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1442 int optval = 1;
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1443
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1444 syslog(LOG_NOTICE, "Thread my_server_loop started");
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1445 if (debug)
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1446 fprintf(stdout, "Thread my_server_loop started\n");
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1447
44
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1448 memset((char *)&myaddr_in, 0, sizeof(struct sockaddr_in));
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1449 memset((char *)&peeraddr_in, 0, sizeof(struct sockaddr_in));
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1450 myaddr_in.sin_family = AF_INET;
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1451 myaddr_in.sin_addr.s_addr = INADDR_ANY;
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1452 myaddr_in.sin_port = htons(Config.my_port);
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1453
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1454 ls = socket(AF_INET, SOCK_STREAM, 0);
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1455 if (ls == -1) {
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1456 syslog(LOG_NOTICE, "Can't create listen socket: %s", strerror(errno));
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1457 fprintf(stderr, "Can't create listen socket: %s\n", strerror(errno));
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1458 return 0;
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1459 }
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1460
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1461 if (setsockopt(ls, SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof(optval)) == -1) {
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1462 syslog(LOG_NOTICE, "Can't setsockopt SO_KEEPALIVE socket: %s", strerror(errno));
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1463 close(ls);
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1464 return 0;
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1465 }
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1466
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1467 if (setsockopt(ls, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) == -1) {
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1468 syslog(LOG_NOTICE, "Can't setsockopt SO_REUSEADDR socket: %s", strerror(errno));
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1469 close(ls);
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 62
diff changeset
1470 return 0;
44
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1471 }
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1472
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1473 if (bind(ls, (struct sockaddr *)&myaddr_in, sizeof(struct sockaddr_in)) == -1) {
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1474 syslog(LOG_NOTICE, "Can't bind to listen socket: %s", strerror(errno));
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1475 close(ls);
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 62
diff changeset
1476 return 0;
44
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1477 }
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1478
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1479 if (listen(ls, 5) == -1) {
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1480 syslog(LOG_NOTICE, "Can't listen on listen socket: %s", strerror(errno));
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1481 close(ls);
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 62
diff changeset
1482 return 0;
44
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1483 }
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1484
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1485 syslog(LOG_NOTICE, "listen socket created %d", ls);
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1486 if (debug)
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1487 fprintf(stdout, "listen socket created %d\n", ls);
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1488
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1489
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1490 /*
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1491 * Loop forever until the external shutdown variable is set.
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1492 */
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1493 for (;;) {
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1494
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1495 addrlen = sizeof(struct sockaddr_in);
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1496 /*
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1497 * This call will block until a new connection
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1498 * arrives. Then it will return the address of
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1499 * the connecting peer, and a new socket
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1500 * descriptor, s, for that connection.
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1501 */
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1502 s = accept(ls, (struct sockaddr *)&peeraddr_in, &addrlen);
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1503 if (s == -1) {
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1504 syslog(LOG_NOTICE, "my_server_loop accept failed %s", strerror(errno));
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1505 if (debug)
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1506 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
1507 return 0;
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1508 }
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1509
48
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1510 cmd_server();
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1511
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1512 if (my_shutdown) {
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1513 syslog(LOG_NOTICE, "Thread my_server_loop stopped");
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1514 if (debug)
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1515 fprintf(stdout, "Thread my_server_loop stopped\n");
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1516 return 0;
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1517 }
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1518
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1519 }
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1520 }
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1521
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1522

mercurial