Browse Source

Merge branch 'mutislave' into 'main'

komunikacia II

See merge request sensorical/fw/nbus!3
Juraj Ďuďák 1 year ago
parent
commit
60e785a42a
5 changed files with 40 additions and 7 deletions
  1. 1 0
      Inc/app_bridge.h
  2. 7 1
      Inc/nbus_types.h
  3. 7 6
      Src/nbus_app.c
  4. 10 0
      Src/nbus_slave_module_unicast.c
  5. 15 0
      Src/nbus_slave_sensor_unicast.c

+ 1 - 0
Inc/app_bridge.h

@@ -59,6 +59,7 @@ typedef struct
     void (*stop)(void);
     void (*read)(void);
     uint8_t (*store)(void);
+    uint8_t (*calibrate)(uint8_t subslaveIndex, uint8_t calibrationParamsNum, uint8_t *calibrationParams);
 } nBusAppInterface_t;
 
 #endif /* MODULES_NBUS_INC_APP_BRIDGE_H_ */

+ 7 - 1
Inc/nbus_types.h

@@ -134,6 +134,12 @@ typedef enum
     MEASURE_RUNNING,
 } nBusMeasurementActive_t;
 
+typedef enum
+{
+    CallbackType_UART,
+    CallbackType_SENSOR,
+} nBusStateCallbackType_t;
+
 /**
  * @brief Dátová štruktúra pre implementáciu základných funkcií na aplikačnej
  * úrovni. Komunikačný zásobník nBus je HW nezávislá implementácia komunikačného
@@ -188,7 +194,7 @@ typedef struct
      * ukončenie načítania vstupných dát cez komunikačné rozhranie. Je to signál
      * pre ukočenie načítania, ktoré bolo sputené cez uart_receive
      */
-    uint8_t (*loop_callback)(void);
+    uint8_t (*loop_callback)(nBusStateCallbackType_t);
 
 } nBusPlatformInterface_t;
 

+ 7 - 6
Src/nbus_app.c

@@ -113,6 +113,7 @@ static void process_request()
     if (nBus.addressModule != MODULE_ADDRESS)
     {
         nBus.send_response = NO_RESPONSE;
+        receivePacket();
         return;
     }
 
@@ -181,7 +182,7 @@ static void nbus_blink_LED(uint8_t delay)
 
 /**
  * @brief UART receive complete.
- * This callback have to valled from application, when RX data is ready.
+ * This callback have to called from application, when RX data is ready.
  * @param int size Size of received packet
  * Received packet is located in uBus.rx_buffer
  */
@@ -308,14 +309,14 @@ void nbus_stack(void)
 
         if (nBus.hw_platform->loop_callback != NULL)
         {
-            switch (nBus.hw_platform->loop_callback())
+            if (nBus.hw_platform->loop_callback(CallbackType_SENSOR) == 1)
             {
-            case 1:
                 nBus.interface->read();
-                break;
-            case 2:
+            }
+
+            if (nBus.hw_platform->loop_callback(CallbackType_UART) == 1)
+            {
                 nBus.uart_state = UART_RX_WAIT;
-                break;
             }
         }
     }

+ 10 - 0
Src/nbus_slave_module_unicast.c

@@ -162,6 +162,16 @@ void nbus_slave_unicastToModuleSet(nBus_TypeDef *nbus)
         nbus->tx_buffer[4] = OK_CODE;
         nbus->tx_length += 1;
     }
+    break;
+
+    case CMD_CALIBRATE: {
+        nbus->hw_platform->led_on();
+        nbus->tx_buffer[4] = nbus->interface->calibrate(0, 0, NULL);
+        nbus->tx_length += 1;
+        nbus->hw_platform->led_off();
+    }
+    break;
+
     case CMD_RESET: {
         // POZOR!  cas fomatovania: 0.3s (pri 1W pamati)
         memory_params_format();

+ 15 - 0
Src/nbus_slave_sensor_unicast.c

@@ -107,6 +107,21 @@ void nbus_slave_unicastToSensorSet(nBus_TypeDef *nbus)
     }
     break;
 
+    case CMD_CALIBRATE: {
+        nbus->hw_platform->led_on();
+        if (1 == nbus->interface->calibrate(nbus->sensorInfo.address, 0, NULL))
+        {
+            nbus->tx_buffer[4] = 1;
+            nbus->tx_length += 1;
+        }
+        else
+        {
+            setErrorResponse(nbus, ILLEGAL_DEVICE_ADDRESS);
+        }
+        nbus->hw_platform->led_off();
+        break;
+    }
+
     case CMD_DATA: {
         nbus->tx_buffer[4] = nbus->interface->setData(&nbus->rx_buffer[3]);
         if (nbus->tx_buffer[4] != OK_CODE)