1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-26 01:35:21 +03:00

Bluetooth SD logs (#7197)

Bluetooth SD logs
This commit is contained in:
Bertrand Songis 2019-12-16 12:22:48 +01:00 committed by GitHub
parent b475a7064d
commit 16c9a92f49
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 94 additions and 31 deletions

View file

@ -21,6 +21,10 @@
#include "opentx.h" #include "opentx.h"
#include "io/frsky_firmware_update.h" #include "io/frsky_firmware_update.h"
#if defined(LOG_BLUETOOTH)
extern FIL g_bluetoothFile;
#endif
#if defined(PCBX9E) #if defined(PCBX9E)
#define BLUETOOTH_COMMAND_NAME "TTM:REN-" #define BLUETOOTH_COMMAND_NAME "TTM:REN-"
#define BLUETOOTH_ANSWER_NAME "TTM:REN" #define BLUETOOTH_ANSWER_NAME "TTM:REN"
@ -44,9 +48,9 @@ Bluetooth bluetooth;
void Bluetooth::write(const uint8_t * data, uint8_t length) void Bluetooth::write(const uint8_t * data, uint8_t length)
{ {
TRACE_NOCRLF("BT>"); BLUETOOTH_TRACE("BT>");
for (int i=0; i<length; i++) { for (int i=0; i<length; i++) {
TRACE_NOCRLF(" %02X", data[i]); BLUETOOTH_TRACE(" %02X", data[i]);
while (btTxFifo.isFull()) { while (btTxFifo.isFull()) {
if (!bluetoothIsWriting()) if (!bluetoothIsWriting())
bluetoothWriteWakeup(); bluetoothWriteWakeup();
@ -54,13 +58,13 @@ void Bluetooth::write(const uint8_t * data, uint8_t length)
} }
btTxFifo.push(data[i]); btTxFifo.push(data[i]);
} }
TRACE_NOCRLF("\r\n"); BLUETOOTH_TRACE(CRLF);
bluetoothWriteWakeup(); bluetoothWriteWakeup();
} }
void Bluetooth::writeString(const char * str) void Bluetooth::writeString(const char * str)
{ {
TRACE("BT> %s", str); BLUETOOTH_TRACE("BT> %s" CRLF, str);
while (*str != 0) { while (*str != 0) {
btTxFifo.push(*str++); btTxFifo.push(*str++);
} }
@ -77,19 +81,19 @@ char * Bluetooth::readline(bool error_reset)
if (!btRxFifo.pop(byte)) { if (!btRxFifo.pop(byte)) {
#if defined(PCBX9E) #if defined(PCBX9E)
// X9E BT module can get unresponsive // X9E BT module can get unresponsive
TRACE("NO RESPONSE FROM BT MODULE"); BLUETOOTH_TRACE("NO RESPONSE FROM BT MODULE" CRLF);
#endif #endif
return nullptr; return nullptr;
} }
TRACE_NOCRLF("%02X ", byte); BLUETOOTH_TRACE("%02X ", byte);
#if 0 #if 0
if (error_reset && byte == 'R' && bufferIndex == 4 && memcmp(buffer, "ERRO", 4)) { if (error_reset && byte == 'R' && bufferIndex == 4 && memcmp(buffer, "ERRO", 4)) {
#if defined(PCBX9E) // X9E enter BT reset loop if following code is implemented #if defined(PCBX9E) // X9E enter BT reset loop if following code is implemented
TRACE("BT Error..."); BLUETOOTH_TRACE("BT Error..." CRLF);
#else #else
TRACE("BT Reset..."); BLUETOOTH_TRACE("BT Reset..." CRLF);
bufferIndex = 0; bufferIndex = 0;
bluetoothDisable(); bluetoothDisable();
state = BLUETOOTH_STATE_OFF; state = BLUETOOTH_STATE_OFF;
@ -104,12 +108,12 @@ char * Bluetooth::readline(bool error_reset)
if (bufferIndex > 2 && buffer[bufferIndex-1] == '\r') { if (bufferIndex > 2 && buffer[bufferIndex-1] == '\r') {
buffer[bufferIndex-1] = '\0'; buffer[bufferIndex-1] = '\0';
bufferIndex = 0; bufferIndex = 0;
TRACE("BT< %s", buffer); BLUETOOTH_TRACE("BT< %s" CRLF, buffer);
if (error_reset && !strcmp((char *)buffer, "ERROR")) { if (error_reset && !strcmp((char *)buffer, "ERROR")) {
#if defined(PCBX9E) // X9E enter BT reset loop if following code is implemented #if defined(PCBX9E) // X9E enter BT reset loop if following code is implemented
TRACE("BT Error..."); BLUETOOTH_TRACE("BT Error..." CRLF);
#else #else
TRACE("BT Reset..."); BLUETOOTH_TRACE("BT Reset..." CRLF);
bluetoothDisable(); bluetoothDisable();
state = BLUETOOTH_STATE_OFF; state = BLUETOOTH_STATE_OFF;
wakeupTime = get_tmr10ms() + 100; /* 1s */ wakeupTime = get_tmr10ms() + 100; /* 1s */
@ -137,7 +141,7 @@ char * Bluetooth::readline(bool error_reset)
void Bluetooth::processTrainerFrame(const uint8_t * buffer) void Bluetooth::processTrainerFrame(const uint8_t * buffer)
{ {
TRACE(""); BLUETOOTH_TRACE(CRLF);
for (uint8_t channel=0, i=1; channel<8; channel+=2, i+=3) { for (uint8_t channel=0, i=1; channel<8; channel+=2, i+=3) {
// +-500 != 512, but close enough. // +-500 != 512, but close enough.
@ -155,7 +159,7 @@ void Bluetooth::appendTrainerByte(uint8_t data)
// we check for "DisConnected", but the first byte could be altered (if received in state STATE_DATA_XOR) // we check for "DisConnected", but the first byte could be altered (if received in state STATE_DATA_XOR)
if (data == '\n') { if (data == '\n') {
if (!strncmp((char *)&buffer[bufferIndex-13], "isConnected", 11)) { if (!strncmp((char *)&buffer[bufferIndex-13], "isConnected", 11)) {
TRACE("BT< DisConnected"); BLUETOOTH_TRACE("BT< DisConnected" CRLF);
state = BLUETOOTH_STATE_DISCONNECTED; state = BLUETOOTH_STATE_DISCONNECTED;
bufferIndex = 0; bufferIndex = 0;
wakeupTime += 200; // 1s wakeupTime += 200; // 1s
@ -285,7 +289,7 @@ void Bluetooth::receiveTrainer()
return; return;
} }
TRACE_NOCRLF("%02X ", byte); BLUETOOTH_TRACE("%02X ", byte);
processTrainerByte(byte); processTrainerByte(byte);
} }

View file

@ -49,6 +49,15 @@ enum BluetoothStates {
#define BLUETOOTH_PACKET_SIZE 14 #define BLUETOOTH_PACKET_SIZE 14
#define BLUETOOTH_LINE_LENGTH 32 #define BLUETOOTH_LINE_LENGTH 32
#if defined(LOG_BLUETOOTH)
#define BLUETOOTH_TRACE(str, ...) \
f_printf(&g_bluetoothFile, str, ##__VA_ARGS__); \
TRACE_NOCRLF(str, ##__VA_ARGS__);
#else
#define BLUETOOTH_TRACE(str, ...) \
TRACE_NOCRLF(str, ##__VA_ARGS__);
#endif
class Bluetooth class Bluetooth
{ {
public: public:

View file

@ -24,6 +24,9 @@
#include <inttypes.h> #include <inttypes.h>
#include "rtc.h" #include "rtc.h"
#include "dump.h" #include "dump.h"
#define CRLF "\r\n"
#if defined(CLI) #if defined(CLI)
#include "cli.h" #include "cli.h"
#else #else
@ -56,7 +59,7 @@ uint8_t auxSerialTracesEnabled();
#endif #endif
#define TRACE_NOCRLF(...) debugPrintf(__VA_ARGS__) #define TRACE_NOCRLF(...) debugPrintf(__VA_ARGS__)
#define TRACE(f_, ...) debugPrintf((f_ "\r\n"), ##__VA_ARGS__) #define TRACE(f_, ...) debugPrintf((f_ CRLF), ##__VA_ARGS__)
#define DUMP(data, size) dump(data, size) #define DUMP(data, size) dump(data, size)
#define TRACE_DEBUG(...) debugPrintf("-D- " __VA_ARGS__) #define TRACE_DEBUG(...) debugPrintf("-D- " __VA_ARGS__)
#define TRACE_DEBUG_WP(...) debugPrintf(__VA_ARGS__) #define TRACE_DEBUG_WP(...) debugPrintf(__VA_ARGS__)
@ -67,7 +70,7 @@ uint8_t auxSerialTracesEnabled();
#define TRACE_ERROR(...) debugPrintf("-E- " __VA_ARGS__) #define TRACE_ERROR(...) debugPrintf("-E- " __VA_ARGS__)
#if defined(TRACE_LUA_INTERNALS_ENABLED) #if defined(TRACE_LUA_INTERNALS_ENABLED)
#define TRACE_LUA_INTERNALS(f_, ...) debugPrintf(("[LUA INT] " f_ "\r\n"), ##__VA_ARGS__) #define TRACE_LUA_INTERNALS(f_, ...) debugPrintf(("[LUA INT] " f_ CRLF), ##__VA_ARGS__)
#define TRACE_LUA_INTERNALS_WITH_LINEINFO(L, f_, ...) do { \ #define TRACE_LUA_INTERNALS_WITH_LINEINFO(L, f_, ...) do { \
lua_Debug ar; \ lua_Debug ar; \
@ -75,7 +78,7 @@ uint8_t auxSerialTracesEnabled();
lua_getinfo(L, ">Sl", &ar); \ lua_getinfo(L, ">Sl", &ar); \
debugPrintf("%s:%d: ", ar.short_src, ar.currentline); \ debugPrintf("%s:%d: ", ar.short_src, ar.currentline); \
} \ } \
debugPrintf(("[LUA INT] " f_ "\r\n"), ##__VA_ARGS__); \ debugPrintf(("[LUA INT] " f_ CRLF), ##__VA_ARGS__); \
} while(0) } while(0)
#else #else
#define TRACE_LUA_INTERNALS(...) #define TRACE_LUA_INTERNALS(...)

View file

@ -40,14 +40,14 @@ void dumpBody(const void *data, unsigned int size)
dumpPrintf("%.2X ", ((uint8_t *)data)[i]); dumpPrintf("%.2X ", ((uint8_t *)data)[i]);
dumpPosition++; dumpPosition++;
if ((dumpPosition & (32-1)) == 0) { if ((dumpPosition & (32-1)) == 0) {
dumpPrintf("\r\n"); dumpPrintf(CRLF);
} }
} }
} }
void dumpEnd() void dumpEnd()
{ {
dumpPrintf("\r\n"); dumpPrintf(CRLF);
} }
#if defined(DEBUG) || defined(CLI) #if defined(DEBUG) || defined(CLI)

View file

@ -90,11 +90,10 @@ class DefaultTheme: public Theme
void loadIcons() const void loadIcons() const
{ {
#if defined(LOG_TELEMETRY) || !defined(WATCHDOG) if (isAsteriskDisplayed())
loadMenuIcon(ICON_OPENTX, "mask_opentx_testmode.png", TEXT_COLOR); loadMenuIcon(ICON_OPENTX, "mask_opentx_testmode.png", TEXT_COLOR);
#else else
loadMenuIcon(ICON_OPENTX, "mask_opentx.png"); loadMenuIcon(ICON_OPENTX, "mask_opentx.png");
#endif
loadMenuIcon(ICON_RADIO, "mask_menu_radio.png"); loadMenuIcon(ICON_RADIO, "mask_menu_radio.png");
loadMenuIcon(ICON_RADIO_SETUP, "mask_radio_setup.png"); loadMenuIcon(ICON_RADIO_SETUP, "mask_radio_setup.png");
loadMenuIcon(ICON_RADIO_SD_MANAGER, "mask_radio_sd_browser.png"); loadMenuIcon(ICON_RADIO_SD_MANAGER, "mask_radio_sd_browser.png");

View file

@ -1398,7 +1398,7 @@ extern uint8_t latencyToggleSwitch;
inline bool isAsteriskDisplayed() inline bool isAsteriskDisplayed()
{ {
#if defined(ASTERISK) || !defined(WATCHDOG) || defined(LOG_TELEMETRY) || defined(DEBUG_LATENCY) #if defined(ASTERISK) || !defined(WATCHDOG) || defined(LOG_TELEMETRY) || defined(LOG_BLUETOOTH) || defined(DEBUG_LATENCY)
return true; return true;
#endif #endif

View file

@ -3,6 +3,7 @@ set_property(CACHE TIMERS PROPERTY STRINGS 2 3)
option(CLI "Command Line Interface" OFF) option(CLI "Command Line Interface" OFF)
option(DEBUG "Debug mode" OFF) option(DEBUG "Debug mode" OFF)
option(LOG_TELEMETRY "Telemetry Logs on SD card" OFF) option(LOG_TELEMETRY "Telemetry Logs on SD card" OFF)
option(LOG_BLUETOOTH "Bluetooth Logs on SD card" OFF)
option(TRACE_SD_CARD "Traces SD enabled" OFF) option(TRACE_SD_CARD "Traces SD enabled" OFF)
option(TRACE_FATFS "Traces FatFS enabled" OFF) option(TRACE_FATFS "Traces FatFS enabled" OFF)
option(TRACE_AUDIO "Traces audio enabled" OFF) option(TRACE_AUDIO "Traces audio enabled" OFF)
@ -30,6 +31,10 @@ if(LOG_TELEMETRY)
add_definitions(-DLOG_TELEMETRY) add_definitions(-DLOG_TELEMETRY)
endif() endif()
if(LOG_BLUETOOTH)
add_definitions(-DLOG_BLUETOOTH)
endif()
if(TRACE_SD_CARD) if(TRACE_SD_CARD)
add_definitions(-DTRACE_SD_CARD) add_definitions(-DTRACE_SD_CARD)
set(DEBUG ON) set(DEBUG ON)

View file

@ -310,10 +310,15 @@ DRESULT disk_ioctl (
// TODO everything here should not be in the driver layer ... // TODO everything here should not be in the driver layer ...
FATFS g_FATFS_Obj __DMA; // initialized in boardInit() FATFS g_FATFS_Obj __DMA; // initialized in boardInit()
#if defined(LOG_TELEMETRY) #if defined(LOG_TELEMETRY)
FIL g_telemetryFile = {}; FIL g_telemetryFile = {};
#endif #endif
#if defined(LOG_BLUETOOTH)
FIL g_bluetoothFile = {};
#endif
#if defined(BOOT) #if defined(BOOT)
void sdInit(void) void sdInit(void)
{ {
@ -350,6 +355,13 @@ void sdMount()
f_lseek(&g_telemetryFile, f_size(&g_telemetryFile)); // append f_lseek(&g_telemetryFile, f_size(&g_telemetryFile)); // append
} }
#endif #endif
#if defined(LOG_BLUETOOTH)
f_open(&g_bluetoothFile, LOGS_PATH "/bluetooth.log", FA_OPEN_ALWAYS | FA_WRITE);
if (f_size(&g_bluetoothFile) > 0) {
f_lseek(&g_bluetoothFile, f_size(&g_bluetoothFile)); // append
}
#endif
} }
else { else {
TRACE("f_mount() failed"); TRACE("f_mount() failed");
@ -362,9 +374,15 @@ void sdDone()
if (sdMounted()) { if (sdMounted()) {
audioQueue.stopSD(); audioQueue.stopSD();
#if defined(LOG_TELEMETRY) #if defined(LOG_TELEMETRY)
f_close(&g_telemetryFile); f_close(&g_telemetryFile);
#endif #endif
#if defined(LOG_BLUETOOTH)
f_close(&g_bluetoothFile);
#endif
f_mount(nullptr, "", 0); // unmount SD f_mount(nullptr, "", 0); // unmount SD
} }
} }

View file

@ -214,6 +214,13 @@ void sdInit(void)
f_lseek(&g_telemetryFile, f_size(&g_telemetryFile)); // append f_lseek(&g_telemetryFile, f_size(&g_telemetryFile)); // append
} }
#endif #endif
#if defined(LOG_BLUETOOTH)
f_open(&g_bluetoothFile, LOGS_PATH "/bluetooth.log", FA_OPEN_ALWAYS | FA_WRITE);
if (f_size(&g_bluetoothFile) > 0) {
f_lseek(&g_bluetoothFile, f_size(&g_bluetoothFile)); // append
}
#endif
} }
else { else {
TRACE_SIMPGMSPACE("f_mount() failed"); TRACE_SIMPGMSPACE("f_mount() failed");
@ -226,6 +233,9 @@ void sdDone()
audioQueue.stopSD(); audioQueue.stopSD();
#if defined(LOG_TELEMETRY) #if defined(LOG_TELEMETRY)
f_close(&g_telemetryFile); f_close(&g_telemetryFile);
#endif
#if defined(LOG_BLUETOOTH)
f_close(&g_bluetoothFile);
#endif #endif
f_mount(NULL, "", 0); // unmount SD f_mount(NULL, "", 0); // unmount SD
} }

View file

@ -978,10 +978,15 @@ void sdPoll10ms()
// TODO everything here should not be in the driver layer ... // TODO everything here should not be in the driver layer ...
FATFS g_FATFS_Obj; FATFS g_FATFS_Obj;
#if defined(LOG_TELEMETRY) #if defined(LOG_TELEMETRY)
FIL g_telemetryFile = {}; FIL g_telemetryFile = {};
#endif #endif
#if defined(LOG_BLUETOOTH)
FIL g_bluetoothFile = {};
#endif
#if defined(BOOT) #if defined(BOOT)
void sdInit(void) void sdInit(void)
{ {
@ -1016,6 +1021,13 @@ void sdMount()
f_lseek(&g_telemetryFile, f_size(&g_telemetryFile)); // append f_lseek(&g_telemetryFile, f_size(&g_telemetryFile)); // append
} }
#endif #endif
#if defined(LOG_BLUETOOTH)
f_open(&g_bluetoothFile, LOGS_PATH "/bluetooth.log", FA_OPEN_ALWAYS | FA_WRITE);
if (f_size(&g_bluetoothFile) > 0) {
f_lseek(&g_bluetoothFile, f_size(&g_bluetoothFile)); // append
}
#endif
} }
} }
@ -1025,6 +1037,9 @@ void sdDone()
audioQueue.stopSD(); audioQueue.stopSD();
#if defined(LOG_TELEMETRY) #if defined(LOG_TELEMETRY)
f_close(&g_telemetryFile); f_close(&g_telemetryFile);
#endif
#if defined(LOG_BLUETOOTH)
f_close(&g_bluetoothFile);
#endif #endif
f_mount(nullptr, "", 0); // unmount SD f_mount(nullptr, "", 0); // unmount SD
} }

View file

@ -282,7 +282,7 @@ void processFlySkyTelemetryData(uint8_t data, uint8_t * rxBuffer, uint8_t &rxBuf
debugPrintf("[%02X %02X %02X%02X] ", rxBuffer[i*4+2], rxBuffer[i*4 + 3], debugPrintf("[%02X %02X %02X%02X] ", rxBuffer[i*4+2], rxBuffer[i*4 + 3],
rxBuffer[i*4 + 4], rxBuffer[i*4 + 5]); rxBuffer[i*4 + 4], rxBuffer[i*4 + 5]);
} }
debugPrintf("\r\n"); debugPrintf(CRLF);
#endif #endif
if (data == 0xAA) processFlySkyPacket(rxBuffer + 1); if (data == 0xAA) processFlySkyPacket(rxBuffer + 1);
else if (data == 0xAC) processFlySkyPacketAC(rxBuffer + 1); else if (data == 0xAC) processFlySkyPacketAC(rxBuffer + 1);

View file

@ -401,7 +401,7 @@ void processHitecTelemetryData(uint8_t data, uint8_t * rxBuffer, uint8_t &rxBuff
for (int i=0; i<5; i++) { for (int i=0; i<5; i++) {
debugPrintf("%02X ", rxBuffer[4+i]); debugPrintf("%02X ", rxBuffer[4+i]);
} }
debugPrintf("\r\n"); debugPrintf(CRLF);
#endif #endif
processHitecPacket(rxBuffer + 1); processHitecPacket(rxBuffer + 1);
rxBufferCount = 0; rxBufferCount = 0;

View file

@ -621,7 +621,7 @@ static void processMultiTelemetryByte(const uint8_t data, uint8_t module)
debugPrintf("[%02X%02X %02X%02X] ", rxBuffer[i*4+2], rxBuffer[i*4 + 3], debugPrintf("[%02X%02X %02X%02X] ", rxBuffer[i*4+2], rxBuffer[i*4 + 3],
rxBuffer[i*4 + 4], rxBuffer[i*4 + 5]); rxBuffer[i*4 + 4], rxBuffer[i*4 + 5]);
} }
debugPrintf("\r\n"); debugPrintf(CRLF);
#endif #endif
// Packet is complete, process it // Packet is complete, process it
processMultiTelemetryPaket(rxBuffer, module); processMultiTelemetryPaket(rxBuffer, module);

View file

@ -434,7 +434,7 @@ void processSpektrumTelemetryData(uint8_t module, uint8_t data, uint8_t* rxBuffe
debugPrintf("%02X%02X %02X%02X ", rxBuffer[i], rxBuffer[i + 1], debugPrintf("%02X%02X %02X%02X ", rxBuffer[i], rxBuffer[i + 1],
rxBuffer[i + 2], rxBuffer[i + 3]); rxBuffer[i + 2], rxBuffer[i + 3]);
} }
debugPrintf("\r\n"); debugPrintf(CRLF);
#endif #endif
processSpektrumPacket(rxBuffer); processSpektrumPacket(rxBuffer);
rxBufferCount = 0; rxBufferCount = 0;