use of jmri.jmrix.lenz.XNetReply in project JMRI by JMRI.
the class Z21XNetSimulatorAdapter method emergencyStopReply.
// Create a broadcast "Emergecy Stop" reply
private XNetReply emergencyStopReply() {
XNetReply r = new XNetReply();
r.setOpCode(XNetConstants.BC_EMERGENCY_STOP);
r.setElement(1, XNetConstants.BC_EVERYTHING_STOP);
// set the parity byte to 0
r.setElement(2, 0x00);
r.setParity();
return r;
}
use of jmri.jmrix.lenz.XNetReply in project JMRI by JMRI.
the class XNetSimulatorAdapter method generateReply.
// generateReply is the heart of the simulation. It translates an
// incoming XNetMessage into an outgoing XNetReply.
@SuppressWarnings("fallthrough")
private XNetReply generateReply(XNetMessage m) {
XNetReply reply = new XNetReply();
switch(m.getElement(0) & 0xff) {
case XNetConstants.CS_REQUEST:
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:
reply = notSupportedReply();
}
break;
case XNetConstants.LI_VERSION_REQUEST:
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:
lastLocoAddressHigh = m.getElement(2);
lastLocoAddressLow = m.getElement(3);
switch(m.getElement(1)) {
case XNetConstants.LOCO_SPEED_14:
CurrentSpeedStepMode = XNetConstants.LOCO_SPEED_14;
CurrentSpeedStep = m.getElement(4);
reply = okReply();
break;
case XNetConstants.LOCO_SPEED_27:
CurrentSpeedStepMode = XNetConstants.LOCO_SPEED_27;
CurrentSpeedStep = m.getElement(4);
reply = okReply();
break;
case XNetConstants.LOCO_SPEED_28:
CurrentSpeedStepMode = XNetConstants.LOCO_SPEED_28;
CurrentSpeedStep = m.getElement(4);
reply = okReply();
break;
case XNetConstants.LOCO_SPEED_128:
CurrentSpeedStepMode = XNetConstants.LOCO_SPEED_128;
CurrentSpeedStep = m.getElement(4);
reply = okReply();
break;
case XNetConstants.LOCO_SET_FUNC_GROUP1:
FunctionGroup1 = m.getElement(4);
reply = okReply();
break;
case XNetConstants.LOCO_SET_FUNC_GROUP2:
FunctionGroup2 = m.getElement(4);
reply = okReply();
break;
case XNetConstants.LOCO_SET_FUNC_GROUP3:
FunctionGroup3 = m.getElement(4);
reply = okReply();
break;
case XNetConstants.LOCO_SET_FUNC_GROUP4:
FunctionGroup4 = m.getElement(4);
reply = okReply();
break;
case XNetConstants.LOCO_SET_FUNC_GROUP5:
FunctionGroup5 = m.getElement(4);
reply = okReply();
break;
case XNetConstants.LOCO_SET_FUNC_Group1:
MomentaryGroup1 = m.getElement(4);
reply = okReply();
break;
case XNetConstants.LOCO_SET_FUNC_Group2:
MomentaryGroup2 = m.getElement(4);
reply = okReply();
break;
case XNetConstants.LOCO_SET_FUNC_Group3:
MomentaryGroup3 = m.getElement(4);
reply = okReply();
break;
case XNetConstants.LOCO_SET_FUNC_Group4:
MomentaryGroup4 = m.getElement(4);
reply = okReply();
break;
case XNetConstants.LOCO_SET_FUNC_Group5:
MomentaryGroup5 = m.getElement(4);
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:
reply = notSupportedReply();
break;
}
break;
case // ALL_ESTOP is XNet V4
XNetConstants.ALL_ESTOP:
csStatus = csEmergencyStop;
reply = emergencyStopReply();
break;
case XNetConstants.EMERGENCY_STOP:
reply = okReply();
break;
case XNetConstants.EMERGENCY_STOP_XNETV1V2:
reply = okReply();
break;
case XNetConstants.ACC_OPER_REQ:
reply = okReply();
break;
case XNetConstants.LOCO_STATUS_REQ:
switch(m.getElement(1)) {
case XNetConstants.LOCO_INFO_REQ_V3:
reply.setOpCode(XNetConstants.LOCO_INFO_NORMAL_UNIT);
reply.setElement(1, CurrentSpeedStepMode);
// set the speed
reply.setElement(2, CurrentSpeedStep);
// direction reverse
// set function group 1
reply.setElement(3, FunctionGroup1);
// set function group 2 and 3
reply.setElement(4, (FunctionGroup2 & 0x0f) + ((FunctionGroup3 & 0x0f) << 4));
// set the parity byte to 0
reply.setElement(5, 0x00);
// set the parity correctly.
reply.setParity();
break;
case XNetConstants.LOCO_INFO_REQ_FUNC:
reply.setOpCode(XNetConstants.LOCO_INFO_RESPONSE);
// momentary function status
reply.setElement(1, XNetConstants.LOCO_FUNCTION_STATUS);
// set function group 1
reply.setElement(2, MomentaryGroup1);
// set function group 2 and 3
reply.setElement(3, (MomentaryGroup2 & 0x0f) + ((MomentaryGroup3 * 0x0f) << 4));
// set the parity byte to 0
reply.setElement(4, 0x00);
// set the parity correctly.
reply.setParity();
break;
case XNetConstants.LOCO_INFO_REQ_FUNC_HI_ON:
reply.setOpCode(XNetConstants.LOCO_INFO_RESPONSE);
// F13-F28 function on/off status
reply.setElement(1, XNetConstants.LOCO_FUNCTION_STATUS_HIGH);
// set function group 4
reply.setElement(2, FunctionGroup4);
// set function group 5
reply.setElement(3, FunctionGroup5);
// set the parity byte to 0
reply.setElement(4, 0x00);
// set the parity correctly.
reply.setParity();
break;
case XNetConstants.LOCO_INFO_REQ_FUNC_HI_MOM:
reply.setOpCode(XNetConstants.LOCO_INFO_NORMAL_UNIT);
// F13-F28 momentary function status
reply.setElement(1, XNetConstants.LOCO_FUNCTION_STATUS_HIGH_MOM);
// set function group 4
reply.setElement(2, MomentaryGroup4);
// set function group 5
reply.setElement(3, MomentaryGroup5);
// set the parity byte to 0
reply.setElement(4, 0x00);
// set the parity correctly.
reply.setParity();
break;
default:
reply = notSupportedReply();
}
break;
case XNetConstants.ACC_INFO_REQ:
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 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:
reply = notSupportedReply();
}
return (reply);
}
use of jmri.jmrix.lenz.XNetReply in project JMRI by JMRI.
the class XNetSimulatorAdapter method emergencyStopReply.
// Create a broadcast "Emergency Stop" reply
private XNetReply emergencyStopReply() {
XNetReply r = new XNetReply();
r.setOpCode(XNetConstants.BC_EMERGENCY_STOP);
r.setElement(1, XNetConstants.BC_EVERYTHING_STOP);
// set the parity byte to 0
r.setElement(2, 0x00);
r.setParity();
return r;
}
use of jmri.jmrix.lenz.XNetReply in project JMRI by JMRI.
the class XNetSimulatorAdapter 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.6
reply.setElement(2, 0x36 & 0xff);
// indicate we are an LZ100;
reply.setElement(3, 0x00 & 0xff);
// set the parity byte to 0
reply.setElement(4, 0x00);
reply.setParity();
return reply;
}
use of jmri.jmrix.lenz.XNetReply in project JMRI by JMRI.
the class XNetSimulatorAdapter method run.
@Override
public void run() {
// of the command station simulation.
if (log.isDebugEnabled()) {
log.debug("Simulator Thread Started");
}
ConnectionStatus.instance().setConnectionState(this.getSystemConnectionMemo().getUserName(), this.getCurrentPortName(), ConnectionStatus.CONNECTION_UP);
for (; ; ) {
XNetMessage m = readMessage();
if (log.isDebugEnabled()) {
log.debug("Simulator Thread received message " + m.toString());
}
XNetReply r = generateReply(m);
writeReply(r);
if (log.isDebugEnabled()) {
log.debug("Simulator Thread sent Reply" + r.toString());
}
}
}
Aggregations