Compare commits

...

3 Commits

4 changed files with 24 additions and 10 deletions

View File

@ -46,9 +46,11 @@ var readCmd = &cobra.Command{
log.Fatal().Err(err).Msg("Error moving file or directory") log.Fatal().Err(err).Msg("Error moving file or directory")
} }
var suffix string
var out *os.File var out *os.File
if args[1] == "-" { if args[1] == "-" {
out = os.Stdout out = os.Stdout
suffix = "\n"
} else { } else {
out, err = os.Create(args[1]) out, err = os.Create(args[1])
if err != nil { if err != nil {
@ -60,6 +62,8 @@ var readCmd = &cobra.Command{
if err != nil { if err != nil {
log.Fatal().Err(err).Msg("Error writing to local file") log.Fatal().Err(err).Msg("Error writing to local file")
} }
out.WriteString(suffix)
log.Info().Msgf("Read %d bytes in %s", n, time.Since(start)) log.Info().Msgf("Read %d bytes in %s", n, time.Since(start))
}, },
} }

4
go.mod
View File

@ -2,6 +2,8 @@ module go.arsenm.dev/itd
go 1.16 go 1.16
replace go.arsenm.dev/infinitime => /home/arsen/Code/infinitime
require ( require (
fyne.io/fyne/v2 v2.1.0 fyne.io/fyne/v2 v2.1.0
github.com/VividCortex/ewma v1.2.0 // indirect github.com/VividCortex/ewma v1.2.0 // indirect
@ -25,7 +27,7 @@ require (
github.com/srwiley/oksvg v0.0.0-20210519022825-9fc0c575d5fe // indirect github.com/srwiley/oksvg v0.0.0-20210519022825-9fc0c575d5fe // indirect
github.com/srwiley/rasterx v0.0.0-20210519020934-456a8d69b780 // indirect github.com/srwiley/rasterx v0.0.0-20210519020934-456a8d69b780 // indirect
github.com/yuin/goldmark v1.4.1 // indirect github.com/yuin/goldmark v1.4.1 // indirect
go.arsenm.dev/infinitime v0.0.0-20211125012112-9966880bc8be go.arsenm.dev/infinitime v0.0.0-20211125203943-58d5036f208b
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d // indirect golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d // indirect
golang.org/x/net v0.0.0-20211011170408-caeb26a5c8c0 // indirect golang.org/x/net v0.0.0-20211011170408-caeb26a5c8c0 // indirect
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac // indirect golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac // indirect

4
go.sum
View File

@ -367,8 +367,8 @@ github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1
github.com/yuin/goldmark v1.3.8/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.3.8/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.1 h1:/vn0k+RBvwlxEmP5E7SZMqNxPhfMVFEJiykr15/0XKM= github.com/yuin/goldmark v1.4.1 h1:/vn0k+RBvwlxEmP5E7SZMqNxPhfMVFEJiykr15/0XKM=
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
go.arsenm.dev/infinitime v0.0.0-20211125012112-9966880bc8be h1:WBD4szNWt5o9z/qEAPKZsTrk9j9uSeNxC0hjw0fQgWc= go.arsenm.dev/infinitime v0.0.0-20211125203943-58d5036f208b h1:spIoyjxLUhzZQ9pno629l9gU/tPjz6MAYhVfHffGUYg=
go.arsenm.dev/infinitime v0.0.0-20211125012112-9966880bc8be/go.mod h1:TzAhsz7TAqEm/vWhgMvmIxHS5jt46hqKkPvr6cqvVyA= go.arsenm.dev/infinitime v0.0.0-20211125203943-58d5036f208b/go.mod h1:TzAhsz7TAqEm/vWhgMvmIxHS5jt46hqKkPvr6cqvVyA=
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=

View File

@ -33,6 +33,7 @@ import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/spf13/viper" "github.com/spf13/viper"
"go.arsenm.dev/infinitime" "go.arsenm.dev/infinitime"
"go.arsenm.dev/infinitime/blefs"
"go.arsenm.dev/itd/internal/types" "go.arsenm.dev/itd/internal/types"
"go.arsenm.dev/itd/translit" "go.arsenm.dev/itd/translit"
) )
@ -79,6 +80,11 @@ func startSocket(dev *infinitime.Device) error {
return err return err
} }
fs, err := dev.FS()
if err != nil {
log.Warn().Err(err).Msg("Error getting BLE filesystem")
}
go func() { go func() {
for { for {
// Accept socket connection // Accept socket connection
@ -88,7 +94,7 @@ func startSocket(dev *infinitime.Device) error {
} }
// Concurrently handle connection // Concurrently handle connection
go handleConnection(conn, dev) go handleConnection(conn, dev, fs)
} }
}() }()
@ -98,14 +104,9 @@ func startSocket(dev *infinitime.Device) error {
return nil return nil
} }
func handleConnection(conn net.Conn, dev *infinitime.Device) { func handleConnection(conn net.Conn, dev *infinitime.Device, fs *blefs.FS) {
defer conn.Close() defer conn.Close()
fs, err := dev.FS()
if err != nil {
connErr(conn, 0, nil, "Error getting device filesystem")
}
// Create new scanner on connection // Create new scanner on connection
scanner := bufio.NewScanner(conn) scanner := bufio.NewScanner(conn)
for scanner.Scan() { for scanner.Scan() {
@ -438,6 +439,10 @@ func handleConnection(conn net.Conn, dev *infinitime.Device) {
} }
firmwareUpdating = false firmwareUpdating = false
case types.ReqTypeFS: case types.ReqTypeFS:
if fs == nil {
connErr(conn, req.Type, nil, "BLE filesystem is not available")
break
}
// If no data, return error // If no data, return error
if req.Data == nil { if req.Data == nil {
connErr(conn, req.Type, nil, "Data required for firmware upgrade request") connErr(conn, req.Type, nil, "Data required for firmware upgrade request")
@ -459,6 +464,7 @@ func handleConnection(conn net.Conn, dev *infinitime.Device) {
break break
} }
} }
json.NewEncoder(conn).Encode(types.Response{Type: req.Type})
case types.FSTypeMove: case types.FSTypeMove:
if len(reqData.Files) != 2 { if len(reqData.Files) != 2 {
connErr(conn, req.Type, nil, "Move FS command requires an old path and new path in the files list") connErr(conn, req.Type, nil, "Move FS command requires an old path and new path in the files list")
@ -469,6 +475,7 @@ func handleConnection(conn net.Conn, dev *infinitime.Device) {
connErr(conn, req.Type, err, "Error moving file") connErr(conn, req.Type, err, "Error moving file")
break break
} }
json.NewEncoder(conn).Encode(types.Response{Type: req.Type})
case types.FSTypeMkdir: case types.FSTypeMkdir:
for _, file := range reqData.Files { for _, file := range reqData.Files {
err := fs.Mkdir(file) err := fs.Mkdir(file)
@ -477,6 +484,7 @@ func handleConnection(conn net.Conn, dev *infinitime.Device) {
break break
} }
} }
json.NewEncoder(conn).Encode(types.Response{Type: req.Type})
case types.FSTypeList: case types.FSTypeList:
if len(reqData.Files) != 1 { if len(reqData.Files) != 1 {
connErr(conn, req.Type, nil, "List FS command requires a path to list in the files list") connErr(conn, req.Type, nil, "List FS command requires a path to list in the files list")