Exemplo n.º 1
0
 def stop(self):
     if self.ardui_dash is not None:
         self.ardui_dash.stop()
     self.clear_ui()
     if self.m_connected:
         Debug.notice('Closing UDP socket')
         self.m_parser.close_socket()
Exemplo n.º 2
0
 def start(self):
     if self.m_connected:
         return
     if self.arduino_auto_start is True:
         self.ardui_dash.start(self.arduino_com_port,
                               self.arduino_baud_rate)
     Debug.notice('Start UDP socket')
     self.m_parser.open_socket()
Exemplo n.º 3
0
 def game_changed(self, action):
     game = action.data()
     if game:
         Debug.notice('Game changed: %s' % game['name'])
         self.m_game = game
         if self.m_connected:
             self.stop()
         self.m_parser.game = game
         self.clear_ui()
Exemplo n.º 4
0
 def fill_games_menu(self):
     games_menu = self.m_window.menu_settings.addMenu('&Game')
     games_group = QtWidgets.QActionGroup(games_menu)
     for game in Games():
         act = QtWidgets.QAction(game['name'], games_group)
         act.setCheckable(True)
         act.setData(game)
         games_menu.addAction(act)
         if game == self.m_game:
             Debug.notice('Current game: %s' % self.m_game['name'])
             act.setChecked(True)
     games_group.triggered.connect(self.game_changed)
     games_group.setExclusive(True)
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
 def update_connection_status(self, status):
     self.m_connected = status
     self.m_window.centralWidget().setEnabled(self.m_connected)
     self.m_window.speed_view.setEnabled(self.m_connected)
     self.m_window.gear_view.setEnabled(self.m_connected)
     if self.m_connected:
         Debug.notice("Socket opened")
         self.m_window.menu_action_connect.setText("Dis&connect")
         self.m_window.action_Connect.setIconText("Dis&connect")
         self.m_window.action_Connect.setToolTip("Disconnect")
         self.m_window.action_Connect.setIcon(
             QtGui.QIcon.fromTheme("offline"))
         self.m_window.statusbar\
             .showMessage("Listening for data on %s:%d " % (self.m_parser.UDP_IP, self.m_parser.UDP_PORT))
         self.ardui_dash.setup(2)
         self.ardui_dash.change_mode(1)
     else:
         Debug.notice("Socket closed")
         self.m_window.menu_action_connect.setText("&Connect")
         self.m_window.action_Connect.setIconText("&Connect")
         self.m_window.action_Connect.setToolTip("Connect")
         self.m_window.action_Connect.setIcon(
             QtGui.QIcon.fromTheme("online"))
         self.m_window.statusbar.clearMessage()
Exemplo n.º 7
0
    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)
Exemplo n.º 8
0
 def finish(self):
     self.finished = True
     Debug.notice('Stopping track scanner')
     if self.sock is not None:
         self.sock.close()
Exemplo n.º 9
0
 def on_close(self):
     Debug.notice('Main window closed')
     self.stop()
Exemplo n.º 10
0
argument_parser.set_defaults(gui=True)
argument_parser.add_argument(
    '--log_level',
    '-V',
    type=int,
    default=LogLevel.warn,
    help='Set debug verbosity from 0 (only errors) to 2 (full output)',
    choices=range(0, 3))
flags = argument_parser.parse_args()
if flags.debug:
    DEBUG = True
if flags.log_level is not None:
    Debug.set_log_level(LogLevel(flags.log_level))
if flags.gui is not None:
    if flags.gui is False:
        Debug.notice('No gui')
        DEBUG = True
        Debug.set_log_level(LogLevel(2))
    GUI = flags.gui

Debug.toggle(DEBUG)


# noinspection PyUnusedLocal
def exit_gracefully(signum, frame):
    Debug.warn('Process killed (%s). Exiting gracefully' % signum)
    app.stop()
    sys.exit(0)


class MainApp(MainWindow.Listener):