public void LoadDefaultResources() { DeviceResources deviceResources = new DeviceResources(); IntegerResources availablePowerSources = new IntegerResources(string.Empty); availablePowerSources.Add(new IntegerResource("0") { Value = 1 }); availablePowerSources.Add(new IntegerResource("1") { Value = 5 }); IntegerResources powerSourceVoltage = new IntegerResources(string.Empty); powerSourceVoltage.Add(new IntegerResource("0") { Value = 3800 }); powerSourceVoltage.Add(new IntegerResource("1") { Value = 5000 }); IntegerResources powerSourceCurrent = new IntegerResources(string.Empty); powerSourceCurrent.Add(new IntegerResource("0") { Value = 3800 }); powerSourceCurrent.Add(new IntegerResource("1") { Value = 5000 }); IntegerResources errorCode = new IntegerResources(string.Empty); errorCode.Add(new IntegerResource("0") { Value = 0 }); deviceResources.Add(new DeviceResource() { Manufacturer = "Open Mobile Alliance", ModelNumber = "Lightweight M2M Client", SerialNumber = "345000123", FirmwareVersion = "1.0", AvailablePowerSources = availablePowerSources, PowerSourceVoltages = powerSourceVoltage, PowerSourceCurrents = powerSourceCurrent, BatteryLevel = 100, MemoryFree = 15, ErrorCodes = errorCode, CurrentTime = DateTime.UtcNow, UTCOffset = "+12:00", SupportedBindingandModes = "U" }); ConnectivityMonitoringResources connectivityMonitoringResources = new ConnectivityMonitoringResources(); IntegerResources availableNetworkBearer = new IntegerResources(string.Empty); availableNetworkBearer.Add(new IntegerResource("0") { Value = 0 }); StringResources ipAddresses = new StringResources(string.Empty); ipAddresses.Add(new StringResource("0") { Value = "192.168.148.18" }); StringResources routerIPAddresse = new StringResources(string.Empty); routerIPAddresse.Add(new StringResource("0") { Value = "192.168.148.1" }); StringResources apn = new StringResources(string.Empty); apn.Add(new StringResource("0") { Value = "internet" }); connectivityMonitoringResources.Add(new ConnectivityMonitoringResource() { NetworkBearer = 0, AvailableNetworkBearers = availableNetworkBearer, RadioSignalStrength = 92, LinkQuality = 2, IPAddresses = ipAddresses, RouterIPAddresses = routerIPAddresse, LinkUtilization = 5, APNs = apn }); this.AddResources(deviceResources); this.AddResources(connectivityMonitoringResources); this.AddResources(new FirmwareUpdateResources()); FlowObjectResources flowObjectResources = new FlowObjectResources(); FlowObjectResource flowObjectResource = new FlowObjectResource() { DeviceType = "EVOKE Flow", TenantID = 1 }; flowObjectResource.Updated += new EventHandler(FlowObject_Updated); flowObjectResources.Add(flowObjectResource); this.AddResources(flowObjectResources); this.AddResources(new FlowAccessResources()); FlowCommandResources flowCommandResources = new FlowCommandResources(); EventHandler <ChildCreatedEventArgs> handler = (s, e) => { FlowCommandResource flowCommandResource = e.Resource as FlowCommandResource; if (flowCommandResource != null) { flowCommandResource.Updated += new EventHandler(FlowCommand_Updated); FlowCommand_Updated(flowCommandResource, null); } }; flowCommandResources.ChildCreated += handler; this.AddResources(flowCommandResources); LocationResources locationResources = new LocationResources(); locationResources.Add(new LocationResource() { Latitude = "-41.0", Longitude = "174.0", Altitude = "150", Uncertainty = "1.0", Velocity = new byte[] { 0, 45, 0, 0 }, Timestamp = DateTime.UtcNow }); this.AddResources(locationResources); DeviceCapabilityResources deviceCapabilityResources = new DeviceCapabilityResources(); deviceCapabilityResources.Add(new DeviceCapabilityResource("0") { Attached = true, Enabled = true, Group = 0, Description = "Temp", Property = "2;3" }); deviceCapabilityResources.Add(new DeviceCapabilityResource("1") { Attached = true, Enabled = true, Group = 1, Description = "Control", Property = "1;2" }); deviceCapabilityResources.Add(new DeviceCapabilityResource("2") { Attached = true, Enabled = false, Group = 2, Description = "Bluetooth", Property = "0" }); deviceCapabilityResources.Add(new DeviceCapabilityResource("3") { Attached = false, Enabled = false, Group = 2, Description = "WiFi", Property = "2" }); this.AddResources(deviceCapabilityResources); }
public override void Execute() { if (Parameters.Count > 1) { if (Parameters[0].StartsWith("/")) { Parameters[0] = Parameters[0].Substring(1); } LWM2MResource resource = _Client.GetResource(Parameters[0]) as LWM2MResource; if (resource == null) { IResource parentResource = _Client.GetParentResource(Parameters[0]); resource = parentResource as LWM2MResource; if (resource == null && parentResource.Parent != null && String.IsNullOrEmpty(parentResource.Parent.Path)) { // object instance does not exist LWM2MResources resources = parentResource as LWM2MResources; string instanceID = Parameters[0].Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)[1]; parentResource = resource = resources.CreateResource(instanceID); resources.ModifiedResource = resource; resources.Changed(); //(parentResource as LWM2MResource).Changed(); resource = null; } if (resource == null) { LWM2MResources resources = parentResource as LWM2MResources; if (resources != null) { string[] paths = Parameters[0].Split('/'); string name = paths[paths.Length - 1]; LWM2MResource childResource = null; BooleanResources booleanResources = resources as BooleanResources; if (booleanResources == null) { DateTimeResources dateTimeResources = resources as DateTimeResources; if (dateTimeResources == null) { FloatResources floatResources = resources as FloatResources; if (floatResources == null) { IntegerResources integerResources = resources as IntegerResources; if (integerResources == null) { OpaqueResources opaqueResources = resources as OpaqueResources; if (opaqueResources == null) { StringResources stringResources = resources as StringResources; if (stringResources == null) { } else { childResource = new StringResource(name); } } else { childResource = new OpaqueResource(name); } } else { childResource = new IntegerResource(name); } } else { childResource = new FloatResource(name); } } else { childResource = new DateTimeResource(name); } } else { childResource = new BooleanResource(name); } if (childResource != null) { childResource.SetValue(Parameters[1]); resources.Add(childResource); } } } else { } } else { resource.SetValue(Parameters[1]); resource.Changed(); LWM2MResource parent = resource.Parent as LWM2MResource; if (parent != null) { parent.Changed(); LWM2MResources grandparent = parent.Parent as LWM2MResources; if (grandparent != null) { grandparent.Changed(); } } } } }