os/ossrv/genericopenlibs/cstdlib/TSTLIB/tirpong.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 1997-2007 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description:
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
#include <stdlib.h>	/* definition of exit() */
sl@0
    20
#include <stdio.h>
sl@0
    21
#include <errno.h>
sl@0
    22
#include <string.h>
sl@0
    23
#include <sys/unistd.h>
sl@0
    24
#include <sys/ioctl.h>
sl@0
    25
#include "CTEST.H"
sl@0
    26
sl@0
    27
int port;
sl@0
    28
sl@0
    29
/**
sl@0
    30
@SYMTestCaseID          SYSLIB-STDLIB-CT-1107
sl@0
    31
@SYMTestCaseDesc	    Tests for serial port
sl@0
    32
@SYMTestPriority 	    High
sl@0
    33
@SYMTestActions  	    Tests for notification support
sl@0
    34
@SYMTestExpectedResults Test must not fail
sl@0
    35
@SYMREQ                 REQ0000
sl@0
    36
*/				
sl@0
    37
void Watcher(void)
sl@0
    38
	{
sl@0
    39
	int res;
sl@0
    40
	int notify[2] = {0,0};
sl@0
    41
	int supported = 0;
sl@0
    42
sl@0
    43
sl@0
    44
	res = ioctl(port, COMMIOCTL_NOTIFYSUPPORTED, &supported);
sl@0
    45
	printf("\nsupported notifies are %08lx\n",supported);
sl@0
    46
	while (-1 != res)
sl@0
    47
		{
sl@0
    48
		notify[0] = supported;
sl@0
    49
		res = ioctl(port, COMMIOCTL_NOTIFY, &notify[0]);
sl@0
    50
		printf("\n**Notify** res = %d params %d, %d, errno %d\n",res, notify[0], notify[1],errno);
sl@0
    51
		}
sl@0
    52
sl@0
    53
	}
sl@0
    54
sl@0
    55
/**
sl@0
    56
@SYMTestCaseID          SYSLIB-STDLIB-CT-1108
sl@0
    57
@SYMTestCaseDesc	    Tests for serial port
sl@0
    58
@SYMTestPriority 	    High
sl@0
    59
@SYMTestActions  	    Tests for writing and reading to a port
sl@0
    60
@SYMTestExpectedResults Test must not fail
sl@0
    61
@SYMREQ                 REQ0000
sl@0
    62
*/				
sl@0
    63
void pong(void)
sl@0
    64
	{
sl@0
    65
	char buf1[50];
sl@0
    66
	char buf2[50];
sl@0
    67
	char * rptr;
sl@0
    68
	char * wptr;
sl@0
    69
	char * tptr;
sl@0
    70
sl@0
    71
	int err = 0;
sl@0
    72
	int timeout = 5000;	//5 seconds
sl@0
    73
	int threshold = -1;
sl@0
    74
sl@0
    75
	rptr = buf1;
sl@0
    76
	wptr = buf2;
sl@0
    77
	
sl@0
    78
	printf("port is %d\n",port);
sl@0
    79
	ioctl(port, COMMIOCTL_SETREADTHRESHOLD, &threshold);
sl@0
    80
	ioctl(port, COMMIOCTL_SETREADTIMEOUT, &timeout);
sl@0
    81
sl@0
    82
	strcpy(buf2,"pong");
sl@0
    83
	while (err >= 0)
sl@0
    84
		{
sl@0
    85
		err = write(port, wptr, strlen(wptr));
sl@0
    86
		if (err >= 0)
sl@0
    87
			{
sl@0
    88
			err = read(port,rptr, 50);
sl@0
    89
			if (err >= 0)
sl@0
    90
				{
sl@0
    91
				rptr[err] = 0;
sl@0
    92
//				printf ("read %s, written %s\n",rptr, wptr);
sl@0
    93
				tptr = rptr;
sl@0
    94
				rptr = wptr;
sl@0
    95
				wptr = tptr;
sl@0
    96
				}
sl@0
    97
			}
sl@0
    98
		}
sl@0
    99
sl@0
   100
	}
sl@0
   101
sl@0
   102
sl@0
   103
int main(void)
sl@0
   104
	{
sl@0
   105
	void* t1;
sl@0
   106
	void* t2;
sl@0
   107
	
sl@0
   108
	start_posix_server();	/* calls SpawnPosixServer from C++ code */
sl@0
   109
	
sl@0
   110
	port = open("IRCOM1:", 0);
sl@0
   111
	
sl@0
   112
	t1 = create_thread(Watcher, "watcher");
sl@0
   113
	t2 = create_thread(pong, "pong");
sl@0
   114
	
sl@0
   115
	start_thread(t1);
sl@0
   116
	start_thread(t2);
sl@0
   117
sl@0
   118
	wait_for_thread(t2);
sl@0
   119
	
sl@0
   120
	close(port);
sl@0
   121
sl@0
   122
	wait_for_thread(t1);
sl@0
   123
sl@0
   124
	return 0;
sl@0
   125
	}
sl@0
   126