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
def battery(**kwargs): """ Gets current battery voltage """ return client.send_sync( msg_pack("ELM_VOLTAGE", force=True, _converter="battery", **kwargs))
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
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))
def download(cmd, size, dest, **kwargs): """ Low-level function to download files. """ return client.send_sync( msg_pack(cmd, size, dest, _handler="download", **kwargs))
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))
def power(cmd, **kwargs): """ Low-level function to run power command. """ return client.send_sync(msg_pack(cmd, _handler="power", **kwargs), timeout=60)
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))
def sync_time(force=False, **kwargs): """ Synchronize system time with network time. """ return client.send_sync( msg_pack(force=force, _handler="sync_time", **kwargs))
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))
def speak(text, **kwargs): """ Speak given text. Args: text (str): """ return client.send_sync(msg_pack(text, _handler="speak", **kwargs))
def queue(audio_file): """ Queues an audio file. Args: audio_file (str): """ return client.send_sync(msg_pack(audio_file, _handler="queue"))
def volume(value=None): """ Set volumen of the playback. Args: value (int): """ return client.send_sync(msg_pack(value=value, _handler="volume"))
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
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"))
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))
def context(**kwargs): """ Queries context of event reactor. """ return client.send_sync(msg_pack(_handler="context", **kwargs))
def upload(cmd, src, **kwargs): """ Low-level function to upload files. """ return client.send_sync(msg_pack(cmd, src, _handler="upload", **kwargs))
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))
def dump(**kwargs): """ Dumps all messages from OBD bus to screen or file. """ return client.send_sync(msg_pack(_handler="dump", **kwargs))
def status(**kwargs): """ Gets current connection status and more. """ return client.send_sync(msg_pack(_handler="status", **kwargs))
def execute(cmd, **kwargs): """ Executes an AT/ST command. """ return client.send_sync(msg_pack(str(cmd), _handler="execute", **kwargs))
def play(file, **kwargs): """ Plays all messages from file on the OBD bus. """ return client.send_sync(msg_pack(file, _handler="play", **kwargs))
def protocol(**kwargs): """ Configures protocol or lists all supported. """ return client.send_sync(msg_pack(_handler="protocol", **kwargs))
def commands(**kwargs): """ Lists all supported OBD commands found for vehicle. """ return client.send_sync(msg_pack(_handler="commands", **kwargs))
def dtc(clear=False, **kwargs): """ Reads and clears Diagnostics Trouble Codes (DTCs). """ return client.send_sync(msg_pack(clear=clear, _handler="dtc", **kwargs))
def stop(): """ Stops playback of the current audio. """ return client.send_sync(msg_pack(_handler="stop"))
def query(cmd, *args, **kwargs): """ Queries a given SPM command. """ return client.send_sync(msg_pack(cmd, *args, **kwargs))
def send(msg, **kwargs): """ Sends a raw message on bus. """ return client.send_sync(msg_pack(str(msg), _handler="send", **kwargs))
def manage(*args, **kwargs): """ Example: obd.manage worker list * """ return client.send_sync(msg_pack(*args, _workflow="manage", **kwargs))