Search in sources :

Example 21 with CanSystemConnectionMemo

use of jmri.jmrix.can.CanSystemConnectionMemo in project JMRI by JMRI.

the class CbusThrottleTest method testCTor.

@Test
public void testCTor() {
    TrafficControllerScaffold tc = new TrafficControllerScaffold();
    CanSystemConnectionMemo memo = new CanSystemConnectionMemo();
    memo.setTrafficController(tc);
    CbusThrottle t = new CbusThrottle(memo, new DccLocoAddress(100, true), 100);
    Assert.assertNotNull("exists", t);
}
Also used : CanSystemConnectionMemo(jmri.jmrix.can.CanSystemConnectionMemo) TrafficControllerScaffold(jmri.jmrix.can.TrafficControllerScaffold) DccLocoAddress(jmri.DccLocoAddress) Test(org.junit.Test)

Example 22 with CanSystemConnectionMemo

use of jmri.jmrix.can.CanSystemConnectionMemo in project JMRI by JMRI.

the class ConfigToolActionTest method testAction.

@Test
public void testAction() {
    Assume.assumeFalse(GraphicsEnvironment.isHeadless());
    // load dummy TrafficController
    TrafficControllerScaffold tcs = new TrafficControllerScaffold();
    CanSystemConnectionMemo memo = new CanSystemConnectionMemo();
    memo.setTrafficController(tcs);
    //f.initComponents(memo);
    ConfigToolPane pane = new ConfigToolPane();
    Assert.assertNotNull("exists", pane);
}
Also used : CanSystemConnectionMemo(jmri.jmrix.can.CanSystemConnectionMemo) TrafficControllerScaffold(jmri.jmrix.can.TrafficControllerScaffold) Test(org.junit.Test)

Example 23 with CanSystemConnectionMemo

use of jmri.jmrix.can.CanSystemConnectionMemo in project JMRI by JMRI.

the class MonitorActionTest method setUp.

// The minimal setup for log4J
@Before
public void setUp() {
    apps.tests.Log4JFixture.setUp();
    jmri.util.JUnitUtil.resetInstanceManager();
    jmri.util.JUnitUtil.initConfigureManager();
    jmri.util.JUnitUtil.initDefaultUserMessagePreferences();
    tcs = new TrafficControllerScaffold();
    memo = new CanSystemConnectionMemo();
    memo.setTrafficController(tcs);
}
Also used : CanSystemConnectionMemo(jmri.jmrix.can.CanSystemConnectionMemo) TrafficControllerScaffold(jmri.jmrix.can.TrafficControllerScaffold) Before(org.junit.Before)

Example 24 with CanSystemConnectionMemo

use of jmri.jmrix.can.CanSystemConnectionMemo in project JMRI by JMRI.

the class LoaderActionTest method setUp.

// The minimal setup for log4J
@Before
public void setUp() {
    apps.tests.Log4JFixture.setUp();
    jmri.util.JUnitUtil.resetInstanceManager();
    jmri.util.JUnitUtil.initConfigureManager();
    jmri.util.JUnitUtil.initDefaultUserMessagePreferences();
    tcs = new TrafficControllerScaffold();
    memo = new CanSystemConnectionMemo();
    memo.setTrafficController(tcs);
}
Also used : CanSystemConnectionMemo(jmri.jmrix.can.CanSystemConnectionMemo) TrafficControllerScaffold(jmri.jmrix.can.TrafficControllerScaffold) Before(org.junit.Before)

Example 25 with CanSystemConnectionMemo

use of jmri.jmrix.can.CanSystemConnectionMemo in project JMRI by JMRI.

the class CbusThrottleManager method reply.

@Override
public synchronized void reply(CanReply m) {
    int opc = m.getElement(0);
    int rcvdIntAddr = (m.getElement(2) & 0x3f) * 256 + m.getElement(3);
    boolean rcvdIsLong = (m.getElement(2) & 0xc0) != 0;
    int handle = m.getElement(1);
    int errCode = m.getElement(3);
    DccLocoAddress rcvdDccAddr;
    String errStr = "";
    Iterator<Integer> itr;
    switch(opc) {
        case CbusConstants.CBUS_PLOC:
            rcvdDccAddr = new DccLocoAddress(rcvdIntAddr, rcvdIsLong);
            log.debug("Throttle manager received PLOC with session handle " + m.getElement(1) + " for address " + rcvdIntAddr);
            if ((_handleExpected) && rcvdDccAddr.equals(_dccAddr)) {
                log.debug("PLOC was expected");
                // We're expecting an engine report and it matches our address
                handle = m.getElement(1);
                CbusThrottle throttle;
                throttleRequestTimer.stop();
                throttle = new CbusThrottle((CanSystemConnectionMemo) adapterMemo, rcvdDccAddr, handle);
                // Initialise throttle from PLOC data to allow taking over moving trains
                throttle.throttleInit(m.getElement(4), m.getElement(5), m.getElement(6), m.getElement(7));
                notifyThrottleKnown(throttle, rcvdDccAddr);
                softThrottles.put(handle, throttle);
                _handleExpected = false;
            }
            break;
        case CbusConstants.CBUS_ERR:
            // TODO: should be a better way to do this with constants or properties
            switch(errCode) {
                case CbusConstants.ERR_LOCO_STACK_FULL:
                    errStr = "loco stack full for address " + rcvdIntAddr;
                    break;
                case CbusConstants.ERR_LOCO_ADDRESS_TAKEN:
                    errStr = "loco address taken for address " + rcvdIntAddr;
                    break;
                case CbusConstants.ERR_INVALID_REQUEST:
                    errStr = "invalid request for address " + rcvdIntAddr;
                    break;
                case CbusConstants.ERR_SESSION_NOT_PRESENT:
                    errStr = "session not present for session " + handle;
                    break;
                case CbusConstants.ERR_CONSIST_EMPTY:
                    errStr = "consist empty for consist " + handle;
                    break;
                case CbusConstants.ERR_LOCO_NOT_FOUND:
                    errStr = "loco not found for session " + handle;
                    break;
                case CbusConstants.ERR_CAN_BUS_ERROR:
                    errStr = "CAN bus error";
                    break;
                case CbusConstants.ERR_SESSION_CANCELLED:
                    errStr = "Throttle session cancelled for loco ";
                    break;
                default:
                    log.warn("Unhandled error code: {}", errCode);
                    break;
            }
            log.debug("Throttle manager received ERR " + errStr);
            rcvdDccAddr = new DccLocoAddress(rcvdIntAddr, rcvdIsLong);
            switch(errCode) {
                case CbusConstants.ERR_LOCO_STACK_FULL:
                case CbusConstants.ERR_LOCO_ADDRESS_TAKEN:
                    log.debug("PLOC expected but received ERR address" + rcvdDccAddr.toString());
                    if ((_handleExpected) && rcvdDccAddr.equals(_dccAddr)) {
                        // We were expecting an engine report and it matches our address
                        log.debug("Failed throttle request due to ERR");
                        _handleExpected = false;
                        throttleRequestTimer.stop();
                        JOptionPane.showMessageDialog(null, "CBUS ERR:" + errStr);
                        failedThrottleRequest(_dccAddr, "CBUS ERR:" + errStr);
                    } else {
                        log.debug("ERR address not matched");
                    }
                    break;
                case CbusConstants.ERR_SESSION_NOT_PRESENT:
                    if ((_handleExpected) && rcvdDccAddr.equals(_dccAddr)) {
                        // We were expecting an engine report and it matches our address
                        _handleExpected = false;
                    }
                    JOptionPane.showMessageDialog(null, "CBUS ERR:" + errStr);
                    break;
                case CbusConstants.ERR_CONSIST_EMPTY:
                case CbusConstants.ERR_LOCO_NOT_FOUND:
                    // and will never issue these errors
                    break;
                case CbusConstants.ERR_CAN_BUS_ERROR:
                case CbusConstants.ERR_INVALID_REQUEST:
                    JOptionPane.showMessageDialog(null, "CBUS ERR:" + errStr);
                    break;
                case CbusConstants.ERR_SESSION_CANCELLED:
                    // There will be a session cancelled error for the other throttle(s)
                    // when you are stealing, but as you don't yet have a session id, it
                    // won't match so you will ignore it, then a PLOC will come with that
                    // session id and your requested loco number which is giving it to you.
                    // Inform the throttle associated with this session handle, if any
                    itr = softThrottles.keySet().iterator();
                    while (itr.hasNext()) {
                        CbusThrottle throttle = softThrottles.get(itr.next());
                        if (throttle.getHandle() == handle) {
                            JOptionPane.showMessageDialog(null, errStr + throttle.getLocoAddress().toString());
                            throttle.throttleTimedOut();
                            // Attempt to dispode of the throttle
                            super.disposeThrottle(throttle, null);
                            break;
                        }
                    }
                    break;
                default:
                    break;
            }
            break;
        case CbusConstants.CBUS_DSPD:
            // Find a throttle corresponding to the handle
            itr = softThrottles.keySet().iterator();
            while (itr.hasNext()) {
                CbusThrottle throttle = softThrottles.get(itr.next());
                if (throttle.getHandle() == handle) {
                    // Set the throttle session to match the DSPD packet received
                    throttle.updateSpeedSetting(m.getElement(2) & 0x7f);
                    throttle.updateIsForward((m.getElement(2) & 0x80) == 0x80);
                }
            }
            break;
        case CbusConstants.CBUS_DFUN:
            // Find a throttle corresponding to the handle
            itr = softThrottles.keySet().iterator();
            while (itr.hasNext()) {
                CbusThrottle throttle = softThrottles.get(itr.next());
                if (throttle.getHandle() == handle) {
                    // Set the throttle session to match the DFUN packet received
                    log.debug("DFUN group: " + m.getElement(2) + " Fns: " + m.getElement(3) + " for session: " + m.getElement(1));
                    switch(m.getElement(2)) {
                        case 1:
                            throttle.updateFunctionGroup1(m.getElement(3));
                            break;
                        case 2:
                            throttle.updateFunctionGroup2(m.getElement(3));
                            break;
                        case 3:
                            throttle.updateFunctionGroup3(m.getElement(3));
                            break;
                        case 4:
                            throttle.updateFunctionGroup4(m.getElement(3));
                            break;
                        case 5:
                            throttle.updateFunctionGroup5(m.getElement(3));
                            break;
                        default:
                            log.error("Unrecognised function group");
                            break;
                    }
                }
            }
            break;
        case CbusConstants.CBUS_DFNON:
        case CbusConstants.CBUS_DFNOF:
            // Find a throttle corresponding to the handle
            itr = softThrottles.keySet().iterator();
            while (itr.hasNext()) {
                CbusThrottle throttle = softThrottles.get(itr.next());
                if (throttle.getHandle() == handle) {
                    throttle.updateFunction(m.getElement(2), (opc == CbusConstants.CBUS_DFNON) ? true : false);
                }
            }
            break;
        case CbusConstants.CBUS_ESTOP:
        case CbusConstants.CBUS_RESTP:
            stopAll();
            break;
        default:
            break;
    }
}
Also used : CanSystemConnectionMemo(jmri.jmrix.can.CanSystemConnectionMemo) DccLocoAddress(jmri.DccLocoAddress)

Aggregations

CanSystemConnectionMemo (jmri.jmrix.can.CanSystemConnectionMemo)25 Before (org.junit.Before)14 TrafficControllerScaffold (jmri.jmrix.can.TrafficControllerScaffold)12 Test (org.junit.Test)10 TestTrafficController (jmri.jmrix.can.TestTrafficController)7 DccLocoAddress (jmri.DccLocoAddress)2 CanMessage (jmri.jmrix.can.CanMessage)1 CanReply (jmri.jmrix.can.CanReply)1