Example #1
0
  @Override
  public void run() {
    running = true;
    done = false;
    Log.println("WAV Source START");
    if (audioStream == null)
      try {
        initWav();
      } catch (UnsupportedAudioFileException e1) {
        Log.errorDialog("ERROR", "Unsupported File Format\n" + e1.getMessage());
        e1.printStackTrace(Log.getWriter());
        running = false;
      } catch (IOException e1) {
        Log.errorDialog("ERROR", "There was a problem opening the wav file\n" + e1.getMessage());
        e1.printStackTrace(Log.getWriter());
        running = false;
      }

    while (running) {
      //			Log.println("wav running");
      if (audioStream != null) {
        int nBytesRead = 0;
        if (circularBuffer.getCapacity() > readBuffer.length) {
          try {
            nBytesRead = audioStream.read(readBuffer, 0, readBuffer.length);
            bytesRead = bytesRead + nBytesRead;
            framesProcessed = framesProcessed + nBytesRead / frameSize;
            // Check we have not stopped mid read
            if (audioStream == null) running = false;
            else if (!(audioStream.available() > 0)) running = false;
          } catch (IOException e) {
            Log.errorDialog("ERROR", "Failed to read from file " + fileName);
            e.printStackTrace(Log.getWriter());
          }
        } else {
          try {
            Thread.sleep(1);
          } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
          // Log.println("No room in Buffer");
        }
        for (int i = 0; i < nBytesRead; i += 2) {
          // circularBuffer.add(readBuffer[i]);
          circularBuffer.add(readBuffer[i], readBuffer[i + 1]);
        }
      }
    }
    framesProcessed = totalFrames;
    cleanup(); // This might cause the decoder to miss the end of a file (testing inconclusive) but
               // it also ensure the file is close and stops an error if run again very quickly
    running = false;
    try {
      Thread.sleep(100);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    Log.println("WAV Source EXIT");
  }
Example #2
0
  @Override
  public void actionPerformed(ActionEvent e) {
    boolean refreshTabs = false;
    if (e.getSource() == btnGetT0) {
      MainWindow.updateManager.updateT0(sat);
      updateTimeSeries();
    }
    if (e.getSource() == btnCancel) {
      this.dispose();
    }
    if (e.getSource() == btnSave) {
      try {
        try {
          sat.telemetryDownlinkFreqkHz = Integer.parseInt(telemetryDownlinkFreqkHz.getText());
          sat.minFreqBoundkHz = Integer.parseInt(minFreqBoundkHz.getText());
          sat.maxFreqBoundkHz = Integer.parseInt(maxFreqBoundkHz.getText());
        } catch (NumberFormatException ex) {
          throw new Exception("The Frequency fields must contain a valid number");
        }
        if (sat.rssiLookUpTableFileName != rssiLookUpTableFileName.getText()) {
          sat.rssiLookUpTableFileName = rssiLookUpTableFileName.getText();
          refreshTabs = true;
        }
        if (sat.ihuTempLookUpTableFileName != ihuTempLookUpTableFileName.getText()) {
          sat.ihuTempLookUpTableFileName = ihuTempLookUpTableFileName.getText();
          refreshTabs = true;
        }
        if (sat.ihuVBattLookUpTableFileName != ihuVBattLookUpTableFileName.getText()) {
          sat.ihuVBattLookUpTableFileName = ihuVBattLookUpTableFileName.getText();
          refreshTabs = true;
        }

        if (sat.BATTERY_CURRENT_ZERO != Double.parseDouble(BATTERY_CURRENT_ZERO.getText())) {
          sat.BATTERY_CURRENT_ZERO = Double.parseDouble(BATTERY_CURRENT_ZERO.getText());
          refreshTabs = true;
        }

        if (sat.useIHUVBatt != useIHUVBatt.isSelected()) {
          sat.useIHUVBatt = useIHUVBatt.isSelected();
          refreshTabs = true;
        }
        sat.track = track.isSelected();

        if (refreshTabs) MainWindow.refreshTabs(false);
        sat.save();
        this.dispose();
      } catch (Exception Ex) {
        Log.errorDialog("Invalid Paramaters", Ex.getMessage());
      }
    }
  }
  /**
   * Load a file from disk
   *
   * @param log
   * @throws FileNotFoundException
   */
  public void load(String log) throws FileNotFoundException {
    String line;
    if (!Config.logFileDirectory.equalsIgnoreCase("")) {
      log = Config.logFileDirectory + File.separator + log;
      Log.println("Loading: " + log);
    }
    File aFile = new File(log);
    if (!aFile.exists()) {
      try {
        aFile.createNewFile();
      } catch (IOException e) {
        JOptionPane.showMessageDialog(
            MainWindow.frame,
            e.toString(),
            "ERROR creating file " + log,
            JOptionPane.ERROR_MESSAGE);
        e.printStackTrace(Log.getWriter());
      }
    }

    BufferedReader dis = new BufferedReader(new FileReader(log));

    try {
      while ((line = dis.readLine()) != null) {
        if (line != null) {
          StringTokenizer st = new StringTokenizer(line, ",");
          String date = st.nextToken();
          int id = Integer.valueOf(st.nextToken()).intValue();
          int reset = Integer.valueOf(st.nextToken()).intValue();
          long uptime = Long.valueOf(st.nextToken()).longValue();
          int type = Integer.valueOf(st.nextToken()).intValue();

          // We should never get this situation, but good to check..
          if (Config.satManager.getSpacecraft(id) == null) {
            Log.errorDialog(
                "FATAL",
                "Attempting to Load payloads from the Payload store for satellite with Fox Id: "
                    + id
                    + "\n when no sattellite with that FoxId is configured.  Add this spacecraft to the satellite directory and restart FoxTelem."
                    + "\nProgram will now exit");
            System.exit(1);
          }
          if (type == RT_MEASUREMENT_TYPE) {
            RtMeasurement rt = new RtMeasurement(id, date, reset, uptime, type, st);
            rtRecords.add(rt);
            updatedRt = true;
          }
          if (type == PASS_MEASUREMENT_TYPE) {
            PassMeasurement rt = new PassMeasurement(id, date, reset, uptime, type, st);
            passRecords.add(rt);
            updatedPass = true;
          }
        }
      }
    } catch (IOException e) {
      e.printStackTrace(Log.getWriter());

    } catch (NumberFormatException n) {
      n.printStackTrace(Log.getWriter());
    } finally {
      try {
        dis.close();
      } catch (IOException e) {
        e.printStackTrace(Log.getWriter());
      }
    }
  }