Example #1
0
        public static NodeDevice BuildWith(
            FieldIdentifier Code, FieldGuid TypeId,
            FieldString Address, FieldBase64 Configuration,
            FieldDeviceName DeviceName)
        {
            //build fields
            Dictionary <FieldIdentifier, FieldBase> mutableFields =
                new Dictionary <FieldIdentifier, FieldBase>();

            mutableFields.Add(new FieldIdentifier(m_CodeName), Code);
            mutableFields.Add(new FieldIdentifier(m_TypeIdName), TypeId);
            mutableFields.Add(new FieldIdentifier(m_AddressName), Address);
            mutableFields.Add(new FieldIdentifier(m_ConfigurationName), Configuration);
            mutableFields.Add(new FieldIdentifier(m_DeviceNameName), DeviceName);
            //Add Fields here: mutableFields.Add(new FieldIdentifier(m_CodeName), Code);

            //build children
            KeyedNodeCollection <NodeBase> mutableChildren =
                new KeyedNodeCollection <NodeBase>();
            //Add Children here: mutableChildren.Add(SomeChild);

            //build node
            NodeDevice Builder = new NodeDevice(
                new ReadOnlyDictionary <FieldIdentifier, FieldBase>(mutableFields),
                new ReadOnlyCollection <NodeBase>(mutableChildren));

            return(Builder);
        }
Example #2
0
        /// <summary>
        /// Assumes the memento is the Node ID (FieldGuid)
        /// </summary>
        /// <param name="memento"></param>
        /// <returns></returns>
        public override IDocument CreateDocument(string memento)
        {
            if (memento == null)
            {
                throw new ArgumentNullException();
            }

            if (!m_docs.ContainsKey(memento))
            {
                ISolutionItem item = null;
                if (FieldGuid.CheckSyntax(memento))
                {
                    item = solutionPad.FindItemByNodeId(new Guid(memento)) as ISolutionItem;
                }

                if (item != null && item is PageItem)
                {
                    var pe = new PageEditor(item as PageItem); // adds itself to m_docs
                }
                else
                {
                    return(null);
                }
            }
            return(m_docs[memento]);
        }
        public NodeInstruction SetSignalInToSignalId(int index, FieldGuid signalId)
        {
            var oldSignalIn    = this.NodeSignalInChildren[index];
            var newSignalIn    = NodeSignalIn.BuildWith(oldSignalIn.DataType, signalId);
            var newInstruction = this.NodeSignalInChildren.Replace(oldSignalIn, newSignalIn);

            return(newInstruction);
        }
Example #4
0
 public NodeRuntimeApplication SetRuntimeId(FieldGuid RuntimeId)
 {
     if (RuntimeId == null)
     {
         throw new ArgumentNullException(m_RuntimeIdName);
     }
     return(new NodeRuntimeApplication(this.SetField(new FieldIdentifier(m_RuntimeIdName), RuntimeId), ChildCollection));
 }
Example #5
0
 public NodeSignal SetSignalId(FieldGuid SignalId)
 {
     if (SignalId == null)
     {
         throw new ArgumentNullException(m_SignalIdName);
     }
     return(new NodeSignal(this.SetField(new FieldIdentifier(m_SignalIdName), SignalId), ChildCollection));
 }
Example #6
0
 public NodeDevice SetTypeId(FieldGuid TypeId)
 {
     if (TypeId == null)
     {
         throw new ArgumentNullException(m_TypeIdName);
     }
     return(new NodeDevice(this.SetField(new FieldIdentifier(m_TypeIdName), TypeId), ChildCollection));
 }
Example #7
0
 /// <summary>
 /// Searches the tree for a signal matching this signal ID.
 /// </summary>
 public NodeSignal FindSignal(FieldGuid signalId)
 {
     if (m_signalLookup.ContainsKey(signalId.ToString()))
     {
         return(m_signalLookup[signalId.ToString()]);
     }
     else
     {
         return(null);
     }
 }
Example #8
0
        public static NodeRuntimeApplication BuildWith(
            FieldIdentifier Code, FieldGuid TypeId, FieldGuid RuntimeId,
            FieldString Address, FieldBase64 Configuration, FieldBool ExecuteOnStartup,
            NodePageCollection Logic, NodeDeviceConfiguration DeviceConfiguration)
        {
            var rta = NodeRuntimeApplication.BuildWith(
                Code, TypeId, RuntimeId, Address, Configuration, ExecuteOnStartup);

            rta = rta.SetLogic(Logic);
            return(rta.SetDeviceConfiguration(DeviceConfiguration));
        }
Example #9
0
        NodeBase peer_OnReceiveDelta(NodePeer FromPeer, FieldGuid BasedOnMessageID)
        {
            NodeBase originalMessage = null;
            IRuntime runtime         = getRelationship(FromPeer);

            if (runtime != null)
            {
                originalMessage = runtime.DeltaReceivedFromPeer(BasedOnMessageID);
            }
            return(originalMessage);
        }
Example #10
0
        /// <summary>
        /// Finds the item (if it exists) in the Items collection
        /// matching the given nodeId.  It is *not* recursive.
        /// </summary>
        public INodeWrapper FindItemByNodeId(FieldGuid nodeId)
        {
            INodeWrapper retVal = null;

            foreach (var item in Items)
            {
                if (item.Node != null && item.Node.ID == nodeId)
                {
                    retVal = item;
                    break;
                }
            }
            return(retVal);
        }
Example #11
0
        public INodeWrapper FindAncestorByNodeId(FieldGuid nodeId)
        {
            INodeWrapper parent = Parent;

            while (parent != null)
            {
                if (parent.Node.ID == nodeId)
                {
                    break;
                }
                parent = parent.Parent;
            }
            return(parent);
        }
Example #12
0
        public static NodeDevice StaticBuild()
        {
            FieldIdentifier code;
            FieldGuid       typeId;
            FieldString     address;
            FieldBase64     configuration;
            FieldDeviceName deviceName;

            code          = new FieldIdentifier(CODE);
            typeId        = new FieldGuid(TYPE_ID);
            address       = new FieldString(string.Empty);
            configuration = new FieldBase64(string.Empty);
            deviceName    = new FieldDeviceName(Resources.Strings.Unknown_Phidget_Name);

            NodeDevice device = NodeDevice.BuildWith(code, typeId, address, configuration, deviceName);

            return(device);
        }
Example #13
0
        private FieldGuid sendTelegramWithGuidPayloadResponse(NodeTelegram telegram)
        {
            var response = sendReceiveTelegram <NodeTelegram>(telegram);

            if (response != null)
            {
                string payload = response.Payload.Decode();
                if (FieldGuid.CheckSyntax(payload))
                {
                    return(new FieldGuid(payload));
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Example #14
0
        public static NodeRuntimeApplication BuildWith(
            FieldIdentifier Code, FieldGuid TypeId, FieldGuid RuntimeId,
            FieldString Address, FieldBase64 Configuration, FieldBool ExecuteOnStartup)
        {
            //build fields
            Dictionary <FieldIdentifier, FieldBase> mutableFields =
                new Dictionary <FieldIdentifier, FieldBase>();

            mutableFields.Add(new FieldIdentifier(m_CodeName), Code);
            mutableFields.Add(new FieldIdentifier(m_TypeIdName), TypeId);
            mutableFields.Add(new FieldIdentifier(m_RuntimeIdName), RuntimeId);
            mutableFields.Add(new FieldIdentifier(m_AddressName), Address);
            mutableFields.Add(new FieldIdentifier(m_ConfigurationName), Configuration);
            mutableFields.Add(new FieldIdentifier(m_ExecuteOnStartupName), ExecuteOnStartup);
            mutableFields.Add(new FieldIdentifier(m_TryModeName), new FieldBool(false));
            //Add Fields here: mutableFields.Add(new FieldIdentifier("Code"), Code);

            //build children
            KeyedNodeCollection <NodeBase> mutableChildren =
                new KeyedNodeCollection <NodeBase>();
            var pc = NodePageCollection.BuildWith(
                new FieldPageCollectionName(m_LogicName)
                );

            pc = pc.SetLogicRoot(new FieldBool(true));
            mutableChildren.Add(pc);
            mutableChildren.Add(
                NodeDeviceConfiguration.BuildWith(
                    new ReadOnlyCollection <NodeDriver>(new Collection <NodeDriver>())
                    ));
            //Add Children here: mutableChildren.Add(SomeChild);

            //build node
            NodeRuntimeApplication Builder = new NodeRuntimeApplication(
                new ReadOnlyDictionary <FieldIdentifier, FieldBase>(mutableFields),
                new ReadOnlyCollection <NodeBase>(mutableChildren));

            return(Builder);
        }
Example #15
0
        /// <summary>
        /// Generic way to send a telegram to the engine, and get a response of a given type
        /// If the receive type if NodeTelegram, it checks the MessageId to make sure the
        /// response matches the outgoing MessageId.
        /// </summary>
        /// <returns>null if no response</returns>
        public T sendReceiveTelegram <T>(NodeTelegram outgoingTelegram) where T : NodeBase
        {
            responseNode = null;
            m_sendReceiveTelegram_ARE.Reset();
            var msgId = new FieldGuid(); // generates a unique message ID

            m_communicationService.Value.SendToPeer(this, Peer, outgoingTelegram.SetMessageId(msgId));
            if (m_sendReceiveTelegram_ARE.WaitOne(COMM_TIMEOUT, false))
            {
                var telegramRead = responseNode as NodeTelegram;
                if (telegramRead != null && telegramRead.MessageId != msgId)
                {
                    return(null);
                }
                return(responseNode as T);
            }
            else
            {
                // timeout
                return(null);
            }
        }
Example #16
0
 /// <summary>
 /// Implements a depth first search
 /// </summary>
 private INodeWrapper findItemByNodeId(INodeWrapper currentItem, FieldGuid fGuid)
 {
     if (currentItem == null)
     {
         return(null);
     }
     else if (currentItem.Node.ID == fGuid)
     {
         return(currentItem);
     }
     else
     {
         foreach (var item in currentItem.Items)
         {
             var foundItem = findItemByNodeId(item, fGuid);
             if (foundItem != null)
             {
                 return(foundItem);
             }
         }
         return(null);
     }
 }
Example #17
0
        /// <summary>
        /// Searches the runtime application for a signal matching the given signalId
        /// </summary>
        public Tuple <string, NodeSignal> FindSignal(INodeWrapper requester, FieldGuid signalId)
        {
            var      tpl = FindParentPageAndRuntimeApp(requester);
            NodePage pg  = tpl.Item1;
            NodeRuntimeApplication rta = tpl.Item2;

            if (rta != null)
            {
                var edits = new Dictionary <NodePage, NodePage>();

                if (pg != null)
                {
                    // Searches the local page first
                    var tryLocal = FindSignalAndName(pg, string.Empty, pg, signalId, edits);
                    if (tryLocal != null)
                    {
                        return(tryLocal);
                    }
                }

                // Make a list of edited page copies
                foreach (var d in layoutManager.Documents)
                {
                    var pageEditor = d as PageEditor;
                    if (pageEditor != null)
                    {
                        edits.Add(pageEditor.PageItemParent.Page, pageEditor.EditorRoot.WorkingCopy);
                    }
                }

                return(FindSignalAndName(rta, string.Empty, pg, signalId, edits));
            }
            else
            {
                return(null);
            }
        }
Example #18
0
        private NodeTelegram readSignals(NodeTelegram request)
        {
            // incoming request should just be a bunch of Guids that represent signalIds
            var inPayload  = request.Payload.Decode();
            var outPayload = new StringBuilder();

            if (runtimeApplication != null)
            {
                for (int index = 0; index < inPayload.Length; index += m_guidLength)
                {
                    string oneGuidString = inPayload.Substring(index, m_guidLength);
                    if (FieldGuid.CheckSyntax(oneGuidString))
                    {
                        var signalId = new FieldGuid(oneGuidString);
                        var signal   = runtimeApplication.FindSignal(signalId);
                        if (signal != null)
                        {
                            outPayload.Append(EncodedSignalValue.EncodeSignalValue(signal));
                        }
                    }
                }
            }
            return(request.SetPayload(FieldBase64.Encode(outPayload.ToString())));
        }
Example #19
0
 public NodeSignalIn SetSignalId(FieldGuid SignalId)
 {
     return(new NodeSignalIn(this.SetField(new FieldIdentifier(m_SignalIdName), SignalId), ChildCollection));
 }
Example #20
0
        public static NodeSignalIn BuildWith(FieldDataType DataType, FieldDataType CompatibleTypes, FieldGuid SignalId)
        {
            //build fields
            Dictionary <FieldIdentifier, FieldBase> mutableFields =
                new Dictionary <FieldIdentifier, FieldBase>();

            mutableFields.Add(new FieldIdentifier(m_DataTypeName), DataType);
            mutableFields.Add(new FieldIdentifier(m_CompatibleTypesName), CompatibleTypes);
            mutableFields.Add(new FieldIdentifier(m_SignalIdName), SignalId);
            //Add Fields here: mutableFields.Add(new FieldIdentifier(m_CodeName), Code);

            //build children
            KeyedNodeCollection <NodeBase> mutableChildren =
                new KeyedNodeCollection <NodeBase>();
            //Add Children here: mutableChildren.Add(SomeChild);

            //build node
            NodeSignalIn Builder = new NodeSignalIn(
                new ReadOnlyDictionary <FieldIdentifier, FieldBase>(mutableFields),
                new ReadOnlyCollection <NodeBase>(mutableChildren));

            return(Builder);
        }
Example #21
0
        public static NodeDevice StaticBuildHelper(string deviceName, int serialNumber, string code, string typeId,
                                                   int discreteInputs, int discreteOutputs, int analogInputs, int analogOutputs, int stringInputs, int stringOutputs,
                                                   string analogOutputNameOverride, string discreteOutputNameOverride)
        {
            FieldIdentifier c;
            FieldGuid       typ;
            FieldString     address;
            FieldBase64     configuration;
            FieldDeviceName dName;

            c             = new FieldIdentifier(code);
            typ           = new FieldGuid(typeId);
            address       = new FieldString(serialNumber.ToString());
            configuration = new FieldBase64(string.Empty);
            dName         = new FieldDeviceName(deviceName);

            NodeDevice device = NodeDevice.BuildWith(c, typ, address, configuration, dName);

            // Add the inputs
            var inputsMutable = new Collection <NodeDiscreteInput>();

            for (int i = 0; i < discreteInputs; i++)
            {
                inputsMutable.Add(NodeDiscreteInput.BuildWith(
                                      new FieldIdentifier(Resources.Strings.Input + i),
                                      new FieldString(i.ToString()),
                                      new FieldSignalName(Resources.Strings.Input + " " + i)));
            }
            var inputs = new ReadOnlyCollection <NodeDiscreteInput>(inputsMutable);

            device = device.NodeDiscreteInputChildren.Append(inputs);

            var analogInputsMutable = new Collection <NodeAnalogInput>();

            for (int i = 0; i < analogInputs; i++)
            {
                analogInputsMutable.Add(NodeAnalogInput.BuildWith(
                                            new FieldIdentifier(Resources.Strings.AnalogInput + i),
                                            new FieldString(i.ToString()),
                                            new FieldSignalName(Resources.Strings.AnalogInput + " " + i)));
            }
            device = device.NodeAnalogInputChildren.Append(new ReadOnlyCollection <NodeAnalogInput>(analogInputsMutable));

            var stringInputsMutable = new Collection <NodeStringInput>();

            for (int i = 0; i < stringInputs; i++)
            {
                stringInputsMutable.Add(NodeStringInput.BuildWith(
                                            new FieldIdentifier(Resources.Strings.StringInput + i),
                                            new FieldString(i.ToString()),
                                            new FieldSignalName(Resources.Strings.StringInput + " " + i)));
            }
            device = device.NodeStringInputChildren.Append(new ReadOnlyCollection <NodeStringInput>(stringInputsMutable));

            // Add the outputs
            var outputsMutable = new Collection <NodeDiscreteOutput>();

            for (int i = 0; i < discreteOutputs; i++)
            {
                outputsMutable.Add(NodeDiscreteOutput.BuildWith(
                                       new FieldIdentifier(Resources.Strings.Output + i),
                                       new FieldString(i.ToString()),
                                       new FieldSignalName(discreteOutputNameOverride + " " + i)));
            }
            var outputs = new ReadOnlyCollection <NodeDiscreteOutput>(outputsMutable);

            device = device.NodeDiscreteOutputChildren.Append(outputs);

            var analogOutputsMutable = new Collection <NodeAnalogOutput>();

            for (int i = 0; i < analogOutputs; i++)
            {
                analogOutputsMutable.Add(NodeAnalogOutput.BuildWith(
                                             new FieldIdentifier(Resources.Strings.AnalogOutput + i),
                                             new FieldString(i.ToString()),
                                             new FieldSignalName(analogOutputNameOverride + " " + i)));
            }
            device = device.NodeAnalogOutputChildren.Append(new ReadOnlyCollection <NodeAnalogOutput>(analogOutputsMutable));

            var stringOutputsMutable = new Collection <NodeStringOutput>();

            for (int i = 0; i < stringOutputs; i++)
            {
                stringOutputsMutable.Add(NodeStringOutput.BuildWith(
                                             new FieldIdentifier(Resources.Strings.StringOutput + i),
                                             new FieldString(i.ToString()),
                                             new FieldSignalName(Resources.Strings.StringOutput + " " + i)));
            }
            device = device.NodeStringOutputChildren.Append(new ReadOnlyCollection <NodeStringOutput>(stringOutputsMutable));

            return(device);
        }
        public static IEnumerable <Tuple <NodeSignal, object> > ParseEncodedSignals(string encoded, IEnumerable <NodeSignal> signals)
        {
            // parse it all into values
            var  dict  = new Dictionary <FieldGuid, object>();
            int  index = 0;
            bool found = true;

            while (found)
            {
                found = false;
                int commaPos1 = encoded.IndexOf(SEPARATOR, index);
                if (commaPos1 > 0) // signalId
                {
                    int commaPos2 = encoded.IndexOf(SEPARATOR, commaPos1 + 1);
                    if (commaPos2 > 0) // DataType
                    {
                        int commaPos3 = encoded.IndexOf(SEPARATOR, commaPos2 + 1);
                        if (commaPos3 > 0) // value length
                        {
                            string valueLengthString = encoded.Substring(commaPos2 + 1, commaPos3 - commaPos2 - 1);
                            int    valueLength;
                            if (int.TryParse(valueLengthString, out valueLength))
                            {
                                string valueString = encoded.Substring(commaPos3 + 1, valueLength);
                                if (valueString.Length == valueLength)
                                {
                                    string guidString = encoded.Substring(index, commaPos1 - index);
                                    if (FieldGuid.CheckSyntax(guidString))
                                    {
                                        var    signalId       = new FieldGuid(guidString);
                                        string dataTypeString = encoded.Substring(commaPos1 + 1, commaPos2 - commaPos1 - 1);
                                        FieldDataType.DataTypeEnum dataType;
                                        if (Enum.TryParse <FieldDataType.DataTypeEnum>(dataTypeString, out dataType))
                                        {
                                            if (FieldConstant.CheckSyntax(dataType + FieldConstant.SEPARATOR + valueString))
                                            {
                                                var constant = new FieldConstant(dataType + FieldConstant.SEPARATOR + valueString);
                                                found = true;
                                                index = commaPos3 + valueLength + 1 + END_OF_LINE.Length;
                                                dict.Add(signalId, constant.Value);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // match it up to the signals
            var retVal = new List <Tuple <NodeSignal, object> >();

            foreach (var signal in signals)
            {
                if (dict.ContainsKey(signal.SignalId))
                {
                    retVal.Add(new Tuple <NodeSignal, object>(signal, dict[signal.SignalId]));
                }
            }
            return(retVal);
        }
 public NodeBase DeltaReceivedFromPeer(FieldGuid basedOnMessageID)
 {
     // not using SoapBox.Protocol to talk to the runtime (Arduino)
     throw new NotImplementedException();
 }
Example #24
0
            private Collection <SignalTreeItem> BuildSignalTree(SignalChooserDialog dlg, NodeBase n,
                                                                NodePage pg, FieldGuid selectedSignalId, FieldDataType.DataTypeEnum dataTypeFilter)
            {
                var items = new Collection <SignalTreeItem>();

                foreach (var child in n.ChildCollection)
                {
                    var nPageCollection      = child as NodePageCollection;
                    var nPage                = child as NodePage;
                    var nInstructionGroup    = child as NodeInstructionGroup;
                    var nInstruction         = child as NodeInstruction;
                    var nSignal              = child as NodeSignal;
                    var nDeviceConfiguration = child as NodeDeviceConfiguration;
                    var nDriver              = child as NodeDriver;
                    var nDevice              = child as NodeDevice;
                    var nDiscreteInput       = child as NodeDiscreteInput;
                    var nAnalogInput         = child as NodeAnalogInput;
                    var nStringInput         = child as NodeStringInput;

                    // the following logic sets one or the other, or neither
                    SignalTreeItem item           = null;
                    NodeBase       searchChildren = null;
                    bool           sort           = false;
                    var            adjustedChild  = child;

                    if (nPageCollection != null)
                    {
                        item = new SignalTreeItem(dlg, nPageCollection.PageCollectionName.ToString(), null);
                    }
                    else if (nPage != null)
                    {
                        var pgToUse = nPage;
                        if (pg != null && nPage.PageId == pg.PageId)
                        {
                            pgToUse       = pg;
                            adjustedChild = pg;
                        }
                        item = new SignalTreeItem(dlg, pgToUse.PageName.ToString(), null);
                        sort = true;
                    }
                    else if (nInstructionGroup != null || nInstruction != null || nDiscreteInput != null || nAnalogInput != null || nStringInput != null)
                    {
                        searchChildren = adjustedChild;
                    }
                    else if (nSignal != null)
                    {
                        if (nSignal.DataType.IsOfType(dataTypeFilter))
                        {
                            item = new SignalTreeItem(dlg, nSignal.SignalName.ToString(), nSignal);
                            if (nSignal.SignalId == selectedSignalId)
                            {
                                item.IsSelected = true;
                            }
                        }
                    }
                    else if (nDeviceConfiguration != null)
                    {
                        item = new SignalTreeItem(dlg, Resources.Strings.Solution_Pad_DeviceConfigurationItem_Header, null);
                    }
                    else if (nDriver != null)
                    {
                        item = new SignalTreeItem(dlg, nDriver.DriverName.ToString(), null);
                    }
                    else if (nDevice != null)
                    {
                        item = new SignalTreeItem(dlg, nDevice.DeviceName.ToString(), null);
                    }

                    if (searchChildren != null)
                    {
                        var childItems = BuildSignalTree(dlg, searchChildren, pg, selectedSignalId, dataTypeFilter);
                        if (childItems != null)
                        {
                            foreach (var childItem in childItems)
                            {
                                items.Add(childItem);
                            }
                        }
                    }

                    if (item != null)
                    {
                        items.Add(item);
                        var childItems = BuildSignalTree(dlg, adjustedChild, pg, selectedSignalId, dataTypeFilter);
                        if (childItems != null)
                        {
                            if (sort)
                            {
                                var sorted = from c in childItems orderby c.Text select c;
                                childItems = new Collection <SignalTreeItem>();
                                foreach (var c in sorted)
                                {
                                    childItems.Add(c);
                                }
                            }
                            // make sure to have this branch of the tree expanded if the selected node is somewhere down there
                            if (childItems.Count((SignalTreeItem ti) => ti.IsSelected) > 0 ||
                                childItems.Count((SignalTreeItem ti) => ti.IsExpanded) > 0)
                            {
                                item.IsExpanded = true;
                            }

                            item.SetItems(childItems);
                        }
                    }
                }

                if (items.Count > 0)
                {
                    return(items);
                }
                else
                {
                    return(null);
                }
            }
        public static NodeDevice StaticBuildHelper(string deviceName, string typeId, Guid instanceId, string code,
                                                   int buttons, int axes, int povhats)
        {
            FieldIdentifier c;
            FieldGuid       typ;
            FieldString     address;
            FieldBase64     configuration;
            FieldDeviceName dName;

            c             = new FieldIdentifier(code);
            typ           = new FieldGuid(typeId);
            address       = new FieldString(instanceId.ToString());
            configuration = new FieldBase64(string.Empty);
            dName         = new FieldDeviceName(deviceName);

            NodeDevice device = NodeDevice.BuildWith(c, typ, address, configuration, dName);

            // Add the inputs
            var inputsMutable = new Collection <NodeDiscreteInput>();

            for (int i = 0; i < buttons; i++)
            {
                int buttonNumber = i + 1;
                inputsMutable.Add(NodeDiscreteInput.BuildWith(
                                      new FieldIdentifier(Resources.Strings.Button + buttonNumber),
                                      new FieldString(i.ToString()),
                                      new FieldSignalName(Resources.Strings.Button + " " + buttonNumber)));
            }
            var inputs = new ReadOnlyCollection <NodeDiscreteInput>(inputsMutable);

            device = device.NodeDiscreteInputChildren.Append(inputs);

            var analogInputsMutable = new Collection <NodeAnalogInput>();

            for (int i = 0; i < axes; i++)
            {
                if (i == 3)
                {
                    break;         // only supports up to 3 axes
                }
                int    axisNumber = i + 1;
                string axisName   =
                    axisNumber == 1 ? "X" :
                    axisNumber == 2 ? "Y" :
                    axisNumber == 3 ? "Z" :
                    null;

                analogInputsMutable.Add(NodeAnalogInput.BuildWith(
                                            new FieldIdentifier(axisName),
                                            new FieldString(axisName),
                                            new FieldSignalName(axisName)));

                string rotationName = "Rotation" + axisName;
                analogInputsMutable.Add(NodeAnalogInput.BuildWith(
                                            new FieldIdentifier(rotationName),
                                            new FieldString(rotationName),
                                            new FieldSignalName(rotationName)));
            }
            for (int i = 0; i < povhats; i++)
            {
                int povNumber = i + 1;
                analogInputsMutable.Add(NodeAnalogInput.BuildWith(
                                            new FieldIdentifier(Resources.Strings.PoVHat + povNumber.ToString()),
                                            new FieldString(i.ToString()),
                                            new FieldSignalName(Resources.Strings.PoVHat + " " + povNumber.ToString())));
            }
            device = device.NodeAnalogInputChildren.Append(new ReadOnlyCollection <NodeAnalogInput>(analogInputsMutable));

            return(device);
        }
Example #26
0
        /// <summary>
        /// Finds the ISolutionItem in the solution tree that
        /// corresponds to the given ID, if any
        /// </summary>
        /// <param name="nodeId"></param>
        /// <returns></returns>
        public INodeWrapper FindItemByNodeId(Guid nodeId)
        {
            var fGuid = new FieldGuid(nodeId);

            return(findItemByNodeId(rootSolutionItem, fGuid));
        }
Example #27
0
        private static Tuple <string, NodeSignal> FindSignalAndName(NodeBase fromNode, string header, NodePage localRoot, FieldGuid signalId,
                                                                    Dictionary <NodePage, NodePage> edits)
        {
            const string SEPARATOR = "/";

            string prevHeader;

            if (header.Length == 0)
            {
                prevHeader = string.Empty;
            }
            else
            {
                prevHeader = header + SEPARATOR;
            }

            var thisSig = fromNode as NodeSignal;

            if (thisSig != null && thisSig.SignalId == signalId)
            {
                return(new Tuple <string, NodeSignal>(prevHeader + thisSig.SignalName, thisSig));
            }
            else
            {
                foreach (var child in fromNode.ChildCollection)
                {
                    var nPageCollection      = child as NodePageCollection;
                    var nPage                = child as NodePage;
                    var nInstructionGroup    = child as NodeInstructionGroup;
                    var nInstruction         = child as NodeInstruction;
                    var nSignal              = child as NodeSignal;
                    var nDeviceConfiguration = child as NodeDeviceConfiguration;
                    var nDriver              = child as NodeDriver;
                    var nDevice              = child as NodeDevice;
                    var nDiscreteInput       = child as NodeDiscreteInput;
                    var nAnalogInput         = child as NodeAnalogInput;
                    var nStringInput         = child as NodeStringInput;

                    Tuple <string, NodeSignal> found = null;

                    if (nInstructionGroup != null || nInstruction != null || nDeviceConfiguration != null ||
                        nDriver != null || nDiscreteInput != null || nAnalogInput != null ||
                        nStringInput != null || nSignal != null)
                    {
                        found = FindSignalAndName(child, header, localRoot, signalId, edits);
                    }
                    else if (nPageCollection != null)
                    {
                        found = FindSignalAndName(child, prevHeader + nPageCollection.PageCollectionName, localRoot, signalId, edits);
                    }
                    else if (nPage != null)
                    {
                        string newHeader = prevHeader + nPage.PageName;
                        if (nPage == localRoot) // first, search local page, if there is one
                        {
                            found = FindSignalAndName(child, string.Empty, localRoot, signalId, edits);
                        }
                        if (found == null && edits.ContainsKey(nPage)) // search edited page, if there is one
                        {
                            found = FindSignalAndName(edits[nPage], newHeader, localRoot, signalId, edits);
                        }
                        if (found == null) // search from the root otherwise
                        {
                            found = FindSignalAndName(child, newHeader, localRoot, signalId, edits);
                        }
                    }
                    else if (nDevice != null)
                    {
                        found = FindSignalAndName(child, prevHeader + nDevice.DeviceName, localRoot, signalId, edits);
                    }
                    if (found != null)
                    {
                        return(found);
                    }
                }
                return(null);
            }
        }
Example #28
0
 public NodeBase DeltaReceivedFromPeer(FieldGuid basedOnMessageID)
 {
     // shouldn't receive any deltas at this time
     throw new NotImplementedException();
 }
Example #29
0
 public static NodeSignalIn BuildWith(FieldDataType DataType, FieldGuid SignalId)
 {
     return(BuildWith(DataType, DataType, SignalId));
 }