Skip to content

Commit 4263ddb

Browse files
committed
Add a debug method to extract RPC hash from packet
1 parent f445345 commit 4263ddb

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

sdl_android_lib/src/com/smartdevicelink/util/DebugTool.java

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
package com.smartdevicelink.util;
22

3+
import java.util.Hashtable;
34
import java.util.Vector;
45

56
import android.util.Log;
67

78
import com.smartdevicelink.exception.SdlException;
9+
import com.smartdevicelink.marshal.JsonRPCMarshaller;
10+
import com.smartdevicelink.protocol.BinaryFrameHeader;
11+
import com.smartdevicelink.protocol.ProtocolMessage;
12+
import com.smartdevicelink.protocol.SdlPacket;
13+
import com.smartdevicelink.protocol.enums.FunctionID;
14+
import com.smartdevicelink.protocol.enums.MessageType;
15+
import com.smartdevicelink.protocol.enums.SessionType;
16+
import com.smartdevicelink.proxy.RPCMessage;
17+
import com.smartdevicelink.proxy.RPCStruct;
818
import com.smartdevicelink.proxy.Version;
919
import com.smartdevicelink.transport.SiphonServer;
1020

@@ -267,4 +277,76 @@ protected static void logRPCReceiveToConsole(String msg) {
267277
} // end-catch
268278
}
269279
}
280+
281+
/**
282+
* Debug method to try to extract the RPC hash from the packet payload. Should only be used while debugging, not in production.
283+
* Currently it will only handle single frame RPCs
284+
* @param packet to inspect
285+
* @return The Hashtable to be used to construct an RPC
286+
*/
287+
public static Hashtable<String, Object> getRPCHash(SdlPacket packet){
288+
if(packet == null ||
289+
packet.getFrameType().getValue() != SdlPacket.FRAME_TYPE_SINGLE ||
290+
packet.getServiceType()!=SdlPacket.SERVICE_TYPE_RPC){
291+
Log.w("Debug", "Unable to get hash");
292+
return null;
293+
}
294+
int version = packet.getVersion();
295+
296+
ProtocolMessage message = new ProtocolMessage();
297+
SessionType serviceType = SessionType.valueOf((byte)packet.getServiceType());
298+
if (serviceType == SessionType.RPC) {
299+
message.setMessageType(MessageType.RPC);
300+
} else if (serviceType == SessionType.BULK_DATA) {
301+
message.setMessageType(MessageType.BULK);
302+
} // end-if
303+
message.setSessionType(serviceType);
304+
message.setSessionID((byte)packet.getSessionId());
305+
//If it is WiPro 2.0 it must have binary header
306+
if (version > 1) {
307+
BinaryFrameHeader binFrameHeader = BinaryFrameHeader.
308+
parseBinaryHeader(packet.getPayload());
309+
message.setVersion((byte) version);
310+
message.setRPCType(binFrameHeader.getRPCType());
311+
message.setFunctionID(binFrameHeader.getFunctionID());
312+
message.setCorrID(binFrameHeader.getCorrID());
313+
if (binFrameHeader.getJsonSize() > 0){
314+
message.setData(binFrameHeader.getJsonData());
315+
}
316+
if (binFrameHeader.getBulkData() != null){
317+
message.setBulkData(binFrameHeader.getBulkData());
318+
}
319+
} else {
320+
message.setData(packet.getPayload());
321+
}
322+
Hashtable<String, Object> hash = new Hashtable<String, Object>();
323+
if (packet.getVersion() > 1) {
324+
Hashtable<String, Object> hashTemp = new Hashtable<String, Object>();
325+
326+
hashTemp.put(RPCMessage.KEY_CORRELATION_ID, message.getCorrID());
327+
if (message.getJsonSize() > 0) {
328+
final Hashtable<String, Object> mhash = JsonRPCMarshaller.unmarshall(message.getData());
329+
hashTemp.put(RPCMessage.KEY_PARAMETERS, mhash);
330+
}
331+
332+
String functionName = FunctionID.getFunctionName(message.getFunctionID());
333+
if (functionName != null) {
334+
hashTemp.put(RPCMessage.KEY_FUNCTION_NAME, functionName);
335+
} else {
336+
return null;
337+
}
338+
if (message.getRPCType() == 0x00) {
339+
hash.put(RPCMessage.KEY_REQUEST, hashTemp);
340+
} else if (message.getRPCType() == 0x01) {
341+
hash.put(RPCMessage.KEY_RESPONSE, hashTemp);
342+
} else if (message.getRPCType() == 0x02) {
343+
hash.put(RPCMessage.KEY_NOTIFICATION, hashTemp);
344+
}
345+
if (message.getBulkData() != null) hash.put(RPCStruct.KEY_BULK_DATA, message.getBulkData());
346+
} else {
347+
final Hashtable<String, Object> mhash = JsonRPCMarshaller.unmarshall(message.getData());
348+
hash = mhash;
349+
}
350+
return hash;
351+
}
270352
}

0 commit comments

Comments
 (0)