<commit_before>import outbound
from observer import Observer

raw_observer_map = {x: Observer() for x in range(1, outbound.NUM_CMDS + 1)}
observer_map = {x: Observer() for x in range(1, outbound.NUM_CMDS + 1)}


def register_map(cmd, func):
    raw_observer_map[cmd].subscribe(lambda msg: observer_map[cmd].notify(*func(msg)))


def read_messages(bus):
    while True:
        msg = bus.try_receive()
        if msg is None:
            return

        packet_id = msg[0]
        if packet_id in raw_observer_map:
            raw_observer_map[packet_id].notify(msg)
        else:
            print('Unknown packet id: ' + packet_id)


def subscribe_to_cmd(cmd, func):
    if cmd in observer_map:
        observer_map[cmd].subscribe(func)
    else:
        print('Trying to subscribe to unknown cmd')


register_map(outbound.CMD_RETURN_SENSOR_DATA, lambda msg: [msg[1], msg[2]])<commit_msg>Changes for 16-bit sensor data<commit_after>import outbound
from observer import Observer

raw_observer_map = {x: Observer() for x in range(1, outbound.NUM_CMDS + 1)}
observer_map = {x: Observer() for x in range(1, outbound.NUM_CMDS + 1)}


def register_map(cmd, func):
    raw_observer_map[cmd].subscribe(lambda msg: observer_map[cmd].notify(*func(msg)))


def read_messages(bus):
    while True:
        msg = bus.try_receive()
        if msg is None:
            return

        packet_id = msg[0]
        if packet_id in raw_observer_map:
            raw_observer_map[packet_id].notify(msg)
        else:
            print('Unknown packet id: ' + str(packet_id))


def subscribe_to_cmd(cmd, func):
    if cmd in observer_map:
        observer_map[cmd].subscribe(func)
    else:
        print('Trying to subscribe to unknown cmd')


def parse_returned_sensor_data(msg):
    return [
        twos_comp((msg[1] << 8) | msg[2], 16),
        twos_comp((msg[3] << 8) | msg[4], 16)
    ]


def twos_comp(val, bits):
    if (val & (1 << (bits - 1))) != 0:
        val -= 1 << bits

    return val

register_map(outbound.CMD_RETURN_SENSOR_DATA, parse_returned_sensor_data)
{'fraction_non_alphanumeric': 0.11478599221789883, 'fraction_numerical': 0.013618677042801557, 'mean_word_length': 3.1305220883534135, 'pattern_counts': {'":': 0, '<': 11, '<?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': '3340588', 'n_tokens_mistral': 724, 'n_tokens_neox': 675, 'n_words': 171}