SEXP rSet(SEXP p) { // 1 - Get data from SEXP p = CDR(p); // Skip the first parameter: because function name IUnknown* instancePtr = readInstanceFromSexp(p); p = CDR(p); char* strPropertyName = readStringFromSexp(p); p = CDR(p); LONGLONG valueAddresse = (LONGLONG)CAR(p); // 2 - Prepare arguments to call proxy SAFEARRAY* args = SafeArrayCreateVector(VT_VARIANT, 0, 3); long i = 0; // 2.1 - external pointer on .Net object variant_t instance(instancePtr); SafeArrayPutElement(args, &i, &instance); i++; // 2.2 - Method name variant_t propertyName(strPropertyName); SafeArrayPutElement(args, &i, &propertyName); i++; // 2.3 property value variant_t value(valueAddresse); SafeArrayPutElement(args, &i, &value); i++; // 3 - Call the proxy CLR_OBJ result; char* errorMsg; HRESULT hr = callProxy(L"SetProperty", args, &result, &errorMsg); if(FAILED(hr)) { Rprintf(errorMsg); error("Exception during netSet !"); free(errorMsg); return R_NilValue; } SafeArrayDestroy(args); return R_NilValue; }
Spectrogram(const Pothos::ProxyEnvironment::Sptr &remoteEnv) { _display.reset(new SpectrogramDisplay()); _display->setName("Display"); auto registry = remoteEnv->findProxy("Pothos/BlockRegistry"); _trigger = registry.callProxy("/comms/wave_trigger"); _trigger.callVoid("setName", "Trigger"); _trigger.callVoid("setMode", "PERIODIC"); //register calls in this topology this->registerCall(this, POTHOS_FCN_TUPLE(Spectrogram, setNumFFTBins)); this->registerCall(this, POTHOS_FCN_TUPLE(Spectrogram, setFreqLabelId)); this->registerCall(this, POTHOS_FCN_TUPLE(Spectrogram, setRateLabelId)); //connect to internal display block this->connect(this, "setTitle", _display, "setTitle"); this->connect(this, "setDisplayRate", _display, "setDisplayRate"); this->connect(this, "setSampleRate", _display, "setSampleRate"); this->connect(this, "setCenterFrequency", _display, "setCenterFrequency"); this->connect(this, "setNumFFTBins", _display, "setNumFFTBins"); this->connect(this, "setWindowType", _display, "setWindowType"); this->connect(this, "setTimeSpan", _display, "setTimeSpan"); this->connect(this, "setReferenceLevel", _display, "setReferenceLevel"); this->connect(this, "setDynamicRange", _display, "setDynamicRange"); this->connect(this, "enableXAxis", _display, "enableXAxis"); this->connect(this, "enableYAxis", _display, "enableYAxis"); this->connect(_display, "frequencySelected", this, "frequencySelected"); //connect to the internal snooper block this->connect(_display, "updateRateChanged", _trigger, "setEventRate"); this->connect(this, "setNumFFTBins", _trigger, "setNumPoints"); //connect stream ports this->connect(this, 0, _trigger, 0); this->connect(_trigger, 0, _display, 0); }
SEXP rGetStatic(SEXP p) { // 1 - Get data from SEXP p = CDR(p); // Skip the first parameter: because function name char* strTypeName = readStringFromSexp(p); p = CDR(p); char* strPropertyName = readStringFromSexp(p); p = CDR(p); // 2 - Prepare arguments to call proxy SAFEARRAY* args = SafeArrayCreateVector(VT_VARIANT, 0, 2); long i = 0; // 2.1 - Type name variant_t typeName(strTypeName); SafeArrayPutElement(args, &i, &typeName); i++; // 2.2 - Method name variant_t propertyName(strPropertyName); SafeArrayPutElement(args, &i, &propertyName); i++; // 3 - Call the proxy CLR_OBJ result; char* errorMsg; HRESULT hr = callProxy(L"GetStaticProperty", args, &result, &errorMsg); if(FAILED(hr)) { Rprintf(errorMsg); error("Exception during netGetStatic !"); free(errorMsg); return R_NilValue; } // 4 - Free memory SafeArrayDestroy(args); return convertToSEXP(result); }
// Copyright (c) 2014-2014 Josh Blum // SPDX-License-Identifier: BSL-1.0 #include <Pothos/Testing.hpp> #include <Pothos/Framework.hpp> #include <Pothos/Proxy.hpp> #include <iostream> POTHOS_TEST_BLOCK("/blocks/tests", test_signals_and_slots) { auto env = Pothos::ProxyEnvironment::make("managed")->findProxy("Pothos/BlockRegistry"); auto feeder = env.callProxy("/blocks/feeder_source", "int"); auto collector = env.callProxy("/blocks/collector_sink", "int"); auto messageToSignal = env.callProxy("/blocks/message_to_signal", "changeEvent"); auto slotToMessage = env.callProxy("/blocks/slot_to_message", "handleEvent"); //feed some msgs feeder.callProxy("feedMessage", Pothos::Object("msg0")); feeder.callProxy("feedMessage", Pothos::Object("msg1")); //run the topology { Pothos::Topology topology; topology.connect(feeder, 0, messageToSignal, 0); topology.connect(messageToSignal, "changeEvent", slotToMessage, "handleEvent"); topology.connect(slotToMessage, 0, collector, 0); topology.commit(); POTHOS_TEST_TRUE(topology.waitInactive()); } //collect the messages
" out[i] = in0[i] + in1[i];\n" "}" "__kernel void copy_int(\n" " __global const int* in,\n" " __global int* out\n" ")\n" "{\n" " const uint i = get_global_id(0);\n" " out[i] = in[i];\n" "}" ; POTHOS_TEST_BLOCK("/opencl/tests", test_opencl_kernel) { auto registry = Pothos::ProxyEnvironment::make("managed")->findProxy("Pothos/BlockRegistry"); auto collector = registry.callProxy("/blocks/collector_sink", "float32"); auto feeder0 = registry.callProxy("/blocks/feeder_source", "float32"); auto feeder1 = registry.callProxy("/blocks/feeder_source", "float32"); auto openClKernel = registry.callProxy("/blocks/opencl_kernel", "0:0", std::vector<std::string>(2, "float"), std::vector<std::string>(1, "float")); openClKernel.callVoid("setSource", "add_2x_float32", KERNEL_SOURCE); openClKernel.callVoid("setLocalSize", 1); openClKernel.callVoid("setGlobalFactor", 1.0); openClKernel.callVoid("setProductionFactor", 1.0); //feed buffer auto b0 = Pothos::BufferChunk(10*sizeof(float)); auto p0 = b0.as<float *>(); for (size_t i = 0; i < 10; i++) p0[i] = i; feeder0.callProxy("feedBuffer", b0);
// Copyright (c) 2014-2014 Josh Blum // SPDX-License-Identifier: BSL-1.0 #include <Pothos/Testing.hpp> #include <Pothos/Framework.hpp> #include <Pothos/Proxy.hpp> #include <iostream> POTHOS_TEST_BLOCK("/blocks/tests", test_arithmetic_add) { auto registry = Pothos::ProxyEnvironment::make("managed")->findProxy("Pothos/BlockRegistry"); auto feeder0 = registry.callProxy("/blocks/feeder_source", "int"); auto feeder1 = registry.callProxy("/blocks/feeder_source", "int"); auto adder = registry.callProxy("/blocks/arithmetic", "int", "ADD"); auto collector = registry.callProxy("/blocks/collector_sink", "int"); //load feeder blocks auto b0 = Pothos::BufferChunk(10*sizeof(int)); auto p0 = b0.as<int *>(); for (size_t i = 0; i < 10; i++) p0[i] = i; feeder0.callProxy("feedBuffer", b0); auto b1 = Pothos::BufferChunk(10*sizeof(int)); auto p1 = b1.as<int *>(); for (size_t i = 0; i < 10; i++) p1[i] = i+10; feeder1.callProxy("feedBuffer", b1); //run the topology { Pothos::Topology topology;
auto collector = Pothos::BlockRegistry::make("/blocks/collector_sink", "uint8"); //setup the topology Pothos::Topology topology; topology.connect(feeder, 0, symsToBits, 0); topology.connect(symsToBits, 0, bitsToSyms, 0); topology.connect(bitsToSyms, 0, collector, 0); //create a test plan for streams std::cout << "Perform stream-based test plan..." << std::endl; Poco::JSON::Object::Ptr testPlan0(new Poco::JSON::Object()); testPlan0->set("enableBuffers", true); testPlan0->set("enableLabels", true); testPlan0->set("minValue", 0); testPlan0->set("maxValue", (1 << mod) - 1); auto expected0 = feeder.callProxy("feedTestPlan", testPlan0); topology.commit(); POTHOS_TEST_TRUE(topology.waitInactive(0.01)); collector.callVoid("verifyTestPlan", expected0); //create a test plan for packets std::cout << "Perform packet-based test plan..." << std::endl; Poco::JSON::Object::Ptr testPlan1(new Poco::JSON::Object()); testPlan1->set("enablePackets", true); testPlan1->set("enableLabels", true); testPlan1->set("minValue", 0); testPlan1->set("maxValue", (1 << mod) - 1); auto expected1 = feeder.callProxy("feedTestPlan", testPlan1); topology.commit(); POTHOS_TEST_TRUE(topology.waitInactive(0.01)); collector.callVoid("verifyTestPlan", expected1);
// Copyright (c) 2015-2015 Josh Blum // SPDX-License-Identifier: BSL-1.0 #include <Pothos/Testing.hpp> #include <Pothos/Framework.hpp> #include <Pothos/Proxy.hpp> #include <Poco/JSON/Object.h> #include <iostream> #include <complex> POTHOS_TEST_BLOCK("/comms/tests", test_symbol_mapper_slicer_float) { auto env = Pothos::ProxyEnvironment::make("managed"); auto registry = env->findProxy("Pothos/BlockRegistry"); auto feeder = registry.callProxy("/blocks/feeder_source", "unsigned char"); auto mapper = registry.callProxy("/comms/symbol_mapper", "float"); auto slicer = registry.callProxy("/comms/symbol_slicer", "float"); auto collector = registry.callProxy("/blocks/collector_sink", "unsigned char"); static const float mapD[] = {-3, -1, 1, 3}; std::vector<float> map(mapD, mapD+4); mapper.callProxy("setMap", map); slicer.callProxy("setMap", map); //load feeder blocks auto b0 = Pothos::BufferChunk(10*sizeof(unsigned char)); auto p0 = b0.as<unsigned char *>(); for (size_t i = 0; i < 10; i++) p0[i] = i&3; feeder.callProxy("feedBuffer", b0);
POTHOS_TEST_BLOCK("/fpga/tests", test_loopback) { //create client environment auto env = getSimulationEnv("LoopbackTb"); auto SimulationHarness = env->findProxy("Pothos/FPGA/SimulationHarness"); auto sourceIndexes = SimulationHarness.call<std::vector<int>>("getSourceIndexes"); POTHOS_TEST_EQUAL(sourceIndexes.size(), 1); POTHOS_TEST_EQUAL(sourceIndexes[0], 0); auto sinkIndexes = SimulationHarness.call<std::vector<int>>("getSinkIndexes"); POTHOS_TEST_EQUAL(sinkIndexes.size(), 1); POTHOS_TEST_EQUAL(sinkIndexes[0], 0); auto source0 = SimulationHarness.callProxy("getSourceBlock", 0); auto sink0 = SimulationHarness.callProxy("getSinkBlock", 0); auto registry = env->findProxy("Pothos/BlockRegistry"); auto feeder = registry.callProxy("/blocks/feeder_source", "int"); auto collector = registry.callProxy("/blocks/collector_sink", "int"); //create a test plan Poco::JSON::Object::Ptr testPlan(new Poco::JSON::Object()); testPlan->set("enableBuffers", true); auto expected = feeder.callProxy("feedTestPlan", testPlan); //run the topology { Pothos::Topology topology; topology.connect(feeder, 0, sink0, 0);
// Copyright (c) 2014-2014 Josh Blum // SPDX-License-Identifier: BSL-1.0 #include <Pothos/Testing.hpp> #include <Pothos/Framework.hpp> #include <Pothos/Proxy.hpp> #include <Pothos/Remote.hpp> #include <Poco/JSON/Object.h> #include <iostream> POTHOS_TEST_BLOCK("/blocks/tests", test_converter) { auto env = Pothos::ProxyEnvironment::make("managed"); auto registry = env->findProxy("Pothos/BlockRegistry"); auto feeder = registry.callProxy("/blocks/feeder_source", "short"); auto converter = registry.callProxy("/blocks/converter", "int"); auto collector = registry.callProxy("/blocks/collector_sink", "int"); //create a test plan Poco::JSON::Object::Ptr testPlan(new Poco::JSON::Object()); testPlan->set("enableBuffers", true); testPlan->set("enableLabels", true); auto expected = feeder.callProxy("feedTestPlan", testPlan); //run the topology { Pothos::Topology topology; topology.connect(feeder, 0, converter, 0); topology.connect(converter, 0, collector, 0); topology.commit(); POTHOS_TEST_TRUE(topology.waitInactive());
// Copyright (c) 2015-2015 Josh Blum // SPDX-License-Identifier: BSL-1.0 #include <Pothos/Testing.hpp> #include <Pothos/Framework.hpp> #include <Pothos/Proxy.hpp> #include <Poco/JSON/Object.h> #include <iostream> POTHOS_TEST_BLOCK("/blocks/tests", test_simple_mac) { auto env = Pothos::ProxyEnvironment::make("managed"); auto registry = env->findProxy("Pothos/BlockRegistry"); //create test blocks auto feeder = registry.callProxy("/blocks/feeder_source", "uint8"); auto collector = registry.callProxy("/blocks/collector_sink", "uint8"); auto mac = registry.callProxy("/blocks/simple_mac"); const unsigned short macId = std::rand() & 0xffff; mac.callVoid("setMacId", macId); //create a test packet Pothos::Packet pkt0; pkt0.payload = Pothos::BufferChunk("uint8", 100); for (size_t i = 0; i < pkt0.payload.elements(); i++) pkt0.payload.as<unsigned char *>()[i] = std::rand() & 0xff; pkt0.metadata["recipient"] = Pothos::Object(macId); feeder.callVoid("feedPacket", pkt0); //setup the topology Pothos::Topology topology;
// SPDX-License-Identifier: BSL-1.0 #include <Pothos/Testing.hpp> #include <Pothos/Proxy.hpp> #include <Pothos/Framework.hpp> #include <Pothos/Exception.hpp> #include <Pothos/Object/Containers.hpp> #include <complex> #include <iostream> POTHOS_TEST_BLOCK("/util/tests", test_eval_expression) { //check that the following does not throw auto env = Pothos::ProxyEnvironment::make("managed"); auto EvalEnvironment = env->findProxy("Pothos/Util/EvalEnvironment"); auto evalEnv = EvalEnvironment.callProxy("new"); //booleans const auto resultT = evalEnv.call<Pothos::Object>("eval", "true"); POTHOS_TEST_TRUE(resultT.convert<bool>()); const auto resultF = evalEnv.call<Pothos::Object>("eval", "false"); POTHOS_TEST_TRUE(not resultF.convert<bool>()); //simple expression const auto result = evalEnv.call<Pothos::Object>("eval", "1 + 2"); POTHOS_TEST_EQUAL(result.convert<int>(), 3); //a pothos type //const auto result2 = evalEnv.call<Pothos::Object>("eval", "DType(\"int32\")"); //POTHOS_TEST_TRUE(result2.convert<Pothos::DType>() == Pothos::DType(typeid(int)));
#include <iostream> POTHOS_TEST_BLOCK("/blocks/tests", test_network_topology) { //spawn a server and client std::cout << "create proxy server\n"; Pothos::RemoteServer server("tcp://0.0.0.0"); Pothos::RemoteClient client("tcp://localhost:"+server.getActualPort()); //local and remote block registries auto remoteReg = client.makeEnvironment("managed")->findProxy("Pothos/BlockRegistry"); auto localReg = Pothos::ProxyEnvironment::make("managed")->findProxy("Pothos/BlockRegistry"); //create local and remote unit test blocks std::cout << "create remote feeder\n"; auto feeder = remoteReg.callProxy("/blocks/feeder_source", "int"); std::cout << "create local collector\n"; auto collector = localReg.callProxy("/blocks/collector_sink", "int"); //create a test plan Poco::JSON::Object::Ptr testPlan(new Poco::JSON::Object()); testPlan->set("enableBuffers", true); testPlan->set("enableLabels", true); testPlan->set("enableMessages", true); auto expected = feeder.callProxy("feedTestPlan", testPlan); //run the topology std::cout << "run the topology\n"; { Pothos::Topology topology; topology.connect(feeder, 0, collector, 0);