@Override
  public void enterProgrammingMode() throws Exception {

    connection.setSerialPortMode(SerialPortMode.PROGRAM);

    // invoke boot loader
    startBootLoader(bsl);

    // perform mass erase to reset the password to default password
    resetPassword(bsl);

    // read boot loader version
    int bslVersion = readBSLVersion(bsl);
    // check if patch is required
    if (bslVersion <= 0x0110) {
      throw new FlashProgramFailedException(
          "Current BSL version is 1.1 or below, patch is required");
    }

    // change baud rate to 38000
    if (bslVersion >= 0x0160 && !bsl.changeBaudRate(BSLTelosb.BaudRate.Baud38000)) {
      LOG.warn("Could not change the baud rate, keeping initial baud rate of 9600.");
    }
  }
 @Override
 public void leaveProgrammingMode() throws Exception {
   LOG.trace("Leaving programming mode...");
   connection.setSerialPortMode(SerialPortMode.NORMAL);
   LOG.trace("Programming mode left");
 }