Skip to main content

Time Synchronization

The header file for time synchronization-related functions is uav_time_sync.h. This document describes the key information and usage of the function prototypes in the uav_time_sync.h file.

Table of Contents

  • Macro Definitions, Enums, and Structures
    E_UAVTimeSyncType
    UAVGetNewestPpsTriggerLocalTimeUsCallback
    T_UAVTimeSyncAircraftTime

  • Function Prototypes
    UAV_TimeSync_Init
    UAV_TimeSync_Deinit<
    UAV_TimeSync_SetType
    UAV_TimeSync_RegGetNewestPpsTriggerTimeCallback
    UAV_TimeSync_TransferToAircraftTime

Macro Definitions, Enums, and Structures

typedef enum E_UAVTimeSyncType

Time synchronization type.

typedef enum {
UAV_TIME_SYNC_TYPE_UNKNOW = 0,
UAV_TIME_SYNC_TYPE_NTP = 1,
UAV_TIME_SYNC_TYPE_PPS_CLOCK = 2
} E_UAVTimeSyncType;

typedef struct T_UAVTimeSyncAircraftTime

Data structure of the time system in the UAV.

typedef struct {
uint16_t year; /*!< Specifies year. */
uint8_t month; /*!< Specifies month. */
uint8_t day; /*!< Specifies day. */
uint8_t hour; /*!< Specifies hour. */
uint8_t minute; /*!< Specifies minute. */
uint8_t second; /*!< Specifies second. */
uint16_t microseconds; /*!< Specifies mircroseconds. */
}T_UAVTimeSyncAircraftTime;

typedef function UAVGetNewestPpsTriggerLocalTimeUsCallback

  • Function: Get the latest PPS triggered timestamp.product: all

This is the callback function prototype for retrieving the latest PPS trigger timestamp.

Note:

  • Users should not perform blocking operations or functions within the callback function, as this can block the UAV root thread, leading to slow system response, disconnection of payloads, or issues like infinite loops.
typedef T_UAVReturnCode (*UAVGetNewestPpsTriggerLocalTimeUsCallback)(uint64_t *localTimeUs);
  • ParameterloacalTimeUs:A pointer to the memory space where the PPS triggered timestamp will be stored.
  • Return Value: The return value corresponds to the execution status of the program. For more details, please refer to: UAV Error Codes.

Function Prototypes

function UAV_TimeSync_Init

  • Function: Initialize the time synchronization module.
  • product: all

This function initializes the time synchronization module in blocking mode. The user should call this function before performing any other time synchronization operations, such as transmitting time.

Note:

  • The maximum execution time for this function is slightly more than 2000ms.
  • This function must be called within a user task, not in the main() function, and it should be invoked after the scheduler has started.
T_UAVReturnCode UAV_TimeSync_Init(void);
  • Parameternone
  • Return Value Outputs the corresponding return value based on the program execution status. For details, refer to: UAV Error Codes.

function UAV_TimeSync_Deinit

  • Function: De-initialize the time synchronization module.
  • product: all
T_UAVReturnCode UAV_TimeSyncDeinit(void);
  • Parameternone
  • Return Value Outputs the corresponding return value based on the program execution status. For details, refer to: UAV Error Codes.

function UAV_TimeSync_SetType

  • Function: Set the time synchronization type.
  • product: all

Sets the time synchronization type function.

T_UAVReturnCode UAV_TimeSync_SetType(E_UAVTimeSyncType type);
  • Parametertype:Time synchronization type.
  • Return Value Outputs the corresponding return value based on the program execution status. For details, refer to: UAV Error Codes.

function UAV_TimeSync_RegGetNewestPpsTriggerTimeCallback

  • Function: Get the latest timestamp.
  • product: all

Registers a callback function to get the latest timestamp in the local time system when the PPS rising edge signal is detected.

T_UAVReturnCode UAV_TimeSync_RegGetNewestPpsTriggerTimeCallback(UAVGetNewestPpsTriggerLocalTimeUsCallback callback);<br />
  • Parametercallback:Pointer to the callback function.
  • Return Value Outputs the corresponding return value based on the program execution status. For details, refer to: UAV Error Codes.

function UAV_TimeSync_TransferToAircraftTime

  • Function: Convert the payload device's local time to the aircraft's time.
  • product: all

Note:

  • When using this interface, please call UAV_TimeSync_RegGetNewestPpsTriggerTimeCallback() to register the callback function for getting the latest timestamp in the payload device's local time when the PPS rising edge signal is detected.
T_UAVReturnCode UAV_TimeSync_TransferToAircraftTime(uint64_t localTimeUs, T_UAVTimeSyncAircraftTime *aircraftTime);
  • Parametertimestamp:Local time in the payload device, in microseconds.aircraft_time:Pointer to memory space for storing the aircraft system time.
  • Return Value Outputs the corresponding return value based on the program execution status. For details, refer to: UAV Error Codes.