uav_time_sync.h
2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef __UAV_TIME_SYNC_H__
#define __UAV_TIME_SYNC_H__
#include "uav_typedef.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
UAV_TIME_SYNC_TYPE_UNKNOW = 0,
UAV_TIME_SYNC_TYPE_NTP = 1,
UAV_TIME_SYNC_TYPE_PPS_CLOCK = 2
} E_UAVTimeSyncType;
/* Exported types ------------------------------------------------------------*/
/**
* @brief Prototype of callback function used to get the newest PPS triggered timestamp.
* @warning User can not execute blocking style operations or functions in callback function, because that will block
* root thread, causing problems such as slow system response, payload disconnection or infinite loop.
* @param localTimeUs: pointer to memory space used to store PPS triggered timestamp.
* @return Execution result.
*/
typedef T_UAVReturnCode (*UAV_GetNewestPpsTriggerLocalTimeUsCallback)(uint64_t *localTimeUs);
typedef void (*UAV_TimeSyncRecvDataCallback)(E_UAVTimeSyncType type, int64_t timestamp);
extern T_UAVReturnCode UAV_TimeSync_Init(void);
extern void UAV_TimeSync_Deinit(void);
extern T_UAVReturnCode UAV_TimeSync_NTP(int64_t ×tamp);
/**
* @brief specify the time synchronization type.
* @param type: time synchronization type.
*/
T_UAVReturnCode UAV_TimeSync_SetType(E_UAVTimeSyncType type);
/**
* @brief Register callback function used to get the newest timestamp in local time system when PPS rising edge signal
* is detected.
* @details PSDK uses the timestamp information to synchronise time of local time system and RTK navigation and
* positioning system.
* @param callback: pointer to the callback function.
* @return Execution result.
*/
T_UAVReturnCode UAV_TimeSync_RegGetNewestPpsTriggerTimeCallback(UAV_GetNewestPpsTriggerLocalTimeUsCallback callback);
/**
* @brief Data structure of time in aircraft time system.
*/
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 milliseconds; /*!< Specifies milliseconds. */
}T_UAVTimeSyncAircraftTime;
/**
* @brief Transfer local time to time in aircraft time system.
* @note Before calling the interface, users must call UAV_TimeSync_RegGetNewestPpsTriggerTimeCallback() to register
* callback function used to report the latest triggered time of PPS signal.
* @param localTimeUs: local time, unit: microsecond.
* @param aircraftTime: pointer to memory space used to store time in aircraft time system.
* @return Execution result.
*/
T_UAVReturnCode UAV_TimeSync_TransferToAircraftTime(uint64_t localTimeUs, T_UAVTimeSyncAircraftTime *aircraftTime);
#ifdef __cplusplus
}
#endif
#endif // !__UAV_TIME_SYNC_H__