From b7bd385c43bccbf206c177e5abf1757a482cf403 Mon Sep 17 00:00:00 2001 From: Arsen Musayelyan Date: Wed, 25 Aug 2021 21:18:24 -0700 Subject: [PATCH] Add GUI frontend --- .gitignore | 3 +- cmd/itgui/error.go | 30 ++++++++ cmd/itgui/info.go | 141 ++++++++++++++++++++++++++++++++++ cmd/itgui/main.go | 23 ++++++ cmd/itgui/notify.go | 43 +++++++++++ cmd/itgui/time.go | 65 ++++++++++++++++ cmd/itgui/upgrade.go | 163 ++++++++++++++++++++++++++++++++++++++++ go.mod | 3 +- go.sum | 40 ++++++++-- internal/types/types.go | 7 ++ socket.go | 26 +++++++ 11 files changed, 536 insertions(+), 8 deletions(-) create mode 100644 cmd/itgui/error.go create mode 100644 cmd/itgui/info.go create mode 100644 cmd/itgui/main.go create mode 100644 cmd/itgui/notify.go create mode 100644 cmd/itgui/time.go create mode 100644 cmd/itgui/upgrade.go diff --git a/.gitignore b/.gitignore index f4105c4..6b81a96 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /itctl -/itd \ No newline at end of file +/itd +/itgui \ No newline at end of file diff --git a/cmd/itgui/error.go b/cmd/itgui/error.go new file mode 100644 index 0000000..7d9c423 --- /dev/null +++ b/cmd/itgui/error.go @@ -0,0 +1,30 @@ +package main + +import ( + "image/color" + + "fyne.io/fyne/v2" + "fyne.io/fyne/v2/canvas" + "fyne.io/fyne/v2/container" + "fyne.io/fyne/v2/dialog" + "fyne.io/fyne/v2/widget" +) + +func guiErr(err error, msg string, parent fyne.Window) { + msgLbl := widget.NewLabel(msg) + msgLbl.Wrapping = fyne.TextWrapWord + msgLbl.Alignment = fyne.TextAlignCenter + rect := canvas.NewRectangle(color.Transparent) + rect.SetMinSize(fyne.NewSize(350, 0)) + content := container.NewVBox( + msgLbl, + rect, + ) + if err != nil { + errLbl := widget.NewLabel(err.Error()) + content.Add(widget.NewAccordion( + widget.NewAccordionItem("More Details", errLbl), + )) + } + dialog.NewCustom("Error", "Ok", content, parent).Show() +} diff --git a/cmd/itgui/info.go b/cmd/itgui/info.go new file mode 100644 index 0000000..6aa2a94 --- /dev/null +++ b/cmd/itgui/info.go @@ -0,0 +1,141 @@ +package main + +import ( + "bufio" + "errors" + "fmt" + "image/color" + "net" + + "encoding/json" + + "fyne.io/fyne/v2" + "fyne.io/fyne/v2/canvas" + "fyne.io/fyne/v2/container" + "fyne.io/fyne/v2/theme" + "go.arsenm.dev/itd/internal/types" +) + +func infoTab(parent fyne.Window) *fyne.Container { + infoLayout := container.NewVBox( + // Add rectangle for a bit of padding + canvas.NewRectangle(color.Transparent), + ) + + heartRateLbl := newText("0 BPM", 24) + heartRate := container.NewVBox( + newText("Heart Rate", 12), + heartRateLbl, + canvas.NewLine(theme.ShadowColor()), + ) + infoLayout.Add(heartRate) + + go watch(types.ReqTypeWatchHeartRate, func(data interface{}) { + heartRateLbl.Text = fmt.Sprintf("%d BPM", int(data.(float64))) + heartRateLbl.Refresh() + }, parent) + + battLevelLbl := newText("0%", 24) + battLevel := container.NewVBox( + newText("Battery Level", 12), + battLevelLbl, + canvas.NewLine(theme.ShadowColor()), + ) + infoLayout.Add(battLevel) + + go watch(types.ReqTypeWatchBattLevel, func(data interface{}) { + battLevelLbl.Text = fmt.Sprintf("%d%%", int(data.(float64))) + battLevelLbl.Refresh() + }, parent) + + fwVerString, err := get(types.ReqTypeFwVersion) + if err != nil { + panic(err) + } + + fwVer := container.NewVBox( + newText("Firmware Version", 12), + newText(fwVerString.(string), 24), + canvas.NewLine(theme.ShadowColor()), + ) + infoLayout.Add(fwVer) + + btAddrString, err := get(types.ReqTypeBtAddress) + if err != nil { + panic(err) + } + + btAddr := container.NewVBox( + newText("Bluetooth Address", 12), + newText(btAddrString.(string), 24), + canvas.NewLine(theme.ShadowColor()), + ) + infoLayout.Add(btAddr) + + return infoLayout +} + +func watch(req int, onRecv func(data interface{}), parent fyne.Window) error { + conn, err := net.Dial("unix", SockPath) + if err != nil { + return err + } + defer conn.Close() + err = json.NewEncoder(conn).Encode(types.Request{ + Type: req, + }) + if err != nil { + return err + } + scanner := bufio.NewScanner(conn) + for scanner.Scan() { + res, err := getResp(scanner.Bytes()) + if err != nil { + guiErr(err, "Error getting response from connection", parent) + continue + } + onRecv(res.Value) + } + return nil +} + +func get(req int) (interface{}, error) { + conn, err := net.Dial("unix", SockPath) + if err != nil { + return nil, err + } + defer conn.Close() + err = json.NewEncoder(conn).Encode(types.Request{ + Type: req, + }) + if err != nil { + return nil, err + } + line, _, err := bufio.NewReader(conn).ReadLine() + if err != nil { + return nil, err + } + res, err := getResp(line) + if err != nil { + return nil, err + } + return res.Value, nil +} + +func getResp(line []byte) (*types.Response, error) { + var res types.Response + err := json.Unmarshal(line, &res) + if err != nil { + return nil, err + } + if res.Error { + return nil, errors.New(res.Message) + } + return &res, nil +} + +func newText(t string, size float32) *canvas.Text { + text := canvas.NewText(t, theme.ForegroundColor()) + text.TextSize = size + return text +} diff --git a/cmd/itgui/main.go b/cmd/itgui/main.go new file mode 100644 index 0000000..457fcf2 --- /dev/null +++ b/cmd/itgui/main.go @@ -0,0 +1,23 @@ +package main + +import ( + "fyne.io/fyne/v2/app" + "fyne.io/fyne/v2/container" +) + +var SockPath = "/tmp/itd/socket" + +func main() { + a := app.New() + window := a.NewWindow("itgui") + + tabs := container.NewAppTabs( + container.NewTabItem("Info", infoTab(window)), + container.NewTabItem("Notify", notifyTab(window)), + container.NewTabItem("Set Time", timeTab(window)), + container.NewTabItem("Upgrade", upgradeTab(window)), + ) + + window.SetContent(tabs) + window.ShowAndRun() +} diff --git a/cmd/itgui/notify.go b/cmd/itgui/notify.go new file mode 100644 index 0000000..2198ce6 --- /dev/null +++ b/cmd/itgui/notify.go @@ -0,0 +1,43 @@ +package main + +import ( + "encoding/json" + "net" + + "fyne.io/fyne/v2" + "fyne.io/fyne/v2/container" + "fyne.io/fyne/v2/layout" + "fyne.io/fyne/v2/widget" + "go.arsenm.dev/itd/internal/types" +) + +func notifyTab(parent fyne.Window) *fyne.Container { + titleEntry := widget.NewEntry() + titleEntry.SetPlaceHolder("Title") + + bodyEntry := widget.NewMultiLineEntry() + bodyEntry.SetPlaceHolder("Body") + + sendBtn := widget.NewButton("Send", func() { + conn, err := net.Dial("unix", SockPath) + if err != nil { + guiErr(err, "Error dialing socket", parent) + return + } + json.NewEncoder(conn).Encode(types.Request{ + Type: types.ReqTypeNotify, + Data: types.ReqDataNotify{ + Title: titleEntry.Text, + Body: bodyEntry.Text, + }, + }) + }) + + return container.NewVBox( + layout.NewSpacer(), + titleEntry, + bodyEntry, + sendBtn, + layout.NewSpacer(), + ) +} diff --git a/cmd/itgui/time.go b/cmd/itgui/time.go new file mode 100644 index 0000000..0397a91 --- /dev/null +++ b/cmd/itgui/time.go @@ -0,0 +1,65 @@ +package main + +import ( + "encoding/json" + "net" + "time" + + "fyne.io/fyne/v2" + "fyne.io/fyne/v2/container" + "fyne.io/fyne/v2/layout" + "fyne.io/fyne/v2/widget" + "go.arsenm.dev/itd/internal/types" +) + +func timeTab(parent fyne.Window) *fyne.Container { + + timeEntry := widget.NewEntry() + timeEntry.SetText(time.Now().Format(time.RFC1123)) + + currentBtn := widget.NewButton("Set Current", func() { + timeEntry.SetText(time.Now().Format(time.RFC1123)) + setTime(true) + }) + + timeBtn := widget.NewButton("Set", func() { + parsedTime, err := time.Parse(time.RFC1123, timeEntry.Text) + if err != nil { + guiErr(err, "Error parsing time string", parent) + return + } + setTime(false, parsedTime) + }) + + return container.NewVBox( + layout.NewSpacer(), + timeEntry, + currentBtn, + timeBtn, + layout.NewSpacer(), + ) +} + +// setTime sets the first element in the variadic parameter +// if current is false, otherwise, it sets the current time. +func setTime(current bool, t ...time.Time) error { + conn, err := net.Dial("unix", SockPath) + if err != nil { + return err + } + var data string + if current { + data = "now" + } else { + data = t[0].Format(time.RFC3339) + } + defer conn.Close() + err = json.NewEncoder(conn).Encode(types.Request{ + Type: types.ReqTypeSetTime, + Data: data, + }) + if err != nil { + return err + } + return nil +} diff --git a/cmd/itgui/upgrade.go b/cmd/itgui/upgrade.go new file mode 100644 index 0000000..8bc433e --- /dev/null +++ b/cmd/itgui/upgrade.go @@ -0,0 +1,163 @@ +package main + +import ( + "bufio" + "encoding/json" + "fmt" + "net" + + "fyne.io/fyne/v2" + "fyne.io/fyne/v2/container" + "fyne.io/fyne/v2/dialog" + "fyne.io/fyne/v2/layout" + "fyne.io/fyne/v2/storage" + "fyne.io/fyne/v2/widget" + "github.com/mitchellh/mapstructure" + "go.arsenm.dev/itd/internal/types" +) + +func upgradeTab(parent fyne.Window) *fyne.Container { + var ( + archivePath string + fiwmarePath string + initPktPath string + ) + + archiveDialog := dialog.NewFileOpen(func(uc fyne.URIReadCloser, e error) { + if e != nil || uc == nil { + return + } + uc.Close() + archivePath = uc.URI().Path() + }, parent) + archiveDialog.SetFilter(storage.NewExtensionFileFilter([]string{".zip"})) + archiveBtn := widget.NewButton("Select archive (.zip)", archiveDialog.Show) + + firmwareDialog := dialog.NewFileOpen(func(uc fyne.URIReadCloser, e error) { + if e != nil || uc == nil { + return + } + uc.Close() + fiwmarePath = uc.URI().Path() + }, parent) + firmwareDialog.SetFilter(storage.NewExtensionFileFilter([]string{".bin"})) + firmwareBtn := widget.NewButton("Select init packet (.bin)", firmwareDialog.Show) + + initPktDialog := dialog.NewFileOpen(func(uc fyne.URIReadCloser, e error) { + if e != nil || uc == nil { + return + } + uc.Close() + initPktPath = uc.URI().Path() + }, parent) + initPktDialog.SetFilter(storage.NewExtensionFileFilter([]string{".dat"})) + initPktBtn := widget.NewButton("Select init packet (.dat)", initPktDialog.Show) + + initPktBtn.Hide() + firmwareBtn.Hide() + + upgradeTypeSelect := widget.NewSelect([]string{ + "Archive", + "Files", + }, func(s string) { + archiveBtn.Hide() + initPktBtn.Hide() + firmwareBtn.Hide() + switch s { + case "Archive": + archiveBtn.Show() + case "Files": + initPktBtn.Show() + firmwareBtn.Show() + } + }) + upgradeTypeSelect.SetSelectedIndex(0) + + startBtn := widget.NewButton("Start", func() { + if archivePath == "" && (initPktPath == "" && fiwmarePath == "") { + guiErr(nil, "Upgrade requires archive or files selected", parent) + return + } + + progressLbl := widget.NewLabelWithStyle("0 / 0 B", fyne.TextAlignCenter, fyne.TextStyle{}) + progressBar := widget.NewProgressBar() + progressDlg := widget.NewModalPopUp(container.NewVBox( + layout.NewSpacer(), + progressLbl, + progressBar, + layout.NewSpacer(), + ), parent.Canvas()) + progressDlg.Resize(fyne.NewSize(300, 100)) + + var fwUpgType int + var files []string + switch upgradeTypeSelect.Selected { + case "Archive": + fwUpgType = types.UpgradeTypeArchive + files = append(files, archivePath) + case "Files": + fwUpgType = types.UpgradeTypeFiles + files = append(files, initPktPath, fiwmarePath) + } + + conn, err := net.Dial("unix", SockPath) + if err != nil { + guiErr(err, "Error dialing socket", parent) + return + } + defer conn.Close() + + json.NewEncoder(conn).Encode(types.Request{ + Type: types.ReqTypeFwUpgrade, + Data: types.ReqDataFwUpgrade{ + Type: fwUpgType, + Files: files, + }, + }) + + progressDlg.Show() + + scanner := bufio.NewScanner(conn) + for scanner.Scan() { + var res types.Response + // Decode scanned line into response struct + err = json.Unmarshal(scanner.Bytes(), &res) + if err != nil { + guiErr(err, "Error decoding response", parent) + return + } + if res.Error { + guiErr(err, "Error returned in response", parent) + return + } + var event types.DFUProgress + // Decode response data into progress struct + err = mapstructure.Decode(res.Value, &event) + if err != nil { + guiErr(err, "Error decoding response value", parent) + return + } + // If transfer finished, break + if event.Received == event.Total { + break + } + progressLbl.SetText(fmt.Sprintf("%d / %d B", event.Received, event.Total)) + progressBar.Max = float64(event.Total) + progressBar.Value = float64(event.Received) + progressBar.Refresh() + } + conn.Close() + + progressDlg.Hide() + }) + + return container.NewVBox( + layout.NewSpacer(), + upgradeTypeSelect, + archiveBtn, + firmwareBtn, + initPktBtn, + startBtn, + layout.NewSpacer(), + ) +} diff --git a/go.mod b/go.mod index 568ea5e..2922acc 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module go.arsenm.dev/itd go 1.16 require ( + fyne.io/fyne/v2 v2.0.4 github.com/VividCortex/ewma v1.2.0 // indirect github.com/abiosoft/ishell v2.0.0+incompatible github.com/abiosoft/readline v0.0.0-20180607040430-155bce2042db // indirect @@ -19,7 +20,7 @@ require ( github.com/spf13/cast v1.4.1 // indirect github.com/spf13/cobra v1.2.1 github.com/spf13/viper v1.8.1 - go.arsenm.dev/infinitime v0.0.0-20210823171603-8648afeebf08 + go.arsenm.dev/infinitime v0.0.0-20210825051734-745b4bd37cf4 golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect golang.org/x/text v0.3.7 // indirect ) diff --git a/go.sum b/go.sum index 7da4862..1e607dd 100644 --- a/go.sum +++ b/go.sum @@ -37,8 +37,11 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= +fyne.io/fyne/v2 v2.0.4 h1:eDGaPGzeR4qNqWuAp9Li1kY4eVIHldCkf42KMakKIK4= +fyne.io/fyne/v2 v2.0.4/go.mod h1:nNpgL7sZkDVLraGtQII2ArNRnnl6kHup/KfQRxIhbvs= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/Kodeworks/golang-image-ico v0.0.0-20141118225523-73f0f4cfade9/go.mod h1:7uhhqiBaR4CpN0k9rMjOtjpcfGd6DG2m04zQxKnWQ0I= github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA= github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow= github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4= @@ -46,6 +49,7 @@ github.com/abiosoft/ishell v2.0.0+incompatible h1:zpwIuEHc37EzrsIYah3cpevrIc8Oma github.com/abiosoft/ishell v2.0.0+incompatible/go.mod h1:HQR9AqF2R3P4XXpMpI0NAzgHf/aS6+zVXRj14cVk9qg= github.com/abiosoft/readline v0.0.0-20180607040430-155bce2042db h1:CjPUSXOiYptLbTdr1RceuZgSFDQ7U15ITERUGrUORx8= github.com/abiosoft/readline v0.0.0-20180607040430-155bce2042db/go.mod h1:rB3B4rKii8V21ydCbIzH5hZiCQE7f5E9SzUb/ZZx530= +github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= @@ -85,17 +89,28 @@ github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= github.com/flynn-archive/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BMXYYRWTLOJKlh+lOBt6nUQgXAfB7oVIQt5cNreqSLI= github.com/flynn-archive/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:rZfgFAXFS/z/lEd6LJmf9HVZ1LkgYiHx5pHhV5DR16M= +github.com/fredbi/uri v0.0.0-20181227131451-3dcfdacbaaf3 h1:FDqhDm7pcsLhhWl1QtD8vlzI4mm59llRvNzrFg6/LAA= +github.com/fredbi/uri v0.0.0-20181227131451-3dcfdacbaaf3/go.mod h1:CzM2G82Q9BDUvMTGHnXf/6OExw/Dz2ivDj48nVg7Lg8= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.5.0 h1:NO5hkcB+srp1x6QmwvNZLeaOgbM8cmBTN32THzjvu2k= github.com/fsnotify/fsnotify v1.5.0/go.mod h1:BX0DCEr5pT4jm2CnQdVP1lFV521fcCNcyEeNp4DQQDk= +github.com/fyne-io/mobile v0.1.3-0.20210412090810-650a3139866a h1:3TAJhl8vXyli0tooKB0vd6gLCyBdWL4QEYbDoJpHEZk= +github.com/fyne-io/mobile v0.1.3-0.20210412090810-650a3139866a/go.mod h1:/kOrWrZB6sasLbEy2JIvr4arEzQTXBTZGb3Y96yWbHY= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7 h1:SCYMcCJ89LjRGwEa0tRluNRiMjZHalQZrVrvTbPh+qw= +github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7/go.mod h1:482civXOzJJCPzJ4ZOX/pwvXBWSnzD4OKMdH4ClKGbk= +github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1 h1:QbL/5oDUmRBzO9/Z7Seo6zf912W/a6Sr4Eu0G/3Jho0= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210410170116-ea3d685f79fb h1:T6gaWBvRzJjuOrdCtg8fXXjKai2xSDqWTcKFUPuw8Tw= +github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210410170116-ea3d685f79fb/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/godbus/dbus/v5 v5.0.4 h1:9349emZab16e7zQvpmsbtjc18ykshndd8y2PG3sgJbA= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/goki/freetype v0.0.0-20181231101311-fa8a33aabaff h1:W71vTCKoxtdXgnm1ECDFkfQnpdqAO00zzGXLA5yaEX8= +github.com/goki/freetype v0.0.0-20181231101311-fa8a33aabaff/go.mod h1:wfqRWLHRBsRgkp5dmbG56SA0DmVtwrF5N3oPdI8t+Aw= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -186,6 +201,8 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1: github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/jackmordaunt/icns v0.0.0-20181231085925-4f16af745526/go.mod h1:UQkeMHVoNcyXYq9otUupF7/h/2tmHlhrS2zw7ZVvUqc= +github.com/josephspurrier/goversioninfo v0.0.0-20200309025242-14b0ab84c6ca/go.mod h1:eJTEwMjXb7kZ633hO3Ln9mBUCOjX2+FlTljvpl9SYdE= github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= @@ -199,6 +216,7 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/lucor/goinfo v0.0.0-20200401173949-526b5363a13a/go.mod h1:ORP3/rB5IsulLEBwQZCJyyV6niqmI7P4EWSmkug+1Ng= github.com/magiconair/properties v1.8.5 h1:b6kJs+EmPFMYGkow9GiUyCyOvIwYetYJ3fSaWak/Gls= github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= @@ -226,12 +244,14 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/muka/go-bluetooth v0.0.0-20210812063148-b6c83362e27d h1:EG/xyWjHT19rkUpwsWSkyiCCmyqNwFovr9m10rhyOxU= github.com/muka/go-bluetooth v0.0.0-20210812063148-b6c83362e27d/go.mod h1:dMCjicU6vRBk34dqOmIZm0aod6gUwZXOXzBROqGous0= +github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= github.com/paypal/gatt v0.0.0-20151011220935-4ae819d591cf/go.mod h1:+AwQL2mK3Pd3S+TUwg0tYQjid0q1txyNUJuuSmz8Kdk= github.com/pelletier/go-toml v1.9.3 h1:zeC5b1GviRUyKYd6OJPvBU/mcVDVoL1OhT17FCt5dSQ= github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI= @@ -258,6 +278,7 @@ github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykE github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= github.com/spf13/afero v1.6.0 h1:xoax2sJ2DT8S8xA2paPFjDCScCNeWsg75VG0DLRreiY= github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I= github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= @@ -267,10 +288,15 @@ github.com/spf13/cobra v1.2.1 h1:+KmjbUw1hriSNMF55oPrkZcb27aECyrj8V2ytv7kWDw= github.com/spf13/cobra v1.2.1/go.mod h1:ExllRjgxM/piMAM+3tAZvg8fsklGAf3tPfi+i8t68Nk= github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk= github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/viper v1.8.1 h1:Kq1fyeebqsBfbjZj4EL7gj2IO0mMaiyjYUWcUsl2O44= github.com/spf13/viper v1.8.1/go.mod h1:o0Pch8wJ9BVSWGQMbra6iw0oQ5oktSIBaujf1rJH9Ns= +github.com/srwiley/oksvg v0.0.0-20200311192757-870daf9aa564 h1:HunZiaEKNGVdhTRQOVpMmj5MQnGnv+e8uZNu3xFLgyM= +github.com/srwiley/oksvg v0.0.0-20200311192757-870daf9aa564/go.mod h1:afMbS0qvv1m5tfENCwnOdZGOF8RGR/FsZ7bvBxQGZG4= +github.com/srwiley/rasterx v0.0.0-20200120212402-85cb7272f5e9 h1:m59mIOBO4kfcNCEzJNy71UkeF4XIx2EVmL9KLwDQdmM= +github.com/srwiley/rasterx v0.0.0-20200120212402-85cb7272f5e9/go.mod h1:mvWM0+15UqyrFKqdRjY6LuAVJR0HOVhJlEgZ5JWtSWU= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= @@ -287,10 +313,8 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -go.arsenm.dev/infinitime v0.0.0-20210822201216-955384489609 h1:QH7hsVjulEs1OP8lcQ7EfVy2UO/rtwRsxUo3ylde83E= -go.arsenm.dev/infinitime v0.0.0-20210822201216-955384489609/go.mod h1:gaepaueUz4J5FfxuV19B4w5pi+V3mD0LTef50ryxr/Q= -go.arsenm.dev/infinitime v0.0.0-20210823171603-8648afeebf08 h1:eh/ZfShWAYhi3UR6nrX+5mORDvN58A1T+NHtYoQeFC4= -go.arsenm.dev/infinitime v0.0.0-20210823171603-8648afeebf08/go.mod h1:gaepaueUz4J5FfxuV19B4w5pi+V3mD0LTef50ryxr/Q= +go.arsenm.dev/infinitime v0.0.0-20210825051734-745b4bd37cf4 h1:XZyynxrvGxP0mwyhdiuMrvj5SkiK6N+MDiC6DiGzgWU= +go.arsenm.dev/infinitime v0.0.0-20210825051734-745b4bd37cf4/go.mod h1:gaepaueUz4J5FfxuV19B4w5pi+V3mD0LTef50ryxr/Q= go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ= @@ -323,6 +347,8 @@ golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EH golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/image v0.0.0-20200430140353-33d19683fad8 h1:6WW6V3x1P/jokJBpRQYUJnMHRP6isStQwCozxnU7XQw= +golang.org/x/image v0.0.0-20200430140353-33d19683fad8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -381,6 +407,7 @@ golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= +golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 h1:4nGaVu0QrbjT/AK2PRLuQfQuh6DJve+pELhqTdAj3x0= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -435,6 +462,7 @@ golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200720211630-cb9d2d5c5666/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200728102440-3e129f6d46b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -451,8 +479,6 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210820121016-41cdb8703e55 h1:rw6UNGRMfarCepjI8qOepea/SXwIBVfTKjztZ5gBbq4= -golang.org/x/sys v0.0.0-20210820121016-41cdb8703e55/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf h1:2ucpDCmfkl8Bd/FsLtiD653Wf96cW37s+iGx93zsu4k= golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -481,6 +507,7 @@ golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBn golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190808195139-e713427fea3f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= @@ -502,6 +529,7 @@ golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapK golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= +golang.org/x/tools v0.0.0-20200328031815-3db5fc6bac03/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= diff --git a/internal/types/types.go b/internal/types/types.go index 2e2fe95..285896d 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -8,6 +8,8 @@ const ( ReqTypeBtAddress ReqTypeNotify ReqTypeSetTime + ReqTypeWatchHeartRate + ReqTypeWatchBattLevel ) const ( @@ -35,3 +37,8 @@ type ReqDataNotify struct { Title string Body string } + +type DFUProgress struct { + Received int64 `mapstructure:"recvd"` + Total int64 `mapstructure:"total"` +} diff --git a/socket.go b/socket.go index 0b0b2b4..2afe771 100644 --- a/socket.go +++ b/socket.go @@ -103,6 +103,32 @@ func handleConnection(conn net.Conn, dev *infinitime.Device) { json.NewEncoder(conn).Encode(types.Response{ Value: heartRate, }) + case types.ReqTypeWatchHeartRate: + heartRateCh, err := dev.WatchHeartRate() + if err != nil { + connErr(conn, err, "Error getting heart rate channel") + break + } + go func() { + for heartRate := range heartRateCh { + json.NewEncoder(conn).Encode(types.Response{ + Value: heartRate, + }) + } + }() + case types.ReqTypeWatchBattLevel: + battLevelCh, err := dev.WatchBatteryLevel() + if err != nil { + connErr(conn, err, "Error getting heart rate channel") + break + } + go func() { + for battLevel := range battLevelCh { + json.NewEncoder(conn).Encode(types.Response{ + Value: battLevel, + }) + } + }() case types.ReqTypeBattLevel: // Get battery level from watch battLevel, err := dev.BatteryLevel()