org.bluemelon.bluesense
Class Master

java.lang.Object
  extended by org.bluemelon.bluesense.Master

public class Master
extends java.lang.Object

The master class forms the gateway between the BlueSense network and the Java application.


Constructor Summary
Master()
          Constructs a Master with id 0 (default).
Master(int id)
          Constructs a Master a given id.
 
Method Summary
 void addIPAddress(java.lang.String ip, java.lang.String usrName, java.lang.String password)
          Connects to a BlueSense internet master via internet
 void aSyncYield(int intervalUs)
          Takes care of data transmission/reception from the BlueSense network.
 void autoYield(int duration, int interval)
          Calls yield every interval us for a total of duration us.
 void clearDeviceTable()
          Clears the device table.
 void clearMessages()
          Clears last errors
 void close()
          Closes the master.
 Device detectDevice(int id, int timeOut)
          Try to detect a device with a given identifier.
 int detectDevices(int count, int timeOut)
          Detects a number of devices
 void dispose()
          Used by PApplet (Processing) to shut things down.
 Device getDeviceById(int id)
          Returns the device with the given id.
 Device getFirstDevice()
          Gets the first found device from the table.
 java.lang.String getLastMessage(int index)
          Get last error messages
 int getListedDeviceCount()
          Return the total number of found devices in the table.
 int getMessageCount()
          Returns the number of occurred messages
 Device getNextDevice(Device dev)
          Gets the next device from the table.
 long getTimeUs()
           
 void requestDeviceTable()
          Checks if there are new devices.
 void setEventMethod(java.lang.Object data, java.lang.reflect.Method evtMethod)
          Supply a method that will be called when certain events take place.
 void start(int intervalMs)
          Starts communication process.
 void startTimeDebug()
           
 void stop()
          Stops communication process.
 void yield()
          Takes care of data transmission/reception from the BlueSense network.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Master

public Master()
Constructs a Master with id 0 (default).


Master

public Master(int id)
Constructs a Master a given id.

Parameters:
id - Not used at the moment, supply 0.
Method Detail

setEventMethod

public void setEventMethod(java.lang.Object data,
                           java.lang.reflect.Method evtMethod)
Supply a method that will be called when certain events take place. Not used at the moment.

Parameters:
data - object instance on which the method will be called.
evtMethod - the method.

close

public void close()
Closes the master. If the communication was started it will be stopped as well.


start

public void start(int intervalMs)
Starts communication process.

The communication process takes care of the sending and receiving of BlueSense data. The communication process actually automatically calls the yield @see method from within a loop. Either use the automatic communication process or use yield manually. Do not use both!

Parameters:
intervalMs - master.yield is called every intervalMs miliseconds.

stop

public void stop()
Stops communication process.


dispose

public void dispose()
Used by PApplet (Processing) to shut things down.


requestDeviceTable

public void requestDeviceTable()
Checks if there are new devices.


yield

public void yield()
Takes care of data transmission/reception from the BlueSense network. Call this method manually or use the communication process. @see start.


autoYield

public void autoYield(int duration,
                      int interval)
Calls yield every interval us for a total of duration us.

Parameters:
duration - duration of the call
interval - yield is called every interval us.

aSyncYield

public void aSyncYield(int intervalUs)
Takes care of data transmission/reception from the BlueSense network. This method ensures that even if you call aSyncYield more often then every intervalUs, yield is actually still called at the specified interval. Call this method manually or use the communication process. @see start.


clearDeviceTable

public void clearDeviceTable()
Clears the device table. Can be usefull if you unplugged some devices as they are not automatically removed from the table.


getFirstDevice

public Device getFirstDevice()
Gets the first found device from the table. Can be used in conjunction with @see getNextDevice to iterate over the devices.

Returns:
the first Device.

getNextDevice

public Device getNextDevice(Device dev)
Gets the next device from the table. Can be used in conjunction with @see getFirstDevice to iterate over the devices.

Parameters:
dev - the current device
Returns:
the next device.

getListedDeviceCount

public int getListedDeviceCount()
Return the total number of found devices in the table.

Returns:
the number of found devices

getDeviceById

public Device getDeviceById(int id)
Returns the device with the given id. If the device is not found or if it's not registered with the master an UnknownDevice will be returned

Parameters:
id - the id of the device
Returns:
an object of type Device. You can cast this object denpending on its type to a UnknownDevice, AdcInputDevice, etc.

detectDevice

public Device detectDevice(int id,
                           int timeOut)
Try to detect a device with a given identifier.

Parameters:
id - The identifier of the device to detect.
timeOut - The maximum amount of time which detection can take.
Returns:
an object of type Device. You can cast this object denpending on its type to a UnknownDevice, AdcInputDevice, etc.

detectDevices

public int detectDevices(int count,
                         int timeOut)
Detects a number of devices

Parameters:
count - The number of devices to detect.
timeOut - The maximum amount of time which detection can take.
Returns:
the number of new found devices.

startTimeDebug

public void startTimeDebug()

getTimeUs

public long getTimeUs()
Returns:
absolute time in microseconds.

getMessageCount

public int getMessageCount()
Returns the number of occurred messages

Returns:
number of errors

getLastMessage

public java.lang.String getLastMessage(int index)
Get last error messages

Parameters:
index - the index of the error message

addIPAddress

public void addIPAddress(java.lang.String ip,
                         java.lang.String usrName,
                         java.lang.String password)
Connects to a BlueSense internet master via internet

Parameters:
ip - ip address of the internet master
usrName - username
password - password

clearMessages

public void clearMessages()
Clears last errors