package awa.imu; import java.io.*; import java.util.StringTokenizer; /** * @author awa * */ public class LogFileReader extends Thread { private IMUControlPanel parent; private File file; private boolean stop = false; public LogFileReader(IMUControlPanel panel, File file) { parent = panel; this.file = file; } public void run() { try { System.out.print("Trying to open " + file.getName() + "..."); BufferedReader in = new BufferedReader(new FileReader(file)); String line; while (!stop && (line = in.readLine()) != null) { if (line.startsWith("$IMADC")) { //System.out.println("read: " + line); StringTokenizer st = new StringTokenizer(line, ",*"); if (st.countTokens() >= 8) { String sname = st.nextToken(); String time = st.nextToken(); String pitch = st.nextToken(); String roll = st.nextToken(); String yaw = st.nextToken(); String accy = st.nextToken(); String accx = st.nextToken(); String accz = st.nextToken(); parent.setIMUValues(pitch, roll, yaw, accy, accx, accz); } Thread.sleep(11); } } System.out.println("closing the file..."); in.close(); } catch (Exception e) { System.err.println("Exception " + e); e.printStackTrace(); // make sure the application exits with an error condition. } } public void stopPlay() { stop = true; } }