|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "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 // test_client_wintunnel.cpp |
|
15 // System Includes |
|
16 // |
|
17 // |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <e32test.h> |
|
21 #include <e32svr.h> |
|
22 #include <c32comm.h> |
|
23 |
|
24 /******************************************************************************** |
|
25 * |
|
26 * Local Includes |
|
27 * |
|
28 *******************************************************************************/ |
|
29 #include "f32file.h" |
|
30 #include "CommonFiles.h" |
|
31 |
|
32 /******************************************************************************** |
|
33 * |
|
34 * Constants |
|
35 * |
|
36 *******************************************************************************/ |
|
37 |
|
38 // Driver names |
|
39 _LIT(PDD_NAME,"ECDRV"); |
|
40 _LIT(LDD_NAME,"ECOMM"); |
|
41 _LIT(CSY_NAME, "ECUART" ); |
|
42 _LIT(PORT_NAME,"COMM::1"); |
|
43 |
|
44 // Test data |
|
45 const TInt DATA_STRING_LENGTH (45); |
|
46 _LIT8(DATA_STRING,"Diana is the greatest person who ever lived\n\r"); |
|
47 |
|
48 // Other |
|
49 const TTimeIntervalMicroSeconds32 KTimeOut(4000000); |
|
50 |
|
51 /******************************************************************************** |
|
52 * |
|
53 * Prototypes |
|
54 * |
|
55 *******************************************************************************/ |
|
56 LOCAL_C void Init(); |
|
57 |
|
58 /******************************************************************************** |
|
59 * |
|
60 * Implementation |
|
61 * |
|
62 *******************************************************************************/ |
|
63 LOCAL_C void doExampleL() |
|
64 { |
|
65 _LIT(KStatus0,"Connect to file server\n"); |
|
66 _LIT(KStatus1,"Connect to comm server\n"); |
|
67 _LIT(KStatus2,"Load ECUART.CSY\n"); |
|
68 _LIT(KStatus3,"Open COMM::1\n"); |
|
69 _LIT(KStatus4,"Writing to the port...\n"); |
|
70 _LIT(KStatus4a,"Reading from the port...\n"); |
|
71 _LIT(KStatus5,"Closing the port...\n"); |
|
72 _LIT(KStatus6,"Closing the server connection...\n"); |
|
73 _LIT(KSuccess,"Successfully read string from the port.\n"); |
|
74 _LIT(KFailure,"Failed reading string from the port.\n"); |
|
75 |
|
76 |
|
77 // connect to the file server |
|
78 console->Printf( KStatus0 ); |
|
79 RFs f; |
|
80 User::LeaveIfError(f.Connect()); |
|
81 f.Close(); |
|
82 |
|
83 // load up the drivers |
|
84 Init(); |
|
85 |
|
86 // start the serial server |
|
87 RCommServ server; |
|
88 console->Printf(KStatus1); |
|
89 server.Connect(); |
|
90 |
|
91 // load the plugin |
|
92 console->Printf(KStatus2); |
|
93 TInt ret=server.LoadCommModule(CSY_NAME); |
|
94 User::LeaveIfError(ret); |
|
95 |
|
96 // open the port |
|
97 RComm commPort; |
|
98 console->Printf(KStatus3); |
|
99 ret=commPort.Open(server,PORT_NAME,ECommExclusive); |
|
100 User::LeaveIfError(ret); |
|
101 |
|
102 // write to the port |
|
103 TRequestStatus status; |
|
104 console->Printf(KStatus4); |
|
105 commPort.Write(status,KTimeOut,DATA_STRING); |
|
106 User::WaitForRequest(status); |
|
107 User::LeaveIfError(status.Int()); |
|
108 |
|
109 // read from the port |
|
110 TBuf8<DATA_STRING_LENGTH> rbuf; |
|
111 console->Printf(KStatus4a); |
|
112 commPort.Read( status, rbuf ); |
|
113 User::WaitForRequest(status); |
|
114 User::LeaveIfError(status.Int()); |
|
115 |
|
116 //check the string matches |
|
117 if(rbuf==DATA_STRING) |
|
118 { |
|
119 console->Printf(KSuccess); |
|
120 } |
|
121 else |
|
122 { |
|
123 console->Printf(KFailure); |
|
124 } |
|
125 |
|
126 // close port and server |
|
127 console->Printf(KStatus5); |
|
128 commPort.Close(); |
|
129 console->Printf(KStatus6); |
|
130 server.Close(); |
|
131 } |
|
132 |
|
133 |
|
134 LOCAL_C void Init() |
|
135 // |
|
136 // Initialisation code - loads the serial LDD and PDD |
|
137 // starts the comm subsystem (for EPOC32 builds) |
|
138 // On a full Symbian OS implementation, this code would not |
|
139 // be required because higher level GUI components |
|
140 // automatically start the services. |
|
141 // |
|
142 { |
|
143 // Load the physical device driver |
|
144 // The OS will automatically append .PDD and |
|
145 // search /System/Libs on all drives. |
|
146 |
|
147 TInt r=User::LoadPhysicalDevice(PDD_NAME); |
|
148 if (r != KErrNone && r!= KErrAlreadyExists) |
|
149 User::Leave(r); |
|
150 r=User::LoadLogicalDevice(LDD_NAME); |
|
151 if (r != KErrNone && r != KErrAlreadyExists) |
|
152 User::Leave(r); |
|
153 |
|
154 #if defined (__EPOC32__) |
|
155 // For EPOC builds we need to start the comms subsystem |
|
156 // This call actually starts the comms server process |
|
157 r=StartC32(); |
|
158 if (r != KErrAlreadyExists) |
|
159 User::LeaveIfError(r); |
|
160 #endif |
|
161 } |
|
162 |
|
163 |