<commit_before>"""
Low-level function call wrappers for libmbus
"""

from ctypes import c_int, c_long, c_longlong, c_char_p, c_void_p, \
        c_char, c_byte, c_ubyte, c_double, POINTER, cdll, c_size_t, c_uint16
from ctypes.util import find_library

from .MBusAddress import MBusAddress
from .MBusFrame import MBusFrame
from .MBusFrameData import MBusFrameData
from .MBusDataFixed import MBusDataFixed
from .MBusDataVariableHeader import MBusDataVariableHeader
from .MBusDataVariable import MBusDataVariable
from .MBusHandle import MBusHandle
from .MBusRecord import MBusRecord
from .MBusDataRecord import MBusDataRecord, MBusValueInformationBlock

c_char_pp = POINTER(POINTER(c_char))    # http://stackoverflow.com/a/13161052
c_double_p = POINTER(c_double)
c_int_p = POINTER(c_int)
c_long_p = POINTER(c_long)
c_longlong_p = POINTER(c_long)
c_ubyte_p = POINTER(c_ubyte)
c_tm_p = c_void_p

mbus_frame_p = POINTER(MBusFrame)
mbus_handle_p = POINTER(MBusHandle)
mbus_address_p = POINTER(MBusAddress)
mbus_record_p = POINTER(MBusRecord)
mbus_frame_data_p = POINTER(MBusFrameData)
mbus_data_record_p = POINTER(MBusDataRecord)
mbus_data_variable_p = POINTER(MBusDataVariable)
mbus_data_fixed_p = POINTER(MBusDataFixed)
mbus_slave_data_p = c_void_p # TODO
mbus_data_variable_header_p = POINTER(MBusDataVariableHeader)
mbus_value_information_block_p = POINTER(MBusValueInformationBlock)


# Constants used throughout MBUS.  Not all of these will be used by the API,
# but it's easier to haul them all out and stuff them in there than to try and
# curate the list.
#
# The following is generated against libmbus using the following command:
# $ sed -n -e 's/#define[ \t]\+\(MBUS_[A-Z0-0_]\+\)[ \t]\+\([0-9a-fx]\+\)$/\1 = \2/i p' ../libmbus/mbus/*.h
MBUS_PROBE_NOTHING = 0
MBUS_PROBE_SINGLE = 1
MBUS_PROBE_COLLISION = 2
MBUS_FRAME_PURGE_NONE = 0
MBUS_FRAME_DATA_LENGTH = 252
MBUS_HANDLE_TYPE_TCP = 0
MBUS_HANDLE_TYPE_SERIAL = 1
MBUS_RECV_RESULT_OK = 0
MBUS_DIB_DIF_WITHOUT_EXTENSION = 0x7F
MBUS_DIB_DIF_EXTENSION_BIT = 0x80
MBUS_DIB_VIF_WITHOUT_EXTENSION = 0x7F
MBUS_DIB_VIF_EXTENSION_BIT = 0x80
MBUS_DIB_DIF_MANUFACTURER_SPECIFIC = 0x0F
MBUS_DIB_DIF_MORE_RECORDS_FOLLOW = 0x1F
MBUS_DIB_DIF_IDLE_FILLER = 0x2F
MBUS_DATA_VARIABLE_HEADER_LENGTH = 12
MBUS_DATA_FIXED_LENGTH = 16
MBUS_DATA_TYPE_FIXED = 1
MBUS_DATA_TYPE_VARIABLE = 2
MBUS_DATA_TYPE_ERROR = 3
MBUS_FRAME_TYPE_ANY = 0x00
MBUS_FRAME_TYPE_ACK = 0x01
MBUS_FRAME_TYPE_SHORT = 0x02
MBUS_FRAME_TYPE_CONTROL = 0x03
MBUS_FRAME_TYPE_LONG = 0x04
MBUS_FRAME_ACK_BASE_SIZE = 1
MBUS_FRAME_SHORT_BASE_SIZE = 5
MBUS_FRAME_CONTROL_BASE_SIZE = 9
MBUS_FRAME_LONG_BASE_SIZE = 9<commit_msg>MBusLowLevel: Add some missed constants.<commit_after>"""
Low-level function call wrappers for libmbus
"""

from ctypes import c_int, c_long, c_longlong, c_char_p, c_void_p, \
        c_char, c_byte, c_ubyte, c_double, POINTER, cdll, c_size_t, c_uint16
from ctypes.util import find_library

from .MBusAddress import MBusAddress
from .MBusFrame import MBusFrame
from .MBusFrameData import MBusFrameData
from .MBusDataFixed import MBusDataFixed
from .MBusDataVariableHeader import MBusDataVariableHeader
from .MBusDataVariable import MBusDataVariable
from .MBusHandle import MBusHandle
from .MBusRecord import MBusRecord
from .MBusDataRecord import MBusDataRecord, MBusValueInformationBlock

c_char_pp = POINTER(POINTER(c_char))    # http://stackoverflow.com/a/13161052
c_double_p = POINTER(c_double)
c_int_p = POINTER(c_int)
c_long_p = POINTER(c_long)
c_longlong_p = POINTER(c_long)
c_ubyte_p = POINTER(c_ubyte)
c_tm_p = c_void_p

mbus_frame_p = POINTER(MBusFrame)
mbus_handle_p = POINTER(MBusHandle)
mbus_address_p = POINTER(MBusAddress)
mbus_record_p = POINTER(MBusRecord)
mbus_frame_data_p = POINTER(MBusFrameData)
mbus_data_record_p = POINTER(MBusDataRecord)
mbus_data_variable_p = POINTER(MBusDataVariable)
mbus_data_fixed_p = POINTER(MBusDataFixed)
mbus_slave_data_p = c_void_p # TODO
mbus_data_variable_header_p = POINTER(MBusDataVariableHeader)
mbus_value_information_block_p = POINTER(MBusValueInformationBlock)


# Constants used throughout MBUS.  Not all of these will be used by the API,
# but it's easier to haul them all out and stuff them in there than to try and
# curate the list.
#
# The following is generated against libmbus using the following command:
# $ sed -n -e 's/#define[ \t]\+\(MBUS_[A-Z0-0_]\+\)[ \t]\+\(-\?[0-9a-fx]\+\)$/\1 = \2/i p' ../libmbus/mbus/*.h
MBUS_PROBE_NOTHING = 0
MBUS_PROBE_SINGLE = 1
MBUS_PROBE_COLLISION = 2
MBUS_PROBE_ERROR = -1
MBUS_FRAME_PURGE_NONE = 0
MBUS_FRAME_DATA_LENGTH = 252
MBUS_HANDLE_TYPE_TCP = 0
MBUS_HANDLE_TYPE_SERIAL = 1
MBUS_RECV_RESULT_OK = 0
MBUS_RECV_RESULT_ERROR = -1
MBUS_RECV_RESULT_INVALID = -2
MBUS_RECV_RESULT_TIMEOUT = -3
MBUS_RECV_RESULT_RESET = -4
MBUS_DIB_DIF_WITHOUT_EXTENSION = 0x7F
MBUS_DIB_DIF_EXTENSION_BIT = 0x80
MBUS_DIB_VIF_WITHOUT_EXTENSION = 0x7F
MBUS_DIB_VIF_EXTENSION_BIT = 0x80
MBUS_DIB_DIF_MANUFACTURER_SPECIFIC = 0x0F
MBUS_DIB_DIF_MORE_RECORDS_FOLLOW = 0x1F
MBUS_DIB_DIF_IDLE_FILLER = 0x2F
MBUS_DATA_VARIABLE_HEADER_LENGTH = 12
MBUS_DATA_FIXED_LENGTH = 16
MBUS_DATA_TYPE_FIXED = 1
MBUS_DATA_TYPE_VARIABLE = 2
MBUS_DATA_TYPE_ERROR = 3
MBUS_FRAME_TYPE_ANY = 0x00
MBUS_FRAME_TYPE_ACK = 0x01
MBUS_FRAME_TYPE_SHORT = 0x02
MBUS_FRAME_TYPE_CONTROL = 0x03
MBUS_FRAME_TYPE_LONG = 0x04
MBUS_FRAME_ACK_BASE_SIZE = 1
MBUS_FRAME_SHORT_BASE_SIZE = 5
MBUS_FRAME_CONTROL_BASE_SIZE = 9
MBUS_FRAME_LONG_BASE_SIZE = 9
{'fraction_non_alphanumeric': 0.07076866223207687, 'fraction_numerical': 0.026053215077605323, 'mean_word_length': 6.755014326647564, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '470770', 'n_tokens_mistral': 2335, 'n_tokens_neox': 2222, 'n_words': 439}