001package jmri.jmrix.roco.z21;
002
003import jmri.DccLocoAddress;
004import jmri.jmrix.Message;
005
006/**
007 * Package protected class containing common methods for Z21 Messages and Replies.
008 *
009 * @author Paul Bender Copyright (C) 2019
010 */
011public class Z21MessageUtils {
012
013    public static int interpretBroadcastFlags(Message m) {
014        return m.getElement(4) + (m.getElement(5) << 8) + (m.getElement(6) << 16) + (m.getElement(7) << 24);
015    }
016
017    static int integer16BitFromOffeset(int[] elements,int offset){
018        return ((0xff&elements[offset+1])<<8) +
019                       (0xff&(elements[offset]));
020    }
021
022    // address value is the 16 bits of the two bytes containing the
023    // address.  The most significant two bits represent the direction.
024    public static DccLocoAddress getCanDetectorLocoAddress(int addressValue) {
025        if(addressValue==0) {
026            return null;
027        } else {
028            int locoAddress = (0x3FFF&addressValue);
029            return new DccLocoAddress(locoAddress,locoAddress>=100);
030        }
031    }
032}