You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# This module contains helper methods for calling dfu.* Notecard API commands.
10
+
# This module is optional and not required for use with the Notecard.
11
+
12
+
fromnotecard.validatorsimportvalidate_card_object
13
+
14
+
15
+
@validate_card_object
16
+
defget(card, length=None, offset=None):
17
+
"""Retrieve downloaded firmware data from the Notecard for use with IAP host MCU firmware updates.
18
+
19
+
Args:
20
+
card (Notecard): The current Notecard object.
21
+
length (int): The number of bytes of firmware data to read and return to the host. Set to `0` to verify that the Notecard is in DFU mode without attempting to retrieve data.
22
+
offset (int): The offset to use before performing a read of firmware data.
"""Get and sets the background download status of MCU host or Notecard firmware updates.
38
+
39
+
Args:
40
+
card (Notecard): The current Notecard object.
41
+
err (str): If `err` text is provided along with `"stop":true`, this sets the host DFU to an error state with the specified string.
42
+
name (str): Determines which type of firmware update status to view. The value can be `"user"` (default), which gets the status of MCU host firmware updates, or `"card"`, which gets the status of Notecard firmware updates.
43
+
off (bool): `true` to disable firmware downloads from Notehub.
44
+
on (bool): `true` to allow firmware downloads from Notehub.
45
+
status (str): When setting `stop` to `true`, an optional string synchronized to Notehub, which can be used for informational or diagnostic purposes.
46
+
stop (bool): `true` to clear DFU state and delete the local firmware image from the Notecard.
47
+
version (str): Version information on the host firmware to pass to Notehub. You may pass a simple version number string (e.g. `"1.0.0.0"`), or an object with detailed information about the firmware image (recommended). If you provide an object it must take the following form. `{"org":"my-organization","product":"My Product","description":"A description of the image","version":"1.2.4","built":"Jan 01 2025 01:02:03","vermajor":1,"verminor":2,"verpatch":4,"verbuild": 5,"builder":"The Builder"}` Code to help you generate a version with the correct formatting is available in Enabling Notecard Outboard Firmware Update.
48
+
vvalue (str): A voltage-variable string that controls, by Notecard voltage, whether or not DFU is enabled. Use a boolean `1` (on) or `0` (off) for each source/voltage level: `usb:<1/0>;high:<1/0>;normal:<1/0>;low:<1/0>;dead:0`.
Copy file name to clipboardExpand all lines: notecard/env.py
+41-16Lines changed: 41 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -9,21 +9,20 @@
9
9
# This module contains helper methods for calling env.* Notecard API commands.
10
10
# This module is optional and not required for use with the Notecard.
11
11
12
-
importnotecard
13
12
fromnotecard.validatorsimportvalidate_card_object
14
13
15
14
16
15
@validate_card_object
17
16
defdefault(card, name=None, text=None):
18
-
"""Perform an env.default request against a Notecard.
17
+
"""Use by the Notecard host to specify a default value for an environment variable until that variable is overridden by a device, project or fleet-wide setting at Notehub.
19
18
20
19
Args:
21
20
card (Notecard): The current Notecard object.
22
-
name (string): The name of an environment var to set a default for.
23
-
text (optional): The default value. Omit to delete the default.
21
+
name (str): The name of the environment variable (case-insensitive).
22
+
text (str): The value of the variable. Pass `""` or omit from the request to delete it.
"""Return a single environment variable, or all variables according to precedence rules.
39
38
40
39
Args:
41
40
card (Notecard): The current Notecard object.
42
-
name (string): The name of an environment variable to get.
41
+
name (str): The name of the environment variable (case-insensitive). Omit to return all environment variables known to the Notecard.
42
+
names (list): A list of one or more variables to retrieve, by name (case-insensitive).
43
+
time (int): Request a modified environment variable or variables from the Notecard, but only if modified after the time provided.
43
44
44
45
Returns:
45
-
string: The result of the Notecard request.
46
+
dict: The result of the Notecard request.
46
47
"""
47
48
req= {"req": "env.get"}
48
49
ifname:
49
50
req["name"] =name
51
+
ifnames:
52
+
req["names"] =names
53
+
iftimeisnotNone:
54
+
req["time"] =time
50
55
returncard.Transaction(req)
51
56
52
57
53
58
@validate_card_object
54
-
defmodified(card):
55
-
"""Perform an env.modified request against a Notecard.
59
+
defmodified(card, time=None):
60
+
"""Get the time of the update to any environment variable managed by the Notecard.
56
61
57
62
Args:
58
63
card (Notecard): The current Notecard object.
64
+
time (int): Request whether the Notecard has detected an environment variable change since a known epoch time.
59
65
60
66
Returns:
61
-
string: The result of the Notecard request.
67
+
dict: The result of the Notecard request.
62
68
"""
63
69
req= {"req": "env.modified"}
70
+
iftimeisnotNone:
71
+
req["time"] =time
64
72
returncard.Transaction(req)
65
73
66
74
67
75
@validate_card_object
68
76
defset(card, name=None, text=None):
69
-
"""Perform an env.set request against a Notecard.
77
+
"""Set a local environment variable on the Notecard. Local environment variables cannot be overridden by a Notehub variable of any scope.
70
78
71
79
Args:
72
80
card (Notecard): The current Notecard object.
73
-
name (string): The name of an environment variable to set.
74
-
text (optional): The variable value. Omit to delete.
81
+
name (str): The name of the environment variable (case-insensitive).
82
+
text (str): The value of the variable. Pass `""` or omit from the request to delete it.
75
83
76
84
Returns:
77
-
string: The result of the Notecard request.
85
+
dict: The result of the Notecard request.
78
86
"""
79
87
req= {"req": "env.set"}
80
88
ifname:
81
89
req["name"] =name
82
90
iftext:
83
91
req["text"] =text
84
92
returncard.Transaction(req)
93
+
94
+
95
+
@validate_card_object
96
+
deftemplate(card, body=None):
97
+
"""Use `env.template` request allows developers to provide a schema for the environment variables the Notecard uses. The provided template allows the Notecard to store environment variables as fixed-length binary records rather than as flexible JSON objects that require much more memory. Using templated environment variables also allows the Notecard to optimize the network traffic related to sending and receiving environment variable updates.
98
+
99
+
Args:
100
+
card (Notecard): The current Notecard object.
101
+
body (dict): A sample JSON body that specifies environment variables names and values as "hints" for the data type. Possible data types are: boolean, integer, float, and string. See Understanding Template Data Types for a full explanation of type hints.
Copy file name to clipboardExpand all lines: notecard/file.py
+42-25Lines changed: 42 additions & 25 deletions
Original file line number
Diff line number
Diff line change
@@ -9,72 +9,89 @@
9
9
# This module contains helper methods for calling file.* Notecard API commands.
10
10
# This module is optional and not required for use with the Notecard.
11
11
12
-
importnotecard
13
12
fromnotecard.validatorsimportvalidate_card_object
14
13
15
14
16
15
@validate_card_object
17
-
defchanges(card, tracker=None, files=None):
18
-
"""Perform individual or batch queries on Notefiles.
16
+
defchangesPending(card):
17
+
"""Return info about file changes that are pending upload to Notehub.
19
18
20
19
Args:
21
20
card (Notecard): The current Notecard object.
22
-
tracker (string): A developer-defined tracker ID.
23
-
files (array): A list of Notefiles to retrieve changes for.
24
21
25
22
Returns:
26
-
string: The result of the Notecard request.
23
+
dict: The result of the Notecard request.
27
24
"""
28
-
req= {"req": "file.changes"}
29
-
iftracker:
30
-
req["tracker"] =tracker
31
-
iffiles:
32
-
req["files"] =files
25
+
req= {"req": "file.changes.pending"}
33
26
returncard.Transaction(req)
34
27
35
28
36
29
@validate_card_object
37
-
defdelete(card, files=None):
38
-
"""Delete individual notefiles and their contents.
30
+
defchanges(card, files=None, tracker=None):
31
+
"""Use to perform queries on a single or multiple files to determine if new Notes are available to read, or if there are unsynced Notes in local Notefiles. Note: This request is a Notefile API request, only. `.qo` Notes in Notehub are automatically ingested and stored, or sent to applicable Routes.
39
32
40
33
Args:
41
34
card (Notecard): The current Notecard object.
42
-
files (array): A list of Notefiles to delete.
35
+
files (list): One or more files to obtain change information from. Omit to return changes for all Notefiles.
36
+
tracker (str): ID of a change tracker to use to determine changes to Notefiles.
43
37
44
38
Returns:
45
-
string: The result of the Notecard request.
39
+
dict: The result of the Notecard request.
46
40
"""
47
-
req= {"req": "file.delete"}
41
+
req= {"req": "file.changes"}
48
42
iffiles:
49
43
req["files"] =files
44
+
iftracker:
45
+
req["tracker"] =tracker
50
46
returncard.Transaction(req)
51
47
52
48
53
49
@validate_card_object
54
-
defstats(card):
55
-
"""Obtain statistics about local notefiles.
50
+
defclear(card, file=None):
51
+
"""Use to clear the contents of a specified outbound (`.qo`/`.qos`) Notefile, deleting all pending Notes.
56
52
57
53
Args:
58
54
card (Notecard): The current Notecard object.
55
+
file (str): The name of the Notefile whose Notes you wish to delete.
59
56
60
57
Returns:
61
-
string: The result of the Notecard request.
58
+
dict: The result of the Notecard request.
62
59
"""
63
-
req= {"req": "file.stats"}
64
-
60
+
req= {"req": "file.clear"}
61
+
iffile:
62
+
req["file"] =file
65
63
returncard.Transaction(req)
66
64
67
65
68
66
@validate_card_object
69
-
defpendingChanges(card):
70
-
"""Retrieve information about pending Notehub changes.
67
+
defdelete(card, files=None):
68
+
"""Delete Notefiles and the Notes they contain.
71
69
72
70
Args:
73
71
card (Notecard): The current Notecard object.
72
+
files (list): One or more files to delete.
74
73
75
74
Returns:
76
-
string: The result of the Notecard request.
75
+
dict: The result of the Notecard request.
77
76
"""
78
-
req= {"req": "file.changes.pending"}
77
+
req= {"req": "file.delete"}
78
+
iffiles:
79
+
req["files"] =files
80
+
returncard.Transaction(req)
81
+
82
+
83
+
@validate_card_object
84
+
defstats(card, file=None):
85
+
"""Get resource statistics about local Notefiles.
86
+
87
+
Args:
88
+
card (Notecard): The current Notecard object.
89
+
file (str): Returns the stats for the specified Notefile only.
0 commit comments