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 (0xB1) to invoke the bootloader
014 * update sequence for Märklin hardware. According to German language 
015 * forum documentation, this is part of the software/bootloader command 
016 * range used for firmware updates and device initialization.
017 *
018 * @author JMRI Community
019 * @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>
020 */
021public class MarklinSendBootAction extends AbstractAction {
022
023    private final MarklinSystemConnectionMemo memo;
024    private static final Logger log = LoggerFactory.getLogger(MarklinSendBootAction.class);
025
026    /**
027     * Create an action to send MCAN BOOT message.
028     *
029     * @param name the name for this action; will appear on menu items, buttons, etc.
030     * @param memo the system connection memo for this action
031     */
032    public MarklinSendBootAction(String name, MarklinSystemConnectionMemo memo) {
033        super(name);
034        this.memo = memo;
035    }
036
037    /**
038     * Create an action with default name.
039     *
040     * @param memo the system connection memo for this action
041     */
042    public MarklinSendBootAction(MarklinSystemConnectionMemo memo) {
043        this(Bundle.getMessage("MenuItemSendMCanBoot"), memo);
044    }
045
046    @Override
047    public void actionPerformed(ActionEvent e) {
048        if (memo != null && memo.getTrafficController() != null) {
049            MarklinMessage bootMessage = MarklinMessage.getCanBoot();
050            memo.getTrafficController().sendMarklinMessage(bootMessage, null);
051            log.info("CanBoot Message sent");
052        } else {
053            log.warn("Cannot send CanBoot message - no connection available");
054        }
055    }
056}