ソースを参照

多功能人孔盖,增加雷达透传指令

guoqiang 11 ヶ月 前
コミット
01a6bc8bf2
共有13 個のファイルを変更した2144 個の追加4490 個の削除を含む
  1. 171 55
      Device/Radar.c
  2. 8 1
      Device/Radar.h
  3. 2 2
      Device/adc.c
  4. 1 1
      Device/adc.h
  5. 5 1
      Device/timer.c
  6. 73 64
      Project/AirControlValve.uvguix.JL200
  7. 1 1
      Project/AirControlValve.uvoptx
  8. 1811 4351
      Project/JLinkLog.txt
  9. 19 11
      User/main_task.c
  10. 14 1
      User/process.c
  11. 3 0
      User/process.h
  12. 32 2
      User/protocol.c
  13. 4 0
      User/protocol.h

+ 171 - 55
Device/Radar.c

@@ -41,7 +41,12 @@
 #define LaDarUARTx   UART0
 #define LaDarUARTx_IRQn  UART0_IRQn
 
-#define RADAR_RX_BUFF_LENGTH   9
+#define RADAR_RX_BUFF_LENGTH   7
+#define RADAR_MAX_BUFFERSIZE   	 32
+
+#define RadarCmd_NULL   			(0)
+#define RadarCmd_AirHeight    (1)  
+#define RadarCmd_Trans        (2)
 
 uint8_t g_radarRxDataBuff[RADAR_RX_BUFF_LENGTH];
 uint16_t g_radarRxDataIndex;
@@ -52,15 +57,27 @@ uint16_t g_radarTxDataIndex;
 
 
 static uint8_t * p_float;
-static float  tmp_v;
-static uint16_t _crc = 0;
+//static float  tmp_v;
+static int16_t  tmp_v;
+//static uint16_t _crc = 0;
+
+static uint8_t recvbuffer_len = 0;
+static uint8_t databuffer_len = 0;
+static uint8_t trans_recvbuffer[RADAR_MAX_BUFFERSIZE] = {0};  //透传指令暂存buffer 
+static uint8_t trans_databuffer[RADAR_MAX_BUFFERSIZE] = {0};	//透传回应数据暂存buffer 
+
+#define WAITTING_TIMEOUT    (100)  //单位  ms 
+static uint8_t  cmd_radar = RadarCmd_NULL;
+uint8_t  waiting_time_ladar =0;  //等待数据时间, ms 
 
 
 static float airHeight = 0;
 static uint8_t _status = 0;
 
 
-uint8_t radar_cmd[8] = {0x7F, 0x04, 0x0A, 0x0F, 0x00, 0x02, 0x48, 0x0E};
+
+//uint8_t radar_cmd[8] = {0x7F, 0x04, 0x0A, 0x0F, 0x00, 0x02, 0x48, 0x0E};
+uint8_t radar_cmd[8] = {0xFF, 0x03, 0x00, 0x01, 0x00, 0x01, 0xC0, 0x14};
 //static uint8_t radar_cmd[32];
 //uint8_t 
 
@@ -81,51 +98,58 @@ static int TransmitData(uint8_t *pdata, uint16_t length);
  static void UartEventCallback(void *device, uint32_t wpara, uint32_t lpara)
 {
     uint8_t data = 0;
+		uint16_t _crc = 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])){
+        data = uart_Device->RBR; 
+				waiting_time_ladar =0;
+				
+				if(RadarCmd_AirHeight == cmd_radar){
+						g_radarRxDataBuff[g_radarRxDataIndex++] = data; 
+						if (g_radarRxDataIndex >= RADAR_RX_BUFF_LENGTH)
+						{
+								g_radarRxDataIndex = 0;
+								_crc = crc16(g_radarRxDataBuff, RADAR_RX_BUFF_LENGTH-2);
 							
-							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;
+								if( _crc ==  (((uint16_t)g_radarRxDataBuff[5]<<8) | g_radarRxDataBuff[6])){
+										_status = STATUS_NORMAL;
+										tmp_v = (int16_t)(g_radarRxDataBuff[3]<<8)|g_radarRxDataBuff[4];
+										airHeight = tmp_v/1000.0;
 								
-									p_float[0] = g_radarRxDataBuff[4];
-									p_float[1] = g_radarRxDataBuff[3];
-									p_float[2] = g_radarRxDataBuff[6];
-									p_float[3] = g_radarRxDataBuff[5];
+								}else{
+										_status = STATUS_DataError;
+										airHeight = 0.0;
+								}	
 								
-									airHeight = tmp_v;
+								//读空高命令结束
+								cmd_radar = RadarCmd_NULL;
 								
-							}	
-							
+//								ladar_printfLen = snprintf((char*)ladar_printfBuff, 64, "Radar st[%d], airheight: %f m [%x][%x][%x][%x][%x][%x][%x]\r\n",
+//									_status, airHeight,
+//									g_radarRxDataBuff[0],
+//								g_radarRxDataBuff[1],
+//								g_radarRxDataBuff[2],
+//								g_radarRxDataBuff[3],
+//								g_radarRxDataBuff[4],
+//								g_radarRxDataBuff[5],
+//								g_radarRxDataBuff[6]);
+//							rs485_TransmitData((uint8_t*)ladar_printfBuff, ladar_printfLen);
+								
+						}
 						
+				}else if(RadarCmd_Trans == cmd_radar){
+					
+						if(databuffer_len < RADAR_MAX_BUFFERSIZE){
+								trans_databuffer[databuffer_len++]=data;
 						}
 
-						
-//						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*/
@@ -151,7 +175,7 @@ static void uart0_Initialize(void)
 {
     UART_ConfigType  uartConfig = {0};
 
-    uartConfig.baudrate = 9600;
+    uartConfig.baudrate = 115200;
     uartConfig.dataBits = UART_WORD_LEN_8BIT;
     uartConfig.stopBits = UART_STOP_1BIT;
     uartConfig.parity = UART_PARI_NO;
@@ -188,21 +212,10 @@ int TransmitData(uint8_t *pdata, uint16_t 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)
 {
@@ -213,14 +226,117 @@ void Radar_Init(void)
 	
 }
 
-uint8_t Radar_MR(void)
+//uint8_t Radar_ReadAirHeight(void)
+//{
+////	 uint16_t crc = 0;
+////	
+////	 //清空、接收缓冲
+////	 g_radarRxDataIndex = 0;
+
+////	 radar_cmd[0] = 0xFF,
+////	 radar_cmd[1] = 0x03,
+////	 radar_cmd[2] = 0x00,
+////	 radar_cmd[3] = 0x01,
+////	 radar_cmd[4] = 0x00,
+////	 radar_cmd[5] = 0x01,
+
+////	 crc = crc16(radar_cmd, 6);
+////	 radar_cmd[6] = (uint8_t)((crc>>8) & 0x00ff);
+////	 radar_cmd[7] = (uint8_t)(crc & 0x00ff);
+//	 
+//	 TransmitData(radar_cmd, 8);
+
+//	 return 0;
+//}
+
+void 	Radar_CheckResponse(void)
+{
+	if(RadarCmd_NULL != cmd_radar){
+		if(waiting_time_ladar >= WAITTING_TIMEOUT){
+			//通信命令结束
+			cmd_radar = RadarCmd_NULL; 
+			
+			if(RadarCmd_AirHeight == cmd_radar){
+					_status = STATUS_NoResponse;
+					airHeight = 0.0;
+					g_radarRxDataIndex = 0;
+				
+//					ladar_printfLen = snprintf((char*)ladar_printfBuff, 64, "Radar_CheckResponse st[%d], airheight: %f m \r\n", _status, airHeight);
+//					rs485_TransmitData((uint8_t*)ladar_printfBuff, ladar_printfLen);
+				
+			}else {
+				  recvbuffer_len = 0;
+			}
+			
+		}
+	
+	}
+}
+
+void Radar_SendRequest(void)
+{
+	if(RadarCmd_NULL != cmd_radar){
+		return;
+	}
+	
+	if(recvbuffer_len > 0){  
+		//有透传数据需要发送 
+		cmd_radar = RadarCmd_Trans;
+		TransmitData(trans_recvbuffer, recvbuffer_len);
+		waiting_time_ladar = 0;
+		//清空接收缓存
+		databuffer_len=0;
+		memset(trans_databuffer, 0, RADAR_MAX_BUFFERSIZE);
+	
+	}else{
+		//读取空高数据 
+		cmd_radar = RadarCmd_AirHeight;
+		TransmitData(radar_cmd, 8);
+		waiting_time_ladar = 0;
+		g_radarRxDataIndex = 0;
+	}
+
+}
+
+void Radar_SendData(uint8_t* pData, uint8_t data_len)
 {
-	 //清空、接收缓冲
-	 g_radarRxDataIndex = 0;
-	 TransmitData(radar_cmd, 8);
+	if(data_len > RADAR_MAX_BUFFERSIZE){
+		return ;
+	}
+	
+	if(RadarCmd_Trans == cmd_radar){ //上一个透传指令还没结束 
+		return;
+	}
+	
+	memcpy(trans_recvbuffer, pData, data_len);
+	recvbuffer_len = data_len;
+	
+}
+
+void Radar_ReadData(uint8_t* pBuffer, uint8_t read_len)
+{
+	if(read_len > RADAR_MAX_BUFFERSIZE){
+		read_len = RADAR_MAX_BUFFERSIZE;
+	}
+	
+	memcpy(pBuffer, trans_databuffer, read_len);
+	
+	//清空接收缓存
+	databuffer_len=0;
+	memset(trans_databuffer, 0, RADAR_MAX_BUFFERSIZE);
 	
-	 return 0;
 }
+
+//uint8_t Radar_SetInstallHeight(uint16_t install_height)
+//{
+//	 //清空、接收缓冲
+//	 g_radarRxDataIndex = 0;
+//	 TransmitData(radar_cmd, 8);
+//	
+//	 return 0;
+//}
+
+
 uint8_t Radar_GetHeight(float* height)
 {
 	*height = airHeight;

+ 8 - 1
Device/Radar.h

@@ -48,11 +48,18 @@ extern "C" {
 #define STATUS_EXCEED   			(1)		//超出量程
 #define STATUS_BLIND   				(2)		//处于盲区
 #define STATUS_WEAK   				(3)		//回波能量不足 
+#define STATUS_DataError   		(4)		//数据错误
+#define STATUS_NoResponse   	(5)		//雷达无响应 
 
 
 void Radar_Init(void);
 
-uint8_t Radar_MR(void);
+//uint8_t Radar_ReadAirHeight(void);
+void Radar_SendRequest(void);
+void Radar_CheckResponse(void);
+
+void Radar_SendData(uint8_t* pData, uint8_t data_len);
+void Radar_ReadData(uint8_t* pBuffer, uint8_t read_len);
 
 //return STATUS
 uint8_t Radar_GetHeight(float* height);

+ 2 - 2
Device/adc.c

@@ -209,7 +209,7 @@ void ADC_init()
 
 float getTemperature(void)
 {
-	uint16_t NtcAdc = 0;
+	uint32_t NtcAdc = 0;
 	uint8_t i;
 	float Rt = 0; 		//NTC µç×è
 	float R = 50000;	//50K ¹Ì¶¨×èÖµµç×è 
@@ -235,7 +235,7 @@ float getTemperature(void)
 
 float getPressure(void)
 {
-		uint16_t Adc = 0;
+		uint32_t Adc = 0;
 		uint8_t i;
 		float v;
 	

+ 1 - 1
Device/adc.h

@@ -51,7 +51,7 @@ extern "C" {
 
 
 #define ADC_SAMPLE_CHANNEL               (2)
-#define ADC_FILTER_NUM               		 (4)
+#define ADC_FILTER_NUM               		 (32)
 
 //void  ADC_DMACallback(void *device, uint32_t wpara, uint32_t lpara);
 //extern uint32_t g_ADCValueBuffer[ADC_SAMPLE_CHANNEL];

+ 5 - 1
Device/timer.c

@@ -44,7 +44,7 @@
 
 /*************<macro>******************/
 
-
+extern uint8_t  waiting_time_ladar;
 /*************<enum>*******************/
 
 
@@ -151,6 +151,10 @@ void Timer_Callback(void *device, uint32_t wpara, uint32_t lpara)
 					g_print_interval++;
 			}
 			
+			if(waiting_time_ladar < 0xFF){
+					waiting_time_ladar++;
+			}
+			
 			
 			/*
 			

File diff suppressed because it is too large
+ 73 - 64
Project/AirControlValve.uvguix.JL200


+ 1 - 1
Project/AirControlValve.uvoptx

@@ -140,7 +140,7 @@
         <SetRegEntry>
           <Number>0</Number>
           <Key>JL2CM3</Key>
-          <Name>-U59518874 -O78 -S5 -ZTIFSpeedSel1000 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST1 -N00("ARM CoreSight SW-DP") -D00(0BC11477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8001 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO15 -FD20000000 -FC1000 -FN1 -FF0AC780x_128KB.FLM -FS08000000 -FL020000 -FP0($$Device:AC78013MDQA$Flash\AC780x_128KB.FLM)</Name>
+          <Name>-U59518874 -O78 -S5 -ZTIFSpeedSel1000 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST1 -N00("ARM CoreSight SW-DP") -D00(0BC11477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8001 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO31 -FD20000000 -FC1000 -FN1 -FF0AC780x_128KB.FLM -FS08000000 -FL020000 -FP0($$Device:AC78013MDQA$Flash\AC780x_128KB.FLM)</Name>
         </SetRegEntry>
         <SetRegEntry>
           <Number>0</Number>

File diff suppressed because it is too large
+ 1811 - 4351
Project/JLinkLog.txt


+ 19 - 11
User/main_task.c

@@ -28,7 +28,7 @@ void mb_03_handle(void)
 	
 		uint16_t tx_offset = 0;
 		uint16_t crc;
-		uint16_t ret_len = 0;
+		//uint16_t ret_len = 0;
 		uint16_t reg_num = ((uint16_t)g_mb_ctx.rxbuf[4]<<8)|g_mb_ctx.rxbuf[5];
 		uint16_t read_len = reg_num<<1; // wanted bytes 
 		//
@@ -157,6 +157,15 @@ void mb_03_handle(void)
 					g_mb_ctx.exception_code = INVALID_DATA;
 				}
 				break;
+				
+			case Cmd_RadarTrans:
+				if(read_len <= 32){
+					tx_offset += Read_RadarTransData(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset, (uint8_t)read_len);
+				}else{
+					g_mb_ctx.exception_code = INVALID_DATA;
+				}
+					
+				break;
 	
 			default:
 				g_mb_ctx.exception_code = INVALID_COMMAND;
@@ -373,15 +382,15 @@ void mb_10_handle(void)
 					}
 					break;
 					
-//				case Cmd_SetThreshold:
+				case Cmd_RadarTrans:
 //					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;
+						ret_write = Write_RadarTransData(g_mb_ctx.rxbuf+7, data_len);
+						if(ret_write&RET_DATAINVALID)
+							g_mb_ctx.exception_code = INVALID_DATA;
 //					}else{
 //							g_mb_ctx.exception_code = INVALID_DATA;
 //					}
-//					break;
+					break;
 				default:
 					g_mb_ctx.exception_code = INVALID_COMMAND;
 					break;
@@ -464,7 +473,7 @@ void mb_42_handle(void)
 void mb_funccodeerror_handle(void)
 {
 	uint16_t crc;
-	uint8_t ret_write = RET_OK;
+	//uint8_t ret_write = RET_OK;
 	
 	memcpy(g_mb_ctx.txbuf, g_mb_ctx.rxbuf, 4);
 	
@@ -520,8 +529,8 @@ void Uart0_RxDataHandle(void)
 		g_mb_ctx.exception_code = NO_EXCEPTION;
 	
 		uint16_t crc;
-		uint16_t ret_len = 0;
-		uint8_t ret_write = RET_OK;
+//		uint16_t ret_len = 0;
+//		uint8_t ret_write = RET_OK;
 	
 		if(g_mb_ctx.rx_len > 2){
 
@@ -733,8 +742,7 @@ void Task_Init(void)
 	
 	
 		rs485_RecvData();
-		
-		
+
 }
 
 

+ 14 - 1
User/process.c

@@ -121,6 +121,7 @@ void Process_RunPeriod(void)
 		g_mr_Interval=0;
 		//g_exception = PressureSensor_MR();
 		Imu_MR();
+		Radar_CheckResponse();
 		
 		update_state();
 		
@@ -131,7 +132,7 @@ void Process_RunPeriod(void)
 	if(g_print_interval >= 500){
 		g_print_interval=0;
 		
-		Radar_MR();
+		Radar_SendRequest();
 		
 		//Imu_MR();
 		
@@ -176,4 +177,16 @@ uint8_t Process_GetAngle(float* pRoll, float* pPitch, float* pYaw)
 		return Imu_GetAngle(pRoll, pPitch, pYaw);
 }
 
+uint8_t Process_WRadarTransData(uint8_t *pdata, uint8_t len)
+{
+		Radar_SendData(pdata, len);
+		return 0;
+}
+
+uint8_t Process_RRadarTransData(uint8_t *pBuf, uint8_t read_len)
+{
+		Radar_ReadData(pBuf, read_len);
+		return 0;
+}
+
 

+ 3 - 0
User/process.h

@@ -68,6 +68,9 @@ float Process_GetPressure(void);
 
 uint8_t Process_GetAirHeight(float* pHeight);
 uint8_t Process_GetAngle(float* pRoll, float* pPitch, float* pYaw);
+
+uint8_t Process_WRadarTransData(uint8_t *pdata, uint8_t len); 
+uint8_t Process_RRadarTransData(uint8_t *pBuf, uint8_t read_len);
  
 #ifdef __cplusplus
 }

+ 32 - 2
User/protocol.c

@@ -6,9 +6,9 @@
 
 
 #ifdef IS_BOOTLOADER
-uint32_t Firmware_Version[4] = {1, 0, 0, 20240827};
+uint32_t Firmware_Version[4] = {1, 0, 0, 20240920};
 #else
-uint32_t Firmware_Version[4] = {1, 1, 0, 20240827};
+uint32_t Firmware_Version[4] = {1, 1, 0, 20240920};
 #endif
 
 
@@ -234,6 +234,23 @@ uint16_t Read_Angle(uint8_t *pBuf, uint16_t buf_len)
 
 }
 
+uint16_t Read_RadarTransData(uint8_t *pBuf, uint16_t buf_len, uint8_t read_len)
+{
+	float height =0;
+	if( buf_len < read_len){
+		return 0;
+	}
+	
+	if(read_len > 32){
+		read_len = 32;
+	}
+	
+	Process_RRadarTransData(pBuf, read_len);
+	
+	return read_len;
+}
+
+
 
 /*=======================================================================================*/
 
@@ -319,6 +336,19 @@ uint8_t Write_Devicetype(uint8_t *pdata, uint8_t len)
 //	}
 //}
 
+uint8_t Write_RadarTransData(uint8_t *pdata, uint8_t len)
+{
+	if(len <= 32){
+		
+		Process_WRadarTransData(pdata, len); 
+		return RET_OK;
+		
+	}else{
+		return RET_DATAINVALID;
+	}
+	
+}
+
 
 
 

+ 4 - 0
User/protocol.h

@@ -58,6 +58,7 @@ extern "C" {
 
 //#define Cmd_SetThreshold  			(0x0030)
 //#define Cmd_ReadThreshold   	  (0x0031)
+#define Cmd_RadarTrans   	      (0xFF00)
 
 #define Cmd_IapUpgrade    		 (0xAABB)
 
@@ -92,6 +93,8 @@ uint16_t Read_Pressure(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);
 
+uint16_t Read_RadarTransData(uint8_t *pBuf, uint16_t buf_len, uint8_t read_len);
+
 
 #define RET_ERROR_MASK     (0xF0)
 #define RET_OK  		 			(0x00)
@@ -111,6 +114,7 @@ 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_RadarTransData(uint8_t *pdata, uint8_t len); 
     
 #ifdef __cplusplus
 }