Пример #1
0
Файл: TMPlan.cs Проект: x2v0/TM
        /// <summary>
        ///    Nexts the full spot.
        /// </summary>
        /// <param name="buf">The buf.</param>
        /// <returns>System.Nullable&lt;SpotFull&gt;.</returns>
        public static SpotFull?NextSpotFull(this BufferChunk buf)
        {
            var plan = new SpotFull();

            try {
                plan.changed       = buf.NextInt32();
                plan.done          = buf.NextInt32();
                plan.energy        = buf.NextFloat();
                plan.id            = buf.NextInt32();
                plan.need_to_sent  = buf.NextInt32();
                plan.pcount        = buf.NextFloat();
                plan.result_pcount = buf.NextFloat();
                plan.result_xangle = buf.NextFloat();
                plan.result_zangle = buf.NextFloat();
                plan.xangle        = buf.NextFloat();
                plan.zangle        = buf.NextFloat();
            } catch {
                //plan.id = -1; //
                return(null);
            }

            return(plan);
        }
Пример #2
0
Файл: TMPlan.cs Проект: x2v0/TM
        /// <summary>
        ///    <code>
        /// LoadPlan(file) - loads the specified file with plan data.
        /// SendPlan()     - sends plan to the server specified by ip nad port
        /// StartPlan()    - starts plan processing on the server
        /// while (ProcessingIsOn) - waits for results of processing
        /// when results of plan processing received from server, fills PlanResults list
        /// if (ServerState == EPlanState.FINISHED) - execute PlanFinished() event
        /// </code>
        /// </summary>
        /// <param name="file">The file with plan data.</param>
        /// <param name="ip">The server IP.</param>
        /// <param name="port">The port.</param>
        /// <returns>Dictionary&lt;System.Int32, SpotFull&gt;.</returns>
        public virtual List <SpotFull> Execute(string file, string ip = null, int port = 0)
        {
            ClearPlan();

            var ok = Connect(ip, port);

            if (!ok)
            {
                return(null);
            }

            ok = Load(file) != null;

            if (!ok)
            {
                return(null);
            }

            ok = Send();

            if (!ok)
            {
                if (Globals.Debug)
                {
                    Console.WriteLine(Resources.Failed_to_send + " " + Resources.plan);
                }

                return(null);
            }

            ok = Start();

            while (true)
            {
                ok = AskServerState();

                if (!ok || (PlanState == EPlanState.NOTREADY))
                {
                    if (Globals.Debug)
                    {
                        Console.WriteLine(Resources.Server_not_ready);
                    }

                    //return null;
                }

                if (PlanState == EPlanState.FINISHED)
                {
                    fFinished = true;

                    if (PlanFinished != null)
                    {
                        PlanFinished.Invoke();
                    }

                    break;
                }

                Thread.Sleep(300);
            }

            var ret = new List <SpotFull>();

            foreach (var spot in PlanResults)
            {
                var plan = Plan[spot.id];
                var full = new SpotFull();
                full.id            = spot.id;
                full.xangle        = plan.xangle;
                full.zangle        = plan.zangle;
                full.pcount        = plan.pcount;
                full.energy        = plan.energy;
                full.result_xangle = spot.result_xangle;
                full.result_zangle = spot.result_zangle;
                full.result_pcount = spot.result_pcount;
                full.done          = spot.done;
                //full.changed = spot.Value.changed;
                ret.Add(full);
            }

            return(ret);
        }