Example #1
0
 private void ReadNull(ref JReader r, ValueVariant variant)
 {
     if (variant == NullableBoolIsNull)
     {
         RequireNull(r.BoolOrNull());
     }
     else if (variant == NullableIntIsNull)
     {
         RequireNull(r.IntOrNull());
     }
     else if (variant == NullableLongIsNull)
     {
         RequireNull(r.LongOrNull());
     }
     else if (variant == NullableDoubleIsNull)
     {
         RequireNull(r.DoubleOrNull());
     }
     else if (variant == NullableStringIsNull)
     {
         Assert.True(r.StringOrNull() == null, "expected null");
     }
     else if (variant == NullableArrayIsNull)
     {
         Assert.False(r.ArrayOrNull().IsDefined, "expected null");
     }
     else if (variant == NullableObjectIsNull)
     {
         Assert.False(r.ObjectOrNull().IsDefined, "expected null");
     }
     else
     {
         r.Null();
     }
 }
            public WriterAction Value(TestValue <WriterAction> value, ValueVariant variant)
            {
                return(w =>
                {
                    switch (value.Type)
                    {
                    case ValueType.Bool:
                        w.Bool(value.BoolValue);
                        break;

                    case ValueType.Number:
                        if (variant == NumberAsLong)
                        {
                            w.Long((long)value.NumberValue);
                        }
                        else if (variant == NumberAsInt)
                        {
                            w.Int((int)value.NumberValue);
                        }
                        else
                        {
                            w.Double(value.NumberValue);
                        }
                        break;

                    case ValueType.String:
                        w.String(value.StringValue);
                        break;

                    case ValueType.Array:
                        using (var arr = w.Array())
                        {
                            foreach (var e in value.ArrayValue)
                            {
                                e(w);
                            }
                        }
                        break;

                    case ValueType.Object:
                        using (var obj = w.Object())
                        {
                            foreach (var p in value.ObjectValue)
                            {
                                var valueWriter = obj.Name(p.Name);
                                foreach (var action in p.Actions)
                                {
                                    action(w);
                                }
                            }
                        }
                        break;

                    default:
                        w.Null();
                        break;
                    }
                });
            }
        internal override void InterpretResult(bool reverseByteOrder, IEECmdConverters cmdConv, IEECommandParameter cmdParams)
        {
            // ACK received...
            if (Data.Length < 4)
            {
                Code = EECmdResultCode.InvalidResult;
                return;
            }

            DpIdx     = Data[1];
            Variant   = (ValueVariant)Data[2];
            Precision = Data[3];
            Name      = StringHelper.ExtractStringContent(Data, 4, -1);
        }
Example #4
0
        internal override void InterpretResult(bool reverseByteOrder, IEECmdConverters cmdConv, IEECommandParameter cmdParams)
        {
            // ACK received...
            if (Data.Length < 6)
            {
                Code = EECmdResultCode.InvalidResult;
                return;
            }

            DpIdx       = Data[1];
            Variant     = (ValueVariant)Data[2];
            DataType    = Data[3];
            ScaleFactor = DataTypeConverter.ByteConverter.ToUInt16(Data, 4, reverseByteOrder);
        }
Example #5
0
 public SetModbusSlaveConfigCmdParams(byte modbusAddrOffset, byte dpIdx, ValueVariant dataVariant, byte dataType, ushort scaleFactor) :
     base(0x0)
 {
     //... set bytes
 }
Example #6
0
            public ReaderAction Value(TestValue <ReaderAction> value, ValueVariant variant)
            {
                return((ref JReader r) =>
                {
                    if (variant == SkipValue)
                    {
                        r.SkipValue();
                        return;
                    }
                    if (variant == AnyValue)
                    {
                        ReadAnyValue(ref r, value);
                        return;
                    }

                    switch (value.Type)
                    {
                    case ValueType.Bool:
                        var bVal = variant == NullableValue?
                                   RequireNonNull(r.BoolOrNull()) : r.Bool();

                        Assert.Equal(value.BoolValue, bVal);
                        break;

                    case ValueType.Number:
                        if (variant == NumberAsInt || variant == NullableNumberAsInt)
                        {
                            var nVal = variant == NullableValue?
                                       RequireNonNull(r.IntOrNull()) : r.Int();

                            Assert.Equal((int)value.NumberValue, nVal);
                        }
                        else if (variant == NumberAsLong || variant == NullableNumberAsLong)
                        {
                            var nVal = variant == NullableValue?
                                       RequireNonNull(r.LongOrNull()) : r.Long();

                            Assert.Equal((long)value.NumberValue, nVal);
                        }
                        else
                        {
                            var nVal = variant == NullableValue?
                                       RequireNonNull(r.DoubleOrNull()) : r.Double();

                            Assert.Equal(value.NumberValue, nVal);
                        }
                        break;

                    case ValueType.String:
                        var sVal = variant == NullableValue?r.StringOrNull() : r.String();

                        Assert.False(sVal == null, "expected non-null");
                        Assert.Equal(value.StringValue, sVal);
                        break;

                    case ValueType.Array:
                        ReadArray(ref r, variant == NullableValue ? r.ArrayOrNull() : r.Array(), value);
                        break;

                    case ValueType.Object:
                        ReadObject(ref r, variant == NullableValue ? r.ObjectOrNull() : r.Object(), value);
                        break;

                    default:
                        ReadNull(ref r, variant);
                        break;
                    }
                });
            }
Example #7
0
 public SetDisplayWindowSlotConfigCmdParams(byte slotNr, byte dpIdx, ValueVariant variant, byte precision, string dpName) :
     base(0x0)
 {
     //... set bytes
 }