Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1611 | - | 1 | package dongfang.mkt.configuration; |
2 | |||
3 | import java.io.IOException; |
||
4 | import java.util.ArrayList; |
||
5 | import java.util.List; |
||
6 | |||
7 | public abstract class ConfigurationSet { |
||
8 | public static final int NUMBER_OF_VARIABLES = 8; |
||
9 | |||
10 | protected int eepromVersion; |
||
11 | protected List<ParameterEntry> entries = new ArrayList<ParameterEntry>(); |
||
12 | |||
13 | public ConfigurationSet() { |
||
14 | super(); |
||
15 | } |
||
16 | |||
17 | public List<ParameterEntry> getEntries() { |
||
18 | return entries; |
||
19 | } |
||
20 | |||
21 | protected abstract int correctLengthToExcludeName(int length); |
||
22 | protected abstract void setName(int[] data, int offset); |
||
23 | protected abstract void outputName(StringBuilder sb); |
||
24 | |||
25 | public void setData(int[] data) throws IOException { |
||
26 | int offset = 0; |
||
27 | int dataLength = correctLengthToExcludeName(data.length); |
||
28 | if (dataLength != getByteCount()) { |
||
29 | throw new IOException("The received number of databytes (" + dataLength + ") was not equal to the length of the declared parameter set(" + getByteCount()+")."); |
||
30 | } |
||
31 | |||
32 | for (ParameterEntry entry : entries) { |
||
33 | offset += entry.setValue(data, offset); |
||
34 | } |
||
35 | |||
36 | setName(data, offset); |
||
37 | } |
||
38 | |||
39 | public int getByteCount() { |
||
40 | int result = 0; |
||
41 | for (ParameterEntry e : entries) { |
||
42 | result += e.getByteCount(); |
||
43 | } |
||
44 | return result; |
||
45 | } |
||
46 | |||
47 | public String toStringWithValues() { |
||
48 | StringBuilder result = new StringBuilder(); |
||
49 | outputName(result); |
||
50 | for (ParameterEntry entry : entries) { |
||
51 | result.append(entry.toStringWithValues() + "\n"); |
||
52 | } |
||
53 | return result.toString(); |
||
54 | } |
||
55 | |||
56 | public String generateDynamicSubstitutionCode() { |
||
57 | StringBuilder result = new StringBuilder( |
||
58 | "const MMXLATION XLATIONS[] = {\n"); |
||
59 | boolean hasEntries = false; |
||
60 | for (ParameterEntry entry : entries) { |
||
61 | if (entry instanceof DynamicByteEntry) { |
||
62 | if (hasEntries) |
||
63 | result.append(",\n"); |
||
64 | else |
||
65 | hasEntries = true; |
||
66 | DynamicByteEntry de = (DynamicByteEntry) entry; |
||
67 | result.append("{offsetof(ParamSet_t, "); |
||
68 | result.append(de.getStaticCodeName()); |
||
69 | result.append("), offsetof(DynamicParams_t, "); |
||
70 | result.append(de.getDynamicCodeName()); |
||
71 | result.append("),"); |
||
72 | result.append(Integer.toString(de.getMinValue())); |
||
73 | result.append(","); |
||
74 | result.append(Integer.toString(de.getMaxValue())); |
||
75 | result.append("}"); |
||
76 | } |
||
77 | } |
||
78 | result.append("};"); |
||
79 | return result.toString(); |
||
80 | } |
||
81 | |||
82 | } |