-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a simple logging framework that will let users adapt to any re…
…al logger they choose.
- Loading branch information
Christopher Piggott
committed
Mar 23, 2015
1 parent
43f853c
commit f565f90
Showing
12 changed files
with
435 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
src/main/java/com/autofrog/xbee/api/cache/PlantUmlGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.autofrog.xbee.api.cache; | ||
|
||
import com.autofrog.xbee.api.messages.XbeeNodeDiscovery; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Generates diagrams and reports from a node database | ||
* | ||
* <p/> | ||
* <pre> | ||
* (C) Copyright 2015 Christopher Piggott (cpiggott@gmail.com) | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the GNU Lesser General Public License | ||
* (LGPL) version 2.1 which accompanies this distribution, and is available at | ||
* http://www.gnu.org/licenses/lgpl-2.1.html | ||
* | ||
* This library 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 | ||
* Lesser General Public License for more details. | ||
* </pre> | ||
*/ | ||
public class PlantUmlGenerator { | ||
|
||
private final XbeeConcurrentDeviceAddressMap addressMap; | ||
private final Map<Integer, XbeeNodeDiscovery> discoveries; | ||
|
||
public enum PlantUmlOpts { | ||
SHOW_ALL, | ||
SHOW_NAME, | ||
SHOW_PROFILE, | ||
SHOW_MANUFACTURER, | ||
SHOW_TYPE | ||
} | ||
|
||
public PlantUmlGenerator(XbeeConcurrentDeviceAddressMap addressMap, Map<Integer, XbeeNodeDiscovery> discoveries) { | ||
this.addressMap = addressMap; | ||
this.discoveries = discoveries; | ||
} | ||
|
||
|
||
public String generatePlantUML(PlantUmlOpts... options) { | ||
|
||
/* | ||
* Example PlantUML Output | ||
* | ||
* @startuml | ||
* | ||
* skinparam state { | ||
* BackgroundColor<<coordinator>> lightblue | ||
* BackgroundColor<<router>> red | ||
* BackgroundColor<<endDevice>> yellow | ||
* } | ||
* state 01E3 as "Router 01E3" <<coordinator>> { | ||
* 01E3: Coordinator | ||
* 01E3: 0x00A01020340303FD | ||
* 01E3: Manufacturer: 0x0001 | ||
* 01E3: Profile ID: 0x0001 | ||
* 01E3: Name: xxxHere is its name | ||
* } | ||
* state 01E2 as "Router 01E3" <<router>> { | ||
* 01E2 : Coordinator | ||
* 01E2 : Router | ||
* 01E2 : Manufacturer: 0x0001 | ||
* 01E2 : Profile ID: 0x0001 | ||
* 01E2 : Name: Here is its name | ||
* } | ||
* | ||
* 01E3 --> 01E2 | ||
* | ||
* @enduml | ||
*/ | ||
|
||
|
||
StringBuilder sb = new StringBuilder(); | ||
|
||
for (int id : discoveries.keySet()) { | ||
XbeeNodeDiscovery d = discoveries.get(id); | ||
|
||
String name; | ||
|
||
if (d.getDeviceName() != null) { | ||
name = d.getDeviceName(); | ||
} else { | ||
name = String.format("%04X", d.getAddress()); | ||
} | ||
|
||
sb.append(name); | ||
} | ||
|
||
|
||
return sb.toString(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/main/java/com/autofrog/xbee/api/messages/XbeeAddressableMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.autofrog.xbee.api.messages; | ||
|
||
/** | ||
* <pre> | ||
* (C) Copyright 2015 Christopher Piggott (cpiggott@gmail.com) | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the GNU Lesser General Public License | ||
* (LGPL) version 2.1 which accompanies this distribution, and is available at | ||
* http://www.gnu.org/licenses/lgpl-2.1.html | ||
* | ||
* This library 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 | ||
* Lesser General Public License for more details. | ||
* </pre> | ||
*/ | ||
public abstract class XbeeAddressableMessage extends XbeeMessageBase { | ||
protected final byte[] deviceId; | ||
protected final int address; | ||
|
||
|
||
public XbeeAddressableMessage(byte rawFrameType, byte[] deviceId, int address) { | ||
super(rawFrameType); | ||
this.deviceId = deviceId; | ||
this.address = address; | ||
} | ||
|
||
/** | ||
* Get the network (16 bit) address of the device. | ||
* @note The 16 bit address is not static. It can change under certain conditions, | ||
* such as an address conflict or when a device leaves then re-joins the network. | ||
* To properly identify a device use its full deviceId. | ||
* | ||
* @return | ||
*/ | ||
public final int getAddress() { | ||
return address; | ||
} | ||
|
||
public final byte[] getDeviceId() { | ||
return deviceId; | ||
} | ||
|
||
|
||
/** | ||
* Messages must implement this - essentially a clone of the original message with | ||
* a new network (16-bit) address. | ||
* @param newDeviceId new address | ||
* @return | ||
*/ | ||
protected abstract XbeeAddressableMessage doCloneWithNewDeviceId(byte [] newDeviceId); | ||
|
||
/** | ||
* Return a copy of the object with a modified network address | ||
* @param newDeviceId | ||
* @return | ||
*/ | ||
public XbeeAddressableMessage cloneWithNewDeviceId(byte[] newDeviceId) { | ||
return doCloneWithNewDeviceId(newDeviceId); | ||
} | ||
|
||
} |
Oops, something went wrong.