Package jmri.jmrix.can.cbus
Class CbusMessage
- java.lang.Object
-
- jmri.jmrix.can.cbus.CbusMessage
-
public class CbusMessage extends java.lang.Object
Class to allow use of CBUS concepts to access the underlying can message.Methods that take a CanMessage or CanReply as argument:
- CanMessage - Can Frame being sent by JMRI
- CanReply - Can Frame being received by JMRI
-
-
Constructor Summary
Constructors Constructor Description CbusMessage()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static CanMessagegetBootCheck(int c, int header)Microchip AN247 format message to send the checksum for comparison.static CanMessagegetBootDevId(int header)CBUS bootloader v1.0 format message to request device ID.static CanMessagegetBootEnables(int enables, int header)CBUS bootloader v1.0 format message to set memory region write enablesstatic CanMessagegetBootEntry(int nn, int header)This is a strict CBUS message to put a node into boot mode.static CanMessagegetBootId(int header)CBUS bootloader v1.0 format message to request bootloader ID.static CanMessagegetBootInitialise(int a, int header)Microchip AN247 format message to initialise the bootloader and set the start address.static CanMessagegetBootNop(int a, int header)Microchip AN247 format NOP message to set address.static CanMessagegetBootReset(int header)Microchip AN247 format message to reset and enter normal mode.static CanMessagegetBootTest(int header)Microchip AN247 format message to check if a module is in boot mode.static CanMessagegetBootWriteData(byte[] d, int header)Microchip AN247 format message to write up to 8 bytes of datastatic CanMessagegetBootWriteData(int[] d, int header)Microchip AN247 format message to write 8 bytes of datastatic intgetDataLength(AbstractMessage am)Get the Data Length from the CanMessagestatic intgetEvent(AbstractMessage m)Get the Event Number from a CBUS Eventstatic intgetEventType(AbstractMessage am)Get the Event Type ( on or off ) from a CanFramestatic intgetId(AbstractMessage f)Get the CAN ID within a CanReply or CanMessage Headerstatic intgetNodeNumber(AbstractMessage am)Get the Node Number from a CanFrame Eventstatic intgetOpcode(AbstractMessage am)Get the Op Code from the CanMessagestatic CanMessagegetOpsModeWriteCV(int mAddress, boolean mLongAddr, int cv, int val, int header)CBUS Ops mode programmer commandsstatic intgetPri(AbstractMessage r)Get the priority from within the CanReply or CanMessage Headerstatic CanMessagegetReadCV(int cv, ProgrammingMode mode, int header)CBUS programmer commandsstatic CanMessagegetRequestTrackOff(int header)Get a CanMessage to send track power offstatic CanMessagegetRequestTrackOn(int header)Get a CanMessage to send track power onstatic CanMessagegetVerifyCV(int cv, ProgrammingMode mode, int startVal, int header)CBUS programmer commands CBUS VCVS works like a QCVS read but the programmer will first check if the CV contents are equal to the startVal.static CanMessagegetWriteCV(int cv, int val, ProgrammingMode mode, int header)Get a CanMessage to write a CV.static booleanisArst(CanReply m)Tests if CanReply is a System Resetstatic booleanisBootConfirm(CanReply r)Tests if incoming CanReply is a Boot Confirm.static booleanisBootDataError(CanReply r)Tests if incoming CanReply is a Boot Data Error.static booleanisBootDataOK(CanReply r)Tests if incoming CanReply is a Boot Data OK.static booleanisBootDataOutOfRange(CanReply r)Tests if incoming CanReply is a Boot Out of Rangestatic booleanisBootDevId(CanReply r)Tests if incoming CanReply is a device ID reply.static booleanisBootError(CanReply r)Tests if incoming CanReply is a Boot Command Error.static booleanisBootId(CanReply r)Tests if incoming CanReply is a bootloader ID reply.static booleanisBootOK(CanReply r)Tests if incoming CanReply is a Boot Command OK.static booleanisBootOutOfRange(CanReply r)Tests if incoming CanReply is a Boot Out of Rangestatic booleanisBootWriteData(CanMessage m)Tests if a message is a bootloader data writestatic booleanisEvent(AbstractMessage am)Tests if a CanMessage or CanReply is an Event.static booleanisRequestTrackOff(CanMessage m)Checks if a CanMessage is requesting Track Power Offstatic booleanisRequestTrackOn(CanMessage m)Checks if a CanMessage is requesting Track Power Onstatic booleanisShort(AbstractMessage am)Tests if CanFrame is a short eventstatic booleanisTrackOff(CanReply m)Tests if CanReply is confirming Track Power Off.static booleanisTrackOn(CanReply m)Tests if CanReply is confirming Track Power On.static CanReplyopcRangeToStl(CanReply original)Return a CanReply for use in sensors, turnouts + light If a response event, set to normal event In future, this may also translate extended messages down to normal messages.static voidsetId(AbstractMessage am, int id)Set the CAN ID within a CanMessage or CanReply Headerstatic voidsetPri(AbstractMessage am, int pri)Set the priority within a CanMessage or CanReply Header.static java.lang.StringtoAddress(AbstractMessage m)Returns string form of a CanMessage ( a Can Frame sent by JMRI ) Short / Long events converted to Sensor / Turnout / Light hardware address message priority not indicated
-
-
-
Constructor Detail
-
CbusMessage
public CbusMessage()
-
-
Method Detail
-
opcRangeToStl
public static CanReply opcRangeToStl(CanReply original)
Return a CanReply for use in sensors, turnouts + light If a response event, set to normal event In future, this may also translate extended messages down to normal messages.- Parameters:
original- CanReply to be coverted to normal opc- Returns:
- new CanReply perhaps converted from response OPC to normal OPC.
-
getOpcode
public static int getOpcode(AbstractMessage am)
Get the Op Code from the CanMessage- Parameters:
am- CanMessage or CanReply- Returns:
- OPC of the message
-
getDataLength
public static int getDataLength(AbstractMessage am)
Get the Data Length from the CanMessage- Parameters:
am- CanMessage or CanReply- Returns:
- the message data length
-
getNodeNumber
public static int getNodeNumber(AbstractMessage am)
Get the Node Number from a CanFrame Event- Parameters:
am- CanMessage or CanReply- Returns:
- the node number if not a short event
-
getEvent
public static int getEvent(AbstractMessage m)
Get the Event Number from a CBUS Event- Parameters:
m- CanMessage or CanReply- Returns:
- the message event ( device ) number, else -1 if not an event.
-
getEventType
public static int getEventType(AbstractMessage am)
Get the Event Type ( on or off ) from a CanFrame- Parameters:
am- CanFrame or CanReply- Returns:
- CbusConstant EVENT_ON or EVENT_OFF
-
isEvent
public static boolean isEvent(AbstractMessage am)
Tests if a CanMessage or CanReply is an Event. Performs Extended and RTR check. Adheres to cbus spec, ie on off responses to an AREQ are events.- Parameters:
am- CanMessage or CanReply- Returns:
- True if event, else False.
-
isShort
public static boolean isShort(AbstractMessage am)
Tests if CanFrame is a short event- Parameters:
am- CanReply or CanMessage- Returns:
- true if Short Event, else false
-
setId
public static void setId(AbstractMessage am, int id) throws java.lang.IllegalArgumentException
Set the CAN ID within a CanMessage or CanReply Header- Parameters:
am- CanMessage or CanReplyid- CAN ID- Throws:
java.lang.IllegalArgumentException- when needed
-
setPri
public static void setPri(AbstractMessage am, int pri) throws java.lang.IllegalArgumentException
Set the priority within a CanMessage or CanReply Header.- Parameters:
am- CanMessage or CanReplypri- Priority- Throws:
java.lang.IllegalArgumentException- when needed
-
toAddress
public static java.lang.String toAddress(AbstractMessage m)
Returns string form of a CanMessage ( a Can Frame sent by JMRI ) Short / Long events converted to Sensor / Turnout / Light hardware address message priority not indicated- Parameters:
m- CanReply or CanMessage- Returns:
- String of hardware address form
-
isRequestTrackOff
public static boolean isRequestTrackOff(CanMessage m)
Checks if a CanMessage is requesting Track Power Off- Parameters:
m- Can Frame Message- Returns:
- boolean
-
isRequestTrackOn
public static boolean isRequestTrackOn(CanMessage m)
Checks if a CanMessage is requesting Track Power On- Parameters:
m- Can Frame Message- Returns:
- True if outgoing track power on request
-
getId
public static int getId(AbstractMessage f) throws java.lang.IllegalArgumentException
Get the CAN ID within a CanReply or CanMessage Header- Parameters:
f- CanReply or CanMessage- Returns:
- CAN ID of the outgoing message
- Throws:
java.lang.IllegalArgumentException- when needed
-
getPri
public static int getPri(AbstractMessage r) throws java.lang.IllegalArgumentException
Get the priority from within the CanReply or CanMessage Header- Parameters:
r- CanReply or CanMessage- Returns:
- Priority of the outgoing message
- Throws:
java.lang.IllegalArgumentException- when needed
-
isTrackOff
public static boolean isTrackOff(CanReply m)
Tests if CanReply is confirming Track Power Off.- Parameters:
m- CanReply- Returns:
- True if is a Track Off notification
-
isTrackOn
public static boolean isTrackOn(CanReply m)
Tests if CanReply is confirming Track Power On.- Parameters:
m- CanReply- Returns:
- True if is a Track On notification
-
isArst
public static boolean isArst(CanReply m)
Tests if CanReply is a System Reset- Parameters:
m- CanReply- Returns:
- True if emergency Stop
-
getReadCV
public static CanMessage getReadCV(int cv, ProgrammingMode mode, int header)
CBUS programmer commands- Parameters:
cv- CV to readmode- Programming Modeheader- CAN ID- Returns:
- CanMessage ready to send
-
getVerifyCV
public static CanMessage getVerifyCV(int cv, ProgrammingMode mode, int startVal, int header)
CBUS programmer commands CBUS VCVS works like a QCVS read but the programmer will first check if the CV contents are equal to the startVal. This can speed up CV reads by skipping reading of other values.- Parameters:
cv- CV to readmode- Programming ModestartVal- Hint of current CV valueheader- CAN ID- Returns:
- CanMessage ready to send
-
getWriteCV
public static CanMessage getWriteCV(int cv, int val, ProgrammingMode mode, int header)
Get a CanMessage to write a CV.- Parameters:
cv- Which CV, 0-65534val- New CV value, 0-255mode- Programming Modeheader- CAN ID- Returns:
- ready to send CanMessage
-
getOpsModeWriteCV
public static CanMessage getOpsModeWriteCV(int mAddress, boolean mLongAddr, int cv, int val, int header)
CBUS Ops mode programmer commands- Parameters:
mAddress- Loco Address, non-DCC formatmLongAddr- If Loco Address is a long addressheader- CAN IDval- New CV valuecv- Which CV, 0-65534- Returns:
- ready to send CanMessage
-
getRequestTrackOn
public static CanMessage getRequestTrackOn(int header)
Get a CanMessage to send track power on- Parameters:
header- for connection CAN ID- Returns:
- the CanMessage to send to request track power on
-
getRequestTrackOff
public static CanMessage getRequestTrackOff(int header)
Get a CanMessage to send track power off- Parameters:
header- for connection CAN ID- Returns:
- the CanMessage to send to request track power off
-
getBootEntry
public static CanMessage getBootEntry(int nn, int header)
This is a strict CBUS message to put a node into boot mode.- Parameters:
nn- Node Number 1-65534header- CAN ID- Returns:
- ready to send CanMessage
-
getBootNop
public static CanMessage getBootNop(int a, int header)
Microchip AN247 format NOP message to set address.The CBUS bootloader uses extended ID frames
- Parameters:
a- addressheader- CAN ID - overridden by call to setHeader- Returns:
- ready to send CanMessage
-
getBootReset
public static CanMessage getBootReset(int header)
Microchip AN247 format message to reset and enter normal mode.- Parameters:
header- CAN ID - overridden by call to setHeader- Returns:
- ready to send CanMessage
-
getBootInitialise
public static CanMessage getBootInitialise(int a, int header)
Microchip AN247 format message to initialise the bootloader and set the start address.- Parameters:
a- start addressheader- CAN ID - overridden by call to setHeader- Returns:
- ready to send CanMessage
-
getBootCheck
public static CanMessage getBootCheck(int c, int header)
Microchip AN247 format message to send the checksum for comparison. At time of writing [6th Feb '20] The MERG bootloader doc is incorrect and shows the checksum as being byte swapped.- Parameters:
c- 0-65535 2's complement of sum of all program bytes sentheader- CAN ID - overridden by call to setHeader- Returns:
- ready to send CanMessage
-
getBootTest
public static CanMessage getBootTest(int header)
Microchip AN247 format message to check if a module is in boot mode.- Parameters:
header- CAN ID - overridden by call to setHeader- Returns:
- ready to send CanMessage
-
getBootDevId
public static CanMessage getBootDevId(int header)
CBUS bootloader v1.0 format message to request device ID.- Parameters:
header- CAN ID - overridden by call to setHeader- Returns:
- ready to send CanMessage
-
getBootId
public static CanMessage getBootId(int header)
CBUS bootloader v1.0 format message to request bootloader ID.- Parameters:
header- CAN ID - overridden by call to setHeader- Returns:
- ready to send CanMessage
-
getBootEnables
public static CanMessage getBootEnables(int enables, int header)
CBUS bootloader v1.0 format message to set memory region write enables- Parameters:
enables- enable bits for memory regionsheader- CAN ID - overridden by call to setHeader- Returns:
- ready to send CanMessage
-
getBootWriteData
public static CanMessage getBootWriteData(int[] d, int header)
Microchip AN247 format message to write 8 bytes of data- Parameters:
d- data array, 8 length, values 0-255header- CAN ID - overridden by call to setHeader- Returns:
- ready to send CanMessage
-
getBootWriteData
public static CanMessage getBootWriteData(byte[] d, int header)
Microchip AN247 format message to write up to 8 bytes of data- Parameters:
d- data array, values 0-255header- CAN ID - overridden by call to setHeader- Returns:
- ready to send CanMessage
-
isBootWriteData
public static boolean isBootWriteData(CanMessage m)
Tests if a message is a bootloader data write- Parameters:
m- message- Returns:
- true if the message is a bootloader data write
-
isBootError
public static boolean isBootError(CanReply r)
Tests if incoming CanReply is a Boot Command Error.- Parameters:
r- CanReply- Returns:
- True if is a Boot Command Error
-
isBootDataError
public static boolean isBootDataError(CanReply r)
Tests if incoming CanReply is a Boot Data Error.- Parameters:
r- CanReply- Returns:
- True if is a Boot Data Error
-
isBootOK
public static boolean isBootOK(CanReply r)
Tests if incoming CanReply is a Boot Command OK.- Parameters:
r- CanReply- Returns:
- True if is a Boot COmmand OK
-
isBootDataOK
public static boolean isBootDataOK(CanReply r)
Tests if incoming CanReply is a Boot Data OK.- Parameters:
r- CanReply- Returns:
- True if is a Boot Data OK
-
isBootOutOfRange
public static boolean isBootOutOfRange(CanReply r)
Tests if incoming CanReply is a Boot Out of Range- Parameters:
r- CanReply- Returns:
- True if is a Boot Data OK
-
isBootDataOutOfRange
public static boolean isBootDataOutOfRange(CanReply r)
Tests if incoming CanReply is a Boot Out of Range- Parameters:
r- CanReply- Returns:
- True if is a Boot Data OK
-
isBootConfirm
public static boolean isBootConfirm(CanReply r)
Tests if incoming CanReply is a Boot Confirm.- Parameters:
r- CanReply- Returns:
- True if is a Boot Confirm
-
isBootDevId
public static boolean isBootDevId(CanReply r)
Tests if incoming CanReply is a device ID reply.- Parameters:
r- CanReply- Returns:
- True if is a Boot Confirm
-
-