Compare commits
17 Commits
3cfcdb7a01
...
v0.0.2
| Author | SHA1 | Date | |
|---|---|---|---|
| b186f77bea | |||
| adb297c6dd | |||
| b4992cb393 | |||
| a5490b8364 | |||
| 44d1f5552b | |||
| 5e34f656b3 | |||
| 560d19860e | |||
| ea1a7fa9f4 | |||
| 81fe634ed8 | |||
| 281e1dcbac | |||
| 4847eee540 | |||
| 19caa3ee83 | |||
| e523a024ec | |||
| 4a3dff646c | |||
| 986d2064a7 | |||
| 95cf5bfe6b | |||
| 0d70dd9b11 |
3
.gitm.toml
Normal file
3
.gitm.toml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[repos]
|
||||||
|
origin = "ssh://git@192.168.100.62:2222/Arsen6331/itd.git"
|
||||||
|
gitlab = "git@gitlab.com:moussaelianarsen/itd.git"
|
||||||
18
Makefile
18
Makefile
@@ -4,8 +4,12 @@ SERVICE_PREFIX = $(DESTDIR)$(PREFIX)/lib/systemd/user
|
|||||||
CFG_PREFIX = $(DESTDIR)/etc
|
CFG_PREFIX = $(DESTDIR)/etc
|
||||||
|
|
||||||
all:
|
all:
|
||||||
go build
|
go build $(GOFLAGS)
|
||||||
go build ./cmd/itctl
|
go build ./cmd/itctl $(GOFLAGS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f itctl
|
||||||
|
rm -f itd
|
||||||
|
|
||||||
install:
|
install:
|
||||||
install -Dm755 ./itd $(BIN_PREFIX)/itd
|
install -Dm755 ./itd $(BIN_PREFIX)/itd
|
||||||
@@ -13,8 +17,10 @@ install:
|
|||||||
install -Dm644 ./itd.service $(SERVICE_PREFIX)/itd.service
|
install -Dm644 ./itd.service $(SERVICE_PREFIX)/itd.service
|
||||||
install -Dm644 ./itd.toml $(CFG_PREFIX)/itd.toml
|
install -Dm644 ./itd.toml $(CFG_PREFIX)/itd.toml
|
||||||
|
|
||||||
clean:
|
uninstall:
|
||||||
rm -f itctl
|
rm $(BIN_PREFIX)/itd
|
||||||
rm -f itd
|
rm $(BIN_PREFIX)/itctl
|
||||||
|
rm $(SERVICE_PREFIX)/itd.service
|
||||||
|
rm $(CFG_PREFIX)/itd.toml
|
||||||
|
|
||||||
.PHONY: all install clean
|
.PHONY: all clean install uninstall
|
||||||
39
README.md
39
README.md
@@ -3,6 +3,10 @@
|
|||||||
|
|
||||||
`itd` is a daemon that uses my infinitime [library](https://go.arsenm.dev/infinitime) to interact with the [PineTime](https://www.pine64.org/pinetime/) running [InfiniTime](https://infinitime.io).
|
`itd` is a daemon that uses my infinitime [library](https://go.arsenm.dev/infinitime) to interact with the [PineTime](https://www.pine64.org/pinetime/) running [InfiniTime](https://infinitime.io).
|
||||||
|
|
||||||
|
[](https://ci.appveyor.com/project/moussaelianarsen/itd)
|
||||||
|
[](https://minio.arsenm.dev/minio/itd/)
|
||||||
|
[](https://aur.archlinux.org/packages/itd-git/)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
@@ -56,11 +60,29 @@ Flags:
|
|||||||
|
|
||||||
Use "itctl [command] --help" for more information about a command.
|
Use "itctl [command] --help" for more information about a command.
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Interactive mode
|
||||||
|
|
||||||
|
Running `itctl` by itself will open interactive mode. It's essentially a shell where you can enter commands. For example:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ itctl
|
||||||
|
itctl> fw ver
|
||||||
|
1.3.0
|
||||||
|
itctl> get batt
|
||||||
|
81%
|
||||||
|
itctl> get heart
|
||||||
|
92 BPM
|
||||||
|
itctl> set time 2021-08-22T00:06:18-07:00
|
||||||
|
itctl> set time now
|
||||||
|
itctl> exit
|
||||||
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### Installation
|
### Installation
|
||||||
|
|
||||||
To install, install the go compiler and make. Usually, go is provided by a package either named `go` or `golang`, and make is usually provided by `make`.
|
To install, install the go compiler and make. Usually, go is provided by a package either named `go` or `golang`, and make is usually provided by `make`. The go compiler must be version 1.16 or newer for the `io/fs` module.
|
||||||
|
|
||||||
To install, run
|
To install, run
|
||||||
```shell
|
```shell
|
||||||
@@ -69,6 +91,21 @@ make && sudo make install
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
### Starting
|
||||||
|
|
||||||
|
To start the daemon, run the following **without root**:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
systemctl --user start itd
|
||||||
|
```
|
||||||
|
|
||||||
|
To autostart on login, run:
|
||||||
|
```shell
|
||||||
|
systemctl --user enable itd
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
### Cross compiling
|
### Cross compiling
|
||||||
|
|
||||||
To cross compile, simply set the go environment variables. For example, for PinePhone, use:
|
To cross compile, simply set the go environment variables. For example, for PinePhone, use:
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/abiosoft/ishell"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -26,10 +27,39 @@ import (
|
|||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
Use: "itctl",
|
Use: "itctl",
|
||||||
Short: "Control the itd daemon for InfiniTime smartwatches",
|
Short: "Control the itd daemon for InfiniTime smartwatches",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
|
// Create new shell
|
||||||
|
sh := ishell.New()
|
||||||
|
sh.SetPrompt("itctl> ")
|
||||||
|
|
||||||
|
// For every command in cobra
|
||||||
|
for _, subCmd := range cmd.Commands() {
|
||||||
|
// Add top level command to ishell
|
||||||
|
sh.AddCmd(&ishell.Cmd{
|
||||||
|
Name: subCmd.Name(),
|
||||||
|
Help: subCmd.Short,
|
||||||
|
Aliases: subCmd.Aliases,
|
||||||
|
LongHelp: subCmd.Long,
|
||||||
|
Func: func(ctx *ishell.Context) {
|
||||||
|
// Append name and arguments of command
|
||||||
|
args := append([]string{ctx.Cmd.Name}, ctx.Args...)
|
||||||
|
// Set root command arguments
|
||||||
|
cmd.SetArgs(args)
|
||||||
|
// Execute root command with new arguments
|
||||||
|
cmd.Execute()
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start shell
|
||||||
|
sh.Run()
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute adds all child commands to the root command and sets flags appropriately.
|
// Execute adds all child commands to the root command and sets flags appropriately.
|
||||||
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
||||||
func Execute() {
|
func Execute() {
|
||||||
|
rootCmd.CompletionOptions.DisableDefaultCmd = true
|
||||||
cobra.CheckErr(rootCmd.Execute())
|
cobra.CheckErr(rootCmd.Execute())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,8 @@ var timeCmd = &cobra.Command{
|
|||||||
// Ensure required arguments
|
// Ensure required arguments
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
cmd.Usage()
|
cmd.Usage()
|
||||||
log.Fatal().Msg("Command time requires one argument")
|
log.Warn().Msg("Command time requires one argument")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connect to itd UNIX socket
|
// Connect to itd UNIX socket
|
||||||
|
|||||||
@@ -60,7 +60,8 @@ var upgradeCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cmd.Usage()
|
cmd.Usage()
|
||||||
log.Fatal().Msg("Upgrade command requires either archive or init packet and firmware.")
|
log.Warn().Msg("Upgrade command requires either archive or init packet and firmware.")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode response into connection
|
// Encode response into connection
|
||||||
|
|||||||
5
go.mod
5
go.mod
@@ -4,8 +4,11 @@ go 1.16
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/VividCortex/ewma v1.2.0 // indirect
|
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
|
||||||
github.com/cheggaaa/pb/v3 v3.0.8
|
github.com/cheggaaa/pb/v3 v3.0.8
|
||||||
github.com/fatih/color v1.12.0 // indirect
|
github.com/fatih/color v1.12.0 // indirect
|
||||||
|
github.com/flynn-archive/go-shlex v0.0.0-20150515145356-3f9db97f8568 // indirect
|
||||||
github.com/fsnotify/fsnotify v1.5.0 // indirect
|
github.com/fsnotify/fsnotify v1.5.0 // indirect
|
||||||
github.com/godbus/dbus/v5 v5.0.4
|
github.com/godbus/dbus/v5 v5.0.4
|
||||||
github.com/mattn/go-isatty v0.0.13 // indirect
|
github.com/mattn/go-isatty v0.0.13 // indirect
|
||||||
@@ -16,7 +19,7 @@ require (
|
|||||||
github.com/spf13/cast v1.4.1 // indirect
|
github.com/spf13/cast v1.4.1 // indirect
|
||||||
github.com/spf13/cobra v1.2.1
|
github.com/spf13/cobra v1.2.1
|
||||||
github.com/spf13/viper v1.8.1
|
github.com/spf13/viper v1.8.1
|
||||||
go.arsenm.dev/infinitime v0.0.0-20210821070429-ea488067fb9b
|
go.arsenm.dev/infinitime v0.0.0-20210822201216-955384489609
|
||||||
golang.org/x/sys v0.0.0-20210820121016-41cdb8703e55 // indirect
|
golang.org/x/sys v0.0.0-20210820121016-41cdb8703e55 // indirect
|
||||||
golang.org/x/text v0.3.7 // indirect
|
golang.org/x/text v0.3.7 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
12
go.sum
12
go.sum
@@ -42,6 +42,10 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym
|
|||||||
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
|
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 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow=
|
||||||
github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4=
|
github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4=
|
||||||
|
github.com/abiosoft/ishell v2.0.0+incompatible h1:zpwIuEHc37EzrsIYah3cpevrIc8Oma7oZPxr03tlmmw=
|
||||||
|
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/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
|
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/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=
|
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
|
||||||
@@ -51,8 +55,10 @@ github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqO
|
|||||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||||
github.com/cheggaaa/pb/v3 v3.0.8 h1:bC8oemdChbke2FHIIGy9mn4DPJ2caZYQnfbRqwmdCoA=
|
github.com/cheggaaa/pb/v3 v3.0.8 h1:bC8oemdChbke2FHIIGy9mn4DPJ2caZYQnfbRqwmdCoA=
|
||||||
github.com/cheggaaa/pb/v3 v3.0.8/go.mod h1:UICbiLec/XO6Hw6k+BHEtHeQFzzBH4i2/qk/ow1EJTA=
|
github.com/cheggaaa/pb/v3 v3.0.8/go.mod h1:UICbiLec/XO6Hw6k+BHEtHeQFzzBH4i2/qk/ow1EJTA=
|
||||||
|
github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE=
|
||||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
||||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
||||||
|
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8=
|
||||||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
|
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
|
||||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||||
@@ -77,6 +83,8 @@ github.com/fatih/color v1.12.0 h1:mRhaKNwANqRgUBGKmnI5ZxEk7QXmjQeCcuYFMX2bfcc=
|
|||||||
github.com/fatih/color v1.12.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
|
github.com/fatih/color v1.12.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
|
||||||
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
|
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
|
||||||
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
|
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/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
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 h1:NO5hkcB+srp1x6QmwvNZLeaOgbM8cmBTN32THzjvu2k=
|
||||||
github.com/fsnotify/fsnotify v1.5.0/go.mod h1:BX0DCEr5pT4jm2CnQdVP1lFV521fcCNcyEeNp4DQQDk=
|
github.com/fsnotify/fsnotify v1.5.0/go.mod h1:BX0DCEr5pT4jm2CnQdVP1lFV521fcCNcyEeNp4DQQDk=
|
||||||
@@ -279,8 +287,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.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
github.com/yuin/goldmark v1.2.1/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=
|
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||||
go.arsenm.dev/infinitime v0.0.0-20210821070429-ea488067fb9b h1:Wwj7F0gqYHUx+9H8fCCIy5JZTlCusJRpPuzeSFM0EoU=
|
go.arsenm.dev/infinitime v0.0.0-20210822201216-955384489609 h1:QH7hsVjulEs1OP8lcQ7EfVy2UO/rtwRsxUo3ylde83E=
|
||||||
go.arsenm.dev/infinitime v0.0.0-20210821070429-ea488067fb9b/go.mod h1:gaepaueUz4J5FfxuV19B4w5pi+V3mD0LTef50ryxr/Q=
|
go.arsenm.dev/infinitime v0.0.0-20210822201216-955384489609/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/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/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
|
||||||
go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ=
|
go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ=
|
||||||
|
|||||||
2
main.go
2
main.go
@@ -36,8 +36,8 @@ func init() {
|
|||||||
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
|
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
|
||||||
|
|
||||||
// Set config settings
|
// Set config settings
|
||||||
viper.AddConfigPath("/etc")
|
|
||||||
viper.AddConfigPath("$HOME/.config")
|
viper.AddConfigPath("$HOME/.config")
|
||||||
|
viper.AddConfigPath("/etc")
|
||||||
viper.SetConfigName("itd")
|
viper.SetConfigName("itd")
|
||||||
viper.SetConfigType("toml")
|
viper.SetConfigType("toml")
|
||||||
viper.WatchConfig()
|
viper.WatchConfig()
|
||||||
|
|||||||
21
socket.go
21
socket.go
@@ -51,7 +51,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func startSocket(dev *infinitime.Device) error {
|
func startSocket(dev *infinitime.Device) error {
|
||||||
// Make socket directory if non existant
|
// Make socket directory if non-existent
|
||||||
err := os.MkdirAll(filepath.Dir(SockPath), 0755)
|
err := os.MkdirAll(filepath.Dir(SockPath), 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -149,14 +149,14 @@ func handleConnection(conn net.Conn, dev *infinitime.Device) {
|
|||||||
case ReqTypeNotify:
|
case ReqTypeNotify:
|
||||||
// If no data, return error
|
// If no data, return error
|
||||||
if req.Data == nil {
|
if req.Data == nil {
|
||||||
connErr(conn, nil, "Data required for notify types.Request")
|
connErr(conn, nil, "Data required for notify request")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
var reqData types.ReqDataNotify
|
var reqData types.ReqDataNotify
|
||||||
// Decode data map to notify types.Request data
|
// Decode data map to notify request data
|
||||||
err = mapstructure.Decode(req.Data, &reqData)
|
err = mapstructure.Decode(req.Data, &reqData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
connErr(conn, err, "Error decoding types.Request data")
|
connErr(conn, err, "Error decoding request data")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
// Send notification to watch
|
// Send notification to watch
|
||||||
@@ -170,13 +170,13 @@ func handleConnection(conn net.Conn, dev *infinitime.Device) {
|
|||||||
case ReqTypeSetTime:
|
case ReqTypeSetTime:
|
||||||
// If no data, return error
|
// If no data, return error
|
||||||
if req.Data == nil {
|
if req.Data == nil {
|
||||||
connErr(conn, nil, "Data required for settime types.Request")
|
connErr(conn, nil, "Data required for settime request")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
// Get string from data or return error
|
// Get string from data or return error
|
||||||
reqTimeStr, ok := req.Data.(string)
|
reqTimeStr, ok := req.Data.(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
connErr(conn, nil, "Data for settime types.Request must be RFC3339 formatted time string")
|
connErr(conn, nil, "Data for settime request must be RFC3339 formatted time string")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,7 +184,7 @@ func handleConnection(conn net.Conn, dev *infinitime.Device) {
|
|||||||
if reqTimeStr == "now" {
|
if reqTimeStr == "now" {
|
||||||
reqTime = time.Now()
|
reqTime = time.Now()
|
||||||
} else {
|
} else {
|
||||||
// Parse time as RFC3339/ISO9601
|
// Parse time as RFC3339/ISO8601
|
||||||
reqTime, err = time.Parse(time.RFC3339, reqTimeStr)
|
reqTime, err = time.Parse(time.RFC3339, reqTimeStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
connErr(conn, err, "Invalid time format. Time string must be formatted as ISO8601 or the word `now`")
|
connErr(conn, err, "Invalid time format. Time string must be formatted as ISO8601 or the word `now`")
|
||||||
@@ -202,14 +202,14 @@ func handleConnection(conn net.Conn, dev *infinitime.Device) {
|
|||||||
case ReqTypeFwUpgrade:
|
case ReqTypeFwUpgrade:
|
||||||
// If no data, return error
|
// If no data, return error
|
||||||
if req.Data == nil {
|
if req.Data == nil {
|
||||||
connErr(conn, nil, "Data required for firmware upgrade types.Request")
|
connErr(conn, nil, "Data required for firmware upgrade request")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
var reqData types.ReqDataFwUpgrade
|
var reqData types.ReqDataFwUpgrade
|
||||||
// Decode data map to firmware upgrade types.Request data
|
// Decode data map to firmware upgrade request data
|
||||||
err = mapstructure.Decode(req.Data, &reqData)
|
err = mapstructure.Decode(req.Data, &reqData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
connErr(conn, err, "Error decoding types.Request data")
|
connErr(conn, err, "Error decoding request data")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
switch reqData.Type {
|
switch reqData.Type {
|
||||||
@@ -272,6 +272,7 @@ func handleConnection(conn net.Conn, dev *infinitime.Device) {
|
|||||||
err = dev.DFU.Start()
|
err = dev.DFU.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
connErr(conn, err, "Error performing upgrade")
|
connErr(conn, err, "Error performing upgrade")
|
||||||
|
firmwareUpdating = false
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
firmwareUpdating = false
|
firmwareUpdating = false
|
||||||
|
|||||||
Reference in New Issue
Block a user