Beispiel #1
0
        public static string ParseBuffer(IBuffer buffer)
        {
            var reader = DataReader.FromBuffer(buffer);
            var result = reader.ReadByte();

            return(BasicParsers.FlagsSetInByte(typeof(Status), result));
        }
Beispiel #2
0
        public void ShouldFailToParseInvalidString()
        {
            var regexParser = BasicParsers.GetRegexParser(new Regex("[a-z]+"));
            var result      = regexParser.Parse("234345") as Error <string>;

            Assert.AreEqual("Expected match on '[a-z]+', got '234345'.", result?.Message);
        }
Beispiel #3
0
        public void ShouldReturnCorrectRestToParse2()
        {
            var stringParser = BasicParsers.GetRegexParser(new Regex("[a-z]+"));
            var result       = stringParser.Parse("whatever man");

            Assert.AreEqual(" man", result.Rest);
        }
Beispiel #4
0
        public void ShouldParseRegularExpression()
        {
            var regexParser = BasicParsers.GetRegexParser(new Regex("[a-z]+"));
            var result      = regexParser.Parse("whatever multipe words");

            Assert.AreEqual("whatever", result.Output);
        }
Beispiel #5
0
        public void ShouldReturnCorrectRestToParse()
        {
            var stringParser = BasicParsers.GetStringParser("whatever");
            var result       = stringParser.Parse("whatever man");

            Assert.AreEqual(" man", result.Rest);
        }
Beispiel #6
0
        public void ShouldFailToParseDifferentString()
        {
            var stringParser = BasicParsers.GetStringParser("whatever");
            var result       = stringParser.Parse("hatever") as Error <string>;

            Assert.AreEqual("Expected \"whatever\", got \"hatever\".", result?.Message);
        }
Beispiel #7
0
        public void ShouldParseSameString()
        {
            var stringParser = BasicParsers.GetStringParser("whatever");
            var result       = stringParser.Parse("whatever");

            Assert.AreNotEqual(typeof(Error <string>), result);
        }
        public async Task ReadUTF8Value()
        {
            try
            {
                if ((_characteristic.CharacteristicProperties & GattCharacteristicProperties.Read) != 0)
                {
                    // Determine if we want to read the actual or cached values
                    var cacheMode = BluetoothCacheMode.Cached;
                    if (!GlobalSettings.UseCachedMode && ServiceM.DeviceM.Connected)
                    {
                        cacheMode = BluetoothCacheMode.Uncached;
                    }

                    // Get some basic device info.
                    var readResult = await _characteristic.ReadValueAsync(cacheMode);

                    var gattStatus = readResult.Status;
                    if (gattStatus == GattCommunicationStatus.Success)
                    {
                        CharacteristicValue = BasicParsers.ParseUtf8(readResult.Value);
                    }
                }
            }
            catch (Exception e)
            {
                // Utilities.OnExceptionWithMessage(e, "Failed to read characteristic value");
                Debug.WriteLine("Failed to read characteristic value {0}", e.Message);
            }
        }
        public static string ParseBuffer(IBuffer buffer)
        {
            string result = "";

            DataReader reader  = DataReader.FromBuffer(buffer);
            byte       current = reader.ReadByte();

            result += BasicParsers.FlagsSetInByte(typeof(CategoryIdBitMask0), current);
            if (reader.UnconsumedBufferLength > 0)
            {
                current = reader.ReadByte();
                result += BasicParsers.FlagsSetInByte(typeof(CategoryIdBitMask1), current);
            }
            return(result);
        }