FSIO RPN progress

This commit is contained in:
rusefi 2020-04-18 21:01:23 -04:00
parent acaf01ecf8
commit 5af28a08d6
10 changed files with 97 additions and 15 deletions

View File

@ -653,6 +653,10 @@
#define FSIO_COMMAND_COUNT 16
#define FSIO_CURVE_16 16
#define FSIO_CURVE_8 8
#define FSIO_METHOD_FSIO_ANALOG_INPUT "fsio_analog_input"
#define FSIO_METHOD_FSIO_DIGITAL_INPUT "fsio_digital_input"
#define FSIO_METHOD_FSIO_SETTING "fsio_setting"
#define FSIO_METHOD_FSIO_TABLE "fsio_table"
#define fsio_setting10_offset 900
#define fsio_setting10_offset_hex 384
#define fsio_setting11_offset 904

View File

@ -59,10 +59,10 @@ static LENameOrdinalPair leAcToggle(LE_METHOD_AC_TOGGLE, "ac_on_switch");
// @returns float number of seconds since last A/C toggle
static LENameOrdinalPair leTimeSinceAcToggle(LE_METHOD_TIME_SINCE_AC_TOGGLE, "time_since_ac_on_switch");
static LENameOrdinalPair leTimeSinceBoot(LE_METHOD_TIME_SINCE_BOOT, "time_since_boot");
static LENameOrdinalPair leFsioSetting(LE_METHOD_FSIO_SETTING, "fsio_setting");
static LENameOrdinalPair leFsioTable(LE_METHOD_FSIO_TABLE, "fsio_table");
static LENameOrdinalPair leFsioAnalogInput(LE_METHOD_FSIO_ANALOG_INPUT, "fsio_analog_input");
static LENameOrdinalPair leFsioDigitalInput(LE_METHOD_FSIO_DIGITAL_INPUT, "fsio_digital_input");
static LENameOrdinalPair leFsioSetting(LE_METHOD_FSIO_SETTING, FSIO_METHOD_FSIO_SETTING);
static LENameOrdinalPair leFsioTable(LE_METHOD_FSIO_TABLE, FSIO_METHOD_FSIO_TABLE);
static LENameOrdinalPair leFsioAnalogInput(LE_METHOD_FSIO_ANALOG_INPUT, FSIO_METHOD_FSIO_ANALOG_INPUT);
static LENameOrdinalPair leFsioDigitalInput(LE_METHOD_FSIO_DIGITAL_INPUT, FSIO_METHOD_FSIO_DIGITAL_INPUT);
static LENameOrdinalPair leKnock(LE_METHOD_KNOCK, "knock");
static LENameOrdinalPair leIntakeVVT(LE_METHOD_INTAKE_VVT, "ivvt");
static LENameOrdinalPair leExhaustVVT(LE_METHOD_EXHAUST_VVT, "evvt");

View File

@ -653,6 +653,10 @@
#define FSIO_COMMAND_COUNT 16
#define FSIO_CURVE_16 16
#define FSIO_CURVE_8 8
#define FSIO_METHOD_FSIO_ANALOG_INPUT "fsio_analog_input"
#define FSIO_METHOD_FSIO_DIGITAL_INPUT "fsio_digital_input"
#define FSIO_METHOD_FSIO_SETTING "fsio_setting"
#define FSIO_METHOD_FSIO_TABLE "fsio_table"
#define fsio_setting10_offset 900
#define fsio_setting10_offset_hex 384
#define fsio_setting11_offset 904

View File

@ -164,6 +164,11 @@ struct_no_prefix engine_configuration_s
#define FSIO_CURVE_8 8
#define FSIO_CURVE_16 16
#define FSIO_METHOD_FSIO_SETTING "fsio_setting"
#define FSIO_METHOD_FSIO_TABLE "fsio_table"
#define FSIO_METHOD_FSIO_ANALOG_INPUT "fsio_analog_input"
#define FSIO_METHOD_FSIO_DIGITAL_INPUT "fsio_digital_input"
#define TPS_TPS_ACCEL_TABLE 8
#define MAP_ACCEL_TAPER 8

View File

@ -6,6 +6,8 @@ import java.text.NumberFormat;
import java.text.ParsePosition;
import java.util.*;
import static com.rusefi.config.generated.Fields.*;
/** An evaluator that is able to evaluate arithmetic expressions on real numbers.
* <br>Built-in operators:<ul>
* <li>+: Addition</li>
@ -112,10 +114,11 @@ public class DoubleEvaluator extends AbstractEvaluator<Double> {
/** Returns the decimal logarithm of a number */
public static final Function LOG = new Function("log", 1);
public static final Function fsio_setting = new Function("fsio_setting", 1);
public static final Function fsio_input = new Function("fsio_input", 1);
public static final Function fsio_setting = new Function(FSIO_METHOD_FSIO_SETTING, 1);
public static final Function fsio_analog_input = new Function(FSIO_METHOD_FSIO_ANALOG_INPUT, 1);
public static final Function fsio_digital_input = new Function(FSIO_METHOD_FSIO_DIGITAL_INPUT, 1);
public static final Function if_function = new Function("if", 3);
public static final Function table_function = new Function("fsio_table", 3);
public static final Function table_function = new Function(FSIO_METHOD_FSIO_TABLE, 3);
/** Returns a pseudo random number */
@ -158,7 +161,11 @@ public class DoubleEvaluator extends AbstractEvaluator<Double> {
/** The standard whole set of predefined operators */
private static final Operator[] OPERATORS = new Operator[]{NEGATE, NOT, NOT2, MORE, MORE_EQ, AND, AND2, OR, OR2, LESS, LESS_EQ, MINUS, PLUS, MULTIPLY, DIVIDE, EXPONENT, MODULO};
private static final List<Function> MISC_FUNCTIONS = Arrays.asList(if_function, fsio_setting, fsio_input, table_function);
private static final List<Function> MISC_FUNCTIONS = Arrays.asList(if_function,
fsio_setting,
fsio_analog_input,
fsio_digital_input,
table_function);
/** The whole set of predefined functions */
private static final List<Function> FUNCTIONS = new ArrayList<>(

View File

@ -1,11 +1,20 @@
package com.rusefi;
import com.fathzer.soft.javaluator.DoubleEvaluator;
import com.fathzer.soft.javaluator.Function;
import com.fathzer.soft.javaluator.Operator;
import java.util.Stack;
public class InfixConverter {
public static String getHumanInfixFormOrError(String rpn) {
try {
return getHumanInfixForm(rpn);
} catch (Throwable e) {
return "Failing to parse. Maybe invalid function was used? Valid functions include " + getReadableListOfFunctions();
}
}
public static String getHumanInfixForm(String rpn) {
String tokens[] = rpn.split(" ");
Stack<String> stack = new Stack<>();
@ -49,4 +58,16 @@ public class InfixConverter {
private static boolean takesTwoParameters(String token) {
return Operator._2_OPERATORS.contains(token);
}
public static String getReadableListOfFunctions() {
StringBuilder result = new StringBuilder();
DoubleEvaluator evaluator = new DoubleEvaluator();
for (Function function : evaluator.getFunctions()) {
if (result.length() > 0) {
result.append(", ");
}
result.append(function.getName());
}
return result.toString();
}
}

View File

@ -1,6 +1,6 @@
package com.rusefi.config.generated;
// this file was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.bat integration\rusefi_config.txt Sat Apr 18 16:38:06 EDT 2020
// this file was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.bat integration\rusefi_config.txt Sat Apr 18 20:42:28 EDT 2020
// by class com.rusefi.output.FileJavaFieldsConsumer
import com.rusefi.config.*;
@ -423,6 +423,10 @@ public class Fields {
public static final int FSIO_COMMAND_COUNT = 16;
public static final int FSIO_CURVE_16 = 16;
public static final int FSIO_CURVE_8 = 8;
public static final String FSIO_METHOD_FSIO_ANALOG_INPUT = "fsio_analog_input";
public static final String FSIO_METHOD_FSIO_DIGITAL_INPUT = "fsio_digital_input";
public static final String FSIO_METHOD_FSIO_SETTING = "fsio_setting";
public static final String FSIO_METHOD_FSIO_TABLE = "fsio_table";
public static final int fsio_setting10_offset = 900;
public static final int fsio_setting10_offset_hex = 384;
public static final int fsio_setting11_offset = 904;

View File

@ -3,12 +3,12 @@ package com.rusefi.test;
import com.fathzer.soft.javaluator.DoubleEvaluator;
import com.fathzer.soft.javaluator.Operator;
import com.rusefi.InfixConverter;
import com.rusefi.config.generated.Fields;
import org.junit.Test;
import java.text.ParseException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.Assert.*;
/**
* @see DoubleEvaluator
@ -70,6 +70,20 @@ public class ReversePolishNotationParserTest {
assertEquals(expectedRPN, evaluator.getPosftfixExpression());
}
@Test
public void testRpnToHuman() {
assertEquals("if((fsio_analog_input(0) > 20), 0, 10)", InfixConverter.getHumanInfixForm("0 fsio_analog_input 20 > 0 10 if"));
assertTrue(InfixConverter.getHumanInfixFormOrError("0 fsoi_input 20 > 0 10 if").contains(Fields.FSIO_METHOD_FSIO_TABLE));
}
@Test
public void testListOfFunctions() {
String readableListOfFunctions = InfixConverter.getReadableListOfFunctions();
assertTrue(readableListOfFunctions.contains(Fields.FSIO_METHOD_FSIO_DIGITAL_INPUT));
assertTrue(readableListOfFunctions.contains(Fields.FSIO_METHOD_FSIO_TABLE));
}
@Test
public void testUnaryMinus() {
/**

View File

@ -49,7 +49,7 @@ import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
* @see EngineSnifferPanel
*/
public class Launcher {
public static final int CONSOLE_VERSION = 20200411;
public static final int CONSOLE_VERSION = 20200418;
public static final String INI_FILE_PATH = System.getProperty("ini_file_path", "..");
public static final String INPUT_FILES_PATH = System.getProperty("input_files_path", "..");
public static final String TOOLS_PATH = System.getProperty("tools_path", ".");

View File

@ -2,6 +2,8 @@ package com.rusefi.ui.widgets;
import com.fathzer.soft.javaluator.DoubleEvaluator;
import com.rusefi.FileLog;
import com.rusefi.InfixConverter;
import com.rusefi.core.MessagesCentral;
import com.rusefi.io.CommandQueue;
import com.rusefi.ui.RecentCommands;
import com.rusefi.ui.storage.Node;
@ -24,6 +26,7 @@ import java.util.concurrent.atomic.AtomicInteger;
*/
public class AnyCommand {
public static final String KEY = "last_value";
private static final String DECODE_RPN = "decode_rpn";
private final JTextComponent text;
private JPanel content = new JPanel(new FlowLayout(FlowLayout.LEFT));
@ -107,6 +110,12 @@ public class AnyCommand {
if (!isValidInput(rawCommand))
return;
String cmd = prepareCommand(rawCommand);
if (cmd == null) {
/**
* {@link #DECODE_RPN} for example does not send out anything
*/
return;
}
if (listener != null)
listener.onSend();
int timeout = CommandQueue.getTimeout(cmd);
@ -117,9 +126,12 @@ public class AnyCommand {
public static String prepareCommand(String rawCommand) {
try {
if (rawCommand.startsWith("eval ")) {
if (rawCommand.startsWith("eval" + " ")) {
return prepareEvalCommand(rawCommand);
} else if (rawCommand.toLowerCase().startsWith("set_fsio_expression ")) {
} else if (rawCommand.toLowerCase().startsWith(DECODE_RPN + " ")) {
handleDecodeRpn(rawCommand);
return null;
} else if (rawCommand.toLowerCase().startsWith("set_fsio_expression" + " ")) {
return prepareSetFsioCommand(rawCommand);
} else {
return rawCommand;
@ -137,12 +149,23 @@ public class AnyCommand {
return "set_rpn_expression " + parts[1] + " " + quote(infix2postfix(unquote(parts[2])));
}
private static void handleDecodeRpn(String rawCommand) {
String[] parts = rawCommand.split(" ", 2);
if (parts.length != 2) {
MessagesCentral.getInstance().postMessage(AnyCommand.class, "Failed to parse, one argument expected");
return;
}
String argument = unquote(parts[1]);
String humanForm = InfixConverter.getHumanInfixFormOrError(argument);
MessagesCentral.getInstance().postMessage(AnyCommand.class, "Human form is \"" + humanForm + "\"");
}
private static String prepareEvalCommand(String rawCommand) {
String[] parts = rawCommand.split(" ", 2);
if (parts.length != 2)
return rawCommand; // let's ignore invalid command
return "rpn_eval " + quote(infix2postfix(unquote(parts[1])));
return "rpn_eval" + " " + quote(infix2postfix(unquote(parts[1])));
}
private static String quote(String s) {