1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-25 09:15:38 +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 "io/frsky_firmware_update.h"
#if defined(LOG_BLUETOOTH)
extern FIL g_bluetoothFile;
#endif
#if defined(PCBX9E)
#define BLUETOOTH_COMMAND_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)
{
TRACE_NOCRLF("BT>");
BLUETOOTH_TRACE("BT>");
for (int i=0; i<length; i++) {
TRACE_NOCRLF(" %02X", data[i]);
BLUETOOTH_TRACE(" %02X", data[i]);
while (btTxFifo.isFull()) {
if (!bluetoothIsWriting())
bluetoothWriteWakeup();
@ -54,13 +58,13 @@ void Bluetooth::write(const uint8_t * data, uint8_t length)
}
btTxFifo.push(data[i]);
}
TRACE_NOCRLF("\r\n");
BLUETOOTH_TRACE(CRLF);
bluetoothWriteWakeup();
}
void Bluetooth::writeString(const char * str)
{
TRACE("BT> %s", str);
BLUETOOTH_TRACE("BT> %s" CRLF, str);
while (*str != 0) {
btTxFifo.push(*str++);
}
@ -77,19 +81,19 @@ char * Bluetooth::readline(bool error_reset)
if (!btRxFifo.pop(byte)) {
#if defined(PCBX9E)
// X9E BT module can get unresponsive
TRACE("NO RESPONSE FROM BT MODULE");
BLUETOOTH_TRACE("NO RESPONSE FROM BT MODULE" CRLF);
#endif
return nullptr;
}
TRACE_NOCRLF("%02X ", byte);
BLUETOOTH_TRACE("%02X ", byte);
#if 0
if (error_reset && byte == 'R' && bufferIndex == 4 && memcmp(buffer, "ERRO", 4)) {
#if defined(PCBX9E) // X9E enter BT reset loop if following code is implemented
TRACE("BT Error...");
BLUETOOTH_TRACE("BT Error..." CRLF);
#else
TRACE("BT Reset...");
BLUETOOTH_TRACE("BT Reset..." CRLF);
bufferIndex = 0;
bluetoothDisable();
state = BLUETOOTH_STATE_OFF;
@ -104,12 +108,12 @@ char * Bluetooth::readline(bool error_reset)
if (bufferIndex > 2 && buffer[bufferIndex-1] == '\r') {
buffer[bufferIndex-1] = '\0';
bufferIndex = 0;
TRACE("BT< %s", buffer);
BLUETOOTH_TRACE("BT< %s" CRLF, buffer);
if (error_reset && !strcmp((char *)buffer, "ERROR")) {
#if defined(PCBX9E) // X9E enter BT reset loop if following code is implemented
TRACE("BT Error...");
BLUETOOTH_TRACE("BT Error..." CRLF);
#else
TRACE("BT Reset...");
BLUETOOTH_TRACE("BT Reset..." CRLF);
bluetoothDisable();
state = BLUETOOTH_STATE_OFF;
wakeupTime = get_tmr10ms() + 100; /* 1s */
@ -137,7 +141,7 @@ char * Bluetooth::readline(bool error_reset)
void Bluetooth::processTrainerFrame(const uint8_t * buffer)
{
TRACE("");
BLUETOOTH_TRACE(CRLF);
for (uint8_t channel=0, i=1; channel<8; channel+=2, i+=3) {
// +-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)
if (data == '\n') {
if (!strncmp((char *)&buffer[bufferIndex-13], "isConnected", 11)) {
TRACE("BT< DisConnected");
BLUETOOTH_TRACE("BT< DisConnected" CRLF);
state = BLUETOOTH_STATE_DISCONNECTED;
bufferIndex = 0;
wakeupTime += 200; // 1s
@ -285,7 +289,7 @@ void Bluetooth::receiveTrainer()
return;
}
TRACE_NOCRLF("%02X ", byte);
BLUETOOTH_TRACE("%02X ", byte);
processTrainerByte(byte);
}

View file

@ -46,8 +46,17 @@ enum BluetoothStates {
#define LEN_BLUETOOTH_ADDR 16
#define MAX_BLUETOOTH_DISTANT_ADDR 6
#define BLUETOOTH_PACKET_SIZE 14
#define BLUETOOTH_LINE_LENGTH 32
#define BLUETOOTH_PACKET_SIZE 14
#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
{

View file

@ -24,6 +24,9 @@
#include <inttypes.h>
#include "rtc.h"
#include "dump.h"
#define CRLF "\r\n"
#if defined(CLI)
#include "cli.h"
#else
@ -56,7 +59,7 @@ uint8_t auxSerialTracesEnabled();
#endif
#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 TRACE_DEBUG(...) debugPrintf("-D- " __VA_ARGS__)
#define TRACE_DEBUG_WP(...) debugPrintf(__VA_ARGS__)
@ -67,7 +70,7 @@ uint8_t auxSerialTracesEnabled();
#define TRACE_ERROR(...) debugPrintf("-E- " __VA_ARGS__)
#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 { \
lua_Debug ar; \
@ -75,7 +78,7 @@ uint8_t auxSerialTracesEnabled();
lua_getinfo(L, ">Sl", &ar); \
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)
#else
#define TRACE_LUA_INTERNALS(...)

View file

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

View file

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

View file

@ -1398,7 +1398,7 @@ extern uint8_t latencyToggleSwitch;
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;
#endif

View file

@ -3,6 +3,7 @@ set_property(CACHE TIMERS PROPERTY STRINGS 2 3)
option(CLI "Command Line Interface" OFF)
option(DEBUG "Debug mode" 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_FATFS "Traces FatFS enabled" OFF)
option(TRACE_AUDIO "Traces audio enabled" OFF)
@ -30,6 +31,10 @@ if(LOG_TELEMETRY)
add_definitions(-DLOG_TELEMETRY)
endif()
if(LOG_BLUETOOTH)
add_definitions(-DLOG_BLUETOOTH)
endif()
if(TRACE_SD_CARD)
add_definitions(-DTRACE_SD_CARD)
set(DEBUG ON)

View file

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

View file

@ -214,6 +214,13 @@ void sdInit(void)
f_lseek(&g_telemetryFile, f_size(&g_telemetryFile)); // append
}
#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 {
TRACE_SIMPGMSPACE("f_mount() failed");
@ -226,6 +233,9 @@ void sdDone()
audioQueue.stopSD();
#if defined(LOG_TELEMETRY)
f_close(&g_telemetryFile);
#endif
#if defined(LOG_BLUETOOTH)
f_close(&g_bluetoothFile);
#endif
f_mount(NULL, "", 0); // unmount SD
}

View file

@ -978,10 +978,15 @@ void sdPoll10ms()
// TODO everything here should not be in the driver layer ...
FATFS g_FATFS_Obj;
#if defined(LOG_TELEMETRY)
FIL g_telemetryFile = {};
#endif
#if defined(LOG_BLUETOOTH)
FIL g_bluetoothFile = {};
#endif
#if defined(BOOT)
void sdInit(void)
{
@ -1016,6 +1021,13 @@ void sdMount()
f_lseek(&g_telemetryFile, f_size(&g_telemetryFile)); // append
}
#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();
#if defined(LOG_TELEMETRY)
f_close(&g_telemetryFile);
#endif
#if defined(LOG_BLUETOOTH)
f_close(&g_bluetoothFile);
#endif
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],
rxBuffer[i*4 + 4], rxBuffer[i*4 + 5]);
}
debugPrintf("\r\n");
debugPrintf(CRLF);
#endif
if (data == 0xAA) processFlySkyPacket(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++) {
debugPrintf("%02X ", rxBuffer[4+i]);
}
debugPrintf("\r\n");
debugPrintf(CRLF);
#endif
processHitecPacket(rxBuffer + 1);
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],
rxBuffer[i*4 + 4], rxBuffer[i*4 + 5]);
}
debugPrintf("\r\n");
debugPrintf(CRLF);
#endif
// Packet is complete, process it
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],
rxBuffer[i + 2], rxBuffer[i + 3]);
}
debugPrintf("\r\n");
debugPrintf(CRLF);
#endif
processSpektrumPacket(rxBuffer);
rxBufferCount = 0;