zhaohe 1 year ago
parent
commit
148f5f9441
  1. 31
      LWIP/App/lwip.c
  2. 10
      LWIP/Target/lwipopts.h
  3. 2
      README.md
  4. 2
      iflytop_xsync_protocol
  5. 2
      usrc/base_service/config_service.c
  6. 1
      usrc/project_configs.h
  7. 131
      usrc/service/network_service.c
  8. 32
      usrc/service/report_generator_service.c
  9. 8
      xsync_stm32.ioc

31
LWIP/App/lwip.c

@ -44,9 +44,6 @@ struct netif gnetif;
ip4_addr_t ipaddr;
ip4_addr_t netmask;
ip4_addr_t gw;
uint8_t IP_ADDRESS[4];
uint8_t NETMASK_ADDRESS[4];
uint8_t GATEWAY_ADDRESS[4];
/* USER CODE BEGIN 2 */
@ -57,30 +54,13 @@ uint8_t GATEWAY_ADDRESS[4];
*/
void MX_LWIP_Init(void)
{
/* IP addresses initialization */
IP_ADDRESS[0] = 192;
IP_ADDRESS[1] = 168;
IP_ADDRESS[2] = 8;
IP_ADDRESS[3] = 10;
NETMASK_ADDRESS[0] = 255;
NETMASK_ADDRESS[1] = 255;
NETMASK_ADDRESS[2] = 255;
NETMASK_ADDRESS[3] = 255;
GATEWAY_ADDRESS[0] = 192;
GATEWAY_ADDRESS[1] = 168;
GATEWAY_ADDRESS[2] = 8;
GATEWAY_ADDRESS[3] = 1;
/* USER CODE BEGIN IP_ADDRESSES */
/* USER CODE END IP_ADDRESSES */
/* Initilialize the LwIP stack with RTOS */
tcpip_init( NULL, NULL );
/* IP addresses initialization without DHCP (IPv4) */
IP4_ADDR(&ipaddr, IP_ADDRESS[0], IP_ADDRESS[1], IP_ADDRESS[2], IP_ADDRESS[3]);
IP4_ADDR(&netmask, NETMASK_ADDRESS[0], NETMASK_ADDRESS[1] , NETMASK_ADDRESS[2], NETMASK_ADDRESS[3]);
IP4_ADDR(&gw, GATEWAY_ADDRESS[0], GATEWAY_ADDRESS[1], GATEWAY_ADDRESS[2], GATEWAY_ADDRESS[3]);
/* IP addresses initialization with DHCP (IPv4) */
ipaddr.addr = 0;
netmask.addr = 0;
gw.addr = 0;
/* add the network interface (IPv4/IPv6) with RTOS */
netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &tcpip_input);
@ -108,6 +88,9 @@ void MX_LWIP_Init(void)
osThreadCreate (osThread(EthLink), &gnetif);
/* USER CODE END H7_OS_THREAD_DEF_CREATE_CMSIS_RTOS_V1 */
/* Start DHCP negotiation for a network interface (IPv4) */
dhcp_start(&gnetif);
/* USER CODE BEGIN 3 */
/* USER CODE END 3 */

10
LWIP/Target/lwipopts.h

@ -49,12 +49,20 @@
/* LwIP Stack Parameters (modified compared to initialization value in opt.h) -*/
/* Parameters set in STM32CubeMX LwIP Configuration GUI -*/
/*----- Value in opt.h for LWIP_DHCP: 0 -----*/
#define LWIP_DHCP 1
/*----- Default Value for LWIP_DNS: 0 ---*/
#define LWIP_DNS 1
/*----- Value in opt.h for MEM_ALIGNMENT: 1 -----*/
#define MEM_ALIGNMENT 4
/*----- Value in opt.h for LWIP_ETHERNET: LWIP_ARP || PPPOE_SUPPORT -*/
#define LWIP_ETHERNET 1
/*----- Default Value for LWIP_AUTOIP: 0 ---*/
#define LWIP_AUTOIP 1
/*----- Default Value for LWIP_DHCP_AUTOIP_COOP: 0 ---*/
#define LWIP_DHCP_AUTOIP_COOP 1
/*----- Default Value for LWIP_DHCP_AUTOIP_COOP_TRIES: 9 ---*/
#define LWIP_DHCP_AUTOIP_COOP_TRIES 3
/*----- Value in opt.h for LWIP_DNS_SECURE: (LWIP_DNS_SECURE_RAND_XID | LWIP_DNS_SECURE_NO_MULTIPLE_OUTSTANDING | LWIP_DNS_SECURE_RAND_SRC_PORT) -*/
#define LWIP_DNS_SECURE 7
/*----- Value in opt.h for TCP_SND_QUEUELEN: (4*TCP_SND_BUF + (TCP_MSS - 1))/TCP_MSS -----*/
@ -67,6 +75,8 @@
#define TCP_WND_UPDATE_THRESHOLD 536
/*----- Default Value for LWIP_NETIF_HOSTNAME: 0 ---*/
#define LWIP_NETIF_HOSTNAME 1
/*----- Default Value for LWIP_NETIF_STATUS_CALLBACK: 0 ---*/
#define LWIP_NETIF_STATUS_CALLBACK 1
/*----- Value in opt.h for LWIP_NETIF_LINK_CALLBACK: 0 -----*/
#define LWIP_NETIF_LINK_CALLBACK 1
/*----- Value in opt.h for TCPIP_THREAD_STACKSIZE: 0 -----*/

2
README.md

@ -10,6 +10,8 @@ V3
1.添加SN码,并规范化
2.修改xsync相机同步消息上报格式
3.修改xsynctimecode消息上报格式
4.添加dhcp支持
5.dhcp失败自动触发LLA,生成随机本地IP
```

2
iflytop_xsync_protocol

@ -1 +1 @@
Subproject commit 6f8c0e94e9d830196ae42bfa6ea7dc447fe230ad
Subproject commit e6aef8efe9806029eb776f851af4c4d043f22a48

2
usrc/base_service/config_service.c

@ -20,7 +20,7 @@ static void create_default_config(config_t *now_cfg, bool cfg_is_error, config_t
IP4_ADDR((ip4_addr_t *)&default_cfg->ip, 192, 168, 8, 10);
IP4_ADDR((ip4_addr_t *)&default_cfg->gw, 192, 168, 8, 1);
IP4_ADDR((ip4_addr_t *)&default_cfg->netmask, 255, 255, 255, 0);
default_cfg->obtaining_ip_mode = obtaining_ip_mode_type_static; // dhcp
default_cfg->obtaining_ip_mode = obtaining_ip_mode_type_dhcp; // dhcp
default_cfg->config0 = KXSYNC_REG_STM32_CONFIG0_MASK_TIMECODE_REPORT_ENABLE | //
KXSYNC_REG_STM32_CONFIG0_MASK_CAMERA_SYNC_REPORT_ENABLE;

1
usrc/project_configs.h

@ -4,6 +4,7 @@
#define PC_MANUFACTURER0 ('i' | 'f' << 8 | 'l' << 16 | 'y' << 24)
#define PC_MANUFACTURER1 ('t' | 'o' << 8 | 'p' << 16 | '\0' << 24)
#define PC_PROJECT_NAME "xsync"
#define PC_DEVICE_NAME "xsync"
#define PC_IFLYTOP_ENABLE_OS 1
#define PC_DEBUG_UART huart1

131
usrc/service/network_service.c

@ -50,52 +50,103 @@ static void ethernet_link_status_updated(struct netif *netif) {
}
}
static void ethernet_status_updated(struct netif *netif) {
ZLOGI(TAG, "dhcp success----");
ZLOGI(TAG, " IP address: %s", ip4addr_ntoa(netif_ip4_addr(netif)));
ZLOGI(TAG, " netmask : %s", ip4addr_ntoa(netif_ip4_netmask(netif)));
ZLOGI(TAG, " gateway : %s", ip4addr_ntoa(netif_ip4_gw(netif)));
}
// tcpip_init( NULL, NULL );
// /* IP addresses initialization with DHCP (IPv4) */
// ipaddr.addr = 0;
// netmask.addr = 0;
// gw.addr = 0;
// /* add the network interface (IPv4/IPv6) with RTOS */
// netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &tcpip_input);
// /* Registers the default network interface */
// netif_set_default(&gnetif);
// if (netif_is_link_up(&gnetif))
// {
// /* When the netif is fully configured this function must be called */
// netif_set_up(&gnetif);
// }
// else
// {
// /* When the netif link is down this function must be called */
// netif_set_down(&gnetif);
// }
// /* Set the link callback function, this function is called on change of link status*/
// netif_set_link_callback(&gnetif, ethernet_link_status_updated);
// /* Create the Ethernet link handler thread */
// /* USER CODE BEGIN H7_OS_THREAD_DEF_CREATE_CMSIS_RTOS_V1 */
// osThreadDef(EthLink, ethernet_link_thread, osPriorityBelowNormal, 0, configMINIMAL_STACK_SIZE *2);
// osThreadCreate (osThread(EthLink), &gnetif);
// /* USER CODE END H7_OS_THREAD_DEF_CREATE_CMSIS_RTOS_V1 */
// /* Start DHCP negotiation for a network interface (IPv4) */
// dhcp_start(&gnetif);
// typedef enum { obtaining_ip_mode_type_static = 0, obtaining_ip_mode_type_dhcp = 1, obtaining_ip_mode_type_lla = 2 } obtaining_ip_mode_t;
void network_service_init() {
ZLOGI(TAG, "network_service_init");
uint32_t mode = config_get()->obtaining_ip_mode;
*(uint32_t *)(IP_ADDRESS) = config_get()->ip;
*(uint32_t *)(NETMASK_ADDRESS) = config_get()->netmask;
*(uint32_t *)(GATEWAY_ADDRESS) = config_get()->gw;
// IP_ADDRESS[0] = 192;
// IP_ADDRESS[1] = 168;
// IP_ADDRESS[2] = 8;
// IP_ADDRESS[3] = 10;
// NETMASK_ADDRESS[0] = 255;
// NETMASK_ADDRESS[1] = 255;
// NETMASK_ADDRESS[2] = 255;
// NETMASK_ADDRESS[3] = 255;
// GATEWAY_ADDRESS[0] = 192;
// GATEWAY_ADDRESS[1] = 168;
// GATEWAY_ADDRESS[2] = 8;
// GATEWAY_ADDRESS[3] = 1;
memcpy(g_mac, config_get()->mac, 6);
/* Initilialize the LwIP stack with RTOS */
tcpip_init(NULL, NULL);
/* IP addresses initialization without DHCP (IPv4) */
IP4_ADDR(&ipaddr, IP_ADDRESS[0], IP_ADDRESS[1], IP_ADDRESS[2], IP_ADDRESS[3]);
IP4_ADDR(&netmask, NETMASK_ADDRESS[0], NETMASK_ADDRESS[1], NETMASK_ADDRESS[2], NETMASK_ADDRESS[3]);
IP4_ADDR(&gw, GATEWAY_ADDRESS[0], GATEWAY_ADDRESS[1], GATEWAY_ADDRESS[2], GATEWAY_ADDRESS[3]);
/* add the network interface (IPv4/IPv6) with RTOS */
netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &tcpip_input);
/* Registers the default network interface */
netif_set_default(&gnetif);
if (netif_is_link_up(&gnetif)) {
/* When the netif is fully configured this function must be called */
netif_set_up(&gnetif);
} else {
/* When the netif link is down this function must be called */
netif_set_down(&gnetif);
}
mode = 1;
/* Set the link callback function, this function is called on change of link status*/
netif_set_link_callback(&gnetif, ethernet_link_status_updated);
osThreadDef(EthLink, ethernet_link_thread, NETWORK_REPORT_TASK_LEVEL, 0, 512);
osThreadCreate(osThread(EthLink), &gnetif);
if (mode == obtaining_ip_mode_type_static) {
memcpy(g_mac, config_get()->mac, 6);
tcpip_init(NULL, NULL);
IP4_ADDR(&ipaddr, IP_ADDRESS[0], IP_ADDRESS[1], IP_ADDRESS[2], IP_ADDRESS[3]);
IP4_ADDR(&netmask, NETMASK_ADDRESS[0], NETMASK_ADDRESS[1], NETMASK_ADDRESS[2], NETMASK_ADDRESS[3]);
IP4_ADDR(&gw, GATEWAY_ADDRESS[0], GATEWAY_ADDRESS[1], GATEWAY_ADDRESS[2], GATEWAY_ADDRESS[3]);
netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &tcpip_input);
netif_set_default(&gnetif);
if (netif_is_link_up(&gnetif)) {
netif_set_up(&gnetif);
} else {
netif_set_down(&gnetif);
}
netif_set_link_callback(&gnetif, ethernet_link_status_updated);
osThreadDef(EthLink, ethernet_link_thread, NETWORK_REPORT_TASK_LEVEL, 0, 512);
osThreadCreate(osThread(EthLink), &gnetif);
} else if (mode == obtaining_ip_mode_type_dhcp) {
memcpy(g_mac, config_get()->mac, 6);
tcpip_init(NULL, NULL);
IP4_ADDR(&ipaddr, 0, 0, 0, 0);
IP4_ADDR(&netmask, 0, 0, 0, 0);
IP4_ADDR(&gw, 0, 0, 0, 0);
netif_set_hostname(&gnetif, PC_DEVICE_NAME);
netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &tcpip_input);
netif_set_default(&gnetif);
if (netif_is_link_up(&gnetif)) {
netif_set_up(&gnetif);
} else {
netif_set_down(&gnetif);
}
netif_set_link_callback(&gnetif, ethernet_link_status_updated);
netif_set_status_callback(&gnetif, ethernet_status_updated);
osThreadDef(EthLink, ethernet_link_thread, NETWORK_REPORT_TASK_LEVEL, 0, 512);
osThreadCreate(osThread(EthLink), &gnetif);
while (!netif_is_up(&gnetif)) {
ZLOGI(TAG, "waiting for dhcp");
osDelay(100);
}
dhcp_start(&gnetif);
} else if (mode == obtaining_ip_mode_type_lla) {
}
}

32
usrc/service/report_generator_service.c

@ -37,6 +37,15 @@ static void create_and_send_timecode(uint32_t timecode0, uint32_t timecode1, uin
txpacket->data[2] = frameNum;
xs_udp_broadcast(&m_udp_camera_timecode_sender, IFLYTOP_XSYNC_EVENT_REPORT_PC_PORT, txbuf, sizeof(iflytop_xsync_event_report_packet_t) + 12);
}
static void create_and_send_device_online_packet() {
static uint8_t txbuf[256];
iflytop_xsync_event_report_packet_t *txpacket = (iflytop_xsync_event_report_packet_t *)txbuf;
txpacket->eventid = kdevice_online_report_event;
txpacket->data[0] = kxsync_device_type_xsync;
xs_udp_broadcast(&m_udp_camera_timecode_sender, IFLYTOP_XSYNC_EVENT_REPORT_PC_PORT, txbuf, sizeof(iflytop_xsync_event_report_packet_t) + 4);
}
static void create_and_send_sync_record_state_packet(uint32_t workstate, uint32_t timecode0, uint32_t timecode1) {
static uint8_t txbuf[256];
uint32_t packetdatalen = 3;
@ -111,9 +120,18 @@ static uint32_t dtimes(timecode_parse_result_t *a, timecode_parse_result_t *b, b
}
}
static uint32_t last_report_packet_time;
static void try_report_device_info_packet() {
if (xs_has_passedms(last_report_packet_time) >= 3000) {
last_report_packet_time = xs_get_ticket();
create_and_send_device_online_packet();
}
}
static void xync_signal_report_thread(void const *argument) {
while (true) {
osEvent signal = osSignalWait(0x07, osWaitForever);
osEvent signal = osSignalWait(0x07, 100);
if (signal.value.signals == 0x01) {
uint32_t tc0;
uint32_t tc1;
@ -133,7 +151,9 @@ static void xync_signal_report_thread(void const *argument) {
daycnt = 0;
}
create_and_send_timecode(tc0, tc1, cnt);
create_and_send_timecode(tc0, tc1, cnt); // timecode밤꺄관
last_report_packet_time = xs_get_ticket();
if (dtime >= 1) {
second = daycnt * 24 * 3600 + result.timeinall;
create_and_send_camera_sync_msg(second);
@ -145,7 +165,8 @@ static void xync_signal_report_thread(void const *argument) {
uint32_t timecode1 = 0;
fpga_if_spi_read_data_02(record_sig_gen_timecode_snapshot0, &timecode0);
fpga_if_spi_read_data_02(record_sig_gen_timecode_snapshot1, &timecode1);
create_and_send_sync_record_state_packet(1, timecode0, timecode1);
create_and_send_sync_record_state_packet(1, timecode0, timecode1); // 谿
last_report_packet_time = xs_get_ticket();
}
if (signal.value.signals & 0x04) {
//
@ -153,8 +174,11 @@ static void xync_signal_report_thread(void const *argument) {
uint32_t timecode1 = 0;
fpga_if_spi_read_data_02(record_sig_gen_timecode_snapshot0, &timecode0);
fpga_if_spi_read_data_02(record_sig_gen_timecode_snapshot1, &timecode1);
create_and_send_sync_record_state_packet(0, timecode0, timecode1);
create_and_send_sync_record_state_packet(0, timecode0, timecode1); // 谿
last_report_packet_time = xs_get_ticket();
}
try_report_device_info_packet();
}
}

8
xsync_stm32.ioc

@ -82,11 +82,15 @@ GPIO.groupedBy=Group By Peripherals
KeepUserPlacement=false
LWIP.BSP.number=1
LWIP.GATEWAY_ADDRESS=192.168.008.001
LWIP.IPParameters=LWIP_DHCP,IP_ADDRESS,NETMASK_ADDRESS,GATEWAY_ADDRESS,LWIP_DNS,LWIP_NETIF_HOSTNAME,LWIP_SO_RCVTIMEO,LWIP_SO_SNDTIMEO
LWIP.IPParameters=LWIP_DHCP,IP_ADDRESS,NETMASK_ADDRESS,GATEWAY_ADDRESS,LWIP_DNS,LWIP_NETIF_HOSTNAME,LWIP_SO_RCVTIMEO,LWIP_SO_SNDTIMEO,LWIP_AUTOIP,LWIP_DHCP_AUTOIP_COOP,LWIP_NETIF_STATUS_CALLBACK,LWIP_DHCP_AUTOIP_COOP_TRIES
LWIP.IP_ADDRESS=192.168.008.010
LWIP.LWIP_DHCP=0
LWIP.LWIP_AUTOIP=1
LWIP.LWIP_DHCP=1
LWIP.LWIP_DHCP_AUTOIP_COOP=1
LWIP.LWIP_DHCP_AUTOIP_COOP_TRIES=0
LWIP.LWIP_DNS=1
LWIP.LWIP_NETIF_HOSTNAME=1
LWIP.LWIP_NETIF_STATUS_CALLBACK=1
LWIP.LWIP_SO_RCVTIMEO=1
LWIP.LWIP_SO_SNDTIMEO=1
LWIP.NETMASK_ADDRESS=255.255.255.255

Loading…
Cancel
Save