|
|
@ -16,9 +16,6 @@ |
|
|
|
checksum_flag = false; \ |
|
|
|
} |
|
|
|
|
|
|
|
static bool udp_client_active_flag; |
|
|
|
static bool genlock_and_esync_active_flag; |
|
|
|
|
|
|
|
/* 定义端口号 */ |
|
|
|
#define UDP_REMOTE_PORT 8881 /* 远端端口 */ |
|
|
|
#define UDP_LOCAL_PORT 8880 /* 本地端口 */ |
|
|
@ -33,6 +30,9 @@ static bool genlock_and_esync_active_flag; |
|
|
|
#define AVTIVE_DISABLE 0 |
|
|
|
#define ACTIVE_ENABLE 1 |
|
|
|
|
|
|
|
#define TRIGGER_MOD_CLOSE 0 |
|
|
|
#define TRIGGER_MOD_GENLOCK_OPEN 1 |
|
|
|
|
|
|
|
#define CLEAR_ENCODER_ALL 0 |
|
|
|
#define CLEAR_ENCODER_1 1 |
|
|
|
#define CLEAR_ENCODER_2 2 |
|
|
@ -40,6 +40,10 @@ static bool genlock_and_esync_active_flag; |
|
|
|
#define ORDER_RECEIPT_INTERCONVERSION 0X8000 |
|
|
|
#define ACTIVE_MIN_REPORT_CYCLE 50 |
|
|
|
|
|
|
|
static bool udp_client_active_flag; |
|
|
|
static bool genlock_and_esync_active_flag; |
|
|
|
static uint16_t s_trigger_mode; |
|
|
|
|
|
|
|
static char s_sendBuf[BUFFER_SIZE]; // 发送数据的缓冲区 |
|
|
|
static char s_receBuf[BUFFER_SIZE]; // 接收数据的缓冲区 |
|
|
|
|
|
|
@ -50,6 +54,7 @@ static struct sockaddr_in sock; |
|
|
|
socklen_t sock_len = sizeof(sock); |
|
|
|
|
|
|
|
static protocol_active_and_trigger_report_t active_report_data_structer; |
|
|
|
static protocol_active_and_trigger_report_t trigger_report_data_structer; |
|
|
|
static int active_report_cycle; |
|
|
|
|
|
|
|
static void udp_client_all_encoder_light_set(encoder_light_state_t state) |
|
|
@ -78,11 +83,29 @@ static void active_report_data_structer_init(void) |
|
|
|
active_report_data_structer.encoder2 = 0; |
|
|
|
} |
|
|
|
|
|
|
|
static void trigger_report_data_structer_init(void) |
|
|
|
{ |
|
|
|
/* index在每次上报一次主动上报数据后+1,时间戳在获取ESync命令时更新,编码器数值在 active_report_data_structer_update中更新,校验和在上传数据前(udp_client_active_response)进行更新*/ |
|
|
|
trigger_report_data_structer.index = 0; /* */ |
|
|
|
trigger_report_data_structer.cmd_id = TRIGGER_ID; /* 指令id */ |
|
|
|
trigger_report_data_structer.placeholder_1 = 0; |
|
|
|
trigger_report_data_structer.placeholder_2 = 0; |
|
|
|
trigger_report_data_structer.encoder1 = 0; |
|
|
|
trigger_report_data_structer.encoder2 = 0; |
|
|
|
} |
|
|
|
|
|
|
|
static void active_report_data_structer_update(void) |
|
|
|
{ |
|
|
|
/* 时间戳暂时先不管,后续完善 */ |
|
|
|
encoder_read_with_encoder(CAMERA_ENCODER, &active_report_data_structer.encoder1); |
|
|
|
encoder_read_with_encoder(DRIVEN_ENCODER_GEAR, &active_report_data_structer.placeholder_2); |
|
|
|
encoder_read_with_encoder(DRIVEN_ENCODER_GEAR, &active_report_data_structer.encoder2); |
|
|
|
} |
|
|
|
|
|
|
|
static void trigger_report_data_structer_update(void) |
|
|
|
{ |
|
|
|
/* 时间戳暂时先不管,后续完善 */ |
|
|
|
encoder_read_with_encoder(CAMERA_ENCODER, &trigger_report_data_structer.encoder1); |
|
|
|
encoder_read_with_encoder(DRIVEN_ENCODER_GEAR, &trigger_report_data_structer.encoder2); |
|
|
|
} |
|
|
|
|
|
|
|
/* 主动上报格式 */ |
|
|
@ -95,6 +118,16 @@ static void udp_client_active_report(void) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/* 触发上报格式 */ |
|
|
|
static void udp_client_trigger_report(void) |
|
|
|
{ |
|
|
|
trigger_report_data_structer.checksum = computesum8((char *)&trigger_report_data_structer, sizeof(protocol_active_and_trigger_report_t) - 1); |
|
|
|
if (sendto(sock_Client, &trigger_report_data_structer, sizeof(protocol_active_and_trigger_report_t), 0, (struct sockaddr *)&addr_server, sizeof(struct sockaddr_in)) == SOCKET_ERROR) |
|
|
|
{ |
|
|
|
printf("send basic_response error\r\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/* 清除编码器数据指令回执 */ |
|
|
|
static void udp_client_clear_encoder_cmd_receipt(protocol_clear_encoder_order_t *order, protocol_status_code_type state_code) |
|
|
|
{ |
|
|
@ -117,7 +150,7 @@ static void udp_client_read_encoder_cmd_receipt(protocol_read_encoder_order_t *o |
|
|
|
receipt.cmd_id = order->cmd_id + ORDER_RECEIPT_INTERCONVERSION; |
|
|
|
active_report_data_structer_update(); |
|
|
|
receipt.encoder1 = active_report_data_structer.encoder1; |
|
|
|
receipt.encoder2 = active_report_data_structer.placeholder_2; |
|
|
|
receipt.encoder2 = active_report_data_structer.encoder2; |
|
|
|
receipt.checksum = computesum8((char *)&receipt, sizeof(protocol_read_encoder_receipt_t) - 1); |
|
|
|
if (sendto(sock_Client, &receipt, sizeof(protocol_read_encoder_receipt_t), 0, (struct sockaddr *)&addr_server, sizeof(struct sockaddr_in)) == SOCKET_ERROR) |
|
|
|
{ |
|
|
@ -140,6 +173,21 @@ static void udp_client_active_cmd_receipt(protocol_active_order_t *order, protoc |
|
|
|
printf("send basic_response error\r\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/* 设置触发上报指令回执 */ |
|
|
|
static void udp_client_trigger_cmd_receipt(protocol_trigger_order_t *order, protocol_status_code_type state_code) |
|
|
|
{ |
|
|
|
protocol_trigger_receipt_t receipt; |
|
|
|
receipt.index = order->index; |
|
|
|
receipt.cmd_id = order->cmd_id + ORDER_RECEIPT_INTERCONVERSION; |
|
|
|
receipt.trigger_mode = order->trigger_mode; |
|
|
|
receipt.status_code = state_code; |
|
|
|
receipt.checksum = computesum8((char *)&receipt, sizeof(protocol_trigger_receipt_t) - 1); |
|
|
|
if (sendto(sock_Client, &receipt, sizeof(protocol_trigger_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) |
|
|
@ -178,7 +226,7 @@ void udp_client_send_string(char *pData) |
|
|
|
void udp_client_init(void) |
|
|
|
{ |
|
|
|
active_report_data_structer_init(); |
|
|
|
active_report_cycle = 1000; /* 上报周期开始设置默认为1S */ |
|
|
|
trigger_report_data_structer_init(); |
|
|
|
|
|
|
|
// bool bOpt = true; |
|
|
|
struct timeval tv = {0, 1000}; |
|
|
@ -240,9 +288,10 @@ void udp_client_parse(int recv_datalen) |
|
|
|
bool checksum_flag = true; |
|
|
|
if (recv_datalen >= adwin_config_protocol_size) |
|
|
|
{ |
|
|
|
/* 时码相关逻辑暂时不处理 */ |
|
|
|
// adwin_config_protocol_t *rxcmd = (adwin_config_protocol_t *)s_receBuf; |
|
|
|
// active_report_data_structer.time_stamp_s = rxcmd->time_stamp_s; |
|
|
|
genlock_and_esync_active_flag = true; |
|
|
|
// genlock_and_esync_active_flag = true; |
|
|
|
} |
|
|
|
else if (recv_datalen >= protocol_basic_size) |
|
|
|
{ |
|
|
@ -250,7 +299,7 @@ void udp_client_parse(int recv_datalen) |
|
|
|
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_trigger_order_t *protocol_trigger_cmd = (protocol_trigger_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) |
|
|
|
{ |
|
|
@ -317,7 +366,21 @@ void udp_client_parse(int recv_datalen) |
|
|
|
} |
|
|
|
break; |
|
|
|
case PROTOCOL_CMD_TRIGGER: /* 配置触发上报指令 */ |
|
|
|
|
|
|
|
cmd_checksum(protocol_trigger_cmd); |
|
|
|
if (checksum_flag) |
|
|
|
{ |
|
|
|
/* 校验通过 */ |
|
|
|
if ((protocol_trigger_cmd->trigger_mode == TRIGGER_MOD_CLOSE) || (protocol_trigger_cmd->trigger_mode == TRIGGER_MOD_GENLOCK_OPEN)) |
|
|
|
{ |
|
|
|
s_trigger_mode = protocol_trigger_cmd->trigger_mode; |
|
|
|
} |
|
|
|
udp_client_trigger_cmd_receipt(protocol_trigger_cmd, PROTOCOL_STATUS_SUCCESS); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
/* 校验未通过 */ |
|
|
|
udp_client_trigger_cmd_receipt(protocol_trigger_cmd, PROTOCOL_STATUS_PARAMETER_ERROR); |
|
|
|
} |
|
|
|
break; |
|
|
|
case PROTOCOL_CMD_MODIFY_NETWORK_CONFIGURATIONS: /* 配置网络相关指令 */ |
|
|
|
|
|
|
@ -350,19 +413,22 @@ void udp_client_active(void) |
|
|
|
|
|
|
|
void udp_client_genlock_and_esync_active(void) |
|
|
|
{ |
|
|
|
if (genlock_and_esync_active_flag) |
|
|
|
if (s_trigger_mode == TRIGGER_MOD_GENLOCK_OPEN) |
|
|
|
{ |
|
|
|
active_report_data_structer_update(); |
|
|
|
udp_client_active_report(); |
|
|
|
|
|
|
|
if (!udp_client_active_flag) |
|
|
|
if (genlock_and_esync_active_flag) |
|
|
|
{ |
|
|
|
udp_client_all_encoder_light_set(STANDBY); |
|
|
|
} |
|
|
|
trigger_report_data_structer_update(); |
|
|
|
udp_client_trigger_report(); |
|
|
|
|
|
|
|
active_report_data_structer.index += 1; |
|
|
|
// active_report_data_structer.time_stamp_s = 0; |
|
|
|
genlock_and_esync_active_flag = false; |
|
|
|
if (!udp_client_active_flag) |
|
|
|
{ |
|
|
|
udp_client_all_encoder_light_set(STANDBY); |
|
|
|
} |
|
|
|
|
|
|
|
trigger_report_data_structer.index += 1; |
|
|
|
// active_report_data_structer.time_stamp_s = 0; |
|
|
|
genlock_and_esync_active_flag = false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|