esp2-gateway-adapter 0.1__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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Philipp Grimm
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,42 @@
1
+ Metadata-Version: 2.1
2
+ Name: esp2_gateway_adapter
3
+ Version: 0.1
4
+ Summary: Protocol adapter from esp3 to esp2 for Home Assistant Eltako Integration
5
+ Home-page: https://github.com/grimmpp/esp2_gateway_adapter
6
+ Author: Philipp Grimm
7
+ License: MIT License
8
+
9
+ Copyright (c) 2024 Philipp Grimm
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+
29
+ Requires-Python: >=3.7
30
+ Description-Content-Type: text/markdown
31
+ License-File: LICENSE
32
+ Requires-Dist: eltako14bus>=0.0.46
33
+ Requires-Dist: enocean>=0.60.1
34
+ Requires-Dist: pyserial
35
+ Requires-Dist: pyserial-asyncio
36
+ Requires-Dist: aiocoap
37
+
38
+ # EnOcean ESP3 to ESP3 Gateway Adapter
39
+
40
+ EnOcean gateway adapter from ESP3 to ESP2 for [Eltako Home Assistant Integration](https://github.com/grimmpp/home-assistant-eltako).
41
+
42
+ This component is mainly required to support USB300, USB400 and USB500 (Wireless EnOcean USB stick/transceiver) which is using ESP3 protocol unlike all other Eltako devices which are using ESP2.
@@ -0,0 +1,5 @@
1
+ # EnOcean ESP3 to ESP3 Gateway Adapter
2
+
3
+ EnOcean gateway adapter from ESP3 to ESP2 for [Eltako Home Assistant Integration](https://github.com/grimmpp/home-assistant-eltako).
4
+
5
+ This component is mainly required to support USB300, USB400 and USB500 (Wireless EnOcean USB stick/transceiver) which is using ESP3 protocol unlike all other Eltako devices which are using ESP2.
@@ -0,0 +1,42 @@
1
+ Metadata-Version: 2.1
2
+ Name: esp2_gateway_adapter
3
+ Version: 0.1
4
+ Summary: Protocol adapter from esp3 to esp2 for Home Assistant Eltako Integration
5
+ Home-page: https://github.com/grimmpp/esp2_gateway_adapter
6
+ Author: Philipp Grimm
7
+ License: MIT License
8
+
9
+ Copyright (c) 2024 Philipp Grimm
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+
29
+ Requires-Python: >=3.7
30
+ Description-Content-Type: text/markdown
31
+ License-File: LICENSE
32
+ Requires-Dist: eltako14bus>=0.0.46
33
+ Requires-Dist: enocean>=0.60.1
34
+ Requires-Dist: pyserial
35
+ Requires-Dist: pyserial-asyncio
36
+ Requires-Dist: aiocoap
37
+
38
+ # EnOcean ESP3 to ESP3 Gateway Adapter
39
+
40
+ EnOcean gateway adapter from ESP3 to ESP2 for [Eltako Home Assistant Integration](https://github.com/grimmpp/home-assistant-eltako).
41
+
42
+ This component is mainly required to support USB300, USB400 and USB500 (Wireless EnOcean USB stick/transceiver) which is using ESP3 protocol unlike all other Eltako devices which are using ESP2.
@@ -0,0 +1,9 @@
1
+ LICENSE
2
+ README.md
3
+ setup.py
4
+ esp2_gateway_adapter.egg-info/PKG-INFO
5
+ esp2_gateway_adapter.egg-info/SOURCES.txt
6
+ esp2_gateway_adapter.egg-info/dependency_links.txt
7
+ esp2_gateway_adapter.egg-info/requires.txt
8
+ esp2_gateway_adapter.egg-info/top_level.txt
9
+ src/esp3_serial_com.py
@@ -0,0 +1,5 @@
1
+ eltako14bus>=0.0.46
2
+ enocean>=0.60.1
3
+ pyserial
4
+ pyserial-asyncio
5
+ aiocoap
@@ -0,0 +1 @@
1
+ esp2_gateway_adapter
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,38 @@
1
+ import os
2
+ from setuptools import setup, find_packages
3
+ from distutils.core import setup
4
+
5
+
6
+
7
+ base_dir = os.path.dirname(__file__)
8
+
9
+ # with open(os.path.join(base_dir, 'README.md'), encoding="utf-8") as f:
10
+ with open('README.md', encoding="utf-8") as f:
11
+ long_description = f.read()
12
+
13
+ # with open(os.path.join(base_dir, 'LICENSE'), encoding="utf-8") as f:
14
+ with open('LICENSE', encoding="utf-8") as f:
15
+ license = f.read()
16
+
17
+ required = ['eltako14bus>=0.0.46', 'enocean>=0.60.1', 'pyserial', 'pyserial-asyncio', 'aiocoap']
18
+
19
+
20
+
21
+ setup(
22
+ name='esp2_gateway_adapter',
23
+ version='0.1',
24
+ package_dir={"esp2_gateway_adapter":'src'},
25
+ package=[""],
26
+ include_package_data=True,
27
+ install_requires=required,
28
+ author="Philipp Grimm",
29
+ description="Protocol adapter from esp3 to esp2 for Home Assistant Eltako Integration",
30
+ long_description=long_description,
31
+ long_description_content_type='text/markdown',
32
+ license=license,
33
+ url="https://github.com/grimmpp/esp2_gateway_adapter",
34
+ python_requires='>=3.7',
35
+ )
36
+
37
+ #.\.venv\Scripts\python.exe -m build --sdistx1xxx
38
+ #python setup.py bdist_wheel
@@ -0,0 +1,400 @@
1
+ # -*- encoding: utf-8 -*-
2
+ from __future__ import print_function, unicode_literals, division, absolute_import
3
+ import asyncio
4
+ import datetime
5
+ import logging
6
+ import serial
7
+ import time
8
+ import threading
9
+
10
+ import queue
11
+
12
+ from enocean.communicators.communicator import Communicator
13
+ from enocean.protocol.packet import Packet, RadioPacket, RORG, PACKET, UTETeachInPacket
14
+ from enocean.protocol.constants import PACKET, PARSE_RESULT, RETURN_CODE
15
+
16
+
17
+ from eltakobus.message import ESP2Message, RPSMessage, Regular1BSMessage, Regular4BSMessage, prettify
18
+ from eltakobus.eep import CentralCommandSwitching, A5_38_08
19
+ from eltakobus.util import b2s
20
+
21
+ class ESP3SerialCommunicator(Communicator):
22
+ ''' Serial port communicator class for EnOcean radio '''
23
+
24
+ def __init__(self,
25
+ filename,
26
+ log=None,
27
+ callback=None,
28
+ baud_rate=57600,
29
+ reconnection_timeout:float=10,
30
+ esp2_translation_enabled:bool=False,
31
+ auto_reconnect:bool=True):
32
+
33
+ self.esp2_translation_enabled = esp2_translation_enabled
34
+ self._outside_callback = callback
35
+ self._auto_reconnect = auto_reconnect
36
+ super(ESP3SerialCommunicator, self).__init__(self.__callback_wrapper)
37
+
38
+ self._filename = filename
39
+ self.log = log or logging.getLogger('enocean.communicators.SerialCommunicator')
40
+
41
+ self._baud_rate = baud_rate
42
+ self.__recon_time = reconnection_timeout
43
+ self.is_serial_connected = threading.Event()
44
+ self.status_changed_handler = None
45
+ self.__ser = None
46
+
47
+ def set_callback(self, callback):
48
+ self._outside_callback = callback
49
+
50
+ def is_active(self) -> bool:
51
+ return not self._stop_flag.is_set() and self.is_serial_connected.is_set()
52
+
53
+ def set_status_changed_handler(self, handler) -> None:
54
+ self.status_changed_handler = handler
55
+ self._fire_status_change_handler(self.is_active())
56
+
57
+ def _fire_status_change_handler(self, connected:bool) -> None:
58
+ try:
59
+ if self.status_changed_handler:
60
+ self.status_changed_handler(connected)
61
+ except Exception as e:
62
+ pass
63
+
64
+ async def base_exchange(self, request:ESP2Message):
65
+ self.esp2_translation_enabled = True
66
+ self.send(request)
67
+
68
+ @classmethod
69
+ def convert_esp2_to_esp3_message(cls, message: ESP2Message) -> RadioPacket:
70
+ optional = []
71
+ if isinstance(message, RPSMessage):
72
+ rorg = RORG.RPS
73
+ data = [message.data[0]]
74
+ elif isinstance(message, Regular1BSMessage):
75
+ rorg = RORG.BS1
76
+ data = [message.data[0]]
77
+ elif isinstance(message, Regular4BSMessage):
78
+ rorg = RORG.BS4
79
+ sub_tel = PACKET.RADIO_SUB_TEL if message.outgoing else 0 # 3 = send, 0 = receive
80
+ optional = [sub_tel, # 3 = sender, 0 = receiver
81
+ 0xFF, 0xFF, 0xFF, 0xFF, # destination broadcast
82
+ 0xFF # wireless quality
83
+ ]
84
+ data = message.data
85
+ else:
86
+ return None
87
+
88
+ command=[rorg]
89
+ command.extend(data)
90
+ command.extend([x for x in message.address])
91
+ command.extend([message.status])
92
+
93
+ package_type = PACKET.RADIO_ERP1
94
+ p = Packet(package_type, command, optional)
95
+ p.rorg = rorg
96
+ p.packet_type = package_type
97
+
98
+ return p
99
+
100
+ @classmethod
101
+ def convert_esp3_to_esp2_message(cls, packet: RadioPacket) -> ESP2Message:
102
+
103
+ if packet.rorg == RORG.RPS:
104
+ org = 0x05
105
+ elif packet.rorg == RORG.BS1:
106
+ org = 0x06
107
+ elif packet.rorg == RORG.BS4:
108
+ org = 0x07
109
+ else:
110
+ return None
111
+
112
+ sub_tel = packet.optional[0] if packet.optional is not None and len(packet.optional) > 0 else 0 # 3 = send, 0 = receive
113
+ in_or_out = 0x6b if sub_tel == PACKET.RADIO_SUB_TEL else 0x0b
114
+
115
+ if org == 0x07:
116
+
117
+ body:bytes = bytes([in_or_out, org] + packet.data[1:])
118
+ else:
119
+ # data = ['0xf6', '0x50', '0xff', '0xa2', '0x24', '0x1', '0x30']
120
+ body:bytes = bytes([in_or_out, org] + packet.data[1:2] + [0,0,0] + packet.data[2:])
121
+
122
+ return prettify( ESP2Message(body) )
123
+
124
+
125
+ def __callback_wrapper(self, msg: Packet):
126
+ if msg.packet_type == PACKET.RESPONSE and msg.data[0] != RETURN_CODE.OK:
127
+ self.log.error(f"Received ESP3 response with with return code {RETURN_CODE(msg.data[0]).name} ({msg.data[0]}) - {str(msg)} ")
128
+ return
129
+
130
+ if self._outside_callback:
131
+ if self.esp2_translation_enabled:
132
+ # only when message is radio telegram
133
+ if msg.packet_type == PACKET.RADIO:
134
+ esp2_msg = ESP3SerialCommunicator.convert_esp3_to_esp2_message(msg)
135
+
136
+ if esp2_msg is None:
137
+ self.log.warn("[ESP3SerialCommunicator] Cannot convert to esp2 message (%s).", msg)
138
+ else:
139
+ self._outside_callback(esp2_msg)
140
+
141
+ else:
142
+ self._outside_callback(msg)
143
+
144
+ def reconnect(self):
145
+ self._stop_flag.set()
146
+ self._stop_flag.wait()
147
+ self.start()
148
+
149
+ async def send(self, packet) -> bool:
150
+ if self.esp2_translation_enabled:
151
+ esp3_msg = ESP3SerialCommunicator.convert_esp2_to_esp3_message(packet)
152
+ self.log.info(f"Converted esp2 ({str(packet)} - {b2s(packet.serialize())}) message to esp3 ({str(esp3_msg)} - {b2s(esp3_msg.build())})")
153
+ if esp3_msg is None:
154
+ self.log.warn(f"[ESP3SerialCommunicator] Cannot convert to esp3 message ({str(packet)}).")
155
+ else:
156
+ self.log.info(f"Send ESP3 message {str(esp3_msg)}")
157
+ return super().send(esp3_msg)
158
+ else:
159
+ self.log.info(f"Send ESP3 message {str(packet)}")
160
+ return super().send(packet)
161
+
162
+ def run(self):
163
+ self.logger.info('SerialCommunicator started')
164
+ self._fire_status_change_handler(connected=False)
165
+ while not self._stop_flag.is_set():
166
+ try:
167
+ # Initialize serial port
168
+ if self.__ser is None:
169
+ self.__ser = serial.Serial(self._filename, self._baud_rate, timeout=0.1)
170
+ self.log.info("Established serial connection to %s - baudrate: %d", self._filename, self._baud_rate)
171
+ self.is_serial_connected.set()
172
+ self._fire_status_change_handler(connected=True)
173
+
174
+ # If there's messages in transmit queue
175
+ # send them
176
+ while True:
177
+ packet = self._get_from_send_queue()
178
+ if not packet:
179
+ break
180
+ self.log.debug("send msg: %s", packet)
181
+ self.__ser.write(bytearray(packet.build()))
182
+
183
+ # Read chars from serial port as hex numbers
184
+ self._buffer.extend(bytearray(self.__ser.read(16)))
185
+ self.parse()
186
+ time.sleep(0)
187
+
188
+ except (serial.SerialException, IOError) as e:
189
+ self._fire_status_change_handler(connected=False)
190
+ self.is_serial_connected.clear()
191
+ self.log.error(e)
192
+ self.__ser = None
193
+ if self._auto_reconnect:
194
+ self.log.info("Serial communication crashed. Wait %s seconds for reconnection.", self.__recon_time)
195
+ time.sleep(self.__recon_time)
196
+ else:
197
+ self._stop_flag.set()
198
+
199
+ if self.__ser is not None:
200
+ self.__ser.close()
201
+ self.__ser = None
202
+ self.is_serial_connected.clear()
203
+ self._fire_status_change_handler(connected=False)
204
+ self.logger.info('SerialCommunicator stopped')
205
+
206
+
207
+ def parse(self):
208
+ ''' Parses messages and puts them to receive queue '''
209
+ # Loop while we get new messages
210
+ while True:
211
+ status, self._buffer, packet = Packet.parse_msg(self._buffer)
212
+ # If message is incomplete -> break the loop
213
+ if status == PARSE_RESULT.INCOMPLETE:
214
+ return status
215
+
216
+ # If message is OK, add it to receive queue or send to the callback method
217
+ if status == PARSE_RESULT.OK and packet:
218
+ packet.received = datetime.datetime.now()
219
+
220
+ if isinstance(packet, UTETeachInPacket) and self.teach_in:
221
+ response_packet = packet.create_response_packet(self.base_id)
222
+ self.logger.info('Sending response to UTE teach-in.')
223
+ self.send(response_packet)
224
+
225
+ if self._outside_callback is None:
226
+ self.receive.put(packet)
227
+ else:
228
+ self.__callback_wrapper(packet)
229
+ self.logger.debug(packet)
230
+
231
+ @property
232
+ def base_id(self):
233
+ ''' Fetches Base ID from the transmitter, if required. Otherwise returns the currently set Base ID. '''
234
+ # If base id is already set, return it.
235
+ if self._base_id is not None:
236
+ return self._base_id
237
+
238
+ # Send COMMON_COMMAND 0x08, CO_RD_IDBASE request to the module
239
+ super().send(Packet(PACKET.COMMON_COMMAND, data=[0x08]))
240
+ # Loop over 10 times, to make sure we catch the response.
241
+ # Thanks to timeout, shouldn't take more than a second.
242
+ # Unfortunately, all other messages received during this time are ignored.
243
+ for i in range(0, 10):
244
+ try:
245
+ packet = self.receive.get(block=True, timeout=0.1)
246
+ # We're only interested in responses to the request in question.
247
+ if packet.packet_type == PACKET.RESPONSE and packet.response == RETURN_CODE.OK and len(packet.response_data) == 4: # noqa: E501
248
+ # Base ID is set in the response data.
249
+ self._base_id = packet.response_data
250
+ # Put packet back to the Queue, so the user can also react to it if required...
251
+ self.receive.put(packet)
252
+ break
253
+ # Put other packets back to the Queue.
254
+ self.receive.put(packet)
255
+ except queue.Empty:
256
+ continue
257
+ # Return the current Base ID (might be None).
258
+ return self._base_id
259
+
260
+ if __name__ == '__main__':
261
+
262
+ def cb(package:Packet):
263
+ print("Callback Base id: " + b2s(package.data[1:]))
264
+ print(package)
265
+
266
+ # com = ESP3SerialCommunicator("COM12", callback=cb)
267
+ # com.start()
268
+ # com.is_serial_connected.wait(timeout=10)
269
+ # asyncio.run( com.send(Packet(PACKET.COMMON_COMMAND, data=[0x08])) )
270
+
271
+
272
+ # ser = serial.Serial("COM12", 57600, timeout=0.1)
273
+
274
+ # # org = 0xF6 # org = 0x05, rorg = 0xF6
275
+ # # package_type = 0x01 # Radio_ERP_1
276
+ # # telegram_count = 0x02 # Sub-Telegram Count
277
+ # # header_checksum = 0x7A
278
+ # # h_seq = property(lambda self: 3 if self.outgoing else 0)
279
+ # # data = [0x70]
280
+ # # address = [0xFF,0xD6,0x30,0x01]
281
+ # # status = 0x00
282
+
283
+ # # # 55 00 07 07 01 7A F6 70 FF B9 FC 8D 30 02 FF FF FF FF 44 00 F8
284
+ # # body = bytes((0x07, 0x07, package_type, header_checksum, org, *data, *address, status, telegram_count, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF))
285
+
286
+ # # data = b"\x55\x00" + body
287
+ # # msg = data + crc8.crc8(data[1:]).digest()
288
+
289
+ # msg = MY_RPSMessage(b'\xFF\xD6\x30\x01',0x00, b'\x70', True)
290
+
291
+ # ser.write(msg.serialize())
292
+ # ser.read_all()
293
+
294
+ # print("\n\n")
295
+ # time.sleep(2)
296
+
297
+ # ser.close()
298
+
299
+ # exit(0)
300
+
301
+ com = ESP3SerialCommunicator("COM12", callback=cb, esp2_translation_enabled=False)
302
+ com.start()
303
+ com.is_serial_connected.wait(timeout=10)
304
+ com.set_callback(None)
305
+
306
+ if com.base_id:
307
+ print("base_id: "+ b2s(com.base_id) +"\n\n")
308
+
309
+ com.set_callback(cb)
310
+ com.base_id
311
+
312
+ # asyncio.run( com.send(RPSMessage(address=b'\xFF\xD6\x30\x01', status=b'\x30', data=b'\x50', outgoing=True)) )
313
+ command=[RORG.BS4, 0x01, 0x00, 0x00, 0x09]
314
+ command.extend([0xFF,0xD6,0x30, 0x01])
315
+ command.extend([0x00])
316
+
317
+ optional=[0x03, 0xFF,0xFF,0xFF,0xFF,0xFF]
318
+
319
+ asyncio.run( com.send(Packet(PACKET.RADIO_ERP1, command, optional)) )
320
+
321
+ command=[RORG.RPS, 0x01, 0x00, 0x00, 0x09]
322
+ command.extend([0xFF,0xD6,0x30, 0x01])
323
+ command.extend([0x00])
324
+ asyncio.run( com.send(Packet(PACKET.RADIO_ERP1, command, optional)) )
325
+
326
+ sender = [0xFF,0xD6,0x30,0x01]
327
+ status = [0x30]
328
+
329
+ command=[RORG.RPS, 0x30]
330
+ command.extend(sender)
331
+ command.extend(status)
332
+
333
+ destination = [0xFF,0xFF,0xFF,0xFF]# [0xFF,0xA2,0x24,0x01]
334
+
335
+
336
+ # command.extend([0xFF,0xD6,0x30,0x01])
337
+ # command.extend([0x00])
338
+
339
+ # p = RadioPacket.create(RORG.RPS, rorg_func=0x02, rorg_type=0x02, command=command, destination=destination, sender=sender)
340
+ # p = Packet(packet_type = 0x01, data=command)
341
+ # p.status = 0x30
342
+ # p.data[1] = 0x30
343
+ # p.data[6] = 0x30
344
+
345
+ p = ESP3SerialCommunicator.convert_esp2_to_esp3_message(RPSMessage(b'\xFF\xD6\x30\x01', 0x30, b'\x30', True))
346
+
347
+
348
+ # p = ESP3SerialCommunicator.convert_esp2_to_esp3_message(Regular4BSMessage(b'\xFF\xD6\x30\x01', 0x00, b'\x01\x00\x00\x09', True))
349
+ # asyncio.run( com.send(p) )
350
+
351
+ print("\n\n")
352
+ # time.sleep(3)
353
+
354
+ address = b'\xFF\xD6\x30\x01'
355
+ # esp2_msg = Regular4BSMessage(address, 0x00, bytes((0x01, 0x00, 0x00, 0x09)), True)
356
+
357
+ esp2_msg = A5_38_08(command=0x01, switching=CentralCommandSwitching(0, 1, 0, 0, 1)).encode_message(address)
358
+ esp2_msg2 = Regular4BSMessage(address, 0x00, b'\x01\x00\x00\x09', True)
359
+
360
+ print("ESP2: "+b2s(esp2_msg.serialize()))
361
+ p = ESP3SerialCommunicator.convert_esp2_to_esp3_message(esp2_msg)
362
+ print(', '.join([hex(i) for i in p.build()]))
363
+
364
+ # p = ESP3SerialCommunicator.convert_esp2_to_esp3_message(RPSMessage(b'\xFF\xD6\x30\x01', 0x30, b'\x10', True))
365
+ # p = ESP3SerialCommunicator.convert_esp2_to_esp3_message(Regular4BSMessage(b'\xFF\x82\x3E\x70', 0x00, bytes((0x01, 0x00, 0x00, 0x08)), True))
366
+ print("ESP3: " + b2s(bytes(p.build())) )
367
+ print("ESP2: " + b2s(ESP3SerialCommunicator.convert_esp3_to_esp2_message(p).serialize() ))
368
+
369
+ asyncio.run( com.send(p) )
370
+
371
+
372
+ print("\n\n")
373
+ time.sleep(2)
374
+
375
+
376
+
377
+ com.stop()
378
+ exit(0)
379
+
380
+ data = [0xf6, 0x50, 0xff, 0xa2, 0x24, 0x1, 0x30]
381
+ body:bytes = bytes([0x0b, 0x05] + data[1:2] + [0,0,0] + data[2:])
382
+ msg = prettify( ESP2Message(body) )
383
+ print( msg )
384
+
385
+ # command = [0xA5, 0x02, 0x01, 0x01, 0x09] # data
386
+ # command.extend([0xFF, 0xD6, 0x30, 0x01]) # address
387
+ # command.extend([0x00]) #status
388
+ # packet = RadioPacket(0x01, command, [])
389
+ # print(packet)
390
+
391
+ packet = RadioPacket.create(rorg=RORG.RPS,
392
+ rorg_func=0x02,
393
+ rorg_type=0x02,
394
+ sender=[0xFF,0xD6,0x30,0x01],
395
+ command=[0x01, 0x00, 0x00, 0x09]
396
+ )
397
+ print(packet)
398
+
399
+ packet = ESP3SerialCommunicator.convert_esp2_to_esp3_message(msg)
400
+ print(packet)