예제 #1
0
        /// <summary>
        /// 生成可发送命令(按时间排序)
        /// </summary>
        private void CreatePacketesToSend()
        {
            var packet = new List <byte>();
            IMakeDataTransportPacket createbigDataTransportPacket     = ProtocolFactory.CreateDataTransportPacket(TransportDataType.BigData);
            IMakeDataTransportPacket createGeneralDataTransportPacket =
                ProtocolFactory.CreateDataTransportPacket(TransportDataType.General);
            var datumList = new List <Data>();

            while (datasTobesent.Count > 0)
            {
                Data data;
                if (datasTobesent.TryDequeue(out data))
                {
                    if (data != null)
                    {
                        datumList.Add(data);
                    }
                }
            }

            var sortedList = datumList.OrderBy(i => i.CollectTime).ToList();

            var N = sortedList.Count;

            for (var i = 0; i < N; i++)
            {
                var data        = sortedList[i];
                int structureId = GetStructureId(data);
                if (data.SafeTypeId == (int)SensorCategory.Vibration)
                {
                    byte[][] packeBytes = createbigDataTransportPacket.MakeDataTransportPacket(data, structureId);
                    foreach (byte[] packeByte in packeBytes)
                    {
                        this.packetsToSend.Enqueue(packeByte);
                        //  this.packetsToSend.Enqueue(null);
                    }
                }
                else
                {
                    var packeBytes = createGeneralDataTransportPacket.MakeDataTransportPacket(data, structureId);
                    if (packet.Count + packeBytes[0].Length < 1024)
                    {
                        packet.AddRange(packeBytes[0]);
                        if (i == N - 1)
                        {
                            this.packetsToSend.Enqueue(packet.ToArray());
                            packet.Clear();
                        }
                    }
                    else
                    {
                        this.packetsToSend.Enqueue(packet.ToArray());
                        packet.Clear();
                        packet.AddRange(packeBytes[0]);
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// 生成可发送命令(旧)
        /// </summary>
        private void CreatePacketesToSendNoOrder()
        {
            List <byte> packet = new List <byte>();
            IMakeDataTransportPacket createbigDataTransportPacket     = ProtocolFactory.CreateDataTransportPacket(TransportDataType.BigData);
            IMakeDataTransportPacket createGeneralDataTransportPacket =
                ProtocolFactory.CreateDataTransportPacket(TransportDataType.General);

            while (datasTobesent.Count > 0)
            {
                Data data;
                if (datasTobesent.TryDequeue(out data))
                {
                    if (data != null)
                    {
                        int structureId = GetStructureId(data);
                        if (data.SafeTypeId == (int)SensorCategory.Vibration)
                        {
                            byte[][] packeBytes = createbigDataTransportPacket.MakeDataTransportPacket(data, structureId);
                            foreach (byte[] packeByte in packeBytes)
                            {
                                this.packetsToSend.Enqueue(packeByte);
                                //  this.packetsToSend.Enqueue(null);
                            }
                        }
                        else
                        {
                            byte[][] packeBytes = createGeneralDataTransportPacket.MakeDataTransportPacket(data, structureId);

                            if (IsPacketed(ref packet, packeBytes[0]))
                            {
                                datasTobesent.Enqueue(data);
                                this.packetsToSend.Enqueue(packet.ToArray());
                                //  this.packetsToSend.Enqueue(null);
                                packet.Clear();
                            }
                            else if (datasTobesent.Count <= 0)
                            {
                                this.packetsToSend.Enqueue(packet.ToArray());
                                // this.packetsToSend.Enqueue(null);
                                packet.Clear();
                            }
                        }
                    }
                }
            }
        }