|  |  |  | @ -46,6 +46,7 @@ | 
		
	
		
			
				|  |  |  |  | #include "wireless.h" | 
		
	
		
			
				|  |  |  |  | #include "flash_if.h" | 
		
	
		
			
				|  |  |  |  | #include "flash_log.h" | 
		
	
		
			
				|  |  |  |  | #include "dau.h" | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | /* Private define ------------------------------------------------------------*/ | 
		
	
		
			
				|  |  |  |  | #define DEBUG_FLASH_BUF_SIZE DEBUG_DATA_SIZE | 
		
	
	
		
			
				
					|  |  |  | @ -111,6 +112,7 @@ static UART_HandleTypeDef *debug_adj_uart = &huart1; | 
		
	
		
			
				|  |  |  |  | static uint8_t debug_state = 0; | 
		
	
		
			
				|  |  |  |  | /* 远程升级 flash 数据校验使用. */ | 
		
	
		
			
				|  |  |  |  | static uint8_t debug_flash[DEBUG_FLASH_BUF_SIZE]; | 
		
	
		
			
				|  |  |  |  | extern int8_t g_is_adj_status; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | /* Private function prototypes -----------------------------------------------*/ | 
		
	
		
			
				|  |  |  |  | /* Internal functions --------------------------------------------------------*/ | 
		
	
	
		
			
				
					|  |  |  | @ -164,7 +166,7 @@ void _debug_pkt_head_init(uint16_t len, uint8_t cmdType) | 
		
	
		
			
				|  |  |  |  | } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | /* 发送数据.. */ | 
		
	
		
			
				|  |  |  |  | void _debug_pkt_send(uint16_t len, uint8_t debug_len) | 
		
	
		
			
				|  |  |  |  | void _debug_pkt_send(uint16_t len, uint16_t debug_len) | 
		
	
		
			
				|  |  |  |  | { | 
		
	
		
			
				|  |  |  |  |     /* 发送报文 */ | 
		
	
		
			
				|  |  |  |  |     HAL_UART_Transmit_IT(debug_uart, debug_buf.buf, len); | 
		
	
	
		
			
				
					|  |  |  | @ -558,7 +560,7 @@ static void _debug_pkt_adj_get(void) | 
		
	
		
			
				|  |  |  |  |     *crc = crc32(debug_buf.buf, head->len); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     /* 发送报文 */ | 
		
	
		
			
				|  |  |  |  |     _debug_pkt_send(head->len + 4, 20); | 
		
	
		
			
				|  |  |  |  |     _debug_pkt_send(head->len + 4, head->len + 4); | 
		
	
		
			
				|  |  |  |  |      | 
		
	
		
			
				|  |  |  |  |     return; | 
		
	
		
			
				|  |  |  |  | } | 
		
	
	
		
			
				
					|  |  |  | @ -682,12 +684,15 @@ static HAL_StatusTypeDef _debug_adj_source_set(uint8_t ch_bitmap, uint8_t index) | 
		
	
		
			
				|  |  |  |  |     { | 
		
	
		
			
				|  |  |  |  |         turn_num = 20; | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     DBG(DBG_M_RS485_SEN, "ADC_base_elec[%d][%d] = %d turn_num = %d\r\n", ch, index, dev_config.ADC_base_elec[ch][index], turn_num); | 
		
	
		
			
				|  |  |  |  |     DBG(DBG_M_RS485_SEN, "ADC_base_elec[%d][%d] / turn_num = %d\r\n", ch, index, dev_config.ADC_base_elec[ch][index]/turn_num); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     /* 填充 buf, 设置电流电压. */ | 
		
	
		
			
				|  |  |  |  |     _debug_adj_source_set_buf(2200000, dev_config.ADC_base_elec[ch][index] / turn_num); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     /* 发送报文. */ | 
		
	
		
			
				|  |  |  |  |     DBG(DBG_M_RS485_SEN, "ADJS(%d):\r\n", head->len); | 
		
	
		
			
				|  |  |  |  |     DBG(DBG_M_RS485_SEN, "ADJS(%d) SEND:\r\n", head->len); | 
		
	
		
			
				|  |  |  |  |     if (dbg_stat_get(DBG_M_RS485_SEN)) | 
		
	
		
			
				|  |  |  |  |     { | 
		
	
		
			
				|  |  |  |  |         buf_print(debug_flash, head->len); | 
		
	
	
		
			
				
					|  |  |  | @ -699,7 +704,7 @@ static HAL_StatusTypeDef _debug_adj_source_set(uint8_t ch_bitmap, uint8_t index) | 
		
	
		
			
				|  |  |  |  |     /* 接收报文. */ | 
		
	
		
			
				|  |  |  |  |     HAL_UART_Abort(debug_adj_uart); | 
		
	
		
			
				|  |  |  |  |     HAL_E_RETURN(HAL_UART_Receive(debug_adj_uart, debug_flash, 0x6, 300)); | 
		
	
		
			
				|  |  |  |  |     DBG(DBG_M_RS485_SEN, "ADJS(%d):\r\n", 0x6); | 
		
	
		
			
				|  |  |  |  |     DBG(DBG_M_RS485_SEN, "ADJS(%d) RECV:\r\n", 0x6); | 
		
	
		
			
				|  |  |  |  |     if (dbg_stat_get(DBG_M_RS485_SEN)) | 
		
	
		
			
				|  |  |  |  |     { | 
		
	
		
			
				|  |  |  |  |         buf_print(debug_flash, 0x6); | 
		
	
	
		
			
				
					|  |  |  | @ -715,6 +720,69 @@ static HAL_StatusTypeDef _debug_adj_source_set(uint8_t ch_bitmap, uint8_t index) | 
		
	
		
			
				|  |  |  |  |     osDelay(4000); | 
		
	
		
			
				|  |  |  |  |     return HAL_OK; | 
		
	
		
			
				|  |  |  |  | } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | static HAL_StatusTypeDef _debug_adj_source_setEx(uint8_t ch_bitmap, uint8_t index, uint16_t elec) | 
		
	
		
			
				|  |  |  |  | { | 
		
	
		
			
				|  |  |  |  |     debug_adj_head_t *head = (debug_adj_head_t*)&debug_flash[1]; | 
		
	
		
			
				|  |  |  |  |     uint8_t ch = 0; | 
		
	
		
			
				|  |  |  |  |     uint8_t turn_num = 10; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     /* 以第一个校准通道的校准点为准. */ | 
		
	
		
			
				|  |  |  |  |     for(ch = 0; ch < DAU_PORT_POWER_CNT; ch++) | 
		
	
		
			
				|  |  |  |  |     { | 
		
	
		
			
				|  |  |  |  |         if (IS_MONITOR_BIT_SET(ch_bitmap, ch)) | 
		
	
		
			
				|  |  |  |  |         { | 
		
	
		
			
				|  |  |  |  |             break; | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |     /* 没有通道被选择直接退出. */ | 
		
	
		
			
				|  |  |  |  |     if (DAU_PORT_POWER_CNT == ch) | 
		
	
		
			
				|  |  |  |  |     { | 
		
	
		
			
				|  |  |  |  |         return HAL_OK; | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     turn_num = dev_config.ADC_turns[ch]; | 
		
	
		
			
				|  |  |  |  |     if (0 == turn_num) | 
		
	
		
			
				|  |  |  |  |     { | 
		
	
		
			
				|  |  |  |  |         turn_num = 20; | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     DBG(DBG_M_RS485_SEN, "ADC_base_elec[%d][%d] = %d turn_num = %d\r\n", ch, index, dev_config.ADC_base_elec[ch][index], turn_num); | 
		
	
		
			
				|  |  |  |  |     DBG(DBG_M_RS485_SEN, "ADC_base_elec[%d][%d] / turn_num = %d\r\n", ch, index, dev_config.ADC_base_elec[ch][index]/turn_num); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     /* 填充 buf, 设置电流电压. */ | 
		
	
		
			
				|  |  |  |  |     _debug_adj_source_set_buf(2200000, elec); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     /* 发送报文. */ | 
		
	
		
			
				|  |  |  |  |     DBG(DBG_M_RS485_SEN, "ADJS(%d) SEND:\r\n", head->len); | 
		
	
		
			
				|  |  |  |  |     if (dbg_stat_get(DBG_M_RS485_SEN)) | 
		
	
		
			
				|  |  |  |  |     { | 
		
	
		
			
				|  |  |  |  |         buf_print(debug_flash, head->len); | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |     HAL_GPIO_WritePin(RS485_A_DE_GPIO_Port, RS485_A_DE_Pin, GPIO_PIN_SET); | 
		
	
		
			
				|  |  |  |  |     HAL_E_RETURN(HAL_UART_Transmit(debug_adj_uart, debug_flash, head->len, 300)); | 
		
	
		
			
				|  |  |  |  |     HAL_GPIO_WritePin(RS485_A_DE_GPIO_Port, RS485_A_DE_Pin, GPIO_PIN_RESET); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     /* 接收报文. */ | 
		
	
		
			
				|  |  |  |  |     HAL_UART_Abort(debug_adj_uart); | 
		
	
		
			
				|  |  |  |  |     HAL_E_RETURN(HAL_UART_Receive(debug_adj_uart, debug_flash, 0x6, 300)); | 
		
	
		
			
				|  |  |  |  |     DBG(DBG_M_RS485_SEN, "ADJS(%d) RECV:\r\n", 0x6); | 
		
	
		
			
				|  |  |  |  |     if (dbg_stat_get(DBG_M_RS485_SEN)) | 
		
	
		
			
				|  |  |  |  |     { | 
		
	
		
			
				|  |  |  |  |         buf_print(debug_flash, 0x6); | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     /* 判断返回值. */ | 
		
	
		
			
				|  |  |  |  |     if (head->cmd != 0x30) | 
		
	
		
			
				|  |  |  |  |     { | 
		
	
		
			
				|  |  |  |  |         return HAL_ERROR; | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     /* 等待电压电流稳定. */ | 
		
	
		
			
				|  |  |  |  |     osDelay(4000); | 
		
	
		
			
				|  |  |  |  |     return HAL_OK; | 
		
	
		
			
				|  |  |  |  | } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | /* 自动校准仪器连接. */ | 
		
	
		
			
				|  |  |  |  | static HAL_StatusTypeDef _debug_adj_connect(void) | 
		
	
	
		
			
				
					|  |  |  | @ -731,7 +799,7 @@ static HAL_StatusTypeDef _debug_adj_connect(void) | 
		
	
		
			
				|  |  |  |  |     *crc = _debug_adj_checksum((uint8_t*)head, head->len - 2); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     /* 发送报文. */ | 
		
	
		
			
				|  |  |  |  |     DBG(DBG_M_RS485_SEN, "ADJS(%d):\r\n", head->len); | 
		
	
		
			
				|  |  |  |  |     DBG(DBG_M_RS485_SEN, "SEND ADJS(%d):\r\n", head->len); | 
		
	
		
			
				|  |  |  |  |     if (dbg_stat_get(DBG_M_RS485_SEN)) | 
		
	
		
			
				|  |  |  |  |     { | 
		
	
		
			
				|  |  |  |  |         buf_print(debug_flash, head->len); | 
		
	
	
		
			
				
					|  |  |  | @ -740,11 +808,11 @@ static HAL_StatusTypeDef _debug_adj_connect(void) | 
		
	
		
			
				|  |  |  |  |     HAL_GPIO_WritePin(RS485_A_DE_GPIO_Port, RS485_A_DE_Pin, GPIO_PIN_SET); | 
		
	
		
			
				|  |  |  |  |     HAL_E_RETURN(HAL_UART_Transmit(debug_adj_uart, debug_flash, head->len, 300)); | 
		
	
		
			
				|  |  |  |  |     HAL_GPIO_WritePin(RS485_A_DE_GPIO_Port, RS485_A_DE_Pin, GPIO_PIN_RESET); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | 	 | 
		
	
		
			
				|  |  |  |  |     /* 接收报文. */ | 
		
	
		
			
				|  |  |  |  |     HAL_UART_Abort(debug_adj_uart); | 
		
	
		
			
				|  |  |  |  |     HAL_E_RETURN(HAL_UART_Receive(debug_adj_uart, debug_flash, 0x29, 300)); | 
		
	
		
			
				|  |  |  |  |     DBG(DBG_M_RS485_SEN, "ADJS(%d):\r\n", 0x29); | 
		
	
		
			
				|  |  |  |  |     DBG(DBG_M_RS485_SEN, "RECV ADJS(%d):\r\n", 0x29); | 
		
	
		
			
				|  |  |  |  |     if (dbg_stat_get(DBG_M_RS485_SEN)) | 
		
	
		
			
				|  |  |  |  |     { | 
		
	
		
			
				|  |  |  |  |         buf_print(debug_flash, 0x29); | 
		
	
	
		
			
				
					|  |  |  | @ -800,6 +868,7 @@ static HAL_StatusTypeDef _debug_adj_start(void) | 
		
	
		
			
				|  |  |  |  | { | 
		
	
		
			
				|  |  |  |  |     MONITOR_BITMAP_SET(system_init_flag, SYS_INIT_ADJ); | 
		
	
		
			
				|  |  |  |  |     HAL_UART_Abort(debug_adj_uart); | 
		
	
		
			
				|  |  |  |  |     HAL_GPIO_WritePin(POWER_RS485_GPIO_Port, POWER_RS485_Pin, GPIO_PIN_SET); | 
		
	
		
			
				|  |  |  |  |     osDelay(1000); | 
		
	
		
			
				|  |  |  |  |     HAL_E_RETURN(_debug_adj_connect()); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
	
		
			
				
					|  |  |  | @ -817,11 +886,12 @@ static HAL_StatusTypeDef _debug_adj_auto(uint8_t bitmap) | 
		
	
		
			
				|  |  |  |  |     { | 
		
	
		
			
				|  |  |  |  |         return HAL_OK; | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     /* 设置开始操作. */ | 
		
	
		
			
				|  |  |  |  |     HAL_E_RETURN(_debug_adj_start()); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     for(i = 0; i < DAU_PORT_POWER_CNT; i++) | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | 	//for(i = 0; i < DAU_PORT_POWER_CNT; i++)
 | 
		
	
		
			
				|  |  |  |  |     for(i = 0; i < 1; i++) | 
		
	
		
			
				|  |  |  |  |     { | 
		
	
		
			
				|  |  |  |  |         /* 过滤不需要的通道. */ | 
		
	
		
			
				|  |  |  |  |         if (!IS_MONITOR_BIT_SET(bitmap, i) || 0 == dev_config.ADC_ratio[i]) | 
		
	
	
		
			
				
					|  |  |  | @ -844,10 +914,18 @@ static HAL_StatusTypeDef _debug_adj_auto(uint8_t bitmap) | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |         /* 开始自动校准, 注意不同变比的通道不能一起校准. */ | 
		
	
		
			
				|  |  |  |  |         for (j = 0; j < DAU_POWER_ADJ_CNT; j++) | 
		
	
		
			
				|  |  |  |  |         for (j = 0; j < 1; j++)	// 只校准一个分段点 2024/12/11
 | 
		
	
		
			
				|  |  |  |  |         { | 
		
	
		
			
				|  |  |  |  |             HAL_E_RETURN(_debug_adj_source_set(bitmap_new, j)); | 
		
	
		
			
				|  |  |  |  |             //HAL_E_RETURN(ADC_base_auto(bitmap_new, j + 1));
 | 
		
	
		
			
				|  |  |  |  |             osDelay(3000); | 
		
	
		
			
				|  |  |  |  |             g_is_adj_status = 1; | 
		
	
		
			
				|  |  |  |  |             while (g_is_adj_status != 2) | 
		
	
		
			
				|  |  |  |  |             { | 
		
	
		
			
				|  |  |  |  | 				common_watchdog_set(COM_WDG_CLI); | 
		
	
		
			
				|  |  |  |  | 				osDelay(2000); | 
		
	
		
			
				|  |  |  |  |             } | 
		
	
		
			
				|  |  |  |  |             DBG(DBG_M_RS485_DEBUG, "capture end...\r\n"); | 
		
	
		
			
				|  |  |  |  |             HAL_E_RETURN(_dau_base_auto(bitmap_new, j + 1)); | 
		
	
		
			
				|  |  |  |  |         }         | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
	
		
			
				
					|  |  |  | @ -856,19 +934,82 @@ static HAL_StatusTypeDef _debug_adj_auto(uint8_t bitmap) | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     return HAL_OK; | 
		
	
		
			
				|  |  |  |  | } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | static HAL_StatusTypeDef _debug_adj_autoEx(uint8_t bitmap, uint16_t elec, uint8_t index) | 
		
	
		
			
				|  |  |  |  | { | 
		
	
		
			
				|  |  |  |  |     uint8_t i = 0; | 
		
	
		
			
				|  |  |  |  |     uint8_t j = 0; | 
		
	
		
			
				|  |  |  |  |     uint8_t bitmap_new = 0; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     if (!bitmap) | 
		
	
		
			
				|  |  |  |  |     { | 
		
	
		
			
				|  |  |  |  |         return HAL_OK; | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     /* 设置开始操作. */ | 
		
	
		
			
				|  |  |  |  |     HAL_E_RETURN(_debug_adj_start()); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | 	//for(i = 0; i < DAU_PORT_POWER_CNT; i++)
 | 
		
	
		
			
				|  |  |  |  |     for(i = 0; i < 1; i++) | 
		
	
		
			
				|  |  |  |  |     { | 
		
	
		
			
				|  |  |  |  |         /* 过滤不需要的通道. */ | 
		
	
		
			
				|  |  |  |  |         if (!IS_MONITOR_BIT_SET(bitmap, i) || 0 == dev_config.ADC_ratio[i]) | 
		
	
		
			
				|  |  |  |  |         { | 
		
	
		
			
				|  |  |  |  |             continue; | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |         /* 将变比相同的通道归到同一个 bitmap 中. */ | 
		
	
		
			
				|  |  |  |  |         bitmap_new = 0; | 
		
	
		
			
				|  |  |  |  |         for (j = i; j < DAU_PORT_POWER_CNT; j++) | 
		
	
		
			
				|  |  |  |  |         { | 
		
	
		
			
				|  |  |  |  |             if (!IS_MONITOR_BIT_SET(bitmap, j) | 
		
	
		
			
				|  |  |  |  |                 || dev_config.ADC_ratio[i] != dev_config.ADC_ratio[j]) | 
		
	
		
			
				|  |  |  |  |             { | 
		
	
		
			
				|  |  |  |  |                 continue; | 
		
	
		
			
				|  |  |  |  |             } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |             MONITOR_BITMAP_RESET(bitmap, j); | 
		
	
		
			
				|  |  |  |  |             MONITOR_BITMAP_SET(bitmap_new, j); | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |         /* 开始自动校准, 注意不同变比的通道不能一起校准. */ | 
		
	
		
			
				|  |  |  |  |         //for (j = 0; j < DAU_POWER_ADJ_CNT; j++)
 | 
		
	
		
			
				|  |  |  |  |         {           		 | 
		
	
		
			
				|  |  |  |  |             HAL_E_RETURN(_debug_adj_source_setEx(bitmap_new, index-1, elec)); | 
		
	
		
			
				|  |  |  |  | 			osDelay(5000); | 
		
	
		
			
				|  |  |  |  |             g_is_adj_status = 1;        | 
		
	
		
			
				|  |  |  |  |             while (g_is_adj_status != 2) | 
		
	
		
			
				|  |  |  |  |             { | 
		
	
		
			
				|  |  |  |  | 				common_watchdog_set(COM_WDG_CLI); | 
		
	
		
			
				|  |  |  |  | 				osDelay(2000); | 
		
	
		
			
				|  |  |  |  |             } | 
		
	
		
			
				|  |  |  |  |             DBG(DBG_M_RS485_DEBUG, "capture end...\r\n"); | 
		
	
		
			
				|  |  |  |  |             HAL_E_RETURN(_dau_base_auto(bitmap_new, index));     | 
		
	
		
			
				|  |  |  |  |     		g_is_adj_status = 0; | 
		
	
		
			
				|  |  |  |  |         }         | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     /* 关闭校准. */ | 
		
	
		
			
				|  |  |  |  |     HAL_E_RETURN(_debug_adj_close()); | 
		
	
		
			
				|  |  |  |  |    | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     return HAL_OK; | 
		
	
		
			
				|  |  |  |  | } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | /* 自动校准报文处理. */ | 
		
	
		
			
				|  |  |  |  | static void _debug_pkt_adj_auto(void) | 
		
	
		
			
				|  |  |  |  | void _debug_pkt_adj_auto(void) | 
		
	
		
			
				|  |  |  |  | { | 
		
	
		
			
				|  |  |  |  |     proto_head_t *head = (proto_head_t*)debug_buf.buf; | 
		
	
		
			
				|  |  |  |  |     debug_adj_set *data = (debug_adj_set*)(debug_buf.buf + sizeof(proto_head_t)); | 
		
	
		
			
				|  |  |  |  |     uint32_t *rt = (uint32_t*)(debug_buf.buf + sizeof(proto_head_t)); | 
		
	
		
			
				|  |  |  |  |     uint32_t *crc = NULL; | 
		
	
		
			
				|  |  |  |  |     HAL_StatusTypeDef rv = HAL_ERROR; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     if (IS_MONITOR_BIT_SET(dev_config.flag, DEV_FLAG_ADJ)) | 
		
	
		
			
				|  |  |  |  |     { | 
		
	
		
			
				|  |  |  |  |         /* 开始自动校准. */ | 
		
	
		
			
				|  |  |  |  |         //data->ch_selecet = 1;
 | 
		
	
		
			
				|  |  |  |  |         rv = _debug_adj_auto(data->ch_selecet); | 
		
	
		
			
				|  |  |  |  |         if (rv == HAL_OK) | 
		
	
		
			
				|  |  |  |  |         { | 
		
	
	
		
			
				
					|  |  |  | @ -900,6 +1041,55 @@ static void _debug_pkt_adj_auto(void) | 
		
	
		
			
				|  |  |  |  |      | 
		
	
		
			
				|  |  |  |  |     return; | 
		
	
		
			
				|  |  |  |  | } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | void _debug_pkt_adj_autoEx(uint16_t elec, uint8_t index) | 
		
	
		
			
				|  |  |  |  | { | 
		
	
		
			
				|  |  |  |  |     proto_head_t *head = (proto_head_t*)debug_buf.buf; | 
		
	
		
			
				|  |  |  |  |     debug_adj_set *data = (debug_adj_set*)(debug_buf.buf + sizeof(proto_head_t)); | 
		
	
		
			
				|  |  |  |  |     uint32_t *rt = (uint32_t*)(debug_buf.buf + sizeof(proto_head_t)); | 
		
	
		
			
				|  |  |  |  |     uint32_t *crc = NULL; | 
		
	
		
			
				|  |  |  |  |     HAL_StatusTypeDef rv = HAL_ERROR; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     if (IS_MONITOR_BIT_SET(dev_config.flag, DEV_FLAG_ADJ)) | 
		
	
		
			
				|  |  |  |  |     { | 
		
	
		
			
				|  |  |  |  |         /* 开始自动校准. */ | 
		
	
		
			
				|  |  |  |  |         data->ch_selecet = 1; | 
		
	
		
			
				|  |  |  |  |         if (data->ch_selecet == 1) | 
		
	
		
			
				|  |  |  |  |         { | 
		
	
		
			
				|  |  |  |  | 			HAL_GPIO_WritePin(LED_RUN_GPIO_Port, LED_RUN_Pin, GPIO_PIN_SET); | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |         rv = _debug_adj_autoEx(data->ch_selecet, elec, index); | 
		
	
		
			
				|  |  |  |  |         if (rv == HAL_OK) | 
		
	
		
			
				|  |  |  |  |         { | 
		
	
		
			
				|  |  |  |  |             /* 完成后保存配置. */ | 
		
	
		
			
				|  |  |  |  |             common_sys_set(COM_SYS_SAVE_CONFIG, 0); | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |         /* 电池电压自动校准. */ | 
		
	
		
			
				|  |  |  |  |         if (data->is_voltage_sel) | 
		
	
		
			
				|  |  |  |  |         { | 
		
	
		
			
				|  |  |  |  |             ADC_vbat_auto(dev_config.vin); | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |     else | 
		
	
		
			
				|  |  |  |  |     { | 
		
	
		
			
				|  |  |  |  |         rv = HAL_ERROR; | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  |     *rt = rv; | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     /* 封装报文头. */ | 
		
	
		
			
				|  |  |  |  |     _debug_pkt_head_init(sizeof(proto_head_t) + 4, DEBUG_CT_PRV_REPLY); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     /* 计算校验和. */ | 
		
	
		
			
				|  |  |  |  |     crc = (uint32_t*)(debug_buf.buf + head->len); | 
		
	
		
			
				|  |  |  |  |     *crc = crc32(debug_buf.buf, head->len); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     /* 发送报文 */ | 
		
	
		
			
				|  |  |  |  |     //_debug_pkt_send(head->len + 4, 20);
 | 
		
	
		
			
				|  |  |  |  |      | 
		
	
		
			
				|  |  |  |  |     return; | 
		
	
		
			
				|  |  |  |  | } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | /* 实时数据获取报文处理. */ | 
		
	
		
			
				|  |  |  |  | static void _debug_pkt_data_get(void) | 
		
	
	
		
			
				
					|  |  |  | @ -1307,7 +1497,7 @@ static HAL_StatusTypeDef _debug_adj_manual(uint8_t bitmap, uint8_t index) | 
		
	
		
			
				|  |  |  |  |         }    | 
		
	
		
			
				|  |  |  |  |     } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     //HAL_E_RETURN(ADC_base_auto(bitmap, index + 1));
 | 
		
	
		
			
				|  |  |  |  |     HAL_E_RETURN(_dau_base_auto(bitmap, index + 1)); | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  |     return HAL_OK; | 
		
	
		
			
				|  |  |  |  | } | 
		
	
	
		
			
				
					|  |  |  | @ -1489,7 +1679,7 @@ static void _debug_pkt_process(void) | 
		
	
		
			
				|  |  |  |  |     return; | 
		
	
		
			
				|  |  |  |  | } | 
		
	
		
			
				|  |  |  |  | 
 | 
		
	
		
			
				|  |  |  |  | /* Interface functions -------------------------------------------------------*/ | 
		
	
		
			
				|  |  |  |  | /* Interface functions -------------------------------------------------------*/ | 
		
	
		
			
				|  |  |  |  | /* RS485 传感器主任务循环. */ | 
		
	
		
			
				|  |  |  |  | void debug_start(void) | 
		
	
		
			
				|  |  |  |  | { | 
		
	
	
		
			
				
					|  |  |  | @ -1556,7 +1746,7 @@ void debug_start(void) | 
		
	
		
			
				|  |  |  |  |         if (dbg_stat_get(DBG_M_RS485_DEBUG)) | 
		
	
		
			
				|  |  |  |  |         { | 
		
	
		
			
				|  |  |  |  |             buf_print(debug_buf.buf, 28); | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |         } | 
		
	
		
			
				|  |  |  |  |          | 
		
	
		
			
				|  |  |  |  |         /* 报文处理. */ | 
		
	
		
			
				|  |  |  |  |         _debug_pkt_process(); | 
		
	
	
		
			
				
					|  |  |  | 
 |