Changeset - e6b42cd565a0
[Not reviewed]
default
0 4 0
Kemp - 6 years ago 2018-04-09 13:02:40

Update some Enums to IntEnums to avoid needing to use .value. Fix some default list parameters to match the accepted Pythonic way.
4 files changed with 17 insertions and 13 deletions:
0 comments (0 inline, 0 general)
neovi/can.py
Show inline comments
...
 
@@ -63,7 +63,7 @@ ECU_NAME                       = 0x0A
 
PERFORMANCE_TRACKING_COUNT_C   = 0x0B
 

 

 
class SessionType(enum.Enum):
 
class SessionType(enum.IntEnum):
 
    """
 
    Session types that can be requested with a DIAGNOSTIC_SESSION_CONTROL message.
 
    """
...
 
@@ -73,7 +73,7 @@ class SessionType(enum.Enum):
 
    SafetySystemDiagnostic = 0x04
 

 

 
class ControlType(enum.Enum):
 
class ControlType(enum.IntEnum):
 
    """
 
    Control types that can be used with an ID_CONTROL_BY_ID message.
 
    """
neovi/ecu.py
Show inline comments
...
 
@@ -167,18 +167,20 @@ class ECU:
 

 
        return values
 

 
    def _send_io_control_by_id(self, identifier, value=(0x00, ), control_type=can.ControlType.ShortTermAdjustment):
 
    def _send_io_control_by_id(self, identifier, value=None, control_type=can.ControlType.ShortTermAdjustment):
 
        """
 
        Send a "IO Control By ID" message.
 
        
 
        :param identifier: An array of integers specifying the identifier to read (e.g. [0x98, 0x05]).
 
        :param value: The value to set the output to. Default = [0x00].
 
        :param value: The value to set the output to. A value of None will use the default. Default = [0x00].
 
        :param can.ControlType control_type: The type of control to apply. Default = ControlType.ShortTermAdjustment.
 
        """
 
        if control_type == can.ControlType.ShortTermAdjustment:
 
            return self.interface.tx_message(self.ecu.get_network(), self.ecu.get_request_id(), can.IO_CONTROL_BY_ID, identifier + (control_type.value,) + value)
 
            if value is None:
 
                value = [0x00]
 
            return self.interface.tx_message(self.ecu.get_network(), self.ecu.get_request_id(), can.IO_CONTROL_BY_ID, identifier + [control_type] + value)
 
        else:
 
            return self.interface.tx_message(self.ecu.get_network(), self.ecu.get_request_id(), can.IO_CONTROL_BY_ID, identifier + (control_type.value,))
 
            return self.interface.tx_message(self.ecu.get_network(), self.ecu.get_request_id(), can.IO_CONTROL_BY_ID, identifier + [control_type])
 

 
    def io_control_by_id(self, identifier, value=0x00, control_type=can.ControlType.ShortTermAdjustment):
 
        """
...
 
@@ -210,7 +212,7 @@ class ECU:
 
        
 
        :param can.SessionType session_type: The type of session to switch to.
 
        """
 
        return self.interface.tx_message(self.ecu.get_network(), self.ecu.get_request_id(), can.DIAGNOSTIC_SESSION_CONTROL, [session_type.value])
 
        return self.interface.tx_message(self.ecu.get_network(), self.ecu.get_request_id(), can.DIAGNOSTIC_SESSION_CONTROL, [session_type])
 

 
    def diagnostic_session_control(self, session_type):
 
        """
...
 
@@ -221,10 +223,12 @@ class ECU:
 
        msg = self._transaction(can.DIAGNOSTIC_SESSION_CONTROL, [], self._send_diagnostic_session_control, (session_type,))
 
        return list(msg.Data[3:])
 

 
    def _send_security_access(self, subfunction, key=()):
 
        return self.interface.tx_message(self.ecu.get_network(), self.ecu.get_request_id(), can.SECURITY_ACCESS, (subfunction,) + key)
 
    def _send_security_access(self, subfunction, key):
 
        return self.interface.tx_message(self.ecu.get_network(), self.ecu.get_request_id(), can.SECURITY_ACCESS, [subfunction] + key)
 

 
    def security_access(self, subfunction, key=()):
 
    def security_access(self, subfunction, key=None):
 
        if key is None:
 
            key = []
 
        msg = self._transaction(can.SECURITY_ACCESS, [subfunction], self._send_security_access, (subfunction, key))
 

 
        if subfunction % 2 == 0:
neovi/neodevice.py
Show inline comments
...
 
@@ -276,14 +276,14 @@ class NeoDevice:
 
        if neovi.NETID_HSCAN in network_settings:
 
            settings.can1.Mode = 0
 
            settings.can1.SetBaudrate = 0
 
            settings.can1.Baudrate = network_settings[neovi.NETID_HSCAN]['bitrate'].value
 
            settings.can1.Baudrate = network_settings[neovi.NETID_HSCAN]['bitrate']
 
        else:
 
            settings.can1.Mode = 1
 
        
 
        if neovi.NETID_MSCAN in network_settings:
 
            settings.can2.Mode = 0
 
            settings.can2.SetBaudrate = 0
 
            settings.can2.Baudrate = network_settings[neovi.NETID_MSCAN]['bitrate'].value
 
            settings.can2.Baudrate = network_settings[neovi.NETID_MSCAN]['bitrate']
 
        else:
 
            settings.can2.Mode = 1
 
        
neovi/neovi.py
Show inline comments
...
 
@@ -275,7 +275,7 @@ NETID_LIN6                          = 98
 
NETID_LSFTCAN2                      = 99
 

 

 
class BitRate(enum.Enum):
 
class BitRate(enum.IntEnum):
 
    """
 
    Available bit rates for NeoVI network interfaces.
 
    """
0 comments (0 inline, 0 general)