Преглед на файлове

增加取样功能,调整485协议

guoqiang преди 11 месеца
родител
ревизия
7092a6c829
променени са 14 файла, в които са добавени 7510 реда и са изтрити 270 реда
  1. 26 1
      Device/AngleSensor.c
  2. 2 0
      Device/AngleSensor.h
  3. 5 5
      Device/gpio.c
  4. 1960 84
      Project/AirControlValve.uvguix.JL200
  5. 2 2
      Project/AirControlValve.uvoptx
  6. 5318 127
      Project/JLinkLog.txt
  7. 4 1
      User/cfg.c
  8. 4 1
      User/cfg.h
  9. 4 3
      User/main.c
  10. 12 3
      User/main_task.c
  11. 115 16
      User/process.c
  12. 11 4
      User/process.h
  13. 41 19
      User/protocol.c
  14. 6 4
      User/protocol.h

+ 26 - 1
Device/AngleSensor.c

@@ -10,6 +10,9 @@
 uint8_t g_spiTxBuff1[DATA_SIZE] = {0};
 uint8_t g_spiRxBuff1[DATA_SIZE] = {0};
 
+static float angle_offset = 0.0;
+static float angle_raw = 0.0;
+
 /*************<prototype>**************/
 void SPI0_Callback(void *device, uint32_t wpara, uint32_t lpara);
 
@@ -60,6 +63,11 @@ void AngleSensor_Init(void)
 
 }
 
+void AngleSensor_Setoffset(float offset)
+{
+	angle_offset = offset;
+}
+
 
 
 float AngleSensor_GetAngle(void)
@@ -83,15 +91,32 @@ float AngleSensor_GetAngle(void)
 	//printf("g_spiRxBuff1[4]:0x%x, g_spiRxBuff1[5]:0x%x \r\n", g_spiRxBuff1[4], g_spiRxBuff1[5]);
 	angle_value = (angle_value<<8)|g_spiRxBuff1[2];
 	angle = (360.0*angle_value)/32768;
-	
+
 	if((g_spiRxBuff1[5]&0xF0) != 0x70){
 	
 		angle = -180.0;
+	}else{
+		angle_raw = angle;
+		
+		angle += angle_offset;
+		if(angle > 360.0){
+			angle -= 360.0;
+		}
+		
+		if(angle < 0.0){
+			angle += 360.0;
+		}
+		
 	}
 	
 	return angle;
 }
 
+float AngleSensor_GetAngleRaw(void)
+{
+		return angle_raw;
+}
+
 void AngleSensor_PrintInfo(void)
 {
 	printf("AngleSensor angle:%f \r\n", AngleSensor_GetAngle());

+ 2 - 0
Device/AngleSensor.h

@@ -47,7 +47,9 @@ extern "C" {
 
 
 void AngleSensor_Init(void);
+void AngleSensor_Setoffset(float offset);
 float AngleSensor_GetAngle(void);
+float AngleSensor_GetAngleRaw(void);
 void AngleSensor_PrintInfo(void);
 
 void AngleSensor_DeInit(void);

+ 5 - 5
Device/gpio.c

@@ -82,9 +82,9 @@ void Gpio_Init(void)
 		GPIO_SetDir(REDLED_PORT, REDLED_PIN, GPIO_OUT);
 	
 		//LDO enable 
-		GPIO_SetFunc(LDOEn_PORT, LDOEn_PIN, GPIO_FUN0);
-		GPIO_SetDir(LDOEn_PORT, LDOEn_PIN, GPIO_OUT);
-		LDOEn_EN;
+//		GPIO_SetFunc(LDOEn_PORT, LDOEn_PIN, GPIO_FUN0);
+//		GPIO_SetDir(LDOEn_PORT, LDOEn_PIN, GPIO_OUT);
+//		LDOEn_EN;
 		
 		//adc0 ch7 ch8
 		GPIO_SetFunc(GPIOA, GPIO_PIN2, GPIO_FUN2); // adc IN8 µç»úµçÁ÷¼à²â
@@ -118,8 +118,8 @@ void Gpio_Init(void)
 		GPIO_SetFunc(GPIOA, GPIO_PIN8, GPIO_FUN3);//CS
 		
 		/*³õʼ»¯RTC  ds1307*/
-		GPIO_SetFunc(GPIOB, GPIO_PIN13, GPIO_FUN3);//I2C1_SCL
-		GPIO_SetFunc(GPIOC, GPIO_PIN4, GPIO_FUN3);//I2C1_sda
+//		GPIO_SetFunc(GPIOB, GPIO_PIN13, GPIO_FUN3);//I2C1_SCL
+//		GPIO_SetFunc(GPIOC, GPIO_PIN4, GPIO_FUN3);//I2C1_sda
 		
 		//GPIO_SetFunc(GPIOB, GPIO_PIN6, GPIO_FUN0);
 		//GPIO_SetDir(GPIOB, GPIO_PIN6, GPIO_OUT);

Файловите разлики са ограничени, защото са твърде много
+ 1960 - 84
Project/AirControlValve.uvguix.JL200


+ 2 - 2
Project/AirControlValve.uvoptx

@@ -140,7 +140,7 @@
         <SetRegEntry>
           <Number>0</Number>
           <Key>JL2CM3</Key>
-          <Name>-U59518874 -O78 -S2 -ZTIFSpeedSel5000 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -N00("ARM CoreSight SW-DP") -D00(0BC11477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -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 -S2 -ZTIFSpeedSel5000 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -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>
         </SetRegEntry>
         <SetRegEntry>
           <Number>0</Number>
@@ -155,7 +155,7 @@
       <DebugFlag>
         <trace>0</trace>
         <periodic>1</periodic>
-        <aLwin>0</aLwin>
+        <aLwin>1</aLwin>
         <aCover>0</aCover>
         <aSer1>0</aSer1>
         <aSer2>0</aSer2>

Файловите разлики са ограничени, защото са твърде много
+ 5318 - 127
Project/JLinkLog.txt


+ 4 - 1
User/cfg.c

@@ -13,7 +13,10 @@ static void Factory_reset(void)
 		config->addr = DEFAULT_ADDR;
 		config->br_index = BaudRate_9600;
 		config->lock_threshold = 0.0;
-		config->lock_threshold = 0.0;
+		config->unlock_threshold = 0.0;
+	  config->sample_threshold1 = 0.0;
+	  config->sample_threshold2 = 0.0;
+		config->angle_offset = 0.0;
 	
 		//config->App2Size = 0;
 		//config->App2Crc = 0;

+ 4 - 1
User/cfg.h

@@ -78,8 +78,11 @@ typedef struct
     uint8_t  br_index;
 		float  	lock_threshold;
 		float	 	unlock_threshold;
+		float	 	sample_threshold1;
+		float	 	sample_threshold2;
+		float   angle_offset;  //±àÂëÆ÷У׼ֵ
 	
-		uint32_t  res[56];
+		uint32_t  res[53];
 	
 		uint16_t hw_version;
 		uint16_t devicetype;

+ 4 - 3
User/main.c

@@ -41,12 +41,13 @@ int main(void)
     Gpio_Init();
 	  IAP_Init();
 
-		RTCx_Init();
+		//RTCx_Init();
 		AngleSensor_Init();
+		AngleSensor_Setoffset(config->angle_offset);
 		ADCSample_Init();
 		Motor_Init();
-		W25Q64_Init();
-		Storage_Init();
+		//W25Q64_Init();
+		//Storage_Init();
 
 		Process_Init();
 		Timer0_Init(); 

+ 12 - 3
User/main_task.c

@@ -114,7 +114,7 @@ void mb_03_handle(void)
 				}
 				break;
 			case Cmd_ReadThreshold:
-				if(8 == read_len){
+				if(16 == read_len){
 					tx_offset += Read_Threshold(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
 				}else{
 					g_mb_ctx.exception_code = INVALID_DATA;
@@ -246,6 +246,15 @@ void mb_06_handle(void)
 					g_mb_ctx.exception_code = INVALID_DATA;
 				}
 				break;
+			case Cmd_AngleCalibration:
+				if(2 == g_mb_ctx.rx_len-4-2){
+					ret_write = Write_AngleCalibration(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_RecordDelete:
 				if(2 == g_mb_ctx.rx_len-4-2){
 					ret_write = Write_RecordsDelete(g_mb_ctx.rxbuf+4, 2); 
@@ -759,11 +768,11 @@ void Task_Handle(void)
 	
 		Process_RunPrd();
 
-		Process_Storage(); 
+		//Process_Storage(); 
 
 		Uart0_RxDataHandle();
 		
-		Process_Poweroff();
+		//Process_Poweroff();
 
 }
 

+ 115 - 16
User/process.c

@@ -10,6 +10,7 @@
 #include "cfg.h"
 #include "Rtcx.h"
 #include "storage.h"
+#include "math.h"
 
 uint8_t		g_devicebusy = 0;
 uint16_t	g_blinkLedTime = 0;									/*LED闪烁频率控制时间*/
@@ -31,6 +32,8 @@ uint8_t g_coverstatus = STATUS_COVERCLOSE;
 uint8_t g_motorstate = MOTOR_INIT;
 uint8_t  g_runReady = 0;
 uint16_t g_runTime = 0;
+static float g_sample_position = 0;  // 触发取样时,PID目标位置,取两阀值的均值 
+//uint8_t  g_sampleing_direction = 0;  //触发取样时,电机运行方向, 0 正转, 1反转 
 
 //状态持续计数,用来起到滤波作用 
 //uint8_t tmp_status;
@@ -57,6 +60,9 @@ static void update_runstate()
 			case STATUS_UNLOCK:
 				g_runstate = STATE_UNLOCK;
 				break;
+			case STATUS_SAMPLE:
+				g_runstate = STATE_SAMPLE;
+				break;
 			case STATUS_UNKOWN:
 				g_runstate = STATE_EXCEPTION;
 				break;
@@ -97,6 +103,7 @@ void Process_RunPrd(void)
 	if (g_blinkLedTime >= g_blinkLedTgtTime)
 	{
 		g_blinkLedTime = 0;
+		g_blinkLedTgtTime = BLINK_LED_DFTT;
 		update_runstate();
 		
 		switch(g_runstate){
@@ -111,6 +118,11 @@ void Process_RunPrd(void)
 			case STATE_INTERMEDIATE:
 				REDGREEN_TOGGLE;
 				break;
+			case STATE_SAMPLE:
+				REDLED_OFF;
+				GREENLED_TOGGLE;
+				g_blinkLedTgtTime = 200;
+				break;
 			case STATE_OPENCOVER:
 				REDLED_OFF;
 			  GREENLED_ON;
@@ -140,9 +152,9 @@ void Process_RunPrd(void)
 	if(g_period1000ms >= 1000){
 		g_period1000ms=0;
 		
-		Storage_CountReduce();
+		//Storage_CountReduce();
 		
-		g_poweroff_count++;
+		//g_poweroff_count++;
 		
 		if(Gpio_IsDC24()){
 			printf(" DC24 Supply \r\n");
@@ -152,9 +164,9 @@ void Process_RunPrd(void)
 		
 		}
 		
-		printf(" Battery Voltage:%f V \r\n", getBatteryVoltage());
+		//printf(" Battery Voltage:%f V \r\n", getBatteryVoltage());
 		
-		RTCx_PrintDateTime();
+		//RTCx_PrintDateTime();
 		//AngleSensor_PrintInfo();
 		
 	
@@ -220,7 +232,7 @@ void Process_Timer10msCB(void)
 				g_runReady =1;
 				g_runTime=0;
 			}else{
-				PID_Calc(&g_pid, config->lock_threshold+3, s_angle);
+				PID_Calc(&g_pid, config->lock_threshold, s_angle);
 				
 				if(g_pid.error > 0){
 						tmp_speed =(uint8_t)(g_pid.output);
@@ -244,7 +256,31 @@ void Process_Timer10msCB(void)
 				g_runReady =1;
 				g_runTime=0;
 			}else{
-				PID_Calc(&g_pid, config->unlock_threshold-3, s_angle);
+				PID_Calc(&g_pid, config->unlock_threshold, s_angle);
+				
+				if(g_pid.error < 0){
+						tmp_speed =(uint8_t)(-g_pid.output);
+						tmp_speed = tmp_speed<50?50:tmp_speed;
+						Motor_Negative(tmp_speed);
+				
+				}else{
+					Motor_Stop();
+					g_motorstate = MOTOR_STOPED;
+					g_runReady =1;
+					g_runTime=0;
+				}
+				
+			}
+			break;
+			
+		case MOTOR_SAMPLEING:
+			if((STATUS_SAMPLE == g_lockstatus)|| (STATUS_UNKOWN == g_lockstatus) ||(g_runTime >= 2000)){
+				Motor_Stop();
+				g_motorstate = MOTOR_STOPED;
+				g_runReady =1;
+				g_runTime=0;
+			}else{
+				PID_Calc(&g_pid, g_sample_position, s_angle);
 				
 				if(g_pid.error < 0){
 						tmp_speed =(uint8_t)(-g_pid.output);
@@ -280,19 +316,42 @@ void Process_Timer10msCB(void)
 
 uint8_t get_lockstatus()
 {
+		static float _tmpf_min=0;
+		static float _tmpf_max = 0;
 		uint8_t status = STATUS_UNKOWN;
 		if(s_angle<0){
 			return status;
 		}
+		
 	
-		if(config->lock_threshold > config->unlock_threshold){
+		if((config->lock_threshold - config->unlock_threshold) > 10.0){
 			
 			if((s_angle > config->lock_threshold)){
 					status = STATUS_LOCK;	
 			}else if(s_angle < config->unlock_threshold){
 					status = STATUS_UNLOCK;	
 			}else {
+					
+				if(fabsf(config->sample_threshold1 - config->sample_threshold2) >  10.0 )
+				{
+					 if(config->sample_threshold1 > config->sample_threshold2){
+							_tmpf_max = config->sample_threshold1;
+							_tmpf_min = config->sample_threshold2;
+						}else{
+							_tmpf_max = config->sample_threshold2;
+							_tmpf_min = config->sample_threshold1;
+						}
+						
+						if((s_angle > _tmpf_min) && (s_angle < _tmpf_max)){
+							status = STATUS_SAMPLE;	
+						}else{
+							status = STATUS_INTERMEDIATE;	
+						}
+						
+				 }else{ //不支持取样
 					status = STATUS_INTERMEDIATE;	
+				 }
+					
 			}
 				
 		}
@@ -327,7 +386,7 @@ uint8_t Process_OpLock(uint8_t speed)
 		g_runReady =1;
 		g_runTime=0;
 		
-		PID_Init(&g_pid, 5, 10, 0, 80, 100);
+		PID_Init(&g_pid, 10, 0, 0, 50, 100);
 	}
 	
 	return 0;
@@ -342,21 +401,61 @@ uint8_t Process_OpUnlock(uint8_t speed)
 		g_runReady =1;
 		g_runTime=0;
 	
-		PID_Init(&g_pid,5, 10, 0, 80, 100);
+		PID_Init(&g_pid,10, 0, 0, 50, 100);
 	}
 
 	return 0;
 }
 
-
-uint8_t Process_CalibrationThreshold(uint8_t islock)
+uint8_t Process_OpSample(uint8_t speed)
 {
-	if(islock){
-		
-		config->lock_threshold = AngleSensor_GetAngle();
+	// 参数不符合要求
+	if(fabsf(config->sample_threshold1 - config->sample_threshold2) <=  10.0 ){
+		return 0;
+	}
 	
-	}else{
-		config->unlock_threshold = AngleSensor_GetAngle();
+	if((MOTOR_READY == g_motorstate) && (STATUS_LOCK == g_lockstatus)){
+		//Motor_Negative(speed);
+		g_motorstate = MOTOR_SAMPLEING;
+		g_runReady =1;
+		g_runTime=0;
+	
+		PID_Init(&g_pid,10, 0, 0, 50, 100);
+		
+		g_sample_position = (config->sample_threshold1 + config->sample_threshold2)/2;
+		
+	}
+
+	return 0;
+}
+
+float Process_GetAngle(void)
+{
+	return s_angle;
+}
+
+uint8_t Process_AngleCalibration(void)
+{
+		float angle_raw = AngleSensor_GetAngleRaw();
+	 if(angle_raw >= 0){
+			config->angle_offset = (200 - angle_raw);
+		  AngleSensor_Setoffset(config->angle_offset);
+	 }
+	 
+	 return 0;
+}
+
+
+uint8_t Process_CalibrationThreshold(uint8_t param)
+{
+	if(0 == param){
+		config->unlock_threshold = s_angle;
+	}else if(1 == param){
+		config->lock_threshold = s_angle;
+	}else if(2 == param){
+		config->sample_threshold1 = s_angle;
+	}else if(3 == param){
+		config->sample_threshold2 = s_angle;
 	}
 	
 	return 0x00;

+ 11 - 4
User/process.h

@@ -59,14 +59,16 @@ extern uint16_t 	g_runTime;
 #define STATE_LOCK     				  (0x00)  /*锁止状态*/
 #define STATE_UNLOCK   					(0x01)	/*开锁状态*/
 #define STATE_INTERMEDIATE      (0x02)	/*中间状态*/
-#define STATE_OPENCOVER         (0x03)	/*开盖状态*/
-#define STATE_EXCEPTION         (0x04)	/*异常状态*/
+#define STATE_SAMPLE   					(0x03)	/*开锁状态*/
+#define STATE_OPENCOVER         (0x04)	/*开盖状态*/
+#define STATE_EXCEPTION         (0x05)	/*异常状态*/
 
 //锁舌状态
 enum _lockstatus {
 	STATUS_INTERMEDIATE = 0, 			/*中间状态*/
 	STATUS_LOCK,									/*锁止状态*/
 	STATUS_UNLOCK,								/*开锁状态*/
+	STATUS_SAMPLE,								/*取样状态*/
 	STATUS_UNKOWN,								/*未知状态,设备异常了*/
 	STATUS_LOCKALL
 };
@@ -85,7 +87,8 @@ enum _coverstatus {
 #define	MOTOR_READY						(1)							
 #define	MOTOR_LOCKING					(2)
 #define	MOTOR_UNLOCKING				(3)
-#define	MOTOR_STOPED					(4)
+#define	MOTOR_SAMPLEING				(4)
+#define	MOTOR_STOPED					(5)
 
 
 
@@ -103,7 +106,11 @@ uint8_t Process_GetLockStatus(void);
 uint8_t Process_GetCoverStatus(void); 
 uint8_t Process_OpLock(uint8_t speed); 
 uint8_t Process_OpUnlock(uint8_t speed); 
-uint8_t Process_CalibrationThreshold(uint8_t islock); 
+uint8_t Process_OpSample(uint8_t speed); 
+uint8_t Process_CalibrationThreshold(uint8_t param); 
+
+float Process_GetAngle(void); 
+uint8_t Process_AngleCalibration(void); 
 
 #ifdef __cplusplus
 }

+ 41 - 19
User/protocol.c

@@ -12,9 +12,9 @@ static DataItem tmp_record;
 static uint8_t tmp_i=0;
 	
 #ifdef IS_BOOTLOADER
-uint32_t Firmware_Version[4] = {1, 0, 0, 20240802};
+uint32_t Firmware_Version[4] = {1, 0, 0, 20240925};
 #else
-uint32_t Firmware_Version[4] = {1, 1, 1, 20240803};
+uint32_t Firmware_Version[4] = {1, 1, 1, 20240925};
 #endif
 
 
@@ -111,20 +111,22 @@ uint16_t Read_Baudrate(uint8_t *pBuf, uint16_t buf_len)
 //读取锁状态 
 uint16_t Read_LockStatus(uint8_t *pBuf, uint16_t buf_len) 
 {
+	uint8_t tmp = 0;
 	if( buf_len < 2){
 		return 0;
 	}
 	
-	pBuf[0] = Process_GetLockStatus();   //锁状态 
-	pBuf[1] = Process_GetCoverStatus();  //上盖状态
+	tmp = Process_GetCoverStatus();  //上盖状态
+	pBuf[0] = (tmp<<4)|Process_GetLockStatus();   //锁状态 
+	pBuf[1] = 0x00;  //油品标识
 	
 	return 2;
 }
 
-//读取开锁、上锁阀值 
+//读取开锁、上锁阀值、取样阀值
 uint16_t Read_Threshold(uint8_t *pBuf, uint16_t buf_len)
 {
-	if( buf_len < 8){
+	if( buf_len < 16){
 		return 0;
 	}
 	
@@ -138,7 +140,17 @@ uint16_t Read_Threshold(uint8_t *pBuf, uint16_t buf_len)
 	pBuf[6] = ((uint8_t*)(&config->lock_threshold))[2];
 	pBuf[7] = ((uint8_t*)(&config->lock_threshold))[3];
 	
-	return 8;
+	pBuf[8] = ((uint8_t*)(&config->sample_threshold1))[0];
+	pBuf[9] = ((uint8_t*)(&config->sample_threshold1))[1];
+	pBuf[10] = ((uint8_t*)(&config->sample_threshold1))[2];
+	pBuf[11] = ((uint8_t*)(&config->sample_threshold1))[3];
+	
+	pBuf[12] = ((uint8_t*)(&config->sample_threshold2))[0];
+	pBuf[13] = ((uint8_t*)(&config->sample_threshold2))[1];
+	pBuf[14] = ((uint8_t*)(&config->sample_threshold2))[2];
+	pBuf[15] = ((uint8_t*)(&config->sample_threshold2))[3];
+	
+	return 16;
 
 }
 
@@ -150,7 +162,7 @@ uint16_t Read_Angle(uint8_t *pBuf, uint16_t buf_len)
 		return 0;
 	}
 	
-	float angle = AngleSensor_GetAngle();
+	float angle = Process_GetAngle();
 	
 	pBuf[0] = ((uint8_t*)(&angle))[0];
 	pBuf[1] = ((uint8_t*)(&angle))[1];
@@ -324,9 +336,11 @@ uint8_t Write_LockOp(uint8_t *pdata, uint8_t len)
 		
 		}else if(0x02 == pdata[0]){ //上锁 
 			Process_OpLock(pdata[1]); 
-		}else if(0x03 == pdata[0]){ //正转测试 
+		}else if(0x03 == pdata[0]){ //取样 
+			Process_OpSample(pdata[1]);
+		}else if(0x04 == pdata[0]){ //正转测试 
 			Motor_Positive(pdata[1]);
-		}else if(0x04 == pdata[0]){ //反转测试 
+		}else if(0x05 == pdata[0]){ //反转测试 
 			Motor_Negative(pdata[1]);
 		}
 	
@@ -337,24 +351,21 @@ uint8_t Write_LockOp(uint8_t *pdata, uint8_t len)
 	}
 }
 
-//开锁阀值、上锁阀值标定
+//开锁阀值、上锁阀值、取样阀值 标定
 uint8_t Write_ThresholdCalibration(uint8_t *pdata, uint8_t len)
 {
 	
 	if(len == 2){
 		
-		if(0x01 == pdata[1]){ //开锁
-			Process_CalibrationThreshold(0);
-		
-		}else if(0x02 == pdata[1]){ //上锁 
-			Process_CalibrationThreshold(1);
+		if(pdata[1] <= 0x03){
+			Process_CalibrationThreshold(pdata[1]);
+			return RET_OK|RET_NEED_SAVE;
 		}
-		return RET_OK|RET_NEED_SAVE;
 		
-	}else{
-		return RET_DATAINVALID;
 	}
 	
+	return RET_DATAINVALID;
+	
 }
 
 //标定设备日期时间 
@@ -398,3 +409,14 @@ uint8_t Write_RecordsDelete(uint8_t *pdata, uint8_t len)
 	
 }
 
+//编码器校准 
+uint8_t Write_AngleCalibration(uint8_t *pdata, uint8_t len)
+{
+	if(len == 2){
+		Process_AngleCalibration();
+		return RET_OK|RET_NEED_SAVE;
+	}
+	
+	return RET_DATAINVALID;	
+}
+

+ 6 - 4
User/protocol.h

@@ -55,11 +55,12 @@ extern "C" {
 #define Cmd_LockOp    		 		 (0x0021)
 #define Cmd_Threshold    		 	 (0x0022)
 #define Cmd_ReadThreshold    	 (0x0023)
-#define Cmd_ReadAngle    	 		 (0x0027)
+#define Cmd_AngleCalibration   (0x002B)
+#define Cmd_ReadAngle    	 		 (0x002C)
 //#define 
-#define Cmd_ReadRecordNum    	 (0x0029)
-#define Cmd_ReadRecords	       (0x002A)
-#define Cmd_RecordDelete  		 (0x005A)
+#define Cmd_ReadRecordNum    	 (0x0030)
+#define Cmd_ReadRecords	       (0x0031)
+#define Cmd_RecordDelete  		 (0x0061)
 
 #define Cmd_IapUpgrade    		 (0xAABB)
 
@@ -119,6 +120,7 @@ uint8_t Write_DateTime(uint8_t *pdata, uint8_t len);//
 
 uint8_t Write_RecordsDelete(uint8_t *pdata, uint8_t len);//读取设备历史记录确认 
 
+uint8_t Write_AngleCalibration(uint8_t *pdata, uint8_t len);//编码器校准 
     
 #ifdef __cplusplus
 }