/// <summary> /// Constructor /// </summary> /// <param name="gattService">Gatt Service found for this sensor</param> /// <param name="sensorIndex">SensorIndex</param> public CC2650SensorTag(GattDeviceService gattService, SensorIndexes sensorIndex) { Debug.WriteLine("Begin sensor constructor: " + sensorIndex.ToString()); GattService = gattService; HasSetCallBacks = false; SensorIndex = sensorIndex; Guid guidNull = Guid.Empty; Guid guidData = guidNull; Guid guidNotification = guidNull; Guid guidConfiguraton = guidNull; Guid guidPeriod = guidNull; Guid guidAddress = guidNull; Guid guidDevId = guidNull; switch (SensorIndex) { case SensorIndexes.KEYS: guidNotification = BUTTONS_NOTIFICATION_GUID; break; case SensorIndexes.IO_SENSOR: guidData = IO_SENSOR_DATA_GUID; guidConfiguraton = IO_SENSOR_CONFIGURATION_GUID; break; case SensorIndexes.REGISTERS: guidData = REGISTERS_DATA_GUID; guidAddress = REGISTERS_ADDRESS_GUID; guidDevId = REGISTERS_DEVICE_ID_GUID; break; default: guidData = new Guid(UUIDBase[(int)SensorIndex] + SENSOR_GUID_SUFFFIX); guidNotification = new Guid(UUIDBase[(int)SensorIndex] + SENSOR_NOTIFICATION_GUID_SUFFFIX); guidConfiguraton = new Guid(UUIDBase[(int)SensorIndex] + SENSOR_ENABLE_GUID_SUFFFIX); guidPeriod = new Guid(UUIDBase[(int)SensorIndex] + SENSOR_PERIOD_GUID_SUFFFIX); break; } IReadOnlyList <GattCharacteristic> characteristicList_Data = null; IReadOnlyList <GattCharacteristic> characteristicList_Notification = null; IReadOnlyList <GattCharacteristic> characteristicList_Configuration = null; IReadOnlyList <GattCharacteristic> characteristicList_Period = null; IReadOnlyList <GattCharacteristic> characteristicList_Address = null; IReadOnlyList <GattCharacteristic> characteristicList_Device_Id = null; if (guidData != guidNull) { characteristicList_Data = gattService.GetCharacteristics(guidData); } if (guidNotification != guidNull) { characteristicList_Notification = gattService.GetCharacteristics(guidNotification); } if (guidConfiguraton != guidNull) { characteristicList_Configuration = gattService.GetCharacteristics(guidConfiguraton); } if (guidPeriod != guidNull) { characteristicList_Period = gattService.GetCharacteristics(guidPeriod); } if (guidAddress != guidNull) { characteristicList_Address = gattService.GetCharacteristics(guidAddress); } if (guidDevId != guidNull) { characteristicList_Device_Id = gattService.GetCharacteristics(guidDevId); } if (characteristicList_Data != null) { if (characteristicList_Data.Count > 0) { Data = characteristicList_Data[0]; } } if (characteristicList_Notification != null) { if (characteristicList_Notification.Count > 0) { Notification = characteristicList_Notification[0]; } } if (characteristicList_Configuration != null) { if (characteristicList_Configuration.Count > 0) { Configuration = characteristicList_Configuration[0]; } } if (characteristicList_Period != null) { if (characteristicList_Period.Count > 0) { Data = characteristicList_Period[0]; } } if (characteristicList_Address != null) { if (characteristicList_Address.Count > 0) { Address = characteristicList_Address[0]; } } if (characteristicList_Device_Id != null) { if (characteristicList_Device_Id.Count > 0) { Device_Id = characteristicList_Device_Id[0]; } } SensorsCharacteristicsList[(int)sensorIndex] = this; if (SensorIndex >= 0 && SensorIndex != SensorIndexes.IO_SENSOR && SensorIndex != SensorIndexes.REGISTERS) { ActiveCharacteristicNotifications[(int)SensorIndex] = Notification; Task.Run(() => this.EnableNotify()).Wait(); //Could leave out Wait but potentially could action this instance too soon Task.Run(() => this.TurnOnSensor()).Wait(); //This launches a new thread for this action but stalls the constructor thread. } Debug.WriteLine("End sensor constructor: " + SensorIndex.ToString()); }