Esempio n. 1
0
  def parse_serial_interface_header(self, s):
      b = s.read("uint:8")
      if b != 0xC0 : raise ParseError("expected 0xC0, found {0}".format(b))
      version = s.read("uint:8")
      if version != 0: raise ParseError("Expected version 0, found {0}".format(version))
      cmd_len = s.read("uint:8")
      if len(self.buffer) - s.bytepos < cmd_len:
        raise ReadError("ALP command not complete yet, expected {0} bytes, got {1}".format(cmd_len, s.len - s.bytepos))

      return cmd_len
Esempio n. 2
0
    def parse_tag_request_action(self, b7, b6, s):
        if b6:
            raise ParseError("bit 6 is RFU")

        tag_id = s.read("uint:8")
        return TagRequestAction(
            respond_when_completed=b7,
            operation=TagRequest(operand=TagId(tag_id=tag_id)))
Esempio n. 3
0
  def parse_alp_return_status_action(self, b7, b6, s):
    if b7:
      raise ParseError("Status Operand extension 2 and 3 is RFU")

    if b6: # interface status
      interface_id = s.read("uint:8")
      try:
        interface_status_operation = {
          0x00 :  self.parse_alp_interface_status_host,
          0xd7 :  self.parse_alp_interface_status_d7asp,
        }[interface_id](s)
        return StatusAction(operation=interface_status_operation,
                            status_operand_extension=StatusActionOperandExtensions.INTERFACE_STATUS)
      except KeyError:
        raise ParseError("Received ALP Interface status for interface " + str(interface_id) + " which is not implemented")
    else: # action status
      pass # TODO
Esempio n. 4
0
  def parse_forward_action(self, b7, b6, s):
    if b7:
      raise ParseError("bit 7 is RFU")

    interface_id = InterfaceType(int(s.read("uint:8")))
    assert(interface_id == InterfaceType.D7ASP)
    interface_config = Configuration.parse(s)
    return ForwardAction(resp=b6, operation=Forward(operand=InterfaceConfiguration(interface_id=interface_id,
                                                                                   interface_configuration=interface_config)))
Esempio n. 5
0
    def __init__(self,
                 actions=[],
                 generate_tag_request_action=True,
                 tag_id=None,
                 send_tag_response_when_completed=True):
        self.actions = []
        self.interface_status = None
        self.generate_tag_request_action = generate_tag_request_action
        self.tag_id = tag_id
        self.send_tag_response_when_completed = send_tag_response_when_completed
        self.execution_completed = False

        for action in actions:
            if type(
                    action
            ) == StatusAction and action.status_operand_extension == StatusActionOperandExtensions.INTERFACE_STATUS:
                if self.interface_status != None:
                    raise ParseError(
                        "An ALP command can contain one and only one Interface Status action"
                    )
                self.interface_status = action
            elif type(action) == TagRequestAction:
                if self.tag_id != None:
                    raise ParseError(
                        "An ALP command can contain one and only one Tag Request Action"
                    )
                self.tag_id = action.operand.tag_id
                self.send_tag_response_when_completed = action.respond_when_completed
                # we don't add this to self.actions but prepend it on serializing
            elif type(action) == TagResponseAction:
                if self.tag_id != None:
                    raise ParseError(
                        "An ALP command can contain one and only one Tag Response Action"
                    )
                self.tag_id = action.operand.tag_id
                self.completed_with_error = action.error  # TODO distinguish between commands and responses?
                self.execution_completed = action.eop
            else:
                self.actions.append(action)

        if self.generate_tag_request_action and self.tag_id == None:
            self.tag_id = random.randint(0, 255)

        super(Command, self).__init__()
Esempio n. 6
0
 def parse_alp_action(self, s):
   # meaning of first 2 bits depend on action opcode
   b7     = s.read("bool")
   b6      = s.read("bool")
   op        = s.read("uint:6")
   try:
     return{
       1 :   self.parse_alp_read_file_data_action,
       32 :  self.parse_alp_return_file_data_action,
       34 :  self.parse_alp_return_status_action,
       52 :  self.parse_tag_request_action
     }[op](b7, b6, s)
   except KeyError:
     raise ParseError("alp_action " + str(op) + " is not implemented")
Esempio n. 7
0
    def parse_forward_action(self, b7, b6, s):
        if b7:
            raise ParseError("bit 7 is RFU")

        interface_id = InterfaceType(int(s.read("uint:8")))
        interface_config = None
        if (interface_id == InterfaceType.D7ASP):
            interface_config = Configuration.parse(s)
        elif (interface_id == InterfaceType.SERIAL):
            pass  # no interface config
        else:
            assert (False)

        return ForwardAction(resp=b6,
                             operation=Forward(operand=InterfaceConfiguration(
                                 interface_id=interface_id,
                                 interface_configuration=interface_config)))
Esempio n. 8
0
 def parse_alp_action(self, s):
     # meaning of first 2 bits depend on action opcode
     b7 = s.read("bool")
     b6 = s.read("bool")
     op = s.read("uint:6")
     try:
         return {
             1: self.parse_alp_read_file_data_action,
             4: self.parse_alp_write_file_data_action,
             9: self.parse_break_query_action,
             32: self.parse_alp_return_file_data_action,
             33: self.parse_alp_return_file_header_action,
             34: self.parse_alp_return_status_action,
             35: self.parse_tag_response_action,
             50: self.parse_forward_action,
             51: self.parse_indirect_forward_action,
             52: self.parse_tag_request_action
         }[op](b7, b6, s)
     except KeyError:
         raise ParseError("alp_action " + str(op) + " is not implemented")