This commit is contained in:
Andrey B 2014-04-30 11:21:31 -05:00
parent 080bf548f8
commit cf72282782
24 changed files with 9500 additions and 23 deletions

View File

@ -0,0 +1,24 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Launcher &quot;log viewer&quot;" type="Application" factoryName="Application">
<option name="MAIN_CLASS_NAME" value="com.irnems.Launcher" />
<option name="VM_PARAMETERS" value="" />
<option name="PROGRAM_PARAMETERS" value="&quot;log viewer&quot; " />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" value="" />
<option name="ENABLE_SWING_INSPECTOR" value="false" />
<option name="ENV_VARIABLES" />
<option name="PASS_PARENT_ENVS" value="true" />
<module name="ui" />
<envs />
<RunnerSettings RunnerId="Debug">
<option name="DEBUG_PORT" value="" />
<option name="TRANSPORT" value="0" />
<option name="LOCAL" value="true" />
</RunnerSettings>
<RunnerSettings RunnerId="Run" />
<ConfigurationWrapper RunnerId="Debug" />
<ConfigurationWrapper RunnerId="Run" />
<method />
</configuration>
</component>

View File

@ -11,46 +11,58 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* This frame is used on startup to select the port we would be using
*
* @author Andrey Belomutskiy
* 2/14/14
* @author Andrey Belomutskiy 2/14/14
*/
public class PortLookupFrame {
public static void chooseSerialPort() {
java.util.List<String> ports = new ArrayList<String>();
List<String> ports = new ArrayList<String>();
ports.addAll(Arrays.asList(SerialPortList.getPortNames()));
ports.addAll(TcpConnector.getAvailablePorts());
ports.add(LinkManager.LOG_VIEWER);
if (ports.size() == 0) {
JOptionPane.showMessageDialog(null, "No suitable ports found");
System.exit(-1);
}
final JFrame frame = new JFrame("Serial port selection");
JPanel panel = new JPanel(new FlowLayout());
final JPanel panel = new JPanel(new FlowLayout());
for (final String port : ports) {
JButton button = new JButton("Use " + port);
if (!ports.isEmpty())
addPortSelection(ports, frame, panel);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frame.dispose();
new Launcher(port);
}
});
panel.add(button);
}
final JButton buttonLogViewer = new JButton();
buttonLogViewer.setText("Use " + LinkManager.LOG_VIEWER);
buttonLogViewer.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frame.dispose();
new Launcher(LinkManager.LOG_VIEWER);
}
});
panel.add(buttonLogViewer);
frame.add(panel);
frame.pack();
frame.setVisible(true);
}
}
private static void addPortSelection(List<String> ports, final JFrame frame, JPanel panel) {
final JComboBox<String> comboPorts = new JComboBox<String>();
for (final String port : ports)
comboPorts.addItem(port);
panel.add(comboPorts);
final JButton buttonUsePort = new JButton("Use this port");
panel.add(buttonUsePort);
buttonUsePort.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frame.dispose();
new Launcher(comboPorts.getSelectedItem().toString());
}
});
}
}

Binary file not shown.

View File

@ -0,0 +1 @@
version2header

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<option name="DEFAULT_COMPILER" value="Javac" />
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.form" />
<entry name="!?*.class" />
<entry name="!?*.groovy" />
<entry name="!?*.scala" />
<entry name="!?*.flex" />
<entry name="!?*.kt" />
<entry name="!?*.clj" />
</wildcardResourcePatterns>
<annotationProcessing>
<profile default="true" name="Default" enabled="false">
<processorPath useClasspath="true" />
</profile>
</annotationProcessing>
</component>
</project>

View File

@ -0,0 +1,5 @@
<component name="CopyrightManager">
<settings default="">
<module2copyright />
</settings>
</component>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
</project>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="1.7" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
<component name="SvnBranchConfigurationManager">
<option name="mySupportsUserInfoFilter" value="true" />
</component>
</project>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/version2header.iml" filepath="$PROJECT_DIR$/version2header.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,5 @@
<component name="DependencyValidationManager">
<state>
<option name="SKIP_IMPORT_STATEMENTS" value="false" />
</state>
</component>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="svn" />
</component>
</project>

View File

@ -0,0 +1,24 @@
<project default="jar">
<target name="clean">
<delete dir="build"/>
</target>
<target name="compile">
<mkdir dir="build/classes"/>
<javac destdir="build/classes" classpath="lib/junit.jar:lib/annotations.jar">
<src path="src"/>
</javac>
</target>
<target name="jar" depends="compile">
<mkdir dir="build/jar"/>
<jar destfile="../version2header.jar" basedir="build/classes">
<manifest>
<attribute name="Main-Class" value="com.rusefi.Version2Header"/>
</manifest>
<zipfileset dir="build/classes" includes="**/*.class"/>
</jar>
</target>
</project>

View File

@ -0,0 +1,46 @@
package com.rusefi;
import java.io.*;
/**
* Andrey Belomutskiy (c) 2014
*/
public class Version2Header {
private static final String COMMAND = "svn info";
private static final String VERSION_MARKER = "Last Changed Rev: ";
private static final String HEADER_TAG = "SVN_VERSION";
public static void main(String[] args) throws IOException {
Process simulatorProcess = null;
try {
simulatorProcess = Runtime.getRuntime().exec(COMMAND);
BufferedReader input =
new BufferedReader(new InputStreamReader(simulatorProcess.getInputStream()));
String line;
while ((line = input.readLine()) != null) {
System.out.println("from " + COMMAND + ": " + line);
if (line.startsWith(VERSION_MARKER)) {
String ver = line.substring(VERSION_MARKER.length());
System.out.println("Version [" + ver + "]");
int version = Integer.parseInt(ver);
writeFile(version);
}
}
} finally {
if (simulatorProcess != null)
simulatorProcess.destroy();
}
}
private static void writeFile(int version) throws IOException {
BufferedWriter bw = new BufferedWriter(new FileWriter("svnversion.h"));
bw.write("// This file was generated by Version2Header\r\n");
bw.write("#ifndef " + HEADER_TAG + "\r\n");
bw.write("#define " + HEADER_TAG + " " + version + "\r\n");
bw.write("#endif\r\n");
bw.close();
}
}

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,58 @@
/*
* test_event_registry.c
*
* Created on: Nov 27, 2013
* Author: Andrey Belomutskiy, (c) 2012-2013
*/
#include "event_registry.h"
#include "test_event_registry.h"
#include "main.h"
#include "OutputSignalList.h"
static ActuatorEventList eventList;
static ActuatorEventList result;
int pinDefaultState[IO_PIN_COUNT];
void initOutputSignal(OutputSignal *signal, io_pin_e ioPin) {
signal->io_pin = ioPin;
}
extern int outputSignalCount;
void testEventRegistry(void) {
printf("*************************************** testEventRegistry\r\n");
printf("resetting\r\n");
resetEventList(&eventList);
OutputSignalList list;
printf("registering 0\r\n");
registerActuatorEvent(&eventList, 0, list.add((io_pin_e)10), 0);
registerActuatorEvent(&eventList, 0, list.add((io_pin_e)20), 10);
assertEquals(2, eventList.size);
printf("registering 1\r\n");
registerActuatorEvent(&eventList, 1, list.add((io_pin_e)30), 0);
registerActuatorEvent(&eventList, 1, list.add((io_pin_e)40), 10);
assertEquals(4, eventList.size);
printf("Looking for 0\r\n");
findEvents(0, &eventList, &result);
assertEquals(2, result.size);
assertEquals(4, eventList.size);
printf("Validating pins\r\n");
assertEquals(10, result.events[0].actuator->io_pin);
assertEquals(20, result.events[1].actuator->io_pin);
printf("Looking for 1\r\n");
findEvents(1, &eventList, &result);
assertEquals(2, result.size);
assertEquals(4, eventList.size);
assertEquals(30, result.events[0].actuator->io_pin);
assertEquals(40, result.events[1].actuator->io_pin);
}

View File

@ -0,0 +1,29 @@
/*
* @file test_engine_math.c
*
* Created on: Nov 14, 2013
* Author: Andrey Belomutskiy, (c) 2012-2013
*/
#include "test_engine_math.h"
#include "main.h"
#include "engine_math.h"
#include "engine_configuration.h"
#include "ec2.h"
#include "map.h"
extern engine_configuration_s *engineConfiguration;
extern engine_configuration2_s *engineConfiguration2;
void testEngineMath(void) {
printf("*************************************************** testEngineMath\r\n");
engineConfiguration->rpmMultiplier = 0.5;
assertEqualsM("600 RPM", 50, getOneDegreeTimeMs(600) * 180);
assertEqualsM("6000 RPM", 5, getOneDegreeTimeMs(6000) * 180);
}
float getMap(void) {
return 0;
}

View File

@ -0,0 +1,152 @@
/**
* @file test_fuel_map.c
*
* Created on: Nov 6, 2013
* Author: Andrey Belomutskiy, (c) 2012-2013
*/
#include "test_fuel_map.h"
#include "main.h"
#include "engine_configuration.h"
#include "fuel_math.h"
#include "trigger_structure.h"
#include "allsensors.h"
#include "engine_math.h"
#include "OutputSignalList.h"
#include "ec2.h"
extern engine_configuration_s *engineConfiguration;
extern engine_configuration2_s *engineConfiguration2;
void testFuelMap(void) {
chDbgCheck(engineConfiguration!=NULL, "engineConfiguration");
printf("*************************************************** testFuelMap\r\n");
for (int k = 0; k < FUEL_LOAD_COUNT; k++) {
for (int r = 0; r < FUEL_RPM_COUNT; r++) {
engineConfiguration->fuelTable[k][r] = k * 200 + r;
}
}
printf("*************************************************** initThermistors\r\n");
initThermistors();
printf("*** getInjectorLag\r\n");
assertEquals(0, getInjectorLag(12));
for (int i = 0; i < FUEL_LOAD_COUNT; i++)
engineConfiguration->fuelLoadBins[i] = i;
for (int i = 0; i < FUEL_RPM_COUNT; i++)
engineConfiguration->fuelRpmBins[i] = i;
printf("*************************************************** prepareFuelMap\r\n");
prepareFuelMap();
assertEquals(1005, getBaseFuel(5, 5));
engineConfiguration->injectorLag = 0.5;
for (int i = 0; i < VBAT_INJECTOR_CURVE_SIZE; i++) {
engineConfiguration->battInjectorLagCorrBins[i] = i;
engineConfiguration->battInjectorLagCorr[i] = 2 * i;
}
// because all the correction tables are zero
printf("*************************************************** getRunningFuel\r\n");
assertEquals(1005.5, getRunningFuel(5, 5));
printf("*************************************************** setting IAT table\r\n");
for (int i = 0; i < IAT_CURVE_SIZE; i++) {
engineConfiguration->iatFuelCorrBins[i] = i;
engineConfiguration->iatFuelCorr[i] = 2 * i;
}
engineConfiguration->iatFuelCorr[0] = 2;
printf("*************************************************** setting CLT table\r\n");
for (int i = 0; i < CLT_CURVE_SIZE; i++) {
engineConfiguration->cltFuelCorrBins[i] = i;
engineConfiguration->cltFuelCorr[i] = 1;
}
engineConfiguration->injectorLag = 0;
assertEquals(NAN, getIntakeAirTemperature());
float iatCorrection = getIatCorrection(-KELV);
assertEqualsM("IAT", 2, iatCorrection);
float cltCorrection = getCltCorrection(getCoolantTemperature());
assertEqualsM("CLT", 1, cltCorrection);
float injectorLag = getInjectorLag(getVBatt());
assertEquals(0, injectorLag);
// 1005 * 2 for IAT correction
printf("*************************************************** getRunningFuel\r\n");
assertEquals(1005, getRunningFuel(5, 5));
engineConfiguration->crankingSettings.coolantTempMaxC = 65; // 8ms at 65C
engineConfiguration->crankingSettings.fuelAtMaxTempMs = 8;
engineConfiguration->crankingSettings.coolantTempMinC = 0; // 20ms at 0C
engineConfiguration->crankingSettings.fuelAtMinTempMs = 20;
printf("*************************************************** getStartingFuel\r\n");
// NAN in case we have issues with the CLT sensor
// assertEquals(16, getStartingFuel(NAN));
assertEquals(20, getStartingFuel(0));
assertEquals(18.5231, getStartingFuel(8));
assertEquals(8, getStartingFuel(70));
}
static void confgiureFordAspireTriggerShape(trigger_shape_s * s) {
triggerShapeInit(s);
triggerAddEvent(s, 53.747, T_SECONDARY, TV_HIGH);
triggerAddEvent(s, 121.90, T_SECONDARY, TV_LOW);
triggerAddEvent(s, 232.76, T_SECONDARY, TV_HIGH);
triggerAddEvent(s, 300.54, T_SECONDARY, TV_LOW);
triggerAddEvent(s, 360, T_PRIMARY, TV_HIGH);
triggerAddEvent(s, 409.8412, T_SECONDARY, TV_HIGH);
triggerAddEvent(s, 478.6505, T_SECONDARY, TV_LOW);
triggerAddEvent(s, 588.045, T_SECONDARY, TV_HIGH);
triggerAddEvent(s, 657.03, T_SECONDARY, TV_LOW);
triggerAddEvent(s, 720, T_PRIMARY, TV_LOW);
}
static ActuatorEventList ae;
void testAngleResolver(void) {
printf("*************************************************** testAngleResolver\r\n");
engineConfiguration->globalTriggerAngleOffset = 175;
trigger_shape_s * ts = &engineConfiguration2->triggerShape;
confgiureFordAspireTriggerShape(ts);
assertEqualsM("shape size", 10, ts->size);
OutputSignalList list;
resetEventList(&ae);
printf("*************************************************** testAngleResolver 0\r\n");
registerActuatorEventExt(engineConfiguration, &engineConfiguration2->triggerShape, &ae, list.add(INJECTOR_1_OUTPUT), 53 - 175);
assertEqualsM("size", 1, ae.size);
assertEquals(1, list.getSize());
assertEquals(0, ae.events[0].eventIndex);
assertEquals(53, ae.events[0].angleOffset);
printf("*************************************************** testAngleResolver 2\r\n");
resetEventList(&ae);
registerActuatorEventExt(engineConfiguration, &engineConfiguration2->triggerShape, &ae, list.add(INJECTOR_1_OUTPUT), 51 + 180 - 175);
assertEquals(2, ae.events[0].eventIndex);
assertEquals(51.9870, ae.events[0].angleOffset);
}
void testPinHelper(void) {
printf("*************************************************** testPinHelper\r\n");
assertEquals(0, getElectricalValue(0, OM_DEFAULT));
assertEquals(1, getElectricalValue(1, OM_DEFAULT));
assertEquals(0, getElectricalValue(1, OM_INVERTED));
assertEquals(1, getElectricalValue(0, OM_INVERTED));
}

View File

@ -0,0 +1,80 @@
/**
* @file test_signal_executor.c
*
* @date Nov 28, 2013
* @author Andrey Belomutskiy, (c) 2012-2013
*/
#include <time.h>
#include "main.h"
#include "signal_executor.h"
#include "test_signal_executor.h"
#include "io_pins.h"
#include "utlist.h"
#include "event_queue.h"
extern OutputSignal *st_output_list;
static io_pin_e testLastToggledPin;
static int testToggleCounter;
int getRevolutionCounter(void) {
return 0;
}
void setOutputPinValue(io_pin_e pin, int value) {
// this is a test implementation of the method - we use it to see what's going on
testLastToggledPin = pin;
testToggleCounter++;
}
void scheduleTask(scheduling_s *scheduling, int delayUs, schfunc_t callback, void *param) {
}
void initSignalExecutorImpl(void) {
}
static EventQueue eq;
static int callbackCounter = 0;
static void callback(void *a) {
callbackCounter++;
}
void testSignalExecutor() {
print("*************************************** testSignalExecutor\r\n");
assertEquals(EMPTY_QUEUE, eq.getNextEventTime(0));
scheduling_s s1;
scheduling_s s2;
eq.insertTask(&s1, 0, 10, callback, NULL);
assertEquals(10, eq.getNextEventTime(0));
eq.executeAll(1);
assertEqualsM("callbacks not expected", 0, callbackCounter);
eq.executeAll(11);
assertEquals(1, callbackCounter);
assertEquals(EMPTY_QUEUE, eq.getNextEventTime(0));
eq.insertTask(&s1, 0, 10, callback, NULL);
eq.insertTask(&s2, 0, 13, callback, NULL);
assertEquals(10, eq.getNextEventTime(0));
eq.executeAll(1);
assertEquals(10, eq.getNextEventTime(0));
eq.clear();
callbackCounter = 0;
// both events are scheduled for the same time
eq.insertTask(&s1, 0, 10, callback, NULL);
eq.insertTask(&s2, 0, 10, callback, NULL);
eq.executeAll(11);
assertEquals(2, callbackCounter);
}

View File

@ -0,0 +1,282 @@
/**
* @file test_trigger_decoder.cpp
*
* @date Dec 24, 2013
* @author Andrey Belomutskiy, (c) 2012-2013
*/
#include "main.h"
#include "test_trigger_decoder.h"
#include "trigger_decoder.h"
#include "engine_math.h"
#include "ford_aspire.h"
#include "dodge_neon.h"
#include "ford_1995_inline_6.h"
#include "mazda_323.h"
extern "C" {
void sendOutConfirmation(char *value, int i);
}
void sendOutConfirmation(char *value, int i) {
// test implementation
}
int getTheAngle(engine_type_e engineType) {
persistent_config_s persistentConfig;
engine_configuration_s *ec = &persistentConfig.engineConfiguration;
engine_configuration2_s ec2;
resetConfigurationExt(engineType, ec, &ec2, &persistentConfig.boardConfiguration);
trigger_shape_s * shape = &ec2.triggerShape;
return findTriggerZeroEventIndex(shape, &ec->triggerConfig);
}
static void testDodgeNeonDecoder(void) {
printf("*************************************************** testDodgeNeonDecoder\r\n");
initTriggerDecoder();
assertEqualsM("trigger zero index", 8, getTheAngle(DODGE_NEON_1995));
persistent_config_s persistentConfig;
engine_configuration_s *ec = &persistentConfig.engineConfiguration;
engine_configuration2_s ec2;
resetConfigurationExt(DODGE_NEON_1995, ec, &ec2, &persistentConfig.boardConfiguration);
trigger_shape_s * shape = &ec2.triggerShape;
trigger_state_s state;
clearTriggerState(&state);
//
// assertFalseM("1 shaft_is_synchronized", state.shaft_is_synchronized);
//
// int r = 0;
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_UP, r + 60);
// assertFalseM("2 shaft_is_synchronized", state.shaft_is_synchronized); // still no synchronization
//
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_DOWN, r + 210);
// assertFalseM("3 shaft_is_synchronized", state.shaft_is_synchronized); // still no synchronization
//
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_UP, r + 420);
// assertFalseM("4 shaft_is_synchronized", state.shaft_is_synchronized); // still no synchronization
//
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_DOWN, r + 630);
// assertFalse(state.shaft_is_synchronized); // still no synchronization
//
// printf("2nd camshaft revolution\r\n");
// r = 720;
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_UP, r + 60);
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_DOWN, r + 210);
// assertTrue(state.shaft_is_synchronized);
// assertEquals(0, state.current_index);
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_UP, r + 420);
// assertEquals(1, state.current_index);
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_DOWN, r + 630);
// assertEquals(2, state.current_index);
//
// printf("3rd camshaft revolution\r\n");
// r = 2 * 720;
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_UP, r + 60);
// assertEqualsM("current index", 3, state.current_index);
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_DOWN, r + 210);
// assertTrue(state.shaft_is_synchronized);
// assertEqualsM("current index", 0, state.current_index);
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_UP, r + 420);
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_DOWN, r + 630);
}
static void test1995FordInline6TriggerDecoder(void) {
printf("*************************************************** test1995FordInline6TriggerDecoder\r\n");
assertEqualsM("triggerIndex ", 0, getTheAngle(FORD_INLINE_6_1995));
initTriggerDecoder();
persistent_config_s persistentConfig;
engine_configuration_s *ec = &persistentConfig.engineConfiguration;
engine_configuration2_s ec2;
resetConfigurationExt(FORD_INLINE_6_1995, ec, &ec2, &persistentConfig.boardConfiguration);
ActuatorEventList *ecl = &ec2.engineEventConfiguration.ignitionEvents;
assertEqualsM("ignition events size", 6, ecl->size);
assertEqualsM("event index", 0, ecl->events[0].eventIndex);
assertEquals(0, ecl->events[0].angleOffset);
assertEqualsM("event index", 10, ecl->events[5].eventIndex);
assertEquals(0, ecl->events[5].angleOffset);
trigger_state_s state;
clearTriggerState(&state);
trigger_shape_s * shape = &ec2.triggerShape;
assertFalseM("shaft_is_synchronized", state.shaft_is_synchronized);
int r = 10;
processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_DOWN, r);
assertFalseM("shaft_is_synchronized", state.shaft_is_synchronized); // still no synchronization
processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_UP, ++r);
assertTrue(state.shaft_is_synchronized); // first signal rise synchronize
assertEquals(0, state.current_index);
processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_DOWN, r++);
assertEquals(1, state.current_index);
for (int i = 2; i < 10;) {
processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_UP, r++);
assertEqualsM("even", i++, state.current_index);
processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_DOWN, r++);
assertEqualsM("odd", i++, state.current_index);
}
processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_UP, r++);
assertEquals(10, state.current_index);
processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_DOWN, r++);
assertEquals(11, state.current_index);
processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_UP, r++);
assertEquals(0, state.current_index); // new revolution
assertEqualsM("running dwell", 0.5, getSparkDwellMsT(ec, 2000));
}
void testFordAspire(void) {
printf("*************************************************** testFordAspire\r\n");
assertEquals(4, getTheAngle(FORD_ASPIRE_1996));
persistent_config_s persistentConfig;
engine_configuration_s *ec = &persistentConfig.engineConfiguration;
engine_configuration2_s ec2;
resetConfigurationExt(FORD_ASPIRE_1996, ec, &ec2, &persistentConfig.boardConfiguration);
assertEquals(800, ec->fuelRpmBins[0]);
assertEquals(7000, ec->fuelRpmBins[15]);
ec->crankingChargeAngle = 65;
ec->crankingTimingAngle = 31;
assertEqualsM("cranking dwell", 54.166670, getSparkDwellMsT(ec, 200));
assertEqualsM("running dwell", 4, getSparkDwellMsT(ec, 2000));
assertEqualsM("higher rpm dwell", 3.25, getSparkDwellMsT(ec, 6000));
}
void testMazda323(void) {
printf("*************************************************** testMazda323\r\n");
persistent_config_s persistentConfig;
engine_configuration_s *ec = &persistentConfig.engineConfiguration;
engine_configuration2_s ec2;
resetConfigurationExt(MAZDA_323, ec, &ec2, &persistentConfig.boardConfiguration);
}
void testMazdaMianaNbDecoder(void) {
printf("*************************************************** testMazdaMianaNbDecoder\r\n");
persistent_config_s persistentConfig;
engine_configuration_s *ec = &persistentConfig.engineConfiguration;
engine_configuration2_s ec2;
resetConfigurationExt(MAZDA_MIATA_NB, ec, &ec2, &persistentConfig.boardConfiguration);
trigger_state_s state;
clearTriggerState(&state);
trigger_shape_s * shape = &ec2.triggerShape;
int a = 0;
processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_DOWN, a + 20);
assertFalseM("0a shaft_is_synchronized", state.shaft_is_synchronized);
processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_UP, a + 340);
assertFalseM("0b shaft_is_synchronized", state.shaft_is_synchronized);
processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_DOWN, a + 360);
assertFalseM("0c shaft_is_synchronized", state.shaft_is_synchronized);
processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_UP, a + 380);
assertFalseM("0d shaft_is_synchronized", state.shaft_is_synchronized);
processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_DOWN, a + 400);
assertTrueM("0e shaft_is_synchronized", state.shaft_is_synchronized);
processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_UP, a + 720);
assertTrueM("0f shaft_is_synchronized", state.shaft_is_synchronized);
a = 720;
processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_DOWN, a + 20);
assertTrueM("1a shaft_is_synchronized", state.shaft_is_synchronized);
processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_UP, a + 340);
assertTrueM("1b shaft_is_synchronized", state.shaft_is_synchronized);
processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_DOWN, a + 360);
assertTrueM("1c shaft_is_synchronized", state.shaft_is_synchronized);
processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_UP, a + 380);
assertTrueM("1d shaft_is_synchronized", state.shaft_is_synchronized);
assertEquals(5, state.current_index);
processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_DOWN, a + 400);
assertTrueM("1e shaft_is_synchronized", state.shaft_is_synchronized);
assertEquals(0, state.current_index);
processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_UP, a + 720);
assertTrueM("1f shaft_is_synchronized", state.shaft_is_synchronized);
}
void testFordEscortGt(void) {
printf("*************************************************** testFordEscortGt\r\n");
persistent_config_s persistentConfig;
engine_configuration_s *ec = &persistentConfig.engineConfiguration;
engine_configuration2_s ec2;
resetConfigurationExt(FORD_ESCORT_GT, ec, &ec2, &persistentConfig.boardConfiguration);
}
void testGY6_139QMB(void) {
printf("*************************************************** testGY6_139QMB\r\n");
persistent_config_s persistentConfig;
engine_configuration_s *ec = &persistentConfig.engineConfiguration;
engine_configuration2_s ec2;
resetConfigurationExt(GY6_139QMB, ec, &ec2, &persistentConfig.boardConfiguration);
trigger_state_s state;
clearTriggerState(&state);
assertFalseM("shaft_is_synchronized", state.shaft_is_synchronized);
trigger_shape_s * shape = &ec2.triggerShape;
assertFalseM("shaft_is_synchronized", state.shaft_is_synchronized);
assertEquals(0, state.current_index);
int now = 0;
processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_UP, now++);
assertTrueM("shaft_is_synchronized", state.shaft_is_synchronized);
assertEquals(0, state.current_index);
processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_DOWN, now++);
assertTrueM("shaft_is_synchronized", state.shaft_is_synchronized);
assertEquals(1, state.current_index);
}
void testTriggerDecoder(void) {
printf("*************************************************** testTriggerDecoder\r\n");
engine_configuration2_s ec2;
initializeSkippedToothTriggerShapeExt(&ec2, 2, 0);
assertEqualsM("shape size", ec2.triggerShape.size, 4);
assertEquals(ec2.triggerShape.wave.switchTimes[0], 0.25);
assertEquals(ec2.triggerShape.wave.switchTimes[1], 0.5);
assertEquals(ec2.triggerShape.wave.switchTimes[2], 0.75);
assertEquals(ec2.triggerShape.wave.switchTimes[3], 1);
testDodgeNeonDecoder();
testFordAspire();
test1995FordInline6TriggerDecoder();
testMazdaMianaNbDecoder();
testGY6_139QMB();
testFordEscortGt();
// testMazda323();
}