message_generator_block.py 861 B

1234567891011121314151617181920212223242526
  1. import json
  2. import pathlib
  3. import gnuradio.gr
  4. import numpy
  5. class MessageGeneratorBlock(gnuradio.gr.basic_block):
  6. def __init__(self):
  7. gnuradio.gr.basic_block.__init__(
  8. self, name="Message Generator", in_sig=None, out_sig=[numpy.uint8]
  9. )
  10. # __file__ is not available
  11. self._messages = json.loads(
  12. pathlib.Path().resolve().parent.joinpath("messages.json").read_text()
  13. )
  14. def general_work(self, input_items, output_items) -> int:
  15. # pylint: disable=unused-argument
  16. message = self._messages["ON0"] + [0] * 128
  17. if len(output_items[0]) < len(message):
  18. print("output buffer too short", len(output_items[0]))
  19. output_items[0][:] = 0
  20. return len(output_items[0])
  21. output_items[0][: len(message)] = message
  22. return len(message)