auto-sync

This commit is contained in:
rusEfi 2015-04-14 21:06:50 -04:00
parent 4e0f8021b2
commit a7fb6f64d3
5 changed files with 60 additions and 44 deletions

View File

@ -176,17 +176,17 @@ static void mapAveragingCallback(trigger_event_e ckpEventType, uint32_t index DE
MAP_sensor_config_s * config = &engineConfiguration->map; MAP_sensor_config_s * config = &engineConfiguration->map;
float startAngle = interpolate2d(rpm, config->samplingAngleBins, config->samplingAngle, MAP_ANGLE_SIZE); angle_t samplingStart = interpolate2d(rpm, config->samplingAngleBins, config->samplingAngle, MAP_ANGLE_SIZE);
float windowAngle = interpolate2d(rpm, config->samplingWindowBins, config->samplingWindow, MAP_WINDOW_SIZE); angle_t samplingDuration = interpolate2d(rpm, config->samplingWindowBins, config->samplingWindow, MAP_WINDOW_SIZE);
if (windowAngle <= 0) { if (samplingDuration <= 0) {
firmwareError("map sampling angle should be positive"); firmwareError("map sampling angle should be positive");
return; return;
} }
int structIndex = getRevolutionCounter() % 2; int structIndex = getRevolutionCounter() % 2;
// todo: schedule this based on closest trigger event, same as ignition works // todo: schedule this based on closest trigger event, same as ignition works
scheduleByAngle(rpm, &startTimer[structIndex], startAngle, startAveraging, NULL); scheduleByAngle(rpm, &startTimer[structIndex], samplingStart, startAveraging, NULL);
scheduleByAngle(rpm, &endTimer[structIndex], startAngle + windowAngle, endAveraging, NULL); scheduleByAngle(rpm, &endTimer[structIndex], samplingStart + samplingDuration, endAveraging, NULL);
} }
static void showMapStats(void) { static void showMapStats(void) {

View File

@ -74,9 +74,9 @@
</table> </table>
</table> </table>
<table type="2D" name="Intake air temperature-based extra idle air" storageaddress="@@iatIdleCorr_hex@@" sizex="16" storagetype="float" endian="big"> <table type="2D" name="Intake air temperature-based extra idle air" storageaddress="@@cltIdleCorr_hex@@" sizex="16" storagetype="float" endian="big">
<scaling units="Target Boost (psia) Compensation (%)" expression="x" to_byte="x" format="0.00" fineincrement=".01" coarseincrement="0.1" /> <scaling units="Target Boost (psia) Compensation (%)" expression="x" to_byte="x" format="0.00" fineincrement=".01" coarseincrement="0.1" />
<table type="X Axis" storageaddress="@@iatIdleCorrBins_hex@@" storagetype="float" endian="big"> <table type="X Axis" storageaddress="@@cltIdleCorrBins_hex@@" storagetype="float" endian="big">
<scaling units="uni" expression="x" to_byte="x" format="0.00" fineincrement=".1" coarseincrement="1" /> <scaling units="uni" expression="x" to_byte="x" format="0.00" fineincrement=".1" coarseincrement="1" />
</table> </table>
</table> </table>

View File

@ -52,6 +52,8 @@ import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.util.Vector; import java.util.Vector;
import javax.management.modelmbean.XMLParseException;
import javax.naming.NameNotFoundException;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JCheckBox; import javax.swing.JCheckBox;
import javax.swing.JInternalFrame; import javax.swing.JInternalFrame;
@ -66,6 +68,7 @@ import javax.swing.tree.TreePath;
import com.rusefi.Launcher; import com.rusefi.Launcher;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException; import org.xml.sax.SAXParseException;
import com.romraider.Settings; import com.romraider.Settings;
@ -171,27 +174,10 @@ public class ECUEditor {
return content; return content;
} }
public static void openImage(byte[] input, File definitionFile, String fileName) throws Exception { public static void openImage(byte[] input, File definitionFile, String fileName) throws IOException, SAXException,
RomNotFoundException, XMLParseException, NameNotFoundException {
ECUEditor editor = ECUEditorManager.getECUEditor(); ECUEditor editor = ECUEditorManager.getECUEditor();
DOMParser parser = new DOMParser(); Rom rom = readRom(input, definitionFile, editor);
Document doc;
FileInputStream fileStream;
fileStream = new FileInputStream(definitionFile);
InputSource src = new InputSource(fileStream);
parser.parse(src);
doc = parser.getDocument();
Rom rom;
try {
rom = new DOMRomUnmarshaller().unmarshallXMLDefinition(doc.getDocumentElement(), input, editor.getStatusPanel());
} finally {
// Release mem after unmarshall.
parser.reset();
doc.removeChild(doc.getDocumentElement());
fileStream.close();
System.gc();
}
editor.getStatusPanel().setStatus("Populating tables..."); editor.getStatusPanel().setStatus("Populating tables...");
@ -206,6 +192,29 @@ public class ECUEditor {
editor.getStatusPanel().setStatus("Done loading image..."); editor.getStatusPanel().setStatus("Done loading image...");
} }
private static Rom readRom(byte[] romContent, File romDefinitionFile, ECUEditor editor) throws SAXException, IOException, RomNotFoundException, XMLParseException, NameNotFoundException {
DOMParser parser = new DOMParser();
Document doc;
FileInputStream fileStream;
fileStream = new FileInputStream(romDefinitionFile);
InputSource src = new InputSource(fileStream);
parser.parse(src);
doc = parser.getDocument();
Rom rom;
try {
rom = new DOMRomUnmarshaller().unmarshallXMLDefinition(doc.getDocumentElement(), romContent, editor.getStatusPanel());
} finally {
// Release mem after unmarshall.
parser.reset();
doc.removeChild(doc.getDocumentElement());
fileStream.close();
System.gc();
}
return rom;
}
public void initializeEditorUI() { public void initializeEditorUI() {
//create menubar //create menubar
menuBar = new ECUEditorMenuBar(); menuBar = new ECUEditorMenuBar();

View File

@ -19,10 +19,7 @@
package com.romraider.util; package com.romraider.util;
import java.io.ByteArrayInputStream; import java.io.*;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
public final class ObjectCloner { public final class ObjectCloner {
@ -30,7 +27,7 @@ public final class ObjectCloner {
} }
// returns a deep copy of an object // returns a deep copy of an object
public static Object deepCopy(Object obj) throws Exception { public static Object deepCopy(Object obj) {
/*ByteArrayOutputStream bos = new ByteArrayOutputStream(); /*ByteArrayOutputStream bos = new ByteArrayOutputStream();
try { try {
ObjectOutputStream oos = new ObjectOutputStream(bos); ObjectOutputStream oos = new ObjectOutputStream(bos);
@ -82,15 +79,25 @@ public final class ObjectCloner {
// read the serialized, and deep copied, object and return it // read the serialized, and deep copied, object and return it
return inStream.readObject(); return inStream.readObject();
} catch (Exception e) { } catch (Throwable e) {
throw (e); throw new IllegalStateException(e);
} finally { } finally {
//always close your streams in finally clauses //always close your streams in finally clauses
outStream.close(); close(outStream);
inStream.close(); close(inStream);
} }
} }
public static void close(Closeable closeable) {
if(closeable!=null) {
try {
closeable.close();
} catch (IOException e) {
// ignoring exception during close()
}
}
}
} }

View File

@ -29,6 +29,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.management.modelmbean.XMLParseException; import javax.management.modelmbean.XMLParseException;
import javax.naming.NameNotFoundException;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import com.rusefi.Launcher; import com.rusefi.Launcher;
@ -62,9 +63,9 @@ public final class DOMRomUnmarshaller {
public DOMRomUnmarshaller() { public DOMRomUnmarshaller() {
} }
public Rom unmarshallXMLDefinition(Node rootNode, byte[] input, public Rom unmarshallXMLDefinition(Node rootNode, byte[] romContent,
JProgressPane progress) throws RomNotFoundException, JProgressPane progress) throws RomNotFoundException,
XMLParseException, StackOverflowError, Exception { XMLParseException, NameNotFoundException {
this.progress = progress; this.progress = progress;
Node n; Node n;
@ -97,13 +98,13 @@ public final class DOMRomUnmarshaller {
RomID romID = unmarshallRomID(n2, new RomID()); RomID romID = unmarshallRomID(n2, new RomID());
if (romID.getInternalIdString().length() > 0 if (romID.getInternalIdString().length() > 0
&& foundMatch(romID, input)) { && foundMatch(romID, romContent)) {
Rom output = unmarshallRom(n, new Rom()); Rom output = unmarshallRom(n, new Rom());
// set ram offset // set ram offset
output.getRomID().setRamOffset( output.getRomID().setRamOffset(
output.getRomID().getFileSize() output.getRomID().getFileSize()
- input.length); - romContent.length);
return output; return output;
} }
} }
@ -189,7 +190,7 @@ public final class DOMRomUnmarshaller {
} }
public Rom unmarshallRom(Node rootNode, Rom rom) throws XMLParseException, public Rom unmarshallRom(Node rootNode, Rom rom) throws XMLParseException,
RomNotFoundException, StackOverflowError, Exception { RomNotFoundException, NameNotFoundException {
Node n; Node n;
NodeList nodes = rootNode.getChildNodes(); NodeList nodes = rootNode.getChildNodes();
@ -251,8 +252,7 @@ public final class DOMRomUnmarshaller {
} }
public Rom getBaseRom(Node rootNode, String xmlID, Rom rom) public Rom getBaseRom(Node rootNode, String xmlID, Rom rom)
throws XMLParseException, RomNotFoundException, StackOverflowError, throws XMLParseException, RomNotFoundException, NameNotFoundException {
Exception {
Node n; Node n;
NodeList nodes = rootNode.getChildNodes(); NodeList nodes = rootNode.getChildNodes();
@ -351,7 +351,7 @@ public final class DOMRomUnmarshaller {
} }
private Table unmarshallTable(Node tableNode, Table table, Rom rom) private Table unmarshallTable(Node tableNode, Table table, Rom rom)
throws XMLParseException, TableIsOmittedException, Exception { throws XMLParseException, TableIsOmittedException, NameNotFoundException {
if (unmarshallAttribute(tableNode, "omit", "false").equalsIgnoreCase( if (unmarshallAttribute(tableNode, "omit", "false").equalsIgnoreCase(
"true")) { // remove table if omitted "true")) { // remove table if omitted