Ver Fonte

master/slave initialization

Juraj Ďuďák há 2 anos atrás
pai
commit
e2b19551a5

+ 11 - 3
Inc/nbus_app.h

@@ -8,10 +8,18 @@
 #define __NBUS_APP_H__
 
 #include "nbus_types.h"
-#include "nbus_impl.h"
+
+
+#if MODULE_SLAVE == 1
+#include "nbus_slave.h"
+#endif
+#if MODULE_MASTER == 1
+#include "nbus_master_module.h"
+#endif
+
 #include "nbus_cmd.h"
-#include "app_bridge.h"
-#include "nbus_memory.h"
+//#include "app_bridge.h"
+//#include "nbus_memory.h"
 #include "one_wire.h"
 #include "memory_ec20.h"
 

+ 2 - 2
Inc/nbus_config.h.default

@@ -10,7 +10,7 @@
 #define __NBUS_CONFIG_H__
 
 #define MODULE_ADDRESS	5
-#define MODULE_MASTER	1
+#define MODULE_MASTER	0
 #define MODULE_SLAVE	1
 
 // MUST BE 2 BYTE LONG
@@ -21,7 +21,7 @@
 // MUST BE 8 BYTE LONG
 #define MODULE_NAME "prototyp"
 // MUST BE 3 BYTE LONG
-#define MODULE_TYPE "DUM"
+#define MODULE_TYPE "FSR"
 
 
 

+ 0 - 23
Inc/nbus_impl.h

@@ -1,23 +0,0 @@
-/**
- * @file  nbus_impl.h
- *
- * @brief Zakladna implementacia prikazov nBus protokolu.
- *
- */
-#ifndef __NBUS_IMPL_H__
-#define __NBUS_IMPL_H__
-
-#include "nbus_types.h"
-#include "nbus_cmd.h"
-
-void setErrorResponse(nBus_TypeDef *nbus, uint8_t code);
-//nBusCommandType_t get_request_type();
-void nbus_unicastToSensorGet(nBus_TypeDef *nbus);
-void nbus_unicastToModuleGet(nBus_TypeDef *nBus);
-
-void nbus_unicastToSensorSet(nBus_TypeDef *nbus);
-void nbus_unicastToModuleSet(nBus_TypeDef *nBus);
-
-void nbus_broadcast(nBus_TypeDef *nBus, nBusCommandType_t request_type);
-#endif
-

+ 21 - 0
Inc/nbus_master_module.h

@@ -0,0 +1,21 @@
+/*
+ * nbus_master_module.h
+ *
+ *  Created on: Nov 12, 2023
+ *      Author: juraj
+ */
+
+#ifndef MODULES_NBUS_INC_NBUS_MASTER_MODULE_H_
+#define MODULES_NBUS_INC_NBUS_MASTER_MODULE_H_
+
+
+#include "nbus_config.h"
+
+#if MODULE_MASTER == 1
+
+void nbus_master_unicastToModuleGet(nBus_TypeDef *nbus);
+void nbus_master_unicastToModuleSet(nBus_TypeDef *nbus);
+
+#endif
+
+#endif /* MODULES_NBUS_INC_NBUS_MASTER_MODULE_H_ */

+ 29 - 0
Inc/nbus_slave.h

@@ -0,0 +1,29 @@
+/**
+ * @file  nbus_impl.h
+ *
+ * @brief Zakladna implementacia prikazov nBus protokolu.
+ *
+ */
+#ifndef __NBUS_IMPL_H__
+#define __NBUS_IMPL_H__
+
+#include "nbus_types.h"
+#include "nbus_cmd.h"
+
+void setErrorResponse(nBus_TypeDef *nbus, uint8_t code);
+//nBusCommandType_t get_request_type();
+
+#if MODULE_SLAVE == 1
+
+void nbus_slave_unicastToSensorGet(nBus_TypeDef *nbus);
+void nbus_slave_unicastToModuleGet(nBus_TypeDef *nBus);
+
+void nbus_slave_unicastToSensorSet(nBus_TypeDef *nbus);
+void nbus_slave_unicastToModuleSet(nBus_TypeDef *nBus);
+
+void nbus_slave_broadcast(nBus_TypeDef *nBus, nBusCommandType_t request_type);
+#endif
+
+
+#endif
+

+ 25 - 5
Src/nbus_app.c

@@ -64,6 +64,11 @@ inline static void send_response(){
 	HAL_GPIO_WritePin(nBus.periph->led->port, nBus.periph->led->pin, GPIO_PIN_RESET);
 }
 
+#if MODULE_MASTER == 1
+inline static void receive_slave_response(){
+
+}
+#endif
 
 static nBusCommandType_t get_request_type(){
 	nBus.addressModule = nBus.rx_buffer[0];
@@ -103,11 +108,13 @@ static void process_request(){
 		return;
 	}
 
+#if MODULE_SLAVE == 1
 	// spracovanie broadcast komunikacie
 	if((request_type == BROADCAST_SPECIFIC_SENSORS || request_type == BROADCAST_GLOBAL)) {
-		nbus_broadcast(&nBus, request_type);
+		nbus_slave_broadcast(&nBus, request_type);
 		return;
 	}
+#endif
 
 	// paket nie je adresovany tomuto modulu
 	if(nBus.addressModule != MODULE_ADDRESS) {
@@ -118,29 +125,39 @@ static void process_request(){
 	nBus.function_code.error = 0;
 	nBus.tx_length = META_SIZE;
 
+#if MODULE_SLAVE == 1
 	if(nBus.function_code.notReadWrite == REQUEST_GET) {
 		if(request_type == UNICAST_TO_SENSOR) {
-			nbus_unicastToSensorGet(&nBus);
+			nbus_slave_unicastToSensorGet(&nBus);
 		}
 
 		if(request_type == UNICAST_TO_MODULE) {
-			nbus_unicastToModuleGet(&nBus);
+			nbus_slave_unicastToModuleGet(&nBus);
 		}
 
 	} else {
 		// else request is REQUEST_SET
 		if(request_type == UNICAST_TO_SENSOR) {
-			nbus_unicastToSensorSet(&nBus);
+			nbus_slave_unicastToSensorSet(&nBus);
 		}
 
 		if(request_type == UNICAST_TO_MODULE) {
-			nbus_unicastToModuleSet(&nBus);
+			nbus_slave_unicastToModuleSet(&nBus);
 		}
 	}
 
 	nBus.tx_buffer[3] = *(uint8_t*)&nBus.function_code;
 	nBus.tx_buffer[nBus.tx_length-1] = crc8x_fast(&nBus.tx_buffer[1], nBus.tx_length-2);
 	nBus.tx_buffer[0] = nBus.tx_length;
+#endif
+
+#if MODULE_MASTER == 1
+	if(nBus.function_code.notReadWrite == REQUEST_GET) {
+		nbus_master_unicastToModuleGet(&nBus);
+	} else {
+		nbus_master_unicastToModuleSet(&nBus);
+	}
+#endif
 
 }
 
@@ -230,6 +247,9 @@ void nbus_stack(void){
 			receiveOneByte();
 
 			send_response();
+#if MODULE_MASTER == 1
+			receive_slave_response();
+#endif
 		}
 	}
 

+ 47 - 0
Src/nbus_master_module.c

@@ -0,0 +1,47 @@
+/*
+ * nbus_master_module.c
+ *
+ *  Created on: Nov 12, 2023
+ *      Author: juraj
+ */
+
+
+#include "nbus_types.h"
+#include "nbus_master_module.h"
+
+
+
+#if MODULE_MASTER == 1
+
+void nbus_master_unicastToModuleSet(nBus_TypeDef *nbus){
+
+}
+
+void nbus_master_unicastToModuleGet(nBus_TypeDef *nbus){
+//		case CMD_SYNC:
+		{
+			if(nbus->rx_length < 11){
+				return;
+			}
+
+			RTC_TimeTypeDef sTime = {0};
+			RTC_DateTypeDef sDate = {0};
+
+			sTime.Hours = nbus->rx_buffer[7];
+			sTime.Minutes = nbus->rx_buffer[8];
+			sTime.Seconds = nbus->rx_buffer[9];
+			sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
+			sTime.StoreOperation = RTC_STOREOPERATION_RESET;
+			HAL_RTC_SetTime(nbus->periph->rtc, &sTime, RTC_FORMAT_BCD);
+
+			sDate.WeekDay = nbus->rx_buffer[6];
+			sDate.Date = nbus->rx_buffer[5];
+			sDate.Month = nbus->rx_buffer[4];
+			sDate.Year = nbus->rx_buffer[3];
+
+			HAL_RTC_SetDate(nbus->periph->rtc, &sDate, RTC_FORMAT_BCD);
+
+		}
+//		break;
+}
+#endif

+ 5 - 28
Src/nbus_impl_broadcast.c → Src/nbus_slave_broadcast.c

@@ -1,5 +1,6 @@
-#include "nbus_impl.h"
+#include "nbus_slave.h"
 
+#if MODULE_SLAVE == 1
 
 inline void setErrorResponse(nBus_TypeDef *nbus, uint8_t code){
 	nbus->function_code.error = 1;
@@ -9,40 +10,14 @@ inline void setErrorResponse(nBus_TypeDef *nbus, uint8_t code){
 
 
 
-void nbus_broadcast(nBus_TypeDef *nbus, nBusCommandType_t request_type){
+void nbus_slave_broadcast(nBus_TypeDef *nbus, nBusCommandType_t request_type){
 	if(request_type == BROADCAST_SPECIFIC_SENSORS) {
 
 	}
 
 	if(request_type == BROADCAST_GLOBAL) {
 		switch(nbus->function_code.function) {
-#if MODULE_MASTER
-		case CMD_SYNC:
-		{
-			if(nbus->rx_length < 11){
-				return;
-			}
-
-			RTC_TimeTypeDef sTime = {0};
-			RTC_DateTypeDef sDate = {0};
-
-			sTime.Hours = nbus->rx_buffer[7];
-			sTime.Minutes = nbus->rx_buffer[8];
-			sTime.Seconds = nbus->rx_buffer[9];
-			sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
-			sTime.StoreOperation = RTC_STOREOPERATION_RESET;
-			HAL_RTC_SetTime(nbus->periph->rtc, &sTime, RTC_FORMAT_BCD);
-
-			sDate.WeekDay = nbus->rx_buffer[6];
-			sDate.Date = nbus->rx_buffer[5];
-			sDate.Month = nbus->rx_buffer[4];
-			sDate.Year = nbus->rx_buffer[3];
-
-			HAL_RTC_SetDate(nbus->periph->rtc, &sDate, RTC_FORMAT_BCD);
 
-		}
-		break;
-#endif
 		case CMD_START:
 		{
 			nbus->measure_active = MEASURE_RUNNING;
@@ -67,3 +42,5 @@ void nbus_broadcast(nBus_TypeDef *nbus, nBusCommandType_t request_type){
 
 	nbus->send_response = NO_RESPONSE;
 }
+
+#endif

+ 6 - 4
Src/nbus_impl_module_unicast.c → Src/nbus_slave_module_unicast.c

@@ -1,9 +1,9 @@
-#include "nbus_impl.h"
+#include <nbus_slave.h>
 
 
+#if MODULE_SLAVE == 1
 
-
-void nbus_unicastToModuleGet(nBus_TypeDef *nbus){
+void nbus_slave_unicastToModuleGet(nBus_TypeDef *nbus){
 	switch(nbus->function_code.function){
 
 	case CMD_ECHO:
@@ -91,7 +91,7 @@ void nbus_unicastToModuleGet(nBus_TypeDef *nbus){
 
 }
 
-void nbus_unicastToModuleSet(nBus_TypeDef *nbus){
+void nbus_slave_unicastToModuleSet(nBus_TypeDef *nbus){
 	switch(nbus->function_code.function){
 	case CMD_PARAM:
 	{
@@ -135,3 +135,5 @@ void nbus_unicastToModuleSet(nBus_TypeDef *nbus){
 	}
 
 }
+
+#endif

+ 6 - 3
Src/nbus_impl_sensor_unicast.c → Src/nbus_slave_sensor_unicast.c

@@ -1,8 +1,9 @@
-#include "nbus_impl.h"
+#include "nbus_slave.h"
 
 
+#if MODULE_SLAVE == 1
 
-void nbus_unicastToSensorGet(nBus_TypeDef *nbus){
+void nbus_slave_unicastToSensorGet(nBus_TypeDef *nbus){
 	switch(nbus->function_code.function){
 	case CMD_SENSOR_TYPE:
 	{
@@ -61,7 +62,7 @@ void nbus_unicastToSensorGet(nBus_TypeDef *nbus){
 	}
 }
 
-void nbus_unicastToSensorSet(nBus_TypeDef *nbus){
+void nbus_slave_unicastToSensorSet(nBus_TypeDef *nbus){
 	switch(nbus->function_code.function){
 	case CMD_PARAM:
 	{
@@ -89,3 +90,5 @@ void nbus_unicastToSensorSet(nBus_TypeDef *nbus){
 	}
 	}
 }
+
+#endif