util

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2020 License: MIT Imports: 20 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 = 150
	// 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 CatchErrs added in v0.0.7

func CatchErrs(fn func() error) error

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 EncodeDataAsPackets added in v0.0.7

func EncodeDataAsPackets(payload []byte, secret string) ([][]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 PacketBuffer added in v0.0.7

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

func NewPacketBuffer added in v0.0.7

func NewPacketBuffer(secret string) *PacketBuffer

func (*PacketBuffer) Set added in v0.0.7

func (buff *PacketBuffer) Set(packet []byte) ([]byte, error)

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