only: proteus_f7

more reliable error approach
This commit is contained in:
rusefillc 2023-07-20 00:23:28 -04:00
parent ab7ddc7e13
commit dd3e273fa8
3 changed files with 22 additions and 4 deletions

View File

@ -19,7 +19,7 @@ import java.nio.ByteBuffer;
import static com.devexperts.logging.Logging.getLogging; import static com.devexperts.logging.Logging.getLogging;
public abstract class BaseConfigField { public abstract class BaseConfigField {
private static final Logging log = getLogging(BaseConfigField.class); protected static final Logging log = getLogging(BaseConfigField.class);
protected final JLabel status = new JLabel("P"); protected final JLabel status = new JLabel("P");
private final JPanel panel = new JPanel(new BorderLayout()); private final JPanel panel = new JPanel(new BorderLayout());

View File

@ -11,6 +11,7 @@ import com.rusefi.ui.UIContext;
import javax.swing.*; import javax.swing.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.rmi.UnexpectedException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -43,7 +44,11 @@ public class EnumConfigField extends BaseConfigField {
Pair<Integer, ?> p = FieldCommandResponse.parseResponse(message); Pair<Integer, ?> p = FieldCommandResponse.parseResponse(message);
if (p != null && p.first == field.getOffset()) { if (p != null && p.first == field.getOffset()) {
int ordinal = (Integer) p.second; int ordinal = (Integer) p.second;
setValue(ordinal); try {
setValue(ordinal);
} catch (UnexpectedEnumOridnalException e) {
System.out.println("ERROR " + e);
}
} }
} }
} }
@ -63,12 +68,14 @@ public class EnumConfigField extends BaseConfigField {
}); });
} }
private void setValue(int ordinal) { private void setValue(int ordinal) throws UnexpectedEnumOridnalException {
String item; String item;
if (ordinal >= options.length) { if (ordinal >= options.length) {
item = "unexpected_" + ordinal; item = "unexpected_" + ordinal;
view.addItem(item); view.addItem(item);
} else { } else {
if (ordinal >= options.length)
throw new UnexpectedEnumOridnalException(ordinal + " unexpected on " + field);
item = options[ordinal]; item = options[ordinal];
} }
@ -89,6 +96,10 @@ public class EnumConfigField extends BaseConfigField {
} else { } else {
ordinal = getByteBuffer(ci).getInt(); ordinal = getByteBuffer(ci).getInt();
} }
setValue(ordinal); try {
setValue(ordinal);
} catch (UnexpectedEnumOridnalException e) {
log.error("Error loading value " + e);
}
} }
} }

View File

@ -0,0 +1,7 @@
package com.rusefi.ui.config;
public class UnexpectedEnumOridnalException extends Throwable {
public UnexpectedEnumOridnalException(String s) {
super(s);
}
}