private static byte[] GetByteArrayPropertyValueFromBuffer(byte[] buffer, int index, PropertyDescriptor onePropertyDescriptor) { byte[] returnValue = null; // if the request was to consume all bytes, then we will do it excluding the trailing checksum if (onePropertyDescriptor.ByteCount == 0) { int checksumIndex = XBeeFrameUtil.CalculateChecksumIndex(buffer); int lengthToCopy = checksumIndex - index; returnValue = new byte[lengthToCopy]; Array.Copy(buffer, index, returnValue, 0, lengthToCopy); } else { returnValue = new byte[onePropertyDescriptor.ByteCount]; Array.Copy(buffer, index, returnValue, 0, onePropertyDescriptor.ByteCount); } return returnValue; }
private static int SetPropertyValueToBuffer(byte[] buffer, int index, object value, PropertyDescriptor onePropertyDescriptor) { int writtenBytes = onePropertyDescriptor.ByteCount; switch (onePropertyDescriptor.PropertyType) { case PropertyType.Byte: buffer[index] = (byte)value; break; case PropertyType.Integer: buffer[index] = (byte)((int)value / 256); buffer[index + 1] = (byte)((int)value % 256); break; case PropertyType.ByteArray: if (onePropertyDescriptor.ByteCount > 0) { Array.Copy((byte[])value, 0, buffer, index, onePropertyDescriptor.ByteCount); } else { byte[] localValue = (byte[])value; Array.Copy(localValue, 0, buffer, index, localValue.Length); writtenBytes = localValue.Length; } break; } return writtenBytes; }
private static object GetPropertyValueFromBuffer(byte[] buffer, int index, PropertyDescriptor onePropertyDescriptor) { switch (onePropertyDescriptor.PropertyType) { case PropertyType.Byte: return buffer[index]; case PropertyType.Integer: return buffer[index] * 256 + buffer[index + 1]; case PropertyType.ByteArray: return GetByteArrayPropertyValueFromBuffer(buffer, index, onePropertyDescriptor); } return null; }