Пример #1
0
        private static ImplementConfiguration AddImplementConfiguration(DeviceElement adaptDeviceElement, DeviceHierarchyElement deviceHierarchy, AgGateway.ADAPT.ApplicationDataModel.ADM.Catalog catalog)
        {
            ImplementConfiguration implementConfig = new ImplementConfiguration();

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

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

            //Offsets
            implementConfig.Offsets = new List <NumericRepresentationValue>();
            if (deviceHierarchy.XOffsetRepresentation != null)
            {
                implementConfig.Offsets.Add(deviceHierarchy.XOffsetRepresentation);
            }
            if (deviceHierarchy.YOffsetRepresentation != null)
            {
                implementConfig.Offsets.Add(deviceHierarchy.YOffsetRepresentation);
            }
            if (deviceHierarchy.ZOffsetRepresentation != null)
            {
                implementConfig.Offsets.Add(deviceHierarchy.ZOffsetRepresentation);
            }

            //Total Width
            if (deviceHierarchy.Width != null)
            {
                //In an earlier implementation, we used Width for an individual Row Width and Physical Width for the max width.
                //Going forward, we are adopting a more conventional definition that Width is any reported width of the implement, and
                //Physical width is a reported max width specifically.
                //Widths set from Timelog binaries will have already observed this convention as they did not contain the row width variation.
                implementConfig.Width = deviceHierarchy.WidthRepresentation;
                if (deviceHierarchy.WidthDDI == "0046")
                {
                    implementConfig.PhysicalWidth = deviceHierarchy.WidthRepresentation;
                }
            }

            catalog.DeviceElementConfigurations.Add(implementConfig);

            return(implementConfig);
        }
Пример #2
0
        private static MachineConfiguration AddMachineConfiguration(DeviceElement adaptDeviceElement, DeviceHierarchyElement 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))
            {
                DeviceHierarchyElement 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);
        }
Пример #3
0
 /// <summary>
 /// 数据转置
 /// </summary>
 private void TransferData(IVTestDataTransferThreadWrapper wrapper)
 {
     while (wrapper.Loop)
     {
         try
         {
             DeviceElement device          = wrapper.Device;
             DateTime      dtStartTime     = DateTime.Now;
             string        strFileFullName = DataTransfer.GetFullFile(device.Path, device.Format);
             string        msg             = string.Empty;
             if (!string.IsNullOrEmpty(strFileFullName))
             {
                 string       accConString = string.Format(ACCESS_STRING, strFileFullName);
                 string       sqlConString = SQLSERVER_STRING;
                 DataTransfer sdgData      = new DataTransfer(accConString, sqlConString);
                 sdgData.AccessToSqlServer(device.Name, device.Type, string.Empty);
                 DateTime dtEndTime = DateTime.Now;
                 if (sdgData.TransferCount > 0)
                 {
                     msg = string.Format("开始时间:{0};结束时间:{1};耗用时间:{2}秒;转置数据数量:{3}。{4}",
                                         dtStartTime, dtEndTime, (dtEndTime - dtStartTime).TotalSeconds, sdgData.TransferCount, strFileFullName
                                         );
                     _evnetLog.WriteEntry(msg);
                 }
             }
             else
             {
                 msg = string.Format("开始时间:{0};获取ACCESS数据库文件失败。", dtStartTime);
                 _evnetLog.WriteEntry(msg);
             }
         }
         catch (Exception ex)
         {
             _evnetLog.WriteEntry(ex.Message, EventLogEntryType.Error);
         }
         if (wrapper.Loop)
         {
             Thread.Sleep(_sleepTime);
         }
     }
     wrapper.AutoResetEvent.Set();
 }
Пример #4
0
        private void UpdateCondensedWorkingDatas(List <WorkingData> condensedWorkingDatas, ISODataLogValue dlv, DeviceElementUse deviceElementUse, List <DeviceElementUse> pendingDeviceElementUses, DeviceElementHierarchy isoDeviceElementHierarchy)
        {
            ISODeviceElement isoDeviceElement = TaskDataMapper.DeviceElementHierarchies.GetISODeviceElementFromID(dlv.DeviceElementIdRef);
            IEnumerable <ISODeviceElement> isoSectionElements = isoDeviceElement.ChildDeviceElements.Where(d => d.DeviceElementType == ISOEnumerations.ISODeviceElementType.Section);

            if (isoSectionElements.Count() > 0 && isoSectionElements.Count() == condensedWorkingDatas.Count)
            {
                //We have found the expected number of sections in the DDOP
                List <ISODeviceElement> targetSections = isoSectionElements.ToList();

                //Update the DeviceElementReference on the Condensed WorkingDatas
                for (int i = 0; i < condensedWorkingDatas.Count; i++)
                {
                    WorkingData workingData = condensedWorkingDatas[i];

                    DeviceElementUse condensedDeviceElementUse = new DeviceElementUse();
                    condensedDeviceElementUse.Depth           = deviceElementUse.Depth + 1;
                    condensedDeviceElementUse.Order           = i + 1;
                    condensedDeviceElementUse.OperationDataId = deviceElementUse.OperationDataId;

                    ISODeviceElement targetSection = targetSections[i];
                    int?deviceElementID            = TaskDataMapper.InstanceIDMap.GetADAPTID(targetSection.DeviceElementId);
                    if (deviceElementID.HasValue)
                    {
                        DeviceElement deviceElement = DataModel.Catalog.DeviceElements.SingleOrDefault(d => d.Id.ReferenceId == deviceElementID.Value);
                        if (deviceElement != null)
                        {
                            DeviceElementConfiguration deviceElementConfig = DeviceElementMapper.GetDeviceElementConfiguration(deviceElement, isoDeviceElementHierarchy.FromDeviceElementID(targetSection.DeviceElementId), DataModel.Catalog);
                            condensedDeviceElementUse.DeviceConfigurationId = deviceElementConfig.Id.ReferenceId;
                        }
                    }
                    condensedDeviceElementUse.GetWorkingDatas = () => new List <WorkingData> {
                        workingData
                    };

                    workingData.DeviceElementUseId = condensedDeviceElementUse.Id.ReferenceId;

                    pendingDeviceElementUses.Add(condensedDeviceElementUse);
                }
            }
        }
Пример #5
0
 /// <summary>
 /// 数据转置
 /// </summary>
 private void TransferData(DeviceElement device)
 {
     try
     {
         string strFillFullName = txtFullName.Text;
         string lotNumber       = this.txtLotNumber.Text;
         if (string.IsNullOrEmpty(strFillFullName))
         {
             strFillFullName = DataTransfer.GetFullFile(device.Path, device.Format);
         }
         if (string.IsNullOrEmpty(strFillFullName))
         {
             MessageBox.Show("请选择需要读取的Access文件!");
             return;
         }
         DateTime dtStart = DateTime.Now;
         SetLableText(this.lblMsg, "正在运行,请稍等...");
         SetButtonEnable(btnDataTransfer, false);
         string       accConString = string.Format(ACCESS_CONNECTION_STRING, strFillFullName);
         string       sqlConString = SQLSERVER_STRING;
         DataTransfer sdgData      = new DataTransfer(accConString, sqlConString);
         bool         bAllSuccess  = sdgData.AccessToSqlServer(device.Name, device.Type, lotNumber);
         if (bAllSuccess == false)
         {
             MessageBox.Show("转置数据时出现错误,详细请查看Windows事件日志。");
         }
         DateTime dtEnd = DateTime.Now;
         string   msg   = string.Format("开始时间:{0}。\n结束时间:{1}。\n耗用时间:{2}秒。\n转置数据数量:{3}。",
                                        dtStart.ToString("yyyy-MM-dd HH:mm:ss"),
                                        dtEnd.ToString("yyyy-MM-dd HH:mm:ss"),
                                        (dtEnd - dtStart).TotalSeconds,
                                        sdgData.TransferCount);
         SetButtonEnable(btnDataTransfer, true);
         SetLableText(this.lblMsg, msg);
     }
     catch (Exception ex)
     {
         EventLog.WriteEntry("Astronergy.MES.IVTest", ex.Message, EventLogEntryType.Error);
         MessageBox.Show(ex.Message);
     }
 }
Пример #6
0
        private static SectionConfiguration AddSectionConfiguration(DeviceElement adaptDeviceElement, DeviceElementHierarchy deviceHierarchy, AgGateway.ADAPT.ApplicationDataModel.ADM.Catalog catalog)
        {
            SectionConfiguration sectionConfiguration = new SectionConfiguration();

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


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

            NumericRepresentationValue width   = deviceHierarchy.WidthRepresentation;
            NumericRepresentationValue xOffset = deviceHierarchy.XOffsetRepresentation;
            NumericRepresentationValue yOffset = deviceHierarchy.YOffsetRepresentation;

            if (adaptDeviceElement.DeviceElementType == DeviceElementTypeEnum.Bin)
            {
                //A bin carries no geometry information and should inherit width from its parent and carry 0 offsets from its parent.
                width   = deviceHierarchy.Parent.WidthRepresentation;
                xOffset = 0.AsNumericRepresentationValue("0086", deviceHierarchy.RepresentationMapper);
                yOffset = 0.AsNumericRepresentationValue("0087", deviceHierarchy.RepresentationMapper);
            }

            //Width & Offsets
            sectionConfiguration.SectionWidth = width;
            sectionConfiguration.Offsets      = new List <NumericRepresentationValue>();
            if (xOffset != null)
            {
                sectionConfiguration.InlineOffset = xOffset;
                sectionConfiguration.Offsets.Add(xOffset);
            }
            if (yOffset != null)
            {
                sectionConfiguration.LateralOffset = yOffset;
                sectionConfiguration.Offsets.Add(yOffset);
            }

            catalog.DeviceElementConfigurations.Add(sectionConfiguration);
            return(sectionConfiguration);
        }
Пример #7
0
        public IEnumerable <ISODeviceElement> ExportDeviceElements(IEnumerable <DeviceElement> adaptRootDeviceElements, ISODevice isoDevice)
        {
            List <ISODeviceElement> isoDeviceElements = new List <ISODeviceElement>();
            DeviceElement           rootElement       = null;

            if (adaptRootDeviceElements.Count() == 1)
            {
                rootElement = adaptRootDeviceElements.Single();
            }
            else
            {
                //Create a single root device element to align with the ISO requirement
                rootElement             = new DeviceElement();
                rootElement.Description = isoDevice.DeviceDesignator;
                List <DeviceElement> clonedRootElements = new List <DeviceElement>();
                foreach (DeviceElement element in adaptRootDeviceElements)
                {
                    DeviceElement clone = new DeviceElement();
                    clone.BrandId              = element.BrandId;
                    clone.ContextItems         = element.ContextItems;
                    clone.Description          = element.Description;
                    clone.DeviceClassification = element.DeviceClassification;
                    clone.DeviceElementType    = element.DeviceElementType;
                    clone.DeviceModelId        = element.DeviceModelId;
                    clone.Id.ReferenceId       = element.Id.ReferenceId;
                    clone.Id.UniqueIds         = element.Id.UniqueIds;
                    clone.ManufacturerId       = element.ManufacturerId;
                    clone.ParentDeviceId       = rootElement.Id.ReferenceId; //Assign the clone to the new single root
                    clone.SerialNumber         = element.SerialNumber;
                    clone.SeriesId             = element.SeriesId;
                }
            }

            int objectID            = 1;
            int deviceElementNumber = 1;

            ExportDeviceElement(rootElement, isoDevice, isoDeviceElements, ref objectID, ref deviceElementNumber);

            return(isoDeviceElements);
        }
Пример #8
0
        /// <summary>
        /// Adds a connector with a hitch at the given reference point, referencing the parent DeviceElement as the DeviceElementConfiguration
        /// </summary>
        /// <param name="rootDeviceHierarchy"></param>
        /// <param name="connectorDeviceElement"></param>
        /// <param name="deviceElement"></param>
        private void AddConnector(DeviceElementHierarchy rootDeviceHierarchy, ISODeviceElement connectorDeviceElement)
        {
            //Per the TC-GEO specification, the connector is always a child of the root device element.
            DeviceElementHierarchy hierarchy = rootDeviceHierarchy.FromDeviceElementID(connectorDeviceElement.DeviceElementId);

            if (hierarchy.Parent == rootDeviceHierarchy)
            {
                int?rootDeviceElementID = TaskDataMapper.InstanceIDMap.GetADAPTID(rootDeviceHierarchy.DeviceElement.DeviceElementId);
                if (rootDeviceElementID.HasValue)
                {
                    HitchPoint hitch = new HitchPoint();
                    hitch.ReferencePoint = new ReferencePoint()
                    {
                        XOffset = hierarchy.XOffsetRepresentation, YOffset = hierarchy.YOffsetRepresentation, ZOffset = hierarchy.ZOffsetRepresentation
                    };
                    hitch.HitchTypeEnum = HitchTypeEnum.Unkown;
                    DataModel.Catalog.HitchPoints.Add(hitch);

                    //Get the DeviceElementConfiguration for the root element in order that we may link the Connector to it.
                    DeviceElement root = DataModel.Catalog.DeviceElements.FirstOrDefault(d => d.Id.ReferenceId == rootDeviceElementID);
                    if (root != null)
                    {
                        DeviceElementConfiguration rootDeviceConfiguration = DeviceElementMapper.GetDeviceElementConfiguration(root, rootDeviceHierarchy, DataModel.Catalog);
                        if (rootDeviceConfiguration != null)
                        {
                            Connector connector = new Connector();
                            ImportIDs(connector.Id, hierarchy.DeviceElement.DeviceElementId);
                            connector.DeviceElementConfigurationId = rootDeviceConfiguration.Id.ReferenceId;
                            connector.HitchPointId = hitch.Id.ReferenceId;
                            DataModel.Catalog.Connectors.Add(connector);

                            //The ID mapping will link the ADAPT Connector to the ISO Device Element
                            TaskDataMapper.InstanceIDMap.Add(connector.Id.ReferenceId, connectorDeviceElement.DeviceElementId);
                        }
                    }
                }
            }
        }
Пример #9
0
        public static DeviceElementConfiguration GetDeviceElementConfiguration(DeviceElement adaptDeviceElement, DeviceElementHierarchy isoHierarchy, AgGateway.ADAPT.ApplicationDataModel.ADM.Catalog catalog)
        {
            if (isoHierarchy.DeviceElement.DeviceElementType == ISOEnumerations.ISODeviceElementType.Connector ||
                isoHierarchy.DeviceElement.DeviceElementType == ISOEnumerations.ISODeviceElementType.Navigation)
            {
                //Data belongs to the parent device element from the ISO element referenced
                //Connector and Navigation data may be stored in Timelog data, but Connectors are not DeviceElements in ADAPT.
                //The data refers to the parent implement, which must always be a Device DET per the ISO spec.  We map this to a Machine Config
                DeviceElement parent = catalog.DeviceElements.FirstOrDefault(d => d.Id.ReferenceId == adaptDeviceElement.ParentDeviceId);
                while (parent != null && parent.DeviceElementType != DeviceElementTypeEnum.Machine)
                {
                    parent = catalog.DeviceElements.FirstOrDefault(d => d.Id.ReferenceId == parent.ParentDeviceId);
                }

                if (parent == null)
                {
                    throw new ApplicationException($"Cannot identify Device for Navigation/Connector DeviceElement: {adaptDeviceElement.Description}.");
                }

                DeviceElementConfiguration parentConfig = catalog.DeviceElementConfigurations.FirstOrDefault(c => c.DeviceElementId == parent.Id.ReferenceId);
                if (parentConfig == null)
                {
                    DeviceElement parentElement = catalog.DeviceElements.Single(d => d.Id.ReferenceId == adaptDeviceElement.ParentDeviceId);
                    parentConfig = AddDeviceElementConfiguration(parentElement, isoHierarchy.Parent, catalog);
                }
                return(parentConfig);
            }
            else
            {
                DeviceElementConfiguration deviceConfiguration = catalog.DeviceElementConfigurations.FirstOrDefault(c => c.DeviceElementId == adaptDeviceElement.Id.ReferenceId);
                if (deviceConfiguration == null)
                {
                    deviceConfiguration = AddDeviceElementConfiguration(adaptDeviceElement, isoHierarchy, catalog);
                }
                return(deviceConfiguration);
            }
        }
	// Methods
	public void Add(DeviceElement deviceElement) {}
Пример #11
0
        public DeviceElement ImportDeviceElement(ISODeviceElement isoDeviceElement, EnumeratedValue deviceClassification, DeviceElementHierarchy rootDeviceHierarchy)
        {
            DeviceElement deviceElement = new DeviceElement();

            //ID
            ImportIDs(deviceElement.Id, isoDeviceElement.DeviceElementId);

            //Device ID
            int?deviceModelId = TaskDataMapper.InstanceIDMap.GetADAPTID(isoDeviceElement.Device.DeviceId);

            if (deviceModelId.HasValue)
            {
                deviceElement.DeviceModelId = deviceModelId.Value;
            }

            //Description
            deviceElement.Description = isoDeviceElement.DeviceElementDesignator;

            //Classification
            deviceElement.DeviceClassification = deviceClassification;

            //Parent ID
            if (isoDeviceElement.Parent != null)
            {
                int?parentDeviceId = null;
                if (isoDeviceElement.ParentObjectId == isoDeviceElement.DeviceElementObjectId)
                {
                    //Element has listed itself as its own parent.   Do not include a parent on the adapt element as it will invalidate logic in the hierarchy creation.
                }
                else if (isoDeviceElement.Parent is ISODeviceElement parentElement)
                {
                    parentDeviceId = TaskDataMapper.InstanceIDMap.GetADAPTID(parentElement.DeviceElementId);
                }
                else if (isoDeviceElement.Parent is ISODevice parentDevice)
                {
                    parentDeviceId = TaskDataMapper.InstanceIDMap.GetADAPTID(parentDevice.DeviceId);
                }
                if (parentDeviceId.HasValue)
                {
                    deviceElement.ParentDeviceId = parentDeviceId.Value;
                }
            }

            DeviceElementHierarchy deviceElementHierarchy = TaskDataMapper.DeviceElementHierarchies.GetRelevantHierarchy(isoDeviceElement.DeviceElementId);

            //Device Element Type
            switch (isoDeviceElement.DeviceElementType)
            {
            case ISODeviceElementType.Device:      //This is the root device element
                if (deviceClassification != null &&
                    deviceClassification.Value != null &&
                    TaskDataMapper.DeviceOperationTypes.First(d => d.MachineEnumerationMember.DomainTag == deviceClassification.Value.Code).HasMachineConfiguration)
                {
                    //Device is a machine
                    deviceElement.DeviceElementType = DeviceElementTypeEnum.Machine;
                }
                else if (deviceElementHierarchy.Children != null &&
                         deviceElementHierarchy.Children.Any(d => d?.DeviceElement.DeviceElementType == ISODeviceElementType.Navigation) &&    //The Nav element should be a direct descendant of the root
                         (!deviceElementHierarchy.Children.Any(d => d?.DeviceElement.DeviceElementType == ISODeviceElementType.Section) &&     //If there are section or function elements, classify as an implement vs. a machine
                          !deviceElementHierarchy.Children.Any(d => d?.DeviceElement.DeviceElementType == ISODeviceElementType.Function)))
                {
                    //Device is a machine
                    deviceElement.DeviceElementType = DeviceElementTypeEnum.Machine;
                }
                else
                {
                    //Default: classify as an implement
                    deviceElement.DeviceElementType = DeviceElementTypeEnum.Implement;
                }
                break;

            case ISODeviceElementType.Bin:
                deviceElement.DeviceElementType = DeviceElementTypeEnum.Bin;
                break;

            case ISODeviceElementType.Function:
                deviceElement.DeviceElementType = DeviceElementTypeEnum.Function;
                break;

            case ISODeviceElementType.Section:
                deviceElement.DeviceElementType = DeviceElementTypeEnum.Section;
                break;

            case ISODeviceElementType.Unit:
                deviceElement.DeviceElementType = DeviceElementTypeEnum.Unit;
                break;

            case ISODeviceElementType.Navigation:
                deviceElement.DeviceElementType = DeviceElementTypeEnum.Function;
                break;
            }


            if (HasGeometryInformation(deviceElementHierarchy))
            {
                //Geometry information is on DeviceProperty elements.
                GetDeviceElementConfiguration(deviceElement, deviceElementHierarchy, DataModel.Catalog); //Add via the Get method to invoke business rules for configs
            }

            return(deviceElement);
        }
Пример #12
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);
                    }
                }
            }
        }
Пример #13
0
        private void UpdateCondensedWorkingDatas(List <WorkingData> condensedWorkingDatas, ISODataLogValue dlv, DeviceElementUse deviceElementUse, List <DeviceElementUse> pendingDeviceElementUses, DeviceElementHierarchy isoDeviceElementHierarchy)
        {
            ISODeviceElement isoDeviceElement = TaskDataMapper.DeviceElementHierarchies.GetISODeviceElementFromID(dlv.DeviceElementIdRef);
            IEnumerable <ISODeviceElement> isoSectionElements = isoDeviceElement.ChildDeviceElements.Where(d => d.DeviceElementType == ISOEnumerations.ISODeviceElementType.Section);

            if (isoSectionElements.Count() > 0 && isoSectionElements.Count() <= condensedWorkingDatas.Count)
            {
                //We have found the expected number of sections in the DDOP
                List <ISODeviceElement> targetSections = isoSectionElements.ToList();

                //Update the DeviceElementReference on the Condensed WorkingDatas
                for (int i = 0; i < isoSectionElements.Count(); i++)
                {
                    WorkingData      workingData   = condensedWorkingDatas[i];
                    ISODeviceElement targetSection = targetSections[i];

                    DeviceElementUse condensedDeviceElementUse = FindExistingDeviceElementUseForCondensedData(targetSection, pendingDeviceElementUses);
                    if (condensedDeviceElementUse == null)
                    {
                        //Make a new DeviceElementUse
                        condensedDeviceElementUse = new DeviceElementUse();
                        condensedDeviceElementUse.OperationDataId = deviceElementUse.OperationDataId;

                        int?deviceElementID = TaskDataMapper.InstanceIDMap.GetADAPTID(targetSection.DeviceElementId);
                        if (deviceElementID.HasValue)
                        {
                            DeviceElement deviceElement = DataModel.Catalog.DeviceElements.SingleOrDefault(d => d.Id.ReferenceId == deviceElementID.Value);
                            if (deviceElement != null)
                            {
                                //Reference the device element in its hierarchy so that we can get the depth & order
                                DeviceElementHierarchy deviceElementInHierarchy = isoDeviceElementHierarchy.FromDeviceElementID(targetSection.DeviceElementId);

                                //Get the config id
                                DeviceElementConfiguration deviceElementConfig = DeviceElementMapper.GetDeviceElementConfiguration(deviceElement, deviceElementInHierarchy, DataModel.Catalog);
                                condensedDeviceElementUse.DeviceConfigurationId = deviceElementConfig.Id.ReferenceId;

                                //Set the depth & order
                                condensedDeviceElementUse.Depth = deviceElementInHierarchy.Depth;
                                condensedDeviceElementUse.Order = deviceElementInHierarchy.Order;
                            }
                        }

                        condensedDeviceElementUse.GetWorkingDatas = () => new List <WorkingData> {
                            workingData
                        };

                        workingData.DeviceElementUseId = condensedDeviceElementUse.Id.ReferenceId;

                        pendingDeviceElementUses.Add(condensedDeviceElementUse);
                    }
                    else
                    {
                        //Use the existing DeviceElementUse
                        List <WorkingData>        data = new List <WorkingData>();
                        IEnumerable <WorkingData> existingWorkingDatas = condensedDeviceElementUse.GetWorkingDatas();
                        if (existingWorkingDatas != null)
                        {
                            data.AddRange(existingWorkingDatas.ToList());  //Add the preexisting
                        }
                        data.Add(workingData);
                        condensedDeviceElementUse.GetWorkingDatas = () => data;
                    }
                }
            }
        }
Пример #14
0
        public List <DeviceElementUse> Map(ISOTime time, IEnumerable <ISOSpatialRow> isoRecords, int operationDataId, IEnumerable <string> isoDeviceElementIDs)
        {
            var sections = new List <DeviceElementUse>();

            foreach (string isoDeviceElementID in isoDeviceElementIDs)
            {
                DeviceElementHierarchy hierarchy = TaskDataMapper.DeviceElementHierarchies.GetRelevantHierarchy(isoDeviceElementID);
                if (hierarchy != null)
                {
                    DeviceElementUse   deviceElementUse = null;
                    List <WorkingData> workingDatas     = new List <WorkingData>();

                    //Get the relevant DeviceElementConfiguration
                    int           adaptDeviceElementId = TaskDataMapper.InstanceIDMap.GetADAPTID(isoDeviceElementID).Value;
                    DeviceElement adaptDeviceElement   = DataModel.Catalog.DeviceElements.SingleOrDefault(d => d.Id.ReferenceId == adaptDeviceElementId);
                    if (adaptDeviceElement != null)
                    {
                        DeviceElementConfiguration config = DeviceElementMapper.GetDeviceElementConfiguration(adaptDeviceElement, hierarchy, DataModel.Catalog);

                        int depth = hierarchy.Depth;
                        int order = hierarchy.Order;
                        if (config.DeviceElementId == adaptDeviceElement.ParentDeviceId)
                        {
                            //The configuration references the parent ISO element
                            depth = hierarchy.Parent.Depth;
                            order = hierarchy.Parent.Order;
                        }

                        //Read any spatially-listed widths/offsets on this data onto the DeviceElementConfiguration objects
                        hierarchy.SetWidthsAndOffsetsFromSpatialData(isoRecords, config, RepresentationMapper);

                        deviceElementUse = sections.FirstOrDefault(d => d.DeviceConfigurationId == config.Id.ReferenceId);
                        if (deviceElementUse == null)
                        {
                            //Create the DeviceElementUse
                            deviceElementUse                       = new DeviceElementUse();
                            deviceElementUse.Depth                 = depth;
                            deviceElementUse.Order                 = order;
                            deviceElementUse.OperationDataId       = operationDataId;
                            deviceElementUse.DeviceConfigurationId = config.Id.ReferenceId;

                            //Add Working Data for any data on this device element
                            List <WorkingData> data = _workingDataMapper.Map(time, isoRecords, deviceElementUse, hierarchy, sections);
                            if (data.Any())
                            {
                                workingDatas.AddRange(data);
                            }
                        }
                        else
                        {
                            workingDatas = deviceElementUse.GetWorkingDatas().ToList();

                            //Add Additional Working Data
                            List <WorkingData> data = _workingDataMapper.Map(time, isoRecords, deviceElementUse, hierarchy, sections);
                            if (data.Any())
                            {
                                workingDatas.AddRange(data);
                            }
                        }

                        deviceElementUse.GetWorkingDatas = () => workingDatas;

                        if (!sections.Contains(deviceElementUse))
                        {
                            sections.Add(deviceElementUse);
                        }
                    }
                }
            }

            return(sections);
        }
 public void Remove(DeviceElement deviceElement)
 {
 }
Пример #16
0
        private void UpdateCondensedWorkingDatas(List <ISOEnumeratedMeter> condensedWorkingDatas, ISODataLogValue dlv, DeviceElementUse deviceElementUse, List <DeviceElementUse> pendingDeviceElementUses, DeviceHierarchyElement isoDeviceElementHierarchy)
        {
            ISODeviceElement        isoDeviceElement   = TaskDataMapper.DeviceElementHierarchies.GetISODeviceElementFromID(dlv.DeviceElementIdRef);
            List <ISODeviceElement> isoSectionElements = isoDeviceElement.ChildDeviceElements.Where(d => d.DeviceElementType == ISOEnumerations.ISODeviceElementType.Section).ToList();

            foreach (var subElement in isoDeviceElement.ChildDeviceElements)
            {
                //This handles cases where the condensed workstate is reported on a top-level boom with sub-booms in the hierarchy above the sections (e.g., ISO 11783-10:2015(E) Figure F.35)
                isoSectionElements.AddRange(subElement.ChildDeviceElements.Where(d => d.DeviceElementType == ISOEnumerations.ISODeviceElementType.Section).ToList());
            }
            //We have some sections in the DDOP
            if (isoSectionElements.Count > 0)
            {
                //Update the DeviceElementReference on the Condensed WorkingDatas
                foreach (var workingData in condensedWorkingDatas)
                {
                    if (workingData.SectionIndex - 1 >= isoSectionElements.Count)
                    {
                        break;
                    }
                    ISODeviceElement targetSection = isoSectionElements[workingData.SectionIndex - 1];

                    DeviceElementUse condensedDeviceElementUse = FindExistingDeviceElementUseForCondensedData(targetSection, pendingDeviceElementUses);
                    if (condensedDeviceElementUse == null)
                    {
                        //Make a new DeviceElementUse
                        condensedDeviceElementUse = new DeviceElementUse();
                        condensedDeviceElementUse.OperationDataId = deviceElementUse.OperationDataId;

                        int?deviceElementID = TaskDataMapper.InstanceIDMap.GetADAPTID(targetSection.DeviceElementId);
                        if (deviceElementID.HasValue)
                        {
                            DeviceElement deviceElement = DataModel.Catalog.DeviceElements.SingleOrDefault(d => d.Id.ReferenceId == deviceElementID.Value);
                            if (deviceElement != null)
                            {
                                //Reference the device element in its hierarchy so that we can get the depth & order
                                DeviceHierarchyElement deviceElementInHierarchy = isoDeviceElementHierarchy.FromDeviceElementID(targetSection.DeviceElementId);

                                //Get the config id
                                DeviceElementConfiguration deviceElementConfig = DeviceElementMapper.GetDeviceElementConfiguration(deviceElement, deviceElementInHierarchy, DataModel.Catalog);
                                condensedDeviceElementUse.DeviceConfigurationId = deviceElementConfig.Id.ReferenceId;

                                //Set the depth & order
                                condensedDeviceElementUse.Depth = deviceElementInHierarchy.Depth;
                                condensedDeviceElementUse.Order = deviceElementInHierarchy.Order;
                            }
                        }

                        condensedDeviceElementUse.GetWorkingDatas = () => new List <WorkingData> {
                            workingData
                        };

                        workingData.DeviceElementUseId = condensedDeviceElementUse.Id.ReferenceId;

                        pendingDeviceElementUses.Add(condensedDeviceElementUse);
                    }
                    else
                    {
                        //Use the existing DeviceElementUse
                        List <WorkingData>        data = new List <WorkingData>();
                        IEnumerable <WorkingData> existingWorkingDatas = condensedDeviceElementUse.GetWorkingDatas();
                        if (existingWorkingDatas != null)
                        {
                            data.AddRange(existingWorkingDatas.ToList());  //Add the preexisting
                        }
                        data.Add(workingData);
                        condensedDeviceElementUse.GetWorkingDatas = () => data;
                    }
                }
            }
        }
 // Methods
 public void Add(DeviceElement deviceElement)
 {
 }
Пример #18
0
        public DeviceElement ImportDeviceElement(ISODeviceElement isoDeviceElement, EnumeratedValue deviceClassification, DeviceElementHierarchy rootDeviceHierarchy)
        {
            DeviceElement deviceElement = new DeviceElement();

            //ID
            ImportIDs(deviceElement.Id, isoDeviceElement.DeviceElementId);

            //Device ID
            deviceElement.DeviceModelId = TaskDataMapper.InstanceIDMap.GetADAPTID(isoDeviceElement.Device.DeviceId).Value;

            //Description
            deviceElement.Description = isoDeviceElement.DeviceElementDesignator;

            //Classification
            deviceElement.DeviceClassification = deviceClassification;

            //Parent ID
            if (isoDeviceElement.Parent != null)
            {
                if (isoDeviceElement.Parent is ISODeviceElement)
                {
                    ISODeviceElement parentElement = isoDeviceElement.Parent as ISODeviceElement;
                    deviceElement.ParentDeviceId = TaskDataMapper.InstanceIDMap.GetADAPTID(parentElement.DeviceElementId).Value;
                }
                else
                {
                    ISODevice parentDevice = isoDeviceElement.Parent as ISODevice;
                    deviceElement.ParentDeviceId = TaskDataMapper.InstanceIDMap.GetADAPTID(parentDevice.DeviceId).Value;
                }
            }

            DeviceElementHierarchy deviceElementHierarchy = TaskDataMapper.DeviceElementHierarchies.GetRelevantHierarchy(isoDeviceElement.DeviceElementId);

            //Device Element Type
            switch (isoDeviceElement.DeviceElementType)
            {
            case ISODeviceElementType.Device:      //This is the root device element
                if (deviceClassification != null &&
                    deviceClassification.Value != null &&
                    TaskDataMapper.DeviceOperationTypes.First(d => d.MachineEnumerationMember.DomainTag == deviceClassification.Value.Code).HasMachineConfiguration)
                {
                    //Device is a machine
                    deviceElement.DeviceElementType = DeviceElementTypeEnum.Machine;
                }
                else if (deviceElementHierarchy.Children != null && deviceElementHierarchy.Children.Any(h => h.DeviceElement != null && h.DeviceElement.DeviceElementType == ISODeviceElementType.Navigation))
                {
                    //Device has a navigation element; classify as a machine
                    deviceElement.DeviceElementType = DeviceElementTypeEnum.Machine;
                }
                else
                {
                    //Default: classify as an implement
                    deviceElement.DeviceElementType = DeviceElementTypeEnum.Implement;
                }
                break;

            case ISODeviceElementType.Bin:
                deviceElement.DeviceElementType = DeviceElementTypeEnum.Bin;
                break;

            case ISODeviceElementType.Function:
                deviceElement.DeviceElementType = DeviceElementTypeEnum.Function;
                break;

            case ISODeviceElementType.Section:
                deviceElement.DeviceElementType = DeviceElementTypeEnum.Section;
                break;

            case ISODeviceElementType.Unit:
                deviceElement.DeviceElementType = DeviceElementTypeEnum.Unit;
                break;

            case ISODeviceElementType.Navigation:
                deviceElement.DeviceElementType = DeviceElementTypeEnum.Function;
                break;
            }


            if (HasGeometryInformation(deviceElementHierarchy))
            {
                //Geometry information is on DeviceProperty elements.
                GetDeviceElementConfiguration(deviceElement, deviceElementHierarchy, DataModel.Catalog); //Add via the Get method to invoke business rules for configs
            }

            return(deviceElement);
        }
        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");
                    }
                }
            }
        }
Пример #20
0
        public SageCommandProcessor(ILifetimeScope lifetimeScope, TunerElement tunerSettings, DeviceElement deviceSettings, ICaptureManager executableProcessCaptureManager, IChannelProvider channelProvider, Logger logger)
        {
            _lifetimeScope  = lifetimeScope;
            _tunerSettings  = tunerSettings;
            _deviceSettings = deviceSettings;

            _executableProcessCapture = executableProcessCaptureManager;
            _channelProvider          = channelProvider;
            Logger = logger;

            _tunerState      = new TunerState();
            _tunerState.Name = _tunerSettings.Name;
        }
Пример #21
0
        public List <DeviceElementUse> Map(ISOTime time,
                                           IEnumerable <ISOSpatialRow> isoRecords,
                                           int operationDataId,
                                           IEnumerable <string> isoDeviceElementIDs,
                                           Dictionary <string, List <ISOProductAllocation> > isoProductAllocations)
        {
            var sections = new List <DeviceElementUse>();

            foreach (string isoDeviceElementID in isoDeviceElementIDs)
            {
                DeviceHierarchyElement hierarchyElement = TaskDataMapper.DeviceElementHierarchies.GetMatchingElement(isoDeviceElementID);
                if (hierarchyElement != null)
                {
                    DeviceElementUse   deviceElementUse = null;
                    List <WorkingData> workingDatas     = new List <WorkingData>();

                    //Get the relevant DeviceElementConfiguration
                    int           adaptDeviceElementId = TaskDataMapper.InstanceIDMap.GetADAPTID(isoDeviceElementID).Value;
                    DeviceElement adaptDeviceElement   = DataModel.Catalog.DeviceElements.SingleOrDefault(d => d.Id.ReferenceId == adaptDeviceElementId);
                    if (adaptDeviceElement != null)
                    {
                        DeviceElementConfiguration config = DeviceElementMapper.GetDeviceElementConfiguration(adaptDeviceElement, hierarchyElement, DataModel.Catalog);

                        int depth = hierarchyElement.Depth;
                        int order = hierarchyElement.Order;
                        if (config.DeviceElementId == adaptDeviceElement.ParentDeviceId)
                        {
                            //The configuration references the parent ISO element
                            depth = hierarchyElement.Parent.Depth;
                            order = hierarchyElement.Parent.Order;
                        }

                        deviceElementUse = sections.FirstOrDefault(d => d.DeviceConfigurationId == config.Id.ReferenceId);
                        if (deviceElementUse == null)
                        {
                            //Create the DeviceElementUse
                            deviceElementUse                       = new DeviceElementUse();
                            deviceElementUse.Depth                 = depth;
                            deviceElementUse.Order                 = order;
                            deviceElementUse.OperationDataId       = operationDataId;
                            deviceElementUse.DeviceConfigurationId = config.Id.ReferenceId;

                            //Add Working Data for any data on this device element
                            List <WorkingData> data = _workingDataMapper.Map(time, isoRecords, deviceElementUse, hierarchyElement, sections, isoProductAllocations);
                            if (data.Any())
                            {
                                workingDatas.AddRange(data);
                            }
                        }
                        else
                        {
                            workingDatas = deviceElementUse.GetWorkingDatas().ToList();

                            //Add Additional Working Data
                            List <WorkingData> data = _workingDataMapper.Map(time, isoRecords, deviceElementUse, hierarchyElement, sections, isoProductAllocations);
                            if (data.Any())
                            {
                                workingDatas.AddRange(data);
                            }
                        }

                        deviceElementUse.GetWorkingDatas = () => workingDatas;

                        if (!sections.Contains(deviceElementUse))
                        {
                            sections.Add(deviceElementUse);
                        }
                    }
                }
            }

            return(sections);
        }
 private void ParseDeviceHeader(ref byte[] data, int nStartPose, int nBodyLen, DeviceElement devData)
 {
     devData.battery           = (((data[nStartPose + 1] & 0xf0) >> 4) + (data[nStartPose + 1] & 0x0f) * 0.1);
     devData.totalChannelCount = data[nStartPose + 2];
     devData.dataTime          = BCDTime2Time(data, nStartPose + 3);
     devData.timeSpan          = (data[nStartPose + 9] << 8) + data[nStartPose + 10];
 }
Пример #23
0
        public ISODeviceElement ExportDeviceElement(DeviceElement adaptDeviceElement, ISODevice isoDevice, List <ISODeviceElement> pendingDeviceElements, ref int objectID, ref int elementNumber)
        {
            ISODeviceElement det = new ISODeviceElement(isoDevice);

            objectID++;
            elementNumber++;

            //ID
            string id = adaptDeviceElement.Id.FindIsoId() ?? GenerateId();

            det.DeviceElementId = id;
            ExportIDs(adaptDeviceElement.Id, id);

            //Object ID
            det.DeviceElementObjectId = (uint)objectID;

            //Device Element Number
            det.DeviceElementNumber = (uint)elementNumber;

            //Designator
            det.DeviceElementDesignator = adaptDeviceElement.Description;

            //Device Element Type
            switch (adaptDeviceElement.DeviceElementType)
            {
            case DeviceElementTypeEnum.Machine:
            case DeviceElementTypeEnum.Implement:
                det.DeviceElementType = ISODeviceElementType.Device;
                break;

            case DeviceElementTypeEnum.Bin:
                det.DeviceElementType = ISODeviceElementType.Bin;
                break;

            case DeviceElementTypeEnum.Function:
                det.DeviceElementType = ISODeviceElementType.Function;
                break;

            case DeviceElementTypeEnum.Section:
                det.DeviceElementType = ISODeviceElementType.Section;
                break;

            case DeviceElementTypeEnum.Unit:
                det.DeviceElementType = ISODeviceElementType.Unit;
                break;
            }

            //Parent ID
            DeviceElement parentDeviceElement = DataModel.Catalog.DeviceElements.FirstOrDefault(d => d.Id.ReferenceId == adaptDeviceElement.ParentDeviceId);

            if (parentDeviceElement != null)
            {
                string deviceElementID = TaskDataMapper.InstanceIDMap.GetISOID(parentDeviceElement.Id.ReferenceId);
                if (pendingDeviceElements.Any(d => d.DeviceElementId == deviceElementID))
                {
                    det.ParentObjectId = pendingDeviceElements.First(d => d.DeviceElementId == deviceElementID).DeviceElementObjectId;
                }
            }
            else
            {
                DeviceModel parentDeviceModel = DataModel.Catalog.DeviceModels.FirstOrDefault(d => d.Id.ReferenceId == adaptDeviceElement.ParentDeviceId);
                if (parentDeviceModel != null)
                {
                    //Parent is Device
                    det.ParentObjectId = 0;
                }
            }

            //Add to the collection
            pendingDeviceElements.Add(det);

            //Child Elements
            int deviceElementNumber = 1;

            foreach (DeviceElement childElement in DataModel.Catalog.DeviceElements.Where(d => d.ParentDeviceId == adaptDeviceElement.Id.ReferenceId))
            {
                ExportDeviceElement(childElement, isoDevice, pendingDeviceElements, ref objectID, ref deviceElementNumber);
            }

            //Connectors
            if (det.DeviceElementType == ISODeviceElementType.Device)
            {
                //Connectors should only exist as children of the top level DeviceElement
                foreach (DeviceElementConfiguration config in DataModel.Catalog.DeviceElementConfigurations.Where(c => c.DeviceElementId == adaptDeviceElement.Id.ReferenceId))
                {
                    foreach (Connector connector in DataModel.Catalog.Connectors.Where(c => c.DeviceElementConfigurationId == config.Id.ReferenceId))
                    {
                        ExportConnectorElement(connector, det, pendingDeviceElements, ref objectID, ref deviceElementNumber);
                    }
                }
            }

            //Device Properties
            ExportDeviceProperties(det, adaptDeviceElement);

            return(det);
        }
	public void Remove(DeviceElement deviceElement) {}