Ejemplo n.º 1
0
        private void ResolveCertificatePaths(MachineConfiguration info)
        {
            var storePath = info.AuthConfig.StorePath;

            var caCertPath     = Path.Combine(storePath, DefaultCaCertName);
            var clientCertPath = Path.Combine(storePath, DefaultClientCertName);
            var clientKeyPath  = Path.Combine(storePath, DefaultClientKeyName);

            if (File.Exists(clientCertPath) && File.Exists(caCertPath) && File.Exists(clientKeyPath))
            {
                // Check if ca, client and key is in the store path
                // if so use those instead.
                Certificates = new CertificatePaths
                {
                    CaCertificate     = info.AuthConfig.CaCertPath,
                    ClientCertificate = info.AuthConfig.ClientCertPath,
                    ClientKey         = info.AuthConfig.ClientKeyPath
                };
                return;
            }

            // Otherwise use the defaults
            Certificates = new CertificatePaths
            {
                CaCertificate     = info.AuthConfig.CaCertPath,
                ClientCertificate = info.AuthConfig.ClientCertPath,
                ClientKey         = info.AuthConfig.ClientKeyPath
            };
        }
    public override void UserConfigLoad()
    {
        //** Define Machines/Presses and the MAC address for the ADAM Module
        //** Example
        //** var Z11 = AddMachine("Z-1-1","Press","FF-FF-FF-FF-FF")

        _defaultDepartment = "Test Department";

        MachineIsRunningGracePeriodInSeconds = 90;

        EmailServerConfiguration = new EmailServerConfiguration()
        {
            EmailServer     = "smtp.ipower.com",
            EmailServerPort = 587,
            Credentials     = ("*****@*****.**", "Betz-320")
        };

        DatabaseConfiguration = new DatabaseConfiguration("172.16.28.250", "RALSystem", "1234", "TRMI_RAL_System_Dev");

        var listOfStackLightConfigs = new StackLightConfiguration[]
        {
            AddStackLight("172.16.28.151", "Row 1 Stack Light"),
            AddStackLight("172.16.28.152", "Row 2 Stack Light"),
            AddStackLight("172.16.28.153", "Row 3 Stack Light"),
            AddStackLight("172.16.28.154", "Row 4 Stack Light"),
            AddStackLight("172.16.28.155", "Row 5 Stack Light"),
            AddStackLight("172.16.28.156", "Row 6 Stack Light"),
            AddStackLight("172.16.28.157", "Row 7 Stack Light"),
            AddStackLight("172.16.28.158", "Row 8 Stack Light")
        };

        int Converter         = 0;
        int StackLightNumber  = 0;
        int LightOnStackLight = 0;

        for (int i = 0; i < 40; i++)
        {
            Converter         = Converter < 8 ? Converter : 0;
            StackLightNumber  = LightOnStackLight < 5 ? StackLightNumber : ++StackLightNumber;
            LightOnStackLight = LightOnStackLight < 5 ? LightOnStackLight : 0;

            string MAC = "00-D0-C9-FC-A9-BA";
            if (i >= 36)
            {
                if (i == 36)
                {
                    Converter = 0;
                }
                MAC = "00-D0-C9-FC-A9-C0";
            }
            var Press = new MachineConfiguration($"Test Line {i + 1}", "Press", MAC, _defaultDepartment, new RAL.Devices.Adam.Mocks.Adam6051StatusConverterForPressMock(Converter++ + 1));
            MachineConfigs.Add(Press);

            AddLightToMachineMap(Press, (StackLight5Lights.LightNumber)LightOnStackLight++, listOfStackLightConfigs[StackLightNumber]);
        }


        AddEmailReport(new [] { "*****@*****.**" }, new[] { "*****@*****.**" });
    }
        public LambdaStateChangedHandlerTests()
        {
            _config = new MachineConfiguration<TestArgs>();

            var args = new TestArgs();
            var stateProvider = new ScanningStateProvider<TestArgs>();

            _machine = new StateMachine<TestArgs>(_config, stateProvider, args);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Create a new machine configuration representation in memory from a file on disk
        /// </summary>
        /// <param name="PathToFile">The path to the configuration XML file</param>
        public void LoadConfig(string PathToFile)
        {
            MachineConfiguration config = MachineConfiguration.FromFile(PathToFile);

            _config          = config;
            _num_balls_total = config.PRGame.numBalls;

            //setup machine items
            (PROC as ProcDevice).SetupProcMachine(config, _coils, _switches, _lamps, _leds, _gi);
        }
Ejemplo n.º 5
0
        private void btnAddMachine_Click(object sender, EventArgs e)
        {
            var newMachine = new MachineConfiguration();

            newMachine.MachineName       = "HostName";
            newMachine.UserName          = "******";
            newMachine.Password          = "******";
            newMachine.NextConnectionDue = DateTime.Now;
            newMachine.LastKnownStatus   = "Just Added";
            Machines.Add(newMachine);
        }
        public void AddTwoMachineConfigurationsWithSameMachineName()
        {
            MachineConfiguration machineConfiguration1 = new MachineConfiguration("Machine A", new ProductionStop[] { productionStop1, productionStop2 });
            MachineConfiguration machineConfiguration2 = new MachineConfiguration("Machine A", new ProductionStop[] { productionStop1, productionStop2 });

            using (IEntityRepository<MachineConfiguration> repository = factory.CreateEntityRepository<MachineConfiguration>())
            {
                repository.Save(machineConfiguration1);
                repository.Save(machineConfiguration2);
            }
        }
Ejemplo n.º 7
0
        public void Load()
        {
            machineConfiguration = LoadMachineConfiguration();

            List<ProductionStopViewEntity> productionStops = new List<ProductionStopViewEntity>();
            foreach (ProductionStop p in machineConfiguration.AvailableProductionStops)
            {
                if (p != null)
                    productionStops.Add(new ProductionStopViewEntity(p));
            }

            productionStopViewEntityBindingSource.DataSource = productionStops;
        }
        public void AddNewMachineConfigurations()
        {
            MachineConfiguration machineConfiguration1 = new MachineConfiguration("Machine A", new ProductionStop[] { productionStop1, productionStop2 });
            MachineConfiguration machineConfiguration2 = new MachineConfiguration("Machine B", new ProductionStop[] { productionStop1, productionStop2 });

            using (IEntityRepository<MachineConfiguration> repository = factory.CreateEntityRepository<MachineConfiguration>())
            {
                repository.Save(machineConfiguration1);
                repository.Save(machineConfiguration2);
            }

            Assert.AreNotEqual(machineConfiguration1.Id, machineConfiguration2.Id);
        }
Ejemplo n.º 9
0
        public static StateMachine<CreditRequest> Create(CreditRequest request)
        {
            var provider = new ScanningStateProvider<CreditRequest>();
            var config = new MachineConfiguration<CreditRequest>();
            config.OnStateChange(
                reset: (sender, args) => args.Switches.State = args.Next.GetType(),
                enter: (sender, args) => args.Switches.State = args.Next.GetType()
            );

            var machine = new StateMachine<CreditRequest>(config, provider, request);
            machine.ResetTo(request.State);

            return machine;
        }
        public void AddNewMachineConfiguration()
        {
            MachineConfiguration machineConfiguration = new MachineConfiguration("Machine A", new ProductionStop[] { productionStop1, productionStop2 });

            Assert.AreEqual(0, machineConfiguration.Id);
            Assert.AreEqual(0, machineConfiguration.Version);

            using (IEntityRepository<MachineConfiguration> repository = factory.CreateEntityRepository<MachineConfiguration>())
            {
                repository.Save(machineConfiguration);
            }

            Assert.AreNotEqual(0, machineConfiguration.Id);
            Assert.AreNotEqual(0, machineConfiguration.Version);
        }
Ejemplo n.º 11
0
 public void GetGlobals(MachineConfiguration config)
 {
     if (config.PRDriverGlobals != null)
     {
         lamp_matrix_strobe_time = config.PRDriverGlobals.lamp_matrix_strobe_time;
         watchdog_time           = config.PRDriverGlobals.watchdog_time;
         use_watchdog            = config.PRDriverGlobals.use_watchdog;
     }
     else
     {
         lamp_matrix_strobe_time = 200;
         watchdog_time           = 1000;
         use_watchdog            = true;
     }
 }
Ejemplo n.º 12
0
        static async Task Main(string[] args)
        {
            ProcDevice PROC = null;

            try
            {
                Console.WriteLine("Creating PROC");
                PROC = new ProcDevice(MachineType.PDB);
                await Task.Delay(100);

                PROC?.Reset(1);

                //load machine config.
                var config = MachineConfiguration.FromFile("machine.json");

                //create collections to pass into the setup.
                //The GameController does this for you in LoadConfig, but this is to test without a game
                _switches = new AttrCollection <ushort, string, Switch>();
                _leds     = new AttrCollection <ushort, string, LED>();
                _coils    = new AttrCollection <ushort, string, IDriver>();

                //setup machine items to be able to process events.
                (PROC as ProcDevice).SetupProcMachine(config, _switches: _switches, _leds: _leds, _coils: _coils);

                //listen for cancel keypress and end run loop
                Console.CancelKeyPress += (sender, eventArgs) =>
                {
                    Console.WriteLine("ctrl+C triggered");
                    source.Cancel();
                    eventArgs.Cancel = true;
                };



                //run game loop
                await RunLoop(PROC);

                //close console
                Console.WriteLine("netprocgame closing...");
                await Task.Delay(500);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Ejemplo n.º 13
0
        public void When_finding_custom_states()
        {
            var scanner = new ScanningStateProvider<CreditRequest>();
            var provider = new MappingStateProvider(scanner);

            var config = new MachineConfiguration<CreditRequest>();
            config.OnStateChange(
                reset: (sender, args) => args.Switches.Progress = ((CustomState<CreditRequest>)args.Next).Type,
                enter: (sender, args) => args.Switches.Progress = ((CustomState<CreditRequest>)args.Next).Type
            );

            var request = LoadFromDatabase();

            var machine = new StateMachine<CreditRequest>(provider, request);
            machine.ResetTo(provider.StateFrom(request.Progress).GetType());

            machine.CurrentState.ShouldBeOfType<Approved>();
        }
Ejemplo n.º 14
0
        private static MachineConfiguration AddMachineConfiguration(DeviceElement adaptDeviceElement, DeviceElementHierarchy deviceHierarchy, AgGateway.ADAPT.ApplicationDataModel.ADM.Catalog catalog)
        {
            MachineConfiguration machineConfig = new MachineConfiguration();

            //Description
            machineConfig.Description = $"{deviceHierarchy.DeviceElement.Device.DeviceDesignator} : {deviceHierarchy.DeviceElement.DeviceElementDesignator}";

            //Device Element ID
            machineConfig.DeviceElementId = adaptDeviceElement.Id.ReferenceId;

            //Offsets
            if (deviceHierarchy.XOffset.HasValue ||
                deviceHierarchy.YOffset.HasValue ||
                deviceHierarchy.ZOffset.HasValue)
            {
                machineConfig.Offsets = new List <NumericRepresentationValue>();
                if (deviceHierarchy.XOffset != null)
                {
                    machineConfig.Offsets.Add(deviceHierarchy.XOffsetRepresentation);
                }
                if (deviceHierarchy.YOffset != null)
                {
                    machineConfig.Offsets.Add(deviceHierarchy.YOffsetRepresentation);
                }
                if (deviceHierarchy.ZOffset != null)
                {
                    machineConfig.Offsets.Add(deviceHierarchy.ZOffsetRepresentation);
                }
            }

            //GPS Offsets
            if (deviceHierarchy.Children != null && deviceHierarchy.Children.Any(h => h.DeviceElement != null && h.DeviceElement.DeviceElementType == ISODeviceElementType.Navigation))
            {
                DeviceElementHierarchy navigation = (deviceHierarchy.Children.First(h => h.DeviceElement.DeviceElementType == ISODeviceElementType.Navigation));
                machineConfig.GpsReceiverXOffset = navigation.XOffsetRepresentation;
                machineConfig.GpsReceiverYOffset = navigation.YOffsetRepresentation;
                machineConfig.GpsReceiverZOffset = navigation.ZOffsetRepresentation;
            }


            catalog.DeviceElementConfigurations.Add(machineConfig);
            return(machineConfig);
        }
Ejemplo n.º 15
0
        // Constructor
        public Machine(IDevice device, GatewayHubHandler gatewayHubCommunication, MachineConfiguration machineConfiguration)
        {
            _device = device;
            _machineStateStarted = DateTime.Now;

            MachineConfiguration     = machineConfiguration;
            _gatewayHubCommunication = gatewayHubCommunication;

            device.Inputs[machineConfiguration.CycleInputPin].InputChanged += InputInterpretation;
            CurrentMachineState = DataAccess.MachineStateHistory.State.Stopped;
            LastMachineStateInMachineStateHistory = DataAccess.MachineStateHistory.State.Stopped;

            MachineStateHistory = new List <MachineStateHistory>();

            _timerCycleTimeOut = ThreadPoolTimer.CreatePeriodicTimer(CycleTimeOut,
                                                                     TimeSpan.FromMilliseconds(machineConfiguration.MachineStateTimeout));

            _timerMachineDataPublish = ThreadPoolTimer.CreatePeriodicTimer(PublishActualMachineData,
                                                                           TimeSpan.FromMilliseconds(machineConfiguration.PublishingIntervall));
        }
        public void DeleteMachineConfigurations()
        {
            MachineConfiguration machineConfiguration1 = new MachineConfiguration("Machine A", new ProductionStop[] { productionStop1, productionStop2 });
            MachineConfiguration machineConfiguration2 = new MachineConfiguration("Machine B", new ProductionStop[] { productionStop1, productionStop2 });

            using (IEntityRepository<MachineConfiguration> repository = factory.CreateEntityRepository<MachineConfiguration>())
            {
                repository.Save(machineConfiguration1);
                repository.Save(machineConfiguration2);
            }

            List<MachineConfiguration> list = null;
            using (IEntityRepository<MachineConfiguration> repository = factory.CreateEntityRepository<MachineConfiguration>())
            {
                list = new List<MachineConfiguration>(repository.LoadAll());
            }
            CollectionAssert.AreEquivalent(new MachineConfiguration[] { machineConfiguration1, machineConfiguration2 }, list);

            using (IEntityRepository<MachineConfiguration> repository = factory.CreateEntityRepository<MachineConfiguration>())
            {
                repository.Delete(machineConfiguration2);
            }
            using (IEntityRepository<MachineConfiguration> repository = factory.CreateEntityRepository<MachineConfiguration>())
            {
                list = new List<MachineConfiguration>(repository.LoadAll());
            }
            CollectionAssert.AreEquivalent(new MachineConfiguration[] { machineConfiguration1 }, list);

            using (IEntityRepository<MachineConfiguration> repository = factory.CreateEntityRepository<MachineConfiguration>())
            {
                repository.Delete(machineConfiguration1);
            }
            using (IEntityRepository<MachineConfiguration> repository = factory.CreateEntityRepository<MachineConfiguration>())
            {
                list = new List<MachineConfiguration>(repository.LoadAll());
            }
            CollectionAssert.AreEquivalent(new MachineConfiguration[] { }, list);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Create a new machine configuration representation in memory from a file on disk
        /// </summary>
        /// <param name="PathToFile">The path to the configuration XML file</param>
        public void LoadConfig(string PathToFile)
        {
            MachineConfiguration config = MachineConfiguration.FromFile(PathToFile);

            foreach (CoilConfigFileEntry ce in config.PRCoils)
            {
                Driver d = new Driver(this, ce.Name, PinProc.PRDecode(_machineType, ce.Number));
                Log("Adding driver " + d.ToString());
                _coils.Add(d.Number, d.Name, d);
            }

            foreach (LampConfigFileEntry le in config.PRLamps)
            {
                Driver d = new Driver(this, le.Name, PinProc.PRDecode(_machineType, le.Number));
                Log("Adding lamp " + d.ToString());
                _lamps.Add(d.Number, d.Name, d);
            }

            foreach (GIConfigFileEntry ge in config.PRGI)
            {
                Driver d = new Driver(this, ge.Name, PinProc.PRDecode(_machineType, ge.Number));
                _gi.Add(d.Number, d.Name, d);
            }

            foreach (SwitchConfigFileEntry se in config.PRSwitches)
            {
                Switch s = new Switch(this, se.Name, PinProc.PRDecode(_machineType, se.Number), se.Type);

                _proc.switch_update_rule(s.Number,
                                         EventType.SwitchClosedDebounced,
                                         new SwitchRule {
                    NotifyHost = true, ReloadActive = false
                },
                                         null,
                                         false
                                         );
                _proc.switch_update_rule(s.Number,
                                         EventType.SwitchOpenDebounced,
                                         new SwitchRule {
                    NotifyHost = true, ReloadActive = false
                },
                                         null,
                                         false
                                         );
                Log("Adding switch " + s.ToString());
                _switches.Add(s.Number, s.Name, s);
            }

            /// TODO: THIS SHOULD RETURN A LIST OF STATES
            EventType[] states = _proc.switch_get_states();
            foreach (Switch s in _switches.Values)
            {
                s.SetState(states[s.Number] == EventType.SwitchClosedDebounced);
            }

            _num_balls_total = config.PRGame.numBalls;
            _config          = config;

            if (_config.PRGame.displayMonitor)
            {
            }
        }
Ejemplo n.º 18
0
        private void ExportDeviceProperties(ISODeviceElement isoDeviceElement, DeviceElement adaptDeviceElement)
        {
            //Connectors
            if (isoDeviceElement.ChildDeviceElements != null)
            {
                foreach (ISODeviceElement connectorElement in isoDeviceElement.ChildDeviceElements.Where(d => d.DeviceElementType == ISODeviceElementType.Connector))
                {
                    int?connectorID = TaskDataMapper.InstanceIDMap.GetADAPTID(connectorElement.DeviceElementId);
                    if (connectorID.HasValue)
                    {
                        Connector  connector = DataModel.Catalog.Connectors.First(c => c.Id.ReferenceId == connectorID.Value);
                        HitchPoint hitch     = DataModel.Catalog.HitchPoints.FirstOrDefault(h => h.Id.ReferenceId == connector.HitchPointId);
                        if (hitch != null && hitch.ReferencePoint != null)
                        {
                            ExportDeviceProperty(connectorElement, hitch.ReferencePoint.XOffset, ++_devicePropertyObjectID);
                            ExportDeviceProperty(connectorElement, hitch.ReferencePoint.YOffset, ++_devicePropertyObjectID);
                            ExportDeviceProperty(connectorElement, hitch.ReferencePoint.ZOffset, ++_devicePropertyObjectID);
                        }
                    }
                }
            }

            //Device Element Widths & Offsets
            IEnumerable <DeviceElementConfiguration> configs = DataModel.Catalog.DeviceElementConfigurations.Where(c => c.DeviceElementId == adaptDeviceElement.Id.ReferenceId);

            foreach (DeviceElementConfiguration config in configs)
            {
                if (config is MachineConfiguration)
                {
                    MachineConfiguration machineConfig     = config as MachineConfiguration;
                    ISODeviceElement     navigationElement = isoDeviceElement.Device.DeviceElements.FirstOrDefault(d => d.DeviceElementType == ISODeviceElementType.Navigation);
                    if (navigationElement == null)
                    {
                        if (machineConfig.GpsReceiverXOffset != null)
                        {
                            ExportDeviceProperty(navigationElement, machineConfig.GpsReceiverXOffset, ++_devicePropertyObjectID);
                        }
                        if (machineConfig.GpsReceiverYOffset != null)
                        {
                            ExportDeviceProperty(navigationElement, machineConfig.GpsReceiverYOffset, ++_devicePropertyObjectID);
                        }
                        if (machineConfig.GpsReceiverZOffset != null)
                        {
                            ExportDeviceProperty(navigationElement, machineConfig.GpsReceiverZOffset, ++_devicePropertyObjectID);
                        }
                    }
                }
                else if (config is ImplementConfiguration)
                {
                    ImplementConfiguration implementConfig = config as ImplementConfiguration;
                    if (implementConfig.Width != null)
                    {
                        ExportDeviceProperty(isoDeviceElement, implementConfig.Width, ++_devicePropertyObjectID);
                    }
                    if (implementConfig.Offsets != null)
                    {
                        implementConfig.Offsets.ForEach(o => ExportDeviceProperty(isoDeviceElement, o, ++_devicePropertyObjectID));
                    }
                }
                else if (config is SectionConfiguration)
                {
                    SectionConfiguration sectionConfig = config as SectionConfiguration;
                    if (sectionConfig.InlineOffset != null)
                    {
                        ExportDeviceProperty(isoDeviceElement, sectionConfig.InlineOffset, ++_devicePropertyObjectID);
                    }
                    if (sectionConfig.LateralOffset != null)
                    {
                        ExportDeviceProperty(isoDeviceElement, sectionConfig.LateralOffset, ++_devicePropertyObjectID);
                    }
                    if (sectionConfig.SectionWidth != null)
                    {
                        ExportDeviceProperty(isoDeviceElement, sectionConfig.SectionWidth, ++_devicePropertyObjectID);
                    }
                }
            }
        }
        public void LoadMachineConfiguration()
        {
            MachineConfiguration machineConfiguration1 = new MachineConfiguration("Machine A", new ProductionStop[] { productionStop1, productionStop2 });
            MachineConfiguration machineConfiguration2 = new MachineConfiguration("Machine B", new ProductionStop[] { productionStop2, productionStop1 });

            using (IEntityRepository<MachineConfiguration> repository = factory.CreateEntityRepository<MachineConfiguration>())
            {
                repository.Save(machineConfiguration1);
                repository.Save(machineConfiguration2);
            }

            using (IEntityRepository<MachineConfiguration> repository = factory.CreateEntityRepository<MachineConfiguration>())
            {
                foreach (MachineConfiguration machineConfiguration in new MachineConfiguration[] { machineConfiguration1, machineConfiguration2 })
                {
                    MachineConfiguration loadedMachineConfiguration = repository.Load(machineConfiguration.Id);

                    Assert.AreNotSame(machineConfiguration, loadedMachineConfiguration);
                    Assert.AreEqual(machineConfiguration, loadedMachineConfiguration);
                    Assert.AreEqual(machineConfiguration.MachineName, loadedMachineConfiguration.MachineName);
                    CollectionAssert.AreEqual(new List<ProductionStop>(machineConfiguration.AvailableProductionStops), new List<ProductionStop>(loadedMachineConfiguration.AvailableProductionStops));
                }
            }
        }
Ejemplo n.º 20
0
        private void LoadEntities()
        {
            _repositoryFactory = new RepositoryFactory();

            using (IEntityRepository<ProductionTeam> productionTeamRepository = _repositoryFactory.CreateEntityRepository<ProductionTeam>())
            {
                _availableTeams = productionTeamRepository.LoadAll();
            }

            using (IEntityRepository<MachineConfiguration> repository = _repositoryFactory.CreateEntityRepository<MachineConfiguration>())
            {
                List<MachineConfiguration> list = new List<MachineConfiguration>(repository.LoadAll());
                if (list.Count > 0)
                    _machineConfiguration = list[0];
                else
                    _machineConfiguration = new MachineConfiguration(Strings.UnknownMachine, new ProductionStop[0]);
            }
        }
        public void UpdateMachineConfiguration()
        {
            MachineConfiguration machineConfiguration = new MachineConfiguration("Machine A", new ProductionStop[] { productionStop1, productionStop2 });

            using (IEntityRepository<MachineConfiguration> repository = factory.CreateEntityRepository<MachineConfiguration>())
            {
                repository.Save(machineConfiguration);
            }

            machineConfiguration.MachineName = "Machine B";
            machineConfiguration.AvailableProductionStops = new ProductionStop[] { productionStop1 };

            using (IEntityRepository<MachineConfiguration> repository = factory.CreateEntityRepository<MachineConfiguration>())
            {
                repository.Save(machineConfiguration);
            }

            using (IEntityRepository<MachineConfiguration> repository = factory.CreateEntityRepository<MachineConfiguration>())
            {
                MachineConfiguration loadedMachineConfiguration = repository.Load(machineConfiguration.Id);

                Assert.AreNotSame(machineConfiguration, loadedMachineConfiguration);
                Assert.AreEqual(machineConfiguration, loadedMachineConfiguration);
                Assert.AreEqual(machineConfiguration.MachineName, loadedMachineConfiguration.MachineName);
                CollectionAssert.AreEqual(new List<ProductionStop>(machineConfiguration.AvailableProductionStops), new List<ProductionStop>(loadedMachineConfiguration.AvailableProductionStops));
            }
        }
Ejemplo n.º 22
0
        public void SetWidthsAndOffsetsFromSpatialData(IEnumerable <ISOSpatialRow> isoRecords, DeviceElementConfiguration config, RepresentationMapper representationMapper)
        {
            //Set values on this object and associated DeviceElementConfiguration
            if (Width == null)
            {
                Width = GetWidthFromSpatialData(isoRecords, DeviceElement.DeviceElementId, representationMapper);
            }

            if (config.Offsets == null)
            {
                config.Offsets = new List <NumericRepresentationValue>();
            }

            if (XOffset == null)
            {
                XOffset = GetXOffsetFromSpatialData(isoRecords, DeviceElement.DeviceElementId, representationMapper);
                if (XOffsetRepresentation != null)
                {
                    config.Offsets.Add(XOffsetRepresentation);
                }
            }

            if (YOffset == null)
            {
                YOffset = GetYOffsetFromSpatialData(isoRecords, DeviceElement.DeviceElementId, representationMapper);
                if (YOffsetRepresentation != null)
                {
                    config.Offsets.Add(YOffsetRepresentation);
                }
            }

            if (ZOffset == null)
            {
                ZOffset = GetZOffsetFromSpatialData(isoRecords, DeviceElement.DeviceElementId, representationMapper);
                if (ZOffsetRepresentation != null)
                {
                    config.Offsets.Add(ZOffsetRepresentation);
                }
            }

            //Update config values as appropriate
            if (this.DeviceElement.DeviceElementType == ISODeviceElementType.Navigation)
            {
                MachineConfiguration machineConfig = config as MachineConfiguration;
                if (machineConfig.GpsReceiverXOffset == null)
                {
                    machineConfig.GpsReceiverXOffset = XOffsetRepresentation;
                }
                if (machineConfig.GpsReceiverYOffset == null)
                {
                    machineConfig.GpsReceiverYOffset = YOffsetRepresentation;
                }
                if (machineConfig.GpsReceiverZOffset == null)
                {
                    machineConfig.GpsReceiverZOffset = ZOffsetRepresentation;
                }
            }
            else
            {
                if (config is SectionConfiguration)
                {
                    SectionConfiguration sectionConfig = config as SectionConfiguration;
                    if (sectionConfig.SectionWidth == null)
                    {
                        sectionConfig.SectionWidth = WidthRepresentation;
                    }
                    if (sectionConfig.InlineOffset == null)
                    {
                        sectionConfig.InlineOffset = XOffsetRepresentation;
                    }
                    if (sectionConfig.LateralOffset == null)
                    {
                        sectionConfig.LateralOffset = YOffsetRepresentation;
                    }
                }
                else if (config is ImplementConfiguration)
                {
                    ImplementConfiguration implementConfig = config as ImplementConfiguration;
                    if (implementConfig.Width == null)
                    {
                        implementConfig.Width = WidthRepresentation;
                    }
                }
            }
        }
        public static void DescribeImplement(Catalog catalog, LoggedData loggedData)
        {
            Console.WriteLine();
            Console.WriteLine("-----------------------");
            Console.WriteLine("Equipment Configuration");
            Console.WriteLine("-----------------------");
            Console.WriteLine();


            //A LoggedData will have a single EquipmentConfigurationGroup that contains any EquipmentConfigurations in the file
            EquipmentConfigurationGroup equipConfigGroup = loggedData.EquipmentConfigurationGroup;

            //The configuration of the equipment can vary by each region, although it is likely that the equipment configuration remains consistent across many regions
            //Any distinct configurations represented in the field operation will be EquipmentConfigurations within this group
            List <EquipmentConfiguration> distinctConfigurations = equipConfigGroup.EquipmentConfigurations;

            Console.WriteLine($"Field operation has {distinctConfigurations.Count} distinct equipment configuration(s).");
            Console.WriteLine();

            //While a single OperationData object supports a list of EquipmentConfigurations, the 2020 plugin will always reference a single EquipmentConfiguration on any one OperationData.
            //This allows the consumer to predictively map data based a known equipment definition for that data.

            //Going deeper on the first OperationData
            Console.WriteLine("The first region and OperationData within the field operation has this configuration:");
            EquipmentConfiguration equipConfig = distinctConfigurations.SingleOrDefault(c => c.Id.ReferenceId == loggedData.OperationData.First().EquipmentConfigurationIds.Single());

            //The equipment configuration maps to 2 connectors, explaining what machinery was hitched together
            Connector connector1 = catalog.Connectors.SingleOrDefault(c => c.Id.ReferenceId == equipConfig.Connector1Id);
            Connector connector2 = catalog.Connectors.SingleOrDefault(c => c.Id.ReferenceId == equipConfig.Connector2Id);

            //Each connector contains two pieces of information, the DeviceElementConfiguration that connector/hitch is a part of, and metadata on a specific hitch point.
            DeviceElementConfiguration deviceElementConfiguration1 = catalog.DeviceElementConfigurations.SingleOrDefault(c => c.Id.ReferenceId == connector1.DeviceElementConfigurationId);
            HitchPoint hitchPoint1 = catalog.HitchPoints.SingleOrDefault(h => h.Id.ReferenceId == connector1.HitchPointId);

            DeviceElementConfiguration deviceElementConfiguration2 = catalog.DeviceElementConfigurations.SingleOrDefault(c => c.Id.ReferenceId == connector2.DeviceElementConfigurationId);
            HitchPoint hitchPoint2 = catalog.HitchPoints.SingleOrDefault(h => h.Id.ReferenceId == connector2.HitchPointId);

            //DeviceElementConfigurations are a polymorphic object within ADAPT.
            //A DeviceElementConfiguration may be of type
            //  MachineConfiguration (describing a tractor/vehicle)
            //  ImplementConfiguration (describing an entire implement)
            //  SectionConfiguration (describing a subsection or individual row of an implement)

            //DeviceElementConfigurations are part of a 3-object hierarchy that describes a piece of equipment
            //1. DeviceModel - A high-level description of the equipment: brand, manufacturer, description.   Any single piece of equipment has only 1 device model.
            //2. DeviceElement -A hierarchical descripion part of the equipment: brand, manufacturer, description, and type of element (section, machine, implement, etc.).
            //                  A DeviceElement maps to a single DeviceModel, and may be a parent and/or child of other DeviceElements.
            //                  E.g., each section is a child of the root implement DeviceElement
            //3. DeviceElementConfigurations - The DeviceElementConfiguration is an extension of the DeviceElement, each mapping to a single DeviceElement,
            //                                  but having specific phyproperties such as width and offsets.

            //The 2020 equipment configuration will always have a Machine/Vehicle as the Connector1 and an Implement as the Connector2.
            MachineConfiguration   vehicleConfiguration   = deviceElementConfiguration1 as MachineConfiguration;
            ImplementConfiguration implementConfiguration = deviceElementConfiguration2 as ImplementConfiguration;

            HitchPoint vehicleHitch   = hitchPoint1;
            HitchPoint implementHitch = hitchPoint2;

            //The DeviceElements expose the hierarchy between parts of the equipment
            Console.WriteLine();
            Console.WriteLine("Vehicle DeviceElement Hierarchy:");
            DeviceElement vehicleDeviceElement = catalog.DeviceElements.SingleOrDefault(d => d.Id.ReferenceId == vehicleConfiguration.DeviceElementId);

            DescribeDeviceHierarchy(catalog, vehicleDeviceElement, 0, new List <DeviceElement>());

            Console.WriteLine();
            Console.WriteLine("Implement DeviceElement Hierarchy:");
            List <DeviceElement> implementChildElements = new List <DeviceElement>();
            DeviceElement        implementDeviceElement = catalog.DeviceElements.SingleOrDefault(d => d.Id.ReferenceId == implementConfiguration.DeviceElementId);

            DescribeDeviceHierarchy(catalog, implementDeviceElement, 0, implementChildElements);

            Console.WriteLine();


            Console.WriteLine();
            Console.WriteLine("-----------------------");
            Console.WriteLine("Implement Width Values");
            Console.WriteLine("-----------------------");
            Console.WriteLine();

            //The Implement and Section DeviceElementConfigurations carry width information.
            Console.WriteLine($"The {implementConfiguration.Description} is {implementConfiguration.PhysicalWidth.Value.Value} {implementConfiguration.PhysicalWidth.Value.UnitOfMeasure.Code} wide.");
            foreach (DeviceElement childElement in implementChildElements)
            {
                DeviceElementConfiguration deviceElementConfiguration = catalog.DeviceElementConfigurations.SingleOrDefault(c => c.DeviceElementId == childElement.Id.ReferenceId);
                if (deviceElementConfiguration != null)
                {
                    SectionConfiguration sectionConfiguration = deviceElementConfiguration as SectionConfiguration;
                    if (sectionConfiguration != null)
                    {
                        Console.WriteLine($"{sectionConfiguration.Description} is {sectionConfiguration.SectionWidth.Value.Value} {sectionConfiguration.SectionWidth.Value.UnitOfMeasure.Code} wide.");
                    }
                }
            }


            Console.WriteLine();
            Console.WriteLine("-----------------------");
            Console.WriteLine("Equipment Offset Values");
            Console.WriteLine("-----------------------");
            Console.WriteLine();

            //Various offset values describe where each device element is located vs. other elements via data on the device element configuration

            //Vehicle GPS Receiver
            DescribeOffset("GPS Receiver", vehicleConfiguration.GpsReceiverXOffset, vehicleConfiguration.GpsReceiverYOffset, "tractor reference point (center of rear axle)");

            //Tractor hitch offset
            DescribeOffset("vehicle hitch point", vehicleHitch.ReferencePoint.XOffset, vehicleHitch.ReferencePoint.YOffset, "tractor reference point (center of rear axle)");

            //Implement hitch offset
            DescribeOffset("implement hitch point", implementHitch.ReferencePoint.XOffset, implementHitch.ReferencePoint.YOffset, "implement reference point (center of implement)");

            //Implmement control point offset (inverse of the prior)
            DescribeOffset("implement control point offset", implementConfiguration.ControlPoint.XOffset, implementConfiguration.ControlPoint.YOffset, "tractor hitch point");

            //Section offsets (measured to center of each section)
            foreach (DeviceElement childElement in implementChildElements)
            {
                DeviceElementConfiguration deviceElementConfiguration = catalog.DeviceElementConfigurations.SingleOrDefault(c => c.DeviceElementId == childElement.Id.ReferenceId);
                if (deviceElementConfiguration != null)
                {
                    SectionConfiguration sectionConfiguration = deviceElementConfiguration as SectionConfiguration;
                    if (sectionConfiguration != null)
                    {
                        DescribeOffset($"{childElement.Description} offset", sectionConfiguration.InlineOffset, sectionConfiguration.LateralOffset, "tractor hitch point");
                    }
                }
            }
        }
Ejemplo n.º 24
0
        public PDBConfig(IProcDevice proc, MachineConfiguration config)
        {
            this.proc = proc;
            this.GetGlobals(config);

            // Initialize some lists for data collection
            List <int>                   coil_bank_list        = new List <int>();
            List <int>                   lamp_source_bank_list = new List <int>();
            List <PDBLampEntry>          lamp_list             = new List <PDBLampEntry>();
            List <PDBLampListIndexEntry> lamp_list_for_index   = new List <PDBLampListIndexEntry>();

            this.aliases = new List <DriverAlias>();
            this.indexes = new List <object>();

            if (config.PRDriverAliases != null)
            {
                foreach (DriverAliasEntry alias in config.PRDriverAliases)
                {
                    aliases.Add(new DriverAlias(alias.expr, alias.repl));
                }
            }
            // Make a list of unique coil banks
            foreach (CoilConfigFileEntry coil in config.PRCoils)
            {
                Coil coilObj = new Coil(this, coil.Number);
                if (!coil_bank_list.Contains(coilObj.bank()))
                {
                    coil_bank_list.Add(coilObj.bank());
                }
            }

            // Make a list of lamp source banks. The P-ROC only supports 2
            foreach (LampConfigFileEntry lamp in config.PRLamps)
            {
                Lamp lampObj = new Lamp(this, lamp.Number);

                // Catalog PDB banks
                // Dedicated lamps don't use PDB banks, they're direct driver pins.
                if (lampObj.lamp_type == "dedicated")
                {
                    continue;
                }
                else if (lampObj.lamp_type == "pdb")
                {
                    if (!lamp_source_bank_list.Contains(lampObj.SourceBank()))
                    {
                        lamp_source_bank_list.Add(lampObj.SourceBank());
                    }

                    // Create dicts of unique sink banks. The source index is needed when
                    // setting up the driver groups
                    PDBLampEntry lamp_dict = new PDBLampEntry()
                    {
                        source_index  = lamp_source_bank_list.IndexOf(lampObj.SourceBank()),
                        sink_bank     = lampObj.SinkBank(),
                        source_output = lampObj.SourceOutput()
                    };
                    PDBLampListIndexEntry lamp_dict_for_index = new PDBLampListIndexEntry()
                    {
                        source_board  = lampObj.SourceBoard(),
                        sink_bank     = lampObj.SinkBank(),
                        source_output = lampObj.SourceOutput()
                    };

                    if (!lamp_list.Contains(lamp_dict))
                    {
                        lamp_list.Add(lamp_dict);
                        lamp_list_for_index.Add(lamp_dict_for_index);
                    }
                }
            }
            // Create a list of indexes. The PDB banks will be mapped into this list.
            // The index of the bank is used to calculate the P-ROC driver number for
            // each driver.
            int num_proc_banks = PinProc.kPRDriverCount / 8;

            for (int i = 0; i < num_proc_banks; i++)
            {
                indexes.Add(99);
            }

            this.InitializeDrivers(proc);

            // Set up dedicated driver groups (groups 0-3)
            int group_ctr = 0;

            for (group_ctr = 0; group_ctr < 4; group_ctr++)
            {
                bool enable = coil_bank_list.Contains(group_ctr);
                proc.driver_update_group_config(
                    (byte)group_ctr,
                    0,
                    (byte)group_ctr,
                    0,
                    0,
                    false,
                    true,
                    enable,
                    true
                    );
            }
            group_ctr++;

            // Process lamps first. The P-ROC can only control so many drivers directly.
            // Since software won't have the speed to control lamp matrixes, map the lamps
            // first. If there aren't enough P-ROC driver groups for coils, the overflow
            // coils can be controlled by software via VirtualDrivers (which should get set up
            // automagically here)
            for (int i = 0; i < lamp_list.Count; i++)
            {
                PDBLampEntry lamp_dict = lamp_list[i];
                if (group_ctr >= num_proc_banks || lamp_dict.sink_bank >= 16)
                {
                    Console.WriteLine("Lamp matrix banks can't be mapped to index {0} because thats outside of the banks that P-ROC can control.", lamp_dict.sink_bank);
                }
                else
                {
                    Console.WriteLine("Driver group {0}: slow_time={1} enable_index={2} row_activate_index={3} row_enable_index={4} matrix={5}", group_ctr, lamp_matrix_strobe_time, lamp_dict.sink_bank, lamp_dict.source_output, lamp_dict.source_index);
                    this.indexes[group_ctr] = lamp_list_for_index[i];
                    proc.driver_update_group_config((byte)group_ctr,
                                                    (byte)lamp_matrix_strobe_time,
                                                    (byte)lamp_dict.sink_bank,
                                                    (byte)lamp_dict.source_output,
                                                    (byte)lamp_dict.source_index,
                                                    true,
                                                    true,
                                                    true,
                                                    true);
                    group_ctr++;
                }
            }

            for (int i = 0; i < coil_bank_list.Count; i++)
            {
                // If the bank is 16 or higher, the P-ROC can't control it directly. Software
                // will have to do the driver logic and write any changes to the PDB bus.
                // Therefore, map these banks to indexes above the P-ROC's driver count,
                // which will force the drivers to be created as VirtualDrivers.
                // Appending the bank avoids conflicts when the group counter (group_ctr) gets too high.
                if (group_ctr >= num_proc_banks || coil_bank_list[i] >= 16)
                {
                    Console.WriteLine("Driver group {0} mapped to driver index outside of P-ROC control. These drivers will become VirtualDrivers. Note, the index will not match the board/bank number; so software will need to request those values before updating the drivers.", coil_bank_list[i]);
                    indexes.Add(coil_bank_list[i]);
                }
                else
                {
                    Console.WriteLine("Driver group {0}: slow_time={1} Enable Index={2}", group_ctr, 0, coil_bank_list[i]);
                    indexes[group_ctr] = coil_bank_list[i];
                    proc.driver_update_group_config((byte)group_ctr,
                                                    0,
                                                    (byte)coil_bank_list[i],
                                                    0,
                                                    0,
                                                    false,
                                                    true,
                                                    true,
                                                    true);

                    group_ctr++;
                }
            }

            for (int i = group_ctr; i < 26; i++)
            {
                Console.WriteLine("Driver group {0} disabled", i);
                proc.driver_update_group_config((byte)i,
                                                lamp_matrix_strobe_time,
                                                0,
                                                0,
                                                0,
                                                false,
                                                true,
                                                false,
                                                true);
            }
            // Make sure there are two indexes. If not, fill them in
            while (lamp_source_bank_list.Count < 2)
            {
                lamp_source_bank_list.Add(0);
            }

            // Now set up globals. First disable them to allow the P-ROC to set up the
            // polarities on the drivers, then enable them.

            ConfigureGlobals(proc, lamp_source_bank_list, false);
            ConfigureGlobals(proc, lamp_source_bank_list, true);
        }