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;
import com.devexperts.logging.Logging;
import com.efiAnalytics.plugin.ecu.*;
import com.rusefi.core.ui.AutoupdateUtil;
import org.putgemin.VerticalFlowLayout;
@ -12,10 +13,14 @@ import java.util.Arrays;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import static com.devexperts.logging.Logging.getLogging;
public class KnockAnalyzerTab {
private static final Logging log = getLogging(KnockAnalyzerTab.class);
public static final String CYLINDERS_COUNT = "cylindersCount";
public static final String ENABLE_KNOCK_SPECTROGRAM = "enableKnockSpectrogram";
private enum CanvasType {
CT_ALL,
@ -39,13 +44,13 @@ public class KnockAnalyzerTab {
private int channel = 0;
private int cylinder = 0;
private float[] values = new float[64];
private final float[] values = new float[64];
private int cylindersCount = 0;
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();
public KnockAnalyzerTab(Supplier<ControllerAccess> controllerAccessSupplier) {
@ -63,7 +68,7 @@ public class KnockAnalyzerTab {
}
});
} catch (ControllerException ee) {
System.out.println(ee.getMessage());
log.error(ee.getMessage());
}
try {
@ -76,8 +81,8 @@ public class KnockAnalyzerTab {
magnituges.setFrequencyStep(frequencyStep);
}
});
} catch (ControllerException ee) {
System.out.println(ee.getMessage());
} catch (ControllerException e) {
log.error(e.getMessage());
}
try {
@ -90,8 +95,8 @@ public class KnockAnalyzerTab {
KnockAnalyzerTab.this.channel = (int) (value >>> 8) & 0xFF;
KnockAnalyzerTab.this.cylinder = (int) (value & 0xFF);
});
} catch (ControllerException ee) {
System.out.println(ee.getMessage());
} catch (ControllerException e) {
log.error(e.getMessage());
}
try {
@ -100,8 +105,8 @@ public class KnockAnalyzerTab {
double value = cylindersCountParameter.getScalarValue();
KnockAnalyzerTab.this.cylindersCount = (int) (value);
}
} catch (ControllerException ee) {
System.out.println(ee.getMessage());
} catch (ControllerException e) {
log.error(e.getMessage());
}
try {
@ -117,6 +122,7 @@ public class KnockAnalyzerTab {
checksum += i;
}
if (outputChannelNames.length!=0)
for (int i = 0; i < 16; ++i) {
try {
@ -154,12 +160,12 @@ public class KnockAnalyzerTab {
}
});
} catch (ControllerException ee) {
System.out.println(ee.getMessage());
log.error(ee.getMessage());
}
}
} catch (ControllerException e) {
log.error(e.getMessage());
}
buttonStartStop.addActionListener(e -> {
@ -327,11 +333,11 @@ public class KnockAnalyzerTab {
public boolean getEnabledEcu() {
try {
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();
return enabled.indexOf("true") > 0;
} catch (ControllerException ee) {
System.out.println(ee.getMessage());
log.error(ee.getMessage());
}
return false;
@ -342,7 +348,7 @@ public class KnockAnalyzerTab {
String ecuControllerName = this.controllerAccessSupplier.get().getEcuConfigurationNames()[0];
controllerAccessSupplier.get().getControllerParameterServer().updateParameter(ecuControllerName, "enableKnockSpectrogram", enabled ? 1.0 : 0.0);
} 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.servers.ControllerParameterServer;
import com.efiAnalytics.plugin.ecu.servers.OutputChannelServer;
import com.opensr5.ini.IniFileModel;
import com.opensr5.ini.IniFileModelImpl;
import com.rusefi.TsTuneReader;
import com.rusefi.core.ui.FrameHelper;
@ -27,13 +26,18 @@ import static org.mockito.Mockito.*;
public class PluginBodySandbox {
private static final String PROJECT_NAME = "dev";
public static final ControllerParameter result = new ControllerParameter() {
public static final ControllerParameter cylinderResult = new ControllerParameter() {
@Override
public double getScalarValue() {
return 2;
}
};
public static final ControllerParameter result2 = new ControllerParameter() {
@Override
public String getStringValue() {
return "true";
}
};
public static void main(String[] args) throws ControllerException {
String iniFile = TsTuneReader.getProjectModeFileName(PROJECT_NAME);
IniFileModelImpl model = IniFileModelImpl.readIniFile(iniFile);
@ -47,7 +51,8 @@ public class PluginBodySandbox {
ControllerParameterServer controllerParameterServer = mock(ControllerParameterServer.class, NEGATIVE_ANSWER);
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());
ControllerAccess controllerAccess = mock(ControllerAccess.class, NEGATIVE_ANSWER);