001package jmri.jmrix.marklin.swing; 002 003import java.awt.event.ActionEvent; 004import javax.swing.AbstractAction; 005import jmri.jmrix.marklin.MarklinMessage; 006import jmri.jmrix.marklin.MarklinSystemConnectionMemo; 007import org.slf4j.Logger; 008import org.slf4j.LoggerFactory; 009 010/** 011 * Action to send MCAN BOOT message to Märklin devices. 012 * <p> 013 * This action sends a CAN BOOT command (0x1B) to reset the Gleisbox/trackbox 014 * and initiate it to start passing commands to locos and accessories on the rails. 015 * Without this command on startup, the hardware does not respond to subsequent 016 * commands. This is part of the software/bootloader command range used for 017 * firmware updates and device initialization. 018 * 019 * @author JMRI Community 020 * @see <a href="https://www.stummiforum.de/t122854f7-M-rklin-CAN-Protokoll-x-B-commands-updates.html">Märklin CAN Protokoll 0x1B commands documentation</a> 021 */ 022public class MarklinSendBootAction extends AbstractAction { 023 024 private final MarklinSystemConnectionMemo memo; 025 private static final Logger log = LoggerFactory.getLogger(MarklinSendBootAction.class); 026 027 /** 028 * Create an action to send MCAN BOOT message. 029 * 030 * @param name the name for this action; will appear on menu items, buttons, etc. 031 * @param memo the system connection memo for this action 032 */ 033 public MarklinSendBootAction(String name, MarklinSystemConnectionMemo memo) { 034 super(name); 035 this.memo = memo; 036 } 037 038 /** 039 * Create an action with default name. 040 * 041 * @param memo the system connection memo for this action 042 */ 043 public MarklinSendBootAction(MarklinSystemConnectionMemo memo) { 044 this(Bundle.getMessage("MenuItemSendMCanBoot"), memo); 045 } 046 047 @Override 048 public void actionPerformed(ActionEvent e) { 049 if (memo != null && memo.getTrafficController() != null) { 050 MarklinMessage bootMessage = MarklinMessage.getCanBoot(); 051 memo.getTrafficController().sendMarklinMessage(bootMessage, null); 052 log.info("CanBoot Message sent"); 053 } else { 054 log.warn("Cannot send CanBoot message - no connection available"); 055 } 056 } 057}