0% found this document useful (0 votes)
20 views

New 1

Uploaded by

mohammedwork218
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

New 1

Uploaded by

mohammedwork218
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

private static JSONArray generate_updateRequest_response(String IMEI, String

informationSerialNumber, FileEntity lastFilEntity) {


Long fileSize = lastFilEntity.getFileSize();
String message = "";
int nextDataLength;
int PacketLength;
String fileId = "000055f1";
String DownloadSizeIndex = "00000001";
String responce_mid = "";
Long numberOfArray = (long) Math.ceil((double) fileSize / 2048);
System.out.println("numberOfArray:" + numberOfArray);
JSONArray jsonArray = new JSONArray();

try (FileInputStream fis = new


FileInputStream(lastFilEntity.getFilePath())) {
byte[] buffer = new byte[(int) lastFilEntity.getFileSize()];
fis.read(buffer);

int startIndex = 0;
int endIndex = 2048;
byte[] byteArray;
for (int i = 1; i <= numberOfArray; i++) {
if (i == numberOfArray) {
endIndex = buffer.length;
System.out.println("endIndex:" + endIndex);
} else if (i != 1) {
System.out.println("Index:" + endIndex);
endIndex = startIndex + 2048;
}
if (endIndex > buffer.length) {
endIndex = buffer.length;
}
byteArray = Arrays.copyOfRange(buffer, startIndex, endIndex);
PacketLength = 28 + byteArray.length / 2;
String PacketLengthHex = String.format("%04X", PacketLength);
nextDataLength = 13 + byteArray.length / 2;
String NextDataLength = String.format("%04X", nextDataLength);
String ContentLength = String.format("%04X", byteArray.length / 2);

JSONObject jsonResponse = new JSONObject();


StringBuilder stringBuilder = new StringBuilder();
for (byte b : byteArray) {
stringBuilder.append(String.format("%02X", b));
}
String hexString = stringBuilder.toString();

responce_mid = PacketLengthHex + "FD" + IMEI + NextDataLength +


"02" + "0401" + fileId + DownloadSizeIndex + ContentLength + hexString +
informationSerialNumber;
String Error_check_Response =
convertintToHexadecimal(Static_Methods.GetCrc162(stringToByteArray(responce_mid),
(stringToByteArray(responce_mid)).length));
message = "7979" + responce_mid + Error_check_Response + "0d0a";
jsonResponse.put("Responce_message", message);
jsonArray.put(jsonResponse);
startIndex = endIndex;
}
} catch (IOException e) {
e.printStackTrace();
}

return jsonArray;
}

You might also like