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;
}