auto-sync

This commit is contained in:
rusEfi 2014-11-06 12:04:30 -06:00
parent 237703a49d
commit 890c2aa836
14 changed files with 84 additions and 33 deletions

View File

@ -134,12 +134,12 @@ void printSensors(Engine *engine) {
reportSensorF("afr", getAfr(), 2);
reportSensorF("vref", getVRef(), 2);
reportSensorF("vbatt", getVBatt(), 2);
reportSensorF("vbatt", getVBatt(engineConfiguration), 2);
reportSensorF("TRG_0_DUTY", getTriggerDutyCycle(0), 2);
reportSensorF("TRG_1_DUTY", getTriggerDutyCycle(1), 2);
reportSensorF(getCaption(LP_THROTTLE), getTPS(engine->engineConfiguration), 2);
reportSensorF(getCaption(LP_THROTTLE), getTPS(engineConfiguration), 2);
if (engineConfiguration->hasCltSensor) {
reportSensorF(getCaption(LP_ECT), getCoolantTemperature(engine), 2);
@ -173,7 +173,7 @@ void printState(Engine *engine, int currentCkpEventCounter) {
debugFloat(&logger, "fuel_base", baseFuel, 2);
// debugFloat(&logger, "fuel_iat", getIatCorrection(getIntakeAirTemperature()), 2);
// debugFloat(&logger, "fuel_clt", getCltCorrection(getCoolantTemperature()), 2);
debugFloat(&logger, "fuel_lag", getInjectorLag(engineConfiguration, getVBatt()), 2);
debugFloat(&logger, "fuel_lag", getInjectorLag(engineConfiguration, getVBatt(engineConfiguration)), 2);
debugFloat(&logger, "fuel", getFuelMs(rpm, engine), 2);
debugFloat(&logger, "timing", getAdvance(rpm, engineLoad), 2);
@ -319,7 +319,7 @@ static void showFuelInfo2(float rpm, float engineLoad, Engine *engine) {
if (engine->rpmCalculator->isRunning()) {
float iatCorrection = getIatCorrection(engineConfiguration, getIntakeAirTemperature(engine));
float cltCorrection = getCltCorrection(engineConfiguration, getCoolantTemperature(engine));
float injectorLag = getInjectorLag(engineConfiguration, getVBatt());
float injectorLag = getInjectorLag(engineConfiguration, getVBatt(engineConfiguration));
scheduleMsg(&logger2, "rpm=%f engineLoad=%f", rpm, engineLoad);
scheduleMsg(&logger2, "baseFuel=%f", baseFuelMs);
@ -428,7 +428,7 @@ void updateTunerStudioState(Engine *engine, TunerStudioOutputChannels *tsOutputC
tsOutputChannels->throttle_positon = tps;
tsOutputChannels->mass_air_flow = getMaf();
tsOutputChannels->air_fuel_ratio = getAfr();
tsOutputChannels->v_batt = getVBatt();
tsOutputChannels->v_batt = getVBatt(engineConfiguration);
tsOutputChannels->tsConfigVersion = TS_FILE_VERSION;
tsOutputChannels->tpsADC = getTPS10bitAdc();
tsOutputChannels->atmospherePressure = getBaroPressure();

View File

@ -81,7 +81,7 @@ float getFuelMs(int rpm, Engine *engine) {
float fuelPerCycle = getRunningFuel(baseFuel, engine, rpm);
theoreticalInjectionLength = fuelPerCycle / getNumberOfInjections(engineConfiguration, engine->engineConfiguration->injectionMode);
}
float injectorLag = getInjectorLag(engineConfiguration, getVBatt());
float injectorLag = getInjectorLag(engineConfiguration, getVBatt(engineConfiguration));
return theoreticalInjectionLength + injectorLag;
}

View File

@ -19,6 +19,7 @@ static LENameOrdinalPair leMoreEquals(LE_OPERATOR_MORE_OR_EQUAL, ">=");
static LENameOrdinalPair leRpm(LE_METHOD_RPM, "rpm");
static LENameOrdinalPair leTps(LE_METHOD_TPS, "tps");
static LENameOrdinalPair leMaf(LE_METHOD_MAF, "maf");
static LENameOrdinalPair leVBatt(LE_METHOD_VBATT, "vbatt");
static LENameOrdinalPair leFan(LE_METHOD_FAN, "fan");
static LENameOrdinalPair leCoolant(LE_METHOD_COOLANT, "coolant");
static LENameOrdinalPair leFanOnSetting(LE_METHOD_FAN_ON_SETTING, "fan_on_setting");
@ -39,6 +40,12 @@ float getLEValue(Engine *engine, le_action_e action) {
return engine->rpmCalculator->rpm();
case LE_METHOD_TIME_SINCE_BOOT:
return getTimeNowSeconds();
case LE_METHOD_FAN_OFF_SETTING:
return engine->engineConfiguration->fanOffTemperature;
case LE_METHOD_FAN_ON_SETTING:
return engine->engineConfiguration->fanOnTemperature;
case LE_METHOD_VBATT:
return getVBatt(engine->engineConfiguration);
default:
firmwareError("No value for %d", action);
return NAN;

View File

@ -11,9 +11,19 @@
#include "engine.h"
#include "logic_expression.h"
/**
* In human language that's
* (time_since_boot < 4) OR (rpm > 0)
*/
// todo: the delay should probably be configurable?
#define FUEL_PUMP_LOGIC "time_since_boot 4 < rpm 0 > OR"
/**
* In human language that's
* (fan and (coolant > fan_off_setting)) OR (coolant > fan_on_setting)
*/
#define FAN_CONTROL_LOGIC "todo"
float getLEValue(Engine *engine, le_action_e action);
#endif /* LE_FUNCTIONS_H_ */

View File

@ -33,6 +33,7 @@ typedef enum {
LE_METHOD_TPS = 106,
LE_METHOD_MAF = 107,
LE_METHOD_INTAKE_AIR = 108,
LE_METHOD_VBATT = 109,
Force_4b_le_action = ENUM_SIZE_HACK,

View File

@ -312,7 +312,7 @@ static void printAnalogInfo(void) {
if (engineConfiguration->hasBaroSensor) {
printAnalogChannelInfo("BARO", engineConfiguration->baroSensor.hwChannel);
}
printAnalogChannelInfoExt("Vbatt", engineConfiguration->vbattAdcChannel, getVBatt());
printAnalogChannelInfoExt("Vbatt", engineConfiguration->vbattAdcChannel, getVBatt(engineConfiguration));
}
static THD_WORKING_AREA(csThreadStack, UTILITY_THREAD_STACK_SIZE); // declare thread stack

View File

@ -33,7 +33,7 @@ char * appendStr(char *ptr, const char *suffix) {
static char * prepareVBattMapLine(engine_configuration_s *engineConfiguration, char *buffer) {
char *ptr = buffer;
*ptr++ = 'V';
ptr = ftoa(ptr, getVBatt(), 10.0f);
ptr = ftoa(ptr, getVBatt(engineConfiguration), 10.0f);
ptr = appendStr(ptr, " M");
ptr = ftoa(ptr, getRawMap(), 10.0f);

View File

@ -20,6 +20,6 @@ float getVRef(void) {
return getVoltageDivided(ADC_CHANNEL_VREF);
}
float getVBatt(void) {
float getVBatt(engine_configuration_s *engineConfiguration) {
return getVoltage(engineConfiguration->vbattAdcChannel) * engineConfiguration->vbattDividerCoeff;
}

View File

@ -11,6 +11,7 @@
#define VOLTAGE_H_
#include "main.h"
#include "engine_configuration.h"
#ifdef __cplusplus
extern "C"
@ -18,7 +19,7 @@ extern "C"
#endif /* __cplusplus */
float getVRef(void);
float getVBatt(void);
float getVBatt(engine_configuration_s *engineConfiguration);
#ifdef __cplusplus
}

View File

@ -119,8 +119,12 @@ void printConfiguration(engine_configuration_s *engineConfiguration, engine_conf
boolToString(engineConfiguration->isManualSpinningMode),
boolToString(engineConfiguration->isCylinderCleanupEnabled));
scheduleMsg(&logger, "crankingChargeAngle=%f", engineConfiguration->crankingChargeAngle);
scheduleMsg(&logger, "crankingTimingAngle=%f", engineConfiguration->crankingTimingAngle);
if (engineConfiguration->useConstantDwellDuringCranking) {
scheduleMsg(&logger, "ignitionDwellForCrankingMs=%f", engineConfiguration->ignitionDwellForCrankingMs);
} else {
scheduleMsg(&logger, "crankingChargeAngle=%f", engineConfiguration->crankingChargeAngle);
scheduleMsg(&logger, "crankingTimingAngle=%f", engineConfiguration->crankingTimingAngle);
}
scheduleMsg(&logger, "globalTriggerAngleOffset=%f", engineConfiguration->globalTriggerAngleOffset);
// scheduleMsg(&logger, "analogChartMode: %d", engineConfiguration->analogChartMode);
@ -131,8 +135,7 @@ void printConfiguration(engine_configuration_s *engineConfiguration, engine_conf
scheduleMsg(&logger, "idlePin: mode %s @ %s freq=%d", getPin_output_mode_e(boardConfiguration->idleValvePinMode),
hwPortname(boardConfiguration->idleValvePin), boardConfiguration->idleSolenoidFrequency);
scheduleMsg(&logger, "malfunctionIndicatorn: %s mode=%s",
hwPortname(boardConfiguration->malfunctionIndicatorPin),
scheduleMsg(&logger, "malfunctionIndicatorn: %s mode=%s", hwPortname(boardConfiguration->malfunctionIndicatorPin),
pinModeToString(boardConfiguration->malfunctionIndicatorPinMode));
scheduleMsg(&logger, "fuelPumpPin: mode %s @ %s", getPin_output_mode_e(boardConfiguration->fuelPumpPinMode),
@ -306,7 +309,8 @@ static void printTPSInfo(void) {
scheduleMsg(&logger, "tps min %d/max %d v=%f @%s%d", engineConfiguration->tpsMin, engineConfiguration->tpsMax,
getTPSVoltage(), portname(port), pin);
#endif
scheduleMsg(&logger, "current 10bit=%d value=%f rate=%f", getTPS10bitAdc(), getTPS(engineConfiguration), getTpsRateOfChange());
scheduleMsg(&logger, "current 10bit=%d value=%f rate=%f", getTPS10bitAdc(), getTPS(engineConfiguration),
getTpsRateOfChange());
}
static void printTemperatureInfo(void) {

View File

@ -20,10 +20,7 @@
package com.autsia.bracer;
import java.text.ParseException;
import java.util.Collection;
import java.util.Collections;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.*;
/**
* Class for parsing and evaluating math expressions
@ -186,12 +183,17 @@ public class BracerParser {
case "/":
stackAnswer.push(Double.toString(b / (a)));
break;
case ">":
stackAnswer.push(Integer.toString(b > a ? 1 : 0));
break;
case "|":
stackAnswer.push(String.valueOf(aBoolean || bBoolean ? "1" : "0"));
break;
case "&":
stackAnswer.push(String.valueOf(aBoolean && bBoolean ? "1" : "0"));
break;
default:
throw new IllegalStateException("Do not know " + token);
}
} else if (isFunction(token)) {
Double a = Double.valueOf(stackAnswer.pop());
@ -357,4 +359,15 @@ public class BracerParser {
}
return 2;
}
public String getRusEfi() {
List<String> list = new ArrayList<>(getStackRPN());
ListIterator<String> li = list.listIterator(list.size());
List<String> reverse = new ArrayList<>();
while (li.hasPrevious()) {
reverse.add(li.previous());
}
String result = reverse.toString();
return result.substring(1, result.length() - 1);
}
}

View File

@ -25,6 +25,8 @@ import org.junit.Test;
import com.autsia.bracer.BracerParser;
import static org.junit.Assert.assertEquals;
/**
* Test class.
* User: Dmytro
@ -43,55 +45,69 @@ public class BracerParserTest {
@Test
public void testEvaluateNoVar() throws Exception {
bracerParser.parse(INPUT_NOVAR);
Assert.assertEquals("-0.6570194619480038", bracerParser.evaluate());
assertEquals("-0.6570194619480038", bracerParser.evaluate());
}
@Test
public void testSimpleBoolean() throws Exception {
bracerParser.parse("true or false");
Assert.assertEquals("1", bracerParser.evaluate());
assertEquals("1", bracerParser.evaluate());
assertEquals("1, 0, |", bracerParser.getRusEfi());
bracerParser.parse("true > false");
assertEquals("1", bracerParser.evaluate());
assertEquals("1, 0, >", bracerParser.getRusEfi());
bracerParser.parse("(true > false)");
assertEquals("1", bracerParser.evaluate());
assertEquals("1, 0, >", bracerParser.getRusEfi());
bracerParser.parse("(rpm > false)");
// todo: that's weird
assertEquals("0, >, rpm", bracerParser.getRusEfi());
}
@Test
public void testBoolean() throws Exception {
bracerParser.parse("( ( true and ( false or ( true and ( ( true ) or ( false ) ) ) ) ) and ( ( false ) ) )");
Assert.assertEquals("0", bracerParser.evaluate());
assertEquals("0", bracerParser.evaluate());
Collection<String> stackRPN = bracerParser.getStackRPN();
Assert.assertEquals("[&, 0, &, |, &, |, 0, 1, 1, 0, 1]", stackRPN.toString());
assertEquals("[&, 0, &, |, &, |, 0, 1, 1, 0, 1]", stackRPN.toString());
}
@Test
public void testBooleanNot1() throws Exception {
bracerParser.parse("not( ( true and ( false or ( true and ( not( true ) or ( false ) ) ) ) ) and ( ( false ) ) )");
Assert.assertEquals("1", bracerParser.evaluate());
assertEquals("1", bracerParser.evaluate());
}
@Test
public void testRusEfi() throws ParseException {
bracerParser.parse("(time_since_boot < 4) | (rpm > 0)");
assertEquals("4, <, time_since_boot, 0, >, rpm, |", bracerParser.getRusEfi());
Assert.assertEquals("[|, rpm, >, 0, time_since_boot, <, 4]", bracerParser.getStackRPN().toString());
bracerParser.parse("(fan and (coolant > fan_off_setting)) OR (coolant > fan_on_setting)");
assertEquals("fan_off_setting, >, coolant, &, fan, fan_on_setting, >, coolant, OR", bracerParser.getRusEfi());
bracerParser.parse("(time_since_boot <= 4) | (rpm > 0)");
Assert.assertEquals("[|, rpm, >, 0, time_since_boot, <=, 4]", bracerParser.getStackRPN().toString());
assertEquals("4, <=, time_since_boot, 0, >, rpm, |", bracerParser.getRusEfi());
bracerParser.parse("(time_since_boot <= 4) | (rpm > 0)");
Assert.assertEquals("[|, rpm, >, 0, time_since_boot, <=, 4]", bracerParser.getStackRPN().toString());
assertEquals("4, <=, time_since_boot, 0, >, rpm, |", bracerParser.getRusEfi());
bracerParser.parse("(time_since_boot <= 4) OR (rpm > 0)");
Assert.assertEquals("[OR, rpm, >, 0, time_since_boot, <=, 4]", bracerParser.getStackRPN().toString());
assertEquals("4, <=, time_since_boot, 0, >, rpm, OR", bracerParser.getRusEfi());
}
@Test
public void testBooleanNot2() throws Exception {
bracerParser.parse("(((true | false) & not(false)) | (true | false))");
Assert.assertEquals("1", bracerParser.evaluate());
assertEquals("1", bracerParser.evaluate());
Collection<String> stackRPN = bracerParser.getStackRPN();
Assert.assertEquals("[|, |, 0, 1, &, not, 0, |, 0, 1]", stackRPN.toString());
assertEquals("[|, |, 0, 1, &, not, 0, |, 0, 1]", stackRPN.toString());
}
}

View File

@ -46,7 +46,6 @@ void assertTrueM(const char *msg, float actual);
void assertFalse(float actual);
void assertFalseM(const char *msg, float actual);
float getVBatt(void);
float getMaf(void);
#define systicks2ms(x) (0)

View File

@ -78,7 +78,7 @@ void testFuelMap(void) {
assertEqualsM("IAT", 2, iatCorrection);
float cltCorrection = getCltCorrection(engineConfiguration, getCoolantTemperature(&eth.engine));
assertEqualsM("CLT", 1, cltCorrection);
float injectorLag = getInjectorLag(engineConfiguration, getVBatt());
float injectorLag = getInjectorLag(engineConfiguration, getVBatt(engineConfiguration));
assertEquals(0, injectorLag);
testMafValue = 5;