253
|
1 |
// Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
|
0
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// @file PBASE-T_USBDI-0482.cpp
|
|
15 |
// @internalComponent
|
|
16 |
//
|
|
17 |
//
|
|
18 |
|
|
19 |
#include "PBASE-T_USBDI-0482.h"
|
|
20 |
#include "tada22.h"
|
253
|
21 |
#include "OstTraceDefinitions.h"
|
|
22 |
#ifdef OST_TRACE_COMPILER_IN_USE
|
|
23 |
#include "PBASE-T_USBDI-0482Traces.h"
|
|
24 |
#endif
|
0
|
25 |
#include <d32usbdescriptors.h>
|
|
26 |
|
|
27 |
|
|
28 |
namespace NUnitTesting_USBDI
|
|
29 |
{
|
|
30 |
|
|
31 |
_LIT(KTestCaseId,"PBASE-T_USBDI-0482");
|
|
32 |
const TFunctorTestCase<CUT_PBASE_T_USBDI_0482,TBool> CUT_PBASE_T_USBDI_0482::iFunctor(KTestCaseId);
|
|
33 |
_LIT8(KHighRecordSamplingRate, "\x80\xBB\x00"); // sampling rate : 48,000 Hz
|
|
34 |
_LIT8(KLowSamplingRate , "\x22\x56\x00"); // sampling rate : 22,050 Hz
|
|
35 |
|
|
36 |
_LIT(KTrackFileName, "Z:\\scripts\\track.dat");
|
|
37 |
|
|
38 |
const TInt KRecordedDataId = 0x12345;
|
|
39 |
const TUint KRecordedPacketsExpected = 1000;
|
|
40 |
const TUint KAudioCDQualityFrequency = 176; // 176 kB/s
|
|
41 |
const TUint KMaxPacketSizeOutExpected = 192;
|
|
42 |
const TUint KMaxPacketSizeInExpected = 96;
|
|
43 |
const TUint KMaxPacketSizeOffset = 4;
|
|
44 |
const TUint KIsochInMaxNumPackets = 2000;
|
|
45 |
const TUint KChunkSize = 500000; // 0.5 Mb
|
|
46 |
|
|
47 |
|
|
48 |
TInt CUT_PBASE_T_USBDI_0482::iExpectedTransferId = 0;
|
|
49 |
|
|
50 |
CUT_PBASE_T_USBDI_0482* CUT_PBASE_T_USBDI_0482::NewL(TBool aHostRole)
|
|
51 |
{
|
253
|
52 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0482_NEWL_ENTRY, aHostRole );
|
0
|
53 |
CUT_PBASE_T_USBDI_0482* self = new (ELeave) CUT_PBASE_T_USBDI_0482(aHostRole);
|
|
54 |
CleanupStack::PushL(self);
|
|
55 |
self->ConstructL();
|
|
56 |
CleanupStack::Pop(self);
|
253
|
57 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0482_NEWL_EXIT, ( TUint )( self ) );
|
0
|
58 |
return self;
|
|
59 |
}
|
|
60 |
|
|
61 |
|
|
62 |
CUT_PBASE_T_USBDI_0482::CUT_PBASE_T_USBDI_0482(TBool aHostRole)
|
|
63 |
: CBaseTestCase(KTestCaseId,aHostRole),
|
|
64 |
iCaseStep(EInProgress)
|
|
65 |
{
|
253
|
66 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0482_CUT_PBASE_T_USBDI_0482_ENTRY, this );
|
0
|
67 |
iEndpointAddressIn = 0x84;
|
|
68 |
iEndpointAddressOut = 0x01;
|
|
69 |
iOutTransferBuf.CreateL(KChunkSize);
|
253
|
70 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0482_CUT_PBASE_T_USBDI_0482_EXIT, this );
|
0
|
71 |
}
|
|
72 |
|
|
73 |
|
|
74 |
void CUT_PBASE_T_USBDI_0482::ConstructL()
|
|
75 |
{
|
253
|
76 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0482_CONSTRUCTL_ENTRY, this );
|
0
|
77 |
BaseConstructL();
|
253
|
78 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0482_CONSTRUCTL_EXIT, this );
|
0
|
79 |
}
|
|
80 |
|
|
81 |
|
|
82 |
CUT_PBASE_T_USBDI_0482::~CUT_PBASE_T_USBDI_0482()
|
|
83 |
{
|
253
|
84 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0482_CUT_PBASE_T_USBDI_0482_ENTRY_DUP01, this );
|
0
|
85 |
|
|
86 |
Cancel();
|
|
87 |
|
|
88 |
// Close pipes before interfaces
|
|
89 |
iPipeOut.Close();
|
|
90 |
iPipeIn.Close();
|
|
91 |
|
|
92 |
iUsbInterface0.Close();
|
|
93 |
iUsbInterface1.Close();
|
|
94 |
iUsbInterface2.Close();
|
|
95 |
|
|
96 |
// Destroy transfers
|
|
97 |
iOutTransfers.ResetAndDestroy();
|
|
98 |
|
|
99 |
iOutTransferBuf.Close();
|
|
100 |
iDataPolledBuf.Close();
|
|
101 |
|
|
102 |
delete iIsochInTransfer;
|
|
103 |
delete iControlEp0;
|
|
104 |
delete iActorFDF;
|
253
|
105 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0482_CUT_PBASE_T_USBDI_0482_EXIT_DUP01, this );
|
0
|
106 |
}
|
|
107 |
|
|
108 |
void CUT_PBASE_T_USBDI_0482::ExecuteHostTestCaseL()
|
|
109 |
{
|
253
|
110 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0482_EXECUTEHOSTTESTCASEL_ENTRY, this );
|
0
|
111 |
|
|
112 |
iActorFDF = CActorFDF::NewL(*this);
|
|
113 |
iControlEp0 = new (ELeave) CEp0Transfer(iUsbInterface0);
|
|
114 |
iActorFDF->Monitor();
|
|
115 |
|
|
116 |
// Wait for the usb headset to be connected
|
|
117 |
TimeoutIn(30);
|
253
|
118 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0482_EXECUTEHOSTTESTCASEL_EXIT, this );
|
0
|
119 |
}
|
|
120 |
|
|
121 |
|
|
122 |
void CUT_PBASE_T_USBDI_0482::HostDoCancel()
|
|
123 |
{
|
253
|
124 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0482_HOSTDOCANCEL_ENTRY, this );
|
|
125 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0482_HOSTDOCANCEL_EXIT, this );
|
0
|
126 |
}
|
|
127 |
|
|
128 |
|
|
129 |
void CUT_PBASE_T_USBDI_0482::ExecuteDeviceTestCaseL()
|
|
130 |
{
|
253
|
131 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0482_EXECUTEDEVICETESTCASEL_ENTRY, this );
|
|
132 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0482_EXECUTEDEVICETESTCASEL_EXIT, this );
|
0
|
133 |
}
|
|
134 |
|
|
135 |
|
|
136 |
void CUT_PBASE_T_USBDI_0482::DeviceDoCancel()
|
|
137 |
{
|
253
|
138 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0482_DEVICEDOCANCEL_ENTRY, this );
|
|
139 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0482_DEVICEDOCANCEL_EXIT, this );
|
0
|
140 |
}
|
|
141 |
|
|
142 |
|
|
143 |
void CUT_PBASE_T_USBDI_0482::DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState,RUsbDevice::TDeviceState aNewState,
|
|
144 |
TInt aCompletionCode)
|
|
145 |
{
|
253
|
146 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0482_DEVICESTATECHANGEL_ENTRY, this );
|
|
147 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0482_DEVICESTATECHANGEL_EXIT, this );
|
0
|
148 |
}
|
|
149 |
|
|
150 |
|
|
151 |
TInt CUT_PBASE_T_USBDI_0482::FindOUTIsochronousEndpoint(TUsbGenericDescriptor*& aDescriptor)
|
|
152 |
{
|
253
|
153 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0482_FINDOUTISOCHRONOUSENDPOINT_ENTRY, this );
|
0
|
154 |
aDescriptor = NULL;
|
|
155 |
|
|
156 |
TUsbInterfaceDescriptor alternate;
|
|
157 |
TInt err = iUsbInterface1.GetAlternateInterfaceDescriptor(1, alternate);
|
|
158 |
if(err)
|
|
159 |
{
|
253
|
160 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0482_FINDOUTISOCHRONOUSENDPOINT, "iUsbInterface1.GetAlternateInterfaceDescriptor error = %d",err);
|
|
161 |
OstTraceFunctionExitExt( CUT_PBASE_T_USBDI_0482_FINDOUTISOCHRONOUSENDPOINT_EXIT, this, err );
|
0
|
162 |
return err;
|
|
163 |
}
|
|
164 |
|
|
165 |
TUsbGenericDescriptor* descriptor = alternate.iFirstChild;
|
|
166 |
while(descriptor)
|
|
167 |
{
|
253
|
168 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0482_FINDOUTISOCHRONOUSENDPOINT_DUP01, "ibDescriptorType = %d", descriptor->ibDescriptorType);
|
0
|
169 |
if(descriptor->ibDescriptorType == EEndpoint)
|
|
170 |
{
|
|
171 |
aDescriptor = descriptor;
|
253
|
172 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0482_FINDOUTISOCHRONOUSENDPOINT_DUP02, "found descriptor return KErrNone");
|
|
173 |
OstTraceFunctionExitExt( CUT_PBASE_T_USBDI_0482_FINDOUTISOCHRONOUSENDPOINT_EXIT_DUP01, this, KErrNone );
|
0
|
174 |
return KErrNone;
|
|
175 |
}
|
|
176 |
descriptor = descriptor->iNextPeer;
|
|
177 |
}
|
|
178 |
|
253
|
179 |
OstTraceFunctionExitExt( CUT_PBASE_T_USBDI_0482_FINDOUTISOCHRONOUSENDPOINT_EXIT_DUP02, this, KErrNotFound );
|
0
|
180 |
return KErrNotFound;
|
|
181 |
}
|
|
182 |
|
|
183 |
|
|
184 |
TInt CUT_PBASE_T_USBDI_0482::FindINIsochronousEndpoint(TUsbGenericDescriptor*& aDescriptor)
|
|
185 |
{
|
253
|
186 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0482_FINDINISOCHRONOUSENDPOINT_ENTRY, this );
|
0
|
187 |
aDescriptor = NULL;
|
|
188 |
|
|
189 |
TUsbInterfaceDescriptor alternate;
|
|
190 |
TInt err = iUsbInterface2.GetAlternateInterfaceDescriptor(1, alternate);
|
|
191 |
if(err)
|
|
192 |
{
|
253
|
193 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0482_FINDINISOCHRONOUSENDPOINT, "iUsbInterface2.GetAlternateInterfaceDescriptor error = %d",err);
|
|
194 |
OstTraceFunctionExitExt( CUT_PBASE_T_USBDI_0482_FINDINISOCHRONOUSENDPOINT_EXIT, this, err );
|
0
|
195 |
return err;
|
|
196 |
}
|
|
197 |
|
|
198 |
TUsbGenericDescriptor* descriptor = alternate.iFirstChild;
|
|
199 |
while(descriptor)
|
|
200 |
{
|
253
|
201 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0482_FINDINISOCHRONOUSENDPOINT_DUP01, "ibDescriptorType = %d", descriptor->ibDescriptorType);
|
0
|
202 |
if(descriptor->ibDescriptorType == EEndpoint)
|
|
203 |
{
|
|
204 |
aDescriptor = descriptor;
|
253
|
205 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0482_FINDINISOCHRONOUSENDPOINT_DUP02, "found descriptor return KErrNone");
|
|
206 |
OstTraceFunctionExitExt( CUT_PBASE_T_USBDI_0482_FINDINISOCHRONOUSENDPOINT_EXIT_DUP01, this, KErrNone );
|
0
|
207 |
return KErrNone;
|
|
208 |
}
|
|
209 |
descriptor = descriptor->iNextPeer;
|
|
210 |
}
|
|
211 |
|
253
|
212 |
OstTraceFunctionExitExt( CUT_PBASE_T_USBDI_0482_FINDINISOCHRONOUSENDPOINT_EXIT_DUP02, this, KErrNotFound );
|
0
|
213 |
return KErrNotFound;
|
|
214 |
}
|
|
215 |
|
|
216 |
|
|
217 |
|
|
218 |
void CUT_PBASE_T_USBDI_0482::DeviceInsertedL(TUint aDeviceHandle)
|
|
219 |
{
|
253
|
220 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0482_DEVICEINSERTEDL_ENTRY, this );
|
0
|
221 |
|
|
222 |
Cancel();
|
|
223 |
CUsbTestDevice& testDevice = iActorFDF->DeviceL(aDeviceHandle);
|
|
224 |
|
|
225 |
CHECK(CheckTreeAfterDeviceInsertion(testDevice, _L("RLogitechHeadSet")) == KErrNone);
|
|
226 |
|
|
227 |
TUint32 token0, token1, token2;
|
|
228 |
CHECK(testDevice.Device().GetTokenForInterface(0,token0) == KErrNone);
|
|
229 |
|
|
230 |
CHECK(iUsbInterface0.Open(token0) == KErrNone); // Default interface setting 0
|
|
231 |
|
|
232 |
|
|
233 |
// open interface 1, alt. sett. 1
|
|
234 |
CHECK(testDevice.Device().GetTokenForInterface(1,token1) == KErrNone);
|
|
235 |
|
|
236 |
CHECK(iUsbInterface1.Open(token1) == KErrNone); // Default interface setting 0
|
|
237 |
|
253
|
238 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0482_DEVICEINSERTEDL, "Selecting alternate interface setting 1");
|
0
|
239 |
CHECK(iUsbInterface1.SelectAlternateInterface(1) == KErrNone);
|
|
240 |
|
|
241 |
|
|
242 |
// open interface 2, alt. sett. 1
|
|
243 |
CHECK(testDevice.Device().GetTokenForInterface(2,token2) == KErrNone);
|
|
244 |
|
|
245 |
CHECK(iUsbInterface2.Open(token2) == KErrNone); // Default interface setting 0
|
|
246 |
|
|
247 |
|
253
|
248 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0482_DEVICEINSERTEDL_DUP01, "Selecting alternate interface setting 1");
|
0
|
249 |
CHECK(iUsbInterface2.SelectAlternateInterface(1) == KErrNone);
|
|
250 |
|
|
251 |
|
|
252 |
iCaseStep = EWaitEndOfMusicTrack;
|
|
253 |
|
|
254 |
// Open a pipe for endpoint (Isoch out)
|
253
|
255 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0482_DEVICEINSERTEDL_DUP02, "Finding address for an out isoch endpoint on interface 1 setting 1");
|
0
|
256 |
// Isochronous OUT
|
|
257 |
TUsbGenericDescriptor* isochEpDescriptorOut;
|
|
258 |
CHECK(KErrNone == FindOUTIsochronousEndpoint(isochEpDescriptorOut));
|
|
259 |
|
|
260 |
// Get the maximum packet size for this isochronous endpoint
|
|
261 |
TUint16 wMaxPacketSizeOut = isochEpDescriptorOut->TUint16At(KMaxPacketSizeOffset);
|
253
|
262 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0482_DEVICEINSERTEDL_DUP03, "wMaxPacketSizeOut = %d", wMaxPacketSizeOut);
|
0
|
263 |
CHECK(wMaxPacketSizeOut == KMaxPacketSizeOutExpected);
|
|
264 |
|
|
265 |
// Isochronous IN
|
|
266 |
TUsbGenericDescriptor* isochEpDescriptorIn;
|
|
267 |
CHECK(KErrNone == FindINIsochronousEndpoint(isochEpDescriptorIn));
|
|
268 |
|
|
269 |
// Get the maximum packet size for this isochronous endpoint
|
|
270 |
TUint16 wMaxPacketSizeIn = isochEpDescriptorIn->TUint16At(KMaxPacketSizeOffset);
|
253
|
271 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0482_DEVICEINSERTEDL_DUP04, "wMaxPacketSizeIn = %d", wMaxPacketSizeIn);
|
0
|
272 |
CHECK(wMaxPacketSizeIn == KMaxPacketSizeInExpected);
|
|
273 |
|
|
274 |
|
|
275 |
// open pipes now.
|
|
276 |
// Out
|
253
|
277 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0482_DEVICEINSERTEDL_DUP05, "Opening a pipe to %08x",iEndpointAddressOut);
|
0
|
278 |
CHECK(iUsbInterface1.OpenPipeForEndpoint(iPipeOut,iEndpointAddressOut,EFalse) == KErrNone);
|
|
279 |
|
253
|
280 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0482_DEVICEINSERTEDL_DUP06, "Opened pipe to endpoint address %08x for isochronous transfer to device",iEndpointAddressOut);
|
0
|
281 |
|
|
282 |
// In
|
253
|
283 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0482_DEVICEINSERTEDL_DUP07, "Opening a pipe to %08x",iEndpointAddressIn);
|
0
|
284 |
CHECK(iUsbInterface2.OpenPipeForEndpoint(iPipeIn,iEndpointAddressIn,EFalse) == KErrNone);
|
|
285 |
|
253
|
286 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0482_DEVICEINSERTEDL_DUP08, "Opened pipe to endpoint address %08x for isochronous transfer to device",iEndpointAddressIn);
|
0
|
287 |
|
|
288 |
// SET_CUR class specific command
|
|
289 |
TSetCurRequest request(KHighRecordSamplingRate ,iEndpointAddressIn);
|
|
290 |
iControlEp0->SendRequest(request,this);
|
|
291 |
|
|
292 |
// Que transfers now
|
|
293 |
// Transfer IN
|
|
294 |
iIsochInTransfer = new (ELeave) CIsochTransfer(iPipeIn,iUsbInterface2,wMaxPacketSizeIn,
|
|
295 |
KIsochInMaxNumPackets ,*this, KRecordedDataId);
|
|
296 |
|
|
297 |
CHECK(iIsochInTransfer->RegisterTransferDescriptor() == KErrNone);
|
|
298 |
|
|
299 |
// Initialise the descriptors for transfer
|
253
|
300 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0482_DEVICEINSERTEDL_DUP09, "Initialising the transfer descriptors interface 2");
|
0
|
301 |
CHECK(iUsbInterface2.InitialiseTransferDescriptors() == KErrNone);
|
|
302 |
|
|
303 |
|
|
304 |
// que interrupt transfer
|
|
305 |
CHECK(iIsochInTransfer->TransferInL(KRecordedPacketsExpected) == KErrNone);
|
|
306 |
|
|
307 |
|
|
308 |
// Transfer OUT
|
|
309 |
RFs iFs;
|
|
310 |
TInt ret = KErrNone;
|
|
311 |
ret = iFs.Connect();
|
|
312 |
CHECK(ret==KErrNone || ret==KErrAlreadyExists);
|
|
313 |
RFile trackFile;
|
|
314 |
CHECK(trackFile.Open(iFs,KTrackFileName,EFileShareAny|EFileRead) == KErrNone);
|
|
315 |
|
|
316 |
|
|
317 |
TInt trackFileSize;
|
|
318 |
trackFile.Size(trackFileSize);
|
|
319 |
|
|
320 |
|
|
321 |
wMaxPacketSizeOut = KAudioCDQualityFrequency;
|
|
322 |
|
|
323 |
TInt nbChunks = trackFileSize/KChunkSize;
|
|
324 |
TInt remainderSize = trackFileSize%KChunkSize;
|
|
325 |
|
|
326 |
if(remainderSize != 0)
|
|
327 |
{
|
|
328 |
nbChunks++;
|
|
329 |
}
|
|
330 |
|
|
331 |
TInt iChunk = 0;
|
|
332 |
TInt size = KChunkSize;
|
|
333 |
|
|
334 |
// create Transfers
|
|
335 |
for(iChunk = 0; iChunk < nbChunks; iChunk++)
|
|
336 |
{
|
253
|
337 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0482_DEVICEINSERTEDL_DUP10, "iChunk = %d", iChunk);
|
0
|
338 |
|
|
339 |
// remainder(last loop)
|
|
340 |
if(remainderSize != 0 && (iChunk == nbChunks-1))
|
|
341 |
{
|
|
342 |
size = remainderSize;
|
|
343 |
}
|
|
344 |
CIsochTransfer* transfer = new (ELeave) CIsochTransfer(iPipeOut,iUsbInterface1,wMaxPacketSizeOut,
|
|
345 |
(size/wMaxPacketSizeOut),*this, iChunk);
|
|
346 |
CHECK(transfer->RegisterTransferDescriptor() == KErrNone);
|
|
347 |
iOutTransfers.AppendL(transfer);
|
|
348 |
iOutTransferBuf.Zero();
|
|
349 |
}
|
|
350 |
|
|
351 |
// Initialise the descriptors for transfer
|
253
|
352 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0482_DEVICEINSERTEDL_DUP11, "Initialising the transfer descriptors");
|
0
|
353 |
CHECK(iUsbInterface1.InitialiseTransferDescriptors() == KErrNone);
|
|
354 |
|
|
355 |
// prepare & send transfers(TODO streaming algorithm with 3 Transfers only, filling 2 while the 3rd is transferring his data)
|
|
356 |
size = KChunkSize;
|
|
357 |
for(TInt iTransfers = 0; iTransfers < iOutTransfers.Count(); iTransfers++)
|
|
358 |
{
|
253
|
359 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0482_DEVICEINSERTEDL_DUP12, "iTransfers = %d", iTransfers);
|
0
|
360 |
// remainder(last loop)
|
|
361 |
if(remainderSize != 0 && (iTransfers == iOutTransfers.Count()-1))
|
|
362 |
{
|
253
|
363 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0482_DEVICEINSERTEDL_DUP13, "remainderSize = %d", remainderSize);
|
0
|
364 |
size = remainderSize;
|
|
365 |
}
|
|
366 |
CHECK(trackFile.Read(KChunkSize*iTransfers, iOutTransferBuf, size) == KErrNone);
|
|
367 |
CHECK(iOutTransfers[iTransfers]->PrepareTransfer(iOutTransferBuf) == KErrNone);
|
|
368 |
CHECK(iOutTransfers[iTransfers]->TransferOut() == KErrNone);
|
|
369 |
iOutTransferBuf.Zero();
|
|
370 |
}
|
253
|
371 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0482_DEVICEINSERTEDL_EXIT, this );
|
0
|
372 |
}
|
|
373 |
|
|
374 |
TBool CUT_PBASE_T_USBDI_0482::ReplayRecordedData()
|
|
375 |
{
|
253
|
376 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0482_REPLAYRECORDEDDATA_ENTRY, this );
|
0
|
377 |
|
|
378 |
iOutTransferBuf.Zero();
|
|
379 |
|
|
380 |
// Transfer OUT
|
|
381 |
TInt nbChunks = iDataPolledBuf.Length()/KChunkSize;
|
|
382 |
TInt remainderSize = iDataPolledBuf.Length()%KChunkSize;
|
253
|
383 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0482_REPLAYRECORDEDDATA, "nbChunks = %d", nbChunks);
|
|
384 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0482_REPLAYRECORDEDDATA_DUP01, "remainderSize = %d", remainderSize);
|
0
|
385 |
|
|
386 |
if(remainderSize != 0)
|
|
387 |
{
|
|
388 |
nbChunks++;
|
|
389 |
}
|
|
390 |
|
|
391 |
// prepare transfers
|
|
392 |
for(TInt iTransfers = 0; iTransfers < nbChunks; iTransfers++)
|
|
393 |
{
|
253
|
394 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0482_REPLAYRECORDEDDATA_DUP02, "iTransfers = %d", iTransfers);
|
0
|
395 |
// remainder(last loop)
|
|
396 |
if(remainderSize != 0 && (iTransfers == nbChunks-1))
|
|
397 |
{
|
253
|
398 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0482_REPLAYRECORDEDDATA_DUP03, "remainderSize = %d", remainderSize);
|
0
|
399 |
}
|
|
400 |
CHECK_RET_BOOL(iOutTransfers[iTransfers]->PrepareTransfer(iDataPolledBuf) == KErrNone); // TODO retrieve relevant part of iDataPolledBuf if several chunks
|
|
401 |
CHECK_RET_BOOL(iOutTransfers[iTransfers]->TransferOut() == KErrNone);
|
|
402 |
iOutTransferBuf.Zero();
|
|
403 |
}
|
253
|
404 |
OstTraceFunctionExitExt( CUT_PBASE_T_USBDI_0482_REPLAYRECORDEDDATA_EXIT, this, ETrue );
|
0
|
405 |
return ETrue;
|
|
406 |
}
|
|
407 |
|
|
408 |
void CUT_PBASE_T_USBDI_0482::TransferCompleteL(TInt aTransferId,TInt aCompletionCode)
|
|
409 |
{
|
253
|
410 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0482_TRANSFERCOMPLETEL_ENTRY, this );
|
|
411 |
OstTraceExt2(TRACE_NORMAL, CUT_PBASE_T_USBDI_0482_TRANSFERCOMPLETEL, "Transfer completed (id=%d), aCompletionCode = %d",aTransferId, aCompletionCode);
|
0
|
412 |
Cancel();
|
|
413 |
|
|
414 |
if(aCompletionCode != KErrNone)
|
|
415 |
{
|
253
|
416 |
OstTraceExt2(TRACE_NORMAL, CUT_PBASE_T_USBDI_0482_TRANSFERCOMPLETEL_DUP01, "<Error %d> Transfer %d not successful",aCompletionCode,aTransferId);
|
0
|
417 |
TestFailed(aCompletionCode);
|
253
|
418 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0482_TRANSFERCOMPLETEL_EXIT, this );
|
0
|
419 |
return;
|
|
420 |
}
|
|
421 |
|
|
422 |
if(aTransferId == KRecordedDataId)
|
|
423 |
{
|
|
424 |
// data successfully recorded
|
|
425 |
// 1. save data recorded
|
|
426 |
CHECK(iIsochInTransfer->DataPolled(KRecordedPacketsExpected, iDataPolledBuf));
|
|
427 |
// 2. waiting now for the end of the music track
|
253
|
428 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0482_TRANSFERCOMPLETEL_EXIT_DUP01, this );
|
0
|
429 |
return;
|
|
430 |
}
|
|
431 |
|
|
432 |
switch(iCaseStep)
|
|
433 |
{
|
|
434 |
case EWaitEndOfMusicTrack:
|
|
435 |
{
|
|
436 |
if(aTransferId != iExpectedTransferId)
|
|
437 |
{
|
253
|
438 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0482_TRANSFERCOMPLETEL_DUP02, "unexpected transfer!");
|
0
|
439 |
TestFailed(KErrCorrupt);
|
|
440 |
}
|
|
441 |
iExpectedTransferId++;
|
|
442 |
// is it the last transfer?
|
|
443 |
if(iExpectedTransferId == iOutTransfers.Count())
|
|
444 |
{
|
253
|
445 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0482_TRANSFERCOMPLETEL_DUP03, "last transfer successful! lets replay recorded data");
|
0
|
446 |
|
|
447 |
iCaseStep = EReplayRecordedData; // assuming that recording is finished
|
|
448 |
TSetCurRequest request(KLowSamplingRate ,iEndpointAddressOut);
|
|
449 |
iControlEp0->SendRequest(request,this);
|
|
450 |
}
|
|
451 |
}
|
|
452 |
break;
|
|
453 |
|
|
454 |
case EReplayRecordedData:
|
|
455 |
{
|
|
456 |
TestPassed(); // TODO only one transfer used in this case(few data recorded), cope with several ones
|
|
457 |
}
|
|
458 |
break;
|
|
459 |
|
|
460 |
default:
|
|
461 |
TestFailed(KErrDisconnected);
|
|
462 |
break;
|
|
463 |
}
|
253
|
464 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0482_TRANSFERCOMPLETEL_EXIT_DUP02, this );
|
0
|
465 |
}
|
|
466 |
|
|
467 |
void CUT_PBASE_T_USBDI_0482::Ep0TransferCompleteL(TInt aCompletionCode)
|
|
468 |
{
|
253
|
469 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0482_EP0TRANSFERCOMPLETEL_ENTRY, this );
|
|
470 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0482_EP0TRANSFERCOMPLETEL, "Transfer EP0 completed aCompletionCode = %d", aCompletionCode);
|
0
|
471 |
|
|
472 |
if(aCompletionCode != KErrNone)
|
|
473 |
{
|
|
474 |
TBuf<256> msg;
|
|
475 |
msg.Format(_L("<Error %d> Transfer to control endpoint 0 was not successful"),aCompletionCode);
|
253
|
476 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0482_EP0TRANSFERCOMPLETEL_DUP01, msg);
|
|
477 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0482_EP0TRANSFERCOMPLETEL_EXIT, this );
|
0
|
478 |
return;
|
|
479 |
}
|
|
480 |
switch(iCaseStep)
|
|
481 |
{
|
|
482 |
case EWaitEndOfMusicTrack:
|
|
483 |
break;
|
|
484 |
|
|
485 |
case EReplayRecordedData:
|
|
486 |
{
|
|
487 |
CHECK(ReplayRecordedData());
|
|
488 |
}
|
|
489 |
break;
|
|
490 |
|
|
491 |
default:
|
253
|
492 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0482_EP0TRANSFERCOMPLETEL_DUP02, "<Error> Unknown test step");
|
0
|
493 |
TestFailed(KErrUnknown);
|
|
494 |
break;
|
|
495 |
}
|
253
|
496 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0482_EP0TRANSFERCOMPLETEL_EXIT_DUP01, this );
|
0
|
497 |
}
|
|
498 |
|
|
499 |
|
|
500 |
void CUT_PBASE_T_USBDI_0482::DeviceRemovedL(TUint aDeviceHandle)
|
|
501 |
{
|
253
|
502 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0482_DEVICEREMOVEDL_ENTRY, this );
|
0
|
503 |
|
|
504 |
// Manual test over
|
|
505 |
switch(iCaseStep)
|
|
506 |
{
|
|
507 |
case EFailed:
|
|
508 |
TestFailed(KErrCompletion);
|
|
509 |
break;
|
|
510 |
|
|
511 |
case EInProgress:
|
|
512 |
default:
|
|
513 |
TestFailed(KErrDisconnected);
|
|
514 |
break;
|
|
515 |
}
|
253
|
516 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0482_DEVICEREMOVEDL_EXIT, this );
|
0
|
517 |
}
|
|
518 |
|
|
519 |
|
|
520 |
void CUT_PBASE_T_USBDI_0482::BusErrorL(TInt aError)
|
|
521 |
{
|
253
|
522 |
OstTraceFunctionEntryExt( CUT_PBASE_T_USBDI_0482_BUSERRORL_ENTRY, this );
|
0
|
523 |
// This test case handles no failiures on the bus
|
|
524 |
TestFailed(KErrCompletion);
|
253
|
525 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0482_BUSERRORL_EXIT, this );
|
0
|
526 |
}
|
|
527 |
|
|
528 |
|
|
529 |
void CUT_PBASE_T_USBDI_0482::HostRunL()
|
|
530 |
{
|
253
|
531 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0482_HOSTRUNL_ENTRY, this );
|
0
|
532 |
|
|
533 |
// Obtain the completion code
|
|
534 |
TInt completionCode(iStatus.Int());
|
|
535 |
|
|
536 |
if(completionCode == KErrNone)
|
|
537 |
{
|
|
538 |
// Action timeout
|
253
|
539 |
OstTrace0(TRACE_NORMAL, CUT_PBASE_T_USBDI_0482_HOSTRUNL, "<Error> Action timeout");
|
0
|
540 |
TestFailed(KErrTimedOut);
|
|
541 |
}
|
|
542 |
else
|
|
543 |
{
|
253
|
544 |
OstTrace1(TRACE_NORMAL, CUT_PBASE_T_USBDI_0482_HOSTRUNL_DUP01, "<Error %d> Timeout timer could not complete",completionCode);
|
0
|
545 |
TestFailed(completionCode);
|
|
546 |
}
|
253
|
547 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0482_HOSTRUNL_EXIT, this );
|
0
|
548 |
}
|
|
549 |
|
|
550 |
void CUT_PBASE_T_USBDI_0482::DeviceRunL()
|
|
551 |
{
|
253
|
552 |
OstTraceFunctionEntry1( CUT_PBASE_T_USBDI_0482_DEVICERUNL_ENTRY, this );
|
|
553 |
OstTraceFunctionExit1( CUT_PBASE_T_USBDI_0482_DEVICERUNL_EXIT, this );
|
0
|
554 |
}
|
|
555 |
|
|
556 |
}
|