Skip to content

Commit

Permalink
Updated macro engine. Added Jint library, now macroses support variab…
Browse files Browse the repository at this point in the history
…les, calculations and machine state.
  • Loading branch information
IlyaChernov committed Sep 6, 2020
1 parent 241c28d commit 11e06e3
Show file tree
Hide file tree
Showing 52 changed files with 756 additions and 300 deletions.
6 changes: 6 additions & 0 deletions grbl Master.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "grbl.Master.BL", "grbl.Mast
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "grbl.Master.Utilities", "grbl.Master.Utilities\grbl.Master.Utilities.csproj", "{9FE0DAFE-CC25-420D-9909-F4D53FD966B0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "grbl.Master.Common", "grbl.Master.Common\grbl.Master.Common.csproj", "{292BC2BE-A547-4567-8592-9CE4D9290E54}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -45,6 +47,10 @@ Global
{9FE0DAFE-CC25-420D-9909-F4D53FD966B0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9FE0DAFE-CC25-420D-9909-F4D53FD966B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9FE0DAFE-CC25-420D-9909-F4D53FD966B0}.Release|Any CPU.Build.0 = Release|Any CPU
{292BC2BE-A547-4567-8592-9CE4D9290E54}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{292BC2BE-A547-4567-8592-9CE4D9290E54}.Debug|Any CPU.Build.0 = Debug|Any CPU
{292BC2BE-A547-4567-8592-9CE4D9290E54}.Release|Any CPU.ActiveCfg = Release|Any CPU
{292BC2BE-A547-4567-8592-9CE4D9290E54}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
7 changes: 6 additions & 1 deletion grbl Master.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=COM/@EntryIndexedValue">COM</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=EEPROM/@EntryIndexedValue">EEPROM</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=NA/@EntryIndexedValue">NA</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=XML/@EntryIndexedValue">XML</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=debounce/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Fody/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=gcode/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Grbl/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=pulloff/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Macroses/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=pulloff/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=regexes/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
namespace grbl.Master.BL.Implementation
namespace grbl.Master.BL
{
using grbl.Master.BL.Interface;
using grbl.Master.Model.Enum;
using grbl.Master.Service.Enum;
using grbl.Master.Service.Interface;
using System;

using grbl.Master.Common.Enum;
using grbl.Master.Common.Interfaces.BL;
using grbl.Master.Common.Interfaces.Service;
using grbl.Master.Model.Enum;

public class GrblDispatcher : IGrblDispatcher
{
private readonly IGrblStatus _grblStatus;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
namespace grbl.Master.BL.Implementation
namespace grbl.Master.BL
{
using grbl.Master.BL.Interface;
using grbl.Master.Service.Interface;
using System;
using System.Text.RegularExpressions;

using grbl.Master.Common.Interfaces.BL;
using grbl.Master.Common.Interfaces.Service;

public class GrblPrompt : IGrblPrompt
{
private const string PromptTag = "^Grbl.{6}\\[.*\\]$";

readonly Regex _promptReg = new Regex(PromptTag);
private readonly Regex _promptReg = new Regex(PromptTag);

public GrblPrompt(IComService comService)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
namespace grbl.Master.BL.Implementation
namespace grbl.Master.BL
{
using grbl.Master.BL.Interface;
using grbl.Master.Model;
using grbl.Master.Model.Enum;
using grbl.Master.Service.Enum;
using grbl.Master.Service.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -14,13 +9,22 @@
using System.Text.RegularExpressions;
using System.Threading;

using grbl.Master.Common.Enum;
using grbl.Master.Common.Interfaces.BL;
using grbl.Master.Common.Interfaces.Service;
using grbl.Master.Model;
using grbl.Master.Model.Enum;
using grbl.Master.Model.Interface;

public class GrblStatus : IGrblStatus
{
private readonly ICommandSender _commandSender;

//private readonly IGrblStatusModel _grblStatusModel;

private readonly string _decimalSeparator = Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator;

readonly Subject<Unit> _stopSubject = new Subject<Unit>();
private readonly Subject<Unit> _stopSubject = new Subject<Unit>();

private struct ResponseProcessingDefinition
{
Expand All @@ -45,9 +49,10 @@ private string TranslateMessageKey(string key)
return Model.Resources.Mssages.ResourceManager.GetString(key);
}

public GrblStatus(IComService comService, ICommandSender commandSender)
public GrblStatus(IComService comService, ICommandSender commandSender, IGrblStatusModel grblStatusModel)
{
_commandSender = commandSender;
GrblStatusModel = grblStatusModel;
comService.ConnectionStateChanged += ComServiceConnectionStateChanged;
_commandSender.ResponseReceived += CommandSenderResponseReceived;

Expand Down Expand Up @@ -84,10 +89,10 @@ public GrblStatus(IComService comService, ICommandSender commandSender)
var setting = new GrblSetting
{
Index = index,
Value = parts[1],
Value = parts[1],
OriginalValue = parts[1]
};
GrblStatusModel.Settings.AddOrUpdate(setting);
}
}
Expand All @@ -97,7 +102,7 @@ public GrblStatus(IComService comService, ICommandSender commandSender)
{ ResponseType.FeedbackMessage, new ResponseProcessingDefinition
{
SplitAction =s =>s.Split(new[]{'[', ']'},StringSplitOptions.RemoveEmptyEntries),
ProcessActions = new List<ResponseProcessor>{new ResponseProcessor()
ProcessActions = new List<ResponseProcessor>{new ResponseProcessor
{
TagExpression = "MSG:.*",
Action = s =>
Expand All @@ -109,7 +114,7 @@ public GrblStatus(IComService comService, ICommandSender commandSender)
{ ResponseType.HelpMessage, new ResponseProcessingDefinition
{
SplitAction =s =>s.Split(new[]{'[', ']'},StringSplitOptions.RemoveEmptyEntries),
ProcessActions = new List<ResponseProcessor>{new ResponseProcessor()
ProcessActions = new List<ResponseProcessor>{new ResponseProcessor
{
TagExpression = "HLP:.*",
Action = s =>
Expand All @@ -120,7 +125,7 @@ public GrblStatus(IComService comService, ICommandSender commandSender)
}},
{ ResponseType.Error, new ResponseProcessingDefinition
{
ProcessActions = new List<ResponseProcessor>{new ResponseProcessor()
ProcessActions = new List<ResponseProcessor>{new ResponseProcessor
{
TagExpression = "error:.*",
Action = s =>
Expand Down Expand Up @@ -258,7 +263,7 @@ public GrblStatus(IComService comService, ICommandSender commandSender)
if (accessoryParts.Length == 2)
{
if(accessoryParts[1].Contains('S'))
{
{
GrblStatusModel.AccessoryState.Spindle = SpindleState.M3;
}
else if(accessoryParts[1].Contains('C'))
Expand Down Expand Up @@ -294,12 +299,12 @@ public GrblStatus(IComService comService, ICommandSender commandSender)
part =>
{
var lineParts = part.Split(new[] { ':', '[', ']' }, StringSplitOptions.RemoveEmptyEntries);
if (ParsePosition(part, out var position))
if (ParsePosition(part.Remove(part.Length-2), out var position))
{
GrblStatusModel.ProbePosition.Update(position);
}
if (lineParts.Length == 5 && int.TryParse(lineParts.Last().Trim(), out var probingResult))
if (lineParts.Length == 3 && int.TryParse(lineParts.Last().Trim(), out var probingResult))
{
GrblStatusModel.ProbeState = probingResult!= 0;
}
Expand Down Expand Up @@ -428,8 +433,8 @@ public GrblStatus(IComService comService, ICommandSender commandSender)
new ResponseProcessor{TagExpression = "^G40$", Action =
s =>
{
Enum.TryParse<CutterRaduisCompensation>(s.Replace('.', '_'), true, out var result);
GrblStatusModel.CutterRaduisCompensation = result;
Enum.TryParse<CutterRadiusCompensation>(s.Replace('.', '_'), true, out var result);
GrblStatusModel.CutterRadiusCompensation = result;
}},
new ResponseProcessor{TagExpression = "^G4(3\\.1|9)$", Action =
s =>
Expand Down Expand Up @@ -496,7 +501,7 @@ private void CommandSenderResponseReceived(object sender, Response e)
}
}

public GrblStatusModel GrblStatusModel { get; set; } = new GrblStatusModel();
public IGrblStatusModel GrblStatusModel { get; } //=> _grblStatusModel; // { get; set; } = new GrblStatusModel();

private bool _isRunning;

Expand Down
18 changes: 7 additions & 11 deletions grbl.Master.BL/grbl.Master.BL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,23 @@
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Windows" />
<Reference Include="System.Windows.Forms" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="Implementation\GrblPrompt.cs" />
<Compile Include="Implementation\GrblStatus.cs" />
<Compile Include="Implementation\GrblDispatcher.cs" />
<Compile Include="Interface\IGrblPrompt.cs" />
<Compile Include="Interface\IGrblStatus.cs" />
<Compile Include="Interface\IGrblDispatcher.cs" />
<Compile Include="GrblPrompt.cs" />
<Compile Include="GrblStatus.cs" />
<Compile Include="GrblDispatcher.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\grbl.Master.Common\grbl.Master.Common.csproj">
<Project>{292BC2BE-A547-4567-8592-9CE4D9290E54}</Project>
<Name>grbl.Master.Common</Name>
</ProjectReference>
<ProjectReference Include="..\grbl.Master.Model\grbl.Master.Model.csproj">
<Project>{B21C205E-5CE2-436E-AFA4-F2A3DAC60D21}</Project>
<Name>grbl.Master.Model</Name>
</ProjectReference>
<ProjectReference Include="..\grbl.Master.Service\grbl.Master.Service.csproj">
<Project>{5233400E-E720-4DE5-8BED-6B11F2AE14C6}</Project>
<Name>grbl.Master.Service</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace grbl.Master.Service.Enum
namespace grbl.Master.Common.Enum
{
public enum ConnectionState
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace grbl.Master.BL.Interface
namespace grbl.Master.Common.Interfaces.BL
{
public interface IGrblDispatcher
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace grbl.Master.BL.Interface
namespace grbl.Master.Common.Interfaces.BL
{
using System;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
namespace grbl.Master.BL.Interface
namespace grbl.Master.Common.Interfaces.BL
{
using System;
using grbl.Master.Model;
using System;

using grbl.Master.Model.Interface;

public interface IGrblStatus
{
void StartRequesting(TimeSpan positionsInterval, TimeSpan gStateInterval,TimeSpan offsetsInterval);
void InitialRequest();
void StopRequesting();
void StopRequesting();

//bool IsRunning
//{
// get;
//}

GrblStatusModel GrblStatusModel { get; set; }
IGrblStatusModel GrblStatusModel { get; }
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace grbl.Master.Service.Interface
namespace grbl.Master.Common.Interfaces.Service
{
using grbl.Master.Model;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace grbl.Master.Service.Interface
namespace grbl.Master.Common.Interfaces.Service
{
using System;
using System.Collections.Generic;

using grbl.Master.Service.Enum;
using grbl.Master.Common.Enum;

public interface IComService
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace grbl.Master.Service.Interface
namespace grbl.Master.Common.Interfaces.Service
{
using System;
using System.Collections.ObjectModel;
Expand All @@ -7,10 +7,15 @@

public interface ICommandSender
{
event EventHandler<int> CommandQueueLengthChanged;

CommandSource SystemCommands { get; }
CommandSource ManualCommands { get; }
CommandSource ManualCommands { get; }
CommandSource MacroCommands { get; }
CommandSource FileCommands { get; }

int CommandQueueLength { get; }

ObservableCollection<string> CommunicationLog
{
get;
Expand All @@ -24,7 +29,7 @@ ObservableCollection<string> CommunicationLog

void Send(string command, string onResult = null);

Command Prepare(string command);
//Command Prepare(string command);

void PurgeQueues();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace grbl.Master.Service.Interface
namespace grbl.Master.Common.Interfaces.Service
{
using grbl.Master.Model;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace grbl.Master.Service.Interface
namespace grbl.Master.Common.Interfaces.Service
{
using grbl.Master.Model;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace grbl.Master.Service.Interface
namespace grbl.Master.Common.Interfaces.Service
{
using grbl.Master.Model.Enum;

Expand Down

0 comments on commit 11e06e3

Please sign in to comment.