Browse Source

设置主动上报指令完成并测试通过

new_pcb
tianjialong 2 years ago
parent
commit
48b43a4933
  1. 4
      MDK-ARM/LWIP.uvguix.29643
  2. 55
      usersrc/udpclient.c

4
MDK-ARM/LWIP.uvguix.29643

@ -3642,9 +3642,9 @@
</Doc>
<Doc>
<Name>..\usersrc\protocol.h</Name>
<ColumnNumber>0</ColumnNumber>
<ColumnNumber>1</ColumnNumber>
<TopLine>8</TopLine>
<CurrentLine>31</CurrentLine>
<CurrentLine>21</CurrentLine>
<Folding>1</Folding>
<ContractedFolders></ContractedFolders>
<PaneID>0</PaneID>

55
usersrc/udpclient.c

@ -37,6 +37,7 @@ static bool genlock_and_esync_active_flag;
#define CLEAR_ENCODER_2 2
#define ORDER_RECEIPT_INTERCONVERSION 0X8000
#define ACTIVE_MIN_REPORT_CYCLE 50
static char s_sendBuf[BUFFER_SIZE]; //
static char s_receBuf[BUFFER_SIZE]; //
@ -124,7 +125,7 @@ static void udp_client_all_encoder_light_set(encoder_light_state_t state)
}
/* ===================================================================== */
/* 清除编码器数据指令回执 */
static void udp_client_clear_encoder_cmd_receipt(protocol_clear_encoder_order_t *order, protocol_status_code_type state_code)
{
protocol_clear_encoder_receipt_t receipt;
@ -138,6 +139,7 @@ static void udp_client_clear_encoder_cmd_receipt(protocol_clear_encoder_order_t
}
}
/* 读取编码器数据指令回执 */
static void udp_client_read_encoder_cmd_receipt(protocol_read_encoder_order_t *order)
{
protocol_read_encoder_receipt_t receipt;
@ -153,6 +155,21 @@ static void udp_client_read_encoder_cmd_receipt(protocol_read_encoder_order_t *o
}
}
/* 设置主动上报指令回执 */
static void udp_client_active_cmd_receipt(protocol_active_order_t *order, protocol_status_code_type state_code)
{
protocol_active_receipt_t receipt;
receipt.index = order->index;
receipt.cmd_id = order->cmd_id + ORDER_RECEIPT_INTERCONVERSION;
receipt.active_report_flag = order->active_report_flag;
receipt.report_cycle = order->report_cycle;
receipt.status_code = state_code;
receipt.checksum = computesum8((char *)&receipt, sizeof(protocol_active_receipt_t) - 1);
if (sendto(sock_Client, &receipt, sizeof(protocol_active_receipt_t), 0, (struct sockaddr *)&addr_server, sizeof(struct sockaddr_in)) == SOCKET_ERROR)
{
printf("send basic_response error\r\n");
}
}
/* ===================================================================== */
void udp_client_recv_data_dump(int recv_datalen)
@ -327,7 +344,7 @@ void udp_client_parse(int recv_datalen)
protocol_basic_t *protocol_basic_cmd = (protocol_basic_t *)s_receBuf;
protocol_clear_encoder_order_t *protocol_clear_encoder_cmd = (protocol_clear_encoder_order_t *)s_receBuf;
protocol_read_encoder_order_t *protocol_read_encoder_cmd = (protocol_read_encoder_order_t *)s_receBuf;
// protocol_active_order_t *protocol_active_cmd = (protocol_active_order_t *)s_receBuf;
protocol_active_order_t *protocol_active_cmd = (protocol_active_order_t *)s_receBuf;
// protocol_trigger_order_t *protocol_trigger_cmd = (protocol_trigger_order_t *)s_receBuf;
// protocol_modify_network_configurations_order_t *protocol_modify_network_configurations_cmd = (protocol_modify_network_configurations_order_t *)s_receBuf;
switch (protocol_basic_cmd->cmd_id)
@ -360,7 +377,39 @@ void udp_client_parse(int recv_datalen)
}
break;
case PROTOCOL_CMD_ACTIVE: /* 配置主动上报指令 */
cmd_checksum(protocol_active_cmd);
if (checksum_flag)
{
/* 校验通过 */
if ((protocol_active_cmd->active_report_flag == AVTIVE_DISABLE) || (protocol_active_cmd->active_report_flag == ACTIVE_ENABLE))
{
udp_client_active_flag = protocol_active_cmd->active_report_flag;
if (udp_client_active_flag)
{
udp_client_all_encoder_light_set(WORKING);
}
else
{
udp_client_all_encoder_light_set(STANDBY);
}
}
if (protocol_active_cmd->report_cycle >= ACTIVE_MIN_REPORT_CYCLE)
{
active_report_cycle = protocol_active_cmd->report_cycle;
}
else
{
active_report_cycle = ACTIVE_MIN_REPORT_CYCLE;
}
udp_client_active_cmd_receipt(protocol_active_cmd, PROTOCOL_STATUS_SUCCESS);
}
else
{
/* 校验未通过 */
udp_client_active_cmd_receipt(protocol_active_cmd, PROTOCOL_STATUS_PARAMETER_ERROR);
}
break;
case PROTOCOL_CMD_TRIGGER: /* 配置触发上报指令 */

Loading…
Cancel
Save