Esempio n. 1
0
        private async Task <CodeResult> ExecuteInternally()
        {
            CodeResult result = null;

            // Preprocess this code
            if (!Flags.HasFlag(CodeFlags.IsPreProcessed))
            {
                result = await Interception.Intercept(this, InterceptionMode.Pre);

                Flags |= CodeFlags.IsPreProcessed;

                if (result != null)
                {
                    InternallyExecuted = true;
                    return(await OnCodeExecuted(result));
                }
            }

            // Attempt to process the code internally
            switch (Type)
            {
            case CodeType.GCode:
                result = await GCodes.Process(this);

                break;

            case CodeType.MCode:
                result = await MCodes.Process(this);

                break;

            case CodeType.TCode:
                result = await TCodes.Process(this);

                break;
            }

            if (result != null)
            {
                InternallyExecuted = true;
                return(await OnCodeExecuted(result));
            }

            // If the could not be interpreted, post-process it
            if (!Flags.HasFlag(CodeFlags.IsPostProcessed))
            {
                result = await Interception.Intercept(this, InterceptionMode.Post);

                Flags |= CodeFlags.IsPostProcessed;

                if (result != null)
                {
                    InternallyExecuted = true;
                    return(await OnCodeExecuted(result));
                }
            }

            // Code has not been interpreted yet
            return(null);
        }
Esempio n. 2
0
        private async Task <bool> ProcessInternally()
        {
            // Pre-process this code
            if (!Flags.HasFlag(CodeFlags.IsPreProcessed))
            {
                bool intercepted = await Interception.Intercept(this, InterceptionMode.Pre);

                Flags |= CodeFlags.IsPreProcessed;

                if (intercepted)
                {
                    InternallyProcessed = true;
                    return(true);
                }
            }

            // Attempt to process the code internally
            switch (Type)
            {
            case CodeType.GCode:
                Result = await GCodes.Process(this);

                break;

            case CodeType.MCode:
                Result = await MCodes.Process(this);

                break;

            case CodeType.TCode:
                Result = await TCodes.Process(this);

                break;
            }

            if (Result != null)
            {
                InternallyProcessed = true;
                return(true);
            }

            // If the code could not be interpreted internally, post-process it
            if (!Flags.HasFlag(CodeFlags.IsPostProcessed))
            {
                bool intercepted = await Interception.Intercept(this, InterceptionMode.Post);

                Flags |= CodeFlags.IsPostProcessed;

                if (intercepted)
                {
                    InternallyProcessed = true;
                    return(true);
                }
            }

            // Code has not been interpreted yet - let RRF deal with it
            return(false);
        }
Esempio n. 3
0
        private async Task CodeExecuted()
        {
            // Start the next code if that hasn't happened yet
            StartNextCode();

            if (Result != null)
            {
                // Process the code result
                switch (Type)
                {
                case CodeType.GCode:
                    await GCodes.CodeExecuted(this);

                    break;

                case CodeType.MCode:
                    await MCodes.CodeExecuted(this);

                    break;

                case CodeType.TCode:
                    await TCodes.CodeExecuted(this);

                    break;
                }

                // RepRapFirmware generally prefixes error messages with the code itself.
                // Do this only for error messages that originate either from a print or from a macro file
                if (Flags.HasFlag(CodeFlags.IsFromMacro) || Channel == CodeChannel.File)
                {
                    foreach (Message msg in Result)
                    {
                        if (msg.Type == MessageType.Error)
                        {
                            msg.Content = ToShortString() + ": " + msg.Content;
                        }
                    }
                }

                // Log warning and error replies after the code has been processed internally
                if (InternallyProcessed)
                {
                    foreach (Message msg in Result)
                    {
                        if (msg.Type != MessageType.Success && Channel != CodeChannel.File)
                        {
                            await Utility.Logger.Log(msg);
                        }
                    }
                }
            }

            // Done
            await Interception.Intercept(this, InterceptionMode.Executed);
        }
Esempio n. 4
0
        private async Task <CodeResult> OnCodeExecuted(CodeResult result)
        {
            // Process code result
            switch (Type)
            {
            case CodeType.GCode:
                result = await GCodes.CodeExecuted(this, result);

                break;

            case CodeType.MCode:
                result = await MCodes.CodeExecuted(this, result);

                break;

            case CodeType.TCode:
                result = await TCodes.CodeExecuted(this, result);

                break;
            }

            // RepRapFirmware generally prefixes error messages with the code itself.
            // Do this only for error messages that come either from a print or from a macro
            if (result != null && (Flags.HasFlag(CodeFlags.IsFromMacro) || Channel == CodeChannel.File))
            {
                foreach (Message msg in result)
                {
                    if (msg.Type == MessageType.Error)
                    {
                        msg.Content = ToShortString() + ": " + msg.Content;
                    }
                }
            }

            // Log warning+error replies if the code could be processed internally
            if (InternallyExecuted && !result.IsEmpty)
            {
                foreach (Message msg in result)
                {
                    if (msg.Type != MessageType.Success || Channel == CodeChannel.File)
                    {
                        await Utility.Logger.Log(msg);
                    }
                }
            }

            // Finished. Optionally an "Executed" interceptor could be called here, but that would only make sense if the code reply was included
            return(result);
        }
Esempio n. 5
0
        public override string ToString()
        {
            var builder = new StringBuilder();

            if (GCodes != null && GCodes.Count > 0)
            {
                if (GCodes.Count > 1)
                {
                    builder.Append($"{GCodes.Select(c => c.ToString(CultureInfo.InvariantCulture)).Aggregate((s1, s2) => $"G{s1} G{s2} ")}");
                }
                else
                {
                    builder.Append($"G{GCodes.First().ToString(CultureInfo.InvariantCulture)} ");
                }
            }
            if (MCodes != null && MCodes.Count > 0)
            {
                if (MCodes.Count > 1)
                {
                    builder.Append($"{MCodes.Select(c => c.ToString(CultureInfo.InvariantCulture)).Aggregate((s1, s2) => $"M{s1} M{s2} ")}");
                }
                else
                {
                    builder.Append($"M{MCodes.First().ToString(CultureInfo.InvariantCulture)} ");
                }
            }
            if (Coordinate.X.HasValue)
            {
                builder.Append($"X{Coordinate.X.Value} ");
                if (IValue.HasValue)
                {
                    builder.Append($"I{IValue} ");
                }
            }
            if (Coordinate.Y.HasValue)
            {
                builder.Append($"Y{Coordinate.Y.Value} ");
                if (JValue.HasValue)
                {
                    builder.Append($"J{JValue} ");
                }
            }
            if (Coordinate.Z.HasValue)
            {
                builder.Append($"Z{Coordinate.Z.Value} ");
                if (KValue.HasValue)
                {
                    builder.Append($"K{KValue} ");
                }
            }
            if (RValue.HasValue)
            {
                builder.Append($"R{RValue} ");
            }
            if (Feedrate.HasValue)
            {
                builder.Append($"F{Feedrate} ");
            }
            if (ToolNumber.HasValue)
            {
                builder.Append($"T{ToolNumber} ");
            }
            return(builder.ToString());
        }