2 BCU SDK bcu development enviroment
3 Copyright (C) 2005-2011 Martin Koegler <mkoegler@auto.tuwien.ac.at>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "xmlwriteappinfo.h"
21 #include <libxml/tree.h>
23 static char buf
[4096];
26 a (xmlNodePtr p
, const char *name
, const char *val
)
28 xmlNewProp (p
, (const xmlChar
*) name
, (const xmlChar
*) val
);
34 return xmlNewNode (0, (const xmlChar
*) name
);
38 nc (xmlNodePtr parent
, const char *name
, const char *val
)
40 return xmlNewTextChild (parent
, 0, (const xmlChar
*) name
,
41 (const xmlChar
*) val
);
45 GenDeviceDesc (const Device
& d
)
47 xmlNodePtr n
= nn ("Description");
48 sprintf (buf
, "%04X", d
.MaskVersion
);
49 nc (n
, "MaskVersion", buf
);
50 nc (n
, "Title", d
.Title ());
52 nc (n
, "AddInfo", d
.AddInfo ());
54 nc (n
, "OrderNo", d
.OrderNo ());
55 if (d
.Manufacturer ())
56 nc (n
, "Manufacturer", d
.Manufacturer ());
58 nc (n
, "Category", d
.Category ());
60 nc (n
, "Author", d
.Author ());
62 nc (n
, "Copyright", d
.Copyright ());
67 GenInterface (const Interface
& d
)
73 xmlNodePtr n
= nn ("Interface");
75 sprintf (buf
, "%0.3f", d
.DPType
);
76 nc (n
, "DPType", buf
);
77 if (d
.Abbreviation ())
78 nc (n
, "Abbreviation", d
.Abbreviation ());
80 nc (n
, "Title", d
.Title ());
82 nc (n
, "AddInfo", d
.AddInfo ());
84 nc (n
, "GroupTitle", d
.GroupTitle ());
85 if (d
.InvisibleIf_lineno
)
86 nc (n
, "InvisibleIf", printExpression (d
.InvisibleIf
) ());
88 for (int i
= 0; i
< d
.References (); i
++)
91 a (p
, "idref", d
.References
[i
] ());
104 GenFunctionalBlock (const FunctionalBlock
& d
)
110 xmlNodePtr n
= nn ("FunctionalBlock");
111 a (n
, "id", d
.ID ());
112 sprintf (buf
, "%d", d
.ProfileID
);
113 nc (n
, "ProfileID", buf
);
114 nc (n
, "Title", d
.Title ());
116 nc (n
, "AddInfo", d
.AddInfo ());
117 for (int i
= 0; i
< d
.Interfaces (); i
++)
119 p
= GenInterface (d
.Interfaces
[i
]);
133 GenGroupObject (const GroupObject
& d
)
137 xmlNodePtr n
= nn ("GroupObject");
138 a (n
, "id", d
.ID ());
139 nc (n
, "Title", d
.Title ());
141 nc (n
, "AddInfo", d
.AddInfo ());
142 sprintf (buf
, "%d", d
.Type
);
143 nc (n
, "GroupType", buf
);
144 nc (n
, "Sending", d
.Sending
? "true" : "false");
145 nc (n
, "Receiving", d
.Receiving
? "true" : "false");
146 nc (n
, "Reading", d
.Reading
? "true" : "false");
147 nc (n
, "StateBased", d
.StateBased
? "true" : "false");
152 GenProperty (const Property
& d
, itype objindex
)
156 xmlNodePtr n
= nn ("Property");
157 a (n
, "id", d
.ID ());
158 nc (n
, "Title", d
.Title ());
160 nc (n
, "AddInfo", d
.AddInfo ());
161 sprintf (buf
, "%d", d
.Type
);
162 nc (n
, "PropertyType", buf
);
164 sprintf (buf
, "%d", objindex
);
165 nc (n
, "ObjectIndex", buf
);
166 sprintf (buf
, "%d", d
.PropertyID
);
167 nc (n
, "PropertyId", buf
);
169 nc (n
, "Writeable", d
.Writeable
? "true" : "false");
170 sprintf (buf
, "%d", d
.MaxArrayLength
);
171 nc (n
, "MaxArrayLength", buf
);
177 GenPollingMaster (const PollingMaster
& d
)
181 xmlNodePtr n
= nn ("PollingMaster");
182 a (n
, "id", d
.ID ());
183 nc (n
, "Title", d
.Title ());
185 nc (n
, "AddInfo", d
.AddInfo ());
191 GenPollingSlave (const PollingSlave
& d
)
195 xmlNodePtr n
= nn ("PollingSlave");
196 a (n
, "id", d
.ID ());
197 nc (n
, "Title", d
.Title ());
199 nc (n
, "AddInfo", d
.AddInfo ());
205 GenListParameter (const ListParameter
& d
)
210 xmlNodePtr n
= nn ("ListParameter");
211 a (n
, "id", d
.ID ());
212 nc (n
, "Title", d
.Title ());
214 nc (n
, "AddInfo", d
.AddInfo ());
216 p
= nn ("ListDefault");
217 a (p
, "idref", d
.ListDefault ());
219 for (int i
= 0; i
< d
.ListElements (); i
++)
221 p
= nc (n
, "ListElement", d
.ListElements
[i
].Value ());
222 a (p
, "id", d
.ListElements
[i
].Name ());
225 nc (n
, "Unit", d
.Unit ());
230 GenIntParameter (const IntParameter
& d
)
234 xmlNodePtr n
= nn ("IntParameter");
235 a (n
, "id", d
.ID ());
236 nc (n
, "Title", d
.Title ());
238 nc (n
, "AddInfo", d
.AddInfo ());
239 sprintf (buf
, "%d", d
.MinValue
);
240 nc (n
, "MinValue", buf
);
241 sprintf (buf
, "%d", d
.MaxValue
);
242 nc (n
, "MaxValue", buf
);
243 sprintf (buf
, "%d", d
.Default
);
244 nc (n
, "Default", buf
);
246 nc (n
, "Unit", d
.Unit ());
247 if (d
.Precision_lineno
)
249 sprintf (buf
, "%d", d
.Precision
);
250 nc (n
, "Precision", buf
);
252 if (d
.Increment_lineno
)
254 sprintf (buf
, "%d", d
.Increment
);
255 nc (n
, "Increment", buf
);
261 GenFloatParameter (const FloatParameter
& d
)
265 xmlNodePtr n
= nn ("FloatParameter");
266 a (n
, "id", d
.ID ());
267 nc (n
, "Title", d
.Title ());
269 nc (n
, "AddInfo", d
.AddInfo ());
270 sprintf (buf
, "%f", d
.MinValue
);
271 nc (n
, "MinValue", buf
);
272 sprintf (buf
, "%f", d
.MaxValue
);
273 nc (n
, "MaxValue", buf
);
274 sprintf (buf
, "%f", d
.Default
);
275 nc (n
, "Default", buf
);
277 nc (n
, "Unit", d
.Unit ());
278 if (d
.Precision_lineno
)
280 sprintf (buf
, "%f", d
.Precision
);
281 nc (n
, "Precision", buf
);
283 if (d
.Increment_lineno
)
285 sprintf (buf
, "%f", d
.Increment
);
286 nc (n
, "Increment", buf
);
293 GenStringParameter (const StringParameter
& d
)
297 xmlNodePtr n
= nn ("StringParameter");
298 a (n
, "id", d
.ID ());
299 nc (n
, "Title", d
.Title ());
301 nc (n
, "AddInfo", d
.AddInfo ());
303 nc (n
, "Default", d
.Default ());
305 nc (n
, "RegExp", d
.RegExp ());
306 sprintf (buf
, "%d", d
.MaxLength
);
307 nc (n
, "MaxLength", buf
);
309 nc (n
, "Unit", d
.Unit ());
315 GenParameters (const Device
& d
)
320 xmlNodePtr n
= nn ("Parameter");
321 for (i
= 0; i
< d
.ListParameters (); i
++)
323 p
= GenListParameter (d
.ListParameters
[i
]);
325 xmlAddChild (n
, p
), cnt
++;
327 for (i
= 0; i
< d
.IntParameters (); i
++)
329 p
= GenIntParameter (d
.IntParameters
[i
]);
331 xmlAddChild (n
, p
), cnt
++;
333 for (i
= 0; i
< d
.FloatParameters (); i
++)
335 p
= GenFloatParameter (d
.FloatParameters
[i
]);
337 xmlAddChild (n
, p
), cnt
++;
339 for (i
= 0; i
< d
.StringParameters (); i
++)
341 p
= GenStringParameter (d
.StringParameters
[i
]);
343 xmlAddChild (n
, p
), cnt
++;
354 GenChild (xmlNodePtr n
, const Device
& d
)
359 for (i
= 0, j
= 0; i
< d
.FunctionalBlocks (); i
++)
361 p
= GenFunctionalBlock (d
.FunctionalBlocks
[i
]);
363 xmlAddChild (n
, p
), j
++;
366 die (_("no functional block with enabled interfaces"));
367 for (i
= 0; i
< d
.GroupObjects (); i
++)
369 p
= GenGroupObject (d
.GroupObjects
[i
]);
373 for (i
= 0; i
< d
.Objects (); i
++)
375 if (!d
.Objects
[i
].ObjectIndex
)
377 for (j
= 0; j
< d
.Objects
[i
].Propertys (); j
++)
380 GenProperty (d
.Objects
[i
].Propertys
[j
], d
.Objects
[i
].ObjectIndex
);
385 for (i
= 0; i
< d
.PollingMasters (); i
++)
387 p
= GenPollingMaster (d
.PollingMasters
[i
]);
391 for (i
= 0; i
< d
.PollingSlaves (); i
++)
393 p
= GenPollingSlave (d
.PollingSlaves
[i
]);
398 p
= GenParameters (d
);
404 WriteAppInfo (const Device
* d
, const char *file
)
410 die (_("no device defined"));
413 doc
= xmlNewDoc ((const xmlChar
*) "1.0");
414 xmlCreateIntSubset (doc
, (const xmlChar
*) "DeviceDesc", NULL
,
416 "http://www.auto.tuwien.ac.at/~mkoegler/eib/xml/appinfo.dtd");
417 root
= xmlNewNode (NULL
, (const xmlChar
*) "DeviceDesc");
418 xmlDocSetRootElement (doc
, root
);
420 a (root
, "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
421 a (root
, "xsi:schemaLocation",
422 "http://www.auto.tuwien.ac.at/~mkoegler/eib/appinfo.xsd");
424 "http://www.auto.tuwien.ac.at/~mkoegler/eib/xml/appinfo.xsd");
425 a (root
, "version", "0.0.0");
427 nc (root
, "ProgramID", d
->ProgramID ());
428 xmlAddChild (root
, GenDeviceDesc (*d
));
433 if (xmlSaveFormatFileEnc (file
, doc
, "UTF-8", 1) < 0)
434 die (_("write to %s failed"), file
);