Esempio n. 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");
  }
Esempio n. 2
0
 public void cleanup() {
   try {
     if (audioStream != null) audioStream.close();
     audioStream =
         null; // This will prevent us from trying one last read from the file and generating an
               // exception
   } catch (IOException e) {
     e.printStackTrace(Log.getWriter());
   }
   // Give the decoder time to finish - not sure this makes any difference though??
   if (circularBuffer.size() > 0) {
     try {
       Thread.sleep(100);
     } catch (InterruptedException e) {
       e.printStackTrace(Log.getWriter());
     }
   }
   done = true;
 }
Esempio n. 3
0
 /**
  * Add a measurement set to this Sats store
  *
  * @param id
  * @param m
  * @return
  * @throws IOException
  */
 public boolean add(int id, Measurement m) throws IOException {
   if (m instanceof RtMeasurement) {
     try {
       save(m, rtFileName);
     } catch (IOException e) {
       // NEED TO SET A FLAG HERE THAT IS THEN SEEN BY THE GUI WHEN IT POLLS FOR RESULTS
       e.printStackTrace(Log.getWriter());
     }
     rtRecords.add(m);
     updatedRt = true;
     return true;
   } else if (m instanceof PassMeasurement) {
     try {
       save(m, passFileName);
     } catch (IOException e) {
       // NEED TO SET A FLAG HERE THAT IS THEN SEEN BY THE GUI WHEN IT POLLS FOR RESULTS
       e.printStackTrace(Log.getWriter());
     }
     passRecords.add(m);
     updatedPass = true;
     return true;
   }
   return false;
 }
Esempio n. 4
0
  /**
   * Create the payload store this this fox id
   *
   * @param id
   */
  public SatMeasurementStore(int id) {
    foxId = id;
    initArrays();

    try {
      rtFileName = "Fox" + id + RT_LOG;
      passFileName = "Fox" + id + PASS_LOG;
      load(rtFileName);
      load(passFileName);
    } catch (FileNotFoundException e) {
      JOptionPane.showMessageDialog(
          MainWindow.frame,
          e.toString(),
          "ERROR Loading Stored Payload data",
          JOptionPane.ERROR_MESSAGE);
      e.printStackTrace(Log.getWriter());
    }
  }
Esempio n. 5
0
  /**
   * 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());
      }
    }
  }