diff --git a/unit_tests/.cproject b/unit_tests/.cproject
index 71e7c9e65e..cb910d6b94 100644
--- a/unit_tests/.cproject
+++ b/unit_tests/.cproject
@@ -1,141 +1,156 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/unit_tests/.project b/unit_tests/.project
index 3238f268dc..771bc268c3 100644
--- a/unit_tests/.project
+++ b/unit_tests/.project
@@ -1,27 +1,27 @@
-
-
- unit_tests
-
-
-
-
-
- org.eclipse.cdt.managedbuilder.core.genmakebuilder
- clean,full,incremental,
-
-
-
-
- org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
- full,incremental,
-
-
-
-
-
- org.eclipse.cdt.core.cnature
- org.eclipse.cdt.core.ccnature
- org.eclipse.cdt.managedbuilder.core.managedBuildNature
- org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
-
-
+
+
+ unit_tests
+
+
+
+
+
+ org.eclipse.cdt.managedbuilder.core.genmakebuilder
+ clean,full,incremental,
+
+
+
+
+ org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
+ full,incremental,
+
+
+
+
+
+ org.eclipse.cdt.core.cnature
+ org.eclipse.cdt.core.ccnature
+ org.eclipse.cdt.managedbuilder.core.managedBuildNature
+ org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
+
+
diff --git a/unit_tests/Makefile b/unit_tests/Makefile
index 1eb54405fd..2cc0a88e0d 100644
--- a/unit_tests/Makefile
+++ b/unit_tests/Makefile
@@ -1,221 +1,228 @@
-##############################################################################
-# Build global options
-# NOTE: Can be overridden externally.
-#
-
-PROJECT_DIR = ../firmware
-#CHIBIOS = $(PROJECT_DIR)/chibios
-
-# Compiler options here.
-ifeq ($(USE_OPT),)
-# -O2 is needed for mingw, without it there is a linking issue to isnanf?!?!
- #USE_OPT = $(RFLAGS) -O2 -fgnu89-inline -ggdb -fomit-frame-pointer -falign-functions=16 -std=gnu99 -Werror-implicit-function-declaration -Werror -Wno-error=pointer-sign -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=sign-compare -Wno-error=unused-parameter -Wno-error=missing-field-initializers
- USE_OPT = -c -Wall -O2
-endif
-
-# C specific options here (added to USE_OPT).
-ifeq ($(USE_COPT),)
- USE_COPT = -std=gnu99 -fgnu89-inline
-endif
-
-# C++ specific options here (added to USE_OPT).
-ifeq ($(USE_CPPOPT),)
- USE_CPPOPT = -fno-rtti -fpermissive -fno-exceptions -fno-use-cxa-atexit
-endif
-
-# Enable this if you want the linker to remove unused code and data
-ifeq ($(USE_LINK_GC),)
- USE_LINK_GC = yes
-endif
-
-# If enabled, this option allows to compile the application in THUMB mode.
-ifeq ($(USE_THUMB),)
- USE_THUMB = no
-endif
-
-# Enable this if you want to see the full log while compiling.
-ifeq ($(USE_VERBOSE_COMPILE),)
- USE_VERBOSE_COMPILE = no
-endif
-
-#
-# Build global options
-##############################################################################
-
-##############################################################################
-# Architecture or project specific options
-#
-
-
-# List all default C defines here, like -D_DEBUG=1
-DDEFS =
-
-#
-# Architecture or project specific options
-##############################################################################
-
-##############################################################################
-# Project, sources and paths
-#
-
-# Define project name here
-PROJECT = rusefi_test
-
-#PROJECT_BOARD = OLIMEX_STM32_E407
-#ifneq ($(PROJECT_BOARD),OLIMEX_STM32_E407)
-# PROJECT_BOARD = ST_STM32F4_DISCOVERY
-#endif
-#DDEFS += -D$(PROJECT_BOARD)
-
-# Imported source files and paths
-include $(PROJECT_DIR)/util/util.mk
-include $(PROJECT_DIR)/config/engines/engines.mk
-include $(PROJECT_DIR)/controllers/algo/algo.mk
-include $(PROJECT_DIR)/controllers/math/math.mk
-include $(PROJECT_DIR)/controllers/sensors/sensors.mk
-include test.mk
-
-# Define linker script file here
-#LDSCRIPT= config/system/STM32F407xG.ld
-#LDSCRIPT= $(PORTLD)/STM32F407xG_CCM.ld
-
-# C sources that can be compiled in ARM or THUMB mode depending on the global
-# setting.
-CSRC = $(UTILSRC) \
- $(CONTROLLERS_ALGO_SRC) \
- $(CONTROLLERS_MATH_SRC) \
- $(CONTROLLERS_SENSORS_SRC) \
- $(ENGINES_SRC) \
- $(TEST_SRC_C)
-
-# C++ sources that can be compiled in ARM or THUMB mode depending on the global
-# setting.
-CPPSRC = $(UTILSRC_CPP) \
- $(CONTROLLERS_ALGO_SRC_CPP) \
- $(ENGINES_SRC_CPP) \
- $(TEST_SRC_CPP) \
- main.cpp
-
-# C sources to be compiled in ARM mode regardless of the global setting.
-# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
-# option that results in lower performance and larger code size.
-ACSRC =
-
-# C++ sources to be compiled in ARM mode regardless of the global setting.
-# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
-# option that results in lower performance and larger code size.
-ACPPSRC =
-
-# C sources to be compiled in THUMB mode regardless of the global setting.
-# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
-# option that results in lower performance and larger code size.
-TCSRC =
-
-# C sources to be compiled in THUMB mode regardless of the global setting.
-# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
-# option that results in lower performance and larger code size.
-TCPPSRC =
-
-# List ASM source files here
-ASMSRC = $(PORTASM)
-
-INCDIR = . \
- $(PROJECT_DIR)/util \
- $(PROJECT_DIR)/config/engines \
- $(PROJECT_DIR)/controllers/sensors \
- $(PROJECT_DIR)/controllers/algo \
- $(PROJECT_DIR)/controllers/math \
- $(PROJECT_DIR)/ext_algo \
- test_data_structures \
- test_basic_math
-
-
-#
-# Project, sources and paths
-##############################################################################
-
-##############################################################################
-# Compiler settings
-#
-
-#MCU = cortex-m4
-
-ifeq ($(OS),Windows_NT)
- TRGT = i686-pc-mingw32-
-else
- TRGT =
-endif
-
-CC = $(TRGT)gcc
-CPPC = $(TRGT)g++
-# Enable loading with g++ only if you need C++ runtime support.
-# NOTE: You can use C++ even without C++ support if you are careful. C++
-# runtime support makes code size explode.
-#LD = $(TRGT)gcc
-LD = $(TRGT)g++
-CP = $(TRGT)objcopy
-AS = $(TRGT)gcc -x assembler-with-cpp
-OD = $(TRGT)objdump
-HEX = $(CP) -O ihex
-BIN = $(CP) -O binary
-
-# ARM-specific options here
-AOPT =
-
-# THUMB-specific options here
-TOPT = -mthumb -DTHUMB
-
-# Define C warning options here
-CWARN = -Wall -Wextra -Wstrict-prototypes
-
-# Define C++ warning options here
-CPPWARN = -Wall -Wextra
-
-#
-# Compiler settings
-##############################################################################
-
-##############################################################################
-# Start of default section
-#
-
-# List all default ASM defines here, like -D_DEBUG=1
-DADEFS =
-
-# List all default directories to look for include files here
-DINCDIR =
-
-# List the default directory to look for the libraries here
-DLIBDIR =
-
-# List all default libraries here
-DLIBS = -static-libgcc -static-libstdc++
-
-#
-# End of default section
-##############################################################################
-
-##############################################################################
-# Start of user section
-#
-
-# List all user C define here, like -D_DEBUG=1
-UDEFS =
-
-# Define ASM defines here
-UADEFS =
-
-# List all user directories here
-UINCDIR =
-
-# List the user directory to look for the libraries here
-ULIBDIR =
-
-# List all user libraries here
-ULIBS = -lm
-
-#
-# End of user defines
-##############################################################################
-
-include rules.mk
+##############################################################################
+# Build global options
+# NOTE: Can be overridden externally.
+#
+
+PROJECT_DIR = ../firmware
+#CHIBIOS = $(PROJECT_DIR)/chibios
+
+# Compiler options here.
+ifeq ($(USE_OPT),)
+# -O2 is needed for mingw, without it there is a linking issue to isnanf?!?!
+ #USE_OPT = $(RFLAGS) -O2 -fgnu89-inline -ggdb -fomit-frame-pointer -falign-functions=16 -std=gnu99 -Werror-implicit-function-declaration -Werror -Wno-error=pointer-sign -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=sign-compare -Wno-error=unused-parameter -Wno-error=missing-field-initializers
+ USE_OPT = -c -Wall -O0 -ggdb -g3
+endif
+
+# C specific options here (added to USE_OPT).
+ifeq ($(USE_COPT),)
+ USE_COPT = -std=gnu99 -fgnu89-inline
+endif
+
+# C++ specific options here (added to USE_OPT).
+ifeq ($(USE_CPPOPT),)
+ USE_CPPOPT = -fno-rtti -fpermissive -fno-exceptions -fno-use-cxa-atexit
+endif
+
+# Enable this if you want the linker to remove unused code and data
+ifeq ($(USE_LINK_GC),)
+ USE_LINK_GC = yes
+endif
+
+# If enabled, this option allows to compile the application in THUMB mode.
+ifeq ($(USE_THUMB),)
+ USE_THUMB = no
+endif
+
+# Enable this if you want to see the full log while compiling.
+ifeq ($(USE_VERBOSE_COMPILE),)
+ USE_VERBOSE_COMPILE = no
+endif
+
+#
+# Build global options
+##############################################################################
+
+##############################################################################
+# Architecture or project specific options
+#
+
+
+# List all default C defines here, like -D_DEBUG=1
+DDEFS =
+
+#
+# Architecture or project specific options
+##############################################################################
+
+##############################################################################
+# Project, sources and paths
+#
+
+# Define project name here
+PROJECT = rusefi_test
+
+#PROJECT_BOARD = OLIMEX_STM32_E407
+#ifneq ($(PROJECT_BOARD),OLIMEX_STM32_E407)
+# PROJECT_BOARD = ST_STM32F4_DISCOVERY
+#endif
+#DDEFS += -D$(PROJECT_BOARD)
+
+# Imported source files and paths
+include $(PROJECT_DIR)/util/util.mk
+include $(PROJECT_DIR)/config/engines/engines.mk
+include $(PROJECT_DIR)/controllers/algo/algo.mk
+include $(PROJECT_DIR)/controllers/math/math.mk
+include $(PROJECT_DIR)/controllers/sensors/sensors.mk
+include test.mk
+
+# Define linker script file here
+#LDSCRIPT= config/system/STM32F407xG.ld
+#LDSCRIPT= $(PORTLD)/STM32F407xG_CCM.ld
+
+# C sources that can be compiled in ARM or THUMB mode depending on the global
+# setting.
+CSRC = $(UTILSRC) \
+ $(CONTROLLERS_ALGO_SRC) \
+ $(CONTROLLERS_MATH_SRC) \
+ $(CONTROLLERS_SENSORS_SRC) \
+ $(ENGINES_SRC) \
+ $(PROJECT_DIR)/controllers/trigger/trigger_mazda.c \
+ $(PROJECT_DIR)/controllers/trigger/trigger_structure.c \
+ $(TEST_SRC_C)
+
+# C++ sources that can be compiled in ARM or THUMB mode depending on the global
+# setting.
+CPPSRC = $(UTILSRC_CPP) \
+ $(CONTROLLERS_ALGO_SRC_CPP) \
+ $(PROJECT_DIR)/controllers/trigger/trigger_chrysler.cpp \
+ $(PROJECT_DIR)/controllers/trigger/trigger_gm.cpp \
+ $(PROJECT_DIR)/controllers/trigger/trigger_decoder.cpp \
+ $(ENGINES_SRC_CPP) \
+ $(CONTROLLERS_MATH_SRC_CPP) \
+ $(TEST_SRC_CPP) \
+ main.cpp
+
+# C sources to be compiled in ARM mode regardless of the global setting.
+# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
+# option that results in lower performance and larger code size.
+ACSRC =
+
+# C++ sources to be compiled in ARM mode regardless of the global setting.
+# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
+# option that results in lower performance and larger code size.
+ACPPSRC =
+
+# C sources to be compiled in THUMB mode regardless of the global setting.
+# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
+# option that results in lower performance and larger code size.
+TCSRC =
+
+# C sources to be compiled in THUMB mode regardless of the global setting.
+# NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler
+# option that results in lower performance and larger code size.
+TCPPSRC =
+
+# List ASM source files here
+ASMSRC = $(PORTASM)
+
+INCDIR = . \
+ $(PROJECT_DIR)/util \
+ $(PROJECT_DIR)/config/engines \
+ $(PROJECT_DIR)/controllers/sensors \
+ $(PROJECT_DIR)/controllers/algo \
+ $(PROJECT_DIR)/controllers/math \
+ $(PROJECT_DIR)/controllers/trigger \
+ $(PROJECT_DIR)/ext_algo \
+ test_data_structures \
+ test_basic_math
+
+
+#
+# Project, sources and paths
+##############################################################################
+
+##############################################################################
+# Compiler settings
+#
+
+#MCU = cortex-m4
+
+ifeq ($(OS),Windows_NT)
+ TRGT = i686-pc-mingw32-
+else
+ TRGT =
+endif
+
+CC = $(TRGT)gcc
+CPPC = $(TRGT)g++
+# Enable loading with g++ only if you need C++ runtime support.
+# NOTE: You can use C++ even without C++ support if you are careful. C++
+# runtime support makes code size explode.
+#LD = $(TRGT)gcc
+LD = $(TRGT)g++
+CP = $(TRGT)objcopy
+AS = $(TRGT)gcc -x assembler-with-cpp
+OD = $(TRGT)objdump
+HEX = $(CP) -O ihex
+BIN = $(CP) -O binary
+
+# ARM-specific options here
+AOPT =
+
+# THUMB-specific options here
+TOPT = -mthumb -DTHUMB
+
+# Define C warning options here
+CWARN = -Wall -Wextra -Wstrict-prototypes
+
+# Define C++ warning options here
+CPPWARN = -Wall -Wextra
+
+#
+# Compiler settings
+##############################################################################
+
+##############################################################################
+# Start of default section
+#
+
+# List all default ASM defines here, like -D_DEBUG=1
+DADEFS =
+
+# List all default directories to look for include files here
+DINCDIR =
+
+# List the default directory to look for the libraries here
+DLIBDIR =
+
+# List all default libraries here
+DLIBS = -static-libgcc -static-libstdc++
+
+#
+# End of default section
+##############################################################################
+
+##############################################################################
+# Start of user section
+#
+
+# List all user C define here, like -D_DEBUG=1
+UDEFS =
+
+# Define ASM defines here
+UADEFS =
+
+# List all user directories here
+UINCDIR =
+
+# List the user directory to look for the libraries here
+ULIBDIR =
+
+# List all user libraries here
+ULIBS = -lm
+
+#
+# End of user defines
+##############################################################################
+
+include rules.mk
diff --git a/unit_tests/adc_inputs.h b/unit_tests/adc_inputs.h
index 5c526173a7..5d6dca110b 100644
--- a/unit_tests/adc_inputs.h
+++ b/unit_tests/adc_inputs.h
@@ -1,11 +1,11 @@
-/**
- * @file adc_inputs.h
- *
- * @date Dec 7, 2013
- * @author Andrey Belomutskiy, (c) 2012-2013
- */
-
-#ifndef ADC_INPUTS_H_
-#define ADC_INPUTS_H_
-
-#endif /* ADC_INPUTS_H_ */
+/**
+ * @file adc_inputs.h
+ *
+ * @date Dec 7, 2013
+ * @author Andrey Belomutskiy, (c) 2012-2013
+ */
+
+#ifndef ADC_INPUTS_H_
+#define ADC_INPUTS_H_
+
+#endif /* ADC_INPUTS_H_ */
diff --git a/unit_tests/boards.c b/unit_tests/boards.c
index 5755c03f80..1b1a9651eb 100644
--- a/unit_tests/boards.c
+++ b/unit_tests/boards.c
@@ -1,23 +1,22 @@
-/**
- * @file board.c
- *
- * @date Nov 15, 2013
- * @author Andrey Belomutskiy, (c) 2012-2013
- */
-
-#include "boards.h"
-
-float getVoltageDivided(int channel) {
- return 0;
-}
-
-float getVoltage(int channel) {
- return 0;
-}
-
-
-int getAdcValue(int channel) {
- return 0;
-}
-
-
+/**
+ * @file board.c
+ *
+ * @date Nov 15, 2013
+ * @author Andrey Belomutskiy, (c) 2012-2013
+ */
+
+#include "boards.h"
+
+float getVoltageDivided(int channel) {
+ return 0;
+}
+
+float getVoltage(int channel) {
+ return 0;
+}
+
+int getAdcValue(int channel) {
+ return 0;
+}
+
+
diff --git a/unit_tests/boards.h b/unit_tests/boards.h
index bbcf9f6256..8a162b459f 100644
--- a/unit_tests/boards.h
+++ b/unit_tests/boards.h
@@ -1,24 +1,24 @@
-/*
- * boards.h
- *
- * Created on: Nov 15, 2013
- * Author: Andrey Belomutskiy, (c) 2012-2013
- */
-
-#ifndef BOARDS_H_
-#define BOARDS_H_
-
-#define ADC_LOGIC_TPS 0
-#define ADC_LOGIC_AFR 0
-#define ADC_LOGIC_MAF 0
-#define ADC_LOGIC_MAP 0
-#define ADC_CHANNEL_VREF 0
-#define ADC_CHANNEL_VBATT 0
-#define ADC_LOGIC_INTAKE_AIR 0
-#define ADC_LOGIC_COOLANT 0
-
-float getVoltageDivided(int);
-float getVoltage(int channel);
-int getAdcValue(int channel);
-
-#endif /* BOARDS_H_ */
+/*
+ * boards.h
+ *
+ * Created on: Nov 15, 2013
+ * Author: Andrey Belomutskiy, (c) 2012-2013
+ */
+
+#ifndef BOARDS_H_
+#define BOARDS_H_
+
+#define ADC_LOGIC_TPS 0
+#define ADC_LOGIC_AFR 0
+#define ADC_LOGIC_MAF 0
+#define ADC_LOGIC_MAP 0
+#define ADC_CHANNEL_VREF 0
+#define ADC_CHANNEL_VBATT 0
+#define ADC_LOGIC_INTAKE_AIR 0
+#define ADC_LOGIC_COOLANT 0
+
+float getVoltageDivided(int);
+float getVoltage(int channel);
+int getAdcValue(int channel);
+
+#endif /* BOARDS_H_ */
diff --git a/unit_tests/compile.bat b/unit_tests/compile.bat
index 1c9d2c2e35..5d15e43e5b 100644
--- a/unit_tests/compile.bat
+++ b/unit_tests/compile.bat
@@ -1,3 +1,3 @@
-rm -rf .dep/
-rm -rf build/
-make
+rm -rf .dep/
+rm -rf build/
+make
diff --git a/unit_tests/efifeatures.h b/unit_tests/efifeatures.h
index 8845e51ac7..5827283bd1 100644
--- a/unit_tests/efifeatures.h
+++ b/unit_tests/efifeatures.h
@@ -1,13 +1,20 @@
-/*
- * efifeatures.h
- *
- * Created on: Mar 7, 2014
- * Author: Andrey
- */
-
-#ifndef EFIFEATURES_H_
-#define EFIFEATURES_H_
-
-#define EFI_CLI_SUPPORT FALSE
-
-#endif /* EFIFEATURES_H_ */
+/*
+ * efifeatures.h
+ *
+ * Created on: Mar 7, 2014
+ * Author: Andrey
+ */
+
+#ifndef EFIFEATURES_H_
+#define EFIFEATURES_H_
+
+#define EFI_CLI_SUPPORT FALSE
+
+#define EFI_SUPPORT_FORD_ASPIRE TRUE
+#define EFI_SUPPORT_DODGE_NEON TRUE
+#define EFI_SUPPORT_1995_FORD_INLINE_6 TRUE
+#define EFI_SUPPORT_FORD_FIESTA TRUE
+#define EFI_SUPPORT_NISSAN_PRIMERA TRUE
+
+
+#endif /* EFIFEATURES_H_ */
diff --git a/unit_tests/global.h b/unit_tests/global.h
index fd7f9e766f..8cf7b254cf 100644
--- a/unit_tests/global.h
+++ b/unit_tests/global.h
@@ -1,23 +1,19 @@
-/*
- * @file global.h
- *
- * @date Nov 28, 2013
- * @author pc
- */
-
-#ifndef GLOBAL_H_
-#define GLOBAL_H_
-
-#include
-#include
-
-#define EFI_SUPPORT_FORD_ASPIRE TRUE
-#define EFI_SUPPORT_DODGE_NEON TRUE
-#define EFI_SUPPORT_1995_FORD_INLINE_6 TRUE
-#define EFI_SUPPORT_FORD_FIESTA TRUE
-#define EFI_SUPPORT_NISSAN_PRIMERA TRUE
-
-#define TRUE 1
-#define FALSE 0
-
-#endif /* GLOBAL_H_ */
+/*
+ * @file global.h
+ *
+ * @date Nov 28, 2013
+ * @author pc
+ */
+
+#ifndef GLOBAL_H_
+#define GLOBAL_H_
+
+#include
+#include
+
+#include "efitime.h"
+
+#define TRUE 1
+#define FALSE 0
+
+#endif /* GLOBAL_H_ */
diff --git a/unit_tests/jenkins.sh b/unit_tests/jenkins.sh
index 67df86f044..0154067250 100644
--- a/unit_tests/jenkins.sh
+++ b/unit_tests/jenkins.sh
@@ -1,40 +1,40 @@
-#!/bin/bash
- echo "The PATH is ${PATH}"
- cd "${WORKSPACE}"
- echo "start in workspace ${PWD}"
-
- cd firmware
- echo "CD to ${PWD}"
-
- rm -fR .dep
- rm -fR build
- make
-
- if [ ! -f build/rusefi.hex ]; then
- echo "Firmware compilation failed"
- exit -1
- fi
-
- cd "${WORKSPACE}/win32_algo_tests"
- echo "CD to ${PWD}"
-
- rm -fR .dep
- rm -fR build
- make
- if [ ! -f build/rusefi_test ]; then
- echo "test compilation failed"
- exit -1
- fi
-
-# we want to terminate if test fails
-set -e
-
- # invoke the tests - hopefully error code would be propagated?
- build/rusefi_test
-
-cd "${WORKSPACE}/java_console"
-echo "CD to ${PWD}"
-
-#JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64
-#ant
-
+#!/bin/bash
+ echo "The PATH is ${PATH}"
+ cd "${WORKSPACE}"
+ echo "start in workspace ${PWD}"
+
+ cd firmware
+ echo "CD to ${PWD}"
+
+ rm -fR .dep
+ rm -fR build
+ make
+
+ if [ ! -f build/rusefi.hex ]; then
+ echo "Firmware compilation failed"
+ exit -1
+ fi
+
+ cd "${WORKSPACE}/win32_algo_tests"
+ echo "CD to ${PWD}"
+
+ rm -fR .dep
+ rm -fR build
+ make
+ if [ ! -f build/rusefi_test ]; then
+ echo "test compilation failed"
+ exit -1
+ fi
+
+# we want to terminate if test fails
+set -e
+
+ # invoke the tests - hopefully error code would be propagated?
+ build/rusefi_test
+
+cd "${WORKSPACE}/java_console"
+echo "CD to ${PWD}"
+
+#JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64
+#ant
+
diff --git a/unit_tests/main.cpp b/unit_tests/main.cpp
index 3335c4cd69..cfb61a912d 100644
--- a/unit_tests/main.cpp
+++ b/unit_tests/main.cpp
@@ -13,6 +13,7 @@
#include
#include "main.h"
+#include "error_handling.h"
extern "C"
{
@@ -28,10 +29,10 @@ extern "C"
#include "test_signal_executor.h"
#include "test_util.h"
#include "engine_configuration.h"
-#include "test_trigger_decoder.h"
-
+#include "engine_math.h"
}
+#include "test_trigger_decoder.h"
static engine_configuration_s ec;
engine_configuration_s *engineConfiguration = &ec;
@@ -40,8 +41,12 @@ static float absF(float value) {
return value > 0 ? value : -value;
}
+uint64_t getTimeNowUs(void) {
+ return 0;
+}
+
void assertEqualsM(char *msg, float expected, float actual) {
- if (isnan(actual) && !isnan(expected)) {
+ if (cisnan(actual) && !cisnan(expected)) {
printf("Unexpected: %s %.4f while expected %.4f\r\n", msg, actual, expected);
exit(-1);
}
@@ -86,6 +91,7 @@ static engine_configuration2_s ec2;
engine_configuration2_s *engineConfiguration2 = &ec2;
int main(void) {
+ testOverflow64Counter();
testInterpolate3d();
testFindIndex();
testInterpolate2d();
@@ -111,15 +117,16 @@ int main(void) {
testPinHelper();
testSetTableValue();
- printf("Success 20130319\r\n");
+ printf("Success 20130422\r\n");
// resizeMap();
return EXIT_SUCCESS;
}
-void warning(char *msg, float value) {
- printf("Warning: %s %f\r\n", msg, value);
+
+int warning(obd_code_e code, const char *fmt, ...) {
+ printf("Warning: %s\r\n", fmt);
}
void firmwareError(const char *fmt, ...) {
diff --git a/unit_tests/main.h b/unit_tests/main.h
index 23f1765c86..e605c6e613 100644
--- a/unit_tests/main.h
+++ b/unit_tests/main.h
@@ -1,58 +1,62 @@
-/**
- * @file main.h
- * @brief Test version of main.h
- *
- * Created on: Oct 17, 2013
- * Author: Andrey Belomutskiy (C) 2012-2013
- */
-
-#ifndef MAIN_H_
-#define MAIN_H_
-
-#include
-#include
-#include "error_handling.h"
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#include "efilib.h"
-
-#include "global.h"
-#include "boards.h"
-#include "engines.h"
-
-typedef int bool_t;
-
-void chDbgAssert(int c, char *msg, void *arg);
-
-void print(const char *fmt, ...);
-
-#define TICKS_IN_MS 100
-
-#define DEBUG_INTERPOLATION 1
-
-#define chDbgCheck(x, y) chDbgAssert(x, y, NULL)
-
-void assertEqualsM(char *msg, float expected, float actual);
-void assertEquals(float expected, float actual);
-void assertTrue(float actual);
-void assertTrueM(char *msg, float actual);
-void assertFalse(float actual);
-void assertFalseM(char *msg, float actual);
-
-float getIntakeAirTemperature(void);
-float getCoolantTemperature(void);
-float getVBatt(void);
-float getMaf(void);
-
-#define systicks2ms(x) (0)
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif /* MAIN_H_ */
+/**
+ * @file main.h
+ * @brief Test version of main.h
+ *
+ * Created on: Oct 17, 2013
+ * Author: Andrey Belomutskiy (C) 2012-2013
+ */
+
+#ifndef MAIN_H_
+#define MAIN_H_
+
+#include
+#include
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define CH_FREQUENCY 1000
+
+#include "global.h"
+#include "error_handling.h"
+
+#include "efilib.h"
+#include "efitime.h"
+
+#include "boards.h"
+#include "engines.h"
+
+typedef int bool_t;
+
+void chDbgAssert(int c, char *msg, void *arg);
+
+void print(const char *fmt, ...);
+
+#define TICKS_IN_MS 100
+
+#define DEBUG_INTERPOLATION 1
+
+#define chDbgCheck(x, y) chDbgAssert(x, y, NULL)
+
+void assertEqualsM(char *msg, float expected, float actual);
+void assertEquals(float expected, float actual);
+void assertTrue(float actual);
+void assertTrueM(char *msg, float actual);
+void assertFalse(float actual);
+void assertFalseM(char *msg, float actual);
+
+float getIntakeAirTemperature(void);
+float getCoolantTemperature(void);
+float getVBatt(void);
+float getMaf(void);
+
+#define systicks2ms(x) (0)
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* MAIN_H_ */
diff --git a/unit_tests/makelinks.bat b/unit_tests/makelinks.bat
index a700673682..95cde49cba 100644
--- a/unit_tests/makelinks.bat
+++ b/unit_tests/makelinks.bat
@@ -1,8 +1,9 @@
-
-junction controllers_algo ..\firmware\controllers\algo
-junction controllers_math ..\firmware\controllers\math
-junction engines ..\firmware\config\engines
-junction controllers_sensors ..\firmware\controllers\sensors
-junction util ..\firmware\util
-junction ext_algo ..\firmware\ext_algo
-
+
+junction controllers_algo ..\firmware\controllers\algo
+junction controllers_math ..\firmware\controllers\math
+junction controllers_trigger ..\firmware\controllers\trigger
+junction engines ..\firmware\config\engines
+junction controllers_sensors ..\firmware\controllers\sensors
+junction util ..\firmware\util
+junction ext_algo ..\firmware\ext_algo
+
diff --git a/unit_tests/map_resize.c b/unit_tests/map_resize.c
index 44b7f5a6e7..cc876a1020 100644
--- a/unit_tests/map_resize.c
+++ b/unit_tests/map_resize.c
@@ -1,176 +1,176 @@
-/**
- * @file map_resize.c
- *
- * @date Jan 12, 2014
- * @author Andrey Belomutskiy, (c) 2012-2013
- */
-
-#include
-#include "fuel_math.h"
-#include "interpolation.h"
-#include "engines.h"
-#include "engine_configuration.h"
-#include "main.h"
-#include "idle_controller.h"
-
-#if 1
-
-#define AD_LOAD_COUNT 16
-#define AD_RPM_COUNT 16
-
-
-static float ad_rpm_table[] = {/*0*/ 800.000000,
- /*1*/ 1213.333374,
- /*2*/ 1626.666748,
- /*3*/ 2040.000000,
- /*4*/ 2453.333496,
- /*5*/ 2866.666748,
- /*6*/ 3280.000000,
- /*7*/ 3693.333496,
- /*8*/ 4106.666992,
- /*9*/ 4520.000000,
- /*10*/ 4933.333496,
- /*11*/ 5346.666992,
- /*12*/ 5760.000000,
- /*13*/ 6173.333496,
- /*14*/ 6586.666992,
- /*15*/ 7000.000000,
- };;
-
-static float ad_maf_table[] =
-{/*0*/ 1.200000,
-/*1*/ 1.413333,
-/*2*/ 1.626667,
-/*3*/ 1.840000,
-/*4*/ 2.053333,
-/*5*/ 2.266667,
-/*6*/ 2.480000,
-/*7*/ 2.693333,
-/*8*/ 2.906667,
-/*9*/ 3.120000,
-/*10*/ 3.333333,
-/*11*/ 3.546667,
-/*12*/ 3.760000,
-/*13*/ 3.973333,
-/*14*/ 4.186667,
-/*15*/ 4.400000,
-};
-
-static float ad_table[AD_LOAD_COUNT][AD_RPM_COUNT] = {
- /* RPM 800.000000 1213.333374 1626.666748 2040.000000 2453.333496 2866.666748 3280.000000 3693.333496 4106.666992 4520.000000 4933.333496 5346.666992 5760.000000 6173.333496 6586.666992 7000.000000*/
- /* Load 1.200000 */{ 0.662000, -7.730000, -16.722000, -23.139999, -29.398001, -31.268000, -32.108002, -30.436001, -30.896000, -26.656000, -24.704000, -25.108000, -25.132000, -25.459999, -25.459999, -25.459999},
- /* Load 1.413333 */{ 0.546000, -7.662000, -16.882000, -23.482000, -29.520000, -31.323999, -32.108002, -30.656000, -30.468000, -26.879999, -24.746000, -24.742001, -29.032000, -25.562000, -25.562000, -25.562000},
- /* Load 1.626667 */{ 0.584000, -7.870000, -16.714001, -23.025999, -29.542000, -31.166000, -32.175999, -30.540001, -30.268000, -26.416000, -24.134001, -25.007999, -24.698000, -26.167999, -26.167999, -26.167999},
- /* Load 1.840000 */{ 0.584000, -7.658000, -16.714001, -23.254000, -29.351999, -30.978001, -32.141998, -30.874001, -30.896000, -26.507999, -24.558001, -24.389999, -25.761999, -35.492001, -35.492001, -35.492001},
- /* Load 2.053333 */{ 0.584000, -7.862000, -16.538000, -23.254000, -29.232000, -31.296000, -32.520000, -30.142000, -30.388000, -25.903999, -24.370001, -24.082001, -24.792000, -24.351999, -24.351999, -24.351999},
- /* Load 2.266667 */{ -1.364000, -7.726000, -16.806000, -23.254000, -29.639999, -31.006001, -32.298000, -30.912001, -29.882000, -26.392000, -24.664000, -27.233999, -25.374001, -25.417999, -25.417999, -25.417999},
- /* Load 2.480000 */{ 1.364000, -10.490000, -16.705999, -22.441999, -28.101999, -30.238001, -32.363998, -30.719999, -30.896000, -26.608000, -24.664000, -24.431999, -24.500000, -25.510000, -25.510000, -25.510000},
- /* Load 2.693333 */{ 9.864000, -10.416000, -11.680000, -19.150000, -25.754000, -27.936001, -32.554001, -30.656000, -30.153999, -27.184000, -25.252001, -22.812000, -24.452000, -25.219999, -25.219999, -25.219999},
- /* Load 2.906667 */{ 9.866000, 5.452000, 2.854000, -17.212000, -17.552000, -20.688000, -25.660000, -27.809999, -27.691999, -27.224001, -25.882000, -25.360001, -26.100000, -27.992001, -27.992001, -27.992001},
- /* Load 3.120000 */{ 9.864000, 5.452000, 2.854000, -0.342000, -12.526000, -16.218000, -21.364000, -27.590000, -25.780001, -24.170000, -24.664000, -25.584000, -26.490000, -31.968000, -31.968000, -31.968000},
- /* Load 3.333333 */{ 9.864000, 5.516000, 2.854000, -0.226000, -2.738000, -3.816000, -11.924000, -18.808001, -21.038000, -21.538000, -21.209999, -22.228001, -25.046000, -25.156000, -25.156000, -25.156000},
- /* Load 3.546667 */{ 9.866000, 5.518000, 2.854000, 0.000000, -3.022000, -3.816000, -6.428000, -7.788000, -19.426001, -20.860001, -19.966000, -21.030001, -21.396000, -21.570000, -21.570000, -21.570000},
- /* Load 3.760000 */{ 9.864000, 5.516000, 2.772000, -0.226000, -2.732000, -3.500000, -6.798000, -8.102000, -8.660000, -9.500000, -11.788000, -20.132000, -20.072001, -20.510000, -20.510000, -20.510000},
- /* Load 3.973333 */{ 9.864000, 5.518000, 2.854000, 0.000000, -2.880000, -3.816000, -6.420000, -8.320000, -8.426000, -8.532000, -11.470000, -11.442000, -13.610000, -12.022000, -12.022000, -12.022000},
- /* Load 4.186667 */{ 9.750000, 5.518000, 2.604000, 0.000000, -2.880000, -3.654000, -6.050000, -6.888000, -8.372000, -9.364000, -11.764000, -11.732000, -11.864000, -12.376000, -12.376000, -12.376000},
- /* Load 4.400000 */{ 0.350000, 5.590000, 0.502000, 0.910000, 0.864000, 0.954000, 1.324000, -7.436000, 1.170000, 1.054000, 2.058000, 2.098000, 2.636000, -12.352000, -12.352000, -12.352000}
- };
-
-//float getBaseAdvance(int rpm, float key) {
-// // todo: use interpolation
-// int rpm_index = findIndex(ad_rpm_table, AD_RPM_COUNT, rpm);
-// rpm_index = max(rpm_index, 0);
-// int maf_index = findIndex(ad_maf_table, AD_LOAD_COUNT, key);
-// maf_index = max(maf_index, 0);
-//
-// return ad_table[rpm_index][maf_index];
-//}
-
-
-
-#define newRpmSize 16
-#define newKeySize 16
-
-static float newRpmBin[newRpmSize];
-static float newKeyBin[newKeySize];
-
-//static float *fuel_ptrs[FUEL_LOAD_COUNT];
-
-//EngineConfiguration *engineConfiguration;
-
-extern int needInterpolationLogging;
-
-void resizeMap(void) {
-// float keyMin = 1.2;
-// float keyMax = 4.4;
-//
-// float rpmMin = 800;
-// float rpmMax = 7000;
-
-// for (int k = 0; k < FUEL_LOAD_COUNT; k++)
-// fuel_ptrs[k] = engineConfiguration->fuelTable[k];
-
-// for (int i = 0; i < FUEL_MAF_COUNT; i++)
-// engineConfiguration->fuelKeyBins[i] = default_fuel_maf_bins[i];
-// for (int i = 0; i < FUEL_RPM_COUNT; i++)
-// engineConfiguration->fuelRpmBins[i] = default_fuel_rpm_bins[i];
-// for (int k = 0; k < FUEL_MAF_COUNT; k++) {
-// for (int r = 0; r < FUEL_RPM_COUNT; r++) {
-// // todo: this is BAD, this needs to be fixed - TS table indexes are different from default indexes
-// engineConfiguration->fuelTable[k][r] = default_fuel_table[r][k];
-// }
-// }
-
-// assertEquals(15, interpolate3d(1.2, engineConfiguration->fuelKeyBins, FUEL_MAF_COUNT, 8000,
-// engineConfiguration->fuelRpmBins,
-// FUEL_RPM_COUNT, fuel_ptrs));
-
- needInterpolationLogging = 0;
-
-// printf("static float ad_maf_table[AD_LOAD_COUNT] = {");
-// for (int i = 0; i < newKeySize; i++) {
-// newKeyBin[i] = interpolate(0, keyMin, newKeySize - 1, keyMax, i);
-// printf("/*%d*/ %f,\r\n", i, newKeyBin[i]);
-// }
-// printf("};\r\n");
-//
-// printf("static float ad_rpm_table[AD_RPM_COUNT] = {");
-// for (int i = 0; i < newRpmSize; i++) {
-// newRpmBin[i] = interpolate(0, rpmMin, newRpmSize - 1, rpmMax, i);
-// printf("/*%d*/ %f,\r\n", i, newRpmBin[i]);
-// }
-// printf("};\r\n");
-
- printf("static float ad_table[AD_RPM_COUNT][AD_LOAD_COUNT] = {\r\n");
-
- printf("/* RPM\t\t");
- for (int r = 0; r < newRpmSize; r++) {
- float rpm = newRpmBin[r];
- printf("\t%f", rpm);
- }
- printf("*/\r\n");
-
- for (int k = 0; k < newKeySize; k++) {
- float load = newKeyBin[k];
- printf("/* Load %f */{", load);
-
- for (int r = 0; r < newRpmSize; r++) {
- float rpm = newRpmBin[r];
-
- float v = ad_table[k][r];
-
- printf("\t%f", v);
- if (r != newRpmSize - 1)
- printf(",");
-
- }
- printf("}");
- if (k != newKeySize - 1)
- printf(",");
- printf("\r\n");
- }
- printf("};\r\n");
-
-}
-
-#endif
+/**
+ * @file map_resize.c
+ *
+ * @date Jan 12, 2014
+ * @author Andrey Belomutskiy, (c) 2012-2013
+ */
+
+#include
+#include "fuel_math.h"
+#include "interpolation.h"
+#include "engines.h"
+#include "engine_configuration.h"
+#include "main.h"
+#include "idle_controller.h"
+
+#if 1
+
+#define AD_LOAD_COUNT 16
+#define AD_RPM_COUNT 16
+
+
+static float ad_rpm_table[] = {/*0*/ 800.000000,
+ /*1*/ 1213.333374,
+ /*2*/ 1626.666748,
+ /*3*/ 2040.000000,
+ /*4*/ 2453.333496,
+ /*5*/ 2866.666748,
+ /*6*/ 3280.000000,
+ /*7*/ 3693.333496,
+ /*8*/ 4106.666992,
+ /*9*/ 4520.000000,
+ /*10*/ 4933.333496,
+ /*11*/ 5346.666992,
+ /*12*/ 5760.000000,
+ /*13*/ 6173.333496,
+ /*14*/ 6586.666992,
+ /*15*/ 7000.000000,
+ };;
+
+static float ad_maf_table[] =
+{/*0*/ 1.200000,
+/*1*/ 1.413333,
+/*2*/ 1.626667,
+/*3*/ 1.840000,
+/*4*/ 2.053333,
+/*5*/ 2.266667,
+/*6*/ 2.480000,
+/*7*/ 2.693333,
+/*8*/ 2.906667,
+/*9*/ 3.120000,
+/*10*/ 3.333333,
+/*11*/ 3.546667,
+/*12*/ 3.760000,
+/*13*/ 3.973333,
+/*14*/ 4.186667,
+/*15*/ 4.400000,
+};
+
+static float ad_table[AD_LOAD_COUNT][AD_RPM_COUNT] = {
+ /* RPM 800.000000 1213.333374 1626.666748 2040.000000 2453.333496 2866.666748 3280.000000 3693.333496 4106.666992 4520.000000 4933.333496 5346.666992 5760.000000 6173.333496 6586.666992 7000.000000*/
+ /* Load 1.200000 */{ 0.662000, -7.730000, -16.722000, -23.139999, -29.398001, -31.268000, -32.108002, -30.436001, -30.896000, -26.656000, -24.704000, -25.108000, -25.132000, -25.459999, -25.459999, -25.459999},
+ /* Load 1.413333 */{ 0.546000, -7.662000, -16.882000, -23.482000, -29.520000, -31.323999, -32.108002, -30.656000, -30.468000, -26.879999, -24.746000, -24.742001, -29.032000, -25.562000, -25.562000, -25.562000},
+ /* Load 1.626667 */{ 0.584000, -7.870000, -16.714001, -23.025999, -29.542000, -31.166000, -32.175999, -30.540001, -30.268000, -26.416000, -24.134001, -25.007999, -24.698000, -26.167999, -26.167999, -26.167999},
+ /* Load 1.840000 */{ 0.584000, -7.658000, -16.714001, -23.254000, -29.351999, -30.978001, -32.141998, -30.874001, -30.896000, -26.507999, -24.558001, -24.389999, -25.761999, -35.492001, -35.492001, -35.492001},
+ /* Load 2.053333 */{ 0.584000, -7.862000, -16.538000, -23.254000, -29.232000, -31.296000, -32.520000, -30.142000, -30.388000, -25.903999, -24.370001, -24.082001, -24.792000, -24.351999, -24.351999, -24.351999},
+ /* Load 2.266667 */{ -1.364000, -7.726000, -16.806000, -23.254000, -29.639999, -31.006001, -32.298000, -30.912001, -29.882000, -26.392000, -24.664000, -27.233999, -25.374001, -25.417999, -25.417999, -25.417999},
+ /* Load 2.480000 */{ 1.364000, -10.490000, -16.705999, -22.441999, -28.101999, -30.238001, -32.363998, -30.719999, -30.896000, -26.608000, -24.664000, -24.431999, -24.500000, -25.510000, -25.510000, -25.510000},
+ /* Load 2.693333 */{ 9.864000, -10.416000, -11.680000, -19.150000, -25.754000, -27.936001, -32.554001, -30.656000, -30.153999, -27.184000, -25.252001, -22.812000, -24.452000, -25.219999, -25.219999, -25.219999},
+ /* Load 2.906667 */{ 9.866000, 5.452000, 2.854000, -17.212000, -17.552000, -20.688000, -25.660000, -27.809999, -27.691999, -27.224001, -25.882000, -25.360001, -26.100000, -27.992001, -27.992001, -27.992001},
+ /* Load 3.120000 */{ 9.864000, 5.452000, 2.854000, -0.342000, -12.526000, -16.218000, -21.364000, -27.590000, -25.780001, -24.170000, -24.664000, -25.584000, -26.490000, -31.968000, -31.968000, -31.968000},
+ /* Load 3.333333 */{ 9.864000, 5.516000, 2.854000, -0.226000, -2.738000, -3.816000, -11.924000, -18.808001, -21.038000, -21.538000, -21.209999, -22.228001, -25.046000, -25.156000, -25.156000, -25.156000},
+ /* Load 3.546667 */{ 9.866000, 5.518000, 2.854000, 0.000000, -3.022000, -3.816000, -6.428000, -7.788000, -19.426001, -20.860001, -19.966000, -21.030001, -21.396000, -21.570000, -21.570000, -21.570000},
+ /* Load 3.760000 */{ 9.864000, 5.516000, 2.772000, -0.226000, -2.732000, -3.500000, -6.798000, -8.102000, -8.660000, -9.500000, -11.788000, -20.132000, -20.072001, -20.510000, -20.510000, -20.510000},
+ /* Load 3.973333 */{ 9.864000, 5.518000, 2.854000, 0.000000, -2.880000, -3.816000, -6.420000, -8.320000, -8.426000, -8.532000, -11.470000, -11.442000, -13.610000, -12.022000, -12.022000, -12.022000},
+ /* Load 4.186667 */{ 9.750000, 5.518000, 2.604000, 0.000000, -2.880000, -3.654000, -6.050000, -6.888000, -8.372000, -9.364000, -11.764000, -11.732000, -11.864000, -12.376000, -12.376000, -12.376000},
+ /* Load 4.400000 */{ 0.350000, 5.590000, 0.502000, 0.910000, 0.864000, 0.954000, 1.324000, -7.436000, 1.170000, 1.054000, 2.058000, 2.098000, 2.636000, -12.352000, -12.352000, -12.352000}
+ };
+
+//float getBaseAdvance(int rpm, float key) {
+// // todo: use interpolation
+// int rpm_index = findIndex(ad_rpm_table, AD_RPM_COUNT, rpm);
+// rpm_index = max(rpm_index, 0);
+// int maf_index = findIndex(ad_maf_table, AD_LOAD_COUNT, key);
+// maf_index = max(maf_index, 0);
+//
+// return ad_table[rpm_index][maf_index];
+//}
+
+
+
+#define newRpmSize 16
+#define newKeySize 16
+
+static float newRpmBin[newRpmSize];
+static float newKeyBin[newKeySize];
+
+//static float *fuel_ptrs[FUEL_LOAD_COUNT];
+
+//EngineConfiguration *engineConfiguration;
+
+extern int needInterpolationLogging;
+
+void resizeMap(void) {
+// float keyMin = 1.2;
+// float keyMax = 4.4;
+//
+// float rpmMin = 800;
+// float rpmMax = 7000;
+
+// for (int k = 0; k < FUEL_LOAD_COUNT; k++)
+// fuel_ptrs[k] = engineConfiguration->fuelTable[k];
+
+// for (int i = 0; i < FUEL_MAF_COUNT; i++)
+// engineConfiguration->fuelKeyBins[i] = default_fuel_maf_bins[i];
+// for (int i = 0; i < FUEL_RPM_COUNT; i++)
+// engineConfiguration->fuelRpmBins[i] = default_fuel_rpm_bins[i];
+// for (int k = 0; k < FUEL_MAF_COUNT; k++) {
+// for (int r = 0; r < FUEL_RPM_COUNT; r++) {
+// // todo: this is BAD, this needs to be fixed - TS table indexes are different from default indexes
+// engineConfiguration->fuelTable[k][r] = default_fuel_table[r][k];
+// }
+// }
+
+// assertEquals(15, interpolate3d(1.2, engineConfiguration->fuelKeyBins, FUEL_MAF_COUNT, 8000,
+// engineConfiguration->fuelRpmBins,
+// FUEL_RPM_COUNT, fuel_ptrs));
+
+ needInterpolationLogging = 0;
+
+// printf("static float ad_maf_table[AD_LOAD_COUNT] = {");
+// for (int i = 0; i < newKeySize; i++) {
+// newKeyBin[i] = interpolate(0, keyMin, newKeySize - 1, keyMax, i);
+// printf("/*%d*/ %f,\r\n", i, newKeyBin[i]);
+// }
+// printf("};\r\n");
+//
+// printf("static float ad_rpm_table[AD_RPM_COUNT] = {");
+// for (int i = 0; i < newRpmSize; i++) {
+// newRpmBin[i] = interpolate(0, rpmMin, newRpmSize - 1, rpmMax, i);
+// printf("/*%d*/ %f,\r\n", i, newRpmBin[i]);
+// }
+// printf("};\r\n");
+
+ printf("static float ad_table[AD_RPM_COUNT][AD_LOAD_COUNT] = {\r\n");
+
+ printf("/* RPM\t\t");
+ for (int r = 0; r < newRpmSize; r++) {
+ float rpm = newRpmBin[r];
+ printf("\t%f", rpm);
+ }
+ printf("*/\r\n");
+
+ for (int k = 0; k < newKeySize; k++) {
+ float load = newKeyBin[k];
+ printf("/* Load %f */{", load);
+
+ for (int r = 0; r < newRpmSize; r++) {
+ float rpm = newRpmBin[r];
+
+ float v = ad_table[k][r];
+
+ printf("\t%f", v);
+ if (r != newRpmSize - 1)
+ printf(",");
+
+ }
+ printf("}");
+ if (k != newKeySize - 1)
+ printf(",");
+ printf("\r\n");
+ }
+ printf("};\r\n");
+
+}
+
+#endif
diff --git a/unit_tests/map_resize.h b/unit_tests/map_resize.h
index 3d105a434e..4157379c9e 100644
--- a/unit_tests/map_resize.h
+++ b/unit_tests/map_resize.h
@@ -1,13 +1,13 @@
-/**
- * @file map_resize.h
- *
- * @date Jan 12, 2014
- * @author Andrey Belomutskiy, (c) 2012-2013
- */
-
-#ifndef MAP_RESIZE_H_
-#define MAP_RESIZE_H_
-
-void resizeMap(void);
-
-#endif /* MAP_RESIZE_H_ */
+/**
+ * @file map_resize.h
+ *
+ * @date Jan 12, 2014
+ * @author Andrey Belomutskiy, (c) 2012-2013
+ */
+
+#ifndef MAP_RESIZE_H_
+#define MAP_RESIZE_H_
+
+void resizeMap(void);
+
+#endif /* MAP_RESIZE_H_ */
diff --git a/unit_tests/readme.txt b/unit_tests/readme.txt
index 621959dacd..d587160641 100644
--- a/unit_tests/readme.txt
+++ b/unit_tests/readme.txt
@@ -1,6 +1,6 @@
-In this folder we have a naive test set. I am not sure what is the best approach to tests in C (someone can educate me), but my approach is:
-
-1) with a symlink linking some (only some, not all) folders of the firmware implementation, we can compile some files of the firmware as win32 code.
-Please execute the 'makelinks.bat' file to get the links. On XP you might need to execute 'junction.exe' before exuting the .bat file.
-
+In this folder we have a naive test set. I am not sure what is the best approach to tests in C (someone can educate me), but my approach is:
+
+1) with a symlink linking some (only some, not all) folders of the firmware implementation, we can compile some files of the firmware as win32 code.
+Please execute the 'makelinks.bat' file to get the links. On XP you might need to execute 'junction.exe' before exuting the .bat file.
+
2) we then compile & run the .exe, which is expected to say SUCCESS and not fail :)
\ No newline at end of file
diff --git a/unit_tests/rules.mk b/unit_tests/rules.mk
index 5e93b3e311..c2a8b23a79 100644
--- a/unit_tests/rules.mk
+++ b/unit_tests/rules.mk
@@ -1,168 +1,168 @@
-# ARM Cortex-Mx common makefile scripts and rules.
-
-# Output directory and files
-ifeq ($(BUILDDIR),)
- BUILDDIR = build
-endif
-ifeq ($(BUILDDIR),.)
- BUILDDIR = build
-endif
-OUTFILES = $(BUILDDIR)/$(PROJECT)
-
-# Automatic compiler options
-OPT = $(USE_OPT)
-COPT = $(USE_COPT)
-CPPOPT = $(USE_CPPOPT)
-ifeq ($(USE_LINK_GC),yes)
- OPT += -ffunction-sections -fdata-sections -fno-common
-endif
-
-# Source files groups and paths
-ifeq ($(USE_THUMB),yes)
- TCSRC += $(CSRC)
- TCPPSRC += $(CPPSRC)
-else
- ACSRC += $(CSRC)
- ACPPSRC += $(CPPSRC)
-endif
-ASRC = $(ACSRC)$(ACPPSRC)
-TSRC = $(TCSRC)$(TCPPSRC)
-SRCPATHS = $(sort $(dir $(ASMXSRC)) $(dir $(ASMSRC)) $(dir $(ASRC)) $(dir $(TSRC)))
-
-# Various directories
-OBJDIR = $(BUILDDIR)/obj
-LSTDIR = $(BUILDDIR)/lst
-
-# Object files groups
-ACOBJS = $(addprefix $(OBJDIR)/, $(notdir $(ACSRC:.c=.o)))
-ACPPOBJS = $(addprefix $(OBJDIR)/, $(notdir $(ACPPSRC:.cpp=.o)))
-TCOBJS = $(addprefix $(OBJDIR)/, $(notdir $(TCSRC:.c=.o)))
-TCPPOBJS = $(addprefix $(OBJDIR)/, $(notdir $(TCPPSRC:.cpp=.o)))
-ASMOBJS = $(addprefix $(OBJDIR)/, $(notdir $(ASMSRC:.s=.o)))
-ASMXOBJS = $(addprefix $(OBJDIR)/, $(notdir $(ASMXSRC:.S=.o)))
-OBJS = $(ASMXOBJS) $(ASMOBJS) $(ACOBJS) $(TCOBJS) $(ACPPOBJS) $(TCPPOBJS)
-
-# Paths
-IINCDIR = $(patsubst %,-I%,$(INCDIR) $(DINCDIR) $(UINCDIR))
-LLIBDIR = $(patsubst %,-L%,$(DLIBDIR) $(ULIBDIR))
-
-# Macros
-DEFS = $(DDEFS) $(UDEFS)
-ADEFS = $(DADEFS) $(UADEFS)
-
-# Libs
-LIBS = $(DLIBS) $(ULIBS)
-
-# Various settings
-#MCFLAGS = -mcpu=$(MCU)
-ODFLAGS = -x --syms
-ASFLAGS = $(MCFLAGS) -Wa,-amhls=$(LSTDIR)/$(notdir $(<:.s=.lst)) $(ADEFS)
-ASXFLAGS = $(MCFLAGS) -Wa,-amhls=$(LSTDIR)/$(notdir $(<:.S=.lst)) $(ADEFS)
-CFLAGS = $(MCFLAGS) $(OPT) $(COPT) $(CWARN) -Wa,-alms=$(LSTDIR)/$(notdir $(<:.c=.lst)) $(DEFS)
-CPPFLAGS = $(MCFLAGS) $(OPT) $(CPPOPT) $(CPPWARN) -Wa,-alms=$(LSTDIR)/$(notdir $(<:.cpp=.lst)) $(DEFS)
-ifeq ($(USE_LINK_GC),yes)
- LDFLAGS = $(MCFLAGS) -Wl,-Map=$(BUILDDIR)/$(PROJECT).map,--cref,--no-warn-mismatch,--gc-sections $(LLIBDIR)
-else
- LDFLAGS = $(MCFLAGS) -Wl,-Map=$(BUILDDIR)/$(PROJECT).map,--cref,--no-warn-mismatch $(LLIBDIR)
-endif
-
-# Generate dependency information
-CFLAGS += -MD -MP -MF .dep/$(@F).d
-CPPFLAGS += -MD -MP -MF .dep/$(@F).d
-
-# Paths where to search for sources
-VPATH = $(SRCPATHS)
-
-#
-# Makefile rules
-#
-
-all: $(OBJS) $(OUTFILES) MAKE_ALL_RULE_HOOK
-
-MAKE_ALL_RULE_HOOK:
-
-$(OBJS): | $(BUILDDIR)
-
-$(BUILDDIR) $(OBJDIR) $(LSTDIR):
-ifneq ($(USE_VERBOSE_COMPILE),yes)
- @echo Compiler Options
- @echo $(CPPC) -c $(CPPFLAGS) -I. $(IINCDIR) main.cpp -o main.o
- @echo
-endif
- mkdir -p $(OBJDIR)
- mkdir -p $(LSTDIR)
-
-$(ACPPOBJS) : $(OBJDIR)/%.o : %.cpp Makefile
-ifeq ($(USE_VERBOSE_COMPILE),yes)
- @echo
- $(CPPC) -c $(CPPFLAGS) $(AOPT) -I. $(IINCDIR) $< -o $@
-else
- @echo Compiling $(/dev/null) $(wildcard .dep/*)
-
-# *** EOF ***
+# ARM Cortex-Mx common makefile scripts and rules.
+
+# Output directory and files
+ifeq ($(BUILDDIR),)
+ BUILDDIR = build
+endif
+ifeq ($(BUILDDIR),.)
+ BUILDDIR = build
+endif
+OUTFILES = $(BUILDDIR)/$(PROJECT)
+
+# Automatic compiler options
+OPT = $(USE_OPT)
+COPT = $(USE_COPT)
+CPPOPT = $(USE_CPPOPT)
+ifeq ($(USE_LINK_GC),yes)
+ OPT += -ffunction-sections -fdata-sections -fno-common
+endif
+
+# Source files groups and paths
+ifeq ($(USE_THUMB),yes)
+ TCSRC += $(CSRC)
+ TCPPSRC += $(CPPSRC)
+else
+ ACSRC += $(CSRC)
+ ACPPSRC += $(CPPSRC)
+endif
+ASRC = $(ACSRC)$(ACPPSRC)
+TSRC = $(TCSRC)$(TCPPSRC)
+SRCPATHS = $(sort $(dir $(ASMXSRC)) $(dir $(ASMSRC)) $(dir $(ASRC)) $(dir $(TSRC)))
+
+# Various directories
+OBJDIR = $(BUILDDIR)/obj
+LSTDIR = $(BUILDDIR)/lst
+
+# Object files groups
+ACOBJS = $(addprefix $(OBJDIR)/, $(notdir $(ACSRC:.c=.o)))
+ACPPOBJS = $(addprefix $(OBJDIR)/, $(notdir $(ACPPSRC:.cpp=.o)))
+TCOBJS = $(addprefix $(OBJDIR)/, $(notdir $(TCSRC:.c=.o)))
+TCPPOBJS = $(addprefix $(OBJDIR)/, $(notdir $(TCPPSRC:.cpp=.o)))
+ASMOBJS = $(addprefix $(OBJDIR)/, $(notdir $(ASMSRC:.s=.o)))
+ASMXOBJS = $(addprefix $(OBJDIR)/, $(notdir $(ASMXSRC:.S=.o)))
+OBJS = $(ASMXOBJS) $(ASMOBJS) $(ACOBJS) $(TCOBJS) $(ACPPOBJS) $(TCPPOBJS)
+
+# Paths
+IINCDIR = $(patsubst %,-I%,$(INCDIR) $(DINCDIR) $(UINCDIR))
+LLIBDIR = $(patsubst %,-L%,$(DLIBDIR) $(ULIBDIR))
+
+# Macros
+DEFS = $(DDEFS) $(UDEFS)
+ADEFS = $(DADEFS) $(UADEFS)
+
+# Libs
+LIBS = $(DLIBS) $(ULIBS)
+
+# Various settings
+#MCFLAGS = -mcpu=$(MCU)
+ODFLAGS = -x --syms
+ASFLAGS = $(MCFLAGS) -Wa,-amhls=$(LSTDIR)/$(notdir $(<:.s=.lst)) $(ADEFS)
+ASXFLAGS = $(MCFLAGS) -Wa,-amhls=$(LSTDIR)/$(notdir $(<:.S=.lst)) $(ADEFS)
+CFLAGS = $(MCFLAGS) $(OPT) $(COPT) $(CWARN) -Wa,-alms=$(LSTDIR)/$(notdir $(<:.c=.lst)) $(DEFS)
+CPPFLAGS = $(MCFLAGS) $(OPT) $(CPPOPT) $(CPPWARN) -Wa,-alms=$(LSTDIR)/$(notdir $(<:.cpp=.lst)) $(DEFS)
+ifeq ($(USE_LINK_GC),yes)
+ LDFLAGS = $(MCFLAGS) -Wl,-Map=$(BUILDDIR)/$(PROJECT).map,--cref,--no-warn-mismatch,--gc-sections $(LLIBDIR)
+else
+ LDFLAGS = $(MCFLAGS) -Wl,-Map=$(BUILDDIR)/$(PROJECT).map,--cref,--no-warn-mismatch $(LLIBDIR)
+endif
+
+# Generate dependency information
+CFLAGS += -MD -MP -MF .dep/$(@F).d
+CPPFLAGS += -MD -MP -MF .dep/$(@F).d
+
+# Paths where to search for sources
+VPATH = $(SRCPATHS)
+
+#
+# Makefile rules
+#
+
+all: $(OBJS) $(OUTFILES) MAKE_ALL_RULE_HOOK
+
+MAKE_ALL_RULE_HOOK:
+
+$(OBJS): | $(BUILDDIR)
+
+$(BUILDDIR) $(OBJDIR) $(LSTDIR):
+ifneq ($(USE_VERBOSE_COMPILE),yes)
+ @echo Compiler Options
+ @echo $(CPPC) -c $(CPPFLAGS) -I. $(IINCDIR) main.cpp -o main.o
+ @echo
+endif
+ mkdir -p $(OBJDIR)
+ mkdir -p $(LSTDIR)
+
+$(ACPPOBJS) : $(OBJDIR)/%.o : %.cpp Makefile
+ifeq ($(USE_VERBOSE_COMPILE),yes)
+ @echo
+ $(CPPC) -c $(CPPFLAGS) $(AOPT) -I. $(IINCDIR) $< -o $@
+else
+ @echo Compiling $(/dev/null) $(wildcard .dep/*)
+
+# *** EOF ***
diff --git a/unit_tests/settings.h b/unit_tests/settings.h
index 31327e150e..208d4ebcf6 100644
--- a/unit_tests/settings.h
+++ b/unit_tests/settings.h
@@ -1,13 +1,13 @@
-/**
- * @file settings.h
- *
- * @date Feb 13, 2014
- * @author Andrey Belomutskiy, (c) 2012-2014
- */
-
-#ifndef SETTINGS_H_
-#define SETTINGS_H_
-
-
-
-#endif /* SETTINGS_H_ */
+/**
+ * @file settings.h
+ *
+ * @date Feb 13, 2014
+ * @author Andrey Belomutskiy, (c) 2012-2014
+ */
+
+#ifndef SETTINGS_H_
+#define SETTINGS_H_
+
+
+
+#endif /* SETTINGS_H_ */
diff --git a/unit_tests/test.mk b/unit_tests/test.mk
index 8929ffc1f6..e983a44c70 100644
--- a/unit_tests/test.mk
+++ b/unit_tests/test.mk
@@ -1,14 +1,15 @@
-TEST_SRC_C = boards.c \
- test_data_structures/test_engine_math.c \
- test_event_registry.c \
- test_basic_math/test_find_index.c \
- test_basic_math/test_interpolation_3d.c \
- test_fuel_map.c \
- test_idle_controller.c \
- test_trigger_decoder.c \
- test_sensors.c \
- test_signal_executor.c
-
-TEST_SRC_CPP = test_util.cpp
-
-
+TEST_SRC_C = boards.c \
+ test_data_structures/test_engine_math.c \
+ test_basic_math/test_find_index.c \
+ test_basic_math/test_interpolation_3d.c \
+ test_idle_controller.c \
+ test_sensors.c
+
+TEST_SRC_CPP = test_util.cpp \
+ test_data_structures/test_event_registry.cpp \
+ test_trigger_decoder.cpp \
+ test_fuel_map.cpp \
+ test_signal_executor.cpp
+
+
+
diff --git a/unit_tests/test_basic_math/test_find_index.c b/unit_tests/test_basic_math/test_find_index.c
index 47d34d851a..1785336c4b 100644
--- a/unit_tests/test_basic_math/test_find_index.c
+++ b/unit_tests/test_basic_math/test_find_index.c
@@ -1,120 +1,120 @@
-/*
- * test_find_index.c
- *
- * Created on: Oct 30, 2013
- * Author: Andrey Belomutskiy, (c) 2012-2013
- */
-
-#include "engine_math.h"
-#include "main.h"
-#include "interpolation.h"
-#include
-#include "engine_configuration.h"
-
-void testFindIndex(void) {
- printf("*************************************************** testFindIndex\r\n");
-
- float array[] = { 1, 2, 3, 4, 5 };
- int size = 4;
- int result;
-
- printf("To the left\r\n");
- result = findIndex(array, size, -1.0);
- assertEquals(-1, result);
-
- printf("To the right4\r\n");
- result = findIndex(array, size, 10.0);
- assertEquals(3, result);
-
- printf("To the right5\r\n");
- result = findIndex(array, 5, 10.0);
- assertEquals(4, result);
-
- printf("On the edge\r\n");
- result = findIndex(array, size, 4.0);
- assertEquals(3, result);
-
- printf("Another1\r\n");
- result = findIndex(array, size, 3.9);
- assertEquals(2, result);
-
- printf("Another2\r\n");
- result = findIndex(array, size, 4.1);
- assertEquals(3, result);
-
- printf("Another3\r\n");
- result = findIndex(array, size, 2);
- assertEquals(1, result);
-
- printf("Left edge1\r\n");
- result = findIndex(array, size, 1);
- assertEquals(0, result);
-
- printf("Left edge2\r\n");
- result = findIndex(array, size, 1.1);
- assertEquals(0, result);
-
- printf("Middle\r\n");
- result = findIndex(array, size, 3);
- assertEquals(2, result);
-
- size = 5; // now test with off array size
-
- printf("Middle2\r\n");
- result = findIndex(array, size, 4);
- assertEquals(3, result);
-
- printf("Middle2\r\n");
- result = findIndex(array, size, 3.1);
- assertEquals(2, result);
-}
-
-//static float getValue2(float key, float maf) {
-//
-//}
-
-void testInterpolate2d(void) {
- printf("*************************************************** testInterpolate2d\r\n");
-
- float bins4[] = { 1, 2, 3, 4 };
- float values4[] = { 1, 20, 30, 400 };
- int size = 4;
-
- int result;
-
- printf("Left size\r\n");
- result = interpolate2d(0, bins4, values4, size);
- assertEquals(1, result);
-
- printf("Right size\r\n");
- result = interpolate2d(10, bins4, values4, size);
- assertEquals(400, result);
-
- printf("Middle1\r\n");
- result = interpolate2d(3, bins4, values4, size);
- assertEquals(30, result);
-
- printf("Middle1\r\n");
- result = interpolate2d(3.5, bins4, values4, size);
- assertEquals(215, result);
-}
-
-static engine_configuration_s engineConfiguration;
-
-void testSetTableValue(void) {
- printf("*************************************************** testSetTableValue\r\n");
-
- for (int i = 0; i < CLT_CURVE_SIZE; i++) {
- engineConfiguration.cltFuelCorrBins[i] = -40 + i * 10;
- engineConfiguration.cltFuelCorr[i] = 1;
- }
-
- assertEquals(1, engineConfiguration.cltFuelCorr[0]);
-
- setTableValue(engineConfiguration.cltFuelCorrBins, engineConfiguration.cltFuelCorr, CLT_CURVE_SIZE, -40, 1.5);
- assertEquals(1.5, engineConfiguration.cltFuelCorr[0]);
-
- setTableValue(engineConfiguration.cltFuelCorrBins, engineConfiguration.cltFuelCorr, CLT_CURVE_SIZE, -50, 1.4);
- assertEquals(1.4, engineConfiguration.cltFuelCorr[0]);
-
-}
+/*
+ * test_find_index.c
+ *
+ * Created on: Oct 30, 2013
+ * Author: Andrey Belomutskiy, (c) 2012-2013
+ */
+
+#include "engine_math.h"
+#include "main.h"
+#include "interpolation.h"
+#include
+#include "engine_configuration.h"
+
+void testFindIndex(void) {
+ printf("*************************************************** testFindIndex\r\n");
+
+ float array[] = { 1, 2, 3, 4, 5 };
+ int size = 4;
+ int result;
+
+ printf("To the left\r\n");
+ result = findIndex(array, size, -1.0);
+ assertEquals(-1, result);
+
+ printf("To the right4\r\n");
+ result = findIndex(array, size, 10.0);
+ assertEquals(3, result);
+
+ printf("To the right5\r\n");
+ result = findIndex(array, 5, 10.0);
+ assertEquals(4, result);
+
+ printf("On the edge\r\n");
+ result = findIndex(array, size, 4.0);
+ assertEquals(3, result);
+
+ printf("Another1\r\n");
+ result = findIndex(array, size, 3.9);
+ assertEquals(2, result);
+
+ printf("Another2\r\n");
+ result = findIndex(array, size, 4.1);
+ assertEquals(3, result);
+
+ printf("Another3\r\n");
+ result = findIndex(array, size, 2);
+ assertEquals(1, result);
+
+ printf("Left edge1\r\n");
+ result = findIndex(array, size, 1);
+ assertEquals(0, result);
+
+ printf("Left edge2\r\n");
+ result = findIndex(array, size, 1.1);
+ assertEquals(0, result);
+
+ printf("Middle\r\n");
+ result = findIndex(array, size, 3);
+ assertEquals(2, result);
+
+ size = 5; // now test with off array size
+
+ printf("Middle2\r\n");
+ result = findIndex(array, size, 4);
+ assertEquals(3, result);
+
+ printf("Middle2\r\n");
+ result = findIndex(array, size, 3.1);
+ assertEquals(2, result);
+}
+
+//static float getValue2(float key, float maf) {
+//
+//}
+
+void testInterpolate2d(void) {
+ printf("*************************************************** testInterpolate2d\r\n");
+
+ float bins4[] = { 1, 2, 3, 4 };
+ float values4[] = { 1, 20, 30, 400 };
+ int size = 4;
+
+ int result;
+
+ printf("Left size\r\n");
+ result = interpolate2d(0, bins4, values4, size);
+ assertEquals(1, result);
+
+ printf("Right size\r\n");
+ result = interpolate2d(10, bins4, values4, size);
+ assertEquals(400, result);
+
+ printf("Middle1\r\n");
+ result = interpolate2d(3, bins4, values4, size);
+ assertEquals(30, result);
+
+ printf("Middle1\r\n");
+ result = interpolate2d(3.5, bins4, values4, size);
+ assertEquals(215, result);
+}
+
+static engine_configuration_s engineConfiguration;
+
+void testSetTableValue(void) {
+ printf("*************************************************** testSetTableValue\r\n");
+
+ for (int i = 0; i < CLT_CURVE_SIZE; i++) {
+ engineConfiguration.cltFuelCorrBins[i] = -40 + i * 10;
+ engineConfiguration.cltFuelCorr[i] = 1;
+ }
+
+ assertEquals(1, engineConfiguration.cltFuelCorr[0]);
+
+ setTableValue(engineConfiguration.cltFuelCorrBins, engineConfiguration.cltFuelCorr, CLT_CURVE_SIZE, -40, 1.5);
+ assertEquals(1.5, engineConfiguration.cltFuelCorr[0]);
+
+ setTableValue(engineConfiguration.cltFuelCorrBins, engineConfiguration.cltFuelCorr, CLT_CURVE_SIZE, -50, 1.4);
+ assertEquals(1.4, engineConfiguration.cltFuelCorr[0]);
+
+}
diff --git a/unit_tests/test_basic_math/test_find_index.h b/unit_tests/test_basic_math/test_find_index.h
index 3a611751c1..b156d57e8e 100644
--- a/unit_tests/test_basic_math/test_find_index.h
+++ b/unit_tests/test_basic_math/test_find_index.h
@@ -1,15 +1,15 @@
-/*
- * test_find_index.h
- *
- * Created on: Oct 30, 2013
- * Author: Andrey Belomutskiy, (c) 2012-2013
- */
-
-#ifndef TEST_FIND_INDEX_H_
-#define TEST_FIND_INDEX_H_
-
-void testFindIndex(void);
-void testInterpolate2d(void);
-void testSetTableValue(void);
-
-#endif /* TEST_FIND_INDEX_H_ */
+/*
+ * test_find_index.h
+ *
+ * Created on: Oct 30, 2013
+ * Author: Andrey Belomutskiy, (c) 2012-2013
+ */
+
+#ifndef TEST_FIND_INDEX_H_
+#define TEST_FIND_INDEX_H_
+
+void testFindIndex(void);
+void testInterpolate2d(void);
+void testSetTableValue(void);
+
+#endif /* TEST_FIND_INDEX_H_ */
diff --git a/unit_tests/test_basic_math/test_interpolation_3d.c b/unit_tests/test_basic_math/test_interpolation_3d.c
index 6fa875b94c..117d1c2073 100644
--- a/unit_tests/test_basic_math/test_interpolation_3d.c
+++ b/unit_tests/test_basic_math/test_interpolation_3d.c
@@ -1,70 +1,70 @@
-/*
- * Created on: Oct 17, 2013
- * Author: Andrey Belomutskiy, (c) 2012-2013
- */
-
-/**
- * @file test_interpolation_3d.c
- */
-
-#include "test_interpolation_3d.h"
-#include
-#include
-
-#include "interpolation.h"
-#include "main.h"
-
-float rpmBins[5] = { 100, 200, 300, 400, 500 };
-float mafBins[4] = { 1, 2, 3, 4 };
-
-float map0[4] = { 1, 2, 3, 4 };
-float map1[4] = { 2, 3, 4, 5 };
-float map2[4] = { 3, 4, 200, 300 };
-float map3[4] = { 4, 200, 500, 600 };
-float map4[4] = { 4, 200, 500, 600 };
-
-float *map[5] = { map0, map1, map2, map3, map4 };
-
-
-static float getValue(float rpm, float maf) {
- return interpolate3d(rpm, rpmBins, 5, maf, mafBins, 4, map);
-}
-
-void testInterpolate3d(void) {
- printf("*************************************************** testInterpolate3d\r\n");
- float dwell;
- printf("*** no interpolation here 1\r\n");
- dwell = getValue(100, 2);
- assertEquals(2, dwell);
-
- printf("*** no interpolation here 2\r\n");
- dwell = getValue(200, 4);
- assertEquals(5, dwell);
-
- printf("*** rpm interpolated value expected1\r\n");
- dwell = getValue(150, 2);
- assertEquals(2.5, dwell);
-
- printf("*** rpm interpolated value expected2\r\n");
- dwell = getValue(250, 3);
- assertEquals(102, dwell);
-
- printf("*** both rpm and maf interpolated value expected\r\n");
- dwell = getValue(335.3, 3.551);
- assertEquals(361, dwell);
-
- printf("*** both rpm and maf interpolated value expected 2\r\n");
- dwell = getValue(410.01, 2.012);
- assertEquals(203.6, dwell);
-
- printf("*** both rpm and maf interpolated value expected 3\r\n");
- dwell = getValue(1000000, 1000);
- assertEquals(600, dwell);
-
- printf("*** both rpm and maf interpolated value expected 4\r\n");
- dwell = getValue(410.01, -1);
- assertEquals(4, dwell);
-
- dwell = getValue(-1, -1);
- assertEquals(1, dwell);
-}
+/*
+ * Created on: Oct 17, 2013
+ * Author: Andrey Belomutskiy, (c) 2012-2013
+ */
+
+/**
+ * @file test_interpolation_3d.c
+ */
+
+#include "test_interpolation_3d.h"
+#include
+#include
+
+#include "interpolation.h"
+#include "main.h"
+
+float rpmBins[5] = { 100, 200, 300, 400, 500 };
+float mafBins[4] = { 1, 2, 3, 4 };
+
+float map0[4] = { 1, 2, 3, 4 };
+float map1[4] = { 2, 3, 4, 5 };
+float map2[4] = { 3, 4, 200, 300 };
+float map3[4] = { 4, 200, 500, 600 };
+float map4[4] = { 4, 200, 500, 600 };
+
+float *map[5] = { map0, map1, map2, map3, map4 };
+
+
+static float getValue(float rpm, float maf) {
+ return interpolate3d(rpm, rpmBins, 5, maf, mafBins, 4, map);
+}
+
+void testInterpolate3d(void) {
+ printf("*************************************************** testInterpolate3d\r\n");
+ float dwell;
+ printf("*** no interpolation here 1\r\n");
+ dwell = getValue(100, 2);
+ assertEquals(2, dwell);
+
+ printf("*** no interpolation here 2\r\n");
+ dwell = getValue(200, 4);
+ assertEquals(5, dwell);
+
+ printf("*** rpm interpolated value expected1\r\n");
+ dwell = getValue(150, 2);
+ assertEquals(2.5, dwell);
+
+ printf("*** rpm interpolated value expected2\r\n");
+ dwell = getValue(250, 3);
+ assertEquals(102, dwell);
+
+ printf("*** both rpm and maf interpolated value expected\r\n");
+ dwell = getValue(335.3, 3.551);
+ assertEquals(361, dwell);
+
+ printf("*** both rpm and maf interpolated value expected 2\r\n");
+ dwell = getValue(410.01, 2.012);
+ assertEquals(203.6, dwell);
+
+ printf("*** both rpm and maf interpolated value expected 3\r\n");
+ dwell = getValue(1000000, 1000);
+ assertEquals(600, dwell);
+
+ printf("*** both rpm and maf interpolated value expected 4\r\n");
+ dwell = getValue(410.01, -1);
+ assertEquals(4, dwell);
+
+ dwell = getValue(-1, -1);
+ assertEquals(1, dwell);
+}
diff --git a/unit_tests/test_basic_math/test_interpolation_3d.h b/unit_tests/test_basic_math/test_interpolation_3d.h
index 684c26ba74..d5f208743c 100644
--- a/unit_tests/test_basic_math/test_interpolation_3d.h
+++ b/unit_tests/test_basic_math/test_interpolation_3d.h
@@ -1,16 +1,16 @@
-/*
- * Created on: Oct 17, 2013
- * Author: Andrey Belomutskiy, (c) 2012-2013
- */
-
-/**
- * @file test_interpolation_3d.h
- */
-
-
-#ifndef TEST_INTERPOLATION_3D_H_
-#define TEST_INTERPOLATION_3D_H_
-
-void testInterpolate3d(void);
-
-#endif /* TEST_INTERPOLATION_3D_H_ */
+/*
+ * Created on: Oct 17, 2013
+ * Author: Andrey Belomutskiy, (c) 2012-2013
+ */
+
+/**
+ * @file test_interpolation_3d.h
+ */
+
+
+#ifndef TEST_INTERPOLATION_3D_H_
+#define TEST_INTERPOLATION_3D_H_
+
+void testInterpolate3d(void);
+
+#endif /* TEST_INTERPOLATION_3D_H_ */
diff --git a/unit_tests/test_data_structures/test_event_registry.h b/unit_tests/test_data_structures/test_event_registry.h
index 593a291844..28c5e31dfb 100644
--- a/unit_tests/test_data_structures/test_event_registry.h
+++ b/unit_tests/test_data_structures/test_event_registry.h
@@ -1,13 +1,22 @@
-/*
- * test_event_registry.h
- *
- * Created on: Nov 27, 2013
- * Author: Andrey Belomutskiy, (c) 2012-2013
- */
-
-#ifndef TEST_EVENT_REGISTRY_H_
-#define TEST_EVENT_REGISTRY_H_
-
-void testEventRegistry(void);
-
-#endif /* TEST_EVENT_REGISTRY_H_ */
+/*
+ * test_event_registry.h
+ *
+ * Created on: Nov 27, 2013
+ * Author: Andrey Belomutskiy, (c) 2012-2013
+ */
+
+#ifndef TEST_EVENT_REGISTRY_H_
+#define TEST_EVENT_REGISTRY_H_
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+void testEventRegistry(void);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* TEST_EVENT_REGISTRY_H_ */
diff --git a/unit_tests/test_engine_math.c b/unit_tests/test_engine_math.c
index b2898892c7..f6deca3558 100644
--- a/unit_tests/test_engine_math.c
+++ b/unit_tests/test_engine_math.c
@@ -1,27 +1,27 @@
-/*
- * @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"
-
-extern engine_configuration_s *engineConfiguration;
-extern engine_configuration2_s *engineConfiguration2;
-
-void testEngineMath(void) {
- printf("*************************************************** testEngineMath\r\n");
-
- engineConfiguration->rpmMultiplier = 0.5;
-
- assertEqualsM("600 RPM", 5000, getOneDegreeTime(600) * 180);
- assertEqualsM("6000 RPM", 500, getOneDegreeTime(6000) * 180);
-}
-
-float getMap(void) {
- return 0;
-}
+/*
+ * @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"
+
+extern engine_configuration_s *engineConfiguration;
+extern engine_configuration2_s *engineConfiguration2;
+
+void testEngineMath(void) {
+ printf("*************************************************** testEngineMath\r\n");
+
+ engineConfiguration->rpmMultiplier = 0.5;
+
+ assertEqualsM("600 RPM", 5000, getOneDegreeTime(600) * 180);
+ assertEqualsM("6000 RPM", 500, getOneDegreeTime(6000) * 180);
+}
+
+float getMap(void) {
+ return 0;
+}
diff --git a/unit_tests/test_engine_math.h b/unit_tests/test_engine_math.h
index 8f80cc7f41..0ca049a2f0 100644
--- a/unit_tests/test_engine_math.h
+++ b/unit_tests/test_engine_math.h
@@ -1,13 +1,13 @@
-/*
- * @file test_engine_math.h
- *
- * Created on: Nov 14, 2013
- * Author: Andrey Belomutskiy, (c) 2012-2013
- */
-
-#ifndef TEST_ENGINE_MATH_H_
-#define TEST_ENGINE_MATH_H_
-
-void testEngineMath(void);
-
-#endif /* TEST_ENGINE_MATH_H_ */
+/*
+ * @file test_engine_math.h
+ *
+ * Created on: Nov 14, 2013
+ * Author: Andrey Belomutskiy, (c) 2012-2013
+ */
+
+#ifndef TEST_ENGINE_MATH_H_
+#define TEST_ENGINE_MATH_H_
+
+void testEngineMath(void);
+
+#endif /* TEST_ENGINE_MATH_H_ */
diff --git a/unit_tests/test_fuel_map.h b/unit_tests/test_fuel_map.h
index 4f68e7daf5..e0c08dcb2d 100644
--- a/unit_tests/test_fuel_map.h
+++ b/unit_tests/test_fuel_map.h
@@ -1,15 +1,24 @@
-/*
- * test_fuel_map.h
- *
- * Created on: Nov 6, 2013
- * Author: pc
- */
-
-#ifndef TEST_FUEL_MAP_H_
-#define TEST_FUEL_MAP_H_
-
-void testFuelMap(void);
-void testAngleResolver(void);
-void testPinHelper(void);
-
-#endif /* TEST_FUEL_MAP_H_ */
+/*
+ * test_fuel_map.h
+ *
+ * Created on: Nov 6, 2013
+ * Author: pc
+ */
+
+#ifndef TEST_FUEL_MAP_H_
+#define TEST_FUEL_MAP_H_
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+void testFuelMap(void);
+void testAngleResolver(void);
+void testPinHelper(void);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* TEST_FUEL_MAP_H_ */
diff --git a/unit_tests/test_idle_controller.c b/unit_tests/test_idle_controller.c
index 8150a638fe..d8fa0e8b25 100644
--- a/unit_tests/test_idle_controller.c
+++ b/unit_tests/test_idle_controller.c
@@ -1,17 +1,17 @@
-/*
- * test_idle_controller.c
- *
- * Created on: Oct 17, 2013
- * Author: Andrey
- */
-
-#include
-
-
-void idleDebug(char *msg, int value) {
- printf("%s\r\n", msg);
-}
-
-void isCranking(void) {
- return;
-}
+/*
+ * test_idle_controller.c
+ *
+ * Created on: Oct 17, 2013
+ * Author: Andrey
+ */
+
+#include
+
+
+void idleDebug(char *msg, int value) {
+ printf("%s\r\n", msg);
+}
+
+void isCranking(void) {
+ return;
+}
diff --git a/unit_tests/test_idle_controller.h b/unit_tests/test_idle_controller.h
index ff3aa90ac1..75a204acaf 100644
--- a/unit_tests/test_idle_controller.h
+++ b/unit_tests/test_idle_controller.h
@@ -1,7 +1,7 @@
-#ifndef TEST_IDLE_CONTROLLER_H
-#define TEST_IDLE_CONTROLLER_H
-
-void idleDebug(char *msg, int value);
-void isCranking(void);
-
-#endif
+#ifndef TEST_IDLE_CONTROLLER_H
+#define TEST_IDLE_CONTROLLER_H
+
+void idleDebug(char *msg, int value);
+void isCranking(void);
+
+#endif
diff --git a/unit_tests/test_sensors.c b/unit_tests/test_sensors.c
index cf4a72c7df..33c8bb43a8 100644
--- a/unit_tests/test_sensors.c
+++ b/unit_tests/test_sensors.c
@@ -1,35 +1,52 @@
-/**
- * @file test_sensors.c
- *
- * @date Dec 7, 2013
- * @author Andrey Belomutskiy, (c) 2012-2013
- */
-
-#include "main.h"
-#include "thermistors.h"
-#include "map.h"
-
-static ThermistorConf tc;
-
-static void testMapDecoding() {
- assertEqualsM("denso 0 volts", -6.64, getMAPValueHonda_Denso183(0));
- assertEquals(31.244, getMAPValueHonda_Denso183(1));
-
- assertEqualsM("MPX_4250 0 volts", 8, getMAPValueMPX_4250(0));
- assertEquals(58.4, getMAPValueMPX_4250(1));
-}
-
-void testSensors(void) {
- print("************************************************** testSensors\r\n");
- testMapDecoding();
- setThermistorConfiguration(&tc, 32, 9500, 75, 2100, 120, 1000);
-
- prepareThermistorCurve(&tc);
-
- assertEquals(-0.003, tc.s_h_a);
- assertEquals(0.001, tc.s_h_b);
- assertEquals(0.0, tc.s_h_c);
-
- float t = convertResistanceToKelvinTemperature(2100, &tc);
- assertEquals(75 + KELV, t);
-}
+/**
+ * @file test_sensors.c
+ *
+ * @date Dec 7, 2013
+ * @author Andrey Belomutskiy, (c) 2012-2013
+ */
+
+#include "main.h"
+#include "thermistors.h"
+#include "allsensors.h"
+
+static ThermistorConf tc;
+
+static void testMapDecoding(void) {
+ assertEqualsM("denso 0 volts", -6.64, getMAPValueHonda_Denso183(0));
+ assertEquals(31.244, getMAPValueHonda_Denso183(1));
+
+ assertEqualsM("MPX_4250 0 volts", 8, getMAPValueMPX_4250(0));
+ assertEquals(58.4, getMAPValueMPX_4250(1));
+}
+
+void testTpsRateOfChange(void) {
+ print("************************************************** testTpsRateOfChange\r\n");
+ saveTpsState(0, 0);
+ saveTpsState(CH_FREQUENCY, 50);
+ assertEquals(50, getTpsRateOfChange());
+
+ saveTpsState(2 * CH_FREQUENCY, 50);
+ assertEquals(0, getTpsRateOfChange());
+
+ saveTpsState(3 * CH_FREQUENCY, 75);
+ assertEquals(25, getTpsRateOfChange());
+
+
+}
+
+void testSensors(void) {
+ print("************************************************** testSensors\r\n");
+ testMapDecoding();
+ testTpsRateOfChange();
+
+ setThermistorConfiguration(&tc, 32, 9500, 75, 2100, 120, 1000);
+
+ prepareThermistorCurve(&tc);
+
+ assertEquals(-0.003, tc.s_h_a);
+ assertEquals(0.001, tc.s_h_b);
+ assertEquals(0.0, tc.s_h_c);
+
+ float t = convertResistanceToKelvinTemperature(2100, &tc);
+ assertEquals(75 + KELV, t);
+}
diff --git a/unit_tests/test_sensors.h b/unit_tests/test_sensors.h
index b59fd418fd..4f82601d16 100644
--- a/unit_tests/test_sensors.h
+++ b/unit_tests/test_sensors.h
@@ -1,13 +1,13 @@
-/**
- * @file test_sensors.h
- *
- * @date Dec 7, 2013
- * @author Andrey Belomutskiy, (c) 2012-2013
- */
-
-#ifndef TEST_SENSORS_H_
-#define TEST_SENSORS_H_
-
-void testSensors(void);
-
-#endif /* TEST_SENSORS_H_ */
+/**
+ * @file test_sensors.h
+ *
+ * @date Dec 7, 2013
+ * @author Andrey Belomutskiy, (c) 2012-2013
+ */
+
+#ifndef TEST_SENSORS_H_
+#define TEST_SENSORS_H_
+
+void testSensors(void);
+
+#endif /* TEST_SENSORS_H_ */
diff --git a/unit_tests/test_signal_executor.h b/unit_tests/test_signal_executor.h
index e61fcf3b38..141bde5957 100644
--- a/unit_tests/test_signal_executor.h
+++ b/unit_tests/test_signal_executor.h
@@ -1,13 +1,23 @@
-/**
- * @file test_signal_executor.h
- *
- * @date Nov 28, 2013
- * @author Andrey Belomutskiy, (c) 2012-2013
- */
-
-#ifndef TEST_SIGNAL_EXECUTOR_H_
-#define TEST_SIGNAL_EXECUTOR_H_
-
-void testSignalExecutor(void);
-
-#endif /* TEST_SIGNAL_EXECUTOR_H_ */
+/**
+ * @file test_signal_executor.h
+ *
+ * @date Nov 28, 2013
+ * @author Andrey Belomutskiy, (c) 2012-2013
+ */
+
+#ifndef TEST_SIGNAL_EXECUTOR_H_
+#define TEST_SIGNAL_EXECUTOR_H_
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+void testSignalExecutor(void);
+int getRevolutionCounter(void);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* TEST_SIGNAL_EXECUTOR_H_ */
diff --git a/unit_tests/test_trigger_decoder.h b/unit_tests/test_trigger_decoder.h
index 916227865c..0a06b7e352 100644
--- a/unit_tests/test_trigger_decoder.h
+++ b/unit_tests/test_trigger_decoder.h
@@ -1,13 +1,13 @@
-/**
- * @file test_trigger_decoder.h
- *
- * @date Dec 24, 2013
- * @author Andrey Belomutskiy, (c) 2012-2013
- */
-
-#ifndef TEST_TRIGGER_DECODER_H_
-#define TEST_TRIGGER_DECODER_H_
-
-void testTriggerDecoder(void);
-
-#endif /* TEST_TRIGGER_DECODER_H_ */
+/**
+ * @file test_trigger_decoder.h
+ *
+ * @date Dec 24, 2013
+ * @author Andrey Belomutskiy, (c) 2012-2013
+ */
+
+#ifndef TEST_TRIGGER_DECODER_H_
+#define TEST_TRIGGER_DECODER_H_
+
+void testTriggerDecoder(void);
+
+#endif /* TEST_TRIGGER_DECODER_H_ */
diff --git a/unit_tests/test_util.cpp b/unit_tests/test_util.cpp
index c04bfb6374..b62b9ec7dd 100644
--- a/unit_tests/test_util.cpp
+++ b/unit_tests/test_util.cpp
@@ -1,278 +1,294 @@
-/**
- * @file test_util.c
- *
- * @date Dec 8, 2013
- * @author Andrey Belomutskiy, (c) 2012-2013
- */
-
-#include
-
-#include "test_util.h"
-#include "cyclic_buffer.h"
-#include "main.h"
-#include "histogram.h"
-
-#include "malfunction_central.h"
-#include "eficonsole_logic.h"
-
-#include "nmea.h"
-
-static cyclic_buffer sb;
-
-
-void testCyclicBuffer(void) {
- print("*************************************** testCyclicBuffer\r\n");
-
- sb.add(10);
-
- assertEquals(10, sb.sum(3));
-
- sb.add(2);
- assertEquals(12, sb.sum(2));
-}
-
-void testHistogram(void) {
- print("******************************************* testHistogram\r\n");
-
- initHistogramsModule();
-
- assertEquals(80, histogramGetIndex(239));
- assertEquals(223, histogramGetIndex(239239));
- assertEquals(364, histogramGetIndex(239239239));
-
- histogram_s h;
-
- initHistogram(&h, "test");
-
- int result[5];
- assertEquals(0, hsReport(&h, result));
-
- hsAdd(&h, 10);
- assertEquals(1, hsReport(&h, result));
- assertEquals(10, result[0]);
-
- // let's add same value one more time
- hsAdd(&h, 10);
- assertEquals(2, hsReport(&h, result));
- assertEquals(10, result[0]);
- assertEquals(10, result[1]);
-
- hsAdd(&h, 10);
- hsAdd(&h, 10);
- hsAdd(&h, 10);
-
- hsAdd(&h, 1000);
- hsAdd(&h, 100);
-
- assertEquals(5, hsReport(&h, result));
-
- assertEquals(5, result[0]);
- assertEquals(10, result[1]);
- assertEquals(10, result[2]);
- assertEquals(100, result[3]);
- // values are not expected to be exactly the same, it's the shape what matters
- assertEquals(1011, result[4]);
-}
-
-static void testMalfunctionCentralRemoveNonExistent() {
- print("******************************************* testMalfunctionCentralRemoveNonExistent\r\n");
- initMalfunctionCentral();
-
- // this should not crash
- removeError(OBD_Engine_Coolant_Temperature_Circuit_Malfunction);
-}
-
-static void testMalfunctionCentralSameElementAgain() {
- initMalfunctionCentral();
- print("******************************************* testMalfunctionCentralSameElementAgain\r\n");
- error_codes_set_s localCopy;
-
- addError(OBD_Engine_Coolant_Temperature_Circuit_Malfunction);
- addError(OBD_Engine_Coolant_Temperature_Circuit_Malfunction);
- getErrorCodes(&localCopy);
- assertEquals(1, localCopy.count);
-}
-
-static void testMalfunctionCentralRemoveFirstElement() {
- initMalfunctionCentral();
- print("******************************************* testMalfunctionCentralRemoveFirstElement\r\n");
- error_codes_set_s localCopy;
-
- obd_code_e firstElement = OBD_Engine_Coolant_Temperature_Circuit_Malfunction;
- addError(firstElement);
-
- obd_code_e secondElement = OBD_Intake_Air_Temperature_Circuit_Malfunction;
- addError(secondElement);
- getErrorCodes(&localCopy);
- assertEquals(2, localCopy.count);
-
- // let's remove first element - code
- removeError(firstElement);
-
- getErrorCodes(&localCopy);
- assertEquals(1, localCopy.count);
- assertEquals(secondElement, localCopy.error_codes[0]);
-}
-
-void testMalfunctionCentral(void) {
- testMalfunctionCentralRemoveNonExistent();
- testMalfunctionCentralSameElementAgain();
- testMalfunctionCentralRemoveFirstElement();
-
- print("******************************************* testMalfunctionCentral\r\n");
- initMalfunctionCentral();
-
- error_codes_set_s localCopy;
-
- // on start-up error storage should be empty
- getErrorCodes(&localCopy);
- assertEquals(0, localCopy.count);
-
- obd_code_e code = OBD_Engine_Coolant_Temperature_Circuit_Malfunction;
- // let's add one error and validate
- addError(code);
-
- getErrorCodes(&localCopy);
- assertEqualsM("count #1", 1, localCopy.count);
- assertEquals(code, localCopy.error_codes[0]);
-
- // let's remove value which is not in the collection
- removeError((obd_code_e)22);
- // element not present - nothing to removed
- assertEquals(1, localCopy.count);
- assertEquals(code, localCopy.error_codes[0]);
-
- code = OBD_Intake_Air_Temperature_Circuit_Malfunction;
- addError(code);
- getErrorCodes(&localCopy);
- // todo: assertEquals(2, localCopy.count);
-
- for (int code = 0; code < 100; code++) {
- addError((obd_code_e) code);
- }
- getErrorCodes(&localCopy);
- assertEquals(MAX_ERROR_CODES_COUNT, localCopy.count);
-
- // now we have full array and code below present
- removeError(code);
- getErrorCodes(&localCopy);
- assertEquals(MAX_ERROR_CODES_COUNT - 1, localCopy.count);
-}
-
-static int lastInteger = -1;
-static int lastInteger2 = -1;
-
-static void testEchoI(int param) {
- lastInteger = param;
-}
-
-static void testEchoII(int param, int param2) {
- lastInteger = param;
- lastInteger2 = param2;
-}
-
-static char *lastFirst = NULL;
-static char *lastThird = NULL;
-
-static void testEchoSSS(char *first, char *second, char *third) {
- lastFirst = first;
- lastThird = third;
-}
-
-#define UNKNOWN_COMMAND "dfadasdasd"
-
-static loc_t GPSdata;
-
-static char nmeaMessage[1000];
-
-void testGpsParser(void) {
- print("******************************************* testGpsParser\r\n");
-
- strcpy(nmeaMessage, "");
- gps_location(&GPSdata, nmeaMessage);
-
- // we need to pass a mutable string, not a constant because the parser would be modifying the string
- strcpy(nmeaMessage, "$GPRMC,173843,A,3349.896,N,11808.521,W,000.0,360.0,230108,013.4,E*69");
- gps_location(&GPSdata, nmeaMessage);
- assertEqualsM("1 valid", 4, GPSdata.quality);
- assertEqualsM("1 latitude", 3349.896, GPSdata.latitude);
- assertEqualsM("1 longitude", 11808.521, GPSdata.longitude);
- assertEqualsM("1 speed", 0, GPSdata.speed);
-// assertEqualsM("1 altitude", 0, GPSdata.altitude); // GPRMC not overwrite altitude
- assertEqualsM("1 course", 360, GPSdata.course);
-
- strcpy(nmeaMessage, "$GPGGA,111609.14,5001.27,N,3613.06,E,3,08,0.0,10.2,M,0.0,M,0.0,0000*70");
- gps_location(&GPSdata, nmeaMessage);
- assertEqualsM("2 valid", 3, GPSdata.quality); // see field details
- assertEqualsM("2 latitude", 50.0212, GPSdata.latitude);
- assertEqualsM("2 longitude", 36.2177, GPSdata.longitude);
- assertEqualsM("2 speed", 0, GPSdata.speed);
- assertEqualsM("2 altitude", 10.2, GPSdata.altitude);
-// assertEqualsM("2 course", 0, GPSdata.course); // GPGGA not overwrite course
-
- strcpy(nmeaMessage, "$GPRMC,111609.14,A,5001.27,N,3613.06,E,11.2,0.0,261206,0.0,E*50");
- gps_location(&GPSdata, nmeaMessage);
- assertEqualsM("3 valid", 4, GPSdata.quality);
- assertEqualsM("3 latitude", 5001.27, GPSdata.latitude);
- assertEqualsM("3 longitude", 3613.06, GPSdata.longitude);
- assertEqualsM("3 speed", 11.2, GPSdata.speed);
-// assertEqualsM("3 altitude", 0, GPSdata.altitude); // GPRMC not overwrite altitude
- assertEqualsM("3 course", 0, GPSdata.course);
- assertEqualsM("3 GPS yy",2006, GPSdata.GPStm.tm_year+1900);
- assertEqualsM("3 GPS mm",12, GPSdata.GPStm.tm_mon);
- assertEqualsM("3 GPS yy",26, GPSdata.GPStm.tm_mday);
- assertEqualsM("3 GPS hh",11, GPSdata.GPStm.tm_hour);
- assertEqualsM("3 GPS mm",16, GPSdata.GPStm.tm_min);
- assertEqualsM("3 GPS ss",9, GPSdata.GPStm.tm_sec);
-
- // check again first one
- // we need to pass a mutable string, not a constant because the parser would be modifying the string
- strcpy(nmeaMessage, "$GPRMC,173843,A,3349.896,N,11808.521,W,000.0,360.0,230108,013.4,E*69");
- gps_location(&GPSdata, nmeaMessage);
- assertEqualsM("4 valid", 4, GPSdata.quality);
- assertEqualsM("4 latitude", 3349.896, GPSdata.latitude);
- assertEqualsM("4 longitude", 11808.521, GPSdata.longitude);
- assertEqualsM("4 speed", 0, GPSdata.speed);
- assertEqualsM("4 course", 360, GPSdata.course);
-}
-
-// this buffer is needed because on Unix you would not be able to change static char constants
-static char buffer[300];
-
-void testConsoleLogic(void) {
- print("******************************************* testConsoleLogic\r\n");
- resetConsoleActions();
-
- helpCommand();
-
- char *ptr = validateSecureLine(UNKNOWN_COMMAND);
- assertEquals(0, strcmp(UNKNOWN_COMMAND, ptr));
- assertEquals(10, tokenLength(UNKNOWN_COMMAND));
-
- // handling invalid token should work
- strcpy(buffer, "sdasdafasd asd");
- handleConsoleLine(buffer);
-
- print("\r\naddConsoleActionI\r\n");
- addConsoleActionI("echoi", testEchoI);
- strcpy(buffer, "echoi 239");
- handleConsoleLine(buffer);
- assertEquals(239, lastInteger);
-
- print("\r\naddConsoleActionII\r\n");
- addConsoleActionII("echoii", testEchoII);
- strcpy(buffer, "echoii 22 239");
- handleConsoleLine(buffer);
- assertEquals(22, lastInteger);
- assertEquals(239, lastInteger2);
-
- print("\r\addConsoleActionSSS\r\n");
- addConsoleActionSSS("echosss", testEchoSSS);
- strcpy(buffer, "echosss 111 222 333");
- handleConsoleLine(buffer);
- assertEquals(111, atoi(lastFirst));
- assertEquals(333, atoi(lastThird));
-
- //addConsoleActionSSS("GPS", testGpsParser);
-}
-
+/**
+ * @file test_util.c
+ *
+ * @date Dec 8, 2013
+ * @author Andrey Belomutskiy, (c) 2012-2013
+ */
+
+#include
+
+#include "test_util.h"
+#include "cyclic_buffer.h"
+#include "main.h"
+#include "histogram.h"
+
+#include "malfunction_central.h"
+#include "eficonsole_logic.h"
+
+#include "nmea.h"
+#include "efilib2.h"
+
+static cyclic_buffer sb;
+
+
+void testOverflow64Counter(void) {
+ print("*************************************** testOverflow64Counter\r\n");
+
+ Overflow64Counter o;
+ assertEquals(0, o.get());
+ o.offer(10);
+ assertEquals(10, o.get());
+
+ o.offer(20);
+ assertEquals(20, o.get());
+
+ o.offer(0); // overflow
+ assertEquals(4294967296, o.get());
+}
+
+void testCyclicBuffer(void) {
+ print("*************************************** testCyclicBuffer\r\n");
+
+ sb.add(10);
+
+ assertEquals(10, sb.sum(3));
+
+ sb.add(2);
+ assertEquals(12, sb.sum(2));
+}
+
+void testHistogram(void) {
+ print("******************************************* testHistogram\r\n");
+
+ initHistogramsModule();
+
+ assertEquals(80, histogramGetIndex(239));
+ assertEquals(223, histogramGetIndex(239239));
+ assertEquals(364, histogramGetIndex(239239239));
+
+ histogram_s h;
+
+ initHistogram(&h, "test");
+
+ int result[5];
+ assertEquals(0, hsReport(&h, result));
+
+ hsAdd(&h, 10);
+ assertEquals(1, hsReport(&h, result));
+ assertEquals(10, result[0]);
+
+ // let's add same value one more time
+ hsAdd(&h, 10);
+ assertEquals(2, hsReport(&h, result));
+ assertEquals(10, result[0]);
+ assertEquals(10, result[1]);
+
+ hsAdd(&h, 10);
+ hsAdd(&h, 10);
+ hsAdd(&h, 10);
+
+ hsAdd(&h, 1000);
+ hsAdd(&h, 100);
+
+ assertEquals(5, hsReport(&h, result));
+
+ assertEquals(5, result[0]);
+ assertEquals(10, result[1]);
+ assertEquals(10, result[2]);
+ assertEquals(100, result[3]);
+ // values are not expected to be exactly the same, it's the shape what matters
+ assertEquals(1011, result[4]);
+}
+
+static void testMalfunctionCentralRemoveNonExistent() {
+ print("******************************************* testMalfunctionCentralRemoveNonExistent\r\n");
+ initMalfunctionCentral();
+
+ // this should not crash
+ removeError(OBD_Engine_Coolant_Temperature_Circuit_Malfunction);
+}
+
+static void testMalfunctionCentralSameElementAgain() {
+ initMalfunctionCentral();
+ print("******************************************* testMalfunctionCentralSameElementAgain\r\n");
+ error_codes_set_s localCopy;
+
+ addError(OBD_Engine_Coolant_Temperature_Circuit_Malfunction);
+ addError(OBD_Engine_Coolant_Temperature_Circuit_Malfunction);
+ getErrorCodes(&localCopy);
+ assertEquals(1, localCopy.count);
+}
+
+static void testMalfunctionCentralRemoveFirstElement() {
+ initMalfunctionCentral();
+ print("******************************************* testMalfunctionCentralRemoveFirstElement\r\n");
+ error_codes_set_s localCopy;
+
+ obd_code_e firstElement = OBD_Engine_Coolant_Temperature_Circuit_Malfunction;
+ addError(firstElement);
+
+ obd_code_e secondElement = OBD_Intake_Air_Temperature_Circuit_Malfunction;
+ addError(secondElement);
+ getErrorCodes(&localCopy);
+ assertEquals(2, localCopy.count);
+
+ // let's remove first element - code
+ removeError(firstElement);
+
+ getErrorCodes(&localCopy);
+ assertEquals(1, localCopy.count);
+ assertEquals(secondElement, localCopy.error_codes[0]);
+}
+
+void testMalfunctionCentral(void) {
+ testMalfunctionCentralRemoveNonExistent();
+ testMalfunctionCentralSameElementAgain();
+ testMalfunctionCentralRemoveFirstElement();
+
+ print("******************************************* testMalfunctionCentral\r\n");
+ initMalfunctionCentral();
+
+ error_codes_set_s localCopy;
+
+ // on start-up error storage should be empty
+ getErrorCodes(&localCopy);
+ assertEquals(0, localCopy.count);
+
+ obd_code_e code = OBD_Engine_Coolant_Temperature_Circuit_Malfunction;
+ // let's add one error and validate
+ addError(code);
+
+ getErrorCodes(&localCopy);
+ assertEqualsM("count #1", 1, localCopy.count);
+ assertEquals(code, localCopy.error_codes[0]);
+
+ // let's remove value which is not in the collection
+ removeError((obd_code_e)22);
+ // element not present - nothing to removed
+ assertEquals(1, localCopy.count);
+ assertEquals(code, localCopy.error_codes[0]);
+
+ code = OBD_Intake_Air_Temperature_Circuit_Malfunction;
+ addError(code);
+ getErrorCodes(&localCopy);
+ // todo: assertEquals(2, localCopy.count);
+
+ for (int code = 0; code < 100; code++) {
+ addError((obd_code_e) code);
+ }
+ getErrorCodes(&localCopy);
+ assertEquals(MAX_ERROR_CODES_COUNT, localCopy.count);
+
+ // now we have full array and code below present
+ removeError(code);
+ getErrorCodes(&localCopy);
+ assertEquals(MAX_ERROR_CODES_COUNT - 1, localCopy.count);
+}
+
+static int lastInteger = -1;
+static int lastInteger2 = -1;
+
+static void testEchoI(int param) {
+ lastInteger = param;
+}
+
+static void testEchoII(int param, int param2) {
+ lastInteger = param;
+ lastInteger2 = param2;
+}
+
+static char *lastFirst = NULL;
+static char *lastThird = NULL;
+
+static void testEchoSSS(char *first, char *second, char *third) {
+ lastFirst = first;
+ lastThird = third;
+}
+
+#define UNKNOWN_COMMAND "dfadasdasd"
+
+static loc_t GPSdata;
+
+static char nmeaMessage[1000];
+
+void testGpsParser(void) {
+ print("******************************************* testGpsParser\r\n");
+
+ strcpy(nmeaMessage, "");
+ gps_location(&GPSdata, nmeaMessage);
+
+ // we need to pass a mutable string, not a constant because the parser would be modifying the string
+ strcpy(nmeaMessage, "$GPRMC,173843,A,3349.896,N,11808.521,W,000.0,360.0,230108,013.4,E*69");
+ gps_location(&GPSdata, nmeaMessage);
+ assertEqualsM("1 valid", 4, GPSdata.quality);
+ assertEqualsM("1 latitude", 3349.896, GPSdata.latitude);
+ assertEqualsM("1 longitude", 11808.521, GPSdata.longitude);
+ assertEqualsM("1 speed", 0, GPSdata.speed);
+// assertEqualsM("1 altitude", 0, GPSdata.altitude); // GPRMC not overwrite altitude
+ assertEqualsM("1 course", 360, GPSdata.course);
+
+ strcpy(nmeaMessage, "$GPGGA,111609.14,5001.27,N,3613.06,E,3,08,0.0,10.2,M,0.0,M,0.0,0000*70");
+ gps_location(&GPSdata, nmeaMessage);
+ assertEqualsM("2 valid", 3, GPSdata.quality); // see field details
+ assertEqualsM("2 latitude", 50.0212, GPSdata.latitude);
+ assertEqualsM("2 longitude", 36.2177, GPSdata.longitude);
+ assertEqualsM("2 speed", 0, GPSdata.speed);
+ assertEqualsM("2 altitude", 10.2, GPSdata.altitude);
+// assertEqualsM("2 course", 0, GPSdata.course); // GPGGA not overwrite course
+
+ strcpy(nmeaMessage, "$GPRMC,111609.14,A,5001.27,N,3613.06,E,11.2,0.0,261206,0.0,E*50");
+ gps_location(&GPSdata, nmeaMessage);
+ assertEqualsM("3 valid", 4, GPSdata.quality);
+ assertEqualsM("3 latitude", 5001.27, GPSdata.latitude);
+ assertEqualsM("3 longitude", 3613.06, GPSdata.longitude);
+ assertEqualsM("3 speed", 11.2, GPSdata.speed);
+// assertEqualsM("3 altitude", 0, GPSdata.altitude); // GPRMC not overwrite altitude
+ assertEqualsM("3 course", 0, GPSdata.course);
+ assertEqualsM("3 GPS yy",2006, GPSdata.GPStm.tm_year+1900);
+ assertEqualsM("3 GPS mm",12, GPSdata.GPStm.tm_mon);
+ assertEqualsM("3 GPS yy",26, GPSdata.GPStm.tm_mday);
+ assertEqualsM("3 GPS hh",11, GPSdata.GPStm.tm_hour);
+ assertEqualsM("3 GPS mm",16, GPSdata.GPStm.tm_min);
+ assertEqualsM("3 GPS ss",9, GPSdata.GPStm.tm_sec);
+
+ // check again first one
+ // we need to pass a mutable string, not a constant because the parser would be modifying the string
+ strcpy(nmeaMessage, "$GPRMC,173843,A,3349.896,N,11808.521,W,000.0,360.0,230108,013.4,E*69");
+ gps_location(&GPSdata, nmeaMessage);
+ assertEqualsM("4 valid", 4, GPSdata.quality);
+ assertEqualsM("4 latitude", 3349.896, GPSdata.latitude);
+ assertEqualsM("4 longitude", 11808.521, GPSdata.longitude);
+ assertEqualsM("4 speed", 0, GPSdata.speed);
+ assertEqualsM("4 course", 360, GPSdata.course);
+}
+
+// this buffer is needed because on Unix you would not be able to change static char constants
+static char buffer[300];
+
+void testConsoleLogic(void) {
+ print("******************************************* testConsoleLogic\r\n");
+ resetConsoleActions();
+
+ helpCommand();
+
+ char *ptr = validateSecureLine(UNKNOWN_COMMAND);
+ assertEquals(0, strcmp(UNKNOWN_COMMAND, ptr));
+ assertEquals(10, tokenLength(UNKNOWN_COMMAND));
+
+ // handling invalid token should work
+ strcpy(buffer, "sdasdafasd asd");
+ handleConsoleLine(buffer);
+
+ print("\r\naddConsoleActionI\r\n");
+ addConsoleActionI("echoi", testEchoI);
+ strcpy(buffer, "echoi 239");
+ handleConsoleLine(buffer);
+ assertEquals(239, lastInteger);
+
+ print("\r\naddConsoleActionII\r\n");
+ addConsoleActionII("echoii", testEchoII);
+ strcpy(buffer, "echoii 22 239");
+ handleConsoleLine(buffer);
+ assertEquals(22, lastInteger);
+ assertEquals(239, lastInteger2);
+
+ print("\r\addConsoleActionSSS\r\n");
+ addConsoleActionSSS("echosss", testEchoSSS);
+ strcpy(buffer, "echosss 111 222 333");
+ handleConsoleLine(buffer);
+ assertEquals(111, atoi(lastFirst));
+ assertEquals(333, atoi(lastThird));
+
+ //addConsoleActionSSS("GPS", testGpsParser);
+}
+
diff --git a/unit_tests/test_util.h b/unit_tests/test_util.h
index e77940bcc7..0bd3c24cb6 100644
--- a/unit_tests/test_util.h
+++ b/unit_tests/test_util.h
@@ -1,30 +1,31 @@
-/**
- * @file test_cyclic_buffer.h
- *
- * @date Dec 8, 2013
- * @author Andrey Belomutskiy, (c) 2012-2013
- */
-
-#ifndef TEST_CYCLIC_BUFFER_H_
-#define TEST_CYCLIC_BUFFER_H_
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif /* __cplusplus */
-
-
-
-void testCyclicBuffer(void);
-void testHistogram(void);
-void testMalfunctionCentral(void);
-void testConsoleLogic(void);
-void testGpsParser(void);
-
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-
-#endif /* TEST_CYCLIC_BUFFER_H_ */
+/**
+ * @file test_cyclic_buffer.h
+ *
+ * @date Dec 8, 2013
+ * @author Andrey Belomutskiy, (c) 2012-2013
+ */
+
+#ifndef TEST_CYCLIC_BUFFER_H_
+#define TEST_CYCLIC_BUFFER_H_
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+
+
+void testCyclicBuffer(void);
+void testOverflow64Counter(void);
+void testHistogram(void);
+void testMalfunctionCentral(void);
+void testConsoleLogic(void);
+void testGpsParser(void);
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+
+#endif /* TEST_CYCLIC_BUFFER_H_ */