Skip to content

Commit 30f80d0

Browse files
committed
adds a new enum value to handle invalid APIFrameType
1 parent b06be7c commit 30f80d0

File tree

8 files changed

+21
-45
lines changed

8 files changed

+21
-45
lines changed

XBeeLibrary/Connection/DataReader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ private void PacketReceived(XBeePacket packet)
353353
// Get the API packet type.
354354
XBeeAPIPacket apiPacket = (XBeeAPIPacket)packet;
355355
APIFrameType apiType = apiPacket.FrameType;
356-
if (apiType == null)
356+
if (apiType == APIFrameType.UNKNOWN)
357357
return;
358358

359359
try
@@ -437,7 +437,7 @@ public RemoteXBeeDevice GetRemoteXBeeDeviceFromPacket(XBeeAPIPacket packet) /*th
437437

438438
XBeeAPIPacket apiPacket = (XBeeAPIPacket)packet;
439439
APIFrameType apiType = apiPacket.FrameType;
440-
if (apiType == null)
440+
if (apiType == APIFrameType.UNKNOWN)
441441
return null;
442442

443443
RemoteXBeeDevice remoteDevice = null;

XBeeLibrary/DigiPointDevice.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public DigiPointDevice(IConnectionInterface connectionInterface)
9090
{
9191
}
9292

93-
public void Open()/*throws XBeeException */{
93+
public override void Open()/*throws XBeeException */{
9494
base.Open();
9595
if (IsRemote)
9696
return;

XBeeLibrary/IO/IOSample.cs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -297,34 +297,6 @@ public IDictionary<IOLine, IOValue> DigitalValues
297297
}
298298
}
299299

300-
/**
301-
* Returns the digital value of the provided IO line.
302-
*
303-
* <p>
304-
* {@code IOLine}, use the method {@code hasDigitalValue(IOLine)}.</p>
305-
*
306-
* <pre>
307-
* {@code
308-
* if (ioSample.hasDigitalValue(IOLine.DIO0_AD0)) {
309-
* IOValue value = ioSample.getDigitalValue(IOLine.DIO0_AD0);
310-
* ...
311-
* } else {
312-
* ...
313-
* }
314-
* }
315-
* </pre>
316-
*
317-
* @param ioLine
318-
*
319-
* @return The {@code IOValue} of the given IO line or {@code null} if the
320-
* IO sample does not contain a digital value for the given IO line.
321-
*
322-
* @see #getDigitalValues()
323-
* @see #hasDigitalValues()
324-
* @see IOLine
325-
* @see IOValue
326-
*/
327-
int e;
328300
/// <summary>
329301
/// Gets the digital value of the provided IO line.
330302
/// </summary>

XBeeLibrary/Models/HardwareVersion.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Kveer.XBeeApi.Models
55
/// <summary>
66
/// This class represents the hardware version number of an XBee device.
77
/// </summary>
8-
public class HardwareVersion
8+
public class HardwareVersion : IEquatable<HardwareVersion>
99
{
1010
// Constants.
1111
private const int HASH_SEED = 23;
@@ -66,14 +66,16 @@ public static HardwareVersion Get(int value, string description)
6666

6767
public override bool Equals(object obj)
6868
{
69-
if (!(obj is HardwareVersion))
70-
return false;
69+
var other = obj as HardwareVersion;
7170

72-
HardwareVersion hwVersion = (HardwareVersion)obj;
73-
if (hwVersion.Value == Value
74-
&& hwVersion.Description == Description)
75-
return true;
76-
return false;
71+
return other != null && Equals(other);
72+
}
73+
74+
public bool Equals(HardwareVersion other)
75+
{
76+
return other != null
77+
&& other.Value == Value
78+
&& other.Description == Description;
7779
}
7880

7981
public override int GetHashCode()

XBeeLibrary/Packet/APIFrameType.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Kveer.XBeeApi.Utils;
22
using System;
33
using System.Collections.Generic;
4+
using System.Diagnostics.Contracts;
45
using System.Linq;
56

67
namespace Kveer.XBeeApi.Packet
@@ -28,6 +29,7 @@ public enum APIFrameType : byte
2829
IO_DATA_SAMPLE_RX_INDICATOR = 0x92,
2930
REMOTE_AT_COMMAND_RESPONSE = 0x97,
3031
GENERIC = 0xFF,
32+
UNKNOWN = 0xfe
3133
}
3234

3335
public static class APIFrameTypeExtensions
@@ -69,14 +71,15 @@ public static APIFrameType Get(this APIFrameType dumb, byte value)
6971
if (values.Cast<byte>().Contains(value))
7072
return (APIFrameType)value;
7173

72-
return APIFrameType.GENERIC;
74+
return APIFrameType.UNKNOWN;
7375
}
7476

7577
/// <summary>
7678
/// Gets the API frame type value.
7779
/// </summary>
7880
/// <param name="source"></param>
7981
/// <returns>The API frame type value.</returns>
82+
[Pure]
8083
public static byte GetValue(this APIFrameType source)
8184
{
8285
return (byte)source;
@@ -89,7 +92,7 @@ public static byte GetValue(this APIFrameType source)
8992
/// <returns>The API frame type name.</returns>
9093
public static string GetName(this APIFrameType source)
9194
{
92-
return lookupTable[source];
95+
return lookupTable.ContainsKey(source) ? lookupTable[source] : source.ToString();
9396
}
9497

9598
public static string ToDisplayString(this APIFrameType source)

XBeeLibrary/Packet/XBeeAPIPacket.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ public abstract class XBeeAPIPacket : XBeePacket
4444
protected XBeeAPIPacket(APIFrameType frameType)
4545
: base()
4646
{
47-
48-
Contract.Requires<ArgumentNullException>(frameType != null, "Frame type cannot be null.");
47+
Contract.Requires<ArgumentNullException>(frameType != APIFrameType.UNKNOWN, "Frame type cannot be unknown.");
4948

5049
this.FrameType = frameType;
5150
FrameTypeValue = frameType.GetValue();

XBeeLibrary/Packet/XBeePacketParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ private XBeePacket ParsePayload(byte[] payload) /*throws InvalidPacketException*
254254
// Get the API frame type.
255255
APIFrameType apiType = APIFrameType.GENERIC.Get(payload[0]);
256256

257-
if (apiType == null)
257+
if (apiType == APIFrameType.UNKNOWN)
258258
// Create unknown packet.
259259
return UnknownXBeePacket.CreatePacket(payload);
260260

XBeeLibrary/Packet/raw/RX16IOPacket.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static RX16IOPacket CreatePacket(byte[] payload)
6868
Contract.Requires<ArgumentNullException>(payload != null, "RX16 Address IO packet payload cannot be null.");
6969
// 1 (Frame type) + 2 (16-bit address) + 1 (RSSI) + 1 (receive options)
7070
Contract.Requires<ArgumentException>(payload.Length >= MIN_API_PAYLOAD_LENGTH, "Incomplete RX16 Address IO packet.");
71-
Contract.Requires<ArgumentException>((payload[0] & 0xFF) == APIFrameType.RX_IO_16.GetValue(), "Payload is not a RX16 Address IO packet.");
71+
Contract.Requires<ArgumentException>(payload[0] == APIFrameType.RX_IO_16.GetValue(), "Payload is not a RX16 Address IO packet.");
7272

7373
// payload[0] is the frame type.
7474
int index = 1;

0 commit comments

Comments
 (0)