root / logic / trunk / src / init / devicelist.c @ 26
History | View | Annotate | Download (4.04 KB)
1 | 10 | Janez1 | #include "devicelist.h" |
---|---|---|---|
2 | 19 | Janez1 | //#include "buf.h"
|
3 | 10 | Janez1 | #include <string.h> |
4 | #include <mxml.h> |
||
5 | |||
6 | device *hDevice; //device list
|
||
7 | |||
8 | 19 | Janez1 | int setDeviceList()
|
9 | 10 | Janez1 | { |
10 | device *curr, *head; |
||
11 | head = NULL;
|
||
12 | |||
13 | FILE *fp; |
||
14 | mxml_node_t *tree, *node; |
||
15 | |||
16 | 19 | Janez1 | if(fp = fopen("./src/init/devicetree.xml", "r")) //TODO !hardcoded |
17 | { |
||
18 | printf("File read!\n");
|
||
19 | } |
||
20 | else
|
||
21 | printf("Error!");
|
||
22 | |||
23 | 10 | Janez1 | tree = mxmlLoadFile(NULL, fp, MXML_IGNORE_CALLBACK);
|
24 | node = tree; |
||
25 | fclose(fp); |
||
26 | |||
27 | /* //structure of XML tree
|
||
28 | ?xml
|
||
29 | |
|
||
30 | devicetree
|
||
31 | |
|
||
32 | dev1 - dev2 - ...
|
||
33 | | |
|
||
34 | | |
|
||
35 | | ID - name - minvalue - maxvalue - action - param
|
||
36 | ID - name - minvalue - maxvalue - action - param
|
||
37 | /**/
|
||
38 | //getting to the correct level of the xml tree (descend 2 levels)
|
||
39 | node=node->child->child; |
||
40 | 19 | Janez1 | // printf("hDevice %d\n", hDevice);
|
41 | 10 | Janez1 | |
42 | // fill the list of known devices
|
||
43 | 19 | Janez1 | // sorry for the ugly chunk of code, but I had to allocate memory
|
44 | 10 | Janez1 | // for each string separately in order to keep it scalable
|
45 | while(node!=NULL) |
||
46 | { |
||
47 | 26 | Janez1 | printf("ime: %s\n", node->value.element.attrs->value);
|
48 | printf("size pointer: %d\n", sizeof(node->value.element.attrs->value)); |
||
49 | printf("size string: %d\n", strlen(node->value.element.attrs->value));
|
||
50 | printf("alociraj: %d\n", sizeof(node->value.element.attrs->value)*strlen(node->value.element.attrs->value)); |
||
51 | printf("----------------------------------------------\n");
|
||
52 | /*
|
||
53 | 10 | Janez1 | curr = (device *)malloc(sizeof(device));
|
54 | |||
55 | curr->id = (char *)malloc(sizeof(node->value.element.attrs->value));
|
||
56 | strcpy(curr->id, node->value.element.attrs->value);
|
||
57 | 24 | Janez1 | printf("id:\t %s\n", curr->id );
|
58 | 26 | Janez1 | /**/
|
59 | 25 | Janez1 | /*
|
60 | 10 | Janez1 | // getting data for individual device
|
61 | mxml_node_t *mxml_deviceNode;
|
||
62 | mxml_deviceNode=node->child;
|
||
63 | //TODO malloc()
|
||
64 | curr->name = (char *)malloc(sizeof(mxml_deviceNode->value.element.attrs->value));
|
||
65 | strcpy(curr->name, mxml_deviceNode->value.element.attrs->value);
|
||
66 | mxml_deviceNode= mxml_deviceNode->next;
|
||
67 | 24 | Janez1 | printf("name:\t %s\n", curr->name );
|
68 | 10 | Janez1 | |
69 | 19 | Janez1 | curr->readitv = atoi(mxml_deviceNode->value.element.attrs->value);
|
70 | 10 | Janez1 | mxml_deviceNode= mxml_deviceNode->next;
|
71 | 24 | Janez1 | printf("readitv:\t %d s\n", curr->readitv );
|
72 | 10 | Janez1 | |
73 | curr->action = (char *)malloc(sizeof(mxml_deviceNode->value.element.attrs->value));
|
||
74 | strcpy(curr->action, mxml_deviceNode->value.element.attrs->value);
|
||
75 | mxml_deviceNode= mxml_deviceNode->next;
|
||
76 | 24 | Janez1 | printf("action:\t %s\n", curr->action );
|
77 | 10 | Janez1 | |
78 | curr->param = (char *)malloc(sizeof(mxml_deviceNode->value.element.attrs->value));
|
||
79 | strcpy(curr->param, mxml_deviceNode->value.element.attrs->value);
|
||
80 | 24 | Janez1 | printf("param:\t %s\n", curr->param );
|
81 | |||
82 | 10 | Janez1 | // done
|
83 | 23 | Janez1 | /*
|
84 | 24 | Janez1 | // TA DEL KODE V TEM KOMENTARJU NE BO UPORABLJEN, IGNORE!
|
85 | 19 | Janez1 | // TODO create buffer
|
86 | curr->buf = init_buf((int)(HISTORY_LENGTH/curr->readitv));
|
||
87 | 23 | Janez1 | // -------------- buffer test-----------------------------!
|
88 | 19 | Janez1 | //printf("curr buf_size %d\n", curr->buf->buffer_size);
|
89 | //printf("curr buf_load %d\n", curr->buf->buffer_load);
|
||
90 | //printf("buf_pos %d\n", &curr->buf);
|
||
91 | //*
|
||
92 | int num;
|
||
93 | buf_put(10, curr->buf);
|
||
94 | //printf("num %d\n",*curr->buf->start_el );
|
||
95 | buf_get(&num, curr->buf);
|
||
96 | printf("num %d\n",num);
|
||
97 | 23 | Janez1 | // -------------- buffer test end-------------------------!
|
98 | 19 | Janez1 | /**/
|
99 | 10 | Janez1 | // moving to the next XML node
|
100 | node=node->next; |
||
101 | |||
102 | curr->nxt = head; |
||
103 | head = curr; |
||
104 | } |
||
105 | //delete obsolete xml tree
|
||
106 | mxmlDelete(tree); |
||
107 | mxmlDelete(node); |
||
108 | 25 | Janez1 | /*
|
109 | 10 | Janez1 | // TODO delete - test
|
110 | hDevice=head;
|
||
111 | curr=head;
|
||
112 | printf("test device list\n");
|
||
113 | 19 | Janez1 | // DEBUG
|
114 | 10 | Janez1 | while(curr)
|
115 | {
|
||
116 | printf("name:\t %s\n", curr->name );
|
||
117 | printf("id:\t %s\n", curr->id );
|
||
118 | 19 | Janez1 | printf("readitv:\t %d s\n", curr->readitv );
|
119 | 10 | Janez1 | printf("action:\t %s\n", curr->action );
|
120 | printf("param:\t %s\n", curr->param );
|
||
121 | curr=curr->nxt;
|
||
122 | }
|
||
123 | /**/
|
||
124 | 19 | Janez1 | return 1; |
125 | 10 | Janez1 | } |
126 | |||
127 | /*
|
||
128 | void updateDeviceList(device_d *deviceList)
|
||
129 | {
|
||
130 | |||
131 | }
|
||
132 | /**/ |