Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions pycsh.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ def push(node: int, timeout: int = None, hwid: int = None, retries: int = None)
:raises ConnectionError: when no response is received.
"""

def pull(node: int = None, timeout: int = None, include_mask: str | int = None, exclude_mask: str | int = None, paramver: int = None) -> None:
def pull(node: int = None, timeout: int = None, include_mask: str | int = None, exclude_mask: str | int = None, paramver: int = None, verbose: int = None) -> None:
""" Pull all or a specific mask of parameters. """

def slash_execute(command: str) -> int:
Expand All @@ -547,23 +547,23 @@ def cmd_new(type: _Literal['get', 'set'], name: str = None, paramver: int = 2) -
def cmd_done() -> None:
""" Clears the queue. """

def node(node: int | str = None) -> int:
def node(node: int | str = None, verbose: int = None) -> int:
"""
Used to get or change the default node.

:param node: Integer to change the default node to.
:return: The current default node.
"""

def timeout(timeout: int = None) -> int:
def timeout(timeout: int = None, verbose: int = None) -> int:
"""
Used to get or change the default timeout.

:param timeout: Integer to change the default timeout to.
:return: The current default timeout.
"""

def verbose(verbose: int = None) -> int:
def verbose(verbose: int = None, /) -> int:
"""
Used to get or change the default parameter verbosity.

Expand All @@ -581,10 +581,16 @@ def list(node: int = None, verbose: int = None, mask: str | int = None, globstr:
:param mask: Mask on which to filter the list.
"""

def list_download(node: int = None, timeout: int = None, version: int = None) -> ParameterList:
def list_download(node: int = None, timeout: int = None, version: int = None, remote: int = None, verbose: int = None) -> ParameterList:
"""
Download all parameters on the specified node.

:param node: Node to download parameters.
:param timeout: Timeout in milliseconds.
:param version: Parameter version (3 includes docstrings)
:param remote: Also download parameters that are remote on the specified node.
:param verbose: 0=quiet, 1=parameter count, 2=every parameter (name/ID). (default = 2)

:raises RuntimeError: When called before .init().
:raises ConnectionError: When no response is received.

Expand All @@ -596,7 +602,9 @@ def list_forget(node: int = None, verbose: int = None) -> int:
Remove remote parameters, matching the provided arguments, from the global list.

:param node: Remove parameters from this node. Use <1 for all nodes.
:param name_filter: Wildcard name pattern to filter parameters by.
#:param name_filter: Wildcard name pattern to filter parameters by.
:param verbose: 0=quiet, 1=parameter count, 2=every parameter (name/ID). (default = 2)

:returns: Count of parameters affected.
"""

Expand Down
6 changes: 3 additions & 3 deletions src/pycsh.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ static PyMethodDef methods[] = {
{"pull", (PyCFunction)pycsh_param_pull, METH_VARARGS | METH_KEYWORDS, "Pull all or a specific set of parameters."},
{"cmd_done", pycsh_param_cmd_done, METH_NOARGS, "Clears the queue."},
{"cmd_new", (PyCFunction)pycsh_param_cmd_new,METH_VARARGS | METH_KEYWORDS, "Create a new command"},
{"node", pycsh_slash_node, METH_VARARGS, "Used to get or change the default node."},
{"timeout", pycsh_slash_timeout, METH_VARARGS, "Used to get or change the default timeout."},
{"node", (PyCFunction)pycsh_slash_node, METH_VARARGS | METH_KEYWORDS, "Used to get or change the default node."},
{"timeout", (PyCFunction)pycsh_slash_timeout,METH_VARARGS | METH_KEYWORDS, "Used to get or change the default timeout."},
{"verbose", pycsh_slash_verbose, METH_VARARGS, "Used to get or change the default parameter verbosity."},
{"queue", pycsh_param_cmd, METH_NOARGS, "Print the current command."},

Expand Down Expand Up @@ -293,7 +293,7 @@ static PyMethodDef methods[] = {
{"csp_add_zmq", (PyCFunction)pycsh_csh_csp_ifadd_zmq, METH_VARARGS | METH_KEYWORDS, "Add a new ZMQ interface"},
{"csp_add_kiss",(PyCFunction)pycsh_csh_csp_ifadd_kiss, METH_VARARGS | METH_KEYWORDS, "Add a new KISS/UART interface"},
#if (CSP_HAVE_LIBSOCKETCAN)
{"csp_add_can", (PyCFunction)pycsh_csh_csp_ifadd_can, METH_VARARGS | METH_KEYWORDS, "Add a new UDP interface"},
{"csp_add_can", (PyCFunction)pycsh_csh_csp_ifadd_can, METH_VARARGS | METH_KEYWORDS, "Add a new CAN interface"},
#endif
{"csp_add_eth", (PyCFunction)pycsh_csh_csp_ifadd_eth, METH_VARARGS | METH_KEYWORDS, "Add a new ethernet interface"},
{"csp_add_udp", (PyCFunction)pycsh_csh_csp_ifadd_udp, METH_VARARGS | METH_KEYWORDS, "Add a new TUN interface"},
Expand Down
34 changes: 24 additions & 10 deletions src/wrapper/dflopt_py.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,27 @@

// TODO Kevin: These differ from the newest version of slash/csh

PyObject * pycsh_slash_node(PyObject * self, PyObject * args) {
PyObject * pycsh_slash_node(PyObject * self, PyObject * args, PyObject * kwds) {

PyObject * node = NULL;
int verbose = pycsh_dfl_verbose;

if (!PyArg_ParseTuple(args, "|O", &node)) {
static char *kwlist[] = {"node", "verbose", NULL};

if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Oi", kwlist, &node, &verbose)) {
return NULL; // TypeError is thrown
}

if (node == NULL) { // No argument passed
printf("Default node = %d\n", pycsh_dfl_node);
if (verbose) {
printf("Default node = %d\n", pycsh_dfl_node);
}
} else if (PyLong_Check(node)) {

pycsh_dfl_node = PyLong_AsUnsignedLong(node);
printf("Set default node to %d\n", pycsh_dfl_node);
if (verbose) {
printf("Set default node to %d\n", pycsh_dfl_node);
}
} else if (PyUnicode_Check(node)) {

slash_dfl_node = known_hosts_get_node(PyUnicode_AsUTF8(node));
Expand All @@ -43,19 +50,26 @@ PyObject * pycsh_slash_node(PyObject * self, PyObject * args) {
return Py_BuildValue("i", pycsh_dfl_node);
}

PyObject * pycsh_slash_timeout(PyObject * self, PyObject * args) {
PyObject * pycsh_slash_timeout(PyObject * self, PyObject * args, PyObject * kwds) {

int timeout = -1;
int verbose = pycsh_dfl_verbose;

static char *kwlist[] = {"timeout", "verbose", NULL};

if (!PyArg_ParseTuple(args, "|i", &timeout)) {
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|ii", kwlist, &timeout, &verbose)) {
return NULL; // TypeError is thrown
}

if (timeout == -1)
printf("Default timeout = %d\n", pycsh_dfl_timeout);
else {
if (timeout == -1) {
if (verbose) {
printf("Default timeout = %d\n", pycsh_dfl_timeout);
}
} else {
pycsh_dfl_timeout = timeout;
printf("Set default timeout to %d\n", pycsh_dfl_timeout);
if (verbose) {
printf("Set default timeout to %d\n", pycsh_dfl_timeout);
}
}

return Py_BuildValue("i", pycsh_dfl_timeout);
Expand Down
4 changes: 2 additions & 2 deletions src/wrapper/dflopt_py.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#define PY_SSIZE_T_CLEAN
#include <Python.h>

PyObject * pycsh_slash_node(PyObject * self, PyObject * args);
PyObject * pycsh_slash_node(PyObject * self, PyObject * args, PyObject * kwds);

PyObject * pycsh_slash_timeout(PyObject * self, PyObject * args);
PyObject * pycsh_slash_timeout(PyObject * self, PyObject * args, PyObject * kwds);

PyObject * pycsh_slash_verbose(PyObject * self, PyObject * args);
24 changes: 14 additions & 10 deletions src/wrapper/param_list_py.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,21 @@ PyObject * pycsh_param_list_download(PyObject * self, PyObject * args, PyObject

CSP_INIT_CHECK()

unsigned int node = pycsh_dfl_node;
unsigned int timeout = pycsh_dfl_timeout;
unsigned int version = 2;
int node = pycsh_dfl_node;
uint32_t timeout = pycsh_dfl_timeout;
int version = 2;
int include_remotes = 0;
int verbose = pycsh_dfl_verbose;

static char *kwlist[] = {"node", "timeout", "version", "remotes", NULL};
static char *kwlist[] = {"node", "timeout", "version", "remote", "verbose", NULL};

if (!PyArg_ParseTupleAndKeywords(args, kwds, "|IIII", kwlist, &node, &timeout, &version, &include_remotes))
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iIiii", kwlist, &node, &timeout, &version, &include_remotes, &verbose))
return NULL; // TypeError is thrown

{ /* Allow threads during list_download() */
int list_download_res;
Py_BEGIN_ALLOW_THREADS;
list_download_res = param_list_download(node, timeout, version, include_remotes);
list_download_res = param_list_download(node, timeout, version, include_remotes, verbose);
Py_END_ALLOW_THREADS;
// TODO Kevin: Downloading parameters with an incorrect version, can lead to a segmentation fault.
// Had it been easier to detect when an incorrect version is used, we would've raised an exception instead.
Expand Down Expand Up @@ -144,16 +145,19 @@ PyObject * pycsh_param_list_add(PyObject * self, PyObject * args, PyObject * kwd
PyObject * pycsh_param_list_forget(PyObject * self, PyObject * args, PyObject * kwds) {

int node = pycsh_dfl_node;
int verbose = 1;
int verbose = pycsh_dfl_verbose;

static char *kwlist[] = {"node", "verbose", NULL};

if (!PyArg_ParseTupleAndKeywords(args, kwds, "|ii", kwlist, &node, &verbose))
return NULL; // TypeError is thrown

int res = param_list_remove(node, verbose);
printf("Removed %i parameters\n", res);
return Py_BuildValue("i", res);;
int count_removed = param_list_remove(node, verbose);

if (verbose >= 1) {
printf("Removed %i parameters\n", count_removed);
}
return Py_BuildValue("i", count_removed);;
}

PyObject * pycsh_param_list_save(PyObject * self, PyObject * args, PyObject * kwds) {
Expand Down
16 changes: 10 additions & 6 deletions src/wrapper/param_py.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,11 @@ PyObject * pycsh_param_pull(PyObject * self, PyObject * args, PyObject * kwds) {
PyObject * include_mask_obj = NULL;
PyObject * exclude_mask_obj = NULL;
int paramver = 2;
int verbose = pycsh_dfl_verbose;

static char *kwlist[] = {"node", "timeout", "include_mask", "exclude_mask", "paramver", NULL};
static char *kwlist[] = {"node", "timeout", "include_mask", "exclude_mask", "paramver", "verbose", NULL};

if (!PyArg_ParseTupleAndKeywords(args, kwds, "|IIOOi", kwlist, &node, &timeout, &include_mask_obj, &exclude_mask_obj, &paramver)) {
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|IIOOii", kwlist, &node, &timeout, &include_mask_obj, &exclude_mask_obj, &paramver, &verbose)) {
return NULL;
}

Expand All @@ -155,7 +156,7 @@ PyObject * pycsh_param_pull(PyObject * self, PyObject * args, PyObject * kwds) {
int param_pull_res;
Py_BEGIN_ALLOW_THREADS;

param_pull_res = param_pull_all(CSP_PRIO_NORM, 1, node, include_mask, exclude_mask, timeout, paramver);
param_pull_res = param_pull_all(CSP_PRIO_NORM, verbose, node, include_mask, exclude_mask, timeout, paramver);
Py_END_ALLOW_THREADS;
if (param_pull_res) {
PyErr_SetString(PyExc_ConnectionError, "No response.");
Expand All @@ -170,10 +171,11 @@ PyObject * pycsh_param_cmd_new(PyObject * self, PyObject * args, PyObject * kwds
char *type;
char *name;
int paramver = 2;
int verbose = pycsh_dfl_verbose;

static char *kwlist[] = {"type", "name", "paramver", NULL};
static char *kwlist[] = {"type", "name", "paramver", "verbose", NULL};

if (!PyArg_ParseTupleAndKeywords(args, kwds, "ss|i", kwlist, &type, &name, &paramver, &paramver)) {
if (!PyArg_ParseTupleAndKeywords(args, kwds, "ss|ii", kwlist, &type, &name, &paramver, &paramver, &verbose)) {
return NULL;
}

Expand All @@ -193,7 +195,9 @@ PyObject * pycsh_param_cmd_new(PyObject * self, PyObject * args, PyObject * kwds
param_queue.used = 0;
param_queue.version = paramver;

printf("Initialized new command: %s\n", name);
if (verbose) {
printf("Initialized new command: %s\n", name);
}

Py_RETURN_NONE;
}
Expand Down