001package jmri.jmrix.ecos;
002
003import java.util.ArrayList;
004import java.util.List;
005import javax.annotation.Nonnull;
006
007import jmri.AddressedProgrammer;
008import jmri.ProgrammingMode;
009import org.slf4j.Logger;
010import org.slf4j.LoggerFactory;
011
012/**
013 * Provide an Ops Mode Programmer via a wrapper what works with the ECoS command
014 * station object.
015 * <p>
016 * Functionally, this just creates packets to send via the command station.
017 *
018 * @see jmri.Programmer Based on work by Bob Jacobsen
019 * @author Karl Johan Lisby Copyright (C) 2018
020 */
021public class EcosOpsModeProgrammer extends EcosProgrammer implements AddressedProgrammer {
022
023    int mAddress;
024    boolean mLongAddr;
025
026    public EcosOpsModeProgrammer(EcosTrafficController tc, int pAddress, boolean pLongAddr) {
027        super(tc);
028        log.debug("ECoS ops mode programmer {} {}", pAddress, pLongAddr);
029        mAddress = pAddress;
030        mLongAddr = pLongAddr;
031        ecosObject = 7;
032        readCommand  = "mode[readdccpomloco],addr["+pAddress+"]";
033        writeCommand = "mode[writedccpomloco],addr["+pAddress+"]";
034    }
035
036    /**
037     * Types implemented here.
038     */
039    @Override
040    @Nonnull
041    public List<ProgrammingMode> getSupportedModes() {
042        List<ProgrammingMode> ret = new ArrayList<ProgrammingMode>();
043        ret.add(ProgrammingMode.OPSBYTEMODE);
044        return ret;
045    }
046
047    /**
048     * Can this ops-mode programmer read back values? Yes - if the locomotive decoder supports it.
049     *
050     * @return always true
051     */
052    @Override
053    public boolean getCanRead() {
054        return true;
055    }
056
057    @Override
058    public boolean getLongAddress() {
059        return mLongAddr;
060    }
061
062    @Override
063    public int getAddressNumber() {
064        return mAddress;
065    }
066
067    @Override
068    public String getAddress() {
069        return "" + getAddressNumber() + " " + getLongAddress();
070    }
071
072    // initialize logging
073    private final static Logger log = LoggerFactory.getLogger(EcosOpsModeProgrammer.class);
074
075}