连续上发三次状态
This commit is contained in:
parent
bd55a7ca61
commit
51d15c1977
|
@ -37,30 +37,31 @@ extern "C"
|
|||
#include "tcpserverc.h"
|
||||
#include "leds.h"
|
||||
#include <string.h>
|
||||
/* USER CODE END Includes */
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN ET */
|
||||
extern uint8_t tcp_echo_flags_hart1;
|
||||
extern uint8_t tcp_echo_flags_hart2;
|
||||
extern uint8_t tcp_echo_flags_ble1;
|
||||
extern uint8_t tcp_echo_flags_ble2;
|
||||
extern uint8_t tcp_echo_flags_control;
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN ET */
|
||||
extern uint8_t tcp_echo_flags_hart1;
|
||||
extern uint8_t tcp_echo_flags_hart2;
|
||||
extern uint8_t tcp_echo_flags_ble1;
|
||||
extern uint8_t tcp_echo_flags_ble2;
|
||||
extern uint8_t tcp_echo_flags_control;
|
||||
extern uint8_t send_data_flag_cmd;
|
||||
#define ARRAY_LEN(arr) (sizeof(arr)) / (sizeof(arr[0]))
|
||||
typedef struct
|
||||
{
|
||||
uint16_t rx_num;
|
||||
uint8_t rx_data[512];
|
||||
uint8_t rx_data_temp[512];
|
||||
uint8_t tx_data[512];
|
||||
} uart_t;
|
||||
typedef struct
|
||||
{
|
||||
uint16_t rx_num;
|
||||
uint8_t rx_data[512];
|
||||
uint8_t rx_data_temp[512];
|
||||
uint8_t tx_data[512];
|
||||
} uart_t;
|
||||
|
||||
extern uart_t lcd_uart4;
|
||||
extern uart_t ble2_uart3;
|
||||
extern uart_t ble1_uart6;
|
||||
extern uart_t hart1_uart5;
|
||||
extern uart_t hart2_uart2;
|
||||
extern uart_t usb_uart1;
|
||||
extern uart_t lcd_uart4;
|
||||
extern uart_t ble2_uart3;
|
||||
extern uart_t ble1_uart6;
|
||||
extern uart_t hart1_uart5;
|
||||
extern uart_t hart2_uart2;
|
||||
extern uart_t usb_uart1;
|
||||
#define DEST_IP_ADDR0 192
|
||||
#define DEST_IP_ADDR1 168
|
||||
#define DEST_IP_ADDR2 1
|
||||
|
|
|
@ -64,6 +64,7 @@ osThreadId ec11_taskHandle;
|
|||
/* USER CODE BEGIN FunctionPrototypes */
|
||||
extern float current_buff[2];
|
||||
extern uint8_t tcp_echo_flags_control;
|
||||
extern uint8_t send_data_flag_cmd;
|
||||
int direction = 0;
|
||||
int encode_num = 0;
|
||||
uint8_t di_state_last[DI_MAX] = {0};
|
||||
|
@ -264,7 +265,7 @@ void start_gpio_di_do_task(void const *argument)
|
|||
/* Infinite loop */
|
||||
for (;;)
|
||||
{
|
||||
uint8_t di_flag = 0;
|
||||
|
||||
uint8_t di_ch = 0;
|
||||
uint8_t tx_data_len = 7 + DI_MAX;
|
||||
uint8_t tx_data[32] = {0};
|
||||
|
@ -279,18 +280,22 @@ void start_gpio_di_do_task(void const *argument)
|
|||
if (di_state_last[di_ch] != di_state_now[di_ch])
|
||||
{
|
||||
di_state_last[di_ch] = di_state_now[di_ch];
|
||||
di_flag = 1;
|
||||
send_data_flag_cmd = 1;
|
||||
}
|
||||
tx_data[5 + di_ch] = di_state_now[di_ch];
|
||||
tx_data[5 + di_ch] = di_state_now[di_ch];
|
||||
}
|
||||
if ((1 == di_flag) && (1 == tcp_echo_flags_control))
|
||||
if ((send_data_flag_cmd != 0) && (1 == tcp_echo_flags_control))
|
||||
{
|
||||
tx_data[5 + DI_MAX] = xor_compute(tx_data + 1, tx_data_len - 3); // 异或校验
|
||||
tx_data[6 + DI_MAX] = FRAME_TAIL; // 帧尾
|
||||
user_send_data_control(tx_data, tx_data_len);
|
||||
di_flag = 0;
|
||||
send_data_flag_cmd++;
|
||||
if (send_data_flag_cmd > 3) // 连续三次上位机没有回应,则停止发送数据包
|
||||
{
|
||||
send_data_flag_cmd = 0;
|
||||
}
|
||||
}
|
||||
vTaskDelay(10);
|
||||
vTaskDelay(100);
|
||||
}
|
||||
/* USER CODE END start_gpio_di_do_task */
|
||||
}
|
||||
|
|
|
@ -78,6 +78,7 @@ uint8_t tcp_echo_flags_hart2 = 0;
|
|||
uint8_t tcp_echo_flags_ble1 = 0;
|
||||
uint8_t tcp_echo_flags_ble2 = 0;
|
||||
uint8_t tcp_echo_flags_control = 0;
|
||||
uint8_t send_data_flag_cmd = 0;
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/**
|
||||
|
|
|
@ -215,6 +215,16 @@
|
|||
<WinNumber>1</WinNumber>
|
||||
<ItemText>di_state_last</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>13</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>di_state_now</ItemText>
|
||||
</Ww>
|
||||
<Ww>
|
||||
<count>14</count>
|
||||
<WinNumber>1</WinNumber>
|
||||
<ItemText>tcp_echo_flags_control</ItemText>
|
||||
</Ww>
|
||||
</WatchWindow1>
|
||||
<Tracepoint>
|
||||
<THDelay>0</THDelay>
|
||||
|
|
|
@ -31,6 +31,7 @@ extern uint8_t tcp_echo_flags_hart2;
|
|||
extern uint8_t tcp_echo_flags_ble1;
|
||||
extern uint8_t tcp_echo_flags_ble2;
|
||||
extern uint8_t tcp_echo_flags_control;
|
||||
extern uint8_t send_data_flag_cmd;
|
||||
|
||||
/*接收回调函数*/
|
||||
static err_t tcpecho_recv_hart1(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
|
||||
|
@ -171,7 +172,7 @@ static err_t tcpecho_recv_control(void *arg, struct tcp_pcb *tpcb, struct pbuf *
|
|||
else if (tcp_rx_data[3] == WRITE_ANALOG_CMD) // 写模拟量指令
|
||||
{
|
||||
/*写操作,将数据写入寄存器,组包返回*/
|
||||
|
||||
|
||||
user_communication_ao = &communication_data.ao_data;
|
||||
communication_set_ao(user_communication_ao);
|
||||
tcp_write(tpcb, tcp_rx_data, rx_data_len, 1);
|
||||
|
@ -192,6 +193,10 @@ static err_t tcpecho_recv_control(void *arg, struct tcp_pcb *tpcb, struct pbuf *
|
|||
user_write_gpio(user_communication_do);
|
||||
tcp_write(tpcb, tcp_rx_data, rx_data_len, 1);
|
||||
}
|
||||
else if (tcp_rx_data[3] == SEND_STATE_CMD)
|
||||
{
|
||||
send_data_flag_cmd = 0; // 上位机返回数据,发送状态标志位清零
|
||||
}
|
||||
else
|
||||
{
|
||||
// 返回命令号错误
|
||||
|
|
Loading…
Reference in New Issue