2
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
package com.nokia.tcf.test;
|
|
18 |
|
|
19 |
import java.io.IOException;
|
|
20 |
|
|
21 |
import org.eclipse.core.runtime.IStatus;
|
|
22 |
|
|
23 |
import com.nokia.tcf.api.ITCAPIConnection;
|
|
24 |
import com.nokia.tcf.api.ITCMessage;
|
|
25 |
import com.nokia.tcf.api.ITCMessageIds;
|
|
26 |
import com.nokia.tcf.api.ITCMessageInputStream;
|
|
27 |
import com.nokia.tcf.api.ITCMessageOptions;
|
|
28 |
import com.nokia.tcf.api.ITCVirtualSerialConnection;
|
|
29 |
import com.nokia.tcf.api.TCFClassFactory;
|
|
30 |
import com.nokia.tcf.impl.TCAPIConnection;
|
|
31 |
|
|
32 |
import junit.framework.TestCase;
|
|
33 |
|
|
34 |
/**
|
|
35 |
* Tests using OST v0.3 Version Protocol
|
|
36 |
*/
|
|
37 |
public class TestOSTVersionRequest extends TestCase {
|
|
38 |
|
59
|
39 |
private boolean startServer = true; // use false when doing Junit plugin test - use true when doing non-plugin junit test
|
|
40 |
|
2
|
41 |
public void testOSTVersionRequest() {
|
|
42 |
// for non-plugin junit test
|
|
43 |
TCAPIConnection api2 = new TCAPIConnection();
|
59
|
44 |
if (startServer) {
|
|
45 |
api2.nativeStartServer();
|
|
46 |
}
|
2
|
47 |
|
|
48 |
// connection
|
59
|
49 |
ITCVirtualSerialConnection conn = (ITCVirtualSerialConnection)TCFClassFactory.createITCVirtualSerialConnection("COM27");
|
2
|
50 |
// set OST decoding for this connection
|
|
51 |
conn.setDecodeFormat("ost");
|
|
52 |
|
|
53 |
// message options
|
|
54 |
ITCMessageOptions options = TCFClassFactory.createITCMessageOptions();
|
|
55 |
// Ask TCF to not format the protocol (we're sending entire message)
|
|
56 |
options.setMessageEncodeFormat(ITCMessageOptions.ENCODE_NO_FORMAT);
|
|
57 |
// ask TCF to leave the protocol headers on incoming messages
|
|
58 |
options.setUnWrapFormat(ITCMessageOptions.UNWRAP_LEAVE_HEADERS);
|
|
59 |
options.setInputStreamSize(64);
|
|
60 |
|
|
61 |
// message Ids to capture
|
|
62 |
ITCMessageIds ids = TCFClassFactory.createITCMessageIds();
|
|
63 |
// This is the protocol ID to capture
|
|
64 |
ids.addMessageId((byte)0x00); // OST version protocol byte = 0x00
|
|
65 |
// ids.addMessageId((byte)0x02); // OST version protocol byte = 0x00
|
|
66 |
|
|
67 |
// OST AlignVersionRequest message (including header)
|
|
68 |
// RAW message ver 00 len len trans req version to check (0.1)
|
|
69 |
byte[] alignreq = {0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x01};
|
|
70 |
// convert to ITCMessage
|
|
71 |
ITCMessage tcalignreq = TCFClassFactory.createITCMessage(alignreq);
|
|
72 |
// Ask TCF to use the OST msg ID for TRK requests (0x90) per DSS
|
|
73 |
// tcMsgPing.setUseMyMessageId(true, (byte)0x90);
|
|
74 |
|
|
75 |
for (int iconnect = 0; iconnect < 1; iconnect++) {
|
|
76 |
// connect
|
|
77 |
ITCAPIConnection api = TCFClassFactory.createITCAPIConnection();
|
|
78 |
IStatus connStatus = api.connect(conn, options, ids);
|
|
79 |
System.out.printf("iconnect=%d connStatus=%d\n", iconnect, connStatus.getCode());
|
|
80 |
|
|
81 |
// get stream reference
|
|
82 |
ITCMessageInputStream stream = null;
|
|
83 |
if (connStatus.isOK()) {
|
|
84 |
stream = api.getInputStream();
|
|
85 |
System.out.printf("stream=%s\n", stream.toString());
|
|
86 |
}
|
|
87 |
|
|
88 |
// send align req
|
|
89 |
if (connStatus.isOK()) {
|
|
90 |
IStatus sendStatus = api.sendMessage(tcalignreq);
|
|
91 |
if (sendStatus.isOK()) {
|
|
92 |
// wait for response
|
|
93 |
int numberMessages = 0;
|
|
94 |
int numberPeeks = 0;
|
|
95 |
int numberSleeps = 0;
|
|
96 |
for (int i = 0; i < 100; i ++) {
|
|
97 |
try {
|
|
98 |
if (stream != null)
|
|
99 |
numberMessages = stream.peekMessages();
|
|
100 |
numberPeeks++;
|
|
101 |
if (numberMessages < 1) {
|
|
102 |
try {
|
|
103 |
Thread.sleep(100);
|
|
104 |
numberSleeps++;
|
|
105 |
} catch (InterruptedException e) {
|
|
106 |
e.printStackTrace();
|
|
107 |
}
|
|
108 |
}
|
|
109 |
} catch (IOException e) {
|
|
110 |
e.printStackTrace();
|
|
111 |
}
|
|
112 |
if (numberMessages == 1) {
|
|
113 |
break;
|
|
114 |
}
|
|
115 |
}
|
|
116 |
System.out.printf("NumberMessages = %d numberPeeks = %d numberSleeps = %d\n", numberMessages, numberPeeks, numberSleeps);
|
|
117 |
if (numberMessages > 0) {
|
|
118 |
try {
|
|
119 |
|
|
120 |
ITCMessage message = stream.readMessage();
|
|
121 |
byte[] b = message.getMessage();
|
|
122 |
System.out.printf("msg: length=%d\n", b.length);
|
|
123 |
for (int i = 0; i < b.length; i++) {
|
|
124 |
System.out.printf("%x ", b[i]);
|
|
125 |
}
|
|
126 |
System.out.printf("\n");
|
|
127 |
numberMessages = stream.peekMessages();
|
|
128 |
} catch (IOException e) {
|
|
129 |
e.printStackTrace();
|
|
130 |
}
|
|
131 |
}
|
|
132 |
} else {
|
|
133 |
System.out.printf("Error on send = %s\n", sendStatus.getMessage());
|
|
134 |
}
|
|
135 |
}
|
|
136 |
if (connStatus.isOK()) {
|
|
137 |
api.disconnect();
|
|
138 |
}
|
|
139 |
}
|
|
140 |
// for non-plugin junit test
|
59
|
141 |
if (startServer) {
|
|
142 |
api2.nativeStopServer();
|
|
143 |
}
|
2
|
144 |
}
|
|
145 |
}
|