Compare commits

..

No commits in common. "main" and "v1.0.1" have entirely different histories.
main ... v1.0.1

2 changed files with 35 additions and 16 deletions

15
go.mod
View File

@ -1,3 +1,18 @@
module git.bellaerba.dev/henry/farm-messages module git.bellaerba.dev/henry/farm-messages
go 1.23 go 1.23
require tinygo.org/x/bluetooth v0.10.0
require (
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/saltosystems/winrt-go v0.0.0-20241030114511-98be01919aa6 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/soypat/cyw43439 v0.0.0-20241116210509-ae1ce0e084c5 // 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-20240901140349-27cbe9d986eb // indirect
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f // indirect
golang.org/x/sys v0.27.0 // indirect
)

View File

@ -28,12 +28,14 @@ package messages
import ( import (
"encoding/json" "encoding/json"
"log"
"math" "math"
"math/rand" "math/rand"
"os" "os"
"strings" "strings"
"sync/atomic" "sync/atomic"
"time" "time"
"tinygo.org/x/bluetooth"
) )
type BuildVersion struct { type BuildVersion struct {
@ -965,38 +967,40 @@ type StatusMessage struct {
States map[string]bool `json:"states,omitempty"` States map[string]bool `json:"states,omitempty"`
} }
type BleServiceData struct { type BleAdvertisementPayload struct {
UUID string `json:"uuid,omitempty"` LocalName string `json:"localName,omitempty"`
Name string `json:"name,omitempty"` Bytes []byte `json:"bytes,omitempty"`
Data []byte `json:"data,omitempty"` ManufacturerData []bluetooth.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 { type BleDevice struct {
Address string `json:"address,omitempty"` Address string `json:"address,omitempty"`
RSSI int16 `json:"rssi,omitempty"` RSSI int16 `json:"rssi,omitempty"`
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
ManufacturerData []BleManufacturerData `json:"companies,omitempty"` Advertisement BleAdvertisementPayload `json:"advertisement,omitempty"`
} }
type BleDevicesMap map[string]BleDevice
type BleDevices []BleDevice
type BleAdvertisementMessage struct { type BleAdvertisementMessage struct {
Header MessageHeader `json:"header,omitempty"` Header MessageHeader `json:"header,omitempty"`
Device BleDevice `json:"device,omitempty"` Devices BleDevices `json:"devices,omitempty"`
} }
// noinspection GoUnusedExportedFunction // noinspection GoUnusedExportedFunction
func CreateHeader(status int, location string) MessageHeader { func CreateHeader(status int, location string) MessageHeader {
// Do we have a build version? // Do we have a build version?
// //
var build BuildVersion var build BuildVersion
buildBytes, err := os.ReadFile("/opt/build_version.json") buildBytes, err := os.ReadFile("/opt/build_version.json")
if err == nil { if err == nil {
err = json.Unmarshal(buildBytes, &build) 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 // Build Message Header