From b181785006ed48c9a86eb22dba2767b5f6f744f4 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Sun, 26 Feb 2023 13:03:19 +0000 Subject: [PATCH] Removed mock --- fuse/main.go => fuse.go | 0 fuse/mock.go | 161 ---------------------------------------- 2 files changed, 161 deletions(-) rename fuse/main.go => fuse.go (100%) delete mode 100644 fuse/mock.go diff --git a/fuse/main.go b/fuse.go similarity index 100% rename from fuse/main.go rename to fuse.go diff --git a/fuse/mock.go b/fuse/mock.go deleted file mode 100644 index 71c1956..0000000 --- a/fuse/mock.go +++ /dev/null @@ -1,161 +0,0 @@ -package main -import ( - "os" - "io/ioutil" - "errors" - "time" -) - -const ( - FSStatusOk = 0x01 - FSStatusError = 0x02 -) - -var ( - ErrFileNotExists = errors.New("file does not exist") - ErrFileReadOnly = errors.New("file is read only") - ErrFileWriteOnly = errors.New("file is write only") - ErrInvalidOffset = errors.New("invalid file offset") - ErrOffsetChanged = errors.New("offset has already been changed") - ErrReadOpen = errors.New("only one file can be opened for reading at a time") - ErrWriteOpen = errors.New("only one file can be opened for writing at a time") - ErrNoRemoveRoot = errors.New("refusing to remove root directory") -) - -type Device struct { -} -type FS struct { -} - -type MyFileInfo struct { - name string - size uint32 - modtime time.Time - dir bool -} -func (n *MyFileInfo) Name() string { - return n.name -} -func (n *MyFileInfo) Size() uint32 { - return n.size -} -func (n *MyFileInfo) ModTime() time.Time { - return n.modtime -} -func (n *MyFileInfo) IsDir() bool { - return n.dir -} - -type MyDirEntry struct { - self MyFileInfo -} -func (n *MyDirEntry) Info() (MyFileInfo, error) { - return n.self, nil -} - -type File struct { - fs *FS - path string - fp *os.File - isReadOnly bool - isWriteOnly bool -} - - - -func (i *Device) HeartRate() (uint8, error) { - return 10, nil -} - -func (i *Device) BatteryLevel() (uint8, error) { - return 95, nil -} - -func (i *Device) StepCount() (uint32, error) { - return 27000, nil -} - -type MotionValues struct { - X int16 - Y int16 - Z int16 -} - -func (i *Device) Motion() (MotionValues, error) { - return MotionValues{-12, +64, -19}, nil -} - -func (i *Device) Address() string { - return "FA:E4:00:00:00:00" -} - -func (i *Device) Version() (string, error) { - return "1.11.0", nil -} - -func (blefs *FS) ReadDir(path string) ([]MyDirEntry, error) { - var out []MyDirEntry - files, err := ioutil.ReadDir("./root/" + path) - - if err != nil { - return nil, nil - } - - for _, f := range files { - listing := MyFileInfo{} - listing.modtime = f.ModTime() - listing.size = uint32(f.Size()) - listing.name = f.Name() - listing.dir = f.IsDir() - out = append(out, MyDirEntry{self : listing}) - } - return out, nil -} - -func (blefs *FS) Mkdir(path string) error { - return os.Mkdir("./root/" + path, os.ModePerm) -} - -func (blefs *FS) Rename(old, new string) error { - return os.Rename("./root/" + old, "./root/" + new) -} - -func (blefs *FS) Remove(path string) error { - return os.Remove("./root/" + path) -} - -func (blefs *FS) Open(path string) (*File, error) { - fp, _ := os.Open("./root/" + path) - return &File{ - fs : blefs, - path : path, - fp : fp, - isReadOnly : true, - isWriteOnly : false, - }, nil -} -func (blefs *FS) Create(path string, size uint32) (*File, error) { - fp, _ := os.Create("./root/" + path) - return &File{ - fs : blefs, - path : path, - fp : fp, - isReadOnly : false, - isWriteOnly : true, - }, nil -} -func (fl *File) Read(b []byte) (n int, err error) { - if fl.isWriteOnly { - return 0, ErrFileWriteOnly - } - return fl.fp.Read(b) -} -func (fl *File) Write(b []byte) (n int, err error) { - if fl.isReadOnly { - return 0, ErrFileReadOnly - } - return fl.fp.Write(b) -} -func (fl *File) Close() error { - return fl.fp.Close() -}