Search in sources :

Example 1 with RailCom

use of jmri.RailCom in project JMRI by JMRI.

the class Dcc4PcReporter method provideTag.

RailCom provideTag(int address, int addr_type) {
    log.debug("provide Tag");
    RailCom rcTag = jmri.InstanceManager.getDefault(jmri.RailComManager.class).provideIdTag("" + address);
    rcTag.setWhereLastSeen(this);
    rcTag.setAddressType(addr_type);
    setReport(rcTag);
    lastLoco = address;
    synchronized (this) {
        addr = address;
    }
    return rcTag;
}
Also used : RailCom(jmri.RailCom)

Example 2 with RailCom

use of jmri.RailCom in project JMRI by JMRI.

the class Dcc4PcReporter method decodeRailComInfo.

synchronized void decodeRailComInfo(RailComPacket rc, int packetTypeCmd) {
    if (log.isDebugEnabled()) {
        log.debug(getDisplayName() + " " + packetTypeCmd);
    }
    addressp1found++;
    RailCom rcTag = null;
    if (log.isDebugEnabled()) {
        log.debug(this.getDisplayName() + " " + super.getCurrentReport());
    }
    if (super.getCurrentReport() instanceof RailCom) {
        rcTag = (RailCom) super.getCurrentReport();
    }
    int[] packet = rc.getPacket();
    char chbyte;
    char type;
    if (log.isDebugEnabled()) {
        StringBuilder buf = new StringBuilder();
        for (int i = 0; i < packet.length; ++i) {
            buf.append(packet[i]);
        }
        String s = buf.toString();
        log.debug("Rail Comm Packets " + s);
    }
    int i = 0;
    while (i < packet.length) {
        packetseen++;
        chbyte = (char) packet[i];
        chbyte = decode[chbyte];
        if (chbyte == ERROR) {
            if (log.isDebugEnabled()) {
                log.debug(this.getDisplayName() + " Error packet stage 1: " + Integer.toHexString(packet[i]));
            }
            packetsinerror++;
            return;
        }
        i++;
        if ((chbyte & ACK) == ACK) {
            chbyte = (char) packet[i];
            i++;
            chbyte = decode[chbyte];
            if (chbyte == ERROR) {
                if (log.isDebugEnabled()) {
                    log.debug(this.getDisplayName() + " Error packet stage 2");
                }
                packetsinerror++;
                return;
            }
            if ((chbyte & ACK) == ACK) {
                if (packet.length <= (i + 1)) {
                    log.debug("No further data to process Only had the ack 1");
                    break;
                }
                chbyte = (char) packet[i];
                i++;
                chbyte = decode[chbyte];
            }
        }
        if (packet.length <= i) {
            break;
        }
        type = chbyte;
        chbyte = (char) packet[i];
        chbyte = decode[chbyte];
        if ((chbyte == ERROR) || ((chbyte & ACK) == ACK)) {
            if (log.isDebugEnabled()) {
                log.debug(this.getDisplayName() + " Error packet stage 3 " + Integer.toHexString(packet[i]) + "\n" + rc.toHexString());
            }
            i++;
            packetsinerror++;
            return;
        }
        chbyte = (char) (((type & 0x03) << 6) | (chbyte & 0x3f));
        type = (char) ((type >> 2) & 0x0F);
        switch(type) {
            case 0:
                if (log.isDebugEnabled()) {
                    log.debug(this.getDisplayName() + " CV Value " + ((int) chbyte) + rcTag);
                }
                cvvalue = chbyte;
                if (rcTag != null) {
                    rcTag.setWhereLastSeen(this);
                    if (rcTag.getExpectedCv() != -1) {
                        rcTag.setCvValue(chbyte);
                    } else {
                        rcTag.setCv(rc.getCvNumber(), chbyte);
                    }
                }
                break;
            case 4:
                if (log.isDebugEnabled()) {
                    log.debug(this.getDisplayName() + " Create/Get id tag for " + rc.getDCCAddress());
                }
                addr = rc.getDCCAddress();
                addr_type = rc.getAddressType();
                break;
            case // Address byte 1
            1:
                if (log.isDebugEnabled()) {
                    log.debug("Address Byte 1");
                }
                address_part_1 = (0x100 | chbyte);
                addressp1found = 0;
                break;
            case //Address byte 2
            2:
                if (log.isDebugEnabled()) {
                    log.debug(this.getDisplayName() + " Address part 2:");
                }
                address_part_2 = chbyte;
                if (packetTypeCmd == 0x03) {
                    log.debug("Type three packet so shouldn't not pair part one with part two if it came from the previous packet");
                //As the last command was a type 3, an address part one packet can not be paired with this address part two packet.  Therefore will set it back to default
                //address_part_1 = 0x100;
                // break;
                }
                if (!((address_part_1 & 0x100) == 0x100)) {
                    log.debug(this.getDisplayName() + " Break at Address part 1, part one not complete");
                    break;
                }
                rcTag = decodeAddress();
                break;
            case //Actual Speed / load
            3:
                if ((chbyte & 0x80) == 0x80) {
                    actual_speed = (chbyte & 0x7f);
                    log.debug(this.getDisplayName() + " Actual Speed: " + actual_speed);
                } else {
                    actual_load = (chbyte & 0x7f);
                    log.debug(this.getDisplayName() + " Actual Load: " + actual_load);
                }
                if (rcTag != null) {
                    rcTag.setActualLoad(actual_load);
                    rcTag.setActualSpeed(actual_speed);
                    rcTag.setWhereLastSeen(this);
                }
                break;
            case //Routing number
            5:
                routing_no = chbyte;
                if (rcTag != null) {
                    rcTag.setRoutingNo(routing_no);
                    rcTag.setWhereLastSeen(this);
                }
                break;
            case //Location
            6:
                location = chbyte;
                if (rcTag != null) {
                    rcTag.setLocation(location);
                    rcTag.setWhereLastSeen(this);
                }
                break;
            case //Fuel water
            7:
                if ((chbyte & 0x80) == 0x80) {
                    fuelLevel = (chbyte & 0x7f);
                } else {
                    waterLevel = (chbyte & 0x7f);
                }
                if (rcTag != null) {
                    rcTag.setWaterLevel(waterLevel);
                    rcTag.setFuelLevel(fuelLevel);
                    rcTag.setWhereLastSeen(this);
                }
                break;
            case //Temp
            8:
                if (!((chbyte & 0x80) == 0x80)) {
                    actual_temperature = (chbyte & 0x7F);
                }
                if (rcTag != null) {
                    rcTag.setActualTemperature(actual_temperature);
                    rcTag.setWhereLastSeen(this);
                }
                break;
            case //CV Address  Value
            15:
                log.debug(this.getDisplayName() + " CV Address and value:");
                i = i + 2;
                //len = 4;
                break;
            default:
                log.info("unknown railcom type packet " + type);
                break;
        }
        i++;
    }
}
Also used : RailCom(jmri.RailCom)

Example 3 with RailCom

use of jmri.RailCom in project JMRI by JMRI.

the class Z21Reporter method reply.

// the Z21 Listener interface
/**
     * Member function that will be invoked by a z21Interface implementation to
     * forward a z21 message from the layout.
     *
     * @param msg The received z21 reply. Note that this same object may be
     * presented to multiple users. It should not be modified here.
     */
@Override
public void reply(Z21Reply msg) {
    // LAN_RAILCOM_DATACHANGED messages.
    if (msg.isRailComDataChangedMessage()) {
        // find out how many RailCom Transmitters the command
        // station is telling us about (there is a maximum of 19).
        int tags = msg.getNumRailComDataEntries();
        for (int i = 0; i < tags; i++) {
            // get the locomotive address from the message.
            DccLocoAddress l = msg.getRailComLocoAddress(i);
            // see if there is a tag for this address.
            RailCom tag = InstanceManager.getDefault(RailComManager.class).provideIdTag("" + l.getNumber());
            tag.setAddressType(l.isLongAddress() ? RailCom.LONG_ADDRESS : RailCom.SHORT_ADDRESS);
            tag.setActualSpeed(msg.getRailComSpeed(i));
            tag.setActualTemperature(msg.getRailComTemp(i));
            // set the tag report.
            notify(tag);
        }
    }
}
Also used : RailComManager(jmri.RailComManager) RailCom(jmri.RailCom) DccLocoAddress(jmri.DccLocoAddress)

Example 4 with RailCom

use of jmri.RailCom in project JMRI by JMRI.

the class DefaultRailComManager method newIdTag.

@Override
public RailCom newIdTag(@Nonnull String systemName, @CheckForNull String userName) {
    if (log.isDebugEnabled()) {
        log.debug("new IdTag:" + ((systemName == null) ? "null" : systemName) + ";" + ((userName == null) ? "null" : userName));
    }
    checkSystemName(systemName, userName);
    // return existing if there is one
    RailCom s;
    if ((userName != null) && ((s = getByUserName(userName)) != null)) {
        if (getBySystemName(systemName) != s) {
            log.error("inconsistent user (" + userName + ") and system name (" + systemName + ") results; userName related to (" + s.getSystemName() + ")");
        }
        return s;
    }
    if ((s = getBySystemName(systemName)) != null) {
        if ((s.getUserName() == null) && (userName != null)) {
            s.setUserName(userName);
        } else if (userName != null) {
            log.warn("Found IdTag via system name (" + systemName + ") with non-null user name (" + userName + ")");
        }
        return s;
    }
    // doesn't exist, make a new one
    s = createNewIdTag(systemName, userName);
    // save in the maps
    register(s);
    // if that failed, blame it on the input arguements
    if (s == null) {
        throw new IllegalArgumentException();
    }
    return s;
}
Also used : DefaultRailCom(jmri.implementation.DefaultRailCom) RailCom(jmri.RailCom)

Example 5 with RailCom

use of jmri.RailCom in project JMRI by JMRI.

the class DefaultRailComTest method testNotYetSeen.

@Test
public void testNotYetSeen() {
    RailCom r = new DefaultRailCom("ID0413276BC1");
    Assert.assertNull("At creation, Reporter where seen is null", r.getWhereLastSeen());
    Assert.assertNull("At creation, Date when seen is null", r.getWhenLastSeen());
    Assert.assertEquals("At creation, RailCom status is UNSEEN", RailCom.UNSEEN, r.getState());
    r.setWhereLastSeen(null);
    Assert.assertNull("After setWhereLastSeen(null), Reporter where seen is null", r.getWhereLastSeen());
    Assert.assertNull("After setWhereLastSeen(null), Date when seen is null", r.getWhenLastSeen());
    Assert.assertEquals("After setWhereLastSeen(null), RailCom status is UNSEEN", RailCom.UNSEEN, r.getState());
}
Also used : RailCom(jmri.RailCom) Test(org.junit.Test)

Aggregations

RailCom (jmri.RailCom)12 Test (org.junit.Test)6 DefaultRailCom (jmri.implementation.DefaultRailCom)2 Date (java.util.Date)1 DccLocoAddress (jmri.DccLocoAddress)1 RailComManager (jmri.RailComManager)1 Reporter (jmri.Reporter)1