예제 #1
0
        /// <summary>
        /// 时间内完成调用
        /// </summary>
        /// <returns>true--结束本次传输</returns>
        private bool AckOnTime()
        {
            switch (stage)
            {
            case TransmitStage.Activity:
            {
                if (WriteFileActivityAckEvent != null)
                {
                    var e = new FileServerEventArgs <FileNr.FileWriteActivityAckPacket>("从机应答", FileNr.OperatSign.WriteFileActivityAck,
                                                                                        writeFileActivityAckPacket, ackPacket);
                    WriteFileActivityAckEvent(Thread.CurrentThread, e);
                }
                mRepeatCount = 0;
                stage        = TransmitStage.Transmission;

                transmitPacket          = packetManager.PacketCollect[ackCount];
                writeFileTransmitPacket = new FileWritePacket(0, 0, CauseOfTransmissionList.ActivationACK,
                                                              0, transmitPacket);



                return(false);
            }

            case TransmitStage.Transmission:
            {
                bool state = false;
                FileNr.FileTransmitDescription result = FileNr.FileTransmitDescription.UnknowError;
                //先检测确认包
                if ((transmitAckPacket.FragmentNum == packetManager.PacketCollect[ackCount].FragmentNum) &&
                    (transmitAckPacket.Result == FileNr.FileTransmitDescription.Success))
                {
                    result = FileNr.FileTransmitDescription.Success;
                    if (++ackCount < packetManager.PacketCollect.Count)
                    {
                        transmitPacket          = packetManager.PacketCollect[ackCount];
                        writeFileTransmitPacket = new FileWritePacket(0, 0, CauseOfTransmissionList.ActivationACK,
                                                                      0, transmitPacket);
                    }
                    else
                    {
                        state = true;
                    }
                    mRepeatCount = 0;
                }
                if (WriteFileTransmitAckEvent != null)
                {
                    var e = new FileServerEventArgs <FileNr.FileWriteThransmitAckPacket>("从机应答:" + result.ToString(), FileNr.OperatSign.WriteFileThransmitAck
                                                                                         , writeFileActivityAckPacket, null);
                    WriteFileTransmitAckEvent(Thread.CurrentThread, e);
                }
                return(state);
            }
            }



            return(true);
        }
예제 #2
0
        /// <summary>
        /// 检测数据
        /// </summary>
        /// <returns></returns>
        private bool CheckData()
        {
            try
            {
                var item = mReciveQuene.Dequeue();
                if (item.ASDU.InformationObject[2] != 2)//是否为文件传输包
                {
                    Console.WriteLine("不是文件传输包");
                    return(false);
                }

                switch (stage)
                {
                case TransmitStage.Activity:
                {
                    if (item.ASDU.InformationObject[3] != 4)        //是否为读文件激活确认
                    {
                        Console.WriteLine("不是读文件激活确认");
                        return(false);
                    }
                    var packet = new FileNr.FileReadActivityAckPacket(item.PacketData, 0, (byte)item.PacketData.Length);
                    if (packet.Name == packetManager.Attribute.Name)
                    {
                        readFileActivityAckPacket = item;
                        ackPacket = packet;

                        return(true);
                    }
                    else
                    {
                        Console.WriteLine("名称不一致");
                        return(false);
                    }
                }

                case TransmitStage.Transmission:
                {
                    if (item.ASDU.InformationObject[3] != 5)        //是否为读文件传输
                    {
                        Console.WriteLine("不是读文件传输");
                        return(false);
                    }
                    var packet = new FileNr.FileDataThransmitPacket(item.PacketData, 0, (byte)item.PacketData.Length);
                    if (packet.FileID == packetManager.Attribute.ID)
                    {
                        readFileTransmitPacket = item;
                        transmitPacket         = packet;
                        return(true);
                    }
                    else
                    {
                        Console.WriteLine("ID不一致");
                        return(false);
                    }
                }
                }

                return(false);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }