Search in sources :

Example 11 with XNetReply

use of jmri.jmrix.lenz.XNetReply in project JMRI by JMRI.

the class XNetSimulatorAdapter method okReply.

// Create an OK XNetReply message
private XNetReply okReply() {
    XNetReply r = new XNetReply();
    r.setOpCode(XNetConstants.LI_MESSAGE_RESPONSE_HEADER);
    r.setElement(1, XNetConstants.LI_MESSAGE_RESPONSE_SEND_SUCCESS);
    // set the parity byte to 0
    r.setElement(2, 0x00);
    r.setParity();
    return r;
}
Also used : XNetReply(jmri.jmrix.lenz.XNetReply)

Example 12 with XNetReply

use of jmri.jmrix.lenz.XNetReply in project JMRI by JMRI.

the class Z21XNetSimulatorAdapter method xNetVersionReply.

// Create a reply to a request for the XPressNet Version
private XNetReply xNetVersionReply() {
    XNetReply reply = new XNetReply();
    reply.setOpCode(XNetConstants.CS_SERVICE_MODE_RESPONSE);
    reply.setElement(1, XNetConstants.CS_SOFTWARE_VERSION);
    // indicate we are version 3.0
    reply.setElement(2, 0x30 & 0xff);
    // indicate we are a Z21;
    reply.setElement(3, 0x12 & 0xff);
    // set the parity byte to 0
    reply.setElement(4, 0x00);
    reply.setParity();
    return reply;
}
Also used : XNetReply(jmri.jmrix.lenz.XNetReply)

Example 13 with XNetReply

use of jmri.jmrix.lenz.XNetReply in project JMRI by JMRI.

the class Z21XNetSimulatorAdapter method generateReply.

// generateReply is the heart of the simulation.  It translates an 
// incoming XNetMessage into an outgoing XNetReply.
// document specific case same as default
@SuppressWarnings("fallthrough")
XNetReply generateReply(XNetMessage m) {
    log.debug("Generating Reply");
    XNetReply reply;
    switch(m.getElement(0) & 0xff) {
        case XNetConstants.CS_REQUEST:
            log.debug("CS Request Received");
            switch(m.getElement(1)) {
                case XNetConstants.CS_VERSION:
                    reply = xNetVersionReply();
                    break;
                case XNetConstants.RESUME_OPS:
                    csStatus = csNormalMode;
                    reply = normalOpsReply();
                    break;
                case XNetConstants.EMERGENCY_OFF:
                    csStatus = csEmergencyStop;
                    reply = everythingOffReply();
                    break;
                case XNetConstants.CS_STATUS:
                    reply = csStatusReply();
                    break;
                case XNetConstants.SERVICE_MODE_CSRESULT:
                default:
                    log.debug("Unsupoorted requested received: {}", m.toString());
                    reply = notSupportedReply();
            }
            break;
        case XNetConstants.LI_VERSION_REQUEST:
            log.debug("LI Version Request Received");
            reply = new XNetReply();
            reply.setOpCode(XNetConstants.LI_VERSION_RESPONSE);
            // set the hardware type to 0
            reply.setElement(1, 0x00);
            // set the firmware version to 0
            reply.setElement(2, 0x00);
            // set the parity byte to 0
            reply.setElement(3, 0x00);
            reply.setParity();
            break;
        case XNetConstants.LOCO_OPER_REQ:
            log.debug("Locomotive Operations Request received");
            switch(m.getElement(1) & 0xff) {
                case XNetConstants.LOCO_SPEED_14:
                    // z21 specific locomotive information reply is expected.
                    reply = new XNetReply();
                    reply.setOpCode(Z21Constants.LAN_X_LOCO_INFO_RESPONSE);
                    // address msb from
                    reply.setElement(1, m.getElement(2));
                    // message.
                    // address lsb from
                    reply.setElement(2, m.getElement(3));
                    // message.
                    // set speed step mode to 14
                    reply.setElement(3, 0x00);
                    // set the speed and direction to the sent value.
                    reply.setElement(4, m.getElement(4) & 0xff);
                    // set function group a off
                    reply.setElement(5, 0x00);
                    // set function group b off
                    reply.setElement(6, 0x00);
                    // set F13-F20 off
                    reply.setElement(7, 0x00);
                    // set F21-F28 off
                    reply.setElement(8, 0x00);
                    // filler
                    reply.setElement(9, 0x00);
                    // filler
                    reply.setElement(10, 0x00);
                    // filler
                    reply.setElement(11, 0x00);
                    // filler
                    reply.setElement(12, 0x00);
                    // filler
                    reply.setElement(13, 0x00);
                    // filler
                    reply.setElement(14, 0x00);
                    // filler
                    reply.setElement(15, 0x00);
                    // set the parity byte to 0
                    reply.setElement(16, 0x00);
                    // set the parity correctly.
                    reply.setParity();
                    // save the address and speed information for
                    // the simulator's RailCom values.
                    locoData[locoPosition] = new Z21SimulatorLocoData((byte) (m.getElement(2) & 0xff), (byte) (m.getElement(3) & 0xff), (byte) (m.getElement(4) & 0xff));
                    locoCount = (locoCount + 1) % 19;
                    if (// 19 is the limit, set by the protocol.
                    locoCount < 19)
                        locoCount++;
                    locoPosition = (locoPosition + 1) % 19;
                    break;
                case XNetConstants.LOCO_SPEED_27:
                    log.debug("Unsupoorted requested received: {}", m.toString());
                    reply = notSupportedReply();
                    break;
                case XNetConstants.LOCO_SPEED_28:
                    // z21 specific locomotive information reply is expected.
                    reply = new XNetReply();
                    reply.setOpCode(Z21Constants.LAN_X_LOCO_INFO_RESPONSE);
                    // address msb from
                    reply.setElement(1, m.getElement(2));
                    // message.
                    // address lsb from
                    reply.setElement(2, m.getElement(3));
                    // message.
                    // set speed step mode to 28
                    reply.setElement(3, 0x02);
                    // set the speed and direction to the sent value.
                    reply.setElement(4, m.getElement(4));
                    // set function group a off
                    reply.setElement(5, 0x00);
                    // set function group b off
                    reply.setElement(6, 0x00);
                    // set F13-F20 off
                    reply.setElement(7, 0x00);
                    // set F21-F28 off
                    reply.setElement(8, 0x00);
                    // filler
                    reply.setElement(9, 0x00);
                    // filler
                    reply.setElement(10, 0x00);
                    // filler
                    reply.setElement(11, 0x00);
                    // filler
                    reply.setElement(12, 0x00);
                    // filler
                    reply.setElement(13, 0x00);
                    // filler
                    reply.setElement(14, 0x00);
                    // filler
                    reply.setElement(15, 0x00);
                    // set the parity byte to 0
                    reply.setElement(16, 0x00);
                    // set the parity correctly.
                    reply.setParity();
                    locoData[locoPosition] = new Z21SimulatorLocoData((byte) (m.getElement(2) & 0xff), (byte) (m.getElement(3) & 0xff), (byte) (m.getElement(4) & 0xff));
                    if (// 19 is the limit, set by the protocol.
                    locoCount < 19)
                        locoCount++;
                    locoPosition = (locoPosition + 1) % 19;
                    break;
                case XNetConstants.LOCO_SPEED_128:
                    // z21 specific locomotive information reply is expected.
                    reply = new XNetReply();
                    reply.setOpCode(Z21Constants.LAN_X_LOCO_INFO_RESPONSE);
                    // address msb from
                    reply.setElement(1, m.getElement(2));
                    // message.
                    // address lsb from
                    reply.setElement(2, m.getElement(3));
                    // message.
                    // set speed step mode to 128
                    reply.setElement(3, 0x04);
                    // set the speed and direction to the sent value.
                    reply.setElement(4, m.getElement(4));
                    // set function group a off
                    reply.setElement(5, 0x00);
                    // set function group b off
                    reply.setElement(6, 0x00);
                    // set F13-F20 off
                    reply.setElement(7, 0x00);
                    // set F21-F28 off
                    reply.setElement(8, 0x00);
                    // filler
                    reply.setElement(9, 0x00);
                    // filler
                    reply.setElement(10, 0x00);
                    // filler
                    reply.setElement(11, 0x00);
                    // filler
                    reply.setElement(12, 0x00);
                    // filler
                    reply.setElement(13, 0x00);
                    // filler
                    reply.setElement(14, 0x00);
                    // filler
                    reply.setElement(15, 0x00);
                    // set the parity byte to 0
                    reply.setElement(16, 0x00);
                    // set the parity correctly.
                    reply.setParity();
                    // set the parity correctly.
                    reply.setParity();
                    locoData[locoPosition] = new Z21SimulatorLocoData((byte) (m.getElement(2) & 0xff), (byte) (m.getElement(3) & 0xff), (byte) (m.getElement(4) & 0xff));
                    if (// 19 is the limit, set by the protocol.
                    locoCount < 19)
                        locoCount++;
                    locoPosition = (locoPosition + 1) % 19;
                    break;
                case Z21Constants.LAN_X_SET_LOCO_FUNCTION:
                    // z21 specific locomotive information reply is expected.
                    reply = new XNetReply();
                    reply.setOpCode(Z21Constants.LAN_X_LOCO_INFO_RESPONSE);
                    // address msb from
                    reply.setElement(1, m.getElement(2));
                    // message.
                    // address lsb from
                    reply.setElement(2, m.getElement(3));
                    // message.
                    // set speed step mode to 128
                    reply.setElement(3, 0x04);
                    // set the speed and direction to the sent value.
                    reply.setElement(4, 0x00);
                    // set function group a off
                    reply.setElement(5, 0x00);
                    // set function group b off
                    reply.setElement(6, 0x00);
                    // set F13-F20 off
                    reply.setElement(7, 0x00);
                    // set F21-F28 off
                    reply.setElement(8, 0x00);
                    // filler
                    reply.setElement(9, 0x00);
                    // filler
                    reply.setElement(10, 0x00);
                    // filler
                    reply.setElement(11, 0x00);
                    // filler
                    reply.setElement(12, 0x00);
                    // filler
                    reply.setElement(13, 0x00);
                    // filler
                    reply.setElement(14, 0x00);
                    // filler
                    reply.setElement(15, 0x00);
                    // set the parity byte to 0
                    reply.setElement(16, 0x00);
                    // set the parity correctly.
                    reply.setParity();
                    break;
                case XNetConstants.LOCO_SET_FUNC_GROUP1:
                // We need to find out what a Z21 actually sends in response.
                case XNetConstants.LOCO_SET_FUNC_GROUP2:
                // We need to find out what a Z21 actually sends in response.
                case XNetConstants.LOCO_SET_FUNC_GROUP3:
                // We need to find out what a Z21 actually sends in response.
                case XNetConstants.LOCO_SET_FUNC_GROUP4:
                // We need to find out what a Z21 actually sends in response.
                case XNetConstants.LOCO_SET_FUNC_GROUP5:
                // We need to find out what a Z21 actually sends in response.
                case XNetConstants.LOCO_SET_FUNC_Group1:
                // We need to find out what a Z21 actually sends in response.
                case XNetConstants.LOCO_SET_FUNC_Group2:
                // We need to find out what a Z21 actually sends in response.
                case XNetConstants.LOCO_SET_FUNC_Group3:
                // We need to find out what a Z21 actually sends in response.
                case XNetConstants.LOCO_SET_FUNC_Group4:
                // We need to find out what a Z21 actually sends in response.
                case XNetConstants.LOCO_SET_FUNC_Group5:
                    // XPressNet set Function Momentary Group 1.
                    // We need to find out what a Z21 actually sends in response.
                    reply = okReply();
                    break;
                case XNetConstants.LOCO_ADD_MULTI_UNIT_REQ:
                case XNetConstants.LOCO_REM_MULTI_UNIT_REQ:
                case XNetConstants.LOCO_IN_MULTI_UNIT_REQ_FORWARD:
                case XNetConstants.LOCO_IN_MULTI_UNIT_REQ_BACKWARD:
                default:
                    log.debug("Unsupoorted requested received: {}", m.toString());
                    reply = notSupportedReply();
                    break;
            }
            break;
        case XNetConstants.ALL_ESTOP:
            log.debug("Emergency Stop Received");
            reply = emergencyStopReply();
            break;
        case XNetConstants.EMERGENCY_STOP:
            reply = okReply();
            break;
        case XNetConstants.EMERGENCY_STOP_XNETV1V2:
            reply = okReply();
            break;
        case XNetConstants.ACC_OPER_REQ:
            log.debug("Accessory Operations Request Received");
            reply = okReply();
            break;
        case XNetConstants.LOCO_STATUS_REQ:
            log.debug("Locomotive Status Request received");
            switch(m.getElement(1) & 0xff) {
                case XNetConstants.LOCO_INFO_REQ_V3:
                    reply = new XNetReply();
                    reply.setOpCode(XNetConstants.LOCO_INFO_NORMAL_UNIT);
                    // set to 128 speed step mode
                    reply.setElement(1, 0x04);
                    // set the speed to 0 
                    reply.setElement(2, 0x00);
                    // direction reverse
                    // set function group a off
                    reply.setElement(3, 0x00);
                    // set function group b off
                    reply.setElement(4, 0x00);
                    // set the parity byte to 0
                    reply.setElement(5, 0x00);
                    // set the parity correctly.
                    reply.setParity();
                    break;
                case Z21Constants.LAN_X_LOCO_INFO_REQUEST_Z21:
                    // z21 specific locomotive information request.
                    reply = new XNetReply();
                    reply.setOpCode(Z21Constants.LAN_X_LOCO_INFO_RESPONSE);
                    // address msb from
                    reply.setElement(1, m.getElement(2));
                    // message.
                    // address lsb from
                    reply.setElement(2, m.getElement(3));
                    // message.
                    // set speed step mode to 128
                    reply.setElement(3, 0x04);
                    // set the speed and direction to 0 and reverse.
                    reply.setElement(4, 0x00);
                    // set function group a off
                    reply.setElement(5, 0x00);
                    // set function group b off
                    reply.setElement(6, 0x00);
                    // set F13-F20 off
                    reply.setElement(7, 0x00);
                    // set F21-F28 off
                    reply.setElement(8, 0x00);
                    // filler
                    reply.setElement(9, 0x00);
                    // filler
                    reply.setElement(10, 0x00);
                    // filler
                    reply.setElement(11, 0x00);
                    // filler
                    reply.setElement(12, 0x00);
                    // filler
                    reply.setElement(13, 0x00);
                    // filler
                    reply.setElement(14, 0x00);
                    // filler
                    reply.setElement(15, 0x00);
                    // set the parity byte to 0
                    reply.setElement(16, 0x00);
                    // set the parity correctly.
                    reply.setParity();
                    break;
                case XNetConstants.LOCO_INFO_REQ_FUNC:
                case XNetConstants.LOCO_INFO_REQ_FUNC_HI_ON:
                case XNetConstants.LOCO_INFO_REQ_FUNC_HI_MOM:
                default:
                    log.debug("Unsupoorted requested received: {}", m.toString());
                    reply = notSupportedReply();
            }
            break;
        case XNetConstants.ACC_INFO_REQ:
            log.debug("Accessory Information Request Received");
            reply = new XNetReply();
            reply.setOpCode(XNetConstants.ACC_INFO_RESPONSE);
            reply.setElement(1, m.getElement(1));
            if (m.getElement(1) < 64) {
                // treat as turnout feedback request.
                if (m.getElement(2) == 0x80) {
                    reply.setElement(2, 0x00);
                } else {
                    reply.setElement(2, 0x10);
                }
            } else {
                // treat as feedback encoder request.
                if (m.getElement(2) == 0x80) {
                    reply.setElement(2, 0x40);
                } else {
                    reply.setElement(2, 0x50);
                }
            }
            reply.setElement(3, 0x00);
            reply.setParity();
            break;
        case Z21Constants.LAN_X_GET_TURNOUT_INFO:
            log.debug("Get Turnout Info Request Received");
            reply = lanXTurnoutInfoReply(m.getElement(1), m.getElement(2), // always sends "thrown".
            true);
            break;
        case Z21Constants.LAN_X_SET_TURNOUT:
            log.debug("Set Turnout Request Received");
            reply = lanXTurnoutInfoReply(m.getElement(1), m.getElement(2), (0x01 & m.getElement(3)) == 0x01);
            break;
        case XNetConstants.LI101_REQUEST:
        case XNetConstants.CS_SET_POWERMODE:
        //have the same value
        case XNetConstants.PROG_WRITE_REQUEST:
        case XNetConstants.OPS_MODE_PROG_REQ:
        case XNetConstants.LOCO_DOUBLEHEAD:
        default:
            log.debug("Unsupoorted requested received: {}", m.toString());
            reply = notSupportedReply();
    }
    log.debug("generated reply {}", reply);
    return reply;
}
Also used : XNetReply(jmri.jmrix.lenz.XNetReply)

Example 14 with XNetReply

use of jmri.jmrix.lenz.XNetReply in project JMRI by JMRI.

the class Z21XNetSimulatorAdapter method notSupportedReply.

// We have a few canned response messages.
// Create an Unsupported XNetReply message
private XNetReply notSupportedReply() {
    XNetReply r = new XNetReply();
    r.setOpCode(XNetConstants.CS_INFO);
    r.setElement(1, XNetConstants.CS_NOT_SUPPORTED);
    // set the parity byte to 0
    r.setElement(2, 0x00);
    r.setParity();
    return r;
}
Also used : XNetReply(jmri.jmrix.lenz.XNetReply)

Example 15 with XNetReply

use of jmri.jmrix.lenz.XNetReply in project JMRI by JMRI.

the class Z21SimulatorAdapter method generateReply.

// end of run.
// generateReply is the heart of the simulation.  It translates an
// incoming XNetMessage into an outgoing XNetReply.
// document values for specific cases
@SuppressWarnings("fallthrough")
private Z21Reply generateReply(Z21Message m) throws Exception {
    log.debug("generate Reply called with message {}", m);
    Z21Reply reply;
    switch(m.getOpCode()) {
        case 0x0010:
            // request for serial number
            reply = getZ21SerialNumberReply();
            break;
        case 0x001a:
            // request for hardware version info.
            reply = getHardwareVersionReply();
            break;
        case 0x0040:
            // XPressNet tunnel message.
            XNetMessage xnm = getXNetMessage(m);
            log.debug("Received XNet Message: {}", m);
            XNetReply xnr = xnetadapter.generateReply(xnm);
            reply = getZ21ReplyFromXNet(xnr);
            break;
        case 0x0030:
            // to indicate this.
            throw (new Exception());
        case 0x0050:
            // set broadcast flags
            flags[0] = m.getElement(4) & 0xff;
            flags[1] = m.getElement(5) & 0xff;
            flags[2] = m.getElement(6) & 0xff;
            flags[3] = m.getElement(7) & 0xff;
            // per the protocol, no reply is generated.
            reply = null;
            break;
        case 0x0051:
            // get broadcast flags
            reply = getZ21BroadCastFlagsReply();
            break;
        case 0x0089:
            // Get Railcom Data
            reply = getZ21RailComDataChangedReply();
            break;
        case 0x0060:
        // get loco mode
        case 0x0061:
        // set loco mode
        case 0x0070:
        // get turnout mode
        case 0x0071:
        // set turnout mode
        case 0x0081:
        // get RMBus data
        case 0x0082:
        // program RMBus module
        case 0x0085:
        // get system state
        case 0x00A2:
        // loconet data from lan
        case 0x00A3:
        // loconet dispatch address
        case 0x00A4:
        // get loconet detector status
        default:
            reply = getXPressNetUnknownCommandReply();
    }
    return reply;
}
Also used : Z21Reply(jmri.jmrix.roco.z21.Z21Reply) XNetReply(jmri.jmrix.lenz.XNetReply) XNetMessage(jmri.jmrix.lenz.XNetMessage)

Aggregations

XNetReply (jmri.jmrix.lenz.XNetReply)57 XNetInterfaceScaffold (jmri.jmrix.lenz.XNetInterfaceScaffold)18 Test (org.junit.Test)17 XNetMessage (jmri.jmrix.lenz.XNetMessage)14 LenzCommandStation (jmri.jmrix.lenz.LenzCommandStation)10 IOException (java.io.IOException)3 BufferedReader (java.io.BufferedReader)2 InputStreamReader (java.io.InputStreamReader)2 ArrayList (java.util.ArrayList)2 Ignore (org.junit.Ignore)2 Z21Reply (jmri.jmrix.roco.z21.Z21Reply)1