Skip to content

Commit

Permalink
Merge branch 'dr-embed' of github.com:drowe67/radae into dr-embed
Browse files Browse the repository at this point in the history
  • Loading branch information
drowe67 committed Sep 25, 2024
2 parents 96b977a + 0a6c04e commit 301fb93
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions embed/radae_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#include "numpy/arrayobject.h"

#ifdef _WIN32
// For _setmode().
#include <io.h>
#include <fcntl.h>
#endif // _WIN32

/* help function to call a Python "getter" function with no arguments that returns a long */
long call_getter(PyObject *pModule, char func_name[]) {
PyObject *pFunc, *pValue;
Expand Down Expand Up @@ -44,7 +50,7 @@ int main(void)
char *python_name = "radae_tx";
char *do_radae_tx_func_name = "do_radae_tx";
char *do_eoo_func_name = "do_eoo";
long nb_floats, Nmf, Neoo;
npy_intp nb_floats, Nmf, Neoo;

Py_Initialize();

Expand All @@ -59,10 +65,10 @@ int main(void)
Py_DECREF(pName);

if (pModule != NULL) {
nb_floats = call_getter(pModule, "get_nb_floats");
Nmf = call_getter(pModule, "get_Nmf");
Neoo = call_getter(pModule, "get_Neoo");
fprintf(stderr, "nb_floats: %ld Nmf: %ld Neoo: %ld\n", nb_floats, Nmf, Neoo);
nb_floats = (int)call_getter(pModule, "get_nb_floats");
Nmf = (int)call_getter(pModule, "get_Nmf");
Neoo = (int)call_getter(pModule, "get_Neoo");
fprintf(stderr, "nb_floats: %d Nmf: %d Neoo: %d\n", (int)nb_floats, (int)Nmf, (int)Neoo);

pFunc = PyObject_GetAttrString(pModule, do_radae_tx_func_name);
if (pFunc && PyCallable_Check(pFunc)) {
Expand All @@ -87,6 +93,13 @@ int main(void)
}
PyTuple_SetItem(pArgs, 1, pValue);

#ifdef _WIN32
// Note: freopen() returns NULL if filename is NULL, so
// we have to use setmode() to make it a binary stream instead.
_setmode(_fileno(stdin), O_BINARY);
_setmode(_fileno(stdout), O_BINARY);
#endif // _WIN32

// We are assuming once args are set up we can make repeat call with the same args, even though
// data in arrays changes
while((unsigned)nb_floats == fread(buffer_f32, sizeof(float), nb_floats, stdin)) {
Expand Down

0 comments on commit 301fb93

Please sign in to comment.