コード例 #1
0
        void Run()
        {
            ModLibrary library = new ModLibrary();

            Console.Out.WriteLine("Loading modules");
#if DEBUG
            cppProxy.CppProxyModuleDriver.DoDiscovery(@"..\..\..\Debug", library);
#else
            cppProxy.CppProxyModuleDriver.DoDiscovery(@"..\..\..\Release", library);
#endif

            Console.Out.WriteLine("Building schematic");
            Layout.Schematic         schem         = new Layout.Schematic();
            Layout.Schematic.Element radioElem     = new Layout.Schematic.Element(Layout.ElementType.Module, "radio");
            Layout.Schematic.Element frameElem     = new Layout.Schematic.Element(Layout.ElementType.Module, "make frame");
            Layout.Schematic.Element fftElem       = new Layout.Schematic.Element(Layout.ElementType.Module, "fft");
            Layout.Schematic.Element mag2Func      = new Layout.Schematic.Element(Layout.ElementType.Function, "mag^2");
            Layout.Schematic.Element divideByN     = new Layout.Schematic.Element(Layout.ElementType.Function, "divide by N");
            Layout.Schematic.Element dbFunc        = new Layout.Schematic.Element(Layout.ElementType.Function, "dB");
            Layout.Schematic.Element splitterElem  = new Layout.Schematic.Element(Layout.ElementType.Module, "splitter");
            Layout.Schematic.Element waterfallElem = new Layout.Schematic.Element(Layout.ElementType.Module, "waterfall");
            Layout.Schematic.Element waveformElem  = new Layout.Schematic.Element(Layout.ElementType.Module, "waveform");
//            Layout.Schematic.Element chopElem = new Layout.Schematic.Element(Layout.ElementType.Function, "chop real frame");
            Layout.Schematic.Element frameMin     = new Layout.Schematic.Element(Layout.ElementType.FunctionOnIn, "frame min");
            Layout.Schematic.Element identityElem = new Layout.Schematic.Element(Layout.ElementType.Module, "=");
//            Layout.Schematic.Element frameMax = new Layout.Schematic.Element(Layout.ElementType.FunctionOnIn, "frame max");

            schem.connect(radioElem, "recv1", frameElem, 0);
//            schem.connect(radioElem, "wide", fftElem, 0);
            schem.connect(frameElem, fftElem);
            schem.connect(fftElem, divideByN);
//            schem.connect(fftElem, chopElem);
//            schem.connect(chopElem, divideByN);
            schem.connect(divideByN, mag2Func);
            schem.connect(mag2Func, dbFunc);
            schem.connect(dbFunc, splitterElem);
            schem.connect(splitterElem, waterfallElem);
            schem.connect(splitterElem, 1, waveformElem, 0);
            schem.connect(splitterElem, 2, frameMin, 0);
//            schem.connect(splitterElem, 3, frameMax, 0);
            schem.connect(frameMin, identityElem);

            Console.Out.WriteLine("Resolving schematic");
            List <Layout.Schematic> options;
            try
            {
                options = schem.resolve(library);
            }
            catch (Layout.Schematic.ResolveFailure fail)
            {
                Console.Out.WriteLine("Schematic could not be resolved:");
                foreach (KeyValuePair <Layout.Schematic.ResolveFailureReason, bool> entry in fail.reasons)
                {
                    Console.Out.WriteLine("\t{0}", entry.Key.Message);
                }
                return;
            }

            Console.Out.WriteLine("Building circuit");
            using (Layout.Circuit circuit = options[0].construct())
            {
                Console.Out.WriteLine("Configuring circuit");
                signals.IBlock      hpsdr = (signals.IBlock)circuit.Entry(radioElem);
                signals.IAttributes attrs = hpsdr.Attributes;
                signals.OnChanged   evt   = new signals.OnChanged(OnChanged);
                foreach (signals.IAttribute attr in attrs)
                {
                    attr.changed += evt;
                }
                attrs["recvRate"].Value  = 48000;
                attrs["Recv1Freq"].Value = 10000000;

                signals.IBlock       ident    = (signals.IBlock)circuit.Entry(identityElem);
                signals.IOutEndpoint identOut = ident.Outgoing[0];
                signals.IEPBuffer    outBuff  = identOut.CreateBuffer();
                identOut.Connect(outBuff);
                cppProxy.ReceiveStream stream = new cppProxy.ReceiveStream(identOut.Type, outBuff);
                stream.data += new cppProxy.ReceiveStream.OnReceive(OnStreamDetail);

                Canvas canvas = new Canvas();
                canvas.freq1.Attribute      = attrs["Recv1Freq"];
                canvas.panel1.WaveformBlock = (signals.IBlock)circuit.Entry(waveformElem);
                canvas.panel2.WaveformBlock = (signals.IBlock)circuit.Entry(waterfallElem);

                Thread canvasThread = canvas.Start();

                Console.Out.WriteLine("Powering circuit");
                circuit.Start();
                canvasThread.Join();

                Console.Out.WriteLine("Shutting down circuit");
                circuit.Stop();
                stream.Stop();
            }
            //        Console.Out.WriteLine(String.Format("{0} received total", packetsReceived));
            int _i = 0;
        }
コード例 #2
0
        public Circuit construct()
        {
            Dictionary <int, Circuit.Element> result    = new Dictionary <int, Circuit.Element>();
            Dictionary <Element, object>      elmResult = new Dictionary <Element, object>();

            foreach (KeyValuePair <int, Element> here in contents)
            {
                Element elm = here.Value;
                if (elm.availObjects.Count != 1)
                {
                    throw new ApplicationException("expecting all elements to have exactly one solution");
                }
                signals.ICircuitConnectible avail = elm.availObjects[0];
                signals.ICircuitElement     newOb = null;
                switch (elm.type)
                {
                case ElementType.Module:
                {
                    signals.IBlockDriver drv = avail as signals.IBlockDriver;
                    if (drv != null)
                    {
                        newOb = drv.Create();
                    }
                    else
                    {
                        newOb = (signals.IBlock)avail;
                    }
                    break;
                }

                case ElementType.Function:
                case ElementType.FunctionOnIn:
                case ElementType.FunctionOnOut:
                    newOb = ((signals.IFunctionSpec)avail).Create();
                    break;
                }
                result.Add(elm.circuitId, new Circuit.Element(new ElemKey(elm), elm.circuitId, newOb));
                elmResult.Add(elm, newOb);
            }

            foreach (KeyValuePair <EndpointKey, EndpointKey> conn in connections)
            {
                EndpointKey from    = conn.Key;
                EndpointKey to      = conn.Value;
                object      fromObj = elmResult[from.elem];
                object      toObj   = elmResult[to.elem];
                switch (from.elem.type)
                {
                case ElementType.Module:
                {
                    signals.IOutEndpoint outEP = from.OutputEP((signals.IBlock)fromObj);
                    switch (to.elem.type)
                    {
                    case ElementType.Module:
                    {
                        signals.IEPBuffer   buff = outEP.CreateBuffer();
                        signals.IInEndpoint inEP = to.InputEP((signals.IBlock)toObj);
                        outEP.Connect(buff);
                        inEP.Connect(buff);
                        break;
                    }

                    case ElementType.Function:
                    case ElementType.FunctionOnIn:
                    {
                        signals.IEPBuffer   buff = outEP.CreateBuffer();
                        signals.IInEndpoint inEP = ((signals.IFunction)toObj).Input;
                        outEP.Connect(buff);
                        inEP.Connect(buff);
                        break;
                    }

                    case ElementType.FunctionOnOut:
                    {
                        signals.IEPSendTo inEP = ((signals.IFunction)toObj).Output;
                        outEP.Connect(inEP);
                        break;
                    }
                    }
                    break;
                }

                case ElementType.Function:
                case ElementType.FunctionOnIn:
                {
                    signals.IInputFunction func = ((signals.IFunction)fromObj).Input;
                    switch (to.elem.type)
                    {
                    case ElementType.Module:
                    {
                        signals.IInEndpoint inEP = to.InputEP((signals.IBlock)toObj);
                        inEP.Connect(func);
                        break;
                    }

                    case ElementType.Function:
                    case ElementType.FunctionOnIn:
                    {
                        signals.IInEndpoint inEP = ((signals.IFunction)toObj).Input;
                        inEP.Connect(func);
                        break;
                    }

                    case ElementType.FunctionOnOut:
                        throw new ApplicationException("incompatible connection types");
                    }
                    break;
                }

                case ElementType.FunctionOnOut:
                {
                    signals.IOutputFunction func = ((signals.IFunction)fromObj).Output;
                    switch (to.elem.type)
                    {
                    case ElementType.Module:
                    {
                        signals.IEPBuffer   buff = func.CreateBuffer();
                        signals.IInEndpoint inEP = to.InputEP((signals.IBlock)toObj);
                        func.Connect(buff);
                        inEP.Connect(buff);
                        break;
                    }

                    case ElementType.Function:
                    case ElementType.FunctionOnIn:
                    {
                        signals.IEPBuffer   buff = func.CreateBuffer();
                        signals.IInEndpoint inEP = ((signals.IFunction)toObj).Input;
                        func.Connect(buff);
                        inEP.Connect(buff);
                        break;
                    }

                    case ElementType.FunctionOnOut:
                    {
                        signals.IOutEndpoint outEP = ((signals.IFunction)toObj).Output;
                        outEP.Connect(func);
                        break;
                    }
                    }
                    break;
                }
                }
            }
            return(new Circuit(result));
        }