Compare commits
13 Commits
Author | SHA1 | Date |
---|---|---|
|
8a80c8a609 | |
|
94940f66c9 | |
|
88ddf0d9c0 | |
|
95d3db9196 | |
|
b52c585528 | |
|
7810772cb5 | |
|
a693a92115 | |
|
7b85cb03bc | |
|
1de06f272c | |
|
6816ebdb73 | |
|
2cc64731f1 | |
|
901972c7b8 | |
|
cf518b3829 |
15
go.mod
15
go.mod
|
@ -1,18 +1,3 @@
|
||||||
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
|
|
||||||
)
|
|
||||||
|
|
37
messages.go
37
messages.go
|
@ -28,14 +28,12 @@ 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 {
|
||||||
|
@ -967,41 +965,38 @@ type StatusMessage struct {
|
||||||
States map[string]bool `json:"states,omitempty"`
|
States map[string]bool `json:"states,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type BleAdvertisementPayload struct {
|
type BleServiceData struct {
|
||||||
LocalName string `json:"localName,omitempty"`
|
UUID string `json:"uuid,omitempty"`
|
||||||
Companies []string `json:"companies,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"`
|
||||||
Advertisement BleAdvertisementPayload `json:"advertisement,omitempty"`
|
ManufacturerData []BleManufacturerData `json:"companies,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"`
|
||||||
Devices BleDevices `json:"devices,omitempty"`
|
Device BleDevice `json:"device,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
|
||||||
|
|
Loading…
Reference in New Issue