001package jmri.jmrix.can.cbus.swing.modules.merg; 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.AbstractEditNVPane; 010import jmri.jmrix.can.cbus.swing.modules.CbusConfigPaneProvider; 011 012import org.openide.util.lookup.ServiceProvider; 013 014/** 015 * Returns configuration objects for a SPROG DCC SPROG 3 Plus 016 * 017 * @author Andrew Crosland Copyright (C) 2021 018 */ 019@ServiceProvider(service = CbusConfigPaneProvider.class) 020public class CanCmdPaneProvider extends CbusConfigPaneProvider { 021 022 String type = "CANCMD"; 023 024 public static final int CMD_STATION_NUMBER = 1; 025 public static final int USER_FLAGS = 2; 026 public static final int OPERATIONS_FLAGS = 3; 027 public static final int DEBUG_FLAGS = 4; 028 public static final int WALKABOUT_TIMEOUT = 5; 029 public static final int MAIN_TRACK_CURRENT_LIMIT = 6; 030 public static final int PROG_TRACK_CURRENT_LIMIT = 7; 031 public static final int CURRENT_MULTIPLIER = 8; 032 public static final int INC_CURRENT_FOR_ACK = 9; 033 public static final int UNUSED_NV10 = 10; 034 public static final int NN_MAP_DCC_HI = 11; 035 public static final int NN_MAP_DCC_LO = 12; 036 public static final int SEND_CURRENT_INTERVAL = 13; 037 public static final int SOD_DELAY = 14; 038 public static final int UNUSED_NV15 = 15; 039 public static final int UNUSED_NV16 = 16; 040 041 // These may be overridden in scripts for unusual use cases 042 public static int MIN_CANID = 100; 043 public static int MAX_CANID = 127; 044 public static int MIN_NN = 65520; 045 public static int MAX_NN = 65534; 046 047 public CanCmdPaneProvider() { 048 super(); 049 } 050 051 /** {@inheritDoc} */ 052 @Override 053 @Nonnull 054 public String getModuleType() { 055 return type; 056 } 057 058 /** 059 * Hashmap for decoding NV names 060 */ 061 private static final Map<Integer, String> nvMap = createNvMap(); 062 063 /* 064 * Populate hashmap with nv strings 065 * 066 */ 067 private static Map<Integer, String> createNvMap() { 068 Map<Integer, String> result = new HashMap<>(); 069 result.put(0, "Error - invalid NV index"); 070 result.put(CMD_STATION_NUMBER, Bundle.getMessage("CmdStaNo")); 071 result.put(USER_FLAGS, Bundle.getMessage("UserFlags")); 072 result.put(OPERATIONS_FLAGS, Bundle.getMessage("OperationsFlags")); 073 result.put(DEBUG_FLAGS, Bundle.getMessage("DebugFlags")); 074 result.put(WALKABOUT_TIMEOUT, Bundle.getMessage("WalkaboutTimeout")); 075 result.put(MAIN_TRACK_CURRENT_LIMIT, Bundle.getMessage("MainTrackCurrentLimit")); 076 result.put(PROG_TRACK_CURRENT_LIMIT, Bundle.getMessage("ProgTrackCurrentLimit")); 077 result.put(CURRENT_MULTIPLIER, Bundle.getMessage("CurrentMultiplier")); 078 result.put(INC_CURRENT_FOR_ACK, Bundle.getMessage("IncCurrentForAck")); 079 result.put(NN_MAP_DCC_HI, Bundle.getMessage("NnMapToDccHi")); 080 result.put(NN_MAP_DCC_LO, Bundle.getMessage("NnMapToDccLo")); 081 result.put(SEND_CURRENT_INTERVAL, Bundle.getMessage("SendCurrentInterval")); 082 result.put(SOD_DELAY, Bundle.getMessage("SodDelay")); 083 084 return Collections.unmodifiableMap(result); 085 } 086 087 /** {@inheritDoc} */ 088 @Override 089 public String getNVNameByIndex(int index) { 090 // look for the NV 091 String nv = nvMap.get(index); 092 if (nv == null) { 093 return Bundle.getMessage("UnknownNv"); 094 } else { 095 return nv; 096 } 097 } 098 099 /** {@inheritDoc} */ 100 @Override 101 public AbstractEditNVPane getEditNVFrameInstance() { 102 return _nVarEditFrame; 103 } 104 105 /** {@inheritDoc} */ 106 @Override 107 public AbstractEditNVPane getEditNVFrame(CbusNodeNVTableDataModel dataModel, CbusNode node) { 108 _nVarEditFrame = new CanCmdEditNVPane(dataModel, node); 109 return _nVarEditFrame.getContent(); 110 } 111}