PMCUFixedAddressParameter.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. from pimonitor.cu.PMCUParameter import PMCUParameter
  2. from pimonitor.cu.PMCUStandardParameter import PMCUStandardParameter
  3. __author__ = 'citan'
  4. class PMCUFixedAddressParameter(PMCUStandardParameter):
  5. def __init__(self, pid, name, desc, target):
  6. PMCUStandardParameter.__init__(self, pid, name, desc, PMCUParameter.CU_INVALID_BYTE_INDEX(),
  7. PMCUParameter.CU_INVALID_BIT_INDEX(), target)
  8. self._cu_type = PMCUParameter.CU_TYPE_FIXED_ADDRESS_PARAMETER()
  9. self._cu_ids = {}
  10. def add_ecu_id(self, cu_id, address):
  11. self._cu_ids[cu_id] = address
  12. def get_address_for_id(self, cu_id):
  13. if cu_id in self._cu_ids:
  14. return self._cu_ids[cu_id]
  15. else:
  16. return None
  17. def switch_to_id(self, cu_id):
  18. self._address = self.get_address_for_id(cu_id)
  19. def set_address(self, address):
  20. raise Exception
  21. def is_supported(self, cu_id):
  22. return self.get_address_for_id(cu_id) is not None
  23. def to_string(self):
  24. return "id=" + self._id + "\nname=" + self._name + "\ndesc=" + self._desc + "\ntarget=" + str(
  25. self._target) + "\nconversion:\n\t" + '%s' % '\n\t'.join(x.to_string() for x in self._conversions) + \
  26. '\necu: ' + ' '.join(['\n\tid={}, {}'.format(k,v.to_string()) for k,v in self._cu_ids.iteritems()])