public final class Network extends Object implements AutoCloseable
| Modifier and Type | Method and Description |
|---|---|
void |
addDevice(PanStamp ps)
Add a user-created device to the panStamp network.
|
void |
addListener(NetworkListener l)
add listener to receive new device events
|
void |
close()
Disconnect the connection and close the network
|
static Network |
create(SwapModem modem)
Create a new network with the given pre-existing SWAP modem.
|
int |
getChannel()
Get the frequency channel
|
PanStamp |
getDevice(int address)
return the device with the given name
|
int |
getDeviceAddress()
get the gateway panStamp's address
|
DeviceLibrary |
getDeviceLibrary()
Return the device library being used to lookup device definitions.
|
List<PanStamp> |
getDevices()
return all the devices associated with this network
|
DeviceStateStore |
getDeviceStore()
Return the device store used to save device state.
|
int |
getNetworkId()
return the network ID for the network supported by this network
|
int |
getSecurityOption()
Get the security option
|
SwapModem |
getSWAPModem()
return the SWAP modem to gain access to the lower layer
|
boolean |
hasDevice(int address)
use to check if a device with the given address is known
|
boolean |
isOpen()
Check if the network is open (is connected to a panStamp network).
|
void |
open()
Open the network.
|
static Network |
openSerial(String port,
int baud)
Create a new serial network (network attached to a serial port) with the
given port and speed, and with the default device library and data store.
|
static Network |
openTcp(String host,
int port)
Create a new TCP/IP network (network attached to a remote TCP service)
with the given host and port, and with the default device library and
data store.
|
void |
removeDevice(int address)
Removes the device with the given address from the network
|
void |
removeListener(NetworkListener l)
remove a listener from the network
|
void |
setChannel(int channel)
Set the frequency channel
|
void |
setDeviceAddress(int addr)
Set the device address for the network panStamp
|
void |
setDeviceLibrary(DeviceLibrary lib)
Set the device library used to lookup device definitions.
|
void |
setDeviceStore(DeviceStateStore store)
Set the device store to use to lookup persisted device registers.
|
void |
setNetworkId(int id)
Set the network ID for the network accessed by this network
|
void |
setSecurityOption(int secOpt)
Set the security option
|
public static Network openSerial(String port, int baud) throws NetworkException
port - The serial port to open, for example COM1 or /dev/ttyS0baud - The speed at which to open it, for example 34800NetworkException - Thrown if there is a problem creating the network.public static Network openTcp(String host, int port) throws NetworkException
host - The host name to which to connect, for example 'localhost' or
'192.168.1.1'port - The TCP port to which to connect.NetworkException - Thrown if there is a problem creating the network.public static Network create(SwapModem modem)
modem - The SWAP modem to use in the network.public boolean isOpen()
public void open()
throws NetworkException
NetworkException - Thrown if there is a problem opening the modem.public void close()
throws ModemException
close in interface AutoCloseableModemException - Thrown if there is a problem
closing the modem supporting the network.public boolean hasDevice(int address)
address - Address of the device we're looking for.public PanStamp getDevice(int address) throws NodeNotFoundException
address - Address of device to finsNodeNotFoundException - Thrown if the device
with the given address cannot be found.public List<PanStamp> getDevices()
public void addDevice(PanStamp ps)
ps - The device to add.public void removeDevice(int address)
address - The address of the device to remove.public void addListener(NetworkListener l)
l - The listener to addpublic void removeListener(NetworkListener l)
l - The listener to removepublic SwapModem getSWAPModem()
public DeviceLibrary getDeviceLibrary()
public DeviceStateStore getDeviceStore()
public void setDeviceLibrary(DeviceLibrary lib)
lib - The library to use.public void setDeviceStore(DeviceStateStore store)
store - The store to use.public int getNetworkId()
throws ModemException
ModemException - Thrown if there is problem
determining the network IDpublic int getChannel()
throws ModemException
ModemException - Thrown if the channel could
not be determined.public int getDeviceAddress()
throws ModemException
ModemException - Thrown if the device address
could not be determined.public int getSecurityOption()
public void setNetworkId(int id)
throws NetworkException
id - The network IDNetworkException - thrown if there is a problem setting the network
IDpublic void setDeviceAddress(int addr)
throws NetworkException
addr - Address to set for the modem device.NetworkException - Thrown if there is a problem setting the modem
device addresspublic void setChannel(int channel)
throws NetworkException
channel - The channel to use.NetworkException - Thrown if there is an error setting the channel.public void setSecurityOption(int secOpt)
secOpt - Security option to use.Copyright © 2015. All rights reserved.