1

I am developing a fleet application where I need to track my vehicle movement and store that into a MySQL db. Am using GT 06 GPS with a sim card.

I created a Java file for checking that GPS is sending the data or not. My program is connected with the GPS but the data I am receiving is not clear. How can U parse the data or is the data I am receiving is wrong?

Below is the program I am using:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class BackupServerListener {

public static void main(String[] args) {
    new ServerListener().startServer();
}

public void startServer() {
    final ExecutorService clientProcessingPool = Executors.newFixedThreadPool(03);

    Runnable serverTask = new Runnable() {
        @SuppressWarnings("resource")
        public void run() {
            try {
                ServerSocket serverSocket = new ServerSocket(9876);
                System.out.println("Waiting for clients to connect...");
                while (true) {
                    Socket clientSocket = serverSocket.accept();
                    clientProcessingPool.submit(new ClientTask(clientSocket));
                }
            } catch (IOException e) {
                System.err.println("Unable to process client request");
                e.printStackTrace();
            }
        }
    };
    Thread serverThread = new Thread(serverTask);
    serverThread.start();
}

private class ClientTask implements Runnable {
    private final Socket clientSocket;

    private ClientTask(Socket clientSocket) {
        this.clientSocket = clientSocket;
    }

    public void run() {
        System.out.println("Got a client !");
        while (true) {

        try {
            BufferedReader reader = new BufferedReader( new InputStreamReader(clientSocket.getInputStream()));
            String clientData = "";

            clientData = reader.readLine();
            String hex_value = asciiToHex(clientData);
            System.out.println("clientdata::::"+hex_value);

        } catch (IOException e) {
            e.printStackTrace();
        }
   
     }

    }
    private String asciiToHex(String clientData) {

        char[] chars = clientData.toCharArray();
        StringBuffer hex = new StringBuffer();
        for (int i = 0; i < chars.length; i++)
        {
            hex.append(Integer.toHexString((int)chars[i]));
        }
        return hex.toString();
    }

 }
}

2 Answers 2

0

I'm looking for a tool that will let me check the raw data from my device. I would like to be able to diagnose and analyze the data from the device end. Can you recommend anything? like any simulator type ?

1
  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review Note that recommendation Questions are likely to be closed quickly as opinion-based. See the Help Center topic on this.
    – Vince
    Commented Aug 3 at 11:57
-2
public class BackupServerListener {

public static void main(String[] args) {
    new BackupServerListener().startServer();
}

!!!!!Instead of !!!!!!!!!!
public class BackupServerListener {

public static void main(String[] args) {
    new ServerListener().startServer();
}
3
  • 4
    Hi! Could you add a quick explanation or a source to help understand the context of your answer ? Thanks a lot!
    – Kantan
    Commented Nov 11, 2019 at 12:56
  • hi, actually there was an error in your listener constructor .because when I ran your code after fixing the constructor .the program ran successfully and the GT06 login heartbeat I got. now GPS device needs to send a response from your end. then you will get the actual GPS location data.
    – Abdul Bari
    Commented Nov 23, 2019 at 6:46
  • Please Edit the Answer to provide the additional information.
    – Vince
    Commented Aug 3 at 11:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.