--- /dev/null
+/******************************************************************************
+
+ Actuator Interface Card
+ Command Daemon
+ Copyright (C) 2005 Walter Fetter Lages <w.fetter@ieee.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ You can also obtain a copy of the GNU General Public License
+ at <http://www.gnu.org/licenses>.
+
+*******************************************************************************/
+
+import br.ufrgs.eletro.AIC.*;
+import com.dalsemi.comm.*;
+import com.dalsemi.system.*;
+import java.io.*;
+import java.lang.*;
+
+class CmdDaemon extends Thread
+{
+ static final int BASE=0x800000;
+
+ static AIC aic;
+ static Host host;
+ static boolean debug=false;
+ static boolean udp=false;
+ static boolean help=false;
+
+ public static void main(String[] args) throws IOException,CanBusException
+ {
+ int i;
+ int hostarg=0;
+
+ System.out.println("AIC Command Daemon");
+ System.out.println("Copyright (C) 2005 Walter Fetter Lages <w.fetter@ieee.org>.\n");
+
+ switch(args.length)
+ {
+ case 0:
+ {
+ help=true;
+ break;
+ }
+ case 1:
+ {
+ if(args[0].equals("-debug") ||
+ args[0].equals("-UDP")) help=true;
+ break;
+ }
+ case 2:
+ {
+ hostarg=1;
+ if(args[0].equals("-debug")) debug=true;
+ else help=true;
+ break;
+ }
+ case 3:
+ {
+ hostarg=1;
+ if(args[0].equals("-UDP")) udp=true;
+ else help=true;
+ break;
+ }
+ case 4:
+ {
+ hostarg=2;
+ if(args[0].equals("-debug")) debug=true;
+ else help=true;
+ if(args[1].equals("-UDP")) udp=true;
+ else help=true;
+ break;
+ }
+ default:
+ {
+ help=true;
+ }
+ }
+
+
+ if(help)
+ {
+ System.out.println("Usage:\tjava CmdDaemon.tini [-debug] aic_id");
+ System.out.println("\tor");
+ System.out.println("\tjava CmdDaemon.tini [-debug] -UDP controller_host status_port");
+ System.exit(1);
+ }
+ try
+ {
+ aic=new AIC(BASE,24.0,20e3,2000);
+ if(udp) host=new HostUDP(args[hostarg],Integer.parseInt(args[hostarg+1]));
+ else host=new HostCAN(Integer.parseInt(args[hostarg]));
+
+ GetCommand getCommand=new GetCommand();
+ getCommand.setPriority(Thread.MAX_PRIORITY);
+ getCommand.start();
+
+ if(debug) System.out.println("getCommand priority="+getCommand.getPriority());
+ }
+ catch (NumberFormatException nfe)
+ {
+ System.out.println("Usage: java CmdDaemon.tini [-debug] [-UDP controller_host port] | aicid");
+ System.exit(1);
+ }
+ }
+}
+
+
+class GetCommand extends CmdDaemon
+{
+ public void run()
+ {
+ try
+ {
+ aic.on();
+ aic.brake.release();
+
+ for(int k=0;;k++)
+ {
+ if(debug) System.out.print("k="+k+"\t");
+
+ int cmd=host.command();
+
+ if(debug) System.out.print("Command="+ cmd +"\t");
+
+ switch(cmd)
+ {
+ case Host.MOTOR_ON:
+ {
+ if(debug) System.out.print("Motor on\t");
+ aic.motor.on();
+ break;
+ }
+ case Host.MOTOR_OFF:
+ {
+ if(debug) System.out.print("Motor off\t");
+ aic.motor.off();
+ break;
+ }
+ case Host.MOTOR_ACT:
+ {
+ if(debug) System.out.print("Voltage="+host.voltage()+"\t");
+ aic.motor.set(host.voltage());
+ break;
+ }
+ case Host.BRAKE_RELEASE:
+ {
+ if(debug) System.out.print("Brake release\t");
+ aic.brake.release();
+ break;
+ }
+ case Host.BRAKE_APPLY:
+ {
+ if(debug) System.out.print("Brake apply\t");
+ aic.brake.apply();
+ break;
+ }
+/* case Host.RESET:
+ {
+ if(debug) System.out.print("Reset\t");
+ aic.reset();
+ break;
+ }
+*/
+ default:
+ {
+ if(debug) System.out.print("Invalid\t");
+ break;
+ }
+
+ }
+ if(debug) System.out.println("");
+ }
+ }
+ catch (Exception all)
+ {
+ all.printStackTrace();
+ }
+ }
+}
--- /dev/null
+CLASSPATH=-classpath /opt/tini/bin/tini.jar:/opt/tini/bin/tiniclasses.jar:/opt/tini/bin/modules.jar:../lib/AIC.jar
+APIDBPATH=-d /opt/tini/bin/tini.db
+DEPPATH=-p /opt/tini/bin/modules.jar
+DEPFILE=-x /opt/tini/bin/owapi_dep.txt
+DEPNAME=-add CAN
+LIBPATH=-path ../lib/AIC.jar
+NATLIB=-n brake.tlib -n encoder.tlib -n index.tlib -n pwm.tlib
+JAVAFLAGS=-O -target 1.1 -source 1.3
+TARGET= aic1 aic2 aic3 aic4 aic5
+
+all: CmdDaemon.tini
+
+CmdDaemon.class: CmdDaemon.java ../lib/AIC.jar
+ javac ${JAVAFLAGS} ${CLASSPATH} CmdDaemon.java
+
+CmdDaemon.tini: CmdDaemon.class ../lib/AIC.jar
+ java ${CLASSPATH} BuildDependency ${DEPNAME} ${DEPFILE} ${DEPPATH} -f CmdDaemon.class ${APIDBPATH} -o CmdDaemon.tini ${LIBPATH} ${NATLIB}
+
+clean:
+ rm -f *.bak *~ *.class UPLOADED
+
+distclean: clean
+ rm -f CmdDaemon.tini
+
+upload: UPLOADED
+
+UPLOADED: CmdDaemon.tini
+ for i in ${TARGET}; do \
+ ftp $$i < upload.ftp; \
+ echo $$i uploaded; \
+ done
+
+