예제 #1
0
            public DefaultSensorModel(Sensor sensor)
            {
                type        = sensor.type.ToString();
                isRelative  = sensor.isRelative;
                isEditable  = sensor.isEditable;
                name        = sensor.name;
                unit        = UnitLookup.GetCode(sensor.unit);
                measurement = sensor.measurement.amount;

                if (sensor.minMeasurement != null)
                {
                    var min = sensor.minMeasurement;
                    hasMinMeasurement = true;
                    minUnit           = UnitLookup.GetCode(min.unit);
                    minMeasurement    = min.amount;
                }

                if (sensor.maxMeasurement != null)
                {
                    var max = sensor.maxMeasurement;
                    hasMaxMeasurement = true;
                    maxUnit           = UnitLookup.GetCode(max.unit);
                    maxMeasurement    = max.amount;
                }
            }
            public BoundedHandler(SensorAlarmActivity activity, IION ion, BoundedSensorAlarm alarm, View view)
            {
                this.activity = activity;
                this.alarm    = alarm;

                toggle      = view.FindViewById <Switch>(Resource.Id.toggle);
                measurement = view.FindViewById <EditText>(Resource.Id.measurement);
                unit        = view.FindViewById <Button>(Resource.Id.unit);

                toggle.SetOnCheckedChangeListener(new ViewCheckChangedAction((but, check) => {
                    alarm.Reset();
                }));
                unit.SetOnClickListener(new ViewClickAction((v) => {
                    UnitDialog.Create(activity, alarm.sensor.supportedUnits, (obj, u) => {
                        var dialog = obj as Android.App.Dialog;

                        if (dialog != null)
                        {
                            dialog.Dismiss();
                        }

                        unit.Text = u.ToString();
                        unitCode  = UnitLookup.GetCode(u);
                    }).Show();
                }));

                toggle.Checked   = alarm.enabled;
                measurement.Text = alarm.bounds.amount + "";
                unit.Text        = alarm.bounds.unit.ToString();
                unitCode         = UnitLookup.GetCode(alarm.bounds.unit);
            }
        /// <summary>
        /// Creates a packet that, when received by a remote terminus, will set the
        /// altitude that is retained within the terminus' memory.
        /// </summary>
        /// <param name="altitude">A scalar whose base unit is METER.</param>
        /// <returns></returns>
        public override byte[] CreateSetAltitudeCommand(Scalar altitude)
        {
            var v   = (int)altitude.amount;
            var msb = (byte)((v >> 8) & 0xff);
            var lsb = (byte)(v & 0xff);

            return(new byte[] { 0x04, msb, lsb, (byte)UnitLookup.GetCode(altitude.unit) });
        }
예제 #4
0
 public ManualSensorParcelable(ManualSensor sensor)
 {
     sensorType = sensor.type;
     isRelative = sensor.isRelative;
     unitCode   = UnitLookup.GetCode(sensor.unit);
     amount     = sensor.measurement.amount;
     name       = sensor.name;
 }
예제 #5
0
 // Implemented for ISubviewParser
 public bool Write(ISensorProperty sp, BinaryWriter writer)
 {
     try {
         var alt = (AlternateUnitSensorProperty)sp;
         writer.Write(UnitLookup.GetCode(alt.unit));
         return(true);
     } catch (Exception e) {
         Log.E(this, "Failed to write.", e);
         return(false);
     }
 }
예제 #6
0
        private void WriteSensorProperty(ISensorProperty property, BinaryWriter writer)
        {
            var name = property.GetType();

            writer.Write(name.Name);

            if (property is AlternateUnitSensorProperty)
            {
                var sp = property as AlternateUnitSensorProperty;
                writer.Write(UnitLookup.GetCode(sp.unit));
            }
        }
예제 #7
0
        /// <summary>
        /// Safely attempts to set the unit for the given key.
        /// </summary>
        /// <returns>The unit set.</returns>
        private void AssertUnitSet(string preferenceKey, Quantity quantity, Unit unit)
        {
            try {
                if (quantity != unit.quantity)
                {
                    throw new ArgumentException("Unit: " + unit + " is not compatible with quantity + " + quantity);
                }

                PutInt(preferenceKey, UnitLookup.GetCode(unit));
            } catch (Exception e) {
                Log.E(this, "Failed to set unit " + unit + " for key: " + preferenceKey, e);
            }
        }
예제 #8
0
        public RemoteSensorMount(Analyzer analyzer, Sensor sensor)
        {
            var gds = sensor as GaugeDeviceSensor;

            if (gds == null)
            {
                throw new Exception("Cannot create sensor mount for {" + sensor + "}: sensor must not be null");
            }
            else if (!analyzer.HasSensor(sensor))
            {
                throw new Exception("Cannot create sensor mount for {" + sensor + "}: sensor must be in analyzer");
            }

            serialNumber  = gds.device.serialNumber.ToString();
            sensorIndex   = gds.index + "";
            analyzerIndex = analyzer.IndexOfSensor(sensor) + "";
            value         = sensor.measurement.amount + "";
            unit          = UnitLookup.GetCode(sensor.unit) + "";
        }
예제 #9
0
        /// <summary>
        /// Safely attempts to set the unit for the given key.
        /// </summary>
        /// <returns>The unit set.</returns>
        private void AssertUnitSet(int preferenceKey, Quantity quantity, Unit unit)
        {
            var key = context.GetString(preferenceKey);

            try {
                if (quantity != unit.quantity)
                {
                    throw new ArgumentException("Unit: " + unit + " is not compatible with quantity + " + quantity);
                }

                var e = prefs.Edit();

                e.PutString(key, UnitLookup.GetCode(unit) + "");

                e.Commit();
            } catch (Exception e) {
                Log.E(this, "Failed to set unit " + unit + " for key: " + key, e);
            }
        }
            private void WriteManualSensor(Sensor sensor, BinaryWriter writer)
            {
                // Write actual sensor type
                writer.Write((int)sensor.type);
                // Write whether or not the sensor is relative
                writer.Write(sensor.isRelative);
                // Write the unit code of the sensor
                writer.Write((byte)UnitLookup.GetCode(sensor.measurement.unit));
                // Write the double amount of the sensor
                writer.Write(sensor.measurement.amount);
                // Write the minimum measurement of the sensor
                if (sensor.minMeasurement.unit == null)
                {
                    writer.Write((byte)0);
                }
                else
                {
                    writer.Write((byte)UnitLookup.GetCode(sensor.minMeasurement.unit));
                    writer.Write(sensor.minMeasurement.amount);
                }
                // Write the maximum measurement of the sensor
                if (sensor.maxMeasurement.unit == null)
                {
                    writer.Write((byte)0);
                }
                else
                {
                    writer.Write((byte)UnitLookup.GetCode(sensor.maxMeasurement.unit));
                    writer.Write(sensor.maxMeasurement.amount);
                }

                if (string.IsNullOrEmpty(sensor.name))
                {
                    sensor.name = "Manual";
                    writer.Write(sensor.name);
                }
                else
                {
                    writer.Write(sensor.name);
                }
            }
        /// <summary>
        /// Creates a packet that, when received by a remote terminus, will set the unit
        /// for a given sensor.
        /// </summary>
        /// <param name="sensorIndex">The 1-based index of the sensor to set the unit for.</param>
        /// <param name="sensorType">The sensor type. This is necessary to deduce the proper
        /// unit code for the packet.</param>
        /// <param name="unit">The unit that the terminus will be set to.</param>
        /// <returns></returns>
        // Overridden from IGaugeProtocol
        public override byte[] CreateSetUnitCommand(int sensorIndex, Sensors.ESensorType sensorType, Unit unit)
        {
            var ret = new byte[] { 0x02, (byte)UnitLookup.GetCode(unit), (byte)sensorIndex };

            return(ret);
        }
예제 #12
0
 public RemoteGaugeDeviceSensor(GaugeDeviceSensor sensor)
 {
     measurement = sensor.measurement.amount;
     unit        = UnitLookup.GetCode(sensor.unit);
     sensorIndex = sensor.index;
 }