Jul 9, 2003

          onlgw, Red Hat Linux 9 のシステムでのJavaRMIの実行
                 ---  リモートマシンからの例題ソフトの実行  #5
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                  (http://www-online.kek.jp/~inoue/para-CAMAC/
                                   Work/CAMAC-JavaRMI5.html)



                        高エネルギー加速器研究機構
                            素粒子原子核研究所
                         物理、オンライングループ
                                井上 栄二



	目的

	    リモートマシン onlnote2 から、CC/NET上のSBCである onlsbc1 を
	    ターゲットマシンとして、JavaRMIとJNIを使ったWebアプリケーションで
	  CAMAC read/write を実行する。


	(1). 構成
	(2). ソフトウェア
	(3). 実行

  --------------------------------------------------------------------


 (1). 構成

	テストに使用するマシンは onlnote2 と onlsbc1 である。 マシン onlnote2 は
	Windows XP が動作している。 Java1.4.1_02 である。 一方 onlsbc1 は、
	アドバンテク社のSBC、PCM-9370である。 このSBCは、CAMACコントローラ上に
	装着されている。 SBC上で動作している OSは Red Hat Linux 8.0 で、コンパク
	トフラッシュ上に構成してある。 Javaのバージョンは1.4.1_02 である。


 (2). ソフトウェア


	CC/NETのSBC、ホスト名onlsbc1のURLをリモートマシンからアクセスすることで
	CAMACへの read/write が実行できるような例題を作る。

   (2-1).  サーバ側、onlsbc1.kek.jp

     (2-1-1).  Javaのチェック

[inoue@onlsbc1 Web]$ java -version
java version "1.4.1_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_02-b06)
Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode)
[inoue@onlsbc1 Web]$


     (2-1-2).  実行環境

[inoue@onlsbc1 Web]$ env
HOSTNAME=onlsbc1.kek.jp
TERM=vt100
SHELL=/bin/bash
JLESSCHARSET=japanese
HISTSIZE=1000
SSH_CLIENT=130.87.153.116 32973 22
SSH_TTY=/dev/pts/0
USER=inoue
LS_COLORS=no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;0
1:or=01;05;37;41:mi=01;05;37;41:ex=01;32:*.cmd=01;32:*.exe=01;32:*.com=01;32:*.b
tm=01;32:*.bat=01;32:*.sh=01;32:*.csh=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:
*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*
.bz=01;31:*.tz=01;31:*.rpm=01;31:*.cpio=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=01;3
5:*.xbm=01;35:*.xpm=01;35:*.png=01;35:*.tif=01;35:
MAIL=/var/spool/mail/inoue
PATH=/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/usr/java/bin:/home/inoue/bin
INPUTRC=/etc/inputrc
PWD=/mnt/inoue/Web
LANG=ja_JP.eucJP
SHLVL=1
HOME=/home/inoue
LOGNAME=inoue
LESSOPEN=|/usr/bin/lesspipe.sh %s
G_BROKEN_FILENAMES=1
_=/bin/env
OLDPWD=/mnt/inoue
[inoue@onlsbc1 Web]$


     (2-1-3).  ソフトウェア(その1)

	HelloWorld をアプレットで実行してみる。

[inoue@onlsbc1 inoue]$ pwd
/home/inoue
[inoue@onlsbc1 inoue]$ ls
[inoue@onlsbc1 inoue]$ mkdir -p public_html/myclasses
[inoue@onlsbc1 inoue]$ ls -lR
.:
合計 1
drwxrwxr-x    3 inoue    inoue        1024  6月 16 09:06 public_html

./public_html:
合計 1
drwxrwxr-x    2 inoue    inoue        1024  6月 16 09:06 myclasses

./public_html/myclasses:
合計 0
[inoue@onlsbc1 inoue]$

[inoue@onlsbc1 hello]$ pwd
/mnt/inoue/JavaRMI/getStart/examples/hello
[inoue@onlsbc1 hello]$ ls -l
合計 20
-rw-r--r--    1 inoue    inoue        1998  1月 25  2002 Hello.java
-rw-r--r--    1 inoue    inoue        2574  1月 25  2002 HelloApplet.java
-rw-r--r--    1 inoue    inoue        2779  1月 25  2002 HelloImpl.java
-rw-r--r--    1 inoue    inoue         245  9月 30  1998 hello.html
-rw-r--r--    1 inoue    inoue          81  9月 30  1998 policy
[inoue@onlsbc1 hello]$ export CLASSPATH=.:$HOME/public_html/myclasses
[inoue@onlsbc1 hello]$ env
HOSTNAME=onlsbc1.kek.jp
TERM=vt100
SHELL=/bin/bash
JLESSCHARSET=japanese
HISTSIZE=1000
SSH_CLIENT=130.87.153.116 32977 22
OLDPWD=/home/inoue
SSH_TTY=/dev/pts/0
USER=inoue
LS_COLORS=no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;0
1:or=01;05;37;41:mi=01;05;37;41:ex=01;32:*.cmd=01;32:*.exe=01;32:*.com=01;32:*.b
tm=01;32:*.bat=01;32:*.sh=01;32:*.csh=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:
*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*
.bz=01;31:*.tz=01;31:*.rpm=01;31:*.cpio=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=01;3
5:*.xbm=01;35:*.xpm=01;35:*.png=01;35:*.tif=01;35:
MAIL=/var/spool/mail/inoue
PATH=/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/usr/java/bin:/home/inoue/bin
INPUTRC=/etc/inputrc
PWD=/mnt/inoue/JavaRMI/getStart/examples/hello
LANG=ja_JP.eucJP
SHLVL=1
HOME=/home/inoue
LOGNAME=inoue
CLASSPATH=.:/home/inoue/public_html/myclasses
LESSOPEN=|/usr/bin/lesspipe.sh %s
G_BROKEN_FILENAMES=1
_=/bin/env
[inoue@onlsbc1 hello]$

[inoue@onlsbc1 hello]$ javac -d $HOME/public_html/myclasses Hello.java HelloImpl
.java HelloApplet.java
[inoue@onlsbc1 hello]$ ls -l ls -lR $HOME/public_html/myclasses
/home/inoue/public_html/myclasses:
合計 1
drwxrwxr-x    3 inoue    inoue        1024  6月 16 09:24 examples

/home/inoue/public_html/myclasses/examples:
合計 1
drwxrwxr-x    2 inoue    inoue        1024  6月 16 09:24 hello

/home/inoue/public_html/myclasses/examples/hello:
合計 5
-rw-rw-r--    1 inoue    inoue         224  6月 16 09:24 Hello.class
-rw-rw-r--    1 inoue    inoue        1284  6月 16 09:24 HelloApplet.class
-rw-rw-r--    1 inoue    inoue        1247  6月 16 09:24 HelloImpl.class
[inoue@onlsbc1 hello]$

[inoue@onlsbc1 hello]$ pwd
/mnt/inoue/JavaRMI/getStart/examples/hello
[inoue@onlsbc1 hello]$ ls -l
合計 20
-rw-r--r--    1 inoue    inoue        1998  1月 25  2002 Hello.java
-rw-r--r--    1 inoue    inoue        2574  1月 25  2002 HelloApplet.java
-rw-r--r--    1 inoue    inoue        2779  1月 25  2002 HelloImpl.java
-rw-r--r--    1 inoue    inoue         245  9月 30  1998 hello.html
-rw-r--r--    1 inoue    inoue          81  9月 30  1998 policy
[inoue@onlsbc1 hello]$ cat Hello.java
/*
 * Copyright 2002 Sun Microsystems, Inc. All  Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or
 * without modification, are permitted provided that the following
 * conditions are met:
 *
 * -Redistributions of source code must retain the above copyright
 *  notice, this list of conditions and the following disclaimer.
 *
 * -Redistribution in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in
 *  the documentation and/or other materials provided with the
 *  distribution.
 *
 * Neither the name of Sun Microsystems, Inc. or the names of
 * contributors may be used to endorse or promote products derived
 * from this software without specific prior written permission.
 *
 * This software is provided "AS IS," without a warranty of any
 * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
 * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY
 * DAMAGES OR LIABILITIES  SUFFERED BY LICENSEE AS A RESULT OF OR
 * RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR
 * ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE
 * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT,
 * SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF
 * THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 *
 * You acknowledge that Software is not designed, licensed or
 * intended for use in the design, construction, operation or
 * maintenance of any nuclear facility.
 */

package examples.hello;

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface Hello extends Remote {
    String sayHello() throws RemoteException;
}
[inoue@onlsbc1 hello]$

[inoue@onlsbc1 hello]$ cat HelloApplet.java
/*
 * Copyright 2002 Sun Microsystems, Inc. All  Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or
 * without modification, are permitted provided that the following
 * conditions are met:
 *
 * -Redistributions of source code must retain the above copyright
 *  notice, this list of conditions and the following disclaimer.
 *
 * -Redistribution in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in
 *  the documentation and/or other materials provided with the
 *  distribution.
 *
 * Neither the name of Sun Microsystems, Inc. or the names of
 * contributors may be used to endorse or promote products derived
 * from this software without specific prior written permission.
 *
 * This software is provided "AS IS," without a warranty of any
 * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
 * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY
 * DAMAGES OR LIABILITIES  SUFFERED BY LICENSEE AS A RESULT OF OR
 * RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR
 * ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE
 * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT,
 * SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF
 * THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 *
 * You acknowledge that Software is not designed, licensed or
 * intended for use in the design, construction, operation or
 * maintenance of any nuclear facility.
 */

package examples.hello;

import java.applet.Applet;
import java.awt.Graphics;
import java.rmi.Naming;
import java.rmi.RemoteException;

public class HelloApplet extends Applet {

    String message = "blank";

    // "obj" is the identifier that we'll use to refer
    // to the remote object that implements the "Hello"
    // interface
    Hello obj = null;

    public void init() {
        try {
            obj = (Hello)Naming.lookup("//" +
                         getCodeBase().getHost() + "/HelloServer");
            message = obj.sayHello();
        } catch (Exception e) {
            System.out.println("HelloApplet exception: " +
                                    e.getMessage());
            e.printStackTrace();
        }
    }

    public void paint(Graphics g) {
        g.drawString(message, 25, 50);
    }
}
[inoue@onlsbc1 hello]$

[inoue@onlsbc1 hello]$ cat HelloImpl.java
/*
 * Copyright 2002 Sun Microsystems, Inc. All  Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or
 * without modification, are permitted provided that the following
 * conditions are met:
 *
 * -Redistributions of source code must retain the above copyright
 *  notice, this list of conditions and the following disclaimer.
 *
 * -Redistribution in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in
 *  the documentation and/or other materials provided with the
 *  distribution.
 *
 * Neither the name of Sun Microsystems, Inc. or the names of
 * contributors may be used to endorse or promote products derived
 * from this software without specific prior written permission.
 *
 * This software is provided "AS IS," without a warranty of any
 * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
 * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY
 * DAMAGES OR LIABILITIES  SUFFERED BY LICENSEE AS A RESULT OF OR
 * RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR
 * ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE
 * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT,
 * SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF
 * THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 *
 * You acknowledge that Software is not designed, licensed or
 * intended for use in the design, construction, operation or
 * maintenance of any nuclear facility.
 */

package examples.hello;

import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.RMISecurityManager;
import java.rmi.server.UnicastRemoteObject;

public class HelloImpl extends UnicastRemoteObject
    implements Hello {

    public HelloImpl() throws RemoteException {
        super();
    }

    public String sayHello() {
        return  "Hello World!";
    }

    public static void main(String args[]) {

        // Create and install a security manager
        if (System.getSecurityManager() == null) {
            System.setSecurityManager(new RMISecurityManager());
        }
        try {
            HelloImpl obj = new HelloImpl();
            // Bind this object instance to the name "HelloServer"
            Naming.rebind("HelloServer", obj);
            System.out.println("HelloServer bound in registry");
        } catch (Exception e) {
            System.out.println("HelloImpl err: " + e.getMessage());
            e.printStackTrace();
        }
    }
}
[inoue@onlsbc1 hello]$

[inoue@onlsbc1 hello]$ cat hello.html

<HTML>
<title>Hello World</title>
<center> <h1>Hello World</h1> </center>

The message from the HelloServer is:
<p>
<applet codebase="myclasses/"
        code="examples.hello.HelloApplet"
        width=500 height=120>
</applet>
</HTML>
[inoue@onlsbc1 hello]$

[inoue@onlsbc1 hello]$ cat policy
grant {
        // Allow everything for now
        permission java.security.AllPermission;
};
[inoue@onlsbc1 hello]$

[inoue@onlsbc1 hello]$ rmic -d $HOME/public_html/myclasses examples.hello.HelloI
mpl
[inoue@onlsbc1 hello]$ ls -lR $HOME/public_html/myclasses
/home/inoue/public_html/myclasses:
合計 1
drwxrwxr-x    3 inoue    inoue        1024  6月 16 09:24 examples

/home/inoue/public_html/myclasses/examples:
合計 1
drwxrwxr-x    2 inoue    inoue        1024  6月 16 09:26 hello

/home/inoue/public_html/myclasses/examples/hello:
合計 10
-rw-rw-r--    1 inoue    inoue         224  6月 16 09:24 Hello.class
-rw-rw-r--    1 inoue    inoue        1284  6月 16 09:24 HelloApplet.class
-rw-rw-r--    1 inoue    inoue        1247  6月 16 09:24 HelloImpl.class
-rw-rw-r--    1 inoue    inoue        1448  6月 16 09:26 HelloImpl_Skel.class
-rw-rw-r--    1 inoue    inoue        2920  6月 16 09:26 HelloImpl_Stub.class
[inoue@onlsbc1 hello]$

[inoue@onlsbc1 hello]$ cp hello.html $HOME/public_html
[inoue@onlsbc1 hello]$

[inoue@onlsbc1 hello]$ ls -l $HOME/..
合計 3
drwx------    2 harada   harada       1024  5月 14 22:59 harada
drwx------    4 inoue    inoue        1024  6月 16 09:06 inoue
drwx------    2 yasu     yasu         1024  5月 14 22:59 yasu
[inoue@onlsbc1 hello]$ chmod o+x $HOME/../inoue
[inoue@onlsbc1 hello]$ ls -l $HOME/..
合計 3
drwx------    2 harada   harada       1024  5月 14 22:59 harada
drwx-----x    4 inoue    inoue        1024  6月 16 09:06 inoue
drwx------    2 yasu     yasu         1024  5月 14 22:59 yasu
[inoue@onlsbc1 hello]$

[root@onlsbc1 hello]# ls -l /etc/httpd/conf
合計 50
-rw-r--r--    1 root     root        34817  9月  5  2002 httpd.conf
-rw-r--r--    1 root     root        12959  9月  5  2002 magic
[root@onlsbc1 hello]# mv /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf-o
rg
[root@onlsbc1 hello]# cp /etc/httpd/conf/httpd.conf-org /etc/httpd/conf/httpd.co
nf
[root@onlsbc1 hello]# ls -l /etc/httpd/conf
合計 86
-rw-r--r--    1 root     root        34817  6月 16 10:30 httpd.conf
-rw-r--r--    1 root     root        34817  9月  5  2002 httpd.conf-org
-rw-r--r--    1 root     root        12959  9月  5  2002 magic
[root@onlsbc1 hello]# vi /etc/httpd/conf/httpd.conf
				:
#ServerName new.host.name:80
ServerName onlsbc1.kek.jp:80
				:

    #
    # UserDir is disabled by default since it can confirm the presence
    # of a username on the system (depending on home directory
    # permissions).
    #
    #UserDir disable

    #
    # To enable requests to /~user/ to serve the user's public_html
    # directory, remove the "UserDir disable" line above, and uncomment
    # the following line instead:
    #
    UserDir public_html


				:
"/etc/httpd/conf/httpd.conf" 1034L, 34846C written
[root@onlsbc1 hello]#

[root@onlsbc1 html]# ls -l /home
合計 3
drwx------    2 harada   harada       1024  5月 14 22:59 harada
drwxr-xr-x    4 inoue    inoue        1024  6月 16 09:06 inoue
drwx------    2 yasu     yasu         1024  5月 14 22:59 yasu
[root@onlsbc1 html]# mkdir -p /home/onlsbc1/public_html
[root@onlsbc1 html]# ls -l /home
合計 4
drwx------    2 harada   harada       1024  5月 14 22:59 harada
drwxr-xr-x    4 inoue    inoue        1024  6月 16 09:06 inoue
drwxr-xr-x    3 root     root         1024  6月 16 15:09 onlsbc1
drwx------    2 yasu     yasu         1024  5月 14 22:59 yasu
[root@onlsbc1 html]#
[root@onlsbc1 html]# ls -l /home/inoue/public_html
合計 5
-rw-r--r--    1 inoue    inoue         245  6月 16 09:28 hello.html
-rw-r--r--    1 inoue    inoue        2145  6月 16 10:38 index.html
drwxrwxr-x    3 inoue    inoue        1024  6月 16 09:24 myclasses
[root@onlsbc1 html]# cp /home/inoue/public_html/index.html /home/onlsbc1/public_
html
[root@onlsbc1 html]# 
[root@onlsbc1 html]# pwd
/var/www/html
[root@onlsbc1 html]# ls -l
合計 0
[root@onlsbc1 html]# ln -s /home/onlsbc1/public_html/index.html index.html
[root@onlsbc1 html]# ls -l
合計 0
lrwxrwxrwx    1 root     root           36  6月 16 15:12 index.html -> /home/onl
sbc1/public_html/index.html
[root@onlsbc1 html]#

[root@onlsbc1 hello]# /sbin/service httpd start
httpdを起動中:                                             [  OK  ]
[root@onlsbc1 hello]#

[inoue@onlsbc1 hello]$ rmiregistry &
[1] 696
[inoue@onlsbc1 hello]$ ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 14:41 ?        00:00:04 init
root         2     1  0 14:41 ?        00:00:00 [keventd]
root         3     1  0 14:41 ?        00:00:00 [kapmd]
root         4     1  0 14:41 ?        00:00:00 [ksoftirqd_CPU0]
root         5     1  0 14:41 ?        00:00:00 [kswapd]
root         6     1  0 14:41 ?        00:00:00 [bdflush]
root         7     1  0 14:41 ?        00:00:00 [kupdated]
root         8     1  0 14:41 ?        00:00:00 [mdrecoveryd]
root        12     1  0 14:41 ?        00:00:00 [kjournald]
root        63     1  0 14:41 ?        00:00:00 [khubd]
root       433     1  0 14:43 ?        00:00:00 syslogd -m 0
root       437     1  0 14:43 ?        00:00:00 klogd -x
rpc        448     1  0 14:43 ?        00:00:00 [portmap]
root       511     1  0 14:43 ?        00:00:01 /usr/sbin/sshd
root       523     1  0 14:43 tty1     00:00:00 /sbin/mingetty tty1
root       524     1  0 14:43 tty2     00:00:00 /sbin/mingetty tty2
root       525     1  0 14:43 tty3     00:00:00 /sbin/mingetty tty3
root       526     1  0 14:43 tty4     00:00:00 /sbin/mingetty tty4
root       527     1  0 14:43 tty5     00:00:00 /sbin/mingetty tty5
root       528     1  0 14:43 tty6     00:00:00 /sbin/mingetty tty6
root       533   511  0 14:58 ?        00:00:00 /usr/sbin/sshd
inoue      535   533  0 14:58 ?        00:00:01 [sshd]
inoue      536   535  0 14:58 pts/0    00:00:00 -bash
root       589     1  0 14:59 ?        00:00:00 [rpciod]
root       590     1  0 14:59 ?        00:00:00 [lockd]
root       660     1  0 15:15 ?        00:00:00 /usr/sbin/httpd
apache     663   660  0 15:15 ?        00:00:00 [httpd]
apache     664   660  0 15:15 ?        00:00:00 [httpd]
apache     665   660  0 15:15 ?        00:00:00 [httpd]
apache     666   660  0 15:15 ?        00:00:00 [httpd]
apache     667   660  0 15:15 ?        00:00:00 [httpd]
apache     668   660  0 15:15 ?        00:00:00 [httpd]
apache     669   660  0 15:15 ?        00:00:00 [httpd]
apache     670   660  0 15:15 ?        00:00:00 [httpd]
inoue      696   536 62 15:22 pts/0    00:00:03 rmiregistry
inoue      708   536  0 15:22 pts/0    00:00:00 ps -ef
[inoue@onlsbc1 hello]$

[inoue@onlsbc1 hello]$ java -Djava.rmi.server.codebase=http://onlsbc1.kek.jp/~in
oue/myclasses/ -Djava.security.policy=/mnt/inoue/JavaRMI/getStart/examples/hello
/policy examples.hello.HelloImpl
HelloServer bound in registry

     (2-1-3A).  サーバへのアクセス

	webブラウザ、IEを使ってサーバにアクセスした結果

	Webブラウザ、IEで "http://onlsbc1.kek.jp/~inoue/hello.html" に
        アクセスすると、"Hello World!"と表示される。


     (2-1-4).  ソフトウェア(その2)

	CAMAC-JavaRMI4.htmlで使用したソフトをアプレット化して実行してみる。


     (2-1-4A).  GUI部のテスト

	ClientImpl.java とGUIの部分のアプレットを一体にして動かしてみる。

	注. この部分は、ホスト名 onlgw 上でテストした。

[inoue@onlgw Swing]$ pwd
/home/inoue/public_html/Web/Swing
[inoue@onlgw Swing]$ more web3.java
// File Name: web3.java
// Date: Jun 24, 2003
// Edited by: Eiji Inoue


import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;

import java.io.*;
import java.rmi.*;
import java.rmi.server.*;


public class web3 extends JApplet implements ActionListener {

  JLabel jLabel1 = new JLabel("CAMAC Command:");
  JLabel jLabel2 = new JLabel("Write Data   :");
  JPanel jPanel1 = new JPanel();
  JTextField tField = new JTextField("5,1,0");
  JTextField tField2 = new JTextField("ffff");
  JTextArea tArea = new JTextArea(10,30);
  JButton btAppend = new JButton("GO");

  String host = "onlsbc1";
  ClientImpl obj = new ClientImpl( host );


  public void init() {    this.setSize(new Dimension(400,300));
    jPanel1.setLayout(null);
    jLabel1.setBounds(new Rectangle(12, 34, 120, 22));
    jLabel2.setBounds(new Rectangle(12, 64, 120, 22));
    tField.setBounds(new Rectangle(120, 34, 120, 22));
    tField.setFont(new Font("Serif",Font.PLAIN,18));
    tField2.setBounds(new Rectangle(120, 64, 120, 22));
    tField2.setFont(new Font("Serif",Font.PLAIN,18));
//    String str = "上の窓のところにCAMACコマンドおよびデータを記入後、右上の「G
O」のボタンを押すと、";
//    str += "CAMACコマンドの実行結果がこの窓の部分に表示されます。";
    String str = "For scroll down to the last message, left-click the mouse butt
on once on blank area following this text line.";
//    str += "\n";
    tArea.setText(str);  //デフォルトのテキストを表示
    tArea.setFont(new Font("Serif",Font.PLAIN,14));
    tArea.setTabSize(4);  //タブサイズを設定
    tArea.setLineWrap(true);  //右辺で自動折り返しにする
    tArea.setSelectionColor(Color.lightGray);  //反転選択範囲の背景色
    tArea.setSelectedTextColor(Color.blue);  //反転選択範囲の文字色
    tArea.setEnabled(false);   //テキストエリアがキー入力を取らないようにする
    btAppend.setBounds(new Rectangle(265, 64, 76, 22));
    btAppend.addActionListener(this);
    this.getContentPane().add(jLabel1, BorderLayout.NORTH);
    this.getContentPane().add(jPanel1, BorderLayout.CENTER);
//    JScrollPane jScrollPane2 = new JScrollPane(tArea);
    JScrollPane jScrollPane2 = new JScrollPane();
//    jScrollPane2.getViewport().setView(tArea);
    jScrollPane2.setPreferredSize( new Dimension (300, 300 ));
    jScrollPane2.getViewport().add(tArea);
    jScrollPane2.setBounds(new Rectangle(10, 120, 485, 165));
    jPanel1.add(jScrollPane2);
    jPanel1.add(jLabel1);
    jPanel1.add(jLabel2);
    jPanel1.add(tField);
    jPanel1.add(tField2);
    jPanel1.add(btAppend);
  }

  public void actionPerformed(ActionEvent e){
    if(e.getSource()==btAppend){  //「末尾に追加」ボタン
      tArea.append("\n" + "web3:  Sent CAMAC command = " + tField.getText() + ",
   data =" + tField2.getText());
//      ClientImpl.mess = tField.getText();
      ClientImpl.acmd = tField.getText();
      ClientImpl.adat = tField2.getText();
      obj.keyincmd();
      tArea.append( "\n" + ClientImpl.mess );
      tArea.append( "\n" + "web3:  Received Command field = " + Integer.toHexStr
ing( ClientImpl.scmd[0] ) + ",   Data field = " + Integer.toHexString( ClientImp
l.sdat[0] ) );
      tArea.append("\n");
    }
  }

/*
 protected void log( final String s){
      Runnable r = new Runnable(){
          public void run(){
              tArea.append("\n" + "log:  " + s);
          }
      };
      SwingUtilities.invokeLater(r);
      return;
 }
*/

}

/**/

// File Name: ClientImpl.java
// Date: Apr 28, 2003
// Edited by: Eiji Inoue

//import java.io.*;
//import java.rmi.*;
//import java.rmi.server.*;

class ClientImpl implements Client {
        public static final int  CMD_F16_A0_N3 = 0xE0030010;
        public static final int  CMD_F0_A0_N3  = 0xE0030000;
        public static final char COM = ',';
        public static final char QUIT = 'q';
        public static final char EXAM = 'e';
        public static final char STAR = 'g';
        public static final char SIN = 's';
        public static final char DMA = 'd';


        public static int scmd[] = new int[100];
        public static int sdat[] = new int[100];

        public static String mess;
        public static String acmd;
        public static String adat;

        static Server server;
        static web3 web3s;

        public ClientImpl(String host) {
                try{
                   UnicastRemoteObject.exportObject(this);
                   Server server = (Server)Naming.lookup("//"+host+"/Server");
                   server.register(this);
                   ClientImpl.server = server;
                } catch ( Exception e ) {
                   System.err.println ("Failed to setup for RMI");
                }
        }

        public void camac_exec( int l_count, int examN ) {
                int[]  s_cmd, s_dat;
                int[] array_sizes = {4096*16};
                int    s_length;
                int    j;

                try{
                System.out.println(" RMI: Client side: ");
                // to send int array

                        System.out.println("   RMI: Sent CAMAC command: array le
ngth =" + l_count );
                        for (int i = 0; i < l_count + 1; i++)
                            System.out.println("      ClientImpl.scmd[" + i + "]
 = 0x" + Integer.toHexString( ClientImpl.scmd[i]) + ", ClientImpl.sdat[" + i + "
] = 0x" + Integer.toHexString( ClientImpl.sdat[i]));

                        ClientImpl.server.camac_cmd(ClientImpl.scmd, ClientImpl.
sdat, l_count, examN );
                } catch ( Exception e ) {
                   System.err.println ("Failed to setup for RMI step2");
                }
        }

        public void camac_reply( int[] c_reply, int[] d_reply, int[] rcmd_buf, i
nt[] rrpl_buf, int l_reply) throws RemoteException {
                System.out.println();
                System.out.println("   RMI: Received CAMAC reply: " + "array len
gth = " + l_reply);
                for (int i = 0; i < l_reply + 1; i++) {
                    System.out.println("      c_reply[" + i + "] = 0x" + Integer
.toHexString(c_reply[i]) + ", d_reply[" + i + "] = 0x" + Integer.toHexString(d_r
eply[i]));
                }
                for (int i = 0; i < l_reply + 1; i += 2) {
                    System.out.println("      rcmd_buf[" + i + "] = 0x" + Intege
r.toHexString(rcmd_buf[i]) + ", rcmd_buf[" + ( i + 1 ) + "] = 0x" + Integer.toHe
xString(rcmd_buf[i+1]));
                    System.out.println("      rrpl_buf[" + i + "] = 0x" + Intege
r.toHexString(rrpl_buf[i]) + ", rrpl_buf[" + ( i + 1 ) + "] = 0x" + Integer.toHe
xString(rrpl_buf[i+1]));
                }
                keyincmd();
//              keyincmd( "next" );
        }

// TX
// +---------+-------+-------+-------+-------+---------------------------+
// |   cmd   |   N   |   A   |   F   |       |       24-bit DATA         |
// +---------+-------+-------+-------+-------+---------------------------+
//
// cmd Header pattern
// +-------------+---------+---------+---------+---------------+
// |             | Packet  | Packet  | Packet  | Single        |
// |             | Start   | Period  | End     | Frame Packet  |
// +-------------+---------+---------+---------+---------------+
// | CAMAC       |         |         |         |               |
// | Operation   |  0xC0   |  0x8C   |  0xA0   |      0xE0     |
// +-------------+---------+---------+---------+---------------+
// | CAMAC       |         |         |         |               |
// | LAM         |   --    |   --    |   --    |      0xE8     |
// +-------------+---------+---------+---------+---------------+
// | DAQ Trigger |         |         |         |               |
// | out         |  0xD0   |  0x90   |  0xB0   |      0xF0     |
// +-------------+---------+---------+---------+---------------+
// | DAQ         |         |         |         |               |
// | Interrupt   |   --    |   --    |   --    |      0xF8     |
// +-------------+---------+---------+---------+---------------+
//
// CAMAC N.
//    55   54   53   52   51  50  49  48  47                              32
// +--------------------+----------------+-------------------+---------------+
// |   -    -    -  N16 | N8  N4  N2  N1 |         |         |       |       |
// +--------------------+----------------+-------------------+---------------+
//
// CAMAC A.
//                        47   46   45  44    43  42  41  40              32
// +--------------------+-------------------+----------------+---------------+
//                      |  -    -    -   -  | A8  A4  A2  A1 |       |       |
// +--------------------+-------------------+----------------+---------------+
//
// CAMAC F.
//                                        39   38   37   36   35  34  33  32
// +--------------------+----------------+------------------+----------------+
//                                       | -    -    -  F16 | F8  F4  F2  F1 |
// +--------------------+----------------+------------------+----------------+
//


   public void cmdbld( int n, int a, int f, int l_count ){
      // CAMAC Single action.
      System.out.println ( "   Make up CAMAC Command of Single action." );
      System.out.println ( "   Accepted data:   n = " + n + ", a = " + a + ", f
= " + f + ", l_count = " + l_count );
      a = a << 8;
      n = n << 16;
      ClientImpl.scmd [ l_count -1 ] = 0xE0000000 | ( 0x0000001F & f ) | ( 0x000
00F00 & a ) | ( 0x001F0000 & n );
      System.out.println ( "   ClientImpl.scmd [ " + ( l_count -1 ) + " ] = " +
ClientImpl.scmd [ l_count -1 ] + "(dec), " + "0x" + Integer.toHexString( ClientI
mpl.scmd [ l_count -1 ] ) + "(hex)" );
      System.out.println ( "   ClientImpl.sdat [ " + ( l_count -1 ) + " ] = " +
ClientImpl.sdat [ l_count -1 ] + "(dec), " + "0x" + Integer.toHexString( ClientI
mpl.sdat [ l_count -1 ] ) + "(hex)" );

      // CAMAC LAM handling.
      // CAMAC DMA action.
   }

//   public void keyincmd( String s2) {
   public void keyincmd() {
//   public String keyincmd( ) {
      char cstr[] = new char[20];
      char n[] = new char[4];
      char a[] = new char[4];
      char f[] = new char[4];
      char kc[] = new char[4];
      int  c[] = new int[3];
      int  i, i2, count, loop, k_error;
      int  spoin, epoin;
      int  examN;
      String cn = "0", ca = "0", cf = "0";
      String tmp;

      String nchk[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "
b", "c", "d", "e", "f" };

//      String s1 = "keyincmd: " + "Received CAMAC Command =" + s2 + "\n" + "key
incmd: " + "Sent Reply command field = 0xe0030010" + ", data field = 0x555";
      String s1 = "keyincmd: " + "ClientImpl.acmd =" + ClientImpl.acmd + ",   Cl
ientImpl.adat =" + ClientImpl.adat + "\n" + "keyincmd: " + "Sent Reply command f
ield = 0xe0030010" + ",    data field = 0x555";
      mess = s1;
      ClientImpl.scmd[0] = 0xe0030010;
      ClientImpl.sdat[0] = 0x555;
//      return (s1);
      return;

/*
      InputStream inStream = System.in;
      InputStreamReader InData = new InputStreamReader ( inStream );

      int s_flg = 0;
      try{
         spoin = 0;
         epoin = 0;
         loop = 2;
         k_error = 0;
         examN = 0;
         System.out.println ( "" );
         System.out.println ( " (1). Enter 'q' to quit." );
         System.out.println ( " (2). Enter 'e' to execute an example program." )
;
         System.out.println ( " (3). Enter 's' to set up Single action CAMAC com
mand");
//         System.out.println ( " (4). Enter 'd' to set up DMA action CAMAC comm
and");
         System.out.println ( " (4). Enter 'g' to start up command execution." )
;
         System.out.println ( "" );
         while ( loop > 1 ) {
            if ( k_error == 1 ) {
                System.out.println ( "" );
                k_error = 0;
            }
            // Execution command interpret.
              System.out.print ( "Execution Command('q' or 'e' or 'g' or 's' or
'd') = ");
            count = InData.read ( cstr, 0, 19 );
            String str1 = new String ( cstr );

            if ( QUIT == str1.charAt ( 0 ) ) {
               s_flg = 2;
               break;
            } else if ( EXAM == str1.charAt ( 0 )) {
                  // example program execution;
                  System.out.println( "   What's number of program which do you
want to execute ? --- default:[1] ");
                  System.out.println( "   exam1:[1], exam2:[2], exam3:[3], exam4
:[4], exam5:[5], exam6:[6], exam21:[7], pio_write_read[8], read:[9], read_write:
[a], reg_dump:[b], write:[c], write_read:[d]");
                  System.out.print( "   Number = " );
                  count = InData.read ( cstr, 0, 19 );
                  String str2 = new String ( cstr );
                  cn = str2.substring ( 0, 1 );

                  cn.getChars(0, 1, kc, 0);

                  try {
                     switch ( kc[0] ) {
                        case '1':
                           s_flg = 1;
                           examN = 1;
                           System.out.println( "   Ok. Start up an example progr
am 1. " );
                           break;

                        case '2':
                           s_flg = 1;
                           examN = 2;
                           System.out.println( "   Ok. Start up an example progr
am 2. " );
                           break;

                        case '3':
                           s_flg = 1;
                           examN = 3;
                           System.out.println( "   Ok. Start up an example progr
am 3. " );
                           break;

                        case '4':
                           s_flg = 1;
                           examN = 4;
                           System.out.println( "   Ok. Start up an example progr
am 4. " );
                           break;

                        case '5':
                           s_flg = 1;
                           examN = 5;
                           System.out.println( "   Ok. Start up an example progr
am 5. " );
                           break;

                        case '6':
                           s_flg = 1;
                           examN = 6;
                           System.out.println( "   Ok. Start up an example progr
am 6. " );
                           break;

                        case '7':
                           s_flg = 1;
                           examN = 7;
                           System.out.println( "   Ok. Start up an example progr
am 21. " );
                           break;

                        case '8':
                           s_flg = 1;
                           examN = 8;
                           System.out.println( "   Ok. Start up an example progr
am pio_write_read. " );
                           break;

                        case '9':
                           s_flg = 1;
                           examN = 9;
                           System.out.println( "   Ok. Start up an example progr
am read. " );
                           break;

                        case 'a':
                           s_flg = 1;
                           examN = 0xa;
                           System.out.println( "   Ok. Start up an example progr
am read_write.");
                           break;

                        case 'b':
                           s_flg = 1;
                           examN = 0xb;
                           System.out.println( "   Ok. Start up an example progr
am reg_dump.");
                           break;

                        case 'c':
                           s_flg = 1;
                           examN = 0xc;
                           System.out.println( "   Ok. Start up an example progr
am write.");
                           break;

                        case 'd':
                           s_flg = 1;
                           examN = 0xd;
                           System.out.println( "   Ok. Start up an example progr
am write_read.");
                           break;

                        default:
                           break;
                     }
                     break;

                  } catch ( NumberFormatException e ) {
                     System.out.println( "   NumberFormatExeception occurred !!
" );
                     System.out.println( "" );
                  }

            } else if ( STAR == str1.charAt ( 0 )) {
               if ( epoin == 0 ) {
                  s_flg = 5;
                  System.out.print ( "   Command bufer is empty !!");
                  System.out.println ( "" );
                  continue;
               } else {
                  // camacstart();
                  s_flg = 1;
                  examN = 0xe;
                  System.out.println( "   Ok. Start up CAMAC execution. " );
                  break;
               }
            } else if ( SIN == str1.charAt ( 0 )) {
               // Single action.
               s_flg = 3;
            } else if ( DMA == str1.charAt ( 0 )) {
               // DNA action.
               s_flg = 4;
               System.out.println ( "     DMA Action." );
            } else {
               s_flg = 5;
               System.out.println ( "     Unmanageable Action." );
               continue;
            }

            tmp = str1.substring ( 0, count -1 );
            System.out.println ( "   Execution Command: " + tmp );

            if ( s_flg == 4 ) {
                // DMA mode & word count set up.
                // Q stop, Q Ignore, Q request, Q scan.
                System.out.println ( "   DMA set up: " );
                System.out.println ( "   DMA set up: DMA mode: " );
                System.out.println ( "   DMA set up: DMA wor count: " );
            }

            // N,A,F CAMAC command set up.
            System.out.print ( "CAMAC Command (N, A, F)(dec) = " );
            count = InData.read ( cstr, 0, 19 );
            String str = new String ( cstr );

            // Single action set up.

            i2 = 0;
            for ( i = 0; i < str.length(); i++ ) {
               if ( COM == str.charAt ( i ) ) {
                   c[ i2++ ] = i;
               }
            }
            cn = str.substring ( 0, c[ 0 ] );
            ca = str.substring ( c[ 0 ] +1, c[ 1 ]  );
            cf = str.substring ( c[ 1 ] +1, count-1 );

            try{
               int in = Integer.parseInt(cn, 10);
               if ( ( in < 0 ) || ( in > 25 ) ) {
                   System.out.println ( "   Command Error: Illegal value of N: O
ut of range !! " );
                   k_error = 1;
                   continue;
               }
               int ia = Integer.parseInt(ca, 10);
               if ( ( ia < 0 ) || ( ia > 15 ) ) {
                   System.out.println ( "   Command Error: Illegal value of A: O
ut of range !! " );
                   k_error = 1;
                   continue;
               }
               int inf = Integer.parseInt(cf, 10);
               if ( ( inf < 0 ) || ( inf > 31 ) ) {
                   System.out.println ( "   Command Error: Illegal value of F: O
ut of range !! " );
                   k_error = 1;
                   continue;
               }

               if ( ( inf >= 16 ) && ( inf <= 23 ) ) {
                  // データ入力要求
                  int datf = 0;
                  do {
                  System.out.print ( "   Write Data(hex) = " );
                  count = InData.read ( cstr, 0, 19 );
                  str = new String ( cstr );
                  String cdat = str.substring ( 0, count -1 );
                  for ( i = 0; i < count -1; i++) {
                     String cdat1 = cdat.substring ( i, i + 1 );
                     // numerical check
                     for ( i2 = 0; i2 < 16; i2++ ) {
                        if ( cdat1.equals( nchk [ i2 ] ) ) {
                           datf = 0;
                           break;
                        }
                           datf = 1;
                     }
                     if ( datf == 1 ) {
                        System.out.println ( "   Data error: Illegal character -
-- " + cdat1 + " !" );
                        System.out.println ( "" );
                        break;
                     }
                  }
                  if ( datf == 1) {
                     continue;
                  }
                  ClientImpl.sdat [ loop -1 ] = Integer.parseInt( cdat, 16);
                  System.out.println ( "   入力されたData:  " + ClientImpl.sdat
[ loop -1 ] + "(dec), 0x" + Integer.toHexString( ClientImpl.sdat [ loop -1 ] ) +
 "(hex)");
                  if ( ( ClientImpl.sdat [ loop -1 ] < 0 ) || ( ClientImpl.sdat
[ loop -1 ] > 0xffffff ) ) {
                     System.out.println ( "   Data error: Out of range ---  " +
ClientImpl.sdat [ loop -1 ] + " !" );
                     System.out.println ( "" );
                     datf = 1;
                     continue;
                  }
                  } while ( datf == 1 );
               }

               // CAMAC command set up.
               cmdbld ( in, ia, inf, loop );
               epoin++;
               loop++;
               System.out.println ( "" );

            } catch (NumberFormatException e) {
               System.out.println("   NumberFormatException occurred !!");
               System.out.println ( "" );
            }
         }
         // end of while loop

         if ( s_flg == 1 ) {
               camac_exec( loop -2, examN );
         } else if ( s_flg == 2 ) {
            System.out.println ( "    Quited Program.  Enter Ctl-C. " );
         }

         } catch ( IOException e ) {
            System.out.println ( "   IOException Error:" + e  + " !");
         }
*/

      }

/*
        public static void main(String argv[]) throws Exception{

                String  host = (argv.length == 1) ? argv[0] : "localhost";
                ClientImpl obj = new ClientImpl(host);
                obj.keyincmd();
        }
*/
}
[inoue@onlgw Swing]$

	GUIの部分の動作をテストする。 合わせて、アプレットとClientImplクラスの
	間のメッセージのやり取りを調べる。

[inoue@onlgw Swing]$ pwd
/home/inoue/public_html/Web/Swing
[inoue@onlgw Swing]$ make clean
rm -f *.class cam.h libMyImpOfcam.so *.o core *~
[inoue@onlgw Swing]$ make
javac web3.java
javac cam.java
javah -jni cam
gcc -c camac.c
gcc -O -shared -I/usr/java/include -I/usr/java/include/linux cam.c camac.o -o li
bMyImpOfcam.so
javac ServerImpl.java
rmic ClientImpl
rmic ServerImpl
[inoue@onlgw Swing]$

	IEを使って、onlgw 上の web3.htmlファイルをアクセスするとGUI部の
	アプレットがが起動した。
 	



	ok.  アプレットweb3とClientImpl.keyincmd()との間でのメッセージの受け渡し
	は正しく実行できている。


     (2-1-4B).  CAMACアクセス部を含めた動作確認

	CAMACアクセスの部分はポートI/Oコマンドを使って実行する。
	CAMAC-JavaRMI4.htmlで使用したソフトを修正して使用した。

	注.  以降のテストはサーバマシンとして再び、CC/NETのSBC、ホスト名 onlsbc1
	     を使用している。


        (2-1-4B-1).  web3.java

[inoue@onlsbc1 Web]$ more web3.java
// File Name: web3.java
// Date: Jun 24, 2003
// Edited by: Eiji Inoue


import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;

import java.io.*;
import java.rmi.*;
import java.rmi.server.*;


public class web3 extends JApplet implements ActionListener {

  JLabel jLabel1 = new JLabel("CAMAC Command:");
  JLabel jLabel2 = new JLabel("Write Data (Hex)  :");
  JPanel jPanel1 = new JPanel();
  JTextField tField = new JTextField("5,1,0");
  JTextField tField2 = new JTextField("ffff");
  JTextArea tArea = new JTextArea(10,30);
  JButton btAppend = new JButton("GO");

  String host = "onlsbc1";
//  ClientImpl obj = new ClientImpl( host );

  ClientImpl obj = new ClientImpl( );
//  obj.ClientImpl1( String host );


  public void init() {    this.setSize(new Dimension(400,300));
    jPanel1.setLayout(null);
    jLabel1.setBounds(new Rectangle(12, 34, 120, 22));
    jLabel2.setBounds(new Rectangle(12, 64, 120, 22));
    tField.setBounds(new Rectangle(120, 34, 120, 22));
    tField.setFont(new Font("Serif",Font.PLAIN,18));
    tField2.setBounds(new Rectangle(120, 64, 120, 22));
    tField2.setFont(new Font("Serif",Font.PLAIN,18));
//    String str = "上の窓のところにCAMACコマンドおよびデータを記入後、右上の「G
O」のボタンを押すと、";
//    str += "CAMACコマンドの実行結果がこの窓の部分に表示されます。";
    String str = "For scroll down to the last message, left-click the mouse butt
on once on blank area following this text line.";
//    str += "\n";
    tArea.setText(str);  //デフォルトのテキストを表示
    tArea.setFont(new Font("Serif",Font.PLAIN,14));
    tArea.setTabSize(4);  //タブサイズを設定
    tArea.setLineWrap(true);  //右辺で自動折り返しにする
    tArea.setSelectionColor(Color.lightGray);  //反転選択範囲の背景色
    tArea.setSelectedTextColor(Color.blue);  //反転選択範囲の文字色
    tArea.setEnabled(false);   //テキストエリアがキー入力を取らないようにする
    btAppend.setBounds(new Rectangle(265, 64, 76, 22));
    btAppend.addActionListener(this);
    this.getContentPane().add(jLabel1, BorderLayout.NORTH);
    this.getContentPane().add(jPanel1, BorderLayout.CENTER);
    JScrollPane jScrollPane2 = new JScrollPane(tArea);
//    JScrollPane jScrollPane2 = new JScrollPane();
//    jScrollPane2.getViewport().setView(tArea);
    jScrollPane2.setPreferredSize( new Dimension (300, 300 ));
    jScrollPane2.getViewport().add(tArea);
    jScrollPane2.setBounds(new Rectangle(10, 120, 485, 165));
    jPanel1.add(jScrollPane2);
    jPanel1.add(jLabel1);
    jPanel1.add(jLabel2);
    jPanel1.add(tField);
    jPanel1.add(tField2);
    jPanel1.add(btAppend);

//    setVisible(true);
//    tArea.requestFocus();

//    try {
//        obj = (Hello)Naming.lookup("//" + getCodeBase().getHost() + "/HelloSer
ver");
//        message = obj.sayHello();
//    } catch (Exception e) {
//        System.out.println("HelloApplet exception: " + e.getMessage());
//        e.printStackTrace();
//    }


//        public ClientImpl(String host) {
                try{
//                   UnicastRemoteObject.exportObject(this);
                   UnicastRemoteObject.exportObject(obj);
//                   UnicastRemoteObject.exportObject(super);
//                   Server server = (Server)Naming.lookup("//"+host+"/Server");

                   Server server = (Server)Naming.lookup("//" + getCodeBase().ge
tHost() + "/Server");
//                   server.register(this);
                   server.register(obj);
//                   server.register(super);
                   ClientImpl.server = server;
                   tArea.append( "\n" + "Success to setup for RMI" );
                } catch ( Exception e ) {
//                   System.err.println ("Failed to setup for RMI");
                   tArea.append( "\n" + "Failed to setup for RMI" );
                }
//        }


  }

  public void actionPerformed(ActionEvent e){
    if(e.getSource()==btAppend){  //「末尾に追加」ボタン
      tArea.append("\n" + "web3:  Sent CAMAC command = " + tField.getText() + ",
   data =" + tField2.getText());
//      ClientImpl.mess = tField.getText();
      ClientImpl.acmd = tField.getText();
      ClientImpl.adat = tField2.getText();
      obj.keyincmd();
      tArea.append( "\n" + ClientImpl.mess );
      tArea.append( "\n" + "web3:  Received Command field = " + Integer.toHexStr
ing( ClientImpl.scmd[0] ) + ",   Data field = " + Integer.toHexString( ClientImp
l.sdat[0] ) );
      tArea.append("\n");
    }
  }

/*
 protected void log( final String s){
      Runnable r = new Runnable(){
          public void run(){
              tArea.append("\n" + "log:  " + s);
          }
      };
      SwingUtilities.invokeLater(r);
      return;
 }
*/

}

/**/

// File Name: ClientImpl.java
// Date: Apr 28, 2003
// Edited by: Eiji Inoue

//import java.io.*;
//import java.rmi.*;
//import java.rmi.server.*;

class ClientImpl implements Client {
        public static final int  CMD_F16_A0_N3 = 0xE0030010;
        public static final int  CMD_F0_A0_N3  = 0xE0030000;
        public static final char COM = ',';
        public static final char QUIT = 'q';
        public static final char EXAM = 'e';
        public static final char STAR = 'g';
        public static final char SIN = 's';
        public static final char DMA = 'd';


        public static int scmd[] = new int[100];
        public static int sdat[] = new int[100];

        public static String mess;
        public static String acmd;
        public static String adat;

        static Server server;
        static web3 web3s;

/*

//        public void ClientImpl1(String host) {
        public ClientImpl(String host) {
                try{
                   UnicastRemoteObject.exportObject(this);
//                   UnicastRemoteObject.exportObject(super);
                   Server server = (Server)Naming.lookup("//"+host+"/Server");
                   server.register(this);
//                   server.register(super);
                   ClientImpl.server = server;
                   String s3 = "Success to setup for RMI";
                   mess = s3;
                } catch ( Exception e ) {
//                   System.err.println ("Failed to setup for RMI");
                   String s3 = "Failed to setup for RMI";
                   mess = s3;
                }
        }
*/

        public void camac_exec( int l_count, int examN ) {
                int[]  s_cmd, s_dat;
                int[] array_sizes = {4096*16};
                int    s_length;
                int    i, j;

                String s2 = "";
                s2 = mess + "\n" + "Top of camac_exec";
                mess = s2;
                try{
//              System.out.println(" RMI: Client side: ");
                s2 = mess + "\n" + "camac_exec:  RMI: Client side: ";
                mess = s2;
                // to send int array

//                      System.out.println("   RMI: Sent CAMAC command: array le
ngth =" + l_count );
                        s2 = mess + "\n" + "camac_exec:  RMI: Sent CAMAC command
: array legth =" + l_count;
                        mess = s2;
/*
                        i = 0;
                        s2 = mess + "\n" + "camac_exec:      ClientImpl.scmd[" +
 i + "] = 0x" + Integer.toHexString( ClientImpl.scmd[i]) + ", ClientImpl.sdat["
+ i + "] = 0x" + Integer.toHexString( ClientImpl.sdat[i]);
                        mess = s2;
 */
                        for (i = 0; i < l_count + 1; i++) {
//                          System.out.println("      ClientImpl.scmd[" + i + "]
 = 0x" + Integer.toHexString( ClientImpl.scmd[i]) + ", ClientImpl.sdat[" + i + "
] = 0x" + Integer.toHexString( ClientImpl.sdat[i]));
                            s2 = mess + "\n" + "camac_exec:      ClientImpl.scmd
[" + i + "] = 0x" + Integer.toHexString( ClientImpl.scmd[i]) + ", ClientImpl.sda
t[" + i + "] = 0x" + Integer.toHexString( ClientImpl.sdat[i]);
                            mess = s2;
                            }
                        s2 = mess + "\n" + "before ClientImpl.server.camac_cmd";

                        mess = s2;
                        ClientImpl.server.camac_cmd(ClientImpl.scmd, ClientImpl.
sdat, l_count, examN );
                        s2 = mess + "\n" + "after ClientImpl.server.camac_cmd";
                        mess = s2;
                } catch ( Exception e ) {
//                   System.err.println ("Failed to setup for RMI step2");
                        s2 = mess + "\n" + "Failed to setup for RMI step2";
                        mess = s2;
                }
                s2 = mess + "\n" + "End of camac_exec";
                mess = s2;
        }

        public void camac_reply( int[] c_reply, int[] d_reply, int[] rcmd_buf, i
nt[] rrpl_buf, int l_reply) throws RemoteException {
                System.out.println();
                System.out.println("   RMI: Received CAMAC reply: " + "array len
gth = " + l_reply);
                for (int i = 0; i < l_reply + 1; i++) {
                    System.out.println("      c_reply[" + i + "] = 0x" + Integer
.toHexString(c_reply[i]) + ", d_reply[" + i + "] = 0x" + Integer.toHexString(d_r
eply[i]));
                }
                for (int i = 0; i < l_reply + 1; i += 2) {
                    System.out.println("      rcmd_buf[" + i + "] = 0x" + Intege
r.toHexString(rcmd_buf[i]) + ", rcmd_buf[" + ( i + 1 ) + "] = 0x" + Integer.toHe
xString(rcmd_buf[i+1]));
                    System.out.println("      rrpl_buf[" + i + "] = 0x" + Intege
r.toHexString(rrpl_buf[i]) + ", rrpl_buf[" + ( i + 1 ) + "] = 0x" + Integer.toHe
xString(rrpl_buf[i+1]));
                }
//              keyincmd();
//              keyincmd( "next" );
        }

// TX
// +---------+-------+-------+-------+-------+---------------------------+
// |   cmd   |   N   |   A   |   F   |       |       24-bit DATA         |
// +---------+-------+-------+-------+-------+---------------------------+
//
// cmd Header pattern
// +-------------+---------+---------+---------+---------------+
// |             | Packet  | Packet  | Packet  | Single        |
// |             | Start   | Period  | End     | Frame Packet  |
// +-------------+---------+---------+---------+---------------+
// | CAMAC       |         |         |         |               |
// | Operation   |  0xC0   |  0x8C   |  0xA0   |      0xE0     |
// +-------------+---------+---------+---------+---------------+
// | CAMAC       |         |         |         |               |
// | LAM         |   --    |   --    |   --    |      0xE8     |
// +-------------+---------+---------+---------+---------------+
// | DAQ Trigger |         |         |         |               |
// | out         |  0xD0   |  0x90   |  0xB0   |      0xF0     |
// +-------------+---------+---------+---------+---------------+
// | DAQ         |         |         |         |               |
// | Interrupt   |   --    |   --    |   --    |      0xF8     |
// +-------------+---------+---------+---------+---------------+
//
// CAMAC N.
//    55   54   53   52   51  50  49  48  47                              32
// +--------------------+----------------+-------------------+---------------+
// |   -    -    -  N16 | N8  N4  N2  N1 |         |         |       |       |
// +--------------------+----------------+-------------------+---------------+
//
// CAMAC A.
//                        47   46   45  44    43  42  41  40              32
// +--------------------+-------------------+----------------+---------------+
//                      |  -    -    -   -  | A8  A4  A2  A1 |       |       |
// +--------------------+-------------------+----------------+---------------+
//
// CAMAC F.
//                                        39   38   37   36   35  34  33  32
// +--------------------+----------------+------------------+----------------+
//                                       | -    -    -  F16 | F8  F4  F2  F1 |
// +--------------------+----------------+------------------+----------------+
//


   public void cmdbld( int n, int a, int f, int l_count ){
      // CAMAC Single action.
      String s2 = "";
//      System.out.println ( "   Make up CAMAC Command of Single action." );
//      System.out.println ( "   Accepted data:   n = " + n + ", a = " + a + ",
f = " + f + ", l_count = " + l_count );
      s2 = mess + "\n" + "cmdbld:  " + "  Make up CAMAC Command of Single action
.";
      mess = s2;
      s2 = mess + "\n" + "cmdbld:  " + "  Accepted data:   n = " + n + ", a = "
+ a + ", f= " + f + ", l_count = " + l_count;
      mess = s2;
      a = a << 8;
      n = n << 16;
      ClientImpl.scmd [ l_count -1 ] = 0xE0000000 | ( 0x0000001F & f ) | ( 0x000
00F00 & a ) | ( 0x001F0000 & n );
//      System.out.println ( "   ClientImpl.scmd [ " + ( l_count -1 ) + " ] = "
+ ClientImpl.scmd [ l_count -1 ] + "(dec), " + "0x" + Integer.toHexString( Clien
tImpl.scmd [ l_count -1 ] ) + "(hex)" );
//      System.out.println ( "   ClientImpl.sdat [ " + ( l_count -1 ) + " ] = "
+ ClientImpl.sdat [ l_count -1 ] + "(dec), " + "0x" + Integer.toHexString( Clien
tImpl.sdat [ l_count -1 ] ) + "(hex)" );
      s2 = mess + "\n" + "cmdbld:  " + "  ClientImpl.scmd [ " + ( l_count -1 ) +
 " ] = " + ClientImpl.scmd [ l_count -1 ] + "(dec), " + "0x" + Integer.toHexStri
ng( ClientImpl.scmd [ l_count -1 ] ) + "(hex)";
      mess = s2;
      s2 = mess + "\n" + "cmdbld:  " + "  ClientImpl.sdat [ " + ( l_count -1 ) +
 " ] = " +ClientImpl.sdat [ l_count -1 ] + "(dec), " + "0x" + Integer.toHexStrin
g( ClientImpl.sdat [ l_count -1 ] ) + "(hex)";
      mess = s2;


      // CAMAC LAM handling.
      // CAMAC DMA action.
   }

   public void keyincmd() {
      char cstr[] = new char[20];
      char n[] = new char[4];
      char a[] = new char[4];
      char f[] = new char[4];
      char kc[] = new char[4];
      int  c[] = new int[3];
      int  i, i2, count, loop, k_error;
      int  spoin, epoin;
      int  examN;
      String cn = "0", ca = "0", cf = "0";
      String tmp;

      String nchk[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "
b", "c", "d", "e", "f" };

      String s2 = "";
      loop = 1;
      epoin = 0;
//      ClientImpl.scmd[0] = 0xe0030010;
//      ClientImpl.sdat[0] = 0x555;


            // N,A,F CAMAC command set up.
            count = ClientImpl.acmd.length();

            // Single action set up.
            i2 = 0;
            for ( i = 0; i < ClientImpl.acmd.length(); i++ ) {
               if ( COM == ClientImpl.acmd.charAt ( i ) ) {
                   c[ i2++ ] = i;
               }
            }
            cn = ClientImpl.acmd.substring ( 0, c[ 0 ] );
            ca = ClientImpl.acmd.substring ( c[ 0 ] +1, c[ 1 ]  );
            cf = ClientImpl.acmd.substring ( c[ 1 ] +1, count );
      String s1 = "keyincmd: " + "cn =" + cn + ",   ca =" + ca + ",   cf =" + cf
;
      mess = s1;

            try{
               int in = Integer.parseInt(cn, 10);
               if ( ( in < 0 ) || ( in > 25 ) ) {
                   s2 = mess + "\n" + "keyincmd: Error:  Command Error: Illegal
value of N: Out of range !!";
                   mess = s2;
                   return;
               }
               int ia = Integer.parseInt(ca, 10);
               if ( ( ia < 0 ) || ( ia > 15 ) ) {
                   s2 = mess + "\n" + "keyincmd: Error:  Command Error: Illegal
value of A: Out of range !! ";
                   mess = s2;
                   return;
               }
               int inf = Integer.parseInt(cf, 10);
               if ( ( inf < 0 ) || ( inf > 31 ) ) {
                   s2 = mess + "\n" + "keyincmd: Error:  Command Error: Illegal
value of F: Out of range !! ";
                   mess = s2;
                   return;
               }

               if ( ( inf >= 16 ) && ( inf <= 23 ) ) {
                  // データ入力要求
                  int datf = 0;
                  count = ClientImpl.adat.length();
                  String cdat = ClientImpl.adat.substring ( 0, count );
                  for ( i = 0; i < count -1; i++) {
                     String cdat1 = cdat.substring ( i, i + 1 );
                     // numerical check
                     for ( i2 = 0; i2 < 16; i2++ ) {
                        if ( cdat1.equals( nchk [ i2 ] ) ) {
                           datf = 0;
                           break;
                        }
                           datf = 1;
                     }
                     if ( datf == 1 ) {
                        s2 = mess + "\n" + "keyincmd: Error :   Data error: Ille
gal character --- " + cdat1 + " !";
                        mess = s2;
                        break;
                     }
                  }
                  if ( datf == 1) {
//                     continue;
                     return;
                  }
                  ClientImpl.sdat [ loop -1 ] = Integer.parseInt( cdat, 16);
                  s2 = mess + "\n" + "keyincmd:  Data : " + ClientImpl.sdat[ loo
p -1 ] + "(dec), 0x" + Integer.toHexString( ClientImpl.sdat [ loop -1 ] ) + "(he
x)";
                  mess = s2;
                  if ( ( ClientImpl.sdat [ loop -1 ] < 0 ) || ( ClientImpl.sdat[
 loop -1 ] > 0xffffff ) ) {
//                     continue;
                     s2 = mess + "\n" + "keyincmd:  Data :   Data error: Out of
range ---  " + Integer.toHexString( ClientImpl.sdat [ loop -1 ] ) + " !";
                     mess = s2;
                     return;
                  }
               }


               // CAMAC command set up.
               cmdbld ( in, ia, inf, loop );
               s2 = mess + "\n" + "keyincmd:   return from cmdbld () \n";
               mess = s2;
               epoin++;
               examN = 0xe;

               s2 = mess + "\n" + "keyincmd:   loop = " + loop;
               mess = s2;


               camac_exec( loop, examN );
               s2 = mess + "\n" + "keyincmd:   return from camac_exec () \n";
               mess = s2;

/*  Begin !!!!  E.Inoue !!!!
  End !!!!  E.Inoue !!!! */

            } catch (NumberFormatException e) {
               s2 = mess + "\n" + "keyincmd: Error:   NumberFormatException occu
rred !! \n";
               mess = s2;
            }


      s2 = mess + "\n" + "keyincmd: " + "Sent Reply command field = 0xe0030010"
+ ",    data field = 0x555";
      mess = s2;


      return;
      }
}
[inoue@onlsbc1 Web]$


        (2-1-4B-2).  cam.java

[inoue@onlsbc1 Web]$ cat cam.java
// File name:  cam.java
// Date: Apr 28, 2003
// Edited by: Eiji Inoue
//
//
// Parallel camac
// packet format of basic camac opeation
// TX
// +---------+-------+-------+-------+-------+---------------------------+
// |   cmd   |   N   |   A   |   F   |       |       24-bit DATA         |
// +---------+-------+-------+-------+-------+---------------------------+
//
// RX
// +---------+-------+-------+-------+-------+---------------------------+
// |  rply   |   N   |   A   |   F   |  ST   |       24-bit DATA         |
// +---------+-------+-------+-------+-------+---------------------------+


public class cam {

  public native int cmdArray(int j_cmd[], int j_dat[], int jrp_cmd[], int jrp_da
t[], int j_length, int j_examN);

  static {
    System.loadLibrary("MyImpOfcam");
  }
}
[inoue@onlsbc1 Web]$


        (2-1-4B-3).  cam.c

[inoue@onlsbc1 Web]$ more cam.c
// file name:  cam.c
// Date: Apr 28, 2003
// Edited by:  E.Inoue
//
// Parallel camac
// packet format of basic camac opeation
// TX
// +---------+-------+-------+-------+-------+---------------------------+
// |   cmd   |   N   |   A   |   F   |       |       24-bit DATA         |
// +---------+-------+-------+-------+-------+---------------------------+
//
// RX
// +---------+-------+-------+-------+-------+---------------------------+
// |  rply   |   N   |   A   |   F   |  ST   |       24-bit DATA         |
// +---------+-------+-------+-------+-------+---------------------------+

#include    
#include    
#include    
#include    "cam.h"

// exam1.c, from here
#include 
#include 
#include 
#include 
#include 
// #include 
#include 
#include 
#include "pcc.h"
// to

#define BASE 0xE800
#define TX_DATA1REG BASE
#define TX_DATA2REG (BASE+4)
/* #define TX_STATUSREG (BASE+0x10) */
#define TX_STATUSREG (BASE+0x1c)
#define TXSTATUS_BUSY 0x10000
#define TXSTATUS_TIMEOUT 0x20000
#define RX_DATA1REG (BASE+0x20)
#define RX_DATA2REG (BASE+0x24)
/* #define RX_FIFOREG  (BASE+0x30) */
#define RX_FIFOREG  (BASE+0x3c)
#define CMD_F16_A0_N3 0xE0030010
#define CMD_F0_A0_N3 0xE0030000

// exam1.c, read.c, from here
//#define SWREG 4
#define SWREG 3
#define CC_READ 0
#define CC_WRITE 16
#define CC_COUNT 10
#define CC_COUNT1 20
#define BUF_LEN 1000*2
// to


JNIEXPORT jint JNICALL
Java_cam_cmdArray(JNIEnv *env, jobject obj, jintArray r_cmd, jintArray r_dat, ji
ntArray cmd_buf, jintArray rpl_buf, jint length1, jint examN)
{
   int  sum = 0;
   jsize        len1 = (*env)->GetArrayLength(env, r_cmd);
   jint         *c_cmd = (*env)->GetIntArrayElements(env, r_cmd, 0);

   jsize        len2 = (*env)->GetArrayLength(env, r_dat);
   jint         *c_dat = (*env)->GetIntArrayElements(env, r_dat, 0);

   jsize        len3 = (*env)->GetArrayLength(env, cmd_buf);
   jint         *ccmdbuf = (*env)->GetIntArrayElements(env, cmd_buf, 0);

   jsize        len4 = (*env)->GetArrayLength(env, rpl_buf);
   jint         *crplybuf = (*env)->GetIntArrayElements(env, rpl_buf, 0);

   int          loop1 = length1;
   int          ii, j, data, cmd, value;
   int          example = examN;

// exam1.c, exam2.c, exam21.c, exam3.c, exam4.c, exam5.c exam6.c, pio_write_read
.c, read.c, read_write.c from here
   int          fd, i, len;
   int          status, loop = 1;
   int          length = BUF_LEN;
   int*         cbuf = ccmdbuf + 2;
   int*         rbuf = crplybuf + 2;
   int          rply;
   struct       pccreg pccreg;
   unsigned     int i1, j1, k1;
   int          retlen;
   int          *w_buffer, *r_buffer;
   int          count, result;
   int          packet1, packet2;
   struct       pollfd pollfds;
   int          timeout = 5000;/* Timeout in msec. */
// to here.


   printf ("\n   JNI, C side: Received CAMAC command: ");
   printf ("array length = %d\n", length1);

   printf ("example number = %d\n", example);
   switch ( example ) {

   case 0xe:
      // camac Single action from remote machine, from here.
      ccmdbuf[1] = length1 * 2;
//      for (i=1; i < length1 +2; i++) {
      for (i=0; i < length1 +1; i++) {
         printf("      c_cmd[%d] = 0x%x, c_dat[%d] = 0x%x\n", i, c_cmd[i], i, c_
dat[i]);
      }

      if( iopl(3) ){
         printf("can not change the privilege level\n");
         exit(0);
      }

      printf("\n   JNI, C side: CAMAC access\n");
//      for( i = 1; i < loop1 + 1; i++) {
      for( i = 0; i < loop1 + 1; i++) {
         switch (c_cmd[i] & 0x00000018) {

            case 0x00000010 :
               //  CAMAC Write

               //  送信可能状態になるまで待つ
               value = inl(TX_STATUSREG);
               while (value & TXSTATUS_BUSY) {
                  if (value & TXSTATUS_TIMEOUT) break;
                  value = inl(TX_STATUSREG);
               }

               //  camac writeコマンド&データをセットして、PCIレジスタに書き込む
               data = c_dat[i] & 0x00ffffff;
               outl(data, TX_DATA1REG);
               outl(CMD_F16_A0_N3, TX_DATA2REG);
               printf("      camac write data:  data = 0x%x\n", data);

               //  camac応答が読み出し可能状態になるまで待つ
               value = 0;
               do {
                  value = inl(RX_FIFOREG);
                  // for PCI ROM of new version
                  //  value = value >> 24;
               } while( value < 2 );

               //  camacからの受信用レジスタを読んで camacからの応答を得る
               data = inl(RX_DATA1REG);
               cmd = inl(RX_DATA2REG);
               printf("      camac write command reply:  cmd = 0x%x : data = %x\
n", cmd, data);
               c_cmd[i] = cmd;
               c_dat[i] = data;
               break;


            case 0x00000000 :
               //  CAMAC Read

               //  送信可能状態になるまで待つ
               value = inl(TX_STATUSREG);
               while (value & TXSTATUS_BUSY) {
                  if (value & TXSTATUS_TIMEOUT) break;
                  value = inl(TX_STATUSREG);
               }

               //  camac readコマンド&データをセットして、PCIレジスタに書き込む
               outl(CMD_F0_A0_N3, TX_DATA2REG);

               //  camac応答が読み出し可能状態になるまで待つ
               value = 0;
               do {
                  value = inl(RX_FIFOREG);
                  // for PCI ROM of new version
                  //  value = value >> 24;
               } while( value < 2);

               //  camacからの受信用レジスタを読んで camacからの応答を得る
               data = inl(RX_DATA1REG);
               cmd = inl(RX_DATA2REG);
               data = 0xffffff & data;
               ii = 0xffffff & c_dat[i];
               printf("      camac read command reply:  cmd = 0x%x : data = 0x%x
\n", cmd, data);
               c_cmd[i] = cmd;
               c_dat[i] = data;
               break;

            default :
               //  Default
               break;
           }
        }
      break;

   default:
      break;
   }

        (*env)->ReleaseIntArrayElements(env, r_cmd, c_cmd, 0);
        (*env)->ReleaseIntArrayElements(env, r_dat, c_dat, 0);
        (*env)->ReleaseIntArrayElements(env, cmd_buf, ccmdbuf, 0);
        (*env)->ReleaseIntArrayElements(env, rpl_buf, crplybuf, 0);
        return sum;
}
[inoue@onlsbc1 Web]$


        (2-1-4B-4).  コンパイル& 実行

	サーバ側のソフトをコンパイルし起動させる。

[inoue@onlsbc1 Web]$ pwd
/home/inoue/public_html/Web
[inoue@onlsbc1 Web]$ make clean
rm -f *.class cam.h libMyImpOfcam.so *.o core *~
[inoue@onlsbc1 Web]$ make
javac web3.java
javac cam.java
javah -jni cam
gcc -c camac.c
gcc -O -shared -I/usr/java/include -I/usr/java/include/linux cam.c camac.o -o li
bMyImpOfcam.so
javac ServerImpl.java
rmic ClientImpl
rmic ServerImpl
[inoue@onlsbc1 Web]$

[root@onlsbc1 Web]# ps -ef
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 Jun16 ?        00:00:04 init
root         2     1  0 Jun16 ?        00:00:00 [keventd]
root         3     1  0 Jun16 ?        00:00:00 [kapmd]
root         4     1  0 Jun16 ?        00:00:00 [ksoftirqd_CPU0]
root         5     1  0 Jun16 ?        00:00:00 [kswapd]
root         6     1  0 Jun16 ?        00:00:00 [bdflush]
root         7     1  0 Jun16 ?        00:00:00 [kupdated]
root         8     1  0 Jun16 ?        00:00:00 [mdrecoveryd]
root        12     1  0 Jun16 ?        00:00:00 [kjournald]
root        63     1  0 Jun16 ?        00:00:00 [khubd]
root       433     1  0 Jun16 ?        00:00:00 syslogd -m 0
root       437     1  0 Jun16 ?        00:00:00 klogd -x
rpc        448     1  0 Jun16 ?        00:00:00 [portmap]
root       511     1  0 Jun16 ?        00:00:11 /usr/sbin/sshd
root       523     1  0 Jun16 ?        00:00:01 [login]
root       524     1  0 Jun16 tty2     00:00:00 /sbin/mingetty tty2
root       525     1  0 Jun16 tty3     00:00:00 /sbin/mingetty tty3
root       526     1  0 Jun16 tty4     00:00:00 /sbin/mingetty tty4
root       527     1  0 Jun16 tty5     00:00:00 /sbin/mingetty tty5
root       528     1  0 Jun16 tty6     00:00:00 /sbin/mingetty tty6
inoue      935   523  0 Jun23 tty1     00:00:00 -bash
root      3350     1  0 08:31 ?        00:00:00 [rpciod]
root      3351     1  0 08:31 ?        00:00:00 [lockd]
root      3406   511  0 08:35 ?        00:00:00 /usr/sbin/sshd
inoue     3408  3406  0 08:35 ?        00:00:18 [sshd]
inoue     3409  3408  0 08:35 pts/0    00:00:01 -bash
root      7504  3409  1 16:30 pts/0    00:00:00 [su]
root      7505  7504  3 16:30 pts/0    00:00:00 bash
root      7535  7505  0 16:30 pts/0    00:00:00 ps -ef
[root@onlsbc1 Web]#

	この時点ではすでに、
	    #  /sbin/insmod pcc.o
	は実行されて、pccドライバはロードされていること。

[root@onlsbc1 public_html]# pwd
/home/inoue/public_html
[root@onlsbc1 public_html]# ./w e840 1
outl(0x1, 0x0000e840)
[root@onlsbc1 public_html]#

[root@onlsbc1 Web]# /sbin/service httpd start
httpdを起動中:                                             [  OK  ]
[root@onlsbc1 Web]# export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH
[root@onlsbc1 Web]# rmiregistry &
[1] 7569
[root@onlsbc1 Web]# java ServerImpl
bind done
 RMI: Server side:
   RMI: Received CAMAC command: array length = 1
      cmd[0] = 0xe0030010, dat[0] = 0xffff
      cmd[1] = 0x0, dat[1] = 0x0

   JNI, Java side: before Native Call
      ServerImpl.r_cmd[0] = 0xe0030010, ServerImpl.r_dat[0] = 0xffff
      ServerImpl.r_cmd[1] = 0x0, ServerImpl.r_dat[1] = 0x0

   JNI, C side: Received CAMAC command: array length = 1
example number = 14
      c_cmd[0] = 0xe0030010, c_dat[0] = 0xffff
      c_cmd[1] = 0x0, c_dat[1] = 0x0

   JNI, C side: CAMAC access
      camac write data:  data = 0xffff
      camac write command reply:  cmd = 0xe0030010 : data = 23000000
      camac read command reply:  cmd = 0xe0030000 : data = 0xffff

   JNI, Java side: after Native Call array length = 1





 RMI: Server side:
   RMI: Received CAMAC command: array length = 1
      cmd[0] = 0xe0030000, dat[0] = 0xffff
      cmd[1] = 0x0, dat[1] = 0x0

   JNI, Java side: before Native Call
      ServerImpl.r_cmd[0] = 0xe0030000, ServerImpl.r_dat[0] = 0xffff
      ServerImpl.r_cmd[1] = 0x0, ServerImpl.r_dat[1] = 0x0

   JNI, C side: Received CAMAC command: array length = 1
example number = 14
      c_cmd[0] = 0xe0030000, c_dat[0] = 0xffff
      c_cmd[1] = 0x0, c_dat[1] = 0x0

   JNI, C side: CAMAC access
      camac read command reply:  cmd = 0xe0030000 : data = 0xffff
      camac read command reply:  cmd = 0xe0030000 : data = 0xffff

   JNI, Java side: after Native Call array length = 1




 RMI: Server side:
   RMI: Received CAMAC command: array length = 1
      cmd[0] = 0xe0030010, dat[0] = 0x5555
      cmd[1] = 0x0, dat[1] = 0x0

   JNI, Java side: before Native Call
      ServerImpl.r_cmd[0] = 0xe0030010, ServerImpl.r_dat[0] = 0x5555
      ServerImpl.r_cmd[1] = 0x0, ServerImpl.r_dat[1] = 0x0

   JNI, C side: Received CAMAC command: array length = 1
example number = 14
      c_cmd[0] = 0xe0030010, c_dat[0] = 0x5555
      c_cmd[1] = 0x0, c_dat[1] = 0x0

   JNI, C side: CAMAC access
      camac write data:  data = 0x5555
      camac write command reply:  cmd = 0xe0030010 : data = 23000000
      camac read command reply:  cmd = 0xe0030000 : data = 0x5555

   JNI, Java side: after Native Call array length = 1




 RMI: Server side:
   RMI: Received CAMAC command: array length = 1
      cmd[0] = 0xe0030000, dat[0] = 0x5555
      cmd[1] = 0x0, dat[1] = 0x0

   JNI, Java side: before Native Call
      ServerImpl.r_cmd[0] = 0xe0030000, ServerImpl.r_dat[0] = 0x5555
      ServerImpl.r_cmd[1] = 0x0, ServerImpl.r_dat[1] = 0x0

   JNI, C side: Received CAMAC command: array length = 1
example number = 14
      c_cmd[0] = 0xe0030000, c_dat[0] = 0x5555
      c_cmd[1] = 0x0, c_dat[1] = 0x0

   JNI, C side: CAMAC access
      camac read command reply:  cmd = 0xe0030000 : data = 0x5555
      camac read command reply:  cmd = 0xe0030000 : data = 0x5555

   JNI, Java side: after Native Call array length = 1


        (2-1-4B-5).  リモートからのアクセス

	サーバ側のソフトを起動しておいてから、リモートからWebブラウザでアクセス
	する。



	ok.  IE6.0からonlsbc1にアクセスして、ポートI/OによるCAMACアクセスが実行
	できた。


     (2-1-5).  CAMACライブラリおよびドライバを使用する

	上記の項目2-1-4での実行は、ポートI/OによるCAMACアクセスであった。 ここ
	ではCAMACライブラリおよびドライバを使用してCAMACアクセスするように変更
	して実行する。


     (2-1-5A).  CAMACライブラリおよびドライバのインストール

[inoue@onlsbc1 camac]$ df -k
Filesystem           1K-ブロック    使用   使用可 使用% マウント位置
/dev/hdc1               484602    433175     26405  95% /
none                    152188         0    152188   0% /dev/shm
onlpara:/home2/onlpara-wrk
                      22659860   1186812  20321992   6% /home
[inoue@onlsbc1 camac]$
[inoue@onlsbc1 camac]$ pwd
/home/inoue/public_html/camac
[inoue@onlsbc1 camac]$ make clean
rm -f *.o *~ core \
pio_write_read write_read read_write \
gen_cam dec_cam dump_reg measure \
exam1 exam2 exam21 exam22 exam23 exam3 exam4 exam5 exam6 \
cam put_cam get_cam clr_fifo
[inoue@onlsbc1 camac]$ make
gcc -O2 -Wall -c -D__KERNEL__ -DMODULE -Wall -I/usr/src/linux-2.4/include  pcc.c
pcc.c: 関数 `pcc_interrupt' 内:
pcc.c:171: 警告: 変数 `data' は使われませんでした
pcc.c: 関数 `pcc_read' 内:
pcc.c:528: 警告: 変数 `i' は使われませんでした
pcc.c: 関数 `pcc_write' 内:
pcc.c:600: 警告: 変数 `i' は使われませんでした
pcc.c: 関数 `init_module' 内:
pcc.c:692: 警告: 変数 `i' は使われませんでした
pcc.c: トップレベル:
pcc.c:53: 警告: `tv' が定義されましたが使われませんでした
gcc -c camac.c
gcc -c camlib.c
gcc -o gen_cam gen_cam.c camac.o
gcc -o dec_cam dec_cam.c camac.o
gcc -o dump_reg dump_reg.c camac.o
gcc -o measure measure.c camac.o
gcc -o exam0 exam0.c camac.o
gcc -o exam1 exam1.c data_pattern.c camac.o
exam1.c: 関数 `main' 内:
exam1.c:130: 警告: 複合文の終りでラベルを使うことは推奨されません
gcc -o exam2 exam2.c data_pattern.c camac.o
gcc -o exam3 exam3.c data_pattern.c camac.o
gcc -o exam4 exam4.c data_pattern.c camac.o
gcc -o cam cam.c camac.o
gcc -o put_cam put_cam.c camac.o
gcc -o get_cam get_cam.c camac.o
gcc -o clr_fifo clr_fifo.c camac.o
gcc -o rst_cam rst_cam.c camac.o
gcc -o camtest1c camtest1c.c camlib.c camac.o
[inoue@onlsbc1 camac]$
[inoue@onlsbc1 camac]$ ls -l
合計 532
-rw-r--r--    1 inoue    inoue        2237  6月 25 14:42 Makefile
-rw-r--r--    1 inoue    inoue        1072  6月 27 10:02 README
-rwxrwxr-x    1 inoue    inoue       19519  7月  2 08:57 cam
-rw-rw-r--    1 inoue    inoue        1050  4月 29 10:47 cam.c
-rwxrwxr-x    1 inoue    inoue         158  4月 23 13:42 cam.sh
-rw-rw-r--    1 inoue    inoue       13325  6月 27 11:22 camac.c
-rw-rw-r--    1 inoue    inoue        8600  7月  2 08:57 camac.o
-rw-r--r--    1 inoue    inoue        2705  6月 27 11:14 camlib.c
-rw-r--r--    1 inoue    inoue         212  6月 27 14:35 camlib.h
-rw-rw-r--    1 inoue    inoue        2824  7月  2 08:57 camlib.o
-rwxrwxr-x    1 inoue    inoue       21333  7月  2 08:57 camtest1c
-rw-rw-r--    1 inoue    inoue        1882  6月 27 11:16 camtest1c.c
-rwxrwxr-x    1 inoue    inoue       18937  7月  2 08:57 clr_fifo
-rw-rw-r--    1 inoue    inoue         411  4月 29 16:32 clr_fifo.c
-rw-rw-r--    1 inoue    inoue        3286  6月 23 14:51 data_pattern.c
-rwxrwxr-x    1 inoue    inoue       19171  7月  2 08:57 dec_cam
-rw-rw-r--    1 inoue    inoue         480  4月 29 11:05 dec_cam.c
-rwxrwxr-x    1 inoue    inoue       18969  7月  2 08:57 dump_reg
-rw-rw-r--    1 inoue    inoue         468  6月 25 14:01 dump_reg.c
-rwxrwxr-x    1 inoue    inoue       21846  7月  2 08:57 exam0
-rw-rw-r--    1 inoue    inoue        4454  6月 13 13:56 exam0.c
-rwxrwxr-x    1 inoue    inoue       24033  7月  2 08:57 exam1
-rw-rw-r--    1 inoue    inoue        4002  7月  1 19:04 exam1.c
-rwxrwxr-x    1 inoue    inoue       23449  7月  2 08:57 exam2
-rw-rw-r--    1 inoue    inoue        3245  6月 20 15:17 exam2.c
-rwxrwxr-x    1 inoue    inoue       22529  7月  2 08:57 exam3
-rw-rw-r--    1 inoue    inoue        2451  6月 27 11:34 exam3.c
-rwxrwxr-x    1 inoue    inoue       21857  7月  2 08:57 exam4
-rw-rw-r--    1 inoue    inoue        1754  6月 27 11:35 exam4.c
-rwxrwxr-x    1 inoue    inoue       20032  4月 28 21:07 gen
-rwxrwxr-x    1 inoue    inoue       19363  7月  2 08:57 gen_cam
-rw-rw-r--    1 inoue    inoue         619  4月 29 11:05 gen_cam.c
-rwxrwxr-x    1 inoue    inoue       19000  7月  2 08:57 get_cam
-rw-rw-r--    1 inoue    inoue         473  4月 29 18:53 get_cam.c
drwxrwxr-x    2 inoue    inoue        4096  6月 27 13:28 junk
-rwxrwxr-x    1 inoue    inoue          65  4月 30 19:14 loop.sh
-rwxrwxr-x    1 inoue    inoue       20527  7月  2 08:57 measure
-rw-rw-r--    1 inoue    inoue        3165  4月 30 19:07 measure.c
-rw-rw-r--    1 inoue    inoue         269  4月 23 11:38 measure.txt
drwxrwxr-x    2 inoue    inoue        4096  6月 16 15:36 old
-rw-r--r--    1 inoue    inoue       23469  6月 27 11:32 pcc.c
-rw-r--r--    1 inoue    inoue        6364  6月 23 14:07 pcc.h
-rw-rw-r--    1 inoue    inoue       10632  7月  2 08:57 pcc.o
-rw-rw-r--    1 inoue    inoue         682  4月  8 14:23 performance.txt
-rwxrwxr-x    1 inoue    inoue       19203  7月  2 08:57 put_cam
-rw-rw-r--    1 inoue    inoue         573  4月 29 15:59 put_cam.c
-rwxrwxr-x    1 inoue    inoue       18936  7月  2 08:57 rst_cam
-rw-rw-r--    1 inoue    inoue         401  4月 29 16:32 rst_cam.c
[inoue@onlsbc1 camac]$

	/devディレクトリに pcc0名のデバイスファイルを作成。

[inoue@onlsbc1 camac]$ ls -l /dev | more
			:
crw-------    1 root     root      14,  33  8月 31  2002 patmgr1
brw-rw----    1 root     disk      46,   0  8月 31  2002 pcd0
brw-rw----    1 root     disk      46,   1  8月 31  2002 pcd1
			:
[inoue@onlsbc1 camac]$
[root@onlsbc1 camac]# pwd
/home/inoue/public_html/camac
[root@onlsbc1 camac]# make device
mknod -m 666 /dev/pcc0 c 70 0
[root@onlsbc1 camac]#
[root@onlsbc1 camac]# ls -l /dev/p* | more
			:
crw-------    1 root     root      14,  33  8月 31  2002 /dev/patmgr1
crw-rw-rw-    1 root     root      70,   0  7月  2 09:03 /dev/pcc0
brw-rw----    1 root     disk      46,   0  8月 31  2002 /dev/pcd0
brw-rw----    1 root     disk      46,   1  8月 31  2002 /dev/pcd1
			:
[root@onlsbc1 camac]#

	Linuxカーネルの中に pcc0デバイスドライバをロードする。

[root@onlsbc1 camac]# /sbin/insmod pcc.o
Warning: loading pcc.o will taint the kernel: no license
  See http://www.tux.org/lkml/#export-tainted for information about tainted modu
les
Module pcc loaded, with warnings
[root@onlsbc1 camac]#
[inoue@onlsbc1 camac]$ /bin/dmesg | more
Linux version 2.4.18-27.8.0 (bhcompile@sylvester.devel.redhat.com) (gcc version
3.2 20020903 (Red Hat Linux 8.0 3.2-7)) #1 Fri Mar 14 08:42:52 EST 2003
BIOS-provided physical RAM map:
 BIOS-e820: 0000000000000000 - 00000000000a0000 (usable)
 BIOS-e820: 00000000000f0000 - 0000000000100000 (reserved)
 BIOS-e820: 0000000000100000 - 0000000012ff0000 (usable)
 BIOS-e820: 0000000012ff0000 - 0000000012ff3000 (ACPI NVS)
 BIOS-e820: 0000000012ff3000 - 0000000013000000 (ACPI data)
 BIOS-e820: 00000000ffff0000 - 0000000100000000 (reserved)
303MB LOWMEM available.
On node 0 totalpages: 77808
zone(0): 4096 pages.
zone(1): 73712 pages.
zone(2): 0 pages.
Kernel command line: ro root=/dev/hdc1 ramdisk_size=32768
Initializing CPU#0
Detected 497.763 MHz processor.
Speakup v-1.00 CVS: Tue Jun 11 14:22:53 EDT 2002 : initialized
Console: colour VGA+ 80x25
Calibrating delay loop... 989.59 BogoMIPS
Memory: 301924k/311232k available (1181k kernel code, 6748k reserved, 997k data,
 152k init, 0k highmem)
Dentry cache hash table entries: 65536 (order: 7, 524288 bytes)
Inode cache hash table entries: 32768 (order: 6, 262144 bytes)
Mount cache hash table entries: 8192 (order: 4, 65536 bytes)
ramfs: mounted with options: 
ramfs: max_pages=38012 max_file_pages=0 max_inodes=0 max_dentries=38012
Buffer cache hash table entries: 16384 (order: 4, 65536 bytes)
Page-cache hash table entries: 131072 (order: 7, 524288 bytes)
CPU: Before vendor init, caps: 0084883f 0081813f 0000000e, vendor = 7
CPU: L1 I Cache: 64K (64 bytes/line), D cache 64K (32 bytes/line)
CPU: L2 Cache: 256K (128 bytes/line)
CPU: Processor revision 1.3.1.3, 500 MHz
CPU: Code Morphing Software revision 4.2.5-8-148
CPU: 20010503 11:00 official release 4.2.5#1
CPU: After vendor init, caps: 0084893f 0081813f 0000000e 00000000
CPU serial number disabled.
CPU:     After generic, caps: 0080893f 0081813f 0000000e 00000000
CPU:             Common caps: 0080893f 0081813f 0000000e 00000000
CPU: Transmeta(tm) Crusoe(tm) Processor TM5400 stepping 03
Checking 'hlt' instruction... OK.
Checking for popad bug... OK.
POSIX conformance testing by UNIFIX
mtrr: v1.40 (20010327) Richard Gooch (rgooch@atnf.csiro.au)
mtrr: detected mtrr type: none
PCI: PCI BIOS revision 2.10 entry at 0xfb330, last bus=0
PCI: Using configuration type 1
PCI: Probing PCI hardware
PCI: Using IRQ router VIA [1106/0686] at 00:07.0
isapnp: Scanning for PnP cards...
isapnp: No Plug & Play device found
speakup:  initialized device: /dev/synth, node (MAJOR 10, MINOR 25)
Linux NET4.0 for Linux 2.4
Based upon Swansea University Computer Society NET3.039
Initializing RT netlink socket
apm: BIOS version 1.2 Flags 0x07 (Driver version 1.16)
Starting kswapd
VFS: Diskquotas version dquot_6.5.0 initialized
Detected PS/2 Mouse Port.
pty: 512 Unix98 ptys configured
Serial driver version 5.05c (2001-07-08) with MANY_PORTS MULTIPORT SHARE_IRQ SER
IAL_PCI ISAPNP enabled
ttyS0 at 0x03f8 (irq = 4) is a 16550A
ttyS1 at 0x02f8 (irq = 3) is a 16550A
Real Time Clock Driver v1.10e
block: 576 slots per queue, batch=144
Uniform Multi-Platform E-IDE driver Revision: 6.31
ide: Assuming 33MHz system bus speed for PIO modes; override with idebus=xx
VP_IDE: IDE controller on PCI bus 00 dev 39
VP_IDE: chipset revision 16
VP_IDE: not 100% native mode: will probe irqs later
ide: Assuming 33MHz system bus speed for PIO modes; override with idebus=xx
VP_IDE: VIA vt82c686a (rev 22) IDE UDMA66 controller on pci00:07.1
    ide0: BM-DMA at 0xd000-0xd007, BIOS settings: hda:DMA, hdb:pio
    ide1: BM-DMA at 0xd008-0xd00f, BIOS settings: hdc:pio, hdd:pio
hda: TOSHIBA MK4018GAS, ATA DISK drive
hdc: SanDisk SDCFB-512, ATA DISK drive
ide0 at 0x1f0-0x1f7,0x3f6 on irq 14
ide1 at 0x170-0x177,0x376 on irq 15
hda: 78140160 sectors (40008 MB), CHS=4864/255/63, UDMA(33)
hdc: 1000944 sectors (512 MB) w/1KiB Cache, CHS=993/16/63
ide-floppy driver 0.99.newide
Partition check:
 hda: hda1 hda2 hda3 hda4 < hda5 hda6 hda7 >
 hdc: hdc1
Floppy drive(s): fd0 is 1.44M
FDC 0 is a post-1991 82077
NET4: Frame Diverter 0.46
RAMDISK driver initialized: 16 RAM disks of 32768K size 1024 blocksize
ide-floppy driver 0.99.newide
md: md driver 0.90.0 MAX_MD_DEVS=256, MD_SB_DISKS=27
md: Autodetecting RAID arrays.
md: autorun ...
md: ... autorun DONE.
NET4: Linux TCP/IP 1.0 for NET4.0
IP Protocols: ICMP, UDP, TCP, IGMP
IP: routing cache hash table of 2048 buckets, 16Kbytes
TCP: Hash tables configured (established 32768 bind 65536)
Linux IP multicast router 0.06 plus PIM-SM
NET4: Unix domain sockets 1.0/SMP for Linux NET4.0.
RAMDISK: Compressed image found at block 0
Freeing initrd memory: 122k freed
VFS: Mounted root (ext2 filesystem).
Journalled Block Device driver loaded
 hdc: hdc1
 hdc: hdc1
kjournald starting.  Commit interval 5 seconds
EXT3-fs: mounted filesystem with ordered data mode.
Freeing unused kernel memory: 152k freed
usb.c: registered new driver usbdevfs
usb.c: registered new driver hub
usb-uhci.c: $Revision: 1.275 $ time 08:59:07 Mar 14 2003
usb-uhci.c: High bandwidth mode enabled
PCI: Found IRQ 11 for device 00:07.2
PCI: Sharing IRQ 11 with 00:0e.0
usb-uhci.c: USB UHCI at I/O 0xd400, IRQ 11
usb-uhci.c: Detected 2 ports
usb.c: new USB bus registered, assigned bus number 1
hub.c: USB hub found
hub.c: 2 ports detected
usb-uhci.c: v1.275:USB Universal Host Controller Interface driver
hub.c: USB new device connect on bus1/1, assigned device number 2
usb.c: USB device 2 (vend/prod 0x46d/0xc00c) is not claimed by any active driver
.
usb.c: registered new driver hiddev
usb.c: registered new driver hid
input0: USB HID v1.10 Mouse [Logitech USB Optical Mouse] on usb1:2.0
hid-core.c: v1.8.1 Andreas Gal, Vojtech Pavlik 
hid-core.c: USB HID support drivers
mice: PS/2 mouse device common for all mice
EXT3 FS 2.4-0.9.18, 14 May 2002 on ide1(22,1), internal journal
parport0: PC-style at 0x378 (0x778) [PCSPP,TRISTATE]
parport_pc: Via 686A parallel port: io=0x378
ohci1394: pci_module_init failed
eepro100.c:v1.09j-t 9/29/99 Donald Becker http://www.scyld.com/network/eepro100.
html
eepro100.c: $Revision: 1.36 $ 2000/11/17 Modified by Andrey V. Savochkin  and others
PCI: Found IRQ 11 for device 00:0e.0
PCI: Sharing IRQ 11 with 00:07.2
divert: allocating divert_blk for eth0
eth0: OEM i82557/i82558 10/100 Ethernet, 00:D0:C9:63:67:64, IRQ 11.
  Board assembly 727095-004, Physical connectors present: RJ45
  Primary interface chip i82555 PHY #1.
  General self-test: passed.
  Serial sub-system self-test: passed.
  Internal registers self-test: passed.
  ROM checksum self-test: passed (0xdbd8681d).
usb-uhci.c: interrupt, status 31, frame# 1533
usb-uhci.c: Host controller halted, trying to restart.
PCI: Found IRQ 5 for device 00:09.0
pcc:IO_BASE = e800
irq number of PCC = 5
PCC has been installed.
[inoue@onlsbc1 camac]$

	PCCはインストールされた。


     (2-1-5B).  JNIプログラム、cam.c を変更して実行

	JNIプログラム、cam.cファイルに cam_put()、cam_get()のCAMACコールを書き
	加える。


        (2-1-5B-1).  cam.cファイルの変更

[inoue@onlsbc1 Web]$ pwd
/home/inoue/public_html/Web
[inoue@onlsbc1 Web]$ more cam.c
// file name:  cam.c
// Date: Jul 3, 2003
// Edited by:  E.Inoue
//
// Parallel camac
// packet format of basic camac opeation
// TX
// +---------+-------+-------+-------+-------+---------------------------+
// |   cmd   |   N   |   A   |   F   |       |       24-bit DATA         |
// +---------+-------+-------+-------+-------+---------------------------+
//
// RX
// +---------+-------+-------+-------+-------+---------------------------+
// |  rply   |   N   |   A   |   F   |  ST   |       24-bit DATA         |
// +---------+-------+-------+-------+-------+---------------------------+

#include    
#include    
#include    
#include    "cam.h"

// exam1.c, from here
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include "pcc.h"
// to

#define BASE 0xE800
#define TX_DATA1REG BASE
#define TX_DATA2REG (BASE+4)
/* #define TX_STATUSREG (BASE+0x10) */
#define TX_STATUSREG (BASE+0x1c)
#define TXSTATUS_BUSY 0x10000
#define TXSTATUS_TIMEOUT 0x20000
#define RX_DATA1REG (BASE+0x20)
#define RX_DATA2REG (BASE+0x24)
/* #define RX_FIFOREG  (BASE+0x30) */
#define RX_FIFOREG  (BASE+0x3c)
#define CMD_F16_A0_N3 0xE0030010
#define CMD_F0_A0_N3 0xE0030000

// exam1.c, read.c, from here
//#define SWREG 4
#define SWREG 3
#define CC_READ 0
#define CC_WRITE 16
#define CC_COUNT 10
#define CC_COUNT1 20
#define BUF_LEN 1000*2
// to


JNIEXPORT jint JNICALL
Java_cam_cmdArray(JNIEnv *env, jobject obj, jintArray r_cmd, jintArray r_dat, ji
ntArray cmd_buf, jintArray rpl_buf, jint length1, jint examN)
{
   int  sum = 0;
   jsize        len1 = (*env)->GetArrayLength(env, r_cmd);
   jint         *c_cmd = (*env)->GetIntArrayElements(env, r_cmd, 0);

   jsize        len2 = (*env)->GetArrayLength(env, r_dat);
   jint         *c_dat = (*env)->GetIntArrayElements(env, r_dat, 0);

   jsize        len3 = (*env)->GetArrayLength(env, cmd_buf);
   jint         *ccmdbuf = (*env)->GetIntArrayElements(env, cmd_buf, 0);

   jsize        len4 = (*env)->GetArrayLength(env, rpl_buf);
   jint         *crplybuf = (*env)->GetIntArrayElements(env, rpl_buf, 0);

   int          loop1 = length1;
//   int                ii, j, data, cmd, value;
   int          ii, j, data, value;
   int          example = examN;

// exam1.c, exam2.c, exam21.c, exam3.c, exam4.c, exam5.c exam6.c, pio_write_read
.c, read.c, read_write.c from here
   int          fd, i, len;
   int          status, loop = 1;
   int          length = BUF_LEN;
   int*         cbuf = ccmdbuf + 2;
   int*         rbuf = crplybuf + 2;
   int          rply;
   struct       pccreg pccreg;
   unsigned     int i1, j1, k1;
   int          retlen;
   int          *w_buffer, *r_buffer;
   int          count, result;
   int          packet1, packet2;
   struct       pollfd pollfds;
   int          timeout = 5000;/* Timeout in msec. */
// to here.
   int          QX;
   int          wdata, rdata, cmd, reply;


   printf ("\n   JNI, C side: Received CAMAC command: ");
   printf ("array length = %d\n", length1);

   printf ("example number = %d\n", example);
//   switch ( example ) {

//   case 0xe:
      // camac Single action from remote machine, from here.
      ccmdbuf[1] = length1 * 2;
//      for (i=1; i < length1 +2; i++) {
      for (i=0; i < length1 +1; i++) {
         printf("      c_cmd[%d] = 0x%x, c_dat[%d] = 0x%x\n", i, c_cmd[i], i, c_
dat[i]);
      }

/*
      if( iopl(3) ){
         printf("can not change the privilege level\n");
//         exit(0);
      }
*/

  if((fd = cam_open( )) == -1) {
    printf("cam_open error\n");
//    exit(0);
  }

  status = 0;
  cmd = c_cmd[0];
  wdata = c_dat[0] & 0x00fffff;

//  if( (status = cam_put( fd, wdata, cmd )) < 0 ) {
  cam_put( fd, wdata, cmd );
//  if( (status = cam_put( fd, c_dat[0], c_cmd[0] )) < 0 ) {
//      printf("cam_put error\n");
//      exit(0);
//  }
  status = 0;
//  if( (status = cam_get( fd, &rdata, &reply )) < 0 ) {
  cam_get( fd, &rdata, &reply );
//  if( (status = cam_get( fd, &c_dat, &c_cmd[0] )) < 0 ) {
//      printf("cam_get error\n");
//      exit(0);
//    }

  c_cmd[0] = reply;
  c_dat[0] = rdata;

//  QX = (rdata >> 24) & 3;
  QX = (c_dat[0] >> 24) & 3;
  printf("Q = %d : X = %d ", QX&1, (QX>>1)&1);
//  if( f >=0 && f <= 7 )
//    printf(": data = %x", (rdata&0xFFFFFF));
    printf(": data = %x", (c_dat[0]&0xFFFFFF));
//  printf("\n");

  cam_close( fd );

/*
      if( iopl(3) ){
         printf("can not change the privilege level\n");
         exit(0);
      }

      printf("\n   JNI, C side: CAMAC access\n");
//      for( i = 1; i < loop1 + 1; i++) {
      for( i = 0; i < loop1 + 1; i++) {
         switch (c_cmd[i] & 0x00000018) {

            case 0x00000010 :
               //  CAMAC Write

               //  送信可能状態になるまで待つ
               value = inl(TX_STATUSREG);
               while (value & TXSTATUS_BUSY) {
                  if (value & TXSTATUS_TIMEOUT) break;
                  value = inl(TX_STATUSREG);
               }

               //  camac writeコマンド&データをセットして、PCIレジスタに書き込む
               data = c_dat[i] & 0x00ffffff;
               outl(data, TX_DATA1REG);
               outl(CMD_F16_A0_N3, TX_DATA2REG);
               printf("      camac write data:  data = 0x%x\n", data);

               //  camac応答が読み出し可能状態になるまで待つ
               value = 0;
               do {
                  value = inl(RX_FIFOREG);
                  // for PCI ROM of new version
                  //  value = value >> 24;
               } while( value < 2 );

               //  camacからの受信用レジスタを読んで camacからの応答を得る
               data = inl(RX_DATA1REG);
               cmd = inl(RX_DATA2REG);
               printf("      camac write command reply:  cmd = 0x%x : data = %x\
n", cmd, data);
               c_cmd[i] = cmd;
               c_dat[i] = data;
               break;


            case 0x00000000 :
               //  CAMAC Read

               //  送信可能状態になるまで待つ
               value = inl(TX_STATUSREG);
               while (value & TXSTATUS_BUSY) {
                  if (value & TXSTATUS_TIMEOUT) break;
                  value = inl(TX_STATUSREG);
               }

               //  camac readコマンド&データをセットして、PCIレジスタに書き込む
               outl(CMD_F0_A0_N3, TX_DATA2REG);

               //  camac応答が読み出し可能状態になるまで待つ
               value = 0;
               do {
                  value = inl(RX_FIFOREG);
                  // for PCI ROM of new version
                  //  value = value >> 24;
               } while( value < 2);

               //  camacからの受信用レジスタを読んで camacからの応答を得る
               data = inl(RX_DATA1REG);
               cmd = inl(RX_DATA2REG);
               data = 0xffffff & data;
               ii = 0xffffff & c_dat[i];
               printf("      camac read command reply:  cmd = 0x%x : data = 0x%x
\n", cmd, data);
               c_cmd[i] = cmd;
               c_dat[i] = data;
               break;

            default :
               //  Default
               break;
           }
        }
      break;

   default:
      break;

   }
*/

        (*env)->ReleaseIntArrayElements(env, r_cmd, c_cmd, 0);
        (*env)->ReleaseIntArrayElements(env, r_dat, c_dat, 0);
        (*env)->ReleaseIntArrayElements(env, cmd_buf, ccmdbuf, 0);
        (*env)->ReleaseIntArrayElements(env, rpl_buf, crplybuf, 0);
        return sum;
}
[inoue@onlsbc1 Web]$


        (2-1-5B-2).  コンパイルおよび web3プログラムの実行

[inoue@onlsbc1 Web]$ pwd
/home/inoue/public_html/Web
[inoue@onlsbc1 Web]$ make clean
rm -f *.class cam.h libMyImpOfcam.so *.o core *~
[inoue@onlsbc1 Web]$ make
gcc -c camac.c
javac web3.java
javac cam.java
javah -jni cam
gcc -O -shared -I/usr/java/include -I/usr/java/include/linux cam.c camac.o -o li
bMyImpOfcam.so
javac ServerImpl.java
rmic ClientImpl
rmic ServerImpl
[inoue@onlsbc1 Web]$

[root@onlsbc1 Web]# /sbin/service httpd start
httpdを起動中:                                             [  OK  ]
[root@onlsbc1 Web]#

[root@onlsbc1 public_html]# pwd
/home/inoue/public_html
[root@onlsbc1 public_html]# ./w e840 1
outl(0x1, 0x0000e840)
[root@onlsbc1 public_html]#

[root@onlsbc1 Web]# pwd
/home/inoue/public_html/Web
[root@onlsbc1 Web]# export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH
[root@onlsbc1 Web]# rmiregistry &
[1] 1602
[root@onlsbc1 Web]# java ServerImpl
bind done
 RMI: Server side:
   RMI: Received CAMAC command: array length = 1
      cmd[0] = 0xe0030010, dat[0] = 0x5555
      cmd[1] = 0x0, dat[1] = 0x0

   JNI, Java side: before Native Call
      ServerImpl.r_cmd[0] = 0xe0030010, ServerImpl.r_dat[0] = 0x5555
      ServerImpl.r_cmd[1] = 0x0, ServerImpl.r_dat[1] = 0x0

   JNI, C side: Received CAMAC command: array length = 1
example number = 14
      c_cmd[0] = 0xe0030010, c_dat[0] = 0x5555
      c_cmd[1] = 0x0, c_dat[1] = 0x0

   JNI, Java side: after Native Call array length = 1



 RMI: Server side:
   RMI: Received CAMAC command: array length = 1
      cmd[0] = 0xe0030000, dat[0] = 0x5555
      cmd[1] = 0x0, dat[1] = 0x0

   JNI, Java side: before Native Call
      ServerImpl.r_cmd[0] = 0xe0030000, ServerImpl.r_dat[0] = 0x5555
      ServerImpl.r_cmd[1] = 0x0, ServerImpl.r_dat[1] = 0x0
Q = 1 : X = 1 : data = ffff
   JNI, C side: Received CAMAC command: array length = 1
example number = 14
      c_cmd[0] = 0xe0030000, c_dat[0] = 0x5555
      c_cmd[1] = 0x0, c_dat[1] = 0x0

   JNI, Java side: after Native Call array length = 1



 RMI: Server side:
   RMI: Received CAMAC command: array length = 1
      cmd[0] = 0xe0030010, dat[0] = 0xffff
      cmd[1] = 0x0, dat[1] = 0x0

   JNI, Java side: before Native Call
      ServerImpl.r_cmd[0] = 0xe0030010, ServerImpl.r_dat[0] = 0xffff
      ServerImpl.r_cmd[1] = 0x0, ServerImpl.r_dat[1] = 0x0
Q = 1 : X = 1 : data = 0
   JNI, C side: Received CAMAC command: array length = 1
example number = 14
      c_cmd[0] = 0xe0030010, c_dat[0] = 0xffff
      c_cmd[1] = 0x0, c_dat[1] = 0x0

   JNI, Java side: after Native Call array length = 1



 RMI: Server side:
   RMI: Received CAMAC command: array length = 1
      cmd[0] = 0xe0030000, dat[0] = 0xffff
      cmd[1] = 0x0, dat[1] = 0x0

   JNI, Java side: before Native Call
      ServerImpl.r_cmd[0] = 0xe0030000, ServerImpl.r_dat[0] = 0xffff
      ServerImpl.r_cmd[1] = 0x0, ServerImpl.r_dat[1] = 0x0
Q = 1 : X = 1 : data = 5555
   JNI, C side: Received CAMAC command: array length = 1
example number = 14
      c_cmd[0] = 0xe0030000, c_dat[0] = 0xffff
      c_cmd[1] = 0x0, c_dat[1] = 0x0

   JNI, Java side: after Native Call array length = 1



        (2-1-5B-3).  リモートからのアクセス

	サーバ側のソフトを起動しておいてから、リモートからWebブラウザでアクセス
	する。



	ok.   正しく実行できた。
	

        (2-1-5B-4).  不要なメッセージ等を削除

	テストの途中で挿入した不要なメッセージ出力や不必要な命令文を削除する。

	ゴミ落としをやった後の実行。

[root@onlsbc1 Web]# ./web.sh
Wait.  In Process .............
bind done
 RMI: Server side:
   JNI, Java side: Received CAMAC command: array length = 1
      cmd[0] = 0xe0030010, dat[0] = 0xffff
      cmd[1] = 0x0, dat[1] = 0x0

   JNI, Java side: before Native Call
      ServerImpl.r_cmd[0] = 0xe0030010, ServerImpl.r_dat[0] = 0xffff
      ServerImpl.r_cmd[1] = 0x0, ServerImpl.r_dat[1] = 0x0

   JNI, C side: Received CAMAC command: array length = 1
example number = 14
      c_cmd[0] = 0xe0030010, c_dat[0] = 0xffff
      c_cmd[1] = 0x0, c_dat[1] = 0x0

   JNI, Java side: after Native Call array length = 1
      ServerImpl.r_cmd[0] = 0xe0030010, ServerImpl.r_dat[0] = 0x23000000
      ServerImpl.r_cmd[1] = 0x0, ServerImpl.r_dat[1] = 0x0

 RMI: Server side:
   JNI, Java side: Received CAMAC command: array length = 1
      cmd[0] = 0xe0030000, dat[0] = 0xffff
      cmd[1] = 0x0, dat[1] = 0x0

   JNI, Java side: before Native Call
      ServerImpl.r_cmd[0] = 0xe0030000, ServerImpl.r_dat[0] = 0xffff
      ServerImpl.r_cmd[1] = 0x0, ServerImpl.r_dat[1] = 0x0
Q = 1 : X = 1 : data = 0
   JNI, C side: Received CAMAC command: array length = 1
example number = 14
      c_cmd[0] = 0xe0030000, c_dat[0] = 0xffff
      c_cmd[1] = 0x0, c_dat[1] = 0x0

   JNI, Java side: after Native Call array length = 1
      ServerImpl.r_cmd[0] = 0xe0030000, ServerImpl.r_dat[0] = 0x2300ffff
      ServerImpl.r_cmd[1] = 0x0, ServerImpl.r_dat[1] = 0x0



	ok.  これでWebアプリケーションは一通り動作した。


---xxxx