Skip to content

Commit

Permalink
Update turnout state in JMRI problem
Browse files Browse the repository at this point in the history
This version is as quiet as can be but the above problem has to be
fixed.
  • Loading branch information
janboen committed Jun 25, 2016
1 parent d5ed519 commit 4c4ea21
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 83 deletions.
4 changes: 2 additions & 2 deletions java/src/jmri/jmrix/tams/TamsMessage.java
Expand Up @@ -101,7 +101,7 @@ public TamsMessage(int[] m) {//an array of int will be interpreted as binary
if (this.getElement(1) == (TamsConstants.XEVTLOK & TamsConstants.MASKFF)){
setReplyLastByte(TamsConstants.EOM80);
}
log.info(jmri.util.StringUtil.appendTwoHexFromInt(this.getElement(1),""));
//log.info(jmri.util.StringUtil.appendTwoHexFromInt(this.getElement(1),""));
//setRetries(1);
//log.info("Binary reply will be: one byte= " + getReplyOneByte() + ", last byte= " + getReplyLastByte());
}
Expand Down Expand Up @@ -143,7 +143,7 @@ static public TamsMessage getXStatus() {
m.setBinary(true);
m.setReplyOneByte(true);
m.setReplyType('P');
log.info("Preformatted Tams getXStatus = " + Integer.toHexString(m.getElement(0)) + " " + Integer.toHexString(m.getElement(1)));
//log.info("Preformatted Tams getXStatus = " + Integer.toHexString(m.getElement(0)) + " " + Integer.toHexString(m.getElement(1)));
//log.info("isBinary= " + m.isBinary() + ", one byte reply " + m.getReplyOneByte() + ", reply type " + m.getReplyType());
return m;
}
Expand Down
46 changes: 23 additions & 23 deletions java/src/jmri/jmrix/tams/TamsSensorManager.java
Expand Up @@ -45,7 +45,7 @@ static private TamsMessage myDummy() {
return m;
}
static private TamsMessage xSR() {
log.info("*** xSR ***");
//log.info("*** xSR ***");
TamsMessage m = new TamsMessage("xSR 1");
m.setBinary(false);
m.setReplyOneByte(false);
Expand All @@ -66,14 +66,14 @@ public TamsSensorManager(TamsSystemConnectionMemo memo) {
tm = xSR();//auto reset after reading S88
tc.sendTamsMessage(tm, this);
tmq.add(tm);
log.info("Sending TamsMessage = " + tm.toString() + " , isBinary = " + tm.isBinary() + " and replyType = " + tm.getReplyType());
//log.info("Sending TamsMessage = " + tm.toString() + " , isBinary = " + tm.isBinary() + " and replyType = " + tm.getReplyType());
//Add polling for sensor state changes
tm = TamsMessage.getXEvtSen(); //reports only sensors with changed states
//startPolling();
tc.sendTamsMessage(tm, this);
tmq.add(tm);
tc.addPollMessage(tm, this);
log.info("TamsMessage added to pollqueue = " + jmri.util.StringUtil.appendTwoHexFromInt(tm.getElement(0) & 0xFF, "") + " " + jmri.util.StringUtil.appendTwoHexFromInt(tm.getElement(1) & 0xFF, "") + " and replyType = " + tm.getReplyType());
//log.info("TamsMessage added to pollqueue = " + jmri.util.StringUtil.appendTwoHexFromInt(tm.getElement(0) & 0xFF, "") + " " + jmri.util.StringUtil.appendTwoHexFromInt(tm.getElement(1) & 0xFF, "") + " and replyType = " + tm.getReplyType());
}

TamsSystemConnectionMemo memo;
Expand All @@ -87,7 +87,7 @@ public String getSystemPrefix() {

public Sensor createNewSensor(String systemName, String userName) {
TamsSensor s = new TamsSensor(systemName, userName);
log.info("Creating new TamsSensor: " + systemName);
//log.info("Creating new TamsSensor: " + systemName);
if (systemName.contains(":")) {
int board = 0;
int channel = 0;
Expand All @@ -96,10 +96,10 @@ public Sensor createNewSensor(String systemName, String userName) {
int seperator = curAddress.indexOf(":");
try {
board = Integer.valueOf(curAddress.substring(0, seperator)).intValue();
log.info("Creating new TamsSensor with board: " + board);
//log.info("Creating new TamsSensor with board: " + board);
if (!_ttams.containsKey(board)) {
_ttams.put(board, new Hashtable<Integer, TamsSensor>());
log.info("_ttams: " + _ttams.toString());
//log.info("_ttams: " + _ttams.toString());
/*if (_ttams.size() == 1) {
synchronized (pollHandler) {
pollHandler.notify();
Expand All @@ -122,7 +122,7 @@ public Sensor createNewSensor(String systemName, String userName) {
}
if ((board * 2) > maxSE) {//Check if newly defined board number is higher than what we know
maxSE = board * 2;//adjust xSE and inform Tams MC
log.info("Changed xSE to " + maxSE);
//log.info("Changed xSE to " + maxSE);
tm = new TamsMessage("xSE " + Integer.toString(maxSE));
tm.setBinary(false);
tm.setReplyType('S');
Expand All @@ -131,7 +131,7 @@ public Sensor createNewSensor(String systemName, String userName) {
//no need to add a message for this board as the polling process will capture all board anyway
}
}
log.info("Returning this sensor: " + s.toString());
//log.info("Returning this sensor: " + s.toString());
return s;
}

Expand Down Expand Up @@ -237,39 +237,39 @@ public boolean allowMultipleAdditions(String systemName) {

// to listen for status changes from Tams system
public void reply(TamsReply r) {
log.info("*** TamsReply ***");
//log.info("*** TamsReply ***");
if(tmq.isEmpty()){
tm = myDummy();
} else
{
tm = tmq.poll();
}
log.info("ReplyType = " + tm.getReplyType() + ", Binary? = " + tm.isBinary()+ ", OneByteReply = " + tm.getReplyOneByte());
//log.info("ReplyType = " + tm.getReplyType() + ", Binary? = " + tm.isBinary()+ ", OneByteReply = " + tm.getReplyOneByte());
if (tm.getReplyType() == 'S'){//Only handle Sensor events
if (tm.isBinary() == true){//Typical polling message
if ((r.getNumDataElements() > 1) && (r.getElement(0) > 0x00)){
//Here we break up a long sensor related TamsReply into individual S88 module status'
int numberOfReplies = r.getNumDataElements() / 3;
log.info("Incoming Reply = ");
//log.info("Incoming Reply = ");
for (int i = 0; i < r.getNumDataElements(); i++){
log.info("Byte " + i + " = " + jmri.util.StringUtil.appendTwoHexFromInt(r.getElement(i) & 0xFF, ""));
//log.info("Byte " + i + " = " + jmri.util.StringUtil.appendTwoHexFromInt(r.getElement(i) & 0xFF, ""));
}
log.info("length of reply = " + r.getNumDataElements() + " & number of replies = " + numberOfReplies);
//log.info("length of reply = " + r.getNumDataElements() + " & number of replies = " + numberOfReplies);
for (int i = 0; i < numberOfReplies; i++) {
//create a new TamsReply and pass it to the decoder
TamsReply tr = new TamsReply();
tr.setBinary(r.isBinary());
tr.setElement(0, r.getElement(3 * i));
tr.setElement(1, r.getElement(3 * i + 1));
tr.setElement(2, r.getElement(3 * i + 2));
log.info("Going to pass this to the decoder = " + tr.toString());
//log.info("Going to pass this to the decoder = " + tr.toString());
//The decodeSensorState will do the actual decoding of each individual S88 port
decodeSensorState(tr);
}
}
} else {//xSR is an ASCII message
//Nothing to do really
log.info("Reply to ACSII command = " + r.toString());
//log.info("Reply to ACSII command = " + r.toString());
}
tm = myDummy();
}
Expand All @@ -282,7 +282,7 @@ public void reply(TamsReply r) {

protected void startPolling() {
stopPolling = false;
log.info("Completed build of active readers " + _ttams.size());
//log.info("Completed build of active readers " + _ttams.size());
if (_ttams.size() > 0) {
if (pollHandler == null) {
pollHandler = new PollHandler(this);
Expand All @@ -293,7 +293,7 @@ protected void startPolling() {
pollThread.start();
pollHandler.notify();
} else {
log.info("No active boards found");
//log.info("No active boards found");
}
}

Expand Down Expand Up @@ -344,14 +344,14 @@ private void decodeSensorState(TamsReply r) {
//byte 2 = bits 1 to 8
//byte 3 = bits 9 to 16
String sensorprefix = getSystemPrefix() + "S" + r.getElement(0) + ":";
log.info("Decoding sensor: " + sensorprefix);
log.info("Lower Byte: " + r.getElement(1));
log.info("Upper Byte: " + r.getElement(2));
//log.info("Decoding sensor: " + sensorprefix);
//log.info("Lower Byte: " + r.getElement(1));
//log.info("Upper Byte: " + r.getElement(2));
Hashtable<Integer, TamsSensor> sensorList = _ttams.get(board);
int i = (r.getElement(1) & 0xff) << 8;//first 8 ports in second element of the reply
//log.info("i after loading first byte= " + Integer.toString(i,2));
i = i + (r.getElement(2) & 0xff);//first 8 ports in third element of the reply
log.info("i after loading second byte= " + Integer.toString(i,2));
//log.info("i after loading second byte= " + Integer.toString(i,2));
int mask = 0b100000000000000;
for (int port = 1; port <= 16; port++) {
int result = i & mask;
Expand All @@ -369,9 +369,9 @@ private void decodeSensorState(TamsReply r) {
if (ms != null) {
if (result == 0) {
ms.setOwnState(Sensor.INACTIVE);
log.debug(sensorprefix + port + " INACTIVE");
//log.info(sensorprefix + port + " INACTIVE");
} else {
log.info(sensorprefix + port + " ACTIVE");
//log.info(sensorprefix + port + " ACTIVE");
ms.setOwnState(Sensor.ACTIVE);
}
}
Expand Down
69 changes: 48 additions & 21 deletions java/src/jmri/jmrix/tams/TamsThrottle.java
Expand Up @@ -236,10 +236,6 @@ public LocoAddress getLocoAddress() {

protected void throttleDispose() {
active = false;
//A poll message get's added by the first throttle
//Duplicates are not put in the queue
//We don't stop polling when a throttle closes
//Only remove the binary polling message
tm = TamsMessage.getXEvtLok();
tc.removePollMessage(tm, this);
}
Expand All @@ -264,7 +260,7 @@ protected float floatSpeed(int lSpeed) {
}

public void reply(TamsReply tr) {
log.info("*** Loco reply ***");
//log.info("*** Loco reply ***");
if(tmq.isEmpty()){
tm = myDummy();
} else
Expand Down Expand Up @@ -292,83 +288,114 @@ public void reply(TamsReply tr) {
int msb = tr.getElement(3) & 0x3F;
int lsb = tr.getElement(2) & 0xFF;
int receivedAddress = msb * 256 + lsb;
log.info("reply = " + jmri.util.StringUtil.appendTwoHexFromInt(tr.getElement(4) & 0xFF, "") + " " + jmri.util.StringUtil.appendTwoHexFromInt(tr.getElement(3) & 0xFF, "") + " " + jmri.util.StringUtil.appendTwoHexFromInt(tr.getElement(2) & 0xFF, "") + " " + jmri.util.StringUtil.appendTwoHexFromInt(tr.getElement(1) & 0xFF, "") + " " + jmri.util.StringUtil.appendTwoHexFromInt(tr.getElement(0) & 0xFF, ""));
//log.info("reply for loco = " + receivedAddress);
//log.info("reply = " + jmri.util.StringUtil.appendTwoHexFromInt(tr.getElement(4) & 0xFF, "") + " " + jmri.util.StringUtil.appendTwoHexFromInt(tr.getElement(3) & 0xFF, "") + " " + jmri.util.StringUtil.appendTwoHexFromInt(tr.getElement(2) & 0xFF, "") + " " + jmri.util.StringUtil.appendTwoHexFromInt(tr.getElement(1) & 0xFF, "") + " " + jmri.util.StringUtil.appendTwoHexFromInt(tr.getElement(0) & 0xFF, ""));
if (receivedAddress == address.getNumber()){//If correct address then decode the content
//log.info("Is my address");
try {
StringBuilder sb = new StringBuilder();
Float newSpeed = Float.valueOf(floatSpeed(tr.getElement(0)));
super.setSpeedSetting(newSpeed);
log.info("f0 = " + (tr.getElement(3) & 0x40 ));
if (((tr.getElement(3) & 0x40 ) == 64) && !this.f0) {
//log.info("f0 = " + (tr.getElement(3) & 0x40 ));
if ((((tr.getElement(3) & 0x40 ) == 64)) && !this.f0) {
notifyPropertyChangeListener(Throttle.F0, this.f0, true);
sb.append("f0 ");
this.f0 = true;
} else if (((tr.getElement(3) & 0x40 ) == 0) && this.f0) {
}
if (((tr.getElement(3) & 0x40 ) == 0) && this.f0) {
notifyPropertyChangeListener(Throttle.F0, this.f0, false);
sb.append("0f ");
this.f0 = false;
}
if (((tr.getElement(3) & 0x80 ) == 0) && isForward) {
if (((tr.getElement(3) & 0x80 ) == 0)&& isForward) {
notifyPropertyChangeListener("IsForward", isForward, false);
isForward = false;
} else if (((tr.getElement(3) & 0x80 ) == 128) && !isForward) {
}
if (((tr.getElement(3) & 0x80 ) == 128)&& !isForward) {
notifyPropertyChangeListener("IsForward", isForward, true);
isForward = true;
}
if (((tr.getElement(1) & 0x01 ) == 1) && !this.f1) {
notifyPropertyChangeListener(Throttle.F1, this.f1, true);
sb.append("f1 ");
this.f1 = true;
} else if (((tr.getElement(1) & 0x01 ) == 0) && this.f1) {
}
if (((tr.getElement(1) & 0x01 ) == 0) && this.f1) {
notifyPropertyChangeListener(Throttle.F1, this.f1, false);
sb.append("1f ");
this.f1 = false;
}
if (((tr.getElement(1) & 0x02 ) == 2) && !this.f2) {
notifyPropertyChangeListener(Throttle.F2, this.f2, true);
sb.append("f2 ");
this.f2 = true;
} else if (((tr.getElement(1) & 0x02 ) == 0) && this.f2) {
}
if (((tr.getElement(1) & 0x02 ) == 0) && this.f2) {
notifyPropertyChangeListener(Throttle.F2, this.f2, false);
sb.append("2f ");
this.f2 = false;
}
if (((tr.getElement(1) & 0x04 ) == 4) && !this.f3) {
if (((tr.getElement(1) & 0x04 ) == 4) && !this.f3){
notifyPropertyChangeListener(Throttle.F3, this.f3, true);
sb.append("f3 ");
this.f3 = true;
} else if (((tr.getElement(1) & 0x04 ) == 0) && this.f3) {
}
if (((tr.getElement(1) & 0x04 ) == 0) && this.f3) {
notifyPropertyChangeListener(Throttle.F3, this.f3, false);
sb.append("3f ");
this.f3 = false;
}
if (((tr.getElement(1) & 0x08 ) == 8) && !this.f4) {
notifyPropertyChangeListener(Throttle.F4, this.f4, true);
sb.append("f4 ");
this.f4 = true;
} else if (((tr.getElement(1) & 0x08 ) == 0) && this.f4) {
}
if (((tr.getElement(1) & 0x08 ) == 0) && this.f4) {
notifyPropertyChangeListener(Throttle.F4, this.f4, false);
sb.append("4f ");
this.f4 = false;
}
if (((tr.getElement(1) & 0x10 ) == 16) && !this.f5) {
notifyPropertyChangeListener(Throttle.F5, this.f5, true);
sb.append("f5 ");
this.f5 = true;
} else if (((tr.getElement(1) & 0x10 ) == 0) && this.f5) {
}
if (((tr.getElement(1) & 0x10 ) == 0) && this.f5) {
notifyPropertyChangeListener(Throttle.F5, this.f5, false);
sb.append("5f ");
this.f5 = false;
}
if (((tr.getElement(1) & 0x20 ) == 32) && !this.f6) {
notifyPropertyChangeListener(Throttle.F6, this.f6, true);
sb.append("f6 ");
this.f6 = true;
} else if (((tr.getElement(1) & 0x20 ) == 0) && this.f6) {
}
if (((tr.getElement(1) & 0x20 ) == 0) && this.f6) {
notifyPropertyChangeListener(Throttle.F6, this.f6, false);
sb.append("6f ");
this.f6 = false;
}
if (((tr.getElement(1) & 0x40 ) == 64) && !this.f7) {
notifyPropertyChangeListener(Throttle.F7, this.f7, true);
sb.append("f7 ");
this.f7 = true;
} else if (((tr.getElement(1) & 0x40 ) == 0) && this.f7) {
}
if (((tr.getElement(1) & 0x40 ) == 0) && this.f7) {
notifyPropertyChangeListener(Throttle.F7, this.f7, false);
sb.append("7f ");
this.f7 = false;
}
if (((tr.getElement(1) & 0x80 ) == 128) && !this.f8) {
notifyPropertyChangeListener(Throttle.F8, this.f8, true);
sb.append("f8");
this.f8 = true;
} else if (((tr.getElement(1) & 0x80 ) == 0) && this.f8) {
}
if (((tr.getElement(1) & 0x80 ) == 0) && this.f8) {
notifyPropertyChangeListener(Throttle.F8, this.f8, false);
sb.append("8f");
this.f8 = false;
}
//log.info(sb.toString());
} catch (Exception ex) {
log.error("Error handling reply from MC " + ex);
}
Expand All @@ -381,7 +408,7 @@ public void reply(TamsReply tr) {
}
if (tr.match("L " + address.getNumber()) >= 0) {
try {
log.info("ASCII address = " + address.getNumber());
//log.info("ASCII address = " + address.getNumber());
String[] lines = tr.toString().split(" ");
Float newSpeed = Float.valueOf(floatSpeed(Integer.parseInt(lines[2])));
super.setSpeedSetting(newSpeed);
Expand Down

2 comments on commit 4c4ea21

@bobjacobsen
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use log.debug instead of commenting out log.info. That is normally silent, but can easily be turn on via the default.lcf file when more output is desired.

@janboen
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Please sign in to comment.