Bläddra i källkod

多功能人孔盖,提交第一版程序

guoqiang 1 år sedan
förälder
incheckning
15ccf683a1
18 ändrade filer med 5454 tillägg och 5426 borttagningar
  1. 259 0
      Device/Imu.c
  2. 63 0
      Device/Imu.h
  3. 239 0
      Device/Radar.c
  4. 71 0
      Device/Radar.h
  5. 40 3
      Device/adc.c
  6. 4 1
      Device/adc.h
  7. 11 3
      Device/gpio.c
  8. 145 91
      Project/AirControlValve.uvguix.JL200
  9. 48 0
      Project/AirControlValve.uvoptx
  10. 21 1
      Project/AirControlValve.uvprojx
  11. 4351 5191
      Project/JLinkLog.txt
  12. 3 5
      User/cfg.h
  13. 10 6
      User/main.c
  14. 40 49
      User/main_task.c
  15. 42 26
      User/process.c
  16. 3 0
      User/process.h
  17. 93 42
      User/protocol.c
  18. 11 8
      User/protocol.h

+ 259 - 0
Device/Imu.c

@@ -0,0 +1,259 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("AutoChips Software") are
+ * protected under relevant copyright laws. The information contained herein is
+ * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
+ * the prior written permission of AutoChips inc. and/or its licensors, any
+ * reproduction, modification, use or disclosure of AutoChips Software, and
+ * information contained herein, in whole or in part, shall be strictly
+ * prohibited.
+ *
+ * AutoChips Inc. (C) 2016. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
+ * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
+ * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
+ * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+ * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
+ * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+ * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+ * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
+ * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
+ * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
+ * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
+ * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
+ * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+ * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
+ */
+ 
+#include "ac780x_uart_reg.h"
+#include "ac780x_gpio.h"
+#include "Imu.h"
+#include "crc16.h"
+#include "uart.h"
+#include "string.h"
+
+#define UARTx   UART2
+#define UARTx_IRQn  UART2_IRQn
+
+#define UART_RX_BUFF_LENGTH     16
+
+uint8_t g_imuRxDataBuff[UART_RX_BUFF_LENGTH];
+uint16_t g_imuRxDataIndex;
+
+uint8_t *g_imuTxDataPoint;
+uint16_t g_imuTxDataLength;
+uint16_t g_imuTxDataIndex;
+
+static uint8_t imucmd_buffer[7];
+
+static uint8_t init_finished = 0;
+static float roll_angle = 0;
+static float pitch_angle = 0;
+static float yaw_angle = 0;
+//static int16_t  tmp =0;
+
+//static uint32_t printfBuff[16];
+//static uint16_t printfLen = 0;
+
+
+static int TransmitData(uint8_t *pdata, uint16_t length);
+/**
+* UartEventCallback
+*
+* @param[in] device: UART_Type pointer
+* @param[in] wpara: UART lsr0 register
+* @param[in] lpara: UART lsr1 register
+* @return    none
+*
+* @brief   uart receive handle
+*/
+static void UartEventCallback(void *device, uint32_t wpara, uint32_t lpara)
+{
+    int16_t tmp = 0;
+    UART_Type *uart_Device = (UART_Type *)device;
+    /*rx interrupt*/
+    if ((uart_Device->IER & UART_IER_ERXNE_Msk) && (wpara & UART_LSR0_DR_Msk))
+    {
+        //data = uart_Device->RBR;  
+        g_imuRxDataBuff[g_imuRxDataIndex++] = uart_Device->RBR;
+        
+        if (g_imuRxDataIndex >= 11)
+        {
+            g_imuRxDataIndex = 0;
+						if(1 == init_finished){
+							
+							tmp = g_imuRxDataBuff[3];
+							tmp = (tmp<<8)|g_imuRxDataBuff[2];
+							roll_angle = 1.0*tmp/32768*180;
+							
+							tmp = g_imuRxDataBuff[5];
+							tmp = (tmp<<8)|g_imuRxDataBuff[4];
+							pitch_angle = 1.0*tmp/32768*180;
+							
+							tmp = g_imuRxDataBuff[7];
+							tmp = (tmp<<8)|g_imuRxDataBuff[6];
+							yaw_angle = 1.0*tmp/32768*180;
+							
+//							printfLen = snprintf((char*)printfBuff, 64, "Imu roll: %f, pitch:%f, yaw:%f \r\n", roll_angle, pitch_angle, yaw_angle);
+//							rs485_TransmitData((uint8_t*)printfBuff, printfLen);
+								
+						}
+        }
+    }
+		
+		
+    /*tx interrupt*/
+    if ((uart_Device->IER & UART_IER_ETXE_Msk) && (wpara & UART_LSR0_THRE_Msk)) 
+    {
+        uart_Device->RBR = g_imuTxDataPoint[g_imuTxDataIndex++];
+
+        if (g_imuTxDataIndex >= g_imuTxDataLength)
+        {
+            UART_SetTXEInterrupt(device, DISABLE);  ///<发送最后一个字节时关闭发送空中断
+        }
+    }
+}
+/**
+* uart_Initialize
+* 
+* @param[in] none
+* @return none
+*
+* @brief uart 初始化
+*/
+static void uart_Initialize(void)
+{
+    UART_ConfigType  uartConfig = {0};
+    
+    //set pin mux
+//    GPIO_SetFunc(GPIOB, GPIO_PIN9, GPIO_FUN3);
+//    GPIO_SetFunc(GPIOB, GPIO_PIN10, GPIO_FUN3);
+    
+    
+    uartConfig.baudrate = 9600;
+    uartConfig.dataBits = UART_WORD_LEN_8BIT;
+    uartConfig.stopBits = UART_STOP_1BIT;
+    uartConfig.parity = UART_PARI_NO;
+    uartConfig.fifoByteEn = DISABLE; ///<must enable fifoByte when use DMA
+    uartConfig.dmaEn = UART_DMA_TXRX_NONE;
+    uartConfig.callBack = UartEventCallback;   ///<uart2 interrupt callback
+    UART_Init(UARTx, &uartConfig);
+    
+    UART_SetRXNEInterrupt(UARTx, ENABLE);
+    ///Enable UARTx interrupt
+    NVIC_SetPriority(UARTx_IRQn, 3);
+    NVIC_ClearPendingIRQ(UARTx_IRQn);
+    NVIC_EnableIRQ(UARTx_IRQn);
+    
+}
+/**
+* TransmitData
+* 
+* @param[in] pdata :发送数据指针
+* @param[in] length :发送数据长度
+* @return none
+*
+* @brief uart 发送函数,通过中断发送 
+*/
+int TransmitData(uint8_t *pdata, uint16_t length) 
+{
+    if (g_imuTxDataIndex < g_imuTxDataLength)  
+    {
+        return -1;      ///<有数据正在发送
+    }
+    g_imuTxDataPoint = pdata;
+    g_imuTxDataLength = length;
+    g_imuTxDataIndex = 0;
+    UART_SetTXEInterrupt(UARTx, ENABLE);
+    return 0;
+}
+
+
+void Imu_Init(void)
+{
+		uint16_t crc;
+		uart_Initialize();
+	
+		//设置参数
+		imucmd_buffer[0] = 0xFF;
+		imucmd_buffer[1] = 0xAA;	
+	
+		//step1 解锁 
+		imucmd_buffer[2] = 0x69;
+		imucmd_buffer[3] = 0x88;
+		imucmd_buffer[4] = 0xB5;
+		crc = crc16(imucmd_buffer, 5);
+		imucmd_buffer[5] = (uint8_t)((crc>>8) & 0x00ff);
+		imucmd_buffer[6] = (uint8_t)(crc & 0x00ff);
+		TransmitData(imucmd_buffer, 7);
+		
+		//step2  设置输出内容 
+		imucmd_buffer[2] = 0x02;
+		imucmd_buffer[3] = 0x08;
+		imucmd_buffer[4] = 0x00;
+	
+		crc = crc16(imucmd_buffer, 5);
+		imucmd_buffer[5] = (uint8_t)((crc>>8) & 0x00ff);
+		imucmd_buffer[6] = (uint8_t)(crc & 0x00ff);
+		TransmitData(imucmd_buffer, 7);
+		
+		//step3  设置单次回传 
+		imucmd_buffer[2] = 0x03;
+		imucmd_buffer[3] = 0x0C;
+		imucmd_buffer[4] = 0x00;
+	
+		crc = crc16(imucmd_buffer, 5);
+		imucmd_buffer[5] = (uint8_t)((crc>>8) & 0x00ff);
+		imucmd_buffer[6] = (uint8_t)(crc & 0x00ff);
+		TransmitData(imucmd_buffer, 7);
+		
+		init_finished = 1;
+		
+}
+
+uint8_t Imu_MR(void)
+{
+		uint16_t crc;
+		imucmd_buffer[0] = 0xFF;
+		imucmd_buffer[1] = 0xAA;
+		
+		imucmd_buffer[2] = 0x03;
+		imucmd_buffer[3] = 0x0C;
+		imucmd_buffer[4] = 0x00;
+	
+		crc = crc16(imucmd_buffer, 5);
+		imucmd_buffer[5] = (uint8_t)((crc>>8) & 0x00ff);
+		imucmd_buffer[6] = (uint8_t)(crc & 0x00ff);
+		TransmitData(imucmd_buffer, 7);
+	
+		g_imuRxDataIndex = 0;
+	
+		return 0;
+}
+
+
+uint8_t Imu_GetAngle(float* roll, float* pitch, float* yaw)
+{
+	*roll = roll_angle;
+	*pitch = pitch_angle;
+	*yaw = yaw_angle;
+	
+		return 0;
+}
+
+uint8_t Imu_Print(void)
+{
+
+}
+
+void Imu_DeInit(void)
+{
+
+}
+

+ 63 - 0
Device/Imu.h

@@ -0,0 +1,63 @@
+
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("AutoChips Software") are
+ * protected under relevant copyright laws. The information contained herein is
+ * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
+ * the prior written permission of AutoChips inc. and/or its licensors, any
+ * reproduction, modification, use or disclosure of AutoChips Software, and
+ * information contained herein, in whole or in part, shall be strictly
+ * prohibited.
+ *
+ * AutoChips Inc. (C) 2018. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
+ * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
+ * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
+ * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+ * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
+ * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+ * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+ * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
+ * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
+ * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
+ * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
+ * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
+ * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+ * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
+ */
+
+/*************<start>******************/
+
+#ifndef IMU_H__
+#define IMU_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "ac780x_uart_reg.h"
+#include "ac780x.h"
+
+
+void Imu_Init(void);
+
+uint8_t Imu_MR(void);
+uint8_t Imu_GetAngle(float* roll, float* pitch, float* yaw);
+uint8_t Imu_Print(void);
+
+void Imu_DeInit(void);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+
+#endif //IMU_H__

+ 239 - 0
Device/Radar.c

@@ -0,0 +1,239 @@
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("AutoChips Software") are
+ * protected under relevant copyright laws. The information contained herein is
+ * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
+ * the prior written permission of AutoChips inc. and/or its licensors, any
+ * reproduction, modification, use or disclosure of AutoChips Software, and
+ * information contained herein, in whole or in part, shall be strictly
+ * prohibited.
+ *
+ * AutoChips Inc. (C) 2016. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
+ * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
+ * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
+ * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+ * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
+ * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+ * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+ * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
+ * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
+ * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
+ * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
+ * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
+ * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+ * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
+ */
+ 
+#include "ac780x_uart_reg.h"
+#include "ac780x_gpio.h"
+#include "Radar.h"
+#include "uart.h"
+#include "string.h"
+#include "crc16.h"
+
+#define LaDarUARTx   UART0
+#define LaDarUARTx_IRQn  UART0_IRQn
+
+#define RADAR_RX_BUFF_LENGTH   9
+
+uint8_t g_radarRxDataBuff[RADAR_RX_BUFF_LENGTH];
+uint16_t g_radarRxDataIndex;
+
+uint8_t *g_radarTxDataPoint;
+uint16_t g_radarTxDataLength;
+uint16_t g_radarTxDataIndex;
+
+
+static uint8_t * p_float;
+static float  tmp_v;
+static uint16_t _crc = 0;
+
+
+static float airHeight = 0;
+static uint8_t _status = 0;
+
+
+uint8_t radar_cmd[8] = {0x7F, 0x04, 0x0A, 0x0F, 0x00, 0x02, 0x48, 0x0E};
+//static uint8_t radar_cmd[32];
+//uint8_t 
+
+//static uint32_t ladar_printfBuff[16];
+//static uint16_t ladar_printfLen = 0;
+
+static int TransmitData(uint8_t *pdata, uint16_t length);
+/**
+* UartEventCallback
+*
+* @param[in] device: UART_Type pointer
+* @param[in] wpara: UART lsr0 register
+* @param[in] lpara: UART lsr1 register
+* @return    none
+*
+* @brief   uart receive handle
+*/
+ static void UartEventCallback(void *device, uint32_t wpara, uint32_t lpara)
+{
+    uint8_t data = 0;
+    UART_Type *uart_Device = (UART_Type *)device;
+	
+    /*rx interrupt*/
+    if ((uart_Device->IER & UART_IER_ERXNE_Msk) && (wpara & UART_LSR0_DR_Msk))
+    {
+        data = uart_Device->RBR;  
+        g_radarRxDataBuff[g_radarRxDataIndex++] = data;
+        
+        if (g_radarRxDataIndex >= RADAR_RX_BUFF_LENGTH)
+        {
+            g_radarRxDataIndex = 0;
+						_crc = crc16(g_radarRxDataBuff, 7);
+					
+						if( _crc ==  (((uint16_t)g_radarRxDataBuff[7]<<8) | g_radarRxDataBuff[8])){
+							
+							if((g_radarRxDataBuff[3] == 0xFF)&&(g_radarRxDataBuff[4] == 0xFF)&&(g_radarRxDataBuff[5] == 0xFF)&&(g_radarRxDataBuff[6] == 0xFF)){
+									_status = STATUS_EXCEED;
+									airHeight = 0;
+							}else if((g_radarRxDataBuff[3] == 0xFE)&&(g_radarRxDataBuff[4] == 0xFE)&&(g_radarRxDataBuff[5] == 0xFE)&&(g_radarRxDataBuff[6] == 0xFE)){
+									_status = STATUS_BLIND;
+									airHeight = 0;
+							}else if((g_radarRxDataBuff[3] == 0xFD)&&(g_radarRxDataBuff[4] == 0xFD)&&(g_radarRxDataBuff[5] == 0xFD)&&(g_radarRxDataBuff[6] == 0xFD)){
+									_status = STATUS_WEAK;
+									airHeight = 0;
+							}else{
+									_status = STATUS_NORMAL;
+									p_float = (uint8_t*)&tmp_v;
+								
+									p_float[0] = g_radarRxDataBuff[4];
+									p_float[1] = g_radarRxDataBuff[3];
+									p_float[2] = g_radarRxDataBuff[6];
+									p_float[3] = g_radarRxDataBuff[5];
+								
+									airHeight = tmp_v;
+								
+							}	
+							
+						
+						}
+
+						
+//						ladar_printfLen = snprintf((char*)ladar_printfBuff, 64, "Radar[%d] airheight: %f m\r\n",_status, airHeight);
+//						rs485_TransmitData((uint8_t*)ladar_printfBuff, ladar_printfLen);
+						
+        }
+    }
+		
+    /*tx interrupt*/
+    if ((uart_Device->IER & UART_IER_ETXE_Msk) && (wpara & UART_LSR0_THRE_Msk)) 
+    {
+        uart_Device->RBR = g_radarTxDataPoint[g_radarTxDataIndex++];
+
+        if (g_radarTxDataIndex >= g_radarTxDataLength)
+        {
+            UART_SetTXEInterrupt(device, DISABLE);  ///<发送最后一个字节时关闭发送空中断
+        }
+    }
+}
+/**
+* uart_Initialize
+* 
+* @param[in] none
+* @return none
+*
+* @brief uart 初始化
+*/
+static void uart0_Initialize(void)
+{
+    UART_ConfigType  uartConfig = {0};
+
+    uartConfig.baudrate = 9600;
+    uartConfig.dataBits = UART_WORD_LEN_8BIT;
+    uartConfig.stopBits = UART_STOP_1BIT;
+    uartConfig.parity = UART_PARI_NO;
+    uartConfig.fifoByteEn = DISABLE; ///<must enable fifoByte when use DMA
+    uartConfig.dmaEn = UART_DMA_TXRX_NONE;
+    uartConfig.callBack = UartEventCallback;   ///<uart0 interrupt callback
+    UART_Init(LaDarUARTx, &uartConfig);
+    
+
+    UART_SetRXNEInterrupt(LaDarUARTx, ENABLE);
+    ///Enable UARTx interrupt
+    NVIC_SetPriority(LaDarUARTx_IRQn, 3);
+    NVIC_ClearPendingIRQ(LaDarUARTx_IRQn);
+    NVIC_EnableIRQ(LaDarUARTx_IRQn);
+    
+}
+/**
+* TransmitData
+* 
+* @param[in] pdata :发送数据指针
+* @param[in] length :发送数据长度
+* @return none
+*
+* @brief uart 发送函数,通过中断发送 
+*/
+int TransmitData(uint8_t *pdata, uint16_t length) 
+{
+    if (g_radarTxDataIndex < g_radarTxDataLength){
+        return -1;      ///<有数据正在发送
+    }
+		
+    g_radarTxDataPoint = pdata;
+    g_radarTxDataLength = length;
+    g_radarTxDataIndex = 0;
+    UART_SetTXEInterrupt(LaDarUARTx, ENABLE);
+		
+    return 0;
+}
+
+//static void set_collectfreq(uint16_t interval){
+//		uint16_t len = 0;
+//		len = (uint16_t)snprintf((char*)radar_cmd, 32, "AT+COLLECTFREQ=%d\n", interval);
+//		TransmitData(radar_cmd, len);
+//}
+
+//static void read_airheight(){
+//		uint16_t len = 0;
+//		len = (uint16_t)snprintf((char*)radar_cmd, 32, "AT+REALAIRHEIGHT\n");
+//		TransmitData(radar_cmd, len);
+//}
+
+
+void Radar_Init(void)
+{
+		uart0_Initialize();
+
+		_status = STATUS_NORMAL;
+		airHeight = 0;
+	
+}
+
+uint8_t Radar_MR(void)
+{
+	 //清空、接收缓冲
+	 g_radarRxDataIndex = 0;
+	 TransmitData(radar_cmd, 8);
+	
+	 return 0;
+}
+uint8_t Radar_GetHeight(float* height)
+{
+	*height = airHeight;
+	return _status;
+}
+
+uint8_t Radar_Print(void)
+{
+	return 0;
+}
+
+void Radar_DeInit(void)
+{
+
+}
+

+ 71 - 0
Device/Radar.h

@@ -0,0 +1,71 @@
+
+/* Copyright Statement:
+ *
+ * This software/firmware and related documentation ("AutoChips Software") are
+ * protected under relevant copyright laws. The information contained herein is
+ * confidential and proprietary to AutoChips Inc. and/or its licensors. Without
+ * the prior written permission of AutoChips inc. and/or its licensors, any
+ * reproduction, modification, use or disclosure of AutoChips Software, and
+ * information contained herein, in whole or in part, shall be strictly
+ * prohibited.
+ *
+ * AutoChips Inc. (C) 2018. All rights reserved.
+ *
+ * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
+ * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("AUTOCHIPS SOFTWARE")
+ * RECEIVED FROM AUTOCHIPS AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER
+ * ON AN "AS-IS" BASIS ONLY. AUTOCHIPS EXPRESSLY DISCLAIMS ANY AND ALL
+ * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
+ * NONINFRINGEMENT. NEITHER DOES AUTOCHIPS PROVIDE ANY WARRANTY WHATSOEVER WITH
+ * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY,
+ * INCORPORATED IN, OR SUPPLIED WITH THE AUTOCHIPS SOFTWARE, AND RECEIVER AGREES
+ * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO.
+ * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO
+ * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN AUTOCHIPS
+ * SOFTWARE. AUTOCHIPS SHALL ALSO NOT BE RESPONSIBLE FOR ANY AUTOCHIPS SOFTWARE
+ * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
+ * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND AUTOCHIPS'S
+ * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE AUTOCHIPS SOFTWARE
+ * RELEASED HEREUNDER WILL BE, AT AUTOCHIPS'S OPTION, TO REVISE OR REPLACE THE
+ * AUTOCHIPS SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE
+ * CHARGE PAID BY RECEIVER TO AUTOCHIPS FOR SUCH AUTOCHIPS SOFTWARE AT ISSUE.
+ */
+
+/*************<start>******************/
+
+#ifndef RADAR_H__
+#define RADAR_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "ac780x_uart_reg.h"
+#include "ac780x.h"
+
+#define STATUS_NORMAL   			(0)  	//正常 
+#define STATUS_EXCEED   			(1)		//超出量程
+#define STATUS_BLIND   				(2)		//处于盲区
+#define STATUS_WEAK   				(3)		//回波能量不足 
+
+
+void Radar_Init(void);
+
+uint8_t Radar_MR(void);
+
+//return STATUS
+uint8_t Radar_GetHeight(float* height);
+
+uint8_t Radar_Print(void);
+
+void Radar_DeInit(void);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+
+#endif //RADAR_H__

+ 40 - 3
Device/adc.c

@@ -34,6 +34,8 @@
 #include "adc.h"
 #include "timer.h"
 #include "math.h"
+#include "uart.h"
+#include "string.h"
 
 /*********<Variable>********/
 uint8_t g_dmaFinish = 0;//DMA传输完成
@@ -42,6 +44,11 @@ uint8_t g_dmaTransError = 0; //DMA
 uint16_t __align(2) g_ADCValueBuffer[ADC_SAMPLE_CHANNEL*ADC_FILTER_NUM] = {0};
 uint32_t g_timer0Cnt = 0;
 //uint32_t g_averageSampleValue = 0;
+
+static uint8_t printfBuff[64];
+static uint16_t printfLen = 0;
+
+
 /**
  * ADC_DMACallback
  *
@@ -188,9 +195,12 @@ void ADC_init()
         1.同步时间为5个APB CLK。
         2.ADC时钟频率 = APB时钟频率 /(分频系数+1)
 	*/
+	
 		ADC_SetRegularGroupChannel(ADC0, ADC_CH_0, ADC_SPT_CLK_7, 0);  //set ADC_CH_7 为第1个采样序列 NTC 温度采集
-    ADC_SetRegularGroupChannel(ADC0, ADC_CH_7, ADC_SPT_CLK_7, 1);  //set ADC_CH_7 为第1个采样序列 线性hall 1
-		ADC_SetRegularGroupChannel(ADC0, ADC_CH_8, ADC_SPT_CLK_7, 2); ///set ADC_CH_8 为第2个采样序列 线性hall 2 
+		ADC_SetRegularGroupChannel(ADC0, ADC_CH_7, ADC_SPT_CLK_7, 1);  //set ADC_CH_7 为第2个采样序列 压力传感器 
+		
+    //ADC_SetRegularGroupChannel(ADC0, ADC_CH_7, ADC_SPT_CLK_7, 1);  //set ADC_CH_7 为第2个采样序列 线性hall 1
+		//ADC_SetRegularGroupChannel(ADC0, ADC_CH_8, ADC_SPT_CLK_7, 2); ///set ADC_CH_8 为第3个采样序列 线性hall 2 
     //ADC_SetRegularGroupChannel(ADC0, ADC_CH_BANDGAP, ADC_SPT_CLK_7, 2); ///set ADC_CH_BANDGAP 为第3个采样序列
     //ADC_SetRegularGroupChannel(ADC0, ADC_CH_TSENSOR, ADC_SPT_CLK_7, 3); ///set ADC_CH_TSENSOR 为第4个采样序列
 		
@@ -210,7 +220,7 @@ float getTemperature(void)
 	float temp = 0;
 	
 	for(i=0; i<ADC_FILTER_NUM; i++){
-		NtcAdc += g_ADCValueBuffer[3*i];
+		NtcAdc += g_ADCValueBuffer[ADC_SAMPLE_CHANNEL*i];
 	}
 	
 	NtcAdc = NtcAdc/ADC_FILTER_NUM;
@@ -223,6 +233,33 @@ float getTemperature(void)
 	return temp;
 }
 
+float getPressure(void)
+{
+		uint16_t Adc = 0;
+		uint8_t i;
+		float v;
+	
+		for(i=0; i<ADC_FILTER_NUM; i++){
+			Adc += g_ADCValueBuffer[ADC_SAMPLE_CHANNEL*i+1];
+		}
+		
+		Adc = Adc/ADC_FILTER_NUM;
+		v = 3.3*Adc/4096;
+		
+		return ((v-0.5)*350/2.0 - 100);
+		
+}
+
+void printTempPress(void)
+{
+
+	printfLen = snprintf((char*)printfBuff, 64, "ADC temp: %f, Press:%f \r\n", getTemperature(),getPressure());
+	rs485_TransmitData(printfBuff, printfLen);
+	
+}
+
+
+
 void  getHallValue(uint16_t* pHall_1, uint16_t* pHall_2)
 {
 	int16_t hall1_ADC = 0;

+ 4 - 1
Device/adc.h

@@ -50,7 +50,7 @@ extern "C" {
 #include "ac780x_pwm.h"
 
 
-#define ADC_SAMPLE_CHANNEL               (3)
+#define ADC_SAMPLE_CHANNEL               (2)
 #define ADC_FILTER_NUM               		 (4)
 
 //void  ADC_DMACallback(void *device, uint32_t wpara, uint32_t lpara);
@@ -58,10 +58,13 @@ extern "C" {
 void ADCSample_Init(void);
 
 float getTemperature(void);
+float getPressure(void);
+
 void  getHallValue(uint16_t* pHall_1, uint16_t* pHall_2);
 int16_t getHalldiff(void);
 
 void printADCValue(void);
+void printTempPress(void);
 
 
 #ifdef __cplusplus

+ 11 - 3
Device/gpio.c

@@ -81,9 +81,17 @@ void GPIO_PortInit(void)
 		GPIO_SetFunc(REDLED_PORT, REDLED_PIN, GPIO_FUN0);
 		GPIO_SetDir(REDLED_PORT, REDLED_PIN, GPIO_OUT);
 		
-		/*łőĘźťŻPressure Sensor iic0 */
-		GPIO_SetFunc(GPIOA, GPIO_PIN0, GPIO_FUN3);//I2C0_SCL
-		GPIO_SetFunc(GPIOA, GPIO_PIN1, GPIO_FUN3);//I2C0_sda
+//		/*łőĘźťŻPressure Sensor iic0 */
+//		GPIO_SetFunc(GPIOA, GPIO_PIN0, GPIO_FUN3);//I2C0_SCL
+//		GPIO_SetFunc(GPIOA, GPIO_PIN1, GPIO_FUN3);//I2C0_sda
+	
+	  //set pin mux for Ladar  
+    GPIO_SetFunc(GPIOC, GPIO_PIN3, GPIO_FUN3);  //UART0_RX
+    GPIO_SetFunc(GPIOC, GPIO_PIN2, GPIO_FUN3);	//UART0_TX
+		
+		//set pin mux for Imu  
+    GPIO_SetFunc(GPIOB, GPIO_PIN10, GPIO_FUN3);  //UART2_RX
+    GPIO_SetFunc(GPIOB, GPIO_PIN9, GPIO_FUN3);	 //UART2_TX
 	
 		//adc0 ch7 ch8
 		GPIO_SetFunc(GPIOA, GPIO_PIN2, GPIO_FUN2); 		// adc IN8 hall_2

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 145 - 91
Project/AirControlValve.uvguix.JL200


+ 48 - 0
Project/AirControlValve.uvoptx

@@ -588,6 +588,54 @@
       <RteFlg>0</RteFlg>
       <bShared>0</bShared>
     </File>
+    <File>
+      <GroupNumber>3</GroupNumber>
+      <FileNumber>32</FileNumber>
+      <FileType>5</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\Device\Radar.h</PathWithFileName>
+      <FilenameWithoutPath>Radar.h</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>3</GroupNumber>
+      <FileNumber>33</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\Device\Radar.c</PathWithFileName>
+      <FilenameWithoutPath>Radar.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>3</GroupNumber>
+      <FileNumber>34</FileNumber>
+      <FileType>5</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\Device\Imu.h</PathWithFileName>
+      <FilenameWithoutPath>Imu.h</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
+    <File>
+      <GroupNumber>3</GroupNumber>
+      <FileNumber>35</FileNumber>
+      <FileType>1</FileType>
+      <tvExp>0</tvExp>
+      <tvExpOptDlg>0</tvExpOptDlg>
+      <bDave2>0</bDave2>
+      <PathWithFileName>..\Device\Imu.c</PathWithFileName>
+      <FilenameWithoutPath>Imu.c</FilenameWithoutPath>
+      <RteFlg>0</RteFlg>
+      <bShared>0</bShared>
+    </File>
   </Group>
 
   <Group>

+ 21 - 1
Project/AirControlValve.uvprojx

@@ -49,7 +49,7 @@
             <InvalidFlash>1</InvalidFlash>
           </TargetStatus>
           <OutputDirectory>.\Objects\</OutputDirectory>
-          <OutputName>SmartSeaValve_20240816</OutputName>
+          <OutputName>SmartMHcover_20240827</OutputName>
           <CreateExecutable>1</CreateExecutable>
           <CreateLib>0</CreateLib>
           <CreateHexFile>1</CreateHexFile>
@@ -549,6 +549,26 @@
               <FileType>1</FileType>
               <FilePath>..\Device\PressureSensor.c</FilePath>
             </File>
+            <File>
+              <FileName>Radar.h</FileName>
+              <FileType>5</FileType>
+              <FilePath>..\Device\Radar.h</FilePath>
+            </File>
+            <File>
+              <FileName>Radar.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Device\Radar.c</FilePath>
+            </File>
+            <File>
+              <FileName>Imu.h</FileName>
+              <FileType>5</FileType>
+              <FilePath>..\Device\Imu.h</FilePath>
+            </File>
+            <File>
+              <FileName>Imu.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\Device\Imu.c</FilePath>
+            </File>
           </Files>
         </Group>
         <Group>

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 4351 - 5191
Project/JLinkLog.txt


+ 3 - 5
User/cfg.h

@@ -58,7 +58,7 @@ extern "C" {
 
 #define CONFIG_MAGIC   		0xA5A5
 
-#define DEFAULT_ADDR     0x60
+#define DEFAULT_ADDR     0x70
 #define BROADCAST_ADDR   0xFF
 
 /* Éý¼¶±êÖ¾ */
@@ -76,11 +76,9 @@ typedef struct
 		uint16_t magic;
     uint8_t  addr;
     uint8_t  br_index;
+
 	
-		int16_t  valvecolse_base;
-		int16_t	 threshold;
-	
-		uint32_t  res[57];
+		uint32_t  res[58];
 	
 		uint16_t hw_version;
 		uint16_t devicetype;

+ 10 - 6
User/main.c

@@ -6,7 +6,8 @@
 #include "process.h"
 #include "main_task.h"
 #include "watchdog.h"
-#include "PressureSensor.h"
+#include "Radar.h"
+#include "Imu.h"
 #include "adc.h"
 
 /*!
@@ -24,7 +25,7 @@ int main(void)
 	#endif
 	
 		InitDelay();
-		InitDebug();
+		//InitDebug();
 
 	
 		Config_Init();
@@ -40,13 +41,16 @@ int main(void)
 	
 	
 		Process_Init();
-		PressureSensor_Init();
+		Task_Init();
+		
 		ADCSample_Init();
-	
+		
+		Imu_Init();
+		Radar_Init();
+		
+		
 		Timer1_Init();
 		
-    Task_Init();
-
 	
     while (1)
     {

+ 40 - 49
User/main_task.c

@@ -112,15 +112,15 @@ void mb_03_handle(void)
 				}else if(8 == read_len){
 					tx_offset += Read_Temperature(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
 					tx_offset += Read_Pressure(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
-				}else if(10 == read_len){
+				}else if(14 == read_len){
 					tx_offset += Read_Temperature(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
 					tx_offset += Read_Pressure(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
-					tx_offset += Read_Status(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
-				}else if(14 == read_len){
+					tx_offset += Read_Height(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
+				}else if(26 == read_len){
 					tx_offset += Read_Temperature(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
 					tx_offset += Read_Pressure(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
-					tx_offset += Read_Status(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
-					tx_offset += Read_Raw(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);					
+					tx_offset += Read_Height(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
+					tx_offset += Read_Angle(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);					
 				}else{
 					g_mb_ctx.exception_code = INVALID_DATA;
 				}
@@ -129,42 +129,35 @@ void mb_03_handle(void)
 			case Cmd_ReadPressure:
 				if(4 == read_len){
 					tx_offset += Read_Pressure(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
-				}else if(6 == read_len){
-					tx_offset += Read_Pressure(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
-					tx_offset += Read_Status(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
 				}else if(10 == read_len){
 					tx_offset += Read_Pressure(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
-					tx_offset += Read_Status(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
-					tx_offset += Read_Raw(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
-				}else{
-					g_mb_ctx.exception_code = INVALID_DATA;
-				}
-				break;
-			case Cmd_ReadStatus:
-				if(2 == read_len){
-					tx_offset += Read_Status(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
-				}else if(6 == read_len){
-					tx_offset += Read_Status(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
-					tx_offset += Read_Raw(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
+					tx_offset += Read_Height(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
+				}else if(22 == read_len){
+					tx_offset += Read_Pressure(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
+					tx_offset += Read_Height(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
+					tx_offset += Read_Angle(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
 				}else{
 					g_mb_ctx.exception_code = INVALID_DATA;
 				}
 				break;
-			case Cmd_ReadRaw:
-				if(4 == read_len){
-					tx_offset += Read_Raw(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
+			case Cmd_ReadHeight:
+				if(6 == read_len){
+					tx_offset += Read_Height(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
+				}else if(18 == read_len){
+					tx_offset += Read_Height(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
+					tx_offset += Read_Angle(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
 				}else{
 					g_mb_ctx.exception_code = INVALID_DATA;
 				}
 				break;
-			case Cmd_ReadThreshold:
-				if(2 == read_len){
-					tx_offset += Read_Threshold(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
+			case Cmd_ReadAngle:
+				if(12 == read_len){
+					tx_offset += Read_Angle(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
 				}else{
 					g_mb_ctx.exception_code = INVALID_DATA;
 				}
 				break;
-				
+	
 			default:
 				g_mb_ctx.exception_code = INVALID_COMMAND;
 
@@ -236,15 +229,15 @@ void mb_06_handle(void)
 					g_mb_ctx.exception_code = INVALID_DATA;
 				}
 				break;
-			case Cmd_SetThreshold:
-				if(2 == g_mb_ctx.rx_len-4-2){
-					ret_write = Write_Threshold(g_mb_ctx.rxbuf+4, 2); 
-					if(RET_DATAINVALID == ret_write)
-						g_mb_ctx.exception_code = INVALID_DATA;
-				}else{
-					g_mb_ctx.exception_code = INVALID_DATA;
-				}
-				break;
+//			case Cmd_SetThreshold:
+//				if(2 == g_mb_ctx.rx_len-4-2){
+//					ret_write = Write_Threshold(g_mb_ctx.rxbuf+4, 2); 
+//					if(RET_DATAINVALID == ret_write)
+//						g_mb_ctx.exception_code = INVALID_DATA;
+//				}else{
+//					g_mb_ctx.exception_code = INVALID_DATA;
+//				}
+//				break;
 			case Cmd_Reboot:
 				//NVIC_SystemReset();
 				ret_write = RET_NEED_REBOOT;
@@ -380,16 +373,15 @@ void mb_10_handle(void)
 					}
 					break;
 					
-				case Cmd_SetThreshold:
-					if(2 == g_mb_ctx.rx_len-4-2){
-						ret_write = Write_Threshold(g_mb_ctx.rxbuf+7, 2); 
-						if(ret_write&RET_DATAINVALID)
-							g_mb_ctx.exception_code = INVALID_DATA;
-					}else{
-							g_mb_ctx.exception_code = INVALID_DATA;
-					}
-
-					break;
+//				case Cmd_SetThreshold:
+//					if(2 == g_mb_ctx.rx_len-4-2){
+//						ret_write = Write_Threshold(g_mb_ctx.rxbuf+7, 2); 
+//						if(ret_write&RET_DATAINVALID)
+//							g_mb_ctx.exception_code = INVALID_DATA;
+//					}else{
+//							g_mb_ctx.exception_code = INVALID_DATA;
+//					}
+//					break;
 				default:
 					g_mb_ctx.exception_code = INVALID_COMMAND;
 					break;
@@ -736,10 +728,10 @@ void Task_Init(void)
     rs485_Initialize();
 
 		memcpy(rs485_info.send_buffer, (void *)"Booted", 6);
-		
 		rs485_info.send_len = 6;
-		
 		rs485_TransmitData(rs485_info.send_buffer, rs485_info.send_len);
+	
+	
 		rs485_RecvData();
 		
 		
@@ -756,7 +748,6 @@ void Task_Init(void)
 void Task_Handle(void)
 {
 		Process_RunPeriod();
-
 		Uart0_RxDataHandle();
 
 }

+ 42 - 26
User/process.c

@@ -2,7 +2,8 @@
 #include "gpio.h"
 #include "cfg.h"
 #include "ac780x_gpio.h"
-#include "PressureSensor.h"
+#include "Radar.h"
+#include "Imu.h"
 #include "adc.h"
 
 uint16_t	g_blinkLedTime;		/*LED闪烁频率控制时间*/
@@ -38,15 +39,15 @@ static void update_state()
 //	
 //	}else{
 		
-		if(getHalldiff() >= (config->valvecolse_base + config->threshold)){
-			//g_state = STATUS_CLOSE;
-			open_count=0;
-			if(close_count < 0xFF) close_count++;
-		}else{
-			//g_state = STATUS_OPEN;
-			if(open_count < 0xFF)  open_count++;
-			close_count=0;
-		}
+//		if(getHalldiff() >= (config->valvecolse_base + config->threshold)){
+//			//g_state = STATUS_CLOSE;
+//			open_count=0;
+//			if(close_count < 0xFF) close_count++;
+//		}else{
+//			//g_state = STATUS_OPEN;
+//			if(open_count < 0xFF)  open_count++;
+//			close_count=0;
+//		}
 	
 //	}
 	
@@ -81,7 +82,7 @@ void Process_Init(void)
 
 		update_state();
 	
-	  printf("process init \r\n");
+	  //printf("process init \r\n");
 }
 
 void Process_RunPeriod(void)
@@ -118,7 +119,8 @@ void Process_RunPeriod(void)
 	//压力传感器测量请求  
 	if(g_mr_Interval >= 50){
 		g_mr_Interval=0;
-		g_exception = PressureSensor_MR();
+		//g_exception = PressureSensor_MR();
+		Imu_MR();
 		
 		update_state();
 		
@@ -126,13 +128,20 @@ void Process_RunPeriod(void)
 	
 	
 	
-//	if(g_print_interval >= 1000){
-//		g_print_interval=0;
-//		PressureSensor_Print();
-//		
-//		printf("the NTC temperature: %f \r\n",getTemperature());
-//		printf("the DIFF ADC1-ADC2: %d \r\n", getHalldiff());
-//	}
+	if(g_print_interval >= 500){
+		g_print_interval=0;
+		
+		Radar_MR();
+		
+		//Imu_MR();
+		
+		//printTempPress();
+		
+		//PressureSensor_Print();
+		
+		//printf("the NTC temperature: %f \r\n",getTemperature());
+		//printf("the DIFF ADC1-ADC2: %d \r\n", getHalldiff());
+	}
 	
 	
 	
@@ -143,21 +152,28 @@ uint8_t Process_GetValveStatus(void)
 	return g_state;
 }
 
+
 float Process_GetTemperature(void)
 {
 	return getTemperature();
 }
 
+
 float Process_GetPressure(void)
 {
-	float pressure = 0.0; 
-	float temperature = 0.0;
-	
-	//PressureSensor_Getvalue(&pressure);
-	PressureSensor_Getvalue2(&pressure, &temperature);
-	
-	return pressure;
+	return getPressure();
 	
 }
 
+uint8_t Process_GetAirHeight(float* pHeight)
+{
+		return Radar_GetHeight(pHeight);
+}
+
+
+uint8_t Process_GetAngle(float* pRoll, float* pPitch, float* pYaw)
+{
+		return Imu_GetAngle(pRoll, pPitch, pYaw);
+}
+
 

+ 3 - 0
User/process.h

@@ -65,6 +65,9 @@ uint8_t Process_GetValveStatus(void);
 
 float Process_GetTemperature(void);
 float Process_GetPressure(void);
+
+uint8_t Process_GetAirHeight(float* pHeight);
+uint8_t Process_GetAngle(float* pRoll, float* pPitch, float* pYaw);
  
 #ifdef __cplusplus
 }

+ 93 - 42
User/protocol.c

@@ -6,9 +6,9 @@
 
 
 #ifdef IS_BOOTLOADER
-uint32_t Firmware_Version[4] = {1, 0, 0, 20240816};
+uint32_t Firmware_Version[4] = {1, 0, 0, 20240827};
 #else
-uint32_t Firmware_Version[4] = {1, 1, 1, 20240816};
+uint32_t Firmware_Version[4] = {1, 1, 0, 20240827};
 #endif
 
 
@@ -137,51 +137,101 @@ uint16_t Read_Pressure(uint8_t *pBuf, uint16_t buf_len)
 	return 4;
 }
 
-uint16_t Read_Status(uint8_t *pBuf, uint16_t buf_len)
+//uint16_t Read_Status(uint8_t *pBuf, uint16_t buf_len)
+//{
+
+//	if( buf_len < 2){
+//		return 0;
+//	}
+//	
+
+//	pBuf[0] = Process_GetValveStatus();
+//	pBuf[1] = 0x00;
+//	
+//	return 2;
+//}
+
+//uint16_t Read_Raw(uint8_t *pBuf, uint16_t buf_len)
+//{
+//	uint16_t hall_1;
+//	uint16_t hall_2;
+//	
+//	if( buf_len < 4){
+//		return 0;
+//	}
+//	
+//	getHallValue(&hall_1, &hall_2);
+//	
+//	pBuf[0] = (hall_1 >> 8)&0xff;
+//	pBuf[1] = (hall_1 >> 0)&0xff;
+//	
+//	pBuf[2] = (hall_2 >> 8)&0xff;
+//	pBuf[3] = (hall_2 >> 0)&0xff;
+//	
+//	return 4;
+//}
+
+//uint16_t Read_Threshold(uint8_t *pBuf, uint16_t buf_len)
+//{
+
+//	if( buf_len < 2){
+//		return 0;
+//	}
+//	
+//	pBuf[0] = (config->threshold >> 8)&0xff;
+//	pBuf[1] = (config->threshold >> 0)&0xff;
+//	
+//	return 2;
+//}
+
+uint16_t Read_Height(uint8_t *pBuf, uint16_t buf_len)
 {
-
-	if( buf_len < 2){
+	float height =0;
+	if( buf_len < 6){
 		return 0;
 	}
 	
-
-	pBuf[0] = Process_GetValveStatus();
+	pBuf[0] = Process_GetAirHeight(&height);
 	pBuf[1] = 0x00;
 	
-	return 2;
+	pBuf[2] = ((uint8_t*)(&height))[0];
+	pBuf[3] = ((uint8_t*)(&height))[1];
+	pBuf[4] = ((uint8_t*)(&height))[2];
+	pBuf[5] = ((uint8_t*)(&height))[3];
+	
+	return 6;
 }
 
-uint16_t Read_Raw(uint8_t *pBuf, uint16_t buf_len)
+
+uint16_t Read_Angle(uint8_t *pBuf, uint16_t buf_len)
 {
-	uint16_t hall_1;
-	uint16_t hall_2;
+	float roll =0;
+	float pitch =0;
+	float yaw =0;
 	
-	if( buf_len < 4){
+	if( buf_len < 12){
 		return 0;
 	}
 	
-	getHallValue(&hall_1, &hall_2);
+	Process_GetAngle(&roll, &pitch, &yaw);
 	
-	pBuf[0] = (hall_1 >> 8)&0xff;
-	pBuf[1] = (hall_1 >> 0)&0xff;
+	pBuf[0] = ((uint8_t*)(&roll))[0];
+	pBuf[1] = ((uint8_t*)(&roll))[1];
+	pBuf[2] = ((uint8_t*)(&roll))[2];
+	pBuf[3] = ((uint8_t*)(&roll))[3];
 	
-	pBuf[2] = (hall_2 >> 8)&0xff;
-	pBuf[3] = (hall_2 >> 0)&0xff;
-	
-	return 4;
-}
-
-uint16_t Read_Threshold(uint8_t *pBuf, uint16_t buf_len)
-{
-
-	if( buf_len < 2){
-		return 0;
-	}
+	pBuf[4] = ((uint8_t*)(&pitch))[0];
+	pBuf[5] = ((uint8_t*)(&pitch))[1];
+	pBuf[6] = ((uint8_t*)(&pitch))[2];
+	pBuf[7] = ((uint8_t*)(&pitch))[3];
 	
-	pBuf[0] = (config->threshold >> 8)&0xff;
-	pBuf[1] = (config->threshold >> 0)&0xff;
+	pBuf[8] = ((uint8_t*)(&yaw))[0];
+	pBuf[9] = ((uint8_t*)(&yaw))[1];
+	pBuf[10] = ((uint8_t*)(&yaw))[2];
+	pBuf[11] = ((uint8_t*)(&yaw))[3];
 	
-	return 2;
+	return 12;
+
 }
 
 
@@ -251,22 +301,23 @@ uint8_t Write_Devicetype(uint8_t *pdata, uint8_t len)
 	}else{
 		return RET_DATAINVALID;
 	}
+	
 }
 
 
-uint8_t Write_Threshold(uint8_t *pdata, uint8_t len)
-{
+//uint8_t Write_Threshold(uint8_t *pdata, uint8_t len)
+//{
 
-	if(len == 2){
-		config->valvecolse_base = getHalldiff();
-		config->threshold = ((uint16_t)pdata[0]<<8) | pdata[1]; 
-		
-		return RET_OK|RET_NEED_SAVE;
-		
-	}else{
-		return RET_DATAINVALID;
-	}
-}
+//	if(len == 2){
+//		config->valvecolse_base = getHalldiff();
+//		config->threshold = ((uint16_t)pdata[0]<<8) | pdata[1]; 
+//		
+//		return RET_OK|RET_NEED_SAVE;
+//		
+//	}else{
+//		return RET_DATAINVALID;
+//	}
+//}
 
 
 

+ 11 - 8
User/protocol.h

@@ -53,11 +53,11 @@ extern "C" {
 
 #define Cmd_ReadTemperature    	(0x0020)
 #define Cmd_ReadPressure    	  (0x0022)
-#define Cmd_ReadStatus    	    (0x0024)
-#define Cmd_ReadRaw    	  			(0x0025)
+#define Cmd_ReadHeight    	    (0x0024)
+#define Cmd_ReadAngle    	  		(0x0027)
 
-#define Cmd_SetThreshold  			(0x0030)
-#define Cmd_ReadThreshold   	  (0x0031)
+//#define Cmd_SetThreshold  			(0x0030)
+//#define Cmd_ReadThreshold   	  (0x0031)
 
 #define Cmd_IapUpgrade    		 (0xAABB)
 
@@ -85,9 +85,12 @@ uint16_t Read_Baudrate(uint8_t *pBuf, uint16_t buf_len);
 
 uint16_t Read_Temperature(uint8_t *pBuf, uint16_t buf_len);
 uint16_t Read_Pressure(uint8_t *pBuf, uint16_t buf_len);
-uint16_t Read_Status(uint8_t *pBuf, uint16_t buf_len);
-uint16_t Read_Raw(uint8_t *pBuf, uint16_t buf_len);
-uint16_t Read_Threshold(uint8_t *pBuf, uint16_t buf_len);
+//uint16_t Read_Status(uint8_t *pBuf, uint16_t buf_len);
+//uint16_t Read_Raw(uint8_t *pBuf, uint16_t buf_len);
+//uint16_t Read_Threshold(uint8_t *pBuf, uint16_t buf_len);
+
+uint16_t Read_Height(uint8_t *pBuf, uint16_t buf_len);
+uint16_t Read_Angle(uint8_t *pBuf, uint16_t buf_len);
 
 
 #define RET_ERROR_MASK     (0xF0)
@@ -107,7 +110,7 @@ uint8_t Write_HardwareVersion(uint8_t *pdata, uint8_t len);
 uint8_t Write_Deviceid(uint8_t *pdata, uint8_t len); 
 uint8_t Write_Devicetype(uint8_t *pdata, uint8_t len); 
 
-uint8_t Write_Threshold(uint8_t *pdata, uint8_t len);
+//uint8_t Write_Threshold(uint8_t *pdata, uint8_t len);
     
 #ifdef __cplusplus
 }