Package jmri.jmrix.zimo
Class Mx1Message
- java.lang.Object
-
- jmri.jmrix.NetMessage
-
- jmri.jmrix.zimo.Mx1Message
-
- All Implemented Interfaces:
java.io.Serializable
public class Mx1Message extends NetMessage
Represents a single command or response to the Zimo Binary Protocol.Content is represented with ints to avoid the problems with sign-extension that bytes have, and because a Java char is actually a variable number of bytes in Unicode.
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static int
ACCCMD
(package private) static int
ACK2
(package private) static int
ACKREP1
(package private) boolean
crcError
(package private) static boolean
CS
Indicates the message source is a command station.(package private) static int
ERR_ADDRESS
(package private) static int
ERR_BUSY
(package private) static int
ERR_CV_ADDRESS
(package private) static int
ERR_FORWARD
(package private) static int
ERR_INDEX
(package private) static int
ERR_MESSAGE
(package private) static int
ERR_NO_DCC
(package private) static int
ERR_NO_MODUL
(package private) static int
ERR_NO_MOT
(package private) static int
ERR_SECTION
(package private) static int
ERR_SPEED
(package private) static int
LOCOCMD
(package private) static int
MX1
Message to/from Command Station MX1(package private) static int
MX8
Message to/from Accessory module MX8(package private) static int
MX9
Message to/from Track Section module MX9(package private) static int
NO_ERROR
(package private) static boolean
PC
Indicates the message source is a command station.(package private) static int
PRIMARY
(package private) static int
PROGCMD
(package private) boolean
protocol
(package private) byte[]
rawPacket
(package private) static int
REPLY2
(package private) int
retries
(package private) long
timeStamp
(package private) static int
TRACKCTL
-
Constructor Summary
Constructors Constructor Description Mx1Message(byte[] contents)
Mx1Message(int len)
Mx1Message(int len, boolean protocol)
Create a new object, representing a specific-length message.Mx1Message(java.lang.Integer[] contents)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
checkParity()
Check if the message has a valid parity (actually check for CR or LF as end of message).static Mx1Message
getCmdStnDetails()
int
getCvValue()
static Mx1Message
getDecProgCmd(int locoAddress, int cv, int value, boolean dcc)
Create a message to read or write a CV.(package private) java.lang.String
getErrorCode(int i)
int
getLocoAddress()
(package private) int
getLocoAddress(int hi, int lo)
static Mx1Message
getLocoControl(int locoAddress, int speed, boolean dcc, int cData1, int cData2, int cData3)
Create a locomotive control message.boolean
getLongMessage()
int
getMessageType()
int
getModule()
Indicates where the message is to/from in the header byte.int
getPrimaryMessage()
protected byte[]
getRawPacket()
int
getRetry()
int
getSequenceNo()
java.lang.String
getStringMsg()
static Mx1Message
getSwitchMsg(int accAddress, int setting, boolean dcc)
protected long
getTimeStamp()
static Mx1Message
getTrackStatus()
boolean
isCRCError()
boolean
messageSource()
Indicates the source of the message.boolean
replyL1Expected()
void
setCRCError()
void
setParity()
Set parity to be correct for this implementation.static Mx1Message
setPowerOff()
Set Track Power Off/Emergency Stopstatic Mx1Message
setPowerOn()
void
setRawPacket(byte[] b)
void
setRetries(int i)
void
setSequenceNo(byte s)
protected void
setTimeStamp(long ts)
-
Methods inherited from class jmri.jmrix.NetMessage
getElement, getNumDataElements, getOpCode, getOpCodeHex, highByte, lowByte, setElement, setOpCode, toString
-
-
-
-
Field Detail
-
protocol
boolean protocol
-
PRIMARY
static final int PRIMARY
- See Also:
- Constant Field Values
-
ACKREP1
static final int ACKREP1
- See Also:
- Constant Field Values
-
REPLY2
static final int REPLY2
- See Also:
- Constant Field Values
-
ACK2
static final int ACK2
- See Also:
- Constant Field Values
-
MX1
static final int MX1
Message to/from Command Station MX1- See Also:
- Constant Field Values
-
MX8
static final int MX8
Message to/from Accessory module MX8- See Also:
- Constant Field Values
-
MX9
static final int MX9
Message to/from Track Section module MX9- See Also:
- Constant Field Values
-
CS
static final boolean CS
Indicates the message source is a command station. true- See Also:
messageSource()
, Constant Field Values
-
PC
static final boolean PC
Indicates the message source is a command station. false- See Also:
messageSource()
, Constant Field Values
-
timeStamp
long timeStamp
-
retries
int retries
-
rawPacket
byte[] rawPacket
-
crcError
boolean crcError
-
NO_ERROR
static final int NO_ERROR
- See Also:
- Constant Field Values
-
ERR_ADDRESS
static final int ERR_ADDRESS
- See Also:
- Constant Field Values
-
ERR_INDEX
static final int ERR_INDEX
- See Also:
- Constant Field Values
-
ERR_FORWARD
static final int ERR_FORWARD
- See Also:
- Constant Field Values
-
ERR_BUSY
static final int ERR_BUSY
- See Also:
- Constant Field Values
-
ERR_NO_MOT
static final int ERR_NO_MOT
- See Also:
- Constant Field Values
-
ERR_NO_DCC
static final int ERR_NO_DCC
- See Also:
- Constant Field Values
-
ERR_CV_ADDRESS
static final int ERR_CV_ADDRESS
- See Also:
- Constant Field Values
-
ERR_SECTION
static final int ERR_SECTION
- See Also:
- Constant Field Values
-
ERR_NO_MODUL
static final int ERR_NO_MODUL
- See Also:
- Constant Field Values
-
ERR_MESSAGE
static final int ERR_MESSAGE
- See Also:
- Constant Field Values
-
ERR_SPEED
static final int ERR_SPEED
- See Also:
- Constant Field Values
-
TRACKCTL
static final int TRACKCTL
- See Also:
- Constant Field Values
-
PROGCMD
static final int PROGCMD
- See Also:
- Constant Field Values
-
LOCOCMD
static final int LOCOCMD
- See Also:
- Constant Field Values
-
ACCCMD
static final int ACCCMD
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Mx1Message
public Mx1Message(int len)
-
Mx1Message
public Mx1Message(int len, boolean protocol)
Create a new object, representing a specific-length message.- Parameters:
len
- Total bytes in message, including opcode and error-detection byte.protocol
- one ofMx1TrafficController.ASCII
orMx1TrafficController.BINARY
-
Mx1Message
public Mx1Message(java.lang.Integer[] contents)
-
Mx1Message
public Mx1Message(byte[] contents)
-
-
Method Detail
-
getLongMessage
public boolean getLongMessage()
-
getModule
public int getModule()
Indicates where the message is to/from in the header byte.Up to JMRI 4.3.5, this was doing
((mod & MX1) == MX1)
for the first test, which is really 0 == 0 and always true. At that point it was changed to just check the bottom two bits.
-
getMessageType
public int getMessageType()
-
getPrimaryMessage
public int getPrimaryMessage()
-
messageSource
public boolean messageSource()
Indicates the source of the message.
-
getTimeStamp
protected long getTimeStamp()
-
setTimeStamp
protected void setTimeStamp(long ts)
-
getRetry
public int getRetry()
-
setRetries
public void setRetries(int i)
-
replyL1Expected
public boolean replyL1Expected()
-
setRawPacket
public void setRawPacket(byte[] b)
-
getRawPacket
protected byte[] getRawPacket()
-
setSequenceNo
public void setSequenceNo(byte s)
-
getSequenceNo
public int getSequenceNo()
-
setCRCError
public void setCRCError()
-
isCRCError
public boolean isCRCError()
-
checkParity
public boolean checkParity()
Check if the message has a valid parity (actually check for CR or LF as end of message).- Specified by:
checkParity
in classNetMessage
- Returns:
- true if message has correct parity bit
-
setParity
public void setParity()
Description copied from class:NetMessage
Set parity to be correct for this implementation. Note that parity is really a stand-in for whatever error checking, etc needs to be done- Specified by:
setParity
in classNetMessage
-
getStringMsg
public java.lang.String getStringMsg()
-
getLocoAddress
public int getLocoAddress()
-
getCvValue
public int getCvValue()
-
getLocoAddress
int getLocoAddress(int hi, int lo)
-
getErrorCode
java.lang.String getErrorCode(int i)
-
getCmdStnDetails
public static Mx1Message getCmdStnDetails()
-
setPowerOff
public static Mx1Message setPowerOff()
Set Track Power Off/Emergency Stop- Returns:
- MrcMessage
-
setPowerOn
public static Mx1Message setPowerOn()
-
getTrackStatus
public static Mx1Message getTrackStatus()
-
getDecProgCmd
public static Mx1Message getDecProgCmd(int locoAddress, int cv, int value, boolean dcc)
Create a message to read or write a CV.- Parameters:
locoAddress
- address of the lococv
- CV to read or writevalue
- value to write to CV, if -1 CV is readdcc
- true if decoder is DCC; false if decoder is Motorola- Returns:
- a message to read or write a CV
-
getLocoControl
public static Mx1Message getLocoControl(int locoAddress, int speed, boolean dcc, int cData1, int cData2, int cData3)
Create a locomotive control message.- Parameters:
locoAddress
- address of the locospeed
- Speed Step in the actual Speed Step Systemdcc
- true if decoder is DCC; false if decoder is MotorolacData1
- ???cData2
- functions output 0-7cData3
- functions output 9-12- Returns:
- message controlling a locomotive
-
getSwitchMsg
public static Mx1Message getSwitchMsg(int accAddress, int setting, boolean dcc)
-
-