Skip to content

Commit 7cb21f0

Browse files
author
James Boulton
committed
Add support for Dash Server OTA and CLK features.
1 parent 297fc65 commit 7cb21f0

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

dashio/device.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,14 @@ def _make_cfg64(self, data):
171171
reply += c64_json + "\n"
172172
return reply
173173

174+
def _server_clk(self, data):
175+
if self._clk_rx_callback is not None:
176+
self._clk_rx_callback(data)
177+
178+
def _server_ota(self, data):
179+
if self._ota_rx_callback is not None:
180+
self._ota_rx_callback(data)
181+
174182
def _make_cfg(self, data):
175183
try:
176184
dashboard_id = data[2]
@@ -226,6 +234,27 @@ def _send_announce(self):
226234
logger.debug("ANNOUNCE: %s", payload.rstrip())
227235
self.tx_zmq_pub.send_multipart([b"ANNOUNCE", payload.encode('utf-8')])
228236

237+
def request_clock(self):
238+
"""Requests UTC Timestamp from the Dash Server
239+
"""
240+
payload = self._device_id_str + "\tCLK\n"
241+
logger.debug("ANNOUNCE: %s", payload.rstrip())
242+
self.tx_zmq_pub.send_multipart([b"ANNOUNCE", payload.encode('utf-8')])
243+
244+
def request_ota_build_number(self):
245+
"""Requests requests latest build number for over the air updates from the Dash Server
246+
"""
247+
payload = self._device_id_str + f"\tOTA\t{self.device_type}\n"
248+
logger.debug("ANNOUNCE: %s", payload.rstrip())
249+
self.tx_zmq_pub.send_multipart([b"ANNOUNCE", payload.encode('utf-8')])
250+
251+
def request_ota(self, build_number, chunk_number):
252+
"""Requests requests latest ota build from the Dash Server
253+
"""
254+
payload = self._device_id_str + f"\tOTA\t{self.device_type}\t{build_number}\t{chunk_number}\n"
255+
logger.debug("ANNOUNCE: %s", payload.rstrip())
256+
self.tx_zmq_pub.send_multipart([b"ANNOUNCE", payload.encode('utf-8')])
257+
229258
def is_control_loaded(self, control_type, control_id: str) -> bool:
230259
"""Is the control loaded in the device?"""
231260
key = f"{control_type}\t{control_id}"
@@ -344,6 +373,42 @@ def _add_action_device_setup(self, settable: bool):
344373
pass
345374
self._cfg["deviceSetup"] = ','.join(self._device_setup_list)
346375

376+
def set_clock_callback(self, callback):
377+
"""
378+
Specify a callback function to be called when The Dash server sends clock data.
379+
380+
Parameters
381+
----------
382+
callback:
383+
The callback function. It will be invoked with one argument, the msg from dash server.
384+
The callback must return a Boolean indicating success.
385+
"""
386+
self._clk_rx_callback = callback
387+
388+
def unset_clock_callback(self):
389+
"""
390+
Unset the clock rx callback.
391+
"""
392+
self._ota_rx_callback = None
393+
394+
def set_ota_callback(self, callback):
395+
"""
396+
Specify a callback function to be called when The Dash server sends ota data.
397+
398+
Parameters
399+
----------
400+
callback:
401+
The callback function. It will be invoked with one argument, the msg from dash server.
402+
The callback must return a Boolean indicating success.
403+
"""
404+
self._clk_rx_callback = callback
405+
406+
def unset_ota_callback(self):
407+
"""
408+
Unset the ota rx callback.
409+
"""
410+
self._ota_rx_callback = None
411+
347412
def set_wifi_callback(self, callback):
348413
"""
349414
Specify a callback function to be called when IoTDashboard sets wifi parameters.
@@ -541,6 +606,8 @@ def __init__(
541606
self._name_rx_callback = None
542607
self._tcp_rx_callback = None
543608
self._mqtt_rx_callback = None
609+
self._clk_rx_callback = None
610+
self._ota_rx_callback = None
544611
self.device_type = device_type.translate(BAD_CHARS)
545612
self.device_id = device_id.translate(BAD_CHARS)
546613
self._b_device_id = self.device_id.encode('utf-8')
@@ -551,6 +618,8 @@ def __init__(
551618
self._device_commands_dict['CONNECT'] = self._make_connect
552619
self._device_commands_dict['STATUS'] = self._make_status
553620
self._device_commands_dict['CFG'] = self._make_cfg64
621+
self._device_commands_dict['CLK'] = self._server_clk
622+
self._device_commands_dict['OTA'] = self._server_ota
554623
self.controls_dict = {}
555624
self._cfg = {}
556625
self._cfg["deviceSetup"] = ''

0 commit comments

Comments
 (0)