Пример #1
0
def flash_firmware(hex_file,
                   part_id,
                   confirm=False,
                   check_only=True,
                   timeout=90):
    """
    Flashes new SPM firmware to ATtiny.
    """

    ret = {}

    if not confirm:
        raise salt.exceptions.CommandExecutionError(
            "This command will flash firmware release '{:s}' onto the ATtiny - add parameter 'confirm=true' to continue anyway"
            .format(hex_file))

    # TODO: It is only possible to test flash an already installed version without getting verification errors from avrdude!
    # Test flash firmware in read-only mode
    #res = client.send_sync(_msg_pack(hex_file, no_write=True, _handler="flash_firmware"), timeout=timeout)
    #ret["output"] = res.get("output", None)

    # Flash firmware
    if not check_only:
        res = client.send_sync(_msg_pack(hex_file,
                                         part_id,
                                         no_write=False,
                                         _handler="flash_firmware"),
                               timeout=timeout)
        ret["output"] = res.get("output", None)

    return ret
Пример #2
0
def query(cmd,
          mode=None,
          pid=None,
          bytes=None,
          decoder=None,
          force=None,
          **kwargs):
    """
    Queries a given OBD command.

    To see supported OBD commands for your vehicle run: obd.commands

    Examples:
        obd.query RPM
        obd.query SPEED
        obd.query FUEL_LEVEL force=True
        obd.query custom_intake_temp_raw mode=01 pid=0F 
        obd.query custom_intake_temp     mode=01 pid=0F decoder=temp
    """

    return client.send_sync(
        _msg_pack(cmd,
                  mode=mode,
                  pid=pid,
                  bytes=bytes,
                  decoder=decoder,
                  force=force,
                  **kwargs))
Пример #3
0
def manage(*args, **kwargs):
    """
    Runtime management of the underlying service instance.

    Supported commands:
      - 'hook list|call <name> [argument]... [<key>=<value>]...'
      - 'worker list|show|start|pause|resume|kill <name>'
      - 'reactor list|show <name>'
      - 'run <key>=<value>...'

    Examples:
      - 'obd.manage hook list'
      - 'obd.manage hook call execute_handler ATRV'
      - 'obd.manage worker list *'
      - 'obd.manage worker show *'
      - 'obd.manage worker start *'
      - 'obd.manage worker pause *'
      - 'obd.manage worker resume *'
      - 'obd.manage worker kill *'
      - 'obd.manage reactor list'
      - 'obd.manage reactor show *'
      - 'obd.manage run handler="query" args="[\"ELM_VOLTAGE\"]" converter="battery" returner="cloud"'
    """

    return client.send_sync(_msg_pack(*args, _workflow="manage", **kwargs))
Пример #4
0
def send(msg, **kwargs):
    """
    Sends a message on bus.

    Arguments:
      - msg (str): Message to send.

    Optional arguments, general:
      - header (str): Identifer of message to send. If none is specifed the default header will be used.
      - auto_format (bool): Apply automatic formatting of messages? Default value is 'False'.
      - expect_response (bool): Wait for response after sending? Avoid waiting for timeout by specifying the exact the number of frames expected. Default value is 'False'.
      - raw_response (bool): Get raw response without any validation nor parsing? Default value is 'False'.
      - echo (bool): Include the request message in the response? Default value is 'False'.
      - protocol (str): ID of specific protocol to be used to receive the data. If none is specifed the current protocol will be used.
      - baudrate (int): Specific protocol baudrate to be used. If none is specifed the current baudrate will be used.
      - verify (bool): Verify that OBD-II communication is possible with the desired protocol? Default value is 'False'.
      - output (str): What data type should the output be returned in? Default is a 'list'.
      - type (str): Specify a name of the type of the result. Default is 'raw'.

    Optional arguments, CAN specific:
      - can_extended_address (str): Use CAN extended address.
      - can_flow_control_clear (bool): Clear all CAN flow control filters and ID pairs before adding any new ones.
      - can_flow_control_filter (str): Ensure CAN flow control filter is added. Value must consist of '<pattern>,<mask>'.
      - can_flow_control_id_pair (str): Ensure CAN flow control ID pair is added. Value must consist of '<transmitter ID>,<receiver ID>'.
    """

    return client.send_sync(_msg_pack(str(msg), _handler="send", **kwargs))
Пример #5
0
def manage(*args, **kwargs):
    """
    Runtime management of the underlying service instance.

    Supported commands:
      - 'hook list|call <name> [argument]... [<key>=<value>]...'
      - 'worker list|show|start|pause|resume|kill <name>'
      - 'reactor list|show <name>'
      - 'run <key>=<value>...'

    Examples:
      - 'cloud.manage hook list'
      - 'cloud.manage hook call status_handler'
      - 'cloud.manage worker list *'
      - 'cloud.manage worker show *'
      - 'cloud.manage worker start *'
      - 'cloud.manage worker pause *'
      - 'cloud.manage worker resume *'
      - 'cloud.manage worker kill *'
      - 'cloud.manage reactor list'
      - 'cloud.manage reactor show *'
      - 'cloud.manage run handler="cache" args="[\"list_queues\"]"'
    """

    return client.send_sync(_msg_pack(*args, _workflow="manage", **kwargs))
Пример #6
0
def play(file, **kwargs):
    """
    Plays all messages from a file on the bus.

    Arguments:
      - file (str): Path to file recorded with the 'obd.dump' command.

    Optional arguments:
      - delay (float): Delay in seconds between sending each message. Default value is '0'.
      - slice (str): Slice the list of messages before sending on the CAN bus. Based one the divide and conquer algorithm. Multiple slice characters can be specified in continuation of each other.
        - 't': Top half of remaining result.
        - 'b': Bottom half of remaining result.
      - filter (str): Filter out messages before sending on the CAN bus. Multiple filters can be specified if separated using comma characters.
        - '+[id][#][data]': Include only messages matching string.
        - '-[id][#][data]': Exclude messages matching string.
        - '+duplicate': Include only messages where duplicates exist.
        - '-duplicate': Exclude messages where duplicates exist.
        - '+mutate': Include only messages where data mutates.
        - '-mutate': Exclude messages where data mutates.
      - group (str): How to group the result of sent messages. This only affects the display values returned from this command. Default value is 'id'.
        - 'id': Group by message ID only.
        - 'msg': Group by entire message string.
      - protocol (str): ID of specific protocol to be used to send the data. If none is specifed the current protocol will be used.
      - baudrate (int): Specific protocol baudrate to be used. If none is specifed the current baudrate will be used.
      - verify (bool): Verify that OBD-II communication is possible with the desired protocol? Default value is 'False'.
      - test (bool): Run command in test-only? (dry-run) mode. No data will be sent on CAN bus. Default value is 'False'.
    """

    return client.send_sync(_msg_pack(file, _handler="play", **kwargs))
Пример #7
0
def query(cmd, mode=None, pid=None, bytes=None, decoder=None, force=None, **kwargs):
    """
    Queries a given OBD command. To see supported OBD commands for your vehicle run: 'obd.commands'

    Arguments:
      - name (str): Name of the command.

    Optional arguments:
      - mode (str): Service section of the PID.
      - pid (str): Code section of the PID.
      - header (str): Identifer of message to send. If none is specifed the default OBD header will be used.
      - bytes (int): Default value is '0'.
      - decoder (str): Specific decoder to be used to process the response.
      - formula (str): Formula written in Python to convert the response.
      - unit (str): Unit of the result.
      - protocol (str): ID of specific protocol to be used to receive the data. If none is specifed the current protocol will be used.
      - baudrate (int): Specific protocol baudrate to be used. If none is specifed the current baudrate will be used.
      - verify (bool): Verify that OBD-II communication is possible with the desired protocol? Default value is 'False'.
      - force (bool): Force query of unknown command. Default is 'False'.

    Examples:
      - 'obd.query RPM'
      - 'obd.query SPEED'
      - 'obd.query FUEL_LEVEL force=True'
      - 'obd.query custom_intake_temp_raw mode=01 pid=0F'
      - 'obd.query custom_intake_temp mode=01 pid=0F decoder=temp'
    """

    return client.send_sync(_msg_pack(cmd, mode=mode, pid=pid, bytes=bytes, decoder=decoder, force=force, **kwargs))
Пример #8
0
def power(cmd, **kwargs):
    """
    Low-level function to run power command.
    """

    return client.send_sync(_msg_pack(cmd, _handler="power", **kwargs),
                            timeout=60)
Пример #9
0
def download(cmd, size, dest, **kwargs):
    """
    Low-level function to download files.
    """

    return client.send_sync(
        _msg_pack(cmd, size, dest, _handler="download", **kwargs))
Пример #10
0
def sync_time(force=False, **kwargs):
    """
    Synchronize system time with network time.
    """

    return client.send_sync(
        _msg_pack(force=force, _handler="sync_time", **kwargs))
Пример #11
0
def query(cmd, cooldown_delay=None, **kwargs):
    """
    Low-level function to execute AT commands.
    """

    return client.send_sync(
        _msg_pack(cmd, cooldown_delay=cooldown_delay, **kwargs))
Пример #12
0
def manage(*args, **kwargs):
    """
    Runtime management of the underlying service instance.

    Supported commands:
      - 'hook list|call <name> [argument]... [<key>=<value>]...'
      - 'worker list|show|start|pause|resume|kill <name>'
      - 'reactor list|show <name>'
      - 'run <key>=<value>...'

    Examples:
      - 'tracking.manage hook list'
      - 'tracking.manage hook call gnss_query_handler location'
      - 'tracking.manage worker list *'
      - 'tracking.manage worker show *'
      - 'tracking.manage worker start *'
      - 'tracking.manage worker pause *'
      - 'tracking.manage worker resume *'
      - 'tracking.manage worker kill *'
      - 'tracking.manage reactor list'
      - 'tracking.manage reactor show *'
      - 'tracking.manage run handler="gnss_query" args="[\"location\"]" converter="gnss_location_to_position" returner="cloud"'
    """

    return client.send_sync(_msg_pack(*args, _workflow="manage", **kwargs))
Пример #13
0
def manage(*args, **kwargs):
    """
    Examples:
      - 'spm.manage handler'        Lists all available handlers.
      - 'spm.manage worker list *'  Lists all existing worker threads.
    """

    return client.send_sync(_msg_pack(*args, _workflow="manage", **kwargs))
Пример #14
0
def cache(cmd, *args, **kwargs):
    """
    Queries/calls a given cache function.
    """

    kwargs["_handler"] = "cache"

    return client.send_sync(_msg_pack(cmd, *args, **kwargs))
Пример #15
0
def queue(audio_file):
    """
    Queues an audio file.

    Args:
        audio_file (str): 
    """

    return client.send_sync(_msg_pack(audio_file, _handler="queue"))
Пример #16
0
def volume(value=None):
    """
    Set volumen of the playback.

    Optional arguments:
      - value (int):
    """

    return client.send_sync(_msg_pack(value=value, _handler="volume"))
Пример #17
0
def queue(audio_file):
    """
    Queues an audio file.

    Arguments:
      - audio_file (str): Local path of audio file to play.
    """

    return client.send_sync(_msg_pack(audio_file, _handler="queue"))
Пример #18
0
def speak(text, **kwargs):
    """
    Speak given text.

    Args:
        text (str): 
    """

    return client.send_sync(_msg_pack(text, _handler="speak", **kwargs))
Пример #19
0
def query(cmd, *args, **kwargs):
    """
    Queries a given SPM command.

    Arguments:
      - cmd (str): The SPM command to query.
    """

    return client.send_sync(_msg_pack(cmd, *args, **kwargs))
Пример #20
0
def action(*args, **kwargs):
    """
    Performs a key fob button action.

    Arguments:
      - *name (str): Name(s) of the action(s) to perform.
    """

    return client.send_sync(_msg_pack(*args, _handler="action", **kwargs))
Пример #21
0
def power(**kwargs):
    """
    Powers on/off key fob.

    Optional arguments:
      - value (bool): Power on or off. 
    """

    return client.send_sync(_msg_pack(_handler="power", **kwargs))
Пример #22
0
def speak(text, **kwargs):
    """
    Speak given text.

    Arguments:
      - text (str): Text to speak out.
    """

    return client.send_sync(_msg_pack(text, _handler="speak", **kwargs))
Пример #23
0
def led_pwm(**kwargs):
    """
    Change PWM frequency and/or duty cycle for LED.

    Optional arguments:
      - frequency (float): Change to frequency in Hz.
      - duty_cycle (float): Change to duty cycle in percent.
    """

    return client.send_sync(_msg_pack(_handler="led_pwm", **kwargs))
Пример #24
0
def battery(**kwargs):
    """
    Gets current battery voltage
    """

    return client.send_sync(
        _msg_pack("ELM_VOLTAGE",
                  protocol=None,
                  force=True,
                  _converter="battery",
                  **kwargs))
Пример #25
0
def _execute(cmd, **kwargs):
    """
    Private helper function to execute commands.
    """

    res = client.send_sync(_msg_pack(cmd, _handler="execute", **kwargs))

    if not "value" in res and not "values" in res:
        raise salt.exceptions.CommandExecutionError(
            "Execution of command '{:s}' returned no value(s)".format(cmd))

    return res
Пример #26
0
def play(audio_file, force=False, loops=0, volume=None):
    """
    Plays a specific audio file. 

    Args:
        audio_file (str): 
        force (bool): 
        loops (int): 
        volume (int): 
    """

    return client.send_sync(_msg_pack(audio_file, force=force, loops=loops, volume=volume, _handler="play"))
Пример #27
0
def setup(**kwargs):
    """
    Setup advanced runtime settings.

    Optional arguments:
      - can_extended_address (str): Use CAN extended address.
      - can_flow_control_clear (bool): Clear all CAN flow control filters and ID pairs before adding any new ones.
      - can_flow_control_filter (str): Ensure CAN flow control filter is added. Value must consist of '<pattern>,<mask>'.
      - can_flow_control_id_pair (str): Ensure CAN flow control ID pair is added. Value must consist of '<transmitter ID>,<receiver ID>'.
    """

    return client.send_sync(_msg_pack(_handler="setup", **kwargs))
Пример #28
0
def connection(**kwargs):
    """
    Manages current connection.

    Optional arguments:
      - close (bool): Close MMA8X5X connection? Default value is 'False'. 

    Examples:
      - 'acc.connection'
      - 'acc.connection close=True'
    """

    return client.send_sync(_msg_pack(_handler="connection", **kwargs))
Пример #29
0
def dump(**kwargs):
    """
    Dumps all messages from bus to screen or file.

    Optional arguments:
      - duration (int): How many seconds to record data? Default value is '2' seconds.
      - file (str): Write data to a file with the given name.
      - description (str): Additional description to the file.
      - protocol (str): ID of specific protocol to be used to receive the data. If none is specifed the current protocol will be used.
      - baudrate (int): Specific protocol baudrate to be used. If none is specifed the current baudrate will be used.
      - verify (bool): Verify that OBD-II communication is possible with the desired protocol? Default value is 'False'.
    """

    return client.send_sync(_msg_pack(_handler="dump", **kwargs))
Пример #30
0
def filter(action, **kwargs):
    """
    Manages filters used when monitoring.

    Arguments:
      - action (str): Action to perform. Available actions are 'list', 'add' and 'clear'.

    Examples:
      - 'obd.filter list'
      - 'obd.filter add type=<pass|block|flow> pattern=7C8 mask=7FF'
      - 'obd.filter clear [type=<pass|block|flow>]'
    """

    return client.send_sync(_msg_pack(action, _handler="filter", **kwargs))