Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Initial addition of ZigBeeNetworkManager #105

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,14 @@ public class ZigBeeApi {
* The {@link Logger}.
*/
private final static Logger LOGGER = LoggerFactory.getLogger(ZigBeeApi.class);
/**
* The network.
*/
private ZigBeeNetwork network;
/**
* The network state.
*/
private ZigBeeNetworkState networkState;
/**
* The command listener creation times.
*/
private Set<CommandExecution> commandExecutions =
new HashSet<CommandExecution>();

private ZigBeeNetworkManager networkManager;

/**
* Default constructor inheritance.
*/
Expand All @@ -63,40 +57,16 @@ public ZigBeeApi() {
* Constructor for setting the ZCL API.
* @param network the ZCL API
*/
public ZigBeeApi(final ZigBeeNetwork network) {
this.network = network;
}

/**
* Sets network.
* @param network the network
*/
public void setNetwork(final ZigBeeNetwork network) {
this.network = network;
public ZigBeeApi(final ZigBeeNetworkManager networkManager) {
this.networkManager = networkManager;
}

/**
* Gets the ZigBee network.
* @return the ZigBee network
*/
public ZigBeeNetwork getNetwork() {
return network;
}

/**
* Sets network state.
* @param networkState the network state
*/
public void setNetworkState(final ZigBeeNetworkState networkState) {
this.networkState = networkState;
}

/**
* Gets the ZigBee network state.
* @return the ZigBee network state
*/
public ZigBeeNetworkState getNetworkState() {
return networkState;
public ZigBeeNetworkManager getNetwork() {
return networkManager;
}

/**
Expand All @@ -106,27 +76,15 @@ public ZigBeeNetworkState getNetworkState() {
* @param label the label
*/
public void setDeviceLabel(final int networkAddress, final int endPointId, final String label) {
final ZigBeeDevice device = networkState.getDevice(networkAddress, endPointId);
device.setLabel(label);
networkState.updateDevice(device);
networkManager.setDeviceLabel(networkAddress, endPointId, label);
}

/**
* Removes device(s) by network address.
* @param networkAddress the network address
*/
public void removeDevice(final int networkAddress) {
final List<ZigBeeDevice> devices = networkState.getDevices();
final List<ZigBeeDevice> devicesToRemove = new ArrayList<ZigBeeDevice>();
for (final ZigBeeDevice device : devices) {
if (device.getNetworkAddress() == networkAddress) {
devicesToRemove.add(device);
}
}

for (final ZigBeeDevice device : devicesToRemove) {
networkState.removeDevice(device.getNetworkAddress(), device.getEndpoint());
}
networkManager.removeDevice(networkAddress);
}


Expand All @@ -135,7 +93,7 @@ public void removeDevice(final int networkAddress) {
* @return list of ZigBee devices
*/
public List<ZigBeeDevice> getDevices() {
return getNetworkState().getDevices();
return networkManager.getDevices();
}

/**
Expand All @@ -144,21 +102,15 @@ public List<ZigBeeDevice> getDevices() {
* @param label the label
*/
public void addMembership(final int groupId, final String label) {
if (networkState.getGroup(groupId) == null) {
networkState.addGroup(new ZigBeeGroup(groupId, label));
} else {
final ZigBeeGroup group = networkState.getGroup(groupId);
group.setLabel(label);
networkState.updateGroup(group);
}
networkManager.addMembership(groupId, label);
}

/**
* Removes group label.
* @param groupId the group ID
*/
public void removeMembership(final int groupId) {
networkState.removeGroup(groupId);
networkManager.removeMembership(groupId);
}

/**
Expand All @@ -167,15 +119,15 @@ public void removeMembership(final int groupId) {
* @return the ZigBee group or null if no exists with given group ID.
*/
public ZigBeeGroup getGroup(final int groupId) {
return networkState.getGroup(groupId);
return networkManager.getGroup(groupId);
}

/**
* Gets all groups.
* @return list of groups.
*/
public List<ZigBeeGroup> getGroups() {
return networkState.getGroups();
return networkManager.getGroups();
}

/**
Expand Down Expand Up @@ -500,7 +452,7 @@ public void permitJoin(final boolean enable) {
command.setTrustCenterSignificance(1);

try {
network.sendCommand(command);
networkManager.sendCommand(command);
} catch (final ZigBeeException e) {
throw new ZigBeeApiException("Error sending permit join command.", e);
}
Expand Down Expand Up @@ -639,7 +591,7 @@ public void commandReceived(Command receivedCommand) {
commandExecution.setCommandListener(commandListener);
addCommandExecution(commandExecution);
try {
int transactionId = network.sendCommand(command);
int transactionId = networkManager.sendCommand(command);
if (command instanceof ZclCommand) {
((ZclCommand) command).setTransactionId((byte) transactionId);
}
Expand All @@ -661,7 +613,7 @@ private Future<CommandResult> broadcast(final Command command) {
final CommandResultFuture future = new CommandResultFuture(this);

try {
network.sendCommand(command);
networkManager.sendCommand(command);
future.set(new CommandResult(new BroadcastResponse()));
} catch (final ZigBeeException e) {
future.set(new CommandResult(e.toString()));
Expand Down Expand Up @@ -690,7 +642,7 @@ private void addCommandExecution(final CommandExecution commandExecution) {
removeCommandExecution(expiredCommandExecution);
}
commandExecutions.add(commandExecution);
network.addCommandListener(commandExecution.getCommandListener());
networkManager.addCommandListener(commandExecution.getCommandListener());
}
}

Expand All @@ -700,10 +652,15 @@ private void addCommandExecution(final CommandExecution commandExecution) {
*/
protected void removeCommandExecution(CommandExecution expiredCommandExecution) {
commandExecutions.remove(expiredCommandExecution);
network.removeCommandListener(expiredCommandExecution.getCommandListener());
networkManager.removeCommandListener(expiredCommandExecution.getCommandListener());
synchronized (expiredCommandExecution.getFuture()) {
expiredCommandExecution.getFuture().notify();
}
}

public ZigBeeNetworkState getNetworkState() {
// TODO Auto-generated method stub
return networkManager.getNetworkState();
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* ZigBee dongle interface implemented by different dongle hardware drivers.
*/
public interface ZigBeeDongle extends ZigBeeNetwork {
public interface ZigBeeDongle {
/**
* Starts up dongle.
*
Expand All @@ -15,4 +15,16 @@ public interface ZigBeeDongle extends ZigBeeNetwork {
* Shuts down dongle.
*/
void shutdown();

/**
* Sends ZigBee library command without waiting for response.
* @param command the command
* @return transaction ID
* @throws ZigBeeException if exception occurs in sending
*/
int sendCommand(final Command command) throws ZigBeeException;


void setZigBeeNetwork(ZigBeeNetwork zigbeeNetwork);

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,25 @@
*/
public interface ZigBeeNetwork {
/**
* Sends ZigBee Cluster Library command without waiting for response.
* Sends ZigBee library command without waiting for response.
* @param command the command
* @return transaction ID
* @throws ZigBeeException if exception occurs in sending
*/
int sendCommand(final Command command) throws ZigBeeException;
/**
* Adds ZigBee Cluster Library command listener.
* Adds ZigBee library command listener.
* @param commandListener the command listener
*/
void addCommandListener(final CommandListener commandListener);
/**
* Removes ZigBee Cluster Library command listener.
* Removes ZigBee library command listener.
* @param commandListener the command listener
*/
void removeCommandListener(final CommandListener commandListener);

void receiveCommand(final Command command);

void setZigBeeNetwork(ZigBeeNetwork zigbeeNetwork);

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class ZigBeeNetworkDiscoverer implements CommandListener {
/**
* The ZigBee command interface.
*/
private ZigBeeNetwork commandInterface;
private ZigBeeNetworkManager commandInterface;
/**
* The received IEEE addresses.
*/
Expand Down Expand Up @@ -62,12 +62,12 @@ public class ZigBeeNetworkDiscoverer implements CommandListener {
/**
* Discovers ZigBee network state.
* @param networkState the network state
* @param commandInterface the command interface
* @param dongle the command interface
*/
public ZigBeeNetworkDiscoverer(final ZigBeeNetworkState networkState,
final ZigBeeNetwork commandInterface) {
final ZigBeeNetworkManager networkManager) {
this.networkState = networkState;
this.commandInterface = commandInterface;
this.commandInterface = networkManager;
}

/**
Expand Down
Loading