001package jmri.jmrix.can.cbus.swing.modules.sprogdcc;
002
003import java.util.*;
004
005import javax.annotation.Nonnull;
006
007import jmri.jmrix.can.cbus.node.CbusNode;
008import jmri.jmrix.can.cbus.node.CbusNodeNVTableDataModel;
009import jmri.jmrix.can.cbus.swing.modules.*;
010
011import org.openide.util.lookup.ServiceProvider;
012
013/**
014 * Returns configuration objects for a SPROG DCC CANISB
015 *
016 * @author Andrew Crosland Copyright (C) 2021
017 */
018@ServiceProvider(service = CbusConfigPaneProvider.class)
019public class CanisbPaneProvider extends CbusConfigPaneProvider {
020    
021    String type = "CANISB";
022    
023    public static final int RX_ERR_CNT = 1;
024    public static final int TX_ERR_CNT = 2;
025    public static final int TX_FAIL_CNT = 3;
026    public static final int RX_OVFLW_COUNT = 4;
027    public static final int SETUP = 5;
028    public static final int CAN_DISABLE = 6;
029    public static final int CANID = 7;
030    public static final int NN_HI = 8;
031    public static final int NN_LO = 9;
032    public static final int CAN_ERR_STATUS_1 = 10;
033    public static final int CAN_ERR_STATUS_2 = 11;
034    public static final int CAN_ERR_CONTROL = 12;
035    public static final int CAN_NOM_BIT_RATE_RX_COUNT = 13;
036    public static final int CAN_NOM_BIT_RATE_TX_COUNT = 14;
037    public static final int CAN_ERR_FREE_COUNT_HI = 15;
038    public static final int CAN_ERR_FREE_COUNT_LO = 16;
039    public static final int CAN_DIAGNOSTICS_HI = 17;
040    public static final int CAN_DIAGNOSTICS_LO = 18;
041    public static final int HOST_TX_CNT_T = 19;
042    public static final int HOST_TX_CNT_U = 20;
043    public static final int HOST_TX_CNT_H = 21;
044    public static final int HOST_TX_CNT_L = 22;
045    public static final int HOST_RX_CNT_T = 23;
046    public static final int HOST_RX_CNT_U = 24;
047    public static final int HOST_RX_CNT_H = 25;
048    public static final int HOST_RX_CNT_L = 26;
049    public static final int CAN_TX_CNT_T = 27;
050    public static final int CAN_TX_CNT_U = 28;
051    public static final int CAN_TX_CNT_H = 29;
052    public static final int CAN_TX_CNT_L = 30;
053    public static final int CAN_RX_CNT_T = 31;
054    public static final int CAN_RX_CNT_U = 32;
055    public static final int CAN_RX_CNT_H = 33;
056    public static final int CAN_RX_CNT_L = 34;
057    public static final int CAN_TX_ARB_DELAY = 35;
058    
059    // These may be overridden in scripts for unusual use cases
060    public static int MIN_CANID = 100;
061    public static int MAX_CANID = 127;
062    public static int MIN_NN = 65520;
063    public static int MAX_NN = 65534;
064
065    public CanisbPaneProvider() {
066        super();
067    }
068    
069    /** {@inheritDoc} */
070    @Override
071    @Nonnull
072    public String getModuleType() {
073        return type;
074    }
075
076    /**
077     * Hashmap for decoding NV names
078     */
079    protected static final Map<Integer, String> nvMap = createNvMap();
080
081    /*
082     * Populate hashmap with nv strings
083     *
084     */
085    protected static Map<Integer, String> createNvMap() {
086        Map<Integer, String> result = new HashMap<>();
087        result.put(0, "Error - invalid NV index");
088        result.put(RX_ERR_CNT, Bundle.getMessage("CanRxErrorCount"));
089        result.put(TX_ERR_CNT, Bundle.getMessage("CanTxErrorCount"));
090        result.put(TX_FAIL_CNT, Bundle.getMessage("CanTxFailureCount"));
091        result.put(RX_OVFLW_COUNT, Bundle.getMessage("CanRxOverflowCount"));
092        result.put(SETUP, Bundle.getMessage("SetupMode"));
093        result.put(CAN_DISABLE, Bundle.getMessage("CanDisable"));
094        result.put(CANID, Bundle.getMessage("CanId"));
095        result.put(NN_HI, Bundle.getMessage("NodeNumberHi"));
096        result.put(NN_LO, Bundle.getMessage("NodeNumberLo"));
097        result.put(CAN_ERR_STATUS_1, Bundle.getMessage("CanErrStatus")+" 1");
098        result.put(CAN_ERR_STATUS_2, Bundle.getMessage("CanErrStatus")+" 2");
099        result.put(CAN_ERR_CONTROL, Bundle.getMessage("CanErrControl"));
100        result.put(CAN_NOM_BIT_RATE_RX_COUNT, Bundle.getMessage("CanNomBitRateRxCount"));
101        result.put(CAN_NOM_BIT_RATE_TX_COUNT, Bundle.getMessage("CanNomBitRateTxCount"));
102        result.put(CAN_ERR_FREE_COUNT_HI, Bundle.getMessage("CanErrFreeCount")+" Hi");
103        result.put(CAN_ERR_FREE_COUNT_LO, Bundle.getMessage("CanErrFreeCount")+" Lo");
104        result.put(CAN_DIAGNOSTICS_HI, Bundle.getMessage("CanDiagnostics")+" Hi");
105        result.put(CAN_DIAGNOSTICS_LO, Bundle.getMessage("CanDiagnostics")+" Lo");
106        result.put(HOST_TX_CNT_T, Bundle.getMessage("HostTxCnt")+" Top");
107        result.put(HOST_TX_CNT_U, Bundle.getMessage("HostTxCnt")+" Upper");
108        result.put(HOST_TX_CNT_H, Bundle.getMessage("HostTxCnt")+" Hi");
109        result.put(HOST_TX_CNT_L, Bundle.getMessage("HostTxCnt")+" Lo");
110        result.put(HOST_RX_CNT_T, Bundle.getMessage("HostRxCnt")+" Top");
111        result.put(HOST_RX_CNT_U, Bundle.getMessage("HostRxCnt")+" Upper");
112        result.put(HOST_RX_CNT_H, Bundle.getMessage("HostRxCnt")+" Hi");
113        result.put(HOST_RX_CNT_L, Bundle.getMessage("HostRxCnt")+" Lo");
114        result.put(CAN_TX_CNT_T, Bundle.getMessage("CanTxCnt")+" Top");
115        result.put(CAN_TX_CNT_U, Bundle.getMessage("CanTxCnt")+" Upper");
116        result.put(CAN_TX_CNT_H, Bundle.getMessage("CanTxCnt")+" Hi");
117        result.put(CAN_TX_CNT_L, Bundle.getMessage("CanTxCnt")+" Lo");
118        result.put(CAN_RX_CNT_T, Bundle.getMessage("CanRxCnt")+" Top");
119        result.put(CAN_RX_CNT_U, Bundle.getMessage("CanRxCnt")+" Upper");
120        result.put(CAN_RX_CNT_H, Bundle.getMessage("CanRxCnt")+" Hi");
121        result.put(CAN_RX_CNT_L, Bundle.getMessage("CanRxCnt")+" Lo");
122        result.put(CAN_TX_ARB_DELAY, Bundle.getMessage("TxArbDelay"));
123
124        return Collections.unmodifiableMap(result);
125    }    
126    
127    /** {@inheritDoc} */
128    @Override
129    public String getNVNameByIndex(int index) {
130        // look for the NV
131        String nv = nvMap.get(index);
132        if (nv == null) {
133            return Bundle.getMessage("UnknownNv");
134        } else {
135            return nv;
136        }
137    }
138
139    /** {@inheritDoc} */
140    @Override
141    public AbstractEditNVPane getEditNVFrameInstance() {
142        return _nVarEditFrame;
143    }
144
145    /** {@inheritDoc} */
146    @Override
147    public AbstractEditNVPane getEditNVFrame(CbusNodeNVTableDataModel dataModel, CbusNode node) {
148//        if (_nVarEditFrame == null ){
149            _nVarEditFrame = new CanisbEditNVPane(dataModel, node);
150//        }
151        return _nVarEditFrame.getContent();
152    }
153    
154}