src/server/server.py
def heartbeat_thread_function():
    '''Allow time for connection handshake to terminate before emitting data'''
    gevent.sleep(0.010)

    '''Emits current rssi data.'''
    while True:
        try:
            global RACE
            node_data = INTERFACE.get_heartbeat_json()

            SOCKET_IO.emit('heartbeat', node_data)
            heartbeat_thread_function.iter_tracker += 1

            # check if race timer is finished
            if RACE.timer_running:
                check_race_time_expired()

            # update displayed IMD rating after freqs changed:
            if heartbeat_thread_function.imdtabler_flag and \
                    (heartbeat_thread_function.iter_tracker % HEARTBEAT_DATA_RATE_FACTOR) == 0:
                heartbeat_thread_function.imdtabler_flag = False
                emit_imdtabler_rating()

            # emit rest of node data, but less often:
            if (heartbeat_thread_function.iter_tracker % (4*HEARTBEAT_DATA_RATE_FACTOR)) == 0:
                emit_node_data()

            # emit cluster status less often:
            if (heartbeat_thread_function.iter_tracker % (4*HEARTBEAT_DATA_RATE_FACTOR)) == (2*HEARTBEAT_DATA_RATE_FACTOR):
                CLUSTER.emitStatus()

            # collect vrx lock status
            if (heartbeat_thread_function.iter_tracker % (10*HEARTBEAT_DATA_RATE_FACTOR)) == 0:
                if vrx_controller:
                    # if vrx_controller.has_connection
                    vrx_controller.get_node_lock_status()
                    vrx_controller.request_variable_status()

            if (heartbeat_thread_function.iter_tracker % (10*HEARTBEAT_DATA_RATE_FACTOR)) == 4:
                # emit display status with offset
                if vrx_controller:
                    emit_vrx_list()

            # emit environment data less often:
            if (heartbeat_thread_function.iter_tracker % (20*HEARTBEAT_DATA_RATE_FACTOR)) == 0:
                INTERFACE.update_environmental_data()
                emit_environmental_data()

            time_now = monotonic()

            # check if race is to be started
            if RACE.scheduled:
                if time_now > RACE.scheduled_time:
                    on_stage_race()
                    RACE.scheduled = False

            # if any comm errors then log them (at defined intervals; faster if debug mode)
            if time_now > heartbeat_thread_function.last_error_rep_time + \
                        (ERROR_REPORT_INTERVAL_SECS if not Config.GENERAL['DEBUG'] \
                        else ERROR_REPORT_INTERVAL_SECS/10):
                heartbeat_thread_function.last_error_rep_time = time_now
                if INTERFACE.get_intf_total_error_count() > 0:
                    logger.info(INTERFACE.get_intf_error_report_str())

            gevent.sleep(0.500/HEARTBEAT_DATA_RATE_FACTOR)

        except KeyboardInterrupt:
            logger.info("Heartbeat thread terminated by keyboard interrupt")
            raise
        except SystemExit:
            raise
        except Exception:
            logger.exception('Exception in Heartbeat thread loop')
            gevent.sleep(0.500)
Allow time for connection handshake to terminate before emitting data
Allow time for connection handshake to terminate before emitting data
Allow time for connection handshake to terminate before emitting data
def heartbeat_thread_function():
    gevent.sleep(0.010)
    while True:
        try:
            global RACE
            node_data = INTERFACE.get_heartbeat_json()
            SOCKET_IO.emit('heartbeat', node_data)
            heartbeat_thread_function.iter_tracker += 1
            if RACE.timer_running:
                check_race_time_expired()
            if heartbeat_thread_function.imdtabler_flag and \
                    (heartbeat_thread_function.iter_tracker % HEARTBEAT_DATA_RATE_FACTOR) == 0:
                heartbeat_thread_function.imdtabler_flag = False
                emit_imdtabler_rating()
            if (heartbeat_thread_function.iter_tracker % (4*HEARTBEAT_DATA_RATE_FACTOR)) == 0:
                emit_node_data()
            if (heartbeat_thread_function.iter_tracker % (4*HEARTBEAT_DATA_RATE_FACTOR)) == (2*HEARTBEAT_DATA_RATE_FACTOR):
                CLUSTER.emitStatus()
            if (heartbeat_thread_function.iter_tracker % (10*HEARTBEAT_DATA_RATE_FACTOR)) == 0:
                if vrx_controller:
                    vrx_controller.get_node_lock_status()
                    vrx_controller.request_variable_status()
            if (heartbeat_thread_function.iter_tracker % (10*HEARTBEAT_DATA_RATE_FACTOR)) == 4:
                if vrx_controller:
                    emit_vrx_list()
            if (heartbeat_thread_function.iter_tracker % (20*HEARTBEAT_DATA_RATE_FACTOR)) == 0:
                INTERFACE.update_environmental_data()
                emit_environmental_data()
            time_now = monotonic()
            if RACE.scheduled:
                if time_now > RACE.scheduled_time:
                    on_stage_race()
                    RACE.scheduled = False
            if time_now > heartbeat_thread_function.last_error_rep_time + \
                        (ERROR_REPORT_INTERVAL_SECS if not Config.GENERAL['DEBUG'] \
                        else ERROR_REPORT_INTERVAL_SECS/10):
                heartbeat_thread_function.last_error_rep_time = time_now
                if INTERFACE.get_intf_total_error_count() > 0:
                    logger.info(INTERFACE.get_intf_error_report_str())
            gevent.sleep(0.500/HEARTBEAT_DATA_RATE_FACTOR)
        except KeyboardInterrupt:
            logger.info("Heartbeat thread terminated by keyboard interrupt")
            raise
        except SystemExit:
            raise
        except Exception:
            logger.exception('Exception in Heartbeat thread loop')
            gevent.sleep(0.500)
def heartbeat_thread_function ( ) : gevent . sleep ( 0.010 ) '''Emits current rssi data.''' while True : try : global RACE node_data = INTERFACE . get_heartbeat_json ( ) SOCKET_IO . emit ( 'heartbeat' , node_data ) heartbeat_thread_function . iter_tracker += 1 if RACE . timer_running : check_race_time_expired ( ) if heartbeat_thread_function . imdtabler_flag and ( heartbeat_thread_function . iter_tracker % HEARTBEAT_DATA_RATE_FACTOR ) == 0 : heartbeat_thread_function . imdtabler_flag = False emit_imdtabler_rating ( ) if ( heartbeat_thread_function . iter_tracker % ( 4 * HEARTBEAT_DATA_RATE_FACTOR ) ) == 0 : emit_node_data ( ) if ( heartbeat_thread_function . iter_tracker % ( 4 * HEARTBEAT_DATA_RATE_FACTOR ) ) == ( 2 * HEARTBEAT_DATA_RATE_FACTOR ) : CLUSTER . emitStatus ( ) if ( heartbeat_thread_function . iter_tracker % ( 10 * HEARTBEAT_DATA_RATE_FACTOR ) ) == 0 : if vrx_controller : vrx_controller . get_node_lock_status ( ) vrx_controller . request_variable_status ( ) if ( heartbeat_thread_function . iter_tracker % ( 10 * HEARTBEAT_DATA_RATE_FACTOR ) ) == 4 : if vrx_controller : emit_vrx_list ( ) if ( heartbeat_thread_function . iter_tracker % ( 20 * HEARTBEAT_DATA_RATE_FACTOR ) ) == 0 : INTERFACE . update_environmental_data ( ) emit_environmental_data ( ) time_now = monotonic ( ) if RACE . scheduled : if time_now > RACE . scheduled_time : on_stage_race ( ) RACE . scheduled = False if time_now > heartbeat_thread_function . last_error_rep_time + ( ERROR_REPORT_INTERVAL_SECS if not Config . GENERAL [ 'DEBUG' ] else ERROR_REPORT_INTERVAL_SECS / 10 ) : heartbeat_thread_function . last_error_rep_time = time_now if INTERFACE . get_intf_total_error_count ( ) > 0 : logger . info ( INTERFACE . get_intf_error_report_str ( ) ) gevent . sleep ( 0.500 / HEARTBEAT_DATA_RATE_FACTOR ) except KeyboardInterrupt : logger . info ( "Heartbeat thread terminated by keyboard interrupt" ) raise except SystemExit : raise except Exception : logger . exception ( 'Exception in Heartbeat thread loop' ) gevent . sleep ( 0.500 )
Allow time for connection handshake to terminate before emitting data
Allow time for connection handshake to terminate before emitting data
'''Allow time for connection handshake to terminate before emitting data''' '''Emits current rssi data.''' # check if race timer is finished # update displayed IMD rating after freqs changed: # emit rest of node data, but less often: # emit cluster status less often: # collect vrx lock status # if vrx_controller.has_connection # emit display status with offset # emit environment data less often: # check if race is to be started # if any comm errors then log them (at defined intervals; faster if debug mode)