async void OnAdded(FezHatWatcher sender, AllJoynServiceInfo args) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { // Get the about data. var aboutData = await AllJoynAboutDataView.GetDataBySessionPortAsync(args.UniqueName, _busAttachment, args.SessionPort); Debug.WriteLine("Found {0} on {1} from manufacturer: {2}. Connecting...", aboutData.AppName, aboutData.DeviceName, aboutData.Manufacturer); var joinResult = await FezHatConsumer.JoinSessionAsync(args, sender); if (joinResult.Status != AllJoynStatus.Ok) { return; } FezHats.Add(new FezHatItem() { UniqueName = args.UniqueName, DefaultAppName = aboutData.AppName, ModelNumber = aboutData.ModelNumber, DateOfManufacture = aboutData.DateOfManufacture, Consumer = joinResult.Consumer }); joinResult.Consumer.SessionLost += OnFezHatLost; joinResult.Consumer.Signals.ButtonDio18PressedReceived += Signals_ButtonDio18PressedReceived; } ); }
private async void FoundLight(LampStateConsumer consumer, AllJoynAboutDataView about) { // consumer.Signals.LampStateChanged() foreach (DisplayLamp d in bulbs) { if (about.DeviceId.Equals(d.about.DeviceId) && about.DeviceName.Equals(d.about.DeviceId)) { return; } } consumer.Signals.LampStateChangedReceived += Signals_LampStateChangedReceived; DisplayLamp dl = new DisplayLamp(consumer, about); bulbs.Add(dl); bool ret = await updateLamp(dl); await updateLamp(dl); var dispatcher = Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher; await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { var vm = this.DataContext as ViewModels.MainPageViewModel; vm.AddBulb(about.DeviceName, about.DeviceId); updateBulbDisplay(dl); }); }
private async void Watcher_Added(LampStateWatcher sender, AllJoynServiceInfo args) { AllJoynAboutDataView aboutData = await AllJoynAboutDataView.GetDataBySessionPortAsync(args.UniqueName, busAttachment, args.SessionPort); if (aboutData != null && !string.IsNullOrWhiteSpace(aboutData.DeviceId)) { // Join session with the producer of the LampState interface. LampStateJoinSessionResult joinSessionResult = await LampStateConsumer.JoinSessionAsync(args, sender); if (joinSessionResult.Status == AllJoynStatus.Ok) { if (string.Equals(aboutData.DeviceId, lampDeviceId)) { consumer = joinSessionResult.Consumer; LampFound?.Invoke(this, new EventArgs()); consumer.Signals.LampStateChangedReceived += Signals_LampStateChangedReceived; } if (!arrLamp.Contains(joinSessionResult.Consumer)) { arrLamp.Add(joinSessionResult.Consumer); } } } }
private async void Watcher_Added(org.allseen.LSF.LampState.LampStateWatcher sender, Windows.Devices.AllJoyn.AllJoynServiceInfo args) { Debug.Write("Watcher_Added"); string name = args.UniqueName; var session = await LampStateConsumer.JoinSessionAsync(args, sender); if (session.Status == AllJoynStatus.Ok) { AllJoynAboutDataView about = await AllJoynAboutDataView.GetDataBySessionPortAsync(args.UniqueName, bus, args.SessionPort); if (about != null) { FoundLight(session.Consumer, about); } } else { if (session.Status == AllJoynStatus.AuthenticationFailed) { Debug.WriteLine(""); } if (session.Status == AllJoynStatus.ConnectionRefused) { Debug.WriteLine(""); } if (session.Status == AllJoynStatus.Fail) { Debug.WriteLine(""); } if (session.Status == AllJoynStatus.InsufficientSecurity) { Debug.WriteLine(""); } if (session.Status == AllJoynStatus.OperationTimedOut) { Debug.WriteLine(""); } if (session.Status == AllJoynStatus.OtherEndClosed) { Debug.WriteLine(""); } if (session.Status == AllJoynStatus.SslConnectFailed) { Debug.WriteLine(""); } if (session.Status == AllJoynStatus.SslIdentityVerificationFailed) { Debug.WriteLine(""); } } }
private async void Watcher_Added(SecureInterfaceWatcher sender, AllJoynServiceInfo args) { // Optional - Get the About data of the producer. AllJoynAboutDataView aboutData = await AllJoynAboutDataView.GetDataBySessionPortAsync(args.UniqueName, m_busAttachment, args.SessionPort); // Check to see if device name is populated in the about data, since device name is not a mandatory field. if (string.IsNullOrEmpty(aboutData.DeviceName)) { UpdateStatusAsync(string.Format("Found {0} from manufacturer: {1}. Connecting...", aboutData.AppName, aboutData.Manufacturer), NotifyType.StatusMessage); } else { UpdateStatusAsync(string.Format("Found {0} on {1} from manufacturer: {2}. Connecting...", aboutData.AppName, aboutData.DeviceName, aboutData.Manufacturer), NotifyType.StatusMessage); } // Attempt to join the session when a producer is discovered. SecureInterfaceJoinSessionResult joinSessionResult = await SecureInterfaceConsumer.JoinSessionAsync(args, sender); if (joinSessionResult.Status == AllJoynStatus.Ok) { DisposeConsumer(); m_consumer = joinSessionResult.Consumer; m_consumer.IsUpperCaseEnabledChanged += Consumer_IsUpperCaseEnabledChanged; m_consumer.Signals.TextSentReceived += Signals_TextSentReceived; m_consumer.SessionLost += Consumer_SessionLost; // At the time of connection, the request credentials callback not being invoked is an // indication that the consumer and producer are already authenticated from a previous session. if (!m_isCredentialsRequested) { UpdateStatusAsync("Connected and already authenticated from previous session.", NotifyType.StatusMessage); UpdateIsUpperCaseEnabledAsync(); } else { if (m_isAuthenticated) { UpdateStatusAsync("Connected with authentication.", NotifyType.StatusMessage); UpdateIsUpperCaseEnabledAsync(); } else { UpdateStatusAsync("Connected but authentication failed.", NotifyType.ErrorMessage); } } ConsumerOptionsVisibility = Visibility.Visible; } else { UpdateStatusAsync(string.Format("Attempt to connect failed with AllJoyn error: 0x{0:X}.", joinSessionResult.Status), NotifyType.ErrorMessage); } }
private async void Watcher_Added(DeviceWatcher sender, DeviceInformation args) { // Optional - Get the About data of the producer. AllJoynAboutDataView aboutData = await m_busAttachment.GetAboutDataAsync(await AllJoynServiceInfo.FromIdAsync(args.Id)); // Check to see if device name is populated in the about data, since device name is not a mandatory field. if (string.IsNullOrEmpty(aboutData.DeviceName)) { UpdateStatusAsync(string.Format("Found {0} from manufacturer: {1}. Connecting...", aboutData.AppName, aboutData.Manufacturer), NotifyType.StatusMessage); } else { UpdateStatusAsync(string.Format("Found {0} on {1} from manufacturer: {2}. Connecting...", aboutData.AppName, aboutData.DeviceName, aboutData.Manufacturer), NotifyType.StatusMessage); } DisposeConsumer(); UpdateStatusAsync("Joining session...", NotifyType.StatusMessage); m_consumer = await SecureInterfaceConsumer.FromIdAsync(args.Id, m_busAttachment); if (m_consumer != null) { m_consumer.IsUpperCaseEnabledChanged += Consumer_IsUpperCaseEnabledChanged; m_consumer.Signals.TextSentReceived += Signals_TextSentReceived; m_consumer.Session.Lost += Consumer_SessionLost; // At the time of connection, the request credentials callback not being invoked is an // indication that the consumer and producer are already authenticated from a previous session. if (!m_isCredentialsRequested) { UpdateStatusAsync("Connected and already authenticated from previous session.", NotifyType.StatusMessage); UpdateIsUpperCaseEnabledAsync(); } else { if (m_isAuthenticated) { UpdateStatusAsync("Connected with authentication.", NotifyType.StatusMessage); UpdateIsUpperCaseEnabledAsync(); } else { UpdateStatusAsync("Connected but authentication failed.", NotifyType.ErrorMessage); } } ConsumerOptionsVisibility = Visibility.Visible; } else { UpdateStatusAsync("Attempt to join session failed.", NotifyType.ErrorMessage); } }
private async void FoundLight(LampStateConsumer consumer, AllJoynAboutDataView about) { consumer.Signals.LampStateChangedReceived += Signals_LampStateChangedReceived; DisplayLamp dl = new DisplayLamp(consumer, about); BulbManager.Instance.AddBulb(dl); var dispatcher = Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher; await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { App.MainMenu.Count = $"({BulbManager.Instance.NumberOfLamps()})";; }); }
public static dynamic GetAllJoynDevice(AllJoynAboutDataView deviceDataView) { var device = DeviceSchemaHelper.BuildDeviceStructure(deviceDataView.DeviceId, IS_SIMULATED_DEVICE); AssignDeviceProperties(deviceDataView, device); AssignCommands(device); device.ObjectType = OBJECT_TYPE_DEVICE_INFO; device.Version = VERSION_1_0; device.IsSimulatedDevice = IS_SIMULATED_DEVICE; // return device; }
private async void Det_Added(org.allseen.LSF.LampDetails.LampDetailsWatcher sender, AllJoynServiceInfo args) { AllJoynAboutDataView about = await AllJoynAboutDataView.GetDataBySessionPortAsync(args.UniqueName, bus, args.SessionPort); var appName = about.AppName; var devName = about.DeviceName; var vm = this.DataContext as ViewModels.MainPageViewModel; vm.AddBulb(devName, about.DeviceId); if (watcher == null) { watcher = new org.allseen.LSF.LampState.LampStateWatcher(bus); watcher.Added += Watcher_Added; watcher.Start(); } }
private async void Details_Added(org.allseen.LSF.LampDetails.LampDetailsWatcher sender, AllJoynServiceInfo args) { var session = await LampDetailsConsumer.JoinSessionAsync(args, sender); if (session.Status == AllJoynStatus.Ok) { AllJoynAboutDataView about = await AllJoynAboutDataView.GetDataBySessionPortAsync(args.UniqueName, bus, args.SessionPort); if (about != null) { LampDetailsGetColorResult lres = await session.Consumer.GetColorAsync(); DisplayLamp dl = new DisplayLamp(session.Consumer, about); dl.isColourLamp = lres; BulbManager.Instance.AddBulb(dl); } } }
private async void Watcher_Added(LampStateWatcher sender, AllJoynServiceInfo args) { Debug.Write("Watcher_Added"); string name = args.UniqueName; var session = await LampStateConsumer.JoinSessionAsync(args, sender); if (session.Status == AllJoynStatus.Ok) { AllJoynAboutDataView about = await AllJoynAboutDataView.GetDataBySessionPortAsync(args.UniqueName, bus, args.SessionPort); if (about != null) { FoundLight(session.Consumer, about); } } }
static async void OnLightControlAdded( LightControlWatcher sender, AllJoynServiceInfo args) { AllJoynAboutDataView advertisementMetadata = await AllJoynAboutDataView.GetDataBySessionPortAsync( args.UniqueName, watchingBusAttachment, args.SessionPort); var buildingName = advertisementMetadata.AppName; if (buildingName != localBuildingName) { discoveredServices[buildingName] = args; LightControlDiscovered?.Invoke(null, new LightControlDiscoveredEventArgs() { BuildingName = buildingName }); } }
private async void RadioWatcher_Added(InternetRadioWatcher sender, AllJoynServiceInfo args) { Debug.WriteLine(args.UniqueName); var about = await AllJoynAboutDataView.GetDataBySessionPortAsync(args.UniqueName, alljoynBusAttachment, args.SessionPort); if (null == about) { Debug.WriteLine("Unable to get AboutData for device: " + args.UniqueName); return; } await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, (() => { devices.Add(new InternetRadioDeviceRegistrationInfo() { Name = string.Format("{0} ({1})", about.AppName, about.DeviceName), sender = sender, args = args }); })); }
private async void LampStateWatcher_Added(LampStateWatcher sender, AllJoynServiceInfo args) { var aboutData = await AllJoynAboutDataView.GetDataBySessionPortAsync(args.UniqueName, _lampStateBusAttachment, args.SessionPort); if (aboutData.Manufacturer.ToLower().Contains("philips")) { var joinResult = await LampStateConsumer.JoinSessionAsync(args, sender); if (joinResult.Status == AllJoynStatus.Ok) { _lampStateConsumer = joinResult.Consumer; _lampStateConsumer.SessionLost += this.Consumer_SessionLost; // subscribe to value changes _lampStateConsumer.Signals.LampStateChangedReceived += this.lampStateConsumer_LampStateChangedReceived; // populate initial values this.GetCurrentValuesAsync(); this.IsConnected = true; } } }
public DisplayLamp(LampStateConsumer consumer, AllJoynAboutDataView about) { this.consumer = consumer; this.about = about; }
/* public static dynamic GetSampleDevice(Random randomNumber, SecurityKeys keys) { string deviceId = string.Format( CultureInfo.InvariantCulture, "00000-DEV-{0}C-{1}LK-{2}D-{3}", MAX_COMMANDS_SUPPORTED, randomNumber.Next(99999), randomNumber.Next(99999), randomNumber.Next(99999)); dynamic device = DeviceSchemaHelper.BuildDeviceStructure(deviceId, false); device.ObjectName = "IoT Device Description"; AssignDeviceProperties(deviceId, device); AssignCommands(device); return device; }*/ private static void AssignDeviceProperties(AllJoynAboutDataView deviceDataView, dynamic device) { dynamic deviceProperties = DeviceSchemaHelper.GetDeviceProperties(device); deviceProperties.HubEnabledState = false; deviceProperties.Manufacturer = deviceDataView.Manufacturer; deviceProperties.ModelNumber = deviceDataView.ModelNumber; deviceProperties.SerialNumber = deviceDataView.DeviceId; deviceProperties.FirmwareVersion = deviceDataView.SoftwareVersion; deviceProperties.Platform = deviceDataView.HardwareVersion; /*deviceProperties.Processor = "ARM"; deviceProperties.InstalledRAM = "No data"; // Choose a location between the 3 above and set Lat and Long for device properties int chosenLocation = GetIntBasedOnString(deviceDataView.DeviceId + "Location", _possibleDeviceLocations.Count); deviceProperties.Latitude = _possibleDeviceLocations[chosenLocation].Latitude; deviceProperties.Longitude = _possibleDeviceLocations[chosenLocation].Longitude;*/ }
public DisplayLamp(LampDetailsConsumer consumer, AllJoynAboutDataView about) { this.DetailsConsumer = consumer; this.about = about; }
/* public static dynamic GetSampleDevice(Random randomNumber, SecurityKeys keys) { string deviceId = string.Format( CultureInfo.InvariantCulture, "00000-DEV-{0}C-{1}LK-{2}D-{3}", MAX_COMMANDS_SUPPORTED, randomNumber.Next(99999), randomNumber.Next(99999), randomNumber.Next(99999)); dynamic device = DeviceSchemaHelper.BuildDeviceStructure(deviceId, false); device.ObjectName = "IoT Device Description"; AssignDeviceProperties(deviceId, device); AssignCommands(device); return device; }*/ private static void AssignDeviceProperties(AllJoynAboutDataView deviceDataView, dynamic device) { dynamic deviceProperties = DeviceSchemaHelper.GetDeviceProperties(device); deviceProperties.HubEnabledState = false; deviceProperties.Manufacturer = deviceDataView.Manufacturer; deviceProperties.ModelNumber = deviceDataView.ModelNumber; deviceProperties.SerialNumber = deviceDataView.DeviceId; ulong version = 0; if (!ulong.TryParse(deviceDataView.SoftwareVersion, out version)) { deviceProperties.FirmwareVersion = String.Empty; } else { deviceProperties.FirmwareVersion = String.Format(CultureInfo.InvariantCulture, "{0}.{1}.{2}.{3}", (version & 0xFFFF000000000000) >> 48, (version & 0x0000FFFF00000000) >> 32, (version & 0x00000000FFFF0000) >> 16, version & 0x000000000000FFFF); } deviceProperties.Platform = deviceDataView.HardwareVersion; /*deviceProperties.Processor = "ARM"; deviceProperties.InstalledRAM = "No data"; // Choose a location between the 3 above and set Lat and Long for device properties int chosenLocation = GetIntBasedOnString(deviceDataView.DeviceId + "Location", _possibleDeviceLocations.Count); deviceProperties.Latitude = _possibleDeviceLocations[chosenLocation].Latitude; deviceProperties.Longitude = _possibleDeviceLocations[chosenLocation].Longitude;*/ }