media

package
v0.0.0-...-26ed527 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2022 License: CC0-1.0 Imports: 3 Imported by: 0

Documentation

Overview

Package media provides the OSI media layers from section 1 & 2.

Index

Constants

View Source
const (
	// format class 1.1, section 1, subclause 6.2.4.1, rule R4
	FT11IdleBits = 22
	// format class 1.2, section 1, subclause 6.2.4.2.1, rule R4
	FT12IdleBits = 33
	// format class 2, section 1, subclause 6.2.4.3.1, rule R5
	FT2IdleBits = 48
	// format class 3, section 1, subclause 6.2.4.4.1, rule R5
	FT3IdleBits = 54
)

Upon detecting an error, a minimum interval of line idle bits is required between packets, depending on the type.

View Source
const (
	DataSize = 8   // bits in charater
	StopBits = 1   // character termination
	Parity   = 'E' // even check bit
)

Fixed serial configuration parameters defined in section 1. See also companion standard 101, annex 1.1 — UART definition.

View Source
const FrameBits = 1 + DataSize + 1 + StopBits

FrameBits is the number of bits per character needed at the physical layer.

Variables

View Source
var ErrAddrFit = errors.New("part5: station address doesn't fit system-specific octet size")

Signals Addr is out of bounds.

View Source
var ErrCheck = errors.New("part5: checksum, constant or redundant value mismatch in packet")

ErrCheck signals integrity verification failure.

View Source
var ErrDataFit = errors.New("part5: user data size exceeds packet capacity or system limit")

ErrDataFit signals user data out of bounds.

Functions

This section is empty.

Types

type Addr

type Addr uint16

Addr is a secondary station address. The actual presence and size is system-dependent. When not in use (with size 0) then GlobalAddr is the mandatory value in all cases.

The reference may be to a single station, a group of stations or all other stations. Group addresses should be defined by agreements between users and vendors.

const GlobalAddr Addr = 0xffff

GlobalAddr is the broadcast address. Use this value on 1 octet addressing systems too [not 255]. This value is applicable in 3 cases, namely (1) for single (control) character frames (2) for systems with addressing disabled (3) for unbalanced systems in combination with

func (Addr) Network

func (a Addr) Network() string

Network honors the net.Addr interface.

func (Addr) String

func (a Addr) String() string

String honors the net.Addr interface.

type Ctrl

type Ctrl byte

Ctrl is the control field.

const (
	// Function codes from section 2, table 1 & 3.
	Reset     Ctrl = iota // 0: reset of remote link
	ResetProc             // 1: reset of user process
	Test                  // 2: test function for link (for balanced systems)
	Give                  // 3: user data: send/confirm expected
	Toss                  // 4: user data: send/no reply expected

	AvailReq  // 8: poll access demand (for unbalanced systems)
	StatusReq // 9: request status of link
	Class1Req // 10: request submission of user data (for unbalanced systems)
	Class2Req // 11: request submission of user data (for unbalanced systems)

	// Flipped on every frame when FrameCountValidFlag to delete losses and duplications.
	FrameCountFlag Ctrl = 1 << 5
	// Marks the applicability of FrameCountFlag for Test, Give, Class1Req and Class2Req.
	FrameCountValidFlag Ctrl = 1 << 4
)

Protocol-control from primary (initiating) stations. See section 2, clause 5.1.2 & 6.1.2.

const (
	// Function codes from section 2, table 2 & 4.
	Ack  Ctrl = iota // 0: positive acknowledgement
	Nack             // 1: message not accepted, link busy

	Data   // 8: submission of user data (for unbalanced systems)
	NoData // 9: no pending user data (for unbalanced systems)

	OK // 11: status of link or access demand

	Down   // 14: link service not functioning
	NoImpl // 15: link service not implemented

	// Data flow control: further messages may cause buffer overflow.
	OverflowFlag Ctrl = 1 << 4

	// With unbalanced transmission, secondary stations [slaves] may report
	// the availability of class 1 data with this flag.
	XSDemandFlag Ctrl = 1 << 5
)

Protocol-control from secondary (responding) stations. See section 2, clause 5.1.2 & 6.1.2. For permissible combinations see companion standard 101, table 3 & 4.

const FromPrimaryFlag Ctrl = 1 << 6

FromPrimaryFlag marks the frame direction.

const FuncMask Ctrl = 1<<4 - 1

FuncMask gets the function code from the control field.

type FT

type FT interface {
	Encode(io.Writer, Packet) error
	Decode(io.Reader) (Packet, error)
}

FT is a format class for Packet encoding.

func NewFT12

func NewFT12(addrSize, maxSize int, singleChar1, singleChar2 Ctrl) FT

NewFT12 returns a new codec for format class FT 1.2, integrity class Ⅱ, Hamming distance 4.

The number of octets for station addresses must be in [0, 2]. When disabled with 0, packets use GlobalAddr exclusively.

The fuction of single (control) character Ⅰ (0xE5) and Ⅱ (0xA2) depends on the system. Character Ⅰ is usually Ack. Don't forget to set FromPrimaryFlag where applicable. Both characters are decoded as a packet with GlobalAddr in place.

WARNING! The implementation reuses one data buffer which makes operation efficient. The user data in packets can only be used until the next call.

See section 2, subclause 3.2 and companion standard 101, annex 1.2.

type Packet

type Packet struct {
	Addr Addr   // address of secondary station
	Ctrl Ctrl   // protocol-control information
	Data []byte // optional user data
}

Packet is an network layer PDU (protocol data unit).

Jump to

Keyboard shortcuts

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