Пример #1
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);
        }
Пример #2
0
        public PackedFrame Pack(SignalMap map)
        {
            var                  sigs             = signals.Select(s => new { signal = s, id = map.BySignal(s.type, s.name) }).Where(s => s.id != 0).OrderBy(s => s.id).ToArray();
            VarInt               lastid           = UInt32.MaxValue;
            VarInt               first_in_segment = UInt32.MaxValue;
            VarInt               sigs_in_segment  = 0u;
            List <VarInt>        segment_data     = new List <VarInt>();
            IEnumerable <VarInt> payload_data     = Enumerable.Empty <VarInt>();

            foreach (var item in sigs)
            {
                if (item.id == lastid + 1)
                {
                    // just add the value and increment both counters
                    sigs_in_segment++;
                    segment_data.Add(item.signal.count);
                }
                else
                {
                    if (lastid != UInt32.MaxValue)
                    {
                        // write out first in segment, count, data[]
                        payload_data = payload_data.Concat(new[] { first_in_segment, sigs_in_segment }).Concat(segment_data);
                    }
                    // reset counters...
                    first_in_segment = item.id;
                    sigs_in_segment  = 1;
                    segment_data     = new List <VarInt>();
                    segment_data.Add(item.signal.count);
                }
                lastid = item.id;
            }

            //last segment...
            payload_data = payload_data.Concat(new[] { first_in_segment, sigs_in_segment }).Concat(segment_data);


            return(new PackedFrame(dstid, srcid, payload_data.ToArray(), map));
        }