Added go.mod
This commit is contained in:
parent
c7e4bfa581
commit
beca61081b
|
@ -0,0 +1,18 @@
|
||||||
|
module farm-messages
|
||||||
|
|
||||||
|
go 1.23
|
||||||
|
|
||||||
|
require tinygo.org/x/bluetooth v0.10.0
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/go-ole/go-ole v1.2.6 // indirect
|
||||||
|
github.com/godbus/dbus/v5 v5.1.0 // indirect
|
||||||
|
github.com/saltosystems/winrt-go v0.0.0-20240509164145-4f7860a3bd2b // indirect
|
||||||
|
github.com/sirupsen/logrus v1.9.3 // indirect
|
||||||
|
github.com/soypat/cyw43439 v0.0.0-20240609122733-da9153086796 // indirect
|
||||||
|
github.com/soypat/seqs v0.0.0-20240527012110-1201bab640ef // indirect
|
||||||
|
github.com/tinygo-org/cbgo v0.0.4 // indirect
|
||||||
|
github.com/tinygo-org/pio v0.0.0-20231216154340-cd888eb58899 // indirect
|
||||||
|
golang.org/x/exp v0.0.0-20230728194245-b0cb94b80691 // indirect
|
||||||
|
golang.org/x/sys v0.11.0 // indirect
|
||||||
|
)
|
48
messages.go
48
messages.go
|
@ -35,6 +35,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
"tinygo.org/x/bluetooth"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BuildVersion struct {
|
type BuildVersion struct {
|
||||||
|
@ -237,39 +238,39 @@ const maxInt64 = float64(math.MaxInt64 - 512)
|
||||||
func (t *ThrottleEntry) ForAttempt(attempt float64, minTime time.Duration, maxTime time.Duration) time.Duration {
|
func (t *ThrottleEntry) ForAttempt(attempt float64, minTime time.Duration, maxTime time.Duration) time.Duration {
|
||||||
// Zero-values are nonsensical, so we use
|
// Zero-values are nonsensical, so we use
|
||||||
// them to apply defaults
|
// them to apply defaults
|
||||||
min := t.Min
|
minValue := t.Min
|
||||||
if min <= 0 {
|
if minValue <= 0 {
|
||||||
min = minTime
|
minValue = minTime
|
||||||
}
|
}
|
||||||
max := t.Max
|
maxValue := t.Max
|
||||||
if max <= 0 {
|
if maxValue <= 0 {
|
||||||
max = maxTime
|
maxValue = maxTime
|
||||||
}
|
}
|
||||||
if min >= max {
|
if minValue >= maxValue {
|
||||||
// short-circuit
|
// short-circuit
|
||||||
return max
|
return maxValue
|
||||||
}
|
}
|
||||||
factor := t.Factor
|
factor := t.Factor
|
||||||
if factor <= 0 {
|
if factor <= 0 {
|
||||||
factor = 2
|
factor = 2
|
||||||
}
|
}
|
||||||
//calculate this duration
|
//calculate this duration
|
||||||
minFloat := float64(min)
|
minFloat := float64(minValue)
|
||||||
durationFloat := minFloat * math.Pow(factor, attempt)
|
durationFloat := minFloat * math.Pow(factor, attempt)
|
||||||
if t.Jitter {
|
if t.Jitter {
|
||||||
durationFloat = rand.Float64()*(durationFloat-minFloat) + minFloat
|
durationFloat = rand.Float64()*(durationFloat-minFloat) + minFloat
|
||||||
}
|
}
|
||||||
//ensure float64 won't overflow int64
|
//ensure float64 won't overflow int64
|
||||||
if durationFloat > maxInt64 {
|
if durationFloat > maxInt64 {
|
||||||
return max
|
return maxValue
|
||||||
}
|
}
|
||||||
dur := time.Duration(durationFloat)
|
dur := time.Duration(durationFloat)
|
||||||
//keep within bounds
|
//keep within bounds
|
||||||
if dur < min {
|
if dur < minValue {
|
||||||
return min
|
return minValue
|
||||||
}
|
}
|
||||||
if dur > max {
|
if dur > maxValue {
|
||||||
return max
|
return maxValue
|
||||||
}
|
}
|
||||||
return dur
|
return dur
|
||||||
}
|
}
|
||||||
|
@ -966,23 +967,10 @@ type StatusMessage struct {
|
||||||
States map[string]bool `json:"states,omitempty"`
|
States map[string]bool `json:"states,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ManufacturerDataElement struct {
|
|
||||||
// The company ID, which must be one of the assigned company IDs.
|
|
||||||
// The full list is in here:
|
|
||||||
// https://www.bluetooth.com/specifications/assigned-numbers/
|
|
||||||
// The list can also be viewed here:
|
|
||||||
// https://bitbucket.org/bluetooth-SIG/public/src/main/assigned_numbers/company_identifiers/company_identifiers.yaml
|
|
||||||
// The value 0xffff can also be used for testing.
|
|
||||||
CompanyID uint16 `json:"company-id,omitempty"`
|
|
||||||
|
|
||||||
// The value, which can be any value but can't be very large.
|
|
||||||
Data []byte `json:"data,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type BleAdvertisementPayload struct {
|
type BleAdvertisementPayload struct {
|
||||||
LocalName string `json:"localName,omitempty"`
|
LocalName string `json:"localName,omitempty"`
|
||||||
Bytes []byte `json:"bytes,omitempty"`
|
Bytes []byte `json:"bytes,omitempty"`
|
||||||
ManufacturerData []ManufacturerDataElement `json:"manufacturerData,omitempty"`
|
ManufacturerData []bluetooth.ManufacturerDataElement `json:"manufacturerData,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type BleDevice struct {
|
type BleDevice struct {
|
||||||
|
|
Loading…
Reference in New Issue