Browse Source

cc1101-transmit: flock SPI device file to avoid race conditions with other processes

Fabian Peter Hammerle 3 years ago
parent
commit
dff95838f7
3 changed files with 4 additions and 2 deletions
  1. 2 0
      CHANGELOG.md
  2. 1 1
      cc1101/_cli.py
  3. 1 1
      tests/test_cli_transmit.py

+ 2 - 0
CHANGELOG.md

@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 ## [Unreleased]
 ### Fixed
 - `cc1101-transmit` command:
+  - set `flock` on SPI device file to avoid race conditions,
+    if other processes attempt to use the same transceiver
   - configure transceiver after reading from stdin
     to avoid delay between configuration and transmission, if pipe is slow
 

+ 1 - 1
cc1101/_cli.py

@@ -59,7 +59,7 @@ def _transmit():
     payload = sys.stdin.buffer.read()
     # configure transceiver after reading from stdin
     # to avoid delay between configuration and transmission if pipe is slow
-    with cc1101.CC1101() as transceiver:
+    with cc1101.CC1101(lock_spi_device=True) as transceiver:
         if args.base_frequency_hertz:
             transceiver.set_base_frequency_hertz(args.base_frequency_hertz)
         if args.symbol_rate_baud:

+ 1 - 1
tests/test_cli_transmit.py

@@ -110,7 +110,7 @@ def test_configure_device(
         with unittest.mock.patch("sys.stdin", stdin_mock):
             with unittest.mock.patch("sys.argv", args):
                 cc1101._cli._transmit()
-    transceiver_mock.assert_called_once_with()
+    transceiver_mock.assert_called_once_with(lock_spi_device=True)
     if base_frequency_hertz is None:
         transceiver_mock().__enter__().set_base_frequency_hertz.assert_not_called()
     else: