Update contrib.
2 * Copyright (c) 1997-2005 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #include <stdlib.h> /* definition of exit() */
23 #include <sys/unistd.h>
24 #include <sys/ioctl.h>
30 void DoSharedStuff(void)
34 p1 = open("COM1:", 1);
35 p2 = open("COM1:", 1);
37 //try changing the settings
38 ret = ioctl(p1, COMMIOCTL_GETCONFIG, &config);
40 config.iRate = Bps115200;
41 ret = ioctl(p2, COMMIOCTL_SETCONFIG, &config);
43 config.iRate = Bps1200;
44 ret = ioctl(p1, COMMIOCTL_GETCONFIG, &config);
47 config.iRate = Bps1200;
48 ret = ioctl(p1, COMMIOCTL_GETCONFIG, &config);
52 void OpenAndConfigure(void)
57 GlobalPort = open("COM1:",0);
58 res = ioctl(GlobalPort, COMMIOCTL_GETCONFIG, &sc);
60 sc.iParity = ParityNone;
61 res = ioctl(GlobalPort, COMMIOCTL_SETCONFIG, &sc);
65 void WaitAndRead(void)
67 int port = GlobalPort;
71 printf("Wait and read\n");
72 ret = read(port, buffer, 10);
73 printf("got it %x\n",buffer[0]);
79 int port = GlobalPort;
81 sprintf(bob, "Test Write >>%d<< >>%x<<\n", x, x);
82 write(port, bob, strlen(bob));
100 port1 = open("COM1:", 0);
102 //this one should fail
103 port2 = open("COM1:", 0);
107 //play with the signals
110 ret = ioctl(port1, COMMIOCTL_SETSIGNALS, &sigs[0]);
111 ret = ioctl(port1, COMMIOCTL_GETSIGNALS, &sig);
113 ret = ioctl(port1, COMMIOCTL_BREAK, &sig);
117 port1 = open("COM1:", 0);
118 port2 = open("COM2:",0);
130 ret = ioctl(port2, COMMIOCTL_SETREADTIMEOUT, &timeout);
132 ret = ioctl(port2, COMMIOCTL_GETREADTIMEOUT, &timeout);
136 ret = ioctl(port2, COMMIOCTL_SETREADTHRESHOLD, &threshold);
138 ret = ioctl(port2, COMMIOCTL_GETREADTHRESHOLD, &threshold);
143 ret = ioctl(port1, COMMIOCTL_GETBUFFERLENGTH, &len);
146 ret = ioctl(port1, COMMIOCTL_SETBUFFERLENGTH, &len);
149 ret = ioctl(port1, COMMIOCTL_GETBUFFERLENGTH, &len);
152 ret = ioctl(port1, COMMIOCTL_SETBUFFERLENGTH, &len);
155 ret = ioctl(port1, COMMIOCTL_GETBUFFERLENGTH, &len);
158 //try changing the settings
159 ret = ioctl(port1, COMMIOCTL_GETCONFIG, &config);
161 config.iRate = Bps115200;
162 ret = ioctl(port1, COMMIOCTL_SETCONFIG, &config);
164 config.iRate = Bps1200;
165 ret = ioctl(port1, COMMIOCTL_GETCONFIG, &config);
168 timeout = threshold = -1;
169 ret = ioctl(port1, COMMIOCTL_SETREADTHRESHOLD, &threshold);
170 ret = ioctl(port1, COMMIOCTL_SETREADTIMEOUT, &timeout);
172 printf("Talk to me, ESC to exit\n");
175 ret = read(port1, buffer, size);
177 printf("look what I got >>> %c\t%x\n",buffer[0],buffer[0]);
179 printf("error, errno is %x \n",errno);
181 while (buffer[0] != 27);
183 printf("Talk to me in blocks of 5, EXIT! to exit\n");
185 ret = ioctl(port1, COMMIOCTL_SETREADTHRESHOLD, &threshold);
188 ret = read(port1, buffer, size);
192 printf("look what I got >>> %s\n",buffer);
197 while (strcmp(buffer, "EXIT!"));
198 printf("Wait 10 seconds then give up\n");
200 ret = ioctl(port1, COMMIOCTL_SETREADTIMEOUT, &timeout);
202 ret = ioctl(port1, COMMIOCTL_SETREADTHRESHOLD, &threshold);
203 ret = read(port1, buffer, size);
205 printf("look what I got >>> %c\t%x\n",buffer[0],buffer[0]);
210 //no threshold, but with a 5 second timeout
211 printf("Now for the hard one!\n");
213 ret = ioctl(port1, COMMIOCTL_SETREADTIMEOUT, &timeout);
215 ret = ioctl(port1, COMMIOCTL_SETREADTHRESHOLD, &threshold);
216 ret = read(port1, buffer, size);
218 printf("got an error, errno is 56 if it a timeout. erno = %d\n", errno);
220 printf("look what I got >>> %c\t%x\n",buffer[0],buffer[0]);
222 printf("Going to write some stuff now\n");
223 ret = write(port1, "Lardy dardy dardy cheese\n\n",26);
224 printf("Written some stuff now and got a ret of %d\n", ret);
233 printf("Press key to exit");
242 int port = open("IRCOM:0", 0);
244 strcpy(buf,"test shot #");
247 write(port, buf, strlen(buf));
258 int port = open("IRCOM:0", 0);
263 write(port, buf, strlen(buf));
269 @SYMTestCaseID SYSLIB-STDLIB-CT-1112
270 @SYMTestCaseDesc Tests for serial port
271 @SYMTestPriority High
272 @SYMTestActions Notifies a thread for events on port
273 @SYMTestExpectedResults Test must not fail
276 void WaitForNotifyThread(void)
283 val[0] = KNotifyFramingError|KNotifyOverrunError|KNotifyParityError;
285 ret = ioctl(GlobalPort, COMMIOCTL_NOTIFY, &val[0]);
286 printf("NotifyThread ret = %d, val[0] is %d, val[1] is %d\n", ret, val[0], val[1]);
291 @SYMTestCaseID SYSLIB-STDLIB-CT-1113
292 @SYMTestCaseDesc Tests for serial port
293 @SYMTestPriority High
294 @SYMTestActions Keep reading infinitely from the port
295 @SYMTestExpectedResults Test must not fail
304 read(GlobalPort, buf, 100);
305 printf("ReadThread got %x\n", buf[0]);
320 // printf("Do it again using the CPosixServer\n");
322 start_posix_server(); /* calls SpawnPosixServer from C++ code */
324 // client=create_thread(DoTests, "serial tests");
325 // start_thread(client);
326 // err=wait_for_thread(client);
329 // t3 = create_thread(OpenAndConfigure,"cfg");
331 // err=wait_for_thread(t3);
333 // t1 = create_thread(WaitAndRead, "open and wait");
334 // t2 = create_thread(writelots, "writelots");
337 // err=wait_for_thread(t1);
338 // err=wait_for_thread(t2);
339 // close(GlobalPort);
343 t1 = create_thread(WaitForNotifyThread, "notify");
344 t2 = create_thread(readloop, "readloop");
349 err=wait_for_thread(t2);
350 err=wait_for_thread(t1);