<commit_before>#include "MotorFaultList.h"

namespace
{
    int NUMBER_OF_MOTOR_ERRORS = 8;
    int NUMBER_OF_MOTOR_LIMITS = 7;
    //Motor errors
    QString MOTOR_OVER_SPEED = "Motor Over Speed";
    QString SOFTWARE_OVER_CURRENT = "Software Over Current";
    QString DC_BUS_OVER_VOLTAGE = "DC Bus Over Voltage";
    QString DESATURATION_FAULT = "Desaturation Fault";
    QString BAD_MOTOR_POSITION_HALL_SEQUENCE = "Bad Motor Position Hall Sequence";
    QString WATCHDOG_CAUSED_LAST_RESET = "Watchdog Caused Last Reset";
    QString CONFIG_READ_ERROR = "Config Read Error";
    QString RAIL_UNDER_VOLTAGE_LOCK_OUT = "Rail Under-Voltage Lock Out";
    //Motor limits
    QString OUTPUT_VOLTAGE_PWM_LIMIT = "Output Voltage PWM Limit";
    QString MOTOR_CURRENT_LIMIT = "Motor Current Limit";
    QString BUS_CURRENT_LIMIT = "Bus Current Limit";
    QString BUS_VOLTAGE_UPPER_LIMIT = "Bus Voltage Upper Limit";
    QString BUS_VOLTAGE_LOWER_LIMIT = "Bus Voltage Lower Limit";
    QString IPM_MOTOR_TEMPERATURE_LIMIT = "IPM or Motor Temperature Limit";
    QString VELOCITY_LIMIT = "Velocity Limit";
}

MotorFaultList::MotorFaultList()
    : faultLabels_(
{
    FaultLabel(MOTOR_OVER_SPEED, FaultPriorities::HIGH_PRIORITY, false)
    , FaultLabel(SOFTWARE_OVER_CURRENT, FaultPriorities::HIGH_PRIORITY, false)
    , FaultLabel(DC_BUS_OVER_VOLTAGE, FaultPriorities::HIGH_PRIORITY, false)
    , FaultLabel(DESATURATION_FAULT, FaultPriorities::HIGH_PRIORITY, false)
    , FaultLabel(BAD_MOTOR_POSITION_HALL_SEQUENCE, FaultPriorities::MEDIUM_PRIORITY, false)
    , FaultLabel(WATCHDOG_CAUSED_LAST_RESET, FaultPriorities::MEDIUM_PRIORITY, false)
    , FaultLabel(CONFIG_READ_ERROR, FaultPriorities::MEDIUM_PRIORITY, false)
    , FaultLabel(RAIL_UNDER_VOLTAGE_LOCK_OUT, FaultPriorities::MEDIUM_PRIORITY, false)
    , FaultLabel(OUTPUT_VOLTAGE_PWM_LIMIT, FaultPriorities::HIGH_PRIORITY, false)
    , FaultLabel(MOTOR_CURRENT_LIMIT, FaultPriorities::HIGH_PRIORITY, false)
    , FaultLabel(BUS_CURRENT_LIMIT, FaultPriorities::HIGH_PRIORITY, false)
    , FaultLabel(BUS_VOLTAGE_UPPER_LIMIT, FaultPriorities::HIGH_PRIORITY, false)
    , FaultLabel(BUS_VOLTAGE_LOWER_LIMIT, FaultPriorities::HIGH_PRIORITY, false)
    , FaultLabel(IPM_MOTOR_TEMPERATURE_LIMIT, FaultPriorities::MEDIUM_PRIORITY, false)
    , FaultLabel(VELOCITY_LIMIT, FaultPriorities::LOW_PRIORITY, false)
})
, currentFault_(0)
{
}

MotorFaultList::~MotorFaultList()
{
}

FaultLabel MotorFaultList::nextActiveFault()
{
    for (int i = 0; i < (NUMBER_OF_MOTOR_ERRORS + NUMBER_OF_MOTOR_LIMITS); i++)
    {   
        int faultIndex = currentFault_;
        currentFault_++;
        currentFault_ %= (NUMBER_OF_MOTOR_ERRORS + NUMBER_OF_MOTOR_LIMITS);

        if (faultLabels_[faultIndex].isActive())
        {
            return faultLabels_[faultIndex];
        }
    }

    return FaultLabel();
}

QVector<FaultLabel>& MotorFaultList::faultLabels()
{
    return faultLabels_;
}

void MotorFaultList::updateErrors(const ErrorFlags& errorFlags)
{
    faultLabels_[0].setActive(errorFlags.motorOverSpeed());
    faultLabels_[1].setActive(errorFlags.softwareOverCurrent());
    faultLabels_[2].setActive(errorFlags.dcBusOverVoltage());
    faultLabels_[3].setActive(errorFlags.desaturationFault());
    faultLabels_[4].setActive(errorFlags.badMotorPositionHallSequence());
    faultLabels_[5].setActive(errorFlags.watchdogCausedLastReset());
    faultLabels_[6].setActive(errorFlags.configReadError());
    faultLabels_[7].setActive(errorFlags.railUnderVoltageLockOut());
}

void MotorFaultList::updateLimits(const LimitFlags& limitFlags)<commit_msg>Astyle<commit_after>#include "MotorFaultList.h"

namespace
{
    int NUMBER_OF_MOTOR_ERRORS = 8;
    int NUMBER_OF_MOTOR_LIMITS = 7;
    //Motor errors
    QString MOTOR_OVER_SPEED = "Motor Over Speed";
    QString SOFTWARE_OVER_CURRENT = "Software Over Current";
    QString DC_BUS_OVER_VOLTAGE = "DC Bus Over Voltage";
    QString DESATURATION_FAULT = "Desaturation Fault";
    QString BAD_MOTOR_POSITION_HALL_SEQUENCE = "Bad Motor Position Hall Sequence";
    QString WATCHDOG_CAUSED_LAST_RESET = "Watchdog Caused Last Reset";
    QString CONFIG_READ_ERROR = "Config Read Error";
    QString RAIL_UNDER_VOLTAGE_LOCK_OUT = "Rail Under-Voltage Lock Out";
    //Motor limits
    QString OUTPUT_VOLTAGE_PWM_LIMIT = "Output Voltage PWM Limit";
    QString MOTOR_CURRENT_LIMIT = "Motor Current Limit";
    QString BUS_CURRENT_LIMIT = "Bus Current Limit";
    QString BUS_VOLTAGE_UPPER_LIMIT = "Bus Voltage Upper Limit";
    QString BUS_VOLTAGE_LOWER_LIMIT = "Bus Voltage Lower Limit";
    QString IPM_MOTOR_TEMPERATURE_LIMIT = "IPM or Motor Temperature Limit";
    QString VELOCITY_LIMIT = "Velocity Limit";
}

MotorFaultList::MotorFaultList()
    : faultLabels_(
{
    FaultLabel(MOTOR_OVER_SPEED, FaultPriorities::HIGH_PRIORITY, false)
    , FaultLabel(SOFTWARE_OVER_CURRENT, FaultPriorities::HIGH_PRIORITY, false)
    , FaultLabel(DC_BUS_OVER_VOLTAGE, FaultPriorities::HIGH_PRIORITY, false)
    , FaultLabel(DESATURATION_FAULT, FaultPriorities::HIGH_PRIORITY, false)
    , FaultLabel(BAD_MOTOR_POSITION_HALL_SEQUENCE, FaultPriorities::MEDIUM_PRIORITY, false)
    , FaultLabel(WATCHDOG_CAUSED_LAST_RESET, FaultPriorities::MEDIUM_PRIORITY, false)
    , FaultLabel(CONFIG_READ_ERROR, FaultPriorities::MEDIUM_PRIORITY, false)
    , FaultLabel(RAIL_UNDER_VOLTAGE_LOCK_OUT, FaultPriorities::MEDIUM_PRIORITY, false)
    , FaultLabel(OUTPUT_VOLTAGE_PWM_LIMIT, FaultPriorities::HIGH_PRIORITY, false)
    , FaultLabel(MOTOR_CURRENT_LIMIT, FaultPriorities::HIGH_PRIORITY, false)
    , FaultLabel(BUS_CURRENT_LIMIT, FaultPriorities::HIGH_PRIORITY, false)
    , FaultLabel(BUS_VOLTAGE_UPPER_LIMIT, FaultPriorities::HIGH_PRIORITY, false)
    , FaultLabel(BUS_VOLTAGE_LOWER_LIMIT, FaultPriorities::HIGH_PRIORITY, false)
    , FaultLabel(IPM_MOTOR_TEMPERATURE_LIMIT, FaultPriorities::MEDIUM_PRIORITY, false)
    , FaultLabel(VELOCITY_LIMIT, FaultPriorities::LOW_PRIORITY, false)
})
, currentFault_(0)
{
}

MotorFaultList::~MotorFaultList()
{
}

FaultLabel MotorFaultList::nextActiveFault()
{
    for (int i = 0; i < (NUMBER_OF_MOTOR_ERRORS + NUMBER_OF_MOTOR_LIMITS); i++)
    {
        int faultIndex = currentFault_;
        currentFault_++;
        currentFault_ %= (NUMBER_OF_MOTOR_ERRORS + NUMBER_OF_MOTOR_LIMITS);

        if (faultLabels_[faultIndex].isActive())
        {
            return faultLabels_[faultIndex];
        }
    }

    return FaultLabel();
}

QVector<FaultLabel>& MotorFaultList::faultLabels()
{
    return faultLabels_;
}

void MotorFaultList::updateErrors(const ErrorFlags& errorFlags)
{
    faultLabels_[0].setActive(errorFlags.motorOverSpeed());
    faultLabels_[1].setActive(errorFlags.softwareOverCurrent());
    faultLabels_[2].setActive(errorFlags.dcBusOverVoltage());
    faultLabels_[3].setActive(errorFlags.desaturationFault());
    faultLabels_[4].setActive(errorFlags.badMotorPositionHallSequence());
    faultLabels_[5].setActive(errorFlags.watchdogCausedLastReset());
    faultLabels_[6].setActive(errorFlags.configReadError());
    faultLabels_[7].setActive(errorFlags.railUnderVoltageLockOut());
}

void MotorFaultList::updateLimits(const LimitFlags& limitFlags)
{'fraction_non_alphanumeric': 0.09515859766277128, 'fraction_numerical': 0.00333889816360601, 'mean_word_length': 5.782075471698113, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2362975', 'n_tokens_mistral': 2615, 'n_tokens_neox': 2565, 'n_words': 375}