meshcore 2.1.12__tar.gz → 2.1.14__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.
Potentially problematic release.
This version of meshcore might be problematic. Click here for more details.
- {meshcore-2.1.12 → meshcore-2.1.14}/PKG-INFO +1 -1
- {meshcore-2.1.12 → meshcore-2.1.14}/pyproject.toml +1 -1
- meshcore-2.1.14/src/meshcore/commands/.contact.py.swp +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/src/meshcore/commands/base.py +49 -38
- {meshcore-2.1.12 → meshcore-2.1.14}/src/meshcore/commands/contact.py +66 -3
- {meshcore-2.1.12 → meshcore-2.1.14}/src/meshcore/events.py +1 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/src/meshcore/reader.py +1 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/.github/python-test.yml +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/.gitignore +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/LICENSE +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/README.md +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/examples/ble_chat.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/examples/ble_pin_pairing_example.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/examples/ble_private_key_export.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/examples/ble_t1000_chan_msg.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/examples/ble_t1000_custom_vars.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/examples/ble_t1000_infos.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/examples/ble_t1000_msg.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/examples/ble_t1000_msg_retries.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/examples/ble_t1000_set_cv.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/examples/connection_events_example.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/examples/mepo_mc_gps.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/examples/pubsub_example.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/examples/rf_packet_monitor.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/examples/serial_battery_monitor.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/examples/serial_channel_manager.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/examples/serial_chat.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/examples/serial_contacts.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/examples/serial_infos.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/examples/serial_msg.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/examples/serial_repeater_status.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/examples/serial_repeater_telemetry.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/examples/serial_trace.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/examples/tcp_chat.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/examples/tcp_login_status.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/examples/tcp_mchome_contacts.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/examples/tcp_mchome_infos.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/examples/tcp_mchome_msg.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/examples/tcp_mchome_readmsgs.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/pytest.ini +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/src/meshcore/__init__.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/src/meshcore/ble_cx.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/src/meshcore/commands/__init__.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/src/meshcore/commands/binary.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/src/meshcore/commands/device.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/src/meshcore/commands/messaging.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/src/meshcore/connection_manager.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/src/meshcore/lpp_json_encoder.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/src/meshcore/meshcore.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/src/meshcore/packets.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/src/meshcore/parsing.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/src/meshcore/serial_cx.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/src/meshcore/tcp_cx.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/tests/README.md +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/tests/test_ble_connection.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/tests/test_ble_pin_pairing.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/tests/test_meshcore_ble_pin.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/tests/unit/test_commands.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/tests/unit/test_events.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/tests/unit/test_private_key_export.py +0 -0
- {meshcore-2.1.12 → meshcore-2.1.14}/tests/unit/test_reader.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: meshcore
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.14
|
|
4
4
|
Summary: Base classes for communicating with meshcore companion radios
|
|
5
5
|
Project-URL: Homepage, https://github.com/fdlamotte/meshcore_py
|
|
6
6
|
Project-URL: Issues, https://github.com/fdlamotte/meshcore_py/issues
|
|
Binary file
|
|
@@ -80,6 +80,53 @@ class CommandHandlerBase:
|
|
|
80
80
|
)-> None:
|
|
81
81
|
self._get_contact_by_prefix = func
|
|
82
82
|
|
|
83
|
+
async def wait_for_events(
|
|
84
|
+
self,
|
|
85
|
+
expected_events: Optional[Union[EventType, List[EventType]]] = None,
|
|
86
|
+
timeout: Optional[float] = None,
|
|
87
|
+
) -> Event:
|
|
88
|
+
try:
|
|
89
|
+
# Convert single event to list if needed
|
|
90
|
+
if not isinstance(expected_events, list):
|
|
91
|
+
expected_events = [expected_events]
|
|
92
|
+
|
|
93
|
+
logger.debug(f"Waiting for events {expected_events}, timeout={timeout}")
|
|
94
|
+
|
|
95
|
+
# Create futures for all expected events
|
|
96
|
+
futures = []
|
|
97
|
+
for event_type in expected_events:
|
|
98
|
+
future = asyncio.create_task(
|
|
99
|
+
self.dispatcher.wait_for_event(event_type, {}, timeout)
|
|
100
|
+
)
|
|
101
|
+
futures.append(future)
|
|
102
|
+
|
|
103
|
+
# Wait for the first event to complete or all to timeout
|
|
104
|
+
done, pending = await asyncio.wait(
|
|
105
|
+
futures, timeout=timeout, return_when=asyncio.FIRST_COMPLETED
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
# Cancel all pending futures
|
|
109
|
+
for future in pending:
|
|
110
|
+
future.cancel()
|
|
111
|
+
|
|
112
|
+
# Check if any future completed successfully
|
|
113
|
+
for future in done:
|
|
114
|
+
event = await future
|
|
115
|
+
if event:
|
|
116
|
+
return event
|
|
117
|
+
|
|
118
|
+
# Create an error event when no event is received
|
|
119
|
+
return Event(EventType.ERROR, {"reason": "no_event_received"})
|
|
120
|
+
except asyncio.TimeoutError:
|
|
121
|
+
logger.debug(f"Command timed out {data}")
|
|
122
|
+
return Event(EventType.ERROR, {"reason": "timeout"})
|
|
123
|
+
except Exception as e:
|
|
124
|
+
logger.debug(f"Command error: {e}")
|
|
125
|
+
return Event(EventType.ERROR, {"error": str(e)})
|
|
126
|
+
|
|
127
|
+
return Event(EventType.ERROR, {})
|
|
128
|
+
|
|
129
|
+
|
|
83
130
|
async def send(
|
|
84
131
|
self,
|
|
85
132
|
data: bytes,
|
|
@@ -110,45 +157,9 @@ class CommandHandlerBase:
|
|
|
110
157
|
await self._sender_func(data)
|
|
111
158
|
|
|
112
159
|
if expected_events:
|
|
113
|
-
try:
|
|
114
|
-
# Convert single event to list if needed
|
|
115
|
-
if not isinstance(expected_events, list):
|
|
116
|
-
expected_events = [expected_events]
|
|
117
|
-
|
|
118
|
-
logger.debug(f"Waiting for events {expected_events}, timeout={timeout}")
|
|
119
|
-
|
|
120
|
-
# Create futures for all expected events
|
|
121
|
-
futures = []
|
|
122
|
-
for event_type in expected_events:
|
|
123
|
-
future = asyncio.create_task(
|
|
124
|
-
self.dispatcher.wait_for_event(event_type, {}, timeout)
|
|
125
|
-
)
|
|
126
|
-
futures.append(future)
|
|
127
|
-
|
|
128
|
-
# Wait for the first event to complete or all to timeout
|
|
129
|
-
done, pending = await asyncio.wait(
|
|
130
|
-
futures, timeout=timeout, return_when=asyncio.FIRST_COMPLETED
|
|
131
|
-
)
|
|
132
|
-
|
|
133
|
-
# Cancel all pending futures
|
|
134
|
-
for future in pending:
|
|
135
|
-
future.cancel()
|
|
136
|
-
|
|
137
|
-
# Check if any future completed successfully
|
|
138
|
-
for future in done:
|
|
139
|
-
event = await future
|
|
140
|
-
if event:
|
|
141
|
-
return event
|
|
142
|
-
|
|
143
|
-
# Create an error event when no event is received
|
|
144
|
-
return Event(EventType.ERROR, {"reason": "no_event_received"})
|
|
145
|
-
except asyncio.TimeoutError:
|
|
146
|
-
logger.debug(f"Command timed out {data}")
|
|
147
|
-
return Event(EventType.ERROR, {"reason": "timeout"})
|
|
148
|
-
except Exception as e:
|
|
149
|
-
logger.debug(f"Command error: {e}")
|
|
150
|
-
return Event(EventType.ERROR, {"error": str(e)})
|
|
151
160
|
# For commands that don't expect events, return a success event
|
|
161
|
+
return await self.wait_for_events(expected_events, timeout)
|
|
162
|
+
|
|
152
163
|
return Event(EventType.OK, {})
|
|
153
164
|
|
|
154
165
|
# attached at base because its a common method
|
|
@@ -1,19 +1,82 @@
|
|
|
1
1
|
import logging
|
|
2
|
+
import asyncio
|
|
2
3
|
from typing import Optional
|
|
3
4
|
|
|
4
|
-
from ..events import Event, EventType
|
|
5
|
+
from ..events import Event, EventDispatcher, EventType
|
|
5
6
|
from .base import CommandHandlerBase, DestinationType, _validate_destination
|
|
6
7
|
|
|
7
8
|
logger = logging.getLogger("meshcore")
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
class ContactCommands(CommandHandlerBase):
|
|
11
|
-
async def get_contacts(self, lastmod=0) -> Event:
|
|
12
|
+
async def get_contacts(self, lastmod=0, anim=False) -> Event:
|
|
12
13
|
logger.debug("Getting contacts")
|
|
13
14
|
data = b"\x04"
|
|
14
15
|
if lastmod > 0:
|
|
15
16
|
data = data + lastmod.to_bytes(4, "little")
|
|
16
|
-
|
|
17
|
+
if anim:
|
|
18
|
+
print("Fetching contacts ", end="", flush=True)
|
|
19
|
+
# wait first event
|
|
20
|
+
res = await self.send(data)
|
|
21
|
+
timeout = 5
|
|
22
|
+
# Inline wait for events to continue waiting for CONTACTS event
|
|
23
|
+
# while receiving NEXT_CONTACTs (or it might be missed over serial)
|
|
24
|
+
try:
|
|
25
|
+
# Create futures for all expected events
|
|
26
|
+
futures = []
|
|
27
|
+
for event_type in [EventType.ERROR, EventType.NEXT_CONTACT, EventType.CONTACTS] :
|
|
28
|
+
future = asyncio.create_task(
|
|
29
|
+
self.dispatcher.wait_for_event(event_type, {}, timeout)
|
|
30
|
+
)
|
|
31
|
+
futures.append(future)
|
|
32
|
+
|
|
33
|
+
while True:
|
|
34
|
+
|
|
35
|
+
# Wait for the first event to complete or all to timeout
|
|
36
|
+
done, pending = await asyncio.wait(
|
|
37
|
+
futures, timeout=timeout, return_when=asyncio.FIRST_COMPLETED
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
# Check if any future completed successfully
|
|
41
|
+
if len(done) == 0:
|
|
42
|
+
print(" Timeout")
|
|
43
|
+
for future in pending: # cancel all futures
|
|
44
|
+
future.cancel()
|
|
45
|
+
return None
|
|
46
|
+
|
|
47
|
+
for future in done:
|
|
48
|
+
event = await future
|
|
49
|
+
|
|
50
|
+
if event:
|
|
51
|
+
if event.type == EventType.NEXT_CONTACT:
|
|
52
|
+
if anim:
|
|
53
|
+
print(".", end="", flush=True)
|
|
54
|
+
else: # Done or Error ... cancel pending and return
|
|
55
|
+
if anim:
|
|
56
|
+
print(" Done" if event.type == EventType.CONTACTS else " Error")
|
|
57
|
+
for future in pending:
|
|
58
|
+
future.cancel()
|
|
59
|
+
return event
|
|
60
|
+
|
|
61
|
+
futures = []
|
|
62
|
+
for future in pending: # put back pending
|
|
63
|
+
futures.append(future)
|
|
64
|
+
|
|
65
|
+
future = asyncio.create_task( # and recreate NEXT_CONTACT
|
|
66
|
+
self.dispatcher.wait_for_event(EventType.NEXT_CONTACT, {}, timeout)
|
|
67
|
+
)
|
|
68
|
+
futures.append(future)
|
|
69
|
+
|
|
70
|
+
except asyncio.TimeoutError:
|
|
71
|
+
logger.debug(f"Timeout receiving contacts")
|
|
72
|
+
if anim:
|
|
73
|
+
print(" Timeout")
|
|
74
|
+
return None
|
|
75
|
+
except Exception as e:
|
|
76
|
+
logger.debug(f"Command error: {e}")
|
|
77
|
+
if anim:
|
|
78
|
+
print(" Error")
|
|
79
|
+
return Event(EventType.ERROR, {"error": str(e)})
|
|
17
80
|
|
|
18
81
|
async def reset_path(self, key: DestinationType) -> Event:
|
|
19
82
|
key_bytes = _validate_destination(key, prefix_length=32)
|
|
@@ -99,6 +99,7 @@ class MessageReader:
|
|
|
99
99
|
if packet_type_value == PacketType.PUSH_CODE_NEW_ADVERT.value:
|
|
100
100
|
await self.dispatcher.dispatch(Event(EventType.NEW_CONTACT, c))
|
|
101
101
|
else:
|
|
102
|
+
await self.dispatcher.dispatch(Event(EventType.NEXT_CONTACT, c))
|
|
102
103
|
self.contacts[c["public_key"]] = c
|
|
103
104
|
|
|
104
105
|
elif packet_type_value == PacketType.CONTACT_END.value:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|