genericopenlibs/cstdlib/TSTLIB/tirping.c
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 /*
       
     2 * Copyright (c) 1997-2007 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 "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 
       
    18 
       
    19 #include <stdlib.h>	/* definition of exit() */
       
    20 #include <stdio.h>
       
    21 #include <errno.h>
       
    22 #include <string.h>
       
    23 #include <sys/unistd.h>
       
    24 #include <sys/ioctl.h>
       
    25 #include "CTEST.H"
       
    26 
       
    27 
       
    28 
       
    29 
       
    30 int port;
       
    31 
       
    32 /**
       
    33 @SYMTestCaseID          SYSLIB-STDLIB-CT-1105
       
    34 @SYMTestCaseDesc	    Tests for serial port
       
    35 @SYMTestPriority 	    High
       
    36 @SYMTestActions  	    Tests for notification support
       
    37 @SYMTestExpectedResults Test must not fail
       
    38 @SYMREQ                 REQ0000
       
    39 */		
       
    40 void Watcher(void)
       
    41 	{
       
    42 	int res;
       
    43 	int notify[2] = {0,0};
       
    44 	int supported = 0;
       
    45 
       
    46 
       
    47 	res = ioctl(port, COMMIOCTL_NOTIFYSUPPORTED, &supported);
       
    48 	printf("\nsupported notifies are %08lx\n",supported);
       
    49 	while (-1 != res)
       
    50 		{
       
    51 		notify[0] = supported;
       
    52 		res = ioctl(port, COMMIOCTL_NOTIFY, &notify[0]);
       
    53 		printf("\n**Notify** res = %d params %d, %d, errno %d\n",res, notify[0], notify[1],errno);
       
    54 		}
       
    55 
       
    56 	}
       
    57 
       
    58 /**
       
    59 @SYMTestCaseID          SYSLIB-STDLIB-CT-1106
       
    60 @SYMTestCaseDesc	    Tests for communication over the port
       
    61 @SYMTestPriority 	    High
       
    62 @SYMTestActions  	    Tests for reading and writing to a port back
       
    63 @SYMTestExpectedResults Test must not fail
       
    64 @SYMREQ                 REQ0000
       
    65 */		
       
    66 void ping(void)
       
    67 	{
       
    68 	char buf1[50];
       
    69 	char buf2[50];
       
    70 	char* rptr =buf1;
       
    71 	char* wptr = buf2;
       
    72 	char * tptr;
       
    73 
       
    74 
       
    75 	int err = 0;
       
    76 	int timeout = 5000;	//5 seconds
       
    77 	int threshold = -1;
       
    78 
       
    79 	printf("port is %d\n",port);
       
    80 	ioctl(port, COMMIOCTL_SETREADTHRESHOLD, &threshold);
       
    81 	ioctl(port, COMMIOCTL_SETREADTIMEOUT, &timeout);
       
    82 
       
    83 	strcpy(wptr, "ping");
       
    84 	while (err >= 0)
       
    85 		{
       
    86 		err = read(port,rptr, 50);
       
    87 		if (err >= 0)
       
    88 			{
       
    89 			rptr[err] = 0;
       
    90 			err = write(port, wptr, strlen(wptr));
       
    91 //			printf("read %s, written %s\n", rptr, wptr);
       
    92 			tptr = wptr;
       
    93 			wptr = rptr;
       
    94 			rptr = tptr;
       
    95 
       
    96 			}
       
    97 
       
    98 		}
       
    99 	}
       
   100 
       
   101 
       
   102 int main(void)
       
   103 	{
       
   104 	void* t1;
       
   105 	void* t2;
       
   106 	
       
   107 	start_posix_server();	/* calls SpawnPosixServer from C++ code */
       
   108 	
       
   109 	port = open("IRCOM1:", 0);
       
   110 	
       
   111 	t1 = create_thread(Watcher, "watcher");
       
   112 	t2 = create_thread(ping, "ping");
       
   113 	
       
   114 	start_thread(t1);
       
   115 	start_thread(t2);
       
   116 
       
   117 	wait_for_thread(t2);
       
   118 	
       
   119 	close(port);
       
   120 
       
   121 	wait_for_thread(t1);
       
   122 
       
   123 	return 0;
       
   124 	}
       
   125