sl@0
|
1 |
// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// e32test\misc\t_ymodem.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <e32test.h>
|
sl@0
|
19 |
#include "ymodemu.h"
|
sl@0
|
20 |
#include <f32file.h>
|
sl@0
|
21 |
|
sl@0
|
22 |
RTest test(_L("YModem"));
|
sl@0
|
23 |
|
sl@0
|
24 |
#define TEST(c) ((void)((c)||(test.Printf(_L("Failed at line %d\n"),__LINE__),test.Getch(),test(0),0)))
|
sl@0
|
25 |
|
sl@0
|
26 |
const TInt KBufferSize=4096;
|
sl@0
|
27 |
|
sl@0
|
28 |
_LIT(KLddName,"ECOMM");
|
sl@0
|
29 |
_LIT(KPddName,"EUART");
|
sl@0
|
30 |
|
sl@0
|
31 |
void LoadCommDrivers()
|
sl@0
|
32 |
{
|
sl@0
|
33 |
test.Printf(_L("Load LDD\n"));
|
sl@0
|
34 |
TInt r=User::LoadLogicalDevice(KLddName);
|
sl@0
|
35 |
TEST(r==KErrNone || r==KErrAlreadyExists);
|
sl@0
|
36 |
|
sl@0
|
37 |
TInt i;
|
sl@0
|
38 |
TInt n=0;
|
sl@0
|
39 |
for (i=-1; i<10; ++i)
|
sl@0
|
40 |
{
|
sl@0
|
41 |
TBuf<16> pddName=KPddName();
|
sl@0
|
42 |
if (i>=0)
|
sl@0
|
43 |
pddName.Append('0'+i);
|
sl@0
|
44 |
TInt r=User::LoadPhysicalDevice(pddName);
|
sl@0
|
45 |
if (r==KErrNone || r==KErrAlreadyExists)
|
sl@0
|
46 |
{
|
sl@0
|
47 |
++n;
|
sl@0
|
48 |
test.Printf(_L("%S found\n"),&pddName);
|
sl@0
|
49 |
}
|
sl@0
|
50 |
}
|
sl@0
|
51 |
TEST(n!=0);
|
sl@0
|
52 |
}
|
sl@0
|
53 |
|
sl@0
|
54 |
GLDEF_C TInt E32Main()
|
sl@0
|
55 |
{
|
sl@0
|
56 |
RThread().SetPriority(EPriorityAbsoluteForeground);
|
sl@0
|
57 |
test.SetLogged(EFalse);
|
sl@0
|
58 |
test.Title();
|
sl@0
|
59 |
|
sl@0
|
60 |
TBuf<256> cmd;
|
sl@0
|
61 |
User::CommandLine(cmd);
|
sl@0
|
62 |
TInt port=0;
|
sl@0
|
63 |
if (cmd.Length()!=0)
|
sl@0
|
64 |
{
|
sl@0
|
65 |
TUint8 c=(TUint8)cmd[0];
|
sl@0
|
66 |
if (c>='0' && c<='9')
|
sl@0
|
67 |
{
|
sl@0
|
68 |
port=c-'0';
|
sl@0
|
69 |
}
|
sl@0
|
70 |
}
|
sl@0
|
71 |
|
sl@0
|
72 |
TInt r=KErrNone;
|
sl@0
|
73 |
LoadCommDrivers();
|
sl@0
|
74 |
|
sl@0
|
75 |
test.Next(_L("Connect to file server"));
|
sl@0
|
76 |
RFs fs;
|
sl@0
|
77 |
r=fs.Connect();
|
sl@0
|
78 |
test(r==KErrNone);
|
sl@0
|
79 |
|
sl@0
|
80 |
test.Next(_L("Create YModem object"));
|
sl@0
|
81 |
YModemU* pY=NULL;
|
sl@0
|
82 |
TRAP(r,pY=YModemU::NewL(port,ETrue));
|
sl@0
|
83 |
test(r==KErrNone && pY!=NULL);
|
sl@0
|
84 |
|
sl@0
|
85 |
test.Next(_L("Create buffer"));
|
sl@0
|
86 |
TUint8* buffer=(TUint8*)User::Alloc(KBufferSize);
|
sl@0
|
87 |
test(buffer!=NULL);
|
sl@0
|
88 |
|
sl@0
|
89 |
test.Start(_L("Receive..."));
|
sl@0
|
90 |
|
sl@0
|
91 |
TBool mode=1;
|
sl@0
|
92 |
FOREVER
|
sl@0
|
93 |
{
|
sl@0
|
94 |
TInt total_size=0;
|
sl@0
|
95 |
TInt size=-1;
|
sl@0
|
96 |
TBuf<256> name;
|
sl@0
|
97 |
r=pY->StartDownload(mode, size, name);
|
sl@0
|
98 |
if (r!=KErrNone)
|
sl@0
|
99 |
break;
|
sl@0
|
100 |
test.Printf(_L("r=%d, size=%d, name %S\n"),r,size,&name);
|
sl@0
|
101 |
if (r==KErrNone)
|
sl@0
|
102 |
{
|
sl@0
|
103 |
test.Printf(_L("Opening file for write\n"));
|
sl@0
|
104 |
RFile file;
|
sl@0
|
105 |
r=file.Replace(fs,name,EFileWrite);
|
sl@0
|
106 |
if (r!=KErrNone)
|
sl@0
|
107 |
{
|
sl@0
|
108 |
test.Printf(_L("RFile::Replace returns %d\n"),r);
|
sl@0
|
109 |
test.Getch();
|
sl@0
|
110 |
test(0);
|
sl@0
|
111 |
}
|
sl@0
|
112 |
while (r==KErrNone)
|
sl@0
|
113 |
{
|
sl@0
|
114 |
TUint8* pD=buffer;
|
sl@0
|
115 |
r=pY->ReadPackets(pD,KBufferSize);
|
sl@0
|
116 |
if (r==KErrNone || r==KErrEof)
|
sl@0
|
117 |
{
|
sl@0
|
118 |
TInt blen=pD-buffer;
|
sl@0
|
119 |
if (size>0) // size was transmitted
|
sl@0
|
120 |
{
|
sl@0
|
121 |
if (blen>size-total_size)
|
sl@0
|
122 |
blen=size-total_size;
|
sl@0
|
123 |
}
|
sl@0
|
124 |
total_size+=blen;
|
sl@0
|
125 |
TPtrC8 fptr(buffer,blen);
|
sl@0
|
126 |
TInt s=file.Write(fptr);
|
sl@0
|
127 |
if (s!=KErrNone)
|
sl@0
|
128 |
{
|
sl@0
|
129 |
test.Printf(_L("RFile::Write returns %d\n"),s);
|
sl@0
|
130 |
test.Getch();
|
sl@0
|
131 |
test(0);
|
sl@0
|
132 |
}
|
sl@0
|
133 |
}
|
sl@0
|
134 |
}
|
sl@0
|
135 |
file.Close();
|
sl@0
|
136 |
test.Printf(_L("rx size=%d\n"),total_size);
|
sl@0
|
137 |
}
|
sl@0
|
138 |
}
|
sl@0
|
139 |
delete buffer;
|
sl@0
|
140 |
delete pY;
|
sl@0
|
141 |
fs.Close();
|
sl@0
|
142 |
test.Printf(_L("r=%d\n"),r);
|
sl@0
|
143 |
test.Getch();
|
sl@0
|
144 |
|
sl@0
|
145 |
return KErrNone;
|
sl@0
|
146 |
}
|