refactoring

This commit is contained in:
rusefi 2017-06-21 07:02:36 +03:00
parent b19b850575
commit fd247c7899
4 changed files with 63 additions and 50 deletions

View File

@ -36,7 +36,7 @@ import com.romraider.editor.ecu.ECUEditorManager;
import com.romraider.maps.Rom;
import com.romraider.util.SettingsManager;
import com.opensr5.ConfigurationImage;
import com.rusefi.binaryprotocol.BinaryProtocolCmd;
import com.rusefi.UploadChanges;
import com.rusefi.io.CommandQueue;
import com.rusefi.ui.SettingsTab;
@ -86,7 +86,7 @@ public class ECUEditorToolBar extends JToolBar {
Rom lastSelectedRom = ECUEditorManager.getECUEditor().getLastSelectedRom();
byte[] newVersion = ConfigurationImage.extractContent(lastSelectedRom.saveFile());
System.out.println("new version size: " + newVersion.length);
BinaryProtocolCmd.scheduleUpload(new ConfigurationImage(newVersion));
UploadChanges.scheduleUpload(new ConfigurationImage(newVersion));
}
});
downloadImage.addActionListener(new ActionListener() {

View File

@ -75,7 +75,11 @@ public class UploadChanges {
final BinaryProtocol bp = new BinaryProtocol(logger, serialPort);
bp.setController(ci1);
scheduleUpload(ci2, null);
scheduleUpload(ci2);
}
public static void scheduleUpload(final ConfigurationImage newVersion) {
scheduleUpload(newVersion, null);
}
public static void scheduleUpload(final ConfigurationImage newVersion, final Runnable afterUpload) {

View File

@ -1,12 +1,8 @@
package com.rusefi.binaryprotocol;
import com.opensr5.ConfigurationImage;
import com.opensr5.Logger;
import com.romraider.editor.ecu.ECUEditor;
import com.rusefi.*;
import com.opensr5.io.ConfigurationImageFile;
import com.rusefi.io.serial.PortHolder;
import jssc.SerialPort;
import com.rusefi.RomRaiderWrapper;
import com.rusefi.UploadChanges;
import javax.swing.*;
import java.io.File;
@ -16,43 +12,6 @@ import java.io.File;
* 3/6/2015
*/
public class BinaryProtocolCmd {
static BinaryProtocol bp;
public static void main(String[] args) throws Exception {
if (args.length != 1) {
System.out.println("Exactly one parameter expected");
return;
}
String port = args[0];
Logger logger = UploadChanges.logger;
SerialPort serialPort;
serialPort = new SerialPort(port);
boolean opened = serialPort.openPort();
if (!opened) {
logger.error("failed to open " + port);
}
bp = new BinaryProtocol(logger, serialPort);
PortHolder.setupPort(serialPort, 38400);
logger.info("Binary looks good!");
bp.switchToBinaryProtocol();
bp.readImage(TsPageSize.IMAGE_SIZE);
//
// image.saveToFile("rusefi_configuration.bin");
//
doShowImage(bp.getController());
}
public static void doShowImage(ConfigurationImage image) throws Exception {
if (!checkForDefinitionFile())
return;
RomRaiderWrapper.startRomRaider();
ECUEditor.openImage(ConfigurationImageFile.getFileContent(image));
}
public static boolean checkForDefinitionFile() {
if (!new File(RomRaiderWrapper.DEFINITION_FILE).exists()) {
@ -61,8 +20,4 @@ public class BinaryProtocolCmd {
}
return true;
}
public static void scheduleUpload(ConfigurationImage newVersion) {
UploadChanges.scheduleUpload(newVersion, null);
}
}

View File

@ -0,0 +1,54 @@
package com.rusefi.binaryprotocol;
import com.opensr5.ConfigurationImage;
import com.opensr5.Logger;
import com.opensr5.io.ConfigurationImageFile;
import com.romraider.editor.ecu.ECUEditor;
import com.rusefi.RomRaiderWrapper;
import com.rusefi.TsPageSize;
import com.rusefi.UploadChanges;
import com.rusefi.io.serial.PortHolder;
import jssc.SerialPort;
/**
* (c) Andrey Belomutskiy
* 6/21/2017
*/
public class BinaryProtocolCmdSandbox {
public static void main(String[] args) throws Exception {
if (args.length != 1) {
System.out.println("Exactly one parameter expected: port");
return;
}
String port = args[0];
Logger logger = UploadChanges.logger;
SerialPort serialPort;
serialPort = new SerialPort(port);
boolean opened = serialPort.openPort();
if (!opened) {
logger.error("failed to open " + port);
}
BinaryProtocol bp = new BinaryProtocol(logger, serialPort);
PortHolder.setupPort(serialPort, 38400);
logger.info("Binary looks good!");
bp.switchToBinaryProtocol();
bp.readImage(TsPageSize.IMAGE_SIZE);
//
// image.saveToFile("rusefi_configuration.bin");
//
doShowImage(bp.getController());
}
private static void doShowImage(ConfigurationImage image) throws Exception {
if (!BinaryProtocolCmd.checkForDefinitionFile())
return;
RomRaiderWrapper.startRomRaider();
ECUEditor.openImage(ConfigurationImageFile.getFileContent(image));
}
}