diff --git a/lib/param b/lib/param index c78c943..812f8a2 160000 --- a/lib/param +++ b/lib/param @@ -1 +1 @@ -Subproject commit c78c943c459d6bea3ea2c780c68dbf3fd174cc7f +Subproject commit 812f8a25295f6186a2810754c03885a7582c522e diff --git a/pycsh.pyi b/pycsh.pyi index 9368084..d4a9ddd 100644 --- a/pycsh.pyi +++ b/pycsh.pyi @@ -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: @@ -547,7 +547,7 @@ 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. @@ -555,7 +555,7 @@ def node(node: int | str = None) -> int: :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. @@ -563,7 +563,7 @@ def timeout(timeout: int = None) -> int: :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. @@ -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. @@ -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. """ diff --git a/src/pycsh.c b/src/pycsh.c index 9361375..ebedf55 100644 --- a/src/pycsh.c +++ b/src/pycsh.c @@ -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."}, @@ -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"}, diff --git a/src/wrapper/dflopt_py.c b/src/wrapper/dflopt_py.c index 30c83a6..251e4da 100644 --- a/src/wrapper/dflopt_py.c +++ b/src/wrapper/dflopt_py.c @@ -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)); @@ -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); diff --git a/src/wrapper/dflopt_py.h b/src/wrapper/dflopt_py.h index 59bfdce..f12a5a7 100644 --- a/src/wrapper/dflopt_py.h +++ b/src/wrapper/dflopt_py.h @@ -10,8 +10,8 @@ #define PY_SSIZE_T_CLEAN #include -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); diff --git a/src/wrapper/param_list_py.c b/src/wrapper/param_list_py.c index 5c077fa..b686faa 100644 --- a/src/wrapper/param_list_py.c +++ b/src/wrapper/param_list_py.c @@ -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. @@ -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) { diff --git a/src/wrapper/param_py.c b/src/wrapper/param_py.c index 44ef98e..e4e0fdd 100644 --- a/src/wrapper/param_py.c +++ b/src/wrapper/param_py.c @@ -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, ¶mver)) { + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|IIOOii", kwlist, &node, &timeout, &include_mask_obj, &exclude_mask_obj, ¶mver, &verbose)) { return NULL; } @@ -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."); @@ -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, ¶mver, ¶mver)) { + if (!PyArg_ParseTupleAndKeywords(args, kwds, "ss|ii", kwlist, &type, &name, ¶mver, ¶mver, &verbose)) { return NULL; } @@ -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; }