auto-sync
This commit is contained in:
parent
5486e53843
commit
2c2f710580
|
@ -38,15 +38,13 @@ public class BracerParser {
|
|||
/* list of available functions */
|
||||
private final String[] FUNCTIONS = {"abs", "acos", "arg", "asin", "atan",
|
||||
"conj", "cos", "cosh", "exp", "imag", "log", "neg", "pow", "real",
|
||||
"sin", "sinh", "sqrt", "tan", "tanh", "not"};
|
||||
"sin", "time_since_boot", "sqrt", "tan", "rpm", "not"};
|
||||
/* list of available operators */
|
||||
private final String OPERATORS = "+-*/&|!";
|
||||
private final String OPERATORS = "<>=+-*/&|!";
|
||||
/* separator of arguments */
|
||||
private final String SEPARATOR = ",";
|
||||
/* variable token */
|
||||
private final String VARIABLE = "var";
|
||||
/* settings for numbers formatting */
|
||||
private NumberFormat numberFormat = NumberFormat.getInstance(Locale.US);
|
||||
/* temporary stack that holds operators, functions and brackets */
|
||||
private Stack<String> stackOperations = new Stack<>();
|
||||
/* stack for holding expression converted to reversed polish notation */
|
||||
|
@ -57,32 +55,9 @@ public class BracerParser {
|
|||
/**
|
||||
* Class ctor for setting up the complex format of the parser
|
||||
*
|
||||
* @param precision Number of digits after the dot
|
||||
* @since 2.0
|
||||
*/
|
||||
public BracerParser(int precision) {
|
||||
setPrecision(precision);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the precision of the real and imaginary parts of numbers
|
||||
*
|
||||
* @param precision Number of digits after the dot
|
||||
* @since 2.0
|
||||
*/
|
||||
public void setPrecision(int precision) {
|
||||
numberFormat.setMinimumFractionDigits(precision);
|
||||
numberFormat.setMaximumFractionDigits(precision);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the precision of the real and imaginary parts of numbers
|
||||
*
|
||||
* @return Precision
|
||||
* @since 2.0
|
||||
*/
|
||||
public int getPrecision() {
|
||||
return numberFormat.getMinimumFractionDigits();
|
||||
public BracerParser() {
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package com.autsia.bracer.test;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
@ -37,18 +38,7 @@ public class BracerParserTest {
|
|||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
bracerParser = new BracerParser(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetPrecision() throws Exception {
|
||||
bracerParser.setPrecision(10);
|
||||
Assert.assertEquals(10, bracerParser.getPrecision());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPrecision() throws Exception {
|
||||
Assert.assertEquals(3, bracerParser.getPrecision());
|
||||
bracerParser = new BracerParser();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -85,6 +75,15 @@ public class BracerParserTest {
|
|||
Assert.assertEquals("1", bracerParser.evaluate());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRusEfi() throws ParseException {
|
||||
bracerParser.parse("(time_since_boot < 4) | (rpm > 0)");
|
||||
Collection<String> stackRPN = bracerParser.getStackRPN();
|
||||
|
||||
Assert.assertEquals("[|, rpm, >, 0, time_since_boot, <, 4]", stackRPN.toString());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBooleanNot2() throws Exception {
|
||||
bracerParser.parse("(((true | false) & not(false)) | (true | false))");
|
||||
|
|
|
@ -19,7 +19,7 @@ import javax.swing.*;
|
|||
* @see WavePanel
|
||||
*/
|
||||
public class Launcher extends FrameHelper {
|
||||
public static final int CONSOLE_VERSION = 20141002;
|
||||
public static final int CONSOLE_VERSION = 20141010;
|
||||
public static final boolean SHOW_STIMULATOR = true;
|
||||
private final String port;
|
||||
|
||||
|
@ -42,6 +42,8 @@ public class Launcher extends FrameHelper {
|
|||
tabbedPane.addTab("Digital Sniffer", WavePanel.getInstance().getPanel());
|
||||
tabbedPane.addTab("Analog Sniffer", new AnalogChartPanel());
|
||||
|
||||
tabbedPane.addTab("LE controls", new FlexibleControls().getPanel());
|
||||
|
||||
// tabbedPane.addTab("ADC", new AdcPanel(new BooleanInputsModel()).createAdcPanel());
|
||||
if (SHOW_STIMULATOR) {
|
||||
EcuStimulator stimulator = EcuStimulator.getInstance();
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package com.rusefi.ui;
|
||||
|
||||
import com.autsia.bracer.BracerParser;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.text.ParseException;
|
||||
|
||||
/**
|
||||
* (c) Andrey Belomutskiy
|
||||
* 10/10/14
|
||||
*/
|
||||
public class FlexibleControls {
|
||||
private final JPanel panel = new JPanel(new BorderLayout());
|
||||
|
||||
private final JTextField normalForm = new JTextField();
|
||||
|
||||
private final JTextField rpnForm = new JTextField();
|
||||
|
||||
public FlexibleControls() {
|
||||
|
||||
panel.add(normalForm, BorderLayout.NORTH);
|
||||
panel.add(rpnForm, BorderLayout.SOUTH);
|
||||
|
||||
normalForm.setText("(time_since_boot < 4) | (rpm > 0)");
|
||||
|
||||
process();
|
||||
|
||||
}
|
||||
|
||||
private void process() {
|
||||
BracerParser bp = new BracerParser();
|
||||
try {
|
||||
bp.parse(normalForm.getText());
|
||||
} catch (ParseException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
rpnForm.setText(bp.getStackRPN().toString());
|
||||
}
|
||||
|
||||
public JPanel getPanel() {
|
||||
return panel;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue