|
|
@ -11,10 +11,8 @@ |
|
|
|
static udp_broadcast_handler_t m_udp_camera_sync_sender; // |
|
|
|
static udp_broadcast_handler_t m_udp_camera_timecode_sender; // |
|
|
|
|
|
|
|
osThreadId timecode_report_thread_id; |
|
|
|
osThreadId xync_signal_report_thread_id; |
|
|
|
|
|
|
|
static uint32_t m_sync_count = 0; |
|
|
|
// static uint32_t m_camera_sync_packet_report_period = 1; |
|
|
|
|
|
|
|
static uint32_t m_xsync_workstate_start_sig_irq_pin_off; |
|
|
@ -30,13 +28,14 @@ static uint32_t m_xyns_camera_sync_packet_last_report_tp; |
|
|
|
* @param timecode1 |
|
|
|
*/ |
|
|
|
|
|
|
|
static void create_and_send_timecode(uint32_t timecode0, uint32_t timecode1) { |
|
|
|
static void create_and_send_timecode(uint32_t timecode0, uint32_t timecode1, uint32_t frameNum) { |
|
|
|
static uint8_t txbuf[256]; |
|
|
|
iflytop_xsync_event_report_packet_t *txpacket = (iflytop_xsync_event_report_packet_t *)txbuf; |
|
|
|
txpacket->eventid = ktimecode_report_event; |
|
|
|
txpacket->data[0] = timecode0; |
|
|
|
txpacket->data[1] = timecode1; |
|
|
|
xs_udp_broadcast(&m_udp_camera_timecode_sender, IFLYTOP_XSYNC_EVENT_REPORT_PC_PORT, txbuf, sizeof(iflytop_xsync_event_report_packet_t) + 8); |
|
|
|
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_sync_record_state_packet(uint32_t workstate, uint32_t timecode0, uint32_t timecode1) { |
|
|
|
static uint8_t txbuf[256]; |
|
|
@ -68,13 +67,77 @@ static void create_and_send_camera_sync_msg(uint32_t count) { |
|
|
|
xs_udp_broadcast(&m_udp_camera_sync_sender, IFLYTOP_XSYNC_CAMERA_SYNC_PACKET_PC_PORT, txbuf, sizeof(txbuf)); |
|
|
|
} |
|
|
|
|
|
|
|
static void timecode_report_thread(void const *argument) { |
|
|
|
typedef struct { |
|
|
|
uint32_t hour; |
|
|
|
uint32_t minute; |
|
|
|
uint32_t second; |
|
|
|
uint32_t frame; |
|
|
|
|
|
|
|
uint32_t timeinall; |
|
|
|
} timecode_parse_result_t; |
|
|
|
|
|
|
|
timecode_parse_result_t parsetimecode(uint32_t t0, uint32_t t1) { |
|
|
|
timecode_parse_result_t result; |
|
|
|
|
|
|
|
uint8_t frameuints = t0 & 0x0f; |
|
|
|
uint8_t frame10s = (t0 >> 8) & 0x3; |
|
|
|
uint8_t seconduints = (t0 >> 16) & 0x0f; |
|
|
|
uint8_t second10s = (t0 >> 24) & 0x07; |
|
|
|
|
|
|
|
uint8_t minuteuints = t1 & 0x0f; |
|
|
|
uint8_t minute10s = (t1 >> 8) & 0x07; |
|
|
|
uint8_t houruints = (t1 >> 16) & 0x0f; |
|
|
|
uint8_t hour10s = (t1 >> 24) & 0x03; |
|
|
|
|
|
|
|
result.hour = hour10s * 10 + houruints; |
|
|
|
result.minute = minute10s * 10 + minuteuints; |
|
|
|
result.second = second10s * 10 + seconduints; |
|
|
|
result.frame = frame10s * 10 + frameuints; |
|
|
|
|
|
|
|
result.timeinall = result.hour * 3600 + result.minute * 60 + result.second; |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
static timecode_parse_result_t lasttimecode; |
|
|
|
static uint32_t daycnt; |
|
|
|
static uint32_t second; |
|
|
|
|
|
|
|
static uint32_t dtimes(timecode_parse_result_t *a, timecode_parse_result_t *b, bool *newday) { |
|
|
|
if (b->timeinall >= a->timeinall) { |
|
|
|
return b->timeinall - a->timeinall; |
|
|
|
} else { |
|
|
|
*newday = true; |
|
|
|
return b->timeinall + 24 * 3600 - a->timeinall; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static void xync_signal_report_thread(void const *argument) { |
|
|
|
while (true) { |
|
|
|
osEvent signal = osSignalWait(0x07, osWaitForever); |
|
|
|
if (signal.value.signals & 0x01) { |
|
|
|
uint32_t timecode0, timecode1; |
|
|
|
fpga_if_get_timecode(&timecode0, &timecode1); |
|
|
|
create_and_send_timecode(timecode0, timecode1); |
|
|
|
if (signal.value.signals == 0x01) { |
|
|
|
uint32_t tc0; |
|
|
|
uint32_t tc1; |
|
|
|
uint32_t cnt; |
|
|
|
|
|
|
|
fpga_if_spi_read_data_02(camera_sync_timecode_snapshot0, &tc0); |
|
|
|
fpga_if_spi_read_data_02(camera_sync_timecode_snapshot1, &tc1); |
|
|
|
fpga_if_spi_read_data_02(camera_sync_cnt, &cnt); |
|
|
|
|
|
|
|
bool newday = false; |
|
|
|
timecode_parse_result_t result = parsetimecode(tc0, tc1); |
|
|
|
uint32_t dtime = dtimes(&lasttimecode, &result, &newday); |
|
|
|
lasttimecode = result; |
|
|
|
if (dtime < 5 && newday) { |
|
|
|
daycnt++; |
|
|
|
} else { // xsync修改了时基 |
|
|
|
daycnt = 0; |
|
|
|
} |
|
|
|
|
|
|
|
create_and_send_timecode(tc0, tc1, cnt); |
|
|
|
if (dtime >= 1) { |
|
|
|
second = daycnt * 24 * 3600 + result.timeinall; |
|
|
|
create_and_send_camera_sync_msg(second); |
|
|
|
} |
|
|
|
} |
|
|
|
if (signal.value.signals & 0x02) { |
|
|
|
// 开始录制 |
|
|
@ -91,45 +154,19 @@ static void timecode_report_thread(void const *argument) { |
|
|
|
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); |
|
|
|
m_sync_count = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
static void xync_signal_report_thread(void const *argument) { |
|
|
|
while (true) { |
|
|
|
osEvent signal = osSignalWait(0x01, osWaitForever); |
|
|
|
if (signal.value.signals == 0x01) { |
|
|
|
if (m_sync_count == 0) { |
|
|
|
m_xyns_camera_sync_packet_last_report_tp = HAL_GetTick(); |
|
|
|
create_and_send_camera_sync_msg(m_sync_count); |
|
|
|
m_sync_count++; |
|
|
|
} else if (xs_has_passedms(m_xyns_camera_sync_packet_last_report_tp) >= 998) { |
|
|
|
// TODO:此处这么写,当拍摄频率大于500HZ的时候,就不能完全满足刚好卡在1s上报一次消息 |
|
|
|
m_xyns_camera_sync_packet_last_report_tp = HAL_GetTick(); |
|
|
|
create_and_send_camera_sync_msg(m_sync_count); |
|
|
|
m_sync_count++; |
|
|
|
} else { |
|
|
|
m_sync_count++; |
|
|
|
} |
|
|
|
} |
|
|
|
// osSignalClear(xync_signal_report_thread_id, 0x01); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void ReportGeneratorService_irq_trigger(uint16_t gpiopin) { |
|
|
|
if (gpiopin == m_timecode_trigger_input_off) { |
|
|
|
// timecode trigger sig |
|
|
|
osSignalSet(timecode_report_thread_id, 0x01); |
|
|
|
} |
|
|
|
if (m_xsync_workstate_start_sig_irq_pin_off == gpiopin) { |
|
|
|
if (xs_gpio_read(&fpga_if_get_instance()->xsync_workstate_start_sig_irq_io)) { |
|
|
|
osSignalSet(timecode_report_thread_id, 0x02); // 开始工作信号 |
|
|
|
osSignalSet(xync_signal_report_thread_id, 0x02); // 开始工作信号 |
|
|
|
} else { |
|
|
|
osSignalSet(timecode_report_thread_id, 0x04); // 结束工作信号 |
|
|
|
osSignalSet(xync_signal_report_thread_id, 0x04); // 结束工作信号 |
|
|
|
} |
|
|
|
} |
|
|
|
if (gpiopin == m_xync_trigger_input_off) { |
|
|
|
// 相机同步信号 |
|
|
|
osSignalSet(xync_signal_report_thread_id, 0x01); |
|
|
|
} |
|
|
|
} |
|
|
@ -138,20 +175,12 @@ void ReportGeneratorService_init() { |
|
|
|
ZASSERT(xs_udp_broadcast_init(&m_udp_camera_sync_sender, IFLYTOP_XSYNC_CAMERA_SYNC_PACKET_XSYNC_PORT)); |
|
|
|
ZASSERT(xs_udp_broadcast_init(&m_udp_camera_timecode_sender, IFLYTOP_XSYNC_EVENT_REPORT_XSYNC_PORT)); |
|
|
|
|
|
|
|
// |
|
|
|
osThreadDef(timecode_report_thread, timecode_report_thread, TIMECODE_REPORT_TASK_LEVEL, 0, 512); |
|
|
|
timecode_report_thread_id = osThreadCreate(osThread(timecode_report_thread), NULL); |
|
|
|
|
|
|
|
osThreadDef(xync_signal_report_thread, xync_signal_report_thread, CAMERA_SYNC_SIG_REPORT_TASK_LEVEL, 0, 512); |
|
|
|
xync_signal_report_thread_id = osThreadCreate(osThread(xync_signal_report_thread), NULL); |
|
|
|
|
|
|
|
ZASSERT(timecode_report_thread_id != NULL); |
|
|
|
ZASSERT(xync_signal_report_thread_id != NULL); |
|
|
|
|
|
|
|
m_timecode_trigger_input_off = fpga_if_get_instance()->timecode_irq_io.pinoff; |
|
|
|
m_xync_trigger_input_off = fpga_if_get_instance()->camera_sync_code_irq_io.pinoff; |
|
|
|
m_xsync_workstate_start_sig_irq_pin_off = fpga_if_get_instance()->xsync_workstate_start_sig_irq_io.pinoff; |
|
|
|
} |
|
|
|
|
|
|
|
void ReportGeneratorService_xsync_set_count(uint32_t count) { m_sync_count = count; } |
|
|
|
uint32_t ReportGeneratorService_xsync_get_count(void) { return m_sync_count; } |