Compare commits

...

17 Commits
v.1.1 ... main

Author SHA1 Message Date
henry 8a80c8a609 Don't do this:
log.Println("[INFO] Reading version: ", string(buildBytes))
	} else {
		log.Println("[ERROR] Unable to read /opt/build_version.json file:", err)
Generates too much spam
2025-03-02 21:52:30 -08:00
henry 94940f66c9 syncing up BLE between Go and Python 2024-12-29 16:33:06 -08:00
Henry Seurer 88ddf0d9c0 Merge remote-tracking branch 'origin/main' 2024-12-17 20:36:55 -08:00
Henry Seurer 95d3db9196 Cleaning up BLE messages 2024-12-17 20:36:50 -08:00
henry b52c585528 Merge remote-tracking branch 'origin/main'
# Conflicts:
#	messages.go
2024-12-08 08:51:38 -08:00
henry 7810772cb5 Added Services 2024-12-08 08:50:20 -08:00
Henry Seurer a693a92115 Added Company Name 2024-11-21 09:42:31 -08:00
Henry Seurer 7b85cb03bc Typo Devices => Device 2024-11-21 09:25:13 -08:00
Henry Seurer 1de06f272c Manufacture Data Update 2024-11-21 09:17:20 -08:00
henry 6816ebdb73 Send one device at a time instead of an array. 2024-11-21 07:58:42 -08:00
Henry Seurer 2cc64731f1 change how we handle ble bluetooth messages. 2024-11-19 08:31:47 -08:00
henry 901972c7b8 Added BleCompany 2024-11-19 06:54:43 -08:00
henry cf518b3829 Added BleCompany 2024-11-19 06:50:02 -08:00
henry 56bf4a9523 tweak to message structure 2024-11-19 06:26:18 -08:00
henry 83e2486d6a updated ble message to support company. 2024-11-19 06:20:53 -08:00
henry e92ee83802 upgraded module and moved to git.bellaerba.dev/henry/farm-messages 2024-11-19 05:59:43 -08:00
Henry Seurer beca61081b Added go.mod 2024-11-18 13:58:04 -08:00
2 changed files with 30 additions and 43 deletions

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module git.bellaerba.dev/henry/farm-messages
go 1.23

View File

@ -28,7 +28,6 @@ package messages
import (
"encoding/json"
"log"
"math"
"math/rand"
"os"
@ -237,39 +236,39 @@ const maxInt64 = float64(math.MaxInt64 - 512)
func (t *ThrottleEntry) ForAttempt(attempt float64, minTime time.Duration, maxTime time.Duration) time.Duration {
// Zero-values are nonsensical, so we use
// them to apply defaults
min := t.Min
if min <= 0 {
min = minTime
minValue := t.Min
if minValue <= 0 {
minValue = minTime
}
max := t.Max
if max <= 0 {
max = maxTime
maxValue := t.Max
if maxValue <= 0 {
maxValue = maxTime
}
if min >= max {
if minValue >= maxValue {
// short-circuit
return max
return maxValue
}
factor := t.Factor
if factor <= 0 {
factor = 2
}
//calculate this duration
minFloat := float64(min)
minFloat := float64(minValue)
durationFloat := minFloat * math.Pow(factor, attempt)
if t.Jitter {
durationFloat = rand.Float64()*(durationFloat-minFloat) + minFloat
}
//ensure float64 won't overflow int64
if durationFloat > maxInt64 {
return max
return maxValue
}
dur := time.Duration(durationFloat)
//keep within bounds
if dur < min {
return min
if dur < minValue {
return minValue
}
if dur > max {
return max
if dur > maxValue {
return maxValue
}
return dur
}
@ -966,53 +965,38 @@ type StatusMessage struct {
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.
type BleServiceData struct {
UUID string `json:"uuid,omitempty"`
Name string `json:"name,omitempty"`
Data []byte `json:"data,omitempty"`
}
type BleAdvertisementPayload struct {
LocalName string `json:"localName,omitempty"`
Bytes []byte `json:"bytes,omitempty"`
ManufacturerData []ManufacturerDataElement `json:"manufacturerData,omitempty"`
type BleManufacturerData struct {
CompanyId uint16 `json:"company_id,omitempty"`
Name string `json:"name,omitempty"`
Data []byte `json:"data,omitempty"`
}
type BleDevice struct {
Address string `json:"address,omitempty"`
RSSI int16 `json:"rssi,omitempty"`
Name string `json:"name,omitempty"`
Advertisement BleAdvertisementPayload `json:"advertisement,omitempty"`
Address string `json:"address,omitempty"`
RSSI int16 `json:"rssi,omitempty"`
Name string `json:"name,omitempty"`
ManufacturerData []BleManufacturerData `json:"companies,omitempty"`
}
type BleDevicesMap map[string]BleDevice
type BleDevices []BleDevice
type BleAdvertisementMessage struct {
Header MessageHeader `json:"header,omitempty"`
Devices BleDevices `json:"devices,omitempty"`
Header MessageHeader `json:"header,omitempty"`
Device BleDevice `json:"device,omitempty"`
}
// noinspection GoUnusedExportedFunction
func CreateHeader(status int, location string) MessageHeader {
// Do we have a build version?
//
var build BuildVersion
buildBytes, err := os.ReadFile("/opt/build_version.json")
if err == nil {
err = json.Unmarshal(buildBytes, &build)
log.Println("[INFO] Reading version: ", string(buildBytes))
} else {
log.Println("[ERROR] Unable to read /opt/build_version.json file:", err)
}
// Build Message Header