packet.py 640 B

12345678910111213141516171819202122
  1. import constants
  2. class Packet(object):
  3. """Container for data to be sent to a sign device.
  4. Packet objects are created by other classes and should not usually be
  5. instantiated directly.
  6. """
  7. def __init__(self, contents):
  8. self.type = "Z" # Type Code (see protocol)
  9. self.address = "00" # Sign Address (see protocol)
  10. self._pkt = ("%s%s%s%s%s%s%s" %
  11. (constants.NUL * 5, constants.SOH, self.type,
  12. self.address, constants.STX, contents,
  13. constants.EOT))
  14. def __str__(self):
  15. return self._pkt
  16. def __repr__(self):
  17. return repr(self._pkt)