Exemple #1
0
 protected synchronized void sendWrite() {
   if (hexFile.getAddress() < 2 * 0x700) {
     //
     if (log.isDebugEnabled()) {
       log.debug("Send write Flash " + hexFile.getAddress());
     }
     msg = SprogMessage.getV4WriteFlash(hexFile.getAddress(), hexFile.getData(), 0);
   } else {
     if (log.isDebugEnabled()) {
       log.debug("null write " + hexFile.getAddress());
     }
     msg = null;
   }
   if (msg != null) {
     bootState = BootState.WRITESENT;
     statusBar.setText("Write " + hexFile.getAddress());
     tc.sendSprogMessage(msg, this);
     if (log.isDebugEnabled()) {
       log.debug("Sent write command to address " + hexFile.getAddress());
     }
     startLongTimer();
   } else {
     // use timeout to kick off the next write
     bootState = BootState.NULLWRITE;
     startVShortTimer();
   }
 }
Exemple #2
0
 protected synchronized void requestBoot() {
   // Look for SPROG in boot mode by sending an extended address command
   // which should be echoed
   if (log.isDebugEnabled()) {
     log.debug("Request bootloader version");
   }
   // allow parsing of bootloader replies
   tc.setSprogState(SprogState.V4BOOTMODE);
   bootState = BootState.VERREQSENT;
   msg = SprogMessage.getv4ExtAddr();
   tc.sendSprogMessage(msg, this);
   startLongTimer();
 }
  public synchronized void saveButtonActionPerformed(java.awt.event.ActionEvent e) {
    SprogMessage saveMsg;
    // Send Current Limit if possible
    state = State.CURRENTSENT;
    if (isCurrentLimitPossible()) {
      validateCurrent();
      // Value written is number of ADC steps 0f 4.88mV across 0.47 ohms
      currentLimit = currentLimit * 470 / 4880;
      if (sv.sprogType.sprogType < SprogType.SPROGIIv3) {
        // Hack for SPROG bug where MSbyte of value must be non-zero
        currentLimit += 256;
      }
      tmpString = String.valueOf(currentLimit);
      saveMsg = new SprogMessage("I " + tmpString);
    } else {
      // Else send blank message to kicj things off
      saveMsg = new SprogMessage(" " + tmpString);
    }
    nextLine("cmd: \"" + saveMsg.toString() + "\"\n", "");
    tc.sendSprogMessage(saveMsg, this);

    // Further messages will be sent from state machine
  }
Exemple #4
0
  protected synchronized void doneWriting() {
    // Finished
    if (log.isDebugEnabled()) {
      log.debug("Done writing");
    }
    statusBar.setText("Write Complete");
    openFileChooserButton.setEnabled(false);
    programButton.setEnabled(false);

    // send end of file record
    if (log.isDebugEnabled()) {
      log.debug("Send end of file ");
    }
    msg = SprogMessage.getV4EndOfFile();
    bootState = BootState.EOFSENT;
    statusBar.setText("Write End Of File");
    tc.sendSprogMessage(msg, this);
    if (log.isDebugEnabled()) {
      log.debug("Sent end of file ");
    }
    startLongTimer();

    // *** Check for reset
  }
  public synchronized void notifyReply(SprogReply l) { // receive a reply message and log it
    SprogMessage msg;
    replyString = l.toString();
    nextLine("rep: \"" + replyString + "\"\n", "");

    // *** Check for error reply
    switch (state) {
      case IDLE:
        if (log.isDebugEnabled()) {
          log.debug("reply in IDLE state: " + replyString);
        }
        break;
      case CURRENTQUERYSENT:
        if (log.isDebugEnabled()) {
          log.debug("reply in CURRENTQUERYSENT state: " + replyString);
        }
        int valueLength = 4;
        if (sv.sprogType.sprogType >= SprogType.SPROGIIv3) {
          valueLength = 6;
        }
        tmpString =
            replyString.substring(
                replyString.indexOf("=") + 1, replyString.indexOf("=") + valueLength);
        if (log.isDebugEnabled()) {
          log.debug("Current limit string: " + tmpString);
        }
        // Value returned is number of ADC steps 0f 4.88mV across 0.47 ohms
        // SPROG 3 is equivalent, using .047R sense with 10x amplifier
        // Convert to milliAmps using integer math
        try {
          currentLimit = (Integer.parseInt(tmpString) * 4880) / 470;
        } catch (NumberFormatException e) {
          JOptionPane.showMessageDialog(
              null,
              "Malformed Reply for current limit",
              "SPROG Console",
              JOptionPane.ERROR_MESSAGE);
          state = State.IDLE;
          return;
        }
        if (log.isDebugEnabled()) {
          log.debug("Current limit value: " + currentLimit);
        }
        currentTextField.setText(String.valueOf(currentLimit));
        currentTextField.setEnabled(true);
        // Next get the mode word
        // Only get this if we have zero active slots in slot manager
        // in command mode
        if (sm.getInUseCount() == 0) {
          state = State.MODEQUERYSENT;
          msg = new SprogMessage(1);
          msg.setOpCode('M');
          nextLine("cmd: \"" + msg + "\"\n", "");
          tc.sendSprogMessage(msg, this);
        } else {
          state = State.IDLE;
        }
        break;
      case MODEQUERYSENT:
        if (log.isDebugEnabled()) {
          log.debug("reply in MODEQUERYSENT state: " + replyString);
        }
        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:
        if (log.isDebugEnabled()) {
          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() + "\"\n", "");
        tc.sendSprogMessage(msg, this);
        break;
      case MODESENT:
        if (log.isDebugEnabled()) {
          log.debug("reply in MODESENT state: " + replyString);
        }
        // Write to EEPROM
        state = State.WRITESENT;
        msg = new SprogMessage("W");
        nextLine("cmd: \"" + msg.toString() + "\"\n", "");
        tc.sendSprogMessage(msg, this);
        break;
      case WRITESENT:
        if (log.isDebugEnabled()) {
          log.debug("reply in WRITESENT state: " + replyString);
        }
        // All done
        state = State.IDLE;
    }
  }
 public synchronized void notifyMessage(SprogMessage l) { // receive a message and log it
   nextLine("cmd: \"" + l.toString() + "\"\n", "");
 }
  public synchronized void notifyVersion(SprogVersion v) {
    sv = 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) {
        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() && sm.getInUseCount() == 0) {
        state = State.CURRENTQUERYSENT;
        msg = new SprogMessage(1);
        msg.setOpCode('I');
        nextLine("cmd: \"" + msg + "\"\n", "");
        tc.sendSprogMessage(msg, this);
      } else {
        // Set default and get the mode word
        currentLimit = (SprogConstants.DEFAULT_I * 4880) / 470;
        currentTextField.setText(String.valueOf(SprogConstants.DEFAULT_I));

        // Only send this if we have zero active slots in slot manager
        // in command mode
        if (sm.getInUseCount() == 0) {
          state = State.MODEQUERYSENT;
          msg = new SprogMessage(1);
          msg.setOpCode('M');
          nextLine("cmd: \"" + msg + "\"\n", "");
          tc.sendSprogMessage(msg, this);
        } else {
          state = State.IDLE;
        }
      }
    }
  }
 public void sendButtonActionPerformed(java.awt.event.ActionEvent e) {
   SprogMessage m = new SprogMessage(cmdTextField.getText());
   // Messages sent by us will not be forwarded back so add to display manually
   nextLine("cmd: \"" + m.toString() + "\"\n", "");
   SprogTrafficController.instance().sendSprogMessage(m, this);
 }