Example #1
0
 public CsacServiceValueChangedEventArgs(CsacMeasurement value)
 {
     this.Measurement = value;
 }
Example #2
0
        private CsacMeasurement createCsacMeasurement(byte[] data, DateTimeOffset timestamp)
        {
            var measurement = new CsacMeasurement();

            measurement.Timestamp = timestamp;

            var flags = (CsacMeasurementFlags)Enum.ToObject(typeof(CsacMeasurementFlags), data[0]);

            var offset = 1;

            // Wheel revolutions...
            if (flags.HasFlag(CsacMeasurementFlags.WheelRevolutionDataPresent))
            {
                // Cumulative wheel revolutions - 4 bytes littleendian
                var cumWRBytes = data.Skip(offset).Take(4).ToArray();
                if (!BitConverter.IsLittleEndian)
                {
                    cumWRBytes.Reverse();
                }

                measurement.CumulativeWheelRevolutions = BitConverter.ToUInt32(cumWRBytes, 0);

                offset += 4;

                // LastWheelEventTime - 2 bytes little-endian
                var lastWheelBytes = data.Skip(offset).Take(2).ToArray();
                if (!BitConverter.IsLittleEndian)
                {
                    lastWheelBytes.Reverse();
                }

                measurement.LastWheelEventTime = BitConverter.ToUInt16(lastWheelBytes, 0);
                offset += 2;
            }

            // Crank revolutions...
            if (flags.HasFlag(CsacMeasurementFlags.CrankRevolutionDataPresent))
            {
                // Cumulative crank revolutions - 4 bytes littleendian
                var cumCRBytes = data.Skip(offset).Take(2).ToArray();
                if (!BitConverter.IsLittleEndian)
                {
                    cumCRBytes.Reverse();
                }

                measurement.CumulativeCrankRevolutions = BitConverter.ToUInt16(cumCRBytes, 0);

                offset += 2;

                // LastWheelEventTime - 2 bytes little-endian
                var lastCrankBytes = data.Skip(offset).Take(2).ToArray();
                if (!BitConverter.IsLittleEndian)
                {
                    lastCrankBytes.Reverse();
                }

                measurement.LastCrankEventTime = BitConverter.ToUInt16(lastCrankBytes, 0);
            }

            return(measurement);
        }