连续上发三次状态
This commit is contained in:
parent
bd55a7ca61
commit
51d15c1977
|
@ -46,6 +46,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;
|
||||
#define ARRAY_LEN(arr) (sizeof(arr)) / (sizeof(arr[0]))
|
||||
typedef struct
|
||||
{
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
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)
|
||||
|
@ -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