Exemplo n.º 1
0
        private readonly int correctstrategy_timespan = 100; //10 毫秒

        private DotManager()
        {
            correctitems = new List <CorrectItem>();

            PhyCombine.GetPhyCombine().onPacketReceived(DataFormater.getDataFormater().PacketReceviedHdlr);

            DataFormater.getDataFormater().onPacketCheckError(PacketCheckErrorHdlr);
            DataFormater.getDataFormater().onPacketCorrected(PacketCorrectedHdlr);
            DataFormater.getDataFormater().onPacketRecevied(PacketReceviedHdlr);

            PhyCombine.GetPhyCombine().onCombineError(CombineErrorHdlr);
        }
Exemplo n.º 2
0
 //获取一个dot,结果使用事件通知
 public void GetDot(byte[] raw)
 {
     PhyCombine.GetPhyCombine().CombineFragment(raw);
 }
Exemplo n.º 3
0
 //清空Dots,rawText所有数据
 public void ReleaseData()
 {
     DataFormater.getDataFormater().GetDots().Clear();
     PhyCombine.GetPhyCombine().Clear();
 }
Exemplo n.º 4
0
 public void DumpRawText(string filename)
 {
     PhyCombine.GetPhyCombine().Dump(filename);
 }
Exemplo n.º 5
0
        //处理PhyCombine.PacketRecevied_Ev的函数, packet是一个纯包
        public void PacketReceviedHdlr(byte[] packet, PacketType ptype)
        {
            switch (ptype)
            {
            case PacketType.CORRECT_RESPONSE:
                if (validateData(packet, PhyCombine.GetPhyCombine().GetMachineInfo().CrtPctDStart
                                 , PhyCombine.GetPhyCombine().GetMachineInfo().DataWidth,
                                 twoint(packet, PhyCombine.GetPhyCombine().GetMachineInfo().CrtPctVStart)) == true)
                {
                    int seq = Utility.ConvertStrToInt_Big(packet,
                                                          PhyCombine.GetPhyCombine().GetMachineInfo().CrtPctSStart,
                                                          PhyCombine.GetPhyCombine().GetMachineInfo().SequenceLength);
                    if (seq > (dots.Count - 1))
                    {
                        Console.WriteLine("CORRECT_RESPONSE Error: 纠正序号越界");
                        return;
                    }
                    dots[seq].Rvalue = Utility.ConvertStrToInt_Big(packet,
                                                                   PhyCombine.GetPhyCombine().GetMachineInfo().CrtPctDStart,
                                                                   PhyCombine.GetPhyCombine().GetMachineInfo().DataWidth);

                    dots[seq].Status = DotStaus.CORRECTED;
                    if (PacketCorrected_Ev != null)
                    {
                        PacketCorrected_Ev(dots[seq], seq);
                    }
                    return;
                }
                else
                {
                    if (PacketStillError_Ev != null)
                    {
                        PacketStillError_Ev(Utility.ConvertStrToInt_Big(packet,
                                                                        PhyCombine.GetPhyCombine().GetMachineInfo().CrtPctSStart,
                                                                        PhyCombine.GetPhyCombine().GetMachineInfo().SequenceLength));
                    }
                }
                break;

            case PacketType.DATA_VALUE:
                if (validateData(packet, PhyCombine.GetPhyCombine().GetMachineInfo().DataPctDStart,
                                 PhyCombine.GetPhyCombine().GetMachineInfo().DataWidth, twoint(packet, PhyCombine.GetPhyCombine().GetMachineInfo().DataPctVStart)) == true)
                {
                    dots.Add(new ADot()
                    {
                        Rvalue = Utility.ConvertStrToInt_Big(packet, PhyCombine.GetPhyCombine().GetMachineInfo().DataPctDStart,
                                                             PhyCombine.GetPhyCombine().GetMachineInfo().DataWidth),
                        Status = DotStaus.OK
                    });
                    if (PacketRecevied_Ev != null)
                    {
                        //通知收到一个包
                        PacketRecevied_Ev(dots[dots.Count - 1], dots.Count - 1, PacketType.DATA_VALUE);
                    }
                }
                else
                {
                    //发生错误
                    dots.Add(new ADot()
                    {
                        Status = DotStaus.CORRECTING,
                    });
                    if (PacketCheckError_Ev != null)
                    {
                        PacketCheckError_Ev(dots.Count - 1, PacketType.DATA_VALUE);
                    }
                }
                break;

            case PacketType.RES_COMPUTE_VALUE:
                if (validateData(packet, PhyCombine.GetPhyCombine().GetMachineInfo().ResComputePctDStart,
                                 PhyCombine.GetPhyCombine().GetMachineInfo().DataWidth, twoint(packet, PhyCombine.GetPhyCombine().GetMachineInfo().ResComputePctVStart)) == true)
                {
                    /*
                     * dots.Add(new ADot()
                     * {
                     *  Rvalue = Utility.ConvertStrToInt_Big(packet, PhyCombine.GetPhyCombine().GetMachineInfo().DataPctDStart,
                     *                              PhyCombine.GetPhyCombine().GetMachineInfo().DataWidth),
                     *  Status = DotStaus.OK
                     * });
                     */
                    if (PacketRecevied_Ev != null)
                    {
                        //通知收到一个包
                        PacketRecevied_Ev(null, Utility.ConvertStrToInt_Big(packet, PhyCombine.GetPhyCombine().GetMachineInfo().ResComputePctDStart,
                                                                            PhyCombine.GetPhyCombine().GetMachineInfo().DataWidth), PacketType.RES_COMPUTE_VALUE);
                    }
                }
                else
                {
                    //发生错误
                    if (PacketCheckError_Ev != null)
                    {
                        PacketCheckError_Ev(0, PacketType.RES_COMPUTE_VALUE);
                    }
                }
                break;

            case PacketType.AIR_FLUENT:
                if (validateData(packet, PhyCombine.GetPhyCombine().GetMachineInfo().AirFluPctDStart,
                                 PhyCombine.GetPhyCombine().GetMachineInfo().AirFluPctDataWidth,
                                 twoint(packet, PhyCombine.GetPhyCombine().GetMachineInfo().AirFluPctVStart)) == true)
                {
                    if (PacketRecevied_Ev != null)
                    {
                        //通知收到一个包
                        PacketRecevied_Ev(null, Utility.ConvertStrToInt_Big(packet, PhyCombine.GetPhyCombine().GetMachineInfo().AirFluPctDStart,
                                                                            PhyCombine.GetPhyCombine().GetMachineInfo().AirFluPctDataWidth), PacketType.AIR_FLUENT);
                    }
                }
                else
                {
                    //发生错误
                    if (PacketCheckError_Ev != null)
                    {
                        PacketCheckError_Ev(0, PacketType.AIR_FLUENT);
                    }
                }
                break;

            case PacketType.AIR_SAMPLE_TIME:
                if (validateData(packet, PhyCombine.GetPhyCombine().GetMachineInfo().AirSTPctDStart,
                                 PhyCombine.GetPhyCombine().GetMachineInfo().AirSTPctDataWidth,
                                 twoint(packet, PhyCombine.GetPhyCombine().GetMachineInfo().AirSTPctVStart)) == true)
                {
                    if (PacketRecevied_Ev != null)
                    {
                        //通知收到一个包
                        PacketRecevied_Ev(null, Utility.ConvertStrToInt_Big(packet, PhyCombine.GetPhyCombine().GetMachineInfo().AirSTPctDStart,
                                                                            PhyCombine.GetPhyCombine().GetMachineInfo().AirSTPctDataWidth), PacketType.AIR_SAMPLE_TIME);
                    }
                }
                else
                {
                    //发生错误
                    if (PacketCheckError_Ev != null)
                    {
                        PacketCheckError_Ev(0, PacketType.AIR_SAMPLE_TIME);
                    }
                }
                break;

            case PacketType.SEQUENCE:

                break;

            case PacketType.GETSTATUS_RESPONSE:
                if (validateData(packet, PhyCombine.GetPhyCombine().GetMachineInfo().GetStatusResPctDStart,
                                 PhyCombine.GetPhyCombine().GetMachineInfo().GetStatusResPctDataWidth,
                                 twoint(packet, PhyCombine.GetPhyCombine().GetMachineInfo().GetStatusResPctVStart)) == true)
                {
                    if (PacketRecevied_Ev != null)
                    {
                        //通知收到一个包, 使用dot传递结果
                        byte[] statusres_packt_data = new byte[8];
                        for (int i = 0; i < 8; i++)
                        {
                            statusres_packt_data[i] = packet[PhyCombine.GetPhyCombine().GetMachineInfo().GetStatusResPctDStart + i];
                        }
                        PacketRecevied_Ev(statusres_packt_data, -1, PacketType.GETSTATUS_RESPONSE);
                    }
                }
                else
                {
                    //发生错误
                    if (PacketCheckError_Ev != null)
                    {
                        PacketCheckError_Ev(0, PacketType.GETSTATUS_RESPONSE);
                    }
                }
                break;

            case PacketType.NORCMD_RESPONSE:
                if (validateData(packet, PhyCombine.GetPhyCombine().GetMachineInfo().NorCmdResPctDStart,
                                 PhyCombine.GetPhyCombine().GetMachineInfo().NorCmdResPctDataWidth,
                                 twoint(packet, PhyCombine.GetPhyCombine().GetMachineInfo().NorCmdResPctVStart)) == true)
                {
                    if (PacketRecevied_Ev != null)
                    {
                        //通知收到一个包, 使用dot传递结果
                        byte[] statusres_packt_data = new byte[3];
                        for (int i = 0; i < 3; i++)
                        {
                            statusres_packt_data[i] = packet[PhyCombine.GetPhyCombine().GetMachineInfo().NorCmdResPctDStart + i];
                        }
                        PacketRecevied_Ev(statusres_packt_data, -1, PacketType.NORCMD_RESPONSE);
                    }
                }
                else
                {
                    //发生错误
                    if (PacketCheckError_Ev != null)
                    {
                        PacketCheckError_Ev(0, PacketType.NORCMD_RESPONSE);
                    }
                }
                break;

            default:
                Console.WriteLine("DataFormater:未知包");
                break;
            }
        }