def exit_gracefully(self, signum, frame): try: Debug.warn('Process killed (%s). Exiting gracefully' % signum) self.finish() sys.exit(0) except Exception as e: Debug.warn(e)
def run(self): try: index = 1 value = None last_update = datetime.now() found = False Debug.head("Car Scanner") Debug.log('ID | Idle RPM | Max RPM | Max Gears') if self.callback is not None: self.callback("Car Scanner") self.callback('ID | Idle RPM | Max RPM | Max Gears') while not self.finished: if last_update is not None: delta = datetime.now() - last_update if delta.seconds >= 30: Debug.notice('New track') found = False last_update = datetime.now() try: data, address = self.sock.recvfrom(512) except socket.timeout: continue except socket.error: break if not data: continue if found: continue stats = struct.unpack('66f', data[0:264]) new_value = "%.14f;%.14f;%d" % \ (stats[Telemetry.IDLE_RPM], stats[Telemetry.MAX_RPM], int(stats[Telemetry.MAX_GEARS])) if new_value != value: value = new_value Debug.log(value, '%d' % index) if self.callback is not None: self.callback('%d;%s' % (index, value)) index += 1 found = True except Exception as e: Debug.warn(e)
def run(self): try: if self.game['db_file'] is None: return app_root = os.path.dirname(os.path.realpath(__file__)) data_path = '/../data/' if getattr(sys, 'frozen', False): data_path = '/data/' conn = sqlite3.connect(app_root + data_path + self.game['db_file']) db = conn.cursor() index = 1 value = None last_update = datetime.now() found = False Debug.head("Track Scanner") Debug.log('ID | Name | Track Length | Z POS | Laps') if self.callback is not None: self.callback("Track Scanner") self.callback('ID | Name | Track Length | Z POS | Laps') while not self.finished: if last_update is not None: delta = datetime.now() - last_update if delta.seconds >= 10: found = False last_update = datetime.now() try: data, address = self.sock.recvfrom(512) except socket.timeout: continue except socket.error: break if not data: print('no data') continue if found: print('found') continue stats = struct.unpack('66f', data[0:264]) new_value = "%.14f;%d;%d" % \ ( stats[Telemetry.TRACK_LENGTH], int(stats[Telemetry.Z_POSITION]), int(stats[Telemetry.TOTAL_LAPS]) ) if new_value != value: value = new_value index += 1 db.execute( 'SELECT id,name FROM Tracks WHERE length = ? AND (start_z = "" OR round(start_z) = ?)', (stats[Telemetry.TRACK_LENGTH], stats[Telemetry.Z_POSITION])) res = db.fetchall() track_name = 'unknown' track_index = -1 if len(res) >= 1: for (index, name) in res: track_index = index track_name = name break Debug.log('%d;%s;%s' % (track_index, track_name, value)) if self.callback is not None: self.callback('%d;%s;%s' % (track_index, track_name, value)) found = True Debug.notice('Scan loop ended') if db is not None: db.close() if conn is not None: conn.close() except sqlite3.Error as e: Debug.err("Database connection error") Debug.err(e) except Exception as e: Debug.warn(e)
def exit_gracefully(signum, frame): Debug.warn('Process killed (%s). Exiting gracefully' % signum) app.stop() sys.exit(0)