/** Transmits one char at a time as check if the loopback received data is same as transmitted * Just used for testing with loopback setup (i.e, @ref TX_PIN_NUMBER connected to @ref RX_PIN_NUMBER) * return true if test passed, else return false */ static void uart_loopback_test() { uint8_t tx_data[] = ("\n\r LOOPBACK_TEST"); uint8_t rx_data[MAX_TEST_DATA_BYTES] = {0}; // Start sending one byte and see if you get the same for(uint8_t i = 0; i < MAX_TEST_DATA_BYTES; i++) { bool status; simple_uart_put(tx_data[i]); if(!simple_uart_get_with_timeout(2, &rx_data[i])) { show_error(); } } for(uint8_t i = 0; i < MAX_TEST_DATA_BYTES; i++) { if ((rx_data[i] != tx_data[i])) { show_error(); } } return; // Test passed }
int packet_info(){ simple_uart_putstring((const uint8_t *)"Digite a ID do atleta: \n"); for(int i = 0; i <= 3; i++){ packet[i + 2] = simple_uart_get(); } simple_uart_putstring((const uint8_t *)"Digite a potencia de transmissão: \n"); if(simple_uart_get_with_timeout(10000, &packet[1])){ } else { packet[0] = NRF_RADIO->POWER; } simple_uart_putstring((const uint8_t *)"Digite o intervalo de transmissão: \n"); if(simple_uart_get_with_timeout(10000, &packet[2])){ } else { packet[1] = 200; } simple_uart_putstring((const uint8_t *)"Digite a nova ID: \n"); if(simple_uart_get_with_timeout(10000, &packet[6]) && simple_uart_get_with_timeout(10000, &packet[7]) && simple_uart_get_with_timeout(10000, &packet[8]) && simple_uart_get_with_timeout(10000, &packet[9])){ } else { packet[6] = packet[2]; packet[7] = packet[3]; packet[8] = packet[4]; packet[9] = packet[5]; } }
void Terminal::PollUART() { #ifdef ENABLE_TERMINAL if (!terminalIsInitialized) return; static char readBuffer[250] = { 0 }; static char testCopy[250] = {0}; readBuffer[0] = 0; if (simple_uart_get_with_timeout(0, (u8*) readBuffer)) { //Output query string and typed symbol to terminal if (promptAndEchoMode) { simple_uart_putstring((const u8*) EOL "mhTerm: "); //Display prompt simple_uart_put(readBuffer[0]); //echo back symbol } //Read line from uart ReadlineUART(readBuffer, 250, 1); //FIXME: remove after finding problem memcpy(testCopy, readBuffer, 250); //Clear previous command commandName.clear(); commandArgs.clear(); //Tokenize input string into vector char* token = strtok(readBuffer, " "); if (token != NULL) commandName.assign(token); while (token != NULL) { token = strtok(NULL, " "); if (token != NULL) commandArgs.push_back(string(token)); } //Check for clear screen if (commandName == "cls") { //Send Escape sequence simple_uart_put(27); //ESC simple_uart_putstring((const u8*) "[2J"); //Clear Screen simple_uart_put(27); //ESC simple_uart_putstring((const u8*) "[H"); //Cursor to Home } else { //Call all callbacks int handled = 0; for(u32 i=0; i<registeredCallbacks->size(); i++){ handled += ((TerminalCommandListener*)registeredCallbacks->GetItemAt(i))->TerminalCommandHandler(commandName, commandArgs); } if (handled == 0){ if(promptAndEchoMode){ simple_uart_putstring((const u8*)"Command not found" EOL); } else { uart_error(Logger::COMMAND_NOT_FOUND); } //FIXME: to find problems with uart input uart("ERROR", "{\"user_input\":\"%s\"}" SEP, testCopy); } } } #endif }