/* This software is subject to the license described in the License.txt file included with this software distribution. You may not use this file except in compliance with this license. Copyright (c) Dynastream Innovations Inc. 2016 All rights reserved. */ using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace ANT_Managed_Library.ANTFS { /// /// ANT-FS Device Parameters /// [StructLayout(LayoutKind.Sequential, Pack=1)] public struct ANTFS_DeviceParameters { /// /// Remote device ID /// public uint DeviceID; /// /// Manufacturer ID of remote device /// public ushort ManufacturerID; /// /// Remote device type /// public ushort DeviceType; /// /// Authentication type supported by remote device /// public byte AuthenticationType; /// /// Status byte 1, as described in the ANT-FS Technology specification /// public byte StatusByte1; /// /// Status byte 2, as described in the ANT-FS Technology specification /// public byte StatusByte2; /// /// Configure specified device parameters /// /// Device ID /// Manufacturer ID /// Device Type /// Authentication Type /// Status byte 1, as described in the ANT-FS Technology specification /// Status byte 2, as described in the ANT-FS Technology specification public ANTFS_DeviceParameters(uint DevID, ushort usMfgID, ushort usDevType, byte AuthType, byte Stat1, byte Stat2) { DeviceID = DevID; ManufacturerID = usMfgID; DeviceType = usDevType; AuthenticationType = AuthType; StatusByte1 = Stat1; StatusByte2 = Stat2; } /// /// Checks if the remote device is capable of the pairing authentication scheme /// /// True if pairing is supported, false otherwise public bool IsPairingEnabled() { if ((StatusByte1 & (byte)Status1.PairingEnabledBit) != 0) return true; else return false; } /// /// Checks if the remote device supports uploads /// /// True if uploads are supported, false otherwise public bool IsUploadEnabled() { if ((StatusByte1 & (byte)Status1.UploadEnabledBit) != 0) return true; else return false; } /// /// Checks if the remote device has data available for download /// /// True if data is available, false otherwise public bool IsDataAvailable() { if ((StatusByte1 & (byte)Status1.DataAvailableBit) != 0) return true; else return false; } /// /// Obtains the beacon period of the remote device /// /// Beacon period of the remote device public BeaconPeriod GetBeaconPeriod() { return (BeaconPeriod)(StatusByte1 & (byte)Status1.BeaconPeriodBits); } /// /// Obtains current state of the remote device /// /// State of the remote device public ClientState GetClientState() { return (ClientState) (StatusByte2 & (byte)Status2.ClientStateBits); } /// /// Enables/disables the pairing bit in the device parameters /// /// Set to true to enable pairing, false otherwise public void SetPairingBit(bool bEnable) { if (bEnable) StatusByte1 |= (byte)Status1.PairingEnabledBit; else StatusByte1 &= ((byte)Status1.PairingEnabledBit ^ 0xFF); // ~Status1.PairingEnabledBit => ~ Operator converts the value to an Int32 } /// /// Enables/disables the upload bit in the device parameters /// /// Set to true to enable uploads, false otherwise public void SetUploadBit(bool bEnable) { if (bEnable) StatusByte1 |= (byte)Status1.UploadEnabledBit; else StatusByte1 &= ((byte)Status1.UploadEnabledBit ^ 0xFF); // ~Status1.UploadEnabledBit => ~ Operator converts the value to an Int32 } /// /// Enables/disables the data available bit in the device parameters /// /// Set to true if there is data available for download, false otherwise public void SetDataAvailableBit(bool bEnable) { if (bEnable) StatusByte1 |= (byte)Status1.DataAvailableBit; else StatusByte1 &= ((byte)Status1.DataAvailableBit ^ 0xFF); // ~Status1.DataAvailableBit => ~ Operator converts the value to an Int32 } /// /// Returns a string with the decoded device parameters /// /// String with decoded device parameters public override string ToString() { String strResults = ""; strResults += " Device ID: " + DeviceID + Environment.NewLine; strResults += " Manufacturer ID: " + ManufacturerID + Environment.NewLine; strResults += " Device Type: " + DeviceType + Environment.NewLine; strResults += " Authentication Type: " + ((AuthenticationType)AuthenticationType).ToString() + Environment.NewLine; if (IsDataAvailable()) strResults += " Device has new data" + Environment.NewLine; else strResults += " Device does not have new data" + Environment.NewLine; if (IsPairingEnabled()) strResults += " Device is in pairing mode" + Environment.NewLine; else strResults += " Device is not in pairing mode" + Environment.NewLine; if (IsUploadEnabled()) strResults += " Device has upload enabled" + Environment.NewLine; else strResults += " Device does not have upload enabled" + Environment.NewLine; return strResults; } } /// /// Parameters retrieved by the host after finding a client matching its search criteria /// public class ANTFS_SearchResults { /// /// Remote device parameters /// public ANTFS_DeviceParameters DeviceParameters; /// /// Friendly name of the remote device /// public String FriendlyName = ""; /// /// Returns a string with the decoded device parameters and friendly name /// /// String with decoded device parameters and friendly name public override string ToString() { String strResults = ""; strResults += "Found remote device: " + FriendlyName + Environment.NewLine; strResults += DeviceParameters.ToString(); return strResults; } } }