package org.tizen.dynamicanalyzer.swap.communicator;
-import static org.tizen.dynamicanalyzer.common.AnalyzerConstants.MSG_CONFIG_ACK;
+import static org.tizen.dynamicanalyzer.common.AnalyzerConstants.*;
import static org.tizen.dynamicanalyzer.common.AnalyzerConstants.MSG_KEEP_ALIVE_ACK;
import static org.tizen.dynamicanalyzer.common.AnalyzerConstants.MSG_START_ACK;
import static org.tizen.dynamicanalyzer.common.AnalyzerConstants.MSG_STOP_ACK;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
import java.util.List;
import org.tizen.dynamicanalyzer.common.AnalyzerConstants;
import org.tizen.dynamicanalyzer.ui.toolbar.ToolbarArea;
import org.tizen.dynamicanalyzer.ui.userinterface.UIDataManager;
import org.tizen.dynamicanalyzer.uirecorder.UIRecorderTool;
+import org.tizen.dynamicanalyzer.utils.ByteSwapper;
import org.tizen.dynamicanalyzer.utils.UpdateViewTimer;
public class Communicator30 extends BaseCommunicator {
// get port
List<DeviceInfo> removeList = new ArrayList<DeviceInfo>();
for (DeviceInfo devInfo : devices) {
- int remotePort = CommunicatorUtils.getRemotePort(devInfo.getIDevice());
+ int remotePort = CommunicatorUtils.getRemotePort(devInfo
+ .getIDevice());
if (remotePort < 0) {
System.out.println(devInfo.getIDevice().getSerialNumber()
- + " remote port get failed and remove this device");
+ + " remote port get failed and remove this device : "
+ + devInfo.getIDevice().getSerialNumber());
removeList.add(devInfo);
// devices.remove(devInfo);
} else {
if (!removeList.isEmpty()) {
devices.removeAll(removeList);
+ removeList.clear();
}
// create control socket
HostResult result = createControlSocket(devInfo);
if (!result.isSuccess()) {
System.out.println(result.toString());
+ removeList.add(devInfo);
+ } else {
+ result = createDataSocket(devInfo);
+ if (!result.isSuccess()) {
+ System.out.println(result.toString());
+ removeList.add(devInfo);
+ }
}
}
// create data socket - not create data receive thread
- for (DeviceInfo devInfo : devices) {
- HostResult result = createDataSocket(devInfo);
- if (!result.isSuccess()) {
- System.out.println(result.toString());
- }
+ // for (DeviceInfo devInfo : devices) {
+ // HostResult result = createDataSocket(devInfo);
+ // if (!result.isSuccess()) {
+ // System.out.println(result.toString());
+ // }
+ // }
+
+ if (!removeList.isEmpty()) {
+ devices.removeAll(removeList);
+ removeList.clear();
}
// target info get
HostResult result = getTargetInfo(devInfo);
if (!result.isSuccess()) {
System.out.println(result.toString());
+ removeList.add(devInfo);
}
}
+ if (!removeList.isEmpty()) {
+ devices.removeAll(removeList);
+ removeList.clear();
+ }
+
+ if (devices.isEmpty()) {
+ System.out.println("device init faiiled...");
+ // TODO: close da
+ }
+
// heart beat thread start
- Thread heartBeat = new Thread(null, new HeartBeatThread(),
- AnalyzerConstants.HEART_BEAT_THREAD);
- heartBeat.start();
+ // Thread heartBeat = new Thread(null, new HeartBeatThread(),
+ // AnalyzerConstants.HEART_BEAT_THREAD);
+ // heartBeat.start();
return HostResult.SUCCESS;
}
@Override
public HostResult startTrace() {
// binary info message send
+ DACommunicator.setRunning(true);
ApplicationInfo appInfo = new ApplicationInfo();
AppInfo selectedApp = DACommunicator.getSelectedApp();
- appInfo.setAppType(Integer.parseInt(selectedApp
- .getInfo(AppInfo.APPTYPE_INDEX))); // tizen native app
+ String appType = selectedApp.getInfo(AppInfo.APPTYPE_INDEX);
+ if (appType.contains(AppInfo.APPTYPE_CPP)) {
+ appInfo.setAppType(APP_TYPE_TIZEN);
+ } else {
+ appInfo.setAppType(APP_TYPE_OSP);
+ }
appInfo.setAppId(selectedApp.getInfo(AppInfo.APPID_INDEX));
appInfo.setExecPath(selectedApp.getInfo(AppInfo.EXEC_INDEX));
if (result.isSuccess()) {
if (!isCorrectAck(MSG_START_ACK, result)) {
- return HostResult.ERR_MSG_START_FAIL;
+ HostResult failResult = HostResult.ERR_MSG_START_FAIL;
+ failResult.setMessage(ErrorCode.getError(
+ getReturnId(result.getRet())).toString());
+ DACommunicator.setRunning(false);
+ return failResult;
}
} else {
DACommunicator.setRunning(false);
System.out.println("wait for ack... [send message : " + message
+ " ]");
- while (DACommunicator.isRunning()) {
- byte[] cbuf = new byte[64];
- blocked = true;
- int readsize = controlSock.getInputStream().read(cbuf);
- blocked = false;
- if (readsize > 0) {
- result = HostResult.SUCCESS;
- result.setRet(cbuf);
- }
+ // while (true) {
+ byte[] cbuf = new byte[64];
+ blocked = true;
+ int readsize = controlSock.getInputStream().read(cbuf);
+ blocked = false;
+ if (readsize > 0) {
+ byte[] buf = new byte[readsize];
+ System.arraycopy(cbuf, 0, buf, 0, readsize);
+ result = HostResult.SUCCESS;
+ result.setRet(buf);
}
+
+ // }
} catch (SocketException e) {
result = HostResult.ERR_EXCEPTION_OCCURRED;
result.setMessage(e.getMessage());
Socket controlSock = null;
try {
controlSock = new Socket(CommonConstants.LOCAL_HOST,
- device.getRemotePort());
+ CommunicatorUtils.LOCAL_PORT);
controlSock.setSoTimeout(AnalyzerConstants.SOCKET_TIMEOUT);
controlSock.setReuseAddress(true);
controlSock.setTcpNoDelay(true);
Socket dataSock = null;
try {
dataSock = new Socket(CommonConstants.LOCAL_HOST,
- device.getRemotePort());
+ CommunicatorUtils.LOCAL_PORT);
dataSock.setSoTimeout(AnalyzerConstants.SOCKET_TIMEOUT);
dataSock.setReuseAddress(true);
dataSock.setTcpNoDelay(true);
public HostResult getTargetInfo(DeviceInfo device) {
System.out.println("Send target info : "
- + ByteUtils.getByte(AnalyzerConstants.MSG_TARGET_INFO));
+ + ByteUtils.getByte(AnalyzerConstants.MSG_TARGET_INFO, 0));
HostResult result = handleControlMessage(device,
- ByteUtils.getByte(AnalyzerConstants.MSG_TARGET_INFO));
+ ByteUtils.getByte(AnalyzerConstants.MSG_TARGET_INFO, 0));
if (result.isSuccess()) {
System.out.println("target info message ack :" + result.getRet());
// FIXME : log parsing
byte[] data = result.getRet();
- int index = INT_SIZE * 2;
+ int index = INT_SIZE * 3;
- if (isCorrectAck(MSG_KEEP_ALIVE_ACK, result)) {
+ if (isCorrectAck(MSG_TARGET_INFO_ACK, result)) {
TargetInfo info = processTargetInfo(data, index);
device.setTargetInfo(info);
return result;
@Override
public HostResult sendKeepAliveMessage(DeviceInfo device) {
System.out.println("Send keep alive message : "
- + ByteUtils.getByte(AnalyzerConstants.MSG_KEEP_ALIVE));
+ + ByteUtils.getByte(AnalyzerConstants.MSG_KEEP_ALIVE, 0));
HostResult result = handleControlMessage(device,
ByteUtils.getByte(AnalyzerConstants.MSG_KEEP_ALIVE, 0));
if (result.isSuccess()) {
int index = 0;
int msgId = ByteUtils.toInt(data, index);
index += INT_SIZE;
+ int length = ByteUtils.toInt(data, index);
+ index += INT_SIZE;
int retId = ByteUtils.toInt(data, index);
index += INT_SIZE;
public void closeSock() {
DACommunicator.getSelectedDevice().releaseDataSock();
}
+
+ private int getMessageId(byte[] data) {
+ int index = 0;
+ return ByteUtils.toInt(data, index);
+ }
+
+ private int getReturnId(byte[] data) {
+ int index = INT_SIZE * 2;
+ return ByteUtils.toInt(data, index);
+ }
}
import java.nio.ByteBuffer;
import java.util.List;
+import org.tizen.dynamicanalyzer.utils.ByteSwapper;
+
public class ByteUtils {
public static byte EOS = '\0';
for (int i = 0; i < 4; i++) {
dword = (dword << 8) + (src[i + srcPos] & 0xFF);
}
- return dword;
+ return ByteSwapper.swap(dword);
+// return dword;
}
/**
for (int i = 0; i < 8; i++) {
qword = (qword << 8) + (src[i + srcPos] & 0xFF);
}
- return qword;
+ return ByteSwapper.swap(qword);
+// return qword;
}
/**
* @return
*/
public static byte[] toBytes(int value) {
+ value = ByteSwapper.swap(value);
byte[] dest = new byte[4];
toBytes(value, dest, 0);
return dest;
byte[] temp = new byte[size];
System.arraycopy(input, from, temp, 0, size);
ByteBuffer buf = ByteBuffer.wrap(temp);
- return buf.getShort();
+ return ByteSwapper.swap(buf.getShort());
}
public static byte[] floatToBytes(float input) {
byte[] temp = new byte[size];
System.arraycopy(input, from, temp, 0, size);
ByteBuffer buf = ByteBuffer.wrap(temp);
- return buf.getFloat();
+ return ByteSwapper.swap(buf.getFloat());
}
public static double toDouble(byte[] input, int from) {
byte[] temp = new byte[size];
System.arraycopy(input, from, temp, 0, size);
ByteBuffer buf = ByteBuffer.wrap(temp);
- return buf.getDouble();
+ return ByteSwapper.swap(buf.getDouble());
}
public static byte[] concatByteArray(byte[] front, byte[] rear) {
--- /dev/null
+package org.tizen.dynamicanalyzer.utils;
+
+public class ByteSwapper {
+ /**
+ * Byte swap a single short value.
+ *
+ * @param value
+ * Value to byte swap.
+ * @return Byte swapped representation.
+ */
+ public static short swap(short value) {
+ int b1 = value & 0xff;
+ int b2 = (value >> 8) & 0xff;
+
+ return (short) (b1 << 8 | b2 << 0);
+ }
+
+ /**
+ * Byte swap a single int value.
+ *
+ * @param value
+ * Value to byte swap.
+ * @return Byte swapped representation.
+ */
+ public static int swap(int value) {
+ int b1 = (value >> 0) & 0xff;
+ int b2 = (value >> 8) & 0xff;
+ int b3 = (value >> 16) & 0xff;
+ int b4 = (value >> 24) & 0xff;
+
+ return b1 << 24 | b2 << 16 | b3 << 8 | b4 << 0;
+ }
+
+ /**
+ * Byte swap a single long value.
+ *
+ * @param value
+ * Value to byte swap.
+ * @return Byte swapped representation.
+ */
+ public static long swap(long value) {
+ long b1 = (value >> 0) & 0xff;
+ long b2 = (value >> 8) & 0xff;
+ long b3 = (value >> 16) & 0xff;
+ long b4 = (value >> 24) & 0xff;
+ long b5 = (value >> 32) & 0xff;
+ long b6 = (value >> 40) & 0xff;
+ long b7 = (value >> 48) & 0xff;
+ long b8 = (value >> 56) & 0xff;
+
+ return b1 << 56 | b2 << 48 | b3 << 40 | b4 << 32 | b5 << 24 | b6 << 16
+ | b7 << 8 | b8 << 0;
+ }
+
+ /**
+ * Byte swap a single float value.
+ *
+ * @param value
+ * Value to byte swap.
+ * @return Byte swapped representation.
+ */
+ public static float swap(float value) {
+ int intValue = Float.floatToIntBits(value);
+ intValue = swap(intValue);
+ return Float.intBitsToFloat(intValue);
+ }
+
+ /**
+ * Byte swap a single double value.
+ *
+ * @param value
+ * Value to byte swap.
+ * @return Byte swapped representation.
+ */
+ public static double swap(double value) {
+ long longValue = Double.doubleToLongBits(value);
+ longValue = swap(longValue);
+ return Double.longBitsToDouble(longValue);
+ }
+
+ /**
+ * Byte swap an array of shorts. The result of the swapping is put back into
+ * the specified array.
+ *
+ * @param array
+ * Array of values to swap
+ */
+ public static void swap(short[] array) {
+ for (int i = 0; i < array.length; i++)
+ array[i] = swap(array[i]);
+ }
+
+ /**
+ * Byte swap an array of ints. The result of the swapping is put back into
+ * the specified array.
+ *
+ * @param array
+ * Array of values to swap
+ */
+ public static void swap(int[] array) {
+ for (int i = 0; i < array.length; i++)
+ array[i] = swap(array[i]);
+ }
+
+ /**
+ * Byte swap an array of longs. The result of the swapping is put back into
+ * the specified array.
+ *
+ * @param array
+ * Array of values to swap
+ */
+ public static void swap(long[] array) {
+ for (int i = 0; i < array.length; i++)
+ array[i] = swap(array[i]);
+ }
+
+ /**
+ * Byte swap an array of floats. The result of the swapping is put back into
+ * the specified array.
+ *
+ * @param array
+ * Array of values to swap
+ */
+ public static void swap(float[] array) {
+ for (int i = 0; i < array.length; i++)
+ array[i] = swap(array[i]);
+ }
+
+ /**
+ * Byte swap an array of doubles. The result of the swapping is put back
+ * into the specified array.
+ *
+ * @param array
+ * Array of values to swap
+ */
+ public static void swap(double[] array) {
+ for (int i = 0; i < array.length; i++)
+ array[i] = swap(array[i]);
+ }
+}