org.bidib.jbidibc.StartMacro Maven / Gradle / Ivy
package org.bidib.jbidibc;
import org.bidib.jbidibc.core.node.AccessoryNode;
import org.bidib.jbidibc.messages.Node;
import org.bidib.jbidibc.messages.enums.LcMacroOperationCode;
import org.bidib.jbidibc.messages.exception.PortNotFoundException;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
/**
* This commands starts the macro on the specified node.
*
*/
@Command
public class StartMacro extends BidibNodeCommand {
@Option(names = { "-macro" }, description = "The macro number", required = true)
private int macroNumber;
public static void main(String[] args) {
run(new StartMacro(), args);
}
@Override
public Integer call() {
int result = 20;
try {
openPort(getPortName(), null);
Node node = findNode();
if (node != null) {
AccessoryNode accessoryNode = getBidib().getAccessoryNode(node);
if (accessoryNode != null) {
accessoryNode.handleMacro(macroNumber, LcMacroOperationCode.START);
result = 0;
}
else {
System.err.println("node with unique id \"" + getNodeIdentifier() + "\" doesn't have macros"); // NOSONAR
}
}
else {
System.err.println("node with unique id \"" + getNodeIdentifier() + "\" not found"); // NOSONAR
}
getBidib().close();
}
catch (PortNotFoundException ex) {
System.err
.println("The provided port was not found: " + ex.getMessage() // NOSONAR
+ ". Verify that the BiDiB device is connected.");
}
catch (Exception ex) {
System.err.println("Execute command failed: " + ex); // NOSONAR
}
return result;
}
}