public void Assign()
        {
            MachineModel original = new MachineModel();

            original.Channels.SPI.RelativePositioning = true;
            original.Channels.USB.Feedrate            = 123F;
            original.Channels.File.Feedrate           = 565F;
            original.Channels.CodeQueue.UsingInches   = true;
            original.Channels.HTTP.RelativeExtrusion  = true;
            original.Channels.Daemon.Feedrate         = 45F;
            original.Channels[DuetAPI.CodeChannel.Telnet].StackDepth = 5;
            original.Channels.LCD.LineNumber          = 45;
            original.Channels.AUX.VolumetricExtrusion = true;
            original.Channels.AutoPause.Compatibility = Compatibility.Marlin;

            MachineModel assigned = new MachineModel();

            assigned.Assign(original);

            Assert.AreEqual(original.Channels.SPI.RelativePositioning, assigned.Channels.SPI.RelativePositioning);
            Assert.AreEqual(original.Channels.USB.Feedrate, assigned.Channels.USB.Feedrate);
            Assert.AreEqual(original.Channels.File.Feedrate, assigned.Channels.File.Feedrate);
            Assert.AreEqual(original.Channels.CodeQueue.UsingInches, assigned.Channels.CodeQueue.UsingInches);
            Assert.AreEqual(original.Channels.HTTP.RelativePositioning, assigned.Channels.HTTP.RelativePositioning);
            Assert.AreEqual(original.Channels.Daemon.Feedrate, assigned.Channels.Daemon.Feedrate);
            Assert.AreEqual(original.Channels.Telnet.StackDepth, assigned.Channels.Telnet.StackDepth);
            Assert.AreEqual(original.Channels.LCD.LineNumber, assigned.Channels.LCD.LineNumber);
            Assert.AreEqual(original.Channels.AUX.VolumetricExtrusion, assigned.Channels.AUX.VolumetricExtrusion);
            Assert.AreEqual(original.Channels.AutoPause.Compatibility, assigned.Channels.AutoPause.Compatibility);
        }
        public void Assign()
        {
            MachineModel original = new MachineModel();

            Storage storage = new Storage
            {
                Capacity  = 12345678,
                Free      = 123456,
                Mounted   = true,
                OpenFiles = 3467,
                Speed     = 200000
            };

            original.Storages.Add(storage);

            MachineModel assigned = new MachineModel();

            assigned.Assign(original);

            Assert.AreEqual(1, original.Storages.Count);
            Assert.AreEqual(original.Storages[0].Capacity, assigned.Storages[0].Capacity);
            Assert.AreEqual(original.Storages[0].Free, assigned.Storages[0].Free);
            Assert.AreEqual(original.Storages[0].Mounted, assigned.Storages[0].Mounted);
            Assert.AreEqual(original.Storages[0].OpenFiles, assigned.Storages[0].OpenFiles);
            Assert.AreEqual(original.Storages[0].Speed, assigned.Storages[0].Speed);
        }
        public void Assign()
        {
            MachineModel original = new MachineModel();

            original.UserSessions.Add(new UserSession {
                AccessLevel = AccessLevel.ReadOnly, Id = 123, Origin = "192.168.1.123", OriginId = 34545, SessionType = SessionType.HTTP
            });
            original.UserSessions.Add(new UserSession {
                AccessLevel = AccessLevel.ReadWrite, Id = 124, Origin = "console", OriginId = -1, SessionType = SessionType.Local
            });

            MachineModel assigned = new MachineModel();

            assigned.Assign(original);

            Assert.AreEqual(original.UserSessions.Count, assigned.UserSessions.Count);
            Assert.AreEqual(original.UserSessions[0].AccessLevel, assigned.UserSessions[0].AccessLevel);
            Assert.AreEqual(original.UserSessions[0].Id, assigned.UserSessions[0].Id);
            Assert.AreEqual(original.UserSessions[0].Origin, assigned.UserSessions[0].Origin);
            Assert.AreEqual(original.UserSessions[0].OriginId, assigned.UserSessions[0].OriginId);
            Assert.AreEqual(original.UserSessions[0].SessionType, assigned.UserSessions[0].SessionType);

            Assert.AreEqual(original.UserSessions[1].AccessLevel, assigned.UserSessions[1].AccessLevel);
            Assert.AreEqual(original.UserSessions[1].Id, assigned.UserSessions[1].Id);
            Assert.AreEqual(original.UserSessions[1].Origin, assigned.UserSessions[1].Origin);
            Assert.AreEqual(original.UserSessions[1].OriginId, assigned.UserSessions[1].OriginId);
            Assert.AreEqual(original.UserSessions[1].SessionType, assigned.UserSessions[1].SessionType);
        }
Example #4
0
        public void Assign()
        {
            MachineModel original = new MachineModel();

            Fan fan = new Fan
            {
                Value     = 100,
                Name      = "Fan Name",
                Rpm       = 1234,
                Inverted  = true,
                Frequency = 20000,
                Min       = 0.01F,
                Max       = 0.99F,
                Blip      = 0
            };

            fan.Thermostatic.Control = false;
            fan.Thermostatic.Heaters.Add(1);
            fan.Thermostatic.Heaters.Add(2);
            fan.Thermostatic.Temperature = 79F;
            fan.Pin = 23;
            original.Fans.Add(fan);

            MachineModel assigned = new MachineModel();

            assigned.Assign(original);

            Assert.AreEqual(1, original.Fans.Count);
            Assert.AreEqual(original.Fans[0].Value, assigned.Fans[0].Value);
            Assert.AreEqual(original.Fans[0].Name, assigned.Fans[0].Name);
            Assert.AreEqual(original.Fans[0].Rpm, assigned.Fans[0].Rpm);
            Assert.AreEqual(original.Fans[0].Inverted, assigned.Fans[0].Inverted);
            Assert.AreEqual(original.Fans[0].Frequency, assigned.Fans[0].Frequency);
            Assert.AreEqual(original.Fans[0].Min, assigned.Fans[0].Min);
            Assert.AreEqual(original.Fans[0].Max, assigned.Fans[0].Max);
            Assert.AreEqual(original.Fans[0].Blip, assigned.Fans[0].Blip);
            Assert.AreEqual(original.Fans[0].Thermostatic.Control, assigned.Fans[0].Thermostatic.Control);
            Assert.AreEqual(original.Fans[0].Thermostatic.Heaters, assigned.Fans[0].Thermostatic.Heaters);
            Assert.AreEqual(original.Fans[0].Thermostatic.Temperature, assigned.Fans[0].Thermostatic.Temperature);
            Assert.AreEqual(original.Fans[0].Pin, assigned.Fans[0].Pin);

            Assert.AreNotSame(original.Fans[0].Value, assigned.Fans[0].Value);
            Assert.AreNotSame(original.Fans[0].Name, assigned.Fans[0].Name);
            Assert.AreNotSame(original.Fans[0].Rpm, assigned.Fans[0].Rpm);
            Assert.AreNotSame(original.Fans[0].Inverted, assigned.Fans[0].Inverted);
            Assert.AreNotSame(original.Fans[0].Frequency, assigned.Fans[0].Frequency);
            Assert.AreNotSame(original.Fans[0].Min, assigned.Fans[0].Min);
            Assert.AreNotSame(original.Fans[0].Max, assigned.Fans[0].Max);
            Assert.AreNotSame(original.Fans[0].Blip, assigned.Fans[0].Blip);
            Assert.AreNotSame(original.Fans[0].Thermostatic.Control, assigned.Fans[0].Thermostatic.Control);
            Assert.AreNotSame(original.Fans[0].Thermostatic.Heaters, assigned.Fans[0].Thermostatic.Heaters);
            Assert.AreNotSame(original.Fans[0].Thermostatic.Temperature, assigned.Fans[0].Thermostatic.Temperature);
            Assert.AreNotSame(original.Fans[0].Pin, assigned.Fans[0].Pin);
        }
Example #5
0
        public void Assign()
        {
            MachineModel original = new MachineModel();

            Tool tool = new Tool
            {
                Filament = "PET-G",
                Name     = "Mixing Tool",
                Number   = 3,
                Spindle  = 3
            };

            tool.Active.Add(200F);
            tool.Active.Add(220F);
            tool.Fans.Add(3);
            tool.Heaters.Add(4);
            tool.Heaters.Add(5);
            tool.Mix.Add(0.4F);
            tool.Mix.Add(0.6F);
            tool.Offsets.Add(12F);
            tool.Offsets.Add(34F);
            tool.Offsets.Add(56F);
            tool.Standby.Add(40F);
            tool.Standby.Add(60F);
            tool.Axes.Add(new int[] { 0 });
            tool.Axes.Add(new int[] { 1 });
            original.Tools.Add(tool);

            MachineModel assigned = new MachineModel();

            assigned.Assign(original);

            Assert.AreEqual(1, original.Tools.Count);
            Assert.AreEqual(original.Tools[0].Active, assigned.Tools[0].Active);
            Assert.AreEqual(original.Tools[0].Axes.Count, 2);
            Assert.AreEqual(original.Tools[0].Axes[0], assigned.Tools[0].Axes[0]);
            Assert.AreEqual(original.Tools[0].Axes[1], assigned.Tools[0].Axes[1]);
            Assert.AreEqual(original.Tools[0].Fans, assigned.Tools[0].Fans);
            Assert.AreEqual(original.Tools[0].Filament, assigned.Tools[0].Filament);
            Assert.AreEqual(original.Tools[0].Heaters, assigned.Tools[0].Heaters);
            Assert.AreEqual(original.Tools[0].Mix, assigned.Tools[0].Mix);
            Assert.AreEqual(original.Tools[0].Name, assigned.Tools[0].Name);
            Assert.AreEqual(original.Tools[0].Number, assigned.Tools[0].Number);
            Assert.AreEqual(original.Tools[0].Offsets, assigned.Tools[0].Offsets);
            Assert.AreEqual(original.Tools[0].Spindle, assigned.Tools[0].Spindle);
            Assert.AreEqual(original.Tools[0].Standby, assigned.Tools[0].Standby);
        }
        public void Assign()
        {
            MachineModel original = new MachineModel();

            original.Messages.Add(new Message(MessageType.Warning, "Test 1 2 3"));
            original.Messages.Add(new Message(MessageType.Error, "Err 3 2 1"));

            MachineModel assigned = new MachineModel();

            assigned.Assign(original);

            Assert.AreEqual(2, original.Messages.Count);
            Assert.AreEqual(original.Messages[0].Content, "Test 1 2 3");
            Assert.AreEqual(original.Messages[0].Type, MessageType.Warning);
            Assert.AreEqual(original.Messages[1].Content, "Err 3 2 1");
            Assert.AreEqual(original.Messages[1].Type, MessageType.Error);
        }
        public void Assign()
        {
            MachineModel original = new MachineModel();

            original.Scanner.Progress = 12.34F;
            original.Scanner.Status   = ScannerStatus.PostProcessing;

            MachineModel assigned = new MachineModel();

            assigned.Assign(original);

            Assert.AreEqual(original.Scanner.Progress, assigned.Scanner.Progress);
            Assert.AreEqual(original.Scanner.Status, assigned.Scanner.Status);

            Assert.AreNotSame(original.Scanner.Progress, assigned.Scanner.Progress);
            Assert.AreNotSame(original.Scanner.Status, assigned.Scanner.Status);
        }
        public void Assign()
        {
            MachineModel original = new MachineModel();

            original.HttpEndpoints.Add(new HttpEndpoint {
                EndpointType = HttpEndpointType.PATCH, Namespace = "my-demo", Path = "ep", UnixSocket = "/tmp/some.sock"
            });

            MachineModel assigned = new MachineModel();

            assigned.Assign(original);

            Assert.AreEqual(original.UserVariables.Count, assigned.UserVariables.Count);
            Assert.AreEqual(original.HttpEndpoints[0].EndpointType, assigned.HttpEndpoints[0].EndpointType);
            Assert.AreEqual(original.HttpEndpoints[0].Namespace, assigned.HttpEndpoints[0].Namespace);
            Assert.AreEqual(original.HttpEndpoints[0].Path, assigned.HttpEndpoints[0].Path);
            Assert.AreEqual(original.HttpEndpoints[0].UnixSocket, assigned.HttpEndpoints[0].UnixSocket);
        }
Example #9
0
        public void Assign()
        {
            MachineModel original = new MachineModel();

            original.UserVariables.Add(new UserVariable {
                Name = "Variable 1", Value = "Value 1"
            });
            original.UserVariables.Add(new UserVariable {
                Name = "Variable 2", Value = "Value 2"
            });

            MachineModel assigned = new MachineModel();

            assigned.Assign(original);

            Assert.AreEqual(original.UserVariables.Count, assigned.UserVariables.Count);
            Assert.AreEqual(original.UserVariables[0].Name, assigned.UserVariables[0].Name);
        }
        public void Assign()
        {
            MachineModel original = new MachineModel();

            original.Directories.GCodes = "0:/gcodes/foo";
            original.Directories.Macros = "0:/my macros";
            original.Directories.System = "0:/sys/test";
            original.Directories.WWW    = "0:/www/test";

            MachineModel assigned = new MachineModel();

            assigned.Assign(original);

            Assert.AreEqual(original.Directories.GCodes, assigned.Directories.GCodes);
            Assert.AreEqual(original.Directories.Macros, assigned.Directories.Macros);
            Assert.AreEqual(original.Directories.System, assigned.Directories.System);
            Assert.AreEqual(original.Directories.WWW, assigned.Directories.WWW);
        }
Example #11
0
        public void Assign()
        {
            MachineModel original = new MachineModel();

            original.MessageBox.AxisControls.Add(1);
            original.MessageBox.AxisControls.Add(2);
            original.MessageBox.Message = "Message";
            original.MessageBox.Mode    = MessageBoxMode.OkCancel;
            original.MessageBox.Title   = "Title";

            MachineModel assigned = new MachineModel();

            assigned.Assign(original);

            Assert.AreEqual(original.MessageBox.AxisControls, assigned.MessageBox.AxisControls);
            Assert.AreEqual(original.MessageBox.Message, assigned.MessageBox.Message);
            Assert.AreEqual(original.MessageBox.Mode, assigned.MessageBox.Mode);
            Assert.AreEqual(original.MessageBox.Title, assigned.MessageBox.Title);
        }
Example #12
0
        public void Assign()
        {
            string modelPath = Path.Combine(Directory.GetCurrentDirectory(), "../../../Machine/JSON/model.json");
            string jsonText  = System.IO.File.ReadAllText(modelPath);

            using JsonDocument parsedJson = JsonDocument.Parse(jsonText);

            MachineModel model = new MachineModel();

            model.UpdateFromJson(parsedJson.RootElement);

            MachineModel newModel = new MachineModel();

            newModel.Assign(model);

            string serializedModel = newModel.ToString();

            Assert.AreEqual(jsonText, serializedModel);
        }
        public void Assign()
        {
            MachineModel original = new MachineModel();

            NetworkInterface iface = new NetworkInterface();

            iface.ActiveProtocols.Add(NetworkProtocol.Telnet);
            iface.MacAddress      = "DE:AD:BE:EF:CA:FE";
            iface.ActualIP        = "12.34.56.78";
            iface.ConfiguredIP    = "34.34.56.78";
            iface.FirmwareVersion = "Firmware version";
            iface.Gateway         = "12.34.56.1";
            iface.NumReconnects   = 123;
            iface.Signal          = -45;
            iface.Speed           = 56;
            iface.Subnet          = "255.0.255.0";
            iface.Type            = InterfaceType.LAN;
            original.Network.Interfaces.Add(iface);

            original.Network.Name     = "Name";
            original.Network.Password = "******";

            MachineModel assigned = new MachineModel();

            assigned.Assign(original);

            Assert.AreEqual(1, original.Network.Interfaces.Count);
            Assert.AreEqual(original.Network.Interfaces[0].ActiveProtocols, assigned.Network.Interfaces[0].ActiveProtocols);
            Assert.AreEqual(original.Network.Interfaces[0].MacAddress, assigned.Network.Interfaces[0].MacAddress);
            Assert.AreEqual(original.Network.Interfaces[0].ActualIP, assigned.Network.Interfaces[0].ActualIP);
            Assert.AreEqual(original.Network.Interfaces[0].ConfiguredIP, assigned.Network.Interfaces[0].ConfiguredIP);
            Assert.AreEqual(original.Network.Interfaces[0].FirmwareVersion, assigned.Network.Interfaces[0].FirmwareVersion);
            Assert.AreEqual(original.Network.Interfaces[0].Gateway, assigned.Network.Interfaces[0].Gateway);
            Assert.AreEqual(original.Network.Interfaces[0].NumReconnects, assigned.Network.Interfaces[0].NumReconnects);
            Assert.AreEqual(original.Network.Interfaces[0].Signal, assigned.Network.Interfaces[0].Signal);
            Assert.AreEqual(original.Network.Interfaces[0].Speed, assigned.Network.Interfaces[0].Speed);
            Assert.AreEqual(original.Network.Interfaces[0].Subnet, assigned.Network.Interfaces[0].Subnet);
            Assert.AreEqual(original.Network.Interfaces[0].Type, assigned.Network.Interfaces[0].Type);

            Assert.AreEqual(original.Network.Name, assigned.Network.Name);
            Assert.AreEqual(original.Network.Password, assigned.Network.Password);
        }
Example #14
0
        public void Assign()
        {
            MachineModel original = new MachineModel();

            original.State.AtxPower       = true;
            original.State.CurrentTool    = 123;
            original.State.DisplayMessage = "display message";
            original.State.DisplayMessage = "log file";
            original.State.Mode           = MachineMode.Laser;
            original.State.Status         = MachineStatus.Processing;

            MachineModel assigned = new MachineModel();

            assigned.Assign(original);

            Assert.AreEqual(original.State.AtxPower, assigned.State.AtxPower);
            Assert.AreEqual(original.State.CurrentTool, assigned.State.CurrentTool);
            Assert.AreEqual(original.State.DisplayMessage, assigned.State.DisplayMessage);
            Assert.AreEqual(original.State.LogFile, assigned.State.LogFile);
            Assert.AreEqual(original.State.Mode, assigned.State.Mode);
            Assert.AreEqual(original.State.Status, assigned.State.Status);
        }
Example #15
0
        public void Assign()
        {
            MachineModel original = new MachineModel();

            original.State.AtxPower    = true;
            original.State.CurrentTool = 123;
            original.State.Mode        = MachineMode.Laser;
            original.State.Status      = MachineStatus.Processing;

            MachineModel clone = new MachineModel();

            clone.Assign(original);

            Assert.AreEqual(original.State.AtxPower, clone.State.AtxPower);
            Assert.AreEqual(original.State.CurrentTool, clone.State.CurrentTool);
            Assert.AreEqual(original.State.Mode, clone.State.Mode);
            Assert.AreEqual(original.State.Status, clone.State.Status);

            Assert.AreNotSame(original.State.AtxPower, clone.State.AtxPower);
            Assert.AreNotSame(original.State.CurrentTool, clone.State.CurrentTool);
            Assert.AreNotSame(original.State.Mode, clone.State.Mode);
            Assert.AreNotSame(original.State.Status, clone.State.Status);
        }
Example #16
0
        public void Assign()
        {
            MachineModel original = new MachineModel();

            Spindle spindle = new Spindle
            {
                Active  = 123.45F,
                Current = 45.678F
            };

            original.Spindles.Add(spindle);

            MachineModel assigned = new MachineModel();

            assigned.Assign(original);

            Assert.AreEqual(1, original.Spindles.Count);
            Assert.AreEqual(original.Spindles[0].Active, assigned.Spindles[0].Active);
            Assert.AreEqual(original.Spindles[0].Current, assigned.Spindles[0].Current);

            Assert.AreNotSame(original.Spindles[0].Active, assigned.Spindles[0].Active);
            Assert.AreNotSame(original.Spindles[0].Current, assigned.Spindles[0].Current);
        }
Example #17
0
        public void Assign()
        {
            MachineModel original = new MachineModel();

            Axis axis = new Axis
            {
                Homed           = true,
                Letter          = 'X',
                MachinePosition = 123,
                Min             = -789,
                MinEndstop      = 1,
                MinProbed       = true,
                Max             = 456,
                MaxEndstop      = 2,
                MaxProbed       = true
            };

            axis.Drives.Add(1);
            axis.Drives.Add(2);
            original.Move.Axes.Add(axis);
            original.Move.BabystepZ    = 0.34F;
            original.Move.Compensation = "Compensation";
            original.Move.CurrentMove.RequestedSpeed = 45;
            original.Move.CurrentMove.TopSpeed       = 30;

            Drive drive = new Drive
            {
                Acceleration = 12,
                Current      = 1200,
                MaxSpeed     = 400,
                MinSpeed     = 10,
                Position     = 56
            };

            drive.Microstepping.Interpolated = false;
            drive.Microstepping.Value        = 256;
            original.Move.Drives.Add(drive);

            Extruder extruder = new Extruder
            {
                Factor = 1.23F
            };

            extruder.Nonlinear.A           = 1;
            extruder.Nonlinear.B           = 2;
            extruder.Nonlinear.Temperature = 56;
            extruder.Nonlinear.UpperLimit  = 78;
            original.Move.Extruders.Add(extruder);

            original.Move.Geometry.Type = GeometryType.Delta;
            original.Move.Idle.Factor   = 0.8F;
            original.Move.Idle.Timeout  = 50;
            original.Move.SpeedFactor   = 1.45F;

            MachineModel assigned = new MachineModel();

            assigned.Assign(original);

            Assert.AreEqual(1, assigned.Move.Axes.Count);
            Assert.AreEqual(original.Move.Axes[0].Drives, assigned.Move.Axes[0].Drives);
            Assert.AreEqual(original.Move.Axes[0].Homed, assigned.Move.Axes[0].Homed);
            Assert.AreEqual(original.Move.Axes[0].Letter, assigned.Move.Axes[0].Letter);
            Assert.AreEqual(original.Move.Axes[0].MachinePosition, assigned.Move.Axes[0].MachinePosition);
            Assert.AreEqual(original.Move.Axes[0].Min, assigned.Move.Axes[0].Min);
            Assert.AreEqual(original.Move.Axes[0].MinEndstop, assigned.Move.Axes[0].MinEndstop);
            Assert.AreEqual(original.Move.Axes[0].MinProbed, assigned.Move.Axes[0].MinProbed);
            Assert.AreEqual(original.Move.Axes[0].Max, assigned.Move.Axes[0].Max);
            Assert.AreEqual(original.Move.Axes[0].MaxEndstop, assigned.Move.Axes[0].MaxEndstop);
            Assert.AreEqual(original.Move.Axes[0].MaxProbed, assigned.Move.Axes[0].MaxProbed);

            Assert.AreEqual(original.Move.BabystepZ, assigned.Move.BabystepZ);
            Assert.AreEqual(original.Move.Compensation, assigned.Move.Compensation);
            Assert.AreEqual(original.Move.CurrentMove.RequestedSpeed, assigned.Move.CurrentMove.RequestedSpeed);
            Assert.AreEqual(original.Move.CurrentMove.TopSpeed, assigned.Move.CurrentMove.TopSpeed);

            Assert.AreEqual(1, assigned.Move.Drives.Count);
            Assert.AreEqual(original.Move.Drives[0].Acceleration, assigned.Move.Drives[0].Acceleration);
            Assert.AreEqual(original.Move.Drives[0].Current, assigned.Move.Drives[0].Current);
            Assert.AreEqual(original.Move.Drives[0].MaxSpeed, assigned.Move.Drives[0].MaxSpeed);
            Assert.AreEqual(original.Move.Drives[0].Microstepping.Interpolated, assigned.Move.Drives[0].Microstepping.Interpolated);
            Assert.AreEqual(original.Move.Drives[0].Microstepping.Value, assigned.Move.Drives[0].Microstepping.Value);
            Assert.AreEqual(original.Move.Drives[0].MinSpeed, assigned.Move.Drives[0].MinSpeed);
            Assert.AreEqual(original.Move.Drives[0].Position, assigned.Move.Drives[0].Position);

            Assert.AreEqual(1, assigned.Move.Extruders.Count);
            Assert.AreEqual(original.Move.Extruders[0].Factor, assigned.Move.Extruders[0].Factor);
            Assert.AreEqual(original.Move.Extruders[0].Nonlinear.A, assigned.Move.Extruders[0].Nonlinear.A);
            Assert.AreEqual(original.Move.Extruders[0].Nonlinear.B, assigned.Move.Extruders[0].Nonlinear.B);
            Assert.AreEqual(original.Move.Extruders[0].Nonlinear.Temperature, assigned.Move.Extruders[0].Nonlinear.Temperature);
            Assert.AreEqual(original.Move.Extruders[0].Nonlinear.UpperLimit, assigned.Move.Extruders[0].Nonlinear.UpperLimit);

            Assert.AreEqual(original.Move.Geometry.Type, assigned.Move.Geometry.Type);
            Assert.AreEqual(original.Move.Idle.Factor, assigned.Move.Idle.Factor);
            Assert.AreEqual(original.Move.Idle.Timeout, assigned.Move.Idle.Timeout);
            Assert.AreEqual(original.Move.SpeedFactor, assigned.Move.SpeedFactor);
        }
Example #18
0
        public void Assign()
        {
            MachineModel original = new MachineModel();

            original.Job.Duration = 123;
            original.Job.ExtrudedRaw.Add(123F);
            original.Job.ExtrudedRaw.Add(456F);
            original.Job.ExtrudedRaw.Add(789F);
            original.Job.File.Filament = new List <float> {
                321F, 654F, 987F
            };
            original.Job.File.GeneratedBy   = "Generated by";
            original.Job.File.Height        = 57;
            original.Job.File.LayerHeight   = 0.43F;
            original.Job.File.FileName      = "0:/gcodes/somefile.g";
            original.Job.File.NumLayers     = 467;
            original.Job.File.PrintTime     = 4566;
            original.Job.File.SimulatedTime = 7964;
            original.Job.File.Size          = 4645645;
            original.Job.FilePosition       = 32423;
            original.Job.LastFileName       = "0:/gcodes/lastfile.g";
            original.Job.LastFileAborted    = true;
            original.Job.LastFileCancelled  = true;
            original.Job.LastFileSimulated  = true;
            original.Job.Layer = 4;

            original.Job.Layers.Add(new Layer
            {
                Duration = 23,
                Filament = new List <float> {
                    12F, 34F, 56F
                },
                FractionPrinted = 0.012F,
                Height          = 0.33F
            });

            original.Job.LayerTime          = 4.3F;
            original.Job.TimesLeft.Filament = 1234;
            original.Job.TimesLeft.File     = 234;
            original.Job.TimesLeft.Layer    = 345;
            original.Job.WarmUpDuration     = 34;

            MachineModel assigned = new MachineModel();

            assigned.Assign(original);

            Assert.AreEqual(original.Job.Duration, assigned.Job.Duration);
            Assert.AreEqual(original.Job.ExtrudedRaw, assigned.Job.ExtrudedRaw);
            Assert.AreEqual(original.Job.File.Filament, assigned.Job.File.Filament);
            Assert.AreEqual(original.Job.File.GeneratedBy, assigned.Job.File.GeneratedBy);
            Assert.AreEqual(original.Job.File.Height, assigned.Job.File.Height);
            Assert.AreEqual(original.Job.File.LayerHeight, assigned.Job.File.LayerHeight);
            Assert.AreEqual(original.Job.File.FileName, assigned.Job.File.FileName);
            Assert.AreEqual(original.Job.File.NumLayers, assigned.Job.File.NumLayers);
            Assert.AreEqual(original.Job.File.PrintTime, assigned.Job.File.PrintTime);
            Assert.AreEqual(original.Job.File.SimulatedTime, assigned.Job.File.SimulatedTime);
            Assert.AreEqual(original.Job.File.Size, assigned.Job.File.Size);
            Assert.AreEqual(original.Job.FilePosition, assigned.Job.FilePosition);
            Assert.AreEqual(original.Job.LastFileName, assigned.Job.LastFileName);
            Assert.AreEqual(original.Job.LastFileAborted, assigned.Job.LastFileAborted);
            Assert.AreEqual(original.Job.LastFileCancelled, assigned.Job.LastFileCancelled);
            Assert.AreEqual(original.Job.LastFileSimulated, assigned.Job.LastFileSimulated);
            Assert.AreEqual(original.Job.Layer, assigned.Job.Layer);

            Assert.AreEqual(1, original.Job.Layers.Count);
            Assert.AreEqual(original.Job.Layers[0].Duration, assigned.Job.Layers[0].Duration);
            Assert.AreEqual(original.Job.Layers[0].Filament, assigned.Job.Layers[0].Filament);
            Assert.AreEqual(original.Job.Layers[0].FractionPrinted, assigned.Job.Layers[0].FractionPrinted);
            Assert.AreEqual(original.Job.Layers[0].Height, assigned.Job.Layers[0].Height);

            Assert.AreEqual(original.Job.LayerTime, assigned.Job.LayerTime);
            Assert.AreEqual(original.Job.TimesLeft.Filament, assigned.Job.TimesLeft.Filament);
            Assert.AreEqual(original.Job.TimesLeft.File, assigned.Job.TimesLeft.File);
            Assert.AreEqual(original.Job.TimesLeft.Layer, assigned.Job.TimesLeft.Layer);
            Assert.AreEqual(original.Job.WarmUpDuration, assigned.Job.WarmUpDuration);
        }
        /// <summary>
        /// Task that keeps pushing model updates to the client
        /// </summary>
        /// <returns>Task that represents the lifecycle of a connection</returns>
        public override async Task Process()
        {
            try
            {
                // First send over the full machine model
                JObject currentObject, lastObject, patch = null;
                lock (_model)
                {
                    currentObject = lastObject = JObject.FromObject(_model, JsonHelper.DefaultSerializer);
                    _model.Messages.Clear();
                }
                await Connection.Send(currentObject.ToString(Formatting.None) + "\n");

                do
                {
                    // Wait for an acknowledgement from the client if anything was sent before
                    if (patch == null || patch.HasValues)
                    {
                        BaseCommand command = await Connection.ReceiveCommand();

                        if (command == null)
                        {
                            return;
                        }

                        if (!SupportedCommands.Contains(command.GetType()))
                        {
                            throw new ArgumentException($"Invalid command {command.Command} (wrong mode?)");
                        }
                    }

                    // Wait for another update
                    if (_mode == SubscriptionMode.Patch)
                    {
                        lastObject = currentObject;
                    }
                    await _updateAvailableEvent.WaitAsync(Program.CancelSource.Token);

                    // Get the updated object model
                    lock (_model)
                    {
                        using (Model.Provider.AccessReadOnly())
                        {
                            // NB: This could be further improved so that all the JSON tokens are written via the INotifyPropertyChanged events
                            _model.Assign(Model.Provider.Get);
                        }
                        lock (_messages)
                        {
                            ListHelpers.AssignList(_model.Messages, _messages);
                            _messages.Clear();
                        }
                        currentObject = JObject.FromObject(_model, JsonHelper.DefaultSerializer);
                    }

                    // Provide the model update
                    if (_mode == SubscriptionMode.Full)
                    {
                        // Send the entire object model in Full mode
                        await Connection.Send(currentObject.ToString(Formatting.None) + "\n");
                    }
                    else
                    {
                        // Only create a diff in Patch mode
                        patch = JsonHelper.DiffObject(lastObject, currentObject);

                        // Compact the job layers. There is no point in sending them all every time an update occurs
                        if (patch.ContainsKey("job") && patch.Value <JObject>("job").ContainsKey("layers"))
                        {
                            JArray layersArray = patch["job"].Value <JArray>("layers");
                            while (!layersArray[0].HasValues)
                            {
                                layersArray.RemoveAt(0);
                            }
                        }

                        // Send the patch unless it is empty
                        if (patch.HasValues)
                        {
                            await Connection.Send(patch.ToString(Formatting.None) + "\n");
                        }
                    }
                } while (!Program.CancelSource.IsCancellationRequested);
            }
            finally
            {
                lock (_subscriptions)
                {
                    _subscriptions.Remove(this);
                }
            }
        }
Example #20
0
        public void Assign()
        {
            MachineModel original = new MachineModel();

            original.Electronics.Type             = "Electronics Type";
            original.Electronics.Name             = "Electronics Name";
            original.Electronics.Revision         = "Electronics Revision";
            original.Electronics.Firmware.Name    = "Firmware Name";
            original.Electronics.Firmware.Version = "Firmware Version";
            original.Electronics.Firmware.Date    = "Firmware Date";
            original.Electronics.ProcessorID      = "Processor ID";
            original.Electronics.VIn.Current      = 321F;
            original.Electronics.VIn.Min          = 654F;
            original.Electronics.VIn.Max          = 987F;
            original.Electronics.McuTemp.Current  = 123F;
            original.Electronics.McuTemp.Min      = 456F;
            original.Electronics.McuTemp.Max      = 789F;

            ExpansionBoard expansionBoard = new ExpansionBoard
            {
                Name       = "Expansion Name",
                Revision   = "Expansion Revision",
                MaxHeaters = 12,
                MaxMotors  = 6
            };

            expansionBoard.Firmware.Name    = "Expansion Firmware Name";
            expansionBoard.Firmware.Date    = "Expansion Firmware Date";
            expansionBoard.Firmware.Version = "Expansion Firmware Version";
            expansionBoard.VIn.Current      = 321F;
            expansionBoard.VIn.Min          = 654F;
            expansionBoard.VIn.Max          = 987F;
            expansionBoard.McuTemp.Current  = 123F;
            expansionBoard.McuTemp.Min      = 456F;
            expansionBoard.McuTemp.Max      = 789F;
            expansionBoard.MaxHeaters       = 12;
            expansionBoard.MaxMotors        = 6;
            original.Electronics.ExpansionBoards.Add(expansionBoard);

            MachineModel assigned = new MachineModel();

            assigned.Assign(original);

            Assert.AreEqual(original.Electronics.Type, assigned.Electronics.Type);
            Assert.AreEqual(original.Electronics.Name, assigned.Electronics.Name);
            Assert.AreEqual(original.Electronics.Revision, assigned.Electronics.Revision);
            Assert.AreEqual(original.Electronics.Firmware.Name, assigned.Electronics.Firmware.Name);
            Assert.AreEqual(original.Electronics.Firmware.Version, assigned.Electronics.Firmware.Version);
            Assert.AreEqual(original.Electronics.Firmware.Date, assigned.Electronics.Firmware.Date);
            Assert.AreEqual(original.Electronics.ProcessorID, assigned.Electronics.ProcessorID);
            Assert.AreEqual(original.Electronics.VIn.Current, assigned.Electronics.VIn.Current);
            Assert.AreEqual(original.Electronics.VIn.Min, assigned.Electronics.VIn.Min);
            Assert.AreEqual(original.Electronics.VIn.Max, assigned.Electronics.VIn.Max);
            Assert.AreEqual(original.Electronics.McuTemp.Current, assigned.Electronics.McuTemp.Current);
            Assert.AreEqual(original.Electronics.McuTemp.Min, assigned.Electronics.McuTemp.Min);
            Assert.AreEqual(original.Electronics.McuTemp.Max, assigned.Electronics.McuTemp.Max);

            Assert.AreEqual(1, assigned.Electronics.ExpansionBoards.Count);
            Assert.AreEqual(original.Electronics.ExpansionBoards[0].Name, assigned.Electronics.ExpansionBoards[0].Name);
            Assert.AreEqual(original.Electronics.ExpansionBoards[0].Revision, assigned.Electronics.ExpansionBoards[0].Revision);
            Assert.AreEqual(original.Electronics.ExpansionBoards[0].Firmware.Name, assigned.Electronics.ExpansionBoards[0].Firmware.Name);
            Assert.AreEqual(original.Electronics.ExpansionBoards[0].Firmware.Date, assigned.Electronics.ExpansionBoards[0].Firmware.Date);
            Assert.AreEqual(original.Electronics.ExpansionBoards[0].Firmware.Version, assigned.Electronics.ExpansionBoards[0].Firmware.Version);
            Assert.AreEqual(original.Electronics.ExpansionBoards[0].VIn.Current, assigned.Electronics.ExpansionBoards[0].VIn.Current);
            Assert.AreEqual(original.Electronics.ExpansionBoards[0].VIn.Min, assigned.Electronics.ExpansionBoards[0].VIn.Min);
            Assert.AreEqual(original.Electronics.ExpansionBoards[0].VIn.Max, assigned.Electronics.ExpansionBoards[0].VIn.Max);
            Assert.AreEqual(original.Electronics.ExpansionBoards[0].McuTemp.Current, assigned.Electronics.ExpansionBoards[0].McuTemp.Current);
            Assert.AreEqual(original.Electronics.ExpansionBoards[0].McuTemp.Min, assigned.Electronics.ExpansionBoards[0].McuTemp.Min);
            Assert.AreEqual(original.Electronics.ExpansionBoards[0].McuTemp.Max, assigned.Electronics.ExpansionBoards[0].McuTemp.Max);
            Assert.AreEqual(original.Electronics.ExpansionBoards[0].MaxHeaters, assigned.Electronics.ExpansionBoards[0].MaxHeaters);
            Assert.AreEqual(original.Electronics.ExpansionBoards[0].MaxMotors, assigned.Electronics.ExpansionBoards[0].MaxMotors);

            // .NET Core supports string deduplication. This means AreNotSame assertions are (usually) meaningless:
            original.Electronics.Name = "Something else";
            Assert.AreNotSame(original.Electronics.Name, assigned.Electronics.Name);
        }
        public void Assign()
        {
            MachineModel original = new MachineModel();

            Endstop endstop = new Endstop
            {
                Position  = EndstopPosition.HighEnd,
                Triggered = true,
                Type      = EndstopType.MotorLoadDetection
            };

            original.Sensors.Endstops.Add(endstop);

            Probe probe = new Probe
            {
                DisablesBed   = true,
                DiveHeight    = 45.6F,
                Inverted      = true,
                MaxProbeCount = 4,
                RecoveryTime  = 0.65F,
                Speed         = 456,
                Threshold     = 678,
                Tolerance     = 0.42F,
                TravelSpeed   = 500,
                TriggerHeight = 1.23F,
                Type          = ProbeType.Switch,
                Value         = 45
            };

            probe.SecondaryValues.Add(12);
            probe.SecondaryValues.Add(34);
            original.Sensors.Probes.Add(probe);

            MachineModel assigned = new MachineModel();

            assigned.Assign(original);

            Assert.AreEqual(1, original.Sensors.Endstops.Count);
            Assert.AreEqual(original.Sensors.Endstops[0].Position, assigned.Sensors.Endstops[0].Position);
            Assert.AreEqual(original.Sensors.Endstops[0].Triggered, assigned.Sensors.Endstops[0].Triggered);
            Assert.AreEqual(original.Sensors.Endstops[0].Type, assigned.Sensors.Endstops[0].Type);

            Assert.AreEqual(1, original.Sensors.Probes.Count);
            Assert.AreEqual(original.Sensors.Probes[0].DisablesBed, assigned.Sensors.Probes[0].DisablesBed);
            Assert.AreEqual(original.Sensors.Probes[0].DiveHeight, assigned.Sensors.Probes[0].DiveHeight);
            Assert.AreEqual(original.Sensors.Probes[0].Inverted, assigned.Sensors.Probes[0].Inverted);
            Assert.AreEqual(original.Sensors.Probes[0].MaxProbeCount, assigned.Sensors.Probes[0].MaxProbeCount);
            Assert.AreEqual(original.Sensors.Probes[0].RecoveryTime, assigned.Sensors.Probes[0].RecoveryTime);
            Assert.AreEqual(original.Sensors.Probes[0].SecondaryValues, assigned.Sensors.Probes[0].SecondaryValues);
            Assert.AreEqual(original.Sensors.Probes[0].Speed, assigned.Sensors.Probes[0].Speed);
            Assert.AreEqual(original.Sensors.Probes[0].Threshold, assigned.Sensors.Probes[0].Threshold);
            Assert.AreEqual(original.Sensors.Probes[0].Tolerance, assigned.Sensors.Probes[0].Tolerance);
            Assert.AreEqual(original.Sensors.Probes[0].TravelSpeed, assigned.Sensors.Probes[0].TravelSpeed);
            Assert.AreEqual(original.Sensors.Probes[0].TriggerHeight, assigned.Sensors.Probes[0].TriggerHeight);
            Assert.AreEqual(original.Sensors.Probes[0].Type, assigned.Sensors.Probes[0].Type);
            Assert.AreEqual(original.Sensors.Probes[0].Value, assigned.Sensors.Probes[0].Value);

            Assert.AreNotSame(original.Sensors.Endstops[0].Position, assigned.Sensors.Endstops[0].Position);
            Assert.AreNotSame(original.Sensors.Endstops[0].Triggered, assigned.Sensors.Endstops[0].Triggered);
            Assert.AreNotSame(original.Sensors.Endstops[0].Type, assigned.Sensors.Endstops[0].Type);

            Assert.AreNotSame(original.Sensors.Probes[0].DisablesBed, assigned.Sensors.Probes[0].DisablesBed);
            Assert.AreNotSame(original.Sensors.Probes[0].DiveHeight, assigned.Sensors.Probes[0].DiveHeight);
            Assert.AreNotSame(original.Sensors.Probes[0].Inverted, assigned.Sensors.Probes[0].Inverted);
            Assert.AreNotSame(original.Sensors.Probes[0].MaxProbeCount, assigned.Sensors.Probes[0].MaxProbeCount);
            Assert.AreNotSame(original.Sensors.Probes[0].RecoveryTime, assigned.Sensors.Probes[0].RecoveryTime);
            Assert.AreNotSame(original.Sensors.Probes[0].SecondaryValues, assigned.Sensors.Probes[0].SecondaryValues);
            Assert.AreNotSame(original.Sensors.Probes[0].Speed, assigned.Sensors.Probes[0].Speed);
            Assert.AreNotSame(original.Sensors.Probes[0].Threshold, assigned.Sensors.Probes[0].Threshold);
            Assert.AreNotSame(original.Sensors.Probes[0].Tolerance, assigned.Sensors.Probes[0].Tolerance);
            Assert.AreNotSame(original.Sensors.Probes[0].TravelSpeed, assigned.Sensors.Probes[0].TravelSpeed);
            Assert.AreNotSame(original.Sensors.Probes[0].TriggerHeight, assigned.Sensors.Probes[0].TriggerHeight);
            Assert.AreNotSame(original.Sensors.Probes[0].Type, assigned.Sensors.Probes[0].Type);
            Assert.AreNotSame(original.Sensors.Probes[0].Value, assigned.Sensors.Probes[0].Value);
        }
Example #22
0
        public void Assigned()
        {
            MachineModel original = new MachineModel();

            BedOrChamber bed = new BedOrChamber
            {
                Name = "Bed Name"
            };

            bed.Active.Add(123F);
            bed.Standby.Add(456F);
            bed.Heaters.Add(0);
            original.Heat.Beds.Add(null);
            original.Heat.Beds.Add(bed);

            BedOrChamber chamber = new BedOrChamber
            {
                Name = "Chamber Name"
            };

            chamber.Active.Add(321F);
            chamber.Standby.Add(654F);
            chamber.Heaters.Add(4);
            chamber.Heaters.Add(6);
            original.Heat.Chambers.Add(null);
            original.Heat.Chambers.Add(chamber);

            original.Heat.ColdExtrudeTemperature = 678F;
            original.Heat.ColdRetractTemperature = 987F;

            ExtraHeater extraHeater = new ExtraHeater
            {
                Current = 123,
                Name    = "Extra Heater",
                Sensor  = 4,
                State   = HeaterState.Tuning
            };

            original.Heat.Extra.Add(extraHeater);

            Heater heater = new Heater
            {
                Current = 567,
                Max     = 578,
                Sensor  = 6,
                State   = HeaterState.Standby
            };

            heater.Model.DeadTime     = 322;
            heater.Model.Gain         = 673;
            heater.Model.MaxPwm       = 0.45F;
            heater.Model.TimeConstant = 32;
            original.Heat.Heaters.Add(heater);

            MachineModel assigned = new MachineModel();

            assigned.Assign(original);

            Assert.AreEqual(2, original.Heat.Beds.Count);
            Assert.AreEqual(original.Heat.Beds[0], null);
            Assert.AreEqual(original.Heat.Beds[1].Active, assigned.Heat.Beds[1].Active);
            Assert.AreEqual(original.Heat.Beds[1].Standby, assigned.Heat.Beds[1].Standby);
            Assert.AreEqual(original.Heat.Beds[1].Name, assigned.Heat.Beds[1].Name);
            Assert.AreEqual(original.Heat.Beds[1].Heaters, assigned.Heat.Beds[1].Heaters);

            Assert.AreEqual(2, original.Heat.Chambers.Count);
            Assert.AreEqual(original.Heat.Chambers[0], null);
            Assert.AreEqual(original.Heat.Chambers[1].Active, assigned.Heat.Chambers[1].Active);
            Assert.AreEqual(original.Heat.Chambers[1].Standby, assigned.Heat.Chambers[1].Standby);
            Assert.AreEqual(original.Heat.Chambers[1].Name, assigned.Heat.Chambers[1].Name);
            Assert.AreEqual(original.Heat.Chambers[1].Heaters, assigned.Heat.Chambers[1].Heaters);

            Assert.AreEqual(original.Heat.ColdExtrudeTemperature, assigned.Heat.ColdExtrudeTemperature);
            Assert.AreEqual(original.Heat.ColdRetractTemperature, assigned.Heat.ColdRetractTemperature);

            Assert.AreEqual(1, original.Heat.Extra.Count);
            Assert.AreEqual(original.Heat.Extra[0].Current, assigned.Heat.Extra[0].Current);
            Assert.AreEqual(original.Heat.Extra[0].Name, assigned.Heat.Extra[0].Name);
            Assert.AreEqual(original.Heat.Extra[0].Sensor, assigned.Heat.Extra[0].Sensor);
            Assert.AreEqual(original.Heat.Extra[0].State, assigned.Heat.Extra[0].State);

            Assert.AreEqual(1, original.Heat.Heaters.Count);
            Assert.AreEqual(original.Heat.Heaters[0].Current, assigned.Heat.Heaters[0].Current);
            Assert.AreEqual(original.Heat.Heaters[0].Max, assigned.Heat.Heaters[0].Max);
            Assert.AreEqual(original.Heat.Heaters[0].Sensor, assigned.Heat.Heaters[0].Sensor);
            Assert.AreEqual(original.Heat.Heaters[0].State, assigned.Heat.Heaters[0].State);
            Assert.AreEqual(original.Heat.Heaters[0].Model.DeadTime, assigned.Heat.Heaters[0].Model.DeadTime);
            Assert.AreEqual(original.Heat.Heaters[0].Model.Gain, assigned.Heat.Heaters[0].Model.Gain);
            Assert.AreEqual(original.Heat.Heaters[0].Model.MaxPwm, assigned.Heat.Heaters[0].Model.MaxPwm);
            Assert.AreEqual(original.Heat.Heaters[0].Model.TimeConstant, assigned.Heat.Heaters[0].Model.TimeConstant);
        }