Selaa lähdekoodia

RUN mode check

Juraj Ďuďák 2 vuotta sitten
vanhempi
commit
2a0f94d5cc
4 muutettua tiedostoa jossa 25 lisäystä ja 8 poistoa
  1. 1 0
      Inc/nbus_cmd.h
  2. 1 1
      Src/nbus_app.c
  3. 13 2
      Src/nbus_slave_module_unicast.c
  4. 10 5
      Src/nbus_slave_sensor_unicast.c

+ 1 - 0
Inc/nbus_cmd.h

@@ -51,6 +51,7 @@
 #define SLAVE_DEVICE_FAILURE 	(0x04)
 #define ACKNOWLEDGE 			(0x05)
 #define DEVICE_BUSY 			(0x06)
+#define DEVICE_NOT_READY		(0x07)
 #define PARAM_NOT_IMPLEMENTED 	(0x10)
 
 /**

+ 1 - 1
Src/nbus_app.c

@@ -54,7 +54,7 @@ inline static void receiveNBytes(uint8_t n){
 
 inline static void send_response(){
 	if(nBus.send_response == SEND_RESPONSE) {
-		nBus.tx_buffer[0] -= 1;
+		nBus.tx_buffer[0] -= 1;		// prvý bajt sa nepočíta
 #if USE_USART_DMA_TX == 1
 		HAL_UART_Transmit_DMA(nBus.periph->huart, nBus.tx_buffer, nBus.tx_length);
 #else

+ 13 - 2
Src/nbus_slave_module_unicast.c

@@ -25,8 +25,19 @@ void nbus_slave_unicastToModuleGet(nBus_TypeDef *nbus){
 
 	case CMD_DATA:
 	{
-		//response: sensor1_index:sensor1_data | sensor2_index:sensor2_data | ...
-		nbus->tx_length +=  nbus->interface->getData(0 , &nbus->tx_buffer[4]);
+		if (nbus->measure_active == MEASURE_RUNNING) {
+			//response: sensor1_index:sensor1_data | sensor2_index:sensor2_data | ...
+			uint8_t cnt = nbus->interface->getData(0, &nbus->tx_buffer[4]);
+			if (cnt == 0){
+				setErrorResponse(nbus, DEVICE_BUSY);
+			}
+			nbus->tx_length += cnt;
+
+
+		} else {
+			setErrorResponse(nbus, DEVICE_NOT_READY);
+		}
+
 	}
 	break;
 

+ 10 - 5
Src/nbus_slave_sensor_unicast.c

@@ -45,12 +45,17 @@ void nbus_slave_unicastToSensorGet(nBus_TypeDef *nbus){
 
 	case CMD_DATA:
 	{
-		uint8_t cnt = nbus->interface->getData(nbus->sensorInfo.address, &nbus->tx_buffer[4]);
-		if (cnt == 0){
-			setErrorResponse(nbus, DEVICE_BUSY);
-			return;
+		if (nbus->measure_active == MEASURE_RUNNING) {
+			uint8_t cnt = nbus->interface->getData(nbus->sensorInfo.address, &nbus->tx_buffer[4]);
+			if (cnt == 0){
+				setErrorResponse(nbus, DEVICE_BUSY);
+				//return;
+			}
+			nbus->tx_length += cnt;
+		} else {
+			setErrorResponse(nbus, DEVICE_NOT_READY);
 		}
-		nbus->tx_length += cnt;
+
 	}
 	break;