|
|
@ -1,8 +1,8 @@ |
|
|
|
#include "project_configs.h" |
|
|
|
#include "project_dep.h" |
|
|
|
// |
|
|
|
#include "reg_manager.h" |
|
|
|
#include "base_service/config_service.h" |
|
|
|
#include "reg_manager.h" |
|
|
|
|
|
|
|
#define TAG "extern_if_service" |
|
|
|
|
|
|
@ -11,7 +11,12 @@ typedef struct { |
|
|
|
zaf_buf_t receipt; |
|
|
|
} extern_if_service_context_t; |
|
|
|
|
|
|
|
static udp_t m_udp_cmd_server; // |
|
|
|
static udp_t m_udp_cmd_server; // |
|
|
|
osThreadId m_cmd_uart_receiver_thread; // |
|
|
|
|
|
|
|
extern DMA_HandleTypeDef COMMAND_UART_DMA_HANDLER; |
|
|
|
extern UART_HandleTypeDef COMMAND_UART; |
|
|
|
|
|
|
|
// static udp_broadcast_handler_t m_udp_camera_sync_sender; // |
|
|
|
|
|
|
|
static struct sockaddr_in m_last_rxpacket_client; |
|
|
@ -54,13 +59,13 @@ static void create_receipt(extern_if_service_context_t *context, uint32_t ecode, |
|
|
|
*******************************************************************************/ |
|
|
|
|
|
|
|
static bool process_rx_packet(extern_if_service_context_t *cx, uint8_t *data, uint16_t len) { |
|
|
|
// ZLOGI(TAG, "udp_on_packet %d:", len); |
|
|
|
// for (int i = 0; i < len; i++) { |
|
|
|
// printf("%02x ", data[i]); |
|
|
|
// } |
|
|
|
// printf("\n"); |
|
|
|
zaf_packet_header_t *rxpacket = (zaf_packet_header_t *)data; |
|
|
|
cx->rxpacket = rxpacket; |
|
|
|
ZLOGI(TAG, "udp_on_packet %d:", len); |
|
|
|
for (int i = 0; i < len; i++) { |
|
|
|
printf("%02x ", data[i]); |
|
|
|
} |
|
|
|
printf("\n"); |
|
|
|
zaf_packet_header_t *rxpacket = (zaf_packet_header_t *)data; |
|
|
|
cx->rxpacket = rxpacket; |
|
|
|
|
|
|
|
if (rxpacket->packet_type != kzaf_packet_type_cmd) return; |
|
|
|
|
|
|
@ -129,6 +134,44 @@ static void udp_on_packet(udp_t *server, struct sockaddr_in *client, uint8_t *da |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static void uart_on_packet(uint8_t *packet, uint32_t len) { |
|
|
|
extern_if_service_context_t cx; |
|
|
|
bool ret = process_rx_packet(&cx, packet, len); |
|
|
|
if (ret) { |
|
|
|
HAL_UART_Transmit(&COMMAND_UART, (uint8_t *)cx.receipt.data, cx.receipt.len, 1000); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
static uint8_t g_uart_rx_buf[128]; |
|
|
|
static uint32_t g_uart_rx_buf_index = 0; |
|
|
|
bool uart_is_rxing(UART_HandleTypeDef *huart) { // |
|
|
|
uint32_t uartstate = HAL_UART_GetState(huart); |
|
|
|
if (uartstate & 0x02) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size) { g_uart_rx_buf_index = Size; } |
|
|
|
|
|
|
|
static void uart_receiver_thread(void *) { |
|
|
|
while (1) { |
|
|
|
if (!uart_is_rxing(&COMMAND_UART)) { |
|
|
|
if (g_uart_rx_buf_index != 0) { |
|
|
|
prv_process_uart_rx_data(); |
|
|
|
} |
|
|
|
g_uart_rx_buf_index = 0; |
|
|
|
memset(g_uart_rx_buf, 0, sizeof(g_uart_rx_buf)); |
|
|
|
HAL_UARTEx_ReceiveToIdle_DMA(&COMMAND_UART, g_uart_rx_buf, sizeof(g_uart_rx_buf) - 1); |
|
|
|
uart_on_packet(g_uart_rx_buf, sizeof(g_uart_rx_buf)); |
|
|
|
} |
|
|
|
osDelay(1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void extern_if_service_init() { // |
|
|
|
ZASSERT(zaf_udp_init(&m_udp_cmd_server, "extern_if_udp", ZAF_SERVICE_DEVICE_PORT, udp_on_packet, 1024, NULL)); |
|
|
|
|
|
|
|
m_cmd_uart_receiver_thread = osThreadCreate(&m_cmd_uart_receiver_thread, uart_receiver_thread); |
|
|
|
ZASSERT(m_cmd_uart_receiver_thread != NULL); |
|
|
|
} |