only:steps towards sandbox

This commit is contained in:
rusefillc 2025-02-22 11:37:37 -05:00
parent 10c08ffa3e
commit 89582a50f9
2 changed files with 29 additions and 18 deletions

View File

@ -1,5 +1,6 @@
package com.rusefi.ts_plugin.knock; package com.rusefi.ts_plugin.knock;
import com.devexperts.logging.Logging;
import com.efiAnalytics.plugin.ecu.*; import com.efiAnalytics.plugin.ecu.*;
import com.rusefi.core.ui.AutoupdateUtil; import com.rusefi.core.ui.AutoupdateUtil;
import org.putgemin.VerticalFlowLayout; import org.putgemin.VerticalFlowLayout;
@ -12,10 +13,14 @@ import java.util.Arrays;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.devexperts.logging.Logging.getLogging;
public class KnockAnalyzerTab { public class KnockAnalyzerTab {
private static final Logging log = getLogging(KnockAnalyzerTab.class);
public static final String CYLINDERS_COUNT = "cylindersCount"; public static final String CYLINDERS_COUNT = "cylindersCount";
public static final String ENABLE_KNOCK_SPECTROGRAM = "enableKnockSpectrogram";
private enum CanvasType { private enum CanvasType {
CT_ALL, CT_ALL,
@ -39,13 +44,13 @@ public class KnockAnalyzerTab {
private int channel = 0; private int channel = 0;
private int cylinder = 0; private int cylinder = 0;
private float[] values = new float[64]; private final float[] values = new float[64];
private int cylindersCount = 0; private int cylindersCount = 0;
private CanvasType canvasType = CanvasType.CT_ALL; private CanvasType canvasType = CanvasType.CT_ALL;
private ArrayList<KnockCanvas> canvases = new ArrayList<>(); private final ArrayList<KnockCanvas> canvases = new ArrayList<>();
private final KnockMagnitudeCanvas magnituges = new KnockMagnitudeCanvas(); private final KnockMagnitudeCanvas magnituges = new KnockMagnitudeCanvas();
public KnockAnalyzerTab(Supplier<ControllerAccess> controllerAccessSupplier) { public KnockAnalyzerTab(Supplier<ControllerAccess> controllerAccessSupplier) {
@ -63,7 +68,7 @@ public class KnockAnalyzerTab {
} }
}); });
} catch (ControllerException ee) { } catch (ControllerException ee) {
System.out.println(ee.getMessage()); log.error(ee.getMessage());
} }
try { try {
@ -76,8 +81,8 @@ public class KnockAnalyzerTab {
magnituges.setFrequencyStep(frequencyStep); magnituges.setFrequencyStep(frequencyStep);
} }
}); });
} catch (ControllerException ee) { } catch (ControllerException e) {
System.out.println(ee.getMessage()); log.error(e.getMessage());
} }
try { try {
@ -90,8 +95,8 @@ public class KnockAnalyzerTab {
KnockAnalyzerTab.this.channel = (int) (value >>> 8) & 0xFF; KnockAnalyzerTab.this.channel = (int) (value >>> 8) & 0xFF;
KnockAnalyzerTab.this.cylinder = (int) (value & 0xFF); KnockAnalyzerTab.this.cylinder = (int) (value & 0xFF);
}); });
} catch (ControllerException ee) { } catch (ControllerException e) {
System.out.println(ee.getMessage()); log.error(e.getMessage());
} }
try { try {
@ -100,8 +105,8 @@ public class KnockAnalyzerTab {
double value = cylindersCountParameter.getScalarValue(); double value = cylindersCountParameter.getScalarValue();
KnockAnalyzerTab.this.cylindersCount = (int) (value); KnockAnalyzerTab.this.cylindersCount = (int) (value);
} }
} catch (ControllerException ee) { } catch (ControllerException e) {
System.out.println(ee.getMessage()); log.error(e.getMessage());
} }
try { try {
@ -117,6 +122,7 @@ public class KnockAnalyzerTab {
checksum += i; checksum += i;
} }
if (outputChannelNames.length!=0)
for (int i = 0; i < 16; ++i) { for (int i = 0; i < 16; ++i) {
try { try {
@ -154,12 +160,12 @@ public class KnockAnalyzerTab {
} }
}); });
} catch (ControllerException ee) { } catch (ControllerException ee) {
System.out.println(ee.getMessage()); log.error(ee.getMessage());
} }
} }
} catch (ControllerException e) { } catch (ControllerException e) {
log.error(e.getMessage());
} }
buttonStartStop.addActionListener(e -> { buttonStartStop.addActionListener(e -> {
@ -327,11 +333,11 @@ public class KnockAnalyzerTab {
public boolean getEnabledEcu() { public boolean getEnabledEcu() {
try { try {
String ecuControllerName = this.controllerAccessSupplier.get().getEcuConfigurationNames()[0]; String ecuControllerName = this.controllerAccessSupplier.get().getEcuConfigurationNames()[0];
ControllerParameter enable = controllerAccessSupplier.get().getControllerParameterServer().getControllerParameter(ecuControllerName, "enableKnockSpectrogram"); ControllerParameter enable = controllerAccessSupplier.get().getControllerParameterServer().getControllerParameter(ecuControllerName, ENABLE_KNOCK_SPECTROGRAM);
String enabled = enable.getStringValue(); String enabled = enable.getStringValue();
return enabled.indexOf("true") > 0; return enabled.indexOf("true") > 0;
} catch (ControllerException ee) { } catch (ControllerException ee) {
System.out.println(ee.getMessage()); log.error(ee.getMessage());
} }
return false; return false;
@ -342,7 +348,7 @@ public class KnockAnalyzerTab {
String ecuControllerName = this.controllerAccessSupplier.get().getEcuConfigurationNames()[0]; String ecuControllerName = this.controllerAccessSupplier.get().getEcuConfigurationNames()[0];
controllerAccessSupplier.get().getControllerParameterServer().updateParameter(ecuControllerName, "enableKnockSpectrogram", enabled ? 1.0 : 0.0); controllerAccessSupplier.get().getControllerParameterServer().updateParameter(ecuControllerName, "enableKnockSpectrogram", enabled ? 1.0 : 0.0);
} catch (ControllerException ee) { } catch (ControllerException ee) {
System.out.println(ee.getMessage()); log.error(ee.getMessage());
} }
} }

View File

@ -5,7 +5,6 @@ import com.efiAnalytics.plugin.ecu.ControllerException;
import com.efiAnalytics.plugin.ecu.ControllerParameter; import com.efiAnalytics.plugin.ecu.ControllerParameter;
import com.efiAnalytics.plugin.ecu.servers.ControllerParameterServer; import com.efiAnalytics.plugin.ecu.servers.ControllerParameterServer;
import com.efiAnalytics.plugin.ecu.servers.OutputChannelServer; import com.efiAnalytics.plugin.ecu.servers.OutputChannelServer;
import com.opensr5.ini.IniFileModel;
import com.opensr5.ini.IniFileModelImpl; import com.opensr5.ini.IniFileModelImpl;
import com.rusefi.TsTuneReader; import com.rusefi.TsTuneReader;
import com.rusefi.core.ui.FrameHelper; import com.rusefi.core.ui.FrameHelper;
@ -27,13 +26,18 @@ import static org.mockito.Mockito.*;
public class PluginBodySandbox { public class PluginBodySandbox {
private static final String PROJECT_NAME = "dev"; private static final String PROJECT_NAME = "dev";
public static final ControllerParameter result = new ControllerParameter() { public static final ControllerParameter cylinderResult = new ControllerParameter() {
@Override @Override
public double getScalarValue() { public double getScalarValue() {
return 2; return 2;
} }
}; };
public static final ControllerParameter result2 = new ControllerParameter() {
@Override
public String getStringValue() {
return "true";
}
};
public static void main(String[] args) throws ControllerException { public static void main(String[] args) throws ControllerException {
String iniFile = TsTuneReader.getProjectModeFileName(PROJECT_NAME); String iniFile = TsTuneReader.getProjectModeFileName(PROJECT_NAME);
IniFileModelImpl model = IniFileModelImpl.readIniFile(iniFile); IniFileModelImpl model = IniFileModelImpl.readIniFile(iniFile);
@ -47,7 +51,8 @@ public class PluginBodySandbox {
ControllerParameterServer controllerParameterServer = mock(ControllerParameterServer.class, NEGATIVE_ANSWER); ControllerParameterServer controllerParameterServer = mock(ControllerParameterServer.class, NEGATIVE_ANSWER);
doReturn(parameterNames).when(controllerParameterServer).getParameterNames(any()); doReturn(parameterNames).when(controllerParameterServer).getParameterNames(any());
doReturn(result).when(controllerParameterServer).getControllerParameter(any(), eq(KnockAnalyzerTab.CYLINDERS_COUNT)); doReturn(cylinderResult).when(controllerParameterServer).getControllerParameter(any(), eq(KnockAnalyzerTab.CYLINDERS_COUNT));
doReturn(result2).when(controllerParameterServer).getControllerParameter(any(), eq(KnockAnalyzerTab.ENABLE_KNOCK_SPECTROGRAM));
doNothing().when(controllerParameterServer).subscribe(any(), any(), any()); doNothing().when(controllerParameterServer).subscribe(any(), any(), any());
ControllerAccess controllerAccess = mock(ControllerAccess.class, NEGATIVE_ANSWER); ControllerAccess controllerAccess = mock(ControllerAccess.class, NEGATIVE_ANSWER);