Signed-off-by: qiuxin <qiuxin@wuxismart.com>

This commit is contained in:
qiuxin 2025-05-08 20:08:13 +08:00
parent 49ab0b8447
commit 2639e18c9f
6 changed files with 320 additions and 13 deletions

View File

@ -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 >>>
// <h> Debug MCU configuration register (DBGMCU_CR)
// <o.2> DBG_STANDBY <i> Debug Standby Mode
// <o.1> DBG_STOP <i> Debug Stop Mode
// <o.0> DBG_SLEEP <i> Debug Sleep Mode
// </h>
DbgMCU_CR = 0x00000007;
// <h> Debug MCU APB1 freeze register (DBGMCU_APB1_FZ)
// <i> Reserved bits must be kept at reset value
// <o.26> DBG_CAN2_STOP <i> CAN2 stopped when core is halted
// <o.25> DBG_CAN1_STOP <i> CAN2 stopped when core is halted
// <o.23> DBG_I2C3_SMBUS_TIMEOUT <i> I2C3 SMBUS timeout mode stopped when core is halted
// <o.22> DBG_I2C2_SMBUS_TIMEOUT <i> I2C2 SMBUS timeout mode stopped when core is halted
// <o.21> DBG_I2C1_SMBUS_TIMEOUT <i> I2C1 SMBUS timeout mode stopped when core is halted
// <o.12> DBG_IWDG_STOP <i> Independent watchdog stopped when core is halted
// <o.11> DBG_WWDG_STOP <i> Window watchdog stopped when core is halted
// <o.10> DBG_RTC_STOP <i> RTC stopped when core is halted
// <o.8> DBG_TIM14_STOP <i> TIM14 counter stopped when core is halted
// <o.7> DBG_TIM13_STOP <i> TIM13 counter stopped when core is halted
// <o.6> DBG_TIM12_STOP <i> TIM12 counter stopped when core is halted
// <o.5> DBG_TIM7_STOP <i> TIM7 counter stopped when core is halted
// <o.4> DBG_TIM6_STOP <i> TIM6 counter stopped when core is halted
// <o.3> DBG_TIM5_STOP <i> TIM5 counter stopped when core is halted
// <o.2> DBG_TIM4_STOP <i> TIM4 counter stopped when core is halted
// <o.1> DBG_TIM3_STOP <i> TIM3 counter stopped when core is halted
// <o.0> DBG_TIM2_STOP <i> TIM2 counter stopped when core is halted
// </h>
DbgMCU_APB1_Fz = 0x00000000;
// <h> Debug MCU APB2 freeze register (DBGMCU_APB2_FZ)
// <i> Reserved bits must be kept at reset value
// <o.18> DBG_TIM11_STOP <i> TIM11 counter stopped when core is halted
// <o.17> DBG_TIM10_STOP <i> TIM10 counter stopped when core is halted
// <o.16> DBG_TIM9_STOP <i> TIM9 counter stopped when core is halted
// <o.1> DBG_TIM8_STOP <i> TIM8 counter stopped when core is halted
// <o.0> DBG_TIM1_STOP <i> TIM1 counter stopped when core is halted
// </h>
DbgMCU_APB2_Fz = 0x00000000;
// <<< end of configuration section >>>

View File

@ -52,7 +52,7 @@
<OutputName>semi-finished_product_testing</OutputName>
<CreateExecutable>1</CreateExecutable>
<CreateLib>0</CreateLib>
<CreateHexFile>1</CreateHexFile>
<CreateHexFile>0</CreateHexFile>
<DebugInformation>1</DebugInformation>
<BrowseInformation>0</BrowseInformation>
<ListingPath></ListingPath>

BIN
Public/~WRL0082.tmp Normal file

Binary file not shown.

View File

@ -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: