示例#1
0
        public void Step()
        {
            //phase 0_start, 1_collect weight, 2_comb_release, 3 packer,
            if (phase == 0)
            {
                NodeMaster.ClearWeights(packer.wn_addrs);
                NodeMaster.Action(packer.wn_addrs, "query");
                phase = 10;
                return;
            }
            //collect weight
            if (phase == 10)
            {
                int cnt = packer.wn_addrs.Length;
                foreach (byte addr in packer.wn_addrs)
                {
                    double wt = NodeMaster.GetWeight(addr);
                    if (NodeMaster.GetStatus(addr) != NodeStatus.ST_IDLE)
                    {
                        cnt--;
                        continue;
                    }
                    if (wt > -1000 && wt <= WeighNode.MAX_VALID_WEIGHT)
                    {
                        cnt--;
                    }
                }
                if (cnt <= NodeAgent.LASTCOMB_NUM)
                {
                    phase = 20;
                    return;
                }
                //prepare for next round query
                if (cnt > 0)
                {
                    byte[] addrs = new byte[cnt];
                    //
                    int idx = 0;
                    foreach (byte addr in packer.wn_addrs)
                    {
                        if (NodeMaster.GetStatus(addr) != NodeStatus.ST_IDLE)
                        {
                            continue;
                        }
                        double wt = NodeMaster.GetWeight(addr);
                        if (wt > -1000 && wt <= WeighNode.MAX_VALID_WEIGHT)
                        {
                            continue;
                        }

                        addrs[idx++] = addr;
                    }
                }
                NodeMaster.Action(packer.wn_addrs, "query");
                return;
            }
            if (phase == 20)
            {
                if (packer.status != PackerStatus.RUNNING)
                {
                    phase = 0;
                    return;
                }
                //do simulated combination
                bSimCombine = true;
                foreach (byte b in packer.weight_nodes)
                {
                    bSimNodeValid[b] = true;
                }
                while (CheckCombination())
                {
                    ;
                }
                bSimCombine = false;
                foreach (byte b in packer.weight_nodes)
                {
                    if (!bSimNodeValid[b]) //has a combination
                    {
                        phase = 30;
                    }
                }
                if (phase == 30)
                {
                    ProcessGoonNodes();
                }
                else  //no combination at all
                {
                    while (ProcessGoonNodes())
                    {
                        ;
                    }
                    CheckNodeStatus();
                    phase = 0;
                    return;
                }
            }
            if (phase == 30)
            {
                if (!CheckCombination())
                {
                    phase = 50;
                    return;
                }
                ProcessGoonNodes();
                ReleaseAction(release_addrs, release_weight);
                q_hits.Enqueue(new CombineEventArgs((byte)packer._pack_id, release_addrs, release_wts, release_weight));


                Intf intf_reg = new Intf(Convert.ToUInt16(NodeMaster.GetNodeReg(packer.vib_addr, "target_weight")));
                //if (pack_cnt % (intf_reg.feed_times + 1) != 0)
                //{
                //    phase = 30;
                //    return;
                //}
                {
                    pack_cnt = 0;
                    NodeMaster.Action(new byte[] { packer.vib_addr }, "trigger");
                    ProcessGoonNodes();
                    phase = 40;
                }
            }
            if (phase == 40)
            {
                NodeMaster.RefreshNodeReg(packer.vib_addr, new string[] { "pack_rel_cnt" });
                UInt32 lw_ub = NodeMaster.GetNodeReg(packer.vib_addr, "pack_rel_cnt");
                if (lw_ub != release_cnt)
                {
                    release_cnt     = lw_ub;
                    release_timeout = 0;
                    phase           = 30;
                }
                else
                {
                    if (release_timeout++ > 4)
                    {
                        release_timeout = 0;
                        NodeMaster.Action(new byte[] { packer.vib_addr }, "trigger");
                    }
                    ProcessGoonNodes();
                    return;
                }
            }
            if (phase == 50)
            {
                NodeMaster.Action(new byte[] { packer.vib_addr }, "fill");
                while (ProcessGoonNodes())
                {
                    ;
                }
                CheckNodeStatus();
                phase = 0;
                return;
            }

            //do combination
            //release action
        }