Skip to content

Commit 688c7b2

Browse files
committed
Merge pull request #55 from digidotcom/descalon/s1b-support
Implemented support for the new S1B modules.
2 parents f41fa43 + 7f977ce commit 688c7b2

File tree

3 files changed

+93
-52
lines changed

3 files changed

+93
-52
lines changed

library/src/main/java/com/digi/xbee/api/NodeDiscovery.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,14 @@ public void packetReceived(XBeePacket receivedPacket) {
316316

317317
// In 802.15.4 devices, the discovery finishes when the 'end' command
318318
// is received, so it's not necessary to calculate the timeout.
319-
if (xbeeDevice.getXBeeProtocol() != XBeeProtocol.RAW_802_15_4)
319+
// This also applies to S1B devices working in compatibility mode.
320+
boolean is802Compatible = is802Compatible();
321+
if (!is802Compatible)
320322
deadLine += calculateTimeout(listeners);
321323

322324
sendNodeDiscoverCommand(id);
323325

324-
if (xbeeDevice.getXBeeProtocol() != XBeeProtocol.RAW_802_15_4) {
326+
if (!is802Compatible) {
325327
// Wait for scan timeout.
326328
while (discovering) {
327329
if (System.currentTimeMillis() < deadLine)
@@ -625,4 +627,24 @@ public String toString() {
625627
return getClass().getName() + " [" + xbeeDevice.toString() + "] @" +
626628
Integer.toHexString(hashCode());
627629
}
630+
631+
/**
632+
* Checks whether the device performing the node discovery is a legacy
633+
* 802.15.4 device or a S1B device working compatibility mode.
634+
*
635+
* @return {@code true} if the device performing the node discovery is a
636+
* legacy 802.15.4 device or S1B in compatibility mode, {@code false}
637+
* otherwise.
638+
*/
639+
private boolean is802Compatible() {
640+
if (xbeeDevice.getXBeeProtocol() != XBeeProtocol.RAW_802_15_4)
641+
return false;
642+
byte[] param = null;
643+
try {
644+
param = xbeeDevice.getParameter("C8");
645+
} catch (Exception e) { }
646+
if (param == null || ((param[0] & 0x2) == 2 ))
647+
return true;
648+
return false;
649+
}
628650
}

library/src/main/java/com/digi/xbee/api/models/HardwareVersionEnum.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,13 @@ public enum HardwareVersionEnum {
6767
XB24C_TH_DIP(0x2E, "XB24C (TH-DIP): XBee DIP"),
6868
XLR_BASEBOARD(0x2F, "XLR Baseboard"),
6969
XBP24C_S2C_SMT(0x30, "XBee PRO SMT"),
70-
XTEND_GEN3(0x31, "XTend Gen 3");
70+
SX_PRO(0x31, "SX Pro"),
71+
S2D_SMT_PRO(0x32, "XBP24D: S2D SMT PRO"),
72+
S2D_SMT_REG(0x33, "XB24D: S2D SMT Reg"),
73+
S2D_TH_PRO(0x34, "XBP24D: S2D TH PRO"),
74+
S2D_TH_REG(0x35, "XB24D: S2D TH Reg"),
75+
SX(0x3E, "SX"),
76+
XTR(0x3F, "XTR");
7177

7278
// Variables
7379
private final int value;

library/src/main/java/com/digi/xbee/api/models/XBeeProtocol.java

Lines changed: 62 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public enum XBeeProtocol {
3333
XC(10, "XSC"),
3434
XLR(11, "XLR"),
3535
XLR_DM(12, "XLR"), // TODO [XLR_DM] XLR device with DigiMesh support.
36+
SX(13, "XBee SX"),
37+
XLR_MODULE(14, "XLR Module"),
3638
UNKNOWN(99, "Unknown");
3739

3840
// Variables
@@ -105,78 +107,77 @@ public static XBeeProtocol get(int id) {
105107
* @see HardwareVersion
106108
*/
107109
public static XBeeProtocol determineProtocol(HardwareVersion hardwareVersion, String firmwareVersion) {
108-
if (hardwareVersion == null || firmwareVersion == null || hardwareVersion.getValue() < 0x09)
110+
if (hardwareVersion == null || firmwareVersion == null || hardwareVersion.getValue() < 0x09
111+
|| HardwareVersionEnum.get(hardwareVersion.getValue()) == null)
109112
return UNKNOWN;
110-
else if (hardwareVersion.getValue() == HardwareVersionEnum.XC09_009.getValue()
111-
|| hardwareVersion.getValue() == HardwareVersionEnum.XC09_038.getValue())
113+
switch (HardwareVersionEnum.get(hardwareVersion.getValue())) {
114+
case XC09_009:
115+
case XC09_038:
112116
return XCITE;
113-
else if (hardwareVersion.getValue() == HardwareVersionEnum.XT09_XXX.getValue()) {
117+
case XT09_XXX:
118+
case XT09B_XXX:
114119
if ((firmwareVersion.length() == 4 && firmwareVersion.startsWith("8"))
115120
|| (firmwareVersion.length() == 5 && firmwareVersion.charAt(1) == '8'))
116121
return XTEND_DM;
117122
return XTEND;
118-
}
119-
else if (hardwareVersion.getValue() == HardwareVersionEnum.XB24_AXX_XX.getValue()
120-
|| hardwareVersion.getValue() == HardwareVersionEnum.XBP24_AXX_XX.getValue()) {
123+
case XB24_AXX_XX:
124+
case XBP24_AXX_XX:
121125
if ((firmwareVersion.length() == 4 && firmwareVersion.startsWith("8")))
122-
return DIGI_MESH;
126+
return DIGI_MESH;
123127
return RAW_802_15_4;
124-
}
125-
else if (hardwareVersion.getValue() == HardwareVersionEnum.XB24_BXIX_XXX.getValue()
126-
|| hardwareVersion.getValue() == HardwareVersionEnum.XBP24_BXIX_XXX.getValue()) {
128+
case XB24_BXIX_XXX:
129+
case XBP24_BXIX_XXX:
127130
if ((firmwareVersion.length() == 4 && firmwareVersion.startsWith("1") && firmwareVersion.endsWith("20"))
128131
|| (firmwareVersion.length() == 4 && firmwareVersion.startsWith("2")))
129132
return ZIGBEE;
130133
else if (firmwareVersion.length() == 4 && firmwareVersion.startsWith("3"))
131134
return SMART_ENERGY;
132135
return ZNET;
133-
}
134-
else if (hardwareVersion.getValue() == HardwareVersionEnum.XBP09_DXIX_XXX.getValue()) {
136+
case XBP09_DXIX_XXX:
135137
if ((firmwareVersion.length() == 4 && firmwareVersion.startsWith("8")
136138
|| (firmwareVersion.length() == 4 && firmwareVersion.charAt(1) == '8'))
137139
|| (firmwareVersion.length() == 5 && firmwareVersion.charAt(1) == '8'))
138140
return DIGI_MESH;
139141
return DIGI_POINT;
140-
}
141-
else if (hardwareVersion.getValue() == HardwareVersionEnum.XBP09_XCXX_XXX.getValue())
142+
case XBP09_XCXX_XXX:
142143
return XC;
143-
else if (hardwareVersion.getValue() == HardwareVersionEnum.XBP08_DXXX_XXX.getValue())
144+
case XBP08_DXXX_XXX:
144145
return DIGI_POINT;
145-
else if (hardwareVersion.getValue() == HardwareVersionEnum.XBP24B.getValue()) {
146+
case XBP24B:
146147
if (firmwareVersion.length() == 4 && firmwareVersion.startsWith("3"))
147148
return SMART_ENERGY;
148149
return ZIGBEE;
149-
}
150-
else if (hardwareVersion.getValue() == HardwareVersionEnum.XB24_WF.getValue()
151-
|| hardwareVersion.getValue() == HardwareVersionEnum.WIFI_ATHEROS.getValue()
152-
|| hardwareVersion.getValue() == HardwareVersionEnum.SMT_WIFI_ATHEROS.getValue())
150+
case XB24_WF:
151+
case WIFI_ATHEROS:
152+
case SMT_WIFI_ATHEROS:
153153
return XBEE_WIFI;
154-
else if (hardwareVersion.getValue() == HardwareVersionEnum.XBP24C.getValue()
155-
|| hardwareVersion.getValue() == HardwareVersionEnum.XB24C.getValue()) {
156-
if (firmwareVersion.length() == 4 && firmwareVersion.startsWith("5"))
154+
case XBP24C:
155+
case XB24C:
156+
if (firmwareVersion.length() == 4 && (firmwareVersion.startsWith("5") || firmwareVersion.startsWith("6")))
157157
return SMART_ENERGY;
158+
else if (firmwareVersion.startsWith("2"))
159+
return RAW_802_15_4;
158160
return ZIGBEE;
159-
}
160-
else if (hardwareVersion.getValue() == HardwareVersionEnum.XSC_GEN3.getValue()
161-
|| hardwareVersion.getValue() == HardwareVersionEnum.SRD_868_GEN3.getValue()) {
161+
case XSC_GEN3:
162+
case SRD_868_GEN3:
162163
if (firmwareVersion.length() == 4 && firmwareVersion.startsWith("8"))
163164
return DIGI_MESH;
164165
else if (firmwareVersion.length() == 4 && firmwareVersion.startsWith("1"))
165166
return DIGI_POINT;
166167
return XC;
167-
}
168-
else if (hardwareVersion.getValue() == HardwareVersionEnum.XBEE_CELL_TH.getValue()) {
168+
case XBEE_CELL_TH:
169169
return UNKNOWN;
170-
}
171-
else if (hardwareVersion.getValue() == HardwareVersionEnum.XLR_MODULE.getValue()) {
170+
case XLR_MODULE:
172171
// This is for the old version of the XLR we have (K60), and it is
173172
// reporting the firmware of the module (8001), this will change in
174173
// future (after K64 integration) reporting the hardware and firmware
175174
// version of the baseboard (see the case HardwareVersionEnum.XLR_BASEBOARD).
176175
// TODO maybe this should be removed in future, since this case will never be released.
177-
return XLR;
178-
}
179-
else if (hardwareVersion.getValue() == HardwareVersionEnum.XLR_BASEBOARD.getValue()) {
176+
if (firmwareVersion.startsWith("1"))
177+
return XLR;
178+
else
179+
return XLR_MODULE;
180+
case XLR_BASEBOARD:
180181
// XLR devices with K64 will report the baseboard hardware version,
181182
// and also firmware version (the one we have here is 1002, but this value
182183
// is not being reported since is an old K60 version, the module fw version
@@ -185,25 +186,37 @@ else if (hardwareVersion.getValue() == HardwareVersionEnum.XLR_BASEBOARD.getValu
185186
// TODO [XLR_DM] The next version of the XLR will add DigiMesh support should be added.
186187
// Probably this XLR_DM and XLR will depend on the firmware version.
187188

188-
return XLR;
189-
}
190-
else if (hardwareVersion.getValue() == HardwareVersionEnum.XB900HP_NZ.getValue()) {
189+
if (firmwareVersion.startsWith("1"))
190+
return XLR;
191+
else
192+
return XLR_MODULE;
193+
case XB900HP_NZ:
191194
return DIGI_POINT;
192-
}
193-
else if (hardwareVersion.getValue() == HardwareVersionEnum.XBP24C_TH_DIP.getValue()
194-
|| hardwareVersion.getValue() == HardwareVersionEnum.XB24C_TH_DIP.getValue()
195-
|| hardwareVersion.getValue() == HardwareVersionEnum.XBP24C_S2C_SMT.getValue()) {
196-
if (firmwareVersion.length() == 4 && firmwareVersion.startsWith("5"))
195+
case XBP24C_TH_DIP:
196+
case XB24C_TH_DIP:
197+
case XBP24C_S2C_SMT:
198+
if (firmwareVersion.length() == 4 && (firmwareVersion.startsWith("5") || firmwareVersion.startsWith("6")))
197199
return SMART_ENERGY;
200+
else if (firmwareVersion.startsWith("2"))
201+
return RAW_802_15_4;
202+
return ZIGBEE;
203+
case SX_PRO:
204+
case SX:
205+
case XTR:
206+
if (firmwareVersion.startsWith("2"))
207+
return XTEND;
208+
else if (firmwareVersion.startsWith("8"))
209+
return XTEND_DM;
210+
else
211+
return SX;
212+
case S2D_SMT_PRO:
213+
case S2D_SMT_REG:
214+
case S2D_TH_PRO:
215+
case S2D_TH_REG:
216+
return ZIGBEE;
217+
default:
198218
return ZIGBEE;
199219
}
200-
// If the hardware is not in the list, lets return Unknown.
201-
else if (HardwareVersionEnum.get(hardwareVersion.getValue()) == null) {
202-
return UNKNOWN;
203-
}
204-
205-
// TODO: Logic protocol goes here.
206-
return ZIGBEE;
207220
}
208221

209222
/*

0 commit comments

Comments
 (0)