/******************************************************************************* * TzCtrl * * Task for receiving commands from embOS-Trace and for recorder diagnostics. * * Stack size and priority is configured in trcKernelPort.h, using: * - TZCTRL_TASK_STACK_SIZE (default 512) * - TZCTRL_TASK_PRIORITY (default 10) ******************************************************************************/ static portTASK_FUNCTION( TzCtrl, pvParameters ) { TracealyzerCommandType msg; int bytes = 0; while (1) { bytes = SEGGER_RTT_Read(TRC_RTT_DOWN_BUFFER_INDEX, (char*)&msg, sizeof(TracealyzerCommandType)); if (bytes != 0) { if (bytes == sizeof(TracealyzerCommandType)) { if (isValidCommand(&msg)) { processCommand(&msg); /* Start or Stop currently... */ } } } else { CheckRecorderStatus(); vTaskDelay((100 * configTICK_RATE_HZ) / 1000); /* 100ms */ } } }
////////////////////////////////////////////////////////////////////////////// /// /// Read the input stream /// ////////////////////////////////////////////////////////////////////////////// void controller::readInputStream(unsigned char* ptr) { int position; sanitize(ptr, &position); bool isOverflow = false; // Validate input stream while (!isValidCommand(ptr) || isDividedByZeroDetected(ptr)) { // Prevent to have a string with no operation or with invalid operands if (isLFDetected(ptr) && (!isOperationDetected(ptr) || !isOperand1Detected(ptr) || !isOperand2Detected(ptr))) { sanitize(ptr, &position); displayMessage((char*) "Invalid input string\n"); isOverflow = false; } if (isDividedByZeroDetected(ptr)) { sanitize(ptr, &position); displayMessage((char*) "Division by zero detected\n"); isOverflow = false; } ptr[position++] = (unsigned char) readInput(); // Loop in array if (position == 20) { sanitize(ptr, &position); if (!isOverflow) displayMessage((char*) "String too long, try again\n"); isOverflow = true; } } }
int main(int argc, char** argv) { aLog::init("c:\\file.log",aLog::MT_DEBUG); printf("dwd1\n"); if(argc <=1) { showError("", invalid_usage); return 1; } printf("dwd\n"); QStringList args; fillArgsFromArgv(&args, argv, argc); QString command = parseCommand(&args); if(!isValidCommand(command)) { showError(command, invalid_command); return 1; } QString argument = parseArgument(&args); if(!isValidArgument(argument)) { showError(argument, invalid_argument); return 2; } QStringList options; parseOptions(&args, &options); removeInvalidOptions(&options); int res = doAction(command, argument, &options); aLog::close(); return res; }
/******************************************************************************* * TzCtrl * * Task for receiving commands from Tracealyzer and for recorder diagnostics. * ******************************************************************************/ static portTASK_FUNCTION( TzCtrl, pvParameters ) { TracealyzerCommandType msg; int bytes = 0; while (1) { bytes = 0; TRC_STREAM_PORT_READ_DATA(&msg, sizeof(TracealyzerCommandType), &bytes); if (bytes != 0) { if (bytes == sizeof(TracealyzerCommandType)) { if (isValidCommand(&msg)) { processCommand(&msg); /* Start or Stop currently... */ } } } do { bytes = 0; TRC_STREAM_PORT_PERIODIC_SEND_DATA(&bytes); } while (bytes != 0); CheckRecorderStatus(); vTaskDelay(TRC_CTRL_TASK_DELAY); /* 10ms */ } }
int isCommaSeperatedCommands() { while (hasNextToken()) { char token[80]; int i=0; strcpy(token, nextToken()); upper(token); if (token[strlen(token)-1] == ',') { char command_token[80]; strncpy(command_token, token, strlen(token)-1); command_token[strlen(token)-1] = '\0'; if (!isValidCommand(command_token)) return i; i++; } else { if (!isValidCommand(token)) return i; char *end_token = nextToken(); upper(end_token); if (strcmp(end_token, "END") != 0) return -i; break; } } return 0; }
int checkCommandList(char *token, int size) { int i; char *temp; int command_length = 0; //Parse through comma separated list to check for each command for (i = 0; i < size; i++) { //Find a comma to find a command if (token[i] == ',' || i == (size - 1)) { //If found a comma, copy the command over and check for its validity temp = (char *) malloc((command_length + 1) * sizeof(char)); temp[command_length] = '\0'; int j; for (j = 0; j < command_length; j++) { temp[j] = token[(i-command_length) + j]; } //If this is the last letter in the token, parse for the last command including the current index if(i == (size - 1)) { temp[command_length] = token[i]; } if (!isValidCommand(temp)) { free(temp); return 0; } //Skip this comma for next iteration i++; command_length = 0; } command_length++; } free(temp); return 1; }
int isValidExpression(char *expression) { initBuffer(expression); char token[TOKEN_SIZE]; if (hasNextToken()) { strcpy(token, nextToken()); } else return 0; upper(token); if (strcmp(token, "REPEAT") == 0) return isRepeatStructure(); if (strcmp(token, "WHILE") == 0) return isWhileStructure(); if (strcmp(token, "SAY") == 0) return isString(); if (isValidCommand(token)) return 1; reportError(0, "not a valid expression"); return 0; }
void byteReceived(unsigned char c) { switch (rx.state) { case WAIT: if (c == START_BYTE) rx.state = START; break; case START: if (isValidCommand(c)) { rx.cmd = c; rx.state = LENGTH; } else { rx.state = WAIT; } break; case LENGTH: rx.length = c; rx.i = 0; rx.checksum = 0; rx.state = DATA; break; case DATA: rx.data[rx.i++] = c; rx.checksum ^= c; if (rx.i == rx.length) rx.state = CHECKSUM; break; case CHECKSUM: if (c == rx.checksum) packetReceived(); rx.state = WAIT; break; default: rx.state = WAIT; break; } // end switch }
// Interactive command-line user interface void userInterface() { printf("\n\n"); // User prompt if (currentUser == 0) printf("Operating System: "); else printf("User %i: ", currentUser); // Get command fgets(controlCommand, 5, stdin); printf("\n"); if (isValidCommand()) { switch (commandCode) { case 1: placeInQueue(); break; case 2: dmp(); break; case 3: placeInQueue(); break; case 4: nop(); break; } // Schedule next execution request scheduler(); // Routine cleanup after every execution; queue manipulation, process removal if (queueArray[currentPriority][0] != NULL) { cleanUp(); } dumpQueues(); // Cycle to the next user if (currentUser == numberOfUsers - 1) currentUser = 0; else currentUser++; } else printf("Invalid command entered\n"); }
int checkWhileExpression(char *expression) { Rewind(); char *first = nextToken(); char *second = nextToken(); char *third = nextToken(); char *fourth = nextToken(); char *fifth = nextToken(); char *sixth = nextToken(); if (checkWHILE(first, strlength(first))&& checkNOT(second, strlength(second))&& isValidCommand(third)&& checkDO(fourth, strlength(fourth))&& checkCommandList(fifth, strlength(fifth))&& checkEND(sixth, strlength(sixth))) { free(first); free(second); free(third); free(fourth); free(fifth); free(sixth); return 1; } else { free(first); free(second); free(third); free(fourth); free(fifth); free(sixth); return 0; } }
////////////////////////////////////////////////////////////////////////////// /// /// Determine if the buffer contains a division by zero /// ////////////////////////////////////////////////////////////////////////////// bool controller::isDividedByZeroDetected(unsigned char* ptr) { return isValidCommand(ptr) && getSecondOperand(ptr) == 0 && getOperation(ptr) == DIVIDE; }
static void prvRS485MasterTask(void *arg) { unsigned char command[3]; unsigned char rxMessage[3]; unsigned char* msg; unsigned char rxChar; unsigned char rxIndex = 0; for (;;) { switch (processState) { case WAITING_COMMAND_TO_SEND: while (xQueueReceive(commandQueue, command, portMAX_DELAY) != pdPASS); if (isValidCommand(command)) { processState = SENDING_COMMAND; } else { flushRs485RxBuffer(); } break; case SENDING_COMMAND: rs485SetWrite(); vTaskDelay(RS485_TRANSITION_DELAY_MS); writeRS485(command); while (!rs485TransmitComplete()) { vTaskDelay(RS485_CHECK_TRANSMIT_OK_DELAY); } processState = WAITING_RESPONSE; break; case WAITING_RESPONSE: rs485SetRead(); vTaskDelay(RS485_TRANSITION_DELAY_MS); rxChar = readRS485(); if (rxChar != '\0' && isValidMessageHeader(rxChar)) { rxIndex = 0; rxMessage[rxIndex] = rxChar; rxIndex++; processState = PARSING_RX_MESSAGE; } break; case PARSING_RX_MESSAGE: rxChar = readRS485(); if (rxChar != '\0') { rxMessage[rxIndex] = rxChar; if (isValidMessageEnd(rxChar)) { flushRs485RxBuffer(); processState = PUBLISHING_SENSORS_RESPONSE; } else { rxIndex++; } } break; case PUBLISHING_SENSORS_RESPONSE: msg = rxMessage; while (xQueueSend(responseQueue, msg, portMAX_DELAY) != pdPASS); processState = WAITING_COMMAND_TO_SEND; break; } } }