I'm now reading some code from radio module library and I found such function:
void nRF24_FlushRX(void)
{
uint8_t command = NRF24_CMD_FLUSH_RX;
NRF24_CSN_LOW;
nRF24_SendSpi(&command, 1);
NRF24_CSN_HIGH;
}
And I wonder what does it means to flush some data via SPI.
Communication modules commonly use a buffer for data received but not obtained by the application. This commands empties the buffer, and you cannot obtain the received data any more.
Related
I am trying to define a complex structure (practically a POD) as a property in a REP file. The structure is defined already as Q_GADGET in a separate header file.
When I try to instantiate the replica the system crashes complaining that
it is unable to create a certain type (and in the log then comes three completely bogus (e.g. too high) type id numbers)
Is it possible to define structures as properties in the QT5 Remote Object
world? If yes how?
Thanks,
It appears my "naive" operator<< implementation was wrong. I simply <<-ed all the members one after the other into the stream, which caused some issues.
However using the
inline QDataStream& operator<<(QDataStream& stream, const my::api::User & value) {
QtRemoteObjects::copyStoredProperties(&value, stream);
return stream;
}
inline QDataStream& operator>>(QDataStream& stream, my::api::User & value) {
QtRemoteObjects::copyStoredProperties(stream, &value);
return stream;
}
"ethalon" solution (generated my the REPC compiler for PODs) works just fine.
Does FlatBuffer allow to convert a binary fbs file to and from JSON (of course the schema will be known)?
My idea is to define the schema of structures for a pipe&filter architecture in FlatBuffer. The FlatBuffer files will also be exchanged between pipes. However, some tools within some of the filters will require me to pass plain old json objects, converted from the FlatBuffer files. And I have several languages to support (C++, Python, Java, JS).
I've found a javascript library which seems to do this:
https://github.com/evanw/node-flatbuffers/
But it seems abdondened and I'm rather interested in officially supported ways.
Only C++ provides this functionality out of the box.
For other languages, you can wrap the C++ parser/generator, and call it (see e.g. for Java: http://frogermcs.github.io/json-parsing-with-flatbuffers-in-android/).
#evanw is the original author of the JS port in FlatBuffers, so the project you mention may be usable, but I don't think he's actively maintaining it anymore.
Alternatively, if this runs on a server and you can run command-line utilities, you can use the flatc binary to do the conversion for you via a file.
Ideally, all languages would have their own native parser, but that is a lot of work to duplicate. While interfacing with C/C++ is a pain, it has the advantage of giving you a really fast parser.
It is easy to convert flatbuffer buffer to JSON using Flat C version (FlatCC).
Please refer the sample tests in flatcc source path: flatcc-master/test/json_test.
Generate required json helper headers files using:
flatcc_d -a --json <yourData.fbs>
It will generate yourData_json_printer.h. Include this header file in your program.
Modify the below code to fit <yourData>. buffer is your flatbuffer input received from other end.
Also do not use sizeof() to get bufferSize from buffer for flatbuffer. Print the buffersize before calling this
function
void flatbufToJson(const char *buffer, size_t bufferSize) {
flatcc_json_printer_t ctx_obj, *ctx;
FILE *fp = 0;
const char *target_filename = "yourData.json";
ctx = &ctx_obj;
fp = fopen(target_filename, "wb");
if (!fp) {
fprintf(stderr, "%s: could not open output file\n", target_filename);
printf("ctx not ready for clenaup, so exit directly\n");
return;
}
flatcc_json_printer_init(ctx, fp);
flatcc_json_printer_set_force_default(ctx, 1);
/* Uses same formatting as golden reference file. */
flatcc_json_printer_set_nonstrict(ctx);
//Check and modify here...
//the following should be re-written based on your fbs file and generated header file.
<yourData>_print_json(ctx, buffer, bufferSize);
flatcc_json_printer_flush(ctx);
if (flatcc_json_printer_get_error(ctx)) {
printf("could not print data\n");
}
fclose(fp);
printf("######### Json is done: \n");
}
I'm trying to force CAN signals to given values using COM interface of CANalyzer. Since there is no COM method to send CAN messages, I'm implementing a workaround using CAPL:
void SendMySignal(int value) {
message MyMessage msg;
msg.MySignal = value;
output(msg);
}
This works fine, however since MyMessage and MySignal are referenced statically (by name) here, I'll have to implement N functions to be able to send N signals (or an N-way switch statement, etc). Is there a way to avoid the hassle and access signals inside a message by string? Something like this:
void SendSignal(int MessageID, char SignalName, int value)
I'm also open to alternative solutions in case I have missed something in the COM interface. If there is a solution which only works for CANoe, I can ask my boss for a license, but of course I'd prefer to do without.
there is such function, but it is restricted to be used only in test nodes
long setSignal(char signalName[], double aValue);
you can find details in:
CAPL Function Overview » Test Feature Set / Signal Access » SetSignal
Special Use Case: Signal is not known before Measurement Start
and take care about not to send for each signal a new message to avoid bus over-flooding. In my opinion it is a better style to set all signals for whole message and to send it on change only when it is not cyclic. Signal updates in cyclic messages mostly have to be sent in next cycle.
i've assumed that dumping a .bc file from a module was a trivial operation, but now,
first time i have to actually do it from code, for the life of me i
can't find one missing step in the process:
static void WriteModule ( const Module * M, BitstreamWriter & Stream )
http://llvm.org/docs/doxygen/html/BitcodeWriter_8cpp.html#a828cec7a8fed9d232556420efef7ae89
to write that module, first i need a BistreamWriter
BitstreamWriter::BitstreamWriter (SmallVectorImpl< char > &O)
http://llvm.org/docs/doxygen/html/classllvm_1_1BitstreamWriter.html
and for a BitstreamWriter i need a SmallVectorImpl. But, what next?
Should i write the content of the SmallVectorImpl byte by byte on a
file handler myself? is there a llvm api for this? do i need something
else?
The WriteModule function is static within lib/Bitcode/Writer/BitcodeWriter.cpp, which means it's not there for outside consumption (you can't even access it).
The same file has another function, however, called WriteBitcodeToFile, with this interface:
/// WriteBitcodeToFile - Write the specified module to the specified output
/// stream.
void llvm::WriteBitcodeToFile(const Module *M, raw_ostream &Out);
I can't imagine a more convenient interface. The header file declaring it is ./include/llvm/Bitcode/ReaderWriter.h, by the way.
I use following code :
std::error_code EC;
llvm::raw_fd_ostream OS("module", EC, llvm::sys::fs::F_None);
WriteBitcodeToFile(pBiFModule, OS);
OS.flush();
and then disassemble using llvm-dis.
I'm trying to build a small program that hosts vst effects and I would like to scan a folder for plugin dlls.
I know how to find all the dlls but now I have the following questions:
What is the best way to determine if a given dll is a vst plugin?
I tried to just see if the ddl exports the proper function and this works fine for plugins made with the more recent versions of the vst sdk since it exports a method called "VstPluginMain" but older versions export a rather generic "main" function.
How do I determine if the plugin is an effect or an instrument?
How do I scan vst shell plugins?
Shell plugins are basically dlls that somehow contain multiple effects. An example of this are the plugins made by Waves Audio http://www.waves.com/
ps: If there is a library that can do all of this for me please let me know.
How to determine a VST plugin?
Once you've found main/VSTPluginMain... call it!
If what's returned is NULL, it's not a VST.
If what's returned is a pointer to the bytes "VstP" (see VstInt32 magic; ///< must be #kEffectMagic ('VstP') in aeffect.h), then you have a VST.
The VSTPluginMain returns a pointer to an AEffect structure. You will need to look at this structure.
Effect or instrument? AEffect::flags | (effFlagsIsSynth = 1 << 8)
Shell VSTs are more complex:
Category will be kPlugCategShell
Support the "shellCategory" canDo.
Use effShellGetNextPlugin to enumerate.
To instance, respond to audioMasterCurrentId in your callback with the ID you want.
#Dave Gamble nailed it, but I wanted to add a few things on VST shell plugins, since they are a bit tricky to work with.
To determine if a VST is a shell plugin, send the effGetPlugCategory opcode to the plugin dispatcher. If it returns kPlugCategShell, then it's a shell plugin. To get the list of sub-plugins in the shell, you basically call effShellGetNextPlugin until it returns 0. Example code snippit (adapted from a working VST host):
// All this stuff should probably be set up far earlier in your code...
// This assumes that you have already opened the plugin and called VSTPluginMain()
typedef VstIntPtr (*Vst2xPluginDispatcherFunc)(AEffect *effect, VstInt32 opCode, VstInt32 index, VstIntPtr value, void *ptr, float opt);
Vst2xPluginDispatcherFunc dispatcher;
AEffect* plugin;
char nameBuffer[40];
while(true) {
memset(nameBuffer, 0, 40);
VstInt32 shellPluginId = dispatcher(pluginHandle, effShellGetNextPlugin, 0, 0, nameBuffer, 0.0f);
if(shellPluginId == 0 || nameBuffer[0] == '\0') {
break;
}
else {
// Do something with the name and ID
}
}
If you actually want to load a plugin in a VST shell, it's a bit trickier. First, your host needs to handle the audioMasterCurrentId opcode in the host callback. When you call the VST's VSTPluginMain() method to instantiate the plugin, it will call the host callback with this opcode and ask for the unique ID which should be loaded.
Because this callback is made before the main function returns (and hence, before it delivers an AEffect* to your host), that means that you probably will need to store the shell plugin ID to load in a global variable, since you will not be able to save a pointer to any meaningful data in void* user field of the AEffect struct in time for it to be passed back to you in the host callback.
If you want to develop your VST Host application in .NET take a look at VST.NET