Revision 40
logic/trunk/devicetree.xml | ||
---|---|---|
1 | 1 |
<?xml version="1.0"?> |
2 | 2 |
<devicetree> |
3 | 3 |
<device id="thermometer_01"> |
4 |
<name nam="Thermometer"></name>
|
|
4 |
<name nam="Termometer server room"></name>
|
|
5 | 5 |
<read_interval rditv="10"/> |
6 | 6 |
<action act="testAction_1"></action> |
7 | 7 |
<param par="testParam_1"></param> |
8 | 8 |
</device> |
9 |
<device id="thermometer_02"> |
|
10 |
<name nam="Termometer pisarna"></name> |
|
11 |
<read_interval rditv="10"/> |
|
12 |
<action act="testAction_1"></action> |
|
13 |
<param par="testParam_1"></param> |
|
14 |
</device> |
|
9 | 15 |
<device id="barometer_01"> |
10 | 16 |
<name nam="Barometer"></name> |
11 | 17 |
<read_interval rditv="20"/> |
logic/trunk/eneraptor.cbp | ||
---|---|---|
43 | 43 |
<Unit filename="src/hci_comm/hci_comm_listener.c"> |
44 | 44 |
<Option compilerVar="CC" /> |
45 | 45 |
</Unit> |
46 |
<Unit filename="src/init/buf.c"> |
|
47 |
<Option compilerVar="CC" /> |
|
48 |
</Unit> |
|
49 |
<Unit filename="src/init/buf.h" /> |
|
50 | 46 |
<Unit filename="src/init/devicelist.c"> |
51 | 47 |
<Option compilerVar="CC" /> |
52 | 48 |
</Unit> |
logic/trunk/scenariotree.xml | ||
---|---|---|
1 | 1 |
<?xml version="1.0"?> |
2 | 2 |
<scenariotree> |
3 |
<scenario id="scenario_01" name="Klima na stropu, w/e">
|
|
3 |
<scenario id="scenario_01" name="Klima v server roomu">
|
|
4 | 4 |
<inDevice id="thermometer_01" /> |
5 | 5 |
<outDevice id="air_cond_01" /> |
6 | 6 |
<reaction func="linear" /> |
7 |
<check_idle val="600" /> |
|
8 |
<check_active val="60" /> |
|
7 |
<check_idle val="30" /> |
|
8 |
<check_active val="3" /> |
|
9 |
<alpha val="0.7"/> |
|
9 | 10 |
<params val="--lazy=true" /> |
10 |
<inDevAalues minval="20" maxval="28" optval="24" tolerance="0.5"/>
|
|
11 |
<inDevAalues minval="20" maxval="25" optval="20" tolerance="0.5"/>
|
|
11 | 12 |
<action act="testAction_1"/> |
12 | 13 |
<param par="testParam_1"/> |
14 |
<conditions/> |
|
15 |
</scenario> |
|
16 |
<scenario id="scenario_02" name="Klima v pisarni"> |
|
17 |
<inDevice id="thermometer_02" /> |
|
18 |
<outDevice id="air_cond_02" /> |
|
19 |
<reaction func="linear" /> |
|
20 |
<check_idle val="600" /> |
|
21 |
<check_active val="30" /> |
|
22 |
<alpha val="0.8"/> |
|
23 |
<params val="--lazy=true" /> |
|
24 |
<inDevAalues minval="20" maxval="26" optval="23" tolerance="0.5"/> |
|
25 |
<action act="testAction_2"/> |
|
26 |
<param par="testParam_3"/> |
|
13 | 27 |
<conditions> |
14 | 28 |
<and> |
15 | 29 |
<greater inDeviceId="barometer_01" val="80" /> |
16 |
<less_or_equal inDeviceId="lightSensor" val="50" /> |
|
17 | 30 |
<or> |
18 |
<greater inDeviceId="time" val="1500" />
|
|
19 |
<less inDeviceId="time" val="1000" />
|
|
31 |
<less inDeviceId="time" val="1600" />
|
|
32 |
<greater inDeviceId="time" val="700" />
|
|
20 | 33 |
</or> |
21 | 34 |
</and> |
22 | 35 |
</conditions> |
23 | 36 |
</scenario> |
24 |
<scenario id="scenario_02" name="Klima v kleti, w/e">
|
|
25 |
<inDevice id="thermometer_01" />
|
|
26 |
<outDevice id="air_cond_01" />
|
|
37 |
<scenario id="scenario_03" name="Okna v pisarni">
|
|
38 |
<inDevice id="hygrometer_01" />
|
|
39 |
<outDevice id="window_01" />
|
|
27 | 40 |
<reaction func="linear" /> |
28 | 41 |
<check_idle val="600" /> |
29 |
<check_active val="60" /> |
|
42 |
<check_active val="10" /> |
|
43 |
<alpha val="0.9"/> |
|
30 | 44 |
<params val="--lazy=true" /> |
31 |
<inDevAalues minval="20" maxval="28" optval="24" tolerance="0.5"/>
|
|
32 |
<action act="testAction_1"/>
|
|
33 |
<param par="testParam_1"/>
|
|
45 |
<inDevAalues minval="20" maxval="28" optval="28" tolerance="0.5"/>
|
|
46 |
<action act="testAction_2"/>
|
|
47 |
<param par="testParam_3"/>
|
|
34 | 48 |
<conditions> |
35 | 49 |
<and> |
36 |
<greater inDeviceId="barometer_01" val="80" /> |
|
37 |
<less_or_equal inDeviceId="lightSensor" val="50" /> |
|
38 |
<or> |
|
39 |
<greater inDeviceId="time" val="1500" /> |
|
40 |
<less inDeviceId="time" val="1000" /> |
|
41 |
</or> |
|
50 |
<greater inDeviceId="time" val="1600" /> |
|
51 |
<less inDeviceId="time" val="700" /> |
|
42 | 52 |
</and> |
43 | 53 |
</conditions> |
44 | 54 |
</scenario> |
logic/trunk/src/logics/operators.h | ||
---|---|---|
11 | 11 |
#define LESS 6 |
12 | 12 |
#define LESS_OR_EQUAL 7 |
13 | 13 |
|
14 |
int operator_AND (int a, int b); |
|
15 |
int operator_NOT_AND (int a, int b); |
|
16 |
int operator_OR (int a, int b); |
|
17 |
int operator_XOR (int a, int b); |
|
18 |
int operator_GREATER (int a, int b); |
|
19 |
int operator_GREATER_OR_EQUAL (int a, int b); |
|
20 |
int operator_LESS (int a, int b); |
|
21 |
int operator_LESS_OR_EQUAL (int a, int b); |
|
14 |
int evalOperators(int opr, int a, int b); |
|
22 | 15 |
|
23 | 16 |
#endif // OPERATORS_H_INCLUDED |
logic/trunk/src/logics/conditions.c | ||
---|---|---|
1 | 1 |
#include "conditions.h" |
2 |
#include <stdio.h> |
|
2 | 3 |
|
3 |
int getConditionsResult(cond_lst *cl)
|
|
4 |
int evaluateAdditionalConditions(cond_lst *cl, device *dev)
|
|
4 | 5 |
{ |
5 |
// TODO dodaj izracun stanja, vrne naj 1 ali 0 |
|
6 |
//* |
|
7 |
while(cl) |
|
6 |
int result = -1; |
|
7 |
int local_result = -1; |
|
8 |
cond_lst *leaf; |
|
9 |
device *testDev; |
|
10 |
|
|
11 |
//printf("dev %s\n",dev->id); |
|
12 |
if(cl->OPERATOR_TYPE == TOP_NODE) |
|
13 |
if(!cl->sub_lst) // no additional conditions |
|
14 |
return 1; |
|
15 |
else{} |
|
16 |
//printf("Evaluating operator %d\n", cl->OPERATOR_TYPE); |
|
17 |
while(cl->sub_lst) |
|
8 | 18 |
{ |
9 |
/* |
|
10 |
printf("=== cl address \t\t%d\n",&cl->OPERATOR_TYPE); |
|
11 |
printf("cl->OPERATOR_TYPE \t%d\n",cl->OPERATOR_TYPE); |
|
12 |
printf("cl->dev \t\t%s\n",cl->dev); |
|
13 |
printf("cl->nxt_lst \t\t%d\n",cl->nxt_lst); |
|
14 |
printf("cl->sub_lst \t\t%d\n",cl->sub_lst); |
|
15 |
printf("cl->value \t\t%d\n",cl->value); |
|
16 |
/**/ |
|
17 |
if(cl->sub_lst) |
|
19 |
if(!cl->sub_lst->sub_lst) //leaf |
|
18 | 20 |
{ |
19 |
//cl2=cl->sub_lst; |
|
20 |
getConditionsResult(cl->sub_lst); |
|
21 |
//printf("Found leaf with opr %d\n", cl->sub_lst->OPERATOR_TYPE); |
|
22 |
//todo glej cez cel sub - nivo |
|
23 |
if(result==-1) //got first leaf element |
|
24 |
{ |
|
25 |
//printf("got FIRST LEAF element with opr %d and device name %s\n", cl->sub_lst->OPERATOR_TYPE, cl->sub_lst->dev); |
|
26 |
if(0==strcmp(cl->sub_lst->dev,"time")) |
|
27 |
result = evalOperators(cl->sub_lst->OPERATOR_TYPE, getLocalFormattedTime(), cl->sub_lst->value); |
|
28 |
else |
|
29 |
result = evalOperators(cl->sub_lst->OPERATOR_TYPE, (*getDevice(dev, cl->sub_lst->dev)).buf, cl->sub_lst->value); |
|
30 |
} |
|
31 |
else |
|
32 |
{ |
|
33 |
//printf("got LEAF element with opr %d\n", cl->sub_lst->OPERATOR_TYPE); |
|
34 |
if(0==strcmp(cl->sub_lst->dev,"time")) |
|
35 |
local_result = evalOperators(cl->sub_lst->OPERATOR_TYPE, getLocalFormattedTime(), cl->sub_lst->value); |
|
36 |
else |
|
37 |
local_result = evalOperators(cl->sub_lst->OPERATOR_TYPE, (*getDevice(dev, cl->sub_lst->dev)).buf, cl->sub_lst->value); |
|
38 |
result = evalOperators(cl->OPERATOR_TYPE, result, local_result); |
|
39 |
} |
|
21 | 40 |
} |
22 |
cl=cl->nxt_lst; |
|
41 |
else //not leaf |
|
42 |
{ |
|
43 |
//printf("Found child with opr %d\n", cl->sub_lst->OPERATOR_TYPE); |
|
44 |
if(result==-1) //got first child element |
|
45 |
{ |
|
46 |
//printf("got FIRST CHILD element with opr %d\n", cl->sub_lst->OPERATOR_TYPE); |
|
47 |
result = evaluateAdditionalConditions(cl->sub_lst, dev); |
|
48 |
} |
|
49 |
else |
|
50 |
{ |
|
51 |
//printf("got CHILD element with opr %d\n", cl->sub_lst->OPERATOR_TYPE); |
|
52 |
result = evaluateAdditionalConditions(cl->sub_lst, dev); |
|
53 |
result = evalOperators(cl->OPERATOR_TYPE, result, local_result); |
|
54 |
} |
|
55 |
} |
|
56 |
cl->sub_lst=cl->sub_lst->nxt_lst; |
|
23 | 57 |
} |
24 |
return 0;
|
|
58 |
return result;
|
|
25 | 59 |
} |
26 | 60 |
|
61 |
// TODO check this one again |
|
62 |
float getNewWeightedMeasurement(float oldval, float newval, float alpha) |
|
63 |
{ |
|
64 |
printf("getNewWeightedMeasurement(float oldval, float newval, float alpha)\n"); |
|
65 |
printf("=== buffer %f, device buffer %f, alpha %f\n", oldval, newval, alpha); |
|
66 |
printf("%f\n",oldval*alpha+newval*(1-alpha)); |
|
67 |
return oldval*alpha+newval*(1-alpha); |
|
68 |
} |
|
27 | 69 |
/*TODO morda dodaj preverbo pravilnosti conditionov (kot podatkov v strukturi)*/ |
logic/trunk/src/logics/conditions.h | ||
---|---|---|
13 | 13 |
struct condition_list *sub_lst; |
14 | 14 |
}cond_lst; |
15 | 15 |
|
16 |
int getConditionsResult(cond_lst *cl); |
|
16 |
int evaluateAdditionalConditions(cond_lst *cl, device *dev); |
|
17 |
//int evaluateAdditionalConditions(cond_lst *cl); |
|
18 |
float getNewWeightedMeasurement(float oldval, float newval, float alpha); |
|
17 | 19 |
#endif // CONDITIONS_H_INCLUDED |
logic/trunk/src/logics/operators.c | ||
---|---|---|
1 | 1 |
#include "operators.h" |
2 |
#include <stdio.h> |
|
2 | 3 |
|
3 |
int operator_AND(int a, int b)
|
|
4 |
int evalOperators(int opr, int a, int b)
|
|
4 | 5 |
{ |
5 |
if(a && b) |
|
6 |
return 1; |
|
7 |
return 0; |
|
6 |
switch(opr) |
|
7 |
{ |
|
8 |
case AND: |
|
9 |
//printf("\t--- Evaluating a %d && b %d = %d\n",a,b,a&&b); |
|
10 |
return a&&b; |
|
11 |
case NOT_AND: |
|
12 |
//printf("\t--- Evaluating !(a %d && b %d) = %d\n",a,b, !(a&&b)); |
|
13 |
return !(a&&b); |
|
14 |
case OR: |
|
15 |
//printf("\t--- Evaluating a %d || b %d = %d\n",a,b, a||b); |
|
16 |
return a||b; |
|
17 |
case XOR: |
|
18 |
//printf("\t--- Evaluating (!a %d && b %d )||(a %d && !b %d)= %d\n",a,b,a,b,(!a&&b)||(a&&!b)); |
|
19 |
return (!a&&b)||(a&&!b); |
|
20 |
case GREATER: |
|
21 |
//printf("\t--- Evaluating a %d > b %d = %d\n",a,b, a>b); |
|
22 |
return a>b; |
|
23 |
case GREATER_OR_EQUAL: |
|
24 |
//printf("\t--- Evaluating a %d >= b %d = %d\n",a,b, a>=b); |
|
25 |
return a>=b; |
|
26 |
case LESS: |
|
27 |
//printf("\t--- Evaluating a %d < b %d = %d\n",a,b, a<b); |
|
28 |
return a<b; |
|
29 |
case LESS_OR_EQUAL: |
|
30 |
//printf("\t--- Evaluating a %d <= b %d = %d\n",a,b, a<=b); |
|
31 |
return a<=b; |
|
32 |
default: |
|
33 |
printf("Evaluation gone wrong!\n"); |
|
34 |
return NULL; |
|
35 |
} |
|
36 |
return NULL; |
|
8 | 37 |
} |
9 |
|
|
10 |
int operator_NOT_AND(int a, int b) |
|
11 |
{ |
|
12 |
// if((!a b) || ) |
|
13 |
return 1; |
|
14 |
return 0; |
|
15 |
} |
|
16 |
|
|
17 |
int operator_OR(int a, int b) |
|
18 |
{ |
|
19 |
if(a || b) |
|
20 |
return 1; |
|
21 |
return 0; |
|
22 |
} |
|
23 |
|
|
24 |
int operator_XOR(int a, int b) |
|
25 |
{ |
|
26 |
if((a && !b) || (!a && b)) |
|
27 |
return 1; |
|
28 |
return 0; |
|
29 |
} |
|
30 |
|
|
31 |
int operator_GREATER(int a, int b) |
|
32 |
{ |
|
33 |
if(a > b) |
|
34 |
return 1; |
|
35 |
return 0; |
|
36 |
} |
|
37 |
|
|
38 |
int operator_GREATER_OR_EQUAL (int a, int b) |
|
39 |
{ |
|
40 |
if(a >= b) |
|
41 |
return 1; |
|
42 |
return 0; |
|
43 |
} |
|
44 |
|
|
45 |
int operator_LESS(int a, int b) |
|
46 |
{ |
|
47 |
if(a < b) |
|
48 |
return 1; |
|
49 |
return 0; |
|
50 |
} |
|
51 |
|
|
52 |
int operator_LESS_OR_EQUAL(int a, int b) |
|
53 |
{ |
|
54 |
if(a <= b) |
|
55 |
return 1; |
|
56 |
return 0; |
|
57 |
} |
logic/trunk/src/startup/main.c | ||
---|---|---|
8 | 8 |
#include "../hci_comm/hci_comm.h" |
9 | 9 |
#include "../init/scenariolist.h" |
10 | 10 |
#include "../init/devicelist.h" |
11 |
#include "../logics/device_threads.h" |
|
12 |
#include "../logics/scenario_threads.h" |
|
11 |
//#include "../logics/device_threads.h"
|
|
12 |
//#include "../logics/scenario_threads.h"
|
|
13 | 13 |
#include <stdio.h> |
14 | 14 |
#include <pthread.h> |
15 | 15 |
|
16 | 16 |
// Inter-thread shared variables |
17 | 17 |
// TODO: These variables could be configuration variables |
18 | 18 |
// (eg: static boolean loggingEnabled) |
19 |
scenario *hScenario; //scenario list
|
|
20 |
scenario *hDevice; //device list
|
|
19 |
static device *hDevice; //device list
|
|
20 |
static scenario *hScenario; //scenario list
|
|
21 | 21 |
|
22 |
//extern scenario *test; //device list |
|
23 |
|
|
22 | 24 |
// Crtitical section mutual exclusion security |
23 | 25 |
static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER; |
24 | 26 |
|
25 | 27 |
void *decisionMakingThread_routine(void *dummy); |
26 | 28 |
void *hciConnectionThread_routine(void *dummy); |
29 |
void *randomValThread_routine(void *dummy); |
|
30 |
void *scenarioThread_routine(void *dummy); |
|
27 | 31 |
|
28 | 32 |
// Application entry point |
29 | 33 |
int main(int argc, char *argv[]) { |
... | ... | |
54 | 58 |
// Decision-making thread routine |
55 | 59 |
// Should just call a function that implements decision making module of the logic |
56 | 60 |
void *decisionMakingThread_routine(void *dummy) { |
57 |
printf("decisionMakingThread_routine started\n");
|
|
61 |
printf("-- decisionMakingThread_routine started --\n");
|
|
58 | 62 |
|
59 | 63 |
/**dummy threads for input devices (sensors)**/ |
60 | 64 |
// TODO check for possible BUG involving declaring pthread_t as pointer! |
... | ... | |
114 | 118 |
pthread_exit(0); |
115 | 119 |
} |
116 | 120 |
|
121 |
// scenario thread routine |
|
117 | 122 |
void *scenarioThread_routine(void *dummy) |
118 | 123 |
{ |
119 |
//get device |
|
120 | 124 |
scenario *scen; |
125 |
device *inDev; |
|
126 |
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); |
|
130 |
/*load scenario*/ |
|
121 | 131 |
scen = getAvailableScenario(hScenario); |
122 | 132 |
if(!scen) pthread_exit(0); |
123 | 133 |
|
134 |
// TODO add pointer to this device (all of them actually) to scenario structure - problems with segfault |
|
135 |
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); |
|
124 | 138 |
//set its value |
139 |
//* |
|
125 | 140 |
while(1) //TODO signal == true |
126 | 141 |
{ |
127 |
/**main scenario loop**/ |
|
128 |
printf("Scenario %s updated!\n", scen->scen_id); |
|
129 |
//printf("scenario id %s\n", scen->scen_id); |
|
130 |
sleep(random(100)%10+1); |
|
142 |
/// main scenario loop |
|
143 |
//printf("inDev->buf %.2f\n", 1.0f*inDev->buf); |
|
144 |
if(active) |
|
145 |
sleep(scen->actvChkItv); |
|
146 |
else |
|
147 |
sleep(scen->idleChkItv); |
|
148 |
//checking primary condition |
|
149 |
if(scen_main_buff) // is not null |
|
150 |
{ |
|
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); |
|
153 |
active = 1; |
|
154 |
|
|
155 |
if((scen_main_buff > scen->optval + scen->tolval) || |
|
156 |
(scen_main_buff < scen->optval - scen->tolval)) |
|
157 |
{ |
|
158 |
if(evaluateAdditionalConditions(scen->cond_l, hDevice)) |
|
159 |
printf("Scenario %s updated!\n", scen->scen_id); |
|
160 |
/*TODO calcualte parameters with given function*/ |
|
161 |
/*TODO execute action with parameter(s)*/ |
|
162 |
else |
|
163 |
printf("Scenario %s not updated!\n", scen->scen_id); |
|
164 |
} |
|
165 |
else |
|
166 |
active = 0; |
|
167 |
} |
|
168 |
if(active) |
|
169 |
printf("%s main buffer %.2f, sleeping %d\n",scen->scen_id, scen_main_buff, scen->actvChkItv); |
|
170 |
else |
|
171 |
printf("%s main buffer %.2f, sleeping %d\n",scen->scen_id, scen_main_buff, scen->idleChkItv); |
|
131 | 172 |
} |
173 |
/**/ |
|
132 | 174 |
pthread_exit(0); |
133 | 175 |
} |
134 | 176 |
|
... | ... | |
144 | 186 |
while(1) //TODO signal == true |
145 | 187 |
{ |
146 | 188 |
dev->buf=random(100)%10+20;// random 20-30 |
189 |
//printf("device %s buf = %d\n", dev->id, dev->buf); |
|
147 | 190 |
sleep(dev->readitv); |
148 | 191 |
} |
149 | 192 |
pthread_exit(0); |
150 | 193 |
} |
194 |
|
logic/trunk/src/init/scenariolist.h | ||
---|---|---|
1 | 1 |
#ifndef SCENARIOLIST_H_INCLUDED |
2 | 2 |
#define SCENARIOLIST_H_INCLUDED |
3 | 3 |
|
4 |
#include "devicelist.h" |
|
5 |
|
|
4 | 6 |
typedef struct scenario_s |
5 | 7 |
{ |
6 | 8 |
char *scen_id; |
7 | 9 |
char *scen_name; |
8 | 10 |
char *inDevice_id; |
11 |
device *dev; |
|
9 | 12 |
char *outDevice_id; |
10 | 13 |
char *func; |
11 | 14 |
int idleChkItv; |
12 | 15 |
int actvChkItv; |
13 |
char *params_val; // TBD kaj je to? |
|
16 |
float alpha; |
|
17 |
char *params_val; // TODO kaj je to? |
|
14 | 18 |
int minval; |
15 | 19 |
int maxval; |
16 | 20 |
int optval; |
17 | 21 |
int tolval; |
18 | 22 |
char *action; |
19 | 23 |
char *param; |
24 |
struct condition_list *cond_l; |
|
25 |
// control variables and pointers |
|
20 | 26 |
int status; // 0 - OK, 1 - fault reason 1, 2 - fault reason 2 ... etc. |
21 |
struct condition_list *cond_l; |
|
22 | 27 |
int running; |
23 | 28 |
struct scenario_s *nxt; |
24 | 29 |
}scenario; |
logic/trunk/src/init/devicelist.c | ||
---|---|---|
1 | 1 |
#include "devicelist.h" |
2 | 2 |
#include <string.h> |
3 | 3 |
#include <mxml.h> |
4 |
#include <time.h> |
|
4 | 5 |
|
5 |
device *hDevice; //device list |
|
6 | 6 |
short NUMBER_OF_DEVICES = 0; |
7 | 7 |
|
8 | 8 |
device *setDeviceList() |
... | ... | |
38 | 38 |
|
39 | 39 |
//getting to the correct level of the xml tree (descend 2 levels) |
40 | 40 |
node=node->child->child; |
41 |
// printf("hDevice %d\n", hDevice); |
|
42 | 41 |
|
43 | 42 |
// fill the list of known devices |
44 | 43 |
while(node!=NULL) |
... | ... | |
70 | 69 |
curr->param = (char *)malloc(sizeof(mxml_deviceNode->value.element.attrs->value)*strlen(node->value.element.attrs->value)); |
71 | 70 |
strcpy(curr->param, mxml_deviceNode->value.element.attrs->value); |
72 | 71 |
//printf("param:\t %s\n", curr->param ); |
73 |
|
|
72 |
curr->buf = 0; |
|
74 | 73 |
curr->running = 0; |
75 | 74 |
// moving to the next XML node |
76 | 75 |
node=node->next; |
... | ... | |
93 | 92 |
return NUMBER_OF_DEVICES; |
94 | 93 |
} |
95 | 94 |
|
96 |
// TODO add this func |
|
95 |
device *getDevice1(char *devName) |
|
96 |
{ |
|
97 |
return NULL; |
|
98 |
} |
|
99 |
|
|
100 |
device *getDevice2(device *dev) |
|
101 |
{ |
|
102 |
return NULL; |
|
103 |
} |
|
104 |
|
|
97 | 105 |
device *getDevice(device *dev, char *devName) |
98 | 106 |
{ |
99 |
printf("getDevice(device *dev, char *devName)\n"); |
|
100 |
printf("%s\n",devName); |
|
101 | 107 |
while(dev) |
102 | 108 |
{ |
103 |
printf("loop\n"); |
|
104 |
printf("dev->id %s\n", dev->id); |
|
105 | 109 |
if(0==strcmp(dev->id,devName)) |
106 | 110 |
{ |
107 |
printf("hooking device %s with status %d\n", dev->id, dev->running); |
|
108 | 111 |
return dev; |
109 | 112 |
} |
110 | 113 |
dev=dev->nxt; |
111 | 114 |
} |
112 |
printf("Device not found!\n"); |
|
113 | 115 |
return NULL; |
114 | 116 |
} |
115 | 117 |
|
... | ... | |
120 | 122 |
if(!dev->running) |
121 | 123 |
{ |
122 | 124 |
dev->running = 1; |
123 |
printf("activating device %s with status %d\n", dev->id, dev->running); |
|
125 |
//printf("activating device %s with status %d\n", dev->id, dev->running);
|
|
124 | 126 |
return dev; |
125 | 127 |
} |
126 | 128 |
dev=dev->nxt; |
... | ... | |
128 | 130 |
|
129 | 131 |
return NULL; |
130 | 132 |
} |
133 |
|
|
134 |
int getLocalFormattedTime() |
|
135 |
{ |
|
136 |
// desired format hhmm, 4 digit int; 1430 = 14:30 |
|
137 |
time_t epoch_time; |
|
138 |
struct tm *tm_p; |
|
139 |
int wntForm=0; |
|
140 |
|
|
141 |
epoch_time = time( NULL ); |
|
142 |
tm_p = localtime( &epoch_time ); |
|
143 |
|
|
144 |
return tm_p->tm_hour*100+tm_p->tm_min; |
|
145 |
} |
|
146 |
|
|
131 | 147 |
/* |
132 | 148 |
void updateDeviceList(device_d *deviceList) |
133 | 149 |
{ |
logic/trunk/src/init/scenariolist.c | ||
---|---|---|
1 | 1 |
#include "scenariolist.h" |
2 |
#include "devicelist.h" |
|
2 | 3 |
#include "../logics/conditions.h" |
3 |
#include <string.h> |
|
4 | 4 |
#include <mxml.h> |
5 | 5 |
|
6 |
//extern device *hDevice; //device list |
|
7 |
|
|
6 | 8 |
short NUMBER_OF_SCENARIOS = 0; |
7 | 9 |
|
8 | 10 |
int getOperatorType(char *val) |
... | ... | |
35 | 37 |
{ |
36 | 38 |
cond_lst *cl, *head; |
37 | 39 |
head = NULL; |
38 |
//cl->OPERATOR_TYPE = |
|
40 |
|
|
39 | 41 |
while(node_t) // same level |
40 | 42 |
{ |
41 | 43 |
//printf("operator name: %s\n", node_t->value.opaque); |
42 | 44 |
//* |
43 | 45 |
cl = (cond_lst *)malloc(sizeof(cond_lst)); |
44 | 46 |
|
45 |
/** possible BUG, random pointer values (uncomment this block)
|
|
47 |
//** //possible BUG, random pointer values (uncomment this block)
|
|
46 | 48 |
cl->OPERATOR_TYPE = NULL; |
47 | 49 |
cl->dev = NULL; |
48 | 50 |
cl->nxt_lst = NULL; |
... | ... | |
59 | 61 |
} |
60 | 62 |
else |
61 | 63 |
{ |
62 |
//printf("create leaf\n"); |
|
63 |
cl->dev = (char *)malloc(sizeof(node_t->value.element.attrs->value)*strlen(mxmlElementGetAttr(node_t, "inDeviceId"))); |
|
64 |
cl->dev = mxmlElementGetAttr(node_t, "inDeviceId"); |
|
65 |
//printf("cl->dev %s\n", cl->dev); |
|
66 |
|
|
67 |
(*cl).value = atoi(mxmlElementGetAttr(node_t, "val")); |
|
68 |
//printf("cl->value %d\n", (*cl).value); |
|
64 |
if(mxmlElementGetAttr(node_t, "inDeviceId")) |
|
65 |
{ |
|
66 |
cl->dev = (char *)malloc(sizeof(node_t->value.element.attrs->value)*strlen(mxmlElementGetAttr(node_t, "inDeviceId"))); |
|
67 |
cl->dev = mxmlElementGetAttr(node_t, "inDeviceId"); |
|
68 |
(*cl).value = atoi(mxmlElementGetAttr(node_t, "val")); |
|
69 |
} |
|
69 | 70 |
} |
70 |
|
|
71 | 71 |
node_t=node_t->next; |
72 | 72 |
|
73 | 73 |
cl->nxt_lst = head; |
... | ... | |
144 | 144 |
//printf("idleChkItv:\t %d s\n", curr->idleChkItv ); |
145 | 145 |
|
146 | 146 |
/// int actvChkItv; |
147 |
curr->idleChkItv = atoi(mxmlElementGetAttr(mxml_scenarioNode, "val"));
|
|
147 |
curr->actvChkItv = atoi(mxmlElementGetAttr(mxml_scenarioNode, "val"));
|
|
148 | 148 |
mxml_scenarioNode= mxml_scenarioNode->next; |
149 |
//printf("idleChkItv:\t %d s\n", curr->idleChkItv );
|
|
149 |
//printf("actvChkItv:\t %d s\n", curr->actvChkItv );
|
|
150 | 150 |
|
151 |
/// float alpha; |
|
152 |
curr->alpha = atof(mxmlElementGetAttr(mxml_scenarioNode, "val")); |
|
153 |
mxml_scenarioNode= mxml_scenarioNode->next; |
|
154 |
//printf("actvChkItv:\t %f s\n", curr->alpha ); |
|
155 |
|
|
151 | 156 |
/// char *params_val; // TBD kaj je to? |
152 | 157 |
curr->params_val = (char *)malloc(sizeof(mxml_scenarioNode->value.element.attrs->value)*strlen(mxmlElementGetAttr(mxml_scenarioNode, "val"))); |
153 | 158 |
curr->params_val = mxmlElementGetAttr(mxml_scenarioNode, "val"); |
... | ... | |
187 | 192 |
curr->cond_l = getScenCond(mxml_scenarioNode); |
188 | 193 |
//printf("----------------------------------------------\n"); |
189 | 194 |
|
190 |
//** TEST conditions |
|
191 |
getConditionsResult(curr->cond_l); |
|
192 |
/**/ |
|
193 |
|
|
194 | 195 |
curr->running = 0; |
195 | 196 |
// done |
196 | 197 |
// moving to the next XML node |
logic/trunk/src/init/devicelist.h | ||
---|---|---|
8 | 8 |
int readitv; //in seconds |
9 | 9 |
char *action; |
10 | 10 |
char *param; |
11 |
//d_bufr *buf; |
|
12 | 11 |
int buf; |
13 | 12 |
int running; |
14 | 13 |
struct device_d *nxt; |
15 | 14 |
} device; |
16 | 15 |
|
17 |
int setNewDeviceList(); // ony called on startup |
|
18 |
int getNumberOfDevices(); |
|
16 |
int setNewDeviceList(); // ony called on startup
|
|
17 |
int getNumberOfDevices();
|
|
19 | 18 |
device *getDevice(device *dev, char *devName); |
19 |
device *getDevice1(char *devName); |
|
20 |
device *getDevice2(device *dev); |
|
20 | 21 |
device *getAvailableDevice(device *dev); |
22 |
int getLocalFormattedTime(); |
|
21 | 23 |
|
22 | 24 |
/* |
23 | 25 |
void updateDeviceList(device_d *deviceList); // called on HMI change |
Also available in: Unified diff