libptpmgmt  1.4
libptpmgmt library that provides the functionality of linuxptp pmc
Public Member Functions | Static Public Member Functions | List of all members
PtpClock Class Reference

POSIX dynamic clock id generator. More...

#include <ptp.h>

Inheritance diagram for PtpClock:
Inheritance graph
[legend]
Collaboration diagram for PtpClock:
Collaboration graph
[legend]

Public Member Functions

bool initUsingDevice (const std::string &device, bool readonly=false)
 
bool initUsingIndex (int ptpIndex, bool readonly=false)
 
bool isInit () const
 
clockid_t clkId () const
 
int getFd () const
 
int fileno () const
 
int ptpIndex () const
 
const std::string & device () const
 
const char * device_c () const
 
bool setTimeFromSys () const
 
bool setTimeToSys () const
 
bool fetchCaps (PtpCaps_t &caps) const
 
bool readPin (unsigned int index, PtpPin_t &pin) const
 
bool writePin (PtpPin_t &pin) const
 
bool ExternTSEbable (unsigned int index, uint8_t flags) const
 
bool ExternTSDisable (unsigned int index) const
 
bool MaskClearAll () const
 
bool MaskEnable (unsigned int index) const
 
bool readEvent (PtpEvent_t &event) const
 
bool readEvents (std::vector< PtpEvent_t > &events, size_t max=0) const
 
bool setPinPeriod (unsigned int index, PtpPinPeriodDef_t times, uint8_t flags=0) const
 
bool setPtpPpsEvent (bool enable) const
 
bool samplePtpSys (size_t count, std::vector< PtpSample_t > &samples) const
 
bool extSamplePtpSys (size_t count, std::vector< PtpSampleExt_t > &samples) const
 
bool preciseSamplePtpSys (PtpSamplePrecise_t &sample) const
 
- Public Member Functions inherited from BaseClock
Timestamp_t getTime () const
 
bool setTime (const Timestamp_t &ts) const
 
bool offsetClock (int64_t offset) const
 
float_freq getFreq () const
 
bool setFreq (float_freq freq) const
 
bool setPhase (int64_t offset) const
 

Static Public Member Functions

static bool isCharFile (const std::string &file)
 

Detailed Description

POSIX dynamic clock id generator.

Create a dynamic clock id for a POSIX clock, that the application can use to fetch the PTP clock time and perform actions on PHC hardware.

Note
The dynamic clock id exists while the object exists. Do NOT delete the object while using the dynamic clock id.
A network interface may have multiple PHCs

Member Function Documentation

◆ clkId()

clockid_t PtpClock::clkId ( ) const
inline

Get dynamic clock id

Returns
dynamic clock id or CLOCK_INVALID if not initialized

◆ device()

const std::string& PtpClock::device ( ) const
inline

Get POSIX device name

Returns
device name or empty string if not initialized

◆ device_c()

const char* PtpClock::device_c ( ) const
inline

Get POSIX device name

Returns
device name or empty string if not initialized

◆ ExternTSDisable()

bool PtpClock::ExternTSDisable ( unsigned int  index) const

Disable PHC pin external events

Parameters
[in]indexpin index to enable
Returns
true for success
Note
Pin index should be in the range (0, PtpCaps_t.num_pins]

◆ ExternTSEbable()

bool PtpClock::ExternTSEbable ( unsigned int  index,
uint8_t  flags 
) const

Enable PHC pin external events

Parameters
[in]indexpin index to enable
[in]flagsusing the PTP_EXTERN_TS_xxx flags
Returns
true for success
Note
Pin index should be in the range (0, PtpCaps_t.num_pins]
old kernel do not support PTP_EXTERN_TS_STRICT

◆ extSamplePtpSys()

bool PtpClock::extSamplePtpSys ( size_t  count,
std::vector< PtpSampleExt_t > &  samples 
) const

Extended sample the PHC and system clock So caller can compare offset and frequancy

Parameters
[in]countnumber of sample to measure
[out]samplestaken by kernel
Returns
true for success
Note
old kernel do not support

◆ fetchCaps()

bool PtpClock::fetchCaps ( PtpCaps_t caps) const

Get PTP clock capabilities

Parameters
[out]capscapabilities
Returns
true for success

◆ fileno()

int PtpClock::fileno ( ) const
inline

Get file description

Returns
file description

◆ getFd()

int PtpClock::getFd ( ) const
inline

Get file description

Returns
file description

◆ initUsingDevice()

bool PtpClock::initUsingDevice ( const std::string &  device,
bool  readonly = false 
)

Initialize a POSIX clock based on its device name

Parameters
[in]devicename
[in]readonlyopen clock to read only
Returns
true if device is a POSIX clock

◆ initUsingIndex()

bool PtpClock::initUsingIndex ( int  ptpIndex,
bool  readonly = false 
)

Initialize a PTP clock based on its index

Parameters
[in]ptpIndexclock PTP index
[in]readonlyopen clock to read only
Returns
true if network interface exists

◆ isCharFile()

static bool PtpClock::isCharFile ( const std::string &  file)
static

Check file is a char file

Parameters
[in]filename to check
Returns
true if file is char device
Note
function will follow a symbolic link

◆ isInit()

bool PtpClock::isInit ( ) const
inline

Is object initialized

Returns
true if PTP clock exist and object was successfully initialized

◆ MaskClearAll()

bool PtpClock::MaskClearAll ( ) const

PHC clear all mask

Returns
true for success

◆ MaskEnable()

bool PtpClock::MaskEnable ( unsigned int  index) const

PHC ebable single pin mask

Parameters
[in]indexpin index in mask to enable
Returns
true for success
Note
Pin index should be in the range (0, PtpCaps_t.num_pins]

◆ preciseSamplePtpSys()

bool PtpClock::preciseSamplePtpSys ( PtpSamplePrecise_t sample) const

Precise sample the PHC using PCI cross time stamp

Parameters
[out]sampletaken by kernel
Returns
true for success
Note
old kernel do not support

◆ ptpIndex()

int PtpClock::ptpIndex ( ) const
inline

Get PTP index

Returns
index or NO_SUCH_PTP if not initialized or clock do not have PTP index

◆ readEvent()

bool PtpClock::readEvent ( PtpEvent_t event) const

Read single external event

Parameters
[out]eventretrieved event
Returns
true for success

◆ readEvents()

bool PtpClock::readEvents ( std::vector< PtpEvent_t > &  events,
size_t  max = 0 
) const

Read external events

Parameters
[out]eventsretrieved events
[in]maxmaximum number of events to read
Returns
true for success
Note
the maximum is trunced to 30 events

◆ readPin()

bool PtpClock::readPin ( unsigned int  index,
PtpPin_t pin 
) const

Read PHC clock pin current functional state

Parameters
[in]indexpin index to read
[out]pinhardware functional state
Returns
true for success
Note
Pin index should be in the range (0, PtpCaps_t.num_pins]

◆ samplePtpSys()

bool PtpClock::samplePtpSys ( size_t  count,
std::vector< PtpSample_t > &  samples 
) const

Sample the PHC and system clock So caller can compare offset and frequancy

Parameters
[in]countnumber of sample to measure
[out]samplestaken by kernel
Returns
true for success

◆ setPinPeriod()

bool PtpClock::setPinPeriod ( unsigned int  index,
PtpPinPeriodDef_t  times,
uint8_t  flags = 0 
) const

Set PHC pin period signal

Parameters
[in]indexpin index
[in]timesprovides the times used for the period
[in]flagsusing the PTP_PERIOD_xxx flags
Returns
true for success
Note
Pin index should be in the range (0, PtpCaps_t.num_pins]
old kernel do not support flags

◆ setPtpPpsEvent()

bool PtpClock::setPtpPpsEvent ( bool  enable) const

Enable or disable Linux pulse per second event

Parameters
[in]enableflag
Returns
true for success
Note
Linux will create a pps device /dev/ppsN User can use the 'pps-tools' to use the device.

◆ setTimeFromSys()

bool PtpClock::setTimeFromSys ( ) const

Set PHC time using the system clock

Returns
true for success

◆ setTimeToSys()

bool PtpClock::setTimeToSys ( ) const

Set system clock using the PHC as source time

Returns
true for success

◆ writePin()

bool PtpClock::writePin ( PtpPin_t pin) const

Set PHC clock pin functional state

Parameters
[in]pinhardware functional state
Returns
true for success
Note
Pin index comes from PtpPin_t!
Pin index should be in the range (0, PtpCaps_t.num_pins]

The documentation for this class was generated from the following file: