smlib

package
v0.0.0-...-5ea5261 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const DISCOVERY_PORT = 20054
View Source
const DISCOVERY_TIMEOUT = time.Second * 1
View Source
const REQUEST_TIMEOUT = time.Second * 3

Variables

View Source
var ErrWaitForAuthOnDevice = errors.New("waiting for authorization on device")

Functions

This section is empty.

Types

type ConnectResponse

type ConnectResponse struct {
	Token        string `json:"token"`
	Readonly     bool   `json:"readonly"`
	Series       string `json:"series"`
	Headtype     uint   `json:"headType"`
	HasEnclosure bool   `json:"hasEnclosure"`
}

ConnectResponse represents http response from snapmaker /connect api endpoint

type Device

type Device struct {
	IP             string           `json:"ip"`
	Port           uint             `json:"port"`
	ConnectionData *ConnectResponse `json:"connectionData"`
	LatestStatus   *StatusResponse
	Connected      bool
}

Device keeps current snapmaker device details

func DeviceFromJson

func DeviceFromJson(deviceBytes []byte) (Device, error)

Creates snapmaker device based on json file serialized earlier. Thanks to this authentication is not needed every time application connects to the device

func NewDevice

func NewDevice(ip string, port uint) Device

Creates new snapmaker device with ip and port

func (*Device) Connect

func (d *Device) Connect() error

Connect - connects to snapmaker device. Saves response into Device structure

func (*Device) Disconnect

func (d *Device) Disconnect() error

Disconnect - breaks current connection with snapmaker device

func (*Device) ExecuteGCode

func (d *Device) ExecuteGCode(code string) (string, error)

ExecuteGCode - executes gcode on snapmaker device. Returns string with response and error if exists

func (*Device) Serialize

func (d *Device) Serialize(path string) ([]byte, error)

Serialize - converts Device into json string. Thanks to this you can later connect to device without clicking yes on device display

func (*Device) Status

func (d *Device) Status() (*StatusResponse, error)

Status gets current status of snapmaker device It returns StatusResponse struct It also saves StatusResponse struct into Device structure for easier access

type DeviceDescription

type DeviceDescription struct {
	IP     string
	Addr   net.Addr
	Name   string
	Type   string
	Status string
}

type ModuleList

type ModuleList struct {
	Enclosure           bool `json:"enclosure"`
	RotaryModule        bool `json:"rotaryModule"`
	EmergencyStopButton bool `json:"emergencyStopButton"`
	AirPurifier         bool `json:"airPurifier"`
}

ModuleList represents part of StatusResponse

type StatusResponse

type StatusResponse struct {
	X                   float32    `json:"x"`
	Y                   float32    `json:"y"`
	Z                   float32    `json:"z"`
	Homed               bool       `json:"homed"`
	OffsetX             float32    `json:"offsetX"`
	OffsetY             float32    `json:"offsetY"`
	OffsetZ             float32    `json:"offsetZ"`
	ToolHead            string     `json:"toolHead"`
	SpindleSpeed        float32    `json:"spindleSpeed"`
	WorkSpeed           float32    `json:"workSpeed"`
	PrintStatus         string     `json:"printStatus"`
	ModuleList          ModuleList `json:"moduleList"`
	IsEnclosureDoorOpen bool       `json:"isEnclosureDoorOpen"`
	DoorSwitchCount     uint       `json:"doorSwitchCount"`
}

StatusResponse represents http response from snapmaker /status api

type WifiManager

type WifiManager struct {
	Devices []DeviceDescription
	Client  net.PacketConn
}

func NewWifiManager

func NewWifiManager() *WifiManager

func (*WifiManager) Close

func (w *WifiManager) Close()

func (*WifiManager) DiscoverDevices

func (w *WifiManager) DiscoverDevices(retries uint) error

DiscoverDevices - tries to discover snapmaker devices for specified number of times

func (*WifiManager) Init

func (w *WifiManager) Init() error

Jump to

Keyboard shortcuts

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