Search in sources :

Example 1 with AddressedProgrammer

use of jmri.AddressedProgrammer in project JMRI by JMRI.

the class DccConsist method addToAdvancedConsist.

/*
     *  Add a Locomotive to an Advanced Consist
     *  @param address is the Locomotive address to add to the locomotive
     *  @param directionNormal is True if the locomotive is traveling
     *        the same direction as the consist, or false otherwise.
     */
protected void addToAdvancedConsist(DccLocoAddress LocoAddress, boolean directionNormal) {
    AddressedProgrammer opsProg = InstanceManager.getDefault(jmri.ProgrammerManager.class).getAddressedProgrammer(LocoAddress.isLongAddress(), LocoAddress.getNumber());
    if (opsProg == null) {
        log.error("Can't make consisting change because no programmer exists; this is probably a configuration error in the preferences");
        return;
    }
    if (directionNormal) {
        try {
            opsProg.writeCV(19, ConsistAddress.getNumber(), this);
        } catch (ProgrammerException e) {
            // Don't do anything with this yet
            log.warn("Exception writing CV19 while adding from consist", e);
        }
    } else {
        try {
            opsProg.writeCV(19, ConsistAddress.getNumber() + 128, this);
        } catch (ProgrammerException e) {
            // Don't do anything with this yet
            log.warn("Exception writing CV19 while adding to consist", e);
        }
    }
    InstanceManager.getDefault(jmri.ProgrammerManager.class).releaseAddressedProgrammer(opsProg);
}
Also used : ProgrammerException(jmri.ProgrammerException) AddressedProgrammer(jmri.AddressedProgrammer)

Example 2 with AddressedProgrammer

use of jmri.AddressedProgrammer in project JMRI by JMRI.

the class DccConsist method removeFromAdvancedConsist.

/*
     *  Remove a Locomotive from an Advanced Consist
     *  @param address is the Locomotive address to remove from the consist
     */
protected void removeFromAdvancedConsist(DccLocoAddress LocoAddress) {
    AddressedProgrammer opsProg = InstanceManager.getDefault(jmri.ProgrammerManager.class).getAddressedProgrammer(LocoAddress.isLongAddress(), LocoAddress.getNumber());
    if (opsProg == null) {
        log.error("Can't make consisting change because no programmer exists; this is probably a configuration error in the preferences");
        return;
    }
    try {
        opsProg.writeCV(19, 0, this);
    } catch (ProgrammerException e) {
        // Don't do anything with this yet
        log.warn("Exception writing CV19 while removing from consist", e);
    }
    InstanceManager.getDefault(jmri.ProgrammerManager.class).releaseAddressedProgrammer(opsProg);
}
Also used : ProgrammerException(jmri.ProgrammerException) AddressedProgrammer(jmri.AddressedProgrammer)

Example 3 with AddressedProgrammer

use of jmri.AddressedProgrammer in project JMRI by JMRI.

the class LV102InternalFrame method writeLV102Settings.

//Send Power Station settings
void writeLV102Settings() {
    // obtain the programmer Manager
    jmri.AddressedProgrammerManager pm = jmri.InstanceManager.getNullableDefault(jmri.AddressedProgrammerManager.class);
    if (pm == null) {
        // no addressed programmer manager, cannot proceed.
        CurrentStatus.setText(Bundle.getMessage("LV102StatusNoPM"));
        log.error("No Programmer Manager Available, cannot configure LV102");
        return;
    }
    // Obtain an ops mode programmer instance
    AddressedProgrammer opsProg = pm.getAddressedProgrammer(false, 00);
    if (opsProg == null) {
        // no ops mode programmer programmer, cannot proceed.
        CurrentStatus.setText(Bundle.getMessage("LV102StatusNoPOM"));
        log.error("Failed to obtain Operations Mode Programmer, cannot configure LV102");
        return;
    }
    // write the values to the power station.
    writeVoltSetting(opsProg);
    writeELineSetting(opsProg);
    writeRailComSetting(opsProg);
    writeRailComModeSetting(opsProg);
    writeRailComTimingSetting(opsProg);
    // we're done now, so we can release the programmer.
    pm.releaseAddressedProgrammer(opsProg);
}
Also used : AddressedProgrammer(jmri.AddressedProgrammer)

Example 4 with AddressedProgrammer

use of jmri.AddressedProgrammer in project JMRI by JMRI.

the class ProgrammerFacadeSelector method loadFacadeElements.

/**
     * Add facades specified in an XML decoder definition element to the front
     * of a programmer.
     *
     * @param element    Contains "capability" elements that define the Facades
     * @param programmer Programmer implementation to decorate
     * @param allowCache Passed to facades that optionally cache
     * @return the programmer with added facades
     */
public static Programmer loadFacadeElements(Element element, Programmer programmer, boolean allowCache) {
    // iterate over any facades and add them
    List<Element> facades = element.getChildren("capability");
    if (log.isDebugEnabled()) {
        log.debug("Found " + facades.size() + " capability elements");
    }
    for (Element facade : facades) {
        String fname = facade.getChild("name").getText();
        if (log.isDebugEnabled()) {
            log.debug("Process capability facade: " + fname);
        }
        List<Element> parameters = facade.getChildren("parameter");
        if (log.isDebugEnabled()) {
            log.debug("Found " + facades.size() + " capability parameters");
        }
        for (Element parameter : parameters) {
            String pval = parameter.getText();
            if (log.isDebugEnabled()) {
                log.debug("Process parameter value: " + pval);
            }
        }
        if (fname.equals("High Access via Double Index")) {
            // going to create a specific one
            String top = parameters.get(0).getText();
            String addrCVhigh = parameters.get(1).getText();
            String addrCVlow = parameters.get(2).getText();
            String valueCV = parameters.get(3).getText();
            String modulo = parameters.get(4).getText();
            jmri.implementation.AddressedHighCvProgrammerFacade pf = new jmri.implementation.AddressedHighCvProgrammerFacade(programmer, top, addrCVhigh, addrCVlow, valueCV, modulo);
            log.debug("new programmer " + pf);
            // to go around and see if there are more
            programmer = pf;
        } else if (fname.equals("High Access via Partial Index")) {
            // going to create a specific one
            String top = parameters.get(0).getText();
            String addrCV = parameters.get(1).getText();
            String factor = parameters.get(2).getText();
            String modulo = parameters.get(3).getText();
            jmri.implementation.OffsetHighCvProgrammerFacade pf = new jmri.implementation.OffsetHighCvProgrammerFacade(programmer, top, addrCV, factor, modulo);
            log.debug("new programmer " + pf);
            // to go around and see if there are more
            programmer = pf;
        } else if (fname.equals("High Access via Partial Index with Reset")) {
            // going to create a specific one
            String top = parameters.get(0).getText();
            String addrCV = parameters.get(1).getText();
            String factor = parameters.get(2).getText();
            String modulo = parameters.get(3).getText();
            String indicator = parameters.get(4).getText();
            jmri.implementation.ResettingOffsetHighCvProgrammerFacade pf = new jmri.implementation.ResettingOffsetHighCvProgrammerFacade(programmer, top, addrCV, factor, modulo, indicator);
            log.debug("new programmer " + pf);
            // to go around and see if there are more
            programmer = pf;
        } else if (fname.equals("Indexed CV access")) {
            // going to create a specific one
            String PI = parameters.get(0).getText();
            String SI = (parameters.size() > 1) ? parameters.get(1).getText() : null;
            boolean cvFirst = (parameters.size() > 2) ? (parameters.get(2).getText().equals("false") ? false : true) : true;
            // if not present, use default
            boolean skipDupIndexWrite = (parameters.size() > 3) ? (parameters.get(3).getText().equals("false") ? false : allowCache) : allowCache;
            jmri.implementation.MultiIndexProgrammerFacade pf = new jmri.implementation.MultiIndexProgrammerFacade(programmer, PI, SI, cvFirst, skipDupIndexWrite);
            log.debug("new programmer " + pf);
            // to go around and see if there are more
            programmer = pf;
        } else if (fname.equals("TCS 4 CV access")) {
            jmri.implementation.TwoIndexTcsProgrammerFacade pf = new jmri.implementation.TwoIndexTcsProgrammerFacade(programmer);
            log.debug("new programmer " + pf);
            // to go around and see if there are more
            programmer = pf;
        } else if (fname.equals("Ops Mode Accessory Programming")) {
            if (programmer instanceof AddressedProgrammer) {
                // create if relevant to current mode, otherwise silently ignore
                String addrType = "decoder";
                if (!parameters.isEmpty()) {
                    addrType = parameters.get(0).getText();
                }
                jmri.implementation.AccessoryOpsModeProgrammerFacade pf = new jmri.implementation.AccessoryOpsModeProgrammerFacade((AddressedProgrammer) programmer, addrType);
                log.debug("new programmer " + pf);
                // to go around and see if there are more
                programmer = pf;
            }
        } else {
            log.error("Cannot create programmer capability named: " + fname);
        }
    }
    return programmer;
}
Also used : AddressedProgrammer(jmri.AddressedProgrammer) Element(org.jdom2.Element)

Example 5 with AddressedProgrammer

use of jmri.AddressedProgrammer in project JMRI by JMRI.

the class ConsistController method setConsistCVs.

/**
     * set CV 21&22 for consist functions send each CV individually
     *
     * @param message RCF<;> locoAddress <:> CV# <;> value
     */
private void setConsistCVs(String message) {
    DccLocoAddress loco;
    List<String> headerAndCVs = Arrays.asList(message.split("<:>"));
    if (log.isDebugEnabled()) {
        log.debug("setConsistCVs string: " + message);
    }
    try {
        List<String> headerData = Arrays.asList(headerAndCVs.get(0).split("<;>"));
        loco = stringToDcc(headerData.get(1));
        if (checkForBroadcastAddress(loco)) {
            return;
        }
    } catch (NullPointerException e) {
        log.warn("setConsistCVs error for message: " + message);
        return;
    }
    AddressedProgrammer pom = jmri.InstanceManager.getDefault(jmri.ProgrammerManager.class).getAddressedProgrammer(loco.isLongAddress(), loco.getNumber());
    // loco done, now get CVs
    for (int i = 1; i < headerAndCVs.size(); i++) {
        List<String> CVData = Arrays.asList(headerAndCVs.get(i).split("<;>"));
        try {
            int CVNum = Integer.parseInt(CVData.get(0));
            int CVValue = Integer.parseInt(CVData.get(1));
            try {
                pom.writeCV(CVNum, CVValue, this);
            } catch (ProgrammerException e) {
            }
        } catch (NumberFormatException nfe) {
            log.warn("Error in setting CVs: " + nfe);
        }
    }
    jmri.InstanceManager.getDefault(jmri.ProgrammerManager.class).releaseAddressedProgrammer(pom);
}
Also used : ProgrammerException(jmri.ProgrammerException) AddressedProgrammer(jmri.AddressedProgrammer) DccLocoAddress(jmri.DccLocoAddress)

Aggregations

AddressedProgrammer (jmri.AddressedProgrammer)5 ProgrammerException (jmri.ProgrammerException)3 DccLocoAddress (jmri.DccLocoAddress)1 Element (org.jdom2.Element)1