Esempio n. 1
0
        //Add an extra AllJoyn device for Learn-in an EO device
        private AdapterDevice AddLearnInDevice()
        {
            AdapterDevice LearnInEODevice = new AdapterDevice("LearnInEODevice", "Digital-Concepts", "", "", "", "");

            IAdapterMethod Add_RockerSwitch = new AdapterMethod("Add_RockerSwitch", "Set EO Gateway to learn in mode", 0, "");

            Add_RockerSwitch.InputParams.Add(new AdapterValue("FriendlyName", "FriendlyName", null));
            LearnInEODevice.Methods.Add(Add_RockerSwitch);

            IAdapterMethod Add_Sensor = new AdapterMethod("Add_Sensor", "Set EO Gateway to learn in mode", 0, "");

            Add_Sensor.InputParams.Add(new AdapterValue("FriendlyName", "FriendlyName", null));
            LearnInEODevice.Methods.Add(Add_Sensor);

            IAdapterMethod Add_Handle = new AdapterMethod("Add_Handle", "Set EO Gateway to learn in mode", 0, "");

            Add_Handle.InputParams.Add(new AdapterValue("FriendlyName", "FriendlyName", null));
            LearnInEODevice.Methods.Add(Add_Handle);

            IAdapterMethod Add_Other = new AdapterMethod("Add_Other", "Set EO Gateway to learn in mode", 0, "");

            Add_Other.InputParams.Add(new AdapterValue("FriendlyName", "FriendlyName", null));
            LearnInEODevice.Methods.Add(Add_Other);

            return(LearnInEODevice);
        }
Esempio n. 2
0
        private Task PopulateDevicesAsync()
        {
            try
            {
                return(httpClient.GetAsync(new Uri(DCGWUrl + "devices")).AsTask().ContinueWith(async(response) =>
                {
                    if (response.Result.IsSuccessStatusCode)
                    {
                        var body = response.Result.Content.ReadAsStringAsync().AsTask().Result;
                        Devices devicesObj = JsonConvert.DeserializeObject <Devices>(JObject.Parse(body).ToString());

                        foreach (var device in devicesObj.devices)
                        {
                            this.AddDevice(device, false);
                        }

                        //Add an extra AllJoyn device for Learn-in process
                        AdapterDevice LearnInEODevice = AddLearnInDevice();
                        devicesDict.Add("LearnInEODevice", LearnInEODevice);
                        this.NotifyDeviceArrival(LearnInEODevice);

                        this.devices = devicesDict.Values.ToList();
                    }
                    await ReadStreamAsync();
                }));
            }
            catch (Exception e)
            {
                Debug.WriteLine("PopulateDevice:{0} Exception caught......", e);
                return(null);
            }
        }
Esempio n. 3
0
        public uint Initialize()
        {
            AdapterDevice myDevice = new AdapterDevice(DeviceName, VENDOR, MODEL, VERSION, SERIAL_NUMBER, DESCRIPTION);

            AdapterProperty robotProperty = new AdapterProperty("Robot", "");

            robotProperty.Attributes.Add(NewAttribute("Mode", "manual", E_ACCESS_TYPE.ACCESS_READWRITE));
            robotProperty.Attributes.Add(NewAttribute("Direction", 0, E_ACCESS_TYPE.ACCESS_READWRITE));
            robotProperty.Attributes.Add(NewAttribute("Speed", 5, E_ACCESS_TYPE.ACCESS_READWRITE));
            myDevice.Properties.Add(robotProperty);

            AdapterProperty speechProperty = new AdapterProperty("Speech", "");

            speechProperty.Attributes.Add(NewAttribute("Message", "Tell me a joke", E_ACCESS_TYPE.ACCESS_READWRITE));
            myDevice.Properties.Add(speechProperty);


            myDevice.Methods.Add(new AdapterMethod("stop", "Stop", 0));
            myDevice.Methods.Add(new AdapterMethod("forward", "Forward", 0));
            myDevice.Methods.Add(new AdapterMethod("left", "Turn left", 0));
            myDevice.Methods.Add(new AdapterMethod("right", "Turn right", 0));
            myDevice.Methods.Add(new AdapterMethod("backward", "Backwards", 0));
            myDevice.Methods.Add(new AdapterMethod("manual", "manual", 0));
            myDevice.Methods.Add(new AdapterMethod("autonomous", "autonomous", 0));
            myDevice.Methods.Add(new AdapterMethod("speak", "speak", 0));


            devices.Add(myDevice);

            return(ERROR_SUCCESS);
        }
Esempio n. 4
0
        //Update status/Property of a single EO abstract device
        private void updateDevice(Telegram telegram)
        {
            var deviceId  = telegram.deviceId;
            var direction = telegram.direction;
            var functions = telegram.functions;

            foreach (var funcntion in functions)
            {
                var key   = funcntion.key;
                var value = funcntion.value.ToString();

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

                if (direction.Equals("from"))
                {
                    if (isLamp(key))
                    {
                        if (value != ((Lamp)device).OnOff_Value_Save.ToString())
                        {
                            ((Lamp)device).updateStates(UInt16.Parse(value));
                        }
                        break;
                    }
                    ;

                    if (device != null)
                    {
                        IList <IAdapterProperty> properties = device.Properties;
                        foreach (var property in properties)
                        {
                            IList <IAdapterAttribute> attributes = property.Attributes;
                            foreach (var attribute in attributes)
                            {
                                if (attribute.Value.Name.Equals(key))
                                {
                                    attribute.Value.Data = Windows.Foundation.PropertyValue.CreateString(value);

                                    int            SignalHashCode = ((AdapterValue)attribute.Value).SignalHashCode;
                                    IAdapterSignal covSignal      = null;
                                    ((AdapterDevice)device).SignalsDict.TryGetValue(SignalHashCode, out covSignal);

                                    this.NotifySignalListener(covSignal);
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        //Update status of all abstract EO devices with their current values
        private void UpdateDevices(IList <Device> devices)
        {
            foreach (var device in devices)
            {
                var           deviceId      = device.deviceId;
                AdapterDevice adapterDevice = (AdapterDevice)GetObject(devicesDict, deviceId);

                var states = device.states;
                if (states != null)
                {
                    foreach (var state in states)
                    {
                        var key     = state.key;
                        var value   = state.value.ToString();
                        var meaning = state.meaning;

                        if (isLamp(key))
                        {
                            ((Lamp)adapterDevice).updateStates(UInt16.Parse(value));
                            break;
                        }
                        ;
                        //AdapterValue in AdapterProperty is update with current value
                        IList <IAdapterProperty> properties = adapterDevice.Properties;
                        foreach (var property in properties)
                        {
                            IList <IAdapterAttribute> attributes = property.Attributes;
                            foreach (var attribute in attributes)
                            {
                                if (attribute.Value.Name.Equals(key))
                                {
                                    if (value != null)
                                    {
                                        attribute.Value.Data = Windows.Foundation.PropertyValue.CreateString(value);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 6
0
        internal AdapterDevice(AdapterDevice Other)
        {
            this.Name            = Other.Name;
            this.Vendor          = Other.Vendor;
            this.Model           = Other.Model;
            this.Version         = Other.Version;
            this.FirmwareVersion = Other.FirmwareVersion;
            this.SerialNumber    = Other.SerialNumber;
            this.Description     = Other.Description;

            try
            {
                this.Properties = new List <IAdapterProperty>(Other.Properties);
                this.Methods    = new List <IAdapterMethod>(Other.Methods);
                this.Signals    = new List <IAdapterSignal>(Other.Signals);
            }
            catch (OutOfMemoryException ex)
            {
                throw;
            }
        }
Esempio n. 7
0
        internal AdapterDevice(AdapterDevice Other)
        {
            this.Name = Other.Name;
            this.Vendor = Other.Vendor;
            this.Model = Other.Model;
            this.Version = Other.Version;
            this.FirmwareVersion = Other.FirmwareVersion;
            this.SerialNumber = Other.SerialNumber;
            this.Description = Other.Description;

            try
            {
                this.Properties = new List<IAdapterProperty>(Other.Properties);
                this.Methods = new List<IAdapterMethod>(Other.Methods);
                this.Signals = new List<IAdapterSignal>(Other.Signals);
            }
            catch (OutOfMemoryException ex)
            {
                throw new OutOfMemoryException(ex.Message);
            }
        }
Esempio n. 8
0
        internal AdapterDevice(AdapterDevice Other)
        {
            this.Name            = Other.Name;
            this.Vendor          = Other.Vendor;
            this.Model           = Other.Model;
            this.Version         = Other.Version;
            this.FirmwareVersion = Other.FirmwareVersion;
            this.SerialNumber    = Other.SerialNumber;
            this.Description     = Other.Description;

            try
            {
                this.Properties = new List <IAdapterProperty>(Other.Properties);
                this.Methods    = new List <IAdapterMethod>(Other.Methods);
                this.Signals    = new List <IAdapterSignal>(Other.Signals);
            }
            catch (OutOfMemoryException ex)
            {
                Debug.WriteLine("Out of memory while trying to allocate adapter device parameter containers." + ex.Message);
                throw;
            }
        }
        public uint Initialize()
        {
            AdapterDevice myDevice = new AdapterDevice(DeviceName, VENDOR, MODEL, VERSION, SERIAL_NUMBER, DESCRIPTION);

            AdapterProperty robotProperty = new AdapterProperty("Robot", "");
            robotProperty.Attributes.Add(NewAttribute("Mode", "manual", E_ACCESS_TYPE.ACCESS_READWRITE));
            robotProperty.Attributes.Add(NewAttribute("Direction", 0, E_ACCESS_TYPE.ACCESS_READWRITE));
            robotProperty.Attributes.Add(NewAttribute("Speed", 5, E_ACCESS_TYPE.ACCESS_READWRITE));
            myDevice.Properties.Add(robotProperty);

            myDevice.Methods.Add(new AdapterMethod("stop", "Stop", 0));
            myDevice.Methods.Add(new AdapterMethod("forward", "Forward", 0));
            myDevice.Methods.Add(new AdapterMethod("left", "Turn left", 0));
            myDevice.Methods.Add(new AdapterMethod("right", "Turn right", 0));
            myDevice.Methods.Add(new AdapterMethod("backward", "Backwards", 0));
            myDevice.Methods.Add(new AdapterMethod("joke", "Tell me a joke", 0));
            myDevice.Methods.Add(new AdapterMethod("banner", "Banner Control", 0));

            AdapterProperty lightProperty = new AdapterProperty("Light", "");
            lightProperty.Attributes.Add(NewAttribute("Mode", "off", E_ACCESS_TYPE.ACCESS_READWRITE));
            myDevice.Properties.Add(lightProperty);

            AdapterProperty speechProperty = new AdapterProperty("Speech", "");
            speechProperty.Attributes.Add(NewAttribute("Volume", 4, E_ACCESS_TYPE.ACCESS_READWRITE));
            speechProperty.Attributes.Add(NewAttribute("Message", "Tell me a joke", E_ACCESS_TYPE.ACCESS_READWRITE));
            myDevice.Properties.Add(speechProperty);

            AdapterProperty bannerProperty = new AdapterProperty("Banner", "");
            bannerProperty.Attributes.Add(NewAttribute("Pre", "Maker Den", E_ACCESS_TYPE.ACCESS_READWRITE));
            bannerProperty.Attributes.Add(NewAttribute("Post", "Data Den", E_ACCESS_TYPE.ACCESS_READWRITE));
            bannerProperty.Attributes.Add(NewAttribute("Calibration", 0, E_ACCESS_TYPE.ACCESS_READWRITE));
            myDevice.Properties.Add(bannerProperty);

            devices.Add(myDevice);

            return ERROR_SUCCESS;
        }
        public uint Initialize()
        {
            AdapterDevice myDevice = new AdapterDevice(DeviceName, VENDOR, MODEL, VERSION, SERIAL_NUMBER, DESCRIPTION);

            AdapterProperty robotProperty = new AdapterProperty("Robot", "");
            robotProperty.Attributes.Add(NewAttribute("Mode", "manual", E_ACCESS_TYPE.ACCESS_READWRITE));
            robotProperty.Attributes.Add(NewAttribute("Direction", 0, E_ACCESS_TYPE.ACCESS_READWRITE));
            robotProperty.Attributes.Add(NewAttribute("Speed", 5, E_ACCESS_TYPE.ACCESS_READWRITE));
            myDevice.Properties.Add(robotProperty);

            AdapterProperty speechProperty = new AdapterProperty("Speech", "");
            speechProperty.Attributes.Add(NewAttribute("Message", "Tell me a joke", E_ACCESS_TYPE.ACCESS_READWRITE));
            myDevice.Properties.Add(speechProperty);

            myDevice.Methods.Add(new AdapterMethod("stop", "Stop", 0));
            myDevice.Methods.Add(new AdapterMethod("forward", "Forward", 0));
            myDevice.Methods.Add(new AdapterMethod("left", "Turn left", 0));
            myDevice.Methods.Add(new AdapterMethod("right", "Turn right", 0));
            myDevice.Methods.Add(new AdapterMethod("backward", "Backwards", 0));
            myDevice.Methods.Add(new AdapterMethod("manual", "manual", 0));
            myDevice.Methods.Add(new AdapterMethod("autonomous", "autonomous", 0));
            myDevice.Methods.Add(new AdapterMethod("speak", "speak", 0));

            devices.Add(myDevice);

            return ERROR_SUCCESS;
        }
Esempio n. 11
0
        public uint Initialize()
        {
            AdapterDevice devicePin5 = new AdapterDevice("Switch 1", "Rohit Narayan", "Testing Model", "0.0.1", "000000001", "Controls Pin 5");
            AdapterDevice devicePin6 = new AdapterDevice("Switch 2", "Rohit Narayan", "Testing Model", "0.0.1", "000000001", "Controls Pin 6");
            AdapterDevice devicePin12 = new AdapterDevice("Switch 3", "Rohit Narayan", "Testing Model", "0.0.1", "000000001", "Controls Pin 12");
            AdapterDevice devicePin16 = new AdapterDevice("Switch 4", "Rohit Narayan", "Testing Model", "0.0.1", "000000001", "Controls Pin 16");

            // Define GPIO Pin-5 as device property. Device contains properties
            AdapterProperty gpioPin_Property5 = new AdapterProperty(PIN_NAME5, PIN_INTERFACE_HINT5);
            // Define and set GPIO Pin-5 value. Device contains properties that have one or more attributes.
            pinValueData5 = (int)pin5.Read();
            AdapterValue pinValueAttr5 = new AdapterValue(PIN_VALUE_NAME5, pinValueData5);
            gpioPin_Property5.Attributes.Add(pinValueAttr5);

            // Define GPIO Pin-6 as device property. Device contains properties
            AdapterProperty gpioPin_Property6 = new AdapterProperty(PIN_NAME6, PIN_INTERFACE_HINT6);
            // Define and set GPIO Pin-6 value. Device contains properties that have one or more attributes.
            pinValueData6 = (int)pin6.Read();
            AdapterValue pinValueAttr6 = new AdapterValue(PIN_VALUE_NAME6, pinValueData6);
            gpioPin_Property6.Attributes.Add(pinValueAttr6);

            // Define GPIO Pin-12 as device property. Device contains properties
            AdapterProperty gpioPin_Property12 = new AdapterProperty(PIN_NAME12, PIN_INTERFACE_HINT12);
            // Define and set GPIO Pin-12 value. Device contains properties that have one or more attributes.
            pinValueData12 = (int)pin12.Read();
            AdapterValue pinValueAttr12 = new AdapterValue(PIN_VALUE_NAME12, pinValueData12);
            gpioPin_Property12.Attributes.Add(pinValueAttr12);

            // Define GPIO Pin-16 as device property. Device contains properties
            AdapterProperty gpioPin_Property16 = new AdapterProperty(PIN_NAME16, PIN_INTERFACE_HINT16);
            // Define and set GPIO Pin-16 value. Device contains properties that have one or more attributes.
            pinValueData16 = (int)pin16.Read();
            AdapterValue pinValueAttr16 = new AdapterValue(PIN_VALUE_NAME16, pinValueData16);
            gpioPin_Property16.Attributes.Add(pinValueAttr16);

            devicePin5.Properties.Add(gpioPin_Property5);

            devicePin6.Properties.Add(gpioPin_Property6);

            devicePin12.Properties.Add(gpioPin_Property12);

            devicePin16.Properties.Add(gpioPin_Property16);

            devices.Add(devicePin5);

            devices.Add(devicePin6);

            devices.Add(devicePin12);

            devices.Add(devicePin16);

            return ERROR_SUCCESS;
        }
Esempio n. 12
0
 private void DeleteDevice(AdapterDevice adapterDevice)
 {
     dsbBridge.UpdateDeviceCustome(adapterDevice, true);
     devicesDict.Remove(adapterDevice.SerialNumber);
 }
Esempio n. 13
0
        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);
            }
        }
Esempio n. 14
0
        // This thread Listen for any change in Stream API
        private Task ReadStreamAsync()
        {
            return(Task.Run(() =>
            {
                var request = PrepareRequest(HttpMethod.Get, "devices/stream", "", "");
                var response = httpClient.SendRequestAsync(request, HttpCompletionOption.ResponseHeadersRead).AsTask().Result;

                if (response.IsSuccessStatusCode)
                {
                    using (response)
                    {
                        using (var stream = response.Content.ReadAsInputStreamAsync().GetResults())
                        {
                            IBuffer buffer = new Windows.Storage.Streams.Buffer(10000);
                            string bufferStream = "";

                            while (true)
                            {
                                buffer = stream.ReadAsync(buffer, buffer.Capacity, InputStreamOptions.Partial).AsTask().Result;
                                DataReader dataReader = DataReader.FromBuffer(buffer);
                                bufferStream += dataReader.ReadString(buffer.Length);

                                var isJsonValid = ValidateJSON(bufferStream);
                                //Debug.WriteLine(isJsonValid + ":::" + bufferStream + "xxx");
                                if (isJsonValid)
                                {
                                    var streamJson = JObject.Parse(bufferStream);
                                    var JsonProperty = streamJson.Property("header");
                                    Header header = JsonConvert.DeserializeObject <Header>(JsonProperty.Value.ToString());

                                    bufferStream = "";
                                    var content = header.content;
                                    if (content.Equals("telegram"))
                                    {
                                        TelegramBody telegram = JsonConvert.DeserializeObject <TelegramBody>(streamJson.ToString());
                                        updateDevice(telegram.telegram);
                                    }
                                    else
                                    if (content.Equals("device"))
                                    {
                                        LearnInTelegram learnInTelegram = JsonConvert.DeserializeObject <LearnInTelegram>(streamJson.ToString());
                                        var device = learnInTelegram.device;
                                        var deviceId = device.deviceId;
                                        var operable = device.operable;
                                        var deleted = device.deleted;

                                        if (!operable && !deleted)
                                        {
                                            if (NewDeviceProfile != null)
                                            {
                                                AddEODevice(learnInTelegram);
                                            }
                                        }
                                        else if (deleted)
                                        {
                                            AdapterDevice DeletedDevice = (AdapterDevice)GetObject(devicesDict, deviceId);
                                            if (DeletedDevice != null)
                                            {
                                                DeleteDevice(DeletedDevice);
                                            }
                                        }
                                        else if (operable)
                                        {
                                            IList <Device> devices = new List <Device>();
                                            devices.Add(device);
                                            AddDevice(device, true);
                                            UpdateDevices(devices);
                                        }
                                    }
                                    else
                                    if (content.Equals("devices"))
                                    {
                                        StreamDevices devices = JsonConvert.DeserializeObject <StreamDevices>(streamJson.ToString());
                                        UpdateDevices(devices.devices);
                                    }
                                }
                            }
                        }
                    }
                }
            }));
        }