|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjmri.NmraPacket
public class NmraPacket
Utilities for coding/decoding NMRA S&RP DCC packets.
Packets are (now) represented by an array of bytes. Preamble/postamble not included. Note that this is a data representation, _not_ a representation of the waveform! But this is a class, which might eventually also form a representation object.
This is meant to be a general Java NMRA implementation, so does NOT use JMRI utilities. In particular, it returns null instead of throwing JmriException for invalid requests. Callers need to check upstream.
The function is provided by static member functions; objects of this class should not be created.
Note that these functions are structured by packet type, not by what want to do. E.g. there are functions to create specific packet formats instead of a general "loco speed packet" routine which figures out which type of packet to use. Those decisions are to be made somewhere else.
Range and value checking is intended to be aggressive; if we can check, we should. Problems are reported as warnings.
The basic function is to build a packet with proper addressing, etc:
JMRI is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. See the "COPYING" file for a copy of this license.
JMRI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
| Field Summary | |
|---|---|
static int |
ACCESSORY_SHORT_ADDRESS
|
static int |
LOCO_LONG_ADDRESS
|
static int |
LOCO_SHORT_ADDRESS
|
static int |
NO_ADDRESS
|
| Method Summary | |
|---|---|
static byte[] |
accDecoderPkt(int number,
boolean closed)
Provide an accessory control packet via a simplified interface |
static byte[] |
accDecoderPkt(int addr,
int active,
int outputChannel)
|
static byte[] |
accDecoderPktOpsMode(int number,
int cvNum,
int data)
Provide an operation mode accessory control packet via a simplified interface |
static byte[] |
accDecoderPktOpsMode(int addr,
int active,
int outputChannel,
int cvNum,
int data)
From the NMRA RP: Basic Accessory Decoder Packet address for operations mode programming 10AAAAAA 0 1AAACDDD 0 1110CCVV 0 VVVVVVVV 0 DDDDDDDD Where DDD is used to indicate the output whose CVs are being modified and C=1. |
static byte[] |
accDecoderPktOpsModeLegacy(int number,
int cvNum,
int data)
Provide a legacy operation mode accessory control packet via a simplified interface |
static byte[] |
accDecPktOpsModeLegacy(int addr,
int cvNum,
int data)
From the NMRA RP: The format for Accessory Decoder Configuration Variable Access Instructions is: {preamble} 0 10AAAAAA 0 0AAA11VV 0 VVVVVVVV 0 DDDDDDDD 0 EEEEEEEE 1 Where: A = Decoder address bits V = Desired CV address - (CV 513 = 10 00000000) D = Data for CV This is the old "legacy" format, newer decoders use the "Basic Accessory Decoder Packet" |
static byte[] |
accSignalDecoderPkt(int outputAddr,
int aspect)
From the RP: Extended Accessory Decoder Control Packet Format The Extended Accessory Decoder Control Packet is included for the purpose of transmitting aspect control to signal decoders or data bytes to more complex accessory decoders. |
static byte[] |
analogControl(int address,
boolean longAddr,
int function,
int value)
Provide an NMRA analog control instruction Note that the NMRA draft of Fall 2004 only defines the value of "1" for the "function parameter", calling that the value for "volume control". |
static byte[] |
consistControl(int address,
boolean longAddr,
int consist,
boolean directionNormal)
Provide an NMRA consist control instruction |
static String |
format(byte[] p)
Convert NMRA packet to a readable form |
static byte[] |
fourBytePacket(int address,
boolean longAddr,
byte arg1,
byte arg2,
byte arg3,
byte arg4)
Create a packet containing a four-byte instruction. |
static byte[] |
function0Through4Packet(int address,
boolean longAddr,
boolean f0,
boolean f1,
boolean f2,
boolean f3,
boolean f4)
|
static byte[] |
function13Through20Packet(int address,
boolean longAddr,
boolean f13,
boolean f14,
boolean f15,
boolean f16,
boolean f17,
boolean f18,
boolean f19,
boolean f20)
|
static byte[] |
function21Through28Packet(int address,
boolean longAddr,
boolean f21,
boolean f22,
boolean f23,
boolean f24,
boolean f25,
boolean f26,
boolean f27,
boolean f28)
|
static byte[] |
function5Through8Packet(int address,
boolean longAddr,
boolean f5,
boolean f6,
boolean f7,
boolean f8)
|
static byte[] |
function9Through12Packet(int address,
boolean longAddr,
boolean f9,
boolean f10,
boolean f11,
boolean f12)
|
static byte[] |
oneBytePacket(int address,
boolean longAddr,
byte arg1)
Create a packet containing a one-byte instruction. |
static byte[] |
opsCvWriteByte(int address,
boolean longAddr,
int cvNum,
int data)
|
static byte[] |
speedStep128Packet(int address,
boolean longAddr,
int speed,
boolean fwd)
|
static byte[] |
speedStep14Packet(int address,
boolean longAddr,
int speed,
boolean fwd,
boolean F0)
|
static byte[] |
speedStep28Packet(int address,
boolean longAddr,
int speed,
boolean fwd)
From NMRA RP 9.2.1 A speed and direction instruction is used send information to motors connected to Multi Function Digital Decoders. |
static byte[] |
threeBytePacket(int address,
boolean longAddr,
byte arg1,
byte arg2,
byte arg3)
Create a packet containing a three-byte instruction. |
static byte[] |
twoBytePacket(int address,
boolean longAddr,
byte arg1,
byte arg2)
Create a packet containing a two-byte instruction. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int NO_ADDRESS
public static final int LOCO_SHORT_ADDRESS
public static final int LOCO_LONG_ADDRESS
public static final int ACCESSORY_SHORT_ADDRESS
| Method Detail |
|---|
public static byte[] oneBytePacket(int address,
boolean longAddr,
byte arg1)
public static byte[] twoBytePacket(int address,
boolean longAddr,
byte arg1,
byte arg2)
public static byte[] threeBytePacket(int address,
boolean longAddr,
byte arg1,
byte arg2,
byte arg3)
public static byte[] fourBytePacket(int address,
boolean longAddr,
byte arg1,
byte arg2,
byte arg3,
byte arg4)
public static byte[] accDecoderPkt(int addr,
int active,
int outputChannel)
public static byte[] accDecoderPktOpsMode(int addr,
int active,
int outputChannel,
int cvNum,
int data)
public static byte[] accDecPktOpsModeLegacy(int addr,
int cvNum,
int data)
public static byte[] accSignalDecoderPkt(int outputAddr,
int aspect)
outputAddr - Address of accessory output, starting with 1 and a maximum of 2044aspect - Aspect Number starting with 0 and a maximum of 31
public static byte[] accDecoderPkt(int number,
boolean closed)
number - Address of accessory output, starting with 1closed - true if the output is to be configured to the "closed", a.k.a. the
"normal" or "unset" position
public static byte[] accDecoderPktOpsMode(int number,
int cvNum,
int data)
number - Address of accessory, starting with 1cvNum - CV number to accessdata - Data to be written
public static byte[] accDecoderPktOpsModeLegacy(int number,
int cvNum,
int data)
number - Address of accessory, starting with 1cvNum - CV number to accessdata - Data to be written
public static byte[] opsCvWriteByte(int address,
boolean longAddr,
int cvNum,
int data)
public static byte[] speedStep128Packet(int address,
boolean longAddr,
int speed,
boolean fwd)
public static byte[] speedStep28Packet(int address,
boolean longAddr,
int speed,
boolean fwd)
public static byte[] speedStep14Packet(int address,
boolean longAddr,
int speed,
boolean fwd,
boolean F0)
public static byte[] function0Through4Packet(int address,
boolean longAddr,
boolean f0,
boolean f1,
boolean f2,
boolean f3,
boolean f4)
public static byte[] function5Through8Packet(int address,
boolean longAddr,
boolean f5,
boolean f6,
boolean f7,
boolean f8)
public static byte[] function9Through12Packet(int address,
boolean longAddr,
boolean f9,
boolean f10,
boolean f11,
boolean f12)
public static byte[] function13Through20Packet(int address,
boolean longAddr,
boolean f13,
boolean f14,
boolean f15,
boolean f16,
boolean f17,
boolean f18,
boolean f19,
boolean f20)
public static byte[] function21Through28Packet(int address,
boolean longAddr,
boolean f21,
boolean f22,
boolean f23,
boolean f24,
boolean f25,
boolean f26,
boolean f27,
boolean f28)
public static byte[] analogControl(int address,
boolean longAddr,
int function,
int value)
Note that the NMRA draft of Fall 2004 only defines the value of "1" for the "function parameter", calling that the value for "volume control". However, DCC systems in the wild have been observed to use 0x7F for the function byte for volume control.
address - DCC locomotive addresslongAddr - true if this is a long address, false if short addressfunction - see note abovevalue - value to be sent in analog control instruction
public static byte[] consistControl(int address,
boolean longAddr,
int consist,
boolean directionNormal)
address - DCC locomotive addresslongAddr - true if this is a long address, false if short addressconsist - the consist address to set for this locomotive. Send
00 as consist address if deleteing from consist.directionNormal - true if the normal direction of travel for this
address is the normal direction of travel for the consist.public static String format(byte[] p)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||