Jelajahi Sumber

store params/part1

Juraj Ďuďák 1 tahun lalu
induk
melakukan
07cd415895
8 mengubah file dengan 50 tambahan dan 33 penghapusan
  1. 1 1
      Core/Inc/app_imu.h
  2. 1 1
      Core/Src/app_adc.c
  3. 3 2
      Core/Src/app_imu.cpp
  4. 9 6
      Core/Src/main.c
  5. 1 1
      Modules/nbus
  6. 1 1
      Modules/one-wire-memory
  7. 18 6
      test/app.py
  8. 16 15
      test/comm.py

+ 1 - 1
Core/Inc/app_imu.h

@@ -32,7 +32,7 @@ int32_t mcu_spi_getParam(uint8_t sensor_index, nBus_param_t param);
 uint8_t mcu_spi_hasParam(uint8_t sensor_index, nBus_param_t param);
 nBus_param_t mcu_spi_setParam(uint8_t sensor_index, nBus_param_t param, int32_t value);
 void mcu_spi_readData(void);
-uint8_t mcu_spi_store(void);
+//uint8_t mcu_spi_store(void);
 
 #ifdef __cplusplus
 }

+ 1 - 1
Core/Src/app_adc.c

@@ -22,7 +22,7 @@ nBusAppInterface_t mcu_adc_driver = {
 	  mcu_adc_start,
 	  mcu_adc_stop,
 	  mcu_adc_read,
-	  mcu_adc_store,
+	  //mcu_adc_store,
 };
 
 uint32_t mcu_adc_data[MCU_ADC_CHANNELS];

+ 3 - 2
Core/Src/app_imu.cpp

@@ -25,7 +25,7 @@ nBusAppInterface_t mcu_spi_driver = {
 	  mcu_spi_start,
 	  mcu_spi_stop,
 	  mcu_spi_readData,
-	  mcu_spi_store,
+	  //mcu_spi_store,
 };
 
 
@@ -352,7 +352,8 @@ nBus_param_t mcu_spi_setParam(uint8_t sensor_index, nBus_param_t param, int32_t
 	return param;
 
 }
-
+/*
 uint8_t mcu_spi_store(void){
 	return 0;
 }
+*/

+ 9 - 6
Core/Src/main.c

@@ -33,6 +33,7 @@
 #endif
 
 #if MODULE == MODULE_IMU
+#include "app_dummy.h"
 #include "app_imu.h"
 #endif
 
@@ -255,7 +256,7 @@ int main(void)
   periph.rtc = &hrtc;
 #endif
 
-
+  //HAL_UARTEx_ReceiveToIdle_DMA(&huart2, data, 64);
 #if MODULE == MODULE_DUMMY
   nbus_init(getDummyDriver(), &hw_platform);
   nbus_init_app(NULL, NULL);
@@ -282,21 +283,23 @@ int main(void)
 
 	 nbus_init(getImuDriver(), &hw_platform);
 	 nbus_init_app(&hspi1, &config);
-
 #endif
 
   nBus_MemoryDriver memory_ec20 = {
   		DS28EC20_init,
   		DS28EC20_readData4B,
   		DS28EC20_readData2B,
-  		DS28EC20_writeData4B,
+  		DS28EC20_readData1B,
+  		DS28EC20_writeData4B, // TODO zamenit za DS28EC20_writeMem(data, size). Vyuzije sa pri formate
   		DS28EC20_writeData2B,
-		DS28EC20_getId
+  		DS28EC20_writeData1B,
+		DS28EC20_getId,
+		DS28EC20_getCapacity
   };
 
-
   memory_ec20.init(ONE_WIRE_GPIO_Port, ONE_WIRE_Pin);
-  nbus_init_memory_driver(&memory_ec20,16);
+  nbus_init_memory_driver(&memory_ec20);
+
 
   nbus_stack();
 

+ 1 - 1
Modules/nbus

@@ -1 +1 @@
-Subproject commit aa18d7ad50ceecc536cf95ce4a9d67ec0bb96b97
+Subproject commit 04de35d2020a9d799e3020d9ed582f175639695d

+ 1 - 1
Modules/one-wire-memory

@@ -1 +1 @@
-Subproject commit 9d08aa557d3f29bc1705bb6f8964f4e863bb74a7
+Subproject commit 8e9af68840ae9e80ad073ff6720424ef29158c6f

+ 18 - 6
test/app.py

@@ -23,6 +23,7 @@ class AppTest:
         if len(resp) == 0:
             print("No ECHO (0-size resp)")
             return 0
+        print(resp)
         for r in range(len(msg)):
             echo = echo + chr(resp[3+r])
         print("Echo:"+echo)
@@ -81,6 +82,11 @@ class AppTest:
         return 0
 
     def cmd_sensor_get_data_IMU(self, sensor_index):
+        '''
+        sensor_index:
+        1 - ACC
+        2 - GYRO
+        '''
         resp = self.serial_port.request(self.module, sensor_index, CMD_DATA,[])
         #print(resp)
         x = 0
@@ -135,6 +141,10 @@ class AppTest:
         print("MODULE STOP")
         self.serial_port.requestBroadcast(CMD_STOP,[])
 
+    def cmd_reset(self):
+        print("MODULE RESET")
+        resp = self.serial_port.request(self.module, 0, (SET+CMD_RESET),[], long_answer=1)
+
 if __name__ == "__main__":
     
     app = AppTest(0x05, 0x0)
@@ -145,9 +155,10 @@ if __name__ == "__main__":
     if app.cmd_echo([97,98,99,100]) == 0:
         sys.exit()
 
-    app.cmd_set_param(1, PARAM_SAMPLERATE, 10)
-    app.cmd_set_param(1, PARAM_RANGE, 1)
-    app.cmd_set_param(1, PARAM_FILTER, 2)
+    app.cmd_reset()
+    #app.cmd_set_param(1, PARAM_SAMPLERATE, 10)
+    #app.cmd_set_param(1, PARAM_RANGE, 1)
+    #app.cmd_set_param(1, PARAM_FILTER, 2)
     
     for s in range(1):
         sr=app.cmd_get_param(s+1,PARAM_SAMPLERATE)
@@ -159,8 +170,9 @@ if __name__ == "__main__":
     sys.exit()
     #time.sleep(0.5)
     #app.cmd_module_stop()
-    time.sleep(0.5)
+    
     app.cmd_module_start()
+    time.sleep(0.5)
     
     #app.cmd_module_stop()
     #sys.exit()
@@ -168,12 +180,12 @@ if __name__ == "__main__":
     #sys.exit()
     print("pocet senzorov=", pocet)
     #app.cmd_sensor_get_data_FSR(pocet)    
-    for i in range(6):
+    for i in range(36):
         acc = app.cmd_sensor_get_data_IMU(1)
         gyr = app.cmd_sensor_get_data_IMU(2)
         print(acc)
         print(gyr)
-
+    app.cmd_module_stop()
     sys.exit()
     
     for i in range(pocet):

+ 16 - 15
test/comm.py

@@ -136,20 +136,20 @@ class SerialComm:
         start.append(crc_sum)
         return start
 
-    def wait_to_response(self, extra_delay):
-        communication_delay = 0.001
-        t0 = time.time()  # timeout for response
-        response_length = self.port.inWaiting()
-        timeout = 0.05
-        if extra_delay != 0:
-            timeout = 0.5
-        while response_length == 0:
-            time.sleep(communication_delay)
-            response_length = self.port.inWaiting()
-            if time.time() - t0 > timeout:
-                self.callback('d', 0, "SKIP response")
-                return 0
-        return 1
+    # def wait_to_response(self, extra_delay):
+    #     communication_delay = 0.001
+    #     t0 = time.time()  # timeout for response
+    #     response_length = self.port.inWaiting()
+    #     timeout = 0.05
+    #     if extra_delay != 0:
+    #         timeout = 0.5
+    #     while response_length == 0:
+    #         time.sleep(communication_delay)
+    #         response_length = self.port.inWaiting()
+    #         if time.time() - t0 > timeout:
+    #             self.callback('d', 0, "SKIP response")
+    #             return 0
+    #     return 1
 
     def receive_response(self):
         data = []
@@ -181,7 +181,8 @@ class SerialComm:
             # self.port.write(m[1:]) # send body of message
 
             self.port.write(m) # send body of message
-
+            if long_answer > 0:
+                time.sleep(long_answer)
             data = self.receive_response()
             if len(data)>0:
                 has_response = True