mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
101 lines
2.9 KiB
Plaintext
101 lines
2.9 KiB
Plaintext
|
/*
|
||
|
* Copyright (C) 2018 Federico Pellegrin <fede@evolware.org>
|
||
|
*
|
||
|
* This file is subject to the terms and conditions of the GNU Lesser
|
||
|
* General Public License v2.1. See the file LICENSE in the top level
|
||
|
* directory for more details.
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* @ingroup tests
|
||
|
* @{
|
||
|
*
|
||
|
* @file
|
||
|
* @brief Test application for arduino module
|
||
|
*
|
||
|
* @author Federico Pellegrin <fede@evolware.org>
|
||
|
*
|
||
|
* @}
|
||
|
*/
|
||
|
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
|
||
|
#ifdef STDIO_UART_BAUDRATE
|
||
|
#define SERIAL_BAUDRATE STDIO_UART_BAUDRATE
|
||
|
#else
|
||
|
#define SERIAL_BAUDRATE 115200
|
||
|
#endif
|
||
|
|
||
|
/* Input buffer for receiving chars on the serial port */
|
||
|
char buf[64];
|
||
|
|
||
|
/* Counter of received chars in currently receiving line */
|
||
|
int count = 0;
|
||
|
|
||
|
void setup(void)
|
||
|
{
|
||
|
Serial.begin(SERIAL_BAUDRATE);
|
||
|
Serial.println("Hello Arduino!");
|
||
|
}
|
||
|
|
||
|
void loop(void)
|
||
|
{
|
||
|
/* Read chars if available and seek for CR or LF */
|
||
|
while (Serial.available() > 0) {
|
||
|
int tmp = Serial.read();
|
||
|
if (tmp == '\n' || tmp == '\r') {
|
||
|
buf[count] = 0;
|
||
|
|
||
|
if (count > 1) {
|
||
|
if (strncmp(buf, "echo", 4) == 0) {
|
||
|
/* echo command just echoes back the input string */
|
||
|
Serial.write("ECHO:");
|
||
|
for (int i = 4; i < count; i++) {
|
||
|
Serial.write(buf[i]);
|
||
|
}
|
||
|
} else if (strncmp(buf, "numb", 4) == 0) {
|
||
|
/* numb command prints input number in various formats */
|
||
|
int numb=atoi(buf + 5);
|
||
|
Serial.print(numb);
|
||
|
Serial.print(" ");
|
||
|
Serial.print(numb, DEC);
|
||
|
Serial.print(" ");
|
||
|
Serial.print(numb, HEX);
|
||
|
Serial.print(" ");
|
||
|
Serial.print(numb, OCT);
|
||
|
} else if (strncmp(buf, "time", 4) == 0) {
|
||
|
/* time command tests printing time and sleeps */
|
||
|
unsigned long curtime = micros();
|
||
|
unsigned long curtime2, curtime3;
|
||
|
|
||
|
Serial.print((int) curtime);
|
||
|
delay(36);
|
||
|
Serial.print(" ");
|
||
|
curtime2=micros();
|
||
|
Serial.print((int) curtime2);
|
||
|
delayMicroseconds(36000);
|
||
|
Serial.print(" ");
|
||
|
curtime3=micros();
|
||
|
Serial.print((int) curtime3);
|
||
|
|
||
|
/* test also that time is actually running */
|
||
|
if ((curtime3 > curtime2) && (curtime2 > curtime)) {
|
||
|
Serial.print(" OK END");
|
||
|
} else {
|
||
|
Serial.print(" ERR END");
|
||
|
}
|
||
|
} else {
|
||
|
Serial.write("UNK");
|
||
|
}
|
||
|
Serial.println("");
|
||
|
}
|
||
|
count = 0;
|
||
|
}
|
||
|
else {
|
||
|
buf[count++] = tmp;
|
||
|
}
|
||
|
}
|
||
|
delay(500);
|
||
|
}
|