Esempio n. 1
0
        public override void HandleMessage(ADMMessage message)
        {
            base.HandleMessage(message);

            if (ADMMessage.IsCommandType(message.CommandID, (byte)ArduinoCommand.CommandType.READ))
            {
                Mode mode = (Mode)ADMMessage.GetCommandIndex(message.CommandID);
                switch (mode)
                {
                case Mode.COUNT:
                    Count    = message.ArgumentAsLong(0);
                    Interval = message.ArgumentAsLong(1);
                    Mgr.Sampler.ProvideSample(this, (double)Count, Interval);

                    message.AddValue(PARAM_COUNT, Count);
                    message.AddValue(PARAM_INTERVAL, Interval);
                    break;

                case Mode.RATE:
                    Rate = message.ArgumentAsFloat(0);
                    Mgr.Sampler.ProvideSample(this, (double)Rate);

                    message.AddValue(PARAM_RATE, Rate);
                    break;
                }
            }
        }
Esempio n. 2
0
        public override void HandleMessage(ADMMessage message)
        {
            base.HandleMessage(message);

            if (message.Type == MessageType.DATA)
            {
                double duration = message.ArgumentAsLong(0); //this is in microseconds
                if (duration > 0)
                {
                    double speedInMicros = Measurement.ConvertUnit(SpeedOfSound, Measurement.Unit.MICROSECOND, Measurement.Unit.SECOND);
                    Distance = 0.5 * Measurement.ConvertUnit(speedInMicros * duration, Measurement.Unit.METER, MeasurementUnit);
                }
                else
                {
                    Distance = 0;
                }

                Sampler?.ProvideSample(this, Distance);

                message.AddValue(PARAM_DISTANCE, Distance);
                message.AddValue(PARAM_UNITS, MeasurementUnit);
            }
        } //end HandleMessage