Beispiel #1
0
        public void Serialize(ByteArrayBuilder cmd)
        {
            cmd.AddUInt8((uint)Input);
            cmd.AddUInt8(Category);
            cmd.AddUInt8(Parameter);
            SerializeType(cmd);

            switch (Type)
            {
            case CameraControlDataType.Bool:
            {
                bool[] data = BoolData ?? Array.Empty <bool>();
                cmd.AddUInt16(data.Length);
                cmd.Pad(6);

                SerializePostLength(cmd);
                cmd.PadToNearestMultipleOf8();

                foreach (bool val in data)
                {
                    cmd.AddBoolArray(val);
                }
                cmd.PadToNearestMultipleOf8();

                break;
            }

            case CameraControlDataType.SInt8:
            {
                int[] data = IntData ?? Array.Empty <int>();
                cmd.AddUInt16(data.Length);
                cmd.Pad(6);

                SerializePostLength(cmd);
                cmd.PadToNearestMultipleOf8();

                foreach (int val in data)
                {
                    cmd.AddInt8(val);
                }
                cmd.PadToNearestMultipleOf8();

                break;
            }

            case CameraControlDataType.SInt16:
            {
                int[] data = IntData ?? Array.Empty <int>();
                cmd.Pad(2);
                cmd.AddUInt16(data.Length);
                cmd.Pad(4);

                SerializePostLength(cmd);
                cmd.PadToNearestMultipleOf8();

                foreach (int val in data)
                {
                    cmd.AddInt16(val);
                }
                cmd.PadToNearestMultipleOf8();

                break;
            }

            case CameraControlDataType.SInt32:
            {
                int[] data = IntData ?? Array.Empty <int>();
                cmd.Pad(4);
                cmd.AddUInt16(data.Length);
                cmd.Pad(2);

                SerializePostLength(cmd);
                cmd.PadToNearestMultipleOf8();

                foreach (int val in data)
                {
                    cmd.AddInt32(val);
                }
                cmd.PadToNearestMultipleOf8();

                break;
            }

            case CameraControlDataType.SInt64:
            {
                long[] data = LongData ?? Array.Empty <long>();
                cmd.Pad(6);
                cmd.AddUInt16(data.Length);

                SerializePostLength(cmd);
                cmd.PadToNearestMultipleOf8();

                foreach (long val in data)
                {
                    cmd.AddInt64(val);
                }
                cmd.PadToNearestMultipleOf8();

                break;
            }

            case CameraControlDataType.String:
            {
                string str = StringData ?? string.Empty;
                cmd.AddUInt16(str.Length);
                cmd.Pad(6);

                SerializePostLength(cmd);
                cmd.PadToNearestMultipleOf8();

                cmd.AddString(str);
                cmd.PadToNearestMultipleOf8();
                break;
            }

            case CameraControlDataType.Float:
            {
                double[] data = FloatData ?? Array.Empty <double>();
                cmd.Pad(2);
                cmd.AddUInt16(data.Length);
                cmd.Pad(4);

                SerializePostLength(cmd);
                cmd.PadToNearestMultipleOf8();

                foreach (double val in data)
                {
                    cmd.AddInt16(0x7ff, val);     // TODO
                }
                cmd.PadToNearestMultipleOf8();

                break;
            }

            default:
                throw new ArgumentOutOfRangeException();
            }
        }