连续上发三次状态
This commit is contained in:
parent
bd55a7ca61
commit
51d15c1977
|
@ -37,30 +37,31 @@ extern "C"
|
||||||
#include "tcpserverc.h"
|
#include "tcpserverc.h"
|
||||||
#include "leds.h"
|
#include "leds.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
/* USER CODE END Includes */
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
/* Exported types ------------------------------------------------------------*/
|
/* Exported types ------------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN ET */
|
/* USER CODE BEGIN ET */
|
||||||
extern uint8_t tcp_echo_flags_hart1;
|
extern uint8_t tcp_echo_flags_hart1;
|
||||||
extern uint8_t tcp_echo_flags_hart2;
|
extern uint8_t tcp_echo_flags_hart2;
|
||||||
extern uint8_t tcp_echo_flags_ble1;
|
extern uint8_t tcp_echo_flags_ble1;
|
||||||
extern uint8_t tcp_echo_flags_ble2;
|
extern uint8_t tcp_echo_flags_ble2;
|
||||||
extern uint8_t tcp_echo_flags_control;
|
extern uint8_t tcp_echo_flags_control;
|
||||||
|
extern uint8_t send_data_flag_cmd;
|
||||||
#define ARRAY_LEN(arr) (sizeof(arr)) / (sizeof(arr[0]))
|
#define ARRAY_LEN(arr) (sizeof(arr)) / (sizeof(arr[0]))
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint16_t rx_num;
|
uint16_t rx_num;
|
||||||
uint8_t rx_data[512];
|
uint8_t rx_data[512];
|
||||||
uint8_t rx_data_temp[512];
|
uint8_t rx_data_temp[512];
|
||||||
uint8_t tx_data[512];
|
uint8_t tx_data[512];
|
||||||
} uart_t;
|
} uart_t;
|
||||||
|
|
||||||
extern uart_t lcd_uart4;
|
extern uart_t lcd_uart4;
|
||||||
extern uart_t ble2_uart3;
|
extern uart_t ble2_uart3;
|
||||||
extern uart_t ble1_uart6;
|
extern uart_t ble1_uart6;
|
||||||
extern uart_t hart1_uart5;
|
extern uart_t hart1_uart5;
|
||||||
extern uart_t hart2_uart2;
|
extern uart_t hart2_uart2;
|
||||||
extern uart_t usb_uart1;
|
extern uart_t usb_uart1;
|
||||||
#define DEST_IP_ADDR0 192
|
#define DEST_IP_ADDR0 192
|
||||||
#define DEST_IP_ADDR1 168
|
#define DEST_IP_ADDR1 168
|
||||||
#define DEST_IP_ADDR2 1
|
#define DEST_IP_ADDR2 1
|
||||||
|
|
|
@ -64,6 +64,7 @@ osThreadId ec11_taskHandle;
|
||||||
/* USER CODE BEGIN FunctionPrototypes */
|
/* USER CODE BEGIN FunctionPrototypes */
|
||||||
extern float current_buff[2];
|
extern float current_buff[2];
|
||||||
extern uint8_t tcp_echo_flags_control;
|
extern uint8_t tcp_echo_flags_control;
|
||||||
|
extern uint8_t send_data_flag_cmd;
|
||||||
int direction = 0;
|
int direction = 0;
|
||||||
int encode_num = 0;
|
int encode_num = 0;
|
||||||
uint8_t di_state_last[DI_MAX] = {0};
|
uint8_t di_state_last[DI_MAX] = {0};
|
||||||
|
@ -264,7 +265,7 @@ void start_gpio_di_do_task(void const *argument)
|
||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
uint8_t di_flag = 0;
|
|
||||||
uint8_t di_ch = 0;
|
uint8_t di_ch = 0;
|
||||||
uint8_t tx_data_len = 7 + DI_MAX;
|
uint8_t tx_data_len = 7 + DI_MAX;
|
||||||
uint8_t tx_data[32] = {0};
|
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])
|
if (di_state_last[di_ch] != di_state_now[di_ch])
|
||||||
{
|
{
|
||||||
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[5 + DI_MAX] = xor_compute(tx_data + 1, tx_data_len - 3); // 异或校验
|
||||||
tx_data[6 + DI_MAX] = FRAME_TAIL; // 帧尾
|
tx_data[6 + DI_MAX] = FRAME_TAIL; // 帧尾
|
||||||
user_send_data_control(tx_data, tx_data_len);
|
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 */
|
/* 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_ble1 = 0;
|
||||||
uint8_t tcp_echo_flags_ble2 = 0;
|
uint8_t tcp_echo_flags_ble2 = 0;
|
||||||
uint8_t tcp_echo_flags_control = 0;
|
uint8_t tcp_echo_flags_control = 0;
|
||||||
|
uint8_t send_data_flag_cmd = 0;
|
||||||
/* USER CODE END 0 */
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -215,6 +215,16 @@
|
||||||
<WinNumber>1</WinNumber>
|
<WinNumber>1</WinNumber>
|
||||||
<ItemText>di_state_last</ItemText>
|
<ItemText>di_state_last</ItemText>
|
||||||
</Ww>
|
</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>
|
</WatchWindow1>
|
||||||
<Tracepoint>
|
<Tracepoint>
|
||||||
<THDelay>0</THDelay>
|
<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_ble1;
|
||||||
extern uint8_t tcp_echo_flags_ble2;
|
extern uint8_t tcp_echo_flags_ble2;
|
||||||
extern uint8_t tcp_echo_flags_control;
|
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)
|
static err_t tcpecho_recv_hart1(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
|
||||||
|
@ -192,6 +193,10 @@ static err_t tcpecho_recv_control(void *arg, struct tcp_pcb *tpcb, struct pbuf *
|
||||||
user_write_gpio(user_communication_do);
|
user_write_gpio(user_communication_do);
|
||||||
tcp_write(tpcb, tcp_rx_data, rx_data_len, 1);
|
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
|
else
|
||||||
{
|
{
|
||||||
// 返回命令号错误
|
// 返回命令号错误
|
||||||
|
|
Loading…
Reference in New Issue