/** * @brief This function takes care of one command line once we have it */ void handleConsoleLine(char *line) { line = validateSecureLine(line); if (line == NULL) return; // error detected int lineLength = strlen(line); if (lineLength > 100) { // todo: better max size logic // todo: better reaction to excessive line print("Long line?\r\n"); return; } strcpy(confirmation, "confirmation_"); strcat(confirmation, line); strcat(confirmation, ":"); bool_t isKnownComman = handleConsoleLineInternal(line, lineLength); // confirmation happens after the command to avoid conflict with command own output sendOutConfirmation(confirmation, lineLength); if (!isKnownComman) helpCommand(); }
/** * @brief This function takes care of one command line once we have it */ void handleConsoleLine(char *line) { line = validateSecureLine(line); if (line == NULL) return; // error detected int lineLength = strlen(line); if (lineLength > 100) { // todo: better max size logic // todo: better reaction to excessive line print("Long line?\r\n"); return; } strcpy(confirmation, "confirmation_"); strcat(confirmation, line); strcat(confirmation, ":"); #if EFI_PROD_CODE || EFI_SIMULATOR sendOutConfirmation(confirmation, lineLength); #endif bool isKnownComman = handleConsoleLineInternal(line, lineLength); if (!isKnownComman) { scheduleMsg(logging, "unknown [%s]", line); helpCommand(); } }
TEST(misc, testConsoleLogic) { print("******************************************* testConsoleLogic\r\n"); resetConsoleActions(); helpCommand(); char * cmd = "he ha"; ASSERT_EQ(2, findEndOfToken(cmd)); cmd = "\"hee\" ha"; ASSERT_EQ(5, findEndOfToken(cmd)); cmd = "\"h e\" ha"; ASSERT_EQ(5, findEndOfToken(cmd)); strcpy(buffer, "echo"); ASSERT_TRUE(strEqual("echo", unquote(buffer))); strcpy(buffer, "\"echo\""); ASSERT_TRUE(strEqual("echo", unquote(buffer))) << "unquote quoted"; char *ptr = validateSecureLine(UNKNOWN_COMMAND); ASSERT_EQ(0, strcmp(UNKNOWN_COMMAND, ptr)); ASSERT_EQ(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); ASSERT_EQ(239, lastInteger); print("\r\naddConsoleActionI 240 with two spaces\r\n"); strcpy(buffer, "echoi 240"); handleConsoleLine(buffer); ASSERT_EQ(240, lastInteger); print("\r\naddConsoleActionII\r\n"); addConsoleActionII("echoii", testEchoII); strcpy(buffer, "echoii 22 239"); handleConsoleLine(buffer); ASSERT_EQ(22, lastInteger); ASSERT_EQ(239, lastInteger2); print("\r\naddConsoleActionII three spaces\r\n"); strcpy(buffer, "echoii 21 220"); handleConsoleLine(buffer); ASSERT_EQ(21, lastInteger); ASSERT_EQ(220, lastInteger2); print("\r\addConsoleActionSSS\r\n"); addConsoleActionSSS("echosss", testEchoSSS); strcpy(buffer, "echosss 111 222 333"); handleConsoleLine(buffer); ASSERT_EQ(111, atoi(lastFirst)); ASSERT_EQ(333, atoi(lastThird)); strcpy(buffer, "echosss \" 1\" 222 333"); handleConsoleLine(buffer); ASSERT_TRUE(strEqual("\" 1\"", lastFirst)); //addConsoleActionSSS("GPS", testGpsParser); }