auto-sync

This commit is contained in:
rusEfi 2016-06-22 23:01:57 -04:00
parent cc6738169c
commit 5146628bd8
5 changed files with 73 additions and 22 deletions

View File

@ -298,5 +298,5 @@ int getRusEfiVersion(void) {
return 123; // this is here to make the compiler happy about the unused array return 123; // this is here to make the compiler happy about the unused array
if (UNUSED_CCM_SIZE[0] * 0 != 0) if (UNUSED_CCM_SIZE[0] * 0 != 0)
return 3211; // this is here to make the compiler happy about the unused array return 3211; // this is here to make the compiler happy about the unused array
return 20160619; return 20160622;
} }

View File

@ -29,6 +29,9 @@
#include "eficonsole.h" #include "eficonsole.h"
#endif /* ! EFI_UNIT_TEST */ #endif /* ! EFI_UNIT_TEST */
// todo: support \t as well
#define SPACE_CHAR ' '
static Logging * logging; static Logging * logging;
static int consoleActionCount = 0; static int consoleActionCount = 0;
@ -201,21 +204,41 @@ int findEndOfToken(const char *line) {
*/ */
return v + 2; return v + 2;
} }
return indexOf(line, ' '); return indexOf(line, SPACE_CHAR);
}
#define REPLACE_SPACES_WITH_ZERO { \
while (parameter[spaceIndex + 1] == SPACE_CHAR) { \
parameter[spaceIndex++] = 0; \
} \
parameter[spaceIndex] = 0; \
} }
void handleActionWithParameter(TokenCallback *current, char *parameter) { void handleActionWithParameter(TokenCallback *current, char *parameter) {
if (current->parameterType == STRING_PARAMETER) { while (parameter[0] == SPACE_CHAR) {
parameter[0] = 0;
parameter++;
}
switch (current->parameterType) {
case STRING_PARAMETER:
{
VoidCharPtr callbackS = (VoidCharPtr) current->callback; VoidCharPtr callbackS = (VoidCharPtr) current->callback;
(*callbackS)(parameter); (*callbackS)(parameter);
return; return;
} }
case STRING_PARAMETER_P:
if (current->parameterType == STRING_PARAMETER_P) { {
VoidCharPtrVoidPtr callbackS = (VoidCharPtrVoidPtr) current->callback; VoidCharPtrVoidPtr callbackS = (VoidCharPtrVoidPtr) current->callback;
(*callbackS)(parameter, current->param); (*callbackS)(parameter, current->param);
return; return;
} }
default:
// todo: handle all cases explicitly
break;
}
// todo: refactor this hell! // todo: refactor this hell!
if (current->parameterType == STRING2_PARAMETER || current->parameterType == STRING2_PARAMETER_P) { if (current->parameterType == STRING2_PARAMETER || current->parameterType == STRING2_PARAMETER_P) {
@ -223,7 +246,7 @@ void handleActionWithParameter(TokenCallback *current, char *parameter) {
if (spaceIndex == -1) { if (spaceIndex == -1) {
return; return;
} }
parameter[spaceIndex] = 0; REPLACE_SPACES_WITH_ZERO;
char * param0 = parameter; char * param0 = parameter;
parameter += spaceIndex + 1; parameter += spaceIndex + 1;
@ -244,14 +267,14 @@ void handleActionWithParameter(TokenCallback *current, char *parameter) {
if (spaceIndex == -1) { if (spaceIndex == -1) {
return; return;
} }
parameter[spaceIndex] = 0; REPLACE_SPACES_WITH_ZERO;
char * param0 = parameter; char * param0 = parameter;
parameter += spaceIndex + 1; parameter += spaceIndex + 1;
spaceIndex = findEndOfToken(parameter); spaceIndex = findEndOfToken(parameter);
if (spaceIndex == -1) if (spaceIndex == -1)
return; return;
parameter[spaceIndex] = 0; REPLACE_SPACES_WITH_ZERO;
char * param1 = parameter; char * param1 = parameter;
parameter += spaceIndex + 1; parameter += spaceIndex + 1;
char * param2 = parameter; char * param2 = parameter;
@ -268,28 +291,28 @@ void handleActionWithParameter(TokenCallback *current, char *parameter) {
if (spaceIndex == -1) { if (spaceIndex == -1) {
return; return;
} }
parameter[spaceIndex] = 0; REPLACE_SPACES_WITH_ZERO;
char * param0 = parameter; char * param0 = parameter;
parameter += spaceIndex + 1; parameter += spaceIndex + 1;
spaceIndex = findEndOfToken(parameter); spaceIndex = findEndOfToken(parameter);
if (spaceIndex == -1) if (spaceIndex == -1)
return; return;
parameter[spaceIndex] = 0; REPLACE_SPACES_WITH_ZERO;
char * param1 = parameter; char * param1 = parameter;
parameter += spaceIndex + 1; parameter += spaceIndex + 1;
spaceIndex = findEndOfToken(parameter); spaceIndex = findEndOfToken(parameter);
if (spaceIndex == -1) if (spaceIndex == -1)
return; return;
parameter[spaceIndex] = 0; REPLACE_SPACES_WITH_ZERO;
char * param2 = parameter; char * param2 = parameter;
parameter += spaceIndex + 1; parameter += spaceIndex + 1;
spaceIndex = findEndOfToken(parameter); spaceIndex = findEndOfToken(parameter);
if (spaceIndex == -1) if (spaceIndex == -1)
return; return;
parameter[spaceIndex] = 0; REPLACE_SPACES_WITH_ZERO;
char * param3 = parameter; char * param3 = parameter;
parameter += spaceIndex + 1; parameter += spaceIndex + 1;
@ -305,7 +328,7 @@ void handleActionWithParameter(TokenCallback *current, char *parameter) {
int spaceIndex = findEndOfToken(parameter); int spaceIndex = findEndOfToken(parameter);
if (spaceIndex == -1) if (spaceIndex == -1)
return; return;
parameter[spaceIndex] = 0; REPLACE_SPACES_WITH_ZERO;
int value1 = atoi(parameter); int value1 = atoi(parameter);
if (absI(value1) == ERROR_CODE) { if (absI(value1) == ERROR_CODE) {
#if (EFI_PROD_CODE || EFI_SIMULATOR) || defined(__DOXYGEN__) #if (EFI_PROD_CODE || EFI_SIMULATOR) || defined(__DOXYGEN__)
@ -328,6 +351,10 @@ void handleActionWithParameter(TokenCallback *current, char *parameter) {
if (current->parameterType == FLOAT_PARAMETER) { if (current->parameterType == FLOAT_PARAMETER) {
float value = atoff(parameter); float value = atoff(parameter);
if (cisnan(value)) {
print("invalid float [%s]\r\n", parameter);
return;
}
VoidFloat callbackF = (VoidFloat) current->callback; VoidFloat callbackF = (VoidFloat) current->callback;
// invoke callback function by reference // invoke callback function by reference
@ -339,11 +366,21 @@ void handleActionWithParameter(TokenCallback *current, char *parameter) {
int spaceIndex = findEndOfToken(parameter); int spaceIndex = findEndOfToken(parameter);
if (spaceIndex == -1) if (spaceIndex == -1)
return; return;
parameter[spaceIndex] = 0; REPLACE_SPACES_WITH_ZERO;
float value1 = atoff(parameter); float value1 = atoff(parameter);
if (cisnan(value1)) {
print("invalid float [%s]\r\n", parameter);
return;
}
parameter += spaceIndex + 1; parameter += spaceIndex + 1;
float value2 = atoff(parameter); float value2 = atoff(parameter);
if (current->parameterType == FLOAT_FLOAT_PARAMETER) {
if (cisnan(value2)) {
print("invalid float [%s]\r\n", parameter);
return;
}
if (current->parameterType == FLOAT_FLOAT_PARAMETER) {
VoidFloatFloat callbackS = (VoidFloatFloat) current->callback; VoidFloatFloat callbackS = (VoidFloatFloat) current->callback;
(*callbackS)(value1, value2); (*callbackS)(value1, value2);
} else { } else {
@ -379,7 +416,7 @@ int tokenLength(const char *msgp) {
int result = 0; int result = 0;
while (*msgp) { while (*msgp) {
char ch = *msgp++; char ch = *msgp++;
if (ch == ' ') { if (ch == SPACE_CHAR) {
break; break;
} }
result++; result++;

View File

@ -190,9 +190,10 @@ int efiPow10(int param) {
} }
/** /**
* string to float * string to float. NaN input is not supported
*
* @return NAN in case of invalid string * @return NAN in case of invalid string
* todo: explicit value for error code? * todo: explicit value for error code? probably not, NaN is only returned in case of an error
*/ */
float atoff(const char *param) { float atoff(const char *param) {
uint32_t totallen = strlen(param); uint32_t totallen = strlen(param);

View File

@ -120,7 +120,6 @@ int main(void) {
testSensors(); testSensors();
testCyclicBuffer(); testCyclicBuffer();
testCrc(); testCrc();
testMisc();
testSignalExecutor(); testSignalExecutor();

View File

@ -331,6 +331,13 @@ void testConsoleLogic(void) {
handleConsoleLine(buffer); handleConsoleLine(buffer);
assertEquals(239, lastInteger); assertEquals(239, lastInteger);
print("\r\naddConsoleActionI 240 with two spaces\r\n");
addConsoleActionI("echoi", testEchoI);
strcpy(buffer, "echoi 240");
handleConsoleLine(buffer);
assertEquals(240, lastInteger);
print("\r\naddConsoleActionII\r\n"); print("\r\naddConsoleActionII\r\n");
addConsoleActionII("echoii", testEchoII); addConsoleActionII("echoii", testEchoII);
strcpy(buffer, "echoii 22 239"); strcpy(buffer, "echoii 22 239");
@ -338,6 +345,13 @@ void testConsoleLogic(void) {
assertEquals(22, lastInteger); assertEquals(22, lastInteger);
assertEquals(239, lastInteger2); assertEquals(239, lastInteger2);
print("\r\naddConsoleActionII three spaces\r\n");
addConsoleActionII("echoii", testEchoII);
strcpy(buffer, "echoii 21 220");
handleConsoleLine(buffer);
assertEquals(21, lastInteger);
assertEquals(220, lastInteger2);
print("\r\addConsoleActionSSS\r\n"); print("\r\addConsoleActionSSS\r\n");
addConsoleActionSSS("echosss", testEchoSSS); addConsoleActionSSS("echosss", testEchoSSS);
strcpy(buffer, "echosss 111 222 333"); strcpy(buffer, "echosss 111 222 333");