Juraj Ďuďák 1 жил өмнө
parent
commit
5e72d66995

+ 11 - 6
Inc/app_bridge.h

@@ -29,9 +29,13 @@ typedef enum{
 	PARAM_GAIN,
 	PARAM_OFFSET,
 	PARAM_SAMPLERATE,
-	PARAM_RANGE
+	PARAM_RANGE,
+	PARAM_RANGE0,
+	PARAM_FILTER
 }nBus_param_t;
 
+#define PARAM_VALUE_NONE  0x7FFFFFFF
+
 
 nBus_param_t* nbus_interface_allParams();
 uint8_t nbus_interface_allParamsCount();
@@ -47,11 +51,12 @@ typedef struct{
 	uint8_t (*getData)(uint8_t sensor_index, uint8_t *data);
 	uint8_t (*setData)(uint8_t *data);
 	uint8_t (*hasParam)(uint8_t sensor_index, nBus_param_t param_name);
-	uint8_t (*getParam)(uint8_t sensor_index, nBus_param_t param_name);
-	nBus_param_t (*setParam)(uint8_t sensor_index, nBus_param_t param_name, uint8_t param_value);
-	void (*start)();
-	void (*stop)();
-	void (*read)();
+	int32_t (*getParam)(uint8_t sensor_index, nBus_param_t param_name);
+	nBus_param_t (*setParam)(uint8_t sensor_index, nBus_param_t param_name, int32_t param_value);
+	void (*start)(void);
+	void (*stop)(void);
+	void (*read)(void);
+	uint8_t (*store)(void);
 }nBusAppInterface_t;
 
 

+ 1 - 0
Inc/app_dummy.h

@@ -28,6 +28,7 @@ nBus_param_t dummy_setParam(uint8_t sensor_index, nBus_param_t param, uint8_t va
 void dummy_start(void);
 void dummy_stop(void);
 void dummy_read(void);
+uint8_t dummy_store(void);
 
 #ifdef __cplusplus
 }

+ 1 - 1
Src/app_bridge.c

@@ -6,7 +6,7 @@
  */
 #include "app_bridge.h"
 
-nBus_param_t allParams[] = {PARAM_TIMEBASE, PARAM_RESOLUTION, PARAM_GAIN, PARAM_OFFSET, PARAM_SAMPLERATE,PARAM_RANGE};
+nBus_param_t allParams[] = {PARAM_TIMEBASE, PARAM_RESOLUTION, PARAM_GAIN, PARAM_OFFSET, PARAM_SAMPLERATE, PARAM_RANGE, PARAM_FILTER, PARAM_RANGE0};
 nBus_sensorType_t allTypes[] = {TYPE_ACCELEROMETER, TYPE_GYROSCOPE, TYPE_MAGNETOMETER, TYPE_TEMPERATURE, TYPE_HUMIDITY, TYPE_PRESSURE, TYPE_HEART_RATE};
 
 nBus_param_t* nbus_interface_allParams()

+ 6 - 0
Src/app_dummy.c

@@ -15,6 +15,7 @@ nBusAppInterface_t dummy_driver = {
 	  dummy_start,
 	  dummy_stop,
 	  dummy_read,
+	  dummy_store,
 };
 
 
@@ -95,3 +96,8 @@ void dummy_stop(void){
 void dummy_read(void){
 	return;
 }
+
+uint8_t dummy_store(void){
+	return 0;
+}
+

+ 37 - 3
Src/nbus_slave_module_unicast.c

@@ -16,6 +16,24 @@ void nbus_slave_unicastToModuleGet(nBus_TypeDef *nbus){
 
 	break;
 
+	case CMD_PARAM:
+	{
+		//same as nbus_unicastToSensorSet
+		int32_t param_value = nbus->interface->getParam(0, (nBus_param_t)nbus->rx_buffer[3]);
+		if (param_value  == PARAM_VALUE_NONE) {
+			setErrorResponse(nbus, PARAM_NOT_IMPLEMENTED);
+			break;
+		}
+
+		nbus->tx_buffer[4] = (uint8_t)(param_value & 0xFF);
+		nbus->tx_buffer[5] = (uint8_t)((param_value>>8) & 0xFF);
+		nbus->tx_buffer[6] = (uint8_t)((param_value>>16) & 0xFF);
+		nbus->tx_buffer[7] = (uint8_t)((param_value>>24) & 0xFF);
+
+		nbus->tx_length += 4;
+	}
+	break;
+
 	case CMD_SENSOR_CNT:
 	{
 		nbus->tx_buffer[4] = nbus->interface->getSensorCount();
@@ -112,7 +130,8 @@ void nbus_slave_unicastToModuleSet(nBus_TypeDef *nbus){
 	case CMD_PARAM:
 	{
 		//same as nbus_unicastToSensorSet
-		nBus_param_t p = nbus->interface->setParam(nbus->sensorInfo.address, (nBus_param_t)nbus->tx_buffer[3], nbus->tx_buffer[4]);
+		int32_t param_value = nbus->rx_buffer[4] | nbus->rx_buffer[5]<<8 | nbus->rx_buffer[6]<<16 << nbus->rx_buffer[7]<<23;
+		nBus_param_t p = nbus->interface->setParam(0, (nBus_param_t)nbus->rx_buffer[3], param_value);
 		if (p == PARAM_NONE) {
 			setErrorResponse(nbus, PARAM_NOT_IMPLEMENTED);
 			break;
@@ -124,8 +143,11 @@ void nbus_slave_unicastToModuleSet(nBus_TypeDef *nbus){
 
 	case CMD_DATA:
 	{
-		nbus->interface->setData(&nbus->rx_buffer[3]);
-		nbus->tx_buffer[4] = OK_CODE;
+		nbus->tx_buffer[4] = nbus->interface->setData(&nbus->rx_buffer[3]);
+		if (nbus->tx_buffer[4] != OK_CODE){
+			nbus->function_code.error = 1;
+		}
+
 		nbus->tx_length += 1;
 	}
 	break;
@@ -142,6 +164,18 @@ void nbus_slave_unicastToModuleSet(nBus_TypeDef *nbus){
 		nbus->tx_buffer[4] = OK_CODE;
 		nbus->tx_length += 1;
 	}
+
+	case CMD_STORE:
+	{
+		if (nbus->interface->store != NULL){
+			nbus->interface->store();
+			nbus->tx_buffer[4] = OK_CODE;
+		} else {
+			nbus->tx_buffer[4] = ILLEGAL_FUNCTION;
+		}
+
+		nbus->tx_length += 1;
+	}
 	break;
 
 	default:

+ 30 - 14
Src/nbus_slave_sensor_unicast.c

@@ -20,26 +20,34 @@ void nbus_slave_unicastToSensorGet(nBus_TypeDef *nbus){
 	case CMD_PARAM:
 	{
 		if (nbus->rx_length >= 5){
-			if (nbus->interface->hasParam(nbus->sensorInfo.address, (nBus_param_t)nbus->tx_buffer[3]) == 0) {
+			if (nbus->interface->hasParam(nbus->sensorInfo.address, (nBus_param_t)nbus->rx_buffer[3]) == 0) {
 				setErrorResponse(nbus, PARAM_NOT_IMPLEMENTED);
 				break;
 			}
-			nbus->tx_buffer[4] = nbus->tx_buffer[3];
-			nbus->tx_buffer[5] = nbus->interface->getParam(nbus->sensorInfo.address, (nBus_param_t)nbus->tx_buffer[3]);
-			nbus->tx_length += 2;
+			nbus->tx_buffer[4] = nbus->rx_buffer[3];
+			int32_t param_value = nbus->interface->getParam(nbus->sensorInfo.address, (nBus_param_t)nbus->rx_buffer[3]);
+			nbus->tx_buffer[5] = (uint8_t)(param_value & 0xFF);
+			nbus->tx_buffer[6] = (uint8_t)((param_value>>8) & 0xFF);
+			nbus->tx_buffer[7] = (uint8_t)((param_value>>16) & 0xFF);
+			nbus->tx_buffer[8] = (uint8_t)((param_value>>24) & 0xFF);
+			nbus->tx_length += 5;
 		} else {
 			nBus_param_t* params = nbus_interface_allParams();
 			for(uint8_t i=0; i < nbus_interface_allParamsCount() ; i++){
-				if(nbus->interface->hasParam(i, params[i])){
-					nbus->tx_buffer[4+2*i] = params[i];
-					nbus->tx_buffer[5+2*i] = nbus->interface->getParam(i, params[i]);
-					nbus->tx_length += 2;
+				if(nbus->interface->hasParam(nbus->sensorInfo.address, params[i])){
+					int32_t param_value = nbus->interface->getParam(nbus->sensorInfo.address, params[i]);
+					nbus->tx_buffer[4+5*i] = params[i];
+					//nbus->tx_buffer[5+2*i] = nbus->interface->getParam(nbus->sensorInfo.address, params[i]);
+					nbus->tx_buffer[5+5*i] = (uint8_t)(param_value & 0xFF);
+					nbus->tx_buffer[6+5*i] = (uint8_t)((param_value>>8) & 0xFF);
+					nbus->tx_buffer[7+5*i] = (uint8_t)((param_value>>16) & 0xFF);
+					nbus->tx_buffer[8+5*i] = (uint8_t)((param_value>>24) & 0xFF);
+
+					nbus->tx_length += 5;
 				}
 			}
 
 		}
-		// alebo
-		nbus->memoryInterface->getParam(nbus->sensorInfo.address, 0x05);
 	}
 	break;
 
@@ -71,11 +79,17 @@ void nbus_slave_unicastToSensorSet(nBus_TypeDef *nbus){
 	switch(nbus->function_code.function){
 	case CMD_PARAM:
 	{
-		nBus_param_t p = nbus->interface->setParam(nbus->sensorInfo.address, (nBus_param_t)nbus->tx_buffer[3], nbus->tx_buffer[4]);
-		if (p == PARAM_NONE) {
+		if (!nbus->interface->hasParam(nbus->sensorInfo.address, (nBus_param_t)nbus->rx_buffer[3])){
 			setErrorResponse(nbus, PARAM_NOT_IMPLEMENTED);
 			break;
 		}
+
+		int32_t param_value = nbus->rx_buffer[4] | nbus->rx_buffer[5]<<8 | nbus->rx_buffer[6]<<16 << nbus->rx_buffer[7]<<23;
+		nBus_param_t p = nbus->interface->setParam(nbus->sensorInfo.address, (nBus_param_t)nbus->rx_buffer[3], param_value);
+		if (p == PARAM_NONE) {
+			setErrorResponse(nbus, ILLEGAL_DATA_VALUE);
+			break;
+		}
 		nbus->tx_buffer[4] = OK_CODE;
 		nbus->tx_length += 1;
 	}
@@ -83,8 +97,10 @@ void nbus_slave_unicastToSensorSet(nBus_TypeDef *nbus){
 
 	case CMD_DATA:
 	{
-		nbus->interface->setData(&nbus->rx_buffer[3]);
-		nbus->tx_buffer[4] = OK_CODE;
+		nbus->tx_buffer[4] = nbus->interface->setData(&nbus->rx_buffer[3]);
+		if (nbus->tx_buffer[4] != OK_CODE){
+			nbus->function_code.error = 1;
+		}
 		nbus->tx_length += 1;
 	}
 	break;