emu

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventNodeAdded           = Event("NodeAdded")
	EventNodeRemoved         = Event("NodeRemoved")
	EventNodeUpdated         = Event("NodeUpdated")
	EventCollision           = Event("NodeCollision")
	EventSending             = Event("NodeSending")
	EventReceived            = Event("NodeReceived")
	EventPayloadSizeExceeded = Event("NodePayloadSizeExceeded")
)
View Source
const (
	// CollisionDecodeableLevel describes the dB strength a received packets needs to have compared
	// to other packets it's collides with. If this is the case the packet can be decoded
	// even while collision.
	CollisionDecodeableLevel = 6

	// MaxPacketLen specifies the maximum length a single LoRa packet can be.
	MaxPacketLen = 255
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Emulator

type Emulator struct {
	sync.RWMutex
	sync.WaitGroup
	// contains filtered or unexported fields
}

Emulator represents a LoRa emulator.

func New

func New(freq float64, gamma float64, refDist float64, kmRange float64, config lora.PacketConfig) *Emulator

New creates a new emulator with the given frequency, gamma (which is the Log-Distance Path Loss exponent) and LoRa packet config.

func (*Emulator) AddNode

func (emu *Emulator) AddNode(node Node) error

AddNode adds a node to the simulation.

func (*Emulator) Clear

func (emu *Emulator) Clear()

Clear removes all nodes.

func (*Emulator) GetFreq

func (emu *Emulator) GetFreq() float64

func (*Emulator) GetGamma

func (emu *Emulator) GetGamma() float64

func (*Emulator) GetKMRange

func (emu *Emulator) GetKMRange() float64

func (*Emulator) GetNode

func (emu *Emulator) GetNode(id string) Node

GetNode gets a node by id.

func (*Emulator) GetRefDist

func (emu *Emulator) GetRefDist() float64

func (*Emulator) GetStartTime

func (emu *Emulator) GetStartTime() int64

func (*Emulator) HasNode

func (emu *Emulator) HasNode(id string) bool

HasNode checks if a node with the given id exists.

func (*Emulator) NodeIDs

func (emu *Emulator) NodeIDs() []string

NodeIDs returns all the node ids as strings.

func (*Emulator) Nodes

func (emu *Emulator) Nodes() []Node

Nodes returns all the Nodes as a copy.

func (*Emulator) RemoveNode

func (emu *Emulator) RemoveNode(id string) error

RemoveNode removes a node by id.

func (*Emulator) SendMessage

func (emu *Emulator) SendMessage(id string, msg []byte) error

SendMessage starts the data sending for a given node by id.

func (*Emulator) SetIgnoreCollision

func (emu *Emulator) SetIgnoreCollision(state bool)

SetIgnoreCollision enables or disables the collision detection.

func (*Emulator) SetLogger

func (emu *Emulator) SetLogger(logger logr.Logger)

SetLogger sets the logger. This will log additional information that are not relevant for the trace.

func (*Emulator) SetOnEvent

func (emu *Emulator) SetOnEvent(onEvent OnEventFn)

SetOnEvent sets the callback that should be called if a event happens in the simulator.

func (*Emulator) SetOnReceived

func (emu *Emulator) SetOnReceived(onReceived OnReceivedFn)

SetOnReceived sets the callback that should be called if a simulated node receives a message.

func (*Emulator) SetSNROffset

func (emu *Emulator) SetSNROffset(value int)

SetSNROffset sets a static offset that will be added to the RSSI and the node SNR (SNR = RSSI + Node.SNR + SNROffset).

func (*Emulator) SetTimeScaling

func (emu *Emulator) SetTimeScaling(value int) error

SetTimeScaling (warning: experimental!) lets the simulator run with a time speedup. A value of 10 would mean that 1 second only takes 100ms.

func (*Emulator) SetTraceWriter

func (emu *Emulator) SetTraceWriter(writer io.Writer)

SetTraceWriter sets the writer for the trace logs. If no writer was set no trace logs will be emitted.

func (*Emulator) UpdateNode

func (emu *Emulator) UpdateNode(id string, updater func(node *Node) error) error

UpdateNode updates a node by a given id. The updater function will be called with the node and any changes to the node in that function will be set to the emulator.

Don't call any other emulator functions in the updater to avoid deadlocks!

type Event

type Event string

type LogEntry

type LogEntry struct {
	Time   time.Time `json:"time"`
	Event  Event     `json:"event"`
	NodeID string    `json:"nodeId"`
	Data   any       `json:"data"`
}

LogEntry represents an entry in the trace log of the emulator.

type Mobility

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

Mobility represents a mobility manager that executes a set of mobility commands from the ns-2 format on a LoRaEMU instance.

func NewMobility

func NewMobility(emu *Emulator, commands []mobility.Command) *Mobility

NewMobility creates a new mobility manager linked to an emu with the given commands.

func (*Mobility) Done

func (m *Mobility) Done()

Done waits for the simulation to finish.

func (*Mobility) GetPause

func (m *Mobility) GetPause() bool

func (*Mobility) SetLoop

func (m *Mobility) SetLoop(val bool) *Mobility

SetLoop changes if the mobility simulation should restart after finishing. Default is false.

func (*Mobility) SetPause

func (m *Mobility) SetPause(val bool)

func (*Mobility) SetTickrate

func (m *Mobility) SetTickrate(tickrate float64) *Mobility

SetTickrate sets the ticks per seconds rate at which the sub-steps of movement will be calculated. 10 means 10 sub-steps per second, 30 means 30 sub-steps per second and so on.

func (*Mobility) SetTimeScaling

func (m *Mobility) SetTimeScaling(value int) error

SetTimeScaling ets the mobility run with a time speedup. A value of 10 would mean that 1 second only takes 100ms.

func (*Mobility) Start

func (m *Mobility) Start()

Start starts the simulation.

func (*Mobility) Stop

func (m *Mobility) Stop()

Stop requests the stop of the simulation. You need to .Wait() after this to ensure graceful shutdown.

type Node

type Node struct {
	ID     string                 `json:"id"`
	Online bool                   `json:"online"`
	X      float64                `json:"x"`
	Y      float64                `json:"y"`
	Z      float64                `json:"z"`
	TXGain float64                `json:"txGain"`
	RXSens float64                `json:"rxSens"`
	SNR    int                    `json:"snr"`
	Icon   string                 `json:"icon"`
	Meta   map[string]interface{} `json:"meta"`
	// contains filtered or unexported fields
}

Node represents a LoRa device in the emulator.

func (Node) DistanceTo

func (n Node) DistanceTo(other Node) float64

func (Node) LatLng

func (n Node) LatLng() (float64, float64)

func (Node) PathLoss

func (n Node) PathLoss(other Node, distanceRef float64, gamma float64, freq float64) float64

func (Node) Valid

func (n Node) Valid() error

type OnEventFn

type OnEventFn func(event Event, node Node, data any)

type OnReceivedFn

type OnReceivedFn func(node Node, packet RxPacket)

type RxPacket

type RxPacket struct {
	RSSI     int     `json:"rssi"`
	SNR      int     `json:"snr"`
	Data     []byte  `json:"data"`
	RecvTime int64   `json:"recvTime"`
	Airtime  float64 `json:"airtime"`
}

RxPacket represents a received packet with its corresponding signal information.

Jump to

Keyboard shortcuts

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