516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
|
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
|
-
+
|
self.set_syncword(self._last_syncword, submit_queue = None, force = True)
self._apply_packet_format_config(self._last_format_config)
def set_channel(self, channel):
state = self.get_register_bits('radio_state')
state['channel'] = channel
self.put_register_bits('radio_state', state)
self.put_register_bits('radio_state', state, delay = 130)
return state
def set_syncword(self, syncword, force = False, submit_queue = '__DEFAULT__'):
# If queuing is being used, just store this message
if submit_queue is not None and self._should_use_queue():
self._enqueue(submit_queue, syncword, None, None, post_delay = 0)
|
602
603
604
605
606
607
608
609
610
611
612
613
614
615
|
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
|
+
|
with self._get_mutex(lock):
# Set the syncword
if syncword is not None:
self.set_syncword(syncword, submit_queue = None)
# Apply any format changes
radio_format_config = self._apply_packet_format_config(format_config)
self._debug("Radio format_config = {}".format(radio_format_config))
# Determine if the length should be included
if radio_format_config['packet_length_encoded'] == 1:
include_length = True
else:
include_length = False
|
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
|
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
|
+
+
-
+
-
+
|
def multi_transmit(self, message, channels, retries = 3, delay = 0.1, syncword = None, submit_queue = '__DEFAULT__', format_config = None):
if len(channels) == 0 or retries == 0:
self._error("Asked to send the message {} a total of zero times ({} channels, {} retries)".format(message, channels, retries))
# Wait at-least 350 microseconds between frames
min_delay = 350.0 / 1000000.0
retry_delay = delay / retries
post_delay = max(min_delay, retry_delay)
final_delay = max(min_delay, delay - (min_delay * (len(channels) * retries - 1)))
final_delay = delay
for channel_idx in range(len(channels)):
if channel_idx == (len(channels) - 1):
retries -= 1
channel = channels[channel_idx]
for i in range(retries):
if not self.transmit(message, channel, post_delay = min_delay, syncword = syncword, submit_queue = submit_queue):
if not self.transmit(message, channel, post_delay = post_delay, syncword = syncword, submit_queue = submit_queue, format_config = format_config):
return False
if not self.transmit(message, channel, post_delay = final_delay, syncword = syncword, submit_queue = submit_queue, format_config = format_config):
return False
return True
def _enqueue(self, submit_queue, syncword, message, channel, post_delay = 0, format_config = None):
|
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
|
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
|
+
-
-
-
-
+
-
-
+
-
-
-
+
+
+
-
-
-
-
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
|
self._debug("Found {} items to transmit in the {} queue".format(pop_items, submit_queue))
while pop_items != 0:
to_transmit.append(self._software_tx_queue[submit_queue].popleft())
pop_items -= 1
remaining_items += len(self._software_tx_queue[submit_queue])
to_transmit_ordered = {}
default_syncword = None
self._debug("Getting ready to transmit {} items".format(len(to_transmit)))
with self._get_mutex():
for item in to_transmit:
for item in to_transmit:
self._debug("Transmitting item {}".format(item))
syncword = item['syncword']
syncword = item['syncword']
message = item['message']
channel = item['channel']
format_config = item['format_config']
channel = item['channel']
format_config = item['format_config']
message = item['message']
if syncword is not None:
default_syncword = syncword
else:
syncword = default_syncword
if syncword is not None:
default_syncword = syncword
else:
syncword = default_syncword
item['syncword'] = syncword
if message is None or channel is None:
continue
if message is None or channel is None:
continue
key = str([syncword, channel])
if key not in to_transmit_ordered:
to_transmit_ordered[key] = []
to_transmit_ordered[key].append(item)
self._debug("Getting ready to transmit {} items".format(len(to_transmit)))
with self._get_mutex():
for (key, items) in to_transmit_ordered.items():
for item in items:
self._debug("Transmitting item {}".format(item))
syncword = item['syncword']
channel = item['channel']
format_config = item['format_config']
message = item['message']
self.transmit(message, channel, lock = False, submit_queue = None, syncword = syncword, post_delay = 0, format_config = format_config)
self._software_tx_queue_next_time[item['submit_queue']] = time.time() + item['post_delay']
self.transmit(message, channel, lock = False, submit_queue = None, syncword = syncword, post_delay = 0, format_config = format_config)
self._software_tx_queue_next_time[item['submit_queue']] = time.time() + item['post_delay']
return [len(to_transmit), remaining_items]
def start_listening(self, channel):
# Initialize the receiver
self.stop_listening()
|