jmri.jmrix.direct
Class MakePacket

java.lang.Object
  extended by jmri.jmrix.direct.MakePacket

public class MakePacket
extends Object

Provide utilities for coding/decoding NMRA S&RP DCC packets into sequences to send through a standard serial port.

This is strongly based on the makepckt.c file from the PacketScript 1.1. package of Kenneth Rice. The original header comment from that file follows here.


 Some Useful Background information

      startbit: 1
      stopbit : 1
      databits: 8
      baudrate: 19200

      ==> one serial bit takes 52.08 usec. (at 19200 baud)

      ==> NMRA-1-Bit: 01         (52 usec low and 52 usec high)
          NMRA-0-Bit: 0011       (at least 100 usec low and high)
           note we are allowed to stretch NMRA-0 e.g. 000111,
           00001111, 000001111
          are all valid NMRA-0 representations

      serial stream (only start/stop bits):

      0_______10_______10_______10_______10_______10_______10___ ...

      problem: how to place the NMRA-0- and NMRA-1-Bits in the
    serial stream

     examples:

      0          0xF0     _____-----
      00         0xC6     __--___---
      01         0x78     ____----_-
      10         0xE1     _-____----
      001        0x66     __--__--_-
      010        0x96     __--_-__--
      011        0x5C     ___---_-_-
      100        0x99     _-__--__--
      101        0x71     _-___---_-
      110        0xC5     _-_-___---
      0111       0x56     __--_-_-_-
      1011       0x59     _-__--_-_-
      1101       0x65     _-_-__--_-
      1110       0x95     _-_-_-__--
      11111      0x55     _-_-_-_-_-
                          ^        ^
                          start-   stop-
                          bit      bit

 Limitation
 If we ever need to generate a pattern of four '1's followed by a '0' and
 land it on a the start of a byte boundary - Sorry - it can't be done !!


 makepckt.c

 Send an nmra packet out the serial port in such a way that the signal can
 just be amplified and put on the track.

 Copyright 1993 Kenneth Rice

 You may freely distribute this source code, and use all or part of
 this source code in all software including commercial, freeware,
 shareware and private applications.

 Please report bugs, fixes, etc to me at:
        kenr@xis.xerox.com
 or
        73577,1653 (compuserve)

 Created        02/08/93
                        03/05/93        Works for all 3 byte packets. Still errors for 4 byte.
                        07/01/93        Renamed to makepckt.c to be nice to dos users.
                        10/23/93        Added backtracking and max length.
 

Author:
Bob Jacobsen Copyright (C) 2001

Constructor Summary
MakePacket()
           
 
Method Summary
static int[] createStream(byte[] packet)
          Function that takes in the packet as a array of Bytes and converts an them into NMRA'1','0' representation, in preparation to be sent over a serial link.
static boolean setPreambleLength(int preambleLen)
          function to set the Preamble Length - Default is 15 NRMA '1's Every NMRA packet decoded starts with a preamble Service mode requires longer preambles Thus this public function allowing user to define the lenght of desired preamble
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MakePacket

public MakePacket()
Method Detail

setPreambleLength

public static boolean setPreambleLength(int preambleLen)
function to set the Preamble Length - Default is 15 NRMA '1's Every NMRA packet decoded starts with a preamble Service mode requires longer preambles Thus this public function allowing user to define the lenght of desired preamble

Parameters:
preambleLen - int
Returns:
boolean - true if preamble is a multiple of 5 otherwise fails and returns alse

createStream

public static int[] createStream(byte[] packet)
Function that takes in the packet as a array of Bytes and converts an them into NMRA'1','0' representation, in preparation to be sent over a serial link.

Parameters:
packet - byte[] - NRMA packet in a array of bytes
Returns:
int[] - first byte is length - 0 length indicates failed to do


Copyright © 1997 - 2011 JMRI Community.
JMRI, DecoderPro, PanelPro, SoundPro, DispatcherPro and associated logos are our trademarks.

Additional information on copyright, trademarks and licenses is linked here.
Site hosted by: Get JMRI Model Railroad Interface at SourceForge.net. Fast, secure and Free Open Source software downloads