コード例 #1
0
 /// <summary>
 /// Convert the specified service class enum value to a byte array, based on the specified byte length.
 /// </summary>
 /// <param name="newSc">Service class enum to convert to a byte array.</param>
 /// <param name="numBytes">How many bytes to use for the conversion of the service class (2 / 4 / 16 bytes)</param>
 /// <returns>The service class enum value converted to a byte array with the specified length.</returns>
 private static byte[] ConvertServiceClassToByte(ServiceClassTypes newSc, int numBytes)
 {
     if (!(numBytes == 2 || numBytes == 4 || numBytes == 16))
     {
         return null;
     }
     var scByte = new byte[numBytes];
     var scOrig = (ushort) newSc;
     switch (numBytes)
     {
         case 2:
             scByte[0] = (byte)newSc;
             scByte[1] = (byte)((scOrig >> 8) & 0xFF);
             break;
         case 4:
             scByte[0] = (byte)newSc;
             scByte[1] = (byte)((scOrig >> 8) & 0xFF);
             scByte[2] = 0;
             scByte[3] = 0;
             break;
         case 16:
             Array.Copy(BtUuid128, scByte, 16);
             scByte[0] = 0;
             scByte[1] = 0;
             scByte[2] = (byte)newSc;
             scByte[3] = (byte)((scOrig >> 8) & 0xFF);
             break;
     }
     return scByte;
 }
コード例 #2
0
 /// <summary>
 /// Add a new service class to the list, specified as an enum value instead of a raw byte array.
 /// The method will take care of using the correct bit length to store the UUID, according to the
 /// setting in use for this instance.
 /// </summary>
 /// <param name="newSc">New service class type to add.</param>
 public void AddServiceClassType(ServiceClassTypes newSc)
 {
     if (ServiceClasses == null)
         ServiceClasses = new List<byte[]>();
     ServiceClasses.Add(ConvertServiceClassToByte(newSc, DataType));
 }
コード例 #3
0
 /// <summary>
 /// Convert the specified service class enum value to a byte array, based on the specified OOB datatype
 /// which influences the bit length.
 /// </summary>
 /// <param name="newSc">Service class enum to convert to a byte array.</param>
 /// <param name="dataType">Data type to use for the conversion - defines the byte length of the resulting
 /// byte array (2 / 4 / 16 bytes)</param>
 /// <returns>The service class enum value converted to a byte array with the specified length.</returns>
 private static byte[] ConvertServiceClassToByte(ServiceClassTypes newSc, OobDataTypes dataType)
 {
     return ConvertServiceClassToByte(newSc, BytesPerServiceClass(dataType));
 }
コード例 #4
0
 /// <summary>
 /// Format the specified service class type enum value as a string that represents
 /// the 128 bit format conversion.
 /// </summary>
 /// <param name="serviceClassType">The service class type to represent as a string.</param>
 /// <returns>Service class type converted to a string that contains the 128 bit service class
 /// UUID.</returns>
 public static string UuidAs128BitString(ServiceClassTypes serviceClassType)
 {
     return string.Format(BtBaseUuid128, serviceClassType);
 }