public BleInfrastructure(IBluetoothLE bluetoothService, IBleExecutionProvider bleExecutionProvider, IBleLogger logger) { Executor = new Executor(logger); BleAvailability = new BleAvailabilityService(bluetoothService, logger); SearchManager = new BleSearchManager(bluetoothService.Adapter, BleAvailability, Executor, logger); ConnectionManager = new BleConnectionManager(bluetoothService.Adapter, BleAvailability, logger); CharacteristicFactory = new CharacteristicFactory(); ExecutionProvider = bleExecutionProvider; Logger = logger; }
public static Characteristic Create <T>(this Accessory accessory, string type, object value, string format, bool canWrite = false) { var service = accessory.Services[1]; int id = service.Characteristics[service.Characteristics.Count - 1].Id + 1; var characteristic = CharacteristicFactory.Create <T>(accessory.Services[1], type, value, id); SetCharacteristicOptions(characteristic, format, canWrite); accessory.Services[1].Characteristics.Add(characteristic); return(characteristic); }
public void BaseCharacteristicList_WithNoParams_CreatesCharacteristicListWith6Entries() { // Arrange List <Characteristic> testList = new List <Characteristic>(); int expectedListSize = 6; // Act testList = CharacteristicFactory.BaseCharacteristicList(); // Assert Assert.AreEqual(expectedListSize, testList.Count, "Characteristic List has an incorrect size (" + testList.Count + ")"); }
public static Service CreateTemperatureSensor(Accessory accessory, int id, double value) { var service = new Service(accessory) { Type = TemperatureSensorType, Id = id }; var state = SetCharacteristicOptions(CharacteristicFactory.Create <bool>(service, CharacteristicBase.CurrentTemperatureType, value, 8), "float", false); state.Value = 0; service.Characteristics.Add(state); return(service); }
public static Service CreateSwitch(Accessory accessory, int id, bool value) { var service = new Service(accessory) { Type = SwitchType, Id = id }; var state = SetCharacteristicOptions(CharacteristicFactory.Create <bool>(service, CharacteristicBase.OnType, value, 8), "bool"); state.Value = false; service.Characteristics.Add(state); return(service); }
public static Service CreateContactSensor(Accessory accessory, int id, int value) { var service = new Service(accessory) { Type = ContactSensorType, Id = id }; var state = SetCharacteristicOptions(CharacteristicFactory.Create <bool>(service, CharacteristicBase.ContactSensorStateType, value, 8), "uint8", false); state.Value = 0; service.Characteristics.Add(state); return(service); }
public void RandomCharacteristicSet_WithValue6_CreatesValidCharacteristicSet() { // Arrange int testValue = 6; int minValue = 6; int maxValue = 6; for (int i = 0; i < TEST_COUNT; ++i) { // Act CharacteristicSet testSet = CharacteristicFactory.RandomCharacteristicSet(testValue); // Assert Assert.IsTrue(SumValues(testSet) >= minValue && SumValues(testSet) <= maxValue, "An invalid sum of characteristics was created (" + SumValues(testSet) + ")"); } }
public void BaseCharacteristicList_WithNoParams_CreatesBasicCharacteristics() { // Arrange List <Characteristic> testList = new List <Characteristic>(); uint expectedValue = 1; // Act testList = CharacteristicFactory.BaseCharacteristicList(); // Assert foreach (Characteristic testCharacteristic in testList) { Assert.AreEqual(expectedValue, testCharacteristic._value, "Characteristic has an incorrect value (" + testCharacteristic._associatedEnum + ": " + testCharacteristic._value + ")"); } }
public static Service CreateLightBulb(Accessory accessory, int id, bool value) { var service = new Service(accessory) { Type = LightBulbType, Id = id }; var bulbC = SetCharacteristicOptions(CharacteristicFactory.Create <bool>(service, CharacteristicBase.OnType, value, 8), "bool"); bulbC.Value = false; service.Characteristics.Add(bulbC); return(service); }
public static Service CreateAccessoryInfo(Accessory accessory, int id, string name, string manufacturer, string serial) { var service = new Service(accessory) { Type = AccessoryInformationType, Id = id }; service.Characteristics.Add(CharacteristicFactory.CreateIdentify(service, 2)); service.Characteristics.Add(CharacteristicFactory.CreateManufacturer(service, manufacturer, 3)); service.Characteristics.Add(CharacteristicFactory.CreateModel(service, name, 4)); service.Characteristics.Add(CharacteristicFactory.CreateName(service, name, 5)); service.Characteristics.Add(CharacteristicFactory.CreateSerial(service, serial, 6)); return(service); }
public static Service CreateOutlet(Accessory accessory, int id, bool value) { var service = new Service(accessory) { Type = OutletType, Id = id }; var on = SetCharacteristicOptions(CharacteristicFactory.Create <bool>(service, CharacteristicBase.OnType, value, 8), "bool"); on.Value = false; var inUse = SetCharacteristicOptions(CharacteristicFactory.Create <bool>(service, CharacteristicBase.OutletInUseType, true, 9), "bool", false); inUse.Value = true; service.Characteristics.Add(on); service.Characteristics.Add(inUse); return(service); }