<commit_before>__author__ = '<NAME>'

import logging
import Queue
import threading
import time
import zmq


class NetScannerResultWrapper(object):
    """
    A wrapper around a list of NetScanner results
    """

    # psi to kPa conversion
    psi_to_kpa = 6.89475729

    def __init__(self, results=None):
        self.channels = [x * self.psi_to_kpa for x in results]

    def channel(self, channel_id):
        """
        Returns a single channel from the results, or -1 if the channel number is invalid

        :param channel_id: The channel number to get the pressure value for
        :returns: A single float value, indicating the channel pressure reading in kPa
        """
        if channel_id < 0 or channel_id > len(self.channels):
            return -1
        return self.channels[channel_id]

    def results(self):
        """
        Returns all of the results from this NetScanner dataset

        :returns: A list of float values indicating kPa pressures
        """
        return self.channels


class NetScannerManager(object):
    """
    A class which handles decoding and interpretation of TCP messages received
    from a NetScanner 9116 or 8IFC device.
    """

    # a list of error codes from section 3.1.3, page 22 of the manual
    error_codes = {
        '00': 'Unused',
        '01': 'Undefined command received',
        '02': 'Unused by TCP/IP',
        '03': 'Input buffer overrun',
        '04': 'Invalid ASCII character received',
        '05': 'Data field error',
        '06': 'Unused by TCP/IP',
        '07': 'Specified limits invalid',
        '08': 'NetScanner error; invalid parameter',
        '09': 'Insufficient source air to shift calibration value',
        '0A': 'Calibration value not in requested position',
    }

    # message codes sent to/from the device
    response_codes = {
        'A': 'ACK',
        'N': 'NAK'
    }

    # commands that can be sent to the unit
    commands = {
        'A': 'Power up clear',
        'B': 'Reset',
        'C': 'Configure/Control multi-point calibration',
        'V': 'Read transducer voltages',
        'Z': 'Calculate and set gains',
        'a': 'Read transducer raw A/D counts',
        'b': 'Read high speed data',
        'h': 'Calculate and set offsets',
        'm': 'Read temperature A/D counts',
        'n': 'Read temperature voltages',
        'q': 'Read module status',
        'r': 'Read high precision data',
        't': 'Read transducer temperatures',
        'u': 'Read internal coefficients',
        'v': 'Download internal coefficients',
        'w': 'Set/Do operating commands'
    }

    SERVER_ENDPOINT = "tcp://%s:%s"

    REQUEST_TIMEOUT = 5

    logger = logging.getLogger(__name__)

    READ_DATA = 'r'

    def __init__(self, host, port=7000):
        """
        Initialises a NetScannerManager which connects a TCP/IP connection to the device<commit_msg>Fix default TCP port<commit_after>__author__ = '<NAME>'

import logging
import Queue
import threading
import time
import zmq


class NetScannerResultWrapper(object):
    """
    A wrapper around a list of NetScanner results
    """

    # psi to kPa conversion
    psi_to_kpa = 6.89475729

    def __init__(self, results=None):
        self.channels = [x * self.psi_to_kpa for x in results]

    def channel(self, channel_id):
        """
        Returns a single channel from the results, or -1 if the channel number is invalid

        :param channel_id: The channel number to get the pressure value for
        :returns: A single float value, indicating the channel pressure reading in kPa
        """
        if channel_id < 0 or channel_id > len(self.channels):
            return -1
        return self.channels[channel_id]

    def results(self):
        """
        Returns all of the results from this NetScanner dataset

        :returns: A list of float values indicating kPa pressures
        """
        return self.channels


class NetScannerManager(object):
    """
    A class which handles decoding and interpretation of TCP messages received
    from a NetScanner 9116 or 8IFC device.
    """

    # a list of error codes from section 3.1.3, page 22 of the manual
    error_codes = {
        '00': 'Unused',
        '01': 'Undefined command received',
        '02': 'Unused by TCP/IP',
        '03': 'Input buffer overrun',
        '04': 'Invalid ASCII character received',
        '05': 'Data field error',
        '06': 'Unused by TCP/IP',
        '07': 'Specified limits invalid',
        '08': 'NetScanner error; invalid parameter',
        '09': 'Insufficient source air to shift calibration value',
        '0A': 'Calibration value not in requested position',
    }

    # message codes sent to/from the device
    response_codes = {
        'A': 'ACK',
        'N': 'NAK'
    }

    # commands that can be sent to the unit
    commands = {
        'A': 'Power up clear',
        'B': 'Reset',
        'C': 'Configure/Control multi-point calibration',
        'V': 'Read transducer voltages',
        'Z': 'Calculate and set gains',
        'a': 'Read transducer raw A/D counts',
        'b': 'Read high speed data',
        'h': 'Calculate and set offsets',
        'm': 'Read temperature A/D counts',
        'n': 'Read temperature voltages',
        'q': 'Read module status',
        'r': 'Read high precision data',
        't': 'Read transducer temperatures',
        'u': 'Read internal coefficients',
        'v': 'Download internal coefficients',
        'w': 'Set/Do operating commands'
    }

    SERVER_ENDPOINT = "tcp://%s:%s"

    REQUEST_TIMEOUT = 5

    logger = logging.getLogger(__name__)

    READ_DATA = 'r'

    def __init__(self, host, port=9000):
        """
        Initialises a NetScannerManager which connects a TCP/IP connection to the device
{'fraction_non_alphanumeric': 0.10482615464452517, 'fraction_numerical': 0.01660612350804359, 'mean_word_length': 2.397179788484136, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1549036', 'n_tokens_mistral': 1724, 'n_tokens_neox': 1585, 'n_words': 618}