framerinterface

package
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 31, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseStats

type BaseStats struct {
	FramesReceivedOversized     uint64
	FramesReceivedZeroLength    uint64
	FramesReceivedWrongChecksum uint64
	FramesReceivedValid         uint64

	FramesSent uint64

	BytesSent        uint64
	BytesSentEscaped uint64

	BytesReceived        uint64
	BytesReceivedEscaped uint64
}

BaseStats contains statistics about the framer operating performance. The values containing the word Received are consistent during execution of the FramerReceivedPacketHandler. The values containing the word Sent are consistent when no SendPacket is executing

func (*BaseStats) CopyBaseStatsAtomic

func (s *BaseStats) CopyBaseStatsAtomic() BaseStats

CopyBaseStatsAtomic makes a copy of BaseStats using atomic access

type Framer

type Framer interface {
	SendPacket(payload []byte) (int64, error)
	SetPort(port io.ReadWriter) error
	GetStats() BaseStats
	Run(receivedPacket FramerReceivedPacketHandler) error
}

Framer is a generic interface to send packets over a stream

type FramerOption

type FramerOption int

FramerOption defines the different options that can be provided. Not every framer supports all options. All options are optional and sane defaults are used.

const (
	// OptionRxIgnore contains an array with 256 booleans. If the value corresponding to a received character is true, the byte is dropped
	OptionRxIgnore FramerOption = 0x0

	// OptionTxEscape contains an array with 256 booleans. If the value corresponding to a character is true, it will be escaped on TX
	OptionTxEscape FramerOption = 0x1

	// OptionTxRxAreEqual can be set to false if TX and RX use different Escape/Ignore maps. This will disable some sanity checks
	OptionTxRxAreEqual FramerOption = 0x4

	// OptionCRCParam contains a *multicrc.Params indicating the CRC type that is added. Default: no crc
	OptionCRCParam FramerOption = 0x2

	// OptionMaxPacketLen contains an integer which specifies the maximum packet length. If <=0 the length is unlimited.
	OptionMaxPacketLen FramerOption = 0x3

	// OptionByteFrameStart contains a byte indicating the start of frame delimited
	OptionByteFrameStart FramerOption = 0x100

	// OptionByteFrameEnd contains a byte indicating the frame termination symbol
	OptionByteFrameEnd FramerOption = 0x101

	// OptionByteEscape contains a byte indicating the escape symbol
	OptionByteEscape FramerOption = 0x102

	// OptionByteEscapeXOR contains a byte indicating the escape XOR value
	OptionByteEscapeXOR FramerOption = 0x103
)

type FramerOptions

type FramerOptions struct {
	// contains filtered or unexported fields
}

FramerOptions contains options passed to the framer constructor

func DefaultFramerOptions

func DefaultFramerOptions() *FramerOptions

DefaultFramerOptions returns the default framer options (note that this is currently a nil value)

func (*FramerOptions) Get

func (o *FramerOptions) Get(t FramerOption) (interface{}, bool)

Get returns the value of a given option

func (*FramerOptions) GetBool

func (o *FramerOptions) GetBool(t FramerOption, defVal bool) bool

GetBool returns the boolean value of a given option, returning a specified default value if it is not found.

func (*FramerOptions) GetDefault

func (o *FramerOptions) GetDefault(t FramerOption, defVal interface{}) interface{}

GetDefault returns the value of a given option, returning a specified default value if it is not found

func (*FramerOptions) GetInt

func (o *FramerOptions) GetInt(t FramerOption, defVal int) int

GetInt returns the integer value of a given option, returning a specified default value if it is not found.

func (*FramerOptions) Set

func (o *FramerOptions) Set(t FramerOption, value interface{}) *FramerOptions

Set modifies the specified option with the given value

type FramerReceivedPacketHandler

type FramerReceivedPacketHandler func(payload []byte, metadata *PacketMetadata) error

FramerReceivedPacketHandler is the type of callback function invoked when a packet is received

type PacketMetadata

type PacketMetadata struct {
	//RxTime is a timestamp when the first byte was received
	RxTime time.Time
}

PacketMetadata contains information about the packet passed to the receive handler

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL