All Downloads are FREE. Search and download functionalities are using the official Maven repository.

info.gratour.jt808core.protocol.JTSiChuanAdasAlarmBit Maven / Gradle / Ivy

Go to download

`jt-core` is a java/scala communication processing library for JT808/JT809/JT1078 standard.

The newest version!
/*******************************************************************************
 *  Copyright (c) 2019, 2020 lucendar.com.
 *  All rights reserved.
 *
 *  Contributors:
 *     KwanKin Yau ([email protected]) - initial API and implementation
 *******************************************************************************/
package info.gratour.jt808core.protocol;

import info.gratour.common.utils.BitUtils;

import java.util.Locale;
import java.util.ResourceBundle;

class JTSiChuanAdasAlarmNames {

    public static final String MESSAGE_KEY_DRIVING_ASSIST_ALM = "adas.driving_assist.0";
    public static final String MESSAGE_KEY_DRIVER_BEHAV_ALM = "adas.driver_behav.1";
    public static final String MESSAGE_KEY_TYRE_STATE_ALM = "adas.tyre_state.2";
    public static final String MESSAGE_KEY_BLIND_AREA_ALM = "adas.blind_area.3";
    public static final String MESSAGE_KEY_INTENSE_DRIVING_ALM = "adas.intense_driving.4";
    public static final String MESSAGE_KEY_OVER_SPD_ALM = "adas.over_spd.5";

    private static final String[] MESSAGE_KEYS = new String[]{
            MESSAGE_KEY_DRIVING_ASSIST_ALM,
            MESSAGE_KEY_DRIVER_BEHAV_ALM,
            MESSAGE_KEY_TYRE_STATE_ALM,
            MESSAGE_KEY_BLIND_AREA_ALM,
            MESSAGE_KEY_INTENSE_DRIVING_ALM,
            MESSAGE_KEY_OVER_SPD_ALM
    };

    private static String alarmMessageKey(int bitIndex) {
        if (bitIndex >= 0 && bitIndex < MESSAGE_KEYS.length)
            return MESSAGE_KEYS[bitIndex];
        else
            return null;
    }

    private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("info.gratour.jt808core.protocol.adas-alarm-names", Locale.getDefault());

    static String getAlarmName(int bitIndex) {
        String key = alarmMessageKey(bitIndex);
        if (key != null)
            return BUNDLE.getString(key);
        else
            return null;
    }

}

public enum JTSiChuanAdasAlarmBit {

    DRIVING_ASSIST_ALM(0),
    DRIVER_BEHAV_ALM(1),
    TYRE_STATE_ALM(2),
    BLIND_AREA_ALM(3),
    INTENSE_DRIVING_ALM(4),
    OVER_SPD_ALM(5);



    private int index;
    private String alarmName;

    JTSiChuanAdasAlarmBit(int bitIndex) {
        this.index = bitIndex;
        alarmName = JTSiChuanAdasAlarmNames.getAlarmName(bitIndex);
    }

    public int bitIndex() {
        return index;
    }

    public String alarmName() {
        return alarmName;
    }

    public static String adasAlmText(int adasAlmBits) {
        StringBuilder str = new StringBuilder();
        boolean first = true;
        for (JTSiChuanAdasAlarmBit bit : values()) {
            if (BitUtils.test(adasAlmBits, bit.index)) {
                if (first)
                    first = false;
                else
                    str.append(',');
                str.append(bit.alarmName);
            }
        }
        return str.toString();

    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy