forked from Elara6331/itd
Compare commits
No commits in common. "1a1bc30df991c396b039957581e8964dc882f256" and "dc53ead3391800b01dec394326e53f8b28337913" have entirely different histories.
1a1bc30df9
...
dc53ead339
10
fuse.go
10
fuse.go
@ -11,15 +11,7 @@ import (
|
|||||||
|
|
||||||
func startFUSE(ctx context.Context, dev *infinitime.Device) error {
|
func startFUSE(ctx context.Context, dev *infinitime.Device) error {
|
||||||
// This is where we'll mount the FS
|
// This is where we'll mount the FS
|
||||||
err := os.MkdirAll(k.String("fuse.mountpoint"), 0755)
|
os.Mkdir(k.String("fuse.mountpoint"), 0755)
|
||||||
if err != nil && !os.IsExist(err) {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ignore the error because nothing might be mounted on the mountpoint
|
|
||||||
_ = fusefs.Unmount(k.String("fuse.mountpoint"))
|
|
||||||
|
|
||||||
|
|
||||||
root, err := fusefs.BuildRootNode(dev)
|
root, err := fusefs.BuildRootNode(dev)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Building root node failed").
|
log.Error("Building root node failed").
|
||||||
|
@ -15,7 +15,6 @@ import (
|
|||||||
type ITProperty struct {
|
type ITProperty struct {
|
||||||
name string
|
name string
|
||||||
Ino uint64
|
Ino uint64
|
||||||
oneshot bool
|
|
||||||
gen func(context.Context) (<-chan []byte, error)
|
gen func(context.Context) (<-chan []byte, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,37 +54,32 @@ func BuildRootNode(dev *infinitime.Device) (*ITNode, error) {
|
|||||||
var properties = make([]ITProperty, 6)
|
var properties = make([]ITProperty, 6)
|
||||||
|
|
||||||
func BuildProperties(dev *infinitime.Device) {
|
func BuildProperties(dev *infinitime.Device) {
|
||||||
properties[0] = ITProperty{"heartrate", 2, true,
|
properties[0] = ITProperty{"heartrate", 2,
|
||||||
func(ctx context.Context) (<-chan []byte, error) {
|
func(ctx context.Context) (<-chan []byte, error) {
|
||||||
ans, err := dev.WatchHeartRate(ctx)
|
ans, err := dev.WatchHeartRate(ctx)
|
||||||
return converterU8(ctx, ans), err
|
return converterU8(ctx, ans), err
|
||||||
}}
|
}}
|
||||||
properties[1] = ITProperty{"battery", 3, true,
|
properties[1] = ITProperty{"battery", 3,
|
||||||
func(ctx context.Context) (<-chan []byte, error) {
|
func(ctx context.Context) (<-chan []byte, error) {
|
||||||
ans, err := dev.WatchBatteryLevel(ctx)
|
ans, err := dev.WatchBatteryLevel(ctx)
|
||||||
return converterU8(ctx, ans), err
|
return converterU8(ctx, ans), err
|
||||||
}}
|
}}
|
||||||
properties[2] = ITProperty{"motion", 4, true,
|
properties[2] = ITProperty{"motion", 4,
|
||||||
func(ctx context.Context) (<-chan []byte, error) {
|
func(ctx context.Context) (<-chan []byte, error) {
|
||||||
ans, err := dev.WatchMotion(ctx)
|
ans, err := dev.WatchMotion(ctx)
|
||||||
return converterMotionValues(ctx, ans), err
|
return converterMotionValues(ctx, ans), err
|
||||||
}}
|
}}
|
||||||
properties[3] = ITProperty{"motion", 5, true,
|
properties[3] = ITProperty{"stepcount", 5,
|
||||||
func(ctx context.Context) (<-chan []byte, error) {
|
|
||||||
ans, err := dev.WatchMotion(ctx)
|
|
||||||
return converterMotionValues(ctx, ans), err
|
|
||||||
}}
|
|
||||||
properties[4] = ITProperty{"stepcount", 6, true,
|
|
||||||
func(ctx context.Context) (<-chan []byte, error) {
|
func(ctx context.Context) (<-chan []byte, error) {
|
||||||
ans, err := dev.WatchStepCount(ctx)
|
ans, err := dev.WatchStepCount(ctx)
|
||||||
return converterU32(ctx, ans), err
|
return converterU32(ctx, ans), err
|
||||||
}}
|
}}
|
||||||
properties[5] = ITProperty{"version", 7, true,
|
properties[4] = ITProperty{"version", 6,
|
||||||
func(ctx context.Context) (<-chan []byte, error) {
|
func(ctx context.Context) (<-chan []byte, error) {
|
||||||
ans, err := dev.Version()
|
ans, err := dev.Version()
|
||||||
return converter1String(ctx, ans), err
|
return converter1String(ctx, ans), err
|
||||||
}}
|
}}
|
||||||
properties[6] = ITProperty{"address", 8, true,
|
properties[5] = ITProperty{"address", 7,
|
||||||
func(ctx context.Context) (<-chan []byte, error) {
|
func(ctx context.Context) (<-chan []byte, error) {
|
||||||
ans := dev.Address()
|
ans := dev.Address()
|
||||||
return converter1String(ctx, ans), nil
|
return converter1String(ctx, ans), nil
|
||||||
@ -103,7 +97,7 @@ func (n *ITNode) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) {
|
|||||||
// root folder
|
// root folder
|
||||||
r := make([]fuse.DirEntry, 2)
|
r := make([]fuse.DirEntry, 2)
|
||||||
r[0] = fuse.DirEntry{
|
r[0] = fuse.DirEntry{
|
||||||
Name: "info",
|
Name: "device",
|
||||||
Ino: 0,
|
Ino: 0,
|
||||||
Mode: fuse.S_IFDIR,
|
Mode: fuse.S_IFDIR,
|
||||||
}
|
}
|
||||||
@ -115,7 +109,7 @@ func (n *ITNode) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) {
|
|||||||
return fs.NewListDirStream(r), 0
|
return fs.NewListDirStream(r), 0
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
// info folder
|
// device folder
|
||||||
r := make([]fuse.DirEntry, 6)
|
r := make([]fuse.DirEntry, 6)
|
||||||
for ind, value := range properties {
|
for ind, value := range properties {
|
||||||
r[ind] = fuse.DirEntry{
|
r[ind] = fuse.DirEntry{
|
||||||
@ -128,7 +122,7 @@ func (n *ITNode) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno) {
|
|||||||
return fs.NewListDirStream(r), 0
|
return fs.NewListDirStream(r), 0
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
// on info
|
// on device
|
||||||
files, err := myfs.ReadDir(n.path)
|
files, err := myfs.ReadDir(n.path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("FUSE ReadDir failed").Str("path", n.path).Err(err).Send()
|
log.Error("FUSE ReadDir failed").Str("path", n.path).Err(err).Send()
|
||||||
@ -185,7 +179,7 @@ func (n *ITNode) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*
|
|||||||
switch n.kind {
|
switch n.kind {
|
||||||
case 0:
|
case 0:
|
||||||
// root folder
|
// root folder
|
||||||
if name == "info" {
|
if name == "device" {
|
||||||
stable := fs.StableAttr{
|
stable := fs.StableAttr{
|
||||||
Mode: fuse.S_IFDIR,
|
Mode: fuse.S_IFDIR,
|
||||||
Ino: uint64(0),
|
Ino: uint64(0),
|
||||||
@ -203,7 +197,7 @@ func (n *ITNode) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (*
|
|||||||
return child, 0
|
return child, 0
|
||||||
}
|
}
|
||||||
case 1:
|
case 1:
|
||||||
// info folder
|
// device folder
|
||||||
for _, value := range properties {
|
for _, value := range properties {
|
||||||
if value.name == name {
|
if value.name == name {
|
||||||
stable := fs.StableAttr{
|
stable := fs.StableAttr{
|
||||||
|
Loading…
Reference in New Issue
Block a user