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