From c8d11a0e67a373fcd8c1e0fc54b1ba56d7122030 Mon Sep 17 00:00:00 2001
From: Alain Carlucci <alain.carlucci@skywarder.eu>
Date: Sun, 30 Apr 2017 15:15:09 +0200
Subject: [PATCH] Minor fixes

---
 src/shared/BusTemplate.h          |  3 ++-
 src/shared/boards/AnakinBoard.cpp |  8 ++++----
 src/shared/log/Log.h              | 14 ++++++++------
 3 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/src/shared/BusTemplate.h b/src/shared/BusTemplate.h
index 482c8812e..41b86f669 100644
--- a/src/shared/BusTemplate.h
+++ b/src/shared/BusTemplate.h
@@ -73,7 +73,8 @@ private:
     inline void _write(uint8_t byte) const {
         getSPIAddr(N)->DR=byte;
         while((getSPIAddr(N)->SR & SPI_SR_RXNE)==0);
-        byte=getSPIAddr(N)->DR;
+        volatile uint8_t temp;
+        temp = getSPIAddr(N)->DR;
     }
 
     inline int _read(void* buffer, size_t max_len) const {
diff --git a/src/shared/boards/AnakinBoard.cpp b/src/shared/boards/AnakinBoard.cpp
index 934205719..c4f009f03 100644
--- a/src/shared/boards/AnakinBoard.cpp
+++ b/src/shared/boards/AnakinBoard.cpp
@@ -4,10 +4,6 @@
     if (!x->init()) { sLog->logString("=== ERR: CANNOT INIT " #x); } \
 } while(0)
 
-#define ADD_SAMPLER(type, name, rate) \
-    sEventScheduler->add(std::bind(& type ## SensorSampler::Update,name), \
-            rate, #name "-" #rate "ms")
-
 AnakinBoard::AnakinBoard()
 {
     mInited = false;
@@ -78,6 +74,10 @@ bool AnakinBoard::init()
     m10HzSimple.AddSensor(mS_MS580);
 
     sLog->logString("Adding samplers to scheduler\n");
+    #define ADD_SAMPLER(type, name, rate) \
+        sEventScheduler->add(std::bind(& type ## SensorSampler::Update,name),\
+                rate, #name "-" #rate "ms")
+
     ADD_SAMPLER(DMA, m100HzDMA, 10); // 10ms
     ADD_SAMPLER(DMA, m25HzDMA, 40);  // 25ms
     ADD_SAMPLER(Simple, m100HzSimple, 10); // 10ms
diff --git a/src/shared/log/Log.h b/src/shared/log/Log.h
index 9e11e6f01..3be1e16ff 100644
--- a/src/shared/log/Log.h
+++ b/src/shared/log/Log.h
@@ -44,7 +44,7 @@ public:
         std::vector<uint8_t> buf(2 + sizeof(float));
         buf[0] = DATA_FLOAT;
         buf[1] = id;
-        memcpy(&buf[2], &data, sizeof(float));
+        *((float *)&buf[2]) = data;
 
         queue(std::move(buf));
     }
@@ -56,9 +56,9 @@ public:
         buf[0] = DATA_VEC3;
         buf[1] = id;
 
-        tmp = data.getX(); memcpy(&buf[2], &tmp, sizeof(float));
-        tmp = data.getY(); memcpy(&buf[6], &tmp, sizeof(float));
-        tmp = data.getZ(); memcpy(&buf[10], &tmp, sizeof(float));
+        tmp = data.getX(); *((float *)&buf[2]) = tmp;
+        tmp = data.getY(); *((float *)&buf[6]) = tmp;
+        tmp = data.getZ(); *((float *)&buf[10]) = tmp;
 
         queue(std::move(buf));
     }
@@ -89,15 +89,17 @@ private:
 
     Log() : ActiveObject(1024)
     {
+        /*
         struct termios t;
         tcgetattr(STDIN_FILENO, &t);
         t.c_lflag &= ~(ISIG | ICANON | ECHO);
         tcsetattr(STDIN_FILENO,TCSANOW, &t);
+        */
     }
 
     void write(const std::vector<uint8_t>& data)
     {
-        const char map[]="0123456789abcdef\r\n";
+        static const char map[]="0123456789abcdef";
         for(size_t i=0;i<data.size();i++)
         {
             const char& di = data[i];
@@ -106,7 +108,7 @@ private:
             out[1] = map[di & 0x0f];
             ::write(1, out, 2);
         } 
-        ::write(1, &map[16], 2);
+        ::write(1, "\r\n", 2);
     }
 
     void queue(std::vector<uint8_t>&& data)
-- 
GitLab