MessagePTP

Summary

Represents a PTP (Precision Time Protocol) message object, follows PTPv2 specifications.

Methods
Properties
Events

Structure

class MessagePTP
capture(filter: Filter = None) MessagePTP

Matches any message with the same protocol.

Parameters

filter (Filter) – Filter to use to narrow down packets to capture

Returns

Listens to the bus until a message is received and returns this first message

Return type

MessagePTP

capture(timeout: int32, filter: Filter = None) MessagePTP

Waits for the first message having the same protocol that the sent message without verify the IP address and the port between send and respond message and return it. A timeout is specified to guarantee that the script can continue if no message is captured in a certain time interval.

Parameters
  • timeout (int32) – Max time in milliseconds to wait for the response.

  • filter (Filter) – Filter to use to narrow down packets to capture

Returns

First message captured from the bus or None in case no message is received.

Return type

MessagePTP

capture_list(timeout: int32, filter: Filter = None) IReadOnlyList[MessagePTP]

Waits for any response having the same protocol that the sent message without verify the IP address and the port between send and respond message and return them all as a list. A timeout is specified to guarantee that the script can continue if no message is received in a certain time interval.

Parameters
  • timeout (int32) – Max time in milliseconds to wait for the response.

  • filter (Filter) – Filter to use to narrow down packets to capture

Returns

List of messages captured from the bus during a given period of time.

Return type

IReadOnlyList[MessagePTP]

close_writer()

Closes the file previously created with open_writer(file).

get_all_bytes() Array[uint8]

Gets the content of the whole message from Ethernet layer.

Returns

Array of bytes representing the message from Ethernet layer.

Return type

Array[uint8]

get_bytes() Array[uint8]

Gets the content of the payload.

Returns

Array of bytes representing the payload of the message.

Return type

Array[uint8]

get_hex_bytes() str

Converts the payload of the message from decimal to hex and outputs it to a string of bytes.

Returns

Payload of message in hex bytes.

Return type

str

hex_view() str

Allows to visualize messages in hexadecimal format.

Returns

Hexadecimal representation of the whole message.

Return type

str

hex_view(nb_bytes_per_line: int32) str

Allows to visualize messages in hexadecimal format.

Parameters

nb_bytes_per_line (int32) – (optional) number of bytes per line.

Returns

Hexadecimal representation of the whole message.

Return type

str

open_writer(file: str, fileFormat: FILEFORMAT or None = None)

Creates a PCAP or PCAPNG file for writing the received messages. If the file already exists, it will be overwritten (old file data will be lost). Use the store() method to record received messages into the file.

Parameters
  • file (str) – Absolute path of the file where the messages will be stored

  • fileFormat (FILEFORMAT or None) – Obsolete, you don't need to specify this argument anymore

receive() MessagePTP

Matches a response for the used message.

Returns

Listens to the bus until a message is received and returns this first message

Return type

MessagePTP

receive(timeout: int32) MessagePTP

Waits for the first response having the IP address destination equals to the IP address source of the sent message and return it. A timeout is specified to guarantee that the script can continue if no message is received in a certain time interval.

Parameters

timeout (int32) – Max time in milliseconds to wait for the response.

Returns

First message received from the bus or None in case no message is received.

Return type

MessagePTP

receive_list(timeout: int32) IReadOnlyList[MessagePTP]

Waits for any response having the IP address destination equals to the IP address source of sent message and return them all as a list. A timeout is specified to guarantee that the script can continue if no message is received in a certain time interval.

Parameters

timeout (int32) – Max time in milliseconds to wait for the response.

Returns

List of messages received from the bus during a given period of time.

Return type

IReadOnlyList[MessagePTP]

send() bool

Sends the message (the one used to call the method) through the Ethernet bus.

Returns

Returns True if the message is sent successfully. Otherwise, an exception will be thrown.

Return type

bool

set_all_bytes(all_packet: Array[uint8]) bool

Sets the content of the whole message from Ethernet layer, byte per byte.

Parameters

all_packet (Array[uint8]) – All packet to set.

Returns

True if the operation was successful, False otherwise.

Return type

bool

set_bytes(payload: Array[uint8])

Sets the content of the payload, byte per byte.

Parameters

payload (Array[uint8]) – Array of bytes to set.

start_capture(filter: Filter = None)

Used for online capture(capturing network traffic from an adapter). Used with callback function(on_message_received()) and stop_capture() method.

Parameters

filter (Filter) – Filter to use to narrow down packets to capture

start_capture(file: str, wait_eof: bool, filter: Filter = None)

Used for offline capture(reading packets from pcap or asc file). Used with callback function(on_message_received()) and stop_capture() method.

Parameters
  • file (str) – The trace file from where the messages will be read.

  • wait_eof (bool) – If True the function would block until all frames in the file are read. If False the function would read the frames in the background.

  • filter (Filter) – Filter to use to narrow down packets to capture

start_responding_machine()

With this function, it is possible to simulate an ECU. It captures packets and, for every received message, it calls is_request callback. If it returns True, then it calls the make_reply callback

stop_capture()

Stops capturing Ethernet messages, either directly from the bus or from a trace file (depending on the version used to start the capture).

stop_responding_machine()

Stops the responding machine activated with start_responding_machine.

store(file: str)

Writes the message into the trace file.

Parameters

file (str) – Path of the file where the messages will be stored.

store()

Writes the message into the trace file opened with open_writer(file).

tree_view() str

Gives the tree view of the message.

Returns

Tree view representation of the message.

Return type

str

@on_capture_start

The event is triggered when the capture of Ethernet messages is started. See start_capture .

@on_capture_stop

The event is triggered when the capture of Ethernet messages is stopped. See stop_capture .

@on_message_received(message: MessagePTP)

Event is triggered every time a message is read from the Ethernet bus or a trace file. See start_capture.

Parameters

message (MessagePTP) – The message object being handled.

capture_info

General information about the context in which the message was captured from. None if the message was not captured

Type

CaptureInfo

clock_identity

A universally unique numeric identifier for the clock.

Type

uint64 or None

control

Control field of the message.

Type

uint8

correction

Sub-nano-seconds accuracy transports clock correction.

Type

float

data_base

Takes the database object.

Type

Database

ethernet_header

Object containing all the information from the Ethernet header like the source and destination MAC addresses of the message.

Type

HeaderEthernet

flags

Flags bit of the PTP header.

Type

uint16

followup_tlv

The follow up TLV object.

Type

IFollowUpTlv

frame_number

Number of the frame received, in the context of all the ethernet traffic captured.

Type

int64

log_message_period

Log message period of the PTP protocol.

Type

int8

message_id

Gets the id of the message.

Type

uint8

message_length

Gets the length of the message.

Type

uint16

message_type

Gets the type of the message.

Type

PtpMessageTypes

message_type_specific

The message type specific of the message.

Type

uint32

minor_sdo_id

The minor SdoId of the message.

Type

uint8

minor_version_ptp

The minor version number of PTP.

Type

uint8

origin_timestamp

Gets the origin timestamp of the message.

Type

ITimeSpan

payload

Content, in bytes, of the payload of the message.

Type

Array[uint8]

requesting_port_id

The requesting port id.

Type

uint16 or None

requesting_port_identity

The requesting port identity.

Type

uint64 or None

sequence_id

Sequence identifier of the message.

Type

uint16

source_port_id

Source port identifier of the message.

Type

uint16

subdomain_number

Sub domain number of the message.

Type

uint8

timestamp

Timestamp of the message.

Type

decimal

transport_specific

Transport specific field of the message.

Type

uint8

version

Version of the PTP protocol.

Type

uint8

vlan_tag

Object containing all VLAN info.

Type

HeaderVlan