<commit_before>'use strict';

var SerialPort = require('serialport').SerialPort;

class ZeroPiCore {
  constructor(options) {
    // Callback placeholders
    this.onOpen = () => {};

    // Serial port setup
    this.options = options || { debug: false };
    this.isOpen = false;
    this.selectors = {};
    this.serialPort = new SerialPort('/dev/ttyAMA0', { baudrate: 115200 });
    this.serialPort.on('open', () => this.open());

    this.serialPort.on('error', err => {
      console.log('An error has occurred with the serial port', err);
    });

    this.serialPort.on('disconnect', () => {
      this.log('Serial port disconnected');
    });
  }

  open() {
    this.isOpen = true;
    this.onOpen();
    this.log('Serial port opened successfully');
    this.serialPort.on('data', data => this.data(data));
  }

  data(data) {
    const result = data.toString('utf8')
      .replace(/\\n|\\r/g, '');
    this.log('Data Received: ', result);

    if (buffer.indexOf('\n') > -1) {
      if (buffer.length > 3 && buffer.indexOf('OK') > -1) {
        this.getCallback(buffer);
      }
    }
  }

  getCallback(buffer) {
    if (buffer.indexOf('L') > -1) {
      const split = buffer.split(' L');

      if (split[0]) {
        const result = Number(split[1].split(' OK')[0]);
        this.selectors[split[0]](result);
      }
    } else {
      const name = String(buffer.split(' OK')[0]);
      if (this.selectors[name]) this.selectors[name]();
    }
  }

  log(message) {
    if (!this.options.debug) return;<commit_msg>Remove the rest of the buffers<commit_after>'use strict';

var SerialPort = require('serialport').SerialPort;

class ZeroPiCore {
  constructor(options) {
    // Callback placeholders
    this.onOpen = () => {};

    // Serial port setup
    this.options = options || { debug: false };
    this.isOpen = false;
    this.selectors = {};
    this.serialPort = new SerialPort('/dev/ttyAMA0', { baudrate: 115200 });
    this.serialPort.on('open', () => this.open());

    this.serialPort.on('error', err => {
      console.log('An error has occurred with the serial port', err);
    });

    this.serialPort.on('disconnect', () => {
      this.log('Serial port disconnected');
    });
  }

  open() {
    this.isOpen = true;
    this.onOpen();
    this.log('Serial port opened successfully');
    this.serialPort.on('data', data => this.data(data));
  }

  data(data) {
    const result = data.toString('utf8')
      .replace(/\\n|\\r/g, '');
    this.log('Data Received: ', result);

    if (result.indexOf('\n') > -1) {
      if (result.length > 3 && result.indexOf('OK') > -1) {
        this.getCallback(result);
      }
    }
  }

  getCallback(result) {
    if (result.indexOf('L') > -1) {
      const split = result.split(' L');

      if (split[0]) {
        const outcome = Number(split[1].split(' OK')[0]);
        this.selectors[split[0]](outcome);
      }
    } else {
      const name = String(result.split(' OK')[0]);
      if (this.selectors[name]) this.selectors[name]();
    }
  }

  log(message) {
    if (!this.options.debug) return;
{'fraction_non_alphanumeric': 0.18796747967479674, 'fraction_numerical': 0.011056910569105691, 'mean_word_length': 2.653206650831354, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '3640770', 'n_tokens_mistral': 1035, 'n_tokens_neox': 1001, 'n_words': 200}