Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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 + ")");
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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) + ")");
            }
        }
Ejemplo n.º 8
0
        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 + ")");
            }
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        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);
        }