def __init__(self, log_file_name=None): self.gps = serial.Serial(os.environ["GPS_PORT"], os.environ["GPS_BAUDRATE"]) if log_file_name is None: self.logging = get_logger("GPS_LOG_FILE") else: self.logging = get_logger(log_file_name, log_file_name)
def __init__(self, log_file_name=None, server_url=None): if log_file_name is None: self.logging = get_logger("WEB_CLIENT_LOG_FILE") else: self.logging = get_logger(log_file_name, log_file_name) if server_url is None: self.url = self.get_server_url_from_env() else: self.url = server_url
def __init__(self, log_file_name=None, port=None): if log_file_name is None: self.logging = get_logger("TRANSMITTER_LOG_FILE") else: self.logging = get_logger(log_file_name, log_file_name) self.port = os.environ[ "RADIO_TRANSMITTER_PORT"] if port is None else port if not self.port: self.port_vid = None self.port_pid = None self.port_vendor = None self.port_intf = None self.port_serial_number = None self.find_port() else: port_info = next( (p for p in serial.tools.list_ports.comports() if p.device == self.port), {}, ) self.port_vid = port_info.vid if hasattr(port_info, "vid") else None self.port_pid = port_info.pid if hasattr(port_info, "pid") else None self.port_vendor = (port_info.manufacturer if hasattr( port_info, "manufacturer") else None) self.port_intf = (port_info.interface if hasattr( port_info, "interface") else None) self.port_serial_number = (port_info.serial_number if hasattr( port_info, "serial_number") else None) self.find_port() baudrate = os.environ["TRANSCEIVER_BAUDRATE"] parity = serial.PARITY_NONE stopbits = serial.STOPBITS_ONE bytesize = serial.EIGHTBITS timeout = int(os.environ["TRANSCEIVER_TIMEOUT"]) self.logging.info("Opening serial on: " + str(self.port)) try: self.serial = serial.Serial( port=self.port, baudrate=baudrate, parity=parity, stopbits=stopbits, bytesize=bytesize, timeout=timeout, ) except Exception as err: self.logging.error("error occurred: {}".format(str(err))) raise
def __init__(self, *args, **kwargs): if os.environ.get("ENABLE_RADIO_TRANSMISSION"): self.transceiver = Transceiver() if os.environ.get("ENABLE_INTERNET_TRANSMISSION"): apiUrl = os.environ.get("REMOTE_SERVER_API_ENDPOINT") self.web_client = WebClient(server_url=apiUrl) self.logging = get_logger("COMM_PI_LOG_FILE") super().__init__(*args, **kwargs)
def __init__(self, log_file_name=None, port=None): if log_file_name is None: self.logging = get_logger("TRANSMITTER_LOG_FILE") else: self.logging = get_logger(log_file_name, log_file_name) self.port = os.environ[ "RADIO_TRANSMITTER_PORT"] if port is None else port if not self.port: self.port_vid = None self.port_pid = None self.port_vendor = None self.port_intf = None self.port_serial_number = None self.find_port() else: port_info = next( (p for p in serial.tools.list_ports.comports() if p.device == self.port), {}, ) self.port_vid = port_info.vid self.port_pid = port_info.pid self.port_vendor = port_info.manufacturer self.port_intf = port_info.interface self.port_serial_number = port_info.serial_number self.find_port() baudrate = os.environ["TRANSCEIVER_BAUDRATE"] parity = serial.PARITY_NONE stopbits = serial.STOPBITS_ONE bytesize = serial.EIGHTBITS timeout = os.environ["TRANSCEIVER_TIMEOUT"] self.logging.info("Opening serial on: " + str(self.port)) self.serial = serial.Serial( port=self.port, baudrate=baudrate, parity=parity, stopbits=stopbits, bytesize=bytesize, timeout=timeout, )
def runServer(server_class=HTTPServer, handler_class=Server, log_file_name=None, port=None): log = (get_logger("LAN_SERVER_LOG_FILE") if log_file_name is None else get_logger(log_file_name)) port = int(os.environ["LAN_PORT"]) if port is None else port server_address = ("", port) httpd = server_class(server_address, handler_class) log.info("Starting server on port: " + str(port)) try: httpd.serve_forever() except KeyboardInterrupt: pass httpd.server_close() log.info("Stopping\n")
def __init__(self, log_file_name=None, sensor_ids=None): nyu_purple = (87, 46, 140) self.sense = SenseHat() self.sense.show_message("MERCURY", text_colour=nyu_purple, scroll_speed=0.04) self.sense.clear() if log_file_name is None: self.logging = get_logger("SENSE_HAT_LOG_FILE") else: self.logging = get_logger(log_file_name, log_file_name) if sensor_ids is None: self.sensor_ids = {} self.sensor_ids[sensor_keys["TEMPERATURE"]] = 1 self.sensor_ids[sensor_keys["PRESSURE"]] = 2 self.sensor_ids[sensor_keys["HUMIDITY"]] = 3 self.sensor_ids[sensor_keys["ACCELERATION"]] = 4 self.sensor_ids[sensor_keys["ORIENTATION"]] = 5 else: self.sensor_ids = sensor_ids
def test_get_logger(self): with TempDirectory() as temp_dir: with mock.patch.dict(os.environ, { "LOG_DIRECTORY": temp_dir.path, "LOGGER": "logger.txt" }): logger = get_logger("LOGGER") self.assertTrue(logger.name == "LOGGER") self.assertTrue(logger.format == "%(asctime)s | %(levelname)s | %(message)s") self.assertTrue(logger.level == INFO) self.assertIsInstance(logger, Logger)
def main(): """The main program.""" parser = argparse.ArgumentParser( prog="find-port.py", usage="%(prog)s [options] [command]", description="Find the /dev/tty port for a USB Serial devices", ) parser.add_argument( "-l", "--list", dest="list", action="store_true", help="List USB Serial devices currently connected", ) parser.add_argument( "-s", "--serial", dest="serial", help="Only show devices with the indicated serial number", default=None, ) parser.add_argument( "-n", "--vendor", dest="vendor", help="Only show devices with the indicated vendor name", default=None, ) parser.add_argument( "--pid", dest="pid", action="store", help="Only show device with indicated PID", default=None, ) parser.add_argument( "-v", "--verbose", dest="verbose", action="store_true", help="Turn on verbose messages", default=False, ) parser.add_argument( "--vid", dest="vid", action="store", help="Only show device with indicated VID", default=None, ) parser.add_argument( "-i", "--intf", dest="intf", action="store", help="Shows devices which conatin the indicated interface string", default=None, ) args = parser.parse_args(sys.argv[1:]) logger = get_logger("PORT_LOGGER", file_name="PORT_LOG_FILE") if args.verbose: logger.info("pyserial version = {}".format(serial.__version__)) logger.info(f" vid = {args.vid}") logger.info(f" pid = {args.pid}") logger.info(f"serial = {args.serial}") logger.info(f"vendor = {args.vendor}") if args.list: detected = False for port in serial.tools.list_ports.comports(): if is_usb_serial(port, args): logger.info( "USB Serial Device {:04x}:{:04x}{} found @{}\r".format( port.vid, port.pid, extra_info(port), port.device)) detected = True if not detected: logger.warn("No USB Serial devices detected.\r") return for port in serial.tools.list_ports.comports(): if is_usb_serial(port, args): logger.info(port) logger.info(port.device) return sys.exit(1)
def __init__(self, *args, **kwargs): self.log = get_logger("LAN_SERVER_LOG_FILE") super().__init__(*args, **kwargs)