14#define GET_FLAG_FROM_BITFIELD(flag, n) (pFlags->flag) = (bitfield >> (n)) & 1
17 GET_FLAG_FROM_BITFIELD(PTP_SECURITY, 15);
18 GET_FLAG_FROM_BITFIELD(PTP_ProfileSpecific_2, 14);
19 GET_FLAG_FROM_BITFIELD(PTP_ProfileSpecific_1, 13);
20 GET_FLAG_FROM_BITFIELD(PTP_UNICAST, 10);
21 GET_FLAG_FROM_BITFIELD(PTP_TWO_STEP, 9);
22 GET_FLAG_FROM_BITFIELD(PTP_ALTERNATE_MASTER, 8);
23 GET_FLAG_FROM_BITFIELD(FREQUENCY_TRACEABLE, 7);
24 GET_FLAG_FROM_BITFIELD(TIME_TRACEABLE, 4);
25 GET_FLAG_FROM_BITFIELD(PTP_TIMESCALE, 3);
26 GET_FLAG_FROM_BITFIELD(PTP_UTC_REASONABLE, 2);
27 GET_FLAG_FROM_BITFIELD(PTP_LI_59, 1);
28 GET_FLAG_FROM_BITFIELD(PTP_LI_61, 0);
34#define SET_BIT_IN_FLAG_BITFIELD(flag, n) bitfield |= (pFlags->flag) ? (1 << (n)) : 0
37 uint16_t bitfield = 0;
38 SET_BIT_IN_FLAG_BITFIELD(PTP_SECURITY, 15);
39 SET_BIT_IN_FLAG_BITFIELD(PTP_ProfileSpecific_2, 14);
40 SET_BIT_IN_FLAG_BITFIELD(PTP_ProfileSpecific_1, 13);
41 SET_BIT_IN_FLAG_BITFIELD(PTP_UNICAST, 10);
42 SET_BIT_IN_FLAG_BITFIELD(PTP_TWO_STEP, 9);
43 SET_BIT_IN_FLAG_BITFIELD(PTP_ALTERNATE_MASTER, 8);
44 SET_BIT_IN_FLAG_BITFIELD(FREQUENCY_TRACEABLE, 7);
45 SET_BIT_IN_FLAG_BITFIELD(TIME_TRACEABLE, 4);
46 SET_BIT_IN_FLAG_BITFIELD(PTP_TIMESCALE, 3);
47 SET_BIT_IN_FLAG_BITFIELD(PTP_UTC_REASONABLE, 2);
48 SET_BIT_IN_FLAG_BITFIELD(PTP_LI_59, 1);
49 SET_BIT_IN_FLAG_BITFIELD(PTP_LI_61, 0);
57 uint8_t *p = (uint8_t *)pPayload;
66 memcpy(&flags, p + 6, 2);
71 memcpy(&pHeader->
control, p + 32, 1);
91 uint8_t *p = (uint8_t *)pData;
92 uint8_t firstByte, secondByte;
107 memcpy(p, &firstByte, 1);
109 memcpy(p + 1, &secondByte, 1);
110 memcpy(p + 2, &messageLength, 2);
112 memcpy(p + 6, &flags, 2);
113 memcpy(p + 8, &correction, 8);
115 memcpy(p + 28, &sourcePortID, 2);
116 memcpy(p + 30, &sequenceID, 2);
117 memcpy(p + 32, &pHeader->
control, 1);
154 memcpy(p + 0, ¤tUTCOffset, 2);
158 memcpy(p + 6, &grandmasterClockVariance, 2);
160 memcpy(p + 9, &grandmasterClockIdentity, 8);
161 memcpy(p + 17, &localStepsRemoved, 2);
171 for (i = 0; i < n; i++) {
180 memcpy(p, &nanosec, 4);
194 for (i = 0; i < n; i++) {
197 memcpy(&ts->
sec, p, 6);
215 uint8_t *p = (uint8_t *)pPayload;
225 uint8_t *p = (uint8_t *)pPayload;
228 memcpy(p + 52, &reqSrcPortId, 2);
233 memset(pFlags, 0,
sizeof(
PtpFlags));
void ptp_write_delay_resp_id_data(void *pPayload, const PtpDelay_RespIdentification *pDRData)
void ptp_construct_binary_announce_message(void *pData, const PtpAnnounceBody *pAnnounce)
void ptp_extract_header(PtpHeader *pHeader, const void *pPayload)
void ptp_extract_timestamps(TimestampI *ts, void *pPayload, uint8_t n)
void ptp_extract_announce_message(PtpAnnounceBody *pAnnounce, void *pPayload)
void ptp_read_delay_resp_id_data(PtpDelay_RespIdentification *pDRData, void *pPayload)
void ptp_load_flags(PtpFlags *pFlags, uint16_t bitfield)
void ptp_construct_binary_header(void *pData, const PtpHeader *pHeader)
uint16_t ptp_write_flags(const PtpFlags *pFlags)
void ptp_write_binary_timestamps(void *pPayload, const TimestampI *ts, uint8_t n)
void ptp_clear_flags(PtpFlags *pFlags)
This module defines functions that deal with actual PTP messages; they can extract or insert headers,...
In here reside a multitude of fundamental PTP-related constants and definitions.
#define PTP_HEADER_LENGTH
Length of the PTP header.
#define PTP_TIMESTAMP_LENGTH
Length of a single timestamp.
This module defines the fundamental PTP message and state machine type, flags, bitfields and the PTP ...
Contents of a PTP Announce message without the common PTP header.
uint16_t currentUTCOffset
Current UTC Offset.
uint64_t grandmasterClockIdentity
Grandmaster Clock Identity.
uint8_t grandmasterClockClass
Grandmaster Clock Class.
uint8_t grandmasterClockAccuracy
Grandmaster Clock Accuracy.
uint16_t localStepsRemoved
Local Steps Removed.
uint16_t grandmasterClockVariance
Grandmaster Clock Variance.
uint8_t priority2
Priority 2.
uint8_t timeSource
Time Source.
uint8_t priority1
Priority 1.
Identification carrying Delay_Resp message.
uint64_t requestingSourceClockIdentity
Requesting Source Clock Identity.
uint16_t requestingSourcePortIdentity
Requesting Source Port Identity.
int32_t nanosec
nanoseconds