001package jmri.jmrix.lenz.messageformatters; 002 003import jmri.jmrix.Message; 004import jmri.jmrix.lenz.LenzCommandStation; 005import jmri.jmrix.lenz.XNetConstants; 006import jmri.jmrix.lenz.XNetReply; 007import jmri.jmrix.lenz.XPressNetMessageFormatter; 008 009/** 010 * Format replies for XPressNet Command Station reply for Loco Info DH Unit. 011 * 012 * @author Paul Bender Copyright (C) 2025 013 */ 014public class XNetLocoInfoDHUnitFormatter implements XPressNetMessageFormatter { 015 @Override 016 public boolean handlesMessage(Message m) { 017 return m instanceof XNetReply && 018 m.getElement(0) == XNetConstants.LOCO_INFO_DH_UNIT; 019 } 020 021 @Override 022 public String formatMessage(Message m) { 023 if(!handlesMessage(m)) { 024 throw new IllegalArgumentException("Message is not supported"); 025 } 026 return Bundle.getMessage("XNetReplyLocoDHLabel") + "," + 027 XNetLocoInfoReplyUtilities.parseSpeedAndDirection(m.getElement(1), m.getElement(2)) + " " + 028 XNetLocoInfoReplyUtilities.parseFunctionStatus(m.getElement(3), m.getElement(4)) + 029 " " + Bundle.getMessage("XNetReplyLoco2DHLabel") + " " + 030 LenzCommandStation.calcLocoAddress(m.getElement(5), m.getElement(6)); 031 032 } 033}