Parcourir la source

多功能人孔盖,增加雷达无响应处理,指示灯红绿管脚切换,异常状态指示等

guoqiang il y a 10 mois
Parent
commit
69dccf22a6
14 fichiers modifiés avec 2182 ajouts et 2077 suppressions
  1. 16 3
      Device/Radar.c
  2. 11 2
      Device/adc.c
  3. 2 0
      Device/adc.h
  4. 4 4
      Device/gpio.h
  5. 236 218
      Project/AirControlValve.uvguix.JL200
  6. 1 1
      Project/AirControlValve.uvprojx
  7. 1805 1811
      Project/JLinkLog.txt
  8. 4 0
      User/cfg.c
  9. 4 1
      User/cfg.h
  10. 18 0
      User/main_task.c
  11. 19 35
      User/process.c
  12. 2 0
      User/process.h
  13. 54 2
      User/protocol.c
  14. 6 0
      User/protocol.h

+ 16 - 3
Device/Radar.c

@@ -69,7 +69,7 @@ static uint8_t trans_databuffer[RADAR_MAX_BUFFERSIZE] = {0};	//透
 #define WAITTING_TIMEOUT    (100)  //单位  ms 
 static uint8_t  cmd_radar = RadarCmd_NULL;
 uint8_t  waiting_time_ladar =0;  //等待数据时间, ms 
-
+static uint8_t radar_timeout_count = 0; //雷达超时次数 
 
 static float airHeight = 0;
 static uint8_t _status = 0;
@@ -108,10 +108,12 @@ static int TransmitData(uint8_t *pdata, uint16_t length);
 				waiting_time_ladar =0;
 				
 				if(RadarCmd_AirHeight == cmd_radar){
+						radar_timeout_count = 0;
 						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( _crc ==  (((uint16_t)g_radarRxDataBuff[5]<<8) | g_radarRxDataBuff[6])){
@@ -223,6 +225,7 @@ void Radar_Init(void)
 
 		_status = STATUS_NORMAL;
 		airHeight = 0;
+		radar_timeout_count = 0;
 	
 }
 
@@ -257,9 +260,16 @@ void 	Radar_CheckResponse(void)
 			cmd_radar = RadarCmd_NULL; 
 			
 			if(RadarCmd_AirHeight == cmd_radar){
-					_status = STATUS_NoResponse;
-					airHeight = 0.0;
+					radar_timeout_count++;
 					g_radarRxDataIndex = 0;
+					
+					if(radar_timeout_count >= 3){
+						radar_timeout_count =3;
+						_status = STATUS_NoResponse;
+						airHeight = 0.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);
@@ -279,6 +289,9 @@ void Radar_SendRequest(void)
 		return;
 	}
 	
+//			ladar_printfLen = snprintf((char*)ladar_printfBuff, 64, "Radar_SendRequest recvbuffer_len[%d] m \r\n", recvbuffer_len);
+//		rs485_TransmitData((uint8_t*)ladar_printfBuff, ladar_printfLen);
+	
 	if(recvbuffer_len > 0){  
 		//有透传数据需要发送 
 		cmd_radar = RadarCmd_Trans;

+ 11 - 2
Device/adc.c

@@ -48,6 +48,9 @@ uint32_t g_timer0Cnt = 0;
 static uint8_t printfBuff[64];
 static uint16_t printfLen = 0;
 
+static float t_bias = 0.0;
+static float p_bias = 0.0;
+
 
 /**
  * ADC_DMACallback
@@ -207,6 +210,12 @@ void ADC_init()
     ADC_DMAInit();   //ADC DMA³õʼ»¯
 }
 
+void ADCSample_UpdateBias(float temp_bias, float press_bias)
+{
+	t_bias = temp_bias;
+	p_bias = press_bias;
+}
+
 float getTemperature(void)
 {
 	uint32_t NtcAdc = 0;
@@ -230,7 +239,7 @@ float getTemperature(void)
 	
 	temp=1/(1/T0+log(Rt/R)/B)-Ka+0.5; //¼ÆËãζÈ
 	
-	return temp;
+	return (temp+t_bias);
 }
 
 float getPressure(void)
@@ -246,7 +255,7 @@ float getPressure(void)
 		Adc = Adc/ADC_FILTER_NUM;
 		v = 3.3*Adc/4096;
 		
-		return ((v-0.5)*350/2.0 - 100);
+		return (((v-0.5)*350/2.0 - 100) + p_bias);
 		
 }
 

+ 2 - 0
Device/adc.h

@@ -57,6 +57,8 @@ extern "C" {
 //extern uint32_t g_ADCValueBuffer[ADC_SAMPLE_CHANNEL];
 void ADCSample_Init(void);
 
+void ADCSample_UpdateBias(float temp_bias, float press_bias);
+
 float getTemperature(void);
 float getPressure(void);
 

+ 4 - 4
Device/gpio.h

@@ -53,11 +53,11 @@ extern "C" {
 #define RS485_TX_EN				do{GPIO_SetPinLevel(RS485CTRL_PORT, RS485CTRL_PIN, GPIO_LEVEL_HIGH);}while(0)
 #define RS485_RX_EN				do{GPIO_SetPinLevel(RS485CTRL_PORT, RS485CTRL_PIN, GPIO_LEVEL_LOW);}while(0)
 
-#define GREENLED_PORT			(GPIOA)
-#define GREENLED_PIN			(GPIO_PIN10)
+#define GREENLED_PORT			(GPIOB)
+#define GREENLED_PIN			(GPIO_PIN8)
 
-#define REDLED_PORT			(GPIOB)
-#define REDLED_PIN			(GPIO_PIN8)
+#define REDLED_PORT			(GPIOA)
+#define REDLED_PIN			(GPIO_PIN10)
 
 /*RUNLED¶¯×÷¶¨Òå.*/	
 #define GREENLED_ON				do{GPIO_SetPinLevel(GREENLED_PORT, GREENLED_PIN, GPIO_LEVEL_HIGH);}while(0)

Fichier diff supprimé car celui-ci est trop grand
+ 236 - 218
Project/AirControlValve.uvguix.JL200


+ 1 - 1
Project/AirControlValve.uvprojx

@@ -49,7 +49,7 @@
             <InvalidFlash>1</InvalidFlash>
           </TargetStatus>
           <OutputDirectory>.\Objects\</OutputDirectory>
-          <OutputName>SmartMHcover_20240827</OutputName>
+          <OutputName>SmartMHcover_20241018</OutputName>
           <CreateExecutable>1</CreateExecutable>
           <CreateLib>0</CreateLib>
           <CreateHexFile>1</CreateHexFile>

Fichier diff supprimé car celui-ci est trop grand
+ 1805 - 1811
Project/JLinkLog.txt


+ 4 - 0
User/cfg.c

@@ -13,6 +13,7 @@ static void Factory_reset(void)
 		config->addr = DEFAULT_ADDR;
 		config->br_index = BaudRate_9600;
 	
+	
 		//config->App2Size = 0;
 		//config->App2Crc = 0;
 		//config->IapFlag = 0;
@@ -36,6 +37,9 @@ int Config_Init(void)
 				config->hw_version = 0x0000;
 				config->devicetype = 0x0000;
 				config->deviceid = 0x00;
+			
+				config->temperature_bias = 0.0;
+			  config->pressure_bias = 0.0;
 				
         SaveConfig();
 			

+ 4 - 1
User/cfg.h

@@ -76,9 +76,12 @@ typedef struct
 		uint16_t magic;
     uint8_t  addr;
     uint8_t  br_index;
+		
+		float  temperature_bias; //侊똑錦攣튤零 
+	  float  pressure_bias;    //箕제錦攣튤零 
 
 	
-		uint32_t  res[58];
+		uint32_t  res[56];
 	
 		uint16_t hw_version;
 		uint16_t devicetype;

+ 18 - 0
User/main_task.c

@@ -158,6 +158,14 @@ void mb_03_handle(void)
 				}
 				break;
 				
+			case Cmd_Bias:
+				if(8 == read_len){
+					tx_offset += Read_Bias(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
+				}else{
+					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);
@@ -382,6 +390,16 @@ void mb_10_handle(void)
 					}
 					break;
 					
+				case Cmd_Bias:
+					if(8 == data_len){
+						ret_write |= Write_Bias(g_mb_ctx.rxbuf+7, 8); 
+						if(ret_write&RET_DATAINVALID)
+							g_mb_ctx.exception_code = INVALID_DATA;
+					}else{
+						g_mb_ctx.exception_code = INVALID_DATA;
+					}
+					break;
+					
 				case Cmd_RadarTrans:
 //					if(2 == g_mb_ctx.rx_len-4-2){
 						ret_write = Write_RadarTransData(g_mb_ctx.rxbuf+7, data_len);

+ 19 - 35
User/process.c

@@ -16,46 +16,22 @@ uint16_t  g_print_interval = 0;   /* 
 
 uint8_t g_runstate; //状态
 uint8_t g_state; 		//状态
-uint8_t g_exception; //异常,主要指IIC 通信 
+uint8_t g_exception; //异常,主要指雷达
 
-uint8_t close_count =0;
-uint8_t open_count=0;
+static float  radar_airheight = 0;
+static uint8_t  radar_status = 0;
 
 
 static void update_state()
 {
-//		//判定阀开状态
-//	if(config->valvecolse_base <= 0){
-//		
-//		if(getHalldiff() > (config->valvecolse_base + config->threshold)){
-//				//g_state = STATUS_OPEN;
-//				if(open_count < 0xFF) open_count++;
-//				close_count=0;
-//		}else{
-//				//g_state = STATUS_CLOSE;
-//				open_count=0;
-//				if(close_count < 0xFF) close_count++;
-//		}
-//	
-//	}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(close_count >= 10){
-		g_state = STATUS_CLOSE;
-	}else if(open_count >= 10){
-		g_state = STATUS_OPEN;
-	}
+	 radar_status = Radar_GetHeight(&radar_airheight);
+	 
+	 if((STATUS_NoResponse == radar_status) || (STATUS_DataError == radar_status)){
+			g_exception = 1;
+	 }else{
+			g_exception = 0;
+	 }
+	
 		
 	if(STATUS_OPEN == g_state){
 		g_runstate = STATUS_OPEN;
@@ -82,6 +58,8 @@ void Process_Init(void)
 
 		update_state();
 	
+		ADCSample_UpdateBias(config->temperature_bias, config->pressure_bias);
+	
 	  //printf("process init \r\n");
 }
 
@@ -189,4 +167,10 @@ uint8_t Process_RRadarTransData(uint8_t *pBuf, uint8_t read_len)
 		return 0;
 }
 
+uint8_t Process_SetBias(float temp_bias, float press_bias)
+{
+		ADCSample_UpdateBias(temp_bias, press_bias);
+	  return 0;
+}
+
 

+ 2 - 0
User/process.h

@@ -71,6 +71,8 @@ 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);
+
+uint8_t Process_SetBias(float temp_bias, float press_bias);
  
 #ifdef __cplusplus
 }

+ 54 - 2
User/protocol.c

@@ -6,9 +6,9 @@
 
 
 #ifdef IS_BOOTLOADER
-uint32_t Firmware_Version[4] = {1, 0, 0, 20240920};
+uint32_t Firmware_Version[4] = {1, 1, 2, 20241018};
 #else
-uint32_t Firmware_Version[4] = {1, 1, 0, 20240920};
+uint32_t Firmware_Version[4] = {1, 1, 2, 20241018};
 #endif
 
 
@@ -234,6 +234,28 @@ uint16_t Read_Angle(uint8_t *pBuf, uint16_t buf_len)
 
 }
 
+uint16_t Read_Bias(uint8_t *pBuf, uint16_t buf_len)
+{
+	
+	if( buf_len < 8){
+		return 0;
+	}
+	
+
+	pBuf[0] = ((uint8_t*)(&config->temperature_bias))[0];
+	pBuf[1] = ((uint8_t*)(&config->temperature_bias))[1];
+	pBuf[2] = ((uint8_t*)(&config->temperature_bias))[2];
+	pBuf[3] = ((uint8_t*)(&config->temperature_bias))[3];
+	
+	pBuf[4] = ((uint8_t*)(&config->pressure_bias))[0];
+	pBuf[5] = ((uint8_t*)(&config->pressure_bias))[1];
+	pBuf[6] = ((uint8_t*)(&config->pressure_bias))[2];
+	pBuf[7] = ((uint8_t*)(&config->pressure_bias))[3];
+	
+
+	return 8;
+}
+
 uint16_t Read_RadarTransData(uint8_t *pBuf, uint16_t buf_len, uint8_t read_len)
 {
 	float height =0;
@@ -321,6 +343,36 @@ uint8_t Write_Devicetype(uint8_t *pdata, uint8_t len)
 	
 }
 
+uint8_t Write_Bias(uint8_t *pdata, uint8_t len)
+{
+	float tmp;
+	uint8_t* p=(uint8_t*)&tmp;
+	
+	if(len == 8){
+		
+		p[0]=pdata[0];
+		p[1]=pdata[1];
+		p[2]=pdata[2];
+		p[3]=pdata[3];
+		
+		config->temperature_bias = tmp;
+		
+		p[0]=pdata[4];
+		p[1]=pdata[5];
+		p[2]=pdata[6];
+		p[3]=pdata[7];
+		
+		config->pressure_bias = tmp;
+		
+		Process_SetBias(config->temperature_bias, config->pressure_bias);
+		
+		return RET_OK|RET_NEED_SAVE;
+		
+	}else{
+		return RET_DATAINVALID;
+	}
+}
+
 
 //uint8_t Write_Threshold(uint8_t *pdata, uint8_t len)
 //{

+ 6 - 0
User/protocol.h

@@ -56,6 +56,8 @@ extern "C" {
 #define Cmd_ReadHeight    	    (0x0024)
 #define Cmd_ReadAngle    	  		(0x0027)
 
+#define Cmd_Bias    	  		    (0x0030)
+
 //#define Cmd_SetThreshold  			(0x0030)
 //#define Cmd_ReadThreshold   	  (0x0031)
 #define Cmd_RadarTrans   	      (0xFF00)
@@ -93,9 +95,12 @@ 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_Bias(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)
 #define RET_NEED_SAVE			(0X01)
@@ -112,6 +117,7 @@ uint8_t Write_Baudrate(uint8_t *pdata, uint8_t len);
 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_Bias(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);