Subversion Repositories Projects

Rev

Rev 1559 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1559 Rev 1578
Line 20... Line 20...
20
 
20
 
21
public class ConfigSet {
21
public class ConfigSet {
22
        public static final int NUMBER_OF_VARIABLES = 8;
22
        public static final int NUMBER_OF_VARIABLES = 8;
23
        String name;
23
        String name;
24
        int eepromVersion;
24
        int eepromVersion;
25
       
25
 
26
        List<Section> declaredSections = new ArrayList<Section>();
26
        List<Section> declaredSections = new ArrayList<Section>();
Line 27... Line 27...
27
        List<ConfigEntry> entries = new ArrayList<ConfigEntry>();
27
        List<ConfigEntry> entries = new ArrayList<ConfigEntry>();
28
 
28
 
29
        public static class Section {
29
        public static class Section {
30
                String name, title;
30
                String name, title;
31
                List<ConfigEntry> entries = new ArrayList<ConfigEntry>();
31
                List<ConfigEntry> entries = new ArrayList<ConfigEntry>();
32
               
32
 
33
                public Section(String name, String title) {
33
                public Section(String name, String title) {
34
                        this.name = name;
34
                        this.name = name;
Line 35... Line 35...
35
                        this.title = title;
35
                        this.title = title;
36
                }
36
                }
37
 
37
 
38
                public void addConfigEntry(ConfigEntry e) {
38
                public void addConfigEntry(ConfigEntry e) {
39
                        this.entries.add(e);
39
                        this.entries.add(e);
40
                }
40
                }
41
               
41
 
42
                public List<ConfigEntry> getEntries() {
42
                public List<ConfigEntry> getEntries() {
43
                        return entries;
43
                        return entries;
-
 
44
                }
-
 
45
 
-
 
46
                public String getName() {
44
                }
47
                        return name;
-
 
48
                }
-
 
49
 
45
               
50
                public String getTitle() {
46
                public String getName() { return name; }
51
                        return title;
47
                public String getTitle() { return title; }
52
                }
48
        }
53
        }
Line 49... Line 54...
49
       
54
 
50
        public static abstract class ConfigEntry {
55
        public static abstract class ConfigEntry {
Line 69... Line 74...
69
                public String getSection() {
74
                public String getSection() {
70
                        return name;
75
                        return name;
71
                }
76
                }
72
        }
77
        }
Line 73... Line 78...
73
 
78
 
74
        public static class ByteEntry extends ConfigEntry {
79
        public static class StaticByteEntry extends ConfigEntry {
75
                ByteEntry(String name, boolean isDynamic) {
80
                StaticByteEntry(String name) {
76
                        super(name);
-
 
77
                        this.isDynamic = isDynamic;
81
                        super(name);
Line 78... Line -...
78
                }
-
 
79
 
82
                }
Line 80... Line 83...
80
                boolean isDynamic;
83
 
81
                int value;
84
                int value;
82
 
85
 
Line 97... Line 100...
97
                        return name + ":\t" + value;
100
                        return name + ":\t" + value;
98
                }
101
                }
Line 99... Line 102...
99
 
102
 
100
                void toXML(StringBuilder result) {
103
                void toXML(StringBuilder result) {
-
 
104
                        String s_value;
-
 
105
                        s_value = Integer.toString(value);
-
 
106
                        result.append("  <parameter name=\"" + name + "\" value=\""
-
 
107
                                        + s_value + "\"/>\n");
-
 
108
                }
-
 
109
        }
-
 
110
 
-
 
111
        public static class DynamicByteEntry extends StaticByteEntry {
101
                        String s_value;
112
                int minValue = 0;
-
 
113
                int maxValue = 255;
-
 
114
                String staticCodeName;
-
 
115
                String dynamicCodeName;
-
 
116
               
-
 
117
                DynamicByteEntry(String name) {
-
 
118
                        super(name);
-
 
119
                }
-
 
120
 
-
 
121
                int getMinValue() {
-
 
122
                        return minValue;
-
 
123
                }
-
 
124
 
-
 
125
                int getMaxValue() {
-
 
126
                        return maxValue;
-
 
127
                }
-
 
128
 
-
 
129
                void setMinValue(int minValue) {
-
 
130
                        this.minValue = minValue;
-
 
131
                }
-
 
132
 
-
 
133
                void setMaxValue(int maxValue) {
-
 
134
                        this.maxValue = maxValue;
-
 
135
                }
-
 
136
 
-
 
137
                String getStaticCodeName() {
-
 
138
                        return staticCodeName;
-
 
139
                }
-
 
140
 
-
 
141
                String getDynamicCodeName() {
-
 
142
                        return dynamicCodeName;
-
 
143
                }
-
 
144
 
-
 
145
                void setStaticCodeName(String staticCodeName) {
-
 
146
                        this.staticCodeName = staticCodeName;
-
 
147
                }
-
 
148
 
102
                        int numberOfHighestVariable = 255;
149
                void setDynamicCodeName(String dynamicCodeName) {
-
 
150
                        this.dynamicCodeName = dynamicCodeName;
-
 
151
                }
-
 
152
 
-
 
153
                void toXML(StringBuilder result) {
103
                        int numberOfLowestVariable = numberOfHighestVariable
154
                        String s_value;
104
                                        - NUMBER_OF_VARIABLES;
155
                        int numberOfLowestVariable = 256 - NUMBER_OF_VARIABLES;
105
                        if (isDynamic && value >= numberOfLowestVariable) {
156
                        if (value >= numberOfLowestVariable) {
106
                                s_value = "var" + (value - numberOfLowestVariable);
157
                                s_value = "var" + (value - numberOfLowestVariable);
107
                        } else
158
                        } else
108
                                s_value = Integer.toString(value);
159
                                s_value = Integer.toString(value);
109
                        result.append("  <parameter name=\"" + name + "\" value=\""
160
                        result.append("  <parameter name=\"" + name + "\" value=\""
Line 204... Line 255...
204
        }
255
        }
Line 205... Line 256...
205
 
256
 
206
        public List<Section> getDeclaredSections() {
257
        public List<Section> getDeclaredSections() {
207
                return declaredSections;
258
                return declaredSections;
208
        }
259
        }
209
       
260
 
210
        public void setData(int[] data) {
261
        public void setData(int[] data) {
211
                int offset = 0;
262
                int offset = 0;
212
                for (ConfigEntry entry : entries) {
263
                for (ConfigEntry entry : entries) {
213
                        offset += entry.setValue(data, offset);
264
                        offset += entry.setValue(data, offset);
Line 285... Line 336...
285
                        NodeList sectionNodes = (NodeList) xpath.evaluate(
336
                        NodeList sectionNodes = (NodeList) xpath.evaluate(
286
                                        "/parametertemplate/section", doc, XPathConstants.NODESET);
337
                                        "/parametertemplate/section", doc, XPathConstants.NODESET);
Line 287... Line 338...
287
 
338
 
288
                        for (int i = 0; i < sectionNodes.getLength(); i++) {
339
                        for (int i = 0; i < sectionNodes.getLength(); i++) {
289
                                Element sectionNode = (Element) sectionNodes.item(i);
340
                                Element sectionNode = (Element) sectionNodes.item(i);
-
 
341
                                Section section = new Section(sectionNode.getAttribute("name"),
290
                                Section section = new Section(sectionNode.getAttribute("name"), sectionNode.getAttribute("title"));
342
                                                sectionNode.getAttribute("title"));
291
                                result.declaredSections.add(section);
-
 
292
                       
-
 
293
                        NodeList parameterNodes = (NodeList) xpath.evaluate(
-
 
294
                                        "parameter", sectionNode, XPathConstants.NODESET);
-
 
295
 
-
 
296
                        for (int j=0; j<parameterNodes.getLength(); j++) {
-
 
297
                                Element parameterNode = (Element) parameterNodes.item(j);
-
 
298
 
-
 
299
                                ConfigEntry entry;
-
 
300
                               
-
 
301
                                if (!sectionNode.hasAttribute("name")) {
-
 
302
                                        throw new IOException("A parameter element (the " + j
-
 
303
                                                        + "th in section "+sectionNode.getAttribute("name")+") had no name attribute!");
-
 
Line 304... Line 343...
304
                                }
343
                                result.declaredSections.add(section);
305
 
344
 
Line 306... Line 345...
306
                                String s_name = parameterNode.getAttribute("name");
345
                                NodeList parameterNodes = (NodeList) xpath.evaluate(
307
                                String s_type;
346
                                                "parameter", sectionNode, XPathConstants.NODESET);
308
 
347
 
309
                                if (parameterNode.hasAttribute("type")) {
348
                                for (int j = 0; j < parameterNodes.getLength(); j++) {
310
                                        s_type = parameterNode.getAttribute("type");
-
 
Line 311... Line 349...
311
                                } else {
349
                                        Element parameterNode = (Element) parameterNodes.item(j);
-
 
350
 
-
 
351
                                        ConfigEntry entry;
312
                                        s_type = "static";
352
 
313
                                }
353
                                        if (!sectionNode.hasAttribute("name")) {
-
 
354
                                                throw new IOException("A parameter element (the " + j
-
 
355
                                                                + "th in section "
314
 
356
                                                                + sectionNode.getAttribute("name")
-
 
357
                                                                + ") had no name attribute!");
-
 
358
                                        }
315
                                if ("static".equals(s_type)) {
359
 
316
                                        entry = new ConfigSet.ByteEntry(s_name, false);
360
                                        String s_name = parameterNode.getAttribute("name");
-
 
361
                                        String s_type;
317
                                } else if ("dynamic".equals(s_type)) {
362
 
-
 
363
                                        if (parameterNode.hasAttribute("type")) {
-
 
364
                                                s_type = parameterNode.getAttribute("type");
318
                                        entry = new ConfigSet.ByteEntry(s_name, true);
365
                                        } else {
319
                                } else if ("bitset".equals(s_type)) {
366
                                                s_type = "static";
320
                                        NodeList bitNodes = (NodeList) xpath.evaluate("bit", parameterNode, XPathConstants.NODESET);
367
                                        }
-
 
368
 
321
                                        String[] bitNames = new String[8];
369
                                        if ("static".equals(s_type)) {
-
 
370
                                                entry = new ConfigSet.StaticByteEntry(s_name);
322
                                        for (int k=0; k<8; k++) {
371
                                        } else if ("dynamic".equals(s_type)) {
323
                                                Element bitNode = (Element) bitNodes.item(k);
372
                                                ConfigSet.DynamicByteEntry de = new ConfigSet.DynamicByteEntry(s_name);
-
 
373
                                                if (parameterNode.hasAttribute("minValue")) {
324
                                                if (bitNode != null) {
374
                                                        de.setMinValue(Integer.parseInt(parameterNode.getAttribute("minValue")));
-
 
375
                                                }
-
 
376
                                                if (parameterNode.hasAttribute("maxValue")) {
-
 
377
                                                        de.setMinValue(Integer.parseInt(parameterNode.getAttribute("maxValue")));
-
 
378
                                                }
-
 
379
                                                if (parameterNode.hasAttribute("staticCodeName")) {
-
 
380
                                                        de.setStaticCodeName(parameterNode.getAttribute("staticCodeName"));
-
 
381
                                                } else de.setStaticCodeName(de.getName());
-
 
382
                                                if (parameterNode.hasAttribute("dynamicCodeName")) {
-
 
383
                                                        de.setDynamicCodeName(parameterNode.getAttribute("dynamicCodeName"));
-
 
384
                                                } else de.setDynamicCodeName(de.getName());
-
 
385
                                                entry = de;
-
 
386
                                        } else if ("bitset".equals(s_type)) {
-
 
387
                                                NodeList bitNodes = (NodeList) xpath.evaluate("bit",
-
 
388
                                                                parameterNode, XPathConstants.NODESET);
-
 
389
                                                String[] bitNames = new String[8];
-
 
390
                                                for (int k = 0; k < 8; k++) {
-
 
391
                                                        Element bitNode = (Element) bitNodes.item(k);
-
 
392
                                                        if (bitNode != null) {
-
 
393
                                                                bitNames[k] = bitNode.getAttribute("name");
-
 
394
                                                        } else {
-
 
395
                                                                bitNames[k] = "Unused";
-
 
396
                                                        }
-
 
397
                                                }
325
                                                        bitNames[k] = bitNode.getAttribute("name");
398
                                                entry = new ConfigSet.BitSetEntry(s_name, bitNames);
-
 
399
                                        } else {
326
                                                } else {
400
                                                throw new IOException("Unknown parameter type: "
327
                                                        bitNames[k] = "Unused";
-
 
328
                                                }
401
                                                                + s_type);
329
                                        }
402
                                        }
330
                                        entry = new ConfigSet.BitSetEntry(s_name, bitNames);
-
 
331
                                } else {
-
 
332
                                        throw new IOException("Unknown parameter type: " + s_type);
-
 
333
                                }
-
 
334
                               
403
 
335
                                result.entries.add(entry);
404
                                        result.entries.add(entry);
336
                                section.addConfigEntry(entry);
405
                                        section.addConfigEntry(entry);
337
                        }
406
                                }
338
                        }
407
                        }
Line 346... Line 415...
346
                        throw new IOException(ex);
415
                        throw new IOException(ex);
347
                } catch (ParserConfigurationException ex) {
416
                } catch (ParserConfigurationException ex) {
348
                        throw new IOException(ex);
417
                        throw new IOException(ex);
349
                }
418
                }
350
        }
419
        }
-
 
420
 
-
 
421
        public String generateDynamicSubstitutionCode() {
-
 
422
                StringBuilder result = new StringBuilder(
-
 
423
                                "const MMXLATION XLATIONS[] = {\n");
-
 
424
                boolean hasEntries = false;
-
 
425
                for (ConfigEntry entry : entries) {
-
 
426
                        if (entry instanceof ConfigSet.DynamicByteEntry) {
-
 
427
                                if (hasEntries)
-
 
428
                                        result.append(",\n");
-
 
429
                                else
-
 
430
                                        hasEntries = true;
-
 
431
                                ConfigSet.DynamicByteEntry de = (ConfigSet.DynamicByteEntry) entry;
-
 
432
                                result.append("{offsetof(ParamSet_t, ");
-
 
433
                                result.append(de.getStaticCodeName());
-
 
434
                                result.append("), offsetof(DynamicParams_t, ");
-
 
435
                                result.append(de.getDynamicCodeName());
-
 
436
                                result.append("),");
-
 
437
                                result.append(Integer.toString(de.getMinValue()));
-
 
438
                                result.append(",");
-
 
439
                                result.append(Integer.toString(de.getMaxValue()));
-
 
440
                                result.append("}");
-
 
441
                        }
-
 
442
                }
-
 
443
                result.append("};");
-
 
444
                return result.toString();
-
 
445
        }
351
}
446
}
352
447