public async Task Save_ShouldNotAddDeviceAuthenticationWhenDeviceIdDoesNotMatchLocalDeviceSaved() { AblyRequest executedRequest = null; var restClient = GetRestClient(request => { executedRequest = request; return(Task.FromResult(new AblyResponse() { TextResponse = string.Empty })); }); var deviceDetails = new LocalDevice() { Id = "123" }; restClient.Device = new LocalDevice() { Id = "456", DeviceIdentityToken = "token" }; _ = await restClient.Push.Admin.DeviceRegistrations.SaveAsync(deviceDetails); executedRequest.Headers.Should().NotContainKey(Defaults.DeviceIdentityTokenHeader); }
//private readonly Map<PropertyIdentifier, Encodable> properties = new HashMap<PropertyIdentifier, Encodable>(); //private readonly List<ObjectCovSubscription> covSubscriptions = new ArrayList<ObjectCovSubscription>(); public BACnetObject(LocalDevice localDevice, ObjectIdentifier id) { this.localDevice = localDevice; if (id == null) { throw new ArgumentException("object id cannot be null"); } Id = id; try { setProperty(PropertyIdentifier.ObjectName, new CharacterString(id.ToString())); // Set any default values. IList defs = ObjectProperties.getPropertyTypeDefinitions(id.ObjectType); foreach (PropertyTypeDefinition def in defs) { if (def.DefaultValue != null) { setProperty(def.PropertyIdentifier, def.DefaultValue); } } } catch (BACnetServiceException e) { // Should never happen, but wrap in an unchecked just in case. throw new BACnetRuntimeException(e); } }
private void Add_Click(object sender, RoutedEventArgs e) { if (Validate()) { lock (MainWindow.LocalDeviceList) { foreach (LocalDevice ld in LocalController.MainWindow.LocalDeviceList) { if (textBoxCode.Text.Equals(ld.LocalDeviceCode)) { textBoxCode.Text = textBoxCode.GetHashCode().ToString(); //ukoliko ime vec postoji, ime ovog LD-a postaje hash code break; } } LocalDevice dev = new LocalDevice(textBoxCode.Text, Double.Parse(textBoxPeriod.Text), Int32.Parse(textBoxLimit.Text), comboBoxType.SelectedItem.ToString(), comboBoxDestination.SelectedItem.ToString(), comboBoxController.SelectedItem.ToString()); MainWindow.LocalDeviceList.Add(dev); foreach (LocalController.Classes.LocalController lc in MainWindow.LocalControllerList) { if (lc.LocalControllerCode.Equals(comboBoxController.SelectedItem.ToString())) { lc.LocalControllerDevices.Add(dev); } } this.Close(); } } }
public override void handle(LocalDevice localDevice, Address from, OctetString linkService) { throw new NotImplementedException(); /*localDevice.getEventHandler().fireCovNotification(subscriberProcessIdentifier, * localDevice.getRemoteDeviceCreate(initiatingDeviceIdentifier.InstanceNumber, from, linkService), * monitoredObjectIdentifier, timeRemaining, listOfValues);*/ }
public override void handle(LocalDevice localDevice, Address from, OctetString linkService) { throw new NotImplementedException(); /*localDevice.getEventHandler().fireTextMessage( * localDevice.getRemoteDeviceCreate(textMessageSourceDevice.InstanceNumber, from, linkService), * messageClass, messagePriority, message);*/ }
public override void handle(LocalDevice localDevice, Address from, OctetString linkService) { throw new NotImplementedException(); /*localDevice.getEventHandler().fireEventNotification(processIdentifier, * localDevice.getRemoteDeviceCreate(initiatingDeviceIdentifier.InstanceNumber, from, linkService), * eventObjectIdentifier, timeStamp, notificationClass, priority, eventType, messageText, notifyType, * ackRequired, fromState, toState, eventValues);*/ }
public void IsCreated_ShouldBeTrueWhenBothIdAndSecretArePresent(string id, string secret, bool result) { var device = new LocalDevice() { Id = id, DeviceSecret = secret, }; device.IsCreated.Should().Be(result); }
public void WhenLocalDevice_DoesNOT_HaveEitherDeviceIdentityTokenAndSecret_ShouldNotAddAnyHeaders() { var request = new AblyRequest("/", HttpMethod.Get); var localDevice = new LocalDevice(); _ = GetRestClient(); PushAdmin.AddDeviceAuthenticationToRequest(request, localDevice); request.Headers.Should().BeEmpty(); }
public override void handle(LocalDevice localDevice, Address from, OctetString linkService) { // TODO RemoteDevice d = localDevice.getRemoteDeviceCreate(deviceIdentifier.getInstanceNumber(), from, linkService); RemoteObject o = new RemoteObject(objectIdentifier); o.ObjectName = objectName.ToString(); // TODO d.setObject(o); // TODO localDevice.getEventHandler().fireIHaveReceived(d, o); }
public void Create_ShouldCreateRandomDeviceSecretsAndIds() { var secrets = Enumerable.Range(1, 100) .Select(x => LocalDevice.Create().DeviceSecret) .Distinct(); var ids = Enumerable.Range(1, 100) .Select(x => LocalDevice.Create().Id) .Distinct(); secrets.Should().HaveCount(100); ids.Should().HaveCount(100); }
public static void Main() { // write your code here LinkLayer ll = new LinkLayer(); NetworkLayer network = new NetworkLayer(1, ll); ApplicationLayer app = new ApplicationLayer(network); ll.NewMessageReceived += BlinkLed; _device = new LocalDevice(999, app, "Netduino", "Netduino"); ll.Start(); }
public void WhenLocalDeviceHasDeviceSecret_ShouldAddHeaderToRequestWithCorrectValue() { var request = new AblyRequest("/", HttpMethod.Get); var localDevice = new LocalDevice() { DeviceSecret = "test" }; _ = GetRestClient(); PushAdmin.AddDeviceAuthenticationToRequest(request, localDevice); request.Headers.Should().ContainKey(Defaults.DeviceSecretHeader).WhoseValue.Should().Be("test"); }
public void WhenLocalDeviceHasBothDeviceIdentityTokenAndSecret_ShouldOnlyAddIdentityTokenHeader() { var request = new AblyRequest("/", HttpMethod.Get); var localDevice = new LocalDevice() { DeviceIdentityToken = "test", DeviceSecret = "secret" }; _ = GetRestClient(); PushAdmin.AddDeviceAuthenticationToRequest(request, localDevice); request.Headers.Should().ContainKey(Defaults.DeviceIdentityTokenHeader).WhoseValue.Should().Be("test"); request.Headers.Should().NotContainKey(Defaults.DeviceSecretHeader); }
public static LocalDevice GetTestLocalDevice(AblyRest client, string clientId = null) { var device = LocalDevice.Create(clientId); device.FormFactor = "phone"; device.Platform = "android"; device.Push.Recipient = JObject.FromObject(new { transportType = "ablyChannel", channel = "pushenabled:test", ablyKey = client.Options.Key, ablyUrl = "https://" + client.Options.FullRestHost(), }); return(device); }
public override void handle(LocalDevice localDevice, Address from, OctetString linkService) { try { ServicesSupported servicesSupported = (ServicesSupported)localDevice.Configuration.getProperty( PropertyIdentifier.ProtocolServicesSupported); if (servicesSupported.isUtcTimeSynchronization()) { throw new NotImplementedException(); } //localDevice.getEventHandler().synchronizeTime(time, true); } catch (BACnetServiceException e) { // no op } }
public async Task Save_ShouldCallTheCorrectUrlWithTheCorrectPayload() { AblyRequest executedRequest = null; var restClient = GetRestClient(request => { executedRequest = request; return(Task.FromResult(new AblyResponse() { TextResponse = string.Empty })); }); var deviceDetails = new LocalDevice() { Id = "123" }; _ = await restClient.Push.Admin.DeviceRegistrations.SaveAsync(deviceDetails); executedRequest.Url.Should().Be($"/push/deviceRegistrations/{deviceDetails.Id}"); executedRequest.PostData.Should().BeSameAs(deviceDetails); }
public override void handle(LocalDevice localDevice, Address from, OctetString linkService) { // Check if we're in the device id range. if (limits != null) { uint localId = localDevice.Configuration.InstanceId; if (localId < limits.DeviceInstanceRangeLowLimit.Value || localId > limits.DeviceInstanceRangeHighLimit.Value) { return; } } // Check if we have the thing being looking for. BACnetObject result; if (@object.ContextId == 2) { ObjectIdentifier oid = (ObjectIdentifier)@object.Data; result = localDevice.GetObject(oid); } else if (@object.ContextId == 3) { string name = ((CharacterString)@object.Data).ToString(); result = localDevice.GetObject(name); } else { return; } if (result != null) { // Return the result in an i have message. IHaveRequest response = new IHaveRequest(localDevice.Configuration.Id, result.Id, result.RawObjectName); localDevice.sendGlobalBroadcast(response); } }
public override void handle(LocalDevice localDevice, Address from, OctetString linkService) { if (!ObjectType.Device.Equals(iAmDeviceIdentifier.ObjectType)) { //LOGGER.warning("Received IAm from an object that is not a device."); Debug.Print("Received IAm from an object that is not a device."); return; } // Make sure we're not hearing from ourselves. uint myDoi = localDevice.Configuration.InstanceId; uint remoteDoi = iAmDeviceIdentifier.InstanceNumber; if (remoteDoi == myDoi) { // Get my bacnet address and compare the addresses foreach (Address addr in localDevice.AllLocalAddresses) { if (addr.MacAddress.Equals(from.MacAddress)) { // This is a local address, so ignore. return; } //LOGGER.warning("Another instance with my device instance ID found!"); Debug.Print("Another instance with my device instance ID found! Here: " + from.MacAddress.MacAddressDottedString); } } // Register the device in the list of known devices. RemoteDevice d = BACnetStack.CreateRemoteDevice(remoteDoi, from, linkService); d.MaxAPDULengthAccepted = maxAPDULengthAccepted.Value; d.SegmentationSupported = segmentationSupported; d.VendorID = vendorId.Value; // Fire the appropriate event. // TODO localDevice.getEventHandler().fireIAmReceived(d); }
public async Task LoadPersistedLocalDevice_ShouldLoadAllSavedProperties() { var mobileDevice = new FakeMobileDevice(); void SetSetting(string key, string value) => mobileDevice.SetPreference(key, value, PersistKeys.Device.SharedName); const string deviceId = "deviceId"; SetSetting(PersistKeys.Device.DeviceId, deviceId); const string clientId = "clientId"; SetSetting(PersistKeys.Device.ClientId, clientId); const string deviceSecret = "secret"; SetSetting(PersistKeys.Device.DeviceSecret, deviceSecret); const string identityToken = "token"; SetSetting(PersistKeys.Device.DeviceToken, identityToken); const string tokenType = "fcm"; SetSetting(PersistKeys.Device.TokenType, tokenType); const string token = "registration_token"; SetSetting(PersistKeys.Device.Token, token); var loadResult = LocalDevice.LoadPersistedLocalDevice(mobileDevice, out var localDevice); loadResult.Should().BeTrue(); localDevice.Platform.Should().Be(mobileDevice.DevicePlatform); localDevice.FormFactor.Should().Be(mobileDevice.FormFactor); localDevice.Id.Should().Be(deviceId); localDevice.ClientId.Should().Be(clientId); localDevice.DeviceSecret.Should().Be(deviceSecret); localDevice.DeviceIdentityToken.Should().Be(identityToken); localDevice.RegistrationToken.Type.Should().Be(tokenType); localDevice.RegistrationToken.Token.Should().Be(token); }
public override void handle(LocalDevice localDevice, Address from, OctetString linkService) { BACnetObject local = localDevice.Configuration; // Check if we're in the device id range. if (DeviceInstanceRangeLowLimit != null && local.InstanceId < DeviceInstanceRangeLowLimit.Value) { return; } if (DeviceInstanceRangeHighLimit != null && local.InstanceId > DeviceInstanceRangeHighLimit.Value) { return; } // Return the result in a i am message. //DCC - AdK //if(!localDevice.getDCCEnableDisable().equals(EnableDisable.disable)) { IAmRequest iam = localDevice.MakeIAmRequest(); localDevice.sendGlobalBroadcast(iam, true); //} }
private void ReplyRootDeviceV2(LocalDevice device, IPEndPoint destination) { try { //string announce_message = "HTTP/1.1 200 OK\r\nCACHE-CONTROL:max-age=" + max_age + "\r\nLOCATION:http://" + local_device_handler.IP + ":" + local_device_handler.Port + "/device/" + device.DeviceID + "/root.xml\r\nNT:urn:" + device.UniqueServiceName + "\r\nUSN:uuid:" + device.UniversalUniqueID + "::urn:" + device.UniqueServiceName + "\r\nST: uuid:" + device.UniversalUniqueID + "\r\nServer:NT/5.0 UPnP/1.0\r\n\r\n"; string reply_message = "HTTP/1.1 200 OK\r\n"; reply_message += "CACHE-CONTROL: max-age=" + max_age + "\r\n"; reply_message += "LOCATION: http://" + local_device_handler.IP + ":" + local_device_handler.Port + "/device/" + device.DeviceID + "/root.xml\r\n"; reply_message += "USN: uuid:" + device.UniversalUniqueID + "\r\n"; reply_message += "ST: uuid:" + device.UniversalUniqueID + "\r\n"; reply_message += "Server: NT/5.0 UPnP/1.0\r\n"; reply_message += "\r\n"; //IPEndPoint udp_announce_endpoint = new IPEndPoint(IPAddress.Parse(upnp_udp_multicast_address), upnp_udp_port); byte[] send_bytes = System.Text.Encoding.Default.GetBytes(reply_message); udp_send_socket.BeginSendTo(send_bytes, 0, send_bytes.Length, SocketFlags.None, destination, new AsyncCallback(ReplyRootDeviceV2Callback), udp_send_socket); } catch (Exception ex) { Console.WriteLine("Exception during sending of root device reply v2 packet: " + ex.Message); } }
public void AddLocalDevice(LocalDevice device) { lock (local_devices_lock) { if (local_devices.Count == 0) StartLocalDeviceHandler(); local_devices.Add(device); } //AnnounceDeviceAll(device, true); }
/// <summary> /// Announce a root device to other upnp aware applications /// </summary> /// <param name="device">the device to broadcast</param> public void AnnounceRootDevice(LocalDevice device, bool is_alive) { try { string nts = "ssdp:alive"; if (!is_alive) nts = "ssdp:byebye"; string announce_message = "NOTIFY * HTTP/1.1\r\n"; announce_message += "HOST: 239.255.255.250:1900\r\n"; announce_message += "CACHE-CONTROL: max-age=" + max_age + "\r\n"; announce_message += "LOCATION: http://" + local_device_handler.IP + ":" + local_device_handler.Port + "/device/" + device.DeviceID + "/root.xml\r\n"; announce_message += "NT: upnp:rootdevice\r\n"; announce_message += "USN: uuid:" + device.UniversalUniqueID + "::upnp:rootdevice\r\n"; announce_message += "NTS: "+nts+"\r\n"; announce_message += "Server: NT/5.0 UPnP/1.0\r\n"; announce_message += "\r\n"; IPEndPoint udp_announce_endpoint = new IPEndPoint(IPAddress.Parse(upnp_udp_multicast_address), upnp_udp_port); byte[] send_bytes = System.Text.Encoding.Default.GetBytes(announce_message); udp_socket.BeginSendTo(send_bytes, 0, send_bytes.Length, SocketFlags.None, udp_announce_endpoint, new AsyncCallback(AnnounceRootDeviceCallback), udp_socket); } catch (Exception ex) { Console.WriteLine("Exception during sending of device announce packet: " + ex.Message); } }
public void RemoveLocalDevice(LocalDevice device) { AnnounceDeviceAll(device, false); lock (local_devices_lock) { local_devices.Remove(device); if (local_devices.Count == 0) StopLocalDeviceHandler(); } //TODO let other upnp devices know that this device has gone offline }
public static void ResetDevice() { LocalDevice.Reset(presentationParameters); }
public void AnnounceDeviceAll(LocalDevice device, bool is_alive) { int packets_num = 1; int small_interval = 75; int big_interval = 0; for (int i = 0; i < packets_num; i++) { AnnounceRootDevice(device, is_alive); Thread.Sleep(small_interval); AnnounceRootDevice(device, is_alive); Thread.Sleep(small_interval); AnnounceDeviceUUID(device, is_alive); Thread.Sleep(small_interval); AnnounceDeviceUUID(device, is_alive); Thread.Sleep(small_interval); AnnounceDevice(device, is_alive); Thread.Sleep(small_interval); AnnounceDevice(device, is_alive); Thread.Sleep(small_interval); AnnounceDeviceServices(device, is_alive); Thread.Sleep(big_interval); } }
public void AnnounceLocalDevice(LocalDevice device) { device.LastAnnouncementTime = DateTime.MinValue; }
public abstract AcknowledgementService handle(LocalDevice localDevice, Address from, OctetString linkService);
public override void handle(LocalDevice localDevice, Address from, OctetString linkService) { // TODO localDevice.getEventHandler().firePrivateTransfer(vendorId, serviceNumber, serviceParameters); }
public void AnnounceDeviceServices(LocalDevice device, bool is_alive) { foreach (SubDevice.Service service in device.RootDevice.Services) { int small_interval = 50; AnnounceDeviceService(device, service, is_alive); Thread.Sleep(small_interval); AnnounceDeviceService(device, service, is_alive); } }
public virtual void handle(LocalDevice localDevice, Address address, OctetString linkService) { throw new NotImplementedException(); }
public void ReplyDeviceServices(LocalDevice device, IPEndPoint destination) { foreach (SubDevice.Service service in device.RootDevice.Services) { ReplyDeviceService(device, service,destination); } }