Skip to content

Commit

Permalink
07/04/2021 : Correction de bugs
Browse files Browse the repository at this point in the history
- prise en compte des objets sans COMPU_METHOD
  • Loading branch information
U354706 authored and U354706 committed Apr 7, 2021
1 parent a1de1d1 commit 2851e8f
Show file tree
Hide file tree
Showing 13 changed files with 278 additions and 33 deletions.
43 changes: 42 additions & 1 deletion A2LParser/src/a2l/A2l.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ public final boolean parse(File a2lFile) {

PrimaryKeywords keyword = PrimaryKeywords.getPrimaryKeywords(sumKeywordChar(line));

// System.out.println(numLine);

try {
switch (keyword) {
case MOD_PAR:
Expand Down Expand Up @@ -462,8 +464,47 @@ public Vector<String> getAdjustableObjectNameByFunction(String function) {
public Vector<AdjustableObject> getAdjustableObjectFromList(Vector<String> listNameAdjObj) {
final Vector<AdjustableObject> listByName = new Vector<AdjustableObject>();

AdjustableObject object;

for (String nameAdjObj : listNameAdjObj) {
object = adjustableObjects.get(nameAdjObj.hashCode());
if (object != null) {
listByName.add(object);
}
}

Collections.sort(listByName);

return listByName;
}

public Vector<String> getAdjustableObjectNameFromList(Vector<String> listNameAdjObj) {
final Vector<String> listByName = new Vector<String>();

AdjustableObject object;

for (String nameAdjObj : listNameAdjObj) {
listByName.add(adjustableObjects.get(nameAdjObj.hashCode()));
object = adjustableObjects.get(nameAdjObj.hashCode());
if (object != null) {
listByName.add(object.toString());
}
}

Collections.sort(listByName);

return listByName;
}

public Vector<String> getMeasurementNameFromList(Vector<String> listNameMeasurement) {
final Vector<String> listByName = new Vector<String>();

for (String nameMeasurement : listNameMeasurement) {
for (Measurement measurement : measurements) {
if (nameMeasurement.equals(measurement.toString())) {
listByName.add(nameMeasurement);
break;
}
}
}

Collections.sort(listByName);
Expand Down
102 changes: 101 additions & 1 deletion A2LParser/src/a2l/A2lUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
*/
package a2l;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -55,7 +58,104 @@ public static final void writeCharacteristicLab(File file, A2l a2l, Function fun
}
}

public static final void renameLabel(A2l a2l, Function function) {
public static final void linkPrototypeAxis(Object a2lObject, File selectedFile) {

A2l a2l = (A2l) a2lObject;

try (BufferedReader br = new BufferedReader(new FileReader(selectedFile))) {
String line;
Vector<String> prototypeAxis = new Vector<String>();

while ((line = br.readLine()) != null) {
prototypeAxis.add(line.substring(0, line.length() - 1));
}

Vector<AdjustableObject> v = a2l.getAdjustableObjectFromList(prototypeAxis);
System.out.println(v);

File newFile = new File(selectedFile.getAbsolutePath().replace(".lab", "_Linked.lab"));

try (PrintWriter pw = new PrintWriter(newFile)) {

pw.println("[Label]");

for (AdjustableObject axis : v) {
if (axis instanceof AxisPts) {
pw.println(axis.toString() + "b");
for (Characteristic s : ((AxisPts) axis).getCharacteristicsDependency()) {
pw.println(s + "b");
}
}
}

} catch (FileNotFoundException e) {
e.printStackTrace();
}

} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

public static final void checkMEIBloc(Object a2lObject, File selectedFile) {

A2l a2l = (A2l) a2lObject;

try (BufferedReader br = new BufferedReader(new FileReader(selectedFile))) {
String line;
Vector<String> measurements = new Vector<String>();
Vector<String> characteristics = new Vector<String>();

boolean bMeasurement = true;

while ((line = br.readLine()) != null) {
if ("[MEASUREMENT]".equals(line) || "[CHARACTERISTIC]".equals(line)) {

if ("[CHARACTERISTIC]".equals(line)) {
bMeasurement = !bMeasurement;
}

line = br.readLine();
}

if (bMeasurement) {
measurements.add(line);
} else {
characteristics.add(line);
}
}

Vector<String> m = a2l.getMeasurementNameFromList(measurements);
measurements.removeAll(m);

Vector<String> c = a2l.getAdjustableObjectNameFromList(characteristics);
characteristics.removeAll(c);

File newFile = new File(selectedFile.getAbsolutePath().replace(".txt", "_checked.txt"));

try (PrintWriter pw = new PrintWriter(newFile)) {

pw.println("[MEASUREMENT]");
for (String measure : measurements) {
pw.println(measure);
}

pw.println("[CHARACTERISTIC]");
for (String characteristic : characteristics) {
pw.println(characteristic);
}

} catch (FileNotFoundException e) {
e.printStackTrace();
}

} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

}

Expand Down
60 changes: 52 additions & 8 deletions A2LParser/src/a2l/Characteristic.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ private static byte getNbAxis(CharacteristicType type) {
@Override
public final void assignComputMethod(HashMap<Integer, CompuMethod> compuMethods) {
this.compuMethod = compuMethods.get(this.conversionId);
if (this.compuMethod == null) {
this.compuMethod = CompuMethod.createNoCompuMethod();
}
if (axisDescrs != null) {
for (int idx = 0; idx < axisDescrs.length; idx++) {
axisDescrs[idx].setCompuMethod(compuMethods.get(axisDescrs[idx].getConversion()));
Expand All @@ -215,7 +218,14 @@ public String[] getUnit() {

switch (getType()) {
case VALUE:
unit = new String[] { this.compuMethod.getUnit() };
unit = new String[1];

if (this.compuMethod != null) {
unit[0] = this.compuMethod.getUnit();
} else {
unit[0] = "";
}

break;
case CURVE:
unit = new String[2];
Expand All @@ -228,22 +238,56 @@ public String[] getUnit() {
} else {
if (axisDescr.getAttribute().compareTo(Attribute.CURVE_AXIS) == 0) {
unit[0] = "";
} else {
unit[0] = "";
}
}
}

unit[1] = this.compuMethod.getUnit();
if (this.compuMethod != null) {
unit[1] = this.compuMethod.getUnit();
} else {
unit[1] = "";
}

break;
case MAP:
unit = new String[3];
unit[0] = this.axisDescrs[0].getPhysUnit().length() > 0 ? this.axisDescrs[0].getPhysUnit()
: this.axisDescrs[0].getCompuMethod().getUnit();
unit[1] = this.axisDescrs[1].getPhysUnit().length() > 0 ? this.axisDescrs[1].getPhysUnit()
: this.axisDescrs[1].getCompuMethod().getUnit();
unit[2] = this.compuMethod.getUnit();

if (this.axisDescrs[0].getPhysUnit().length() > 0) {
unit[0] = this.axisDescrs[0].getPhysUnit();
} else {
if (this.axisDescrs[0].getCompuMethod() != null) {
unit[0] = this.axisDescrs[0].getCompuMethod().getUnit();
} else {
unit[0] = "";
}
}

if (this.axisDescrs[1].getPhysUnit().length() > 0) {
unit[1] = this.axisDescrs[1].getPhysUnit();
} else {
if (this.axisDescrs[1].getCompuMethod() != null) {
unit[1] = this.axisDescrs[1].getCompuMethod().getUnit();
} else {
unit[1] = "";
}
}

if (this.compuMethod != null) {
unit[2] = this.compuMethod.getUnit();
} else {
unit[2] = "";
}
break;
case VAL_BLK:
unit = new String[] { this.compuMethod.getUnit() };
unit = new String[1];

if (this.compuMethod != null) {
unit[0] = this.compuMethod.getUnit();
} else {
unit[0] = "";
}
break;
default:
unit = new String[] { "" };
Expand Down
12 changes: 12 additions & 0 deletions A2LParser/src/a2l/CompuMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,23 @@ public CompuMethod(List<String> parameters, int beginLine, int endLine) {
build(parameters, beginLine, endLine);
}

private CompuMethod() {
this.name = "NO_COMPU_METHOD";
this.longIdentifier = new char[] { ' ' };
this.conversionType = ConversionType.getConversionType("");
this.format = new Format("");
this.unit = new char[] { ' ' };
}

@Override
public String toString() {
return this.name;
}

public static final CompuMethod createNoCompuMethod() {
return new CompuMethod();
}

public final void assignConversionTable(HashMap<Integer, ConversionTable> conversionTables) {
if (!hasCompuTabRef()) {
return;
Expand Down
6 changes: 2 additions & 4 deletions A2LParser/src/a2l/Function.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@

import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Vector;

import constante.SecondaryKeywords;
Expand Down Expand Up @@ -204,10 +202,10 @@ public void build(List<String> parameters, int beginLine, int endLine) throws Il
}

@SuppressWarnings("unchecked")
public final Set<String> getSubFunction() {
public final Vector<String> getSubFunction() {
Object object = optionalsParameters.get(SUB_FUNCTION);

return object != null ? (Set<String>) object : new HashSet<String>();
return object != null ? (Vector<String>) object : new Vector<String>();
}

@Override
Expand Down
3 changes: 3 additions & 0 deletions A2LParser/src/a2l/Measurement.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ public void build(List<String> parameters, int beginLine, int endLine) throws Il

public final void assignComputMethod(HashMap<Integer, CompuMethod> compuMethods) {
this.compuMethod = compuMethods.get(this.conversionId);
if (this.compuMethod == null) {
this.compuMethod = CompuMethod.createNoCompuMethod();
}
}

public final String getUnit() {
Expand Down
5 changes: 5 additions & 0 deletions A2LParser/src/data/DataDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ public final boolean readDataFromFile() {

for (AdjustableObject adjustableObject : a2l.getAdjustableObjects().values()) {
if (adjustableObject instanceof AxisPts && adjustableObject.isValid()) {

if (((AxisPts) adjustableObject).toString().equals("TrbAct_tiFilDftlY_A")) {
int i = 0;
}

readAxisPts(byteOrder, (AxisPts) adjustableObject);
}
}
Expand Down
2 changes: 1 addition & 1 deletion A2LParser/src/data/Memory.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public final class Memory {

public Memory(long address, byte[] data) {
this.address = address;
listByte = new ArrayList<Byte>();
listByte = new ArrayList<Byte>(data.length);
for (int i = 0; i < data.length; i++) {
listByte.add(data[i]);
}
Expand Down
1 change: 0 additions & 1 deletion A2LParser/src/gui/A2lDisplayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ protected void done() {
doc.getText(offs, nleft, text);

} catch (BadLocationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// do something with text
Expand Down
3 changes: 0 additions & 3 deletions A2LParser/src/gui/DisplayLog_Bis.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,8 @@ protected void done() {
try {
get();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Expand All @@ -74,7 +72,6 @@ protected void process(List<String> chunks) {
try {
doc.insertString(doc.getLength(), text, null);
} catch (BadLocationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Expand Down
Loading

0 comments on commit 2851e8f

Please sign in to comment.