Example #1
0
        private RouteComponent applyMath(Operation op, float rhs)
        {
            bool multiChnlMath = state.bridge.getFirmware().CompareTo(MULTI_CHANNEL_MATH) >= 0;

            if (!multiChnlMath && source.attributes.length() > 4)
            {
                throw new IllegalRouteOperationException("Cannot apply math operations on multi-channel data for firmware prior to " + MULTI_CHANNEL_MATH.ToString());
            }

            if (source.attributes.length() <= 0)
            {
                throw new IllegalRouteOperationException("Cannot apply math operations to null data");
            }

            if (source.eventConfig[0] == (byte)SENSOR_FUSION)
            {
                throw new IllegalRouteOperationException("Cannot apply math operations to sensor fusion data");
            }

            int scaledRhs;

            switch (op)
            {
            case Operation.Add:
            case Operation.Modulus:
            case Operation.Subtract:
                scaledRhs = (int)(rhs * source.scale(state.bridge));
                break;

            case Operation.Sqrt:
            case Operation.AbsValue:
                scaledRhs = 0;
                break;

            default:
                scaledRhs = (int)rhs;
                break;
            }

            var config = new MathConfig(source.attributes, multiChnlMath, op, scaledRhs);
            var next   = source.transform(config, state.bridge.GetModule <IDataProcessor>() as DataProcessor);

            config.output = next.Item1.attributes.sizes[0];

            return(postCreate(next.Item2, new MapEditorInner(config, next.Item1, state.bridge)));
        }
Example #2
0
        public static void ParseMML(XElement root, MathNode parentNode, MathConfig mc, int depth)
        {
            int recDepth = depth + 1;

            foreach (XElement element in root.Elements())
            {
                //ToDo: implement namespaces
                Console.WriteLine("{0} {1}", new String(' ', recDepth), element.Name);
                MathNode mn = new MathNode(
                    element.Name.LocalName,
                    element.Attributes().ToDictionary(kvp => kvp.Name.ToString(), kvp => kvp.Value),
                    mc, parentNode);
                element.Nodes()
                .Where(x => x.NodeType == System.Xml.XmlNodeType.Text || x.NodeType == System.Xml.XmlNodeType.Whitespace)
                .ToList()
                .ForEach(x => mn.Text = mn.Text + string.Join(" ", ((XText)x).Value.Split(null)));
                ParseMML(element, mn, mc, recDepth);
            }
        }