From ac8ea67534a2e8ed049e0306a582ed486a508a8f Mon Sep 17 00:00:00 2001
From: Davide Mor <davide.mor@skywarder.eu>
Date: Wed, 13 Mar 2024 12:45:11 +0100
Subject: [PATCH] [SX1278] Remove TRACE and changed it with LOG_ERR

---
 src/shared/radio/SX1278/SX1278Fsk.cpp  | 12 +++++++++---
 src/shared/radio/SX1278/SX1278Fsk.h    |  2 +-
 src/shared/radio/SX1278/SX1278Lora.cpp | 13 +++++++++----
 src/shared/radio/SX1278/SX1278Lora.h   |  5 +++--
 4 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/src/shared/radio/SX1278/SX1278Fsk.cpp b/src/shared/radio/SX1278/SX1278Fsk.cpp
index ddd866875..1cf29fcee 100644
--- a/src/shared/radio/SX1278/SX1278Fsk.cpp
+++ b/src/shared/radio/SX1278/SX1278Fsk.cpp
@@ -63,9 +63,15 @@ bool SX1278Fsk::checkVersion()
     SPITransaction spi(getSpiSlave());
 
     uint8_t version = spi.readRegister(REG_VERSION);
-    TRACE("[sx1278] Chip id: %d\n", version);
-
-    return version == 0x12;
+    if (version == 0x12)
+    {
+        return true;
+    }
+    else
+    {
+        LOG_ERR(logger, "Wrong chip id: {}", version);
+        return false;
+    }
 }
 
 SX1278Fsk::Error SX1278Fsk::configure(const Config &config)
diff --git a/src/shared/radio/SX1278/SX1278Fsk.h b/src/shared/radio/SX1278/SX1278Fsk.h
index b67f6c202..b25d645e9 100644
--- a/src/shared/radio/SX1278/SX1278Fsk.h
+++ b/src/shared/radio/SX1278/SX1278Fsk.h
@@ -212,7 +212,7 @@ private:
     bool crc_enabled;
     long long last_tx  = 0;
     float last_rx_rssi = 0.0f;
-    PrintLogger logger = Logging::getLogger("sx1278");
+    PrintLogger logger = Logging::getLogger("sx1278-fsk");
 };
 
 }  // namespace Boardcore
diff --git a/src/shared/radio/SX1278/SX1278Lora.cpp b/src/shared/radio/SX1278/SX1278Lora.cpp
index 6062b50b2..fe6b5f315 100644
--- a/src/shared/radio/SX1278/SX1278Lora.cpp
+++ b/src/shared/radio/SX1278/SX1278Lora.cpp
@@ -135,7 +135,6 @@ SX1278Lora::Error SX1278Lora::init(const Config &config)
     // First probe for the device
     if (!checkVersion())
     {
-        TRACE("[sx1278] Wrong chipid\n");
         return Error::BAD_VALUE;
     }
 
@@ -152,9 +151,15 @@ bool SX1278Lora::checkVersion()
     SPITransaction spi(getSpiSlave());
 
     uint8_t version = spi.readRegister(REG_VERSION);
-    TRACE("[sx1278] Chip id: %d\n", version);
-
-    return version == 0x12;
+    if (version == 0x12)
+    {
+        return true;
+    }
+    else
+    {
+        LOG_ERR(logger, "Wrong chip id: {}", version);
+        return false;
+    }
 }
 
 SX1278Lora::Error SX1278Lora::configure(const Config &config)
diff --git a/src/shared/radio/SX1278/SX1278Lora.h b/src/shared/radio/SX1278/SX1278Lora.h
index c30bdf41f..edde853ae 100644
--- a/src/shared/radio/SX1278/SX1278Lora.h
+++ b/src/shared/radio/SX1278/SX1278Lora.h
@@ -22,6 +22,8 @@
 
 #pragma once
 
+#include <diagnostic/PrintLogger.h>
+
 #include "SX1278Common.h"
 #include "SX1278LoraTimings.h"
 
@@ -203,9 +205,8 @@ private:
     void setMode(Mode mode) override;
     void setMapping(SX1278::DioMapping mapping) override;
 
-    void setFreqRF(int freq_rf);
-
     bool crc_enabled;
+    PrintLogger logger = Logging::getLogger("sx1278-lora");
 };
 
 }  // namespace Boardcore
-- 
GitLab