diff --git a/MDK-ARM/DebugConfig/controller_pcba_STM32F407VGTx.dbgconf b/MDK-ARM/DebugConfig/controller_pcba_STM32F407VGTx.dbgconf new file mode 100644 index 0000000..1df0a1b --- /dev/null +++ b/MDK-ARM/DebugConfig/controller_pcba_STM32F407VGTx.dbgconf @@ -0,0 +1,48 @@ +// File: STM32F405_415_407_417_427_437_429_439.dbgconf +// Version: 1.0.0 +// Note: refer to STM32F405/415 STM32F407/417 STM32F427/437 STM32F429/439 reference manual (RM0090) +// refer to STM32F40x STM32F41x datasheets +// refer to STM32F42x STM32F43x datasheets + +// <<< Use Configuration Wizard in Context Menu >>> + +// Debug MCU configuration register (DBGMCU_CR) +// DBG_STANDBY Debug Standby Mode +// DBG_STOP Debug Stop Mode +// DBG_SLEEP Debug Sleep Mode +// +DbgMCU_CR = 0x00000007; + +// Debug MCU APB1 freeze register (DBGMCU_APB1_FZ) +// Reserved bits must be kept at reset value +// DBG_CAN2_STOP CAN2 stopped when core is halted +// DBG_CAN1_STOP CAN2 stopped when core is halted +// DBG_I2C3_SMBUS_TIMEOUT I2C3 SMBUS timeout mode stopped when core is halted +// DBG_I2C2_SMBUS_TIMEOUT I2C2 SMBUS timeout mode stopped when core is halted +// DBG_I2C1_SMBUS_TIMEOUT I2C1 SMBUS timeout mode stopped when core is halted +// DBG_IWDG_STOP Independent watchdog stopped when core is halted +// DBG_WWDG_STOP Window watchdog stopped when core is halted +// DBG_RTC_STOP RTC stopped when core is halted +// DBG_TIM14_STOP TIM14 counter stopped when core is halted +// DBG_TIM13_STOP TIM13 counter stopped when core is halted +// DBG_TIM12_STOP TIM12 counter stopped when core is halted +// DBG_TIM7_STOP TIM7 counter stopped when core is halted +// DBG_TIM6_STOP TIM6 counter stopped when core is halted +// DBG_TIM5_STOP TIM5 counter stopped when core is halted +// DBG_TIM4_STOP TIM4 counter stopped when core is halted +// DBG_TIM3_STOP TIM3 counter stopped when core is halted +// DBG_TIM2_STOP TIM2 counter stopped when core is halted +// +DbgMCU_APB1_Fz = 0x00000000; + +// Debug MCU APB2 freeze register (DBGMCU_APB2_FZ) +// Reserved bits must be kept at reset value +// DBG_TIM11_STOP TIM11 counter stopped when core is halted +// DBG_TIM10_STOP TIM10 counter stopped when core is halted +// DBG_TIM9_STOP TIM9 counter stopped when core is halted +// DBG_TIM8_STOP TIM8 counter stopped when core is halted +// DBG_TIM1_STOP TIM1 counter stopped when core is halted +// +DbgMCU_APB2_Fz = 0x00000000; + +// <<< end of configuration section >>> \ No newline at end of file diff --git a/MDK-ARM/controller_pcba.uvprojx b/MDK-ARM/controller_pcba.uvprojx index ade6a97..c777a88 100644 --- a/MDK-ARM/controller_pcba.uvprojx +++ b/MDK-ARM/controller_pcba.uvprojx @@ -52,7 +52,7 @@ semi-finished_product_testing 1 0 - 1 + 0 1 0 diff --git a/Public/PCBA测试需求说明书 V1.1.docx b/Public/PCBA测试需求说明书 V1.1.docx index 766562f..c4d531f 100644 Binary files a/Public/PCBA测试需求说明书 V1.1.docx and b/Public/PCBA测试需求说明书 V1.1.docx differ diff --git a/Public/~$BA测试需求说明书 V1.1.docx b/Public/~$BA测试需求说明书 V1.1.docx index 06dbef6..6c0a742 100644 Binary files a/Public/~$BA测试需求说明书 V1.1.docx and b/Public/~$BA测试需求说明书 V1.1.docx differ diff --git a/Public/~WRL0082.tmp b/Public/~WRL0082.tmp new file mode 100644 index 0000000..d811b05 Binary files /dev/null and b/Public/~WRL0082.tmp differ diff --git a/User/application/src/tcpserverc.c b/User/application/src/tcpserverc.c index e76d803..62ef590 100644 --- a/User/application/src/tcpserverc.c +++ b/User/application/src/tcpserverc.c @@ -47,7 +47,85 @@ uint16_t data_len = 0; // 帧体长度 #define target_addr_h 0x0A // 目标地址高 #define target_addr_l 0x0B // 目标地址低 uint16_t reply_type = 0x00;// 报文类型_应答 - +uint8_t enable_data[7] = { + 0x03, // Byte 0: 蓝牙 + WIFI + 0x00, // Byte 1: 预留 + 0xFF, // Byte 2: 恒压输出 + 模拟输出(全使能) + 0x0F, // Byte 3: 电磁阀1-3 + IO扩展2 + 0x00, // Byte 4: 预留 + 0x00, // Byte 5: 预留 + 0x00 // Byte 6: 预留 +}; +uint8_t adc_read_data[22] = { + + 0x0C,0x80,// 恒压输出1高字节, 恒压输出1低字节, + 0x0C,0x80,// 恒压输出2高字节, 恒压输出2低字节, + 0x0C,0x80,// 模拟输出1高字节, 模拟输出1低字节, + 0x0C,0x80,// 模拟输出2高字节, 模拟输出2低字节, + 0x0C,0x80,// 模拟输出3高字节, 模拟输出3低字节, + 0x0C,0x80,// 模拟输出4高字节, 模拟输出4低字节, + 0x0C,0x80,// 模拟输出5高字节, 模拟输出5低字节, + 0x0C,0x80,// 模拟输出6高字节, 模拟输出6低字节, + 0x0C,0x80,// 输出目标设备4 - 20mA高字节, 输出目标设备4 - 20mA低字节, + 0x0C,0x80,// 比例阀1输出高字节, 比例阀1输出低字节, + 0x0C,0x80,// 比例阀2输出高字节, 比例阀2输出低字节 +}; +uint8_t adc_set_data[22] = { + + 0x0D,0xF0,// 恒压输出1高字节, 恒压输出1低字节, + 0x0D,0xF0,// 恒压输出2高字节, 恒压输出2低字节, + 0x0D,0xF0,// 模拟输出1高字节, 模拟输出1低字节, + 0x0D,0xF0,// 模拟输出2高字节, 模拟输出2低字节, + 0x0D,0xF0,// 模拟输出3高字节, 模拟输出3低字节, + 0x0D,0xF0,// 模拟输出4高字节, 模拟输出4低字节, + 0x0D,0xF0,// 模拟输出5高字节, 模拟输出5低字节, + 0x0D,0xF0,// 模拟输出6高字节, 模拟输出6低字节, + 0x0D,0xF0,// 输出目标设备4 - 20mA高字节, 输出目标设备4 - 20mA低字节, + 0x0D,0xF0,// 比例阀1输出高字节, 比例阀1输出低字节, + 0x0D,0xF0,// 比例阀2输出高字节, 比例阀2输出低字节 +}; +// 假设数据按高字节到低字节排列 +// 定义数组存放数据,总字节数根据表格计算为:2 + 4×18 = 74 字节 +uint8_t test_adc_read_data[74] = { + // IO扩展1高字节, IO扩展1低字节 + 0x12, 0x34, + // ADC(通道1)高字节1, ADC(通道1)高字节2, ADC(通道1)低字节1, ADC(通道1)低字节2 + 0x01, 0x02, 0x03, 0x04, + // ADC(通道2)高字节1, ADC(通道2)高字节2, ADC(通道2)低字节1, ADC(通道2)低字节2 + 0x05, 0x06, 0x07, 0x08, + // ADC(通道3)高字节1, ADC(通道3)高字节2, ADC(通道3)低字节1, ADC(通道3)低字节2 + 0x09, 0x0A, 0x0B, 0x0C, + // ADC(通道4)高字节1, ADC(通道4)高字节2, ADC(通道4)低字节1, ADC(通道4)低字节2 + 0x0D, 0x0E, 0x0F, 0x10, + // ADC(通道5)高字节1, ADC(通道5)高字节2, ADC(通道5)低字节1, ADC(通道5)低字节2 + 0x11, 0x12, 0x13, 0x14, + // ADC(通道6)高字节1, ADC(通道6)高字节2, ADC(通道6)低字节1, ADC(通道6)低字节2 + 0x15, 0x16, 0x17, 0x18, + // ADC(通道7)高字节1, ADC(通道7)高字节2, ADC(通道7)低字节1, ADC(通道7)低字节2 + 0x19, 0x1A, 0x1B, 0x1C, + // ADC(通道8)高字节1, ADC(通道8)高字节2, ADC(通道8)低字节1, ADC(通道8)低字节2 + 0x1D, 0x1E, 0x1F, 0x20, + // ADC(通道9)高字节1, ADC(通道9)高字节2, ADC(通道9)低字节1, ADC(通道9)低字节2 + 0x21, 0x22, 0x23, 0x24, + // ADC(通道10)高字节1, ADC(通道10)高字节2, ADC(通道10)低字节1, ADC(通道10)低字节2 + 0x25, 0x26, 0x27, 0x28, + // ADC(通道11)高字节1, ADC(通道11)高字节2, ADC(通道11)低字节1, ADC(通道11)低字节2 + 0x29, 0x2A, 0x2B, 0x2C, + // ADC(通道12)高字节1, ADC(通道12)高字节2, ADC(通道12)低字节1, ADC(通道12)低字节2 + 0x2D, 0x2E, 0x2F, 0x30, + // ADC(通道13)高字节1, ADC(通道13)高字节2, ADC(通道13)低字节1, ADC(通道13)低字节2 + 0x31, 0x32, 0x33, 0x34, + // ADC(通道14)高字节1, ADC(通道14)高字节2, ADC(通道14)低字节1, ADC(通道14)低字节2 + 0x35, 0x36, 0x37, 0x38, + // ADC(通道15)高字节1, ADC(通道15)高字节2, ADC(通道15)低字节1, ADC(通道15)低字节2 + 0x39, 0x3A, 0x3B, 0x3C, + // ADC(通道16)高字节1, ADC(通道16)高字节2, ADC(通道16)低字节1, ADC(通道16)低字节2 + 0x3D, 0x3E, 0x3F, 0x40, + // 比例阀1输入高字节1, 比例阀1输入高字节2, 比例阀1输入低字节1, 比例阀1输入低字节2 + 0x41, 0x42, 0x43, 0x44, + // 比例阀2输入高字节1, 比例阀2输入高字节2, 比例阀2输入低字节1, 比例阀2输入低字节2 + 0x45, 0x46, 0x47, 0x48 +}; // 校验和函数 uint8_t calc_checksum(const uint8_t *data, uint8_t start, uint8_t end) { uint8_t checksum = 0; @@ -154,6 +232,50 @@ uint16_t handle_type_82(const uint8_t *body, uint16_t body_len, uint8_t *tx) return total_len; } uint16_t handle_type_83(const uint8_t *body, uint16_t body_len, uint8_t *tx) +{ + // 检查 body_len 是否为7,如果不是则返回错误(可选) + if (body_len != 7) { + return 0; // 或返回错误码 + } + + uint16_t total_len = 2 + 2 + 2 + 2 + 1 + 7 + 2; // 帧头+帧长+源+目标+类型+7字节使能+校验 + + // 帧头 + tx[0] = head_00; + tx[1] = head_01; + + // 帧长度(大端) + tx[2] = (total_len >> 8) & 0xFF; + tx[3] = total_len & 0xFF; + + // 源地址 + tx[4] = source_addr_h; + tx[5] = source_addr_l; + + // 目标地址 + tx[6] = target_addr_h; + tx[7] = target_addr_l; + + // 报文类型 + tx[8] = reply_type; + + // 7字节使能状态(直接复制 body 到 tx[9]~tx[15]) + memcpy(&tx[9], body, 7); // 确保 body 是7字节 + + // 校验和(累加源地址到7字节使能数据) + uint16_t checksum = 0; + for (int i = 4; i < 16; ++i) // 4~15(源地址+目标地址+类型+7字节使能) + { + checksum += tx[i]; + } + + // 校验和2字节(大端,只取低8位) + tx[total_len - 2] = 0x00; // 高8位强制为0(如果协议要求) + tx[total_len - 1] = checksum & 0xFF; + + return total_len; +} +uint16_t handle_type_84(const uint8_t *body, uint16_t body_len, uint8_t *tx) { uint16_t total_len = 2 + 2 + 2 + 2 + 1 + body_len + 2; // 帧头+帧长+源+目标+类型+体+校验 // 帧头 @@ -171,8 +293,7 @@ uint16_t handle_type_83(const uint8_t *body, uint16_t body_len, uint8_t *tx) // 报文类型 tx[8] = reply_type; // 报文体 - tx[9] = 0x00;//7个字节表示的使能状态 - + memcpy(&tx[9], body, body_len);//发啥回啥 // 校验和(累加源地址到报文体) uint16_t checksum = 0; for (int i = 4; i < 9 + body_len; ++i) @@ -180,11 +301,129 @@ uint16_t handle_type_83(const uint8_t *body, uint16_t body_len, uint8_t *tx) checksum += tx[i]; } // 校验和2字节(大端) - //tx[total_len - 2] = (checksum >> 8) & 0xFF; - tx[total_len - 2] =0x00;//校验和只取低八位 + tx[total_len - 2] = 0x00;//校验和只取低八位 tx[total_len - 1] = checksum & 0xFF; return total_len; } +uint16_t handle_type_85(const uint8_t *body, uint16_t body_len, uint8_t *tx) +{ + + + uint16_t total_len = 2 + 2 + 2 + 2 + 1 + 22 + 2; // 帧头+帧长+源+目标+类型+22字节输出读取+校验 + + // 帧头 + tx[0] = head_00; + tx[1] = head_01; + + // 帧长度(大端) + tx[2] = (total_len >> 8) & 0xFF; + tx[3] = total_len & 0xFF; + + // 源地址 + tx[4] = source_addr_h; + tx[5] = source_addr_l; + + // 目标地址 + tx[6] = target_addr_h; + tx[7] = target_addr_l; + + // 报文类型 + tx[8] = reply_type; + + // 7字节使能状态(直接复制 body 到 tx[9]~tx[15]) + memcpy(&tx[9], body, 22); // 确保 body 是22字节 + + // 校验和 + uint16_t checksum = 0; + for (int i = 4; i < 32; ++i) // 4~32(源地址+目标地址+类型+22字节) + { + checksum += tx[i]; + } + + // 校验和2字节(大端,只取低8位) + tx[total_len - 2] = 0x00; // 高8位强制为0(如果协议要求) + tx[total_len - 1] = checksum & 0xFF; + + return total_len; +} +uint16_t handle_type_86(const uint8_t *body, uint16_t body_len, uint8_t *tx) +{ +uint16_t total_len = 2 + 2 + 2 + 2 + 1 + 22 + 2; // 帧头+帧长+源+目标+类型+22字节输出读取+校验 + + // 帧头 + tx[0] = head_00; + tx[1] = head_01; + + // 帧长度(大端) + tx[2] = (total_len >> 8) & 0xFF; + tx[3] = total_len & 0xFF; + + // 源地址 + tx[4] = source_addr_h; + tx[5] = source_addr_l; + + // 目标地址 + tx[6] = target_addr_h; + tx[7] = target_addr_l; + + // 报文类型 + tx[8] = reply_type; + + // 7字节使能状态(直接复制 body 到 tx[9]~tx[15]) + memcpy(&tx[9], body, 22); // 确保 body 是22字节 + + // 校验和 + uint16_t checksum = 0; + for (int i = 4; i < 32; ++i) // 4~31(源地址+目标地址+类型+22字节) + { + checksum += tx[i]; + } + + // 校验和2字节(大端,只取低8位) + tx[total_len - 2] = 0x00; // 高8位强制为0(如果协议要求) + tx[total_len - 1] = checksum & 0xFF; + + return total_len; +} +uint16_t handle_type_87(const uint8_t *body, uint16_t body_len, uint8_t *tx) +{ +uint16_t total_len = 2 + 2 + 2 + 2 + 1 + 74 + 2; // 帧头+帧长+源+目标+类型+74字节输出读取+校验 + + // 帧头 + tx[0] = head_00; + tx[1] = head_01; + + // 帧长度(大端) + tx[2] = (total_len >> 8) & 0xFF; + tx[3] = total_len & 0xFF; + + // 源地址 + tx[4] = source_addr_h; + tx[5] = source_addr_l; + + // 目标地址 + tx[6] = target_addr_h; + tx[7] = target_addr_l; + + // 报文类型 + tx[8] = reply_type; + + // 7字节使能状态(直接复制 body 到 tx[9]~tx[15]) + memcpy(&tx[9], body, 74); // 确保 body 是74字节 + + // 校验和 + uint16_t checksum = 0; + for (int i = 4; i < 84; ++i) // 4~83(源地址+目标地址+类型+74字节) + { + checksum += tx[i]; + } + + // 校验和2字节(大端,只取低8位) + tx[total_len - 2] = 0x00; // 高8位强制为0(如果协议要求) + tx[total_len - 1] = checksum & 0xFF; + + return total_len; +} /*接收回调函数*/ static err_t tcpecho_recv_hart1(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err) { // 对应接收数据连接的控制块 接收到的数据 @@ -342,23 +581,43 @@ static err_t tcpecho_recv_control(void *arg, struct tcp_pcb *tpcb, struct pbuf * } case 0x83://读取模块使能状态 { - + uint16_t body_len = 7; //7个字节表示的是各个模块的使能状态 + reply_type = tcp_rx_data[8]; + tx_data_len = handle_type_83(enable_data, body_len, tcp_tx_data); } break; - case 0x84://设置模块是能状态 - + case 0x84://设置模块使能状态 + { + uint16_t body_len = 7; //7个字节表示的是各个模块的使能状态 + reply_type = tcp_rx_data[8]; + tx_data_len = handle_type_84(tcp_rx_data + 9, body_len, tcp_tx_data); + } break; case 0x85://读取读取配置参数 - + { + uint16_t body_len = 22; //22个字节表示的是输出参数 + reply_type = tcp_rx_data[8]; + tx_data_len = handle_type_85(adc_read_data, body_len, tcp_tx_data); + } break; case 0x86://设置配置参数 - + { + uint16_t body_len = 22; //22个字节表示的是设置的参数 + reply_type = tcp_rx_data[8]; + tx_data_len = handle_type_86(adc_set_data, body_len, tcp_tx_data); + } break; case 0x87://读取测试数据 - + { + uint16_t body_len = 74; //22个字节表示的是设置的参数 + reply_type = tcp_rx_data[8]; + tx_data_len = handle_type_87(test_adc_read_data, body_len, tcp_tx_data); + } break; case 0x88://透传数据 - + { + + } break; default: