use of jmri.ProgListener in project JMRI by JMRI.
the class AddressedHighCvProgrammerFacadeTest method testWriteReadIndexed.
public void testWriteReadIndexed() throws jmri.ProgrammerException, InterruptedException {
ProgDebugger dp = new ProgDebugger();
dp.setTestReadLimit(256);
dp.setTestWriteLimit(256);
Programmer p = new AddressedHighCvProgrammerFacade(dp, "256", "253", "254", "255", "100");
ProgListener l = new ProgListener() {
@Override
public void programmingOpReply(int value, int status) {
log.debug("callback value=" + value + " status=" + status);
replied = true;
readValue = value;
}
};
p.writeCV("258", 12, l);
waitReply();
Assert.assertTrue("target not written", !dp.hasBeenWritten(258));
Assert.assertEquals("index H written", 2, dp.getCvVal(253));
Assert.assertEquals("index L written", 58, dp.getCvVal(254));
Assert.assertEquals("value written", 12, dp.getCvVal(255));
p.readCV("258", l);
waitReply();
Assert.assertEquals("read back", 12, readValue);
}
use of jmri.ProgListener in project JMRI by JMRI.
the class OffsetHighCvProgrammerFacadeTest method testWriteReadIndexed.
public void testWriteReadIndexed() throws jmri.ProgrammerException, InterruptedException {
ProgDebugger dp = new ProgDebugger();
dp.setTestReadLimit(256);
dp.setTestWriteLimit(256);
Programmer p = new OffsetHighCvProgrammerFacade(dp, "256", "7", "10", "100");
ProgListener l = new ProgListener() {
@Override
public void programmingOpReply(int value, int status) {
log.debug("callback value=" + value + " status=" + status);
replied = true;
readValue = value;
}
};
p.writeCV("258", 12, l);
waitReply();
Assert.assertTrue("target not written", !dp.hasBeenWritten(258));
Assert.assertEquals("index written", 20, dp.getCvVal(7));
Assert.assertEquals("value written", 12, dp.getCvVal(58));
p.readCV("258", l);
waitReply();
Assert.assertEquals("read back", 12, readValue);
}
use of jmri.ProgListener in project JMRI by JMRI.
the class LnOpsModeProgrammer method message.
@Override
public void message(LocoNetMessage m) {
// see if reply to LNSV 1 or LNSV2 request
if ((m.getElement(0) & 0xFF) != 0xE5)
return;
if ((m.getElement(1) & 0xFF) != 0x10)
return;
log.debug("reply {}", m);
if (getMode().equals(LnProgrammerManager.LOCONETSV1MODE)) {
// format 1
if ((m.getElement(4) & 0xFF) != 0x01)
return;
// 5
if ((m.getElement(5) & 0x70) != 0x00)
return;
// this might not be the right way to tell....
if ((m.getElement(3) & 0x7F) != 0x50)
return;
// check pending activity
if (p == null) {
log.warn("received SV reply message with no reply object: {}", m);
return;
} else {
log.debug("returning SV programming reply: {}", m);
int code = ProgListener.OK;
int val;
if (doingWrite) {
val = m.getPeerXfrData()[7];
} else {
val = m.getPeerXfrData()[5];
}
ProgListener temp = p;
p = null;
temp.programmingOpReply(val, code);
}
} else if (getMode().equals(LnProgrammerManager.LOCONETSV2MODE)) {
// need a "Write One Reply", or a "Read One Reply"
if ((m.getElement(3) != 0x41) && (m.getElement(3) != 0x42))
return;
// format 2
if ((m.getElement(4) & 0xFF) != 0x02)
return;
// need SVX1 high nibble = 1
if ((m.getElement(5) & 0x70) != 0x10)
return;
// need SVX2 high nibble = 1
if ((m.getElement(10) & 0x70) != 0x10)
return;
// return reply
if (p == null) {
log.error("received SV reply message with no reply object: {}", m);
return;
} else {
log.debug("returning SV programming reply: {}", m);
int code = ProgListener.OK;
int val = (m.getElement(11) & 0x7F) | (((m.getElement(10) & 0x01) != 0x00) ? 0x80 : 0x00);
ProgListener temp = p;
p = null;
temp.programmingOpReply(val, code);
}
}
}
use of jmri.ProgListener in project JMRI by JMRI.
the class BoosterProgPanel method setStartPushed.
void setStartPushed() {
getProgrammer();
status.setText(rb.getString("StatusProgramming"));
int val = Integer.parseInt(start.getText());
try {
p.writeCV(255, val, new ProgListener() {
@Override
public void programmingOpReply(int value, int retval) {
status.setText(rb.getString("StatusOK"));
}
});
} catch (ProgrammerException e) {
status.setText(rb.getString("StatusError") + e);
} finally {
releaseProgrammer();
}
}
use of jmri.ProgListener in project JMRI by JMRI.
the class BoosterProgPanel method durationPart2.
void durationPart2() {
status.setText(rb.getString("StatusProgramming"));
int val = Integer.parseInt(length.getText()) % 256;
try {
p.writeCV(254, val, new ProgListener() {
@Override
public void programmingOpReply(int value, int retval) {
status.setText(rb.getString("StatusOK"));
}
});
} catch (ProgrammerException e) {
status.setText(rb.getString("StatusError") + e);
} finally {
releaseProgrammer();
}
}
Aggregations