librfm

package module
v2.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2023 License: MIT Imports: 18 Imported by: 1

README

librfm

Library to perform file and directory actions on the SD Card of a RepRapFirmware (RRF) managed device such as Duet 3D printer mainboards.

Documentation

Index

Constants

View Source
const (

	// TimeFormat is the format of timestamps used by RRF
	TimeFormat = "2006-01-02T15:04:05"
)

Variables

View Source
var ErrDirectoryNotFound = errors.New("Directory not found")

ErrDirectoryNotFound is the error returned if a directory was not found

View Source
var ErrDriveNotMounted = errors.New("Drive not mounted")

ErrDriveNotMounted is the error returned if the requested drive is not mounted

View Source
var ErrFileNotFound = errors.New("File not found")

ErrFileNotFound is the error returned in case a call to the rr_fileinfo interface was successful but returned err != 0

Functions

This section is empty.

Types

type File

type File struct {
	// Type of file - can be file or directory
	Type string
	// Name of file
	Name string
	// Size of file in bytes
	Size uint64
	// Timestamp corresponds to last modification date
	Timestamp localTime `json:"date"`
}

File resembles the JSON object returned in the files property of the rr_filelist response

func (*File) Date

func (f *File) Date() time.Time

Date returns the last modification date of a file/directory

func (*File) IsDir

func (f *File) IsDir() bool

IsDir returns true if the File instance is a directory, false otherwise

func (*File) IsFile

func (f *File) IsFile() bool

IsFile returns true if the File instance is a file, false otherwise

type Fileinfo

type Fileinfo struct {
	// Err holds a numeric error code where 0 means no error
	Err uint64
	// Size is the size of a file in bytes (0 for directories)
	Size      uint64
	Timestamp localTime `json:"lastModified"`
	// Height in mm for a job file
	Height float64
	// FirstLayerHeight in mm for a job file
	FirstLayerHeight float64
	// LayerHeight in mm for a job file
	LayerHeight float64
	// PrintTime in seconds for a job file
	PrintTime uint64
	// Filament contains an array of used filaments in mm
	Filament []float64
	// GeneratedBy returns the string which application created the job file
	GeneratedBy string
}

Fileinfo is the structure returned at rr_fileinfo interface

func (*Fileinfo) LastModified

func (f *Fileinfo) LastModified() time.Time

LastModified returns the last modification time of this file

type Filelist

type Filelist struct {
	Dir     string
	Files   []File
	Next    uint64
	Err     uint64
	Subdirs []*Filelist
	// contains filtered or unexported fields
}

Filelist resembled the JSON object in rr_filelist

func (*Filelist) Contains

func (f *Filelist) Contains(path string) bool

Contains checks for a path to exist in this filelist

type RRFFileManager

type RRFFileManager struct {
	// contains filtered or unexported fields
}

RRFFileManager provides means to interact with SD card contents on a machine using RepRapFirmware (RRF). It will communicate through its HTTP interface.

func New

func New(domain string, port uint64, debug bool) *RRFFileManager

New creates a new instance of RRFFileManager

func (*RRFFileManager) Connect

func (r *RRFFileManager) Connect(ctx context.Context, password string) error

Connect establishes a connection to RepRapFirmware

func (*RRFFileManager) Delete

func (r *RRFFileManager) Delete(ctx context.Context, path string) error

Delete removes the given path. It will fail for non-empty directories.

func (*RRFFileManager) Download

func (r *RRFFileManager) Download(ctx context.Context, path string) ([]byte, *time.Duration, error)

GetFile downloads a file with the given path also returning the duration of this action

func (*RRFFileManager) Fileinfo

func (r *RRFFileManager) Fileinfo(ctx context.Context, path string) (*Fileinfo, error)

Fileinfo returns information on a given file or an error if the file does not exist

func (*RRFFileManager) Filelist

func (r *RRFFileManager) Filelist(ctx context.Context, dir string, recursive bool) (*Filelist, error)

Filelist will download a list of all files (also including directories) for the given path. If recursive is true it will also populate the field Subdirs of Filelist to contain the full tree.

func (*RRFFileManager) Mkdir

func (r *RRFFileManager) Mkdir(ctx context.Context, path string) error

Mkdir creates a new directory with the given path

func (*RRFFileManager) Move

func (r *RRFFileManager) Move(ctx context.Context, oldpath, newpath string) error

Move renames or moves a file or directory (only within the same SD card)

func (*RRFFileManager) Upload

func (r *RRFFileManager) Upload(ctx context.Context, path string, content io.Reader) (*time.Duration, error)

Upload uploads a new file to the given path on the SD card

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL