Revision 30

View differences:

logic/trunk/src/init/scenarios.xml
1
<?xml version="1.0"?>
2
<scenariotree>
3
    <scenario id="ac_01">
4
        <name nam="Air Conditioner"/>
5
        <minvalue minval="18"/>
6
        <maxvalue maxval="27"/>
7
	<optimal_value optVal="23"/>
8
	<idle_check_interval ici="600"/>
9
	<active_check_interval aci="600"/>
10
	<sensors chk_dev1="thermometer_01" chk_dev2="thermometer_01"/>
11
	...
12
	<reaction_function fr="linear"/>
13
        <action act="testAction_1"/>
14
        <param par="testParam_1"/>
15
    </scenario>
16
</scenariotree>
17

  
18
name
19
action path
20
param
21
idle check interval (s)
22
active check interval (s)
23
influence devices
24
reaction values //treba razdelat
25
function type //static (on - off), linear, log etc. (kako se spreminja moč na intervalu)
26

  
logic/trunk/src/init/scenariolist.c
1
#include "scenariolist.h"
2
#include "../logics/conditions.h"
3
#include <string.h>
4
#include <mxml.h>
5

  
6

  
7

  
8
scenario *hScenario; //scenario list
9

  
10
//parseScenCondLeaf()
11
//parseScenCondNode()
12

  
13
cond_lst *parseScenCond()
14
{
15
    return NULL;
16
}
17

  
18
int setNewScenarioList() // ony called on startup
19
{
20
    //TODO vedno preverjaj, ce so vse naprave, ki jih uporabljas, prisotne! npr. termometer mora biti v device list-u
21
    scenario *curr, *head;
22
    head = NULL;
23

  
24
    FILE *fp;
25
    mxml_node_t *tree, *node;
26

  
27
	if(fp = fopen("./src/init/scenariotree.xml", "r")) //TODO !hardcoded
28
	{
29
        printf("File read!\n");
30
        //TODO replace with syslog error
31
	}
32
	else
33
        printf("Error!");
34
        //TODO replace with syslog error
35

  
36
	tree = mxmlLoadFile(NULL, fp, MXML_IGNORE_CALLBACK);
37
	node = tree;
38
	fclose(fp);
39

  
40
    /* //structure of XML tree
41
    ?xml
42
      |
43
    devicetree
44
      |
45
    dev1 - dev2 - ...
46
      |      |
47
      |      |
48
      |     ID - name - minvalue - maxvalue - action - param
49
    ID - name - minvalue - maxvalue - action - param
50
    /**/
51
    //getting to the correct level of the xml tree (descend 2 levels)
52
    node=node->child->child;
53
    // printf("hDevice %d\n", hDevice);
54

  
55
    // fill the list of known devices
56
    //      sorry for the ugly chunk of code, but I had to allocate memory
57
    // for each string separately in order to keep it scalable
58
    while(node!=NULL)
59
    {
60
        curr = (scenario *)malloc(sizeof(scenario));
61

  
62
        /// char    *scen_id;
63
        curr->scen_id = (char *)malloc(sizeof(node->value.element.attrs->value)*strlen(mxmlElementGetAttr(node, "id")));
64
        curr->scen_id = mxmlElementGetAttr(node, "id"); // possible BUG, perhaps use strcpy here!
65
        printf("id:\t %s\n", curr->scen_id );
66

  
67
        /// char    *scen_name;
68
        curr->scen_name = (char *)malloc(sizeof(node->value.element.attrs->value)*strlen(mxmlElementGetAttr(node, "name")));
69
        curr->scen_name = mxmlElementGetAttr(node, "name"); // possible BUG, perhaps use strcpy here!
70
        printf("scenario name:\t %s\n", curr->scen_name);
71

  
72
        // getting data for individual scenario
73
        mxml_node_t *mxml_scenarioNode;
74
        mxml_scenarioNode=node->child;
75

  
76
        /// char    *inDevice_id;
77
        curr->inDevice_id = (char *)malloc(sizeof(mxml_scenarioNode->value.element.attrs->value)*strlen(mxmlElementGetAttr(mxml_scenarioNode, "id")));
78
        curr->inDevice_id = mxmlElementGetAttr(mxml_scenarioNode, "id");
79
            mxml_scenarioNode = mxml_scenarioNode->next;
80
        printf("inDevice_id:\t %s\n", curr->inDevice_id );
81

  
82
        /// char    *outDevice_id;
83
        curr->outDevice_id = (char *)malloc(sizeof(mxml_scenarioNode->value.element.attrs->value)*strlen(mxmlElementGetAttr(mxml_scenarioNode, "id")));
84
        curr->outDevice_id = mxmlElementGetAttr(mxml_scenarioNode, "id");
85
            mxml_scenarioNode = mxml_scenarioNode->next;
86
        printf("outDevice_id:\t %s\n", curr->outDevice_id );
87

  
88
        /// char    *func;
89
        curr->func = (char *)malloc(sizeof(mxml_scenarioNode->value.element.attrs->value)*strlen(mxmlElementGetAttr(mxml_scenarioNode, "func")));
90
        curr->func = mxmlElementGetAttr(mxml_scenarioNode, "func");
91
            mxml_scenarioNode = mxml_scenarioNode->next;
92
        printf("func:\t %s\n", curr->func );
93

  
94
        /// int     idleChkItv;
95
        curr->idleChkItv = atoi(mxmlElementGetAttr(mxml_scenarioNode, "val"));
96
            mxml_scenarioNode= mxml_scenarioNode->next;
97
        printf("idleChkItv:\t %d s\n", curr->idleChkItv );
98

  
99
        /// int     actvChkItv;
100
        curr->idleChkItv = atoi(mxmlElementGetAttr(mxml_scenarioNode, "val"));
101
            mxml_scenarioNode= mxml_scenarioNode->next;
102
        printf("idleChkItv:\t %d s\n", curr->idleChkItv );
103

  
104
        /// char    *params_val;    // TBD kaj je to?
105
        curr->params_val = (char *)malloc(sizeof(mxml_scenarioNode->value.element.attrs->value)*strlen(mxmlElementGetAttr(mxml_scenarioNode, "val")));
106
        curr->params_val = mxmlElementGetAttr(mxml_scenarioNode, "val");
107
            mxml_scenarioNode = mxml_scenarioNode->next;
108
        printf("params_val:\t %s\n", curr->params_val );
109

  
110
        /// int     minval;
111
        curr->minval = atoi(mxmlElementGetAttr(mxml_scenarioNode, "minval"));
112
        printf("minval:\t %d\n", curr->minval );
113

  
114
        /// int     maxval;
115
        curr->maxval = atoi(mxmlElementGetAttr(mxml_scenarioNode, "maxval"));
116
        printf("maxval:\t %d\n", curr->maxval );
117

  
118
        /// int     optval;
119
        curr->optval = atoi(mxmlElementGetAttr(mxml_scenarioNode, "optval"));
120
        printf("optval:\t %d\n", curr->optval );
121

  
122
        /// int     tolval;
123
        curr->tolval = atoi(mxmlElementGetAttr(mxml_scenarioNode, "tolerance"));
124
            mxml_scenarioNode = mxml_scenarioNode->next;
125
        printf("tolval:\t %d\n", curr->tolval );
126

  
127
        /// char    *action;
128
        curr->action = (char *)malloc(sizeof(mxml_scenarioNode->value.element.attrs->value)*strlen(mxmlElementGetAttr(mxml_scenarioNode, "act")));
129
        curr->action = mxmlElementGetAttr(mxml_scenarioNode, "act");
130
            mxml_scenarioNode = mxml_scenarioNode->next;
131
        printf("action:\t %s\n", curr->action );
132

  
133
        /// char    *param;
134
        curr->param = (char *)malloc(sizeof(mxml_scenarioNode->value.element.attrs->value)*strlen(mxmlElementGetAttr(mxml_scenarioNode, "par")));
135
        curr->param = mxmlElementGetAttr(mxml_scenarioNode, "par");
136
            mxml_scenarioNode = mxml_scenarioNode->next;
137
        printf("param:\t %s\n", curr->param );
138

  
139
        // TODO parse struct cond
140

  
141
        printf("----------------------------------------------\n");
142
        // done
143
        // moving to the next XML node
144
        node=node->next;
145

  
146
        /// struct  scenario_s *nxt;
147
        curr->nxt = head;
148
        head = curr;
149
    }
150

  
151
    hScenario=head; // handle to device list
152
    //delete obsolete xml tree
153
    mxmlDelete(tree);
154
    mxmlDelete(node);
155

  
156
    return 1;
157
}
158

  
159
/*
160
void updateDeviceList(device_d *deviceList)
161
{
162

  
163
}
164
/**/
logic/trunk/src/init/scenariotree.xml
1
<?xml version="1.0"?>
2
<scenariotree>
3
  <scenario id="scenario_01" name="Klima na stropu, w/e">
4
    <inDevice id="thermometer_01" />
5
    <outDevice id="air_cond_01" />
6
    <reaction func="linear" />
7
    <check_idle val="600" />
8
    <check_active val="60" />
9
    <params val="--lazy=true" />
10
    <inDevAalues minval="20" maxval="28" optval="24" tolerance="0.5"/>
11
    <action act="testAction_1"/>
12
    <param par="testParam_1"/>
13
    <conditions>
14
      <and>
15
        <greater inDeviceId="barometer_01" val="80" />
16
        <lower_or_equal inDeviceId="lightSensor" val="50" />
17
        <or>
18
          <greater inDeviceId="time" val="15:00" />
19
          <smaller inDeviceId="time" val="10:00" />
20
        </or>
21
      </and>
22
    </conditions>
23
  </scenario>
24
    <scenario id="scenario_02" name="Klima v kleti, w/e">
25
    <inDevice id="thermometer_01" />
26
    <outDevice id="air_cond_01" />
27
    <reaction func="linear" />
28
    <check_idle val="600" />
29
    <check_active val="60" />
30
    <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"/>
34
    <conditions>
35
      <and>
36
        <greater inDeviceId="barometer_01" val="80" />
37
        <lower_or_equal inDeviceId="lightSensor" val="50" />
38
        <or>
39
          <greater inDeviceId="time" val="15:00" />
40
          <smaller inDeviceId="time" val="10:00" />
41
        </or>
42
      </and>
43
    </conditions>
44
  </scenario>
45
</scenariotree>
logic/trunk/src/init/scenariolist.h
1
#ifndef SCENARIOLIST_H_INCLUDED
2
#define SCENARIOLIST_H_INCLUDED
3

  
4
typedef struct scenario_s
5
{
6
    char    *scen_id;
7
    char    *scen_name;
8
    char    *inDevice_id;
9
    char    *outDevice_id;
10
    char    *func;
11
    int     idleChkItv;
12
    int     actvChkItv;
13
    char    *params_val;    // TBD kaj je to?
14
    int     minval;
15
    int     maxval;
16
    int     optval;
17
    int     tolval;
18
    char    *action;
19
    char    *param;
20
    struct  condition_list *cond_l;
21
    // struct cond
22
    struct  scenario_s *nxt;
23
}scenario;
24

  
25
int setNewScenarioList(); // ony called on startup
26
// update scenario list
27
// get scenario (id)
28
// ...
29
#endif // SCENARIOLIST_H_INCLUDED

Also available in: Unified diff