/// <summary>
 /// 检测数据
 /// </summary>
 /// <returns></returns>
 private bool CheckData()
 {
     try
     {
         var item = mReciveQuene.Dequeue();
         if (item.ASDU.InformationObject[2] != 2) //是否为文件传输包
         {
             return(false);
         }
         if (item.ASDU.InformationObject[3] != 2) //是否为目录召唤确认
         {
             return(false);
         }
         var packet = new FileNr.FileDirectoryCalledAckPacket(item.PacketData, 0, (byte)item.PacketData.Length);
         if (packet.DirectoryID == callPacket.DirectoryID)
         {
             readFileDicrectoryAckPacket = item;
             ackPacket = packet;
             return(true);
         }
         return(false);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemple #2
0
 /// <summary>
 /// 文件服务时间
 /// </summary>
 /// <param name="message">文件消息</param>
 /// <param name="operation">操作标识</param>
 /// <param name="packet">数据包</param>
 /// <param name="additionalPacket">附加数据包</param>
 public FileServerEventArgs(string message, FileNr.OperatSign operation, FilePacket packet, T additionalPacket)
 {
     Message          = message;
     Operation        = operation;
     Packet           = packet;
     AdditionalPacket = additionalPacket;
 }
Exemple #3
0
 /// <summary>
 /// 信息入队
 /// </summary>
 /// <param name="packet">文件数据包</param>
 public void Enqueue(FilePacket packet)
 {
     lock (RecivePacketQuene)
     {
         RecivePacketQuene.Enqueue(packet);
     }
 }
Exemple #4
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);
        }
Exemple #5
0
        /// <summary>
        /// 时间内完成调用
        /// </summary>
        /// <returns>true--结束本次传输</returns>
        private bool AckOnTime()
        {
            switch (stage)
            {
            case TransmitStage.Activity:
            {
                if (ReadFileActivityAckEvent != null)
                {
                    var e = new FileServerEventArgs <FileNr.FileReadActivityAckPacket>("从机应答", FileNr.OperatSign.ReadFileActivityACK,
                                                                                       readFileActivityAckPacket, ackPacket);
                    ReadFileActivityAckEvent(Thread.CurrentThread, e);
                }
                mRepeatCount = 0;
                stage        = TransmitStage.Transmission;
                return(false);
            }

            case TransmitStage.Transmission:
            {
                var result = packetManager.AddPacketData(transmitPacket);
                if (result == FileNr.FileTransmitDescription.Success)
                {
                    var addPacket = new FileNr.FileReadThransmitAckPacket(packetManager.Attribute.ID,
                                                                          packetManager.CurrentPacket.FragmentNum, packetManager.CurrentPacket.Fllow);
                    readFileTransmitAckPacket = new FilePacket(0, 0, CauseOfTransmissionList.ActivationACK,
                                                               0, addPacket.GetPacketData());
                }
                else
                {
                    if (ReadFileTransmitAckEvent != null)
                    {
                        var e = new FileServerEventArgs <FileNr.FileReadThransmitAckPacket>("从机应答:" + result.ToString(), FileNr.OperatSign.ReadFileDataResponseACK,
                                                                                            readFileActivityAckPacket, null);
                        ReadFileTransmitAckEvent(Thread.CurrentThread, e);
                    }
                }
                mRepeatCount = 0;
                return(false);
            }
            }



            return(true);
        }
Exemple #6
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;
            }
        }
Exemple #7
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] != 8)        //是否为读文件激活确认
                    {
                        Console.WriteLine("不是写文件激活确认");
                        return(false);
                    }
                    var packet = new FileNr.FileWriteActivityAckPacket(item.PacketData, 0, (byte)item.PacketData.Length);
                    if (packet.Name != packetManager.Attribute.Name)
                    {
                        Console.WriteLine("名称不一致");
                        return(false);
                    }
                    if (packet.FileID != packetManager.Attribute.ID)
                    {
                        Console.WriteLine("ID不一致");
                        return(false);
                    }
                    writeFileActivityAckPacket = item;
                    ackPacket = packet;
                    return(true);
                }

                case TransmitStage.Transmission:
                {
                    if (item.ASDU.InformationObject[3] != 10)        //是否写文件传输确认
                    {
                        Console.WriteLine("不是写文件传输确认");
                        return(false);
                    }
                    var packet = new FileNr.FileWriteThransmitAckPacket(item.PacketData, 0);
                    if (packet.Result == FileNr.FileTransmitDescription.Success)
                    {
                        writeFileTransmitAckPacket = item;
                        transmitAckPacket          = packet;
                        return(true);
                    }
                    else
                    {
                        Console.WriteLine("ID不一致");
                        if (WriteFileTransmitAckEvent != null)
                        {
                            var e = new FileServerEventArgs <FileNr.FileWriteThransmitAckPacket>("从机应答:" + packet.Result.ToString(), FileNr.OperatSign.WriteFileThransmitAck
                                                                                                 , writeFileActivityAckPacket, null);
                            WriteFileTransmitAckEvent(Thread.CurrentThread, e);
                        }
                        return(false);
                    }
                }
                }

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