|
|
@ -10,21 +10,47 @@ |
|
|
#include "udp.h" |
|
|
#include "udp.h" |
|
|
#include "string.h" |
|
|
#include "string.h" |
|
|
#include "bsp_UDP.h" |
|
|
#include "bsp_UDP.h" |
|
|
|
|
|
#include "bsp_DLT_Log.h" |
|
|
|
|
|
#include <bsp_UpperComputer_Handler.h> |
|
|
|
|
|
#include "bsp_GPIO.h" |
|
|
|
|
|
void UDP_GV_Dispatch(); |
|
|
|
|
|
void UDP_IV_Dispatch(); |
|
|
|
|
|
void udp_cmd_send_GV(char *pData, uint16_t Size); |
|
|
/* 定义端口号 */ |
|
|
/* 定义端口号 */ |
|
|
#define UDP_REMOTE_PORT 8881 /* 远端端口 */ |
|
|
#define UDP_DLT_LOCAL_PORT 8000 /* 本地端口 */ |
|
|
#define UDP_LOCAL_PORT 8880 /* 本地端口 */ |
|
|
#define UDP_CMD_LOCAL_PORT 8002 /* 本地端口 */ |
|
|
#define UDP_Send_LOCAL_PORT 9880 /* 本地端口 */ |
|
|
#define UDP_CMD_LOCAL_Android_Listen_PORT 8006 /* 本地端口 接收安卓 */ |
|
|
|
|
|
|
|
|
|
|
|
#define UDP_DLT_Send_LOCAL_PORT 7000 /* 本地端口 */ |
|
|
|
|
|
#define UDP_CMD_Send_LOCAL_PORT 7002 /* 本地端口 */ |
|
|
|
|
|
#define UDP_GV_Send_LOCAL_PORT 7004 /* 本地端口 */ |
|
|
|
|
|
#define UDP_Android_Send_LOCAL_PORT 7006 /* 本地端口 发给安卓*/ |
|
|
|
|
|
/*32从7006发往安卓9006*/ |
|
|
|
|
|
/*安卓从9006发往32的8006*/ |
|
|
|
|
|
#define UDP_REMOTE_DLT_PORT 9000 /* 远端端口 */ |
|
|
|
|
|
#define UDP_REMOTE_CMD_PORT 9002 /* 远端端口 */ |
|
|
|
|
|
#define UDP_REMOTE_GV_PORT 9004 /* 远端端口 */ |
|
|
|
|
|
#define UDP_REMOTE_Android_PORT 9006 /* 远端端口 */ |
|
|
|
|
|
|
|
|
#define UDP_Printf_PORT 8881 |
|
|
int8_t is_udp_GV_update_loop_enalbed = 0; |
|
|
#define UDP_Long_PORT 8882 |
|
|
|
|
|
#define UDP_UpdataPos_PORT 8883 |
|
|
|
|
|
unsigned char received_data[1000]; |
|
|
unsigned char received_data[1000]; |
|
|
|
|
|
|
|
|
/* udp控制块 */ |
|
|
/* udp控制块 */ |
|
|
static struct udp_pcb *upcb; |
|
|
static struct udp_pcb *upcb_Rx_DLT; |
|
|
static struct udp_pcb *upcb_send; |
|
|
static struct udp_pcb *upcb_Rx_Cmd; |
|
|
|
|
|
static struct udp_pcb *upcb_Rx_From_Android; |
|
|
|
|
|
|
|
|
|
|
|
static struct udp_pcb *upcb_Tx_DLT; |
|
|
|
|
|
static struct udp_pcb *upcb_Tx_Cmd; |
|
|
|
|
|
static struct udp_pcb *upcb_Tx_GV; |
|
|
|
|
|
static struct udp_pcb *upcb_Tx_Android; |
|
|
|
|
|
|
|
|
ip_addr_t serverIP; |
|
|
ip_addr_t serverIP; |
|
|
|
|
|
|
|
|
|
|
|
ip_addr_t Android_ServerIP; |
|
|
|
|
|
|
|
|
|
|
|
DLT_DecodeFuncPtr UDP_DLT_ReceivedCallback; |
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
/******************************************************************************
|
|
|
* 描述 : 接收回调函数 |
|
|
* 描述 : 接收回调函数 |
|
|
* 参数 : - |
|
|
* 参数 : - |
|
|
@ -33,49 +59,119 @@ ip_addr_t serverIP; |
|
|
static void udp_receive_callback(void *arg, struct udp_pcb *upcb, |
|
|
static void udp_receive_callback(void *arg, struct udp_pcb *upcb, |
|
|
struct pbuf *p, const ip_addr_t *addr, u16_t port) |
|
|
struct pbuf *p, const ip_addr_t *addr, u16_t port) |
|
|
{ |
|
|
{ |
|
|
|
|
|
if (p == NULL) return; |
|
|
|
|
|
|
|
|
|
|
|
memcpy(received_data, p->payload, p->len); |
|
|
|
|
|
|
|
|
if (p != NULL) |
|
|
if (upcb->local_port == UDP_DLT_LOCAL_PORT) |
|
|
{ |
|
|
{ |
|
|
memcpy(received_data, p->payload, p->len); |
|
|
UDP_DLT_ReceivedCallback(received_data, p->len); |
|
|
//err_t t = udp_sendto(upcb_send, p, &serverIP, 8000);
|
|
|
//DLT_DataReceiveEndCallback(received_data, p->len);
|
|
|
pbuf_free(p); |
|
|
} |
|
|
} else |
|
|
else if (upcb->local_port == UDP_CMD_LOCAL_PORT) |
|
|
{ |
|
|
{ |
|
|
pbuf_free(p); |
|
|
|
|
|
|
|
|
if (*received_data == 0x55 && *(received_data + 1) == 0x55 |
|
|
|
|
|
&& p->len >= 3) |
|
|
|
|
|
{ |
|
|
|
|
|
decode_command_and_feedback(received_data + 2, p->len - 2, 2, |
|
|
|
|
|
NULL); //0代表UDP
|
|
|
} |
|
|
} |
|
|
|
|
|
else if (*received_data == 0x66 && *(received_data + 1) == 0x66 |
|
|
|
|
|
&& p->len >= 3) |
|
|
|
|
|
{ |
|
|
|
|
|
GF_BSP_GPIO_SetIO(received_data[3], received_data[2]); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
udp_cmd_send_back(received_data, p->len); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
else if (upcb->local_port == UDP_CMD_LOCAL_Android_Listen_PORT) |
|
|
|
|
|
{ |
|
|
|
|
|
//对PV数据进行修改
|
|
|
|
|
|
//if (*buffer == 0x55 && *(buffer + 1) == 0x55 && length >= 4)
|
|
|
|
|
|
if (received_data[0] != 0x55 || received_data[1] != 0x55 || p->len < 4) |
|
|
|
|
|
{ |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
uint16_t crc_check = ((received_data[p->len - 1] << 8) |
|
|
|
|
|
| received_data[p->len - 2]); |
|
|
|
|
|
uint16_t crc_check1 = MB_CRC16(received_data, p->len - 2); |
|
|
|
|
|
/* CRC 校验正确 */ |
|
|
|
|
|
if (crc_check != MB_CRC16(received_data, p->len - 2)) return; |
|
|
|
|
|
|
|
|
|
|
|
if (received_data[2] != 0x01 || received_data[3] != 0x01) return; |
|
|
|
|
|
|
|
|
|
|
|
pb_istream_t i_pv_stream = |
|
|
|
|
|
{ 0 }; |
|
|
|
|
|
|
|
|
|
|
|
i_pv_stream = pb_istream_from_buffer(&received_data[4], p->len - 4); |
|
|
|
|
|
pb_decode(&i_pv_stream, PV_struct_define_fields, &_decoded_PV_temp); |
|
|
|
|
|
if (_decoded_PV_temp.TimeStamp > decoded_PV.TimeStamp) |
|
|
|
|
|
{ |
|
|
|
|
|
decoded_PV = _decoded_PV_temp; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
pbuf_free(p); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//char UDPprintf[100];
|
|
|
//char UDPprintf[100];
|
|
|
|
|
|
|
|
|
void udp_printf_CmdBack(char *pData) |
|
|
void udp_dlt_send_back(char *pData, uint16_t Size) |
|
|
{ |
|
|
{ |
|
|
struct pbuf *p; |
|
|
struct pbuf *p; |
|
|
|
|
|
|
|
|
/* 分配缓冲区空间 */ |
|
|
/* 分配缓冲区空间 */ |
|
|
p = pbuf_alloc(PBUF_TRANSPORT, strlen(pData), PBUF_POOL); |
|
|
p = pbuf_alloc(PBUF_TRANSPORT, Size, PBUF_RAM); |
|
|
|
|
|
|
|
|
if (p != NULL) |
|
|
if (p != NULL) |
|
|
{ |
|
|
{ |
|
|
/* 填充缓冲区数据 */ |
|
|
/* 填充缓冲区数据 */ |
|
|
pbuf_take(p, pData, strlen(pData)); |
|
|
pbuf_take(p, pData, Size); |
|
|
|
|
|
|
|
|
/* 发送udp数据 */ |
|
|
/* 发送udp数据 */ |
|
|
|
|
|
|
|
|
udp_send(upcb, p); |
|
|
//udp_send(upcb_DLT, p);
|
|
|
//err_t t = udp_sendto(upcb, p, &serverIP, UDP_Printf_PORT);
|
|
|
err_t t = udp_sendto(upcb_Tx_DLT, p, &serverIP, |
|
|
|
|
|
UDP_REMOTE_DLT_PORT); |
|
|
|
|
|
/* 释放缓冲区空间 */ |
|
|
|
|
|
pbuf_free(p); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
void udp_cmd_send_back(char *pData, uint16_t Size) |
|
|
|
|
|
{ |
|
|
|
|
|
struct pbuf *p; |
|
|
|
|
|
|
|
|
|
|
|
/* 分配缓冲区空间 */ |
|
|
|
|
|
p = pbuf_alloc(PBUF_TRANSPORT, Size, PBUF_RAM); |
|
|
|
|
|
|
|
|
|
|
|
if (p != NULL) |
|
|
|
|
|
{ |
|
|
|
|
|
/* 填充缓冲区数据 */ |
|
|
|
|
|
pbuf_take(p, pData, Size); |
|
|
|
|
|
|
|
|
|
|
|
/* 发送udp数据 */ |
|
|
|
|
|
err_t err = udp_send(upcb_Tx_Cmd, p); |
|
|
|
|
|
if (err != ERR_OK) |
|
|
|
|
|
{ |
|
|
|
|
|
// 发送失败
|
|
|
|
|
|
printf("Failed to send UDP data: %d\n", err); |
|
|
|
|
|
} |
|
|
/* 释放缓冲区空间 */ |
|
|
/* 释放缓冲区空间 */ |
|
|
pbuf_free(p); |
|
|
pbuf_free(p); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void GF_UDP_Send(uint8_t *pData, uint16_t Size, uint16_t UDP_port) |
|
|
void udp_cmd_send_GV(char *pData, uint16_t Size) |
|
|
{ |
|
|
{ |
|
|
struct pbuf *p; |
|
|
struct pbuf *p; |
|
|
|
|
|
|
|
|
/* 分配缓冲区空间 */ |
|
|
/* 分配缓冲区空间 */ |
|
|
p = pbuf_alloc(PBUF_TRANSPORT, Size, PBUF_POOL); |
|
|
p = pbuf_alloc(PBUF_TRANSPORT, Size, PBUF_RAM); |
|
|
|
|
|
|
|
|
if (p != NULL) |
|
|
if (p != NULL) |
|
|
{ |
|
|
{ |
|
|
@ -83,16 +179,39 @@ void GF_UDP_Send(uint8_t *pData, uint16_t Size, uint16_t UDP_port) |
|
|
pbuf_take(p, pData, Size); |
|
|
pbuf_take(p, pData, Size); |
|
|
|
|
|
|
|
|
/* 发送udp数据 */ |
|
|
/* 发送udp数据 */ |
|
|
//udp_send(upcb, p);
|
|
|
err_t err = udp_send(upcb_Tx_GV, p); |
|
|
err_t t = udp_sendto(upcb, p, &serverIP, UDP_port); |
|
|
if (err != ERR_OK) |
|
|
|
|
|
{ |
|
|
|
|
|
// 发送失败
|
|
|
|
|
|
//printf("Failed to send UDP data: %d\n", err);
|
|
|
|
|
|
} |
|
|
/* 释放缓冲区空间 */ |
|
|
/* 释放缓冲区空间 */ |
|
|
pbuf_free(p); |
|
|
pbuf_free(p); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void GF_UpdataPos_Send(uint8_t *pData, uint32_t Size) |
|
|
void udp_send_by_pcb(struct udp_pcb *upcb, char *pData, uint16_t Size) |
|
|
{ |
|
|
{ |
|
|
GF_UDP_Send(pData, Size, UDP_UpdataPos_PORT); |
|
|
struct pbuf *p; |
|
|
|
|
|
|
|
|
|
|
|
/* 分配缓冲区空间 */ |
|
|
|
|
|
p = pbuf_alloc(PBUF_TRANSPORT, Size, PBUF_RAM); |
|
|
|
|
|
|
|
|
|
|
|
if (p != NULL) |
|
|
|
|
|
{ |
|
|
|
|
|
/* 填充缓冲区数据 */ |
|
|
|
|
|
pbuf_take(p, pData, Size); |
|
|
|
|
|
|
|
|
|
|
|
/* 发送udp数据 */ |
|
|
|
|
|
err_t err = udp_send(upcb, p); |
|
|
|
|
|
if (err != ERR_OK) |
|
|
|
|
|
{ |
|
|
|
|
|
// 发送失败
|
|
|
|
|
|
//printf("Failed to send UDP data: %d\n", err);
|
|
|
|
|
|
} |
|
|
|
|
|
/* 释放缓冲区空间 */ |
|
|
|
|
|
pbuf_free(p); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
/******************************************************************************
|
|
|
@ -102,54 +221,212 @@ void GF_UpdataPos_Send(uint8_t *pData, uint32_t Size) |
|
|
******************************************************************************/ |
|
|
******************************************************************************/ |
|
|
void udp_client_init(void) |
|
|
void udp_client_init(void) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
GF_BSP_Interrupt_Add_CallBack( |
|
|
|
|
|
DF_BSP_InterCall_TIM8_2ms_PeriodElapsedCallback, UDP_GV_Dispatch); |
|
|
|
|
|
//将UDP上传IV关闭
|
|
|
|
|
|
GF_BSP_Interrupt_Add_CallBack( |
|
|
|
|
|
DF_BSP_InterCall_TIM8_2ms_PeriodElapsedCallback, UDP_IV_Dispatch); |
|
|
|
|
|
//Timer intialize();
|
|
|
err_t err; |
|
|
err_t err; |
|
|
|
|
|
|
|
|
IP4_ADDR(&serverIP, 192, 168, 1, 102); |
|
|
IP4_ADDR(&serverIP, 192, 168, 144, 255); |
|
|
|
|
|
IP4_ADDR(&Android_ServerIP, 192, 168, 144, 20); |
|
|
|
|
|
|
|
|
/* 创建udp控制块 */ |
|
|
/* 创建udp控制块 */ |
|
|
upcb = udp_new(); |
|
|
upcb_Rx_DLT = udp_new(); |
|
|
|
|
|
|
|
|
if (upcb != NULL) |
|
|
if (upcb_Rx_DLT != NULL) |
|
|
{ |
|
|
{ |
|
|
/* 配置本地端口 */ |
|
|
/* 配置本地端口 */ |
|
|
upcb->local_port = UDP_LOCAL_PORT; |
|
|
//upcb_DLT->local_port = UDP_DLT_LOCAL_PORT;
|
|
|
|
|
|
/* 配置服务器IP和端口 */ |
|
|
|
|
|
//upcb_DLT->so_options |= SOF_BROADCAST;
|
|
|
|
|
|
//err = udp_connect(upcb_DLT, &serverIP, UDP_REMOTE_DLT_PORT);
|
|
|
|
|
|
err = udp_bind(upcb_Rx_DLT, IP_ADDR_ANY, UDP_DLT_LOCAL_PORT); |
|
|
|
|
|
if (err == ERR_OK) |
|
|
|
|
|
{ |
|
|
|
|
|
/* 注册接收回调函数 */ |
|
|
|
|
|
/* 注册接收回调函数 */ |
|
|
|
|
|
udp_recv(upcb_Rx_DLT, udp_receive_callback, NULL); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
udp_remove(upcb_Rx_DLT); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
upcb_Rx_From_Android = udp_new(); |
|
|
|
|
|
|
|
|
|
|
|
if (upcb_Rx_From_Android != NULL) |
|
|
|
|
|
{ |
|
|
|
|
|
/* 配置本地端口 */ |
|
|
|
|
|
//upcb_DLT->local_port = UDP_DLT_LOCAL_PORT;
|
|
|
/* 配置服务器IP和端口 */ |
|
|
/* 配置服务器IP和端口 */ |
|
|
err= udp_connect(upcb, &serverIP, UDP_REMOTE_PORT); |
|
|
//upcb_DLT->so_options |= SOF_BROADCAST;
|
|
|
// err = udp_bind(upcb, IP_ADDR_ANY, UDP_LOCAL_PORT);
|
|
|
//err = udp_connect(upcb_DLT, &serverIP, UDP_REMOTE_DLT_PORT);
|
|
|
upcb->so_options |= SOF_BROADCAST; |
|
|
err = udp_bind(upcb_Rx_From_Android, IP_ADDR_ANY, |
|
|
|
|
|
UDP_CMD_LOCAL_Android_Listen_PORT); |
|
|
if (err == ERR_OK) |
|
|
if (err == ERR_OK) |
|
|
{ |
|
|
{ |
|
|
/* 注册接收回调函数 */ |
|
|
/* 注册接收回调函数 */ |
|
|
udp_recv(upcb, udp_receive_callback, NULL); |
|
|
/* 注册接收回调函数 */ |
|
|
|
|
|
udp_recv(upcb_Rx_From_Android, udp_receive_callback, NULL); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
udp_remove(upcb_Rx_From_Android); |
|
|
|
|
|
|
|
|
/* 发送udp数据 */ |
|
|
} |
|
|
//printf("udp client connected\r\n");
|
|
|
} |
|
|
} else |
|
|
|
|
|
{ |
|
|
upcb_Rx_Cmd = udp_new(); |
|
|
udp_remove(upcb); |
|
|
|
|
|
|
|
|
if (upcb_Rx_Cmd != NULL) |
|
|
//printf("can not connect udp pcb\r\n");
|
|
|
{ |
|
|
} |
|
|
/* 配置本地端口 */ |
|
|
} |
|
|
//upcb_Cmd->local_port = UDP_CMD_LOCAL_PORT;
|
|
|
// upcb_send = udp_new();
|
|
|
/* 配置服务器IP和端口 */ |
|
|
//
|
|
|
//upcb_Cmd->so_options |= SOF_BROADCAST;
|
|
|
// if (upcb_send != NULL)
|
|
|
//err = udp_connect(upcb_Cmd, &serverIP, UDP_REMOTE_CMD_PORT);
|
|
|
// {
|
|
|
err = udp_bind(upcb_Rx_Cmd, IP_ADDR_ANY, UDP_CMD_LOCAL_PORT); |
|
|
// /* 配置本地端口 */
|
|
|
if (err == ERR_OK) |
|
|
// upcb_send->local_port = UDP_Send_LOCAL_PORT;
|
|
|
{ |
|
|
//
|
|
|
/* 注册接收回调函数 */ |
|
|
// /* 配置服务器IP和端口 */
|
|
|
udp_recv(upcb_Rx_Cmd, udp_receive_callback, NULL); |
|
|
// upcb_send->so_options |= SOF_BROADCAST;
|
|
|
} |
|
|
// err = udp_bind(upcb_send, IP_ADDR_ANY, UDP_Send_LOCAL_PORT);
|
|
|
else |
|
|
// if (err == ERR_OK)
|
|
|
{ |
|
|
// {
|
|
|
udp_remove(upcb_Rx_Cmd); |
|
|
//
|
|
|
} |
|
|
// } else
|
|
|
} |
|
|
// {
|
|
|
|
|
|
// udp_remove(upcb_send);
|
|
|
upcb_Tx_Cmd = udp_new(); |
|
|
//
|
|
|
|
|
|
// }
|
|
|
if (upcb_Tx_Cmd != NULL) |
|
|
// }
|
|
|
{ |
|
|
|
|
|
/* 配置本地端口 */ |
|
|
|
|
|
upcb_Tx_Cmd->local_port = UDP_CMD_Send_LOCAL_PORT; |
|
|
|
|
|
|
|
|
|
|
|
/* 配置服务器IP和端口 */ |
|
|
|
|
|
//upcb_Cmd->so_options |= SOF_BROADCAST;
|
|
|
|
|
|
err = udp_connect(upcb_Tx_Cmd, &serverIP, UDP_REMOTE_CMD_PORT); |
|
|
|
|
|
|
|
|
|
|
|
if (err == ERR_OK) |
|
|
|
|
|
{ |
|
|
|
|
|
/* 注册接收回调函数 */ |
|
|
|
|
|
//udp_recv(upcb_Tx_Cmd, udp_receive_callback, NULL);
|
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
udp_remove(upcb_Tx_Cmd); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
upcb_Tx_DLT = udp_new(); |
|
|
|
|
|
|
|
|
|
|
|
if (upcb_Tx_DLT != NULL) |
|
|
|
|
|
{ |
|
|
|
|
|
/* 配置本地端口 */ |
|
|
|
|
|
upcb_Tx_Cmd->local_port = UDP_DLT_Send_LOCAL_PORT; |
|
|
|
|
|
/* 配置服务器IP和端口 */ |
|
|
|
|
|
//upcb_Cmd->so_options |= SOF_BROADCAST;
|
|
|
|
|
|
err = udp_connect(upcb_Tx_DLT, &serverIP, UDP_REMOTE_DLT_PORT); |
|
|
|
|
|
|
|
|
|
|
|
if (err == ERR_OK) |
|
|
|
|
|
{ |
|
|
|
|
|
/* 注册接收回调函数 */ |
|
|
|
|
|
//udp_recv(upcb_Tx_Cmd, udp_receive_callback, NULL);
|
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
udp_remove(upcb_Tx_DLT); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
upcb_Tx_GV = udp_new(); |
|
|
|
|
|
|
|
|
|
|
|
if (upcb_Tx_GV != NULL) |
|
|
|
|
|
{ |
|
|
|
|
|
/* 配置本地端口 */ |
|
|
|
|
|
upcb_Tx_Cmd->local_port = UDP_GV_Send_LOCAL_PORT; |
|
|
|
|
|
/* 配置服务器IP和端口 */ |
|
|
|
|
|
//upcb_Cmd->so_options |= SOF_BROADCAST;
|
|
|
|
|
|
err = udp_connect(upcb_Tx_GV, &serverIP, UDP_REMOTE_GV_PORT); |
|
|
|
|
|
|
|
|
|
|
|
if (err == ERR_OK) |
|
|
|
|
|
{ |
|
|
|
|
|
/* 注册接收回调函数 */ |
|
|
|
|
|
//udp_recv(upcb_Tx_Cmd, udp_receive_callback, NULL);
|
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
udp_remove(upcb_Tx_GV); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
upcb_Tx_Android = udp_new(); |
|
|
|
|
|
|
|
|
|
|
|
if (upcb_Tx_Android != NULL) |
|
|
|
|
|
{ |
|
|
|
|
|
/* 配置本地端口 */ |
|
|
|
|
|
upcb_Tx_Android->local_port = UDP_Android_Send_LOCAL_PORT; |
|
|
|
|
|
/* 配置服务器IP和端口 */ |
|
|
|
|
|
//upcb_Cmd->so_options |= SOF_BROADCAST;
|
|
|
|
|
|
err = udp_connect(upcb_Tx_Android, &Android_ServerIP, |
|
|
|
|
|
UDP_REMOTE_Android_PORT); |
|
|
|
|
|
|
|
|
|
|
|
if (err == ERR_OK) |
|
|
|
|
|
{ |
|
|
|
|
|
/* 注册接收回调函数 */ |
|
|
|
|
|
//udp_recv(upcb_Tx_Cmd, udp_receive_callback, NULL);
|
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
udp_remove(upcb_Tx_Android); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
int counter_index = 0; |
|
|
|
|
|
int iv_counter_index = 0; |
|
|
|
|
|
void UDP_GV_Dispatch() |
|
|
|
|
|
{ |
|
|
|
|
|
counter_index++; |
|
|
|
|
|
if (counter_index <= 50) return; |
|
|
|
|
|
if (is_udp_GV_update_loop_enalbed == 0) return; |
|
|
|
|
|
counter_index = 0; |
|
|
|
|
|
pb_ostream_t GV_o_stream = |
|
|
|
|
|
{ 0 }; |
|
|
|
|
|
char buf[1024]; |
|
|
|
|
|
GV_o_stream = pb_ostream_from_buffer(&buf[2], sizeof(buf)); |
|
|
|
|
|
pb_encode(&GV_o_stream, GV_struct_define_fields, &GV); |
|
|
|
|
|
buf[1] = 0xfe; |
|
|
|
|
|
buf[0] = 0xfe; |
|
|
|
|
|
//memcpy(&wh_LTE_7S0_Handler->Tx_Buf[2], buf, GV_o_stream.bytes_written);
|
|
|
|
|
|
udp_cmd_send_GV(buf, GV_o_stream.bytes_written + 2); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
//现在是每一百ms执行一次
|
|
|
|
|
|
void UDP_IV_Dispatch() |
|
|
|
|
|
{ |
|
|
|
|
|
iv_counter_index++; |
|
|
|
|
|
if (iv_counter_index <= 50) return; |
|
|
|
|
|
iv_counter_index = 0; |
|
|
|
|
|
char Tx_Buf[1024]; |
|
|
|
|
|
pb_ostream_t IV_o_stream = pb_ostream_from_buffer(&Tx_Buf[2], |
|
|
|
|
|
sizeof(Tx_Buf) - 2); |
|
|
|
|
|
pb_encode(&IV_o_stream, IV_struct_define_fields, &IV); |
|
|
|
|
|
|
|
|
|
|
|
Tx_Buf[0] = 0x55; |
|
|
|
|
|
Tx_Buf[1] = 0x55; |
|
|
|
|
|
int32_t TxCount = IV_o_stream.bytes_written + 4; |
|
|
|
|
|
uint16_t crc = MB_CRC16(Tx_Buf, IV_o_stream.bytes_written + 2); |
|
|
|
|
|
|
|
|
|
|
|
Tx_Buf[IV_o_stream.bytes_written + 2] = (crc >> 8) & 0xff; |
|
|
|
|
|
Tx_Buf[IV_o_stream.bytes_written + 3] = crc & 0xff; |
|
|
|
|
|
|
|
|
|
|
|
udp_send_by_pcb(upcb_Tx_Android, Tx_Buf, IV_o_stream.bytes_written + 4); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|