Skip to content

Commit 45bbf58

Browse files
committed
Refactoring
1 parent cef6687 commit 45bbf58

20 files changed

+157
-178
lines changed

XBeeLibrary/AbstractXBeeDevice.cs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ public abstract class AbstractXBeeDevice
6868

6969
protected DataReader dataReader = null;
7070

71-
protected XBeeProtocol xbeeProtocol = XBeeProtocol.UNKNOWN;
72-
7371
protected OperatingMode operatingMode = OperatingMode.UNKNOWN;
7472

7573
protected XBee16BitAddress xbee16BitAddress = XBee16BitAddress.UNKNOWN_ADDRESS;
@@ -188,6 +186,7 @@ public AbstractXBeeDevice(IConnectionInterface connectionInterface)
188186
{
189187
Contract.Requires<ArgumentNullException>(connectionInterface != null, "ConnectionInterface cannot be null.");
190188

189+
XBeeProtocol = XBeeProtocol.UNKNOWN;
191190
this.connectionInterface = connectionInterface;
192191
this.logger = LogManager.GetLogger(this.GetType());
193192
logger.DebugFormat(ToString() + "Using the connection interface {0}.",
@@ -257,6 +256,7 @@ public AbstractXBeeDevice(XBeeDevice localXBeeDevice, XBee64BitAddress addr64,
257256
if (localXBeeDevice.IsRemote)
258257
throw new ArgumentException("The given local XBee device is remote.");
259258

259+
XBeeProtocol = XBeeProtocol.UNKNOWN;
260260
this.localXBeeDevice = localXBeeDevice;
261261
this.connectionInterface = localXBeeDevice.GetConnectionInterface();
262262
this.xbee64BitAddress = addr64;
@@ -346,12 +346,12 @@ public void readDeviceInfo() /*throws TimeoutException, XBeeException*/ {
346346
firmwareVersion = HexUtils.ByteArrayToHexString(response);
347347

348348
// Obtain the device protocol.
349-
xbeeProtocol = XBeeProtocol.UNKNOWN.DetermineProtocol(hardwareVersion, firmwareVersion);
349+
XBeeProtocol = XBeeProtocol.UNKNOWN.DetermineProtocol(hardwareVersion, firmwareVersion);
350350

351351
// Get the 16-bit address. This must be done after obtaining the protocol because
352352
// DigiMesh and Point-to-Multipoint protocols don't have 16-bit addresses.
353-
if (GetXBeeProtocol() != XBeeProtocol.DIGI_MESH
354-
&& GetXBeeProtocol() != XBeeProtocol.DIGI_POINT)
353+
if (XBeeProtocol != XBeeProtocol.DIGI_MESH
354+
&& XBeeProtocol != XBeeProtocol.DIGI_POINT)
355355
{
356356
response = GetParameter("MY");
357357
xbee16BitAddress = new XBee16BitAddress(response);
@@ -405,19 +405,11 @@ protected OperatingMode GetOperatingMode()
405405
return operatingMode;
406406
}
407407

408-
/**
409-
* Returns the XBee Protocol of this XBee device.
410-
*
411-
* <p>To refresh this value use the {@link #readDeviceInfo()} method.</p>
412-
*
413-
* @return The XBee device protocol.
414-
*
415-
* @see com.digi.xbee.api.models.XBeeProtocol
416-
*/
417-
public virtual XBeeProtocol GetXBeeProtocol()
418-
{
419-
return xbeeProtocol;
420-
}
408+
/// <summary>
409+
/// Gets the XBee protocol of this XBee device.
410+
/// </summary>
411+
/// <remarks>To refresh this value, use the <see cref="ReadDeviceInfo"/> method.</remarks>
412+
public virtual XBeeProtocol XBeeProtocol { get; protected set; }
421413

422414
/// <summary>
423415
/// Gets or sets the node identifier of thix XBee device.
@@ -1800,7 +1792,7 @@ public IOSample readIOSample()/*throws TimeoutException, XBeeException */{
18001792

18011793
// The response to the IS command in local 802.15.4 devices is empty,
18021794
// so we have to create a packet listener to receive the IO sample.
1803-
if (!IsRemote && GetXBeeProtocol() == XBeeProtocol.RAW_802_15_4)
1795+
if (!IsRemote && XBeeProtocol == XBeeProtocol.RAW_802_15_4)
18041796
{
18051797
ExecuteParameter("IS");
18061798
samplePayload = receiveRaw802IOPacket();
@@ -2125,7 +2117,7 @@ protected void Set16BitAddress(XBee16BitAddress xbee16BitAddress)/*throws Timeou
21252117
* @see #setPANID(byte[])
21262118
*/
21272119
public byte[] GetPANID()/*throws TimeoutException, XBeeException */{
2128-
switch (GetXBeeProtocol())
2120+
switch (XBeeProtocol)
21292121
{
21302122
case XBeeProtocol.ZIGBEE:
21312123
return GetParameter("OP");

XBeeLibrary/Connection/DataReader.cs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ private RemoteXBeeDevice createRemoteXBeeDevice(XBee64BitAddress addr64,
523523
{
524524
RemoteXBeeDevice device = null;
525525

526-
switch (xbeeDevice.GetXBeeProtocol())
526+
switch (xbeeDevice.XBeeProtocol)
527527
{
528528
case XBeeProtocol.ZIGBEE:
529529
device = new RemoteZigBeeDevice(xbeeDevice, addr64, addr16, ni);
@@ -751,14 +751,9 @@ private void NotifyModemStatusReceived(ModemStatusEvent modemStatusEvent)
751751
}
752752
}
753753

754-
/**
755-
* Returns whether this Data reader is running or not.
756-
*
757-
* @return {@code true} if the Data reader is running, {@code false}
758-
* otherwise.
759-
*
760-
* @see #stopReader()
761-
*/
754+
/// <summary>
755+
/// Indicates whether the data reader is running or not.
756+
/// </summary>
762757
public bool IsRunning
763758
{
764759
get
@@ -767,11 +762,9 @@ public bool IsRunning
767762
}
768763
}
769764

770-
/**
771-
* Stops the Data reader thread.
772-
*
773-
* @see #isRunning()
774-
*/
765+
/// <summary>
766+
/// Stops the data reader thread.
767+
/// </summary>
775768
public void StopReader()
776769
{
777770
running = false;

XBeeLibrary/DigiMeshDevice.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ public DigiMeshDevice(IConnectionInterface connectionInterface)
9999
public override void Open()/*throws XBeeException */{
100100
base.Open();
101101

102-
if (xbeeProtocol != XBeeProtocol.DIGI_MESH)
103-
throw new XBeeDeviceException("XBee device is not a " + GetXBeeProtocol().GetDescription() + " device, it is a " + xbeeProtocol.GetDescription() + " device.");
102+
if (base.XBeeProtocol != XBeeProtocol.DIGI_MESH)
103+
throw new XBeeDeviceException("XBee device is not a " + XBeeProtocol.GetDescription() + " device, it is a " + base.XBeeProtocol.GetDescription() + " device.");
104104
}
105105

106106
public override XBeeNetwork GetNetwork()
@@ -112,9 +112,12 @@ public override XBeeNetwork GetNetwork()
112112
return network;
113113
}
114114

115-
public override XBeeProtocol GetXBeeProtocol()
115+
public override XBeeProtocol XBeeProtocol
116116
{
117-
return XBeeProtocol.DIGI_MESH;
117+
get
118+
{
119+
return XBeeProtocol.DIGI_MESH;
120+
}
118121
}
119122
}
120123
}

XBeeLibrary/DigiMeshNetwork.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,11 @@ namespace Kveer.XBeeApi
1414
*/
1515
public class DigiMeshNetwork : XBeeNetwork
1616
{
17-
18-
/**
19-
* Instantiates a new DigiMesh Network object.
20-
*
21-
* @param device Local DigiMesh device to get the network from.
22-
*
23-
* @throws ArgumentNullException if {@code device == null}.
24-
*
25-
* @see DigiMeshDevice
26-
*/
17+
/// <summary>
18+
/// Initializes a new instance of <see cref="DigiMeshNetwork"/>.
19+
/// </summary>
20+
/// <param name="device">A local DigiMesh device to get the network from.</param>
21+
/// <exception cref="ArgumentNullException">if <paramref name="device"/> is null.</exception>
2722
public DigiMeshNetwork(DigiMeshDevice device)
2823
: base(device)
2924
{

XBeeLibrary/DigiPointDevice.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,12 @@ public DigiPointDevice(IConnectionInterface connectionInterface)
9292

9393
public override void Open()/*throws XBeeException */{
9494
base.Open();
95+
9596
if (IsRemote)
9697
return;
97-
if (xbeeProtocol != XBeeProtocol.DIGI_POINT)
98-
throw new XBeeDeviceException("XBee device is not a " + GetXBeeProtocol().GetDescription() + " device, it is a " + xbeeProtocol.GetDescription() + " device.");
98+
99+
if (base.XBeeProtocol != XBeeProtocol.DIGI_POINT)
100+
throw new XBeeDeviceException("XBee device is not a " + XBeeProtocol.GetDescription() + " device, it is a " + base.XBeeProtocol.GetDescription() + " device.");
99101
}
100102

101103
/*
@@ -113,14 +115,12 @@ public override XBeeNetwork GetNetwork()
113115
return network;
114116
}
115117

116-
/*
117-
* (non-Javadoc)
118-
* @see com.digi.xbee.api.XBeeDevice#getXBeeProtocol()
119-
*/
120-
//@Override
121-
public override XBeeProtocol GetXBeeProtocol()
118+
public override XBeeProtocol XBeeProtocol
122119
{
123-
return XBeeProtocol.DIGI_POINT;
120+
get
121+
{
122+
return XBeeProtocol.DIGI_POINT;
123+
}
124124
}
125125
}
126126
}

XBeeLibrary/DigiPointNetwork.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,11 @@ namespace Kveer.XBeeApi
1313
*/
1414
public class DigiPointNetwork : XBeeNetwork
1515
{
16-
17-
/**
18-
* Instantiates a new DigiPoint Network object.
19-
*
20-
* @param device Local DigiPoint device to get the network from.
21-
*
22-
* @throws ArgumentNullException if {@code device == null}.
23-
*
24-
* @see DigiPointDevice
25-
*/
16+
/// <summary>
17+
/// Initializes a new instance of <see cref="DigiPointNetwork"/>.
18+
/// </summary>
19+
/// <param name="device">A local DigiPoint device to get the network from.</param>
20+
/// <exception cref="ArgumentNullException">if <see cref="device"/> is null.</exception>
2621
public DigiPointNetwork(DigiPointDevice device)
2722
: base(device)
2823
{

XBeeLibrary/NodeDiscovery.cs

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ public List<RemoteXBeeDevice> discoverDevices(IList<string> ids)/*throws XBeeExc
178178
* @throws InterfaceNotOpenException if the device is not open.
179179
* @throws ArgumentNullException if {@code listeners == null}.
180180
*
181-
* @see #isRunning()
182-
* @see #stopDiscoveryProcess()
181+
* @see #IsRunning()
182+
* @see #StopDiscoveryProcess()
183183
*/
184184
public void startDiscoveryProcess(IList<IDiscoveryListener> listeners)
185185
{
@@ -211,26 +211,25 @@ public void startDiscoveryProcess(IList<IDiscoveryListener> listeners)
211211
/**
212212
* Stops the discovery process if it is running.
213213
*
214-
* @see #isRunning()
214+
* @see #IsRunning()
215215
* @see #startDiscoveryProcess(List)
216216
*/
217-
public void stopDiscoveryProcess()
217+
public void StopDiscoveryProcess()
218218
{
219219
discovering = false;
220220
}
221221

222-
/**
223-
* Retrieves whether the discovery process is running.
224-
*
225-
* @return {@code true} if the discovery process is running, {@code false}
226-
* otherwise.
227-
*
228-
* @see #startDiscoveryProcess(List)
229-
* @see #stopDiscoveryProcess()
230-
*/
231-
public bool isRunning()
222+
/// <summary>
223+
/// Indicates whether the discovery process is running.
224+
/// </summary>
225+
/// <see cref="StartDiscoveryProcess"/>
226+
/// <see cref="StopDiscoveryProcess"/>
227+
public bool IsRunning
232228
{
233-
return running;
229+
get
230+
{
231+
return running;
232+
}
234233
}
235234

236235
/**
@@ -292,7 +291,7 @@ public async void PacketReceived(XBeePacket receivedPacket)
292291
_node.deviceList.Add(rdevice);
293292
}
294293
// If the local device is 802.15.4 wait until the 'end' command is received.
295-
if (_node.xbeeDevice.GetXBeeProtocol() != XBeeProtocol.RAW_802_15_4)
294+
if (_node.xbeeDevice.XBeeProtocol != XBeeProtocol.RAW_802_15_4)
296295
_node.discovering = false;
297296
}
298297
}
@@ -327,12 +326,12 @@ private void DiscoverDevicesAPI(IList<IDiscoveryListener> listeners, string id)/
327326

328327
// In 802.15.4 devices, the discovery finishes when the 'end' command
329328
// is received, so it's not necessary to calculate the timeout.
330-
if (xbeeDevice.GetXBeeProtocol() != XBeeProtocol.RAW_802_15_4)
329+
if (xbeeDevice.XBeeProtocol != XBeeProtocol.RAW_802_15_4)
331330
deadLine += CalculateTimeout(listeners);
332331

333332
sendNodeDiscoverCommand(id);
334333

335-
if (xbeeDevice.GetXBeeProtocol() != XBeeProtocol.RAW_802_15_4)
334+
if (xbeeDevice.XBeeProtocol != XBeeProtocol.RAW_802_15_4)
336335
{
337336
// Wait for scan timeout.
338337
while (discovering)
@@ -411,17 +410,17 @@ private long CalculateTimeout(IList<IDiscoveryListener> listeners)
411410
// In DigiMesh/DigiPoint the network discovery timeout is NT + the
412411
// network propagation time. It means that if the user sends an AT
413412
// command just after NT ms, s/he will receive a timeout exception.
414-
if (xbeeDevice.GetXBeeProtocol() == XBeeProtocol.DIGI_MESH)
413+
if (xbeeDevice.XBeeProtocol == XBeeProtocol.DIGI_MESH)
415414
{
416415
timeout += 3000;
417416
}
418-
else if (xbeeDevice.GetXBeeProtocol() == XBeeProtocol.DIGI_POINT)
417+
else if (xbeeDevice.XBeeProtocol == XBeeProtocol.DIGI_POINT)
419418
{
420419
timeout += 8000;
421420
}
422421
}
423422

424-
if (xbeeDevice.GetXBeeProtocol() == XBeeProtocol.DIGI_MESH)
423+
if (xbeeDevice.XBeeProtocol == XBeeProtocol.DIGI_MESH)
425424
{
426425
try
427426
{
@@ -513,7 +512,7 @@ private async Task<RemoteXBeeDevice> ParseDiscoveryAPIData(byte[] data, XBeeDevi
513512
addr64 = new XBee64BitAddress(await ByteUtils.ReadBytes(8, inputStream));
514513

515514

516-
switch (localDevice.GetXBeeProtocol())
515+
switch (localDevice.XBeeProtocol)
517516
{
518517
case XBeeProtocol.ZIGBEE:
519518
case XBeeProtocol.DIGI_MESH:
@@ -537,7 +536,7 @@ private async Task<RemoteXBeeDevice> ParseDiscoveryAPIData(byte[] data, XBeeDevi
537536
manufacturerID = await ByteUtils.ReadBytes(2, inputStream);
538537

539538
logger.DebugFormat("{0}Discovered {1} device: 16-bit[{2}], 64-bit[{3}], id[{4}], parent[{5}], profile[{6}], manufacturer[{7}].",
540-
xbeeDevice.ToString(), localDevice.GetXBeeProtocol().GetDescription(), addr16,
539+
xbeeDevice.ToString(), localDevice.XBeeProtocol.GetDescription(), addr16,
541540
addr64, id, parentAddress, HexUtils.ByteArrayToHexString(profileID),
542541
HexUtils.ByteArrayToHexString(manufacturerID));
543542

@@ -549,18 +548,18 @@ private async Task<RemoteXBeeDevice> ParseDiscoveryAPIData(byte[] data, XBeeDevi
549548
id = ByteUtils.ReadString(inputStream);
550549

551550
logger.DebugFormat("{0}Discovered {1} device: 16-bit[{2}], 64-bit[{3}], id[{4}], rssi[{5}].",
552-
xbeeDevice.ToString(), localDevice.GetXBeeProtocol().GetDescription(), addr16, addr64, id, signalStrength);
551+
xbeeDevice.ToString(), localDevice.XBeeProtocol.GetDescription(), addr16, addr64, id, signalStrength);
553552

554553
break;
555554
case XBeeProtocol.UNKNOWN:
556555
default:
557556
logger.DebugFormat("{0}Discovered {1} device: 16-bit[{2}], 64-bit[{3}].",
558-
xbeeDevice.ToString(), localDevice.GetXBeeProtocol().GetDescription(), addr16, addr64);
557+
xbeeDevice.ToString(), localDevice.XBeeProtocol.GetDescription(), addr16, addr64);
559558
break;
560559
}
561560

562561
// Create device and fill with parameters.
563-
switch (localDevice.GetXBeeProtocol())
562+
switch (localDevice.XBeeProtocol)
564563
{
565564
case XBeeProtocol.ZIGBEE:
566565
device = new RemoteZigBeeDevice(localDevice, addr64, addr16, id/*, role*/);

0 commit comments

Comments
 (0)