auto-sync

This commit is contained in:
rusEfi 2016-12-22 14:02:38 -05:00
parent 3ffda1aecd
commit 83ab00ba5a
8 changed files with 40 additions and 67 deletions

View File

@ -47,24 +47,24 @@ typedef struct {
char crcReadBuffer[350]; char crcReadBuffer[350];
} ts_channel_s; } ts_channel_s;
#define TS_HELLO_COMMAND_DEPRECATED 'H' #define TS_HELLO_COMMAND_DEPRECATED 'H' // 0x48
#define TS_HELLO_COMMAND 'S' #define TS_HELLO_COMMAND 'S' // 0x53
#define TS_TEST_COMMAND 't' #define TS_TEST_COMMAND 't' // 0x74
#define TS_LEGACY_HELLO_COMMAND 'Q' #define TS_LEGACY_HELLO_COMMAND 'Q' // 0x51
#define TS_OUTPUT_COMMAND 'O' #define TS_OUTPUT_COMMAND 'O' // 0x4F
#define TS_READ_COMMAND 'R' #define TS_READ_COMMAND 'R' // 0x52
#define TS_PAGE_COMMAND 'P' #define TS_PAGE_COMMAND 'P' // 0x50
#define TS_COMMAND_F 'F' #define TS_COMMAND_F 'F' // 0x46
#define TS_EXECUTE 'E' #define TS_EXECUTE 'E' // 0x45
#define TS_GET_TEXT 'G' #define TS_GET_TEXT 'G' // 0x47
#define TS_GET_FILE_RANGE '2' #define TS_GET_FILE_RANGE '2'
#define TS_SINGLE_WRITE_COMMAND 'W' #define TS_SINGLE_WRITE_COMMAND 'W' // 0x57
#define TS_CHUNK_WRITE_COMMAND 'C' #define TS_CHUNK_WRITE_COMMAND 'C' // 0x43
#define TS_BURN_COMMAND 'B' #define TS_BURN_COMMAND 'B' // 0x42
#define TS_IO_TEST_COMMAND 'w' #define TS_IO_TEST_COMMAND 'w' // 0x77
#define TS_CRC_CHECK_COMMAND 'k' #define TS_CRC_CHECK_COMMAND 'k' // 0x6B
#define CRC_VALUE_SIZE 4 #define CRC_VALUE_SIZE 4
// todo: double-check this // todo: double-check this

View File

@ -56,8 +56,11 @@ private:
class ThermistorMath { class ThermistorMath {
public: public:
ThermistorMath(); ThermistorMath();
thermistor_curve_s curve;
void setConfig(thermistor_conf_s *config); void setConfig(thermistor_conf_s *config);
void prepareThermistorCurve(thermistor_conf_s *tc);
float s_h_a;
float s_h_b;
float s_h_c;
private: private:
thermistor_conf_s currentConfig; thermistor_conf_s currentConfig;
}; };

View File

@ -1,4 +1,4 @@
// this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Wed Dec 21 11:35:20 EST 2016 // this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Thu Dec 22 13:03:39 EST 2016
// begin // begin
#ifndef ENGINE_CONFIGURATION_GENERATED_H_ #ifndef ENGINE_CONFIGURATION_GENERATED_H_
#define ENGINE_CONFIGURATION_GENERATED_H_ #define ENGINE_CONFIGURATION_GENERATED_H_
@ -134,26 +134,6 @@ typedef struct {
/** total size 28*/ /** total size 28*/
} thermistor_conf_s; } thermistor_conf_s;
/**
* @brief Thermistor curve parameters
*/
typedef struct {
/**
* offset 0
*/
float s_h_a;
/**
* offset 4
*/
float s_h_b;
/**
* offset 8
*/
float s_h_c;
/** total size 12*/
} thermistor_curve_s;
/** /**
* @brief Thermistor curve parameters * @brief Thermistor curve parameters
@ -2026,4 +2006,4 @@ typedef struct {
#endif #endif
// end // end
// this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Wed Dec 21 11:35:20 EST 2016 // this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Thu Dec 22 13:03:39 EST 2016

View File

@ -51,15 +51,13 @@ float getVoutInVoltageDividor(float Vin, float r1, float r2) {
float getKelvinTemperature(ThermistorConf *config, float resistance, ThermistorMath *tm) { float getKelvinTemperature(ThermistorConf *config, float resistance, ThermistorMath *tm) {
tm->setConfig(&config->config); // implementation checks if config has changed or not tm->setConfig(&config->config); // implementation checks if config has changed or not
thermistor_curve_s * curve = &tm->curve;
efiAssert(curve != NULL, "thermistor pointer is NULL", NAN);
if (resistance <= 0) { if (resistance <= 0) {
//warning("Invalid resistance in getKelvinTemperature=", resistance); //warning("Invalid resistance in getKelvinTemperature=", resistance);
return 0.0f; return 0.0f;
} }
float logR = logf(resistance); float logR = logf(resistance);
return 1 / (curve->s_h_a + curve->s_h_b * logR + curve->s_h_c * logR * logR * logR); return 1 / (tm->s_h_a + tm->s_h_b * logR + tm->s_h_c * logR * logR * logR);
} }
float convertCelsiustoF(float tempC) { float convertCelsiustoF(float tempC) {
@ -75,8 +73,7 @@ float convertKelvinToFahrenheit(float kelvin) {
return convertCelsiustoF(tempC); return convertCelsiustoF(tempC);
} }
float getResistance(ThermistorConf *config) { float getResistance(ThermistorConf *config, float voltage) {
float voltage = getVoltageDivided("term", config->adcChannel);
efiAssert(config != NULL, "thermistor config is null", NAN); efiAssert(config != NULL, "thermistor config is null", NAN);
thermistor_conf_s *tc = &config->config; thermistor_conf_s *tc = &config->config;
@ -89,7 +86,8 @@ float getTemperatureC(ThermistorConf *config, ThermistorMath *tm) {
firmwareError(CUSTOM_ERR_THERM, "thermstr not initialized"); firmwareError(CUSTOM_ERR_THERM, "thermstr not initialized");
return NAN; return NAN;
} }
float resistance = getResistance(config); float voltage = getVoltageDivided("term", config->adcChannel);
float resistance = getResistance(config, voltage);
float kelvinTemperature = getKelvinTemperature(config, resistance, tm); float kelvinTemperature = getKelvinTemperature(config, resistance, tm);
return convertKelvinToCelcius(kelvinTemperature); return convertKelvinToCelcius(kelvinTemperature);
@ -138,7 +136,7 @@ void setThermistorConfiguration(ThermistorConf * thermistor, float tempC1, float
tc->resistance_3 = r3; tc->resistance_3 = r3;
} }
static void prepareThermistorCurve(thermistor_conf_s *tc, thermistor_curve_s * curve) { void ThermistorMath::prepareThermistorCurve(thermistor_conf_s *tc) {
float T1 = tc->tempC_1 + KELV; float T1 = tc->tempC_1 + KELV;
float T2 = tc->tempC_2 + KELV; float T2 = tc->tempC_2 + KELV;
float T3 = tc->tempC_3 + KELV; float T3 = tc->tempC_3 + KELV;
@ -167,9 +165,9 @@ static void prepareThermistorCurve(thermistor_conf_s *tc, thermistor_curve_s * c
float U3 = (Y3 - Y1) / (L3 - L1); float U3 = (Y3 - Y1) / (L3 - L1);
curve->s_h_c = (U3 - U2) / (L3 - L2) * pow(L1 + L2 + L3, -1); s_h_c = (U3 - U2) / (L3 - L2) * pow(L1 + L2 + L3, -1);
curve->s_h_b = U2 - curve->s_h_c * (L1 * L1 + L1 * L2 + L2 * L2); s_h_b = U2 - s_h_c * (L1 * L1 + L1 * L2 + L2 * L2);
curve->s_h_a = Y1 - (curve->s_h_b + L1 * L1 * curve->s_h_c) * L1; s_h_a = Y1 - (s_h_b + L1 * L1 * s_h_c) * L1;
#if EXTREME_TERM_LOGGING || defined(__DOXYGEN__) #if EXTREME_TERM_LOGGING || defined(__DOXYGEN__)
scheduleMsg(logger, "Y1=%..100000f/Y2=%..100000f/Y3=%..100000f", Y1, Y2, Y3); scheduleMsg(logger, "Y1=%..100000f/Y2=%..100000f/Y3=%..100000f", Y1, Y2, Y3);
@ -234,7 +232,7 @@ void initThermistors(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_S) {
ThermistorMath::ThermistorMath() { ThermistorMath::ThermistorMath() {
memset(&currentConfig, 0, sizeof(currentConfig)); memset(&currentConfig, 0, sizeof(currentConfig));
memset(&curve, 0, sizeof(curve)); s_h_a = s_h_b = s_h_c = 0;
} }
void ThermistorMath::setConfig(thermistor_conf_s *config) { void ThermistorMath::setConfig(thermistor_conf_s *config) {
@ -243,5 +241,5 @@ void ThermistorMath::setConfig(thermistor_conf_s *config) {
return; return;
} }
memcpy(&currentConfig, config, sizeof(currentConfig)); memcpy(&currentConfig, config, sizeof(currentConfig));
prepareThermistorCurve(config, &curve); prepareThermistorCurve(config);
} }

View File

@ -31,7 +31,7 @@ float convertCelciustoF(float tempC);
float convertFtoCelcius(float tempF); float convertFtoCelcius(float tempF);
float getKelvinTemperature(ThermistorConf *config, float resistance, ThermistorMath *tm); float getKelvinTemperature(ThermistorConf *config, float resistance, ThermistorMath *tm);
float getResistance(ThermistorConf *config); float getResistance(ThermistorConf *config, float voltage);
float getTemperatureC(ThermistorConf *config, ThermistorMath *tm); float getTemperatureC(ThermistorConf *config, ThermistorMath *tm);
float getCoolantTemperature(DECLARE_ENGINE_PARAMETER_F); float getCoolantTemperature(DECLARE_ENGINE_PARAMETER_F);
bool isValidCoolantTemperature(float temperature); bool isValidCoolantTemperature(float temperature);

View File

@ -376,10 +376,9 @@ static void setOM(int value) {
static char pinNameBuffer[16]; static char pinNameBuffer[16];
static void printThermistor(const char *msg, ThermistorConf *config, ThermistorMath *tm) { static void printThermistor(const char *msg, ThermistorConf *config, ThermistorMath *tm) {
thermistor_curve_s * curve = &tm->curve;
adc_channel_e adcChannel = config->adcChannel; adc_channel_e adcChannel = config->adcChannel;
float voltage = getVoltageDivided("term", adcChannel); float voltage = getVoltageDivided("term", adcChannel);
float r = getResistance(config); float r = getResistance(config, voltage);
float t = getTemperatureC(config, tm); float t = getTemperatureC(config, tm);
@ -393,7 +392,7 @@ static void printThermistor(const char *msg, ThermistorConf *config, ThermistorM
tc->tempC_3, tc->resistance_3); tc->tempC_3, tc->resistance_3);
scheduleMsg(&logger, "bias resistor=%fK A=%..100000f B=%..100000f C=%..100000f", tc->bias_resistor / 1000, scheduleMsg(&logger, "bias resistor=%fK A=%..100000f B=%..100000f C=%..100000f", tc->bias_resistor / 1000,
curve->s_h_a, curve->s_h_b, curve->s_h_c); tm->s_h_a, tm->s_h_b, tm->s_h_c);
scheduleMsg(&logger, "=============================="); scheduleMsg(&logger, "==============================");
} }

View File

@ -158,12 +158,6 @@ float resistance_3;;"Ohm", 1, 0, 0, 200000, 1
float bias_resistor;;"Ohm", 1, 0, 0, 200000, 1 float bias_resistor;;"Ohm", 1, 0, 0, 200000, 1
end_struct end_struct
struct_no_prefix thermistor_curve_s @brief Thermistor curve parameters
float s_h_a;
float s_h_b;
float s_h_c;
end_struct
struct ThermistorConf @brief Thermistor curve parameters struct ThermistorConf @brief Thermistor curve parameters
thermistor_conf_s config; thermistor_conf_s config;
adc_channel_e adcChannel; adc_channel_e adcChannel;

View File

@ -89,15 +89,14 @@ void testSensors(void) {
testHip9011lookup(); testHip9011lookup();
ThermistorMath tm; ThermistorMath tm;
thermistor_curve_s *curve = &tm.curve;
{ {
setThermistorConfiguration(&tc, 32, 9500, 75, 2100, 120, 1000); setThermistorConfiguration(&tc, 32, 9500, 75, 2100, 120, 1000);
float t = getKelvinTemperature(&tc, 2100, &tm); float t = getKelvinTemperature(&tc, 2100, &tm);
assertEquals(75 + KELV, t); assertEquals(75 + KELV, t);
assertEquals(-0.003, curve->s_h_a); assertEquals(-0.003, tm.s_h_a);
assertEquals(0.001, curve->s_h_b); assertEquals(0.001, tm.s_h_b);
assertEquals(0.0, curve->s_h_c); assertEquals(0.0, tm.s_h_c);
} }
@ -108,9 +107,9 @@ void testSensors(void) {
float t = getKelvinTemperature(&tc, 38000, &tm); float t = getKelvinTemperature(&tc, 38000, &tm);
assertEquals(-2.7983, t - KELV); assertEquals(-2.7983, t - KELV);
assertEqualsM("A", 0.0009, curve->s_h_a); assertEqualsM("A", 0.0009, tm.s_h_a);
assertEqualsM("B", 0.0003, curve->s_h_b); assertEqualsM("B", 0.0003, tm.s_h_b);
assertEquals(0.0, curve->s_h_c); assertEquals(0.0, tm.s_h_c);
} }
} }