001package jmri.jmrix.rps;
002
003import jmri.DccThrottle;
004import jmri.InstanceManager;
005import jmri.ThrottleListener;
006
007/**
008 * Represents an RPS transmitter, generally a locomotive.
009 * <p>
010 * The "ID" is used to identify this transmitter in RPS. The "rosterName" is the
011 * name (ID) of the roster entry this was originally created from.
012 *
013 * @author Bob Jacobsen Copyright (C) 2006, 2008
014 */
015public class Transmitter implements ThrottleListener {
016
017    Transmitter(String id, boolean polled, int address, boolean longAddress) {
018        setId(id);
019        setPolled(polled);
020        setAddress(address);
021        setLongAddress(longAddress);
022    }
023
024    public String getId() {
025        return id;
026    }
027    String id;
028
029    public void setId(String id) {
030        this.id = id;
031    }
032
033    public String getRosterName() {
034        return rosterName;
035    }
036    String rosterName;
037
038    public void setRosterName(String rosterName) {
039        this.rosterName = rosterName;
040    }
041
042    public boolean isLongAddress() {
043        return longAddress;
044    }
045    boolean longAddress;
046
047    public void setLongAddress(boolean longAddress) {
048        this.longAddress = longAddress;
049    }
050
051    public int getAddress() {
052        return address;
053    }
054    int address;
055
056    public void setAddress(int address) {
057        this.address = address;
058    }
059
060    public boolean isPolled() {
061        return polled;
062    }
063    boolean polled;
064
065    public void setPolled(boolean polled) {
066        this.polled = polled;
067    }
068
069    Measurement lastMeasurement = null;
070
071    public void setLastMeasurement(Measurement last) {
072        lastMeasurement = last;
073    }
074
075    public Measurement getLastMeasurement() {
076        return lastMeasurement;
077    }
078
079    // stuff to do F2 poll
080    DccThrottle throttle;
081    boolean needReqThrottle = true;
082
083    DccThrottle getThrottle() {
084        return throttle;
085    }
086
087    boolean checkInit() {
088        if (throttle != null) {
089            return true;
090        }
091        if (!needReqThrottle) {
092            return false;
093        }
094        // request throttle
095        InstanceManager.throttleManagerInstance().requestThrottle(
096            new jmri.DccLocoAddress(address, longAddress), this, false);
097        return false;
098    }
099
100    @Override
101    public void notifyThrottleFound(DccThrottle t) {
102        needReqThrottle = false;
103        throttle = t;
104    }
105
106    @Override
107    public void notifyFailedThrottleRequest(jmri.LocoAddress address, String reason) {
108    }
109
110    /**
111     * No steal or share decisions made locally
112     * <p>
113     * {@inheritDoc}
114     */
115    @Override
116    public void notifyDecisionRequired(jmri.LocoAddress address, DecisionType question) {
117    }
118
119}