Exemplo n.º 1
0
 private void OnCharacteristicValueChanged(GattCharacteristic sender, GattValueChangedEventArgs args)
 {
     try
     {
         using (Stream s = args.CharacteristicValue.AsStream())
         {
             using (BinaryReader br = new BinaryReader(s))
             {
                 LineSensorData lsd = CreateLineSensorData(br);
                 DeviceSentDataEvent?.Invoke(this, lsd);
             }
         }
     }
     catch (Exception e)
     {
         this.logger.Error(e, "unexpected exception while receiving data from BLE device");
     }
 }
Exemplo n.º 2
0
        internal static LineSensorData CreateLineSensorData(BinaryReader br)
        {
            LineSensorData lineSensorData = new LineSensorData();

            lineSensorData.SensorValues = new ushort[NUMBER_OF_SENSORS];

            for (int i = 0; i < NUMBER_OF_SENSORS; ++i)
            {
                lineSensorData.SensorValues[i] = br.ReadUInt16();
            }

            lineSensorData.NumberOfCalls         = br.ReadByte();
            lineSensorData.NumberOfFailures      = br.ReadByte();
            lineSensorData.NumberOfCrcErrors     = br.ReadByte();
            lineSensorData.CurrentStatus         = (LineSensorStatus)br.ReadByte();
            lineSensorData.CurrentDetailedStatus = br.ReadUInt32();
            lineSensorData.CumulativeDetailedStatusSinceLastReset = br.ReadUInt32();

            return(lineSensorData);
        }