From f4e115e191d95d6b2fa300af3c9436a9d7a4e5fd Mon Sep 17 00:00:00 2001
From: Jochen Vothknecht <jochen3120@gmail.com>
Date: Tue, 29 Mar 2022 19:45:55 +0200
Subject: [PATCH] Moar CyanBus development

---
 CLC-qthing/SiliconTorch/CyanBus.cpp | 28 +++++++++++++++++++---------
 CLC-qthing/SiliconTorch/CyanBus.hpp |  7 +++++++
 CLC-qthing/device_main.cpp          | 10 +++++++---
 3 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/CLC-qthing/SiliconTorch/CyanBus.cpp b/CLC-qthing/SiliconTorch/CyanBus.cpp
index 24c4d71..5dfe382 100644
--- a/CLC-qthing/SiliconTorch/CyanBus.cpp
+++ b/CLC-qthing/SiliconTorch/CyanBus.cpp
@@ -9,6 +9,7 @@
 #include "esp_log.h"
 #include "driver/gpio.h"
 #include "driver/uart.h"
+#include "freertos/FreeRTOS.h"
 #include "freertos/queue.h"
 
 // project specific
@@ -22,15 +23,15 @@
 static const char* TAG = "CyanBus";
 
 
-// This leads to ~54 P/s @ 2 MBaud at 100% load
-// TODO: Make configurable?!
-const uint32_t CyanBusMTU = 4096;
-
-
 namespace SiliconTorch {
 
   namespace CyanBus {
 
+    // This leads to ~54 P/s @ 2 MBaud at 100% load
+    const uint32_t MTU = 4096;
+
+    const uint8_t* const HEADER = (const uint8_t*)"fxCyan";
+
 
     CyanBus::CyanBus(uint8_t tx, uint8_t rx, uint8_t de, uint8_t re, uint32_t baudRate, uint8_t uartChannel) : tx(tx), rx(rx), de(de), re(re), uartChannel(uartChannel) {
 
@@ -74,7 +75,7 @@ namespace SiliconTorch {
 
       uart_port_t _ch = (uart_port_t)uartChannel;
 
-      uart_driver_install(_ch, CyanBusMTU, 0, 0, &uartEvQ, 0);
+      uart_driver_install(_ch, MTU * 2, 0, 32, &uartEvQ, 0);  // txBuf = 0; queue size = 32;  TODO: evaluate!!!
       uart_param_config(_ch, &uartConfig);
       uart_set_pin(_ch, tx, rx, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
       uart_set_mode(_ch, UART_MODE_UART);
@@ -85,12 +86,21 @@ namespace SiliconTorch {
       rxEN(true);
 
 
-      // readerTaskHandle = new SiliconTorch::Util::LambdaTask([&](){ readerTask(); });
-
+      readerTaskHandle = new SiliconTorch::Util::LambdaTask([&](){ readerTask(); });
     }
 
     void CyanBus::readerTask() {
-      // const uint8_t* header = (const uint8_t*)"fxCyan";
+
+      uart_event_t event;
+
+      uint32_t bufLEN = MTU * 1.2;
+      uint8_t* buffer = new uint8_t[bufLEN];
+      uint8_t* bufPTR = buffer;
+
+      ESP_LOGW(TAG, "bufLEN = %d   BufferSize[MTU * 1.2] = %d", bufLEN, (int)sizeof(buffer));
+
+
+
     }
 
 
diff --git a/CLC-qthing/SiliconTorch/CyanBus.hpp b/CLC-qthing/SiliconTorch/CyanBus.hpp
index e3f0a7e..ee561e7 100644
--- a/CLC-qthing/SiliconTorch/CyanBus.hpp
+++ b/CLC-qthing/SiliconTorch/CyanBus.hpp
@@ -6,6 +6,7 @@
 #include <functional>
 
 // ESP32 specific
+#include "freertos/FreeRTOS.h"
 #include "freertos/queue.h"
 
 // project specific
@@ -16,6 +17,12 @@ namespace SiliconTorch {
 
   namespace CyanBus {
 
+    // CyanBus payload MTU
+    extern const uint32_t MTU;
+
+    // CyanBus envelope header
+    extern const uint8_t* const HEADER;
+
     class CyanBus {
       public:
         CyanBus(uint8_t tx, uint8_t rx, uint8_t de, uint8_t re, uint32_t baudRate = 115200, uint8_t uartChannel = 1);
diff --git a/CLC-qthing/device_main.cpp b/CLC-qthing/device_main.cpp
index f8a0a69..c158576 100644
--- a/CLC-qthing/device_main.cpp
+++ b/CLC-qthing/device_main.cpp
@@ -9,7 +9,6 @@
 
 #include "CyanLight.hpp"
 
-#include "SiliconTorch/RS485.hpp"
 #include "SiliconTorch/CyanBus.hpp"
 
 
@@ -20,10 +19,15 @@ CyanLight::CyanLightControl* ctrl;
 
 void device_main() {
 
-  SiliconTorch::Impl::RS485 rs485(25, 21, 22, 23);
-  SiliconTorch::CyanBus::CyanBus cyanBus(rs485);
+  uint8_t tx = 0;
+  uint8_t rx = 0;
 
+  uint8_t de = 0;
+  uint8_t re = 0;
 
+  SiliconTorch::CyanBus::CyanBus cyanBus(tx, rx, de, re);
+
+  // TODO: ???
 
 
 
-- 
GitLab