flexPTP 1.0
An IEEE 1588 PTP implementation designed for microcontrollers
Loading...
Searching...
No Matches
CLI interface

Command Line Interface

If a suitable Command Line Interface is defined in compile time, the following commands are available:

  • ptp reset
    • Resets flexPTP's internal state machines and statistics, but does not clear the PTP profile, clock offset and priority settings.
  • ptp servo offset [offset_ns]
    • Set (if given) or query clock offset in nanoseconds. For special measurements and experiments this way local delay asymmetry can be easily compensated.
  • ptp log {def|corr|ts|info|locked|bmca} {on|off}
  • ptp master [[un]prefer] [clockid]
    • Make this device follow ('prefer') or unfollow a specific master clock. If no parameters are passed, then the current master's clock identity is printed.
  • ptp info
    • Print general PTP information: our clock ID and the master's clock ID
  • ptp domain [domain]
    • Print or set PTP domain.
  • ptp addend [addend]
    • Print or set the addend, the hardware clock tuning word. Setting this directly influences the clock. If manual control over the clock was desired, disable the servo before. This option in only available with the ADDEND-interface.
  • ptp tuning [tuning]
    • Print or set the clock tuning in PPB. Setting this directly influences the clock. If manual control over the clock was desired, disable the servo before. This option in only available with the HLT-interface.
  • ptp transport [{ipv4|802.3}]
    • Set or get PTP transport layer.
  • ptp delmech [{e2e|p2p}]
    • Set or get PTP delay mechanism
  • ptp transpec [{def|gPTP}]
    • Set or get PTP transportSpecific field (majorSdoId). Currently only used when operating the gPTP profile.
  • ptp profile [preset [<name>]]
    • Print or set PTP profile, or list available presets. Currently default, defp2p and gPTP presets are defined.
  • ptp tlv [preset [name]|unload]
    • Get or set TLV-chain, or list available TLV presets. Currently only the gptp TLV-preset is defined.
  • ptp pflags [<flags>]
    • Print or set profile flags. All possible profile flags are printed when this command is invoked in any form.
  • ptp period <delreq|sync|ann> [<lp>|matched]
    • Print or set logarithmic (P)Delay_Req, Sync or Announce period. Minimum is -3 maximum is +4. matched makes (P)Delay_Req transmission triggered by the Sync reception, that's why this option is only meaningful when setting (P)Delay_Req period.
  • ptp priority [<p1> <p2>]
    • Print or set clock priority fields (0-255)
  • ptp coarse [threshold]
    • Print or set coarse correction kick-in threshold (nanoseconds)
  • time [ns]
    • Print datetime, if ns is specified, time is returned in UNIX format

Registering commands

The following command is used for illustration: ptp priority [<p1> <p2>] Print or set clock priority fields

The flexPTP expects a CLI_REG_CMD(cmd_hintline, n_cmd, n_min_arg, cb) macro with the below parameters. The function should return an int value. The returned value can be optionally used later to identify the registered commands.

  • cmd_hintline: a joint string with the command and the hint separated by at least one tabulator (\t) character (e.g. ptp priority [<p1> <p2>]\tPrint or set clock priority fields),
  • n_cmd: number of words in the command section (2 in this case: ptp and priority),
  • n_min_arg: minimum required number of arguments (0 in this case, since both parameters are optional)
  • cb: the callback function with the following signature: int cb(const char ** ppArgs, uint8_t argc). The return value should be negative if the command execution fails, and 0 at successful processing.
    • ppArgs: array of command parameters. If char ** typing is not viable with the first parameter, then use any equivalent, like char[N]*, etc.
    • argc: number of parameters.

The library also expects a CMD_FUNCTION(name) macro to construct the command callback functions, e.g.

#define CMD_FUNCTION(name) int (name) (const char ** ppArgs, uint8_t argc)

Using the two macro above, the command registration can be easily adapted to any type of CLI management system.

To learn more about flexPTP's CLI command registration, refer to: cli_cmds.c.

Removing commands

Optionally, define the CLI_REMOVE_CMD(id) macro that removes a CLI command. It will be invoked during the de-initialization of the library. The id is the numeric value returned by the CLI_REG_CMD() call.