JAVA - Retrieve NMEA frame from a GPS Receptor -More details about RandomAccessFile WriteBytes method

107 Views Asked by At

I have a GPS receptor. I retrieve all the NMEA frames captured by this one in the Eclipse console.

EDIT - This is my full class :

public class GPSFrame extends Observable implements Runnable
{
    static Thread myThread=null;
    static BufferedReader br;
    static BufferedWriter wr;
    static PrintWriter out;
    static InputStreamReader isr;
    static OutputStreamWriter osw;
    static java.io.RandomAccessFile port; 


    /**  CONSTRUCTOR **/
    public  GPSFrame()
    {    
         myThread=new Thread(this);
    }

    public void start()
    {
        try 
        {
            port=new java.io.RandomAccessFile("COM5","rwd");
            port.writeBytes("\r\n");
            port.writeBytes("c,31,0,0,5\r\n");
            port.writeBytes("T,1000,1\r\n");
        }
        catch (Exception e){ System.out.println("start "+e.toString()); }
        // The thread start automatically run() method
        myThread.start();
    }

/**********************************************************************************************
 *************************** RETRIEVE GPS FRAMES AND SEND TO SERVEUR **************************
 **********************************************************************************************/
    public void run() 
    {
        System.out.println("lecture COM...");
        // INFINIT LOOP - GPSFrame is always listening for the GPS receptor
        for(;;)
        {
            String st = null;
            try 
            {
                st=port.readLine();
                String[]gpsframe=st.split(",");

                /* IMPORTANT - DON'T FORGET SETCHANGED() or GPSFrame'll never
                 * notify UPDATE() ServerBoard method - We'll never see any changes */
                setChanged();
                notifyObservers(st);

            } 
            catch (IOException e){ System.out.println(e.getMessage()); }
            // Show in console
            System.out.println(st);
        }
    }   
}

To do that, I searched on the net. But I don't understand the start() method. What is the signification of c, T and the number we give to writeBytes ?

(I've also posted a question about this code, but for another reason. If you can help me, I shall be extremely grateful JAVA - GPS RECEPTOR sending strange/encoded frames in console)

Can someone enlighten me please ?

Thanks a lot in advance ! :)

Best regards,

Tofuw

1

There are 1 best solutions below

2
On

Well, as documentation for writeBytes states, it simply writes the sequence of bytes (in your case regular ASCII symbols: c, , , 3, 1, etc.) to the file.

Everything between double quote marks is written as is, without extra-logic for understanding what T, or c or particular number may mean.

Hope that helps.