bbc

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2019 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package bbc describes a simple Bundle Broadcasting Connector to receive and transmit Bundles over a shared broadcasting medium, e.g., LoRa.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connector

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

Connector implements both a cla.ConvergenceReceiver and cla.ConvergenceSender and supplies the possibility to receive and send Bundles over a Modem. However, based on the broadcasting nature of this CLA, addressing specific recipients is not possible. Furthermore, attributing senders is also not possible.

func NewBundleBroadcastingConnector

func NewBundleBroadcastingConnector(addr string, permanent bool) (c *Connector, err error)

NewBundleBroadcastingConnector tries to create a new Bundle Broadcasting Connector based on an bbc URI.

  • bbc://rf95modem/dev/ttyUSB0 would open a rf95modem for /dev/ttyUSB0.
  • bbc://rf95modem/dev/ttyUSB0?frequency=865.4 would open a rf95modem at 865.4 MHz.
  • bbc://rf95modem/dev/ttyUSB0?mode=fast-short-range would open a rf95modem with the FAST+SHORT RANGE mode.
  • bbc://rf95modem/dev/ttyUSB0?frequency=865.23&mode=fast-short-range would be all together.

func NewConnector

func NewConnector(modem Modem, permanent bool) *Connector

NewConnector creates a new Connector, wrapping around the given Modem.

func (*Connector) Address

func (c *Connector) Address() string

func (*Connector) Channel

func (c *Connector) Channel() chan cla.ConvergenceStatus

func (*Connector) Close

func (c *Connector) Close()

func (*Connector) GetEndpointID

func (c *Connector) GetEndpointID() bundle.EndpointID

func (*Connector) GetPeerEndpointID

func (c *Connector) GetPeerEndpointID() bundle.EndpointID

func (*Connector) IsPermanent

func (c *Connector) IsPermanent() bool

func (*Connector) Send

func (c *Connector) Send(bndl *bundle.Bundle) error

func (*Connector) Start

func (c *Connector) Start() (error, bool)

func (*Connector) String

func (c *Connector) String() string

type Fragment

type Fragment struct {
	Payload []byte
	// contains filtered or unexported fields
}

Fragment is a part of a Transmission. Multiple Fragments represent an entire Transmission.

For identification, a tuple consisting of a transmission ID, a sequence number, a start bit, an end bit, and a fail bit is used. Because of memory reasons, the whole header has a size of two bytes. First the transmission ID with a length of one byte is given, followed by the two five long sequence number and the three flags, the start, end and fail bits.

The transmission ID is taken from the respective Transmission. If this Fragment is the first of a Transmission, the start bit is set to one. The same applies to the end bit for the last Fragment.

The five bit sequence number represents a simple binary counter, which is incremented for each Fragment. Missing Fragments can be detected this way

The header is followed by the payload. The total data can be as long as the particular MTU allows.

  0   1   2   3   4   5   6   7
+---+---+---+---+---+---+---+---+
|Transmission ID                |
+---+---+---+---+---+---+---+---+
|Seq. No            |SB |EB |FB |
+---+---+---+---+---+---+---+---+
|                               |
+            Payload            +
|                               |

func NewFragment

func NewFragment(transmissionId, sequenceNo byte, start, end, fail bool, payload []byte) Fragment

NewFragment creates a new Fragment based on the given arguments.

func ParseFragment

func ParseFragment(data []byte) (f Fragment, err error)

func (Fragment) Bytes

func (f Fragment) Bytes() []byte

Bytes creates a byte array for this Fragment.

func (Fragment) EndBit

func (f Fragment) EndBit() bool

EndBit checks if the end bit is set.

func (Fragment) FailBit added in v0.5.3

func (f Fragment) FailBit() bool

FailBit checks if the fail bit is set.

func (Fragment) ReportFailure added in v0.5.3

func (f Fragment) ReportFailure() Fragment

ReportFailure creates a failure Fragment based on the current one.

func (Fragment) SequenceNumber

func (f Fragment) SequenceNumber() byte

SequenceNumber returns the two bit sequence number.

func (Fragment) StartBit

func (f Fragment) StartBit() bool

StartBit checks if the start bit is set.

func (Fragment) String

func (f Fragment) String() string

func (Fragment) TransmissionID

func (f Fragment) TransmissionID() byte

TransmissionID returns the four bit transmission ID.

type IncomingTransmission

type IncomingTransmission struct {
	Transmission
	// contains filtered or unexported fields
}

IncomingTransmission are the incoming Transmissions from external sources.

func NewIncomingTransmission

func NewIncomingTransmission(f Fragment) (t *IncomingTransmission, err error)

NewIncomingTransmission creates a new IncomingTransmission from a Fragment with the start bit set.

func (*IncomingTransmission) Bundle

func (t *IncomingTransmission) Bundle() (bndl bundle.Bundle, err error)

func (*IncomingTransmission) ReadFragment

func (t *IncomingTransmission) ReadFragment(f Fragment) (finished bool, err error)

ReadFragment processes the next Fragment for this IncomingTransmission.

type Modem

type Modem interface {
	// Mtu returns the maximum transmission unit for this Modem.
	Mtu() int

	// Send broadcasts a Fragment over this Modem. This method might block.
	Send(Fragment) error

	// Receive waits for the next Fragment to be received. This method blocks.
	Receive() (Fragment, error)

	// Close this Modem. Furthermore, the Receive method should be interrupted.
	Close() error
}

Modem is the interface for possible broadcasting modems. Every Modem must be able to broadcast and receive packets resp. Fragments. The Mtu method indicates the maximum transmission unit (Mtu) for outgoing Fragments.

type OutgoingTransmission

type OutgoingTransmission struct {
	Transmission
	// contains filtered or unexported fields
}

OutgoingTransmission are the outgoing Transmissions to external sources.

func NewOutgoingTransmission

func NewOutgoingTransmission(transmissionID byte, bndl bundle.Bundle, mtu int) (t *OutgoingTransmission, err error)

NewOutgoingTransmission creates a new OutgoingTransmission for a Bundle.

func (*OutgoingTransmission) WriteFragment

func (t *OutgoingTransmission) WriteFragment() (f Fragment, finished bool, err error)

WriteFragment creates the next Fragment for an OutgoingTransmission.

type Rf95Modem

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

Rf95Modem is a Modem for transmitting and receiving Fragments by using LoRa over a rf95modem.

func NewRf95Modem

func NewRf95Modem(device string) (rfModem *Rf95Modem, err error)

NewRf95Modem creates a new Rf95Modem using a serial connection to the given device, e.g., /dev/ttyUSB0.

func (*Rf95Modem) Close

func (rfModem *Rf95Modem) Close() error

func (*Rf95Modem) Frequency

func (rfModem *Rf95Modem) Frequency(frequency float64) error

Frequency changes the internal rf95modem's frequency, specified in MHz.

func (*Rf95Modem) Mode

func (rfModem *Rf95Modem) Mode(mode rf95.ModemMode) error

Mode sets the internal rf95modem's modem config.

func (*Rf95Modem) Mtu

func (rfModem *Rf95Modem) Mtu() (mtu int)

func (*Rf95Modem) Receive

func (rfModem *Rf95Modem) Receive() (fragment Fragment, err error)

func (*Rf95Modem) Send

func (rfModem *Rf95Modem) Send(f Fragment) (err error)

func (*Rf95Modem) String

func (rfModem *Rf95Modem) String() string

type Transmission

type Transmission struct {
	TransmissionID byte
	Payload        []byte
	// contains filtered or unexported fields
}

Transmission allows the transmission of data, for example Bundles, between several endpoints.

Due to the maximum transmission unit (MTU), most Transmissions are likely to be fragmented. This results in Fragments. In order to keep the Fragments apart and to associate them with their Transmission, a transmission ID exists. Since the data size is very limited, the transmission ID is reduced to a byte. In order to avoid collisions, the transmission ID should be chosen as randomly or cleverly as possible.

In the following, a distinction is made between incoming and outgoing Transmissions: IncomingTransmission and OutgoingTransmission.

func (Transmission) IsFinished

func (t Transmission) IsFinished() bool

IsFinished indicates a finished Transmission.

func (Transmission) String

func (t Transmission) String() string

Jump to

Keyboard shortcuts

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