<commit_before>import logging
import i2cMock
import time
from Queue import Queue, Empty
from threading import Lock
from utils import *

class TransmitterDevice(i2cMock.I2CDevice):
    MAX_CONTENT_SIZE = 235
    BUFFER_SIZE = 40

    def __init__(self):
        super(TransmitterDevice, self).__init__(0x62)
        self.log = logging.getLogger("Comm Transmitter")
        self.on_watchdog_reset = None
        self.on_hardware_reset = None
        self.on_reset = None
        self.on_send_frame = None
        self._buffer = Queue(TransmitterDevice.BUFFER_SIZE)
    
    @i2cMock.command([0xAA])
    def _reset(self):
        self.log.info("Reset")
        call(self.on_reset, None)
        reset()

    @i2cMock.command([0xAB])
    def _hwreset(self):
        self.log.info("Hardware Reset")
        call(self.on_hardware_reset, None)

    @i2cMock.command([0xCC])
    def _watchdog_reset(self):
        self.log.info("Watchdog Reset")
        call(self.on_watchdog_reset, None)

    @i2cMock.command([0x10])
    def _send_frame(self, *data):
        self.log.info("Send frame %s", data)

        call(self.on_send_frame, None, self, data)
        self._buffer.put_nowait(data)
        return [TransmitterDevice.BUFFER_SIZE - self._buffer.qsize()]

    def get_message_from_buffer(self, timeout=None):
        return self._buffer.get(timeout=timeout)

    def reset(self):
        self._buffer = Queue(TransmitterDevice.BUFFER_SIZE)

class ReceiverDevice(i2cMock.I2CDevice):
    def __init__(self):
        super(ReceiverDevice, self).__init__(0x60)
        self.log = logging.getLogger("Comm Receiver")
        self.on_watchdog_reset = None
        self.on_hardware_reset = None
        self.on_reset = None
        self.on_frame_remove = None
        self.on_frame_receive = None
        self._buffer = Queue()
        self._lock = Lock()

    @i2cMock.command([0xAA])
    def _reset(self):
        self.log.info("Reset")
        call(self.on_reset, None)
        reset()

    @i2cMock.command([0xAB])
    def _hwreset(self):
        self.log.info("Hardware reset")
        call(self.on_hardware_reset, None)

    @i2cMock.command([0xCC])
    def _watchdog_reset(self):
        self.log.info("Watchdog Reset")
        call(self.on_watchdog_reset, None)

    @i2cMock.command([0x21])
    def _get_number_of_frames(self):
        with self._lock:
            size = self._buffer.qsize();
            return [size & 0xff, size / 256]

    @i2cMock.command([0x22])
    def _receive_frame(self):
        if call(self.on_frame_receive, True, self):
            with self._lock:
                if self._buffer.empty():
                    return []

                frame = self._buffer.queue[0]
                return ReceiverDevice.build_frame_response(frame, 257, 300)
        else:
            return []
<commit_msg>[comm] Update comm python simulator.<commit_after>import logging
import i2cMock
import time
from Queue import Queue, Empty
from threading import Lock
from utils import *

class TransmitterDevice(i2cMock.I2CDevice):
    MAX_CONTENT_SIZE = 235
    BUFFER_SIZE = 40

    def __init__(self):
        super(TransmitterDevice, self).__init__(0x62)
        self.log = logging.getLogger("Comm Transmitter")
        self.on_watchdog_reset = None
        self.on_hardware_reset = None
        self.on_reset = None
        self.on_send_frame = None
        self._buffer = Queue(TransmitterDevice.BUFFER_SIZE)
        self._lock = Lock()
    
    @i2cMock.command([0xAA])
    def _reset(self):
        self.log.info("Reset")
        call(self.on_reset, None)
        self.reset()

    @i2cMock.command([0xAB])
    def _hwreset(self):
        self.log.info("Hardware Reset")
        call(self.on_hardware_reset, None)

    @i2cMock.command([0xCC])
    def _watchdog_reset(self):
        self.log.info("Watchdog Reset")
        call(self.on_watchdog_reset, None)

    @i2cMock.command([0x10])
    def _send_frame(self, *data):
        self.log.info("Send frame %s", data)

        call(self.on_send_frame, None, self, data)
        with self._lock:
            self._buffer.put_nowait(data)
            return [TransmitterDevice.BUFFER_SIZE - self._buffer.qsize()]

    def get_message_from_buffer(self, timeout=None):
        return self._buffer.get(timeout=timeout)

    def reset(self):
        with self._lock:
            self._buffer = Queue(TransmitterDevice.BUFFER_SIZE)

class ReceiverDevice(i2cMock.I2CDevice):
    def __init__(self):
        super(ReceiverDevice, self).__init__(0x60)
        self.log = logging.getLogger("Comm Receiver")
        self.on_watchdog_reset = None
        self.on_hardware_reset = None
        self.on_reset = None
        self.on_frame_remove = None
        self.on_frame_receive = None
        self._buffer = Queue()
        self._lock = Lock()

    @i2cMock.command([0xAA])
    def _reset(self):
        self.log.info("Reset")
        call(self.on_reset, None)
        self.reset()

    @i2cMock.command([0xAB])
    def _hwreset(self):
        self.log.info("Hardware reset")
        call(self.on_hardware_reset, None)

    @i2cMock.command([0xCC])
    def _watchdog_reset(self):
        self.log.info("Watchdog Reset")
        call(self.on_watchdog_reset, None)

    @i2cMock.command([0x21])
    def _get_number_of_frames(self):
        with self._lock:
            size = self._buffer.qsize();
            return [size & 0xff, size / 256]

    @i2cMock.command([0x22])
    def _receive_frame(self):
        if call(self.on_frame_receive, True, self):
            with self._lock:
                if self._buffer.empty():
                    return []

                frame = self._buffer.queue[0]
                return ReceiverDevice.build_frame_response(frame, 257, 300)
        else:
            return []

{'fraction_non_alphanumeric': 0.10991491578399028, 'fraction_numerical': 0.01771140823059559, 'mean_word_length': 2.4657039711191335, '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': '5374966', 'n_tokens_mistral': 1950, 'n_tokens_neox': 1859, 'n_words': 336}