-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcentral-heating.c
More file actions
184 lines (161 loc) · 3.74 KB
/
central-heating.c
File metadata and controls
184 lines (161 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/* central-heating.c -- calculate fuzzy logic measure with delta function
* Copyright (C) 2014 Sergei Ianovich <ynvich@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "includes.h"
#include <stdio.h>
#include "block.h"
#include "central-heating.h"
#include "map.h"
#include "state.h"
#define PCS_BLOCK "central-heating"
struct central_heating_state {
long *input_flowback;
long *input_street;
long *feed;
long *flowback;
long *inside;
long *stop;
long *street;
};
static void
central_heating_run(struct block *b, struct server_state *s)
{
struct central_heating_state *d = b->data;
long long t11;
long long t12_excess;
long street = *d->input_street;
if (street > *d->stop)
street = *d->stop;
t11 = *d->feed - *d->inside;
t11 *= *d->inside - street;
t11 /= *d->inside - *d->street;
t11 += *d->inside;
t12_excess = *d->feed - *d->flowback;
t12_excess *= *d->inside - street;
t12_excess /= *d->inside - *d->street;
t12_excess += *d->input_flowback - t11;
*b->outputs = (long) (t11 - t12_excess);
debug3("%s: %lli %lli %li\n", PCS_BLOCK, t11, t12_excess, *b->outputs);
}
static void
set_input_flowback(void *data, const char const *key, long *input_flowback)
{
struct central_heating_state *d = data;
d->input_flowback = input_flowback;
}
static void
set_input_street(void *data, const char const *key, long *input_street)
{
struct central_heating_state *d = data;
d->input_street = input_street;
}
static int
set_feed(void *data, const char const *key, long *feed)
{
struct central_heating_state *d = data;
d->feed = feed;
return 0;
}
static int
set_flowback(void *data, const char const *key, long *flowback)
{
struct central_heating_state *d = data;
d->flowback = flowback;
return 0;
}
static int
set_inside(void *data, const char const *key, long *inside)
{
struct central_heating_state *d = data;
d->inside = inside;
return 0;
}
static int
set_stop(void *data, const char const *key, long *stop)
{
struct central_heating_state *d = data;
d->stop = stop;
return 0;
}
static int
set_street(void *data, const char const *key, long *street)
{
struct central_heating_state *d = data;
d->street = street;
return 0;
}
static const char *outputs[] = {
NULL
};
static struct pcs_map inputs[] = {
{
.key = "flowback",
.value = set_input_flowback,
}
,{
.key = "street",
.value = set_input_street,
}
,{
.key = "feed setpoint",
.value = set_feed,
}
,{
.key = "flowback setpoint",
.value = set_flowback,
}
,{
.key = "inside setpoint",
.value = set_inside,
}
,{
.key = "stop setpoint",
.value = set_stop,
}
,{
.key = "street setpoint",
.value = set_street,
}
,{
}
};
static void *
alloc(void)
{
struct central_heating_state *d = xzalloc(sizeof(*d));
return d;
}
static struct block_ops ops = {
.run = central_heating_run,
};
static struct block_ops *
init(struct block *b)
{
return &ops;
}
static struct block_builder builder = {
.alloc = alloc,
.ops = init,
.outputs = outputs,
.inputs = inputs,
};
struct block_builder *
load_central_heating_builder(void)
{
return &builder;
}