linklayerprotocol

package module
v0.0.0-...-1b23af5 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2025 License: MIT Imports: 1 Imported by: 0

README

Protocol for simple simplex/duplex communication.

  • CRC to check data integrity
  • drop frame in silent mode when crc is bad
  • build/unbuild frame byte after byte
  • transfer payload to another party

Frame: Start / Payload_Length / Payload / CRC16

Communication layer between bits and upper layer.

This package build and unbuild frames. For communication transfer, use another package for serial_port on computer or uart on microcontroller (TinyGo).

Thirdparty can easily call LinkProtocol.SendByte(). LinkProtocol call ComSender.send() to send bytes over serial communication.

Thirparty can easily call LinkProtocol.ReceiveByte() when serial com has new data. LinkProtocol call AppReceiver.receive() interface to send payload to the upper layer.

C lib available here.

Install

go get github.com/dufguix/simple-data-link-protocol_golib

import (
	"time"
	sdlp "github.com/dufguix/simple-data-link-protocol_golib"
)

TODO

  • provide examples in readme

Documentation

Index

Constants

View Source
const (
	StartByte      uint8 = 0x7E
	MaxPayloadSize uint8 = 10
	OverheadSize   uint8 = 4 // start, length, crc16
	MaxFrameSize   uint8 = MaxPayloadSize + OverheadSize
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AppReceiver

type AppReceiver interface {
	Receive(payload []uint8)
}

type ComSender

type ComSender interface {
	Send(bytes []uint8)
}

type Crc16

type Crc16 struct {
	Polynomial uint16 // Polynomial used in this CRC calculation
	StartMask  uint16 // bit shift register init
	EndMask    uint16 // xor-out, applied before returning result
	// contains filtered or unexported fields
}

REFIN and REFOUT hardcoded

func (*Crc16) Compute

func (crc *Crc16) Compute(data []uint8) uint16

Compute from init to result This method don't use Crc.Value member.

func (*Crc16) ComputeReflect

func (crc *Crc16) ComputeReflect(data []uint8) uint16

Compute from init to result in reflect mode (REFIN and REFOUT) This method don't use Crc.Value member.

func (*Crc16) Init

func (crc *Crc16) Init()

func (*Crc16) Result

func (crc *Crc16) Result() uint16

func (*Crc16) Update

func (crc *Crc16) Update(data uint8)

func (*Crc16) UpdateReflect

func (crc *Crc16) UpdateReflect(data uint8)

type LinkProtocol

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

func NewDefaultLinkProtocol

func NewDefaultLinkProtocol(lowerLayer ComSender, upperLayer AppReceiver, crc Crc16) LinkProtocol

func (*LinkProtocol) Init

func (lp *LinkProtocol) Init(lowerLayer ComSender, upperLayer AppReceiver, crc Crc16)

func (*LinkProtocol) ReceiveByte

func (lp *LinkProtocol) ReceiveByte(currentByte uint8)

func (*LinkProtocol) Send

func (lp *LinkProtocol) Send(bytes []uint8)

Jump to

Keyboard shortcuts

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