commands

package
v3.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2021 License: LGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package commands implements all commands that can be sent to the server. Most of the commands include a BaseCommand unnamed member. To obtain correctly initialized command instances the user is strongly advised to use the prodived NewCommandName() functions instead of creating a new instance of the according struct.

Index

Constants

View Source
const (
	// Comment if this code is whole line comment
	Comment CodeType = "Q"
	// GCode if this code is a G-Code
	GCode = "G"
	// MCode if this code is a M-Code
	MCode = "M"
	// TCode if this code is a T-Code
	TCode = "T"
)
View Source
const (
	// StatusCode without payload
	StatusCode HttpResponseType = "statuscode"
	// PlainText UTF-8 response
	PlainText = "plaintext"
	// JSON formatted response
	JSON = "json"
	// File content. Response must hold the absolute path to the file to return
	File = "file"
)
View Source
const (
	// LetterForUnprecentedString is a special value for Parameters
	// that have no preceding letter
	LetterForUnprecentedString = "@"
)

Variables

View Source
var ErrMissingParameter = errors.New("Parameter not found")

ErrMissingParameter if a parameter was not available

Functions

This section is empty.

Types

type AddUserSession

type AddUserSession struct {
	BaseCommand
	// AccessLevel of this session
	AccessLevel usersessions.AccessLevel
	// SessionType of this session
	SessionType usersessions.SessionType
	// Origin of this session. For remote sessions this equals the remote IP address
	Origin string
	// OriginPort corresponds to the identifier of the origin.
	// If it is a remote session it is the remote port
	// else it defaults to the PID of the current process
	OriginPort int
}

AddUserSession registers a new user session

func NewAddUserSession

func NewAddUserSession(access usersessions.AccessLevel, t usersessions.SessionType, origin string, op int) *AddUserSession

NewAddUserSession creates a new instance of AddUserSession

type BaseCommand

type BaseCommand struct {
	Command string
}

BaseCommand is the common base member of nearly all actual commands

func NewAcknowledge

func NewAcknowledge() *BaseCommand

NewAcknowledge returns a Acknowledge command

func NewBaseCommand

func NewBaseCommand(command string) *BaseCommand

NewBaseCommand instantiates a new BaseCommand with the given name

func NewCancel

func NewCancel() *BaseCommand

NewCancel returns a Cancel command

func NewGetObjectModel added in v3.2.0

func NewGetObjectModel() *BaseCommand

NewGetObjectModel returns a GetObjectModel command

func NewIgnore

func NewIgnore() *BaseCommand

NewIgnore returns an Ignore command

func NewLockObjectModel added in v3.2.0

func NewLockObjectModel() *BaseCommand

NewLockObjectModel returns a LockObjectModel command

func NewSyncObjectModel added in v3.2.0

func NewSyncObjectModel() *BaseCommand

NewSyncObjectModel returns a SyncObjectModel command

func NewUnlockObjectModel added in v3.2.0

func NewUnlockObjectModel() *BaseCommand

NewUnlockObjectModel returns a UnlockObjectModel command

func (*BaseCommand) GetCommand

func (bc *BaseCommand) GetCommand() string

GetCommand returns the type of command

type BaseResponse

type BaseResponse struct {
	Success      bool
	Result       interface{}
	ErrorType    string
	ErrorMessage string
}

BaseResponse contains all possible response fields

func (*BaseResponse) GetErrorMessage

func (br *BaseResponse) GetErrorMessage() string

GetErrorMessage returns the error message if it was not successful

func (*BaseResponse) GetErrorType

func (br *BaseResponse) GetErrorType() string

GetErrorType returns the type of error if it was not succesful

func (*BaseResponse) GetResult

func (br *BaseResponse) GetResult() interface{}

GetResult returns the response body

func (*BaseResponse) IsSuccess

func (br *BaseResponse) IsSuccess() bool

IsSuccess returns true if the sent command was executed successfully

type Code

type Code struct {
	BaseCommand
	// SourceConnection ID this code was received from. If this is 0, the code originates from an internal DCS task
	// Usually there is no need to populate this property. It is internally overwritten by the control server on receipt
	SourceConnection int64
	// Result of this code. This property is only set when the code has finished its execution
	// It remains nil if the code has been cancelled.
	Result CodeResult
	// Type of the code
	Type CodeType
	// Channel to send this code to
	Channel types.CodeChannel
	// LineNumber of this code
	LineNumber *int64
	// Indent are the number of whitespaces prefixing the command content
	Indent byte
	// Keyword type of conditional G-code
	Keyword KeywordType
	// KeywordArgument of the conditional G-code
	KeywordArgument string
	// MajorNumber of the code (e.g. 28 in G28)
	MajorNumber *int64
	// MinorNumber of the code (e.g. 3 in G54.3)
	MinorNumber *int8
	// Flags of this code
	Flags CodeFlags
	// Comment provided to this G/M/T-code
	Comment string
	// FilePosition of this code in bytes (optional)
	FilePosition *int64
	// Length of the original code in bytes (optional)
	Length *int64
	// Parameters are a list of parsed code parameters
	Parameters []CodeParameter
}

Code is a parsed representation of a generic G/M/T/code

func NewCode

func NewCode() *Code

NewCode instantiates a Code with default values

func (*Code) Clone

func (c *Code) Clone() *Code

Clone an existing Code into a new instance

func (*Code) GetUnprecedentedString

func (c *Code) GetUnprecedentedString(quote bool) string

GetUnprecedentedString reconstructs an unprecedented string from parameter list

func (*Code) HasFlag

func (c *Code) HasFlag(flag CodeFlags) bool

HasFlag checks if this code has the given flag set

func (*Code) HasParameter

func (c *Code) HasParameter(letter string) bool

HasParameter returns whether or not a certain parameter is present without returning the CodeParameter instance

func (*Code) IsMajorNumber

func (c *Code) IsMajorNumber(n int64) bool

IsMajorNumber is a convenience function that checks if the MajorNumber of this Code instance is present and equal to the given value

func (*Code) Parameter

func (c *Code) Parameter(letter string) *CodeParameter

Parameter retrieves a parameter for the given letter. This will return nil in case there is no parameter with this letter. Lookup is case-insensitive.

func (*Code) ParameterOrDefault

func (c *Code) ParameterOrDefault(letter string, value interface{}) *CodeParameter

ParameterOrDefault will return the Parameter for the given letter or return the given default value. Lookup is case-insensitive.

func (*Code) RemoveParameter

func (c *Code) RemoveParameter(letter string) *CodeParameter

RemoveParameter removes all parameters with the given letter

func (*Code) ReplaceParameter

func (c *Code) ReplaceParameter(letter string, np *CodeParameter) bool

ReplaceParameter will replace the first occurrence of a parameter with the given letter

func (*Code) ShortString

func (c *Code) ShortString() string

ShortString converts only the command portion to text-based G/M/T-code (e.g. G28)

func (*Code) String

func (c *Code) String() string

String will convert the parsed code back to a text-based G/M/T-code

type CodeFlags

type CodeFlags int64

CodeFlags are bit masks to classify G/M/T-codes

const (
	// Asynchronous codes are considered finished as soon as they enter the code queue
	Asynchronous CodeFlags = 1 << iota
	// IsPreProcessed marks pre-processed codes
	IsPreProcessed
	// IsPostProcessed marks post-processed codes
	IsPostProcessed
	// IsFromMacro indicates code originating from macro
	IsFromMacro
	// IsNestedMacro indicates code originating from system macro
	IsNestedMacro
	// IsFromConfig indicates code originating from config.g or config.g.bak
	IsFromConfig
	// IsFromConfigOverride indicated code originating from config-override.g
	IsFromConfigOverride
	// EnforceAbsolutePosition marks code prefixed with G53
	EnforceAbsolutePosition
	// IsPrioritized will be sent to the firmware as soon as possible jumping all queued codes
	IsPrioritized
	// Unbuffered will execute this code circumventing any buffers
	// Do NOT process another code on the same channel before this code has been fully executed
	Unbuffered
	// IsFromFirmware indicates if this code was requested by the firmware
	IsFromFirmware
	// IsLastCode indicates if this is the last code on the line
	IsLastCode
	// CodeFlagsNone is a placeholder to indicate that no flags are set
	CodeFlagsNone = 0
)

type CodeParameter

type CodeParameter struct {
	// Letter of the code parameter (e.g. P in M106 P2). This is the LetterForUnprecentedString if
	// this parameter does not have a preceding letter.
	Letter string
	// IsExpression indicates if this parameter is an expression that can be evaluated
	IsExpression bool
	// IsDriverId indicated if this parameter is a driver identifier
	IsDriverId bool

	// IsString indicates if this parameter is a string
	IsString bool
	// contains filtered or unexported fields
}

CodeParameter represents a parsed parameter of a G/M/T-code

func NewCodeParameter

func NewCodeParameter(letter, value string, isString, isDriverId bool) (*CodeParameter, error)

NewCodeParameter creates a new CodeParameter instance and parses value to a native data type if applicable

func NewSimpleCodeParameter

func NewSimpleCodeParameter(letter string, value interface{}) *CodeParameter

NewSimpleCodeParameter instantiates a CodeParameter for the given letter and value

func (*CodeParameter) AsBool

func (cp *CodeParameter) AsBool() (bool, error)

AsBool returns the value as bool as returned by strconv.ParseBool()

func (*CodeParameter) AsDriverId

func (cp *CodeParameter) AsDriverId() (types.DriverId, error)

AsDriverId returns the value as DriverId if it was of this type or can be converted to one or an error otherwise

func (*CodeParameter) AsDriverIdSlice

func (cp *CodeParameter) AsDriverIdSlice() ([]types.DriverId, error)

AsDriverIdSlice returns the value as []DriverId if it was of this type or can be converted to one or an error otherwise

func (*CodeParameter) AsFloat64

func (cp *CodeParameter) AsFloat64() (float64, error)

AsFloat64 returns the value as float64 if it was of this type or can be converted to one or an error otherwise

func (*CodeParameter) AsFloat64Slice

func (cp *CodeParameter) AsFloat64Slice() ([]float64, error)

AsFloat64Slice converts this parameter to []float64 if it is a numeric type (or slice)

func (*CodeParameter) AsInt64

func (cp *CodeParameter) AsInt64() (int64, error)

AsInt64 returns the value as int64 if it was of this type or can be converted to one or an error otherwise

func (*CodeParameter) AsInt64Slice

func (cp *CodeParameter) AsInt64Slice() ([]int64, error)

AsInt64Slice converts this parameter to []int64 if it is a numeric type (or slice)

func (*CodeParameter) AsString

func (cp *CodeParameter) AsString() string

AsString returns the string representation of this parameter

func (*CodeParameter) AsUint64

func (cp *CodeParameter) AsUint64() (uint64, error)

AsUint64 returns the value as uint64 if it was of this type or can be converted to one or an error otherwise

func (*CodeParameter) AsUint64Slice

func (cp *CodeParameter) AsUint64Slice() ([]uint64, error)

AsUint64Slice converts this parameter to []uint64 if it is a numeric type (or slice)

func (*CodeParameter) Clone

func (cp *CodeParameter) Clone() *CodeParameter

Clone will create a copy of the this instance

func (*CodeParameter) ConvertDriverIds

func (cp *CodeParameter) ConvertDriverIds() error

ConvertDriverIds converts this parameter to a driver id or a list of such

func (*CodeParameter) MarshalJSON

func (cp *CodeParameter) MarshalJSON() ([]byte, error)

func (CodeParameter) String

func (cp CodeParameter) String() string

String prints out the parameter with quotes around the value if it is a string parameter

func (*CodeParameter) UnmarshalJSON

func (cp *CodeParameter) UnmarshalJSON(data []byte) error

type CodeResult

type CodeResult []messages.Message

CodeResult is a list of code results Deprecated: This class is now deprecated. It will be replaced with messages.Message in foreseeable future

func (CodeResult) String

func (cr CodeResult) String() string

type CodeType

type CodeType string

CodeType is the generic type of G/M/T-code or being a comment

type Command

type Command interface {
	// GetCommand returns the type of command
	GetCommand() string
}

Command interface

type EvaluateExpression

type EvaluateExpression struct {
	BaseCommand
	// Channel where the expression is evaluated
	Channel types.CodeChannel
	// Expression to evaluate
	Expression string
}

EvaluateExpression can be used to evaluate an arbitrary expression on the given channel in RepRapFirmware

Do not use this call to evaluation file-based or network-related fields because DSF and RRF models diverge in this regard

func NewEvaluateExpression

func NewEvaluateExpression(channel types.CodeChannel, expression string) *EvaluateExpression

NewEvaluateExpression creates a new EvaluateExpression instance for the given settings

type Flush

type Flush struct {
	BaseCommand
	// Channel is the CodeChannel to flush
	// This value is ignored if this request is processed while a code is
	// being intercepted.
	Channel types.CodeChannel
}

Flush waits for all pending (macro) codes on the given channel to finish. This effectively guarantees that all buffered codes are processed by RRF before this command finishes. If the flush request is successful, true is returned

func NewFlush

func NewFlush(channel types.CodeChannel) *Flush

NewFlush creates a flush command for the given CodeChannel

type GetFileInfo

type GetFileInfo struct {
	BaseCommand
	// Filename of the file to analyse
	FileName string
}

GetFileInfo will initiate analysis of a G-code file and returns ParsedFileInfo when ready.

func NewGetFileInfo

func NewGetFileInfo(fileName string) *GetFileInfo

NewGetFileInfo creates a new GetFileInfo for the given file name

type HttpEndpointCommand

type HttpEndpointCommand struct {
	BaseCommand
	// EndpointType is type of HTTP request
	EndpointType httpendpoints.HttpEndpointType
	// Namespace of the plugin wanting to create a new third-party endpoint
	Namespace string
	// Path to the endpoint to register
	Path string
	// Whether this is an upload request
	IsUploadRequest bool
}

HttpEndpointCommand is used to either create or remove a custom HTTP endpoint

func NewAddHttpEndpoint

func NewAddHttpEndpoint(t httpendpoints.HttpEndpointType, ns, path string, isUploadRequest bool) *HttpEndpointCommand

NewAddHttpEndpoint registers a new HTTP endpoint via DuetWebServer. This will create a new HTTP endpoint under /machine/{Namespace}/{EndpointPath}. Returns a path to the UNIX socket which DuetWebServer will connect to whenever a matching HTTP request is received. A plugin using this command has to open a new UNIX socket with the given path that DuetWebServer can connect to

func NewRemoveHttpEndpoint

func NewRemoveHttpEndpoint(t httpendpoints.HttpEndpointType, ns, path string) *HttpEndpointCommand

NewRemoveHttpEndpoint removes an existing HTTP endpoint.

type HttpResponseType

type HttpResponseType string

HttpResponseType enumerates supported HTTP responses

type InstallPlugin added in v3.2.0

type InstallPlugin struct {
	BaseCommand
	// Absolute file path to the plugin ZIP bundle
	PluginFile string
}

InstallPlugin is used to install or upgrade a plugin

func NewInstallPlugin added in v3.2.0

func NewInstallPlugin(pluginFile string) *InstallPlugin

NewInstallPlugin creates a new InstallPlugin instance for the given path

type KeywordType

type KeywordType byte

KeywordType is the type of conditional G-code

const (
	// None for no conditional code
	None KeywordType = iota
	// If condition
	If
	// ElseIf condition
	ElseIf
	// Else condition
	Else
	// While condition
	While
	// Break instruction (used in While)
	Break
	// Return instruction
	Return
	// Abort instruction
	Abort
	// Var operation
	Var
	// Set operation
	Set
	// Echo operation
	Echo
	// Continue instruction (used in While)
	Continue
)

func (KeywordType) String

func (k KeywordType) String() string

type PatchObjectModel added in v3.2.0

type PatchObjectModel struct {
	BaseCommand
	// Key to update
	Key string
	// Patch to apply in JSON format
	Patch string
}

PatchObjectModel applies as full patch to the object model. May be used only in non-SPI mode

func NewPatchObjectModel added in v3.2.0

func NewPatchObjectModel(key, patch string) *PatchObjectModel

NewPatchObjectModel creates a new SetObjectModel for the given key-patch pair

type PluginControl added in v3.2.0

type PluginControl struct {
	BaseCommand
	// Plugin is the name of the plugin
	Plugin string
}

PluginControl is used to start/stop/uninstall plugins

func NewStartPlugin added in v3.2.0

func NewStartPlugin(plugin string) *PluginControl

NewStartPlugin creates a new start command for the given plugin

func NewStopPlugin added in v3.2.0

func NewStopPlugin(plugin string) *PluginControl

NewStopPlugin creates a new stop command for the given plugin

func NewUninstallPlugin added in v3.2.0

func NewUninstallPlugin(plugin string) *PluginControl

NewUninstallPlugin creates a new uninstall command for the given plugin

type ReceivedHttpRequest

type ReceivedHttpRequest struct {
	// SessionId of the corresponding user session. This is -1 if it is an anonymous request
	SessionId int64
	// Queries is a map of HTTP query parameters
	Queries map[string]string
	// Headers is a map of HTTP headers
	Headers map[string]string
	// ContentType is the type of the request body
	ContentType string
	// Body content as plain-text or the filename where the body payload was saved
	// if HttpEndpointCommand.IsUploadRequest is true
	Body string
}

ReceivedHttpRequest is the notification sent by the webserver when a new HTTP request is received

func NewReceivedHttpRequest

func NewReceivedHttpRequest() *ReceivedHttpRequest

NewReceivedHttpRequest creates a new default ReceivedHttpRequest

type RemoveUserSession

type RemoveUserSession struct {
	BaseCommand
	// Id of the user session to remove
	Id int
}

RemoveUserSession to remove an existing user session

func NewRemoveUserSession

func NewRemoveUserSession(id int) *RemoveUserSession

NewRemoveUserSession to create a correctly initialized instance of RemoveUserSession

type Resolve

type Resolve struct {
	BaseCommand
	// Type of the resolving message
	Type messages.MessageType
	// Content of the resolving message
	Content string
}

Resolve the code to intercept and return the given message details for its completion.

func NewResolve

func NewResolve(mType messages.MessageType, content string) *Resolve

NewResolve creates a new Resolve for the given type and message

type ResolvePath

type ResolvePath struct {
	BaseCommand
	// POath that is RepRapFirmware-compatible
	Path string
}

ResolvePath will resolve a RepRapFirmware-style path to an actual file system path

func NewResolvePath

func NewResolvePath(path string) *ResolvePath

NewResolvePath creates a new ResolvePath for the given path

type Response

type Response interface {
	// IsSuccess returns true if the sent command was executed successfully
	IsSuccess() bool
	// GetResult returns the response body
	GetResult() interface{}
	// GetErrorType returns the type of error if it was not succesful
	GetErrorType() string
	// GetErrorMessage returns the error message if it was not successful
	GetErrorMessage() string
}

Response is a generic response interface

type SendHttpResponse

type SendHttpResponse struct {
	// StatusCode (HTTP or WebSocket) to return. If this is greater or equal to 1000 the WbeSocket is closed
	StatusCode uint16
	// Response is the content to return. If this is null or empty and a WebSocket is conencted the connection is closed
	Response string
	// ResponseType of the content to return. Ignored if a WebSocket is connected.
	ResponseType HttpResponseType
}

SendHttpResponse responds to a received HTTP request

func NewSendHttpResponse

func NewSendHttpResponse(statusCode uint16, response string, t HttpResponseType) *SendHttpResponse

NewSendHttpResponse creates a new SendHttpResponse for the given status code, response body and type.

type SetObjectModel added in v3.2.0

type SetObjectModel struct {
	BaseCommand
	// PropertyPtath to the property in the machine model
	PropertyPath string
	// Value is the string representation of the value to set
	Value string
}

SetObjectModel sets an atomic property in the machine model. Mameksure to acquire the read/wrtie lock first.

func NewSetObjectModel added in v3.2.0

func NewSetObjectModel(path, val string) *SetObjectModel

NewSetObjectModel creates a new SetObjectModel for the given key-value pair

type SetPluginData added in v3.2.0

type SetPluginData struct {
	BaseCommand
	// Plugin is the name of the plugin
	Plugin string
	// Key to set
	Key string
	// Value to set
	Value string
}

SetPluginData sets custom plugin data in the object model May be used to update only the own plugin data unless the plugin has the SbcPermissions.ManagePlugins permission.

func NewSetPluginData added in v3.2.0

func NewSetPluginData(plugin, key, value string) *SetPluginData

New SetPluginData creates a new command to set plugin data

type SetUpdateStatus added in v3.2.0

type SetUpdateStatus struct {
	BaseCommand
	// Updating sets whether an update is in progress
	Updating bool
}

SetUpdateStatus overrides the current status as reported by the object model when performing a software update

func NewSetUpdateStatus added in v3.2.0

func NewSetUpdateStatus(updating bool) *SetUpdateStatus

NewSetUpdateStatus creates a new SetUpdateStatus command

type SimpleCode

type SimpleCode struct {
	BaseCommand
	// Code to parse and execute
	Code string
	// Channel to execute this code on
	Channel types.CodeChannel
}

SimpleCode performs a simple G/M/T-code. On the server the code passed is converted to a full Code instance and on completion its CodeResult is transformed back into a basic string. This is useful for minimal extensions that do not require granular control of the code details. Important Note: Except for certain cases, it is NOT recommended for usage in connection.InterceptionConnection because it renders the internal code buffer useless.

func NewSimpleCode

func NewSimpleCode(code string, channel types.CodeChannel) *SimpleCode

NewSimpleCode creates a new SimpleCode for the given code and channel.

type WriteMessage

type WriteMessage struct {
	BaseCommand
	// Type of the message to write
	Type messages.MessageType
	// Content of the message to write
	Content string
	// OutputMessage on the console and via the object model
	OutputMessage bool
	// LogMessage writes the message to the log file (if applicable)
	LogMessage bool
}

WriteMessage writes an arbitrary generic message. If neither OutputMessage nor LogMessage is true the message is written to the console output.

func NewWriteMessage

func NewWriteMessage(mType messages.MessageType, content string, outputMessage, logMessage bool) *WriteMessage

NewWriteMessage creates a new WriteMessage

Jump to

Keyboard shortcuts

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