Skip to content
This repository has been archived by the owner on Sep 5, 2022. It is now read-only.

wilriker/execonmcode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deprecated

Since the go-library is no longer maintained this has been superseeded by a version written in Python.

See Duet3D Forum Thread for details.

This repository is now archived.

Description

This is a small extension to DuetSoftwareFramework to execute arbitrary system commands when a user-defined M-Code is encountered.

An example usage would be to execute system shutdown on the SBC when a e.g. M7722 is run.

Usage

$ execonmcode -help
Usage of ./execonmcode:
  -command value
        Command to execute. This can be specified multiple times.
  -debug
        Print debug output
  -execAsync
        Run command to execute async and return success to DCS immediately
  -interceptionMode string
        Interception mode to use (default "Pre")
  -mCode value
        Code that will initiate execution of the command. This can be specified multiple times.
  -noFlush
        Do not flush the code channel before executing the associated command
  -returnOutput
        Return the output of the command back to DCS. Use with care. Cannot be combined with -execAsync.
  -socketPath string
        Path to socket (default "/var/run/dsf/dcs.sock")
  -trace
        Print underlying requests/responses
  -version
        Show version and exit

Starting from version 3 it is possible to provide an arbitrary number of -mCode + -command tuples. This way a single instance of execonmcode can handle multiple commands. Side-effect is that there is no more default for -mCode.

Parameters

execonmcode does provide a simple mechanism for parameter substitution. It is possible to pass string parameters to the selected M-Code and have them inserted in the -command. In the command string they have to be single letters prefixed by the percent-sign (%) and they must not be G, M or T.

All parameters that do not have a corresponding value in the M-Code will be forwarded as given.

Parameters in systemd units

Since % is used to access systemd-specific variables in unit files it is necessary to escape them by using double-percent, i.e. %%.

Example

Run execonmcode as

$ execonmcode -command "mycommand %F %N %D"

Then you can use the following M-Code syntax to replace these parameters

M7722 F"my first parameter" N"my second parameter"

this will lead to an execution of

mycommand "my first parameter" "my second parameter" %D

Note that %D was passed as is since it was not given in the M-Code.

Installation

  • Download from Releases page. When in doubt use the armv7h version.
  • Rename to just execonmcode
  • Make executable via chmod +x execonmcode
  • Put it into any path of your $PATH e.g. /usr/local/bin
  • Run it as root or with sudo
  • Optional: use the shutdownsbc.service systemd unit (included in the repo) to run it at startup and let it shutdown the SBC (customize to your liking)

Contribution

I am happy about comments, suggestions, bug reports, pull requests, etc. either here or in the forum.

About

Small DuetSoftwareFramework extension that listens for a user-defined M code to run a user-defined command on the SBC.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages