Revision 19

View differences:

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

  
5 6
device *hDevice; //device list
6 7

  
7
void setDeviceList()
8
int setDeviceList()
8 9
{
9 10
    device *curr, *head;
10 11
    head = NULL;
......
12 13
    FILE *fp;
13 14
    mxml_node_t *tree, *node;
14 15

  
15
	fp = fopen("devicetree.xml", "r"); //TODO !hardcoded
16
	if(fp = fopen("./src/init/devicetree.xml", "r")) //TODO !hardcoded
17
	{
18
        printf("File read!\n");
19
	}
20
	else
21
        printf("Error!");
22

  
16 23
	tree = mxmlLoadFile(NULL, fp, MXML_IGNORE_CALLBACK);
17 24
	node = tree;
18 25
	fclose(fp);
......
30 37
    /**/
31 38
    //getting to the correct level of the xml tree (descend 2 levels)
32 39
    node=node->child->child;
33
    printf("hDevice %d\n", hDevice);
40
    // printf("hDevice %d\n", hDevice);
34 41

  
35 42
    // fill the list of known devices
36
    // sorry for the ugly chunk of code, but I had to allocate memory
43
    //      sorry for the ugly chunk of code, but I had to allocate memory
37 44
    // for each string separately in order to keep it scalable
38 45
    while(node!=NULL)
39 46
    {
......
50 57
        strcpy(curr->name, mxml_deviceNode->value.element.attrs->value);
51 58
            mxml_deviceNode= mxml_deviceNode->next;
52 59

  
53
        curr->minval= atoi(mxml_deviceNode->value.element.attrs->value);
60
        curr->readitv = atoi(mxml_deviceNode->value.element.attrs->value);
54 61
            mxml_deviceNode= mxml_deviceNode->next;
55 62

  
56
        curr->maxval= atoi(mxml_deviceNode->value.element.attrs->value);
57
            mxml_deviceNode= mxml_deviceNode->next;
58

  
59 63
        curr->action = (char *)malloc(sizeof(mxml_deviceNode->value.element.attrs->value));
60 64
        strcpy(curr->action, mxml_deviceNode->value.element.attrs->value);
61 65
            mxml_deviceNode= mxml_deviceNode->next;
......
63 67
        curr->param = (char *)malloc(sizeof(mxml_deviceNode->value.element.attrs->value));
64 68
        strcpy(curr->param, mxml_deviceNode->value.element.attrs->value);
65 69
        // done
70
        // TODO create buffer
71
        curr->buf = init_buf((int)(HISTORY_LENGTH/curr->readitv));
72

  
73
        //printf("curr buf_size %d\n", curr->buf->buffer_size);
74
        //printf("curr buf_load %d\n", curr->buf->buffer_load);
75
        //printf("buf_pos %d\n", &curr->buf);
76
        //*
77
        int num;
78
        buf_put(10, curr->buf);
79
        //printf("num %d\n",*curr->buf->start_el );
80
        buf_get(&num, curr->buf);
81
        printf("num %d\n",num);
82
        /**/
66 83
        // moving to the next XML node
67 84
        node=node->next;
68 85

  
......
72 89
    //delete obsolete xml tree
73 90
    mxmlDelete(tree);
74 91
    mxmlDelete(node);
75
    /*
92
    //*
76 93
    // TODO delete - test
77 94
    hDevice=head;
78 95
    curr=head;
79 96
    printf("test device list\n");
80
    //*
97
    /*
98
    // DEBUG
81 99
    while(curr)
82 100
    {
83 101
        printf("name:\t %s\n", curr->name );
84 102
        printf("id:\t %s\n", curr->id );
85
        printf("minval:\t %d\n", curr->minval );
86
        printf("maxval:\t %d\n", curr->maxval );
103
        printf("readitv:\t %d s\n", curr->readitv );
87 104
        printf("action:\t %s\n", curr->action );
88 105
        printf("param:\t %s\n", curr->param );
89 106
        curr=curr->nxt;
90 107
    }
91 108
    /**/
109
    return 1;
92 110
}
93 111

  
94 112
/*
logic/trunk/src/init/devicetree.xml
2 2
<devicetree>
3 3
    <device id="thermometer_01">
4 4
        <name nam="Thermometer"></name>
5
        <minvalue minval="18"></minvalue>
6
        <maxvalue maxval="27"></maxvalue>
5
        <read_interval rditv="10"/>
7 6
        <action act="testAction_1"></action>
8 7
        <param par="testParam_1"></param>
9 8
    </device>
10 9
    <device id="barometer_01">
11 10
        <name nam="Barometer"></name>
12
        <minvalue minval="18"></minvalue>
13
        <maxvalue maxval="27"></maxvalue>
11
        <read_interval rditv="20"/>
14 12
        <action act="testAction_2"></action>
15 13
        <param par="testParam_2"></param>
16 14
    </device>
17 15
    <device id="hygrometer_01">
18 16
        <name nam="Hygrometer"></name>
19
        <minvalue minval="18"></minvalue>
20
        <maxvalue maxval="27"></maxvalue>
17
        <read_interval rditv="30"/>
21 18
        <action act="testAction_3"></action>
22 19
        <param par="testParam_3"></param>
23 20
    </device>
24 21
    <device id="light_sensor_01">
25 22
        <name nam="Light sensor"></name>
26
        <minvalue minval="18"></minvalue>
27
        <maxvalue maxval="27"></maxvalue>
23
        <read_interval rditv="1"/>
28 24
        <action act="testAction_4"></action>
29 25
        <param par="testParam_4"></param>
30 26
    </device>
31 27
    <device id="smart_meter_01">
32 28
        <name nam="Smart meter"></name>
33
        <minvalue minval="18"></minvalue>
34
        <maxvalue maxval="27"></maxvalue>
29
        <read_interval rditv="3"/>
35 30
        <action act="testAction_5"></action>
36 31
        <param par="testParam_5"></param>
37 32
    </device>
logic/trunk/src/init/devicelist.h
1 1
#ifndef DEVICELIST_H_INCLUDED
2 2
#define DEVICELIST_H_INCLUDED
3

  
4
// in seconds, history for each sensor is at most 600 seconds old
5
// TODO maybe this isn't the best idea, perhaps every sensor needs different length of history
6
#define HISTORY_LENGTH 600
7

  
8
#include "buf.h"
3 9

  
4 10
//struct device_d ; /* Forward declaration */
5 11

  
......
7 13
{
8 14
    char    *name;
9 15
    char    *id;
10
    int     minval;
11
    int     maxval;
16
    int     readitv; //in seconds
12 17
    char    *action;
13 18
    char    *param;
19
    d_bufr  *buf;
14 20
    //TODO add circular buffer for each device
15 21
    struct  device_d *nxt;
16 22
}device;
17 23

  
18
void setNewDeviceList(); // ony called on startup
24
int setNewDeviceList(); // ony called on startup
19 25
/*
20 26
void updateDeviceList(device_d *deviceList); // called on HMI change
21 27
char *getDeviceName();

Also available in: Unified diff