thermferm/server.c

Sun, 27 Jul 2014 17:06:08 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 27 Jul 2014 17:06:08 +0200
changeset 140
1b001de37945
parent 138
e7e7a23af890
child 155
0d86f3c0a07b
permissions
-rw-r--r--

Implemented PROFILE PUTS command

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
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 * along with EC-65K; see the file COPYING. If not, write to the Free
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"
106
1bd9a16f5061 Added .h files
Michiel Broek <mbroek@mbse.eu>
parents: 101
diff changeset
25 #include "server.h"
1bd9a16f5061 Added .h files
Michiel Broek <mbroek@mbse.eu>
parents: 101
diff changeset
26 #include "xutil.h"
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27
58
e8e7b46b705b Fixed compilation without wiringpi
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
28
75
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 74
diff changeset
29 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
30 extern int debug;
131
528dc0bb81ab Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents: 125
diff changeset
31 extern char *current_unit;
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 62
diff changeset
32 #ifdef HAVE_WIRINGPI_H
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33 extern int lcdHandle;
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34 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
35 #endif
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
36 extern sys_config Config;
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
37 extern const char UNITMODE[5][8];
95
2c28afc329a5 Removed old brewPi settings
Michiel Broek <mbroek@mbse.eu>
parents: 92
diff changeset
38 extern const char UNITmode[5];
101
1302abe92eb1 Made temperature sensors working in the units
Michiel Broek <mbroek@mbse.eu>
parents: 100
diff changeset
39 extern const char TEMPSTATE[3][8];
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
41 int s; /* connected socket */
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
42 int ls; /* listen socket */
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
44 struct sockaddr_in myaddr_in; /* for local socket address */
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
45 struct sockaddr_in peeraddr_in; /* for peer socket address */
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
46
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
47 struct hostent *hp;
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
48
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
49 #define SS_BUFSIZE 1024
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
50 #define SS_TIMEOUT 300
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51
48
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
52
95
2c28afc329a5 Removed old brewPi settings
Michiel Broek <mbroek@mbse.eu>
parents: 92
diff changeset
53 float cs_heatEstimator = 0.2;
2c28afc329a5 Removed old brewPi settings
Michiel Broek <mbroek@mbse.eu>
parents: 92
diff changeset
54 float cs_coolEstimator = 5;
48
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
55 float cv_beerDiff = 0.0;
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
56
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57
46
000399c64d3f More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents: 45
diff changeset
58
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
59 /*
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
60 * Send message to client
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
61 */
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
62 int srv_send(const char *format, ...)
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
63 {
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
64 char out[SS_BUFSIZE];
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
65 va_list va_ptr;
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
66
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
67 if (s == -1)
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
68 return -1;
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
70 va_start(va_ptr, format);
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
71 vsnprintf(out, SS_BUFSIZE-1, format, va_ptr);
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
72 va_end(va_ptr);
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
73
48
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
74 if (debug) {
80
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
75 syslog(LOG_NOTICE, "send: \"%s\"", out);
45
053c4657105f Mirror LCD display on the webpage works
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
76 fprintf(stdout, "send: \"%s\"\n", out);
48
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
77 }
44
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
78
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
79 if (send(s, out, strlen(out), 0) != strlen(out)) {
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
80 syslog(LOG_NOTICE, "srv_send failed");
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
81 return -1;
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
82 }
80
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
83
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
84 if (send(s, (char *)"\r\n", 2, 0) != 2) {
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
85 syslog(LOG_NOTICE, "srv_send failed");
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
86 return -1;
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
87 }
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 return 0;
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
90 }
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
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
93
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
94 /*
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
95 * ADD PROFILE name
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
96 * ADD UNIT name
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
97 */
80
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
98 int unit_add(char *buf)
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
99 {
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
100 units_list *unit, *tmpu;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
101 profiles_list *profile, *tmpp;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
102 uuid_t uu;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
103 char *opt, *param;
80
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
104
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
105 opt = strtok(buf, " \0");
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
106 opt = strtok(NULL, " \0");
80
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
107 if (opt == NULL) {
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
108 srv_send((char *)"501 Subcommand missing");
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
109 return 1;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
110 }
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
111
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
112 param = strtok(NULL, "\0");
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
113 if (param == NULL) {
80
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
114 srv_send((char *)"501 Parameter missing");
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
115 return 1;
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
116 }
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
117
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
118 if (debug)
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
119 fprintf(stdout, "opt: '%s' param: '%s'\n", MBSE_SS(opt), MBSE_SS(param));
80
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
120
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
121 if (strcmp(opt, (char *)"PROFILE") == 0) {
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
122 profile = (profiles_list *)malloc(sizeof(profiles_list));
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
123 profile->next = NULL;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
124 profile->version = 1;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
125 profile->uuid = malloc(37);
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
126 uuid_generate(uu);
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
127 uuid_unparse(uu, profile->uuid);
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
128 profile->name = xstrcpy(param);
138
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
129 profile->busy = 0;
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
130 profile->steps = NULL;
80
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
131
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
132 if (Config.profiles == NULL) {
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
133 Config.profiles = profile;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
134 } else {
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
135 for (tmpp = Config.profiles; tmpp; tmpp = tmpp->next) {
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
136 if (tmpp->next == NULL) {
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
137 tmpp->next = profile;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
138 break;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
139 }
80
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
140 }
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
141 }
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
142
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
143 syslog(LOG_NOTICE, "Profile \"%s\" with uuid %s added", param, profile->uuid);
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
144 srv_send((char *)"211 Profile \"%s\" with uuid %s added", param, profile->uuid);
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
145 return 0;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
146
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
147 } else if (strcmp(opt, (char *)"UNIT") == 0) {
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
148 unit = (units_list *)malloc(sizeof(units_list));
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
149 unit->next = NULL;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
150 unit->version = 1;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
151 unit->uuid = malloc(37);
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
152 uuid_generate(uu);
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
153 uuid_unparse(uu, unit->uuid);
131
528dc0bb81ab Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents: 125
diff changeset
154 if (current_unit)
528dc0bb81ab Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents: 125
diff changeset
155 free(current_unit);
528dc0bb81ab Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents: 125
diff changeset
156 current_unit = xstrcpy(unit->uuid);
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
157 unit->name = xstrcpy(param);
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
158 unit->air_address = unit->beer_address = unit->io1_address = unit->io2_address = unit->profile = NULL;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
159 unit->volume = 0.0;
101
1302abe92eb1 Made temperature sensors working in the units
Michiel Broek <mbroek@mbse.eu>
parents: 100
diff changeset
160 unit->air_state = unit->beer_state = 1;
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
161 unit->heater_available = unit->cooler_available = unit->fan_available = FALSE;
101
1302abe92eb1 Made temperature sensors working in the units
Michiel Broek <mbroek@mbse.eu>
parents: 100
diff changeset
162 unit->air_temperature = unit->beer_temperature = 20000;
1302abe92eb1 Made temperature sensors working in the units
Michiel Broek <mbroek@mbse.eu>
parents: 100
diff changeset
163 unit->beer_set = unit->fridge_set = 20.0;
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
164 unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->mode = unit->prof_state = 0;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
165 unit->temp_set_min = 1.0;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
166 unit->temp_set_max = 30.0;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
167 unit->idle_rangeH = 1.0;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
168 unit->idle_rangeL = -1.0;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
169 unit->prof_started = (time_t)0;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
170
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
171 if (Config.units == NULL) {
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
172 Config.units = unit;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
173 } else {
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
174 for (tmpu = Config.units; tmpu; tmpu = tmpu->next) {
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
175 if (tmpu->next == NULL) {
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
176 tmpu->next = unit;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
177 break;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
178 }
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
179 }
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
180 }
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
181
131
528dc0bb81ab Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents: 125
diff changeset
182 syslog(LOG_NOTICE, "Unit with uuid %s added", unit->uuid);
528dc0bb81ab Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents: 125
diff changeset
183 srv_send((char *)"211 Unit with uuid %s added", unit->uuid);
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
184 return 0;
80
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
185 }
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
186
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
187 srv_send((char *)"502 Unknown command option");
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
188 return 1;
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
189 }
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
190
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
191
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
192
138
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
193
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
194 void delete_Profile(char *uuid)
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
195 {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
196 profiles_list *current = Config.profiles;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
197 profiles_list *previous = NULL;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
198 prof_step *step, *olds;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
199
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
200
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
201 while (current) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
202 if (strcmp(current->uuid, uuid) == 0) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
203 if (previous == NULL) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
204 Config.profiles = current->next;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
205 free(current->uuid);
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
206 current->uuid = NULL;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
207 free(current->name);
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
208 current->name = NULL;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
209 if (current->steps) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
210 for (step = current->steps; step; step = olds) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
211 olds = step->next;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
212 free(step);
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
213 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
214 current->steps = NULL;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
215 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
216 free(current);
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
217 return;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
218 } else {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
219 free(current->uuid);
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
220 current->uuid = NULL;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
221 free(current->name);
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
222 current->name = NULL;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
223 if (current->steps) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
224 for (step = current->steps; step; step = olds) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
225 olds = step->next;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
226 free(step);
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
227 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
228 current->steps = NULL;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
229 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
230 previous->next = current->next;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
231 free(current);
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
232 current = previous->next;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
233 return;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
234 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
235 } else {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
236 previous = current;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
237 current = current->next;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
238 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
239 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
240 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
241
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
242
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
243
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
244 /*
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
245 * DEL PROFILE
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
246 */
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
247 int cmd_del(char *buf)
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
248 {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
249 char *opt, *param;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
250
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
251 opt = strtok(buf, " \0");
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
252 opt = strtok(NULL, " \0");
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
253 if (opt == NULL) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
254 srv_send((char *)"501 Subcommand missing");
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
255 return 1;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
256 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
257
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
258 param = strtok(NULL, "\0");
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
259 if (param == NULL) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
260 srv_send((char *)"501 Parameter missing");
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
261 return 1;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
262 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
263
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
264 if (debug)
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
265 fprintf(stdout, "opt: '%s' param: '%s'\n", MBSE_SS(opt), MBSE_SS(param));
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
266
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
267 if (strcmp(opt, (char *)"PROFILE") == 0) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
268 delete_Profile(param);
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
269 srv_send((char *)"211 Profile %s deleted", param);
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
270 return 0;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
271 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
272
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
273 srv_send((char *)"502 Unknown command option");
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
274 return 1;
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
275 }
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
276
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
277
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
278
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
279 /*
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
280 * LIST
84
ef4c0032b51f Can list the 1-wire bus
Michiel Broek <mbroek@mbse.eu>
parents: 81
diff changeset
281 * LIST BUS
120
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
282 * LIST LOG
84
ef4c0032b51f Can list the 1-wire bus
Michiel Broek <mbroek@mbse.eu>
parents: 81
diff changeset
283 * LIST PROFILES
ef4c0032b51f Can list the 1-wire bus
Michiel Broek <mbroek@mbse.eu>
parents: 81
diff changeset
284 * LIST UNIT
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
285 */
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
286 int cmd_list(char *buf)
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
287 {
120
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
288 char *opt, *filename, *p, q[2], buffer[256];
84
ef4c0032b51f Can list the 1-wire bus
Michiel Broek <mbroek@mbse.eu>
parents: 81
diff changeset
289 units_list *unit;
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
290 profiles_list *profile;
124
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
291 prof_step *step;
131
528dc0bb81ab Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents: 125
diff changeset
292 int j, ref;
84
ef4c0032b51f Can list the 1-wire bus
Michiel Broek <mbroek@mbse.eu>
parents: 81
diff changeset
293 DIR *fd;
120
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
294 FILE *fp;
84
ef4c0032b51f Can list the 1-wire bus
Michiel Broek <mbroek@mbse.eu>
parents: 81
diff changeset
295 struct dirent *de;
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
296
87
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
297 opt = strtok(buf, " \0");
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
298 opt = strtok(NULL, "\0");
84
ef4c0032b51f Can list the 1-wire bus
Michiel Broek <mbroek@mbse.eu>
parents: 81
diff changeset
299
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
300 if (opt == NULL) {
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
301 /*
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
302 * Default, list available units
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
303 */
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
304 srv_send((char *)"212 Fermenter list follows:");
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
305 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
306 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
307 }
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
308 srv_send((char *)".");
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
309 return 0;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
310
84
ef4c0032b51f Can list the 1-wire bus
Michiel Broek <mbroek@mbse.eu>
parents: 81
diff changeset
311 } else if (strcmp(opt, (char *)"BUS") == 0) {
86
3d7a241329e2 Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents: 85
diff changeset
312 /*
3d7a241329e2 Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents: 85
diff changeset
313 * 1-wire bus
3d7a241329e2 Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents: 85
diff changeset
314 */
84
ef4c0032b51f Can list the 1-wire bus
Michiel Broek <mbroek@mbse.eu>
parents: 81
diff changeset
315 if ((fd = opendir((char *)"/sys/bus/w1/devices"))) {
86
3d7a241329e2 Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents: 85
diff changeset
316 srv_send((char *)"212 1-wire bus devices:");
3d7a241329e2 Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents: 85
diff changeset
317 while ((de = readdir(fd))) {
3d7a241329e2 Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents: 85
diff changeset
318 if (de->d_name[0] != '.') {
124
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
319 ref = 0;
86
3d7a241329e2 Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents: 85
diff changeset
320 if (strncmp(de->d_name, (char *)"w1", 2) == 0) {
124
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
321 srv_send((char *)"%s,0,NA,System device", de->d_name);
86
3d7a241329e2 Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents: 85
diff changeset
322 } else if (strncmp(de->d_name, (char *)"10", 2) == 0) {
125
94aea38d4da5 Fixed LIST BUS output
Michiel Broek <mbroek@mbse.eu>
parents: 124
diff changeset
323 if (Config.air_address && (strcmp(de->d_name, Config.air_address) == 0))
124
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
324 ref++;
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
325 for (unit = Config.units; unit; unit = unit->next) {
125
94aea38d4da5 Fixed LIST BUS output
Michiel Broek <mbroek@mbse.eu>
parents: 124
diff changeset
326 if (unit->air_address && (strcmp(de->d_name, unit->air_address) == 0))
124
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
327 ref++;
125
94aea38d4da5 Fixed LIST BUS output
Michiel Broek <mbroek@mbse.eu>
parents: 124
diff changeset
328 if (unit->beer_address && (strcmp(de->d_name, unit->beer_address) == 0))
124
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
329 ref++;
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
330 }
125
94aea38d4da5 Fixed LIST BUS output
Michiel Broek <mbroek@mbse.eu>
parents: 124
diff changeset
331 srv_send((char *)"%s,%d,18S20,Digital thermometer", de->d_name, ref);
86
3d7a241329e2 Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents: 85
diff changeset
332 } else if (strncmp(de->d_name, (char *)"28", 2) == 0) {
125
94aea38d4da5 Fixed LIST BUS output
Michiel Broek <mbroek@mbse.eu>
parents: 124
diff changeset
333 if (Config.air_address && (strcmp(de->d_name, Config.air_address) == 0))
124
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
334 ref++;
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
335 for (unit = Config.units; unit; unit = unit->next) {
125
94aea38d4da5 Fixed LIST BUS output
Michiel Broek <mbroek@mbse.eu>
parents: 124
diff changeset
336 if (unit->air_address && (strcmp(de->d_name, unit->air_address) == 0))
124
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
337 ref++;
125
94aea38d4da5 Fixed LIST BUS output
Michiel Broek <mbroek@mbse.eu>
parents: 124
diff changeset
338 if (unit->beer_address && (strcmp(de->d_name, unit->beer_address) == 0))
124
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
339 ref++;
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
340 }
125
94aea38d4da5 Fixed LIST BUS output
Michiel Broek <mbroek@mbse.eu>
parents: 124
diff changeset
341 srv_send((char *)"%s,%d,18B20,Digital thermometer", de->d_name, ref);
86
3d7a241329e2 Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents: 85
diff changeset
342 } else if (strncmp(de->d_name, (char *)"29", 2) == 0) {
124
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
343 for (unit = Config.units; unit; unit = unit->next) {
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
344 if (unit->io1_address && (strncmp((char *)"29", unit->io1_address, 2) == 0))
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
345 ref++;
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
346 if (unit->io2_address && (strncmp((char *)"29", unit->io2_address, 2) == 0))
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
347 ref++;
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
348 }
125
94aea38d4da5 Fixed LIST BUS output
Michiel Broek <mbroek@mbse.eu>
parents: 124
diff changeset
349 srv_send((char *)"%s,%d,2408,8 Channel addressable switch/LCD", de->d_name, ref);
86
3d7a241329e2 Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents: 85
diff changeset
350 } else if (strncmp(de->d_name, (char *)"3a", 2) == 0) {
124
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
351 for (unit = Config.units; unit; unit = unit->next) {
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
352 if (unit->io1_address && (strncmp((char *)"3a", unit->io1_address, 2) == 0))
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
353 ref++;
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
354 if (unit->io2_address && (strncmp((char *)"3a", unit->io2_address, 2) == 0))
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
355 ref++;
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
356 }
125
94aea38d4da5 Fixed LIST BUS output
Michiel Broek <mbroek@mbse.eu>
parents: 124
diff changeset
357 srv_send((char *)"%s,%d,2413,Dual channel addressable switchs", de->d_name, ref);
86
3d7a241329e2 Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents: 85
diff changeset
358 } else {
124
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
359 srv_send((char *)"%s,0,NA,Unknown device", de->d_name);
84
ef4c0032b51f Can list the 1-wire bus
Michiel Broek <mbroek@mbse.eu>
parents: 81
diff changeset
360 }
ef4c0032b51f Can list the 1-wire bus
Michiel Broek <mbroek@mbse.eu>
parents: 81
diff changeset
361 }
86
3d7a241329e2 Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents: 85
diff changeset
362 }
3d7a241329e2 Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents: 85
diff changeset
363 srv_send((char *)".");
84
ef4c0032b51f Can list the 1-wire bus
Michiel Broek <mbroek@mbse.eu>
parents: 81
diff changeset
364 closedir(fd);
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
365 return 0;
84
ef4c0032b51f Can list the 1-wire bus
Michiel Broek <mbroek@mbse.eu>
parents: 81
diff changeset
366 } else {
ef4c0032b51f Can list the 1-wire bus
Michiel Broek <mbroek@mbse.eu>
parents: 81
diff changeset
367 srv_send((char *)"503 directory /sys/bus/w1/devices: %s", strerror(errno));
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
368 return 1;
84
ef4c0032b51f Can list the 1-wire bus
Michiel Broek <mbroek@mbse.eu>
parents: 81
diff changeset
369 }
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
370
120
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
371 } else if (strcmp(opt, (char *)"LOG") == 0) {
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
372 /*
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
373 * Get the logfile data and emit only one line per hour.
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
374 */
131
528dc0bb81ab Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents: 125
diff changeset
375 if (current_unit == NULL) {
120
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
376 srv_send((char *)"401 No fermenter unit selected");
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
377 return 1;
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
378 }
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
379
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
380 q[0] = q[1] = 'a';
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
381 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
382 if (strcmp(current_unit, unit->uuid) == 0)
120
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
383 break;
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
384 }
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
385
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
386 srv_send((char *)"212 Logfile list follows:");
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
387 if (getenv((char *)"USER") == NULL) {
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
388 filename = xstrcpy((char *)"/root");
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
389 } else {
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
390 filename = xstrcpy(getenv((char *)"HOME"));
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
391 }
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
392 filename = xstrcat(filename, (char *)"/.thermferm/log/");
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
393 filename = xstrcat(filename, unit->name);
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
394 filename = xstrcat(filename, (char *)".log");
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
395 if ((fp = fopen(filename, "r"))) {
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
396 while (fgets(buffer, sizeof(buffer)-1, fp) != NULL) {
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
397 buffer[strlen(buffer) -1] = '\0';
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
398 p = buffer + 17;
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
399 if (strncmp(p, (char *)"Mode", 4)) {
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
400 if ((q[0] != buffer[11]) || (q[1] != buffer[12])) {
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
401 q[0] = buffer[11];
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
402 q[1] = buffer[12];
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
403 srv_send(buffer);
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
404 }
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
405 }
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
406 }
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
407 }
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
408 free(filename);
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
409 filename = NULL;
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
410 srv_send((char *)".");
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
411 return 0;
466c5cee0463 Added LIST LOG command
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
412
84
ef4c0032b51f Can list the 1-wire bus
Michiel Broek <mbroek@mbse.eu>
parents: 81
diff changeset
413 } else if (strcmp(opt, (char *)"PROFILES") == 0) {
86
3d7a241329e2 Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents: 85
diff changeset
414 /*
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
415 * Fermenting profiles
86
3d7a241329e2 Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents: 85
diff changeset
416 */
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
417 srv_send((char *)"212 profiles:");
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
418 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
419 j = 0;
350401bac16e Added maintenance tabs and extended server output
Michiel Broek <mbroek@mbse.eu>
parents: 120
diff changeset
420 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
421 j++;
136
264e5ee5abfc Profiles now have a busy state
Michiel Broek <mbroek@mbse.eu>
parents: 133
diff changeset
422 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
423 }
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
424 srv_send((char *)".");
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
425 return 0;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
426
84
ef4c0032b51f Can list the 1-wire bus
Michiel Broek <mbroek@mbse.eu>
parents: 81
diff changeset
427 } else if (strcmp(opt, (char *)"UNIT") == 0) {
86
3d7a241329e2 Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents: 85
diff changeset
428 /*
3d7a241329e2 Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents: 85
diff changeset
429 * List configured and selected fermenter unit
3d7a241329e2 Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents: 85
diff changeset
430 */
131
528dc0bb81ab Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents: 125
diff changeset
431 if (current_unit == NULL) {
84
ef4c0032b51f Can list the 1-wire bus
Michiel Broek <mbroek@mbse.eu>
parents: 81
diff changeset
432 srv_send((char *)"401 No fermenter unit selected");
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
433 return 1;
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
434 }
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
435
131
528dc0bb81ab Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents: 125
diff changeset
436 srv_send((char *)"213 Unit %s listing follows:", current_unit);
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
437 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
438 if (strcmp(current_unit, unit->uuid) == 0) {
100
012576d7386d Basic web idea
Michiel Broek <mbroek@mbse.eu>
parents: 95
diff changeset
439 srv_send((char *)"NAME,%s", unit->name);
012576d7386d Basic web idea
Michiel Broek <mbroek@mbse.eu>
parents: 95
diff changeset
440 srv_send((char *)"UUID,%s", unit->uuid);
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
441 if (unit->air_address) {
100
012576d7386d Basic web idea
Michiel Broek <mbroek@mbse.eu>
parents: 95
diff changeset
442 srv_send((char *)"AIR_ADDRESS,%s", unit->air_address);
101
1302abe92eb1 Made temperature sensors working in the units
Michiel Broek <mbroek@mbse.eu>
parents: 100
diff changeset
443 srv_send((char *)"AIR_STATE,%s", TEMPSTATE[unit->air_state]);
1302abe92eb1 Made temperature sensors working in the units
Michiel Broek <mbroek@mbse.eu>
parents: 100
diff changeset
444 srv_send((char *)"AIR_TEMPERATURE,%.3f", unit->air_temperature / 1000.0);
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
445 }
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
446 if (unit->beer_address) {
100
012576d7386d Basic web idea
Michiel Broek <mbroek@mbse.eu>
parents: 95
diff changeset
447 srv_send((char *)"BEER_ADDRESS,%s", unit->beer_address);
101
1302abe92eb1 Made temperature sensors working in the units
Michiel Broek <mbroek@mbse.eu>
parents: 100
diff changeset
448 srv_send((char *)"BEER_STATE,%s", TEMPSTATE[unit->beer_state]);
1302abe92eb1 Made temperature sensors working in the units
Michiel Broek <mbroek@mbse.eu>
parents: 100
diff changeset
449 srv_send((char *)"BEER_TEMPERATURE,%.3f", unit->beer_temperature / 1000.0);
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
450 }
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
451 if (unit->io1_address) {
100
012576d7386d Basic web idea
Michiel Broek <mbroek@mbse.eu>
parents: 95
diff changeset
452 srv_send((char *)"IO1_ADDRESS,%s", unit->io1_address);
87
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
453 }
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
454 if (unit->io2_address) {
100
012576d7386d Basic web idea
Michiel Broek <mbroek@mbse.eu>
parents: 95
diff changeset
455 srv_send((char *)"IO2_ADDRESS,%s", unit->io2_address);
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
456 }
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
457 if (unit->heater_available) {
100
012576d7386d Basic web idea
Michiel Broek <mbroek@mbse.eu>
parents: 95
diff changeset
458 srv_send((char *)"HEATER_AVAILABLE,%s", unit->heater_available);
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
459 }
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
460 if (unit->cooler_available) {
100
012576d7386d Basic web idea
Michiel Broek <mbroek@mbse.eu>
parents: 95
diff changeset
461 srv_send((char *)"COOLER_AVAILABLE,%s", unit->cooler_available);
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
462 }
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
463 if (unit->fan_available) {
100
012576d7386d Basic web idea
Michiel Broek <mbroek@mbse.eu>
parents: 95
diff changeset
464 srv_send((char *)"FAN_AVAILABLE,%s", unit->fan_available);
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
465 }
100
012576d7386d Basic web idea
Michiel Broek <mbroek@mbse.eu>
parents: 95
diff changeset
466 srv_send((char *)"MODE,%s", UNITMODE[unit->mode]);
012576d7386d Basic web idea
Michiel Broek <mbroek@mbse.eu>
parents: 95
diff changeset
467 srv_send((char *)"FRIDGE_SET,%.1f", unit->fridge_set);
012576d7386d Basic web idea
Michiel Broek <mbroek@mbse.eu>
parents: 95
diff changeset
468 srv_send((char *)"BEER_SET,%.1f", unit->beer_set);
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
469 if (unit->profile) {
100
012576d7386d Basic web idea
Michiel Broek <mbroek@mbse.eu>
parents: 95
diff changeset
470 srv_send((char *)"PROFILE,%s", unit->profile);
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
471 }
100
012576d7386d Basic web idea
Michiel Broek <mbroek@mbse.eu>
parents: 95
diff changeset
472 srv_send((char *)"TEMP_SET_MIN,%.1f", unit->temp_set_min);
012576d7386d Basic web idea
Michiel Broek <mbroek@mbse.eu>
parents: 95
diff changeset
473 srv_send((char *)"TEMP_SET_MAX,%.1f", unit->temp_set_max);
012576d7386d Basic web idea
Michiel Broek <mbroek@mbse.eu>
parents: 95
diff changeset
474 srv_send((char *)"IDLE_RANGE_L,%.1f", unit->idle_rangeL);
012576d7386d Basic web idea
Michiel Broek <mbroek@mbse.eu>
parents: 95
diff changeset
475 srv_send((char *)"IDLE_RANGE_H,%.1f", unit->idle_rangeH);
87
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
476 }
84
ef4c0032b51f Can list the 1-wire bus
Michiel Broek <mbroek@mbse.eu>
parents: 81
diff changeset
477 }
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
478 srv_send((char *)".");
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
479 return 0;
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
480 }
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
481
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
482 srv_send((char *)"502 Unknown command option");
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
483 return 1;
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
484 }
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
485
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
486
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
487
87
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
488 /*
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
489 * Set new operating mode
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
490 * MODE OFF|NONE|BEER|FRIDGE|PROFILE
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
491 */
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
492 int cmd_mode(char *buf)
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
493 {
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
494 return 1;
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
495 }
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
496
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
497
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
498
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
499 /*
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
500 * PROFILE List profile status of current unit
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
501 * PROFILE uuid,name Rename profile name
140
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
502 * PROFILE GETS uuid Get profile steps list
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
503 * PROFILE PUTS uuid Put profile steps list
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
504 */
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
505 int cmd_profile(char *buf)
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
506 {
140
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
507 char ibuf[SS_BUFSIZE], *sstep, *rest, *targ;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
508 int i, rlen, istep, irest;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
509 float ftarg;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
510 socklen_t fromlen;
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
511 char *opt, *uuid, *param;
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
512 profiles_list *profile;
140
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
513 prof_step *step, *olds;
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
514 units_list *unit;
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
515
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
516 opt = strtok(buf, " \0");
140
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
517 opt = strtok(NULL, " \0");
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
518
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
519 if (opt == NULL) {
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
520 /*
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
521 * Profile status of current unit
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
522 */
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
523 if (current_unit == NULL) {
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
524 srv_send((char *)"401 No fermenter unit selected");
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
525 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
526 }
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
527 for (unit = Config.units; unit; unit = unit->next) {
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
528 if (strcmp(current_unit, unit->uuid) == 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
529 break;
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
530 }
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
531
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
532 if (unit->profile == NULL) {
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
533 srv_send((char *)"441 Unit has no profile");
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
534 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
535 }
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
536 if (unit->mode != UNITMODE_PROFILE) {
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
537 srv_send((char *)"442 Unit is not using a profile");
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
538 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
539 }
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
540 srv_send((char *)"241 Profile status follows:");
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
541
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
542
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
543 srv_send((char *)".");
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
544 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
545
140
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
546 } else if (strcmp(opt, (char *)"GETS") == 0) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
547
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
548 uuid = strtok(NULL, "\0\n\r");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
549 if (uuid == NULL) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
550 srv_send((char *)"502 Unknown command option");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
551 return 1;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
552 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
553
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
554 for (profile = Config.profiles; profile; profile = profile->next) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
555 if (strcmp(profile->uuid, uuid) == 0) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
556 srv_send((char *)"215 Profile steps follow:");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
557 for (step = profile->steps; step; step = step->next) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
558 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
559 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
560 srv_send((char *)".");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
561 return 1;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
562 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
563 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
564
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
565 srv_send((char *)"440 No such profile");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
566 return 1;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
567
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
568 } else if (strcmp(opt, (char *)"PUTS") == 0) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
569
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
570 uuid = strtok(NULL, "\0\n\r");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
571 if (uuid == NULL) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
572 srv_send((char *)"502 Unknown command option");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
573 return 1;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
574 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
575
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
576 for (profile = Config.profiles; profile; profile = profile->next) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
577 if (strcmp(profile->uuid, uuid) == 0) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
578
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
579 fprintf(stdout, "profile found\n");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
580 if (profile->steps) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
581 for (step = profile->steps; step; step = olds) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
582 olds = step->next;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
583 free(step);
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
584 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
585 profile->steps = NULL;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
586 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
587 fprintf(stdout, "profile cleared\n");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
588
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
589 while (1) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
590 memset((char *)&ibuf, 0, SS_BUFSIZE);
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
591 fromlen = sizeof(peeraddr_in);
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
592 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
593 if (rlen == -1) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
594 syslog(LOG_NOTICE, "recvfrom(): %s", strerror(errno));
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
595 srv_send((char *)"518 recfrom(): %s", strerror(errno));
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
596 return 1;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
597 } else {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
598 for (i = 0; i < strlen(ibuf); i++) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
599 if (ibuf[i] == '\n')
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
600 ibuf[i] = '\0';
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
601 if (ibuf[i] == '\r')
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
602 ibuf[i] = '\0';
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
603 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
604 for (i = strlen(ibuf) -1; i > 0; i--) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
605 if (ibuf[i] == ' ')
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
606 ibuf[i] = '\0';
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
607 else
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
608 break;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
609 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
610 if (strlen(ibuf)) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
611 if (debug) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
612 syslog(LOG_NOTICE, "recv: \"%s\"", ibuf);
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
613 fprintf(stdout, "recv: \"%s\"\n", ibuf);
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
614 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
615 if (strcmp(ibuf, (char *)".") == 0) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
616
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
617 srv_send((char *)"219 Accepted profile steps");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
618 return 0;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
619 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
620 sstep = strtok(ibuf, ",\0");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
621 rest = strtok(NULL, ",\0");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
622 targ = strtok(NULL, "\0");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
623
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
624 if ((sscanf(sstep, "%d", &istep) == 1) &&
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
625 (sscanf(rest, "%d", &irest) == 1) &&
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
626 (sscanf(targ, "%f", &ftarg) == 1)) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
627
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
628 step = (prof_step *)malloc(sizeof(prof_step));
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
629 step->next = NULL;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
630 step->version = 1;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
631 step->steptime = istep;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
632 step->resttime = irest;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
633 step->target = ftarg;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
634
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
635 if (profile->steps == NULL) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
636 profile->steps = step;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
637 } else {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
638 for (olds = profile->steps; olds; olds = olds->next) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
639 if (olds->next == NULL) {
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
640 olds->next = step;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
641 break;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
642 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
643 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
644 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
645 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
646
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
647 fprintf(stdout, "this was data\n");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
648 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
649 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
650 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
651 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
652 }
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
653
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
654 srv_send((char *)"440 No such profile");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
655 return 1;
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
656
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
657 } else {
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
658 /*
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
659 * uuid,name rename profile
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
660 */
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
661 uuid = strtok(opt, ",");
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
662 param = strtok(NULL, "\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
663 fprintf(stdout, "uuid: '%s' param: '%s'\n", uuid, param);
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
664 for (profile = Config.profiles; profile; profile = profile->next) {
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
665 if (strcmp(profile->uuid, uuid) == 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
666 syslog(LOG_NOTICE, "Profile %s rename from '%s' to '%s'", uuid, profile->name, param);
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
667 if (profile->name)
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
668 free(profile->name);
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
669 profile->name = xstrcpy(param);
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
670 srv_send((char *)"240 Profile updated");
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
671 return 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
672 }
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
673 }
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
674 srv_send((char *)"440 No such profile");
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
675 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
676 }
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
677
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
678 srv_send((char *)"502 Unknown command option");
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
679 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
680 }
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
681
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
682
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
683
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
684 /*
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
685 * SET BEER float
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
686 * SET FRIDGE float
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
687 * SET VOLUME float
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
688 * SET IDLE_LOW float
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
689 * SET IDLE_HIGH float
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
690 * SET TEMP_MIN float
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
691 * SET TEMP_MAX float
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
692 * SET NAME string
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
693 * SET PROFILE string
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
694 */
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
695 int cmd_set(char *buf)
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
696 {
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
697 char *opt, *param;
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
698 units_list *unit;
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
699 profiles_list *profile;
131
528dc0bb81ab Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents: 125
diff changeset
700 int rc;
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
701 float fval;
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
702
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
703 opt = strtok(buf, " \0");
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
704 opt = strtok(NULL, " \0");
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
705 if (opt == NULL) {
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
706 srv_send((char *)"501 Subcommand missing");
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
707 return 1;
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
708 }
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
709
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
710 param = strtok(NULL, "\0");
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
711 if (param == NULL) {
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
712 srv_send((char *)"501 Parameter missing");
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
713 return 1;
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
714 }
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
715
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
716 rc = sscanf(param, "%f", &fval);
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
717
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
718 if (debug)
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
719 fprintf(stdout, "opt='%s' param='%s' rc=%d fval=%.1f\n", opt, param, rc, fval);
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
720
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
721 /*
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
722 * Commands below need a selected unit
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
723 */
131
528dc0bb81ab Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents: 125
diff changeset
724 if (current_unit == NULL) {
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
725 srv_send((char *)"401 No fermenter unit selected");
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
726 return 1;
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
727 }
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
728
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
729 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
730 if (strcmp(current_unit, unit->uuid) == 0)
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
731 break;
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
732 }
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
733
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
734 /*
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
735 * If a valid parameter float value
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
736 */
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
737 if (rc == 1) {
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
738 if (strcmp(opt, (char *)"BEER") == 0) {
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
739 if ((fval >= unit->temp_set_min) && (fval <= unit->temp_set_max)) {
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
740 unit->beer_set = fval;
131
528dc0bb81ab Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents: 125
diff changeset
741 srv_send((char *)"214 Unit %s BEER set to %.1f", current_unit, fval);
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
742 return 0;
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
743 } else {
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
744 srv_send((char *)"510 New temperature not between %.1f and %.1f", unit->temp_set_min, unit->temp_set_max);
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
745 return 1;
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
746 }
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
747 } else if (strcmp(opt, (char *)"FRIDGE") == 0) {
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
748 if ((fval >= unit->temp_set_min) && (fval <= unit->temp_set_max)) {
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
749 unit->fridge_set = fval;
131
528dc0bb81ab Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents: 125
diff changeset
750 srv_send((char *)"214 Unit %s BEER set to %.1f", current_unit, fval);
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
751 return 0;
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
752 } else {
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
753 srv_send((char *)"510 New temperature not between %.1f and %.1f", unit->temp_set_min, unit->temp_set_max);
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
754 return 1;
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
755 }
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
756 } else if (strcmp(opt, (char *)"VOLUME") == 0) {
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
757 /*
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
758 * Must fit in a 2 TEU container
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
759 */
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
760 if ((fval >= 0.0) && (fval <= 77020.0)) {
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
761 unit->volume = fval;
131
528dc0bb81ab Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents: 125
diff changeset
762 srv_send((char *)"214 Unit %s VOLUME set to %.1f", current_unit, fval);
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
763 return 0;
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
764 } else {
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
765 srv_send((char *)"510 New volume not between 0 and 77020");
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
766 return 1;
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
767 }
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
768 } else if (strcmp(opt, (char *)"IDLE_LOW") == 0) {
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
769 if ((fval >= -5.0) && (fval <= -0.1)) {
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
770 unit->idle_rangeL = fval;
131
528dc0bb81ab Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents: 125
diff changeset
771 srv_send((char *)"214 Unit %s IDLE_LOW set to %.1f", current_unit, fval);
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
772 return 0;
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
773 } else {
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
774 srv_send((char *)"510 New value not between -5.0 and -0.1");
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
775 return 1;
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
776 }
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
777 } else if (strcmp(opt, (char *)"IDLE_HIGH") == 0) {
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
778 if ((fval >= 0.1) && (fval <= 5.0)) {
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
779 unit->idle_rangeH = fval;
131
528dc0bb81ab Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents: 125
diff changeset
780 srv_send((char *)"214 Unit %s IDLE_HIGH set to %.1f", current_unit, fval);
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
781 return 0;
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
782 } else {
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
783 srv_send((char *)"510 New value not between -5.0 and -0.1");
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
784 return 1;
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
785 }
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
786 } else if (strcmp(opt, (char *)"TEMP_MIN") == 0) {
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
787 if ((fval >= -2.0) && (fval <= 35.0) && (fval < unit->temp_set_max)) {
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
788 unit->temp_set_min = fval;
131
528dc0bb81ab Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents: 125
diff changeset
789 srv_send((char *)"214 Unit %s TEMP_MIN set to %.1f", current_unit, fval);
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
790 return 0;
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
791 } else {
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
792 srv_send((char *)"510 New value not between -2.0 and 35.0 and lower then TEMP_MAX");
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
793 return 1;
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
794 }
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
795 } else if (strcmp(opt, (char *)"TEMP_MAX") == 0) {
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
796 if ((fval >= -2.0) && (fval <= 35.0) && (fval > unit->temp_set_min)) {
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
797 unit->temp_set_max = fval;
131
528dc0bb81ab Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents: 125
diff changeset
798 srv_send((char *)"214 Unit %s TEMP_MAX set to %.1f", current_unit, fval);
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
799 return 0;
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
800 } else {
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
801 srv_send((char *)"510 New value not between -2.0 and 35.0 and higher then TEMP_MIN");
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
802 return 1;
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
803 }
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
804 }
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
805 }
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
806
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
807 /*
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
808 * Set new unit or beer name
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
809 */
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
810 if (strcmp(opt, (char *)"NAME") == 0) {
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
811 if (unit->name)
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
812 free(unit->name);
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
813 unit->name = xstrcpy(param);
131
528dc0bb81ab Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents: 125
diff changeset
814 srv_send((char *)"214 Unit %s NAME set to '%s'", current_unit, param);
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
815 // TODO: change logfile name
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
816 return 0;
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
817 } else if (strcmp(opt, (char *)"PROFILE") == 0) {
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
818 /*
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
819 * Check for active profile, already selected etc.
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
820 */
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
821 if (unit->profile && (unit->mode == UNITMODE_PROFILE)) {
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
822 srv_send((char *)"541 Cannot change profile while a profile is active");
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
823 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
824 }
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
825 if (unit->profile && (strcmp(unit->profile, param) == 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
826 srv_send((char *)"542 Profile already set");
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
827 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
828 }
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
829 for (profile = Config.profiles; profile; profile = profile->next) {
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
830 if (strcmp(profile->uuid, param) == 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
831 if (unit->profile)
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
832 free(unit->profile);
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
833 unit->profile = xstrcpy(param);
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
834 srv_send((char *)"242 Unit profile changed to %s", param);
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
835 return 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
836 }
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
837 }
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
838 srv_send((char *)"543 Invalid profile");
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
839 return 1;
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
840 }
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
841
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
842 srv_send((char *)"502 Unknown command option");
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
843 return 1;
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
844 }
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
845
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
846
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
847
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
848 /*
87
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
849 * UNIT uuid
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
850 */
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
851 int cmd_unit(char *buf)
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
852 {
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
853 char *opt;
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
854 units_list *tmp;
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
855
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
856 opt = strtok(buf, " \0");
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
857 opt = strtok(NULL, " \0");
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
858
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
859 if (opt == NULL) {
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
860 srv_send((char *)"501 Parameter missing");
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
861 return 1;
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
862 }
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
863
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
864 if (strlen(opt) == 36) {
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
865 /*
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
866 * Search using uuid
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
867 */
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
868 for (tmp = Config.units; tmp; tmp = tmp->next) {
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
869 if (strcmp(opt, tmp->uuid) == 0) {
131
528dc0bb81ab Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents: 125
diff changeset
870 srv_send((char *)"210 Unit %s selected", tmp->uuid);
528dc0bb81ab Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents: 125
diff changeset
871 if (current_unit)
528dc0bb81ab Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents: 125
diff changeset
872 free(current_unit);
528dc0bb81ab Always use uuid to select units and remove numeric record id's.
Michiel Broek <mbroek@mbse.eu>
parents: 125
diff changeset
873 current_unit = xstrcpy(tmp->uuid);;
87
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
874 return 0;
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
875 }
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
876 }
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
877 srv_send((char *)"410 No such unit");
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
878 return 1;
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
879 }
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
880
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
881 srv_send((char *)"502 Unknown command option");
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
882 return 1;
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
883 }
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
884
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
885
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
886
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
887 void cmd_server(void)
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
888 {
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
889 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
890 int i, rlen;
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
891 socklen_t fromlen;
68
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
892 #ifdef HAVE_WIRINGPI_H
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
893 int j;
133
345307762220 Fixed compiling on systems with wiringpi libs
Michiel Broek <mbroek@mbse.eu>
parents: 132
diff changeset
894 char obuf[SS_BUFSIZE];
68
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
895 #endif
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
896
48
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
897 memset((char *)&buf, 0, SS_BUFSIZE);
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
898 fromlen = sizeof(peeraddr_in);
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
899 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
900 if (rlen == -1) {
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
901 syslog(LOG_NOTICE, "recvfrom(): %s", strerror(errno));
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
902 } else {
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
903 for (i = 0; i < strlen(buf); i++) {
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
904 if (buf[i] == '\n')
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
905 buf[i] = '\0';
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
906 if (buf[i] == '\r')
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
907 buf[i] = '\0';
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
908 }
80
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
909 for (i = strlen(buf) -1; i > 0; i--) {
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
910 if (buf[i] == ' ')
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
911 buf[i] = '\0';
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
912 else
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
913 break;
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
914 }
48
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
915 if (strlen(buf)) {
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
916 if (debug) {
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
917 syslog(LOG_NOTICE, "recv: \"%s\"", buf);
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
918 fprintf(stdout, "recv: \"%s\"\n", buf);
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
919 }
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
920
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
921 /*
48
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
922 * Process commands from the client
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
923 */
80
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
924 if (strncmp(buf, "ADD", 3) == 0) {
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
925 if (unit_add(buf) == 0)
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
926 wrconfig();
138
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
927 } else if (strncmp(buf, "DEL", 3) == 0) {
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
928 if (cmd_del(buf) == 0)
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
929 wrconfig();
80
81bf78a7618e Switched to xml configuration
Michiel Broek <mbroek@mbse.eu>
parents: 79
diff changeset
930 } 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
931 srv_send((char *)"100 Help text follows");
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
932 srv_send((char *)"Recognized commands:");
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
933 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
934 // 12345678901234567890123456789012345678901234567890123456789012345678901234567890
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
935 srv_send((char *)"ADD PROFILE name Add a new profile with \"name\"");
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
936 srv_send((char *)"ADD UNIT name Add a new unit with \"name\"");
138
e7e7a23af890 Added DEL PROFILE command
Michiel Broek <mbroek@mbse.eu>
parents: 136
diff changeset
937 srv_send((char *)"DEL PROFILE uuid Delete profile with uuid");
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
938 // srv_send((char *)"DEL UNIT uuid Delete unit with uuid");
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
939 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
940 srv_send((char *)"LIST List all fermenter units");
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
941 srv_send((char *)"LIST BUS List 1-wire bus");
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
942 srv_send((char *)"LIST LOG List logfile data in 1 hour lines");
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
943 srv_send((char *)"LIST PROFILES List available profiles");
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
944 srv_send((char *)"LIST UNIT List fermenter unit");
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
945 srv_send((char *)"MODE OFF|NONE|BEER|FRIDGE|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
946 // srv_send((char *)"PROFILE Profile status of current unit");
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
947 srv_send((char *)"PROFILE uuid,name Profile rename");
140
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
948 srv_send((char *)"PROFILE GETS uuid Profile get steps list");
1b001de37945 Implemented PROFILE PUTS command
Michiel Broek <mbroek@mbse.eu>
parents: 138
diff changeset
949 srv_send((char *)"PROFILE PUTS uuid Profile put steps list");
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
950 srv_send((char *)"SET BEER val Set beer temperature");
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
951 srv_send((char *)"SET FRIDGE val Set fridge temperature");
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
952 srv_send((char *)"SET IDLE_LOW val Set idle temperature low (-5.0 .. -0.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
953 srv_send((char *)"SET IDLE_HIGH val Set idle temperature high (0.1 .. 5.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
954 srv_send((char *)"SET NAME name Set name or beername for the unit");
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
955 srv_send((char *)"SET PROFILE uuid Set unit profile");
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
956 // srv_send((char *)"SET PROFILE start|stop|pause Profile start, stop or pause");
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
957 srv_send((char *)"SET TEMP_MIN val Set unit minimum temperature");
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
958 srv_send((char *)"SET TEMP_MAX val Set unit maximum temperature");
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
959 srv_send((char *)"SET VOLUME val Set unit volume");
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
960 srv_send((char *)"UNIT uuid Select unit by uuid");
68
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
961 srv_send((char *)".");
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
962 } else if (strncmp(buf, "LCD", 3) == 0) {
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
963 #ifdef HAVE_WIRINGPI_H
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
964 srv_send((char *)"201 information follows");
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
965 for (j = 0; j < 4; j++) {
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
966 sprintf(obuf, " ");
70
920eface3ec5 Small fix for LCD output
Michiel Broek <mbroek@mbse.eu>
parents: 68
diff changeset
967 obuf[20] = '\0';
68
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
968 for (i = 0; i < 20; i++)
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
969 obuf[i] = lcdbuf[lcdHandle][i][j];
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
970 srv_send(obuf);
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
971 }
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
972 srv_send((char *)".");
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
973 #else
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
974 srv_send((char *)"403 LCD not available");
6dba71439cd8 Added first part of out own protocol
Michiel Broek <mbroek@mbse.eu>
parents: 66
diff changeset
975 #endif
81
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
976 } else if (strncmp(buf, "LIST", 4) == 0) {
547bbe344886 Added list command
Michiel Broek <mbroek@mbse.eu>
parents: 80
diff changeset
977 cmd_list(buf);
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
978 } else if (strncmp(buf, "MODE", 4) == 0) {
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
979 cmd_mode(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
980 } 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
981 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
982 wrconfig();
88
12259362595b Added SET commands
Michiel Broek <mbroek@mbse.eu>
parents: 87
diff changeset
983 } else if (strncmp(buf, "SET", 3) == 0) {
92
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
984 if (cmd_set(buf) == 0)
116226a8c70a Added profiles configuration
Michiel Broek <mbroek@mbse.eu>
parents: 88
diff changeset
985 wrconfig();
87
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
986 } else if (strncmp(buf, "UNIT", 4) == 0) {
55f1315c94f1 Added unit command and list unit command
Michiel Broek <mbroek@mbse.eu>
parents: 86
diff changeset
987 cmd_unit(buf);
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
988 } else {
48
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
989 if (debug)
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
990 fprintf(stdout, "unknown command \"%s\"\n", 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
991 srv_send((char *)"500 Unknown command");
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
992 }
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
993 }
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
994 }
44
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
995
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
996 close(s);
42
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
997 }
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
998
01b96a24ae7c Corrected missing and obsolete files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
999
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
1000
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 62
diff changeset
1001 #ifdef HAVE_WIRINGPI_H
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1002 PI_THREAD (my_server_loop)
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 62
diff changeset
1003 #else
74
879bd09e2b96 Reinstalled threads
Michiel Broek <mbroek@mbse.eu>
parents: 71
diff changeset
1004 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
1005 #endif
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1006 {
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1007 socklen_t addrlen;
44
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1008 int optval = 1;
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1009
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1010 syslog(LOG_NOTICE, "Thread my_server_loop started");
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1011 if (debug)
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1012 fprintf(stdout, "Thread my_server_loop started\n");
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1013
44
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1014 memset((char *)&myaddr_in, 0, sizeof(struct sockaddr_in));
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1015 memset((char *)&peeraddr_in, 0, sizeof(struct sockaddr_in));
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1016 myaddr_in.sin_family = AF_INET;
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1017 myaddr_in.sin_addr.s_addr = INADDR_ANY;
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1018 myaddr_in.sin_port = htons(Config.my_port);
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1019
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1020 ls = socket(AF_INET, SOCK_STREAM, 0);
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1021 if (ls == -1) {
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1022 syslog(LOG_NOTICE, "Can't create listen socket: %s", strerror(errno));
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1023 fprintf(stderr, "Can't create listen socket: %s\n", strerror(errno));
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1024 return 0;
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1025 }
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1026
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1027 if (setsockopt(ls, SOL_SOCKET, SO_KEEPALIVE, &optval, sizeof(optval)) == -1) {
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1028 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
1029 close(ls);
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1030 return 0;
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1031 }
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1032
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1033 if (setsockopt(ls, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) == -1) {
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1034 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
1035 close(ls);
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 62
diff changeset
1036 return 0;
44
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1037 }
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1038
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1039 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
1040 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
1041 close(ls);
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 62
diff changeset
1042 return 0;
44
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1043 }
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1044
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1045 if (listen(ls, 5) == -1) {
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1046 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
1047 close(ls);
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 62
diff changeset
1048 return 0;
44
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1049 }
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1050
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1051 syslog(LOG_NOTICE, "listen socket created %d", ls);
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1052 if (debug)
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1053 fprintf(stdout, "listen socket created %d\n", ls);
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1054
f37d73940699 Server communication works
Michiel Broek <mbroek@mbse.eu>
parents: 43
diff changeset
1055
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1056 /*
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1057 * Loop forever until the external shutdown variable is set.
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1058 */
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1059 for (;;) {
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1060
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1061 addrlen = sizeof(struct sockaddr_in);
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1062 /*
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1063 * This call will block until a new connection
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1064 * arrives. Then it will return the address of
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1065 * the connecting peer, and a new socket
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1066 * descriptor, s, for that connection.
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1067 */
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1068 s = accept(ls, (struct sockaddr *)&peeraddr_in, &addrlen);
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1069 if (s == -1) {
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1070 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
1071 if (debug)
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1072 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
1073 return 0;
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1074 }
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1075
48
d8c64f81b192 Single client server works
Michiel Broek <mbroek@mbse.eu>
parents: 46
diff changeset
1076 cmd_server();
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1077
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1078 if (my_shutdown) {
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1079 syslog(LOG_NOTICE, "Thread my_server_loop stopped");
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1080 if (debug)
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1081 fprintf(stdout, "Thread my_server_loop stopped\n");
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1082 return 0;
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1083 }
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1084
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1085 }
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1086 }
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1087
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 42
diff changeset
1088

mercurial