001package jmri.jmrix.loconet; 002 003import javax.annotation.Nonnull; 004 005import jmri.StringIO; 006 007/** 008 * Manage the LocoNet-specific Sensor implementation. 009 * System names are "LSnnn", where L is the user configurable system prefix, 010 * nnn is the sensor number without padding. Valid sensor numbers are in the 011 * range 1 to 2048, inclusive. 012 * 013 * Provides a mechanism to perform the LocoNet "Interrogate" process in order 014 * to get initial values from those LocoNet devices which support the process 015 * and provide LocoNet Sensor (and/or LocoNet Turnout) functionality. 016 * 017 * @author Bob Jacobsen Copyright (C) 2001 018 * @author B. Milhaupt Copyright (C) 2020 019 * @author Daniel Bergqvist Copyright (C) 2021 020 */ 021public class LnStringIOManager extends jmri.managers.AbstractStringIOManager implements LocoNetListener { 022 023 protected final LnTrafficController tc; 024 025 public LnStringIOManager(LocoNetSystemConnectionMemo memo) { 026 super(memo); 027 tc = memo.getLnTrafficController(); 028 if (tc == null) { 029 log.error("LnStringIOManager Created, yet there is no Traffic Controller"); 030// return; // The return statement is not needed now since we don't register a listener. 031 } 032 033 // Don't register a listener now. But keep this line in case it's 034 // neede later. 035 // ctor has to register for LocoNet events 036// tc.addLocoNetListener(~0, this); 037 } 038 039 /** {@inheritDoc} */ 040 @Override 041 @Nonnull 042 public LocoNetSystemConnectionMemo getMemo() { 043 return (LocoNetSystemConnectionMemo) memo; 044 } 045 046 // to free resources when no longer used 047 /** {@inheritDoc} */ 048 @Override 049 public void dispose() { 050 tc.removeLocoNetListener(~0, this); 051 super.dispose(); 052 } 053 054 @Override 055 @Nonnull 056 public StringIO provideStringIO(@Nonnull String sName) throws IllegalArgumentException { 057 throw new IllegalArgumentException("Generic LocoNet StringIOs are not yet supported"); 058 // in the alternative, return provideStringIO(name); 059 } 060 061 /** {@inheritDoc} */ 062 @Override 063 @Nonnull 064 public StringIO provide(@Nonnull String name) throws IllegalArgumentException { 065 throw new IllegalArgumentException("Generic LocoNet StringIOs are not yet supported"); 066 // in the alternative, return provideStringIO(name); 067 } 068 069 @Override 070 @Nonnull 071 public StringIO createNewStringIO(String sName, String uName) { 072 throw new IllegalArgumentException("Generic LocoNet StringIOs are not yet supported"); 073 // in the alternative, return provideStringIO(name); 074 } 075 076 // LocoNet-specific methods 077 078 /** 079 * Listen for sensor messages, creating them as needed. 080 * @param l LocoNet message to be examined 081 */ 082 @Override 083 public void message(LocoNetMessage l) { 084// switch (l.getOpCode()) { 085// case LnConstants.OPC_INPUT_REP: /* page 9 of LocoNet PE */ 086// break; 087// //$FALL-THROUGH$ 088// default: // here we didn't find an interesting command 089// return; 090// } 091 // reach here for LocoNet sensor input command; make sure we know about this one 092 } 093 094 private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LnStringIOManager.class); 095 096}