Beispiel #1
0
 internal AdapterAttribute(AdapterAttribute Other)
 {
     this.Value       = Other.Value;
     this.Annotations = Other.Annotations;
     this.Access      = Other.Access;
     this.COVBehavior = Other.COVBehavior;
 }
 internal AdapterAttribute(AdapterAttribute Other)
 {
     this.Value = Other.Value;
     this.Annotations = Other.Annotations;
     this.Access = Other.Access;
     this.COVBehavior = Other.COVBehavior;
 }
Beispiel #3
0
        AdapterAttribute NewAttribute(string name, object value, E_ACCESS_TYPE access)
        {
            AdapterAttribute attr = new AdapterAttribute(name, value, access);

            attr.COVBehavior = SignalBehavior.Always;

            return(attr);
        }
        AdapterAttribute NewAttribute(string name, object value, E_ACCESS_TYPE access)
        {
            AdapterAttribute attr = new AdapterAttribute(name, value, access);
            attr.COVBehavior = SignalBehavior.Always;

            return attr;
        }
        public void AddDevice(Device device, bool isNew)
        {
            var           deviceId      = device.deviceId;
            var           friendlyId    = device.friendlyId;
            var           manufacturer  = device.manufacturer != null ? device.manufacturer : "Manufacturer";
            AdapterDevice adapterDevice = null;

            Task <HttpResponseMessage> response = httpClient.GetAsync(new Uri(DCGWUrl + "devices/" + deviceId)).AsTask();
            string body = response.Result.Content.ReadAsStringAsync().AsTask().Result;

            //DeviceProfiles deviceProifles = JsonConvert.DeserializeObject<DeviceProfiles>(JObject.Parse(body).ToString());
            foreach (var eep in device.eeps)
            {
                var eepName = eep.eep;
                response = httpClient.GetAsync(new Uri(DCGWUrl + "profiles/" + eepName)).AsTask();
                body     = response.Result.Content.ReadAsStringAsync().AsTask().Result;

                ProfileDefination profileInfo = JsonConvert.DeserializeObject <ProfileDefination>(JObject.Parse(body).ToString());
                var profile        = profileInfo.profile;
                var functionGroups = profile.functionGroups;
                var title          = profile.title != null ? profile.title : "TitleDesciption";


                if (isLampProfile(eepName))
                {
                    adapterDevice = new Lamp(friendlyId, manufacturer, eepName, "0", deviceId, title);
                    ((Lamp)adapterDevice).Adapter = this;
                }
                else
                {
                    adapterDevice = new AdapterDevice(friendlyId, manufacturer, eepName, "0", deviceId, title);
                    foreach (var functionGroup in functionGroups)
                    {
                        string titleFG   = functionGroup.title != null ? functionGroup.title : "Property";
                        string direction = direction = functionGroup.direction;;
                        var    functions = functionGroup.functions;

                        var property = new AdapterProperty(titleFG, "");
                        foreach (var function in functions)
                        {
                            var key          = function.key;
                            var description  = function.description;
                            var defaultValue = function.defaultValue;

                            var    values  = function.values;
                            string meaning = null;
                            Range  range   = null;

                            double min  = 0.0;
                            double max  = 0.0;
                            double step = 0.0;
                            string unit = null;

                            if (defaultValue == null)
                            {
                                var valueTk = values.First <Value>();
                                meaning      = valueTk.meaning;
                                range        = valueTk.range;
                                defaultValue = valueTk.value;
                                if (range != null)
                                {
                                    min          = range.min;
                                    max          = range.max;
                                    step         = range.step;
                                    unit         = range.unit;
                                    defaultValue = range.min;
                                }
                            }

                            object defaultData = Windows.Foundation.PropertyValue.CreateString(defaultValue.ToString());
                            var    valueAttr   = new AdapterAttribute(key, defaultData, deviceId, E_ACCESS_TYPE.ACCESS_READWRITE);

                            if (range != null)
                            {
                                valueAttr.Annotations.Add("min", defaultValue.ToString());
                                valueAttr.Annotations.Add("max", max.ToString());
                                valueAttr.Annotations.Add("range", step.ToString());
                                valueAttr.Annotations.Add("unit", unit);
                            }

                            if (direction.Equals("from"))
                            {
                                valueAttr = new AdapterAttribute(key, defaultData, deviceId, E_ACCESS_TYPE.ACCESS_READ);
                            }
                            else if (direction.Equals("both"))
                            {
                                object valueDataTest = Windows.Foundation.PropertyValue.CreateString("");

                                //This is a workaround to know if device supports both functionality
                                //500 is response status for read only property and 400 for device that support both direct,
                                //status is 400 because we are sending no value (valueDataTest is emplty string)
                                uint status = SetHttpValue("devices/" + deviceId + "/state", valueDataTest, key);
                                if (status == 500)
                                {
                                    valueAttr = new AdapterAttribute(key, defaultData, deviceId, E_ACCESS_TYPE.ACCESS_READ);
                                }
                            }

                            valueAttr.COVBehavior = SignalBehavior.Always;
                            adapterDevice.AddChangeOfValueSignal(property, valueAttr.Value);

                            property.Attributes.Add(valueAttr);
                        }
                        adapterDevice.Properties.Add(property);
                    }
                }
            }

            IAdapterMethod Delete = new AdapterMethod("Delete", "Delete EO device", 0, "devices/" + deviceId);

            adapterDevice.Methods.Add(Delete);

            AdapterDevice AddedDevice = (AdapterDevice)GetObject(devicesDict, deviceId);

            if (AddedDevice == null)

            {
                this.devicesDict.Add(deviceId, adapterDevice);

                //update device list in the bridge if device is added when bridge is running
                if (isNew)
                {
                    dsbBridge.UpdateDeviceCustome(adapterDevice, false);
                }
                this.NotifyDeviceArrival(adapterDevice);
            }
        }