-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcard.py
More file actions
184 lines (148 loc) · 5.07 KB
/
Copy pathcard.py
File metadata and controls
184 lines (148 loc) · 5.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
"""card Fluent API Helper."""
##
# @file card.py
#
# @brief card Fluent API Helper.
#
# @section description Description
# This module contains helper methods for calling card.* Notecard API commands.
# This module is optional and not required for use with the Notecard.
from notecard.validators import validate_card_object
@validate_card_object
def attn(card, mode=None, files=None, seconds=None, payload=None, start=None):
"""Configure interrupt detection between a host and Notecard.
Args:
card (Notecard): The current Notecard object.
mode (string): The attn mode to set.
files (array): A collection of notefiles to watch.
seconds (int): A timeout to use when arming attn mode.
payload (int): When using sleep mode, a payload of data from the host
that the Notecard should hold in memory until retrieved by
the host.
start (bool): When using sleep mode and the host has reawakened,
request the Notecard to return the stored payload.
Returns:
string: The result of the Notecard request.
"""
req = {"req": "card.attn"}
if mode:
req["mode"] = mode
if files:
req["files"] = files
if seconds:
req["seconds"] = seconds
if payload:
req["payload"] = payload
if start:
req["start"] = start
return card.Transaction(req)
@validate_card_object
def time(card):
"""Retrieve the current time and date from the Notecard.
Args:
card (Notecard): The current Notecard object.
Returns:
string: The result of the Notecard request.
"""
req = {"req": "card.time"}
return card.Transaction(req)
@validate_card_object
def status(card):
"""Retrieve the status of the Notecard.
Args:
card (Notecard): The current Notecard object.
Returns:
string: The result of the Notecard request.
"""
req = {"req": "card.status"}
return card.Transaction(req)
@validate_card_object
def temp(card, minutes=None):
"""Retrieve the current temperature from the Notecard.
Args:
card (Notecard): The current Notecard object.
minutes (int): If specified, creates a templated _temp.qo file that
gathers Notecard temperature value at the specified interval.
Returns:
string: The result of the Notecard request.
"""
req = {"req": "card.temp"}
if minutes:
req["minutes"] = minutes
return card.Transaction(req)
@validate_card_object
def version(card):
"""Retrieve firmware version information from the Notecard.
Args:
card (Notecard): The current Notecard object.
Returns:
string: The result of the Notecard request.
"""
req = {"req": "card.version"}
return card.Transaction(req)
@validate_card_object
def voltage(card, hours=None, offset=None, vmax=None, vmin=None,
usb=None, alert=None):
"""Retrieve current and historical voltage info from the Notecard.
Args:
card (Notecard): The current Notecard object.
hours (int): Number of hours to analyze.
offset (int): Number of hours to offset.
vmax (decimal): max voltage level to report.
vmin (decimal): min voltage level to report.
usb (bool): Enable USB power state monitoring.
alert (bool): Enable alerts for USB power state changes. Only works
when usb=True.
Returns:
dict: The result of the Notecard request containing voltage and power
state information.
Note:
For Mojo-based power consumption monitoring with temperature and
milliamp-hour tracking, see card.power().
"""
req = {"req": "card.voltage"}
if hours:
req["hours"] = hours
if offset:
req["offset"] = offset
if vmax:
req["vmax"] = vmax
if vmin:
req["vmin"] = vmin
if usb is not None:
req["usb"] = usb
if alert is not None:
req["alert"] = alert
return card.Transaction(req)
@validate_card_object
def power(card, minutes=None, reset=None):
"""Configure and query the Mojo-based power consumption monitoring.
Args:
card (Notecard): The current Notecard object.
minutes (int, optional): How often to log power consumption.
reset (bool, optional): Reset consumption counters if True.
Returns:
dict: Contains temperature, voltage, and milliamp_hours readings.
"""
req = {"req": "card.power"}
if minutes is not None:
req["minutes"] = minutes
if reset:
req["reset"] = True
return card.Transaction(req)
@validate_card_object
def wireless(card, mode=None, apn=None):
"""Retrieve wireless modem info or customize modem behavior.
Args:
card (Notecard): The current Notecard object.
mode (string): The wireless module mode to set.
apn (string): Access Point Name (APN) when using an external SIM.
Returns:
string: The result of the Notecard request.
"""
req = {"req": "card.wireless"}
if mode:
req["mode"] = mode
if apn:
req["apn"] = apn
return card.Transaction(req)