Reputation: 9
I have been using TK06A GPS tracker and I 'm developing my own server java file and I have received the initial login message packet as per the TK06A manual and now I need to send back the ack to the device to get the GPS message packet.
I am not getting the GPS message packet which holds the coordinates. I'm adding the code below. I'm sure that till obtaining the IMEI number in the LOC is correct and I'm having problems in the outputstream/sending the ACk. I'm totally struck here. I don't know where am I going wrong.
Kindly help !
public void run() {
DataInputStream inputS = null;
DataOutputStream dos = null;
try {
inputS = new DataInputStream(socket.getInputStream());
if (inputS.available() > 0) {
byte[] bb = getBytesFromInputStream(inputS);
ChannelBuffer buf = toByteBuffer(bb);
String imei = readImei(buf);
System.out.println("IMEI::::: " + imei);
buf.skipBytes(5); // End
OutputStream os = socket.getOutputStream();
dos = new DataOutputStream(os);
byte[] response = parseHex();
dos.write(response);
Thread.sleep(1000);
dos.flush();
}
} catch (Exception e) {
e.printStackTrace();
}
finally {
try {
inputS.close();
if (dos != null)
dos.close();
socket.close();
} catch (IOException e) {
}
}
}
public byte[] parseHex() {
String hexACKlogin = "787805010001D9DC0D0A"; // String in HEX format
int len = hexACKlogin.length();
byte[] data = new byte[len / 2];
for (int i = 0; i < len; i += 2) {
data[i / 2] = (byte) ((Character.digit(hexACKlogin.charAt(i), 16) << 4)
+ Character.digit(hexACKlogin.charAt(i+1), 16));
}
return data;
}
Upvotes: 0
Views: 2019
Reputation: 9
I'm implementing a logic for a GPS tracking device (TK06A). Client being the GPS tracker and server which I'm using to read the data sent from the tracker.
I'm receiving a 18 bytes data which I found out to be a Login Message packet which doesn't contain the co-ordinates/latitude & longitude.
It is said that I need to send a ACK response to the client[I'm stuck here].
I need to send the byte as a response to the client in my case Gps tracker the byte[] response = {0x78 0x78 0x05 0x01 0x00 0x01 0xD9 0xDC 0x0D 0x0A};
I have used portpeeker to send the ack and it was returning some response of 36 bytes.
PS: I'm using TCP for data transfer
try {
inputS = new DataInputStream(socket.getInputStream());
oos = new ObjectOutputStream(socket.getOutputStream());
if (inputS.available() > 0) {
System.out.println("Bytes Cap::: "+inputS.available());
byte[] bb = getBytesFromInputStream(inputS);
ChannelBuffer buf = toByteBuffer(bb);
buf.skipBytes(4);
String imei = readImei(buf);
System.out.println("IMEI::::: " + imei);
buf.skipBytes(5); // End
byte[] response = sendOutputMessage();
oos.write(response);
oos.flush();
}
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
inputS.close();
oos.close();
socket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public byte[] sendOutputMessage() {
byte buf[] = new byte[10];
// Start of the body of setOutput
// Message type 0x78 0x78 0x05 0x01 0x00 0x01 0xD9 0xDC 0x0D 0x0A
buf[0] = (byte) 0x78;
buf[1] = (byte) 0x78;
buf[2] = (byte) 0x05;
buf[3] = (byte) 0x01;
buf[4] = (byte) 0x00;
buf[5] = (byte) 0x01;
buf[6] = (byte) 0xD9;
buf[7] = (byte) 0xDC;
buf[8] = (byte) 0x0D; // end f1
buf[9] = (byte) 0x0A;
return buf;
}
Upvotes: 0