⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 serialrpc.c

📁 基于psos操作系统的dec21140驱动
💻 C
字号:
/*
 *  +-------------------------------------------------------------------+
 *  | Copyright (c) 1999,2000 TriMedia Technologies Inc.                |
 *  |                                                                   |
 *  | This software  is furnished under a license  and may only be used |
 *  | and copied in accordance with the terms  and conditions of such a |
 *  | license  and with  the inclusion of this  copyright notice.  This |
 *  | software or any other copies of this software may not be provided |
 *  | or otherwise  made available  to any other person.  The ownership |
 *  | and title of this software is not transferred.                    |
 *  |                                                                   |
 *  | The information  in this software  is subject  to change  without |
 *  | any  prior notice  and should not be construed as a commitment by |
 *  | TriMedia Technologies.                                            |
 *  |                                                                   |
 *  | This  code  and  information  is  provided  "as is"  without  any |
 *  | warranty of any kind,  either expressed or implied, including but |
 *  | not limited  to the implied warranties  of merchantability and/or |
 *  | fitness for any particular purpose.                               |
 *  +-------------------------------------------------------------------+
 *
 *
 *  Module name              : SerialRPC.c    1.3
 *
 *  Last update              : 14:50:35 - 00/06/19
 *
 *  Title                    : Serial communication driver for ANSI I/O,
 *                             host side
 *
 *  Description              : This file is a serial driver that completes
 *                             the generic serial rpc server that can be
 *                             found in $(TCS)/lib/$(UNAME)/serial_host_comm.a.
 *                             Such a completed serial rpc server can be used
 *                             for serving the I/O of a TM1 program that has
 *                             been linked with host 'serial', and that has
 *                             been completed with the TM-1 counterpart
 *                             of this serial driver.
 *
 *                             This particular serial driver communicates
 *                             with the serial TM-1 application via tcp/ip,  
 *                             using a socket as serial connection. 
 *                             The host/port name is currently hardcoded in
 *                             this driver, and the dll path is set to the
 *                             current directory only (see main program),
 *                             but this can be easily changed.
 *
 *                             Starting a TM-1 application and its serial server
 *                             is to be performed using the following steps:
 * 
 *                             1) start the TM-1 application. This application
 *                                is to be linked with the target counterpart
 *                                of this serial driver, and has to have network
 *                                access.
 *
 *                             2) start the serial server on a PC or Unix machine
 *                                that can reach the TM-1 application via tcp/ip.
 *                                Stdin, stdout/stderr of the TM-1 application 
 *                                will be mapped to the stdin, stdout/stderr of the
 *                                server process (on PC or Unix), and file I/O will
 *                                be effectively performed by this same server process.
 */

/*--------------------------- Includes ---------------------------------------*/

#include "errno.h"
#include "stdio.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <tmtypes.h>
#include <assert.h>

/*------------------------------- Reading / Writing --------------------------*/



static Int g_socket;


void SerialRPC_write_buffer(Pointer buffer, Int32 size)
{
        Address p= buffer;
        Int     s;

        while (size > 0) {
            s= send(g_socket, p, size, 0);
            assert( s > 0 );
            p    += s;
            size -= s;
        }
}


void SerialRPC_read_buffer(Pointer buffer, Int32 size)
{
        Address p= buffer;
        Int     s;

        while (size > 0) {
            s= recv(g_socket, p, size, 0);
            assert( s > 0 );
            p    += s;
            size -= s;
        }
}



Bool SerialRPC_init()
{
    return True;
}
   

/*--------------------------- Initialisation / Termination -------------------*/

Int32 main(Int argc, String argv[])
{
	struct sockaddr_in addr;
	UInt32             port     = 3357;
	String             hostname = "130.140.33.180";
	UInt32             iaddr;
	Bool               result;
	struct hostent    *hp;
        UInt x1,x2,x3,x4;
	
	hp = gethostbyname(hostname);
	
	if (hp != Null) {
            assert(hp->h_length == sizeof(UInt32));
	    memcpy(&iaddr, hp->h_addr_list[0], hp->h_length);
        } else
        if (sscanf(hostname, "%d.%d.%d.%d", &x1,&x2,&x3,&x4) == 4 ) {
            iaddr= x1<<24 | x2<<16 | x3<<8 | x4;
        } else {
	    printf("Unknown host: %s\n", hostname);
	    exit(1);
	} 

	addr.sin_family      = AF_INET;
	addr.sin_addr.s_addr = iaddr;
	addr.sin_port        = htons(port);
	
	g_socket = socket(AF_INET, SOCK_STREAM, 0);
	
	result= connect(g_socket, &addr, sizeof (struct sockaddr_in)) != -1;
	
	if (result) {
	    printf("Connected to %s, port %d for RPC serving\n", hostname, port );
	} else {
	    printf("Failed to connect to %s, port %d for RPC serving\n", hostname, port );
	}
	
        OpenDll_add_dll_path(".");

	return _serial_main(argc,argv);
}

⌨️ 快捷键说明

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