import subprocess import os import signal import psutil from log import logname logger = logname() def kill(): logger.info('Checking for another server instances...') child = subprocess.Popen(['pgrep', '-f', "server.py"], stdout=subprocess.PIPE, shell=False) pids = child.communicate()[0].split() for pid in pids: if int(pid) != os.getppid() and int(pid) != os.getpid(): logger.warn("Killing...%s", int(pid)) try: os.kill(int(pid), signal.SIGKILL) except psutil.NoSuchProcess: logger.info('No other server instance...')
''' Created on Oct 18, 2017 @author: marcin ''' import subprocess import asyncio import socket import fcntl import struct from threading import Thread from log import logname logger = logname("signal") class Signal(Thread): def __init__(self): Thread.__init__(self) self.daemon = True self.strength = 0 self.MOVING_AVERAGE_LEN = 40 self.LIST_DEFAULT_VAL = 1 self.dots = self.fillList(self.MOVING_AVERAGE_LEN, self.LIST_DEFAULT_VAL) self.backspaces = self.fillList(self.MOVING_AVERAGE_LEN, self.LIST_DEFAULT_VAL) self.output_hex = hex(0x00) self.prev_output_hex = self.output_hex
#!/usr/bin/python3 import serial import serial.tools.list_ports from log import logname from time import sleep from threading import Thread # from events import Events logger = logname("uart") class Uart(Thread): def __init__(self): Thread.__init__(self) self.daemon = True # self.events = Events() self.BAUD = 115200 self.TIMEOUT = None self.serial = None self.port = "AMA" def run(self): return self.waiter() def send(self, data): logger.debug(''.join(format(x, '02x') for x in data)) self.serial.write(data) def readline(self): try:
import asyncio from aiohttp import web import socketio import hexdump from log import logname from firmware import Shield from system import System from version import version_info logger = logname("sockets") class WSnamespace(socketio.AsyncNamespace): def __init__(self, namespace='/sockets'): super().__init__(namespace) self.sio = None self.shield = Shield() self.system = System() async def on_connect(self, sid, environ): logger.info("connected %s", sid) await self.sio.emit('connected', { 'tcs_ver': version_info, 'firmware_ver': self.shield.getFirmwareVersion(), 'wifi_dongle': self.system.getWirelessAdapterInfo(), 'video_devices': self.system.getCameraInfo() }, namespace="/sockets") async def on_motors(self, sid, payload): self.shield.setMotors(payload)