Beispiel #1
0
    def update(self):
        upd_list = []  # list of nodes with new laps (node, new_lap_id, lap_timestamp)
        cross_list = []  # list of nodes with crossing-flag changes
        startThreshLowerNode = None
        for index, node in enumerate(self.nodes):
            if node.frequency:
                readtime = monotonic()

                node_data = self.data[index]
                if node_data:
                    data_line = node_data.readline()
                    if data_line == '':
                        node_data.seek(0)
                        data_line = node_data.readline()
                    data_columns = data_line.split(',')
                    lap_id = int(data_columns[1])
                    ms_val = int(data_columns[2])
                    rssi_val = int(data_columns[3])
                    node.node_peak_rssi = int(data_columns[4])
                    node.pass_peak_rssi = int(data_columns[5])
                    node.loop_time = int(data_columns[6])
                    cross_flag = True if data_columns[7]=='T' else False
                    node.pass_nadir_rssi = int(data_columns[8])
                    node.node_nadir_rssi = int(data_columns[9])
                    pn_history = PeakNadirHistory(node.index)
                    pn_history.peakRssi = int(data_columns[10])
                    pn_history.peakFirstTime = int(data_columns[11])
                    pn_history.peakLastTime = int(data_columns[12])
                    pn_history.nadirRssi = int(data_columns[13])
                    pn_history.nadirFirstTime = int(data_columns[14])
                    pn_history.nadirLastTime = int(data_columns[15])
                    if node.is_valid_rssi(rssi_val):
                        node.current_rssi = rssi_val
                        self.process_lap_stats(node, readtime, lap_id, ms_val, cross_flag, pn_history, cross_list, upd_list)
                    else:
                        self.log('RSSI reading ({0}) out of range on Node {1}; rejected'.format(rssi_val, node.index+1))

                # check if node is set to temporary lower EnterAt/ExitAt values
                if node.start_thresh_lower_flag:
                    time_now = monotonic()
                    if time_now >= node.start_thresh_lower_time:
                        # if this is the first one found or has earliest time
                        if startThreshLowerNode == None or node.start_thresh_lower_time < \
                                            startThreshLowerNode.start_thresh_lower_time:
                            startThreshLowerNode = node

        # process any nodes with crossing-flag changes
        self.process_crossings(cross_list)

        # process any nodes with new laps detected
        self.process_updates(upd_list)

        if startThreshLowerNode:
            logger.info("For node {0} restoring EnterAt to {1} and ExitAt to {2}"\
                    .format(startThreshLowerNode.index+1, startThreshLowerNode.enter_at_level, \
                            startThreshLowerNode.exit_at_level))
            self.set_enter_at_level(startThreshLowerNode.index, startThreshLowerNode.enter_at_level)
            self.set_exit_at_level(startThreshLowerNode.index, startThreshLowerNode.exit_at_level)
            startThreshLowerNode.start_thresh_lower_flag = False
            startThreshLowerNode.start_thresh_lower_time = 0
    def update(self):
        upd_list = [
        ]  # list of nodes with new laps (node, new_lap_id, lap_timestamp)
        cross_list = []  # list of nodes with crossing-flag changes
        for index, node in enumerate(self.nodes):
            if node.frequency:
                readtime = monotonic()

                node_data = self.data[index]
                if not node_data:
                    break

                data_line = node_data.readline()
                if data_line == '':
                    node_data.seek(0)
                    data_line = node_data.readline()
                data_columns = data_line.split(',')
                lap_id = int(data_columns[1])
                ms_val = int(data_columns[2])
                rssi_val = int(data_columns[3])
                node.node_peak_rssi = int(data_columns[4])
                node.pass_peak_rssi = int(data_columns[5])
                node.loop_time = int(data_columns[6])
                cross_flag = True if data_columns[7] == 'T' else False
                node.pass_nadir_rssi = int(data_columns[8])
                node.node_nadir_rssi = int(data_columns[9])
                pn_history = PeakNadirHistory(node.index)
                pn_history.peakRssi = int(data_columns[10])
                pn_history.peakFirstTime = int(data_columns[11])
                pn_history.peakLastTime = int(data_columns[12])
                pn_history.nadirRssi = int(data_columns[13])
                pn_history.nadirFirstTime = int(data_columns[14])
                pn_history.nadirLastTime = int(data_columns[15])

                if node.is_valid_rssi(rssi_val):
                    node.current_rssi = rssi_val
                    self.process_lap_stats(node, readtime, lap_id, ms_val,
                                           cross_flag, pn_history, cross_list,
                                           upd_list)
                else:
                    self.log(
                        'RSSI reading ({0}) out of range on Node {1}; rejected'
                        .format(rssi_val, node.index + 1))

        # process any nodes with crossing-flag changes
        self.process_crossings(cross_list)

        # process any nodes with new laps detected
        self.process_updates(upd_list)
Beispiel #3
0
    def update(self):
        upd_list = [
        ]  # list of nodes with new laps (node, new_lap_id, lap_timestamp)
        cross_list = []  # list of nodes with crossing-flag changes
        for node in self.nodes:
            if node.frequency:
                if node.api_valid_flag or node.api_level >= 5:
                    if node.api_level >= 21:
                        data = node.read_block(self, READ_LAP_STATS, 16)
                    elif node.api_level >= 18:
                        data = node.read_block(self, READ_LAP_STATS, 19)
                    elif node.api_level >= 17:
                        data = node.read_block(self, READ_LAP_STATS, 28)
                    elif node.api_level >= 13:
                        data = node.read_block(self, READ_LAP_STATS, 20)
                    else:
                        data = node.read_block(self, READ_LAP_STATS, 18)
                    server_roundtrip = node.io_response - node.io_request
                    server_oneway = server_roundtrip / 2
                    readtime = node.io_response - server_oneway
                else:
                    data = node.read_block(self, READ_LAP_STATS, 17)

                if data != None and len(data) > 0:
                    lap_id = data[0]

                    if node.api_level >= 18:
                        offset_rssi = 3
                        offset_nodePeakRssi = 4
                        offset_passPeakRssi = 5
                        offset_loopTime = 6
                        offset_lapStatsFlags = 8
                        offset_passNadirRssi = 9
                        offset_nodeNadirRssi = 10
                        if node.api_level >= 21:
                            offset_peakRssi = 11
                            offset_peakFirstTime = 12
                            offset_peakLastTime = 14
                            offset_nadirRssi = 11
                            offset_nadirFirstTime = 12
                            offset_nadirLastTime = 14
                        else:
                            offset_peakRssi = 11
                            offset_peakFirstTime = 12
                            offset_peakLastTime = 14
                            offset_nadirRssi = 16
                            offset_nadirFirstTime = 17
                    else:
                        offset_rssi = 5
                        offset_nodePeakRssi = 7
                        offset_passPeakRssi = 9
                        offset_loopTime = 11
                        offset_lapStatsFlags = 15
                        offset_passNadirRssi = 16
                        offset_nodeNadirRssi = 18
                        offset_peakRssi = 20
                        offset_peakTime = 22
                        offset_nadirRssi = 24
                        offset_nadirFirstTime = 26

                    rssi_val = unpack_rssi(node, data[offset_rssi:])
                    if node.is_valid_rssi(rssi_val):
                        node.current_rssi = rssi_val

                        cross_flag = None
                        pn_history = None
                        if node.api_valid_flag:  # if newer API functions supported
                            if node.api_level >= 18:
                                ms_val = unpack_16(data[1:])
                                pn_history = PeakNadirHistory(node.index)
                                if node.api_level >= 21:
                                    if data[offset_lapStatsFlags] & LAPSTATS_FLAG_PEAK:
                                        rssi_val = unpack_rssi(
                                            node, data[offset_peakRssi:])
                                        if node.is_valid_rssi(rssi_val):
                                            pn_history.peakRssi = rssi_val
                                            pn_history.peakFirstTime = unpack_16(
                                                data[offset_peakFirstTime:]
                                            )  # ms *since* the first peak time
                                            pn_history.peakLastTime = unpack_16(
                                                data[offset_peakLastTime:]
                                            )  # ms *since* the last peak time
                                        elif rssi_val > 0:
                                            self.log(
                                                'History peak RSSI reading ({0}) out of range on Node {1}; rejected'
                                                .format(
                                                    rssi_val, node.index + 1))
                                    else:
                                        rssi_val = unpack_rssi(
                                            node, data[offset_nadirRssi:])
                                        if node.is_valid_rssi(rssi_val):
                                            pn_history.nadirRssi = rssi_val
                                            pn_history.nadirFirstTime = unpack_16(
                                                data[offset_nadirFirstTime:])
                                            pn_history.nadirLastTime = unpack_16(
                                                data[offset_nadirLastTime:])
                                        elif rssi_val > 0:
                                            self.log(
                                                'History nadir RSSI reading ({0}) out of range on Node {1}; rejected'
                                                .format(
                                                    rssi_val, node.index + 1))
                                else:
                                    rssi_val = unpack_rssi(
                                        node, data[offset_peakRssi:])
                                    if node.is_valid_rssi(rssi_val):
                                        pn_history.peakRssi = rssi_val
                                        pn_history.peakFirstTime = unpack_16(
                                            data[offset_peakFirstTime:]
                                        )  # ms *since* the first peak time
                                        pn_history.peakLastTime = unpack_16(
                                            data[offset_peakLastTime:]
                                        )  # ms *since* the last peak time
                                    rssi_val = unpack_rssi(
                                        node, data[offset_nadirRssi:])
                                    if node.is_valid_rssi(rssi_val):
                                        pn_history.nadirRssi = rssi_val
                                        pn_history.nadirFirstTime = unpack_16(
                                            data[offset_nadirFirstTime:])
                                        pn_history.nadirLastTime = pn_history.nadirFirstTime
                            else:
                                ms_val = unpack_32(data[1:])

                            rssi_val = unpack_rssi(node,
                                                   data[offset_nodePeakRssi:])
                            if node.is_valid_rssi(rssi_val):
                                node.node_peak_rssi = rssi_val
                            rssi_val = unpack_rssi(node,
                                                   data[offset_passPeakRssi:])
                            if node.is_valid_rssi(rssi_val):
                                node.pass_peak_rssi = rssi_val
                            node.loop_time = unpack_16(data[offset_loopTime:])
                            if data[offset_lapStatsFlags] & LAPSTATS_FLAG_CROSSING:
                                cross_flag = True
                            else:
                                cross_flag = False
                            rssi_val = unpack_rssi(node,
                                                   data[offset_passNadirRssi:])
                            if node.is_valid_rssi(rssi_val):
                                node.pass_nadir_rssi = rssi_val

                            if node.api_level >= 13:
                                rssi_val = unpack_rssi(
                                    node, data[offset_nodeNadirRssi:])
                                if node.is_valid_rssi(rssi_val):
                                    node.node_nadir_rssi = rssi_val

                            if node.api_level >= 18:
                                data_logger = self.data_loggers[node.index]
                                if data_logger:
                                    data_logger.write(
                                        "{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15}\n"
                                        .format(readtime, lap_id, int(ms_val),
                                                node.current_rssi,
                                                node.node_peak_rssi,
                                                node.pass_peak_rssi,
                                                node.loop_time,
                                                'T' if cross_flag else 'F',
                                                node.pass_nadir_rssi,
                                                node.node_nadir_rssi,
                                                pn_history.peakRssi,
                                                pn_history.peakFirstTime,
                                                pn_history.peakLastTime,
                                                pn_history.nadirRssi,
                                                pn_history.nadirFirstTime,
                                                pn_history.nadirLastTime))

                        else:  # if newer API functions not supported
                            ms_val = unpack_32(data[1:])
                            node.pass_peak_rssi = unpack_rssi(node, data[11:])
                            node.loop_time = unpack_32(data[13:])

                        self.process_lap_stats(node, readtime, lap_id, ms_val,
                                               cross_flag, pn_history,
                                               cross_list, upd_list)

                    else:
                        self.log(
                            'RSSI reading ({0}) out of range on Node {1}; rejected'
                            .format(rssi_val, node.index + 1))

        # process any nodes with crossing-flag changes
        self.process_crossings(cross_list)

        # process any nodes with new laps detected
        self.process_updates(upd_list)
Beispiel #4
0
    def update(self):
        upd_list = []  # list of nodes with new laps (node, new_lap_id, lap_timestamp)
        cross_list = []  # list of nodes with crossing-flag changes
        startThreshLowerNode = None
        for node in self.nodes:
            if node.frequency:
                if node.api_valid_flag or node.api_level >= 5:
                    if node.api_level >= 32:
                        data = node.read_block(self, READ_LAP_PASS_STATS, 8)
                        if data != None:
                            data.extend(node.read_block(self, READ_LAP_EXTREMUMS, 8))
                    elif node.api_level >= 21:
                        data = node.read_block(self, READ_LAP_STATS, 16)
                    elif node.api_level >= 18:
                        data = node.read_block(self, READ_LAP_STATS, 19)
                    elif node.api_level >= 17:
                        data = node.read_block(self, READ_LAP_STATS, 28)
                    elif node.api_level >= 13:
                        data = node.read_block(self, READ_LAP_STATS, 20)
                    else:
                        data = node.read_block(self, READ_LAP_STATS, 18)
                    server_roundtrip = node.io_response - node.io_request
                    server_oneway = server_roundtrip / 2
                    readtime = node.io_response - server_oneway
                else:
                    data = node.read_block(self, READ_LAP_STATS, 17)

                if data != None and len(data) > 0:
                    lap_id = data[0]

                    if node.api_level >= 18:
                        offset_rssi = 3
                        offset_nodePeakRssi = 4
                        offset_passPeakRssi = 5
                        offset_loopTime = 6
                        offset_lapStatsFlags = 8
                        offset_passNadirRssi = 9
                        offset_nodeNadirRssi = 10
                        if node.api_level >= 21:
                            offset_peakRssi = 11
                            offset_peakFirstTime = 12
                            if node.api_level >= 33:
                                offset_peakDuration = 14
                            else:
                                offset_peakLastTime = 14
                            offset_nadirRssi = 11
                            offset_nadirFirstTime = 12
                            if node.api_level >= 33:
                                offset_nadirDuration = 14
                            else:
                                offset_nadirLastTime = 14
                        else:
                            offset_peakRssi = 11
                            offset_peakFirstTime = 12
                            offset_peakLastTime = 14
                            offset_nadirRssi = 16
                            offset_nadirFirstTime = 17
                    else:
                        offset_rssi = 5
                        offset_nodePeakRssi = 7
                        offset_passPeakRssi = 9
                        offset_loopTime = 11
                        offset_lapStatsFlags = 15
                        offset_passNadirRssi = 16
                        offset_nodeNadirRssi = 18
                        offset_peakRssi = 20
                        offset_peakFirstTime = 22
                        offset_nadirRssi = 24
                        offset_nadirFirstTime = 26

                    rssi_val = unpack_rssi(node, data[offset_rssi:])
                    node.current_rssi = rssi_val  # save value (even if invalid so displayed in GUI)
                    if node.is_valid_rssi(rssi_val):

                        cross_flag = None
                        pn_history = None
                        if node.api_valid_flag:  # if newer API functions supported
                            if node.api_level >= 18:
                                ms_val = unpack_16(data[1:])
                                pn_history = PeakNadirHistory(node.index)
                                if node.api_level >= 21:
                                    if data[offset_lapStatsFlags] & LAPSTATS_FLAG_PEAK:
                                        rssi_val = unpack_rssi(node, data[offset_peakRssi:])
                                        if node.is_valid_rssi(rssi_val):
                                            pn_history.peakRssi = rssi_val
                                            pn_history.peakFirstTime = unpack_16(data[offset_peakFirstTime:]) # ms *since* the first peak time
                                            if node.api_level >= 33:
                                                pn_history.peakLastTime = pn_history.peakFirstTime - unpack_16(data[offset_peakDuration:])   # ms *since* the last peak time
                                            else:
                                                pn_history.peakLastTime = unpack_16(data[offset_peakLastTime:])   # ms *since* the last peak time
                                        elif rssi_val > 0:
                                            self.log('History peak RSSI reading ({0}) out of range on Node {1}; rejected'.format(rssi_val, node.index+1))
                                    else:
                                        rssi_val = unpack_rssi(node, data[offset_nadirRssi:])
                                        if node.is_valid_rssi(rssi_val):
                                            pn_history.nadirRssi = rssi_val
                                            pn_history.nadirFirstTime = unpack_16(data[offset_nadirFirstTime:])
                                            if node.api_level >= 33:
                                                pn_history.nadirLastTime = pn_history.nadirFirstTime - unpack_16(data[offset_nadirDuration:])
                                            else:
                                                pn_history.nadirLastTime = unpack_16(data[offset_nadirLastTime:])
                                        elif rssi_val > 0:
                                            self.log('History nadir RSSI reading ({0}) out of range on Node {1}; rejected'.format(rssi_val, node.index+1))
                                else:
                                    rssi_val = unpack_rssi(node, data[offset_peakRssi:])
                                    if node.is_valid_rssi(rssi_val):
                                        pn_history.peakRssi = rssi_val
                                        pn_history.peakFirstTime = unpack_16(data[offset_peakFirstTime:]) # ms *since* the first peak time
                                        pn_history.peakLastTime = unpack_16(data[offset_peakLastTime:])   # ms *since* the last peak time
                                    rssi_val = unpack_rssi(node, data[offset_nadirRssi:])
                                    if node.is_valid_rssi(rssi_val):
                                        pn_history.nadirRssi = rssi_val
                                        pn_history.nadirFirstTime = unpack_16(data[offset_nadirFirstTime:])
                                        pn_history.nadirLastTime = pn_history.nadirFirstTime
                            else:
                                ms_val = unpack_32(data[1:])

                            rssi_val = unpack_rssi(node, data[offset_nodePeakRssi:])
                            if node.is_valid_rssi(rssi_val):
                                node.node_peak_rssi = rssi_val
                            rssi_val = unpack_rssi(node, data[offset_passPeakRssi:])
                            if node.is_valid_rssi(rssi_val):
                                node.pass_peak_rssi = rssi_val
                            node.loop_time = unpack_16(data[offset_loopTime:])
                            if data[offset_lapStatsFlags] & LAPSTATS_FLAG_CROSSING:
                                cross_flag = True
                            else:
                                cross_flag = False
                            rssi_val = unpack_rssi(node, data[offset_passNadirRssi:])
                            if node.is_valid_rssi(rssi_val):
                                node.pass_nadir_rssi = rssi_val

                            if node.api_level >= 13:
                                rssi_val = unpack_rssi(node, data[offset_nodeNadirRssi:])
                                if node.is_valid_rssi(rssi_val):
                                    node.node_nadir_rssi = rssi_val

                            if node.api_level >= 18:
                                data_logger = self.data_loggers[node.index]
                                if data_logger:
                                    data_logger.write("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15}\n".format(readtime,lap_id, int(ms_val), node.current_rssi, node.node_peak_rssi, node.pass_peak_rssi, node.loop_time, 'T' if cross_flag else 'F', node.pass_nadir_rssi, node.node_nadir_rssi, pn_history.peakRssi, pn_history.peakFirstTime, pn_history.peakLastTime, pn_history.nadirRssi, pn_history.nadirFirstTime, pn_history.nadirLastTime))

                        else:  # if newer API functions not supported
                            ms_val = unpack_32(data[1:])
                            node.pass_peak_rssi = unpack_rssi(node, data[11:])
                            node.loop_time = unpack_32(data[13:])

                        self.process_lap_stats(node, readtime, lap_id, ms_val, cross_flag, pn_history, cross_list, upd_list)

                    else:
                        node.bad_rssi_count += 1
                        # log the first ten, but then only 1 per 100 after that
                        if node.bad_rssi_count <= 10 or node.bad_rssi_count % 100 == 0:
                            self.log('RSSI reading ({}) out of range on Node {}; rejected; count={}'.\
                                     format(rssi_val, node.index+1, node.bad_rssi_count))

                # check if node is set to temporary lower EnterAt/ExitAt values
                if node.start_thresh_lower_flag:
                    time_now = monotonic()
                    if time_now >= node.start_thresh_lower_time:
                        # if this is the first one found or has earliest time
                        if startThreshLowerNode == None or node.start_thresh_lower_time < \
                                            startThreshLowerNode.start_thresh_lower_time:
                            startThreshLowerNode = node


        # process any nodes with crossing-flag changes
        self.process_crossings(cross_list)

        # process any nodes with new laps detected
        self.process_updates(upd_list)

        if startThreshLowerNode:
            logger.info("For node {0} restoring EnterAt to {1} and ExitAt to {2}"\
                    .format(startThreshLowerNode.index+1, startThreshLowerNode.enter_at_level, \
                            startThreshLowerNode.exit_at_level))
            self.set_enter_at_level(startThreshLowerNode.index, startThreshLowerNode.enter_at_level)
            self.set_exit_at_level(startThreshLowerNode.index, startThreshLowerNode.exit_at_level)
            startThreshLowerNode.start_thresh_lower_flag = False
            startThreshLowerNode.start_thresh_lower_time = 0