Beispiel #1
0
        public UnpackedFrame Unpack()
        {
            var i = 0u;
            List <CircuitFrameValue> signals = new List <CircuitFrameValue>();

            while (i < payload.Length)
            {
                UInt32 first_in_segment = payload[i++];
                UInt32 sigs_in_segment  = payload[i++];
                for (var j = 0u; j < sigs_in_segment; j++)
                {
                    var value = (Int32)payload[i + j];
                    if (value != 0)
                    {
                        var mapped = map.ByID(first_in_segment + j);
                        signals.Add(
                            new CircuitFrameValue
                        {
                            type  = mapped.type,
                            name  = mapped.name,
                            count = value
                        });
                    }
                }
                i += sigs_in_segment;
            }

            return(new UnpackedFrame(dstid, srcid, signals));
        }
Beispiel #2
0
        public PackedFrame PackWithZeros(SignalMap map)
        {
            var count = this.signals.Max(cfv => map.BySignal(cfv.type, cfv.name));
            var pf    = new PackedFrame(dstid, srcid, new VarInt[count + 2], map);

            pf.payload[0] = 1;
            pf.payload[1] = count;
            for (var i = 2u; i < pf.payload.Length; i++)
            {
                var mapping = map.ByID(i - 1);
                pf.payload[i] = signals.FirstOrDefault(s => s.type == mapping.type && s.name == mapping.name).count;
            }
            return(pf);
        }