Explorar o código

oddelenie CMD pre bridge a slave

Juraj Ďuďák hai 4 semanas
pai
achega
67dba4daba

+ 11 - 0
Core/Inc/NbusBridge.h

@@ -24,13 +24,22 @@
 /** Makro zistí kód funkcie z RX paketu */
 #define FUNCTION_CODE(packet)   packet[2]
 
+/** Adresa broadcastu */
 #define BROADCAST_ADDRESS	0
+/** Virtuálna adresa modulu nBus Bridge */
+#define BRIDGE_ADDRESS		0xFF
+
+#define BRIDGE_INFO_VERSION		"1.0"
+#define BRIDGE_INFO_HW_FAMILY	"STM"
+#define BRIDGE_INFO_HW_VERSION	"0.5"
+
 #define RX_META	4
 
 #define DATAPACKET_SIZE  (NBUS_MAX_FRAME_SIZE*MAX_SLAVES)
 
 /* DEFINES END */
 
+
 typedef enum {
 	STATE_STOPPED,
 	STATE_TO_STOP,
@@ -76,6 +85,8 @@ public:
 	DataFrame * getSlavesInfo();
 	void sendResponseToMaster(DataFrame *response_frame);
 	void processRequest(uint8_t *rxFrame, uint8_t size);
+	void process_bridge_request(uint8_t *rxFrame, uint8_t size);
+	void process_slave_request(uint8_t *rxFrame, uint8_t size);
 	void broadcastStart();
 	void broadcastStop();
 	void processRunningState();

+ 2 - 0
Core/Inc/NbusCommunicator.h

@@ -42,6 +42,8 @@ public:
 	DataFrame* sendAndReceive(Nbus_pdu *pdu, uint8_t *data, uint8_t data_len);
 	DataFrame* formatSlaveInfo(uint8_t slave_address[], uint8_t num);
 	void send(Nbus_pdu *pdu, uint8_t *data, uint8_t data_len);
+
+	DataFrame *formatPacket(uint8_t *rxFrame, uint8_t size);
 };
 
 

+ 1 - 4
Core/Src/AppBridge.cpp

@@ -6,13 +6,10 @@
  * @author Juraj Dudak
  */
 
-// #include <NbusSlave.h>
+
 #include "AppBridge.h"
-// #include "dataframe.h"
 #include "NbusBridge.h"
 
-// #include "NbusCommunicator.h"
-
 /**
  * @brief UART rozhranie medzi Master-Bridge.
  */

+ 77 - 31
Core/Src/NbusBridge.cpp

@@ -185,44 +185,58 @@ void NbusBridge::process_broadcast(uint8_t *rxFrame)
     }
 }
 
-/**
- * Pripraví informáciu o všetkcýh nBus slave moduloch
- */
-DataFrame *NbusBridge::getSlavesInfo()
-{
-    return _communicator->formatSlaveInfo(_slave_adress, _num_slaves);
-    ;
-}
 
 /**
- * Implementácia rozhrania nBus.
+ * Spracovanie requestu pre bridge.
+ * Implementované funkcie:
+ * - FC_SLAVES
+ * - FC_INFO
+ * - FC_ECHO
  */
-void NbusBridge::processRequest(uint8_t *rxFrame, uint8_t size)
+void NbusBridge::process_bridge_request(uint8_t *rxFrame, uint8_t size)
 {
-    if (MODULE_ADDRESS(rxFrame) == 0)
+    switch (FUNCTION_CODE(rxFrame))
     {
-        process_broadcast(rxFrame);
-        return;
-    }
 
-    uint8_t send_reponse = 1;
-    NbusSlave *selected_slave = getSlave(MODULE_ADDRESS(rxFrame));
-    if (selected_slave == NULL)
-    {
-        return;
-    }
+    case FC_ECHO: 		/* 1 */
+    	_frame_nbus_internal = _communicator->formatPacket(rxFrame, size);
+        break;
 
-    if (!selected_slave->isActive())
-    {
-        return;
-    }
+    case FC_INFO: 		/* 0xE => 15 */
+    	/*
+    	 * verzia
+    	 * HW
+    	 * HW.verzia
+    	 */
+    	_frame_nbus_internal->Init();
+    	_frame_nbus_internal->AddArray((uint8_t*)BRIDGE_INFO_VERSION, 3);
+    	_frame_nbus_internal->AddArray((uint8_t*)BRIDGE_INFO_HW_FAMILY, 3);
+    	_frame_nbus_internal->AddArray((uint8_t*)BRIDGE_INFO_HW_VERSION, 3);
+    	_frame_nbus_internal->Commit();
+        break;
 
-    uint8_t crcC = crc8x_fast(rxFrame, size - 1);
+    case FC_SLAVES: 	/* 0x10 => 16 */
+        _frame_nbus_internal = getSlavesInfo();
+        break;
 
-    if (crcC != rxFrame[size - 1])
-    {
-        return;
+    default:; // nothing
     }
+}
+
+void NbusBridge::process_slave_request(uint8_t *rxFrame, uint8_t size)
+{
+    uint8_t send_reponse = 1;
+
+    NbusSlave * selected_slave = getSlave(MODULE_ADDRESS(rxFrame));
+	if (selected_slave == NULL)
+	{
+		return;
+	}
+
+	if (!selected_slave->isActive())
+	{
+		return;
+	}
 
     switch (FUNCTION_CODE(rxFrame))
     {
@@ -284,9 +298,6 @@ void NbusBridge::processRequest(uint8_t *rxFrame, uint8_t size)
         _frame_nbus_internal = selected_slave->nbus_sensor_format(SENSOR_ADDRESS(rxFrame));
         break;
 
-    case FC_SLAVES: /* 0x10 => 16 */
-        _frame_nbus_internal = getSlaves();
-        break;
     default:
         send_reponse = 0;
     }
@@ -297,6 +308,41 @@ void NbusBridge::processRequest(uint8_t *rxFrame, uint8_t size)
     }
 }
 
+/**
+ * Pripraví informáciu o všetkcýh nBus slave moduloch
+ */
+DataFrame *NbusBridge::getSlavesInfo()
+{
+    return _communicator->formatSlaveInfo(_slave_adress, _num_slaves);
+}
+
+/**
+ * Implementácia rozhrania nBus.
+ */
+void NbusBridge::processRequest(uint8_t *rxFrame, uint8_t size)
+{
+    uint8_t crcC = crc8x_fast(rxFrame, size - 1);
+
+    if (crcC != rxFrame[size - 1])
+    {
+        return;
+    }
+
+    if (MODULE_ADDRESS(rxFrame) == BROADCAST_ADDRESS)
+    {
+    	if (SENSOR_ADDRESS(rxFrame) == BRIDGE_ADDRESS) {
+    		process_bridge_request(rxFrame, size);
+    		sendResponseToMaster(_frame_nbus_internal);
+    	} else {
+    		process_broadcast(rxFrame);
+    	}
+
+    } else {
+    	process_slave_request(rxFrame, size);
+    }
+
+}
+
 /**
  * Implementácia stavu STATE_RUNNING.
  * V tomto stave je spustené automatické odčítanie údajov zo všetkých slave/všetkých senzorov.

+ 18 - 0
Core/Src/NbusCommunicator.cpp

@@ -131,3 +131,21 @@ DataFrame *NbusCommunicator::formatSlaveInfo(uint8_t slave_address[], uint8_t nu
 
     return _packet_rx;
 }
+
+
+/**
+ * Informácia o existujúcih moduloch nBus Slave.
+ * Formát: [index1 adresa1 index2 adresa2 ...  indexN andresaN]
+ */
+DataFrame *NbusCommunicator::formatPacket(uint8_t *rxFrame, uint8_t size)
+{
+    _packet_rx->Init();
+
+    for (uint8_t i = 0; i < size; i++)
+    {
+        _packet_rx->AddInt8(rxFrame[i]);
+    }
+    _packet_rx->Commit();
+
+    return _packet_rx;
+}

+ 1 - 1
Core/Src/NbusSlave.cpp

@@ -1,6 +1,6 @@
 /*
  * @file AppBridge.cpp
- * @brief Implemetnácia modulu nBus Slave z pohľadu nBus Bridge
+ * @brief Implemetnácia mostup na modul nBus Slave.
  * @date Mar 2, 2025
  * @author Juraj Dudak
  */

+ 2 - 2
Doxyfile

@@ -1079,7 +1079,7 @@ EXCLUDE_SYMBOLS        =
 # that contain example code fragments that are included (see the \include
 # command).
 
-EXAMPLE_PATH           =
+EXAMPLE_PATH           = .
 
 # If the value of the EXAMPLE_PATH tag contains directories, you can use the
 # EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and
@@ -1160,7 +1160,7 @@ FILTER_SOURCE_PATTERNS =
 # (index.html). This can be useful if you have a project on for instance GitHub
 # and want to reuse the introduction page also for the doxygen output.
 
-USE_MDFILE_AS_MAINPAGE =
+USE_MDFILE_AS_MAINPAGE = README.md
 
 # The Fortran standard specifies that for fixed formatted Fortran code all
 # characters from position 72 are to be considered as comment. A common