public DigitalOutputInstance(ushort ObjectInstanceId, ushort InstanceId, bool?CurrentState, string ApplicationType) : base(ObjectInstanceId, InstanceId) { this.state = new Lwm2mResourceBoolean("Digital Output State", ObjectInstanceId, InstanceId, 5550, true, false, CurrentState); if (ApplicationType != null) { this.applicationType = new Lwm2mResourceString("Application Type", ObjectInstanceId, InstanceId, 5750, true, true, ApplicationType); } this.state.OnRemoteUpdate += (sender, e) => { this.state.TriggerAll(); this.TriggerAll(); try { this.OnRemoteUpdate?.Invoke(this, e); } catch (Exception ex) { Log.Critical(ex); } }; this.Add(this.state); if (this.applicationType != null) { this.Add(this.applicationType); } }
public ActuationInstance(ushort ObjectInstanceId, ushort InstanceId, bool?CurrentState, string ApplicationType) : base(ObjectInstanceId, InstanceId) { this.onOff = new Lwm2mResourceBoolean("On/Off", ObjectInstanceId, InstanceId, 5850, true, false, CurrentState); this.onTime = new Lwm2mResourceInteger("On Time", ObjectInstanceId, InstanceId, 5852, true, false, 0, false); if (ApplicationType != null) { this.applicationType = new Lwm2mResourceString("Application Type", ObjectInstanceId, InstanceId, 5750, true, true, ApplicationType); } this.onOff.OnRemoteUpdate += (sender, e) => { this.onOff.TriggerAll(); this.TriggerAll(); try { this.OnRemoteUpdate?.Invoke(this, e); } catch (Exception ex) { Log.Critical(ex); } }; this.onTime.OnBeforeGet += (sender, e) => { if (this.onOff.BooleanValue.HasValue && this.onOff.BooleanValue.Value) { this.onTime.IntegerValue = (long)((DateTime.Now - this.lastSet).TotalSeconds + 0.5); } else { this.onTime.IntegerValue = 0; } }; this.onTime.OnRemoteUpdate += (sender, e) => { if (this.onTime.IntegerValue.HasValue) { this.lastSet = DateTime.Now.AddSeconds(-this.onTime.IntegerValue.Value); } else { this.lastSet = DateTime.Now; } }; this.Add(this.onOff); this.Add(this.onTime); if (this.applicationType != null) { this.Add(this.applicationType); } }
public DigitalInputInstance(ushort ObjectInstanceId, ushort InstanceId, bool?CurrentState, string ApplicationType, string SensorType) : base(ObjectInstanceId, InstanceId) { this.state = new Lwm2mResourceBoolean("Digital Input State", ObjectInstanceId, InstanceId, 5500, false, false, CurrentState); this.counter = new Lwm2mResourceInteger("Digital Input Counter", ObjectInstanceId, InstanceId, 5501, false, false, 0, false); this.counterReset = new Lwm2mResourceCommand("Digital Input Counter Reset", ObjectInstanceId, InstanceId, 5505); if (ApplicationType != null) { this.applicationType = new Lwm2mResourceString("Application Type", ObjectInstanceId, InstanceId, 5750, true, true, ApplicationType); } if (SensorType != null) { this.sensorType = new Lwm2mResourceString("Sensor Type", ObjectInstanceId, InstanceId, 5751, false, false, SensorType); } this.counterReset.OnExecute += (sender, e) => { this.counter.IntegerValue = 0; this.counter.TriggerAll(); this.TriggerAll(); }; this.Add(this.state); this.Add(this.counter); this.Add(this.counterReset); if (this.applicationType != null) { this.Add(this.applicationType); } if (this.sensorType != null) { this.Add(this.sensorType); } }