<commit_before>"""
@package mi.instrument.um.thsph.thsph.driver
@file marine-integrations/mi/instrument/um/thsph/thsph/driver.py
@author <NAME>
@brief Driver for the thsph
Release notes:

Vent Chemistry Instrument  Driver


"""
__author__ = '<NAME>'
__license__ = 'Apache 2.0'

import time
import re
import string

from mi.core.driver_scheduler import DriverSchedulerConfigKey, TriggerType
from mi.core.exceptions import SampleException, InstrumentProtocolException, InstrumentParameterException, \
    InstrumentTimeoutException
from mi.core.instrument.driver_dict import DriverDictKey
from mi.core.instrument.protocol_param_dict import ParameterDictType

from mi.core.log import get_logger;

log = get_logger()

from mi.core.common import BaseEnum, InstErrorCode, Units
from mi.core.instrument.instrument_protocol import CommandResponseInstrumentProtocol
from mi.core.instrument.instrument_fsm import InstrumentFSM
from mi.core.instrument.instrument_driver import SingleConnectionInstrumentDriver, DriverConfigKey
from mi.core.instrument.instrument_driver import DriverEvent
from mi.core.instrument.instrument_driver import DriverAsyncEvent
from mi.core.instrument.instrument_driver import DriverProtocolState
from mi.core.instrument.instrument_driver import DriverParameter
from mi.core.instrument.instrument_driver import ResourceAgentState
from mi.core.instrument.data_particle import DataParticle
from mi.core.instrument.data_particle import DataParticleKey
from mi.core.instrument.data_particle import CommonDataParticleType
from mi.core.instrument.chunker import StringChunker

###
#    Driver Constant Definitions
###

# newline.
NEWLINE = '\r\n'

# default timeout.
TIMEOUT = 10

# Maximum number of communication test to wake up the instrument
MAX_COMM_TEST = 2

# Time wait for the instrument response
CMD_RESP_TIME = .1

#The timeout to wake the device
WAKEUP_TIMEOUT = 3

# The time to look for response to a wake up attempt
RESPONSE_TIMEOUT = 1


class ScheduledJob(BaseEnum):
    AUTO_SAMPLE = 'auto_sample'


class DataParticleType(BaseEnum):
    """
    Data particle types produced by this driver
    """
    RAW = CommonDataParticleType.RAW
    THSPH_PARSED = 'thsph_sample'


class Command(BaseEnum):
    """
    Instrument command strings
    """
    GET_SAMPLE = 'aH*'  # Gets data sample from ADC
    COMM_TEST = 'aP*'  # Communication test, returns aP#


class ProtocolState(BaseEnum):
    """
    Instrument protocol states
    """
    UNKNOWN = DriverProtocolState.UNKNOWN
    COMMAND = DriverProtocolState.COMMAND
    AUTOSAMPLE = DriverProtocolState.AUTOSAMPLE
    DIRECT_ACCESS = DriverProtocolState.DIRECT_ACCESS


class ProtocolEvent(BaseEnum):
    """
    Protocol events
    """
    ENTER = DriverEvent.ENTER
    EXIT = DriverEvent.EXIT
    DISCOVER = DriverEvent.DISCOVER
    START_DIRECT = DriverEvent.START_DIRECT
    STOP_DIRECT = DriverEvent.STOP_DIRECT
    EXECUTE_DIRECT = DriverEvent.EXECUTE_DIRECT
    ACQUIRE_SAMPLE = DriverEvent.ACQUIRE_SAMPLE
    START_AUTOSAMPLE = DriverEvent.START_AUTOSAMPLE
    STOP_AUTOSAMPLE = DriverEvent.STOP_AUTOSAMPLE
    GET = DriverEvent.GET
    SET = DriverEvent.SET


class Capability(BaseEnum):
    """
    Protocol events that should be exposed to users (subset of above).
    """
    ACQUIRE_SAMPLE = ProtocolEvent.ACQUIRE_SAMPLE
    START_AUTOSAMPLE = ProtocolEvent.START_AUTOSAMPLE
    STOP_AUTOSAMPLE = ProtocolEvent.STOP_AUTOSAMPLE
    GET = ProtocolEvent.GET
    SET = ProtocolEvent.SET


class Parameter(DriverParameter):
    """
    Device specific parameters for THSPH.
    """
    INTERVAL = 'SampleInterval'


class Prompt(BaseEnum):
    """
    Device i/o prompts for THSPH
    """
    COMM_RESPONSE = 'aP#'


###############################################################################
# Data Particles
###############################################################################
class THSPHDataParticleKey(BaseEnum):
    HIGH_IMPEDANCE_ELECTRODE_1 = "hie1"  # High Impedance Electrode 1 for pH
    HIGH_IMPEDANCE_ELECTRODE_2 = "hie2"  # High Impedance Electrode 2 for pH
    H2_ELECTRODE = "h2electrode"  # H2 electrode
    S2_ELECTRODE = "s2electrode"  # Sulfide Electrode
    THERMOCOUPLE1 = "thermocouple1"  # Type E thermocouple 1-high
    THERMOCOUPLE2 = "thermocouple2"  # Type E thermocouple 2-low
    REFERENCE_THERMISTOR = "rthermistor"  # Reference Thermistor
    BOARD_THERMISTOR = "bthermistor"  # Board Thermistor


class THSPHParticle(DataParticle):
    """<commit_msg>Fixed Code Review Comments<commit_after>"""
@package mi.instrument.um.thsph.thsph.driver
@file marine-integrations/mi/instrument/um/thsph/thsph/driver.py
@author <NAME>
@brief Driver for the thsph
Release notes:

Vent Chemistry Instrument  Driver


"""
__author__ = '<NAME>'
__license__ = 'Apache 2.0'

import time
import re
import string

from mi.core.driver_scheduler import DriverSchedulerConfigKey, TriggerType
from mi.core.exceptions import SampleException, InstrumentProtocolException, InstrumentParameterException, \
    InstrumentTimeoutException
from mi.core.instrument.driver_dict import DriverDictKey
from mi.core.instrument.protocol_param_dict import ParameterDictType

from mi.core.log import get_logger;

log = get_logger()

from mi.core.common import BaseEnum, InstErrorCode, Units
from mi.core.instrument.instrument_protocol import CommandResponseInstrumentProtocol
from mi.core.instrument.instrument_fsm import InstrumentFSM
from mi.core.instrument.instrument_driver import SingleConnectionInstrumentDriver, DriverConfigKey
from mi.core.instrument.instrument_driver import DriverEvent
from mi.core.instrument.instrument_driver import DriverAsyncEvent
from mi.core.instrument.instrument_driver import DriverProtocolState
from mi.core.instrument.instrument_driver import DriverParameter
from mi.core.instrument.instrument_driver import ResourceAgentState
from mi.core.instrument.data_particle import DataParticle
from mi.core.instrument.data_particle import DataParticleKey
from mi.core.instrument.data_particle import CommonDataParticleType
from mi.core.instrument.chunker import StringChunker

###
#    Driver Constant Definitions
###

# newline.
NEWLINE = '\r\n'

# default timeout.
TIMEOUT = 10

# Maximum number of communication test to wake up the instrument
MAX_COMM_TEST = 2

# Time wait for the instrument response
CMD_RESP_TIME = .1

#The timeout to wake the device
WAKEUP_TIMEOUT = 3

# The time to look for response to a wake up attempt
RESPONSE_TIMEOUT = 1


class ScheduledJob(BaseEnum):
    AUTO_SAMPLE = 'auto_sample'


class DataParticleType(BaseEnum):
    """
    Data particle types produced by this driver
    """
    RAW = CommonDataParticleType.RAW
    THSPH_PARSED = 'thsph_sample'


class Command(BaseEnum):
    """
    Instrument command strings
    """
    GET_SAMPLE = 'aH*'  # Gets data sample from ADC
    COMM_TEST = 'aP*'  # Communication test, returns aP#


class ProtocolState(BaseEnum):
    """
    Instrument protocol states
    """
    UNKNOWN = DriverProtocolState.UNKNOWN
    COMMAND = DriverProtocolState.COMMAND
    AUTOSAMPLE = DriverProtocolState.AUTOSAMPLE
    DIRECT_ACCESS = DriverProtocolState.DIRECT_ACCESS


class ProtocolEvent(BaseEnum):
    """
    Protocol events
    """
    ENTER = DriverEvent.ENTER
    EXIT = DriverEvent.EXIT
    DISCOVER = DriverEvent.DISCOVER
    START_DIRECT = DriverEvent.START_DIRECT
    STOP_DIRECT = DriverEvent.STOP_DIRECT
    EXECUTE_DIRECT = DriverEvent.EXECUTE_DIRECT
    ACQUIRE_SAMPLE = DriverEvent.ACQUIRE_SAMPLE
    START_AUTOSAMPLE = DriverEvent.START_AUTOSAMPLE
    STOP_AUTOSAMPLE = DriverEvent.STOP_AUTOSAMPLE
    GET = DriverEvent.GET
    SET = DriverEvent.SET


class Capability(BaseEnum):
    """
    Protocol events that should be exposed to users (subset of above).
    """
    ACQUIRE_SAMPLE = ProtocolEvent.ACQUIRE_SAMPLE
    START_AUTOSAMPLE = ProtocolEvent.START_AUTOSAMPLE
    STOP_AUTOSAMPLE = ProtocolEvent.STOP_AUTOSAMPLE
    GET = ProtocolEvent.GET
    SET = ProtocolEvent.SET


class Parameter(DriverParameter):
    """
    Device specific parameters for THSPH.
    """
    INTERVAL = 'SampleInterval'


class Prompt(BaseEnum):
    """
    Device i/o prompts for THSPH
    """
    COMM_RESPONSE = 'aP#'


###############################################################################
# Data Particles
###############################################################################
class THSPHDataParticleKey(BaseEnum):
    HIGH_IMPEDANCE_ELECTRODE_1 = "thsph_hie1"  # High Impedance Electrode 1 for pH
    HIGH_IMPEDANCE_ELECTRODE_2 = "thsph_hie2"  # High Impedance Electrode 2 for pH
    H2_ELECTRODE = "thsph_h2electrode"  # H2 electrode
    S2_ELECTRODE = "thsph_s2electrode"  # Sulfide Electrode
    THERMOCOUPLE1 = "thsph_thermocouple1"  # Type E thermocouple 1-high
    THERMOCOUPLE2 = "thsph_thermocouple2"  # Type E thermocouple 2-low
    REFERENCE_THERMISTOR = "thsph_rthermistor"  # Reference Thermistor
    BOARD_THERMISTOR = "thsph_bthermistor"  # Board Thermistor


class THSPHParticle(DataParticle):
    """
{'fraction_non_alphanumeric': 0.10326869806094183, 'fraction_numerical': 0.00554016620498615, 'mean_word_length': 4.741730279898219, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6332002', 'n_tokens_mistral': 2880, 'n_tokens_neox': 2705, 'n_words': 655}