test0319b.cpp

来自「应用小程序」· C++ 代码 · 共 94 行

CPP
94
字号
#include "vxworks.h"
#include "ioLib.h"
#include "pipeDrv.h"
#include "taskLib.h"
#include "string.h"
#include "stdio.h"
#include "selectLib.h"

#define STACK_SIZE 2000
#define MAX_MSGS 10
#define MAX_MSG_LEN 100
#define DELAY_TICKS 50
/*define MESSAGE "This is a test!!!"*/

int demoPipeFd;
int tidSend;
int tidReceive;

STATUS progStart();
STATUS progStop();
STATUS taskSend();
STATUS taskReceive();

STATUS progStart()
{
	if( pipeDevCreate( "/pipe/demo", MAX_MSGS, MAX_MSG_LEN ) == ERROR )
	{
		return ERROR;
	}
	demoPipeFd = open( "/pipe/demo", MAX_MSGS, MAX_MSG_LEN );
	if( demoPipeFd == ERROR )
	{
		return ERROR;
	}

	tidSend = taskSpawn( "tSend", 200, 0, STACK_SIZE, (FUNCPTR)taskSend,
				0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
	tidReceive = taskSpawn( "tReceive", 220, 0,  STACK_SIZE, (FUNCPTR)taskReceive,
				0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );

	return	OK;
}

STATUS taskSend()
{
	int temp;
	FOREVER
	{
		temp = rand();
		write( demoPipeFd,(char*)&temp, sizeof( temp ) );
		printf("shuju %d \n", temp);
		
		taskDelay( DELAY_TICKS );
	}

	return OK;
}

STATUS taskReceive()
{
	char msgBuff[MAX_MSG_LEN];
	fd_set readFd;
	int ddd;

	FOREVER
	{
		memset( msgBuff, 0, MAX_MSG_LEN );
		/*
		FD_ZERO( &readFd );
		FD_SET( demoPipeFd, &readFd );
		if( select( sizeof( fd_set ), &readFd, NULL, NULL, NULL ) <= 0 )
		{
			return ERROR;
		}*/
		read( demoPipeFd, (char *)&ddd, MAX_MSG_LEN );              
		printf( "Message is %d\n", ddd );                                                            
	}

	return OK;
}

STATUS progStop()
{	
	taskDelete( tidSend );
	taskDelete( tidReceive );

	close( demoPipeFd );
	pipeDevDelete( "/pipe/demo", TRUE );

	printf("Bye bye!!!\n");
	return OK;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?