use of jmri.jmrix.sprog.SprogMessage in project JMRI by JMRI.
the class SprogConsoleFrame method notifyVersion.
@Override
public synchronized void notifyVersion(SprogVersion v) {
sv = v;
// Save it for others
_memo.setSprogVersion(v);
if (log.isDebugEnabled()) {
log.debug("Found: " + sv.toString());
}
if (sv.sprogType.isSprog() == false) {
// Didn't recognize a SPROG so check if it is in boot mode already
JOptionPane.showMessageDialog(null, "SPROG prompt not found", "SPROG Console", JOptionPane.ERROR_MESSAGE);
} else {
if ((sv.sprogType.sprogType > SprogType.SPROGIIv3) && (sv.sprogType.sprogType < SprogType.NANO)) {
currentTextField.setToolTipText("Enter new current limit in milliAmps (less than 2500)");
}
// We know what we're connected to
setTitle(title() + " - Connected to " + sv.toString());
// Enable blueline & firmware unlock check boxes
if (isBlueLineSupportPossible()) {
if (log.isDebugEnabled()) {
log.debug("Enable blueline check box");
}
blueCheckBox.setEnabled(true);
if (log.isDebugEnabled()) {
log.debug(Boolean.toString(blueCheckBox.isEnabled()));
}
}
if (isFirmwareUnlockPossible()) {
if (log.isDebugEnabled()) {
log.debug("Enable firmware check box");
}
unlockCheckBox.setEnabled(true);
if (log.isDebugEnabled()) {
log.debug(Boolean.toString(unlockCheckBox.isEnabled()));
}
}
ztcCheckBox.setEnabled(isZTCModePossible());
// Get Current Limit if available
if (isCurrentLimitPossible()) {
state = State.CURRENTQUERYSENT;
msg = new SprogMessage(1);
msg.setOpCode('I');
nextLine("cmd: \"" + msg + "\"\n", "");
tc.sendSprogMessage(msg, this);
startTimer();
} else {
// Set default and get the mode word
currentLimit = (int) (SprogConstants.DEFAULT_I * sv.sprogType.getCurrentMultiplier());
currentTextField.setText(String.valueOf(SprogConstants.DEFAULT_I));
state = State.MODEQUERYSENT;
msg = new SprogMessage(1);
msg.setOpCode('M');
nextLine("cmd: \"" + msg + "\"\n", "");
tc.sendSprogMessage(msg, this);
startTimer();
}
}
}
use of jmri.jmrix.sprog.SprogMessage in project JMRI by JMRI.
the class SprogConsoleFrame method saveButtonActionPerformed.
public synchronized void saveButtonActionPerformed(java.awt.event.ActionEvent e) {
SprogMessage saveMsg;
int currentLimitForHardware;
// Send Current Limit if possible
state = State.CURRENTSENT;
if (isCurrentLimitPossible()) {
validateCurrent();
// Value written is scaled from mA to hardware units
currentLimitForHardware = (int) (currentLimit * (1 / sv.sprogType.getCurrentMultiplier()));
if (sv.sprogType.sprogType < SprogType.SPROGIIv3) {
// Hack for SPROG bug where MSbyte of value must be non-zero
currentLimitForHardware += 256;
}
tmpString = String.valueOf(currentLimitForHardware);
saveMsg = new SprogMessage("I " + tmpString);
} else {
// Else send blank message to kick things off
saveMsg = new SprogMessage(" " + tmpString);
}
nextLine("cmd: \"" + saveMsg.toString(_memo.getSprogTrafficController().isSIIBootMode()) + "\"\n", "");
tc.sendSprogMessage(saveMsg, this);
// Further messages will be sent from state machine
}
use of jmri.jmrix.sprog.SprogMessage in project JMRI by JMRI.
the class SprogConsoleFrame method notifyReply.
@Override
public synchronized void notifyReply(SprogReply l) {
// receive a reply message and log it
SprogMessage msg;
int currentLimitFromHardware;
replyString = l.toString();
nextLine("rep: \"" + replyString + "\"\n", "");
// *** Check for error reply
switch(state) {
case IDLE:
log.debug("reply in IDLE state: " + replyString);
break;
case CURRENTQUERYSENT:
// Look for an "I=" reply
log.debug("reply in CURRENTQUERYSENT state: " + replyString);
if (replyString.contains("I=")) {
stopTimer();
int valueLength = 4;
if (sv.sprogType.sprogType >= SprogType.SPROGIIv3) {
valueLength = 6;
}
tmpString = replyString.substring(replyString.indexOf("=") + 1, replyString.indexOf("=") + valueLength);
log.debug("Current limit string: " + tmpString);
try {
currentLimitFromHardware = Integer.parseInt(tmpString);
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "Malformed Reply for current limit", "SPROG Console", JOptionPane.ERROR_MESSAGE);
state = State.IDLE;
return;
}
// Value written is scaled from hardware units to mA
currentLimit = (int) (currentLimitFromHardware * sv.sprogType.getCurrentMultiplier());
log.debug("Current limit scale factor: " + sv.sprogType.getCurrentMultiplier());
log.debug("Current limit from hardware: " + currentLimitFromHardware + " scaled to: " + currentLimit + "mA");
currentTextField.setText(String.valueOf(currentLimit));
currentTextField.setEnabled(true);
// Next get the mode word
state = State.MODEQUERYSENT;
msg = new SprogMessage(1);
msg.setOpCode('M');
nextLine("cmd: \"" + msg + "\"\n", "");
tc.sendSprogMessage(msg, this);
startTimer();
}
break;
case MODEQUERYSENT:
log.debug("reply in MODEQUERYSENT state: " + replyString);
if (replyString.contains("M=")) {
stopTimer();
tmpString = replyString.substring(replyString.indexOf("=") + 2, replyString.indexOf("=") + 6);
// Value returned is in hex
try {
modeWord = Integer.parseInt(tmpString, 16);
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "Malformed Reply for mode word", "SPROG Console", JOptionPane.ERROR_MESSAGE);
state = State.IDLE;
return;
}
state = State.IDLE;
// Set Speed step radio buttons, etc., according to mode word
if ((modeWord & SprogConstants.STEP14_BIT) != 0) {
speed14Button.setSelected(true);
} else if ((modeWord & SprogConstants.STEP28_BIT) != 0) {
speed28Button.setSelected(true);
} else {
speed128Button.setSelected(true);
}
if ((modeWord & SprogConstants.ZTC_BIT) != 0) {
ztcCheckBox.setSelected(true);
}
if ((modeWord & SprogConstants.BLUE_BIT) != 0) {
blueCheckBox.setSelected(true);
}
}
break;
case CURRENTSENT:
// Any reply will do here
log.debug("reply in CURRENTSENT state: " + replyString);
// Get new mode word - assume 128 steps
modeWord = SprogConstants.STEP128_BIT;
if (speed14Button.isSelected()) {
modeWord = modeWord & ~SprogConstants.STEP_MASK | SprogConstants.STEP14_BIT;
} else if (speed28Button.isSelected()) {
modeWord = modeWord & ~SprogConstants.STEP_MASK | SprogConstants.STEP28_BIT;
}
// ZTC mode
if (ztcCheckBox.isSelected() == true) {
modeWord = modeWord | SprogConstants.ZTC_BIT;
}
// Blueline mode
if (blueCheckBox.isSelected() == true) {
modeWord = modeWord | SprogConstants.BLUE_BIT;
}
// firmware unlock
if (unlockCheckBox.isSelected() == true) {
modeWord = modeWord | SprogConstants.UNLOCK_BIT;
}
// Send new mode word
state = State.MODESENT;
msg = new SprogMessage("M " + modeWord);
nextLine("cmd: \"" + msg.toString(_memo.getSprogTrafficController().isSIIBootMode()) + "\"\n", "");
tc.sendSprogMessage(msg, this);
break;
case MODESENT:
// Any reply will do here
log.debug("reply in MODESENT state: " + replyString);
// Write to EEPROM
state = State.WRITESENT;
msg = new SprogMessage("W");
nextLine("cmd: \"" + msg.toString(_memo.getSprogTrafficController().isSIIBootMode()) + "\"\n", "");
tc.sendSprogMessage(msg, this);
break;
case WRITESENT:
// Any reply will do here
log.debug("reply in WRITESENT state: " + replyString);
// All done
state = State.IDLE;
break;
default:
log.warn("Unhandled state: {}", state);
break;
}
}
use of jmri.jmrix.sprog.SprogMessage in project JMRI by JMRI.
the class SprogIIUpdateFrame method notifyVersion.
@SuppressFBWarnings(value = "SWL_SLEEP_WITH_LOCK_HELD")
@Override
public synchronized void notifyVersion(SprogVersion v) {
sv = v;
if (sv.sprogType.isSprog() == false) {
// Didn't recognize a SPROG so check if it is in boot mode already
if (log.isDebugEnabled()) {
log.debug("SPROG not found - looking for bootloader");
}
statusBar.setText("SPROG not found - looking for bootloader");
blockLen = -1;
requestBoot();
} else {
// Check that it's not a V4
if (sv.sprogType.sprogType > SprogType.SPROGV4) {
statusBar.setText("Found " + sv.toString());
blockLen = sv.sprogType.getBlockLen();
// Put SPROG in boot mode
if (log.isDebugEnabled()) {
log.debug("Putting SPROG in boot mode");
}
msg = new SprogMessage("b 1 1 1");
tc.sendSprogMessage(msg, this);
// SPROG II and 3 will not reply to this so just wait a while
tc.setSprogState(SprogState.SIIBOOTMODE);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
// retain if needed later
Thread.currentThread().interrupt();
}
// Look for bootloader version
requestBoot();
} else {
log.error("Incorrect SPROG Type detected");
statusBar.setText("Incorrect SPROG Type detected");
bootState = BootState.IDLE;
}
}
}
use of jmri.jmrix.sprog.SprogMessage in project JMRI by JMRI.
the class Sprogv4UpdateFrame method notifyVersion.
@Override
public synchronized void notifyVersion(SprogVersion v) {
sv = v;
if (sv.sprogType.isSprog() == false) {
// Didn't recognize a SPROG so check if it is in boot mode already
if (log.isDebugEnabled()) {
log.debug("SPROG not found - looking for bootloader");
}
statusBar.setText("SPROG not found - looking for bootloader");
requestBoot();
} else {
// Check that it's a V4
if (sv.sprogType.sprogType == SprogType.SPROGV4) {
statusBar.setText("Found " + sv.toString());
// Put SPROG in boot mode
if (log.isDebugEnabled()) {
log.debug("Putting SPROG in boot mode");
}
msg = new SprogMessage("b 1 1 1");
tc.sendSprogMessage(msg, this);
// SPROG v4 will reply
bootState = BootState.SETBOOTSENT;
} else {
log.error("Incorrect SPROG Type detected");
statusBar.setText("Incorrect SPROG Type deteceted");
bootState = BootState.IDLE;
}
}
}
Aggregations