Skip to content

Commit

Permalink
pycsp: Implement Python binding for csp_sfp_send
Browse files Browse the repository at this point in the history
The function sets internal flags on csp_conn_t that are not accessible in
Python, making it hard to implement in Python.
  • Loading branch information
jichgom committed Jul 1, 2024
1 parent 2173b6b commit bac8ce3
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/bindings/python/pycsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,32 @@ static PyObject* pycsp_send(PyObject *self, PyObject *args) {
Py_RETURN_NONE;
}

static PyObject* pycsp_sfp_send(PyObject *self, PyObject *args) {
PyObject* conn_capsule;
Py_buffer data;
uint32_t mtu;
uint32_t timeout;
if (!PyArg_ParseTuple(args, "Ow*II", &conn_capsule, &data, &mtu, &timeout)) {
return NULL; // TypeError is thrown
}

csp_conn_t* conn = get_obj_as_conn(conn_capsule, false);
if (conn == NULL) {
PyBuffer_Release(&data);
return NULL;
}

int res;
Py_BEGIN_ALLOW_THREADS;
res = csp_sfp_send(conn, data.buf, data.len, mtu, timeout);
Py_END_ALLOW_THREADS;

PyBuffer_Release(&data);
return res == CSP_ERR_NONE
? Py_None
: PyErr_Error("csp_sfp_send()", res);
}

static PyObject* pycsp_transaction(PyObject *self, PyObject *args) {
uint8_t prio;
uint8_t dest;
Expand Down Expand Up @@ -1013,6 +1039,7 @@ static PyMethodDef methods[] = {
{"accept", pycsp_accept, METH_VARARGS, ""},
{"read", pycsp_read, METH_VARARGS, ""},
{"send", pycsp_send, METH_VARARGS, ""},
{"sfp_send", pycsp_sfp_send, METH_VARARGS, ""},
{"transaction", pycsp_transaction, METH_VARARGS, ""},
{"sendto_reply", pycsp_sendto_reply, METH_VARARGS, ""},
{"sendto", pycsp_sendto, METH_VARARGS, ""},
Expand Down

0 comments on commit bac8ce3

Please sign in to comment.