void QApplicationCommand::setMistEnabled(bool enable)
{
    if (m_connectionState != Connected) {
        return;
    }

    if (enable)
    {
        sendCommandMessage(pb::MT_EMC_COOLANT_MIST_ON);
    }
    else
    {
        sendCommandMessage(pb::MT_EMC_COOLANT_MIST_OFF);
    }
}
void QApplicationCommand::setSpindleBrake(QApplicationCommand::SpindleBrake brake)
{
    if (m_connectionState != Connected) {
        return;
    }

    if (brake == EngageBrake)
    {
        sendCommandMessage(pb::MT_EMC_SPINDLE_BRAKE_ENGAGE);
    }
    else if (brake == ReleaseBrake)
    {
        sendCommandMessage(pb::MT_EMC_SPINDLE_BRAKE_RELEASE);
    }
}
void QApplicationCommand::jog(QApplicationCommand::JogType type, int axisIndex, double velocity, double distance)
{
    if (m_connectionState != Connected) {
        return;
    }

    pb::ContainerType containerType;
    pb::EmcCommandParameters *commandParams = m_tx.mutable_emc_command_params();
    commandParams->set_index(axisIndex);

    if (type == StopJog)
    {
        containerType = pb::MT_EMC_AXIS_ABORT;
    }
    else if (type == ContinousJog) {
        containerType = pb::MT_EMC_AXIS_JOG;
        commandParams->set_velocity(velocity);
    }
    else if (type == IncrementJog)
    {
        containerType = pb::MT_EMC_AXIS_INCR_JOG;
        commandParams->set_velocity(velocity);
        commandParams->set_distance(distance);
    }
    else
    {
        m_tx.Clear();
        return;
    }

    sendCommandMessage(containerType);
}
void QApplicationCommand::loadToolTable()
{
    if (m_connectionState != Connected) {
        return;
    }

    sendCommandMessage(pb::MT_EMC_TOOL_LOAD_TOOL_TABLE);
}
void QApplicationLauncher::shutdown()
{
    if (!m_connected) {
        return;
    }

    sendCommandMessage(pb::MT_LAUNCHER_SHUTDOWN);
}
void QApplicationCommand::shutdown()
{
    if (m_connectionState != Connected) {
        return;
    }

    sendCommandMessage(pb::MT_SHUTDOWN);
}
void QApplicationCommand::overrideLimits()
{
    if (m_connectionState != Connected) {
        return;
    }

    sendCommandMessage(pb::MT_EMC_AXIS_OVERRIDE_LIMITS);
}
void QApplicationLauncher::call(const QString &command)
{
    if (!m_connected) {
        return;
    }

    m_tx.set_name(command.toStdString());
    sendCommandMessage(pb::MT_LAUNCHER_CALL);
}
void QApplicationLauncher::kill(int index)
{
    if (!m_connected) {
        return;
    }

    m_tx.set_index(index);
    sendCommandMessage(pb::MT_LAUNCHER_KILL);
}
void QApplicationLauncher::terminate(int index)
{
    if (!m_connected) {
        return;
    }

    m_tx.set_index(index);
    sendCommandMessage(pb::MT_LAUNCHER_TERMINATE);
}
void QApplicationCommand::abort(const QString &interpreter)
{
    if (m_connectionState != Connected) {
        return;
    }

    m_tx.set_interp_name(interpreter.toStdString());

    sendCommandMessage(pb::MT_EMC_TASK_ABORT);
}
void QApplicationLauncher::writeToStdin(int index, const QString &data)
{
    if (!m_connected) {
        return;
    }

    m_tx.set_index(index);
    m_tx.set_name(data.toStdString());
    sendCommandMessage(pb::MT_LAUNCHER_WRITE_STDIN);
}
void QApplicationCommand::resumeProgram(const QString &interpreter)
{
    if (m_connectionState != Connected) {
        return;
    }

    m_tx.set_interp_name(interpreter.toStdString());

    sendCommandMessage(pb::MT_EMC_TASK_PLAN_RESUME);
}
void QApplicationCommand::setSpindleOverride(double scale)
{
    if (m_connectionState != Connected) {
        return;
    }

    pb::EmcCommandParameters *commandParams = m_tx.mutable_emc_command_params();
    commandParams->set_scale(scale);

    sendCommandMessage(pb::MT_EMC_TRAJ_SET_SPINDLE_SCALE);
}
void QApplicationCommand::setAdaptiveFeedEnabled(bool enable)
{
    if (m_connectionState != Connected) {
        return;
    }

    pb::EmcCommandParameters *commandParams = m_tx.mutable_emc_command_params();
    commandParams->set_enable(enable);

    sendCommandMessage(pb::MT_EMC_MOTION_ADAPTIVE);
}
void QApplicationCommand::unhomeAxis(int index)
{
    if (m_connectionState != Connected) {
        return;
    }

    pb::EmcCommandParameters *commandParams = m_tx.mutable_emc_command_params();
    commandParams->set_index(index);

    sendCommandMessage(pb::MT_EMC_AXIS_UNHOME);
}
void QApplicationCommand::setTrajectoryMode(QApplicationStatus::TrajectoryMode mode)
{
    if (m_connectionState != Connected) {
        return;
    }

    pb::EmcCommandParameters *commandParams = m_tx.mutable_emc_command_params();
    commandParams->set_traj_mode((pb::EmcTrajectoryModeType)mode);

    sendCommandMessage(pb::MT_EMC_TRAJ_SET_MODE);
}
void QApplicationCommand::setTeleopEnabled(bool enable)
{
    if (m_connectionState != Connected) {
        return;
    }

    pb::EmcCommandParameters *commandParams = m_tx.mutable_emc_command_params();
    commandParams->set_enable(enable);

    sendCommandMessage(pb::MT_EMC_TRAJ_SET_TELEOP_ENABLE);
}
void QApplicationCommand::setMaximumVelocity(double velocity)
{
    if (m_connectionState != Connected) {
        return;
    }

    pb::EmcCommandParameters *commandParams = m_tx.mutable_emc_command_params();
    commandParams->set_velocity(velocity);

    sendCommandMessage(pb::MT_EMC_TRAJ_SET_MAX_VELOCITY);
}
void QApplicationCommand::setDebugLevel(int debugLevel)
{
    if (m_connectionState != Connected) {
        return;
    }

    pb::EmcCommandParameters *commandParams = m_tx.mutable_emc_command_params();
    commandParams->set_debug_level(debugLevel);

    sendCommandMessage(pb::MT_EMC_SET_DEBUG);
}
void QApplicationCommand::setOptionalStopEnabled(bool enable)
{
    if (m_connectionState != Connected) {
        return;
    }

    pb::EmcCommandParameters *commandParams = m_tx.mutable_emc_command_params();
    commandParams->set_enable(enable);

    sendCommandMessage(pb::MT_EMC_TASK_PLAN_OPTIONAL_STOP);
}
void QApplicationCommand::setBlockDeleteEnabled(bool enable)
{
    if (m_connectionState != Connected) {
        return;
    }

    pb::EmcCommandParameters *commandParams = m_tx.mutable_emc_command_params();
    commandParams->set_enable(enable);

    sendCommandMessage(pb::MT_EMC_TASK_PLAN_SET_BLOCK_DELETE);
}
void QApplicationCommand::openProgram(const QString &interpreter, const QString &filePath)
{
    if (m_connectionState != Connected) {
        return;
    }

    pb::EmcCommandParameters *commandParams = m_tx.mutable_emc_command_params();
    commandParams->set_path(QUrl(filePath).toLocalFile().toStdString());
    m_tx.set_interp_name(interpreter.toStdString());

    sendCommandMessage(pb::MT_EMC_TASK_PLAN_OPEN);
}
void QApplicationCommand::setAnalogOutput(int index, double value)
{
    if (m_connectionState != Connected) {
        return;
    }

    pb::EmcCommandParameters *commandParams = m_tx.mutable_emc_command_params();
    commandParams->set_index(index);
    commandParams->set_value(value);

    sendCommandMessage(pb::MT_EMC_MOTION_SET_AOUT);
}
void QApplicationCommand::runProgram(const QString &interpreter, int lineNumber = 0)
{
    if (m_connectionState != Connected) {
        return;
    }

    pb::EmcCommandParameters *commandParams = m_tx.mutable_emc_command_params();
    commandParams->set_line_number(lineNumber);
    m_tx.set_interp_name(interpreter.toStdString());

    sendCommandMessage(pb::MT_EMC_TASK_PLAN_RUN);
}
void QApplicationCommand::setAxisMinPositionLimit(int axisIndex, double value)
{
    if (m_connectionState != Connected) {
        return;
    }

    pb::EmcCommandParameters *commandParams = m_tx.mutable_emc_command_params();
    commandParams->set_index(axisIndex);
    commandParams->set_value(value);

    sendCommandMessage(pb::MT_EMC_AXIS_SET_MIN_POSITION_LIMIT);
}
void QApplicationCommand::setDigitalOutput(int index, bool enable)
{
    if (m_connectionState != Connected) {
        return;
    }

    pb::EmcCommandParameters *commandParams = m_tx.mutable_emc_command_params();
    commandParams->set_index(index);
    commandParams->set_enable(enable);

    sendCommandMessage(pb::MT_EMC_MOTION_SET_DOUT);
}
void QApplicationCommand::setTaskState(const QString &interpreter, TaskState state)
{
    if (m_connectionState != Connected) {
        return;
    }

    pb::EmcCommandParameters *commandParams = m_tx.mutable_emc_command_params();
    commandParams->set_task_state((pb::EmcTaskStateType)state);
    m_tx.set_interp_name(interpreter.toStdString());

    sendCommandMessage(pb::MT_EMC_TASK_SET_STATE);
}
void QApplicationCommand::executeMdi(const QString &interpreter, const QString &command)
{
    if (m_connectionState != Connected) {
        return;
    }

    pb::EmcCommandParameters *commandParams = m_tx.mutable_emc_command_params();
    commandParams->set_command(command.toStdString());
    m_tx.set_interp_name(interpreter.toStdString());

    sendCommandMessage(pb::MT_EMC_TASK_PLAN_EXECUTE);
}
void QApplicationLauncher::start(int index)
{
    if (!m_connected) {
        return;
    }

#ifdef QT_DEBUG
    DEBUG_TAG(1, m_commandIdentity, "starting launcher" << index)
#endif

    m_tx.set_index(index);
    sendCommandMessage(pb::MT_LAUNCHER_START);
}