浏览代码

更新协议、启用类modbus 协议格式

guoqiang 1 年之前
父节点
当前提交
94dd27b3f6
共有 6 个文件被更改,包括 518 次插入77 次删除
  1. 51 51
      Project/AirControlValve.uvguix.孙凯
  2. 1 1
      Project/AirControlValve.uvprojx
  3. 448 11
      User/main_task.c
  4. 3 3
      User/process.c
  5. 5 4
      User/protocol.c
  6. 10 7
      User/protocol.h

文件差异内容过多而无法显示
+ 51 - 51
Project/AirControlValve.uvguix.孙凯


+ 1 - 1
Project/AirControlValve.uvprojx

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

+ 448 - 11
User/main_task.c

@@ -8,6 +8,438 @@
 #include "crc16.h"
 #include <string.h>
 
+typedef struct _mb_ctx
+{
+	uint8_t* rxbuf;
+	uint8_t* txbuf;
+	uint16_t rx_len;  //recv data length
+	uint16_t tx_len;  //will be transfer data length
+	uint16_t txbuf_size;
+	uint8_t  exception_code;
+	uint8_t  func_code;   // function code 
+	uint16_t cmd;    			// register
+
+}MB_CTX;
+
+static MB_CTX g_mb_ctx;
+
+void mb_03_handle(void)
+{
+	
+		uint16_t tx_offset = 0;
+		uint16_t crc;
+		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 
+		//
+		g_mb_ctx.txbuf[0] = g_mb_ctx.rxbuf[0]; 		// slave addr 
+		g_mb_ctx.txbuf[1] = g_mb_ctx.rxbuf[1]; 		// func code 
+		g_mb_ctx.txbuf[2] = 0x00;
+	
+		tx_offset = 3;
+	
+		switch(g_mb_ctx.cmd){
+			case Cmd_FirmwareVersion:
+				if(16 == read_len){
+					tx_offset += Read_FirmwareVersion(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);	
+				}else if(18 == read_len){
+					tx_offset += Read_FirmwareVersion(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
+					tx_offset += Read_HardwareVersion(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
+				}else if(22 == read_len){
+					tx_offset += Read_FirmwareVersion(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
+					tx_offset += Read_HardwareVersion(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
+					tx_offset += Read_Deviceid(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
+				}else if(24 == read_len){
+					tx_offset += Read_FirmwareVersion(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
+					tx_offset += Read_HardwareVersion(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
+					tx_offset += Read_Deviceid(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
+					tx_offset += Read_Devicetype(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
+				}else {
+					g_mb_ctx.exception_code = INVALID_DATA;
+				}
+				break;
+			case Cmd_HardwareVersion:
+				if(2 == read_len){
+					tx_offset += Read_HardwareVersion(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
+				}else if(6 == read_len){
+					tx_offset += Read_HardwareVersion(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
+					tx_offset += Read_Deviceid(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
+				}else if(8 == read_len){
+					tx_offset += Read_HardwareVersion(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
+					tx_offset += Read_Deviceid(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
+					tx_offset += Read_Devicetype(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
+				}else{
+					g_mb_ctx.exception_code = INVALID_DATA;
+				}
+				break;
+			case Cmd_DeviceID:
+				if(4 == read_len){
+					tx_offset += Read_Deviceid(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
+				}else if(6 == read_len){
+					tx_offset += Read_Deviceid(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
+					tx_offset += Read_Devicetype(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
+				}else{
+					g_mb_ctx.exception_code = INVALID_DATA;
+				}
+				break;
+			case Cmd_DeviceType:
+				if(2 == read_len){
+					tx_offset += Read_Devicetype(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
+				}else{
+					g_mb_ctx.exception_code = INVALID_DATA;
+				}
+				break;
+			case Cmd_Addr:
+				if(2 == read_len){
+					tx_offset += Read_Addr(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
+				}else if(4 == read_len){
+					tx_offset += Read_Addr(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
+					tx_offset += Read_Baudrate(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
+				}else {
+					g_mb_ctx.exception_code = INVALID_DATA;
+				}
+				break;
+			case Cmd_Baudrate:
+				if(2 == read_len){
+					tx_offset += Read_Baudrate(g_mb_ctx.txbuf+tx_offset, g_mb_ctx.txbuf_size-tx_offset);
+				}else{
+					g_mb_ctx.exception_code = INVALID_DATA;
+				}
+				break;
+			case Cmd_LockStatus:
+				if(4 == read_len){
+					tx_offset += Read_LockStatus(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;
+
+				break;
+		};
+		
+		if(NO_EXCEPTION == g_mb_ctx.exception_code){
+				g_mb_ctx.txbuf[2] = (uint8_t)read_len;
+				g_mb_ctx.tx_len = tx_offset;
+		
+		}else{
+				g_mb_ctx.txbuf[1] |= 0x80; 		// func code 
+				g_mb_ctx.txbuf[2] = g_mb_ctx.exception_code;
+				g_mb_ctx.tx_len = 3;
+		}
+		
+		crc = crc16(g_mb_ctx.txbuf, g_mb_ctx.tx_len);
+		g_mb_ctx.txbuf[g_mb_ctx.tx_len++] = (uint8_t)((crc>>8) & 0x00ff);
+		g_mb_ctx.txbuf[g_mb_ctx.tx_len++] = (uint8_t)(crc & 0x00ff); 
+								
+		uart0_TransmitData(g_mb_ctx.txbuf, g_mb_ctx.tx_len);
+			
+}
+
+void mb_06_handle(void)
+{
+		uint16_t crc;
+		uint8_t ret_write = RET_OK;
+
+		memcpy(g_mb_ctx.txbuf, g_mb_ctx.rxbuf, g_mb_ctx.rx_len);
+	
+		switch(g_mb_ctx.cmd){
+			case Cmd_HardwareVersion:
+				if(2 == g_mb_ctx.rx_len-4-2){
+					ret_write = Write_HardwareVersion(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_DeviceType:
+				if(2 == g_mb_ctx.rx_len-4-2){
+					ret_write = Write_Devicetype(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_Addr:
+				if(2 == g_mb_ctx.rx_len-4-2){
+					ret_write = Write_Addr(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_Baudrate:
+				if(2 == g_mb_ctx.rx_len-4-2){
+					ret_write = Write_Baudrate(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;
+				break;
+			case Cmd_Reset:
+				ResetConfig();
+				ret_write = RET_NEED_SAVE|RET_NEED_REBOOT;
+				//NVIC_SystemReset();
+				break;
+			default:
+				g_mb_ctx.exception_code = INVALID_COMMAND;
+				break;
+		};
+		
+		if(NO_EXCEPTION == g_mb_ctx.exception_code){
+				g_mb_ctx.tx_len = g_mb_ctx.rx_len;
+		
+		}else{
+				g_mb_ctx.txbuf[1] |= 0x80; 		// func code 
+				g_mb_ctx.txbuf[2] = g_mb_ctx.exception_code;
+				g_mb_ctx.tx_len = 3;
+			
+				crc = crc16(g_mb_ctx.txbuf, g_mb_ctx.tx_len);
+				g_mb_ctx.txbuf[g_mb_ctx.tx_len++] = (uint8_t)((crc>>8) & 0x00ff);
+				g_mb_ctx.txbuf[g_mb_ctx.tx_len++] = (uint8_t)(crc & 0x00ff); 
+		}
+		
+		uart0_TransmitData(g_mb_ctx.txbuf, g_mb_ctx.tx_len);
+		
+		if((ret_write&RET_NEED_SAVE) > 0 ){
+				SaveConfig();
+		}
+		
+		if((ret_write&RET_NEED_REBOOT) > 0 ){
+				mdelay(200);
+				NVIC_SystemReset();
+		}
+
+		
+}
+
+void mb_10_handle(void)
+{
+		uint16_t crc;
+		uint8_t ret_write = RET_OK;
+		uint16_t reg_num = ((uint16_t)g_mb_ctx.rxbuf[4]<<8)|g_mb_ctx.rxbuf[5];
+		uint16_t data_len = g_mb_ctx.rxbuf[6];
+
+		memcpy(g_mb_ctx.txbuf, g_mb_ctx.rxbuf, g_mb_ctx.rx_len);
+	
+		// 先判段数据长度是否一致
+		if(data_len != reg_num*2){
+			g_mb_ctx.exception_code = INVALID_DATA;
+		}else{
+			if(data_len != g_mb_ctx.rx_len-7-2){
+				g_mb_ctx.exception_code = INVALID_DATA;
+			}
+		
+		}
+		
+		if(NO_EXCEPTION == g_mb_ctx.exception_code){
+			
+			switch(g_mb_ctx.cmd){
+				case Cmd_HardwareVersion:
+					if(8 == data_len){
+						ret_write |= Write_HardwareVersion(g_mb_ctx.rxbuf+7, 2); 
+						ret_write |= Write_Deviceid(g_mb_ctx.rxbuf+7+2, 4); 
+						ret_write |= Write_Devicetype(g_mb_ctx.rxbuf+7+6, 2); 
+						if(ret_write&RET_DATAINVALID)
+							g_mb_ctx.exception_code = INVALID_DATA;
+					}else if(6 == data_len){
+						ret_write |= Write_HardwareVersion(g_mb_ctx.rxbuf+7, 2); 
+						ret_write |= Write_Deviceid(g_mb_ctx.rxbuf+7+2, 4); 
+						if(ret_write&RET_DATAINVALID)
+							g_mb_ctx.exception_code = INVALID_DATA;
+					}else if(2 == g_mb_ctx.rx_len-4-2){
+						ret_write = Write_HardwareVersion(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_DeviceID:
+					if(6 == data_len){
+						ret_write |= Write_Deviceid(g_mb_ctx.rxbuf+7, 4); 
+						ret_write |= Write_Devicetype(g_mb_ctx.rxbuf+7+4, 2); 
+						if(ret_write&RET_DATAINVALID)
+							g_mb_ctx.exception_code = INVALID_DATA;
+					}else if(4 == data_len){
+						ret_write |= Write_Deviceid(g_mb_ctx.rxbuf+7, 4); 
+						if(ret_write&RET_DATAINVALID)
+							g_mb_ctx.exception_code = INVALID_DATA;
+					}else{
+						g_mb_ctx.exception_code = INVALID_DATA;
+					}
+
+					break;
+
+				case Cmd_DeviceType:
+					if(2 == data_len){
+						ret_write |= Write_Devicetype(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_Addr:
+					if(4 == data_len){
+						ret_write |= Write_Addr(g_mb_ctx.rxbuf+7, 2); 
+						ret_write |= Write_Addr(g_mb_ctx.rxbuf+7+2, 2); 
+						if(ret_write&RET_DATAINVALID)
+							g_mb_ctx.exception_code = INVALID_DATA;
+					}else if(2 == data_len){
+						ret_write |= Write_Addr(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_Baudrate:
+					if(2 == data_len){
+						ret_write |= Write_Baudrate(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;
+			};
+		}
+	
+		
+		
+		if(NO_EXCEPTION == g_mb_ctx.exception_code){
+				//只需要收到的前面6个字节的数据
+				g_mb_ctx.tx_len = 6;
+		
+		}else{
+				g_mb_ctx.txbuf[1] |= 0x80; 		// func code 
+				g_mb_ctx.txbuf[2] = g_mb_ctx.exception_code;
+				g_mb_ctx.tx_len = 3;
+		}
+		
+		crc = crc16(g_mb_ctx.txbuf, g_mb_ctx.tx_len);
+		g_mb_ctx.txbuf[g_mb_ctx.tx_len++] = (uint8_t)((crc>>8) & 0x00ff);
+		g_mb_ctx.txbuf[g_mb_ctx.tx_len++] = (uint8_t)(crc & 0x00ff); 
+		
+		uart0_TransmitData(g_mb_ctx.txbuf, g_mb_ctx.tx_len);
+		
+		if((ret_write&RET_NEED_SAVE) > 0 ){
+				SaveConfig();
+		}
+		
+		if((ret_write&RET_NEED_REBOOT) > 0 ){
+				mdelay(200);
+				NVIC_SystemReset();
+		}
+}
+
+void mb_42_handle(void)
+{
+	uint16_t crc;
+	uint8_t ret_write = RET_OK;
+	
+	memcpy(g_mb_ctx.txbuf, g_mb_ctx.rxbuf, 4);
+	g_mb_ctx.tx_len = 4;
+	
+	if(Cmd_IapUpgrade == g_mb_ctx.cmd){
+		
+		g_mb_ctx.tx_len += IAP_CmdHandle(g_mb_ctx.rxbuf+g_mb_ctx.tx_len, g_mb_ctx.rx_len-4-2, g_mb_ctx.txbuf+g_mb_ctx.tx_len);
+		if(1 == iap_reboot){
+			ret_write |= RET_NEED_REBOOT;
+		}
+		
+	}else{
+		g_mb_ctx.exception_code = INVALID_COMMAND;
+	}
+	
+	if(NO_EXCEPTION == g_mb_ctx.exception_code){
+			//啥都不用做
+	
+	}else{
+			g_mb_ctx.txbuf[1] |= 0x80; 		// func code 
+			g_mb_ctx.txbuf[2] = g_mb_ctx.exception_code;
+			g_mb_ctx.tx_len = 3;
+	}
+	
+	crc = crc16(g_mb_ctx.txbuf, g_mb_ctx.tx_len);
+	g_mb_ctx.txbuf[g_mb_ctx.tx_len++] = (uint8_t)((crc>>8) & 0x00ff);
+	g_mb_ctx.txbuf[g_mb_ctx.tx_len++] = (uint8_t)(crc & 0x00ff); 
+	
+	uart0_TransmitData(g_mb_ctx.txbuf, g_mb_ctx.tx_len);
+	
+	if((ret_write&RET_NEED_SAVE) > 0 ){
+			SaveConfig();
+	}
+	
+	if((ret_write&RET_NEED_REBOOT) > 0 ){
+			mdelay(200);
+			NVIC_SystemReset();
+	}
+	
+}
+
+void mb_funccodeerror_handle(void)
+{
+	uint16_t crc;
+	uint8_t ret_write = RET_OK;
+	
+	memcpy(g_mb_ctx.txbuf, g_mb_ctx.rxbuf, 4);
+	
+	
+	g_mb_ctx.txbuf[1] |= 0x80;
+	g_mb_ctx.txbuf[2] = INVALID_FUNCTION_CODE;
+	g_mb_ctx.tx_len = 3;
+	
+	crc = crc16(g_mb_ctx.txbuf, g_mb_ctx.tx_len);
+	g_mb_ctx.txbuf[g_mb_ctx.tx_len++] = (uint8_t)((crc>>8) & 0x00ff);
+	g_mb_ctx.txbuf[g_mb_ctx.tx_len++] = (uint8_t)(crc & 0x00ff); 
+	
+	uart0_TransmitData(g_mb_ctx.txbuf, g_mb_ctx.tx_len);
+	
+}
+
+void mb_handle(void)
+{
+		g_mb_ctx.func_code = g_mb_ctx.rxbuf[1];
+		g_mb_ctx.cmd = ((uint16_t)g_mb_ctx.rxbuf[2]<<8) | g_mb_ctx.rxbuf[3]; 
+	
+		if(MB_FUNC_03 == g_mb_ctx.func_code){
+				mb_03_handle();
+		}else if(MB_FUNC_06 == g_mb_ctx.func_code){
+				mb_06_handle();
+		}else if(MB_FUNC_10 == g_mb_ctx.func_code){
+				mb_10_handle();
+		}else if(MB_FUNC_42 == g_mb_ctx.func_code){
+				mb_42_handle();
+		}else{
+				mb_funccodeerror_handle();
+		}
+}
+
+
+
+
 
 /**
 * Uart0_RxDataHandle
@@ -18,27 +450,31 @@
 */
 void Uart0_RxDataHandle(void)
 {
-		uint8_t* rxbuf = uart0_info.recv_buffer;
-		uint16_t rx_len = uart0_info.recv_len;
-		uint8_t* txbuf = uart0_info.send_buffer;
-		uint16_t txbuf_size = UART0_TRANSMIT_DATA_POOL_COUNT;
-		uint16_t tx_len = 0;
-		uint16_t cmd;
+		g_mb_ctx.rxbuf = uart0_info.recv_buffer;
+		g_mb_ctx.rx_len = uart0_info.recv_len;
+		g_mb_ctx.txbuf = uart0_info.send_buffer;
+		g_mb_ctx.txbuf_size = UART0_TRANSMIT_DATA_POOL_COUNT;
+		g_mb_ctx.tx_len = 0;
+		g_mb_ctx.exception_code = NO_EXCEPTION;
+	
 		uint16_t crc;
 		uint16_t ret_len = 0;
 		uint8_t ret_write = RET_OK;
 	
-		if(rx_len > 2){
+		if(g_mb_ctx.rx_len > 2){
 
 	
 			//check rs485 addr 
-			if(config->addr == rxbuf[0] || BROADCAST_ADDR == rxbuf[0]){
+			if(config->addr == g_mb_ctx.rxbuf[0] || BROADCAST_ADDR == g_mb_ctx.rxbuf[0]){
 				
 #if 1						
 					// check crc
-					crc = ((uint16_t)rxbuf[rx_len-2]<<8) | rxbuf[rx_len-1]; 
-					if (crc == crc16(rxbuf, rx_len-2))
+					crc = ((uint16_t)g_mb_ctx.rxbuf[g_mb_ctx.rx_len-2]<<8) | g_mb_ctx.rxbuf[g_mb_ctx.rx_len-1]; 
+					if (crc == crc16(g_mb_ctx.rxbuf, g_mb_ctx.rx_len-2))
 					{
+							mb_handle();
+						
+#if 0
 							//copy 地址、功能码、命令、到发送buf 
 							memcpy(txbuf, (void *)rxbuf, 4);
 							tx_len +=4;
@@ -186,6 +622,7 @@ void Uart0_RxDataHandle(void)
 								uart0_TransmitData(txbuf, tx_len);
 
 							}
+#endif 
 							
 					}
 		#else
@@ -200,7 +637,7 @@ void Uart0_RxDataHandle(void)
 		
 		} //END rx_len 
 		
-		if(rx_len > 0){
+		if(g_mb_ctx.rx_len > 0){
 			uart0_RecvData();
 		}
 		

+ 3 - 3
User/process.c

@@ -101,16 +101,16 @@ void Process_ThreeStatus(void)
 
 uint8_t Process_LockStatus(void)
 {
-	return g_lockstatus;
+	return g_lockstatus==STATUS_OPEN?0x00:0x01;
 }
 
 uint8_t Process_UnlockStatus(void)
 {
-	return g_unlockstatus;
+	return g_unlockstatus==STATUS_OPEN?0x00:0x01;
 }
 
 uint8_t Process_CoverStatus(void)
 {
-	return g_coverstatus;
+	return g_coverstatus==STATUS_OPEN?0x00:0x01;
 }
 

+ 5 - 4
User/protocol.c

@@ -5,9 +5,9 @@
 
 
 #ifdef IS_BOOTLOADER
-uint32_t Firmware_Version[4] = {1, 0, 0, 20231214};
+uint32_t Firmware_Version[4] = {1, 0, 0, 20240401};
 #else
-uint32_t Firmware_Version[4] = {1, 1, 0, 20240108};
+uint32_t Firmware_Version[4] = {1, 1, 1, 20240401};
 #endif
 
 
@@ -104,15 +104,16 @@ uint16_t Read_Baudrate(uint8_t *pBuf, uint16_t buf_len)
 uint16_t Read_LockStatus(uint8_t *pBuf, uint16_t buf_len)
 {
 
-	if( buf_len < 3){
+	if( buf_len < 4){
 		return 0;
 	}
 	
 	pBuf[0] = Process_LockStatus();
 	pBuf[1] = Process_UnlockStatus();
 	pBuf[2] = Process_CoverStatus();
+	pBuf[3] = 0x00;
 	
-	return 3;
+	return 4;
 }
 
 

+ 10 - 7
User/protocol.h

@@ -42,11 +42,11 @@ extern "C" {
 #include "ac780x.h"
 
 #define Cmd_FirmwareVersion    (0x0000)
-#define Cmd_HardwareVersion    (0x0001)
-#define Cmd_DeviceID    			 (0x0002)
-#define Cmd_DeviceType    		 (0x0003)
-#define Cmd_Reboot		 		     (0x0004)
-#define Cmd_Reset    					 (0x0005)
+#define Cmd_HardwareVersion    (0x0008)
+#define Cmd_DeviceID    			 (0x0009)
+#define Cmd_DeviceType    		 (0x000B)
+#define Cmd_Reboot		 		     (0x000C)
+#define Cmd_Reset    					 (0x000D)
 
 #define Cmd_Addr    					 (0x0010)
 #define Cmd_Baudrate    			 (0x0011)
@@ -55,9 +55,12 @@ extern "C" {
 
 #define Cmd_IapUpgrade    		 (0xAABB)
 
-#define MODBUS_FUNC_READ				(0x03)
-#define MODBUS_FUNC_WRITE				(0x06)
+#define MB_FUNC_03				(0x03)
+#define MB_FUNC_06				(0x06)
+#define MB_FUNC_10			  (0x10)
+#define MB_FUNC_42				(0x42)  //for iap 
 
+#define NO_EXCEPTION						(0x00)
 #define INVALID_FUNCTION_CODE   (0x01)
 #define INVALID_COMMAND			    (0x02)
 #define INVALID_DATA   					(0x03)