001package jmri.jmrix.lenz.messageformatters; 002 003import jmri.jmrix.Message; 004import jmri.jmrix.lenz.XNetConstants; 005import jmri.jmrix.lenz.XNetReply; 006import jmri.jmrix.lenz.XPressNetMessageFormatter; 007 008/** 009 * Formatter for XpressNet Locomotive Information Normal Unit High Function Momentary Status messages. 010 * 011 * @author Paul Bender Copyright (C) 2025 012 */ 013public class XNetLocoInfoNormalUnitHighFunctionMomentaryStatusFormatter implements XPressNetMessageFormatter { 014 015 @Override 016 public boolean handlesMessage(Message m) { 017 return m instanceof XNetReply && ((XNetReply) m).getElement(0) == XNetConstants.LOCO_INFO_NORMAL_UNIT && 018 ((XNetReply) m).getElement(1) == XNetConstants.LOCO_FUNCTION_STATUS_HIGH_MOM; 019 } 020 021 @Override 022 public String formatMessage(Message m) { 023 if(!handlesMessage(m)) { 024 return Bundle.getMessage("XNetReplyLocoStatus13Label"); 025 } 026 return Bundle.getMessage("XNetReplyLocoStatus13Label") + " " + 027 parseFunctionHighMomentaryStatus(m.getElement(2), m.getElement(3)); 028 } 029 030 031 private static final String FUNCTION_MOMENTARY = "FunctionMomentary"; 032 private static final String FUNCTION_CONTINUOUS = "FunctionContinuous"; 033 034 /** 035 * Parse the Momentary sytatus of functions F13-F28. 036 * 037 * @param element3 contains F20,F19,F18,F17,F16,F15,F14,F13 038 * @param element4 contains F28,F27,F26,F25,F24,F23,F22,F21 039 * @return readable version of message 040 */ 041 protected String parseFunctionHighMomentaryStatus(int element3, int element4) { 042 String text = ""; 043 if ((element3 & 0x01) != 0) { 044 text += "F13 " + Bundle.getMessage(FUNCTION_MOMENTARY) + "; "; 045 } else { 046 text += "F13 " + Bundle.getMessage(FUNCTION_CONTINUOUS) + "; "; 047 } 048 if ((element3 & 0x02) != 0) { 049 text += "F14 " + Bundle.getMessage(FUNCTION_MOMENTARY) + "; "; 050 } else { 051 text += "F14 " + Bundle.getMessage(FUNCTION_CONTINUOUS) + "; "; 052 } 053 if ((element3 & 0x04) != 0) { 054 text += "F15 " + Bundle.getMessage(FUNCTION_MOMENTARY) + "; "; 055 } else { 056 text += "F15 " + Bundle.getMessage(FUNCTION_CONTINUOUS) + "; "; 057 } 058 if ((element3 & 0x08) != 0) { 059 text += "F16 " + Bundle.getMessage(FUNCTION_MOMENTARY) + "; "; 060 } else { 061 text += "F16 " + Bundle.getMessage(FUNCTION_CONTINUOUS) + "; "; 062 } 063 if ((element3 & 0x10) != 0) { 064 text += "F17 " + Bundle.getMessage(FUNCTION_MOMENTARY) + "; "; 065 } else { 066 text += "F17 " + Bundle.getMessage(FUNCTION_CONTINUOUS) + "; "; 067 } 068 if ((element3 & 0x20) != 0) { 069 text += "F18 " + Bundle.getMessage(FUNCTION_MOMENTARY) + "; "; 070 } else { 071 text += "F18 " + Bundle.getMessage(FUNCTION_CONTINUOUS) + "; "; 072 } 073 if ((element3 & 0x40) != 0) { 074 text += "F19 " + Bundle.getMessage(FUNCTION_MOMENTARY) + "; "; 075 } else { 076 text += "F19 " + Bundle.getMessage(FUNCTION_CONTINUOUS) + "; "; 077 } 078 if ((element3 & 0x80) != 0) { 079 text += "F20 " + Bundle.getMessage(FUNCTION_MOMENTARY) + "; "; 080 } else { 081 text += "F20 " + Bundle.getMessage(FUNCTION_CONTINUOUS) + "; "; 082 } 083 if ((element4 & 0x01) != 0) { 084 text += "F21 " + Bundle.getMessage(FUNCTION_MOMENTARY) + "; "; 085 } else { 086 text += "F21 " + Bundle.getMessage(FUNCTION_CONTINUOUS) + "; "; 087 } 088 if ((element4 & 0x02) != 0) { 089 text += "F22 " + Bundle.getMessage(FUNCTION_MOMENTARY) + "; "; 090 } else { 091 text += "F22 " + Bundle.getMessage(FUNCTION_CONTINUOUS) + "; "; 092 } 093 if ((element4 & 0x04) != 0) { 094 text += "F23 " + Bundle.getMessage(FUNCTION_MOMENTARY) + "; "; 095 } else { 096 text += "F23 " + Bundle.getMessage(FUNCTION_CONTINUOUS) + "; "; 097 } 098 if ((element4 & 0x08) != 0) { 099 text += "F24 " + Bundle.getMessage(FUNCTION_MOMENTARY) + "; "; 100 } else { 101 text += "F24 " + Bundle.getMessage(FUNCTION_CONTINUOUS) + "; "; 102 } 103 if ((element4 & 0x10) != 0) { 104 text += "F25 " + Bundle.getMessage(FUNCTION_MOMENTARY) + "; "; 105 } else { 106 text += "F25 " + Bundle.getMessage(FUNCTION_CONTINUOUS) + "; "; 107 } 108 if ((element4 & 0x20) != 0) { 109 text += "F26 " + Bundle.getMessage(FUNCTION_MOMENTARY) + "; "; 110 } else { 111 text += "F26 " + Bundle.getMessage(FUNCTION_CONTINUOUS) + "; "; 112 } 113 if ((element4 & 0x40) != 0) { 114 text += "F27 " + Bundle.getMessage(FUNCTION_MOMENTARY) + "; "; 115 } else { 116 text += "F27 " + Bundle.getMessage(FUNCTION_CONTINUOUS) + "; "; 117 } 118 if ((element4 & 0x80) != 0) { 119 text += "F28 " + Bundle.getMessage(FUNCTION_MOMENTARY) + "; "; 120 } else { 121 text += "F28 " + Bundle.getMessage(FUNCTION_CONTINUOUS) + "; "; 122 } 123 return (text); 124 } 125 126}