
#include "error.h"
#include "comm/protocol.h"
#include <QObject>

#define CASE_OP(cd, str) \
{\
    case cd:\
        errinfo = str;\
        break;\
}

QString getErrStr(u32 code)
{
    QString errinfo;
    errinfo.clear();
    QString errorCode;
    errorCode.clear();

    switch (code)
    {  
        //通用的错误代码
        CASE_OP(ERR_NONE,              QObject::tr(""));     // 没有错误
        CASE_OP(ERR_NO_AIR,            QObject::tr("Insufficient air pressure"));	// 气压不足
        CASE_OP(ERR_NOT_SAFE,          QObject::tr("safe area error"));	// 安全区域介入
        CASE_OP(ERR_EXPIRATION,        QObject::tr("Expiration of use"));	// 使用时限已到
        CASE_OP(ERR_DRIVER,            QObject::tr("Driver alarm"));	// 驱动器报警
        CASE_OP(ERR_FILL_DATA,         QObject::tr("Fill data error"));	// 填充数据错误
        CASE_OP(ERR_NOT_ALLOWED,       QObject::tr("Not allowed to work"));	// 不允许工作状态
        CASE_OP(ERR_CTRL_ERR,          QObject::tr("Control error"));	// 控制错误
        CASE_OP(ERR_FPGA_ERR,          QObject::tr("Motion control chip version error"));	// 运动控制芯片版本错误
        CASE_OP(ERR_BUTTON_NOUP,       QObject::tr("Waiting for button to lift timeout"));	// 等待按钮抬起超时
        CASE_OP(ERR_FPGA_RESET,        QObject::tr("FPGA Reset"));	// FPGA复位
        CASE_OP(ERR_NO_READY,          QObject::tr("Peripheral Device not ready"));	// 外设未就绪
        CASE_OP(ERR_NO_SEND_ERR,      QObject::tr("Transmission data error"));	// 传输数据错误
        CASE_OP(ERR_EDTION_ERR,      QObject::tr("Program version error"));	// 程序版本错误
        CASE_OP(ERR_WORK_DONE,           QObject::tr("Complete output"));	// 完成产量
        CASE_OP(ERR_LMT_POSITIVE,      QObject::tr("Positive limit"));	// 正向限位
        CASE_OP(ERR_LMT_NEGATIVE,      QObject::tr("Negative limit"));	// 反向限位
        CASE_OP(ERR_RUN_ALM,           QObject::tr("Motion alarm"));	// 运动报警
        CASE_OP(ERR_RUN_LIMIT,         QObject::tr("Motion limit"));	// 运动限位
        CASE_OP(ERR_RUN_EMS,           QObject::tr("Emergency stop"));	// 运动急停
        CASE_OP(ERR_MV_PARA,           QObject::tr("Motion parameters error"));     // 运动参数错误
        CASE_OP(ERR_MC_PARA,           QObject::tr("Machine parameters error"));	// 机器参数错误
        CASE_OP(ERR_IN_PARA,           QObject::tr("Input parameters error"));      // 输入参数错误
        CASE_OP(ERR_NOT_WORKSTA,       QObject::tr("Not in work status error"));	// 不能工作状态
        CASE_OP(ERR_NOT_MOVESTA,       QObject::tr("Prohibited frame moving state")); // 禁止移框状态
        CASE_OP(ERR_MTZ_RIGHT,         QObject::tr("Zero success"));                  // 归零成功
        CASE_OP(ERR_MTZ_ERROR,         QObject::tr("Return to zero error"));        // 归零错误
        CASE_OP(ERR_COOR_SYSTM,        QObject::tr("Coordinate system error"));     // 坐标系统错误
        CASE_OP(ERR_OUT_RANGE,         QObject::tr("Target position out of bounds"));	// 目标位置越界
        CASE_OP(ERR_X_LIT_POSI,        QObject::tr("X Positive limit"));	// X正向限位
        CASE_OP(ERR_X_LIT_NEGA,        QObject::tr("X Negative limit"));	// X反向限位
        CASE_OP(ERR_Y_LIT_POSI,        QObject::tr("Y Positive limit"));	// Y正向限位
        CASE_OP(ERR_Y_LIT_NEGA,        QObject::tr("Y Negative limit"));	// Y反向限位
        CASE_OP(ERR_MC_MANUAL,         QObject::tr("Machine is in manual state"));	// 机器处于手动状态
        CASE_OP(ERR_KEY_SW_OFF,        QObject::tr("Machine key off"));	// 机器钥匙开关关闭
        CASE_OP(ERR_NO_DATA,           QObject::tr("None data"));       // 无数据
        CASE_OP(ERR_DATA_ERROR,        QObject::tr("Data error"));        // 数据错误
        CASE_OP(ERR_GRAPH_OUT_RANGE,   QObject::tr("Graphics out of range")); // 图形超出范围
        CASE_OP(ERR_MS_NOT_ZERO,       QObject::tr("Spindle is not in zero position"));	// 主轴不在零位
        CASE_OP(ERR_CUTTER_NOT_POS,    QObject::tr("Scissors are not in position"));	// 剪刀不在回位
        CASE_OP(ERR_UPER_TBREAK,       QObject::tr("Thread is broken"));// 断线
        CASE_OP(ERR_BOBBIN_TBREAK,     QObject::tr("Bottom thread disconnected"));       // 底线断线
        CASE_OP(ERR_TRANS_TIMEOUT,     QObject::tr("Execution command timed out"));       // 执行命令超时
        CASE_OP(ERR_LIFT_TIMEOUT,      QObject::tr("Head lifting timeout"));       // 机头升降超时
        CASE_OP(ERR_CHANGE_BOBBIN,     QObject::tr("Change the bobbin"));       // 更换梭芯
        CASE_OP(ERR_CHANGE_BOBBIN_A,   QObject::tr("Replace bobbin A"));       // 更换梭芯A
        CASE_OP(ERR_CHANGE_BOBBIN_B,   QObject::tr("Replace bobbin B"));       // 更换梭芯B
        CASE_OP(ERR_CHANGE_BOBBIN_STA, QObject::tr("The machine is in the state of replacing the bobbin"));       // 机器处于更换梭芯状态
        CASE_OP(ERR_AIR_POWER,         QObject::tr("Insufficient air pressure"));	// 气压不足
        CASE_OP(ERR_MC_AUTO,           QObject::tr("Machine is in auto state"));	// 机器处于自动状态
        CASE_OP(ERR_INSTALLMENT_OK,    QObject::tr("Password set finished"));	// 密码设置成功
        CASE_OP(ERR_INSTALLMENT_FAIL,  QObject::tr("Password set failed"));     // 密码设置失败
        CASE_OP(ERR_FOOT_POS,  QObject::tr("Presser foot position error"));     // 压脚位置错误

        //通用的状态信息
        CASE_OP(STA_NORMAL_STOP,       QObject::tr("Normal stop"));	// 正常停止
        CASE_OP(STA_MTZ_SUCCESS,       QObject::tr("Find zero success"));	// 归零成功
        CASE_OP(STA_WORK_PAUSE,        QObject::tr("work pause"));	// 工作暂停
        CASE_OP(STA_WORK_OVER,         QObject::tr("End of work"));	// 工作结束
        CASE_OP(STA_WORK_FINISH,       QObject::tr("Work done"));	// 工作完成
        CASE_OP(STA_WORK_DONE,         QObject::tr("Complete production"));	// 完成产量
        CASE_OP(STA_EXEC_SUCCESS,      QObject::tr("Execute success"));	// 执行成功
        CASE_OP(STA_EXEC_FAILED,       QObject::tr("Execute false"));	// 执行失败
        CASE_OP(STA_WAIT_FILE,         QObject::tr("wait file"));       // 等待文件
        CASE_OP(STA_CHANGE_BOBBIN,     QObject::tr("change the bobbin"));	// 更换梭芯
        CASE_OP(STA_PROCESS_FINISH,    QObject::tr("Execute finish"));      // 执行完成
        CASE_OP(STA_PROCESS_RUNNING,   QObject::tr("Execute runnibng"));	// 执行过程中

    default:
        //errorCode.sprintf("CODE 0x%x", code);
        //errinfo.append(QObject::tr("Undefined error,") + errorCode);
        break;
    }
    return errinfo;
}

QString getPromptStr(u32 code)
{
    QString errinfo;
    switch (code)
    {
        CASE_OP(ERR_NO_MATERIEL,       QObject::tr("Please feed"));	// 请上料
        CASE_OP(ERR_CMK_SAFE,          QObject::tr("Safety input alarm"));                                                          // 安全输入报警
    }
    return errinfo;
}
