From b96748ba82eb48fda4f48e49b0d888b6b1733631 Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Wed, 19 Sep 2018 21:26:04 -0700 Subject: [PATCH] Use uniform line endings across repository Unix-style is by far the most common, so convert the 7 files that don't conform. --- CONTRIBUTORS.txt | 48 +++--- LICENSE.txt | 330 ++++++++++++++++++++-------------------- can/ctypesutil.py | 200 ++++++++++++------------ doc/installation.rst | 186 +++++++++++------------ doc/listeners.rst | 302 ++++++++++++++++++------------------- doc/scripts.rst | 352 +++++++++++++++++++++---------------------- 6 files changed, 709 insertions(+), 709 deletions(-) diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 3ce2ff730..0576c2b66 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -1,24 +1,24 @@ -Ben Powell -Brian Thorne -Geert Linders -Mark Catley -Phillip Dixon -Rose Lu -Karl van Workum -Albert Bloomfield -Sam Bristow -Ethan Zonca -Robert Kaye -Andrew Beal -Jonas Frid -Tynan McAuley -Bruno Pennati -Jack Jester-Weinstein -Joshua Villyard -Giuseppe Corbelli -Christian Sandberg -Eduard Bröcker -Boris Wenzlaff -Pierre-Luc Tessier Gagné -Felix Divo -Kristian Sloth Lauszus +Ben Powell +Brian Thorne +Geert Linders +Mark Catley +Phillip Dixon +Rose Lu +Karl van Workum +Albert Bloomfield +Sam Bristow +Ethan Zonca +Robert Kaye +Andrew Beal +Jonas Frid +Tynan McAuley +Bruno Pennati +Jack Jester-Weinstein +Joshua Villyard +Giuseppe Corbelli +Christian Sandberg +Eduard Bröcker +Boris Wenzlaff +Pierre-Luc Tessier Gagné +Felix Divo +Kristian Sloth Lauszus diff --git a/LICENSE.txt b/LICENSE.txt index b14ca0a55..65c5ca88a 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,165 +1,165 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/can/ctypesutil.py b/can/ctypesutil.py index 6dc372268..4c103310d 100644 --- a/can/ctypesutil.py +++ b/can/ctypesutil.py @@ -1,100 +1,100 @@ -#!/usr/bin/env python -# coding: utf-8 - -""" -This module contains common `ctypes` utils. -""" - -import binascii -import ctypes -import logging -import sys - -log = logging.getLogger('can.ctypesutil') - -__all__ = ['CLibrary', 'HANDLE', 'PHANDLE', 'HRESULT'] - -try: - _LibBase = ctypes.WinDLL -except AttributeError: - _LibBase = ctypes.CDLL - - -class LibraryMixin: - def map_symbol(self, func_name, restype=None, argtypes=(), errcheck=None): - """ - Map and return a symbol (function) from a C library. A reference to the - mapped symbol is also held in the instance - - :param str func_name: - symbol_name - :param ctypes.c_* restype: - function result type (i.e. ctypes.c_ulong...), defaults to void - :param tuple(ctypes.c_* ... ) argtypes: - argument types, defaults to no args - :param callable errcheck: - optional error checking function, see ctypes docs for _FuncPtr - """ - if (argtypes): - prototype = self.function_type(restype, *argtypes) - else: - prototype = self.function_type(restype) - try: - symbol = prototype((func_name, self)) - except AttributeError: - raise ImportError("Could not map function '{}' from library {}".format(func_name, self._name)) - - setattr(symbol, "_name", func_name) - log.debug('Wrapped function "{}", result type: {}, error_check {}'.format(func_name, type(restype), errcheck)) - - if (errcheck): - symbol.errcheck = errcheck - - setattr(self, func_name, symbol) - return symbol - - -class CLibrary_Win32(_LibBase, LibraryMixin): - " Basic ctypes.WinDLL derived class + LibraryMixin " - - def __init__(self, library_or_path): - if (isinstance(library_or_path, str)): - super(CLibrary_Win32, self).__init__(library_or_path) - else: - super(CLibrary_Win32, self).__init__(library_or_path._name, library_or_path._handle) - - @property - def function_type(self): - return ctypes.WINFUNCTYPE - - -class CLibrary_Unix(ctypes.CDLL, LibraryMixin): - " Basic ctypes.CDLL derived class + LibraryMixin " - - def __init__(self, library_or_path): - if (isinstance(library_or_path, str)): - super(CLibrary_Unix, self).__init__(library_or_path) - else: - super(CLibrary_Unix, self).__init__(library_or_path._name, library_or_path._handle) - - @property - def function_type(self): - return ctypes.CFUNCTYPE - - -if sys.platform == "win32": - CLibrary = CLibrary_Win32 - HRESULT = ctypes.HRESULT -else: - CLibrary = CLibrary_Unix - if sys.platform == "cygwin": - # Define HRESULT for cygwin - class HRESULT(ctypes.c_long): - pass - - -# Common win32 definitions -class HANDLE(ctypes.c_void_p): - pass - -PHANDLE = ctypes.POINTER(HANDLE) +#!/usr/bin/env python +# coding: utf-8 + +""" +This module contains common `ctypes` utils. +""" + +import binascii +import ctypes +import logging +import sys + +log = logging.getLogger('can.ctypesutil') + +__all__ = ['CLibrary', 'HANDLE', 'PHANDLE', 'HRESULT'] + +try: + _LibBase = ctypes.WinDLL +except AttributeError: + _LibBase = ctypes.CDLL + + +class LibraryMixin: + def map_symbol(self, func_name, restype=None, argtypes=(), errcheck=None): + """ + Map and return a symbol (function) from a C library. A reference to the + mapped symbol is also held in the instance + + :param str func_name: + symbol_name + :param ctypes.c_* restype: + function result type (i.e. ctypes.c_ulong...), defaults to void + :param tuple(ctypes.c_* ... ) argtypes: + argument types, defaults to no args + :param callable errcheck: + optional error checking function, see ctypes docs for _FuncPtr + """ + if (argtypes): + prototype = self.function_type(restype, *argtypes) + else: + prototype = self.function_type(restype) + try: + symbol = prototype((func_name, self)) + except AttributeError: + raise ImportError("Could not map function '{}' from library {}".format(func_name, self._name)) + + setattr(symbol, "_name", func_name) + log.debug('Wrapped function "{}", result type: {}, error_check {}'.format(func_name, type(restype), errcheck)) + + if (errcheck): + symbol.errcheck = errcheck + + setattr(self, func_name, symbol) + return symbol + + +class CLibrary_Win32(_LibBase, LibraryMixin): + " Basic ctypes.WinDLL derived class + LibraryMixin " + + def __init__(self, library_or_path): + if (isinstance(library_or_path, str)): + super(CLibrary_Win32, self).__init__(library_or_path) + else: + super(CLibrary_Win32, self).__init__(library_or_path._name, library_or_path._handle) + + @property + def function_type(self): + return ctypes.WINFUNCTYPE + + +class CLibrary_Unix(ctypes.CDLL, LibraryMixin): + " Basic ctypes.CDLL derived class + LibraryMixin " + + def __init__(self, library_or_path): + if (isinstance(library_or_path, str)): + super(CLibrary_Unix, self).__init__(library_or_path) + else: + super(CLibrary_Unix, self).__init__(library_or_path._name, library_or_path._handle) + + @property + def function_type(self): + return ctypes.CFUNCTYPE + + +if sys.platform == "win32": + CLibrary = CLibrary_Win32 + HRESULT = ctypes.HRESULT +else: + CLibrary = CLibrary_Unix + if sys.platform == "cygwin": + # Define HRESULT for cygwin + class HRESULT(ctypes.c_long): + pass + + +# Common win32 definitions +class HANDLE(ctypes.c_void_p): + pass + +PHANDLE = ctypes.POINTER(HANDLE) diff --git a/doc/installation.rst b/doc/installation.rst index 0dc498583..add0f5cec 100644 --- a/doc/installation.rst +++ b/doc/installation.rst @@ -1,93 +1,93 @@ -Installation -============ - - -Install ``can`` with ``pip``: -:: - - $ pip install python-can - - -As most likely you will want to interface with some hardware, you may -also have to install platform dependencies. Be sure to check any other -specifics for your hardware in :doc:`interfaces`. - - -GNU/Linux dependencies ----------------------- - -Reasonably modern Linux Kernels (2.6.25 or newer) have an implementation -of ``socketcan``. This version of python-can will directly use socketcan -if called with Python 3.3 or greater, otherwise that interface is used -via ctypes. - -Windows dependencies --------------------- - -Kvaser -~~~~~~ - -To install ``python-can`` using the Kvaser CANLib SDK as the backend: - -1. Install the `latest stable release of - Python `__. - -2. Install `Kvaser's latest Windows CANLib - drivers `__. - -3. Test that Kvaser's own tools work to ensure the driver is properly - installed and that the hardware is working. - -PCAN -~~~~ - -Download and install the latest driver for your interface from -`PEAK-System's download page `__. - -Note that PCANBasic API timestamps count seconds from system startup. To -convert these to epoch times, the uptime library is used. If it is not -available, the times are returned as number of seconds from system -startup. To install the uptime library, run ``pip install uptime``. - -This library can take advantage of the `Python for Windows Extensions -`__ library if installed. -It will be used to get notified of new messages instead of -the CPU intensive polling that will otherwise have be used. - -IXXAT -~~~~~ - -To install ``python-can`` using the IXXAT VCI V3 SDK as the backend: - -1. Install `IXXAT's latest Windows VCI V3 SDK - drivers `__. - -2. Test that IXXAT's own tools (i.e. MiniMon) work to ensure the driver - is properly installed and that the hardware is working. - -NI-CAN -~~~~~~ - -Download and install the NI-CAN drivers from -`National Instruments `__. - -Currently the driver only supports 32-bit Python on Windows. - -neoVI -~~~~~ - -See :doc:`interfaces/neovi`. - - -Installing python-can in development mode ------------------------------------------ - -A "development" install of this package allows you to make changes locally -or pull updates from the Mercurial repository and use them without having to -reinstall. Download or clone the source repository then: - -:: - - python setup.py develop - - +Installation +============ + + +Install ``can`` with ``pip``: +:: + + $ pip install python-can + + +As most likely you will want to interface with some hardware, you may +also have to install platform dependencies. Be sure to check any other +specifics for your hardware in :doc:`interfaces`. + + +GNU/Linux dependencies +---------------------- + +Reasonably modern Linux Kernels (2.6.25 or newer) have an implementation +of ``socketcan``. This version of python-can will directly use socketcan +if called with Python 3.3 or greater, otherwise that interface is used +via ctypes. + +Windows dependencies +-------------------- + +Kvaser +~~~~~~ + +To install ``python-can`` using the Kvaser CANLib SDK as the backend: + +1. Install the `latest stable release of + Python `__. + +2. Install `Kvaser's latest Windows CANLib + drivers `__. + +3. Test that Kvaser's own tools work to ensure the driver is properly + installed and that the hardware is working. + +PCAN +~~~~ + +Download and install the latest driver for your interface from +`PEAK-System's download page `__. + +Note that PCANBasic API timestamps count seconds from system startup. To +convert these to epoch times, the uptime library is used. If it is not +available, the times are returned as number of seconds from system +startup. To install the uptime library, run ``pip install uptime``. + +This library can take advantage of the `Python for Windows Extensions +`__ library if installed. +It will be used to get notified of new messages instead of +the CPU intensive polling that will otherwise have be used. + +IXXAT +~~~~~ + +To install ``python-can`` using the IXXAT VCI V3 SDK as the backend: + +1. Install `IXXAT's latest Windows VCI V3 SDK + drivers `__. + +2. Test that IXXAT's own tools (i.e. MiniMon) work to ensure the driver + is properly installed and that the hardware is working. + +NI-CAN +~~~~~~ + +Download and install the NI-CAN drivers from +`National Instruments `__. + +Currently the driver only supports 32-bit Python on Windows. + +neoVI +~~~~~ + +See :doc:`interfaces/neovi`. + + +Installing python-can in development mode +----------------------------------------- + +A "development" install of this package allows you to make changes locally +or pull updates from the Mercurial repository and use them without having to +reinstall. Download or clone the source repository then: + +:: + + python setup.py develop + + diff --git a/doc/listeners.rst b/doc/listeners.rst index b807cc7a7..f90c5d027 100644 --- a/doc/listeners.rst +++ b/doc/listeners.rst @@ -1,151 +1,151 @@ -Listeners -========= - -Listener --------- - -The Listener class is an "abstract" base class for any objects which wish to -register to receive notifications of new messages on the bus. A Listener can -be used in two ways; the default is to **call** the Listener with a new -message, or by calling the method **on_message_received**. - -Listeners are registered with :ref:`notifier` object(s) which ensure they are -notified whenever a new message is received. - -Subclasses of Listener that do not override **on_message_received** will cause -:class:`NotImplementedError` to be thrown when a message is received on -the CAN bus. - -.. autoclass:: can.Listener - :members: - - -BufferedReader --------------- - -.. autoclass:: can.BufferedReader - :members: - -.. autoclass:: can.AsyncBufferedReader - :members: - - -Logger ------- - -The :class:`can.Logger` uses the following :class:`can.Listener` types to -create log files with different file types of the messages received. - -.. autoclass:: can.Logger - :members: - - -Printer -------- - -.. autoclass:: can.Printer - :members: - - -CSVWriter ---------- - -.. autoclass:: can.CSVWriter - :members: - -.. autoclass:: can.CSVReader - :members: - - -SqliteWriter ------------- - -.. autoclass:: can.SqliteWriter - :members: - -.. autoclass:: can.SqliteReader - :members: - - -Database table format -~~~~~~~~~~~~~~~~~~~~~ - -The messages are written to the table ``messages`` in the sqlite database -by default. The table is created if it does not already exist. - -The entries are as follows: - -============== ============== ============== -Name Data type Note --------------- -------------- -------------- -ts REAL The timestamp of the message -arbitration_id INTEGER The arbitration id, might use the extended format -extended INTEGER ``1`` if the arbitration id uses the extended format, else ``0`` -remote INTEGER ``1`` if the message is a remote frame, else ``0`` -error INTEGER ``1`` if the message is an error frame, else ``0`` -dlc INTEGER The data length code (DLC) -data BLOB The content of the message -============== ============== ============== - - -ASC (.asc Logging format) -------------------------- -ASCWriter logs CAN data to an ASCII log file compatible with other CAN tools such as -Vector CANalyzer/CANoe and other. -Since no official specification exists for the format, it has been reverse- -engineered from existing log files. One description of the format can be found `here -`_. - - -.. note:: - - Channels will be converted to integers. - - -.. autoclass:: can.ASCWriter - :members: - -ASCReader reads CAN data from ASCII log files .asc, -as further references can-utils can be used: -`asc2log `_, -`log2asc `_. - -.. autoclass:: can.ASCReader - :members: - - -Log (.log can-utils Logging format) ------------------------------------ - -CanutilsLogWriter logs CAN data to an ASCII log file compatible with `can-utils ` -As specification following references can-utils can be used: -`asc2log `_, -`log2asc `_. - - -.. autoclass:: can.CanutilsLogWriter - :members: - -**CanutilsLogReader** reads CAN data from ASCII log files .log - -.. autoclass:: can.CanutilsLogReader - :members: - - -BLF (Binary Logging Format) ---------------------------- - -Implements support for BLF (Binary Logging Format) which is a proprietary -CAN log format from Vector Informatik GmbH. - -The data is stored in a compressed format which makes it very compact. - -.. note:: Channels will be converted to integers. - -.. autoclass:: can.BLFWriter - :members: - -The following class can be used to read messages from BLF file: - -.. autoclass:: can.BLFReader - :members: +Listeners +========= + +Listener +-------- + +The Listener class is an "abstract" base class for any objects which wish to +register to receive notifications of new messages on the bus. A Listener can +be used in two ways; the default is to **call** the Listener with a new +message, or by calling the method **on_message_received**. + +Listeners are registered with :ref:`notifier` object(s) which ensure they are +notified whenever a new message is received. + +Subclasses of Listener that do not override **on_message_received** will cause +:class:`NotImplementedError` to be thrown when a message is received on +the CAN bus. + +.. autoclass:: can.Listener + :members: + + +BufferedReader +-------------- + +.. autoclass:: can.BufferedReader + :members: + +.. autoclass:: can.AsyncBufferedReader + :members: + + +Logger +------ + +The :class:`can.Logger` uses the following :class:`can.Listener` types to +create log files with different file types of the messages received. + +.. autoclass:: can.Logger + :members: + + +Printer +------- + +.. autoclass:: can.Printer + :members: + + +CSVWriter +--------- + +.. autoclass:: can.CSVWriter + :members: + +.. autoclass:: can.CSVReader + :members: + + +SqliteWriter +------------ + +.. autoclass:: can.SqliteWriter + :members: + +.. autoclass:: can.SqliteReader + :members: + + +Database table format +~~~~~~~~~~~~~~~~~~~~~ + +The messages are written to the table ``messages`` in the sqlite database +by default. The table is created if it does not already exist. + +The entries are as follows: + +============== ============== ============== +Name Data type Note +-------------- -------------- -------------- +ts REAL The timestamp of the message +arbitration_id INTEGER The arbitration id, might use the extended format +extended INTEGER ``1`` if the arbitration id uses the extended format, else ``0`` +remote INTEGER ``1`` if the message is a remote frame, else ``0`` +error INTEGER ``1`` if the message is an error frame, else ``0`` +dlc INTEGER The data length code (DLC) +data BLOB The content of the message +============== ============== ============== + + +ASC (.asc Logging format) +------------------------- +ASCWriter logs CAN data to an ASCII log file compatible with other CAN tools such as +Vector CANalyzer/CANoe and other. +Since no official specification exists for the format, it has been reverse- +engineered from existing log files. One description of the format can be found `here +`_. + + +.. note:: + + Channels will be converted to integers. + + +.. autoclass:: can.ASCWriter + :members: + +ASCReader reads CAN data from ASCII log files .asc, +as further references can-utils can be used: +`asc2log `_, +`log2asc `_. + +.. autoclass:: can.ASCReader + :members: + + +Log (.log can-utils Logging format) +----------------------------------- + +CanutilsLogWriter logs CAN data to an ASCII log file compatible with `can-utils ` +As specification following references can-utils can be used: +`asc2log `_, +`log2asc `_. + + +.. autoclass:: can.CanutilsLogWriter + :members: + +**CanutilsLogReader** reads CAN data from ASCII log files .log + +.. autoclass:: can.CanutilsLogReader + :members: + + +BLF (Binary Logging Format) +--------------------------- + +Implements support for BLF (Binary Logging Format) which is a proprietary +CAN log format from Vector Informatik GmbH. + +The data is stored in a compressed format which makes it very compact. + +.. note:: Channels will be converted to integers. + +.. autoclass:: can.BLFWriter + :members: + +The following class can be used to read messages from BLF file: + +.. autoclass:: can.BLFReader + :members: diff --git a/doc/scripts.rst b/doc/scripts.rst index b58125ea5..e10ea87e0 100644 --- a/doc/scripts.rst +++ b/doc/scripts.rst @@ -1,176 +1,176 @@ -Scripts -======= - -The following modules are callable from python-can. - -They can be called for example by ``python -m can.logger`` or ``can_logger.py`` (if installed using pip). - -can.logger ----------- - -Command line help, called with ``--help``:: - - usage: python -m can.logger [-h] [-f LOG_FILE] [-v] [-c CHANNEL] - [-i {pcan,ixxat,socketcan_ctypes,kvaser,virtual,usb2can,vector,slcan,nican,socketcan,iscan,neovi,serial,socketcan_native}] - [--filter ...] [-b BITRATE] - [--active | --passive] - - Log CAN traffic, printing messages to stdout or to a given file. - - optional arguments: - -h, --help show this help message and exit - -f LOG_FILE, --file_name LOG_FILE - Path and base log filename, for supported types see - can.Logger. - -v How much information do you want to see at the command - line? You can add several of these e.g., -vv is DEBUG - -c CHANNEL, --channel CHANNEL - Most backend interfaces require some sort of channel. - For example with the serial interface the channel - might be a rfcomm device: "/dev/rfcomm0" With the - socketcan interfaces valid channel examples include: - "can0", "vcan0" - -i {pcan,ixxat,socketcan_ctypes,kvaser,virtual,usb2can,vector,slcan,nican,socketcan,iscan,neovi,serial,socketcan_native}, --interface {pcan,ixxat,socketcan_ctypes,kvaser,virtual,usb2can,vector,slcan,nican,socketcan,iscan,neovi,serial,socketcan_native} - Specify the backend CAN interface to use. If left - blank, fall back to reading from configuration files. - --filter ... Comma separated filters can be specified for the given - CAN interface: : (matches when - & mask == can_id & mask) - ~ (matches when & - mask != can_id & mask) - -b BITRATE, --bitrate BITRATE - Bitrate to use for the CAN bus. - --active Start the bus as active, this is applied the default. - --passive Start the bus as passive. - - -can.player ----------- - -Command line help, called with ``--help``:: - - usage: python -m can.player [-h] [-f LOG_FILE] [-v] [-c CHANNEL] - [-i {pcan,ixxat,socketcan_ctypes,kvaser,virtual,usb2can,vector,slcan,nican,socketcan,iscan,neovi,serial,socketcan_native}] - [-b BITRATE] [--ignore-timestamps] - [-g GAP] [-s SKIP] - input-file - - Replay CAN traffic. - - positional arguments: - input-file The file to replay. For supported types see - can.LogReader. - - optional arguments: - -h, --help show this help message and exit - -f LOG_FILE, --file_name LOG_FILE - Path and base log filename, for supported types see - can.LogReader. - -v Also print can frames to stdout. You can add several - of these to enable debugging - -c CHANNEL, --channel CHANNEL - Most backend interfaces require some sort of channel. - For example with the serial interface the channel - might be a rfcomm device: "/dev/rfcomm0" With the - socketcan interfaces valid channel examples include: - "can0", "vcan0" - -i {pcan,ixxat,socketcan_ctypes,kvaser,virtual,usb2can,vector,slcan,nican,socketcan,iscan,neovi,serial,socketcan_native}, --interface {pcan,ixxat,socketcan_ctypes,kvaser,virtual,usb2can,vector,slcan,nican,socketcan,iscan,neovi,serial,socketcan_native} - Specify the backend CAN interface to use. If left - blank, fall back to reading from configuration files. - -b BITRATE, --bitrate BITRATE - Bitrate to use for the CAN bus. - --ignore-timestamps Ignore timestamps (send all frames immediately with - minimum gap between frames) - -g GAP, --gap GAP minimum time between replayed frames - -s SKIP, --skip SKIP skip gaps greater than 's' seconds - -can.viewer ----------- - -A screenshot of the application can be seen below: - -.. image:: ../images/viewer.png - :width: 100% - -The first column is the number of times a frame with the particular ID that has been received, next is the timestamp of the frame relative to the first received message. The third column is the time between the current frame relative to the previous one. Next is the length of the frame, the data and then the decoded data converted according to the ``-d`` argument. The top red row indicates an error frame. - -Command line arguments -^^^^^^^^^^^^^^^^^^^^^^ - -By default it will be using the :doc:`/interfaces/socketcan` interface. All interfaces supported are supported and can be specified using the ``-i`` argument. - -The full usage page can be seen below:: - - Usage: python -m can.viewer [-h] [--version] [-b BITRATE] [-c CHANNEL] - [-d {:,:::...:,file.txt}] - [-f {:,~}] - [-i {iscan,ixxat,kvaser,neovi,nican,pcan,serial,slcan,socketcan,socketcan_ctypes,socketcan_native,usb2can,vector,virtual}] - - A simple CAN viewer terminal application written in Python - - Optional arguments: - -h, --help Show this help message and exit - --version Show program's version number and exit - -b, --bitrate BITRATE - Bitrate to use for the given CAN interface - -c, --channel CHANNEL - Most backend interfaces require some sort of channel. - For example with the serial interface the channel - might be a rfcomm device: "/dev/rfcomm0" with the - socketcan interfaces valid channel examples include: - "can0", "vcan0". (default: use default for the - specified interface) - -d, --decode {:,:::...:,file.txt} - Specify how to convert the raw bytes into real values. - The ID of the frame is given as the first argument and the format as the second. - The Python struct package is used to unpack the received data - where the format characters have the following meaning: - < = little-endian, > = big-endian - x = pad byte - c = char - ? = bool - b = int8_t, B = uint8_t - h = int16, H = uint16 - l = int32_t, L = uint32_t - q = int64_t, Q = uint64_t - f = float (32-bits), d = double (64-bits) - Fx to convert six bytes with ID 0x100 into uint8_t, uint16 and uint32_t: - $ python -m can.viewer -d "100::,~} - Comma separated CAN filters for the given CAN interface: - : (matches when & mask == can_id & mask) - ~ (matches when & mask != can_id & mask) - Fx to show only frames with ID 0x100 to 0x103: - python -m can.viewer -f 100:7FC - Note that the ID and mask are alway interpreted as hex values - -i, --interface {iscan,ixxat,kvaser,neovi,nican,pcan,serial,slcan,socketcan,socketcan_ctypes,socketcan_native,usb2can,vector,virtual} - Specify the backend CAN interface to use. - - Shortcuts: - +---------+-------------------------+ - | Key | Description | - +---------+-------------------------+ - | ESQ/q | Exit the viewer | - | c | Clear the stored frames | - | s | Sort the stored frames | - | SPACE | Pause the viewer | - | UP/DOWN | Scroll the viewer | - +---------+-------------------------+ +Scripts +======= + +The following modules are callable from python-can. + +They can be called for example by ``python -m can.logger`` or ``can_logger.py`` (if installed using pip). + +can.logger +---------- + +Command line help, called with ``--help``:: + + usage: python -m can.logger [-h] [-f LOG_FILE] [-v] [-c CHANNEL] + [-i {pcan,ixxat,socketcan_ctypes,kvaser,virtual,usb2can,vector,slcan,nican,socketcan,iscan,neovi,serial,socketcan_native}] + [--filter ...] [-b BITRATE] + [--active | --passive] + + Log CAN traffic, printing messages to stdout or to a given file. + + optional arguments: + -h, --help show this help message and exit + -f LOG_FILE, --file_name LOG_FILE + Path and base log filename, for supported types see + can.Logger. + -v How much information do you want to see at the command + line? You can add several of these e.g., -vv is DEBUG + -c CHANNEL, --channel CHANNEL + Most backend interfaces require some sort of channel. + For example with the serial interface the channel + might be a rfcomm device: "/dev/rfcomm0" With the + socketcan interfaces valid channel examples include: + "can0", "vcan0" + -i {pcan,ixxat,socketcan_ctypes,kvaser,virtual,usb2can,vector,slcan,nican,socketcan,iscan,neovi,serial,socketcan_native}, --interface {pcan,ixxat,socketcan_ctypes,kvaser,virtual,usb2can,vector,slcan,nican,socketcan,iscan,neovi,serial,socketcan_native} + Specify the backend CAN interface to use. If left + blank, fall back to reading from configuration files. + --filter ... Comma separated filters can be specified for the given + CAN interface: : (matches when + & mask == can_id & mask) + ~ (matches when & + mask != can_id & mask) + -b BITRATE, --bitrate BITRATE + Bitrate to use for the CAN bus. + --active Start the bus as active, this is applied the default. + --passive Start the bus as passive. + + +can.player +---------- + +Command line help, called with ``--help``:: + + usage: python -m can.player [-h] [-f LOG_FILE] [-v] [-c CHANNEL] + [-i {pcan,ixxat,socketcan_ctypes,kvaser,virtual,usb2can,vector,slcan,nican,socketcan,iscan,neovi,serial,socketcan_native}] + [-b BITRATE] [--ignore-timestamps] + [-g GAP] [-s SKIP] + input-file + + Replay CAN traffic. + + positional arguments: + input-file The file to replay. For supported types see + can.LogReader. + + optional arguments: + -h, --help show this help message and exit + -f LOG_FILE, --file_name LOG_FILE + Path and base log filename, for supported types see + can.LogReader. + -v Also print can frames to stdout. You can add several + of these to enable debugging + -c CHANNEL, --channel CHANNEL + Most backend interfaces require some sort of channel. + For example with the serial interface the channel + might be a rfcomm device: "/dev/rfcomm0" With the + socketcan interfaces valid channel examples include: + "can0", "vcan0" + -i {pcan,ixxat,socketcan_ctypes,kvaser,virtual,usb2can,vector,slcan,nican,socketcan,iscan,neovi,serial,socketcan_native}, --interface {pcan,ixxat,socketcan_ctypes,kvaser,virtual,usb2can,vector,slcan,nican,socketcan,iscan,neovi,serial,socketcan_native} + Specify the backend CAN interface to use. If left + blank, fall back to reading from configuration files. + -b BITRATE, --bitrate BITRATE + Bitrate to use for the CAN bus. + --ignore-timestamps Ignore timestamps (send all frames immediately with + minimum gap between frames) + -g GAP, --gap GAP minimum time between replayed frames + -s SKIP, --skip SKIP skip gaps greater than 's' seconds + +can.viewer +---------- + +A screenshot of the application can be seen below: + +.. image:: ../images/viewer.png + :width: 100% + +The first column is the number of times a frame with the particular ID that has been received, next is the timestamp of the frame relative to the first received message. The third column is the time between the current frame relative to the previous one. Next is the length of the frame, the data and then the decoded data converted according to the ``-d`` argument. The top red row indicates an error frame. + +Command line arguments +^^^^^^^^^^^^^^^^^^^^^^ + +By default it will be using the :doc:`/interfaces/socketcan` interface. All interfaces supported are supported and can be specified using the ``-i`` argument. + +The full usage page can be seen below:: + + Usage: python -m can.viewer [-h] [--version] [-b BITRATE] [-c CHANNEL] + [-d {:,:::...:,file.txt}] + [-f {:,~}] + [-i {iscan,ixxat,kvaser,neovi,nican,pcan,serial,slcan,socketcan,socketcan_ctypes,socketcan_native,usb2can,vector,virtual}] + + A simple CAN viewer terminal application written in Python + + Optional arguments: + -h, --help Show this help message and exit + --version Show program's version number and exit + -b, --bitrate BITRATE + Bitrate to use for the given CAN interface + -c, --channel CHANNEL + Most backend interfaces require some sort of channel. + For example with the serial interface the channel + might be a rfcomm device: "/dev/rfcomm0" with the + socketcan interfaces valid channel examples include: + "can0", "vcan0". (default: use default for the + specified interface) + -d, --decode {:,:::...:,file.txt} + Specify how to convert the raw bytes into real values. + The ID of the frame is given as the first argument and the format as the second. + The Python struct package is used to unpack the received data + where the format characters have the following meaning: + < = little-endian, > = big-endian + x = pad byte + c = char + ? = bool + b = int8_t, B = uint8_t + h = int16, H = uint16 + l = int32_t, L = uint32_t + q = int64_t, Q = uint64_t + f = float (32-bits), d = double (64-bits) + Fx to convert six bytes with ID 0x100 into uint8_t, uint16 and uint32_t: + $ python -m can.viewer -d "100::,~} + Comma separated CAN filters for the given CAN interface: + : (matches when & mask == can_id & mask) + ~ (matches when & mask != can_id & mask) + Fx to show only frames with ID 0x100 to 0x103: + python -m can.viewer -f 100:7FC + Note that the ID and mask are alway interpreted as hex values + -i, --interface {iscan,ixxat,kvaser,neovi,nican,pcan,serial,slcan,socketcan,socketcan_ctypes,socketcan_native,usb2can,vector,virtual} + Specify the backend CAN interface to use. + + Shortcuts: + +---------+-------------------------+ + | Key | Description | + +---------+-------------------------+ + | ESQ/q | Exit the viewer | + | c | Clear the stored frames | + | s | Sort the stored frames | + | SPACE | Pause the viewer | + | UP/DOWN | Scroll the viewer | + +---------+-------------------------+