Revision 44 logic/trunk/src/startup/main.c
main.c | ||
---|---|---|
12 | 12 |
//#include "../logics/scenario_threads.h" |
13 | 13 |
#include <stdio.h> |
14 | 14 |
#include <pthread.h> |
15 |
#include <syslog.h> |
|
15 | 16 |
|
16 | 17 |
// Inter-thread shared variables |
17 | 18 |
// TODO: These variables could be configuration variables |
... | ... | |
34 | 35 |
|
35 | 36 |
/* initialisation */ |
36 | 37 |
hDevice = setDeviceList(); |
37 |
hScenario = setNewScenarioList(); |
|
38 |
hScenario = setNewScenarioList(hDevice);
|
|
38 | 39 |
|
39 | 40 |
printf("Devices present:\t%d\n", getNumberOfDevices()); |
40 | 41 |
printf("Scenarios present:\t%d\n", getNumberOfScenarios()); |
... | ... | |
124 | 125 |
scenario *scen; |
125 | 126 |
device *inDev; |
126 | 127 |
int active = 0; |
127 |
float scen_main_buff; |
|
128 |
//float alpha = 0.7f; //TODO put this in xml also |
|
129 |
//printf("alpha %.2f\n", alpha); |
|
128 |
float scenarioBuffer; |
|
129 |
|
|
130 | 130 |
/*load scenario*/ |
131 | 131 |
scen = getAvailableScenario(hScenario); |
132 | 132 |
if(!scen) pthread_exit(0); |
133 | 133 |
|
134 | 134 |
// TODO add pointer to this device (all of them actually) to scenario structure - problems with segfault |
135 |
//indev = scen->inDev; |
|
135 | 136 |
inDev = getDevice(hDevice, scen->inDevice_id); |
136 |
scen_main_buff=inDev->buf;
|
|
137 |
printf("Scenario %s buffer updated to %.2f!\n", scen->scen_id, scen_main_buff);
|
|
137 |
scen->buf=inDev->buf;
|
|
138 |
printf("Scenario %s buffer updated to %.2f!\n", scen->scen_id, inDev->buf);
|
|
138 | 139 |
//set its value |
139 | 140 |
//* |
140 | 141 |
while(1) //TODO signal == true |
... | ... | |
146 | 147 |
else |
147 | 148 |
sleep(scen->idleChkItv); |
148 | 149 |
//checking primary condition |
149 |
if(scen_main_buff) // is not null
|
|
150 |
if(scen->buf) // is not null
|
|
150 | 151 |
{ |
151 |
scen_main_buff = scen_main_buff*scen->alpha+inDev->buf*(1-scen->alpha); |
|
152 |
printf("Scenario %s buffer updated to %f, alpha: %.2f!\n", scen->scen_id, scen_main_buff, scen->alpha); |
|
152 |
scen->buf = scen->buf*scen->alpha+inDev->buf*(1-scen->alpha); |
|
153 |
//printf("Scenario %s buffer updated to %f, alpha: %.2f!\n", scen->scen_id, scenarioBuffer, scen->alpha); |
|
154 |
syslog(LOG_MAIL, "%s:%.2f", scen->inDevice_id, scen->buf); |
|
153 | 155 |
active = 1; |
154 | 156 |
|
155 |
if((scen_main_buff > scen->optval + scen->tolval) ||
|
|
156 |
(scen_main_buff < scen->optval - scen->tolval))
|
|
157 |
if((scen->buf > scen->optval + scen->tolval) ||
|
|
158 |
(scen->buf < scen->optval - scen->tolval))
|
|
157 | 159 |
{ |
158 | 160 |
if(evaluateAdditionalConditions(scen->cond_l, hDevice)) |
159 | 161 |
{ |
160 |
printf("Scenario %s updated!\n", scen->scen_id); |
|
161 |
syslog(LOG_MAIL, "%s:%.2f", scen->inDevice_id, scen_main_buff); |
|
162 |
/*TODO calcualte parameters with given function*/ |
|
162 |
// TODO syslog - "action:scen_ID:power_percentage" |
|
163 |
int power = getPowerPercentage(scen->minval, scen->maxval, scen->optval, &scen->buf, scen->func); |
|
164 |
syslog(LOG_MAIL, "%s:%s:%.2f", scen->action, scen->scen_id, power); |
|
165 |
printf("Zaganjam napravo %s z mocjo %d\n", scen->scen_id, power); |
|
163 | 166 |
/*TODO execute action with parameter(s)*/ |
164 | 167 |
} |
165 | 168 |
else |
... | ... | |
168 | 171 |
else |
169 | 172 |
active = 0; |
170 | 173 |
} |
174 |
/* |
|
171 | 175 |
if(active) |
172 |
printf("%s main buffer %.2f, sleeping %d\n",scen->scen_id, scen_main_buff, scen->actvChkItv);
|
|
176 |
printf("%s main buffer %.2f, sleeping %d\n",scen->scen_id, scen->buf, scen->actvChkItv);
|
|
173 | 177 |
else |
174 |
printf("%s main buffer %.2f, sleeping %d\n",scen->scen_id, scen_main_buff, scen->idleChkItv); |
|
178 |
printf("%s main buffer %.2f, sleeping %d\n",scen->scen_id, scen->buf, scen->idleChkItv); |
|
179 |
/**/ |
|
175 | 180 |
} |
176 | 181 |
/**/ |
177 | 182 |
pthread_exit(0); |
Also available in: Unified diff