Skip to content
Permalink
Browse files

Fixes for SPROG Bootloader

  • Loading branch information...
crosland
crosland committed Apr 18, 2019
1 parent d4988b2 commit 8048e05e3373833eb62f33a56c7ce64b88ca977d
@@ -7,15 +7,14 @@ SprogXFirmwareUpdate = SPROGII/SPROG 3/Pi-SPROG Firmware Update
SprogConsoleTitle = SPROG Console
SprogProgrammerTitle = SPROG Programmer
SprogSimulatorTitle = SPROG Sim
SprogBootloaderXTitle = SPROG{0} Bootloader
SprogBootloaderv4Title = SPROG v4 Bootloader
SprogVersionTitle = SPROG Version
SprogVersionDialogString = SPROG version: {0}
CommandHistoryTitle = Command History

# update messages
IoErrorReadingHexFile = I/O Error reading hex file!
InvalidHexDigitAtLine = Invalid hex digit at line {0}
SprogXUpdateDialogString = In order to proceed with a SPROG{0} firmware update\nyou must have a valid .hex firmware update file.\nAre you certain you want to update the SPROG II firmware?
SprogXUpdateDialogString = In order to proceed with a SPROG firmware update\nyou must have a valid .hex firmware update file and unlock the firmware.\nAre you certain you want to proceed?
StatusFoundX = Found {0}
StatusSprogNotFound = SPROG not found - looking for bootloader
StatusIncorrectSprogType = Incorrect SPROG Type detected
@@ -34,6 +33,7 @@ HexFileSelectTitle = Hex File Select
HexFileSelectDialogString = File does not appear to be a valid SPROG II hex file.
CurrentLimitDialogString = Invalid Current Limit entered.\nPlease enter a value in the range {0}
FatalErrorTitle = Fatal Error
ErrorFirmwareLocked = You must first unlock the firmware
ErrorConnectingDialogString = Unable to connect to bootloader.
ErrorConnectingStatus=Fatal error - unable to connect
ErrorTimeoutDialogString = Timeout during write to SPROG.
@@ -7,15 +7,14 @@ SprogXFirmwareUpdate = M\u00e0J Firmware SPROGII/SPROG 3/Pi-SPROG
SprogConsoleTitle = Console SPROG
SprogProgrammerTitle = Programmeur SPROG
SprogSimulatorTitle = Simulateur SPROG
SprogBootloaderXTitle = Bootloader SPROG{0}
SprogBootloaderv4Title = Bootloader SPROG v4
SprogVersionTitle = Version SPROG
SprogVersionDialogString = Version SPROG: {0}
CommandHistoryTitle = Historique Commandes

# update messages
IoErrorReadingHexFile = Erreur E/S lors lecture fichier hex!
InvalidHexDigitAtLine = Nombre hex invalide en ligne {0}
SprogXUpdateDialogString = Pour proc\u00e9der \u00e0 une mise \u00e0 jour du firmware SPROG{0}\nvous devez avoir un fichier de mise \u00e0 jour .hex valide.\n\u00cates-vous certain de vouloir mettre \u00e0 jour le firmware SPROG II?
SprogXUpdateDialogString = Pour proc\u00e9der \u00e0 une mise \u00e0 jour du firmware SPROG\nvous devez avoir un fichier de mise \u00e0 jour .hex valide.\n\u00cates-vous certain de vouloir mettre \u00e0 jour le firmware SPROG?
StatusFoundX = Trouv\u00e9 {0}
StatusSprogNotFound = SPROG pas trouv\u00e9 - recherche du bootloader
StatusIncorrectSprogType = Type SPROG incorrect d\u00e9tect\u00e9
@@ -34,6 +33,7 @@ HexFileSelectTitle = Fichier Hex S\u00e9lectionn\u00e9
HexFileSelectDialogString = Le fichier ne semble pas \u00eatre un fichier hex SPROG valide.
CurrentLimitDialogString = Limite de Courant Invalide saisie.\nSVP entrer une valeur dans l''intervalle {0}
FatalErrorTitle = Erreur Fatale
ErrorFirmwareLocked = Vous devez d'abord d\u00e9verrouiller le firmware
ErrorConnectingDialogString = Impossible de se connecter au bootloader.
ErrorConnectingStatus = Erreur Fatale - impossible de se connecter
ErrorTimeoutDialogString = Tempo expir\u00e9e pendant l'\u00e9criture vers SPROG.
@@ -8,15 +8,14 @@ SprogXFirmwareUpdate=SPROG II/SPROG 3/Pi-SPROG firmware bijwerken
SprogConsoleTitle = SPROG Console
SprogProgrammerTitle = SPROG Programmeerunit
SprogSimulatorTitle = SPROG Sim
SprogBootloaderXTitle=SPROG{0} Bootloader
SprogBootloaderv4Title=SPROG v4 Bootloader
SprogVersionTitle = SPROG Versie
SprogVersionDialogString = SPROG versie: {0}
CommandHistoryTitle = Commando-geschiedenis

# update messages
IoErrorReadingHexFile = I/O Fout bij lezen van hex bestand!
InvalidHexDigitAtLine=Ongeldige hex digit in regel {0}
SprogXUpdateDialogString = Om verder te gaan met de SPROG{0} firmware update\nmoet een geldig .hex firmware update-bestand op schijf staan.\nVerder gaan met bijwerken van de SPROG II firmware?
SprogXUpdateDialogString = Om verder te gaan met de SPROG firmware update\nmoet een geldig .hex firmware update-bestand op schijf staan.\nVerder gaan met bijwerken van de SPROG firmware?
StatusFoundX = {0} gevonden
StatusSprogNotFound = SPROG niet gevonden - zoeken naar bootloader
StatusIncorrectSprogType = Fout Type SPROG gedecteerd
@@ -35,6 +34,7 @@ HexFileSelectTitle = Kies Hex bestand
HexFileSelectDialogString = Bestand lijkt geen geldig SPROG II hex bestand.
CurrentLimitDialogString = Ongeldige waarde voor Maximum baanstroom ingevuld.\nVul een waarde in in bereik {0}
FatalErrorTitle = Fatale fout
ErrorFirmwareLocked = U moet eerst de firmware ontgrendelen
ErrorConnectingDialogString = Kan geen verbinding maken met bootloader.
ErrorConnectingStatus=Fout - kan niet verbinden
ErrorTimeoutDialogString = Timeout tijdens schrijven naar SPROG.
@@ -293,21 +293,6 @@ public void run() {
}
replyAvailable = false;
sendToInterface(messageToSend.message);
log.debug("Waiting for a reply");
try {
synchronized (lock) {
lock.wait(timeout); // Wait for notify
}
} catch (InterruptedException e) {
log.debug("waitingForReply interrupted");
return;
}
if (!replyAvailable) {
// Timed out
log.warn("Timeout waiting for reply from hardware");
} else {
log.debug("Notified of reply");
}
}
}

@@ -21,8 +21,8 @@ public SprogIIUpdateAction(String s,SprogSystemConnectionMemo memo) {
public void actionPerformed(ActionEvent e) {
Object[] options = {Bundle.getMessage("ButtonCancel"), Bundle.getMessage("ButtonContinue")};
if (1 == JOptionPane.showOptionDialog(null,
Bundle.getMessage("SprogXUpdateDialogString", " II"),
Bundle.getMessage("SprogXFirmwareUpdate", " II"), JOptionPane.YES_NO_OPTION,
Bundle.getMessage("SprogXUpdateDialogString"),
Bundle.getMessage("SprogXFirmwareUpdate"), JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE, null, options, options[0])) {
// create a SprogIIUpdateFrame
SprogIIUpdateFrame f = new SprogIIUpdateFrame(_memo);
@@ -1,5 +1,7 @@
package jmri.jmrix.sprog.update;

import static jmri.jmrix.sprog.SprogConstants.TC_BOOT_REPLY_TIMEOUT;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import javax.swing.JOptionPane;
import jmri.jmrix.sprog.SprogConstants.SprogState;
@@ -33,6 +35,9 @@ public void initComponents() {
// add help menu to window
addHelpMenu("package.jmri.jmrix.sprog.update.SprogIIUpdateFrame", true);

// Set a shorter timeout in the TC. Must be shorter than SprogUpdateFrame long timeout
tc.setTimeout(TC_BOOT_REPLY_TIMEOUT);

// Get the SPROG version
_memo.getSprogVersionQuery().requestVersion(this);
}
@@ -65,16 +70,12 @@ synchronized public void notifyVersion(SprogVersion v) {
log.debug("Putting SPROG in boot mode");
}
msg = new SprogMessage("b 1 1 1");
bootState = BootState.SETBOOTSENT;
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) {
Thread.currentThread().interrupt(); // retain if needed later
}
// Look for bootloader version
requestBoot();
// SPROG II and 3 will not reply to this if successfull. Will
// reply with error if firmware is locked. Wait a while to allow
// Traffic Controller to time out
startLongTimer();
} else {
log.error("Incorrect SPROG Type detected");
statusBar.setText(Bundle.getMessage("StatusIncorrectSprogType"));
@@ -104,6 +105,18 @@ synchronized protected void frameCheck() {
}
}

@Override
synchronized protected void stateSetBootSent() {
stopTimer();
log.debug("reply in SETBOOTSENT state");
// A reply to the enter bootloader command means the firmware is locked.
bootState = BootState.IDLE;
tc.setSprogState(SprogState.NORMAL);
JOptionPane.showMessageDialog(this, Bundle.getMessage("ErrorFirmwareLocked"),
Bundle.getMessage("SprogXFirmwareUpdate"), JOptionPane.ERROR_MESSAGE);
statusBar.setText(Bundle.getMessage("ErrorFirmwareLocked"));
}

@Override
synchronized protected void stateBootVerReqSent() {
stopTimer();
@@ -143,7 +156,7 @@ synchronized protected void stateBootVerReqSent() {
bootState = BootState.IDLE;
tc.setSprogState(SprogState.NORMAL);
JOptionPane.showMessageDialog(this, Bundle.getMessage("StatusUnableToConnectBootloader"),
Bundle.getMessage("SprogXFirmwareUpdate", " II"), JOptionPane.ERROR_MESSAGE);
Bundle.getMessage("SprogXFirmwareUpdate"), JOptionPane.ERROR_MESSAGE);
statusBar.setText(Bundle.getMessage("StatusUnableToConnectBootloader"));
}
}
@@ -365,6 +378,8 @@ synchronized public void setSprogModeButtonActionPerformed(java.awt.event.Action
}
msg = SprogMessage.getWriteEE(0xff, new int[]{0});
bootState = BootState.SPROGMODESENT;
// Set TC timeout back to normal
tc.resetTimeout();
tc.sendSprogMessage(msg, this);
startLongTimer();
}
@@ -82,7 +82,7 @@ public SprogUpdateFrame(SprogSystemConnectionMemo memo) {
}

protected String title() {
return Bundle.getMessage("SprogXFirmwareUpdate", "");
return Bundle.getMessage("SprogXFirmwareUpdate");
}

protected void init() {
@@ -306,13 +306,13 @@ public void setSprogModeButtonActionPerformed(java.awt.event.ActionEvent e) {
* Internal routine to handle a timeout.
*/
synchronized protected void timeout() {
if (bootState == BootState.CRSENT) {
if (log.isDebugEnabled()) {
log.debug("timeout in CRSENT - assuming boot mode");
// we were looking for a SPROG in normal mode but have had no reply
// so maybe it was already in boot mode.
// Try looking for bootloader
}
if ((bootState == BootState.CRSENT) || (bootState == BootState.SETBOOTSENT)) {
log.debug("timeout in CRSENT - assuming boot mode");
// Either:
// 1) We were looking for a SPROG in normal mode but have had no reply
// so maybe it was already in boot mode.
// 2) We sent the b command and had an extected timeout
// In both cases, try looking for bootloader version
requestBoot();
} else if (bootState == BootState.VERREQSENT) {
log.error("timeout in VERREQSENT!");
@@ -1,5 +1,7 @@
package jmri.jmrix.sprog.update;

import static jmri.jmrix.sprog.SprogConstants.TC_BOOT_REPLY_TIMEOUT;

import java.util.Vector;
import jmri.jmrix.sprog.SprogListener;
import jmri.jmrix.sprog.SprogMessage;
@@ -99,6 +101,8 @@ synchronized public void requestVersion(SprogVersionListener l) {
// Kick things off with a blank message
m = new SprogMessage(1);
m.setOpCode(' ');
// Set a short timeout for the traffic controller
tc.setTimeout(TC_BOOT_REPLY_TIMEOUT);
tc.sendSprogMessage(m, this);
state = QueryState.CRSENT;
startLongTimer();
@@ -245,6 +249,7 @@ synchronized public void notifyReply(SprogReply m) {
}

case DONE:
tc.resetTimeout();
break;

default: {
@@ -279,6 +284,7 @@ synchronized protected void timeout() {
log.warn("Unhandled timeout state code: {}", state);
break;
}
tc.resetTimeout();
}

/**
@@ -24,8 +24,8 @@ public Sprogv4UpdateAction(String s,SprogSystemConnectionMemo memo) {
public void actionPerformed(ActionEvent e) {
Object[] options = {Bundle.getMessage("ButtonCancel"), Bundle.getMessage("ButtonContinue")};
if (1 == JOptionPane.showOptionDialog(null,
Bundle.getMessage("SprogXUpdateDialogString", ""),
Bundle.getMessage("SprogXFirmwareUpdate", " v3/v4"), JOptionPane.YES_NO_OPTION,
Bundle.getMessage("SprogXUpdateDialogString"),
Bundle.getMessage("SprogXFirmwareUpdate"), JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE, null, options, options[0])) {
// create a SprogIIUpdateFrame
// create a SprogUpdateFrame
@@ -89,7 +89,7 @@ synchronized protected void stateSetBootSent() {
// We remain in this state until program button is pushed
} else {
JOptionPane.showMessageDialog(null, Bundle.getMessage("StatusBadBootloaderReply"),
Bundle.getMessage("SprogBootloaderXTitle", " v4"), JOptionPane.ERROR_MESSAGE);
Bundle.getMessage("SprogBootloaderv4Title"), JOptionPane.ERROR_MESSAGE);
log.error("Bad reply to SETBOOT request");
bootState = BootState.IDLE;
tc.setSprogState(SprogState.NORMAL);

0 comments on commit 8048e05

Please sign in to comment.
You can’t perform that action at this time.