Class CbusMessage

java.lang.Object
jmri.jmrix.can.cbus.CbusMessage

public class CbusMessage
extends 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
https://github.com/MERG-DEV/CBUSlib.
  • Constructor Details

  • Method Details

    • opcRangeToStl

      public static CanReply opcRangeToStl​(CanReply msg)
      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:
      msg - CanReply to be coverted to normal opc
      Returns:
      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 IllegalArgumentException
      Set the CAN ID within a CanMessage or CanReply Header
      Parameters:
      am - CanMessage or CanReply
      id - CAN ID
      Throws:
      IllegalArgumentException
    • setPri

      public static void setPri​(AbstractMessage am, int pri) throws IllegalArgumentException
      Set the priority within a CanMessage or CanReply Header.
      Parameters:
      am - CanMessage or CanReply
      pri - Priority
      Throws:
      IllegalArgumentException
    • toAddress

      public static 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 IllegalArgumentException
      Get the CAN ID within a CanReply or CanMessage Header
      Parameters:
      f - CanReply or CanMessage
      Returns:
      CAN ID of the outgoing message
      Throws:
      IllegalArgumentException
    • getPri

      public static int getPri​(AbstractMessage r) throws IllegalArgumentException
      Get the priority from within the CanReply or CanMessage Header
      Parameters:
      r - CanReply or CanMessage
      Returns:
      Priority of the outgoing message
      Throws:
      IllegalArgumentException
    • 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 read
      mode - Programming Mode
      header - 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-65534
      val - New CV value, 0-255
      mode - Programming Mode
      header - 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 format
      mLongAddr - If Loco Address is a long address
      header - CAN ID
      val - New CV value
      cv - 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-65534
      header - 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 - address
      header - 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 address
      header - 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 sent
      header - 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
    • 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-255
      header - 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 8 bytes of data
      Parameters:
      d - data array, 8 length, values 0-255
      header - 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 Error.
      Parameters:
      r - CanReply
      Returns:
      True if is a Boot Error
    • isBootOK

      public static boolean isBootOK​(CanReply r)
      Tests if incoming CanReply is a Boot OK.
      Parameters:
      r - CanReply
      Returns:
      True if is a Boot 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