Revision 19 logic/trunk/src/init/devicelist.c

View differences:

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
/*

Also available in: Unified diff