New logging and more (#446)

- `TT_LOG_*` macros are replaced by `Logger` via `#include<Tactility/Logger.h>`
- Changed default timezone to Europe/Amsterdam
- Fix for logic bug in unPhone hardware
- Fix for init/deinit in DRV2605 driver
- Other fixes
- Removed optimization that broke unPhone (disabled the moving of heap-related functions to flash)
This commit is contained in:
Ken Van Hoeylandt
2026-01-06 22:35:39 +01:00
committed by GitHub
parent 719f7bcece
commit f620255c41
188 changed files with 1973 additions and 1755 deletions
+38 -39
View File
@@ -2,13 +2,13 @@
#include <Tactility/hal/gps/UbloxMessages.h>
#include <Tactility/hal/uart/Uart.h>
#include <Tactility/kernel/Kernel.h>
#include <Tactility/Log.h>
#include <Tactility/Logger.h>
#include <cstring>
namespace tt::hal::gps::ublox {
constexpr auto TAG = "ublox";
static const auto LOGGER = Logger("Ublox");
bool initUblox6(uart::Uart& uart);
bool initUblox789(uart::Uart& uart, GpsModel model);
@@ -19,7 +19,7 @@ bool initUblox10(uart::Uart& uart);
auto msglen = makePacket(TYPE, ID, DATA, sizeof(DATA), BUFFER); \
UART.writeBytes(BUFFER, sizeof(BUFFER)); \
if (getAck(UART, TYPE, ID, TIMEOUT) != GpsResponse::Ok) { \
TT_LOG_I(TAG, "Sending packet failed: %s", #ERRMSG); \
LOGGER.info("Sending packet failed: {}", #ERRMSG); \
} \
} while (0)
@@ -82,7 +82,7 @@ GpsResponse getAck(uart::Uart& uart, uint8_t class_id, uint8_t msg_id, uint32_t
while (kernel::getTicks() - startTime < waitMillis) {
if (ack > 9) {
#ifdef GPS_DEBUG
TT_LOG_I(TAG, "Got ACK for class %02X message %02X in %lums", class_id, msg_id, kernel::getMillis() - startTime);
LOGGER.info("Got ACK for class {:02X} message {:02X} in {}ms", class_id, msg_id, kernel::getMillis() - startTime);
#endif
return GpsResponse::Ok; // ACK received
}
@@ -93,7 +93,7 @@ GpsResponse getAck(uart::Uart& uart, uint8_t class_id, uint8_t msg_id, uint32_t
if (sCounter == 26) {
#ifdef GPS_DEBUG
TT_LOG_I(TAG, "%s", debugmsg.c_str());
LOGGER.info("%s", debugmsg.c_str());
#endif
return GpsResponse::FrameErrors;
}
@@ -108,9 +108,9 @@ GpsResponse getAck(uart::Uart& uart, uint8_t class_id, uint8_t msg_id, uint32_t
} else {
if (ack == 3 && b == 0x00) { // UBX-ACK-NAK message
#ifdef GPS_DEBUG
TT_LOG_I(TAG, "%s", debugmsg.c_str());
LOGGER.info("%s", debugmsg.c_str());
#endif
TT_LOG_W(TAG, "Got NAK for class %02X message %02X", class_id, msg_id);
LOGGER.warn("Got NAK for class {:02X} message {:02X}", class_id, msg_id);
return GpsResponse::NotAck; // NAK received
}
ack = 0; // Reset the acknowledgement counter
@@ -118,8 +118,8 @@ GpsResponse getAck(uart::Uart& uart, uint8_t class_id, uint8_t msg_id, uint32_t
}
}
#ifdef GPS_DEBUG
TT_LOG_I(TAG, "%s", debugmsg.c_str());
TT_LOG_W(TAG, "No response for class %02X message %02X", class_id, msg_id);
LOGGER.info("%s", debugmsg.c_str());
LOGGER.warn("No response for class %02X message %02X", class_id, msg_id);
#endif
return GpsResponse::None; // No response received within timeout
}
@@ -180,7 +180,7 @@ static int getAck(uart::Uart& uart, uint8_t* buffer, uint16_t size, uint8_t requ
} else {
// return payload length
#ifdef GPS_DEBUG
TT_LOG_I(TAG, "Got ACK for class %02X message %02X in %lums", requestedClass, requestedId, kernel::getMillis() - startTime);
LOGGER.info("Got ACK for class {:02X} message {:02X} in {}ms", requestedClass, requestedId, kernel::getMillis() - startTime);
#endif
return needRead;
}
@@ -195,8 +195,6 @@ static int getAck(uart::Uart& uart, uint8_t* buffer, uint16_t size, uint8_t requ
return 0;
}
#define DETECTED_MESSAGE "%s detected, using %s Module"
static struct uBloxGnssModelInfo {
char swVersion[30];
char hwVersion[10];
@@ -206,7 +204,8 @@ static struct uBloxGnssModelInfo {
} ublox_info;
GpsModel probe(uart::Uart& uart) {
TT_LOG_I(TAG, "Probing for U-blox");
LOGGER.info("Probing for U-blox");
constexpr auto DETECTED_MESSAGE = "{} detected, using {} Module";
uint8_t cfg_rate[] = {0xB5, 0x62, 0x06, 0x08, 0x00, 0x00, 0x00, 0x00};
checksum(cfg_rate, sizeof(cfg_rate));
@@ -215,10 +214,10 @@ GpsModel probe(uart::Uart& uart) {
// Check that the returned response class and message ID are correct
GpsResponse response = getAck(uart, 0x06, 0x08, 750);
if (response == GpsResponse::None) {
TT_LOG_W(TAG, "No GNSS Module (baudrate %lu)", uart.getBaudRate());
LOGGER.warn("No GNSS Module (baudrate {})", uart.getBaudRate());
return GpsModel::Unknown;
} else if (response == GpsResponse::FrameErrors) {
TT_LOG_W(TAG, "UBlox Frame Errors (baudrate %lu)", uart.getBaudRate());
LOGGER.warn("UBlox Frame Errors (baudrate {})", uart.getBaudRate());
}
uint8_t buffer[256];
@@ -256,12 +255,12 @@ GpsModel probe(uart::Uart& uart) {
break;
}
TT_LOG_I(TAG, "Module Info : ");
TT_LOG_I(TAG, "Soft version: %s", ublox_info.swVersion);
TT_LOG_I(TAG, "Hard version: %s", ublox_info.hwVersion);
TT_LOG_I(TAG, "Extensions:%d", ublox_info.extensionNo);
LOGGER.info("Module Info:");
LOGGER.info("Soft version: {}", ublox_info.swVersion);
LOGGER.info("Hard version: {}", ublox_info.hwVersion);
LOGGER.info("Extensions: {}", ublox_info.extensionNo);
for (int i = 0; i < ublox_info.extensionNo; i++) {
TT_LOG_I(TAG, " %s", ublox_info.extension[i]);
LOGGER.info(" %s", ublox_info.extension[i]);
}
memset(buffer, 0, sizeof(buffer));
@@ -274,29 +273,29 @@ GpsModel probe(uart::Uart& uart) {
char* ptr = nullptr;
memset(buffer, 0, sizeof(buffer));
strncpy((char*)buffer, &(ublox_info.extension[i][8]), sizeof(buffer));
TT_LOG_I(TAG, "Protocol Version:%s", (char*)buffer);
LOGGER.info("Protocol Version: {}", (char*)buffer);
if (strlen((char*)buffer)) {
ublox_info.protocol_version = strtoul((char*)buffer, &ptr, 10);
TT_LOG_I(TAG, "ProtVer=%d", ublox_info.protocol_version);
LOGGER.info("ProtVer={}", ublox_info.protocol_version);
} else {
ublox_info.protocol_version = 0;
}
}
}
if (strncmp(ublox_info.hwVersion, "00040007", 8) == 0) {
TT_LOG_I(TAG, DETECTED_MESSAGE, "U-blox 6", "6");
LOGGER.info(DETECTED_MESSAGE, "U-blox 6", "6");
return GpsModel::UBLOX6;
} else if (strncmp(ublox_info.hwVersion, "00070000", 8) == 0) {
TT_LOG_I(TAG, DETECTED_MESSAGE, "U-blox 7", "7");
LOGGER.info(DETECTED_MESSAGE, "U-blox 7", "7");
return GpsModel::UBLOX7;
} else if (strncmp(ublox_info.hwVersion, "00080000", 8) == 0) {
TT_LOG_I(TAG, DETECTED_MESSAGE, "U-blox 8", "8");
LOGGER.info(DETECTED_MESSAGE, "U-blox 8", "8");
return GpsModel::UBLOX8;
} else if (strncmp(ublox_info.hwVersion, "00190000", 8) == 0) {
TT_LOG_I(TAG, DETECTED_MESSAGE, "U-blox 9", "9");
LOGGER.info(DETECTED_MESSAGE, "U-blox 9", "9");
return GpsModel::UBLOX9;
} else if (strncmp(ublox_info.hwVersion, "000A0000", 8) == 0) {
TT_LOG_I(TAG, DETECTED_MESSAGE, "U-blox 10", "10");
LOGGER.info(DETECTED_MESSAGE, "U-blox 10", "10");
return GpsModel::UBLOX10;
}
}
@@ -305,7 +304,7 @@ GpsModel probe(uart::Uart& uart) {
}
bool init(uart::Uart& uart, GpsModel model) {
TT_LOG_I(TAG, "U-blox init");
LOGGER.info("U-blox init");
switch (model) {
case GpsModel::UBLOX6:
return initUblox6(uart);
@@ -316,7 +315,7 @@ bool init(uart::Uart& uart, GpsModel model) {
case GpsModel::UBLOX10:
return initUblox10(uart);
default:
TT_LOG_E(TAG, "Unknown or unsupported U-blox model");
LOGGER.error("Unknown or unsupported U-blox model");
return false;
}
}
@@ -365,9 +364,9 @@ bool initUblox10(uart::Uart& uart) {
auto packet_size = makePacket(0x06, 0x09, _message_SAVE_10, sizeof(_message_SAVE_10), buffer);
uart.writeBytes(buffer, packet_size);
if (getAck(uart, 0x06, 0x09, 2000) != GpsResponse::Ok) {
TT_LOG_W(TAG, "Unable to save GNSS module config");
LOGGER.warn("Unable to save GNSS module config");
} else {
TT_LOG_I(TAG, "GNSS module configuration saved!");
LOGGER.info("GNSS module configuration saved!");
}
return true;
}
@@ -375,7 +374,7 @@ bool initUblox10(uart::Uart& uart) {
bool initUblox789(uart::Uart& uart, GpsModel model) {
uint8_t buffer[256];
if (model == GpsModel::UBLOX7) {
TT_LOG_D(TAG, "Set GPS+SBAS");
LOGGER.debug("Set GPS+SBAS");
auto msglen = makePacket(0x06, 0x3e, _message_GNSS_7, sizeof(_message_GNSS_7), buffer);
uart.writeBytes(buffer, msglen);
} else { // 8,9
@@ -385,12 +384,12 @@ bool initUblox789(uart::Uart& uart, GpsModel model) {
if (getAck(uart, 0x06, 0x3e, 800) == GpsResponse::NotAck) {
// It's not critical if the module doesn't acknowledge this configuration.
TT_LOG_D(TAG, "reconfigure GNSS - defaults maintained. Is this module GPS-only?");
LOGGER.debug("reconfigure GNSS - defaults maintained. Is this module GPS-only?");
} else {
if (model == GpsModel::UBLOX7) {
TT_LOG_I(TAG, "GPS+SBAS configured");
LOGGER.info("GPS+SBAS configured");
} else { // 8,9
TT_LOG_I(TAG, "GPS+SBAS+GLONASS+Galileo configured");
LOGGER.info("GPS+SBAS+GLONASS+Galileo configured");
}
// Documentation say, we need wait at least 0.5s after reconfiguration of GNSS module, before sending next
// commands for the M8 it tends to be more. 1 sec should be enough
@@ -439,9 +438,9 @@ bool initUblox789(uart::Uart& uart, GpsModel model) {
auto packet_size = makePacket(0x06, 0x09, _message_SAVE, sizeof(_message_SAVE), buffer);
uart.writeBytes(buffer, packet_size);
if (getAck(uart, 0x06, 0x09, 2000) != GpsResponse::Ok) {
TT_LOG_W(TAG, "Unable to save GNSS module config");
LOGGER.warn("Unable to save GNSS module config");
} else {
TT_LOG_I(TAG, "GNSS module configuration saved!");
LOGGER.info("GNSS module configuration saved!");
}
return true;
}
@@ -473,9 +472,9 @@ bool initUblox6(uart::Uart& uart) {
auto packet_size = makePacket(0x06, 0x09, _message_SAVE, sizeof(_message_SAVE), buffer);
uart.writeBytes(buffer, packet_size);
if (getAck(uart, 0x06, 0x09, 2000) != GpsResponse::Ok) {
TT_LOG_W(TAG, "Unable to save GNSS module config");
LOGGER.warn("Unable to save GNSS module config");
} else {
TT_LOG_I(TAG, "GNSS module config saved!");
LOGGER.info("GNSS module config saved!");
}
return true;
}