mirror of https://github.com/FOME-Tech/fome-fw.git
big crusty
This commit is contained in:
parent
c7c9f4ed86
commit
d624e4dc5f
|
@ -4,16 +4,13 @@ import com.devexperts.logging.Logging;
|
|||
import com.rusefi.NamedThreadFactory;
|
||||
import com.rusefi.io.LinkManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Andrey Belomutskiy, (c) 2013-2020
|
||||
|
|
|
@ -9,7 +9,6 @@ import com.rusefi.io.serial.BufferedSerialIoStream;
|
|||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static com.rusefi.binaryprotocol.IoHelper.checkResponseCode;
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.rusefi.binaryprotocol;
|
|||
import com.devexperts.logging.Logging;
|
||||
import com.opensr5.ConfigurationImage;
|
||||
import com.opensr5.io.DataListener;
|
||||
import com.rusefi.ConfigurationImageDiff;
|
||||
import com.rusefi.NamedThreadFactory;
|
||||
import com.rusefi.core.SignatureHelper;
|
||||
import com.rusefi.Timeouts;
|
||||
|
@ -19,9 +18,6 @@ import com.rusefi.core.FileUtil;
|
|||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
import static com.devexperts.logging.Logging.getLogging;
|
||||
|
|
|
@ -151,10 +151,6 @@ public class CommandQueue {
|
|||
write(command, timeout, InvocationConfirmationListener.VOID);
|
||||
}
|
||||
|
||||
public void write(String command, InvocationConfirmationListener listener) {
|
||||
write(command, DEFAULT_TIMEOUT, listener, true);
|
||||
}
|
||||
|
||||
public void write(String command, int timeoutMs, InvocationConfirmationListener listener) {
|
||||
write(command, timeoutMs, listener, true);
|
||||
}
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
package com.rusefi.io.commands;
|
||||
|
||||
import com.rusefi.io.IoStream;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface Command {
|
||||
byte getCommand();
|
||||
|
||||
void handle(IoStream stream) throws IOException;
|
||||
}
|
|
@ -11,7 +11,7 @@ import java.io.IOException;
|
|||
|
||||
import static com.rusefi.binaryprotocol.IoHelper.checkResponseCode;
|
||||
|
||||
public class HelloCommand implements Command {
|
||||
public class HelloCommand {
|
||||
private final String tsSignature;
|
||||
|
||||
public HelloCommand(String tsSignature) {
|
||||
|
@ -35,12 +35,10 @@ public class HelloCommand implements Command {
|
|||
return new String(response, 1, response.length - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getCommand() {
|
||||
return Fields.TS_HELLO_COMMAND;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(IoStream stream) throws IOException {
|
||||
stream.sendPacket((BinaryProtocolServer.TS_OK + tsSignature).getBytes());
|
||||
}
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
package com.rusefi.io.serial;
|
||||
|
||||
import com.rusefi.Timeouts;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class RateCounter {
|
||||
private final static int MAGIC_DURATION = Timeouts.SECOND;
|
||||
|
||||
private final LinkedList<Pair> timeStamps = new LinkedList<>();
|
||||
|
||||
/**
|
||||
* @return number of events in the last second
|
||||
*/
|
||||
public int getCurrentRate() {
|
||||
return getCurrentRate(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public synchronized int getCurrentRate(long now) {
|
||||
long threshold = now - MAGIC_DURATION;
|
||||
|
||||
while (!timeStamps.isEmpty() && timeStamps.peekFirst().timestamp < threshold)
|
||||
timeStamps.removeFirst();
|
||||
|
||||
int result = 0;
|
||||
for (Pair pair : timeStamps)
|
||||
result += pair.value;
|
||||
return result;
|
||||
}
|
||||
|
||||
public synchronized int getSizeForUnitTest() {
|
||||
return timeStamps.size();
|
||||
}
|
||||
|
||||
public void add() {
|
||||
add(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public synchronized void add(long timestamp) {
|
||||
timeStamps.add(new Pair(timestamp, 1));
|
||||
}
|
||||
|
||||
private static class Pair {
|
||||
private final long timestamp;
|
||||
private final int value;
|
||||
|
||||
public Pair(long timestamp, int value) {
|
||||
this.timestamp = timestamp;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -35,13 +35,6 @@ public class SerialIoStream extends AbstractIoStream {
|
|||
this.port = port;
|
||||
}
|
||||
|
||||
public static IoStream openPort(String port) {
|
||||
log.info("[SerialIoStream] openPort " + port);
|
||||
SerialPort serialPort = openSerial(port);
|
||||
// FileLog.LOGGER.info("[SerialIoStreamJSerialComm] opened " + port);
|
||||
return new SerialIoStream(serialPort, port);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected static SerialPort openSerial(String port) {
|
||||
SerialPort serialPort = SerialPort.getCommPort(port);
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
package com.rusefi.io.serial;
|
||||
|
||||
import com.rusefi.Timeouts;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class RateCounterTest {
|
||||
@Test
|
||||
public void testRateCalculation() {
|
||||
|
||||
RateCounter rateCounter = new RateCounter();
|
||||
|
||||
assertEquals(0, rateCounter.getCurrentRate());
|
||||
|
||||
rateCounter.add(/*timestamp*/1);
|
||||
rateCounter.add(1);
|
||||
rateCounter.add(1);
|
||||
rateCounter.add(1);
|
||||
|
||||
// cute size effect: FUTURE timestamps are also counted :)
|
||||
assertEquals(4, rateCounter.getCurrentRate(0));
|
||||
assertEquals(4, rateCounter.getSizeForUnitTest());
|
||||
|
||||
|
||||
assertEquals(0, rateCounter.getCurrentRate(2 * Timeouts.SECOND));
|
||||
// assert purge of oldest records
|
||||
assertEquals(0, rateCounter.getSizeForUnitTest());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
package com.rusefi;
|
||||
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
public class MockitoTestHelper {
|
||||
public static final Answer<?> NEGATIVE_ANSWER = invocation -> {
|
||||
throw new UnsupportedOperationException("Not mocked " + invocation);
|
||||
};
|
||||
}
|
|
@ -28,7 +28,7 @@ import static com.rusefi.config.generated.Fields.TS_FILE_VERSION_OFFSET;
|
|||
import static com.rusefi.io.tcp.TcpConnector.LOCALHOST;
|
||||
import org.junit.Assert;
|
||||
|
||||
public class TestHelper extends MockitoTestHelper {
|
||||
public class TestHelper {
|
||||
private static final Logging log = getLogging(TestHelper.class);
|
||||
public static final String TEST_SIGNATURE_1 = "rusEFI master.2020.07.06.frankenso_na6.2468827536";
|
||||
public static final String TEST_SIGNATURE_2 = "rusEFI master.2020.07.11.proteus_f4.1986715563";
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.rusefi;
|
||||
|
||||
import com.devexperts.logging.Logging;
|
||||
import com.rusefi.autodetect.PortDetector;
|
||||
import com.rusefi.core.MessagesCentral;
|
||||
import com.rusefi.io.CommandQueue;
|
||||
import com.rusefi.io.LinkManager;
|
||||
|
|
|
@ -1,18 +1,14 @@
|
|||
package com.rusefi.ui;
|
||||
|
||||
import com.devexperts.logging.Logging;
|
||||
import com.rusefi.AverageAnglesUtil;
|
||||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.core.MessagesCentral;
|
||||
import com.rusefi.io.CommandQueue;
|
||||
import com.rusefi.ui.util.UiUtils;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
|
|
@ -66,12 +66,11 @@ public class RpmLabel {
|
|||
return content;
|
||||
}
|
||||
|
||||
public RpmLabel setSize(int size) {
|
||||
public void setSize(int size) {
|
||||
Font f = rpmCaption.getFont();
|
||||
int fontSize = size * f.getSize();
|
||||
Font font = new Font(f.getName(), f.getStyle(), fontSize);
|
||||
setFont(font);
|
||||
return this;
|
||||
}
|
||||
|
||||
private void setFont(Font font) {
|
||||
|
|
|
@ -3,13 +3,10 @@ package com.rusefi.ui.console;
|
|||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.core.MessagesCentral;
|
||||
import com.rusefi.io.ConnectionStatusLogic;
|
||||
import com.rusefi.ui.UIContext;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
import static com.rusefi.core.preferences.storage.PersistentConfiguration.getConfig;
|
||||
|
||||
public class TabbedPanel {
|
||||
// todo: the logic around 'criticalError' could be implemented nicer
|
||||
private String criticalError;
|
||||
|
|
|
@ -15,13 +15,9 @@ import java.awt.event.MouseEvent;
|
|||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.net.URLStreamHandlerFactory;
|
||||
|
||||
import static com.rusefi.ui.util.LocalizedMessages.CLEAR;
|
||||
import static com.rusefi.ui.util.LocalizedMessages.PAUSE;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.rusefi.ui.widgets;
|
||||
|
||||
import com.rusefi.NamedThreadFactory;
|
||||
import com.rusefi.io.CommandQueue;
|
||||
import com.rusefi.ui.RecentCommands;
|
||||
import com.rusefi.ui.UIContext;
|
||||
|
@ -16,7 +15,6 @@ import java.awt.event.ActionEvent;
|
|||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue