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