示例#1
0
def xyz_logger(enabled=None):
    """
    Enable/disable accelerometer data logger.
    """

    WORKER_NAME = "xyz_logger"

    if enabled == None:
        res = client.send_sync(
            msg_pack("worker", "query", WORKER_NAME, _workflow="admin"))

        res["status"] = "running" if len(res.pop("result")) else "stopped"
    elif enabled:
        res = client.send_sync(
            msg_pack(mma8x5x.OUT_X_MSB,
                     6,
                     _workflow="simple",
                     _worker="infinite?name={:s}".format(WORKER_NAME),
                     _handler="interrupt_read",
                     _converter="g_block",
                     _returner="redis"))

        res["status"] = res.pop("notif", {}).get("status", "unknown")
    else:
        res = client.send_sync(
            msg_pack("worker", "kill", WORKER_NAME, _workflow="admin"))

        res["status"] = "stopped" if res.pop("result") else "unknown"

    return res
示例#2
0
def battery(**kwargs):
    """
    Gets current battery voltage
    """

    return client.send_sync(
        msg_pack("ELM_VOLTAGE", force=True, _converter="battery", **kwargs))
示例#3
0
def flash_firmware(hex_file, confirm=False, check_only=True, timeout=90):
    """
    Flash 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,
                                        no_write=False,
                                        _handler="flash_firmware"),
                               timeout=timeout)
        ret["output"] = res.get("output", None)

    return ret
示例#4
0
def _read_write(register, mask, value, **kwargs):
    """
    Low-level command to update a value within a specified register.
    """

    return client.send_sync(
        msg_pack(register, mask, value, _handler="read_write", **kwargs))
示例#5
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))
示例#6
0
def _write(register, value, **kwargs):
    """
    Low-level command to write a value to a specified register.
    """

    return client.send_sync(
        msg_pack(register, value, _handler="write", **kwargs))
示例#7
0
def power(cmd, **kwargs):
    """
    Low-level function to run power command.
    """

    return client.send_sync(msg_pack(cmd, _handler="power", **kwargs),
                            timeout=60)
示例#8
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))
示例#9
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))
示例#10
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))
示例#11
0
def speak(text, **kwargs):
    """
    Speak given text.

    Args:
        text (str): 
    """

    return client.send_sync(msg_pack(text, _handler="speak", **kwargs))
示例#12
0
def queue(audio_file):
    """
    Queues an audio file.

    Args:
        audio_file (str): 
    """

    return client.send_sync(msg_pack(audio_file, _handler="queue"))
示例#13
0
def volume(value=None):
    """
    Set volumen of the playback.

    Args: 
        value (int): 
    """

    return client.send_sync(msg_pack(value=value, _handler="volume"))
示例#14
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
示例#15
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"))
示例#16
0
def query(cmd,
          mode=None,
          pid=None,
          bytes=None,
          decoder=None,
          force=None,
          **kwargs):
    """
    Queries a given OBD command.
    """

    return client.send_sync(
        msg_pack(cmd,
                 mode=mode,
                 pid=pid,
                 bytes=bytes,
                 decoder=decoder,
                 force=force,
                 **kwargs))
示例#17
0
def context(**kwargs):
    """
    Queries context of event reactor.
    """

    return client.send_sync(msg_pack(_handler="context", **kwargs))
示例#18
0
def upload(cmd, src, **kwargs):
    """
    Low-level function to upload files.
    """

    return client.send_sync(msg_pack(cmd, src, _handler="upload", **kwargs))
示例#19
0
def _read(register, length=1, **kwargs):
    """
    Low-level command to read value of register or a range of registers.
    """

    return client.send_sync(msg_pack(register, length, **kwargs))
示例#20
0
def dump(**kwargs):
    """
    Dumps all messages from OBD bus to screen or file.
    """

    return client.send_sync(msg_pack(_handler="dump", **kwargs))
示例#21
0
def status(**kwargs):
    """
    Gets current connection status and more.
    """

    return client.send_sync(msg_pack(_handler="status", **kwargs))
示例#22
0
def execute(cmd, **kwargs):
    """
    Executes an AT/ST command.
    """

    return client.send_sync(msg_pack(str(cmd), _handler="execute", **kwargs))
示例#23
0
def play(file, **kwargs):
    """
    Plays all messages from file on the OBD bus.
    """

    return client.send_sync(msg_pack(file, _handler="play", **kwargs))
示例#24
0
def protocol(**kwargs):
    """
    Configures protocol or lists all supported.
    """

    return client.send_sync(msg_pack(_handler="protocol", **kwargs))
示例#25
0
def commands(**kwargs):
    """
    Lists all supported OBD commands found for vehicle.
    """

    return client.send_sync(msg_pack(_handler="commands", **kwargs))
示例#26
0
def dtc(clear=False, **kwargs):
    """
    Reads and clears Diagnostics Trouble Codes (DTCs).
    """

    return client.send_sync(msg_pack(clear=clear, _handler="dtc", **kwargs))
示例#27
0
def stop():
    """
    Stops playback of the current audio.
    """

    return client.send_sync(msg_pack(_handler="stop"))
示例#28
0
def query(cmd, *args, **kwargs):
    """
    Queries a given SPM command.
    """

    return client.send_sync(msg_pack(cmd, *args, **kwargs))
示例#29
0
def send(msg, **kwargs):
    """
    Sends a raw message on bus.
    """

    return client.send_sync(msg_pack(str(msg), _handler="send", **kwargs))
示例#30
0
def manage(*args, **kwargs):
    """
    Example: obd.manage worker list *
    """

    return client.send_sync(msg_pack(*args, _workflow="manage", **kwargs))