修改87指令,新增IO扩展读取16-31
This commit is contained in:
parent
beae8c556b
commit
2fde000d3a
|
@ -8,8 +8,10 @@
|
|||
#include "lwip/pbuf.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "stm32f4xx_hal.h"
|
||||
#include "usart.h"
|
||||
#include "main.h"
|
||||
#include "gpio.h"
|
||||
#include "ht1200m.h"
|
||||
#include "user_lib.h"
|
||||
#include "communication_protocol.h"
|
||||
|
@ -48,6 +50,14 @@ extern uint8_t uart_echo_flags_hart2;
|
|||
extern uint8_t uart_echo_flags_ble1;
|
||||
extern uint8_t uart_echo_flags_ble2;
|
||||
|
||||
// 添加TCA6416状态变量的外部声明
|
||||
extern volatile uint8_t tca6416_port0_status; // 第一个TCA6416的Port0状态
|
||||
extern volatile uint8_t tca6416_port1_status; // 第一个TCA6416的Port1状态
|
||||
extern volatile uint8_t tca6416_port2_status; // 第二个TCA6416的Port0状态
|
||||
extern volatile uint8_t tca6416_port3_status; // 第二个TCA6416的Port1状态
|
||||
extern volatile uint8_t tca6416_port4_status; // 第三个TCA6416的Port0状态
|
||||
extern volatile uint8_t tca6416_port5_status; // 第三个TCA6416的Port1状态
|
||||
|
||||
#define head_00 0xD5 // 帧头1
|
||||
#define head_01 0xC8 // 帧头2
|
||||
uint16_t data_len = 0; // 帧体长度
|
||||
|
@ -378,7 +388,7 @@ uint16_t total_len = 2 + 2 + 2 + 2 + 1 + 22 + 2; // 帧头+帧长+源+目标+类
|
|||
}
|
||||
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字节输出读取+校验
|
||||
uint16_t total_len = 2 + 2 + 2 + 2 + 1 + 76 + 2; // 帧头+帧长+源+目标+类型+76字节输出读取+校验 = 87字节
|
||||
|
||||
// 帧头
|
||||
tx[0] = head_00;
|
||||
|
@ -399,30 +409,32 @@ uint16_t handle_type_87(const uint8_t *body, uint16_t body_len, uint8_t *tx)
|
|||
// 报文类型
|
||||
tx[8] = reply_type;
|
||||
|
||||
// 填充地址为0x21的TCA6416芯片状态到第9-10字节
|
||||
// tx[9] = tca6416_port2_status; // 第二个TCA6416的Port0状态(地址0x21)外部端口8-15
|
||||
// tx[10] = tca6416_port3_status; // 第二个TCA6416的Port1状态(地址0x21)外部端口0-7
|
||||
// 填充第二个TCA6416芯片状态到第9-10字节(地址0x21)
|
||||
tx[9] = tca6416_port3_status; // 第二个TCA6416的Port0状态(地址0x21)外部端口0-7
|
||||
tx[10] = tca6416_port2_status; // 第二个TCA6416的Port1状态(地址0x21)外部端口8-15
|
||||
|
||||
// 填充AD7124原始数据到tx[11]~tx[75],每通道4字节,MSB格式
|
||||
// 填充第三个TCA6416芯片状态到第11-12字节(地址0x20,第二条总线)
|
||||
tx[11] = tca6416_port5_status; // 第三个TCA6416的Port0状态(地址0x20)外部端口0-7
|
||||
tx[12] = tca6416_port4_status; // 第三个TCA6416的Port1状态(地址0x20)外部端口8-15
|
||||
|
||||
// 填充AD7124原始数据到tx[13]~tx[76],每通道4字节,MSB格式
|
||||
extern ad7124_analog_t ad7124_analog[AD7124_CHANNEL_EN_MAX];
|
||||
for (int ch = 0; ch < AD7124_CHANNEL_EN_MAX; ++ch) {
|
||||
int32_t data = ad7124_analog[ch].data;
|
||||
tx[11 + ch * 4 + 0] = (data >> 24) & 0xFF;
|
||||
tx[11 + ch * 4 + 1] = (data >> 16) & 0xFF;
|
||||
tx[11 + ch * 4 + 2] = (data >> 8) & 0xFF;
|
||||
tx[11 + ch * 4 + 3] = (data) & 0xFF;
|
||||
tx[13 + ch * 4 + 0] = (data >> 24) & 0xFF;
|
||||
tx[13 + ch * 4 + 1] = (data >> 16) & 0xFF;
|
||||
tx[13 + ch * 4 + 2] = (data >> 8) & 0xFF;
|
||||
tx[13 + ch * 4 + 3] = (data) & 0xFF;
|
||||
}
|
||||
|
||||
// 其余tx[75]~tx[81]可按需要填充(如比例阀等),此处保持原样或补零
|
||||
for (int i = 11 + AD7124_CHANNEL_EN_MAX * 4; i < 81; ++i) {
|
||||
// 其余tx[77]~tx[84]可按需要填充(如比例阀等),此处保持原样或补零
|
||||
for (int i = 13 + AD7124_CHANNEL_EN_MAX * 4; i < 85; ++i) {
|
||||
tx[i] = 0;
|
||||
}
|
||||
|
||||
// 校验和
|
||||
// 校验和(从源地址到数据结束)
|
||||
uint16_t checksum = 0;
|
||||
for (int i = 4; i < 82; ++i) // 4~81(源地址+目标地址+类型+72字节)
|
||||
for (int i = 4; i < 85; ++i) // 4~84(源地址+目标地址+类型+76字节数据)
|
||||
{
|
||||
checksum += tx[i];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue