@@ -171,6 +171,14 @@ def _make_cfg64(self, data):
171
171
reply += c64_json + "\n "
172
172
return reply
173
173
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
+
174
182
def _make_cfg (self , data ):
175
183
try :
176
184
dashboard_id = data [2 ]
@@ -226,6 +234,27 @@ def _send_announce(self):
226
234
logger .debug ("ANNOUNCE: %s" , payload .rstrip ())
227
235
self .tx_zmq_pub .send_multipart ([b"ANNOUNCE" , payload .encode ('utf-8' )])
228
236
237
+ def request_clock (self ):
238
+ """Requests UTC Timestamp from the Dash Server
239
+ """
240
+ payload = self ._device_id_str + "\t CLK\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"\t OTA\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"\t OTA\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
+
229
258
def is_control_loaded (self , control_type , control_id : str ) -> bool :
230
259
"""Is the control loaded in the device?"""
231
260
key = f"{ control_type } \t { control_id } "
@@ -344,6 +373,42 @@ def _add_action_device_setup(self, settable: bool):
344
373
pass
345
374
self ._cfg ["deviceSetup" ] = ',' .join (self ._device_setup_list )
346
375
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
+
347
412
def set_wifi_callback (self , callback ):
348
413
"""
349
414
Specify a callback function to be called when IoTDashboard sets wifi parameters.
@@ -541,6 +606,8 @@ def __init__(
541
606
self ._name_rx_callback = None
542
607
self ._tcp_rx_callback = None
543
608
self ._mqtt_rx_callback = None
609
+ self ._clk_rx_callback = None
610
+ self ._ota_rx_callback = None
544
611
self .device_type = device_type .translate (BAD_CHARS )
545
612
self .device_id = device_id .translate (BAD_CHARS )
546
613
self ._b_device_id = self .device_id .encode ('utf-8' )
@@ -551,6 +618,8 @@ def __init__(
551
618
self ._device_commands_dict ['CONNECT' ] = self ._make_connect
552
619
self ._device_commands_dict ['STATUS' ] = self ._make_status
553
620
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
554
623
self .controls_dict = {}
555
624
self ._cfg = {}
556
625
self ._cfg ["deviceSetup" ] = ''
0 commit comments