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.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 [Pi-]SPROG 3 [v2|Plus] 016 * 017 * @author Andrew Crosland Copyright (C) 2021 018 */ 019@ServiceProvider(service = CbusConfigPaneProvider.class) 020public class Sprog3PlusPaneProvider extends CbusConfigPaneProvider { 021 022 String type = "CANSPROG3P"; 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 PROG_TRACK_POWER_MODE = 5; 029 public static final int PROG_TRACK_CURRENT_LIMIT = 6; 030 public static final int INPUT_VOLTAGE = 7; 031 public static final int MAIN_TRACK_CURRENT = 8; 032 public static final int ACCY_PACKET_REPEAT_COUNT = 9; 033 public static final int MULTIMETER_MODE = 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 MAIN_TRACK_CURRENT_LIMIT = 13; 037 public static final int PROG_TRACK_CURRENT = 14; 038 public static final int MAIN_HIGH_WATER_MARK = 15; 039 public static final int PROG_HIGH_WATER_MARK = 16; 040 public static final int SETUP = 17; 041 public static final int CANID = 18; 042 public static final int NN_HI = 19; 043 public static final int NN_LO = 20; 044 public static final int DCC_PREAMBLE = 21; 045 public static final int CAN_DISABLE = 22; 046 public static final int USER_FLAGS_2 = 23; 047 048 // These may be overridden in scripts for unusual use cases 049 public static int MIN_CANID = 100; 050 public static int MAX_CANID = 127; 051 public static int MIN_NN = 65520; 052 public static int MAX_NN = 65535; 053 054 public Sprog3PlusPaneProvider() { 055 super(); 056 } 057 058 /** {@inheritDoc} */ 059 @Override 060 @Nonnull 061 public String getModuleType() { 062 return type; 063 } 064 065 /** 066 * Hashmap for decoding NV names 067 */ 068 private static final Map<Integer, String> nvMap = createNvMap(); 069 070 /* 071 * Populate hashmap with nv strings 072 * 073 */ 074 private static Map<Integer, String> createNvMap() { 075 Map<Integer, String> result = new HashMap<>(); 076 result.put(0, "Error - invalid NV index"); 077 result.put(CMD_STATION_NUMBER, Bundle.getMessage("CmdStaNo")); 078 result.put(USER_FLAGS, Bundle.getMessage("UserFlags")); 079 result.put(OPERATIONS_FLAGS, Bundle.getMessage("OperationsFlags")); 080 result.put(DEBUG_FLAGS, Bundle.getMessage("DebugFlags")); 081 result.put(PROG_TRACK_POWER_MODE, Bundle.getMessage("ProgTrackPowerMode")); 082 result.put(PROG_TRACK_CURRENT_LIMIT, Bundle.getMessage("ProgTrackCurrentLimit")); 083 result.put(INPUT_VOLTAGE, Bundle.getMessage("InputVoltage")); 084 result.put(MAIN_TRACK_CURRENT, Bundle.getMessage("MainTrackCurrent")); 085 result.put(ACCY_PACKET_REPEAT_COUNT, Bundle.getMessage("AccessoryPacketRepeatCount")); 086 result.put(MULTIMETER_MODE, Bundle.getMessage("MultimeterMode")); 087 result.put(NN_MAP_DCC_HI, Bundle.getMessage("NnMapToDccHi")); 088 result.put(NN_MAP_DCC_LO, Bundle.getMessage("NnMapToDccLo")); 089 result.put(MAIN_TRACK_CURRENT_LIMIT, Bundle.getMessage("MainTrackCurrentLimit")); 090 result.put(PROG_TRACK_CURRENT, Bundle.getMessage("ProgTackCurrent")); 091 result.put(MAIN_HIGH_WATER_MARK, Bundle.getMessage("MainTrackCurrentHWM")); 092 result.put(PROG_HIGH_WATER_MARK, Bundle.getMessage("ProgTrackCurrentHWM")); 093 result.put(SETUP, Bundle.getMessage("SetupMode")); 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(DCC_PREAMBLE, Bundle.getMessage("DccPreambleBits")); 098 result.put(CAN_DISABLE, Bundle.getMessage("CanDisable")); 099 result.put(USER_FLAGS_2, Bundle.getMessage("UserFlags2")); 100 return Collections.unmodifiableMap(result); 101 } 102 103 /** {@inheritDoc} */ 104 @Override 105 public String getNVNameByIndex(int index) { 106 // look for the NV 107 String nv = nvMap.get(index); 108 if (nv == null) { 109 return Bundle.getMessage("UnknownNv"); 110 } else { 111 return nv; 112 } 113 } 114 115 /** {@inheritDoc} */ 116 @Override 117 public AbstractEditNVPane getEditNVFrameInstance() { 118 return _nVarEditFrame; 119 } 120 121 /** {@inheritDoc} */ 122 @Override 123 public AbstractEditNVPane getEditNVFrame(CbusNodeNVTableDataModel dataModel, CbusNode node) { 124 _nVarEditFrame = new Sprog3PlusEditNVPane(dataModel, node); 125 return _nVarEditFrame.getContent(); 126 } 127}