auto-sync

This commit is contained in:
rusEfi 2014-12-03 10:03:52 -06:00
parent 0b98f1d9fc
commit a611130271
4 changed files with 41 additions and 7 deletions

View File

@ -330,10 +330,32 @@ static void setUserOutput(const char *indexStr, const char *quotedLine, Engine *
strcpy(engine->engineConfiguration->bc.le_formulas[index], l); strcpy(engine->engineConfiguration->bc.le_formulas[index], l);
} }
static void setFloat(const char *offsetStr, const char *valueStr) { static void setInt(const char *offsetStr, const char *valueStr) {
} }
static void getFloat(int offset) {
float *ptr = (float *)(((char *) engine->engineConfiguration)[offset]);
float value = *ptr;
scheduleMsg(&logger, "float @%d is %f", offset, value);
}
static void setFloat(const char *offsetStr, const char *valueStr) {
int offset = atoi(offsetStr);
if (absI(offset) == absI(ERROR_CODE)) {
scheduleMsg(&logger, "invalid offset [%s]", offsetStr);
return;
}
float value = atoff(valueStr);
if (cisnan(value)) {
scheduleMsg(&logger, "invalid value [%s]", valueStr);
return;
}
float *ptr = (float *)(((char *) engine->engineConfiguration)[offset]);
*ptr = value;
scheduleMsg(&logger, "setting float @%d to %f", offset, value);
}
static pin_output_mode_e d = OM_DEFAULT; static pin_output_mode_e d = OM_DEFAULT;
void initEngineContoller(Engine *engine) { void initEngineContoller(Engine *engine) {
@ -443,6 +465,8 @@ void initEngineContoller(Engine *engine) {
} }
addConsoleActionSSP("set_user_out", (VoidCharPtrCharPtrVoidPtr) setUserOutput, engine); addConsoleActionSSP("set_user_out", (VoidCharPtrCharPtrVoidPtr) setUserOutput, engine);
addConsoleActionSS("set_float", (VoidCharPtrCharPtr)setFloat); addConsoleActionSS("set_float", (VoidCharPtrCharPtr) setFloat);
addConsoleActionSS("set_int", (VoidCharPtrCharPtr) setInt);
addConsoleActionI("get_float", getFloat);
initEval(engine); initEval(engine);
} }

View File

@ -304,7 +304,7 @@ void handleActionWithParameter(TokenCallback *current, char *parameter) {
return; return;
parameter[spaceIndex] = 0; parameter[spaceIndex] = 0;
int value1 = atoi(parameter); int value1 = atoi(parameter);
if (absI(value1) == absI(ERROR_CODE)) { if (absI(value1) == ERROR_CODE) {
#if (EFI_PROD_CODE || EFI_SIMULATOR) || defined(__DOXYGEN__) #if (EFI_PROD_CODE || EFI_SIMULATOR) || defined(__DOXYGEN__)
scheduleMsg(&logging, "not an integer [%s]", parameter); scheduleMsg(&logging, "not an integer [%s]", parameter);
#endif #endif
@ -312,7 +312,7 @@ void handleActionWithParameter(TokenCallback *current, char *parameter) {
} }
parameter += spaceIndex + 1; parameter += spaceIndex + 1;
int value2 = atoi(parameter); int value2 = atoi(parameter);
if (absI(value2) == absI(ERROR_CODE)) { if (absI(value2) == ERROR_CODE) {
#if (EFI_PROD_CODE || EFI_SIMULATOR) || defined(__DOXYGEN__) #if (EFI_PROD_CODE || EFI_SIMULATOR) || defined(__DOXYGEN__)
scheduleMsg(&logging, "not an integer [%s]", parameter); scheduleMsg(&logging, "not an integer [%s]", parameter);
#endif #endif
@ -351,7 +351,7 @@ void handleActionWithParameter(TokenCallback *current, char *parameter) {
} }
int value = atoi(parameter); int value = atoi(parameter);
if (value == ERROR_CODE) { if (absI(value) == ERROR_CODE) {
print("invalid integer [%s]\r\n", parameter); print("invalid integer [%s]\r\n", parameter);
return; return;
} }

View File

@ -147,7 +147,11 @@ bool isSameF(float v1, float v2) {
return absF(v1 - v2) < EPS; return absF(v1 - v2) < EPS;
} }
// string to float /**
* string to float
* @return NAN in case of invalid string
* todo: explicit value for error code?
*/
float atoff(const char *param) { float atoff(const char *param) {
uint32_t totallen = strlen(param); uint32_t totallen = strlen(param);
if (totallen > sizeof(todofixthismesswithcopy) - 1) if (totallen > sizeof(todofixthismesswithcopy) - 1)
@ -161,14 +165,20 @@ float atoff(const char *param) {
if (dotIndex == -1) { if (dotIndex == -1) {
// just an integer // just an integer
int result = atoi(string); int result = atoi(string);
if (absI(result) == ERROR_CODE)
return (float) NAN;
return (float) result; return (float) result;
} }
// todo: this needs to be fixed // todo: this needs to be fixed
string[dotIndex] = 0; string[dotIndex] = 0;
int integerPart = atoi(string); int integerPart = atoi(string);
if (absI(integerPart) == ERROR_CODE)
return (float) NAN;
string += (dotIndex + 1); string += (dotIndex + 1);
int decimalLen = strlen(string); int decimalLen = strlen(string);
int decimal = atoi(string); int decimal = atoi(string);
if (absI(decimal) == ERROR_CODE)
return (float) NAN;
float divider = 1.0; float divider = 1.0;
// todo: reuse 'pow10' function which we have anyway // todo: reuse 'pow10' function which we have anyway
for (int i = 0; i < decimalLen; i++) { for (int i = 0; i < decimalLen; i++) {

View File

@ -29,7 +29,7 @@ extern "C"
{ {
#endif /* __cplusplus */ #endif /* __cplusplus */
#define ERROR_CODE -11223344 #define ERROR_CODE 311223344
const char * boolToString(bool value); const char * boolToString(bool value);