python4yahdlc 1.2.0__tar.gz → 1.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ # See https://packaging.python.org/en/latest/guides/using-manifest-in/ for
2
+ # further information on this file.
3
+
4
+ include yahdlc/C/*.h
5
+
6
+ global-exclude *~ *.sw[nop] *.py[cod] *.so
@@ -0,0 +1,162 @@
1
+ Metadata-Version: 2.4
2
+ Name: python4yahdlc
3
+ Version: 1.4.0
4
+ Summary: Python binding of the yahdlc library allowing to encode and decode HDLC frames.
5
+ Author: Paul-Emmanuel Raoul
6
+ License-Expression: GPL-3.0-only
7
+ Project-URL: Bug Tracker, https://github.com/SkypLabs/python4yahdlc/issues
8
+ Project-URL: Source Code, https://github.com/SkypLabs/python4yahdlc
9
+ Keywords: hdlc,yahdlc,binding,network
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
13
+ Classifier: Natural Language :: English
14
+ Classifier: Programming Language :: C
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Requires-Python: <4,>=3.10
22
+ Description-Content-Type: text/x-rst
23
+ License-File: LICENSE.txt
24
+ Provides-Extra: examples
25
+ Requires-Dist: fysom; extra == "examples"
26
+ Requires-Dist: pyserial; extra == "examples"
27
+ Provides-Extra: tests
28
+ Requires-Dist: ruff>=0.3; extra == "tests"
29
+ Requires-Dist: tox; extra == "tests"
30
+ Dynamic: license-file
31
+
32
+ =============
33
+ python4yahdlc
34
+ =============
35
+
36
+ |PyPI Package| |PyPI Downloads| |PyPI Python Versions| |Build Status|
37
+
38
+ python4yahdlc is a Python binding of the `yahdlc
39
+ <https://github.com/bang-olufsen/yahdlc>`__ library, allowing to encode and
40
+ decode `HDLC <https://en.wikipedia.org/wiki/High-Level_Data_Link_Control>`__
41
+ frames.
42
+
43
+ Dependencies
44
+ ============
45
+
46
+ This software requires CPython, a C compiler such as Clang or GCC, a C standard
47
+ library, and the Python development headers.
48
+
49
+ For example, on Alpine Linux:
50
+
51
+ .. code:: sh
52
+
53
+ apk add python3 gcc python3-dev musl-dev
54
+
55
+ Installation
56
+ ============
57
+
58
+ From PyPI (recommended)
59
+ -----------------------
60
+
61
+ .. code:: sh
62
+
63
+ pip install --upgrade python4yahdlc
64
+
65
+ From sources
66
+ ------------
67
+
68
+ .. code:: sh
69
+
70
+ # This will clone only the latest stable version of python4yahdlc.
71
+ git clone --single-branch --depth=1 -b main https://github.com/SkypLabs/python4yahdlc.git
72
+
73
+ # Move into the source code directory.
74
+ cd python4yahdlc
75
+
76
+ # Initialise and clone the Git sub-modules (yahdlc itself).
77
+ git submodule update --init --recursive
78
+
79
+ # Install python4yahdlc with pip.
80
+ pip install --upgrade .
81
+
82
+ Usage
83
+ =====
84
+
85
+ To generate a new HDLC data frame:
86
+
87
+ .. code:: python
88
+
89
+ from yahdlc import *
90
+
91
+ frame = frame_data('hello world!')
92
+
93
+ To generate a new HDLC ``ACK`` frame with a specific sequence number:
94
+
95
+ .. code:: python
96
+
97
+ frame = frame_data('', FRAME_ACK, 3)
98
+
99
+ The highest sequence number is 7 and the following frame types are available:
100
+
101
+ - ``FRAME_DATA``
102
+ - ``FRAME_ACK``
103
+ - ``FRAME_NACK``
104
+
105
+ Note that when you generate an ``ACK`` or ``NACK`` frame, the payload is
106
+ useless.
107
+
108
+ To decode a received HDLC frame:
109
+
110
+ .. code:: python
111
+
112
+ data, ftype, seq_no = get_data(frame)
113
+
114
+ For a more advanced use, take a look at the examples available in the `examples
115
+ <https://github.com/SkypLabs/python4yahdlc/tree/main/examples>`__ folder.
116
+
117
+ Development
118
+ ===========
119
+
120
+ To set up a development environment on your local machine:
121
+
122
+ .. code:: sh
123
+
124
+ # Clone the Git repository and initialise its sub-modules.
125
+ git clone https://github.com/SkypLabs/python4yahdlc.git
126
+ cd python4yahdlc
127
+ git submodule update --init --recursive
128
+
129
+ # Create a virtual environment and activate it.
130
+ python -m venv .venv
131
+ source .venv/bin/activate
132
+
133
+ # Make sure to have the latest versions of pip and setuptools.
134
+ pip install --upgrade pip setuptools
135
+
136
+ # Install python4yahdlc in editable mode with all its optional
137
+ # dependencies.
138
+ pip install -e .[examples,tests]
139
+
140
+ Licence
141
+ =======
142
+
143
+ This project is released under the `GPL version 3
144
+ <https://www.gnu.org/licenses/gpl.txt>`__ licence. The `yahdlc
145
+ <https://github.com/bang-olufsen/yahdlc>`__ library is released under the `MIT
146
+ <https://github.com/bang-olufsen/yahdlc/blob/master/LICENSE>`__ licence.
147
+
148
+ .. |Build Status| image:: https://github.com/SkypLabs/python4yahdlc/actions/workflows/test_and_publish.yml/badge.svg?branch=develop
149
+ :target: https://github.com/SkypLabs/python4yahdlc/actions/workflows/test_and_publish.yml?query=branch%3Adevelop
150
+ :alt: Build Status
151
+
152
+ .. |PyPI Downloads| image:: https://img.shields.io/pypi/dm/python4yahdlc.svg?style=flat
153
+ :target: https://pypi.org/project/python4yahdlc/
154
+ :alt: PyPI Package Downloads Per Month
155
+
156
+ .. |PyPI Package| image:: https://img.shields.io/pypi/v/python4yahdlc.svg?style=flat
157
+ :target: https://pypi.org/project/python4yahdlc/
158
+ :alt: PyPI Package Latest Release
159
+
160
+ .. |PyPI Python Versions| image:: https://img.shields.io/pypi/pyversions/python4yahdlc.svg?logo=python&style=flat
161
+ :target: https://pypi.org/project/python4yahdlc/
162
+ :alt: PyPI Package Python Versions
@@ -0,0 +1,131 @@
1
+ =============
2
+ python4yahdlc
3
+ =============
4
+
5
+ |PyPI Package| |PyPI Downloads| |PyPI Python Versions| |Build Status|
6
+
7
+ python4yahdlc is a Python binding of the `yahdlc
8
+ <https://github.com/bang-olufsen/yahdlc>`__ library, allowing to encode and
9
+ decode `HDLC <https://en.wikipedia.org/wiki/High-Level_Data_Link_Control>`__
10
+ frames.
11
+
12
+ Dependencies
13
+ ============
14
+
15
+ This software requires CPython, a C compiler such as Clang or GCC, a C standard
16
+ library, and the Python development headers.
17
+
18
+ For example, on Alpine Linux:
19
+
20
+ .. code:: sh
21
+
22
+ apk add python3 gcc python3-dev musl-dev
23
+
24
+ Installation
25
+ ============
26
+
27
+ From PyPI (recommended)
28
+ -----------------------
29
+
30
+ .. code:: sh
31
+
32
+ pip install --upgrade python4yahdlc
33
+
34
+ From sources
35
+ ------------
36
+
37
+ .. code:: sh
38
+
39
+ # This will clone only the latest stable version of python4yahdlc.
40
+ git clone --single-branch --depth=1 -b main https://github.com/SkypLabs/python4yahdlc.git
41
+
42
+ # Move into the source code directory.
43
+ cd python4yahdlc
44
+
45
+ # Initialise and clone the Git sub-modules (yahdlc itself).
46
+ git submodule update --init --recursive
47
+
48
+ # Install python4yahdlc with pip.
49
+ pip install --upgrade .
50
+
51
+ Usage
52
+ =====
53
+
54
+ To generate a new HDLC data frame:
55
+
56
+ .. code:: python
57
+
58
+ from yahdlc import *
59
+
60
+ frame = frame_data('hello world!')
61
+
62
+ To generate a new HDLC ``ACK`` frame with a specific sequence number:
63
+
64
+ .. code:: python
65
+
66
+ frame = frame_data('', FRAME_ACK, 3)
67
+
68
+ The highest sequence number is 7 and the following frame types are available:
69
+
70
+ - ``FRAME_DATA``
71
+ - ``FRAME_ACK``
72
+ - ``FRAME_NACK``
73
+
74
+ Note that when you generate an ``ACK`` or ``NACK`` frame, the payload is
75
+ useless.
76
+
77
+ To decode a received HDLC frame:
78
+
79
+ .. code:: python
80
+
81
+ data, ftype, seq_no = get_data(frame)
82
+
83
+ For a more advanced use, take a look at the examples available in the `examples
84
+ <https://github.com/SkypLabs/python4yahdlc/tree/main/examples>`__ folder.
85
+
86
+ Development
87
+ ===========
88
+
89
+ To set up a development environment on your local machine:
90
+
91
+ .. code:: sh
92
+
93
+ # Clone the Git repository and initialise its sub-modules.
94
+ git clone https://github.com/SkypLabs/python4yahdlc.git
95
+ cd python4yahdlc
96
+ git submodule update --init --recursive
97
+
98
+ # Create a virtual environment and activate it.
99
+ python -m venv .venv
100
+ source .venv/bin/activate
101
+
102
+ # Make sure to have the latest versions of pip and setuptools.
103
+ pip install --upgrade pip setuptools
104
+
105
+ # Install python4yahdlc in editable mode with all its optional
106
+ # dependencies.
107
+ pip install -e .[examples,tests]
108
+
109
+ Licence
110
+ =======
111
+
112
+ This project is released under the `GPL version 3
113
+ <https://www.gnu.org/licenses/gpl.txt>`__ licence. The `yahdlc
114
+ <https://github.com/bang-olufsen/yahdlc>`__ library is released under the `MIT
115
+ <https://github.com/bang-olufsen/yahdlc/blob/master/LICENSE>`__ licence.
116
+
117
+ .. |Build Status| image:: https://github.com/SkypLabs/python4yahdlc/actions/workflows/test_and_publish.yml/badge.svg?branch=develop
118
+ :target: https://github.com/SkypLabs/python4yahdlc/actions/workflows/test_and_publish.yml?query=branch%3Adevelop
119
+ :alt: Build Status
120
+
121
+ .. |PyPI Downloads| image:: https://img.shields.io/pypi/dm/python4yahdlc.svg?style=flat
122
+ :target: https://pypi.org/project/python4yahdlc/
123
+ :alt: PyPI Package Downloads Per Month
124
+
125
+ .. |PyPI Package| image:: https://img.shields.io/pypi/v/python4yahdlc.svg?style=flat
126
+ :target: https://pypi.org/project/python4yahdlc/
127
+ :alt: PyPI Package Latest Release
128
+
129
+ .. |PyPI Python Versions| image:: https://img.shields.io/pypi/pyversions/python4yahdlc.svg?logo=python&style=flat
130
+ :target: https://pypi.org/project/python4yahdlc/
131
+ :alt: PyPI Package Python Versions
@@ -0,0 +1,35 @@
1
+ [build-system]
2
+ requires = ["setuptools >= 77.0.3", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "python4yahdlc"
7
+ version = "1.4.0"
8
+ description = "Python binding of the yahdlc library allowing to encode and decode HDLC frames."
9
+ readme = "README.rst"
10
+ keywords = ["hdlc", "yahdlc", "binding", "network"]
11
+ authors = [{ name = "Paul-Emmanuel Raoul" }]
12
+ license = "GPL-3.0-only"
13
+ license-files = ["LICEN[CS]E*"]
14
+ requires-python = ">=3.10, <4"
15
+ classifiers = [
16
+ "Development Status :: 5 - Production/Stable",
17
+ "Intended Audience :: Developers",
18
+ "Topic :: Software Development :: Libraries :: Python Modules",
19
+ "Natural Language :: English",
20
+ "Programming Language :: C",
21
+ "Programming Language :: Python :: 3 :: Only",
22
+ "Programming Language :: Python :: 3.10",
23
+ "Programming Language :: Python :: 3.11",
24
+ "Programming Language :: Python :: 3.12",
25
+ "Programming Language :: Python :: 3.13",
26
+ "Programming Language :: Python :: 3.14",
27
+ ]
28
+
29
+ [project.optional-dependencies]
30
+ examples = ["fysom", "pyserial"]
31
+ tests = ["ruff >= 0.3", "tox"]
32
+
33
+ [project.urls]
34
+ "Bug Tracker" = "https://github.com/SkypLabs/python4yahdlc/issues"
35
+ "Source Code" = "https://github.com/SkypLabs/python4yahdlc"
@@ -0,0 +1,24 @@
1
+ """
2
+ Setuptools configuration for building yahdlc as a C extension module.
3
+
4
+ See https://setuptools.pypa.io/en/latest/userguide/ext_modules.html for further
5
+ information on this topic.
6
+ """
7
+
8
+ from setuptools import Extension, setup
9
+
10
+ setup(
11
+ ext_modules=[
12
+ Extension(
13
+ name="yahdlc",
14
+ sources=[
15
+ "src/python4yahdlc.c",
16
+ "yahdlc/C/fcs.c",
17
+ "yahdlc/C/yahdlc.c",
18
+ ],
19
+ include_dirs=[
20
+ "yahdlc/C/",
21
+ ],
22
+ )
23
+ ]
24
+ )
@@ -1,3 +1,4 @@
1
+ #define PY_SSIZE_T_CLEAN
1
2
  #include <Python.h>
2
3
  #include "yahdlc.h"
3
4
 
@@ -19,7 +20,8 @@ static PyObject *get_data(PyObject *self, PyObject *args)
19
20
  int ret;
20
21
  const char *frame_data;
21
22
  char recv_data[TOTAL_FRAME_LENGTH];
22
- unsigned int buf_length = 0, recv_length = 0;
23
+ Py_ssize_t buf_length = 0;
24
+ unsigned int recv_length = 0;
23
25
  yahdlc_control_t control;
24
26
 
25
27
  if (!PyArg_ParseTuple(args, "s#", &frame_data, &buf_length))
@@ -88,7 +90,8 @@ static PyObject *frame_data(PyObject *self, PyObject *args)
88
90
  int ret;
89
91
  const char *send_data;
90
92
  char frame_data[TOTAL_FRAME_LENGTH];
91
- unsigned int data_length = 0, frame_length = 0, frame_type = YAHDLC_FRAME_DATA, seq_no = 0;
93
+ Py_ssize_t data_length = 0;
94
+ unsigned int frame_length = 0, frame_type = YAHDLC_FRAME_DATA, seq_no = 0;
92
95
  yahdlc_control_t control;
93
96
 
94
97
  if (!PyArg_ParseTuple(args, "s#|II", &send_data, &data_length, &frame_type, &seq_no))
@@ -161,12 +164,22 @@ PyMODINIT_FUNC PyInit_yahdlc(void)
161
164
  return NULL;
162
165
 
163
166
  Yahdlc_MessageError = PyErr_NewException("yahdlc.MessageError", NULL, NULL);
164
- Py_INCREF(Yahdlc_MessageError);
165
- PyModule_AddObject(m, "MessageError", Yahdlc_MessageError);
167
+ Py_XINCREF(Yahdlc_MessageError);
168
+ if (PyModule_AddObject(m, "MessageError", Yahdlc_MessageError) < 0) {
169
+ Py_XDECREF(Yahdlc_MessageError);
170
+ Py_CLEAR(Yahdlc_MessageError);
171
+ Py_DECREF(m);
172
+ return NULL;
173
+ }
166
174
 
167
175
  Yahdlc_FCSError = PyErr_NewException("yahdlc.FCSError", NULL, NULL);
168
- Py_INCREF(Yahdlc_FCSError);
169
- PyModule_AddObject(m, "FCSError", Yahdlc_FCSError);
176
+ Py_XINCREF(Yahdlc_FCSError);
177
+ if (PyModule_AddObject(m, "FCSError", Yahdlc_FCSError) < 0) {
178
+ Py_XDECREF(Yahdlc_FCSError);
179
+ Py_CLEAR(Yahdlc_FCSError);
180
+ Py_DECREF(m);
181
+ return NULL;
182
+ }
170
183
 
171
184
  PyModule_AddIntConstant(m, "FRAME_DATA", YAHDLC_FRAME_DATA);
172
185
  PyModule_AddIntConstant(m, "FRAME_ACK", YAHDLC_FRAME_ACK);
@@ -0,0 +1,162 @@
1
+ Metadata-Version: 2.4
2
+ Name: python4yahdlc
3
+ Version: 1.4.0
4
+ Summary: Python binding of the yahdlc library allowing to encode and decode HDLC frames.
5
+ Author: Paul-Emmanuel Raoul
6
+ License-Expression: GPL-3.0-only
7
+ Project-URL: Bug Tracker, https://github.com/SkypLabs/python4yahdlc/issues
8
+ Project-URL: Source Code, https://github.com/SkypLabs/python4yahdlc
9
+ Keywords: hdlc,yahdlc,binding,network
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
13
+ Classifier: Natural Language :: English
14
+ Classifier: Programming Language :: C
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Requires-Python: <4,>=3.10
22
+ Description-Content-Type: text/x-rst
23
+ License-File: LICENSE.txt
24
+ Provides-Extra: examples
25
+ Requires-Dist: fysom; extra == "examples"
26
+ Requires-Dist: pyserial; extra == "examples"
27
+ Provides-Extra: tests
28
+ Requires-Dist: ruff>=0.3; extra == "tests"
29
+ Requires-Dist: tox; extra == "tests"
30
+ Dynamic: license-file
31
+
32
+ =============
33
+ python4yahdlc
34
+ =============
35
+
36
+ |PyPI Package| |PyPI Downloads| |PyPI Python Versions| |Build Status|
37
+
38
+ python4yahdlc is a Python binding of the `yahdlc
39
+ <https://github.com/bang-olufsen/yahdlc>`__ library, allowing to encode and
40
+ decode `HDLC <https://en.wikipedia.org/wiki/High-Level_Data_Link_Control>`__
41
+ frames.
42
+
43
+ Dependencies
44
+ ============
45
+
46
+ This software requires CPython, a C compiler such as Clang or GCC, a C standard
47
+ library, and the Python development headers.
48
+
49
+ For example, on Alpine Linux:
50
+
51
+ .. code:: sh
52
+
53
+ apk add python3 gcc python3-dev musl-dev
54
+
55
+ Installation
56
+ ============
57
+
58
+ From PyPI (recommended)
59
+ -----------------------
60
+
61
+ .. code:: sh
62
+
63
+ pip install --upgrade python4yahdlc
64
+
65
+ From sources
66
+ ------------
67
+
68
+ .. code:: sh
69
+
70
+ # This will clone only the latest stable version of python4yahdlc.
71
+ git clone --single-branch --depth=1 -b main https://github.com/SkypLabs/python4yahdlc.git
72
+
73
+ # Move into the source code directory.
74
+ cd python4yahdlc
75
+
76
+ # Initialise and clone the Git sub-modules (yahdlc itself).
77
+ git submodule update --init --recursive
78
+
79
+ # Install python4yahdlc with pip.
80
+ pip install --upgrade .
81
+
82
+ Usage
83
+ =====
84
+
85
+ To generate a new HDLC data frame:
86
+
87
+ .. code:: python
88
+
89
+ from yahdlc import *
90
+
91
+ frame = frame_data('hello world!')
92
+
93
+ To generate a new HDLC ``ACK`` frame with a specific sequence number:
94
+
95
+ .. code:: python
96
+
97
+ frame = frame_data('', FRAME_ACK, 3)
98
+
99
+ The highest sequence number is 7 and the following frame types are available:
100
+
101
+ - ``FRAME_DATA``
102
+ - ``FRAME_ACK``
103
+ - ``FRAME_NACK``
104
+
105
+ Note that when you generate an ``ACK`` or ``NACK`` frame, the payload is
106
+ useless.
107
+
108
+ To decode a received HDLC frame:
109
+
110
+ .. code:: python
111
+
112
+ data, ftype, seq_no = get_data(frame)
113
+
114
+ For a more advanced use, take a look at the examples available in the `examples
115
+ <https://github.com/SkypLabs/python4yahdlc/tree/main/examples>`__ folder.
116
+
117
+ Development
118
+ ===========
119
+
120
+ To set up a development environment on your local machine:
121
+
122
+ .. code:: sh
123
+
124
+ # Clone the Git repository and initialise its sub-modules.
125
+ git clone https://github.com/SkypLabs/python4yahdlc.git
126
+ cd python4yahdlc
127
+ git submodule update --init --recursive
128
+
129
+ # Create a virtual environment and activate it.
130
+ python -m venv .venv
131
+ source .venv/bin/activate
132
+
133
+ # Make sure to have the latest versions of pip and setuptools.
134
+ pip install --upgrade pip setuptools
135
+
136
+ # Install python4yahdlc in editable mode with all its optional
137
+ # dependencies.
138
+ pip install -e .[examples,tests]
139
+
140
+ Licence
141
+ =======
142
+
143
+ This project is released under the `GPL version 3
144
+ <https://www.gnu.org/licenses/gpl.txt>`__ licence. The `yahdlc
145
+ <https://github.com/bang-olufsen/yahdlc>`__ library is released under the `MIT
146
+ <https://github.com/bang-olufsen/yahdlc/blob/master/LICENSE>`__ licence.
147
+
148
+ .. |Build Status| image:: https://github.com/SkypLabs/python4yahdlc/actions/workflows/test_and_publish.yml/badge.svg?branch=develop
149
+ :target: https://github.com/SkypLabs/python4yahdlc/actions/workflows/test_and_publish.yml?query=branch%3Adevelop
150
+ :alt: Build Status
151
+
152
+ .. |PyPI Downloads| image:: https://img.shields.io/pypi/dm/python4yahdlc.svg?style=flat
153
+ :target: https://pypi.org/project/python4yahdlc/
154
+ :alt: PyPI Package Downloads Per Month
155
+
156
+ .. |PyPI Package| image:: https://img.shields.io/pypi/v/python4yahdlc.svg?style=flat
157
+ :target: https://pypi.org/project/python4yahdlc/
158
+ :alt: PyPI Package Latest Release
159
+
160
+ .. |PyPI Python Versions| image:: https://img.shields.io/pypi/pyversions/python4yahdlc.svg?logo=python&style=flat
161
+ :target: https://pypi.org/project/python4yahdlc/
162
+ :alt: PyPI Package Python Versions
@@ -0,0 +1,15 @@
1
+ LICENSE.txt
2
+ MANIFEST.in
3
+ README.rst
4
+ pyproject.toml
5
+ setup.py
6
+ src/python4yahdlc.c
7
+ src/python4yahdlc.egg-info/PKG-INFO
8
+ src/python4yahdlc.egg-info/SOURCES.txt
9
+ src/python4yahdlc.egg-info/dependency_links.txt
10
+ src/python4yahdlc.egg-info/requires.txt
11
+ src/python4yahdlc.egg-info/top_level.txt
12
+ yahdlc/C/fcs.c
13
+ yahdlc/C/fcs.h
14
+ yahdlc/C/yahdlc.c
15
+ yahdlc/C/yahdlc.h
@@ -0,0 +1,8 @@
1
+
2
+ [examples]
3
+ fysom
4
+ pyserial
5
+
6
+ [tests]
7
+ ruff>=0.3
8
+ tox
@@ -0,0 +1,84 @@
1
+ #include "fcs.h"
2
+
3
+ #ifdef CRC32
4
+ /*
5
+ * CRC-Type: CRC32 (IEEE 802.3 - Ethernet)
6
+ * Polynomial: 0x04C11DB7
7
+ * (x^32+x^26+x^23^+x^22+x^16+x^12+x^11+x^10+
8
+ * +x^8+x^7+x^5+x^4+x^2+x+1)
9
+ * Lookup Table: Reflected
10
+ */
11
+ static const unsigned int fcstab[256] = {
12
+ 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
13
+ 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
14
+ 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
15
+ 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,
16
+ 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
17
+ 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
18
+ 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
19
+ 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,
20
+ 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
21
+ 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
22
+ 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,
23
+ 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
24
+ 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,
25
+ 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
26
+ 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
27
+ 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
28
+ 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,
29
+ 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
30
+ 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,
31
+ 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
32
+ 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
33
+ 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,
34
+ 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,
35
+ 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
36
+ 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
37
+ 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,
38
+ 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
39
+ 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
40
+ 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,
41
+ 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
42
+ 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
43
+ 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
44
+ };
45
+ #else
46
+ /*
47
+ * CRC-Type: CRC16 CCIT
48
+ * Polynomial: 0x1021 (x^16+x^12+x^5+1)
49
+ * Lookup Table: Reflected
50
+ */
51
+ static const unsigned short fcstab[256] = { 0x0000, 0x1189, 0x2312, 0x329b,
52
+ 0x4624, 0x57ad, 0x6536, 0x74bf, 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c,
53
+ 0xdbe5, 0xe97e, 0xf8f7, 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c,
54
+ 0x75b7, 0x643e, 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff,
55
+ 0xe876, 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
56
+ 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5, 0x3183,
57
+ 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c, 0xbdcb, 0xac42,
58
+ 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974, 0x4204, 0x538d, 0x6116,
59
+ 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb, 0xce4c, 0xdfc5, 0xed5e, 0xfcd7,
60
+ 0x8868, 0x99e1, 0xab7a, 0xbaf3, 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1,
61
+ 0x0528, 0x37b3, 0x263a, 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960,
62
+ 0xbbfb, 0xaa72, 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630,
63
+ 0x17b9, 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
64
+ 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738, 0xffcf,
65
+ 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70, 0x8408, 0x9581,
66
+ 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7, 0x0840, 0x19c9, 0x2b52,
67
+ 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff, 0x9489, 0x8500, 0xb79b, 0xa612,
68
+ 0xd2ad, 0xc324, 0xf1bf, 0xe036, 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5,
69
+ 0x4f6c, 0x7df7, 0x6c7e, 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7,
70
+ 0xc03c, 0xd1b5, 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74,
71
+ 0x5dfd, 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
72
+ 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c, 0xc60c,
73
+ 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3, 0x4a44, 0x5bcd,
74
+ 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb, 0xd68d, 0xc704, 0xf59f,
75
+ 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232, 0x5ac5, 0x4b4c, 0x79d7, 0x685e,
76
+ 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a, 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a,
77
+ 0xb0a3, 0x8238, 0x93b1, 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb,
78
+ 0x0e70, 0x1ff9, 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9,
79
+ 0x8330, 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78 };
80
+ #endif
81
+
82
+ FCS_SIZE calc_fcs(FCS_SIZE fcs, unsigned char value) {
83
+ return (fcs >> 8) ^ fcstab[(fcs ^ value) & 0xff];
84
+ }