• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

blues / note-python / 13416193193

19 Feb 2025 03:26PM UTC coverage: 91.822%. Remained the same
13416193193

Pull #95

github

web-flow
Merge c028f6883 into dbec383c7
Pull Request #95: Update CI workflow to use ubuntu-24.04

2066 of 2250 relevant lines covered (91.82%)

3.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

46.43
/notecard/transaction_manager.py
1
"""TransactionManager-related code for note-python."""
2

3
import sys
4✔
4
import time
4✔
5

6
from notecard.timeout import start_timeout, has_timed_out
4✔
7
from notecard.gpio import GPIO
4✔
8

9

10
class TransactionManager:
4✔
11
    """Class for managing the start and end of Notecard transactions.
12

13
    Some Notecards need to be signaled via GPIO when a transaction is about to
14
    start. When the Notecard sees a particular GPIO, called RTX (ready to
15
    transact), go high, it responds with a high pulse on another GPIO, CTX
16
    (clear to transact). At this point, the transaction can proceed. This class
17
    implements this protocol in its start method.
18
    """
19

20
    def __init__(self, rtx_pin, ctx_pin):
4✔
21
        """Initialize the TransactionManager.
22

23
        Even though RTX is an output, we set it as an input here to conserve
24
        power until we need to use it.
25
        """
26
        self.rtx_pin = GPIO.setup(rtx_pin, GPIO.IN)
×
27
        self.ctx_pin = GPIO.setup(ctx_pin, GPIO.IN)
×
28

29
    def start(self, timeout_secs):
4✔
30
        """Prepare the Notecard for a transaction."""
31
        start = start_timeout()
×
32

33
        self.rtx_pin.direction(GPIO.OUT)
×
34
        self.rtx_pin.value(1)
×
35
        # If the Notecard supports RTX/CTX, it'll pull CTX low. If the Notecard
36
        # doesn't support RTX/CTX, this pull up will make sure we get the clear
37
        # to transact immediately.
38
        self.ctx_pin.pull(GPIO.PULL_UP)
×
39

40
        # Wait for the Notecard to signal clear to transact (i.e. drive the CTX
41
        # pin HIGH). Time out after timeout_secs seconds.
42
        while True:
43
            if self.ctx_pin.value():
×
44
                break
×
45

46
            if (has_timed_out(start, timeout_secs)):
×
47
                # Abandon request on timeout.
48
                self.stop()
×
49
                raise Exception(
×
50
                    "Timed out waiting for Notecard to give clear to transact."
51
                )
52

53
            time.sleep(.001)
×
54

55
        self.ctx_pin.pull(GPIO.PULL_NONE)
×
56

57
    def stop(self):
4✔
58
        """Make RTX an input to conserve power and remove the pull up on CTX."""
59
        self.rtx_pin.direction(GPIO.IN)
×
60
        self.ctx_pin.pull(GPIO.PULL_NONE)
×
61

62

63
class NoOpTransactionManager:
4✔
64
    """Class for transaction start/stop when no transaction pins are set.
65

66
    If the transaction pins aren't set, the start and stop operations should be
67
    no-ops.
68
    """
69

70
    def start(self, timeout_secs):
4✔
71
        """No-op start function."""
72
        pass
4✔
73

74
    def stop(self):
4✔
75
        """No-op stop function."""
76
        pass
4✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc