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
- Variables
- type AddUserSession
- type BaseCommand
- func NewAcknowledge() *BaseCommand
- func NewBaseCommand(command string) *BaseCommand
- func NewCancel() *BaseCommand
- func NewGetObjectModel() *BaseCommand
- func NewIgnore() *BaseCommand
- func NewLockObjectModel() *BaseCommand
- func NewStartPlugins() *BaseCommand
- func NewStopPlugins() *BaseCommand
- func NewSyncObjectModel() *BaseCommand
- func NewUnlockObjectModel() *BaseCommand
- type BaseResponse
- type CheckPassword
- type Code
- func (c *Code) Clone() *Code
- func (c *Code) GetUnprecedentedString(quote bool) string
- func (c *Code) HasFlag(flag CodeFlags) bool
- func (c *Code) HasParameter(letter string) bool
- func (c *Code) IsMajorNumber(n int64) bool
- func (c *Code) Parameter(letter string) *CodeParameter
- func (c *Code) ParameterOrDefault(letter string, value interface{}) *CodeParameter
- func (c *Code) RemoveParameter(letter string) *CodeParameter
- func (c *Code) ReplaceParameter(letter string, np *CodeParameter) bool
- func (c *Code) ShortString() string
- func (c *Code) String() string
- type CodeFlags
- type CodeParameter
- func (cp *CodeParameter) AsBool() (bool, error)
- func (cp *CodeParameter) AsDriverId() (types.DriverId, error)
- func (cp *CodeParameter) AsDriverIdSlice() ([]types.DriverId, error)
- func (cp *CodeParameter) AsFloat64() (float64, error)
- func (cp *CodeParameter) AsFloat64Slice() ([]float64, error)
- func (cp *CodeParameter) AsInt64() (int64, error)
- func (cp *CodeParameter) AsInt64Slice() ([]int64, error)
- func (cp *CodeParameter) AsString() string
- func (cp *CodeParameter) AsUint64() (uint64, error)
- func (cp *CodeParameter) AsUint64Slice() ([]uint64, error)
- func (cp *CodeParameter) Clone() *CodeParameter
- func (cp *CodeParameter) ConvertDriverIds() error
- func (cp *CodeParameter) MarshalJSON() ([]byte, error)
- func (cp CodeParameter) String() string
- func (cp *CodeParameter) UnmarshalJSON(data []byte) error
- type CodeResult
- type CodeType
- type Command
- type EvaluateExpression
- type Flush
- type GetFileInfo
- type HttpEndpointCommand
- type HttpResponseType
- type InstallPlugin
- type KeywordType
- type PatchObjectModel
- type PluginControl
- type ReceivedHttpRequest
- type RemoveUserSession
- type Resolve
- type ResolvePath
- type Response
- type SendHttpResponse
- type SetObjectModel
- type SetPluginData
- type SetUpdateStatus
- type SimpleCode
- type WriteMessage
Constants ¶
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" )
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" )
const ( // LetterForUnprecentedString is a special value for Parameters // that have no preceding letter LetterForUnprecentedString = "@" )
Variables ¶
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 NewGetObjectModel ¶
func NewGetObjectModel() *BaseCommand
NewGetObjectModel returns a GetObjectModel command
func NewLockObjectModel ¶
func NewLockObjectModel() *BaseCommand
NewLockObjectModel returns a LockObjectModel command
func NewStartPlugins ¶
func NewStartPlugins() *BaseCommand
NewStartPlugins starts all previously started plugins again
func NewStopPlugins ¶
func NewStopPlugins() *BaseCommand
NewStopPlugins returns a command to stop all plugins and save which plugins were running. This command is intended for shutdown or update requests
func NewSyncObjectModel ¶
func NewSyncObjectModel() *BaseCommand
NewSyncObjectModel returns a SyncObjectModel command
func NewUnlockObjectModel ¶
func NewUnlockObjectModel() *BaseCommand
NewUnlockObjectModel returns a UnlockObjectModel command
func (*BaseCommand) GetCommand ¶
func (bc *BaseCommand) GetCommand() string
GetCommand returns the type of command
type BaseResponse ¶
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 CheckPassword ¶
type CheckPassword struct { BaseCommand Password string }
CheckPassword checks if the given password is correct and matches the previously set value from M551. If no password was configured before or if it was set to "reprap" this will always return true.
func NewCheckPassword ¶
func NewCheckPassword(password string) *CheckPassword
NewCheckPassword creates a new CheckPassword instance for the given password
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 (*Code) GetUnprecedentedString ¶
GetUnprecedentedString reconstructs an unprecedented string from parameter list
func (*Code) HasParameter ¶
HasParameter returns whether or not a certain parameter is present without returning the CodeParameter instance
func (*Code) IsMajorNumber ¶
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 ¶
ShortString converts only the command portion to text-based G/M/T-code (e.g. G28)
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 ¶
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 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 ¶
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 ¶
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 // Deprecated: was never supported by RRF Return // Abort instruction Abort // Var operation Var // Set operation Set // Echo operation Echo // Continue instruction (used in While) Continue // Global operation Global )
func (KeywordType) String ¶
func (k KeywordType) String() string
type PatchObjectModel ¶
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 ¶
func NewPatchObjectModel(key, patch string) *PatchObjectModel
NewPatchObjectModel creates a new SetObjectModel for the given key-patch pair
type PluginControl ¶
type PluginControl struct { BaseCommand // Plugin is the identifier of the plugin Plugin string }
PluginControl is used to start/stop/uninstall plugins
func NewStartPlugin ¶
func NewStartPlugin(plugin string) *PluginControl
NewStartPlugin creates a new start command for the given plugin
func NewStopPlugin ¶
func NewStopPlugin(plugin string) *PluginControl
NewStopPlugin creates a new stop command for the given plugin
func NewUninstallPlugin ¶
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 ¶
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 ¶
func NewSetObjectModel(path, val string) *SetObjectModel
NewSetObjectModel creates a new SetObjectModel for the given key-value pair
type SetPluginData ¶
type SetPluginData struct { BaseCommand // Plugin is the identifier of the plugin (optional) Plugin string // Key to set Key string // Value custom value to set Value string }
SetPluginData updates 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. Note that the corresponding key must already exist in the plugin data!
func NewSetPluginData ¶
func NewSetPluginData(plugin, key, value string) *SetPluginData
New SetPluginData creates a new command to set plugin data
type SetUpdateStatus ¶
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 ¶
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) // Deprecated: in favor of LogLevel LogMessage bool // LogLevel of this message LogLevel *state.LogLevel }
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 bool, logLevel *state.LogLevel) *WriteMessage
NewWriteMessage creates a new WriteMessage