<commit_before>__author__ = 'Matthew'

import requests
from robot import Robot
import time
import serial
import traceback

import logging
logging.basicConfig(filename='../beercaddy.log', level=logging.DEBUG)

import binascii


def calcCheckSum(incoming):
    msgByte = Str2ByteArray(incoming)
    check = 0
    for i in msgByte:
        check = AddToCRC(i, check)
    return check


def AddToCRC(b, crc):
    b2 = b
    if (b < 0):
        b2 = b + 256
    for i in range(8):
        odd = ((b2^crc) & 1) == 1
        crc >>= 1
        b2 >>= 1
        if (odd):
            crc ^= 0x8C # this means crc ^= 140
    return crc


def Str2ByteArray(msg):
    b = bytearray()
    b.extend(map(ord, msg))
    return b


def read_serial_message():
    recieved_data = []

    logging.debug('Waiting for message')
    byte = ser.read()

    if byte == b'\x3A':
        length = int.from_bytes(ser.read(), byteorder='little')
        command = int.from_bytes(ser.read(), byteorder='little')

        for _ in range(length):
            recieved_data.append(ser.read())

        checksum = ser.read()

        logging.debug('Message Length: {}'.format(length))
        logging.debug('Message Command: {}'.format(command))
        logging.debug('Raw Message {}'.format(b''.join(recieved_data)))
        logging.debug('Message Checksum: {}'.format(int.from_bytes(checksum, byteorder='little')))

    else:
        logging.debug('Received unexpected character - {}'.format(int.from_bytes(byte, byteorder='little')))
        return

    string_message = ''.join([x.decode('ascii') for x in recieved_data])
    logging.debug('Message: {}'.format(string_message))

    checksum_string = ':' + chr(length) + chr(command) + string_message
    logging.debug('Checksum String: {}'.format(checksum_string))
<commit_msg>Added further logging<commit_after>__author__ = 'Matthew'

import requests
from robot import Robot
import time
import serial
import traceback

import logging
logging.basicConfig(filename='../beercaddy.log', level=logging.DEBUG)

import binascii


def calcCheckSum(incoming):
    msgByte = Str2ByteArray(incoming)
    check = 0
    for i in msgByte:
        check = AddToCRC(i, check)
    return check


def AddToCRC(b, crc):
    b2 = b
    if (b < 0):
        b2 = b + 256
    for i in range(8):
        odd = ((b2^crc) & 1) == 1
        crc >>= 1
        b2 >>= 1
        if (odd):
            crc ^= 0x8C # this means crc ^= 140
    return crc


def Str2ByteArray(msg):
    b = bytearray()
    b.extend(map(ord, msg))
    logging.debug('ByteArray: {}'.format(b))
    return b


def read_serial_message():
    recieved_data = []

    logging.debug('Waiting for message')
    byte = ser.read()

    if byte == b'\x3A':
        length = int.from_bytes(ser.read(), byteorder='little')
        command = int.from_bytes(ser.read(), byteorder='little')

        for _ in range(length):
            recieved_data.append(ser.read())

        checksum = ser.read()

        logging.debug('Message Length: {}'.format(length))
        logging.debug('Message Command: {}'.format(command))
        logging.debug('Raw Message {}'.format(recieved_data))
        logging.debug('Message Checksum: {}'.format(int.from_bytes(checksum, byteorder='little')))

    else:
        logging.debug('Received unexpected character - {}'.format(int.from_bytes(byte, byteorder='little')))
        return

    string_message = ''.join([x.decode('ascii') for x in recieved_data])
    logging.debug('Message: {}'.format(string_message))

    checksum_string = ':' + chr(length) + chr(command) + string_message

{'fraction_non_alphanumeric': 0.1417785234899329, 'fraction_numerical': 0.012304250559284116, 'mean_word_length': 2.935093509350935, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '148304', 'n_tokens_mistral': 1206, 'n_tokens_neox': 1138, 'n_words': 269}