ArduinoMega2560_SPI 1.0
Cargando...
Buscando...
Nada coincide
diagnosticsUART.cpp
Ir a la documentación de este archivo.
1#include "system/diagnostics/diagnosticsUART.h" // Header for UART diagnostics
2
3/**
4 * @brief Ejecuta diagnósticos en todos los puertos UART disponibles.
5 *
6 * Esta función:
7 * - Muestra un mensaje de inicio del diagnóstico.
8 * - Ejecuta diagnoseSerial1() y diagnoseSerial2().
9 * - Muestra un mensaje de finalización del diagnóstico.
10 *
11 * Actualmente incluye:
12 * - UART1 (Serial1)
13 * - UART2 (Serial2)
14 */
16 standardMessage("Starting UART communication diagnostic", __FILE__, __FUNCTION__, __DATE__, __TIME__);
17
20
21 standardHeaderFull("Completed UART diagnostic", __FILE__, __FUNCTION__, __DATE__, __TIME__);
22}
23
24/**
25 * @brief Realiza un diagnóstico sobre un puerto UART específico.
26 *
27 * El procedimiento:
28 * - Inicia el puerto UART a 9600 baudios.
29 * - Espera durante 3 segundos la llegada de datos.
30 * - Si recibe datos, los imprime por consola.
31 * - Si no recibe nada, informa que no hubo actividad.
32 *
33 * @param serialPort Referencia al objeto HardwareSerial (por ejemplo, Serial1 o Serial2).
34 * @param portName Nombre del puerto UART para mostrar en consola.
35 */
36void diagnoseUARTStream(HardwareSerial& serialPort, const char* portName) {
37 Serial.println("📡 Diagnosing " + String(portName));
38
39 serialPort.begin(9600);
40 delay(100);
41
42 Serial.println("⌛ Waiting for data on " + String(portName) + " for 3 seconds...");
43
44 unsigned long start = millis();
45 bool received = false;
46
47 while (millis() - start < 3000) {
48 if (serialPort.available()) {
49 received = true;
50 Serial.print("📥 Data received on ");
51 Serial.print(portName);
52 Serial.print(": ");
53 while (serialPort.available()) {
54 char c = serialPort.read();
55 Serial.print(c);
56 }
57 Serial.println();
58 break;
59 }
60 }
61
62 if (!received) {
63 Serial.println("🔻 No data detected on " + String(portName));
64 }
65
66 // Do not call serialPort.end() to keep the port active
67 Serial.println("✅ End of diagnostic.\n");
68}
69
70/**
71 * @brief Ejecuta diagnóstico sobre Serial1 (UART1), si está disponible.
72 *
73 * Esta función solo se compila si HAVE_HWSERIAL1 está definido.
74 */
76#if defined(HAVE_HWSERIAL1)
77 diagnoseUARTStream(Serial1, "Serial1");
78#endif
79}
80
81/**
82 * @brief Ejecuta diagnóstico sobre Serial2 (UART2), si está disponible.
83 *
84 * Esta función solo se compila si HAVE_HWSERIAL2 está definido.
85 */
87#if defined(HAVE_HWSERIAL2)
88 diagnoseUARTStream(Serial2, "Serial2");
89#endif
90}
void diagnoseUARTStream(HardwareSerial &serialPort, const char *portName)
Realiza un diagnóstico sobre un puerto UART específico.
void diagnoseSerial2()
Ejecuta diagnóstico sobre Serial2 (UART2), si está disponible.
void diagnoseSerial1()
Ejecuta diagnóstico sobre Serial1 (UART1), si está disponible.
void diagnoseAllUART()
Ejecuta diagnósticos en todos los puertos UART disponibles.
void standardMessage(const char *message, const char *file, const char *function, const char *date, const char *time)
Prints an enriched log message to the serial monitor.
Definition msg.cpp:15
void standardHeaderFull(const char *message, const char *file, const char *function, const char *date, const char *time, uint16_t width=120, char deco='-')
Prints a decorated header with centered text and padding on both sides.
Definition msg.cpp:121