def __init__(self):
     """
     Abstraction of the HW layer.
     """
     self._signature = MappedBuffer(fields=(
         {
             "first_byte": "B"
         },
         {
             "second_byte": "B"
         },
     ))
     self._signature.first_byte = ord(self._SIGNATURE[0])
     self._signature.second_byte = ord(self._SIGNATURE[1])
     self._header = MappedBuffer(fields=(
         {
             "message_len": "B"
         },
         {
             "message_id": "B"
         },
     ))
     self._payload = []
     self._checksum = MappedBuffer(fields=({"checksum": "B"}, ))
     self._deadline = None
 def encode(self, data):
     """
     Generates the byte sequence for a USB keyboard command.
     """
     # pylint: disable=exec-used
     # pylint: disable=unused-argument
     buf = MappedBuffer(fields=(
         {
             "byte_0": "B"
         },
         {
             "byte_1": "B"
         },
         {
             "byte_2": "B"
         },
         {
             "byte_3": "B"
         },
         {
             "byte_4": "B"
         },
         {
             "byte_5": "B"
         },
         {
             "byte_6": "B"
         },
         {
             "byte_7": "B"
         },
     ))
     for index in range(0, 8):
         exec("buf.byte_" + str(index) + " = data['buffer'][" + str(index) +
              "]")
     state = CMD_NEW_KEYBOARD_DATA
     return self.pack(command_id=state, data=buf.pack())