├── A2LParser
├── .classpath
├── .gitignore
├── .project
├── .settings
│ ├── .gitignore
│ └── org.eclipse.jdt.core.prefs
├── SurfacePlotter.jar
├── images
│ ├── A2L.png
│ ├── ASCII.png
│ ├── AXIS.png
│ ├── COMPAR_A2L_24.png
│ ├── COMPAR_VTAB_24.png
│ ├── COMPU_METHOD.png
│ ├── CONVERSION_TABLE.png
│ ├── CURVE.png
│ ├── FLAT_MAP_24.png
│ ├── FUNCTION.png
│ ├── INCONNU.png
│ ├── INFO_24.png
│ ├── IN_MEASUREMENT.png
│ ├── LOC_MEASUREMENT.png
│ ├── MAP.png
│ ├── MEASUREMENT.png
│ ├── OPEN_A2L_24.png
│ ├── OPEN_DATA_24.png
│ ├── OUT_MEASUREMENT.png
│ ├── RECORD_LAYOUT.png
│ ├── SCALAIRE.png
│ ├── VALUEBLOCK.png
│ └── WARNING_24.png
└── src
│ ├── a2l
│ ├── A2l.java
│ ├── A2lObject.java
│ ├── A2lObjectParsingException.java
│ ├── A2lStateListener.java
│ ├── A2lUtils.java
│ ├── AdjustableObject.java
│ ├── Annotation.java
│ ├── ArrayValue.java
│ ├── AxisDescr.java
│ ├── AxisPts.java
│ ├── Characteristic.java
│ ├── CompuMethod.java
│ ├── CompuTab.java
│ ├── CompuVTab.java
│ ├── CompuVTabRange.java
│ ├── ConversionTable.java
│ ├── DataValue.java
│ ├── DisplayIdentifier.java
│ ├── FixAxisPar.java
│ ├── FixAxisParDist.java
│ ├── FixAxisParList.java
│ ├── Format.java
│ ├── Function.java
│ ├── Group.java
│ ├── Measurement.java
│ ├── ModCommon.java
│ ├── ModPar.java
│ ├── OptionalParameterRL.java
│ ├── RecordLayout.java
│ ├── RecordLayout_old.java
│ ├── SingleValue.java
│ ├── SystemConstant.java
│ ├── TableModelView.java
│ └── Unit.java
│ ├── constante
│ ├── AdressType.java
│ ├── ConversionType.java
│ ├── DataSize.java
│ ├── DataType.java
│ ├── DepositMode.java
│ ├── IndexMode.java
│ ├── IndexOrder.java
│ ├── PrimaryKeywords.java
│ ├── SecondaryKeywords.java
│ └── UnitType.java
│ ├── data
│ ├── DataCalibration.java
│ ├── DataDecoder.java
│ ├── IntelHex.java
│ ├── Memory.java
│ └── MotorolaS19.java
│ ├── gui
│ ├── A2lDisplayer.java
│ ├── DisplayLog.java
│ ├── DisplayLog_Bis.java
│ ├── FilteredTree.java
│ ├── FilteredTreeModel.java
│ ├── Ihm.java
│ ├── Main.java
│ ├── SurfaceChart.java
│ ├── TableView.java
│ └── TextSearchTest.java
│ └── utils
│ ├── Converter.java
│ ├── Interpolation.java
│ ├── NumeralString.java
│ └── ParserUtils.java
└── README.md
/A2LParser/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/A2LParser/.gitignore:
--------------------------------------------------------------------------------
1 | /bin/
2 |
--------------------------------------------------------------------------------
/A2LParser/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | AsamCalTool
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.sonarlint.eclipse.core.sonarlintBuilder
15 |
16 |
17 |
18 |
19 |
20 | org.eclipse.jdt.core.javanature
21 |
22 |
23 |
--------------------------------------------------------------------------------
/A2LParser/.settings/.gitignore:
--------------------------------------------------------------------------------
1 | /org.sonarlint.eclipse.core.prefs
2 |
--------------------------------------------------------------------------------
/A2LParser/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6 | org.eclipse.jdt.core.compiler.compliance=1.8
7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate
8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate
9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
11 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
12 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
13 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
14 | org.eclipse.jdt.core.compiler.release=enabled
15 | org.eclipse.jdt.core.compiler.source=1.8
16 |
--------------------------------------------------------------------------------
/A2LParser/SurfacePlotter.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sanglinard26/AsamCalTool/abfb49a9c8e5825f4dfc7f2debb9616e58cfb6cb/A2LParser/SurfacePlotter.jar
--------------------------------------------------------------------------------
/A2LParser/images/A2L.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sanglinard26/AsamCalTool/abfb49a9c8e5825f4dfc7f2debb9616e58cfb6cb/A2LParser/images/A2L.png
--------------------------------------------------------------------------------
/A2LParser/images/ASCII.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sanglinard26/AsamCalTool/abfb49a9c8e5825f4dfc7f2debb9616e58cfb6cb/A2LParser/images/ASCII.png
--------------------------------------------------------------------------------
/A2LParser/images/AXIS.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sanglinard26/AsamCalTool/abfb49a9c8e5825f4dfc7f2debb9616e58cfb6cb/A2LParser/images/AXIS.png
--------------------------------------------------------------------------------
/A2LParser/images/COMPAR_A2L_24.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sanglinard26/AsamCalTool/abfb49a9c8e5825f4dfc7f2debb9616e58cfb6cb/A2LParser/images/COMPAR_A2L_24.png
--------------------------------------------------------------------------------
/A2LParser/images/COMPAR_VTAB_24.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sanglinard26/AsamCalTool/abfb49a9c8e5825f4dfc7f2debb9616e58cfb6cb/A2LParser/images/COMPAR_VTAB_24.png
--------------------------------------------------------------------------------
/A2LParser/images/COMPU_METHOD.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sanglinard26/AsamCalTool/abfb49a9c8e5825f4dfc7f2debb9616e58cfb6cb/A2LParser/images/COMPU_METHOD.png
--------------------------------------------------------------------------------
/A2LParser/images/CONVERSION_TABLE.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sanglinard26/AsamCalTool/abfb49a9c8e5825f4dfc7f2debb9616e58cfb6cb/A2LParser/images/CONVERSION_TABLE.png
--------------------------------------------------------------------------------
/A2LParser/images/CURVE.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sanglinard26/AsamCalTool/abfb49a9c8e5825f4dfc7f2debb9616e58cfb6cb/A2LParser/images/CURVE.png
--------------------------------------------------------------------------------
/A2LParser/images/FLAT_MAP_24.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sanglinard26/AsamCalTool/abfb49a9c8e5825f4dfc7f2debb9616e58cfb6cb/A2LParser/images/FLAT_MAP_24.png
--------------------------------------------------------------------------------
/A2LParser/images/FUNCTION.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sanglinard26/AsamCalTool/abfb49a9c8e5825f4dfc7f2debb9616e58cfb6cb/A2LParser/images/FUNCTION.png
--------------------------------------------------------------------------------
/A2LParser/images/INCONNU.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sanglinard26/AsamCalTool/abfb49a9c8e5825f4dfc7f2debb9616e58cfb6cb/A2LParser/images/INCONNU.png
--------------------------------------------------------------------------------
/A2LParser/images/INFO_24.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sanglinard26/AsamCalTool/abfb49a9c8e5825f4dfc7f2debb9616e58cfb6cb/A2LParser/images/INFO_24.png
--------------------------------------------------------------------------------
/A2LParser/images/IN_MEASUREMENT.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sanglinard26/AsamCalTool/abfb49a9c8e5825f4dfc7f2debb9616e58cfb6cb/A2LParser/images/IN_MEASUREMENT.png
--------------------------------------------------------------------------------
/A2LParser/images/LOC_MEASUREMENT.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sanglinard26/AsamCalTool/abfb49a9c8e5825f4dfc7f2debb9616e58cfb6cb/A2LParser/images/LOC_MEASUREMENT.png
--------------------------------------------------------------------------------
/A2LParser/images/MAP.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sanglinard26/AsamCalTool/abfb49a9c8e5825f4dfc7f2debb9616e58cfb6cb/A2LParser/images/MAP.png
--------------------------------------------------------------------------------
/A2LParser/images/MEASUREMENT.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sanglinard26/AsamCalTool/abfb49a9c8e5825f4dfc7f2debb9616e58cfb6cb/A2LParser/images/MEASUREMENT.png
--------------------------------------------------------------------------------
/A2LParser/images/OPEN_A2L_24.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sanglinard26/AsamCalTool/abfb49a9c8e5825f4dfc7f2debb9616e58cfb6cb/A2LParser/images/OPEN_A2L_24.png
--------------------------------------------------------------------------------
/A2LParser/images/OPEN_DATA_24.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sanglinard26/AsamCalTool/abfb49a9c8e5825f4dfc7f2debb9616e58cfb6cb/A2LParser/images/OPEN_DATA_24.png
--------------------------------------------------------------------------------
/A2LParser/images/OUT_MEASUREMENT.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sanglinard26/AsamCalTool/abfb49a9c8e5825f4dfc7f2debb9616e58cfb6cb/A2LParser/images/OUT_MEASUREMENT.png
--------------------------------------------------------------------------------
/A2LParser/images/RECORD_LAYOUT.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sanglinard26/AsamCalTool/abfb49a9c8e5825f4dfc7f2debb9616e58cfb6cb/A2LParser/images/RECORD_LAYOUT.png
--------------------------------------------------------------------------------
/A2LParser/images/SCALAIRE.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sanglinard26/AsamCalTool/abfb49a9c8e5825f4dfc7f2debb9616e58cfb6cb/A2LParser/images/SCALAIRE.png
--------------------------------------------------------------------------------
/A2LParser/images/VALUEBLOCK.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sanglinard26/AsamCalTool/abfb49a9c8e5825f4dfc7f2debb9616e58cfb6cb/A2LParser/images/VALUEBLOCK.png
--------------------------------------------------------------------------------
/A2LParser/images/WARNING_24.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Sanglinard26/AsamCalTool/abfb49a9c8e5825f4dfc7f2debb9616e58cfb6cb/A2LParser/images/WARNING_24.png
--------------------------------------------------------------------------------
/A2LParser/src/a2l/A2lObject.java:
--------------------------------------------------------------------------------
1 | package a2l;
2 |
3 | import java.util.List;
4 |
5 | public interface A2lObject {
6 |
7 | void build(List parameters, int beginLine, int endLine) throws A2lObjectParsingException;
8 |
9 | boolean isValid();
10 |
11 | String getProperties();
12 | }
13 |
--------------------------------------------------------------------------------
/A2LParser/src/a2l/A2lObjectParsingException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 24 avr. 2019
3 | */
4 | package a2l;
5 |
6 | public final class A2lObjectParsingException extends IllegalArgumentException {
7 |
8 | private static final long serialVersionUID = 1L;
9 |
10 | public A2lObjectParsingException(String message, int beginLine, int endLine) {
11 | super(String.format("%s between line %d and %d", message, beginLine, endLine));
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/A2LParser/src/a2l/A2lStateListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 14 janv. 2020
3 | */
4 | package a2l;
5 |
6 | import java.util.EventListener;
7 |
8 | public interface A2lStateListener extends EventListener {
9 |
10 | void stateChange(String state);
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/A2LParser/src/a2l/A2lUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 8 janv. 2020
3 | */
4 | package a2l;
5 |
6 | import java.io.BufferedReader;
7 | import java.io.File;
8 | import java.io.FileNotFoundException;
9 | import java.io.FileReader;
10 | import java.io.IOException;
11 | import java.io.PrintWriter;
12 | import java.nio.file.Files;
13 | import java.util.ArrayList;
14 | import java.util.Arrays;
15 | import java.util.Collections;
16 | import java.util.List;
17 | import java.util.Vector;
18 |
19 | public final class A2lUtils {
20 |
21 | private static final String RAMCELL = "[RAMCELL]";
22 | private static final String LABEL = "[Label]";
23 |
24 | public static final void writeMeasurementLab(File file, Function function) {
25 |
26 | try (PrintWriter pw = new PrintWriter(file)) {
27 |
28 | final List listMeasurement = new ArrayList<>();
29 | listMeasurement.addAll(function.getInMeasurement());
30 | listMeasurement.addAll(function.getLocMeasurement());
31 | listMeasurement.addAll(function.getOutMeasurement());
32 |
33 | Collections.sort(listMeasurement);
34 |
35 | pw.println(RAMCELL);
36 | for (String measurementName : listMeasurement) {
37 | pw.println(measurementName);
38 | }
39 |
40 | } catch (FileNotFoundException e) {
41 | e.printStackTrace();
42 | }
43 | }
44 |
45 | public static final void writeAllMeasurementLab(File file, A2l a2l) {
46 |
47 | try (PrintWriter pw = new PrintWriter(file)) {
48 |
49 | final Vector listMeasurement = a2l.getListMeasurement();
50 |
51 | pw.println(RAMCELL);
52 | for (Measurement measurementName : listMeasurement) {
53 | pw.println(measurementName);
54 | }
55 |
56 | } catch (FileNotFoundException e) {
57 | e.printStackTrace();
58 | }
59 | }
60 |
61 | public static final void writeCharacteristicLab(File file, A2l a2l, Function function) {
62 |
63 | try (PrintWriter pw = new PrintWriter(file)) {
64 | final Vector listCharacteristic = a2l.getAdjustableObjectNameByFunction(function.toString());
65 | listCharacteristic.addAll(function.getRefCharacteristic());
66 |
67 | Collections.sort(listCharacteristic);
68 |
69 | pw.println(LABEL);
70 | for (String characteristicName : listCharacteristic) {
71 | pw.println(characteristicName);
72 | }
73 |
74 | } catch (FileNotFoundException e) {
75 | e.printStackTrace();
76 | }
77 | }
78 |
79 | public static final void linkPrototypeAxis(Object a2lObject, File selectedFile) {
80 |
81 | A2l a2l = (A2l) a2lObject;
82 |
83 | try (BufferedReader br = new BufferedReader(new FileReader(selectedFile))) {
84 | String line;
85 | Vector prototypeAxis = new Vector();
86 |
87 | while ((line = br.readLine()) != null) {
88 | prototypeAxis.add(line.substring(0, line.length() - 1));
89 | }
90 |
91 | Vector v = a2l.getAdjustableObjectFromList(prototypeAxis);
92 | System.out.println(v);
93 |
94 | File newFile = new File(selectedFile.getAbsolutePath().replace(".lab", "_Linked.lab"));
95 |
96 | try (PrintWriter pw = new PrintWriter(newFile)) {
97 |
98 | pw.println("[Label]");
99 |
100 | for (AdjustableObject axis : v) {
101 | if (axis instanceof AxisPts) {
102 | pw.println(axis.toString() + "b");
103 | for (Characteristic s : ((AxisPts) axis).getCharacteristicsDependency()) {
104 | pw.println(s + "b");
105 | }
106 | }
107 | }
108 |
109 | } catch (FileNotFoundException e) {
110 | e.printStackTrace();
111 | }
112 |
113 | } catch (FileNotFoundException e) {
114 | e.printStackTrace();
115 | } catch (IOException e) {
116 | e.printStackTrace();
117 | }
118 | }
119 |
120 | public static final List searchFId(Object a2lObject, String FIdName) {
121 | A2l a2l = (A2l) a2lObject;
122 |
123 | Vector objects = a2l.getListAdjustableObjects();
124 | List foundObject = new ArrayList<>();
125 |
126 | for (AdjustableObject object : objects) {
127 | if (object instanceof Characteristic) {
128 | Characteristic characteristic = (Characteristic) object;
129 | if (characteristic.hasData() && characteristic.name.startsWith("DINH_FId")) {
130 | ArrayValue values = (ArrayValue) characteristic.getValues();
131 | int idx = Arrays.binarySearch(values.getValues(), FIdName);
132 | if (idx > -1) {
133 | foundObject.add(characteristic.name);
134 | }
135 | }
136 | }
137 | }
138 |
139 | return foundObject;
140 | }
141 |
142 | public static final void checkMEIBloc(Object a2lObject, File selectedFile) {
143 |
144 | A2l a2l = (A2l) a2lObject;
145 |
146 | try (BufferedReader br = new BufferedReader(new FileReader(selectedFile))) {
147 | String line;
148 | Vector measurements = new Vector();
149 | Vector characteristics = new Vector();
150 |
151 | boolean bMeasurement = true;
152 |
153 | while ((line = br.readLine()) != null) {
154 | if ("[MEASUREMENT]".equals(line) || "[CHARACTERISTIC]".equals(line)) {
155 |
156 | if ("[CHARACTERISTIC]".equals(line)) {
157 | bMeasurement = !bMeasurement;
158 | }
159 |
160 | line = br.readLine();
161 | }
162 |
163 | if (bMeasurement) {
164 | measurements.add(line);
165 | } else {
166 | characteristics.add(line);
167 | }
168 | }
169 |
170 | Vector m = a2l.getMeasurementNameFromList(measurements);
171 | measurements.removeAll(m);
172 |
173 | Vector c = a2l.getAdjustableObjectNameFromList(characteristics);
174 | characteristics.removeAll(c);
175 |
176 | File newFile = new File(selectedFile.getAbsolutePath().replace(".txt", "_checked.txt"));
177 |
178 | try (PrintWriter pw = new PrintWriter(newFile)) {
179 |
180 | pw.println("[MEASUREMENT]");
181 | for (String measure : measurements) {
182 | pw.println(measure);
183 | }
184 |
185 | pw.println("[CHARACTERISTIC]");
186 | for (String characteristic : characteristics) {
187 | pw.println(characteristic);
188 | }
189 |
190 | } catch (FileNotFoundException e) {
191 | e.printStackTrace();
192 | }
193 |
194 | } catch (FileNotFoundException e) {
195 | e.printStackTrace();
196 | } catch (IOException e) {
197 | e.printStackTrace();
198 | }
199 |
200 | }
201 |
202 | public static final File getZResolutionFromLab(Object a2lObject, File labFile) {
203 | A2l a2l = (A2l) a2lObject;
204 |
205 | try {
206 | List listLabel = Files.readAllLines(labFile.toPath());
207 | Vector v = new Vector<>(listLabel);
208 | Vector listObj = a2l.getAdjustableObjectFromList(v);
209 |
210 | File newFile = new File(labFile.getAbsolutePath().replace(".lab", "_withResol.lab"));
211 |
212 | try (PrintWriter pw = new PrintWriter(newFile)) {
213 |
214 | for (AdjustableObject obj : listObj) {
215 | pw.println(obj.name + "\t" + obj.getZResolution());
216 | }
217 |
218 | return newFile;
219 |
220 | } catch (FileNotFoundException e) {
221 | e.printStackTrace();
222 | }
223 |
224 | } catch (IOException e) {
225 | // TODO Auto-generated catch block
226 | e.printStackTrace();
227 | }
228 | return null;
229 |
230 | }
231 |
232 | public static void checkMeasurementFromLab(Object a2lObject, File selectedFile) {
233 | A2l a2l = (A2l) a2lObject;
234 |
235 | Vector measurements = a2l.getListMeasurement();
236 | Vector a2lsupp = new Vector<>();
237 |
238 | for (Measurement measurement : measurements) {
239 | a2lsupp.add(measurement.toString());
240 | }
241 |
242 | try (BufferedReader br = new BufferedReader(new FileReader(selectedFile))) {
243 | String line;
244 | Vector slddMeasurements = new Vector();
245 |
246 | while ((line = br.readLine()) != null) {
247 | if ("[RAMCELL]".equals(line)) {
248 | continue;
249 | }
250 | slddMeasurements.add(line);
251 | }
252 |
253 | // a2lsupp.removeAll(slddMeasurements);
254 | slddMeasurements.removeAll(a2lsupp);
255 |
256 | File newFile = new File(selectedFile.getAbsolutePath().replace(".lab", "_checked.txt"));
257 |
258 | try (PrintWriter pw = new PrintWriter(newFile)) {
259 |
260 | pw.println("Flux supplémentaires dans les SLDD:");
261 | for (String measure : slddMeasurements) {
262 | pw.println(measure);
263 | }
264 |
265 | } catch (FileNotFoundException e) {
266 | e.printStackTrace();
267 | }
268 |
269 | } catch (FileNotFoundException e) {
270 | e.printStackTrace();
271 | } catch (IOException e) {
272 | e.printStackTrace();
273 | }
274 |
275 | }
276 |
277 | }
278 |
--------------------------------------------------------------------------------
/A2LParser/src/a2l/AdjustableObject.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 2 avr. 2019
3 | */
4 | package a2l;
5 |
6 | import static constante.SecondaryKeywords.BYTE_ORDER;
7 | import static constante.SecondaryKeywords.DISPLAY_IDENTIFIER;
8 | import static constante.SecondaryKeywords.FORMAT;
9 | import static constante.SecondaryKeywords.READ_ONLY;
10 |
11 | import java.nio.ByteOrder;
12 | import java.text.DecimalFormat;
13 | import java.text.DecimalFormatSymbols;
14 | import java.util.HashMap;
15 | import java.util.Map;
16 | import java.util.Map.Entry;
17 |
18 | import a2l.AxisDescr.Attribute;
19 | import a2l.Characteristic.CharacteristicType;
20 | import constante.DataType;
21 | import constante.PrimaryKeywords;
22 | import constante.SecondaryKeywords;
23 |
24 | public abstract class AdjustableObject implements A2lObject, Comparable {
25 |
26 | protected String name;
27 | protected char[] longIdentifier;
28 | protected long adress;
29 | protected int depositId;
30 | protected float maxDiff;
31 | protected int conversionId;
32 | protected float lowerLimit;
33 | protected float upperLimit;
34 |
35 | protected boolean validParsing;
36 |
37 | protected String functionRef;
38 |
39 | protected DataValue values;
40 |
41 | protected Map optionalsParameters;
42 |
43 | protected CompuMethod compuMethod;
44 | protected RecordLayout recordLayout;
45 |
46 | @Override
47 | public final int compareTo(AdjustableObject o) {
48 | return this.name.compareToIgnoreCase(o.toString());
49 | }
50 |
51 | public final int getID() {
52 | return this.name.hashCode();
53 | }
54 |
55 | public final long getAdress() {
56 | return adress;
57 | }
58 |
59 | public final CompuMethod getCompuMethod() {
60 | return compuMethod;
61 | }
62 |
63 | public final String getConverionTable() {
64 | ConversionTable convTable = compuMethod.getConvTable();
65 |
66 | if (convTable != null) {
67 | StringBuilder sb = new StringBuilder();
68 |
69 | Map, ?> mapConv = convTable.getMap();
70 |
71 | for (Entry, ?> entry : mapConv.entrySet()) {
72 | sb.append("" + entry.getKey() + " => " + entry.getValue() + "\n");
73 | }
74 |
75 | return sb.toString();
76 | }
77 | return "";
78 | }
79 |
80 | public final RecordLayout getRecordLayout() {
81 | return recordLayout;
82 | }
83 |
84 | public final String getFunction() {
85 | return this.functionRef;
86 | }
87 |
88 | public final boolean assignRecordLayout(HashMap recordLayouts) {
89 | this.recordLayout = recordLayouts.get(this.depositId);
90 | if (this.recordLayout != null) {
91 | return true;
92 | }
93 | return false;
94 | }
95 |
96 | public final byte getNbDecimal() {
97 | Object objectDisplayFormat = optionalsParameters.get(FORMAT);
98 | Format displayFormat;
99 |
100 | if (!compuMethod.isVerbal()) {
101 | if (objectDisplayFormat == null) {
102 | displayFormat = compuMethod.getFormat();
103 | } else {
104 | displayFormat = (Format) objectDisplayFormat;
105 | }
106 | return displayFormat.getDecimalesPlace();
107 | }
108 | return 0;
109 | }
110 |
111 | public final ByteOrder getByteOrder() {
112 | String sByteOrder = (String) optionalsParameters.get(BYTE_ORDER);
113 | if (sByteOrder != null) {
114 | if ("MSB_LAST".equals(sByteOrder) || "BIG_ENDIAN".equals(sByteOrder)) {
115 | return ByteOrder.LITTLE_ENDIAN;
116 | }
117 | return ByteOrder.BIG_ENDIAN;
118 | }
119 | return null;
120 | }
121 |
122 | public final String getDisplayIdentifier() {
123 | char[] dispIdentifier = (char[]) optionalsParameters.get(DISPLAY_IDENTIFIER);
124 | if (dispIdentifier != null) {
125 | return String.valueOf(dispIdentifier);
126 | }
127 | return "";
128 | }
129 |
130 | public final String getDimension() {
131 | StringBuilder stringDimension = new StringBuilder();
132 | if (this instanceof AxisPts) {
133 | stringDimension.append("[" + ((AxisPts) this).getMaxAxisPoints() + " x 1]");
134 | } else {
135 | Characteristic characteristic = (Characteristic) this;
136 |
137 | stringDimension.append("[");
138 | if (values != null) {
139 | if (characteristic.getType().compareTo(CharacteristicType.VALUE) == 0) {
140 | stringDimension.append("1 x 1");
141 | } else if (characteristic.getType().compareTo(CharacteristicType.CURVE) == 0) {
142 | stringDimension.append(values.getDimX() + " x 2");
143 | } else {
144 | stringDimension.append((values.getDimX() - 1) + " x " + (values.getDimY() - 1));
145 | }
146 | } else {
147 | stringDimension.append("? x ?");
148 | }
149 | stringDimension.append("]");
150 |
151 | if (characteristic.getType().compareTo(CharacteristicType.CURVE) == 0) {
152 | int dimMaxX = characteristic.getAxisDescrs()[0].getMaxAxisPoints();
153 | stringDimension.append(" (Max : [" + dimMaxX + " x 2])");
154 | } else if (characteristic.getType().compareTo(CharacteristicType.MAP) == 0) {
155 | int dimMaxX = characteristic.getAxisDescrs()[0].getMaxAxisPoints();
156 | int dimMaxY = characteristic.getAxisDescrs()[1].getMaxAxisPoints();
157 | stringDimension.append(" (Max : [" + dimMaxX + " x " + dimMaxY + "])");
158 | }
159 | }
160 | return stringDimension.toString();
161 | }
162 |
163 | public final Format getFormat() {
164 | Object oFormat = optionalsParameters.get(FORMAT);
165 | return oFormat != null ? (Format) oFormat : compuMethod.getFormat();
166 | }
167 |
168 | protected static double formatValue(double value, byte nbDecimal) {
169 | final DecimalFormat df = new DecimalFormat();
170 | DecimalFormatSymbols dfs = new DecimalFormatSymbols();
171 | String separator = new String(new char[] { dfs.getGroupingSeparator() });
172 | dfs.setDecimalSeparator('.');
173 | df.setDecimalFormatSymbols(dfs);
174 | df.setMaximumFractionDigits(nbDecimal);
175 | try {
176 | return Double.parseDouble(df.format(value).replace(separator, ""));
177 | } catch (Exception e) {
178 | return Double.NaN;
179 | }
180 |
181 | }
182 |
183 | protected abstract void formatValues();
184 |
185 | public final DataValue getValues() {
186 | formatValues();
187 | return this.values;
188 | }
189 |
190 | public final DataValue getRawValues() {
191 | DataValue rawValues = null;
192 | DataValue physValues = getValues();
193 |
194 | if (physValues instanceof SingleValue) {
195 | rawValues = new SingleValue(physValues.getValue(1, 1));
196 | if (compuMethod.isVerbal()) {
197 | rawValues.setValue(compuMethod.computeStringToRaw(physValues.getValue(1, 1).toString()), null);
198 | System.out.println(rawValues.getValue(null));
199 | System.out.println(compuMethod.getCompuVTab().getValuePairs());
200 | } else {
201 |
202 | }
203 | } else {
204 | rawValues = new ArrayValue((ArrayValue) physValues);
205 |
206 | }
207 |
208 | return rawValues;
209 | }
210 |
211 | public final String getBinariesValues() {
212 | DataValue rawValues = getRawValues();
213 | if (rawValues instanceof SingleValue) {
214 | DataType dataType = getDataType()[0];
215 | if (dataType.isInteger()) {
216 | System.out.println(Integer.toUnsignedString(((Number) rawValues.getValue(null)).intValue(), dataType.getNbByte() * 8));
217 | }
218 | }
219 | return "NaN";
220 | }
221 |
222 | public final boolean hasData() {
223 | return this.values != null;
224 | }
225 |
226 | public final boolean isReadOnly() {
227 | Object readOnly = optionalsParameters.get(READ_ONLY);
228 | return readOnly != null ? (boolean) optionalsParameters.get(READ_ONLY) : false;
229 | }
230 |
231 | public final void setValues(DataValue values) {
232 | this.values = values;
233 | }
234 |
235 | public final void setFunction(String function) {
236 | this.functionRef = function == null ? "" : function;
237 | }
238 |
239 | public final void setValidity(boolean validity) {
240 | this.validParsing = validity;
241 | }
242 |
243 | public abstract void assignComputMethod(HashMap compuMethods);
244 |
245 | public abstract String[] getUnit();
246 |
247 | public abstract DataType[] getDataType();
248 |
249 | public abstract double[] getResolution();
250 |
251 | public abstract double getZResolution();
252 |
253 | public final String getTxtResolution() {
254 | StringBuilder sb = new StringBuilder();
255 |
256 | for (double resol : getResolution()) {
257 | sb.append("[" + resol + "]");
258 | }
259 | return sb.toString();
260 | }
261 |
262 | public String getProperties() {
263 | StringBuilder sb = new StringBuilder("PROPERTIES :");
264 |
265 | sb.append("- Name: " + name + "\n");
266 | sb.append("
- Long identifier: " + new String(longIdentifier) + "\n");
267 | sb.append("
- Display identifier: " + getDisplayIdentifier() + "\n");
268 | sb.append("
- Function: " + getFunction() + "\n");
269 | sb.append("
- Unit: ");
270 | for (String unit : getUnit()) {
271 | sb.append("[" + unit + "]");
272 | }
273 | sb.append("
- Resolution: ");
274 | for (double resol : getResolution()) {
275 | sb.append("[" + resol + "]");
276 | }
277 | sb.append("
- Data type: ");
278 | for (DataType dataType : getDataType()) {
279 | sb.append("[" + dataType + "]");
280 | }
281 | sb.append("\n");
282 | sb.append("
- Lower limit: " + lowerLimit + "\n");
283 | sb.append("
- Upper limit: " + upperLimit + "\n");
284 | sb.append("
- Max diff: " + maxDiff + "\n");
285 | sb.append("
- Adress: " + "0x" + Long.toHexString(adress) + "\n");
286 | sb.append("
- Deposit: " + recordLayout.toString() + "\n");
287 | sb.append("
- Conversion: " + compuMethod.toString() + "\n");
288 |
289 | String convTableTxt = getConverionTable();
290 | if (!convTableTxt.isEmpty()) {
291 | sb.append("
");
292 | sb.append(convTableTxt);
293 | sb.append("
");
294 | }
295 |
296 | sb.append(" - Dimensions [X x Y]: " + getDimension() + "\n");
297 |
298 | if (this instanceof Characteristic) {
299 | Characteristic characteristic = (Characteristic) this;
300 | AxisDescr axis;
301 | for (int i = 0; i < characteristic.getAxisDescrs().length; i++) {
302 | sb.append("
- Axis " + (i + 1) + ": ");
303 | axis = characteristic.getAxisDescrs()[i];
304 | sb.append("");
309 | }
310 | }
311 |
312 | if (this instanceof AxisPts) {
313 | AxisPts axisPts = (AxisPts) this;
314 | sb.append("
- Used by: ");
315 | for (Characteristic characteristic : axisPts.getCharacteristicsDependency()) {
316 | sb.append(characteristic.name + " | ");
317 | }
318 | }
319 |
320 | sb.append("
");
321 |
322 | sb.append("OPTIONALS PARAMETERS :\n");
323 | sb.append("- Format : " + getFormat() + "\n");
324 | sb.append("
- Read only : " + isReadOnly() + "\n");
325 |
326 | sb.append("");
327 |
328 | return sb.toString();
329 | }
330 |
331 | public static final HashMap compar(AdjustableObject oldObj, AdjustableObject newObj) {
332 |
333 | HashMap diff = new HashMap();
334 |
335 | if (oldObj.conversionId != newObj.conversionId) {
336 | diff.put("\n\t" + PrimaryKeywords.COMPU_METHOD.name(), oldObj.compuMethod.toString() + " | " + newObj.compuMethod.toString());
337 | }
338 |
339 | if (Double.compare(oldObj.lowerLimit, newObj.lowerLimit) != 0) {
340 | diff.put("\n\tLower limit", oldObj.lowerLimit + " | " + newObj.lowerLimit);
341 | }
342 |
343 | if (Double.compare(oldObj.upperLimit, newObj.upperLimit) != 0) {
344 | diff.put("\n\tUpper limit", oldObj.upperLimit + " | " + newObj.upperLimit);
345 | }
346 |
347 | if (Double.compare(oldObj.maxDiff, newObj.maxDiff) != 0) {
348 | diff.put("\n\tMax diff", oldObj.maxDiff + " | " + newObj.maxDiff);
349 | }
350 |
351 | if (!AdjustableObject.equalsDouble(oldObj.getResolution(), newObj.getResolution())) {
352 | diff.put("\n\tResolution", oldObj.getTxtResolution() + " | " + newObj.getTxtResolution());
353 | }
354 |
355 | return diff;
356 |
357 | }
358 |
359 | public static final String comparVTAB(AdjustableObject oldObj, AdjustableObject newObj) {
360 |
361 | StringBuilder sb = new StringBuilder();
362 |
363 | if (oldObj.conversionId != newObj.conversionId && oldObj.compuMethod.isVerbal()) {
364 |
365 | CompuVTab compuVTabOld = oldObj.compuMethod.getCompuVTab();
366 | CompuVTab compuVTabNew = newObj.compuMethod.getCompuVTab();
367 |
368 | if (compuVTabOld != null && compuVTabNew != null) {
369 | Map pairsOld = compuVTabOld.getValuePairs();
370 | Map pairsNew = compuVTabNew.getValuePairs();
371 |
372 | if (!pairsOld.equals(pairsNew)) {
373 |
374 | sb.append("\t" + compuVTabOld.name + " | " + compuVTabNew.name);
375 | sb.append("\n");
376 |
377 | for (Entry entry : pairsOld.entrySet()) {
378 | float key = entry.getKey();
379 | sb.append("\t\t" + key + "->" + entry.getValue() + " | " + pairsNew.get(key));
380 | sb.append("\n");
381 | }
382 | }
383 |
384 | }
385 | }
386 |
387 | return sb.toString();
388 |
389 | }
390 |
391 | public static boolean equalsDouble(double[] a, double[] a2) {
392 | if (a == a2)
393 | return true;
394 | if (a == null || a2 == null)
395 | return false;
396 |
397 | int length = a.length;
398 | if (a2.length != length)
399 | return false;
400 |
401 | for (int i = 0; i < length; i++)
402 | if (Double.doubleToLongBits(a[i]) != Double.doubleToLongBits(a2[i]))
403 | return false;
404 |
405 | return true;
406 | }
407 |
408 | }
409 |
--------------------------------------------------------------------------------
/A2LParser/src/a2l/Annotation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 20 févr. 2019
3 | */
4 | package a2l;
5 |
6 | import static constante.SecondaryKeywords.ANNOTATION_LABEL;
7 | import static constante.SecondaryKeywords.ANNOTATION_ORIGIN;
8 | import static constante.SecondaryKeywords.ANNOTATION_TEXT;
9 |
10 | import java.util.HashMap;
11 | import java.util.List;
12 | import java.util.Map;
13 |
14 | import constante.SecondaryKeywords;
15 |
16 | public final class Annotation {
17 |
18 | private Map optionalsParameters;
19 |
20 | public Annotation(List parameters) {
21 |
22 | optionalsParameters = new HashMap();
23 |
24 | build(parameters);
25 | }
26 |
27 | private void build(List parameters) throws IllegalArgumentException {
28 |
29 | final int nbParams = parameters.size();
30 |
31 | SecondaryKeywords keyWord;
32 | for (int nPar = 0; nPar < nbParams; nPar++) {
33 | keyWord = SecondaryKeywords.getSecondaryKeyWords(parameters.get(nPar));
34 | switch (keyWord) {
35 | case ANNOTATION_LABEL:
36 | optionalsParameters.put(ANNOTATION_LABEL, parameters.get(nPar + 1).toCharArray());
37 | break;
38 | case ANNOTATION_ORIGIN:
39 | optionalsParameters.put(ANNOTATION_ORIGIN, parameters.get(nPar + 1).toCharArray());
40 | break;
41 | case ANNOTATION_TEXT:
42 | optionalsParameters.put(ANNOTATION_TEXT, parameters.get(nPar + 1).toCharArray());
43 | break;
44 | default:
45 | break;
46 | }
47 | }
48 | }
49 |
50 | public final String getAnnotationParam(SecondaryKeywords keyword) {
51 | Object oText = optionalsParameters.get(keyword);
52 | return oText != null ? new String((char[]) oText) : "";
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/A2LParser/src/a2l/ArrayValue.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 3 oct. 2020
3 | */
4 | package a2l;
5 |
6 | import java.util.Arrays;
7 |
8 | import utils.NumeralString;
9 |
10 | public class ArrayValue extends DataValue {
11 |
12 | private final short dimX;
13 | private final short dimY;
14 | private final Object[] values;
15 |
16 | public ArrayValue(short dimX, short dimY) {
17 | this.dimX = dimX;
18 | this.dimY = dimY;
19 | this.values = new Object[dimX * dimY];
20 | }
21 |
22 | public ArrayValue(ArrayValue physValues) {
23 | this.dimX = physValues.getDimX();
24 | this.dimY = physValues.getDimY();
25 | this.values = Arrays.copyOf(physValues.getValues(), this.dimX * this.dimY);
26 | }
27 |
28 | @Override
29 | public Object getValue(int... coord) {
30 | int idx = coord[1] + dimX * coord[0];
31 | return this.values[idx];
32 | }
33 |
34 | @Override
35 | public void setValue(Object value, int... coord) {
36 | int idx = coord[1] + dimX * coord[0];
37 | this.values[idx] = getStorageObject(value);
38 | }
39 |
40 | @Override
41 | public short getDimX() {
42 | return dimX;
43 | }
44 |
45 | @Override
46 | public short getDimY() {
47 | return dimY;
48 | }
49 |
50 | public final float[] getXAxis() {
51 | float[] xAxis = new float[dimX - 1];
52 |
53 | for (int x = 1; x < dimX; x++) {
54 | if (NumeralString.isNumber(getValue(0, x).toString())) {
55 | xAxis[x - 1] = Float.parseFloat(getValue(0, x).toString());
56 | } else {
57 | xAxis[x - 1] = x;
58 | }
59 | }
60 | return xAxis;
61 | }
62 |
63 | public final Object[] getValues() {
64 | return this.values;
65 | }
66 |
67 | public final float[] getYAxis() {
68 | float[] yAxis = new float[dimY - 1];
69 |
70 | for (int y = 1; y < dimY; y++) {
71 | if (NumeralString.isNumber(getValue(y, 0).toString())) {
72 | yAxis[y - 1] = Float.parseFloat(getValue(y, 0).toString());
73 | } else {
74 | yAxis[y - 1] = y;
75 | }
76 | }
77 | return yAxis;
78 | }
79 |
80 | public final float[][] getZvalues() {
81 |
82 | float[][] floatValues;
83 |
84 | if (values[0].equals("Y\\X")) {
85 | floatValues = new float[dimY - 1][dimX - 1];
86 | for (short y = 1; y < dimY; y++) {
87 | for (short x = 1; x < dimX; x++) {
88 |
89 | if (NumeralString.isNumber(getValue(y, x).toString())) {
90 | floatValues[y - 1][x - 1] = Float.parseFloat(getValue(y, x).toString());
91 | } else {
92 | floatValues[y - 1][x - 1] = Float.NaN;
93 | }
94 | }
95 | }
96 | } else {
97 | floatValues = new float[dimY - 1][dimX];
98 | for (short y = 1; y < dimY; y++) {
99 | for (short x = 1; x < dimX; x++) {
100 |
101 | if (NumeralString.isNumber(getValue(y, x).toString())) {
102 | floatValues[y - 1][x - 1] = Float.parseFloat(getValue(y, x).toString());
103 | } else {
104 | floatValues[y - 1][x - 1] = Float.NaN;
105 | }
106 | }
107 | }
108 | }
109 |
110 | return floatValues;
111 | }
112 |
113 | public final float getDiffMinMaxZvalues() {
114 |
115 | float min = Float.MAX_VALUE;
116 | float max = Float.MIN_VALUE;
117 |
118 | if (values[0].equals("Y\\X")) {
119 | for (short y = 1; y < dimY; y++) {
120 | for (short x = 1; x < dimX; x++) {
121 |
122 | if (NumeralString.isNumber(getValue(y, x).toString())) {
123 | min = Math.min(Float.parseFloat(getValue(y, x).toString()), min);
124 | max = Math.max(Float.parseFloat(getValue(y, x).toString()), max);
125 | } else {
126 | return Float.NaN;
127 | }
128 | }
129 | }
130 | } else {
131 | for (short y = 1; y < dimY; y++) {
132 | for (short x = 1; x < dimX; x++) {
133 |
134 | if (NumeralString.isNumber(getValue(y, x).toString())) {
135 | min = Math.min(Float.parseFloat(getValue(y, x).toString()), min);
136 | max = Math.max(Float.parseFloat(getValue(y, x).toString()), max);
137 | } else {
138 | return Float.NaN;
139 | }
140 | }
141 | }
142 | }
143 |
144 | return max - min;
145 | }
146 | }
147 |
--------------------------------------------------------------------------------
/A2LParser/src/a2l/AxisDescr.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 20 févr. 2019
3 | */
4 | package a2l;
5 |
6 | import static constante.SecondaryKeywords.AXIS_PTS_REF;
7 | import static constante.SecondaryKeywords.BYTE_ORDER;
8 | import static constante.SecondaryKeywords.CURVE_AXIS_REF;
9 | import static constante.SecondaryKeywords.DEPOSIT;
10 | import static constante.SecondaryKeywords.FIX_AXIS_PAR;
11 | import static constante.SecondaryKeywords.FIX_AXIS_PAR_DIST;
12 | import static constante.SecondaryKeywords.FIX_AXIS_PAR_LIST;
13 | import static constante.SecondaryKeywords.FORMAT;
14 | import static constante.SecondaryKeywords.MONOTONY;
15 | import static constante.SecondaryKeywords.PHYS_UNIT;
16 |
17 | import java.nio.ByteOrder;
18 | import java.util.HashMap;
19 | import java.util.List;
20 | import java.util.Map;
21 |
22 | import constante.SecondaryKeywords;
23 |
24 | public final class AxisDescr {
25 |
26 | private Attribute attribute;
27 | @SuppressWarnings("unused")
28 | private char[] inputQuantity;
29 | private int conversionId;
30 | private short maxAxisPoints;
31 | @SuppressWarnings("unused")
32 | private float lowerLimit;
33 | @SuppressWarnings("unused")
34 | private float upperLimit;
35 |
36 | private CompuMethod compuMethod;
37 | private AdjustableObject axisPts;
38 | private AdjustableObject curveAxis;
39 |
40 | private Map optionalsParameters;
41 |
42 | public AxisDescr(List parameters) {
43 |
44 | optionalsParameters = new HashMap();
45 |
46 | build(parameters);
47 | }
48 |
49 | public final Attribute getAttribute() {
50 | return attribute;
51 | }
52 |
53 | public final void setCompuMethod(CompuMethod compuMethod) {
54 | this.compuMethod = compuMethod;
55 | }
56 |
57 | public final void setAxisPts(AdjustableObject axisPts) {
58 | this.axisPts = axisPts;
59 | }
60 |
61 | public final AdjustableObject getAxisPts() {
62 | return axisPts;
63 | }
64 |
65 | public final void setCurveAxis(AdjustableObject adjustableObject) {
66 | this.curveAxis = adjustableObject;
67 | }
68 |
69 | public final AdjustableObject getCurveAxis() {
70 | return curveAxis;
71 | }
72 |
73 | public final int getConversion() {
74 | return conversionId;
75 | }
76 |
77 | public final CompuMethod getCompuMethod() {
78 | return compuMethod;
79 | }
80 |
81 | public final short getMaxAxisPoints() {
82 | if (attribute.equals(Attribute.COM_AXIS)) {
83 | return ((AxisPts) getAxisPts()).getMaxAxisPoints();
84 | }
85 | return maxAxisPoints;
86 | }
87 |
88 | public final String getDepositMode() {
89 | Object oDeposit = optionalsParameters.get(DEPOSIT);
90 | return oDeposit != null ? oDeposit.toString() : "";
91 | }
92 |
93 | public final ByteOrder getByteOrder() {
94 | String sByteOrder = (String) optionalsParameters.get(BYTE_ORDER);
95 | if (sByteOrder != null) {
96 | if ("MSB_LAST".equals(sByteOrder) || "BIG_ENDIAN".equals(sByteOrder)) {
97 | return ByteOrder.LITTLE_ENDIAN;
98 | }
99 | return ByteOrder.BIG_ENDIAN;
100 | }
101 | return null;
102 | }
103 |
104 | public final int getAxisRef(Attribute type) {
105 | Object object = null;
106 | switch (type) {
107 | case COM_AXIS:
108 | object = optionalsParameters.get(AXIS_PTS_REF);
109 | break;
110 | case RES_AXIS:
111 | object = optionalsParameters.get(AXIS_PTS_REF);
112 | break;
113 | case CURVE_AXIS:
114 | object = optionalsParameters.get(CURVE_AXIS_REF);
115 | break;
116 | default:
117 | break;
118 | }
119 | return (int) (object != null ? object : 0);
120 | }
121 |
122 | public final Map getOptionalsParameters() {
123 | return optionalsParameters;
124 | }
125 |
126 | public final byte getNbDecimal() {
127 | Object objectDisplayFormat = optionalsParameters.get(FORMAT);
128 | Format displayFormat;
129 |
130 | if (!compuMethod.isVerbal()) {
131 | if (objectDisplayFormat == null) {
132 | displayFormat = compuMethod.getFormat();
133 | } else {
134 | displayFormat = (Format) objectDisplayFormat;
135 | }
136 | return displayFormat.getDecimalesPlace();
137 | }
138 | return 0;
139 | }
140 |
141 | public final String getPhysUnit() {
142 | Object oPhysUnit = optionalsParameters.get(PHYS_UNIT);
143 | return oPhysUnit != null ? new String((char[]) oPhysUnit) : "";
144 | }
145 |
146 | public enum Attribute {
147 | CURVE_AXIS, COM_AXIS, FIX_AXIS, RES_AXIS, STD_AXIS, UNKNOWN;
148 |
149 | public static Attribute getAttribute(String name) {
150 | switch (name) {
151 | case "CURVE_AXIS":
152 | return CURVE_AXIS;
153 | case "COM_AXIS":
154 | return COM_AXIS;
155 | case "FIX_AXIS":
156 | return FIX_AXIS;
157 | case "RES_AXIS":
158 | return RES_AXIS;
159 | case "STD_AXIS":
160 | return STD_AXIS;
161 | default:
162 | return UNKNOWN;
163 | }
164 | }
165 | }
166 |
167 | private void build(List parameters) throws IllegalArgumentException {
168 |
169 | final int nbParams = parameters.size();
170 |
171 | if (nbParams >= 6) {
172 |
173 | this.attribute = Attribute.getAttribute(parameters.get(0));
174 | this.inputQuantity = parameters.get(1).toCharArray();
175 | this.conversionId = parameters.get(2).hashCode();
176 | this.maxAxisPoints = Short.parseShort(parameters.get(3));
177 | this.lowerLimit = Float.parseFloat(parameters.get(4));
178 | this.upperLimit = Float.parseFloat(parameters.get(5));
179 |
180 | int n = 6;
181 |
182 | SecondaryKeywords keyWord;
183 | for (int nPar = n; nPar < nbParams; nPar++) {
184 | keyWord = SecondaryKeywords.getSecondaryKeyWords(parameters.get(nPar));
185 | switch (keyWord) {
186 | case AXIS_PTS_REF:
187 | optionalsParameters.put(AXIS_PTS_REF, parameters.get(nPar + 1).hashCode());
188 | nPar += 1;
189 | break;
190 | case BYTE_ORDER:
191 | optionalsParameters.put(BYTE_ORDER, parameters.get(nPar + 1));
192 | nPar += 1;
193 | break;
194 | case CURVE_AXIS_REF:
195 | optionalsParameters.put(CURVE_AXIS_REF, parameters.get(nPar + 1).hashCode());
196 | nPar += 1;
197 | break;
198 | case DEPOSIT:
199 | optionalsParameters.put(DEPOSIT, parameters.get(nPar + 1));
200 | nPar += 1;
201 | break;
202 | case FIX_AXIS_PAR:
203 | n = nPar + 1;
204 | optionalsParameters.put(FIX_AXIS_PAR, new FixAxisPar(parameters.subList(n, n + 3)));
205 | nPar += 3;
206 | break;
207 | case FIX_AXIS_PAR_DIST:
208 | n = nPar + 1;
209 | optionalsParameters.put(FIX_AXIS_PAR_DIST, new FixAxisParDist(parameters.subList(n, n + 3)));
210 | nPar += 3;
211 | break;
212 | case FIX_AXIS_PAR_LIST:
213 | n = nPar + 1;
214 | do {
215 | } while (!parameters.get(++nPar).equals(FIX_AXIS_PAR_LIST.name()));
216 | optionalsParameters.put(FIX_AXIS_PAR_LIST, new FixAxisParList(parameters.subList(n, nPar - 1)));
217 | n = nPar + 1;
218 | break;
219 | case FORMAT:
220 | optionalsParameters.put(FORMAT, new Format(parameters.get(nPar + 1)));
221 | nPar += 1;
222 | break;
223 | case MONOTONY:
224 | optionalsParameters.put(MONOTONY, parameters.get(nPar + 1).toCharArray());
225 | nPar += 1;
226 | break;
227 | case PHYS_UNIT:
228 | optionalsParameters.put(PHYS_UNIT, parameters.get(nPar + 1).toCharArray());
229 | nPar += 1;
230 | break;
231 | default:
232 | break;
233 | }
234 | }
235 |
236 | } else {
237 | throw new IllegalArgumentException("Nombre de parametres inferieur au nombre requis");
238 | }
239 |
240 | }
241 | }
242 |
--------------------------------------------------------------------------------
/A2LParser/src/a2l/AxisPts.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 2 mars 2018
3 | */
4 | package a2l;
5 |
6 | import static constante.SecondaryKeywords.ANNOTATION;
7 | import static constante.SecondaryKeywords.BYTE_ORDER;
8 | import static constante.SecondaryKeywords.DEPOSIT;
9 | import static constante.SecondaryKeywords.DISPLAY_IDENTIFIER;
10 | import static constante.SecondaryKeywords.FORMAT;
11 | import static constante.SecondaryKeywords.READ_ONLY;
12 |
13 | import java.text.DecimalFormat;
14 | import java.text.DecimalFormatSymbols;
15 | import java.util.ArrayList;
16 | import java.util.HashMap;
17 | import java.util.List;
18 |
19 | import constante.ConversionType;
20 | import constante.DataType;
21 | import constante.SecondaryKeywords;
22 |
23 | public final class AxisPts extends AdjustableObject {
24 |
25 | @SuppressWarnings("unused")
26 | private char[] inputQuantity; // Reference to INPUT_QUANTITY
27 | private short maxAxisPoints;
28 |
29 | private List characteristicsDependency;
30 |
31 | public AxisPts(List parameters, int beginLine, int endLine) {
32 |
33 | optionalsParameters = new HashMap();
34 |
35 | build(parameters, beginLine, endLine);
36 | }
37 |
38 | @Override
39 | public String toString() {
40 | return this.name;
41 | }
42 |
43 | public final short getMaxAxisPoints() {
44 | return maxAxisPoints;
45 | }
46 |
47 | public final String getDepositMode() {
48 | Object oDeposit = optionalsParameters.get(DEPOSIT);
49 | return oDeposit != null ? oDeposit.toString() : "";
50 | }
51 |
52 | public final Object[] getZValues() {
53 | Object[] values = new Object[this.values.getDimX()];
54 | for (short i = 0; i < values.length; i++) {
55 | values[i] = this.values.getValue(0, i);
56 | }
57 |
58 | return values;
59 | }
60 |
61 | @Override
62 | public final void assignComputMethod(HashMap compuMethods) {
63 | this.compuMethod = compuMethods.get(this.conversionId);
64 | if (this.compuMethod == null) {
65 | this.compuMethod = CompuMethod.createNoCompuMethod();
66 | }
67 | }
68 |
69 | public final void assignCharacteristic(Characteristic characteristic) {
70 | if (characteristicsDependency == null) {
71 | characteristicsDependency = new ArrayList();
72 | }
73 | characteristicsDependency.add(characteristic);
74 | }
75 |
76 | public final List getCharacteristicsDependency() {
77 | return characteristicsDependency;
78 | }
79 |
80 | @Override
81 | public DataType[] getDataType() {
82 |
83 | DataType[] dataTypes = new DataType[1];
84 |
85 | dataTypes[0] = getRecordLayout().getAxisPtsX().getDataType();
86 |
87 | return dataTypes;
88 | }
89 |
90 | @Override
91 | public String[] getUnit() {
92 | return new String[] { this.compuMethod.getUnit() };
93 | }
94 |
95 | @Override
96 | public void build(List parameters, int beginLine, int endLine) throws IllegalArgumentException {
97 |
98 | final int nbParams = parameters.size();
99 |
100 | if (nbParams >= 9) {
101 |
102 | this.name = parameters.get(2);
103 | this.longIdentifier = parameters.get(3).toCharArray();
104 | this.adress = Long.parseLong(parameters.get(4).substring(2), 16);
105 | this.inputQuantity = parameters.get(5).toCharArray();
106 | this.depositId = parameters.get(6).hashCode();
107 | this.maxDiff = Float.parseFloat(parameters.get(7));
108 | this.conversionId = parameters.get(8).hashCode();
109 | this.maxAxisPoints = Short.parseShort(parameters.get(9));
110 | this.lowerLimit = Float.parseFloat(parameters.get(10));
111 | this.upperLimit = Float.parseFloat(parameters.get(11));
112 |
113 | int n = 12;
114 |
115 | SecondaryKeywords keyWord;
116 | for (int nPar = n; nPar < nbParams; nPar++) {
117 | keyWord = SecondaryKeywords.getSecondaryKeyWords(parameters.get(nPar));
118 | switch (keyWord) {
119 | case ANNOTATION:
120 | n = nPar + 1;
121 | do {
122 | } while (!parameters.get(++nPar).equals(ANNOTATION));
123 | optionalsParameters.put(ANNOTATION, new Annotation(parameters.subList(n, nPar - 3)));
124 | n = nPar + 1;
125 | break;
126 | case BYTE_ORDER:
127 | optionalsParameters.put(BYTE_ORDER, parameters.get(nPar + 1));
128 | nPar += 1;
129 | break;
130 | case DEPOSIT:
131 | optionalsParameters.put(DEPOSIT, parameters.get(nPar + 1));
132 | nPar += 1;
133 | break;
134 | case DISPLAY_IDENTIFIER:
135 | optionalsParameters.put(DISPLAY_IDENTIFIER, parameters.get(nPar + 1).toCharArray());
136 | nPar += 1;
137 | break;
138 | case FORMAT:
139 | optionalsParameters.put(FORMAT, new Format(parameters.get(nPar + 1)));
140 | nPar += 1;
141 | break;
142 | case PHYS_UNIT:
143 | break;
144 | case READ_ONLY:
145 | optionalsParameters.put(READ_ONLY, true);
146 | break;
147 | default:
148 | break;
149 | }
150 | }
151 |
152 | } else {
153 | validParsing = false;
154 | throw new IllegalArgumentException("Nombre de parametres inferieur au nombre requis");
155 | }
156 | validParsing = true;
157 | }
158 |
159 | @Override
160 | protected void formatValues() {
161 |
162 | if (values != null) {
163 | final DecimalFormat df = new DecimalFormat();
164 | DecimalFormatSymbols dfs = new DecimalFormatSymbols();
165 | dfs.setDecimalSeparator('.');
166 | String separator = new String(new char[] { dfs.getGroupingSeparator() });
167 | df.setDecimalFormatSymbols(dfs);
168 | df.setMaximumFractionDigits(getNbDecimal());
169 |
170 | int nbValues = values.getDimX();
171 |
172 | for (int i = 0; i < nbValues; i++) {
173 | try {
174 | double doubleValue = Double.parseDouble(values.getValue(0, i).toString());
175 | values.setValue(df.format(doubleValue).replace(separator, ""), 0, i);
176 | } catch (Exception e) {
177 | // Nothing
178 | }
179 | }
180 | }
181 | }
182 |
183 | @Override
184 | public double[] getResolution() {
185 |
186 | if (ConversionType.TAB_VERB.equals(this.compuMethod.getConversionType())) {
187 | double val0 = this.compuMethod.compute(1);
188 | double val1 = this.compuMethod.compute(2);
189 | double resol = val1 - val0;
190 | return new double[] { resol };
191 | }
192 |
193 | return new double[] { Double.NaN };
194 | }
195 |
196 | @Override
197 | public boolean isValid() {
198 | return validParsing;
199 | }
200 |
201 | @Override
202 | public double getZResolution() {
203 | return Double.NaN;
204 | }
205 |
206 | }
207 |
--------------------------------------------------------------------------------
/A2LParser/src/a2l/CompuMethod.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 3 janv. 2019
3 | */
4 | package a2l;
5 |
6 | import static constante.SecondaryKeywords.COEFFS;
7 | import static constante.SecondaryKeywords.COEFFS_LINEAR;
8 | import static constante.SecondaryKeywords.COMPU_TAB_REF;
9 |
10 | import java.util.HashMap;
11 | import java.util.List;
12 | import java.util.Map;
13 | import java.util.Map.Entry;
14 |
15 | import constante.ConversionType;
16 | import constante.SecondaryKeywords;
17 | import utils.Interpolation;
18 |
19 | public final class CompuMethod implements A2lObject, Comparable {
20 |
21 | private String name;
22 | private char[] longIdentifier;
23 | private ConversionType conversionType;
24 | private Format format;
25 | private char[] unit;
26 |
27 | private Map optionalsParameters;
28 |
29 | public CompuMethod(List parameters, int beginLine, int endLine) {
30 |
31 | optionalsParameters = new HashMap();
32 |
33 | build(parameters, beginLine, endLine);
34 | }
35 |
36 | private CompuMethod() {
37 | this.name = "NO_COMPU_METHOD";
38 | this.longIdentifier = new char[] { ' ' };
39 | this.conversionType = ConversionType.getConversionType("NO_COMPU_METHOD");
40 | this.format = new Format("");
41 | this.unit = new char[] { ' ' };
42 | }
43 |
44 | @Override
45 | public String toString() {
46 | return this.name;
47 | }
48 |
49 | public static final CompuMethod createNoCompuMethod() {
50 | return new CompuMethod();
51 | }
52 |
53 | public final void assignConversionTable(HashMap conversionTables) {
54 | if (!hasCompuTabRef()) {
55 | return;
56 | }
57 | int compuTabRef = (int) this.optionalsParameters.get(COMPU_TAB_REF);
58 | this.optionalsParameters.put(COMPU_TAB_REF, conversionTables.get(compuTabRef));
59 | }
60 |
61 | public final double compute(double hex) {
62 |
63 | float[] _coeffs;
64 |
65 | switch (this.conversionType) {
66 | case NO_COMPU_METHOD:
67 | return hex;
68 | case IDENTICAL:
69 | return hex;
70 | case FORM:
71 | return hex;
72 | case LINEAR:
73 | CoeffsLinear coeffsLinear = (CoeffsLinear) this.optionalsParameters.get(COEFFS_LINEAR);
74 | _coeffs = coeffsLinear.getCoeffs();
75 | return (_coeffs[0] * hex) - _coeffs[1];
76 | case RAT_FUNC:
77 | Coeffs coeffs = (Coeffs) this.optionalsParameters.get(COEFFS);
78 | _coeffs = coeffs.getCoeffs();
79 | if (_coeffs[0] + _coeffs[2] + _coeffs[3] + _coeffs[4] == 0) {
80 | return (hex * _coeffs[5]) / _coeffs[1];
81 | }
82 | if (_coeffs[0] + _coeffs[3] + _coeffs[4] == 0) {
83 | return (hex * _coeffs[5] - _coeffs[2]) / _coeffs[1];
84 | }
85 | if (_coeffs[0] + _coeffs[1] + _coeffs[3] + _coeffs[5] == 0) {
86 | return _coeffs[2] / (hex * _coeffs[4]);
87 | }
88 | return Double.NaN;
89 | case TAB_NOINTP:
90 | Object compuTabRef = this.optionalsParameters.get(COMPU_TAB_REF);
91 | if (compuTabRef instanceof CompuTab) {
92 | CompuTab compuTab = (CompuTab) compuTabRef;
93 | Float result = compuTab.getValuePairs().get((float) hex);
94 | return result != null ? result : Double.NaN;
95 | }
96 | case TAB_INTP:
97 | Object compuTabRefBis = this.optionalsParameters.get(COMPU_TAB_REF);
98 | if (compuTabRefBis instanceof CompuTab) {
99 | CompuTab compuTab = (CompuTab) compuTabRefBis;
100 | Float value = compuTab.getValuePairs().get((float) hex);
101 | if (value == null) {
102 | int nbValuePairs = compuTab.getNumberValuePairs();
103 | Float[] keys = compuTab.getValuePairs().keySet().toArray(new Float[nbValuePairs]);
104 | int cnt = 0;
105 | float x1 = 0;
106 | float x2 = 0;
107 | float y1 = 0;
108 | float y2 = 0;
109 | for (float entryKey : keys) {
110 | if (entryKey > (float) hex) {
111 | x1 = keys[cnt - 1];
112 | x2 = keys[cnt];
113 | y1 = compuTab.getValuePairs().get(new Float(x1));
114 | y2 = compuTab.getValuePairs().get(new Float(x2));
115 | break;
116 | }
117 | cnt++;
118 | }
119 | return Interpolation.interpLinear(x1, x2, y1, y2, (float) hex);
120 | }
121 | return value;
122 | }
123 | default:
124 | return Double.NaN;
125 | }
126 | }
127 |
128 | public final String computeString(double hex) {
129 |
130 | Object compuTabRef = this.optionalsParameters.get(COMPU_TAB_REF);
131 |
132 | switch (this.conversionType) {
133 | case TAB_VERB:
134 | if (compuTabRef instanceof CompuVTab) {
135 | CompuVTab compuVTab = (CompuVTab) compuTabRef;
136 | return compuVTab.getValuePairs().get((float) hex);
137 | }
138 | if (compuTabRef instanceof CompuVTabRange) {
139 | CompuVTabRange compuVTabRange = (CompuVTabRange) compuTabRef;
140 | return compuVTabRange.getStringValue(hex);
141 | }
142 | return "NaN";
143 | default:
144 | return "NaN";
145 | }
146 | }
147 |
148 | public final double computeStringToRaw(String physValue) {
149 | Object compuTabRef = this.optionalsParameters.get(COMPU_TAB_REF);
150 |
151 | switch (this.conversionType) {
152 | case TAB_VERB:
153 | if (compuTabRef instanceof CompuVTab) {
154 | CompuVTab compuVTab = (CompuVTab) compuTabRef;
155 | for (Entry entry : compuVTab.getValuePairs().entrySet()) {
156 | if (entry.getValue().equals(physValue)) {
157 | return entry.getKey();
158 | }
159 | }
160 | }
161 | return Double.NaN;
162 | default:
163 | return Double.NaN;
164 | }
165 | }
166 |
167 | public final ConversionTable getConvTable() {
168 |
169 | if (conversionType != ConversionType.NO_COMPU_METHOD) {
170 | Object compuTabRef = this.optionalsParameters.get(COMPU_TAB_REF);
171 |
172 | if (compuTabRef instanceof CompuVTab) {
173 | return (CompuVTab) compuTabRef;
174 | }
175 |
176 | if (compuTabRef instanceof CompuVTabRange) {
177 | return (CompuVTabRange) compuTabRef;
178 | }
179 |
180 | if (compuTabRef instanceof CompuTab) {
181 | return (CompuTab) compuTabRef;
182 | }
183 | }
184 | return null;
185 | }
186 |
187 | public final CompuVTab getCompuVTab() {
188 | if (isVerbal()) {
189 | Object compuTabRef = this.optionalsParameters.get(COMPU_TAB_REF);
190 |
191 | if (compuTabRef instanceof CompuVTab) {
192 | return (CompuVTab) compuTabRef;
193 | }
194 | }
195 | return null;
196 | }
197 |
198 | public final CompuVTabRange getCompuVTabRange() {
199 | if (isVerbal()) {
200 | Object compuTabRef = this.optionalsParameters.get(COMPU_TAB_REF);
201 |
202 | if (compuTabRef instanceof CompuVTabRange) {
203 | return (CompuVTabRange) compuTabRef;
204 | }
205 | }
206 | return null;
207 | }
208 |
209 | public final ConversionType getConversionType() {
210 | return this.conversionType;
211 | }
212 |
213 | public final boolean hasCompuTabRef() {
214 | return optionalsParameters.get(COMPU_TAB_REF) != null ? true : false;
215 | }
216 |
217 | public final boolean isVerbal() {
218 | return this.conversionType.equals(ConversionType.TAB_VERB);
219 | }
220 |
221 | @Override
222 | public boolean equals(Object obj) {
223 | return this.name.equals(obj.toString());
224 | }
225 |
226 | public final Format getFormat() {
227 | return format;
228 | }
229 |
230 | public final String getUnit() {
231 | return new String(unit);
232 | }
233 |
234 | public final String getProperties() {
235 | StringBuilder sb = new StringBuilder("PROPERTIES :");
236 |
237 | sb.append("
- Name: " + name + "\n");
238 | sb.append("
- Long identifier: " + new String(longIdentifier) + "\n");
239 | sb.append("
- Conversion type: " + getConversionType().name() + "\n");
240 | sb.append("
- Unit: [" + getUnit() + "]\n");
241 | sb.append("
- Format: " + getFormat() + "\n");
242 | if (hasCompuTabRef()) {
243 | String compuTabRef = optionalsParameters.get(COMPU_TAB_REF).toString();
244 | sb.append("
- Ref conversion table: " + compuTabRef + "\n");
245 | }
246 | sb.append("");
247 |
248 | return sb.toString();
249 | }
250 |
251 | @Override
252 | public int compareTo(CompuMethod o) {
253 | return this.name.compareTo(o.name);
254 | }
255 |
256 | public final class Coeffs {
257 |
258 | // INT = f(PHYS), f(x) = (axx + bx + c) / (dxx + ex + f)
259 |
260 | private final float k1;
261 | private final float k2;
262 | private final float k3;
263 | private final float k4;
264 | private final float k5;
265 | private final float k6;
266 |
267 | public Coeffs(List params) {
268 | this.k1 = Float.parseFloat(params.get(0));
269 | this.k2 = Float.parseFloat(params.get(1));
270 | this.k3 = Float.parseFloat(params.get(2));
271 | this.k4 = Float.parseFloat(params.get(3));
272 | this.k5 = Float.parseFloat(params.get(4));
273 | this.k6 = Float.parseFloat(params.get(5));
274 | }
275 |
276 | public final float[] getCoeffs() {
277 | return new float[] { k1, k2, k3, k4, k5, k6 };
278 | }
279 | }
280 |
281 | private final class CoeffsLinear {
282 |
283 | // PHYS = f(INT), f(x) = ax + b
284 |
285 | private final float k1;
286 | private final float k2;
287 |
288 | public CoeffsLinear(List params) {
289 | this.k1 = Float.parseFloat(params.get(0));
290 | this.k2 = Float.parseFloat(params.get(1));
291 | }
292 |
293 | public final float[] getCoeffs() {
294 | return new float[] { k1, k2 };
295 | }
296 | }
297 |
298 | @Override
299 | public boolean isValid() {
300 | return true;
301 | }
302 |
303 | @Override
304 | public void build(List parameters, int beginLine, int endLine) throws IllegalArgumentException {
305 |
306 | final int nbParams = parameters.size();
307 |
308 | if (nbParams >= 5) {
309 |
310 | this.name = parameters.get(2);
311 | this.longIdentifier = parameters.get(3).toCharArray();
312 | this.conversionType = ConversionType.getConversionType(parameters.get(4));
313 | this.format = new Format(parameters.get(5));
314 | this.unit = parameters.get(6).toCharArray();
315 |
316 | int n = 7;
317 |
318 | SecondaryKeywords keyWord;
319 | for (int nPar = n; nPar < nbParams; nPar++) {
320 | keyWord = SecondaryKeywords.getSecondaryKeyWords(parameters.get(nPar));
321 | switch (keyWord) {
322 | case COEFFS: // 6 coeffs
323 | optionalsParameters.put(COEFFS, new Coeffs(parameters.subList(nPar + 1, nPar + 7)));
324 | nPar += 6;
325 | break;
326 | case COEFFS_LINEAR: // 2 coeffs
327 | optionalsParameters.put(COEFFS_LINEAR, new CoeffsLinear(parameters.subList(nPar + 1, nPar + 3)));
328 | nPar += 2;
329 | break;
330 | case COMPU_TAB_REF:
331 | optionalsParameters.put(COMPU_TAB_REF, parameters.get(nPar + 1).hashCode());
332 | nPar += 1;
333 | break;
334 | case FORMULA:
335 | break;
336 | case REF_UNIT:
337 | break;
338 |
339 | default:
340 | break;
341 | }
342 | }
343 |
344 | } else {
345 | throw new IllegalArgumentException("Nombre de parametres inferieur au nombre requis");
346 | }
347 |
348 | }
349 |
350 | }
351 |
--------------------------------------------------------------------------------
/A2LParser/src/a2l/CompuTab.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 5 janv. 2019
3 | */
4 | package a2l;
5 |
6 | import java.util.LinkedHashMap;
7 | import java.util.List;
8 | import java.util.Map;
9 | import java.util.Map.Entry;
10 |
11 | import constante.ConversionType;
12 |
13 | public final class CompuTab extends ConversionTable {
14 |
15 | private short numberValuePairs;
16 | private Map valuePairs;
17 | private char[] defaultValue; // DEFAULT_VALUE
18 | private static float defaultValueNumeric = Float.NaN; // DEFAULT_VALUE_NUMERIC
19 |
20 | public CompuTab(List parameters, int beginLine, int endLine) {
21 |
22 | build(parameters, beginLine, endLine);
23 |
24 | }
25 |
26 | public final short getNumberValuePairs() {
27 | return numberValuePairs;
28 | }
29 |
30 | public final Map getValuePairs() {
31 | return valuePairs;
32 | }
33 |
34 | @Override
35 | public boolean isValid() {
36 | return true;
37 | }
38 |
39 | @Override
40 | public void build(List parameters, int beginLine, int endLine) throws IllegalArgumentException {
41 |
42 | final int nbParams = parameters.size();
43 |
44 | if (nbParams >= 5) {
45 |
46 | this.name = parameters.get(2);
47 | this.longIdentifier = parameters.get(3).toCharArray();
48 | this.conversionType = ConversionType.getConversionType(parameters.get(4));
49 | this.numberValuePairs = Short.parseShort(parameters.get(5));
50 |
51 | this.valuePairs = new LinkedHashMap(this.numberValuePairs);
52 |
53 | int lastIdx = parameters.indexOf("DEFAULT_VALUE");
54 | if (lastIdx < 0) {
55 | lastIdx = parameters.indexOf("DEFAULT_VALUE_NUMERIC");
56 | } else {
57 | this.defaultValue = parameters.get(lastIdx + 1).toCharArray();
58 | }
59 |
60 | final List listValuePairs;
61 |
62 | if (lastIdx > -1) {
63 | listValuePairs = parameters.subList(6, lastIdx);
64 | } else {
65 | listValuePairs = parameters.subList(6, parameters.size());
66 | }
67 |
68 | for (int i = 0; i < listValuePairs.size(); i++) {
69 | if (i % 2 == 0) {
70 | valuePairs.put(Float.parseFloat(listValuePairs.get(i)), Float.parseFloat(listValuePairs.get(i + 1)));
71 | }
72 | }
73 | } else {
74 | throw new IllegalArgumentException("Nombre de parametres inferieur au nombre requis");
75 | }
76 |
77 | }
78 |
79 | @Override
80 | public String getProperties() {
81 |
82 | StringBuilder sb = new StringBuilder("PROPERTIES :");
83 |
84 | sb.append("
- Name: " + name + "\n");
85 | sb.append("
- Long identifier: " + new String(longIdentifier) + "\n");
86 | sb.append("
- Conversion type: " + conversionType.name() + "\n");
87 | sb.append("
- Number of value pairs: " + numberValuePairs + "\n");
88 | sb.append("
- Value pairs: ");
89 | sb.append("
");
90 | for (Entry entry : valuePairs.entrySet()) {
91 | sb.append("- " + entry.getKey() + " => " + entry.getValue() + "\n");
92 | }
93 | sb.append("
");
94 | sb.append(" - Default value: " + new String(defaultValue) + "\n");
95 | sb.append("
- Default value numeric: " + defaultValueNumeric + "\n");
96 | sb.append("");
97 |
98 | return sb.toString();
99 | }
100 |
101 | @Override
102 | Map, ?> getMap() {
103 | return valuePairs;
104 | }
105 |
106 | }
107 |
--------------------------------------------------------------------------------
/A2LParser/src/a2l/CompuVTab.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 5 janv. 2019
3 | */
4 | package a2l;
5 |
6 | import java.util.LinkedHashMap;
7 | import java.util.List;
8 | import java.util.Map;
9 | import java.util.Map.Entry;
10 |
11 | import constante.ConversionType;
12 | import utils.NumeralString;
13 |
14 | public final class CompuVTab extends ConversionTable {
15 |
16 | private int numberValuePairs;
17 | private Map valuePairs;
18 | private char[] defaultValue; // DEFAULT_VALUE
19 |
20 | public CompuVTab(List parameters, int beginLine, int endLine) {
21 |
22 | build(parameters, beginLine, endLine);
23 |
24 | }
25 |
26 | public final Map getValuePairs() {
27 | return valuePairs;
28 | }
29 |
30 | @Override
31 | public boolean isValid() {
32 | return true;
33 | }
34 |
35 | @Override
36 | public void build(List parameters, int beginLine, int endLine) throws IllegalArgumentException {
37 |
38 | final int nbParams = parameters.size();
39 |
40 | if (nbParams >= 5) {
41 |
42 | this.name = parameters.get(2);
43 | this.longIdentifier = parameters.get(3).toCharArray();
44 | this.conversionType = ConversionType.getConversionType(parameters.get(4));
45 | this.numberValuePairs = Integer.parseInt(parameters.get(5));
46 |
47 | this.valuePairs = new LinkedHashMap(numberValuePairs);
48 |
49 | int lastIdx = parameters.indexOf("DEFAULT_VALUE");
50 |
51 | final List listValuePairs;
52 |
53 | if (lastIdx > -1) {
54 | listValuePairs = parameters.subList(6, lastIdx);
55 | this.defaultValue = parameters.get(lastIdx + 1).toCharArray();
56 | } else {
57 | listValuePairs = parameters.subList(6, parameters.size());
58 | this.defaultValue = new char[0];
59 | }
60 |
61 | Float key = null;
62 | String value;
63 |
64 | for (int i = 0; i < listValuePairs.size() - 1; i++) {
65 |
66 | try {
67 | key = Float.parseFloat(listValuePairs.get(i));
68 | value = listValuePairs.get(i + 1);
69 | valuePairs.put(key, value);
70 | i++;
71 | } catch (NumberFormatException e) {
72 |
73 | String oldVal;
74 |
75 | do {
76 | oldVal = valuePairs.get(key);
77 | valuePairs.put(key, oldVal + " " + listValuePairs.get(i++));
78 | } while (!NumeralString.isNumber(listValuePairs.get(i)) && i < listValuePairs.size() - 1);
79 |
80 | i--;
81 | }
82 |
83 | }
84 | } else {
85 | throw new IllegalArgumentException("Nombre de parametres inferieur au nombre requis");
86 | }
87 |
88 | }
89 |
90 | @Override
91 | public String getProperties() {
92 |
93 | StringBuilder sb = new StringBuilder("PROPERTIES :");
94 |
95 | sb.append("
- Name: " + name + "\n");
96 | sb.append("
- Long identifier: " + new String(longIdentifier) + "\n");
97 | sb.append("
- Conversion type: " + conversionType.name() + "\n");
98 | sb.append("
- Number of value pairs: " + numberValuePairs + "\n");
99 | sb.append("
- Value pairs: ");
100 | sb.append("
");
101 | for (Entry entry : valuePairs.entrySet()) {
102 | sb.append("- " + entry.getKey() + " => " + entry.getValue() + "\n");
103 | }
104 | sb.append("
");
105 | sb.append(" - Default value: " + new String(defaultValue) + "\n");
106 | sb.append("");
107 |
108 | return sb.toString();
109 | }
110 |
111 | @Override
112 | Map, ?> getMap() {
113 | // TODO Auto-generated method stub
114 | return valuePairs;
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/A2LParser/src/a2l/CompuVTabRange.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 5 janv. 2019
3 | */
4 | package a2l;
5 |
6 | import java.util.Iterator;
7 | import java.util.LinkedHashMap;
8 | import java.util.List;
9 | import java.util.Map;
10 | import java.util.Map.Entry;
11 | import java.util.Set;
12 |
13 | public final class CompuVTabRange extends ConversionTable {
14 |
15 | private short numberValueTriples;
16 | private Map valueTriples;
17 | private char[] defaultValue; // DEFAULT_VALUE
18 |
19 | public CompuVTabRange(List parameters, int beginLine, int endLine) {
20 |
21 | build(parameters, beginLine, endLine);
22 | }
23 |
24 | public final String getStringValue(double hex) {
25 | Set> entries = valueTriples.entrySet();
26 | Iterator> it = entries.iterator();
27 | while (it.hasNext()) {
28 | Entry entry = it.next();
29 | Range range = entry.getKey();
30 | if (((int) hex) == hex) {
31 | if (range.getMin() >= hex && hex <= range.getMax()) {
32 | return entry.getValue();
33 | }
34 | } else {
35 | if (range.getMin() >= hex && hex < range.getMax()) {
36 | return entry.getValue();
37 | }
38 | }
39 | }
40 | return new String(defaultValue);
41 | }
42 |
43 | @Override
44 | public boolean isValid() {
45 | return true;
46 | }
47 |
48 | @Override
49 | public void build(List parameters, int beginLine, int endLine) throws IllegalArgumentException {
50 |
51 | final int nbParams = parameters.size();
52 |
53 | if (nbParams >= 4) {
54 |
55 | this.name = parameters.get(2);
56 | this.longIdentifier = parameters.get(3).toCharArray();
57 | this.numberValueTriples = Short.parseShort(parameters.get(4));
58 |
59 | this.valueTriples = new LinkedHashMap(numberValueTriples);
60 |
61 | int lastIdx = parameters.indexOf("DEFAULT_VALUE");
62 |
63 | final List listValuePairs;
64 |
65 | if (lastIdx > -1) {
66 | listValuePairs = parameters.subList(5, lastIdx);
67 | this.defaultValue = parameters.get(lastIdx + 1).toCharArray();
68 | } else {
69 | listValuePairs = parameters.subList(5, parameters.size());
70 | this.defaultValue = new char[0];
71 | }
72 |
73 | for (int i = 0; i < listValuePairs.size(); i++) {
74 | if (i % 3 == 0) {
75 | valueTriples.put(new Range(Float.parseFloat(listValuePairs.get(i)), Float.parseFloat(listValuePairs.get(i + 1))),
76 | listValuePairs.get(i + 2));
77 | }
78 | }
79 | } else {
80 | throw new IllegalArgumentException("Nombre de parametres inferieur au nombre requis");
81 | }
82 |
83 | }
84 |
85 | @Override
86 | public String getProperties() {
87 | StringBuilder sb = new StringBuilder("PROPERTIES :");
88 |
89 | sb.append("
- Name: " + name + "\n");
90 | sb.append("
- Long identifier: " + new String(longIdentifier) + "\n");
91 | sb.append("
- Number of value triples: " + numberValueTriples + "\n");
92 | sb.append("
- Value triples: ");
93 | sb.append("
");
94 | for (Entry entry : valueTriples.entrySet()) {
95 | sb.append("- " + entry.getKey() + " => " + entry.getValue() + "\n");
96 | }
97 | sb.append("
");
98 | sb.append(" - Default value: " + new String(defaultValue) + "\n");
99 | sb.append("");
100 |
101 | return sb.toString();
102 | }
103 |
104 | @Override
105 | Map, ?> getMap() {
106 | // TODO Auto-generated method stub
107 | return valueTriples;
108 | }
109 | }
110 |
111 | final class Range {
112 |
113 | private final float min;
114 | private final float max;
115 |
116 | public Range(float min, float max) {
117 | this.min = min;
118 | this.max = max;
119 | }
120 |
121 | public final float getMin() {
122 | return min;
123 | }
124 |
125 | public final float getMax() {
126 | return max;
127 | }
128 |
129 | @Override
130 | public String toString() {
131 | return min + "-" + max;
132 | }
133 |
134 | }
135 |
--------------------------------------------------------------------------------
/A2LParser/src/a2l/ConversionTable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 31 mars 2019
3 | */
4 | package a2l;
5 |
6 | import java.util.Map;
7 |
8 | import constante.ConversionType;
9 |
10 | public abstract class ConversionTable implements A2lObject, Comparable {
11 |
12 | protected String name;
13 | protected char[] longIdentifier;
14 | protected ConversionType conversionType;
15 |
16 | @Override
17 | public final int compareTo(ConversionTable o) {
18 | return this.name.compareToIgnoreCase(o.toString());
19 | }
20 |
21 | abstract Map, ?> getMap();
22 |
23 | @Override
24 | public String toString() {
25 | return this.name;
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/A2LParser/src/a2l/DataValue.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 3 oct. 2020
3 | */
4 | package a2l;
5 |
6 | public abstract class DataValue {
7 |
8 | public abstract short getDimX();
9 |
10 | public abstract short getDimY();
11 |
12 | public abstract Object getValue(int... coord);
13 |
14 | public abstract void setValue(Object value, int... coord);
15 |
16 | protected final Object getStorageObject(Object o) {
17 |
18 | if (o instanceof Number) {
19 |
20 | if (o instanceof Double) {
21 | double d = (double) o;
22 | int i = (int) d;
23 | if (d - i != 0) {
24 | return (double) o;
25 | } else if (i <= Byte.MAX_VALUE && i >= Byte.MIN_VALUE) {
26 | return (byte) i;
27 | } else if (i <= Short.MAX_VALUE && i >= Short.MIN_VALUE) {
28 | return (short) i;
29 | } else {
30 | return i;
31 | }
32 | }
33 |
34 | if (o instanceof Short) {
35 | short i = (short) o;
36 |
37 | if (i <= Byte.MAX_VALUE && i >= Byte.MIN_VALUE) {
38 | return (byte) i;
39 | }
40 | }
41 |
42 | }
43 |
44 | return o;
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/A2LParser/src/a2l/DisplayIdentifier.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 22 févr. 2019
3 | */
4 | package a2l;
5 |
6 | public final class DisplayIdentifier {
7 |
8 | private final String ident;
9 |
10 | public DisplayIdentifier(String ident) {
11 | this.ident = ident;
12 | }
13 |
14 | public final String getIdent() {
15 | return this.ident;
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/A2LParser/src/a2l/FixAxisPar.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 12 mars 2019
3 | */
4 | package a2l;
5 |
6 | import java.util.List;
7 |
8 | public final class FixAxisPar {
9 |
10 | private final float offset;
11 | private final float shift;
12 | private final short numberapo;
13 |
14 | public FixAxisPar(List parameters) {
15 |
16 | this.offset = Float.parseFloat(parameters.get(0));
17 | this.shift = Float.parseFloat(parameters.get(1));
18 | this.numberapo = (short) Integer.parseInt(parameters.get(2));
19 |
20 | }
21 |
22 | public final double compute(int numVal) {
23 | return offset + (numVal << (int) shift);
24 | }
25 |
26 | public final float getOffset() {
27 | return offset;
28 | }
29 |
30 | public final float getShift() {
31 | return shift;
32 | }
33 |
34 | public final short getNumberapo() {
35 | return numberapo;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/A2LParser/src/a2l/FixAxisParDist.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 12 mars 2019
3 | */
4 | package a2l;
5 |
6 | import java.util.List;
7 |
8 | public final class FixAxisParDist {
9 |
10 | private final float offset;
11 | private final float distance;
12 | private final short numberapo;
13 |
14 | public FixAxisParDist(List parameters) {
15 |
16 | this.offset = Float.parseFloat(parameters.get(0));
17 | this.distance = Float.parseFloat(parameters.get(1));
18 | this.numberapo = (short) Integer.parseInt(parameters.get(2));
19 |
20 | }
21 |
22 | public final double compute(int numVal) {
23 | return offset + (numVal * distance);
24 | }
25 |
26 | public float getOffset() {
27 | return offset;
28 | }
29 |
30 | public float getDistance() {
31 | return distance;
32 | }
33 |
34 | public short getNumberapo() {
35 | return numberapo;
36 | }
37 | }
--------------------------------------------------------------------------------
/A2LParser/src/a2l/FixAxisParList.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 12 mars 2019
3 | */
4 | package a2l;
5 |
6 | import java.util.List;
7 |
8 | public final class FixAxisParList {
9 |
10 | private final float[] axisPtsValue;
11 |
12 | public FixAxisParList(List parameters) {
13 |
14 | axisPtsValue = new float[parameters.size()];
15 |
16 | for (short n = 0; n < axisPtsValue.length; n++) {
17 | axisPtsValue[n] = Float.parseFloat(parameters.get(n));
18 | }
19 | }
20 |
21 | public final short getNbValue() {
22 | return (short) axisPtsValue.length;
23 | }
24 |
25 | public final double compute(int numVal) {
26 | return axisPtsValue[numVal];
27 | }
28 | }
--------------------------------------------------------------------------------
/A2LParser/src/a2l/Format.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 10 oct. 2020
3 | */
4 | package a2l;
5 |
6 | import utils.NumeralString;
7 |
8 | public final class Format {
9 |
10 | private byte overallLength;
11 | private byte decimalesPlace;
12 |
13 | public Format(String txtFormat) {
14 |
15 | int idxDot = txtFormat.indexOf('.');
16 | if (idxDot > -1) {
17 | if (txtFormat.charAt(idxDot - 1) != '%') {
18 | if (idxDot > 1) {
19 | this.overallLength = Byte.parseByte(txtFormat.substring(1, idxDot));
20 | } else {
21 | this.overallLength = Byte.parseByte(txtFormat.substring(0, idxDot));
22 | }
23 |
24 | } else {
25 | this.overallLength = -1;
26 | }
27 |
28 | String tmpVal = txtFormat.substring(idxDot + 1);
29 | if (NumeralString.isNumber(tmpVal)) {
30 | this.decimalesPlace = Byte.parseByte(tmpVal);
31 | } else {
32 | // Default decimalesPlace
33 | this.decimalesPlace = 2;
34 | }
35 | } else {
36 | this.overallLength = 16;
37 | this.decimalesPlace = 16;
38 | }
39 | }
40 |
41 | public final byte getOverallLength() {
42 | return overallLength;
43 | }
44 |
45 | public final byte getDecimalesPlace() {
46 | return decimalesPlace;
47 | }
48 |
49 | @Override
50 | public String toString() {
51 | return this.overallLength != -1 ? "%" + this.overallLength + "." + this.decimalesPlace : "%." + this.decimalesPlace;
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/A2LParser/src/a2l/Function.java:
--------------------------------------------------------------------------------
1 | package a2l;
2 |
3 | import static constante.SecondaryKeywords.DEF_CHARACTERISTIC;
4 | import static constante.SecondaryKeywords.FUNCTION_VERSION;
5 | import static constante.SecondaryKeywords.IN_MEASUREMENT;
6 | import static constante.SecondaryKeywords.LOC_MEASUREMENT;
7 | import static constante.SecondaryKeywords.OUT_MEASUREMENT;
8 | import static constante.SecondaryKeywords.REF_CHARACTERISTIC;
9 | import static constante.SecondaryKeywords.SUB_FUNCTION;
10 |
11 | import java.util.Collections;
12 | import java.util.HashMap;
13 | import java.util.List;
14 | import java.util.Map;
15 | import java.util.Vector;
16 |
17 | import constante.SecondaryKeywords;
18 |
19 | public final class Function implements A2lObject, Comparable {
20 |
21 | private String name;
22 | private char[] longIdentifier;
23 |
24 | private Map optionalsParameters;
25 |
26 | public Function(List parameters, int beginLine, int endLine) {
27 |
28 | optionalsParameters = new HashMap();
29 |
30 | build(parameters, beginLine, endLine);
31 | }
32 |
33 | @Override
34 | public String toString() {
35 | return this.name;
36 | }
37 |
38 | @SuppressWarnings("unchecked")
39 | public final Map getDefCharacteristic() {
40 | Object object = optionalsParameters.get(DEF_CHARACTERISTIC);
41 | return (Map) (object != null ? object : new HashMap());
42 | }
43 |
44 | @SuppressWarnings("unchecked")
45 | public final Vector getRefCharacteristic() {
46 | Object object = optionalsParameters.get(REF_CHARACTERISTIC);
47 | if (object != null) {
48 | Vector v = (Vector) object;
49 | Collections.sort(v);
50 | return v;
51 | }
52 | return new Vector();
53 | }
54 |
55 | @SuppressWarnings("unchecked")
56 | public final Vector getInMeasurement() {
57 | Object object = optionalsParameters.get(IN_MEASUREMENT);
58 | if (object != null) {
59 | Vector v = (Vector) object;
60 | Collections.sort(v);
61 | return v;
62 | }
63 | return new Vector();
64 | }
65 |
66 | @SuppressWarnings("unchecked")
67 | public final Vector getLocMeasurement() {
68 | Object object = optionalsParameters.get(LOC_MEASUREMENT);
69 | if (object != null) {
70 | Vector v = (Vector) object;
71 | Collections.sort(v);
72 | return v;
73 | }
74 | return new Vector();
75 | }
76 |
77 | @SuppressWarnings("unchecked")
78 | public final Vector getOutMeasurement() {
79 | Object object = optionalsParameters.get(OUT_MEASUREMENT);
80 | if (object != null) {
81 | Vector v = (Vector) object;
82 | Collections.sort(v);
83 | return v;
84 | }
85 | return new Vector();
86 | }
87 |
88 | @Override
89 | public int compareTo(Function function) {
90 | return this.name.compareToIgnoreCase(function.toString());
91 | }
92 |
93 | @Override
94 | public boolean isValid() {
95 | return true;
96 | }
97 |
98 | @Override
99 | public void build(List parameters, int beginLine, int endLine) throws IllegalArgumentException {
100 |
101 | final int nbParams = parameters.size();
102 |
103 | if (nbParams >= 2) {
104 |
105 | this.name = parameters.get(2).intern();
106 | this.longIdentifier = parameters.get(3).toCharArray();
107 |
108 | int n = 4;
109 |
110 | SecondaryKeywords keyWord;
111 | for (int nPar = n; nPar < nbParams; nPar++) {
112 | keyWord = SecondaryKeywords.getSecondaryKeyWords(parameters.get(nPar));
113 | switch (keyWord) {
114 | case DEF_CHARACTERISTIC:
115 | Map defCharacteristic = new HashMap();
116 | optionalsParameters.put(DEF_CHARACTERISTIC, defCharacteristic);
117 | nPar++;
118 | do {
119 | if (parameters.get(nPar).equals("/end")) {
120 | break;
121 | }
122 | defCharacteristic.put(parameters.get(nPar).hashCode(), this.name);
123 | nPar++;
124 | } while (nPar < nbParams - 1 && !parameters.get(nPar).equals("/end"));
125 | nPar++;
126 | break;
127 | case REF_CHARACTERISTIC:
128 | Vector refCharacteristic = new Vector();
129 | optionalsParameters.put(REF_CHARACTERISTIC, refCharacteristic);
130 | nPar++;
131 | do {
132 | if (parameters.get(nPar).equals("/end")) {
133 | break;
134 | }
135 | refCharacteristic.add(parameters.get(nPar));
136 | nPar++;
137 | } while (nPar < nbParams - 1 && !parameters.get(nPar).equals("/end"));
138 | nPar++;
139 | break;
140 | case FUNCTION_VERSION:
141 | optionalsParameters.put(FUNCTION_VERSION, parameters.get(++nPar));
142 | nPar++;
143 | break;
144 | case IN_MEASUREMENT:
145 | Vector inMeasurement = new Vector();
146 | optionalsParameters.put(IN_MEASUREMENT, inMeasurement);
147 | nPar++;
148 | do {
149 | if (parameters.get(nPar).equals("/end")) {
150 | break;
151 | }
152 | inMeasurement.add(parameters.get(nPar));
153 | nPar++;
154 | } while (nPar < nbParams - 1 && !parameters.get(nPar).equals("/end"));
155 | nPar++;
156 | break;
157 | case LOC_MEASUREMENT:
158 | Vector locMeasurement = new Vector();
159 | optionalsParameters.put(LOC_MEASUREMENT, locMeasurement);
160 | nPar++;
161 | do {
162 | if (parameters.get(nPar).equals("/end")) {
163 | break;
164 | }
165 | locMeasurement.add(parameters.get(nPar));
166 | nPar++;
167 | } while (nPar < nbParams - 1 && !parameters.get(nPar).equals("/end"));
168 | nPar++;
169 | break;
170 | case OUT_MEASUREMENT:
171 | Vector outMeasurement = new Vector();
172 | optionalsParameters.put(OUT_MEASUREMENT, outMeasurement);
173 | nPar++;
174 | do {
175 | if (parameters.get(nPar).equals("/end")) {
176 | break;
177 | }
178 | outMeasurement.add(parameters.get(nPar));
179 | nPar++;
180 | } while (nPar < nbParams - 1 && !parameters.get(nPar).equals("/end"));
181 | nPar++;
182 | break;
183 | case SUB_FUNCTION:
184 | Vector subFunction = new Vector();
185 | optionalsParameters.put(SUB_FUNCTION, subFunction);
186 | nPar++;
187 | do {
188 | if (parameters.get(nPar).equals("/end")) {
189 | break;
190 | }
191 | subFunction.add(parameters.get(nPar));
192 | nPar++;
193 | } while (nPar < nbParams - 1 && !parameters.get(nPar).equals("/end"));
194 | nPar++;
195 | break;
196 |
197 | default:
198 | break;
199 | }
200 | }
201 |
202 | } else {
203 | throw new IllegalArgumentException("Nombre de parametres inferieur au nombre requis");
204 | }
205 |
206 | }
207 |
208 | @SuppressWarnings("unchecked")
209 | public final Vector getSubFunction() {
210 | Object object = optionalsParameters.get(SUB_FUNCTION);
211 |
212 | return object != null ? (Vector) object : new Vector();
213 | }
214 |
215 | @Override
216 | public String getProperties() {
217 | StringBuilder sb = new StringBuilder("PROPERTIES :");
218 |
219 | sb.append("
- Name: " + name + "\n");
220 | sb.append("
- Long identifier: " + new String(longIdentifier) + "\n");
221 |
222 | if (getSubFunction().size() > 0) {
223 | sb.append("
- Sub Function: ");
224 | sb.append("
");
225 | for (String subFunction : getSubFunction()) {
226 | sb.append("- " + subFunction);
227 | }
228 | }
229 |
230 | sb.append("");
231 |
232 | return sb.toString();
233 | }
234 | }
235 |
--------------------------------------------------------------------------------
/A2LParser/src/a2l/Group.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 20 févr. 2025
3 | */
4 | package a2l;
5 |
6 | import static constante.SecondaryKeywords.REF_CHARACTERISTIC;
7 | import static constante.SecondaryKeywords.REF_MEASUREMENT;
8 | import static constante.SecondaryKeywords.ROOT;
9 | import static constante.SecondaryKeywords.SUB_GROUP;
10 |
11 | import java.util.HashMap;
12 | import java.util.List;
13 | import java.util.Map;
14 | import java.util.Vector;
15 |
16 | import constante.SecondaryKeywords;
17 |
18 | public class Group implements A2lObject, Comparable {
19 |
20 | private String name;
21 | private char[] longIdentifier;
22 |
23 | private Map optionalsParameters;
24 |
25 | public Group(List parameters, int beginLine, int endLine) {
26 |
27 | optionalsParameters = new HashMap();
28 |
29 | build(parameters, beginLine, endLine);
30 | }
31 |
32 | @Override
33 | public void build(List parameters, int beginLine, int endLine) throws A2lObjectParsingException {
34 |
35 | final int nbParams = parameters.size();
36 |
37 | if (nbParams >= 2) {
38 |
39 | this.name = parameters.get(2).intern();
40 | this.longIdentifier = parameters.get(3).toCharArray();
41 |
42 | int n = 4;
43 |
44 | SecondaryKeywords keyWord;
45 | for (int nPar = n; nPar < nbParams; nPar++) {
46 | keyWord = SecondaryKeywords.getSecondaryKeyWords(parameters.get(nPar));
47 | switch (keyWord) {
48 | case ROOT:
49 | optionalsParameters.put(ROOT, "ROOT");
50 | break;
51 | case REF_CHARACTERISTIC:
52 | Vector refCharacteristic = new Vector();
53 | optionalsParameters.put(REF_CHARACTERISTIC, refCharacteristic);
54 | nPar++;
55 | do {
56 | if (parameters.get(nPar).equals("/end")) {
57 | break;
58 | }
59 | refCharacteristic.add(parameters.get(nPar));
60 | nPar++;
61 | } while (nPar < nbParams - 1 && !parameters.get(nPar).equals("/end"));
62 | nPar++;
63 | break;
64 | case FUNCTION_LIST:
65 | // optionalsParameters.put(FUNCTION_LIST, parameters.get(++nPar));
66 | nPar++;
67 | break;
68 | case REF_MEASUREMENT:
69 | Vector outMeasurement = new Vector();
70 | optionalsParameters.put(REF_MEASUREMENT, outMeasurement);
71 | nPar++;
72 | do {
73 | if (parameters.get(nPar).equals("/end")) {
74 | break;
75 | }
76 | outMeasurement.add(parameters.get(nPar));
77 | nPar++;
78 | } while (nPar < nbParams - 1 && !parameters.get(nPar).equals("/end"));
79 | nPar++;
80 | break;
81 | case SUB_GROUP:
82 | Vector subFunction = new Vector();
83 | optionalsParameters.put(SUB_GROUP, subFunction);
84 | nPar++;
85 | do {
86 | if (parameters.get(nPar).equals("/end")) {
87 | break;
88 | }
89 | subFunction.add(parameters.get(nPar));
90 | nPar++;
91 | } while (nPar < nbParams - 1 && !parameters.get(nPar).equals("/end"));
92 | nPar++;
93 | break;
94 |
95 | default:
96 | break;
97 | }
98 | }
99 |
100 | } else {
101 | throw new IllegalArgumentException("Nombre de parametres inferieur au nombre requis");
102 | }
103 |
104 | }
105 |
106 | @SuppressWarnings("unchecked")
107 | public final Vector getSubGroup() {
108 | Object object = optionalsParameters.get(SUB_GROUP);
109 |
110 | return object != null ? (Vector) object : new Vector();
111 | }
112 |
113 | @Override
114 | public String toString() {
115 | return this.name;
116 | }
117 |
118 | @Override
119 | public boolean isValid() {
120 | return true;
121 | }
122 |
123 | @Override
124 | public String getProperties() {
125 | StringBuilder sb = new StringBuilder("PROPERTIES :");
126 |
127 | sb.append("
- Name: " + name + "\n");
128 | sb.append("
- Long identifier: " + new String(longIdentifier) + "\n");
129 |
130 | if (getSubGroup().size() > 0) {
131 | sb.append("
- Sub Group: ");
132 | sb.append("
");
133 | for (String subFunction : getSubGroup()) {
134 | sb.append("- " + subFunction);
135 | }
136 | }
137 |
138 | sb.append("");
139 |
140 | return sb.toString();
141 | }
142 |
143 | @Override
144 | public int compareTo(Group group) {
145 | return this.name.compareToIgnoreCase(group.toString());
146 | }
147 |
148 | }
149 |
--------------------------------------------------------------------------------
/A2LParser/src/a2l/Measurement.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 3 janv. 2019
3 | */
4 | package a2l;
5 |
6 | import static constante.SecondaryKeywords.ANNOTATION;
7 | import static constante.SecondaryKeywords.BIT_MASK;
8 | import static constante.SecondaryKeywords.BYTE_ORDER;
9 | import static constante.SecondaryKeywords.DISPLAY_IDENTIFIER;
10 | import static constante.SecondaryKeywords.FORMAT;
11 | import static constante.SecondaryKeywords.MATRIX_DIM;
12 | import static constante.SecondaryKeywords.PHYS_UNIT;
13 |
14 | import java.util.ArrayList;
15 | import java.util.HashMap;
16 | import java.util.List;
17 | import java.util.Map;
18 |
19 | import constante.DataType;
20 | import constante.SecondaryKeywords;
21 |
22 | public final class Measurement implements A2lObject, Comparable {
23 |
24 | private String name;
25 | private char[] longIdentifier;
26 | private DataType dataType;
27 | private int conversionId;
28 | @SuppressWarnings("unused")
29 | private byte resolution;
30 | @SuppressWarnings("unused")
31 | private float accuracy;
32 | private float lowerLimit;
33 | private float upperLimit;
34 |
35 | private CompuMethod compuMethod;
36 |
37 | private Map optionalsParameters;
38 |
39 | public Measurement(List parameters, int beginLine, int endLine) {
40 |
41 | optionalsParameters = new HashMap();
42 |
43 | build(parameters, beginLine, endLine);
44 | }
45 |
46 | public final Annotation getAnnotation() {
47 | Object object = optionalsParameters.get(ANNOTATION);
48 | return object != null ? (Annotation) object : null;
49 | }
50 |
51 | @Override
52 | public String toString() {
53 | return this.name;
54 | }
55 |
56 | @Override
57 | public boolean isValid() {
58 | return true;
59 | }
60 |
61 | @Override
62 | public void build(List parameters, int beginLine, int endLine) throws IllegalArgumentException {
63 |
64 | final int nbParams = parameters.size();
65 |
66 | try {
67 | if (nbParams >= 8) {
68 | this.name = parameters.get(2);
69 | this.longIdentifier = parameters.get(3).toCharArray();
70 | this.dataType = DataType.getDataType(parameters.get(4));
71 | this.conversionId = parameters.get(5).hashCode();
72 | this.resolution = (byte) Integer.parseInt(parameters.get(6));
73 | this.accuracy = Float.parseFloat(parameters.get(7));
74 | this.lowerLimit = Float.parseFloat(parameters.get(8));
75 | if (parameters.get(9).startsWith("0x")) { // Test pour A2L AW
76 | this.upperLimit = Integer.parseInt(parameters.get(9).substring(2), 16);
77 | } else {
78 | this.upperLimit = Float.parseFloat(parameters.get(9));
79 | }
80 |
81 | int n = 10;
82 |
83 | SecondaryKeywords keyWord;
84 | for (int nPar = n; nPar < nbParams; nPar++) {
85 | keyWord = SecondaryKeywords.getSecondaryKeyWords(parameters.get(nPar));
86 | switch (keyWord) {
87 | case ANNOTATION:
88 | n = nPar + 1;
89 | do {
90 | } while (!parameters.get(++nPar).equals(ANNOTATION.name()));
91 | optionalsParameters.put(ANNOTATION, new Annotation(parameters.subList(n, nPar - 3)));
92 | n = nPar + 1;
93 | break;
94 | case BIT_MASK:
95 | String bitMask = parameters.get(nPar + 1);
96 | if (bitMask.startsWith("0x")) {
97 | optionalsParameters.put(BIT_MASK, Long.parseLong(bitMask.substring(2), 16));
98 | } else {
99 | optionalsParameters.put(BIT_MASK, Long.parseLong(bitMask));
100 | }
101 | nPar += 1;
102 | break;
103 | case BYTE_ORDER:
104 | optionalsParameters.put(BYTE_ORDER, parameters.get(nPar + 1));
105 | nPar += 1;
106 | break;
107 | case DISPLAY_IDENTIFIER:
108 | optionalsParameters.put(DISPLAY_IDENTIFIER, parameters.get(nPar + 1).toCharArray());
109 | nPar += 1;
110 | break;
111 | case FORMAT:
112 | optionalsParameters.put(FORMAT, new Format(parameters.get(nPar + 1)));
113 | nPar += 1;
114 | break;
115 | case MATRIX_DIM:
116 | List dim = new ArrayList();
117 |
118 | try {
119 | nPar += 1;
120 | do {
121 | dim.add((short) Integer.parseInt(parameters.get(nPar)));
122 | nPar += 1;
123 | } while (nPar < parameters.size());
124 | } catch (NumberFormatException nfe) {
125 | nPar += 1;
126 | }
127 | optionalsParameters.put(MATRIX_DIM, dim.toArray());
128 | dim.clear();
129 | break;
130 | case PHYS_UNIT:
131 | optionalsParameters.put(PHYS_UNIT, parameters.get(nPar + 1).toCharArray());
132 | nPar += 1;
133 | break;
134 | default:
135 | break;
136 | }
137 | }
138 |
139 | } else {
140 | throw new IllegalArgumentException("Nombre de parametres inferieur au nombre requis");
141 | }
142 | } catch (IllegalArgumentException e) {
143 | throw new A2lObjectParsingException("Parsing error on " + this.name, beginLine, endLine);
144 | }
145 |
146 | }
147 |
148 | public final void assignComputMethod(HashMap compuMethods) {
149 | this.compuMethod = compuMethods.get(this.conversionId);
150 | if (this.compuMethod == null) {
151 | this.compuMethod = CompuMethod.createNoCompuMethod();
152 | }
153 | }
154 |
155 | public final String getUnit() {
156 | Object oPhysUnit = optionalsParameters.get(PHYS_UNIT);
157 |
158 | return (oPhysUnit != null && "NO_COMPU_METHOD".equals(conversionId)) ? new String((char[]) oPhysUnit) : compuMethod.getUnit();
159 | }
160 |
161 | @Override
162 | public String getProperties() {
163 | StringBuilder sb = new StringBuilder("PROPERTIES :");
164 |
165 | sb.append("
- Name: " + name + "\n");
166 | sb.append("
- Long identifier: " + new String(longIdentifier) + "\n");
167 | sb.append("
- Data type: " + dataType + "\n");
168 | sb.append("
- Conversion: " + compuMethod.toString() + "\n");
169 | sb.append("
- Unit: " + "[" + getUnit() + "]\n");
170 | sb.append("
- Lower limit: " + lowerLimit + "\n");
171 | sb.append("
- Upper limit: " + upperLimit + "\n");
172 | sb.append("
");
173 |
174 | sb.append("OPTIONALS PARAMETERS :");
175 | Annotation annotation = getAnnotation();
176 | if (annotation != null) {
177 | sb.append("- Annotation : ");
178 | sb.append("
");
179 | sb.append("- " + "Label : " + getAnnotation().getAnnotationParam(SecondaryKeywords.ANNOTATION_LABEL) + "\n");
180 | sb.append("
- " + "Text : " + getAnnotation().getAnnotationParam(SecondaryKeywords.ANNOTATION_TEXT) + "\n");
181 | sb.append("
- " + "Origine : " + getAnnotation().getAnnotationParam(SecondaryKeywords.ANNOTATION_ORIGIN) + "\n");
182 | }
183 |
184 | sb.append("");
185 |
186 | return sb.toString();
187 | }
188 |
189 | @Override
190 | public int compareTo(Measurement measurement) {
191 | return this.name.compareToIgnoreCase(measurement.name);
192 | }
193 |
194 | }
195 |
--------------------------------------------------------------------------------
/A2LParser/src/a2l/ModCommon.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 20 févr. 2019
3 | */
4 | package a2l;
5 |
6 | import static constante.SecondaryKeywords.ALIGNMENT_BYTE;
7 | import static constante.SecondaryKeywords.ALIGNMENT_FLOAT16_IEEE;
8 | import static constante.SecondaryKeywords.ALIGNMENT_FLOAT32_IEEE;
9 | import static constante.SecondaryKeywords.ALIGNMENT_FLOAT64_IEEE;
10 | import static constante.SecondaryKeywords.ALIGNMENT_INT64;
11 | import static constante.SecondaryKeywords.ALIGNMENT_LONG;
12 | import static constante.SecondaryKeywords.ALIGNMENT_WORD;
13 | import static constante.SecondaryKeywords.BYTE_ORDER;
14 | import static constante.SecondaryKeywords.DATA_SIZE;
15 | import static constante.SecondaryKeywords.DEPOSIT;
16 |
17 | import java.nio.ByteOrder;
18 | import java.util.HashMap;
19 | import java.util.List;
20 | import java.util.Map;
21 |
22 | import constante.DataType;
23 | import constante.SecondaryKeywords;
24 | import data.DataCalibration;
25 | import data.MotorolaS19;
26 |
27 | public final class ModCommon implements A2lObject {
28 |
29 | private char[] comment;
30 |
31 | private Map optionalsParameters;
32 |
33 | public ModCommon(List parameters, int beginLine, int endLine) {
34 |
35 | initOptionalsParameters();
36 |
37 | build(parameters, beginLine, endLine);
38 | }
39 |
40 | public ModCommon(DataCalibration data) {
41 | initOptionalsParameters();
42 |
43 | if (data instanceof MotorolaS19) {
44 | optionalsParameters.put(BYTE_ORDER, "MSB_FIRST");
45 | }
46 | }
47 |
48 | private final void initOptionalsParameters() {
49 | optionalsParameters = new HashMap();
50 | optionalsParameters.put(ALIGNMENT_BYTE, 1);
51 | optionalsParameters.put(ALIGNMENT_FLOAT16_IEEE, 2);
52 | optionalsParameters.put(ALIGNMENT_FLOAT32_IEEE, 4);
53 | optionalsParameters.put(ALIGNMENT_FLOAT64_IEEE, 8);
54 | optionalsParameters.put(ALIGNMENT_INT64, 8);
55 | optionalsParameters.put(ALIGNMENT_LONG, 4);
56 | optionalsParameters.put(ALIGNMENT_WORD, 2);
57 | optionalsParameters.put(BYTE_ORDER, "MSB_LAST"); // If this optional parameter is not declared, MSB_LAST (Intel format) is used as a default
58 | }
59 |
60 | public final int getAlignment(DataType dataType) {
61 |
62 | switch (dataType) {
63 | case UBYTE:
64 | return (int) optionalsParameters.get(ALIGNMENT_BYTE);
65 | case SBYTE:
66 | return (int) optionalsParameters.get(ALIGNMENT_BYTE);
67 | case UWORD:
68 | return (int) optionalsParameters.get(ALIGNMENT_WORD);
69 | case SWORD:
70 | return (int) optionalsParameters.get(ALIGNMENT_WORD);
71 | case ULONG:
72 | return (int) optionalsParameters.get(ALIGNMENT_LONG);
73 | case SLONG:
74 | return (int) optionalsParameters.get(ALIGNMENT_LONG);
75 | case FLOAT16_IEEE:
76 | return (int) optionalsParameters.get(ALIGNMENT_FLOAT16_IEEE);
77 | case FLOAT32_IEEE:
78 | return (int) optionalsParameters.get(ALIGNMENT_FLOAT32_IEEE);
79 | case FLOAT64_IEEE:
80 | return (int) optionalsParameters.get(ALIGNMENT_FLOAT64_IEEE);
81 | case A_UINT64:
82 | return (int) optionalsParameters.get(ALIGNMENT_INT64);
83 | case A_INT64:
84 | return (int) optionalsParameters.get(ALIGNMENT_INT64);
85 | default:
86 | return 0;
87 | }
88 | }
89 |
90 | public final ByteOrder getByteOrder() {
91 | String sByteOrder = (String) optionalsParameters.get(BYTE_ORDER);
92 | if ("MSB_LAST".equals(sByteOrder) || "BIG_ENDIAN".equals(sByteOrder)) {
93 | return ByteOrder.LITTLE_ENDIAN;
94 | }
95 | return ByteOrder.BIG_ENDIAN;
96 | }
97 |
98 | public final String getComment() {
99 | return new String(comment);
100 | }
101 |
102 | @Override
103 | public boolean isValid() {
104 | return true;
105 | }
106 |
107 | @Override
108 | public void build(List parameters, int beginLine, int endLine) throws IllegalArgumentException {
109 |
110 | final int nbParams = parameters.size();
111 |
112 | if (nbParams >= 1) {
113 | for (int n = 2; n < nbParams; n++) {
114 | switch (n) {
115 | case 2:
116 | this.comment = parameters.get(n).toCharArray();
117 | break;
118 | default: // Cas de parametres optionels
119 | SecondaryKeywords keyWord;
120 | for (int nPar = n; nPar < nbParams; nPar++) {
121 | keyWord = SecondaryKeywords.getSecondaryKeyWords(parameters.get(nPar));
122 | switch (keyWord) {
123 | case ALIGNMENT_BYTE:
124 | optionalsParameters.put(ALIGNMENT_BYTE, Integer.parseInt(parameters.get(nPar + 1)));
125 | break;
126 | case ALIGNMENT_FLOAT16_IEEE:
127 | optionalsParameters.put(ALIGNMENT_FLOAT16_IEEE, Integer.parseInt(parameters.get(nPar + 1)));
128 | break;
129 | case ALIGNMENT_FLOAT32_IEEE:
130 | optionalsParameters.put(ALIGNMENT_FLOAT32_IEEE, Integer.parseInt(parameters.get(nPar + 1)));
131 | break;
132 | case ALIGNMENT_FLOAT64_IEEE:
133 | optionalsParameters.put(ALIGNMENT_FLOAT64_IEEE, Integer.parseInt(parameters.get(nPar + 1)));
134 | break;
135 | case ALIGNMENT_INT64:
136 | optionalsParameters.put(ALIGNMENT_INT64, Integer.parseInt(parameters.get(nPar + 1)));
137 | break;
138 | case ALIGNMENT_LONG:
139 | optionalsParameters.put(ALIGNMENT_LONG, Integer.parseInt(parameters.get(nPar + 1)));
140 | break;
141 | case ALIGNMENT_WORD:
142 | optionalsParameters.put(ALIGNMENT_WORD, Integer.parseInt(parameters.get(nPar + 1)));
143 | break;
144 | case BYTE_ORDER:
145 | optionalsParameters.put(BYTE_ORDER, parameters.get(nPar + 1));
146 | break;
147 | case DATA_SIZE:
148 | optionalsParameters.put(DATA_SIZE, Integer.parseInt(parameters.get(nPar + 1)));
149 | break;
150 | case DEPOSIT:
151 | optionalsParameters.put(DEPOSIT, parameters.get(nPar + 1));
152 | break;
153 | default:
154 | break;
155 | }
156 | }
157 | n = nbParams;
158 | break;
159 | }
160 | }
161 |
162 | } else {
163 | throw new IllegalArgumentException("Nombre de parametres inferieur au nombre requis");
164 | }
165 |
166 | }
167 |
168 | @Override
169 | public String getProperties() {
170 | StringBuilder sb = new StringBuilder("...");
171 |
172 | return sb.toString();
173 | }
174 |
175 | }
176 |
--------------------------------------------------------------------------------
/A2LParser/src/a2l/ModPar.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 20 févr. 2019
3 | */
4 | package a2l;
5 |
6 | import static constante.SecondaryKeywords.ADDR_EPK;
7 | import static constante.SecondaryKeywords.ECU_CALIBRATION_OFFSET;
8 | import static constante.SecondaryKeywords.EPK;
9 | import static constante.SecondaryKeywords.SYSTEM_CONSTANT;
10 |
11 | import java.util.ArrayList;
12 | import java.util.HashMap;
13 | import java.util.List;
14 | import java.util.Map;
15 |
16 | import constante.SecondaryKeywords;
17 |
18 | public final class ModPar implements A2lObject {
19 |
20 | private char[] comment;
21 |
22 | private Map optionalsParameters;
23 |
24 | public ModPar(List parameters, int beginLine, int endLine) {
25 |
26 | optionalsParameters = new HashMap();
27 |
28 | build(parameters, beginLine, endLine);
29 | }
30 |
31 | public final long getEPKAdress() {
32 | String addressEPK = ((String) optionalsParameters.get(ADDR_EPK));
33 | if (addressEPK != null) {
34 | return Long.parseLong(addressEPK.substring(2), 16);
35 | }
36 | return -1;
37 | }
38 |
39 | public final String getEPK() {
40 | return (String) optionalsParameters.get(EPK);
41 | }
42 |
43 | public final String getComment() {
44 | return new String(this.comment);
45 | }
46 |
47 | @SuppressWarnings("unchecked")
48 | public final List getSystemConstant() {
49 | Object object = optionalsParameters.get(SYSTEM_CONSTANT);
50 | return object != null ? (List) object : new ArrayList();
51 | }
52 |
53 | @Override
54 | public boolean isValid() {
55 | return true;
56 | }
57 |
58 | @Override
59 | public void build(List parameters, int beginLine, int endLine) throws IllegalArgumentException {
60 |
61 | final int nbParams = parameters.size();
62 |
63 | List systemConstant = new ArrayList();
64 |
65 | if (nbParams >= 1) {
66 | for (int n = 2; n < nbParams; n++) {
67 | switch (n) {
68 | case 2:
69 | this.comment = parameters.get(n).toCharArray();
70 | break;
71 | default: // Cas de parametres optionels
72 | SecondaryKeywords keyWord;
73 | for (int nPar = n; nPar < nbParams; nPar++) {
74 | keyWord = SecondaryKeywords.getSecondaryKeyWords(parameters.get(nPar));
75 | switch (keyWord) {
76 | case ADDR_EPK:
77 | optionalsParameters.put(ADDR_EPK, parameters.get(nPar + 1));
78 | nPar += 1;
79 | break;
80 | case ECU_CALIBRATION_OFFSET:
81 | optionalsParameters.put(ECU_CALIBRATION_OFFSET, parameters.get(nPar + 1));
82 | nPar += 1;
83 | break;
84 | case EPK:
85 | optionalsParameters.put(EPK, parameters.get(nPar + 1));
86 | nPar += 1;
87 | break;
88 | case SYSTEM_CONSTANT:
89 | if (systemConstant.isEmpty()) {
90 | optionalsParameters.put(SYSTEM_CONSTANT, systemConstant);
91 | }
92 | systemConstant.add(new SystemConstant(parameters.subList(nPar + 1, nPar + 3)));
93 | nPar += 2;
94 | break;
95 | default:
96 | break;
97 | }
98 | }
99 | n = nbParams;
100 | break;
101 | }
102 | }
103 | } else {
104 | throw new IllegalArgumentException("Nombre de parametres inferieur au nombre requis");
105 | }
106 |
107 | }
108 |
109 | @Override
110 | public String getProperties() {
111 | StringBuilder sb = new StringBuilder("...");
112 |
113 | return sb.toString();
114 | }
115 |
116 | }
117 |
--------------------------------------------------------------------------------
/A2LParser/src/a2l/OptionalParameterRL.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 31 mars 2019
3 | */
4 | package a2l;
5 |
6 | public abstract class OptionalParameterRL {
7 |
8 | protected byte position;
9 |
10 | public final byte getPosition() {
11 | return position;
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/A2LParser/src/a2l/RecordLayout_old.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 20 févr. 2019
3 | */
4 | package a2l;
5 |
6 | import static constante.SecondaryKeywords.AXIS_PTS_X;
7 | import static constante.SecondaryKeywords.AXIS_PTS_Y;
8 | import static constante.SecondaryKeywords.AXIS_RESCALE_X;
9 | import static constante.SecondaryKeywords.FNC_VALUES;
10 | import static constante.SecondaryKeywords.NO_AXIS_PTS_X;
11 | import static constante.SecondaryKeywords.NO_AXIS_PTS_Y;
12 | import static constante.SecondaryKeywords.NO_RESCALE_X;
13 | import static constante.SecondaryKeywords.RESERVED;
14 | import static constante.SecondaryKeywords.SRC_ADDR_X;
15 | import static constante.SecondaryKeywords.SRC_ADDR_Y;
16 |
17 | import java.util.Collections;
18 | import java.util.HashMap;
19 | import java.util.Iterator;
20 | import java.util.List;
21 | import java.util.Map;
22 | import java.util.TreeMap;
23 |
24 | import constante.AdressType;
25 | import constante.DataSize;
26 | import constante.DataType;
27 | import constante.IndexMode;
28 | import constante.IndexOrder;
29 | import constante.SecondaryKeywords;
30 |
31 | public final class RecordLayout_old implements A2lObject, Comparable {
32 |
33 | private String name;
34 |
35 | private Map optionalsParameters;
36 |
37 | public RecordLayout_old(List parameters, int beginLine, int endLine) {
38 |
39 | optionalsParameters = new HashMap();
40 |
41 | build(parameters, beginLine, endLine);
42 | }
43 |
44 | @Override
45 | public String toString() {
46 | return this.name;
47 | }
48 |
49 | public final Map getSortedObject() {
50 | TreeMap treeMap = new TreeMap();
51 |
52 | Iterator> iter = optionalsParameters.entrySet().iterator();
53 | while (iter.hasNext()) {
54 | Map.Entry entry = iter.next();
55 | treeMap.put(entry.getValue().getPosition(), entry.getValue());
56 | }
57 |
58 | return treeMap;
59 | }
60 |
61 | public FncValues getFncValues() {
62 | return (FncValues) optionalsParameters.get(FNC_VALUES);
63 | }
64 |
65 | public NoAxisPtsX getNoAxisPtsX() {
66 | Object object = optionalsParameters.get(NO_AXIS_PTS_X);
67 | return object != null ? (NoAxisPtsX) object : null;
68 | }
69 |
70 | public AxisPtsX getAxisPtsX() {
71 | Object object = optionalsParameters.get(AXIS_PTS_X);
72 | return object != null ? (AxisPtsX) object : null;
73 | }
74 |
75 | public NoAxisPtsY getNoAxisPtsY() {
76 | Object object = optionalsParameters.get(NO_AXIS_PTS_Y);
77 | return object != null ? (NoAxisPtsY) object : null;
78 | }
79 |
80 | public AxisPtsY getAxisPtsY() {
81 | Object object = optionalsParameters.get(AXIS_PTS_Y);
82 | return object != null ? (AxisPtsY) object : null;
83 | }
84 |
85 | public SrcAddrX getSrcAddrX() {
86 | Object object = optionalsParameters.get(SRC_ADDR_X);
87 | return object != null ? (SrcAddrX) object : null;
88 | }
89 |
90 | public SrcAddrY getSrcAddrY() {
91 | Object object = optionalsParameters.get(SRC_ADDR_Y);
92 | return object != null ? (SrcAddrY) object : null;
93 | }
94 |
95 | public NoRescaleX getNoRescaleX() {
96 | Object object = optionalsParameters.get(NO_RESCALE_X);
97 | return object != null ? (NoRescaleX) object : null;
98 | }
99 |
100 | public Reserved getReserved() {
101 | Object object = optionalsParameters.get(RESERVED);
102 | return object != null ? (Reserved) object : null;
103 | }
104 |
105 | public AxisRescaleX getAxisRescaleX() {
106 | Object object = optionalsParameters.get(AXIS_RESCALE_X);
107 | return object != null ? (AxisRescaleX) object : null;
108 | }
109 |
110 | public final class FncValues extends OptionalParameterRL {
111 |
112 | private final DataType dataType;
113 | private final IndexMode indexMode;
114 | private final AdressType adressType;
115 |
116 | public FncValues(List parameters) {
117 | this.position = Byte.parseByte(parameters.get(0));
118 | this.dataType = DataType.getDataType(parameters.get(1));
119 | this.indexMode = IndexMode.getIndexMode(parameters.get(2));
120 | this.adressType = AdressType.getAdressType(parameters.get(3));
121 | }
122 |
123 | public final DataType getDataType() {
124 | return dataType;
125 | }
126 |
127 | public final IndexMode getIndexMode() {
128 | return indexMode;
129 | }
130 |
131 | public final AdressType getAdressType() {
132 | return adressType;
133 | }
134 | }
135 |
136 | public final class AxisPtsX extends OptionalParameterRL {
137 |
138 | private final DataType dataType;
139 | private final IndexOrder indexOrder;
140 | private final AdressType adressType;
141 |
142 | public AxisPtsX(List parameters) {
143 | this.position = Byte.parseByte(parameters.get(0));
144 | this.dataType = DataType.getDataType(parameters.get(1));
145 | this.indexOrder = IndexOrder.getIndexOrder(parameters.get(2));
146 | this.adressType = AdressType.getAdressType(parameters.get(3));
147 | }
148 |
149 | public final DataType getDataType() {
150 | return dataType;
151 | }
152 |
153 | public final IndexOrder getIndexOrder() {
154 | return indexOrder;
155 | }
156 |
157 | public final AdressType getAdressType() {
158 | return adressType;
159 | }
160 | }
161 |
162 | public final class NoAxisPtsX extends OptionalParameterRL {
163 |
164 | private final DataType dataType;
165 |
166 | public NoAxisPtsX(List parameters) {
167 | this.position = Byte.parseByte(parameters.get(0));
168 | this.dataType = DataType.getDataType(parameters.get(1));
169 | }
170 |
171 | public final DataType getDataType() {
172 | return dataType;
173 | }
174 |
175 | }
176 |
177 | public final class AxisPtsY extends OptionalParameterRL {
178 |
179 | private final DataType dataType;
180 | private final IndexOrder indexOrder;
181 | private final AdressType adressType;
182 |
183 | public AxisPtsY(List parameters) {
184 | this.position = Byte.parseByte(parameters.get(0));
185 | this.dataType = DataType.getDataType(parameters.get(1));
186 | this.indexOrder = IndexOrder.getIndexOrder(parameters.get(2));
187 | this.adressType = AdressType.getAdressType(parameters.get(3));
188 | }
189 |
190 | public final DataType getDataType() {
191 | return dataType;
192 | }
193 |
194 | public final IndexOrder getIndexOrder() {
195 | return indexOrder;
196 | }
197 |
198 | public final AdressType getAdressType() {
199 | return adressType;
200 | }
201 | }
202 |
203 | public final class NoAxisPtsY extends OptionalParameterRL {
204 |
205 | private final DataType dataType;
206 |
207 | public NoAxisPtsY(List parameters) {
208 | this.position = Byte.parseByte(parameters.get(0));
209 | this.dataType = DataType.getDataType(parameters.get(1));
210 | }
211 |
212 | public final DataType getDataType() {
213 | return dataType;
214 | }
215 |
216 | }
217 |
218 | public final class SrcAddrX extends OptionalParameterRL {
219 |
220 | private final DataType dataType;
221 |
222 | public SrcAddrX(List parameters) {
223 | this.position = Byte.parseByte(parameters.get(0));
224 | this.dataType = DataType.getDataType(parameters.get(1));
225 | }
226 |
227 | public final DataType getDataType() {
228 | return dataType;
229 | }
230 |
231 | }
232 |
233 | public final class SrcAddrY extends OptionalParameterRL {
234 |
235 | private final DataType dataType;
236 |
237 | public SrcAddrY(List parameters) {
238 | this.position = Byte.parseByte(parameters.get(0));
239 | this.dataType = DataType.getDataType(parameters.get(1));
240 | }
241 |
242 | public final DataType getDataType() {
243 | return dataType;
244 | }
245 |
246 | }
247 |
248 | public final class NoRescaleX extends OptionalParameterRL {
249 |
250 | private final DataType dataType;
251 |
252 | public NoRescaleX(List parameters) {
253 | this.position = Byte.parseByte(parameters.get(0));
254 | this.dataType = DataType.getDataType(parameters.get(1));
255 | }
256 |
257 | public final DataType getDataType() {
258 | return dataType;
259 | }
260 |
261 | }
262 |
263 | public final class Reserved extends OptionalParameterRL {
264 |
265 | private final DataSize dataSize;
266 |
267 | public Reserved(List parameters) {
268 | this.position = Byte.parseByte(parameters.get(0));
269 | this.dataSize = DataSize.getDataSize(parameters.get(1));
270 | }
271 |
272 | public final DataSize getDataSize() {
273 | return dataSize;
274 | }
275 | }
276 |
277 | public final class AxisRescaleX extends OptionalParameterRL {
278 |
279 | private final DataType dataType;
280 | private final short maxNumberOfRescalePairs;
281 | private final IndexOrder indexOrder;
282 | private final AdressType adressType;
283 |
284 | public AxisRescaleX(List parameters) {
285 | this.position = Byte.parseByte(parameters.get(0));
286 | this.dataType = DataType.getDataType(parameters.get(1));
287 | this.maxNumberOfRescalePairs = Short.parseShort(parameters.get(2));
288 | this.indexOrder = IndexOrder.getIndexOrder(parameters.get(3));
289 | this.adressType = AdressType.getAdressType(parameters.get(4));
290 | }
291 |
292 | public final DataType getDataType() {
293 | return dataType;
294 | }
295 |
296 | public final short getMaxNumberOfRescalePairs() {
297 | return maxNumberOfRescalePairs;
298 | }
299 |
300 | public final IndexOrder getIndexOrder() {
301 | return indexOrder;
302 | }
303 |
304 | public final AdressType getAdressType() {
305 | return adressType;
306 | }
307 | }
308 |
309 | @Override
310 | public int compareTo(RecordLayout_old o) {
311 | return this.name.compareTo(o.name);
312 | }
313 |
314 | @Override
315 | public boolean isValid() {
316 | return true;
317 | }
318 |
319 | @Override
320 | public void build(List parameters, int beginLine, int endLine) throws IllegalArgumentException {
321 |
322 | final int nbParams = parameters.size();
323 |
324 | List subList = Collections.emptyList();
325 |
326 | if (nbParams >= 1) {
327 | for (int n = 2; n < nbParams; n++) {
328 | switch (n) {
329 | case 2:
330 | this.name = parameters.get(n);
331 | break;
332 | default: // Cas de parametres optionels
333 | switch (parameters.get(n)) {
334 | case "FNC_VALUES":
335 | subList = parameters.subList(n + 1, n + 5);
336 | optionalsParameters.put(FNC_VALUES, new FncValues(subList));
337 | n += 4;
338 | break;
339 | case "AXIS_PTS_X":
340 | subList = parameters.subList(n + 1, n + 5);
341 | optionalsParameters.put(AXIS_PTS_X, new AxisPtsX(subList));
342 | n += 4;
343 | break;
344 | case "AXIS_PTS_Y":
345 | subList = parameters.subList(n + 1, n + 5);
346 | optionalsParameters.put(AXIS_PTS_Y, new AxisPtsY(subList));
347 | n += 4;
348 | break;
349 | case "NO_AXIS_PTS_X":
350 | subList = parameters.subList(n + 1, n + 3);
351 | optionalsParameters.put(NO_AXIS_PTS_X, new NoAxisPtsX(subList));
352 | n += 2;
353 | break;
354 | case "NO_AXIS_PTS_Y":
355 | subList = parameters.subList(n + 1, n + 3);
356 | optionalsParameters.put(NO_AXIS_PTS_Y, new NoAxisPtsY(subList));
357 | n += 2;
358 | break;
359 | case "AXIS_RESCALE_X":
360 | subList = parameters.subList(n + 1, n + 6);
361 | optionalsParameters.put(AXIS_RESCALE_X, new AxisRescaleX(subList));
362 | n += 5;
363 | break;
364 | case "NO_RESCALE_X":
365 | subList = parameters.subList(n + 1, n + 3);
366 | optionalsParameters.put(NO_RESCALE_X, new NoRescaleX(subList));
367 | n += 2;
368 | break;
369 | case "RESERVED":
370 | subList = parameters.subList(n + 1, n + 3);
371 | optionalsParameters.put(RESERVED, new Reserved(subList));
372 | n += 2;
373 | break;
374 | case "SRC_ADDR_X":
375 | subList = parameters.subList(n + 1, n + 3);
376 | optionalsParameters.put(SRC_ADDR_X, new SrcAddrX(subList));
377 | n += 2;
378 | break;
379 | case "SRC_ADDR_Y":
380 | subList = parameters.subList(n + 1, n + 3);
381 | optionalsParameters.put(SRC_ADDR_Y, new SrcAddrY(subList));
382 | n += 2;
383 | break;
384 | default:
385 | break;
386 | }
387 | break;
388 | }
389 | }
390 |
391 | subList.clear();
392 |
393 | } else {
394 | throw new IllegalArgumentException("Nombre de parametres inferieur au nombre requis");
395 | }
396 |
397 | }
398 |
399 | @Override
400 | public String getProperties() {
401 | StringBuilder sb = new StringBuilder("PROPERTIES :");
402 |
403 | sb.append("
- Name: " + name + "\n");
404 | sb.append("");
405 |
406 | return sb.toString();
407 | }
408 |
409 | }
410 |
--------------------------------------------------------------------------------
/A2LParser/src/a2l/SingleValue.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 3 oct. 2020
3 | */
4 | package a2l;
5 |
6 | public class SingleValue extends DataValue {
7 |
8 | private Object value;
9 |
10 | public SingleValue(Object value) {
11 | this.value = getStorageObject(value);
12 | }
13 |
14 | @Override
15 | public Object getValue(int... coord) {
16 | return this.value;
17 | }
18 |
19 | @Override
20 | public void setValue(Object value, int... coord) {
21 | this.value = getStorageObject(value);
22 | }
23 |
24 | @Override
25 | public short getDimX() {
26 | return 1;
27 | }
28 |
29 | @Override
30 | public short getDimY() {
31 | return 1;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/A2LParser/src/a2l/SystemConstant.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 8 avr. 2019
3 | */
4 | package a2l;
5 |
6 | import java.util.List;
7 |
8 | public final class SystemConstant implements A2lObject, Comparable {
9 |
10 | private String name;
11 | private char[] value;
12 |
13 | public SystemConstant(List parameters) {
14 |
15 | build(parameters, 0, 0);
16 |
17 | }
18 |
19 | public final String getName() {
20 | return this.name;
21 | }
22 |
23 | public final String getValue() {
24 | return new String(this.value);
25 | }
26 |
27 | @Override
28 | public String toString() {
29 | return this.name;
30 | }
31 |
32 | @Override
33 | public int compareTo(SystemConstant o) {
34 | return this.name.compareTo(o.name);
35 | }
36 |
37 | @Override
38 | public boolean isValid() {
39 | return true;
40 | }
41 |
42 | @Override
43 | public void build(List parameters, int beginLine, int endLine) throws A2lObjectParsingException {
44 | this.name = parameters.get(0);
45 | this.value = parameters.get(1).toCharArray();
46 | }
47 |
48 | @Override
49 | public String getProperties() {
50 | StringBuilder sb = new StringBuilder("PROPERTIES :");
51 |
52 | sb.append("
- Name: " + name + "\n");
53 | sb.append("
- Value: " + getValue() + "\n");
54 | sb.append("");
55 |
56 | return sb.toString();
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/A2LParser/src/a2l/TableModelView.java:
--------------------------------------------------------------------------------
1 | package a2l;
2 |
3 | import javax.swing.table.AbstractTableModel;
4 |
5 | public final class TableModelView extends AbstractTableModel {
6 |
7 | private static final long serialVersionUID = 1L;
8 |
9 | private static final String EMPTY = "";
10 | private int nbCol = 0;
11 | private DataValue values;
12 |
13 | @Override
14 | public String getColumnName(int column) {
15 | return EMPTY;
16 | }
17 |
18 | @Override
19 | public boolean isCellEditable(int rowIndex, int columnIndex) {
20 | return false;
21 | }
22 |
23 | @Override
24 | public int getColumnCount() {
25 | return nbCol;
26 | }
27 |
28 | @Override
29 | public int getRowCount() {
30 | return values != null ? values.getDimY() : 0;
31 | }
32 |
33 | @Override
34 | public Object getValueAt(int row, int col) {
35 |
36 | final Object value = values.getValue(row, col);
37 |
38 | return value != null ? value : EMPTY;
39 | }
40 |
41 | public final void setData(DataValue data) {
42 | this.values = data;
43 | this.nbCol = values != null ? values.getDimX() : 0;
44 |
45 | fireTableStructureChanged();
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/A2LParser/src/a2l/Unit.java:
--------------------------------------------------------------------------------
1 | package a2l;
2 |
3 | import static constante.SecondaryKeywords.REF_UNIT;
4 | import static constante.SecondaryKeywords.SI_EXPONENTS;
5 | import static constante.SecondaryKeywords.UNIT_CONVERSION;
6 |
7 | import java.util.HashMap;
8 | import java.util.List;
9 | import java.util.Map;
10 |
11 | import constante.SecondaryKeywords;
12 | import constante.UnitType;
13 |
14 | public final class Unit implements A2lObject, Comparable {
15 |
16 | private String name;
17 | private char[] longIdentifier;
18 | private char[] display;
19 | private UnitType unitType;
20 | private Map optionalsParameters;
21 |
22 | public Unit(List parameters, int beginLine, int endLine) {
23 |
24 | optionalsParameters = new HashMap();
25 |
26 | build(parameters, beginLine, endLine);
27 | }
28 |
29 | @Override
30 | public boolean isValid() {
31 | return true;
32 | }
33 |
34 | @Override
35 | public void build(List parameters, int beginLine, int endLine) throws A2lObjectParsingException {
36 |
37 | final int nbParams = parameters.size();
38 |
39 | if (nbParams >= 4) {
40 |
41 | this.name = parameters.get(2);
42 | this.longIdentifier = parameters.get(3).toCharArray();
43 | this.display = parameters.get(4).toCharArray();
44 | this.unitType = UnitType.getUnitType(parameters.get(5));
45 |
46 | int n = 6;
47 |
48 | SecondaryKeywords keyWord;
49 | for (int nPar = n; nPar < nbParams; nPar++) {
50 | keyWord = SecondaryKeywords.getSecondaryKeyWords(parameters.get(nPar));
51 | switch (keyWord) {
52 | case REF_UNIT:
53 | optionalsParameters.put(REF_UNIT, parameters.get(nPar + 1));
54 | nPar += 1;
55 | break;
56 | case SI_EXPONENTS:
57 | optionalsParameters.put(SI_EXPONENTS, new SiExponents(parameters.subList(nPar + 1, nPar + 8)));
58 | nPar += 7;
59 | break;
60 | case UNIT_CONVERSION:
61 | optionalsParameters.put(UNIT_CONVERSION, new UnitConversion(parameters.subList(nPar + 1, nPar + 3)));
62 | nPar += 2;
63 | break;
64 | default:
65 | break;
66 | }
67 | }
68 | } else {
69 | throw new IllegalArgumentException("Nombre de parametres inferieur au nombre requis");
70 | }
71 | }
72 |
73 | @Override
74 | public String toString() {
75 | return this.name;
76 | }
77 |
78 | private final class UnitConversion {
79 | @SuppressWarnings("unused")
80 | private final float gradient;
81 | @SuppressWarnings("unused")
82 | private final float offset;
83 |
84 | public UnitConversion(List params) {
85 | this.gradient = Float.parseFloat(params.get(0));
86 | this.offset = Float.parseFloat(params.get(1));
87 | }
88 | }
89 |
90 | private final class SiExponents {
91 | @SuppressWarnings("unused")
92 | private final byte length;
93 | @SuppressWarnings("unused")
94 | private final byte mass;
95 | @SuppressWarnings("unused")
96 | private final byte time;
97 | @SuppressWarnings("unused")
98 | private final byte electricCurrent;
99 | @SuppressWarnings("unused")
100 | private final byte temperature;
101 | @SuppressWarnings("unused")
102 | private final byte amountOfSubstance;
103 | @SuppressWarnings("unused")
104 | private final byte luminousIntensity;
105 |
106 | public SiExponents(List params) {
107 | this.length = Byte.parseByte(params.get(0));
108 | this.mass = Byte.parseByte(params.get(1));
109 | this.time = Byte.parseByte(params.get(2));
110 | this.electricCurrent = Byte.parseByte(params.get(3));
111 | this.temperature = Byte.parseByte(params.get(4));
112 | this.amountOfSubstance = Byte.parseByte(params.get(5));
113 | this.luminousIntensity = Byte.parseByte(params.get(6));
114 | }
115 | }
116 |
117 | @Override
118 | public int compareTo(Unit o) {
119 | return this.name.compareTo(o.name);
120 | }
121 |
122 | @Override
123 | public String getProperties() {
124 | StringBuilder sb = new StringBuilder("PROPERTIES :");
125 |
126 | sb.append("
- Name: " + name + "\n");
127 | sb.append("
- Long identifier: " + new String(longIdentifier) + "\n");
128 | sb.append("
- Display: " + new String(display) + "\n");
129 | sb.append("
- Unit type: " + unitType.name() + "\n");
130 | sb.append("");
131 |
132 | return sb.toString();
133 | }
134 | }
135 |
--------------------------------------------------------------------------------
/A2LParser/src/constante/AdressType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 20 févr. 2019
3 | */
4 | package constante;
5 |
6 | public enum AdressType {
7 |
8 | PBYTE(1), PWORD(2), PLONG(4), PLONGLONG(8), DIRECT(0), UNKNOWN(-1);
9 |
10 | private int nbByte;
11 |
12 | // Constructeur
13 | AdressType(int nbbits) {
14 | this.setNbByte(nbbits);
15 | }
16 |
17 | public int getNbByte() {
18 | return nbByte;
19 | }
20 |
21 | public void setNbByte(int nbbits) {
22 | this.nbByte = nbbits;
23 | }
24 |
25 | public static AdressType getAdressType(String type) {
26 | switch (type) {
27 | case "PBYTE":
28 | return PBYTE;
29 | case "PWORD":
30 | return PWORD;
31 | case "PLONG":
32 | return PLONG;
33 | case "PLONGLONG":
34 | return PLONGLONG;
35 | case "DIRECT":
36 | return DIRECT;
37 | default:
38 | return UNKNOWN;
39 | }
40 |
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/A2LParser/src/constante/ConversionType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 20 févr. 2019
3 | */
4 | package constante;
5 |
6 | public enum ConversionType {
7 |
8 | IDENTICAL, FORM, LINEAR, RAT_FUNC, TAB_INTP, TAB_NOINTP, TAB_VERB, NO_COMPU_METHOD, UNKNOWN;
9 |
10 | public static ConversionType getConversionType(String type) {
11 | switch (type) {
12 | case "IDENTICAL":
13 | return IDENTICAL;
14 | case "FORM":
15 | return FORM;
16 | case "LINEAR":
17 | return LINEAR;
18 | case "RAT_FUNC":
19 | return RAT_FUNC;
20 | case "TAB_INTP":
21 | return TAB_INTP;
22 | case "TAB_NOINTP":
23 | return TAB_NOINTP;
24 | case "TAB_VERB":
25 | return TAB_VERB;
26 | case "NO_COMPU_METHOD":
27 | return NO_COMPU_METHOD;
28 | default:
29 | return UNKNOWN;
30 | }
31 |
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/A2LParser/src/constante/DataSize.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 3 avr. 2019
3 | */
4 | package constante;
5 |
6 | public enum DataSize {
7 |
8 | BYTE(8), WORD(16), LONG(32), UNKNOWN(0);
9 |
10 | private int nbBits;
11 |
12 | private DataSize(int nbBits) {
13 | this.nbBits = nbBits;
14 | }
15 |
16 | public final int getNbBits() {
17 | return nbBits;
18 | }
19 |
20 | public final int getNbByte() {
21 | return this.nbBits >> 3;
22 | }
23 |
24 | public static DataSize getDataSize(String type) {
25 | switch (type) {
26 | case "BYTE":
27 | return BYTE;
28 | case "WORD":
29 | return WORD;
30 | case "LONG":
31 | return LONG;
32 | default:
33 | return UNKNOWN;
34 | }
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/A2LParser/src/constante/DataType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 20 févr. 2019
3 | */
4 | package constante;
5 |
6 | public enum DataType {
7 |
8 | UBYTE(1, true), SBYTE(1, true), UWORD(2, true), SWORD(2, true), ULONG(4, true), SLONG(4, true), FLOAT16_IEEE(2, false), FLOAT32_IEEE(4,
9 | false), FLOAT64_IEEE(8, false), A_UINT64(8, true), A_INT64(8, true), UNKNOWN(0, false);
10 |
11 | private byte nbByte;
12 | private boolean integer;
13 |
14 | // Constructeur
15 | DataType(int nbByte, boolean integer) {
16 | this.nbByte = (byte) nbByte;
17 | this.integer = integer;
18 | }
19 |
20 | public final byte getNbByte() {
21 | return nbByte;
22 | }
23 |
24 | public boolean isInteger() {
25 | return integer;
26 | }
27 |
28 | public static DataType getDataType(String type) {
29 | switch (type) {
30 | case "UBYTE":
31 | return UBYTE;
32 | case "SBYTE":
33 | return SBYTE;
34 | case "UWORD":
35 | return UWORD;
36 | case "SWORD":
37 | return SWORD;
38 | case "ULONG":
39 | return ULONG;
40 | case "SLONG":
41 | return SLONG;
42 | case "FLOAT16_IEEE":
43 | return FLOAT16_IEEE;
44 | case "FLOAT32_IEEE":
45 | return FLOAT32_IEEE;
46 | case "FLOAT64_IEEE":
47 | return FLOAT64_IEEE;
48 | case "A_UINT64":
49 | return A_UINT64;
50 | case "A_INT64":
51 | return A_INT64;
52 | default:
53 | return UNKNOWN;
54 | }
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/A2LParser/src/constante/DepositMode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 20 févr. 2019
3 | */
4 | package constante;
5 |
6 | public enum DepositMode {
7 |
8 | ABSOLUTE, DIFFERENCE, UNKNOWN;
9 |
10 | public static DepositMode getDepositMode(String type) {
11 | switch (type) {
12 | case "ABSOLUTE":
13 | return ABSOLUTE;
14 | case "DIFFERENCE":
15 | return DIFFERENCE;
16 | default:
17 | return UNKNOWN;
18 | }
19 |
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/A2LParser/src/constante/IndexMode.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 20 févr. 2019
3 | */
4 | package constante;
5 |
6 | public enum IndexMode {
7 |
8 | ALTERNATE_CURVES, ALTERNATE_WITH_X, ALTERNATE_WITH_Y, COLUMN_DIR, ROW_DIR, UNKNOWN;
9 |
10 | public static IndexMode getIndexMode(String type) {
11 | switch (type) {
12 | case "ALTERNATE_CURVES":
13 | return ALTERNATE_CURVES;
14 | case "ALTERNATE_WITH_X":
15 | return ALTERNATE_WITH_X;
16 | case "ALTERNATE_WITH_Y":
17 | return ALTERNATE_WITH_Y;
18 | case "COLUMN_DIR":
19 | return COLUMN_DIR;
20 | case "ROW_DIR":
21 | return ROW_DIR;
22 | default:
23 | return UNKNOWN;
24 | }
25 |
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/A2LParser/src/constante/IndexOrder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 20 févr. 2019
3 | */
4 | package constante;
5 |
6 | public enum IndexOrder {
7 |
8 | INDEX_INCR, INDEX_DECR, UNKNOWN;
9 |
10 | public static IndexOrder getIndexOrder(String type) {
11 | switch (type) {
12 | case "INDEX_INCR":
13 | return INDEX_INCR;
14 | case "INDEX_DECR":
15 | return INDEX_DECR;
16 | default:
17 | return UNKNOWN;
18 | }
19 |
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/A2LParser/src/constante/PrimaryKeywords.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 2 mars 2018
3 | */
4 | package constante;
5 |
6 | import java.util.HashMap;
7 | import java.util.Map;
8 |
9 | public enum PrimaryKeywords {
10 | MOD_PAR, MOD_COMMON, AXIS_PTS, CHARACTERISTIC, COMPU_METHOD, COMPU_TAB, COMPU_VTAB, COMPU_VTAB_RANGE, MEASUREMENT, RECORD_LAYOUT, FUNCTION, GROUP, UNIT, UNKNOWN;
11 |
12 | private static final Map nameIndex = new HashMap<>(PrimaryKeywords.values().length);
13 |
14 | static {
15 | for (PrimaryKeywords primaryKeywords : PrimaryKeywords.values()) {
16 | nameIndex.put(sumChar(primaryKeywords.name()), primaryKeywords);
17 | }
18 | }
19 |
20 | public static int sumChar(String name) {
21 | final int size = name.length();
22 | int sum = 0;
23 |
24 | for (int idx = 0; idx < size; idx++) {
25 | sum += (name.charAt(idx) * idx);
26 | }
27 |
28 | return sum;
29 | }
30 |
31 | public static final PrimaryKeywords getPrimaryKeywords(Integer code) {
32 | PrimaryKeywords primaryKeywords = nameIndex.get(code);
33 | return primaryKeywords != null ? primaryKeywords : UNKNOWN;
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/A2LParser/src/constante/SecondaryKeywords.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 2 mars 2018
3 | */
4 | package constante;
5 |
6 | import java.util.HashMap;
7 | import java.util.Map;
8 |
9 | public enum SecondaryKeywords {
10 | ADDR_EPK, ALIGNMENT_BYTE, ALIGNMENT_FLOAT16_IEEE, ALIGNMENT_FLOAT32_IEEE, ALIGNMENT_FLOAT64_IEEE, ALIGNMENT_INT64, ALIGNMENT_LONG, ALIGNMENT_WORD, ANNOTATION, ANNOTATION_LABEL, ANNOTATION_ORIGIN, ANNOTATION_TEXT, AXIS_DESCR, AXIS_PTS_REF, AXIS_PTS_X, AXIS_PTS_Y, AXIS_PTS_Z, AXIS_RESCALE_X, BIT_MASK, BYTE_ORDER, CALIBRATION_ACCESS, COEFFS, COEFFS_LINEAR, COMPARISON_QUANTITY, COMPU_TAB_REF, CURVE_AXIS_REF, DATA_SIZE, DEFAULT_VALUE, DEFAULT_VALUE_NUMERIC, DEF_CHARACTERISTIC, DEPENDENT_CHARACTERISTIC, DEPOSIT, DISCRETE, DISPLAY_IDENTIFIER, DIST_OP_X, DIST_OP_Y, DIST_OP_Z, ECU_ADDRESS_EXTENSION, ECU_CALIBRATION_OFFSET, EPK, EXTENDED_LIMITS, FIX_AXIS_PAR, FIX_AXIS_PAR_DIST, FIX_AXIS_PAR_LIST, FIX_NO_AXIS_PTS_X, FIX_NO_AXIS_PTS_Y, FIX_NO_AXIS_PTS_Z, FNC_VALUES, FORMAT, FORMULA, FORMULA_INV, FUNCTION_VERSION, IDENTIFICATION, IN_MEASUREMENT, LOC_MEASUREMENT, MATRIX_DIM, MAX_GRAD, MAX_REFRESH, MONOTONY, NO_AXIS_PTS_X, NO_AXIS_PTS_Y, NO_RESCALE_X, NUMBER, OUT_MEASUREMENT, PHYS_UNIT, PROJECT_NO, READ_ONLY, REF_CHARACTERISTIC, REF_MEMORY_SEGMENT, REF_UNIT, RESERVED, SI_EXPONENTS, SRC_ADDR_X, SRC_ADDR_Y, STATIC_RECORD_LAYOUT, STATUS_STRING_REF, STEP_SIZE, SUB_FUNCTION, SYSTEM_CONSTANT, VERSION, VIRTUAL_CHARACTERISTIC, UNIT_CONVERSION, UNKNOWN, FUNCTION_LIST, REF_MEASUREMENT, SUB_GROUP, ROOT;
11 |
12 | private static final Map nameIndex = new HashMap<>(SecondaryKeywords.values().length);
13 |
14 | static {
15 | for (SecondaryKeywords secondaryKeywords : SecondaryKeywords.values()) {
16 | nameIndex.put(secondaryKeywords.name(), secondaryKeywords);
17 | }
18 | }
19 |
20 | public static final SecondaryKeywords getSecondaryKeyWords(String name) {
21 | SecondaryKeywords secondaryKeywords = nameIndex.get(name);
22 | return secondaryKeywords != null ? secondaryKeywords : UNKNOWN;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/A2LParser/src/constante/UnitType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 20 févr. 2019
3 | */
4 | package constante;
5 |
6 | public enum UnitType {
7 |
8 | DERIVED, EXTENDED_SI, UNKNOWN;
9 |
10 | public static UnitType getUnitType(String type) {
11 | switch (type) {
12 | case "DERIVED":
13 | return DERIVED;
14 | case "EXTENDED_SI":
15 | return EXTENDED_SI;
16 | default:
17 | return UNKNOWN;
18 | }
19 |
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/A2LParser/src/data/DataCalibration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 15 janv. 2020
3 | */
4 | package data;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | public abstract class DataCalibration {
10 |
11 | protected final List memorySegments = new ArrayList();
12 |
13 | public final byte[] readBytes(long address, int len) {
14 | byte[] retval;
15 | final int memorySegmentsSize = memorySegments.size();
16 | Memory mem = null;
17 |
18 | for (int i = 0; i < memorySegmentsSize; i++) {
19 | mem = memorySegments.get(i);
20 | if (address >= mem.address && (address + len) <= (mem.address + mem.listByte.size())) {
21 | retval = new byte[len];
22 | for (int j = 0; j < len; j++) {
23 | retval[j] = mem.listByte.get((int) (j + address - mem.address));
24 | }
25 | return retval;
26 | }
27 | }
28 | return new byte[0];
29 | }
30 |
31 | public final String readString(long address, int nByte) {
32 | long _address = address;
33 | final int memorySegmentsSize = memorySegments.size();
34 | Memory mem = null;
35 |
36 | for (int i = 0; i < memorySegmentsSize; i++) {
37 | mem = memorySegments.get(i);
38 | if (_address >= mem.address && _address < mem.address + mem.listByte.size()) {
39 | StringBuilder retval = new StringBuilder(nByte);
40 | while (_address < mem.address + mem.listByte.size() && retval.length() < nByte) {
41 | retval.append((char) mem.listByte.get((int) (_address - mem.address)).byteValue());
42 | _address++;
43 | }
44 | return retval.toString();
45 | }
46 | }
47 | return null;
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/A2LParser/src/data/IntelHex.java:
--------------------------------------------------------------------------------
1 |
2 | package data;
3 |
4 | import java.io.BufferedReader;
5 | import java.io.FileNotFoundException;
6 | import java.io.FileReader;
7 | import java.io.IOException;
8 |
9 | /**
10 | * @author albert_kurucz
11 | */
12 | public final class IntelHex extends DataCalibration {
13 |
14 | @SuppressWarnings("unused")
15 | private Long startAddress = null;
16 | private Memory last = null;
17 | private long extendedAddress = 0;
18 | private boolean endOfFile = false;
19 |
20 | private final static byte parseHexByte(String str, int beginIndex) {
21 | return (byte) Integer.parseInt(str.substring(beginIndex, beginIndex + 2), 16);
22 | }
23 |
24 | public IntelHex(String fileName) throws FileNotFoundException, IOException {
25 | this(new BufferedReader(new FileReader(fileName)));
26 |
27 | }
28 |
29 | private final void processLine(String line) {
30 | if (endOfFile) {
31 | return;
32 | }
33 |
34 | char recordType = line.charAt(8);
35 |
36 | switch (recordType) {
37 | case '0':
38 | Memory memoryOfLine = processDataRecordLine(line, extendedAddress);
39 | if (last == null) {
40 | memorySegments.add(memoryOfLine);
41 | last = memoryOfLine;
42 | } else {
43 | if (last.address + last.listByte.size() == memoryOfLine.address) {
44 | last.appendMemory(memoryOfLine);
45 | } else {
46 | memorySegments.add(memoryOfLine);
47 | last = memoryOfLine;
48 | }
49 | }
50 | break;
51 | case '1':
52 | if (!":00000001FF".equals(line)) {
53 | throw new IllegalArgumentException("Illegal End-Of-Line record received");
54 | }
55 | endOfFile = true;
56 | break;
57 | case '4':
58 | extendedAddress = processExtendedLinearAddressRecord(line);
59 | break;
60 | case '5':
61 | startAddress = processStartAddressRecord(line);
62 | break;
63 | default:
64 | break;
65 | }
66 | }
67 |
68 | public IntelHex(BufferedReader sr) throws IOException {
69 | String line;
70 |
71 | while (!endOfFile) {
72 | line = sr.readLine();
73 | if (line == null) {
74 | break;
75 | }
76 | processLine(line);
77 | }
78 |
79 | sr.close();
80 | }
81 |
82 | private static final long processExtendedLinearAddressRecord(String line) {
83 | if (!line.startsWith(":02000004")) {
84 | throw new IllegalArgumentException("Illegal Extended Linear Address Record line received: " + line);
85 | }
86 | long address = Long.parseLong(line.substring(9, 13), 16);
87 | if (0 != (byte) (6 + address + (address >> 8) + parseHexByte(line, 13))) {
88 | throw new IllegalArgumentException("HexFile Extended Linear Address line checksum error");
89 | }
90 | return address << 16;
91 | }
92 |
93 | private static final long processStartAddressRecord(String line) {
94 | if (!line.startsWith(":04000005")) {
95 | throw new IllegalArgumentException("Illegal Extended Linear Address Record line received: " + line);
96 | }
97 | long address = Long.parseLong(line.substring(9, 17), 16);
98 | if (0 != (byte) (9 + address + (address >> 8) + (address >> 16) + (address >> 24) + parseHexByte(line, 17))) {
99 | throw new IllegalArgumentException("HexFile Start Address line checksum error");
100 | }
101 | return address;
102 | }
103 |
104 | private static final Memory processDataRecordLine(String line, long address) {
105 | Memory memory = processDataRecordLine(line);
106 | memory.address = memory.address + address;
107 | return memory;
108 | }
109 |
110 | private static final Memory processDataRecordLine(String line) {
111 | if (line.charAt(0) != ':') {
112 | throw new IllegalArgumentException("HexFile line does not start with colon: " + line);
113 | }
114 | byte length = parseHexByte(line, 1);
115 | byte sum = length;
116 |
117 | int lineAddress = Integer.parseInt(line.substring(3, 7), 16);
118 | sum += (byte) lineAddress;
119 | sum += (byte) (lineAddress >> 8);
120 |
121 | byte[] hexLineDataBytes = new byte[length];
122 |
123 | byte i;
124 | for (i = 0; i < length; i++) {
125 | hexLineDataBytes[i] = parseHexByte(line, 9 + 2 * i);
126 | sum += hexLineDataBytes[i];
127 | }
128 |
129 | // checksum
130 | sum += parseHexByte(line, 9 + 2 * i);
131 |
132 | if (sum != 0) {
133 | throw new IllegalArgumentException("HexFile Data Record line checksum error : " + line);
134 | }
135 |
136 | return new Memory(lineAddress, hexLineDataBytes);
137 | }
138 |
139 | }
140 |
--------------------------------------------------------------------------------
/A2LParser/src/data/Memory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * To change this template, choose Tools | Templates
3 | * and open the template in the editor.
4 | */
5 | package data;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | /**
11 | * @author albert_kurucz
12 | */
13 | public final class Memory {
14 |
15 | public long address;
16 | public final List listByte;
17 |
18 | public Memory(long address, byte[] data) {
19 | this.address = address;
20 | listByte = new ArrayList(data.length);
21 | for (int i = 0; i < data.length; i++) {
22 | listByte.add(data[i]);
23 | }
24 | }
25 |
26 | private final boolean canAppendMemory(Memory append) {
27 | return append.address == (address + listByte.size());
28 | }
29 |
30 | public final void appendMemory(Memory append) {
31 | if (!canAppendMemory(append)) {
32 | throw new IllegalArgumentException("Cannot append memory");
33 | }
34 | listByte.addAll(append.listByte);
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/A2LParser/src/data/MotorolaS19.java:
--------------------------------------------------------------------------------
1 |
2 | package data;
3 |
4 | import java.io.BufferedReader;
5 | import java.io.FileNotFoundException;
6 | import java.io.FileReader;
7 | import java.io.IOException;
8 |
9 | /**
10 | * @author albert_kurucz
11 | */
12 | public final class MotorolaS19 extends DataCalibration {
13 |
14 | private Memory last = null;
15 | private long extendedAddress = 0;
16 | private boolean endOfFile = false;
17 |
18 | private final static byte parseHexByte(String str, int beginIndex) {
19 | return (byte) Integer.parseInt(str.substring(beginIndex, beginIndex + 2), 16);
20 | }
21 |
22 | public MotorolaS19(String fileName) throws FileNotFoundException, IOException {
23 | this(new BufferedReader(new FileReader(fileName)));
24 |
25 | }
26 |
27 | private final void processLine(String line) {
28 | if (endOfFile) {
29 | return;
30 | }
31 |
32 | char recordType = line.charAt(1);
33 |
34 | switch (recordType) {
35 | case '3': // Séquence de données - 4 octets
36 | Memory memoryOfLine = processDataRecordLine(line, extendedAddress);
37 | if (last == null) {
38 | memorySegments.add(memoryOfLine);
39 | last = memoryOfLine;
40 | } else {
41 | if (last.address + last.listByte.size() == memoryOfLine.address) {
42 | last.appendMemory(memoryOfLine);
43 | } else {
44 | memorySegments.add(memoryOfLine);
45 | last = memoryOfLine;
46 | }
47 | }
48 | break;
49 | case '7': // Fin de bloc - 4 octets
50 | endOfFile = true;
51 | break;
52 | default:
53 | break;
54 | }
55 | }
56 |
57 | public MotorolaS19(BufferedReader sr) throws IOException {
58 | String line;
59 |
60 | while (!endOfFile) {
61 | line = sr.readLine();
62 | if (line == null) {
63 | break;
64 | }
65 | processLine(line);
66 | }
67 |
68 | sr.close();
69 | }
70 |
71 | private static final Memory processDataRecordLine(String line, long address) {
72 | Memory memory = processDataRecordLine(line);
73 | memory.address = memory.address + address;
74 | return memory;
75 | }
76 |
77 | private static final Memory processDataRecordLine(String line) {
78 | if (line.charAt(0) != 'S') {
79 | throw new IllegalArgumentException("s19File line does not start with colon: " + line);
80 | }
81 |
82 | byte length = (byte) (parseHexByte(line, 2) - 5);
83 |
84 | long lineAddress = Long.parseLong(line.substring(4, 12), 16);
85 |
86 | byte[] hexLineDataBytes = new byte[length];
87 |
88 | byte i;
89 | for (i = 0; i < length; i++) {
90 | hexLineDataBytes[i] = parseHexByte(line, 12 + 2 * i);
91 | }
92 |
93 | if (!isValidChecksum(line)) {
94 | throw new IllegalArgumentException("s19File Data Record line checksum error : " + line);
95 | }
96 |
97 | return new Memory(lineAddress, hexLineDataBytes);
98 | }
99 |
100 | private static boolean isValidChecksum(String line) {
101 | int sum = 0;
102 |
103 | byte checksum = parseHexByte(line, line.length() - 2);
104 |
105 | for (int i = 2; i < line.length() - 2; i += 2) {
106 | sum += Integer.parseInt(line.substring(i, i + 2), 16);
107 | }
108 |
109 | byte calcChecksum = (byte) ~(sum & 0xFF);
110 |
111 | return calcChecksum == checksum;
112 | }
113 |
114 | }
115 |
--------------------------------------------------------------------------------
/A2LParser/src/gui/A2lDisplayer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 22 janv. 2020
3 | */
4 | package gui;
5 |
6 | import java.awt.Adjustable;
7 | import java.awt.Dimension;
8 | import java.awt.event.AdjustmentEvent;
9 | import java.awt.event.AdjustmentListener;
10 | import java.io.File;
11 | import java.io.IOException;
12 | import java.nio.MappedByteBuffer;
13 | import java.nio.channels.FileChannel;
14 | import java.nio.channels.SeekableByteChannel;
15 | import java.nio.charset.Charset;
16 | import java.nio.file.Files;
17 | import java.nio.file.StandardOpenOption;
18 |
19 | import javax.swing.JFrame;
20 | import javax.swing.JScrollBar;
21 | import javax.swing.JScrollPane;
22 | import javax.swing.JTextArea;
23 | import javax.swing.ScrollPaneConstants;
24 | import javax.swing.SwingWorker;
25 | import javax.swing.text.BadLocationException;
26 | import javax.swing.text.PlainDocument;
27 | import javax.swing.text.Segment;
28 |
29 | public final class A2lDisplayer extends JFrame {
30 |
31 | private static final long serialVersionUID = 1L;
32 |
33 | static SeekableByteChannel sbc = null;
34 | static MappedByteBuffer mappedByteBuffer = null;
35 | static byte[] b;
36 | static int fileLength;
37 | static JTextArea textArea;
38 | static JScrollPane scrollPane;
39 | static PlainDocument doc;
40 |
41 | public A2lDisplayer(File a2lFile) {
42 | DisplayWorker displayWorker = new DisplayWorker(a2lFile);
43 | displayWorker.execute();
44 | }
45 |
46 | private static class DisplayWorker extends SwingWorker {
47 |
48 | private final File file;
49 |
50 | private DisplayWorker(File file) {
51 | this.file = file;
52 |
53 | }
54 |
55 | @Override
56 | protected PlainDocument doInBackground() {
57 |
58 | try {
59 |
60 | sbc = Files.newByteChannel(file.toPath(), StandardOpenOption.READ);
61 | fileLength = (int) sbc.size();
62 | mappedByteBuffer = ((FileChannel) sbc).map(FileChannel.MapMode.READ_ONLY, 0, sbc.size());
63 |
64 | b = new byte[(int) sbc.size()];
65 | mappedByteBuffer.get(b);
66 |
67 | mappedByteBuffer.clear();
68 | sbc.close();
69 |
70 | doc = new PlainDocument();
71 |
72 | doc.insertString(0, new String(b, 0, fileLength / 2, Charset.defaultCharset()), null);
73 |
74 | return doc;
75 |
76 | } catch (IOException e) {
77 | e.printStackTrace();
78 | } catch (BadLocationException e) {
79 | e.printStackTrace();
80 | }
81 |
82 | return null;
83 | }
84 |
85 | @Override
86 | protected void done() {
87 | JFrame frame = new JFrame("A2L");
88 | textArea = new JTextArea(doc);
89 | textArea.setRows(30);
90 | textArea.setColumns(50);
91 | scrollPane = new JScrollPane(textArea, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
92 | scrollPane.getVerticalScrollBar().addAdjustmentListener(new MyAdjustmentListener());
93 |
94 | frame.setSize(new Dimension(1000, 500));
95 | frame.add(scrollPane);
96 |
97 | frame.setVisible(true);
98 |
99 | int nleft = doc.getLength();
100 | Segment text = new Segment();
101 | int offs = 0;
102 | text.setPartialReturn(true);
103 | while (nleft > 0) {
104 | try {
105 | doc.getText(offs, nleft, text);
106 |
107 | } catch (BadLocationException e) {
108 | e.printStackTrace();
109 | }
110 | // do something with text
111 | nleft -= text.count;
112 | offs += text.count;
113 | }
114 |
115 | }
116 |
117 | }
118 |
119 | static class MyAdjustmentListener implements AdjustmentListener {
120 |
121 | boolean secondPart = false;
122 |
123 | public void adjustmentValueChanged(AdjustmentEvent evt) {
124 | Adjustable source = evt.getAdjustable();
125 | JScrollBar bar = (JScrollBar) source;
126 |
127 | int value = evt.getValue();
128 |
129 | if (!secondPart && value > bar.getMaximum() / 2) {
130 | int offset = Math.min(fileLength / 2, fileLength - 1);
131 | int length = fileLength - offset;
132 | textArea.replaceRange(new String(b, offset, length, Charset.defaultCharset()), 0, doc.getLength());
133 | secondPart = true;
134 | }
135 |
136 | }
137 | }
138 |
139 | }
140 |
--------------------------------------------------------------------------------
/A2LParser/src/gui/DisplayLog.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 30 juil. 2020
3 | */
4 | package gui;
5 |
6 | import java.awt.BorderLayout;
7 | import java.awt.EventQueue;
8 | import java.beans.PropertyChangeEvent;
9 | import java.beans.PropertyChangeListener;
10 | import java.io.BufferedReader;
11 | import java.io.File;
12 | import java.io.FileReader;
13 |
14 | import javax.swing.JFrame;
15 | import javax.swing.JProgressBar;
16 | import javax.swing.JScrollPane;
17 | import javax.swing.JTable;
18 | import javax.swing.SwingWorker;
19 | import javax.swing.table.DefaultTableModel;
20 | import javax.swing.table.TableModel;
21 |
22 | public class DisplayLog {
23 |
24 | private static final String NAME = "C:\\User\\U354706\\Perso\\WorkInProgress\\MG1CS032_D081C_VC2bis.a2l";
25 |
26 | private static class LogWorker extends SwingWorker {
27 |
28 | private final File file;
29 | private final DefaultTableModel model;
30 |
31 | private LogWorker(File file, DefaultTableModel model) {
32 | this.file = file;
33 | this.model = model;
34 | model.setColumnIdentifiers(new Object[] { file.getAbsolutePath() });
35 | }
36 |
37 | @Override
38 | protected TableModel doInBackground() throws Exception {
39 | BufferedReader br = new BufferedReader(new FileReader(file));
40 | String s;
41 | while ((s = br.readLine()) != null) {
42 | publish(s);
43 | }
44 | return model;
45 | }
46 |
47 | @Override
48 | protected void process(java.util.List chunks) {
49 | for (String s : chunks) {
50 | model.addRow(new Object[] { s });
51 | }
52 | }
53 | }
54 |
55 | private void display() {
56 | JFrame f = new JFrame("DisplayLog");
57 | f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
58 | DefaultTableModel model = new DefaultTableModel();
59 | JTable table = new JTable(model);
60 | final JProgressBar jpb = new JProgressBar();
61 | f.add(jpb, BorderLayout.NORTH);
62 | f.add(new JScrollPane(table));
63 | f.pack();
64 | f.setLocationRelativeTo(null);
65 | f.setVisible(true);
66 | LogWorker lw = new LogWorker(new File(NAME), model);
67 | lw.addPropertyChangeListener(new PropertyChangeListener() {
68 | @Override
69 | public void propertyChange(PropertyChangeEvent e) {
70 | SwingWorker.StateValue s = (SwingWorker.StateValue) e.getNewValue();
71 | jpb.setIndeterminate(s.equals(SwingWorker.StateValue.STARTED));
72 | }
73 | });
74 | lw.execute();
75 | }
76 |
77 | public static void main(String[] args) {
78 | EventQueue.invokeLater(new Runnable() {
79 | @Override
80 | public void run() {
81 | new DisplayLog().display();
82 | }
83 | });
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/A2LParser/src/gui/DisplayLog_Bis.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 30 juil. 2020
3 | */
4 | package gui;
5 |
6 | import java.awt.BorderLayout;
7 | import java.awt.EventQueue;
8 | import java.beans.PropertyChangeEvent;
9 | import java.beans.PropertyChangeListener;
10 | import java.io.BufferedReader;
11 | import java.io.File;
12 | import java.io.FileReader;
13 | import java.util.ArrayList;
14 | import java.util.List;
15 | import java.util.concurrent.ExecutionException;
16 |
17 | import javax.swing.JFrame;
18 | import javax.swing.JProgressBar;
19 | import javax.swing.JScrollPane;
20 | import javax.swing.JTextArea;
21 | import javax.swing.SwingWorker;
22 | import javax.swing.text.BadLocationException;
23 | import javax.swing.text.PlainDocument;
24 |
25 | public class DisplayLog_Bis {
26 |
27 | private static final String NAME = "C:\\User\\U354706\\Perso\\WorkInProgress\\MG1CS032_D081C_VC2bis.a2l";
28 |
29 | private static class FileReaderWorker extends SwingWorker
, String> {
30 |
31 | private final File file;
32 | private final PlainDocument doc;
33 |
34 | private FileReaderWorker(File file, PlainDocument doc) {
35 | this.file = file;
36 | this.doc = doc;
37 | }
38 |
39 | public File getFile() {
40 | return file;
41 | }
42 |
43 | @Override
44 | protected List doInBackground() throws Exception {
45 | List contents = new ArrayList<>(256);
46 | try (BufferedReader br = new BufferedReader(new FileReader(getFile()))) {
47 | String text = null;
48 | while ((text = br.readLine()) != null) {
49 | // You will want to deal with adding back in the new line characters
50 | // here if that is important to you...
51 | contents.add(text);
52 | publish(text);
53 | }
54 | }
55 | return contents;
56 | }
57 |
58 | @Override
59 | protected void done() {
60 | try {
61 | get();
62 | } catch (InterruptedException e) {
63 | e.printStackTrace();
64 | } catch (ExecutionException e) {
65 | e.printStackTrace();
66 | }
67 | }
68 |
69 | @Override
70 | protected void process(List chunks) {
71 | for (String text : chunks) {
72 | try {
73 | doc.insertString(doc.getLength(), text, null);
74 | } catch (BadLocationException e) {
75 | e.printStackTrace();
76 | }
77 | }
78 | }
79 | }
80 |
81 | private void display() {
82 | JFrame f = new JFrame("DisplayLog");
83 | f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
84 | PlainDocument doc = new PlainDocument();
85 | JTextArea ta = new JTextArea();
86 | final JProgressBar jpb = new JProgressBar();
87 | f.add(jpb, BorderLayout.NORTH);
88 | f.add(new JScrollPane(ta));
89 | f.pack();
90 | f.setLocationRelativeTo(null);
91 | f.setVisible(true);
92 | FileReaderWorker lw = new FileReaderWorker(new File(NAME), doc);
93 | lw.addPropertyChangeListener(new PropertyChangeListener() {
94 | @Override
95 | public void propertyChange(PropertyChangeEvent e) {
96 | SwingWorker.StateValue s = (SwingWorker.StateValue) e.getNewValue();
97 | jpb.setIndeterminate(s.equals(SwingWorker.StateValue.STARTED));
98 | }
99 | });
100 | lw.execute();
101 |
102 | while (!lw.isDone()) {
103 |
104 | }
105 |
106 | System.out.println("finished");
107 | }
108 |
109 | public static void main(String[] args) {
110 | EventQueue.invokeLater(new Runnable() {
111 | @Override
112 | public void run() {
113 | new DisplayLog_Bis().display();
114 | }
115 | });
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/A2LParser/src/gui/FilteredTreeModel.java:
--------------------------------------------------------------------------------
1 | package gui;
2 |
3 | import javax.swing.event.TreeModelListener;
4 | import javax.swing.tree.TreeModel;
5 | import javax.swing.tree.TreePath;
6 |
7 | public final class FilteredTreeModel implements TreeModel {
8 |
9 | private TreeModel treeModel;
10 | private String filter;
11 |
12 | public FilteredTreeModel(final TreeModel treeModel) {
13 | this.treeModel = treeModel;
14 | this.filter = "";
15 | }
16 |
17 | public TreeModel getTreeModel() {
18 | return treeModel;
19 | }
20 |
21 | public void setFilter(final String filter) {
22 | this.filter = filter;
23 | }
24 |
25 | private boolean recursiveMatch(final Object node, final String filter) {
26 |
27 | boolean matches = node.toString().contains(filter);
28 |
29 | int childCount = treeModel.getChildCount(node);
30 | for (int i = 0; i < childCount; i++) {
31 | Object child = treeModel.getChild(node, i);
32 | matches |= recursiveMatch(child, filter);
33 | }
34 |
35 | return matches;
36 | }
37 |
38 | @Override
39 | public Object getRoot() {
40 | return treeModel.getRoot();
41 | }
42 |
43 | @Override
44 | public Object getChild(final Object parent, final int index) {
45 | int count = 0;
46 | int childCount = treeModel.getChildCount(parent);
47 | for (int i = 0; i < childCount; i++) {
48 | Object child = treeModel.getChild(parent, i);
49 | if (recursiveMatch(child, filter)) {
50 | if (count == index) {
51 | return child;
52 | }
53 | count++;
54 | }
55 | }
56 | return null;
57 | }
58 |
59 | @Override
60 | public int getChildCount(final Object parent) {
61 | int count = 0;
62 | int childCount = treeModel.getChildCount(parent);
63 | for (int i = 0; i < childCount; i++) {
64 | Object child = treeModel.getChild(parent, i);
65 | if (recursiveMatch(child, filter)) {
66 | count++;
67 | }
68 | }
69 | return count;
70 | }
71 |
72 | @Override
73 | public boolean isLeaf(final Object node) {
74 | return treeModel.isLeaf(node);
75 | }
76 |
77 | @Override
78 | public void valueForPathChanged(final TreePath path, final Object newValue) {
79 | treeModel.valueForPathChanged(path, newValue);
80 | }
81 |
82 | @Override
83 | public int getIndexOfChild(final Object parent, final Object childToFind) {
84 | int childCount = treeModel.getChildCount(parent);
85 | for (int i = 0; i < childCount; i++) {
86 | Object child = treeModel.getChild(parent, i);
87 | if (recursiveMatch(child, filter)) {
88 | if (childToFind.equals(child)) {
89 | return i;
90 | }
91 | }
92 | }
93 | return -1;
94 | }
95 |
96 | @Override
97 | public void addTreeModelListener(final TreeModelListener l) {
98 | treeModel.addTreeModelListener(l);
99 | }
100 |
101 | @Override
102 | public void removeTreeModelListener(final TreeModelListener l) {
103 | treeModel.removeTreeModelListener(l);
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/A2LParser/src/gui/Main.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 28 févr. 2018
3 | */
4 | package gui;
5 |
6 | import javax.swing.SwingUtilities;
7 | import javax.swing.UIManager;
8 | import javax.swing.UIManager.LookAndFeelInfo;
9 | import javax.swing.UnsupportedLookAndFeelException;
10 |
11 | public class Main {
12 |
13 | public static void main(final String[] args) {
14 |
15 | try {
16 |
17 | for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
18 | if ("Windows".equals(info.getName())) {
19 | try {
20 | UIManager.setLookAndFeel(info.getClassName());
21 | } catch (ClassNotFoundException e1) {
22 | e1.printStackTrace();
23 | } catch (InstantiationException e1) {
24 | e1.printStackTrace();
25 | } catch (IllegalAccessException e1) {
26 | e1.printStackTrace();
27 | } catch (UnsupportedLookAndFeelException e1) {
28 | e1.printStackTrace();
29 | }
30 | break;
31 | }
32 | }
33 |
34 | } catch (Exception e) {
35 | e.printStackTrace();
36 | }
37 |
38 | SwingUtilities.invokeLater(new Runnable() {
39 |
40 | @Override
41 | public void run() {
42 | new Ihm();
43 |
44 | }
45 | });
46 |
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/A2LParser/src/gui/SurfaceChart.java:
--------------------------------------------------------------------------------
1 | package gui;
2 |
3 | import java.awt.BorderLayout;
4 |
5 | import javax.swing.BorderFactory;
6 | import javax.swing.JComponent;
7 |
8 | import net.ericaro.surfaceplotter.surface.AbstractSurfaceModel;
9 | import net.ericaro.surfaceplotter.surface.JSurface;
10 | import net.ericaro.surfaceplotter.surface.SurfaceModel;
11 | import net.ericaro.surfaceplotter.surface.SurfaceVertex;
12 |
13 | public final class SurfaceChart extends JComponent {
14 |
15 | private static final long serialVersionUID = 1L;
16 |
17 | private final MapSurfaceModel arraySurfaceModel;
18 | private final JSurface surface;
19 |
20 | public SurfaceChart() {
21 |
22 | setBorder(BorderFactory.createEmptyBorder());
23 |
24 | this.setLayout(new BorderLayout());
25 |
26 | arraySurfaceModel = new MapSurfaceModel();
27 |
28 | surface = new JSurface(arraySurfaceModel);
29 |
30 | this.add(surface);
31 |
32 | }
33 |
34 | public MapSurfaceModel getArraySurfaceModel() {
35 | return arraySurfaceModel;
36 | }
37 |
38 | public JSurface getSurface() {
39 | return surface;
40 | }
41 |
42 | public class MapSurfaceModel extends AbstractSurfaceModel {
43 |
44 | private SurfaceVertex[][] surfaceVertex;
45 |
46 | public MapSurfaceModel() {
47 | setPlotFunction2(false);
48 | setBoxed(true);
49 | setDisplayXY(true);
50 | setExpectDelay(false);
51 | setDisplayZ(true);
52 | setMesh(true);
53 | setPlotType(SurfaceModel.PlotType.SURFACE);
54 | setDisplayGrids(true);
55 | setPlotColor(SurfaceModel.PlotColor.SPECTRUM);
56 | setFirstFunctionOnly(true);
57 | }
58 |
59 | public void setValues(float[] xAxis, float[] yAxis, float[][] zValues) {
60 | setDataAvailable(false);
61 |
62 | final int xLength = xAxis.length;
63 | final int yLength = yAxis.length;
64 |
65 | setXMin(xAxis[0]);
66 | setXMax(xAxis[(xLength - 1)]);
67 | setYMin(yAxis[0]);
68 | setYMax(yAxis[(yLength - 1)]);
69 | setCalcDivisions(Math.max(xLength - 1, yLength - 1));
70 |
71 | float minZValue = Float.POSITIVE_INFINITY;
72 | float maxZValue = Float.NEGATIVE_INFINITY;
73 |
74 | final float xfactor = 20.0F / (xMax - xMin);
75 | final float yfactor = 20.0F / (yMax - yMin);
76 |
77 | final int total = (calcDivisions + 1) * (calcDivisions + 1);
78 | surfaceVertex = new SurfaceVertex[1][total];
79 |
80 | for (int i = 0; i < xLength; i++) {
81 | for (int j = 0; j < yLength; j++) {
82 | int k = i * (calcDivisions + 1) + j;
83 | float xv = xAxis[i];
84 | float yv = yAxis[j];
85 | float v1 = 0;
86 |
87 | if (zValues != null) {
88 | v1 = zValues[j][i];
89 |
90 | if (v1 < minZValue)
91 | minZValue = v1;
92 |
93 | if (v1 > maxZValue)
94 | maxZValue = v1;
95 |
96 | } else {
97 | v1 = Float.NaN;
98 | }
99 |
100 | surfaceVertex[0][k] = new SurfaceVertex((xv - xMin) * xfactor - 10.0F, (yv - yMin) * yfactor - 10.0F, v1);
101 | }
102 | }
103 |
104 | for (int s = 0; s < total; s++) { // avoid NPE in plotArea
105 | if (surfaceVertex[0][s] == null) {
106 | surfaceVertex[0][s] = new SurfaceVertex(Float.NaN, Float.NaN, Float.NaN);
107 | }
108 | }
109 |
110 | zMin = minZValue;
111 | zMax = maxZValue;
112 |
113 | if (zMax - zMin == 0) {
114 | zMax += 0.1;
115 | zMin -= 0.1;
116 | }
117 |
118 | setDataAvailable(true);
119 | fireStateChanged();
120 | }
121 |
122 | @Override
123 | public SurfaceVertex[][] getSurfaceVertex() {
124 | return this.surfaceVertex;
125 | }
126 | }
127 |
128 | }
129 |
--------------------------------------------------------------------------------
/A2LParser/src/gui/TableView.java:
--------------------------------------------------------------------------------
1 | package gui;
2 |
3 | import java.awt.Component;
4 |
5 | import javax.swing.JTable;
6 | import javax.swing.ListSelectionModel;
7 | import javax.swing.SwingConstants;
8 | import javax.swing.table.DefaultTableCellRenderer;
9 | import javax.swing.table.TableCellRenderer;
10 | import javax.swing.table.TableColumn;
11 | import javax.swing.table.TableColumnModel;
12 |
13 | import a2l.TableModelView;
14 |
15 | public final class TableView extends JTable {
16 |
17 | private static final long serialVersionUID = 1L;
18 |
19 | public TableView(TableModelView model) {
20 | super(model);
21 | this.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
22 | this.setTableHeader(null);
23 | setDefaultRenderer(Object.class, new TableRenderer());
24 | this.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
25 | this.setCellSelectionEnabled(true);
26 | }
27 |
28 | @Override
29 | public TableModelView getModel() {
30 | return (TableModelView) super.getModel();
31 | }
32 |
33 | public static final void adjustCells(JTable table) {
34 |
35 | final TableColumnModel columnModel = table.getColumnModel();
36 | final int nbCol = columnModel.getColumnCount();
37 | final int nbRow = table.getRowCount();
38 | int maxWidth;
39 | TableCellRenderer cellRenderer;
40 | Object value;
41 | Component component;
42 | TableColumn column;
43 |
44 | for (short col = 0; col < nbCol; col++) {
45 | maxWidth = 0;
46 | for (short row = 0; row < nbRow; row++) {
47 | cellRenderer = table.getCellRenderer(row, col);
48 | value = table.getValueAt(row, col);
49 | component = cellRenderer.getTableCellRendererComponent(table, value, false, false, row, col);
50 | maxWidth = Math.max(component.getPreferredSize().width, maxWidth);
51 | }
52 | column = columnModel.getColumn(col);
53 | column.setPreferredWidth(maxWidth + 10);
54 | }
55 | }
56 |
57 | private final class TableRenderer extends DefaultTableCellRenderer
58 | {
59 | private static final long serialVersionUID = 1L;
60 |
61 | @Override
62 | public Component getTableCellRendererComponent(JTable paramJTable, Object paramObject, boolean paramBoolean1,
63 | boolean paramBoolean2, int paramInt1, int paramInt2) {
64 | super.getTableCellRendererComponent(paramJTable, paramObject, paramBoolean1, paramBoolean2, paramInt1,
65 | paramInt2);
66 | setHorizontalAlignment(SwingConstants.CENTER);
67 | return this;
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/A2LParser/src/gui/TextSearchTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 27 janv. 2020
3 | */
4 | package gui;
5 |
6 | import java.awt.Cursor;
7 | import java.awt.EventQueue;
8 | import java.awt.GridBagConstraints;
9 | import java.awt.GridBagLayout;
10 | import java.awt.event.ActionEvent;
11 | import java.awt.event.ActionListener;
12 | import java.io.File;
13 | import java.io.IOException;
14 | import java.nio.MappedByteBuffer;
15 | import java.nio.channels.FileChannel;
16 | import java.nio.channels.SeekableByteChannel;
17 | import java.nio.charset.Charset;
18 | import java.nio.file.Files;
19 | import java.nio.file.StandardOpenOption;
20 | import java.util.ArrayList;
21 | import java.util.HashMap;
22 | import java.util.List;
23 | import java.util.concurrent.Callable;
24 | import java.util.concurrent.ExecutorService;
25 | import java.util.concurrent.Executors;
26 | import java.util.concurrent.Future;
27 |
28 | import javax.swing.JFrame;
29 | import javax.swing.JOptionPane;
30 | import javax.swing.JPanel;
31 | import javax.swing.JScrollPane;
32 | import javax.swing.JSpinner;
33 | import javax.swing.JTextArea;
34 | import javax.swing.JTextField;
35 | import javax.swing.SpinnerNumberModel;
36 | import javax.swing.event.ChangeEvent;
37 | import javax.swing.event.ChangeListener;
38 | import javax.swing.text.BadLocationException;
39 | import javax.swing.text.DefaultHighlighter;
40 | import javax.swing.text.Document;
41 | import javax.swing.text.Element;
42 | import javax.swing.text.Highlighter;
43 | import javax.swing.text.PlainDocument;
44 | import javax.swing.text.Segment;
45 |
46 | public class TextSearchTest {
47 |
48 | private static SpinnerNumberModel numberModel;
49 |
50 | private static class Search implements Callable> {
51 |
52 | private Document document;
53 | HashMap dataOffsets;
54 | String searchString;
55 |
56 | public Search(Document document, String searchString) {
57 | this.document = document;
58 | this.searchString = searchString;
59 | }
60 |
61 | @Override
62 | public HashMap call() throws Exception {
63 | search();
64 |
65 | return dataOffsets;
66 | }
67 |
68 | @SuppressWarnings("boxing")
69 | private void search() {
70 |
71 | List lineOffsets = new ArrayList();
72 | dataOffsets = new HashMap();
73 | Element element = document.getDefaultRootElement();
74 | int elementCount = element.getElementCount();
75 |
76 | for (int i = 0; i < elementCount; i++) {
77 | lineOffsets.add(element.getElement(i).getStartOffset());
78 | }
79 | lineOffsets.add(element.getElement(element.getElementCount() - 1).getEndOffset());
80 |
81 | int count = 0;
82 | int lsOffset;
83 | int leOffset;
84 | int keyCnt = 1;
85 |
86 | while (count < (lineOffsets.size() - 1)) {
87 |
88 | lsOffset = lineOffsets.get(count);
89 | leOffset = lineOffsets.get(count + 1);
90 | count++;
91 | Segment seg = new Segment();
92 |
93 | try {
94 | document.getText(lsOffset, leOffset - lsOffset, seg);
95 | } catch (BadLocationException e) {
96 | e.printStackTrace();
97 | }
98 |
99 | String line = seg.toString();
100 | int mark = 0;
101 |
102 | while ((mark = line.indexOf(searchString, mark)) > -1) {
103 | dataOffsets.put(keyCnt++, lsOffset + mark);
104 | mark += searchString.length();
105 | }
106 | }
107 |
108 | }
109 |
110 | }
111 |
112 | private static class TextSearchPanel extends JPanel implements ActionListener {
113 |
114 | private static final long serialVersionUID = 1L;
115 |
116 | JTextField textField;
117 | JTextArea textArea;
118 | Highlighter highlighter;
119 |
120 | public TextSearchPanel(File file) {
121 | super(new GridBagLayout());
122 |
123 | try {
124 |
125 | SeekableByteChannel sbc = Files.newByteChannel(file.toPath(), StandardOpenOption.READ);
126 | int fileLength = (int) sbc.size();
127 | MappedByteBuffer mappedByteBuffer = ((FileChannel) sbc).map(FileChannel.MapMode.READ_ONLY, 0, sbc.size());
128 |
129 | byte[] b = new byte[(int) sbc.size()];
130 | mappedByteBuffer.get(b);
131 |
132 | mappedByteBuffer.clear();
133 | sbc.close();
134 |
135 | PlainDocument doc = new PlainDocument();
136 |
137 | doc.insertString(0, new String(b, 0, fileLength / 4, Charset.defaultCharset()), null);
138 | textField = new JTextField(20);
139 | textArea = new JTextArea(40, 100);
140 |
141 | textField.addActionListener(this);
142 | textField.setText("data");
143 | textArea.setEditable(true);
144 | textArea.setDocument(doc);
145 | JScrollPane scrollPane = new JScrollPane(textArea);
146 |
147 | GridBagConstraints c = new GridBagConstraints();
148 | c.gridwidth = GridBagConstraints.REMAINDER;
149 |
150 | c.fill = GridBagConstraints.HORIZONTAL;
151 | add(textField, c);
152 |
153 | numberModel = new SpinnerNumberModel();
154 | JSpinner spinner = new JSpinner(numberModel);
155 | add(spinner, c);
156 |
157 | spinner.addChangeListener(new ChangeListener() {
158 |
159 | @Override
160 | public void stateChanged(ChangeEvent e) {
161 | if (highlighter != null && highlighter.getHighlights().length > 0) {
162 | int idx = numberModel.getNumber().intValue();
163 | textArea.setCaretPosition(highlighter.getHighlights()[idx].getStartOffset());
164 | } else {
165 | numberModel.setValue(0);
166 | }
167 |
168 | }
169 | });
170 |
171 | c.fill = GridBagConstraints.BOTH;
172 | c.weightx = 1.0;
173 | c.weighty = 1.0;
174 | add(scrollPane, c);
175 |
176 | } catch (IOException e) {
177 | e.printStackTrace();
178 | } catch (BadLocationException e1) {
179 | e1.printStackTrace();
180 | }
181 |
182 | }
183 |
184 | @SuppressWarnings("boxing")
185 | @Override
186 | public void actionPerformed(ActionEvent event) {
187 |
188 | Cursor startCursor = textArea.getCursor();
189 | Cursor waitCursor = new Cursor(Cursor.WAIT_CURSOR);
190 | highlighter = textArea.getHighlighter();
191 | String searchText = textField.getText();
192 | Search search = new Search(textArea.getDocument(), searchText);
193 |
194 | textArea.setEditable(false);
195 | textArea.setCursor(waitCursor);
196 | highlighter.removeAllHighlights();
197 |
198 | ExecutorService service = Executors.newSingleThreadExecutor();
199 | Future> offsets = service.submit(search);
200 |
201 | try {
202 | for (Integer start : offsets.get().values()) {
203 | highlighter.addHighlight(start, start + searchText.length(), DefaultHighlighter.DefaultPainter);
204 | }
205 | } catch (Exception e) {
206 | }
207 |
208 | textArea.setEditable(true);
209 | textArea.setCursor(startCursor);
210 |
211 | if (highlighter.getHighlights().length > 0) {
212 | textArea.setCaretPosition(highlighter.getHighlights()[0].getStartOffset());
213 |
214 | numberModel.setMinimum(0);
215 | numberModel.setMaximum(highlighter.getHighlights().length - 1);
216 | numberModel.setStepSize(1);
217 |
218 | JOptionPane.showMessageDialog(this, "Search done!\nResult are highlighted.");
219 | } else {
220 | JOptionPane.showMessageDialog(this, "No result...");
221 | }
222 |
223 | }
224 | }
225 |
226 | public static void createAndShowGUI(File file) {
227 |
228 | JFrame frame = new JFrame("TextSearchTest");
229 | frame.add(new TextSearchPanel(file));
230 | frame.setLocationByPlatform(true);
231 | frame.pack();
232 | frame.setVisible(true);
233 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
234 | }
235 |
236 | public static void main(String args[]) {
237 |
238 | EventQueue.invokeLater(new Runnable() {
239 | public void run() {
240 |
241 | long start = System.currentTimeMillis();
242 |
243 | createAndShowGUI(new File("C:\\User\\U354706\\Perso\\WorkInProgress\\MG1CS032_D081C_VC2bis.a2l"));
244 |
245 | System.out.println("Durée : " + (System.currentTimeMillis() - start) + "ms");
246 | }
247 | });
248 | }
249 | }
250 |
--------------------------------------------------------------------------------
/A2LParser/src/utils/Converter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 10 mars 2019
3 | */
4 | package utils;
5 |
6 | import java.nio.ByteBuffer;
7 | import java.nio.ByteOrder;
8 |
9 | import constante.DataType;
10 | import data.DataCalibration;
11 |
12 | public final class Converter {
13 |
14 | private static final short readUBYTE(ByteBuffer bb) {
15 | return (short) (bb.get() & 0xff);
16 | }
17 |
18 | private static final byte readSBYTE(ByteBuffer bb) {
19 | return bb.get();
20 | }
21 |
22 | private static final long readULONG(ByteBuffer bb) {
23 | return bb.getInt() & 0xffffffffL;
24 | }
25 |
26 | private static final int readSLONG(ByteBuffer bb) {
27 | return bb.getInt();
28 | }
29 |
30 | private static final int readUWORD(ByteBuffer bb) {
31 | return bb.getShort() & 0xffff;
32 | }
33 |
34 | private static final short readSWORD(ByteBuffer bb) {
35 | return bb.getShort();
36 | }
37 |
38 | private static final float readFLOAT32IEEE(ByteBuffer bb) {
39 | return bb.getFloat();
40 | }
41 |
42 | private static final double readFLOAT64IEEE(ByteBuffer bb) {
43 | return bb.getDouble();
44 | }
45 |
46 | public static final double readHexValue(DataCalibration hex, long adress, DataType dataType, ByteOrder byteOrder) {
47 | return readHexValues(hex, adress, dataType, byteOrder, 1)[0];
48 | }
49 |
50 | public static final double[] readHexValues(DataCalibration hex, long adress, DataType dataType, ByteOrder byteOrder, int nbValue) {
51 |
52 | byte[] byteValues;
53 | final double[] hexValues = new double[nbValue];
54 | final byte nbByte = dataType.getNbByte();
55 |
56 | final ByteBuffer bb = ByteBuffer.allocateDirect(nbByte);
57 | bb.order(byteOrder);
58 |
59 | for (int nValue = 0; nValue < nbValue; nValue++) {
60 | byteValues = hex.readBytes(adress + (nValue * nbByte), nbByte);
61 | if (byteValues.length > 0) {
62 |
63 | bb.put(byteValues);
64 | bb.rewind();
65 |
66 | switch (dataType) {
67 | case UBYTE:
68 | hexValues[nValue] = readUBYTE(bb);
69 | break;
70 | case SBYTE:
71 | hexValues[nValue] = readSBYTE(bb);
72 | break;
73 | case UWORD:
74 | hexValues[nValue] = readUWORD(bb);
75 | break;
76 | case SWORD:
77 | hexValues[nValue] = readSWORD(bb);
78 | break;
79 | case ULONG:
80 | hexValues[nValue] = readULONG(bb);
81 | break;
82 | case SLONG:
83 | hexValues[nValue] = readSLONG(bb);
84 | break;
85 | case FLOAT32_IEEE:
86 | hexValues[nValue] = readFLOAT32IEEE(bb);
87 | break;
88 | case FLOAT64_IEEE:
89 | hexValues[nValue] = readFLOAT64IEEE(bb);
90 | break;
91 | default:
92 | // Nothing
93 | break;
94 | }
95 |
96 | bb.clear();
97 | }
98 | }
99 | return hexValues;
100 | }
101 |
102 | public static final double[] readHexValuesPairs(DataCalibration hex, long adress, DataType dataType, ByteOrder byteOrder, int nbValue) {
103 |
104 | byte[] byteValues;
105 | final double[] hexValues = new double[nbValue];
106 | final byte nbByte = dataType.getNbByte();
107 |
108 | final ByteBuffer bb = ByteBuffer.allocateDirect(nbByte);
109 | bb.order(byteOrder);
110 |
111 | for (int nValue = 0; nValue < nbValue; nValue++) {
112 | byteValues = hex.readBytes(adress + (nValue * 2 * nbByte), nbByte); // *2 : Patch pour ne lire une valeur par paire sur les axis_rescale
113 | if (byteValues.length > 0) {
114 |
115 | bb.put(byteValues);
116 | bb.rewind();
117 |
118 | switch (dataType) {
119 | case UBYTE:
120 | hexValues[nValue] = readUBYTE(bb);
121 | break;
122 | case SBYTE:
123 | hexValues[nValue] = readSBYTE(bb);
124 | break;
125 | case UWORD:
126 | hexValues[nValue] = readUWORD(bb);
127 | break;
128 | case SWORD:
129 | hexValues[nValue] = readSWORD(bb);
130 | break;
131 | case ULONG:
132 | hexValues[nValue] = readULONG(bb);
133 | break;
134 | case SLONG:
135 | hexValues[nValue] = readSLONG(bb);
136 | break;
137 | case FLOAT32_IEEE:
138 | hexValues[nValue] = readFLOAT32IEEE(bb);
139 | break;
140 | case FLOAT64_IEEE:
141 | hexValues[nValue] = readFLOAT64IEEE(bb);
142 | break;
143 | default:
144 | // Nothing
145 | break;
146 | }
147 |
148 | bb.clear();
149 | }
150 | }
151 | return hexValues;
152 | }
153 |
154 | }
155 |
--------------------------------------------------------------------------------
/A2LParser/src/utils/Interpolation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 25 juin 2018
3 | */
4 | package utils;
5 |
6 | public final class Interpolation {
7 |
8 | public static final double interpLinear(double x1, double x2, double y1, double y2, double xi) throws IllegalArgumentException {
9 | if (x1 == 0 && x2 == 0) {
10 | return Double.NaN;
11 | }
12 | return y1 + (xi - x1) * ((y2 - y1) / (x2 - x1));
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/A2LParser/src/utils/NumeralString.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 21 nov. 2018
3 | */
4 | package utils;
5 |
6 | import java.text.DecimalFormat;
7 | import java.util.regex.Pattern;
8 |
9 | public final class NumeralString {
10 |
11 | private static final Pattern NUMBER_SI = Pattern.compile("[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?");
12 | private static final Pattern ZERO_REPLACEMENT = Pattern.compile("0*$");
13 | private static final Pattern OTHER_REPLACEMENT = Pattern.compile("\\.$");
14 |
15 | public static final boolean isNumber(String s) {
16 |
17 | return NUMBER_SI.matcher(s).matches();
18 | }
19 |
20 | public static final String cutNumber(String number) {
21 | return (number.indexOf("e") > -1 || number.indexOf(".") < 0) ? number
22 | : OTHER_REPLACEMENT.matcher(ZERO_REPLACEMENT.matcher(number).replaceAll("")).replaceAll("");
23 | }
24 |
25 | public static final String formatStringNumber(double number) {
26 |
27 | final DecimalFormat format = new DecimalFormat();
28 |
29 | if (Math.floor(number) == number) {
30 |
31 | format.setMaximumFractionDigits(0);
32 |
33 | } else {
34 |
35 | String text = Double.toString(number);
36 | int integerPlaces = text.indexOf('.');
37 | int decimalPlaces = text.length() - integerPlaces - 1;
38 |
39 | if (decimalPlaces > 3) {
40 |
41 | return String.format("%1.3g", number).toLowerCase();
42 | }
43 |
44 | format.setMaximumFractionDigits(3);
45 | }
46 |
47 | return format.format(number);
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/A2LParser/src/utils/ParserUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Creation : 21 févr. 2019
3 | */
4 | package utils;
5 |
6 | import java.util.regex.Pattern;
7 |
8 | public final class ParserUtils {
9 |
10 | public static final Pattern LINE_COMMENT = Pattern.compile("/\\*.*?\\*/");
11 | public static final Pattern QUOTE = Pattern.compile("[^\\s\"']+|\"([^\"]*)\"|'([^']*)'");
12 |
13 | public static final boolean isUniqueString(String line) {
14 |
15 | final int nbChar = line.length();
16 | byte counter = 2;
17 |
18 | for (int i = 1; i < nbChar - 1; i++) {
19 | if (line.charAt(i) == '"') {
20 | if (line.charAt(i - 1) != '\\' && line.charAt(i + 1) != '"') {
21 | counter++;
22 | } else {
23 | i++;
24 | }
25 | }
26 | }
27 |
28 | return counter == 2;
29 | }
30 |
31 | public static String replaceSlashDoubleQuote(String s) {
32 | if ((s.indexOf('\\') == -1) && (s.indexOf('"') == -1))
33 | return s;
34 | StringBuilder sb = new StringBuilder();
35 | char oldC = 0;
36 | for (int i = 0; i < s.length(); i++) {
37 | char c = s.charAt(i);
38 | if (c == '\\' || (c == '\"' && oldC == '\\')) {
39 | oldC = c;
40 | continue;
41 | }
42 | oldC = c;
43 | sb.append(c);
44 | }
45 | return sb.toString();
46 | }
47 |
48 | public static final byte countQuote(String line) {
49 | final int nbChar = line.length();
50 | byte nbQuote = 0;
51 |
52 | for (int i = 0; i < nbChar; i++) {
53 | if (line.charAt(i) == '"') {
54 | nbQuote++;
55 | }
56 | }
57 |
58 | return nbQuote;
59 | }
60 |
61 | public static final boolean isEvenQuote(String line) {
62 | final byte nbQuote = countQuote(line);
63 | return (nbQuote & 1) != 1;
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AsamCalTool
2 | [](https://app.codacy.com/app/Sanglinard26/A2LParser?utm_source=github.com&utm_medium=referral&utm_content=Sanglinard26/A2LParser&utm_campaign=Badge_Grade_Dashboard)
3 |
--------------------------------------------------------------------------------