util

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2020 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MTU is used for the max size of bytes allowed for data transmittion between ble client and server
	MTU = 256
	// MainServiceUUID represents UUID for ble service for all ble characteristics
	MainServiceUUID = "00010000-0001-1000-8000-00805F9B34FB"
	// ClientStateUUID represents UUID for ble characteristic which handles writes from client to server for client state changes
	ClientStateUUID = "00010000-0003-1000-8000-00805F9B34FB"
	// TimeSyncUUID represents UUID for ble clients to time sync with ble server
	TimeSyncUUID = "00010000-0004-1000-8000-00805F9B34FB"
	// ClientLogUUID represents UUID for ble clients to write logs to
	ClientLogUUID = "00010000-0006-1000-8000-00805F9B34FB"
	// WriteForwardCharUUID represents UUID for ble characteristic which handles forwarding of writes
	WriteForwardCharUUID = "00030000-0003-1000-8000-00805F9B34FB"
	// StartReadForwardCharUUID represents UUID for ble characteristic which handles forwarding of reads (start)
	StartReadForwardCharUUID = "00030000-0004-1000-8000-00805F9B34FB"
	// EndReadForwardCharUUID represents UUID for ble characteristic which handles forwarding of reads (end)
	EndReadForwardCharUUID = "00030000-0006-1000-8000-00805F9B34FB"
	// ReadRssiMapCharUUID represents UUID for ble characteristic which is a getter for rssi map data
	ReadRssiMapCharUUID = "00030000-0005-1000-8000-00805F9B34FB"
	// ReadConnectionGraphUUID represents UUID for ble characteristic which is a getter for connection graph data
	ReadConnectionGraphUUID = "00030000-0007-1000-8000-00805F9B34FB"
)

Variables

This section is empty.

Functions

func AddrEqualAddr

func AddrEqualAddr(a string, b string) bool

func Decode added in v0.0.5

func Decode(data []byte, x interface{}) error

func Decrypt

func Decrypt(data []byte, passphrase string) ([]byte, error)

Decrypt will decrypt data with passphrase

func Encode added in v0.0.5

func Encode(x interface{}) ([]byte, error)

func Encrypt

func Encrypt(data []byte, passphrase string) ([]byte, error)

Encrypt will encrypt data with passphrase

func MakeINFContext

func MakeINFContext() context.Context

func Optimize

func Optimize(fn func() error) error

func ShortestPath

func ShortestPath(rssiMap map[string]map[string]int, forwarderAddr string, serverAddr string) ([]string, error)

ShortestPath tells forwarder which path to take to forward packets to server

func Throw

func Throw(up error)

func Timeout

func Timeout(fn func() error, duration time.Duration) error

Timeout is a utility method used to timeout function calls after the specified interval

func UnixTS

func UnixTS() int64

UnixTS returns the current unix (epoch) timestamp in milliseconds

func UuidEqualStr

func UuidEqualStr(u ble.UUID, s string) bool

func UuidToStr

func UuidToStr(u ble.UUID) string

Types

type BLEPacket

type BLEPacket struct {
	RawData  []byte
	Guid     string
	Index    int
	Total    int
	Checksum string
}

BLEPacket is a struct used for packaging data within MTU chunks

func (*BLEPacket) Data

func (p *BLEPacket) Data() ([]byte, error)

Data will serialize BLEPacket to []byte

type PacketAggregator

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

PacketAggregator is a struct with function to get constructed & validated data

func NewPacketAggregator

func NewPacketAggregator() PacketAggregator

NewPacketAggregator makes new struct for packet aggregation

func (*PacketAggregator) AddData

func (pa *PacketAggregator) AddData(data []byte) (string, error)

AddData will take input bytes, get packets from bytes, and call AddPacketFromPacketBytes black box

func (*PacketAggregator) AddPacketFromPacketBytes

func (pa *PacketAggregator) AddPacketFromPacketBytes(packetBytes []byte) (string, error)

AddPacketFromPacketBytes will take the input bytes, parse to packet struct, and add to store (returns guid)

func (*PacketAggregator) HasDataFromPacketStream

func (pa *PacketAggregator) HasDataFromPacketStream(guid string) bool

HasDataFromPacketStream returns true if all packet data is in correctly for a given guid stream

func (*PacketAggregator) PopAllDataFromPackets

func (pa *PacketAggregator) PopAllDataFromPackets(guid string) ([]byte, error)

PopAllDataFromPackets aggregates all the packets and confirms if data accurate

func (*PacketAggregator) PopPacketDataFromStream

func (pa *PacketAggregator) PopPacketDataFromStream(guid string) ([]byte, bool, error)

PopPacketDataFromStream returns next packet in (index) order in the given guid stream

type TimeSync

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

TimeSync is a utility struct for syncing time with a given source of truth

func NewTimeSync

func NewTimeSync(initTS int64) TimeSync

NewTimeSync generates the utility struct for time syncing

func (*TimeSync) TS

func (t *TimeSync) TS() int64

TS returns the current unix (epoch) timestamp in milliseconds (offset by diff from source of truth)

type TryCatchBlock

type TryCatchBlock struct {
	Try     func()
	Catch   func(error)
	Finally func()
}

func (TryCatchBlock) Do

func (tcf TryCatchBlock) Do()

Jump to

Keyboard shortcuts

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