How do I make SWAT stuff?

It is fundamentally very simple to make SWAT applications. But before being able to write or test anything, computers and systems have to be set up properly to do so.


Setting up your system
These instructions only pertain to Windows systems, eventually there will be more instructions for other OSes.

First, you must map \\norgay\home to your z: and then add z:\hot\mks\mksnt to your path (you must put them before the windows and windows\command path entries). Then add the following to your CLASSPATH variable: z:\Hot\WWW\codebase\; z:\Hot\WWW\codebase\pia\agents\db; z:\Hot\WWW\codebase\pia\agents\db\objects; z:\hot\pia\midi. The following lines also need to be added to the AUTOEXEC.BAT :
SET HOMEDRIVE=z:
set HOME=z:\Hot\MKS
set ROOTDIR=z:\Hot\MKS
set TMPDIR=C:\WIN95\TEMP
set SHELL=z:\Hot\MKS\mksnt\sh.exe
set LOGNAME=mks

After all this, your machine should be set up completely to use the SWAT system. Unfortunately, the system is setup to be used over a KSH shell as opposed to a MS-DOS shell, but it is possible to use an MS-DOS shell if you are familar with all our macros, but it is undocumented.

To run the KSH shell, simply run sh -L from the command line or set a macro to run it.


Writing your first SWAT app

import java.lang.*;
import java.rmi.*;

import pia.agents.*;
import pia.agents.widgets.*;

public class MessageListener 
implements Listener, ConduitListener, BroadcasterConduitListener {
  private static Ubic TechReaderUbic = new Ubic("12.1");
  private BroadcasterConduit techReaderConduit;

  public MessageListener() { 
    techReaderConduit = new BroadcasterConduit(TechReaderUbic, this);
  }

  public void conduitAvailable(Conduit c) { }
  public void conduitUnavailable(Conduit c) {
    System.out.println("MessageListener ERROR: conduitLost");
    System.exit(0);
  }
 
  public synchronized void message(BroadcasterAgent b, Object o) {
    System.out.print("Message: ");
    if (o instanceof NewUbicMessage) {
      System.out.println("NewUbic!");
    } else if (o instanceof NoUbicMessage) {
      System.out.println("NoUbic!");
    } 
  }

  public static void main(String args[]) {
    MessageListener ml = new MessageListener();
  }
}

To run this app, start the KSH shell, run rmistart, then piastart, then bagstart, then hotstart. At the prompt in the hotstart window, type start 12.1 TechReader COM1 1000. Rmistart runs all the RMI connections necessary, piastart is the master binder and finder for the system, bagstart starts the bitbags, and hotstart runs the devices connected in the system. The command line that you entered into the hotstart start a ID Technologies Tech Reader on COM1 of the machine you are logged in at.

The java file needs to be compiled under JDK1.1, and then can be simply run as java MessageListener. All this app does is tell you when a registered tag is put down on the reader and when it is taken off.

To explain the code:

public class MessageListener 
implements Listener, ConduitListener, BroadcasterConduitListener

Listener allows this app to listen for messages, ConduitListener is the interface for the conduit to the devices, BroadcasterConduitListner listens to messages from the TechReader or any other "broadcasting" device.

  public MessageListener() { 
    techReaderConduit = new BroadcasterConduit(TechReaderUbic, this);
  }
Opens a conduit to the broadcasting device with the 12.1 Ubic with this class being the controller.

  public void conduitAvailable(Conduit c) { }
  public void conduitUnavailable(Conduit c) {
    System.out.println("MessageListener ERROR: conduitLost");
    System.exit(0);
  }
Handles all the conduit connections

  public synchronized void message(BroadcasterAgent b, Object o) {
    System.out.print("Message: ");
    if (o instanceof NewUbicMessage) {
      System.out.println("NewUbic!");
    } else if (o instanceof NoUbicMessage) {
      System.out.println("NoUbic!");
    } 
  } 
Handles all the messages. Whenever a message comes in, the program echos Message to the screen then it sees what kind of message and echos the type after that.


That's it!
There is nothing else to it. There are specialized devices such as the barcode reader or the IR reader that can be put on the SWAT network also.


Bit Bags
If you want to have your own bit bags to let you use the system, first approach Steve Gray or Raffi Krikorian to get the low-down. After you have set up your own bit bag file, it is realitvely simple.

Intead of opening a BroadcasterAgentConduit, open an AgentConduit to the UBIC of the bit bags. AgentConduits have a getAgent() method which will return an interface to it. Use getAgent() and retrieve a BitBagAgent. BitBagAgents have the get(), put, remove, and exists methods which can be used for manipulation.


Not sure what else you want to know. This is basically it. If you have any questions, Steve Gray and Raffi Krikorian cam handle all your quesions. If you want a list of all the methods, try the AllNames.html file.