<commit_before>var assign = require("object-assign");

/**
 * @author <NAME>
 */
/**
 * Module Dependencies
 */
var util = require("util"),
  Emitter = require("events").EventEmitter,
  chrome = chrome || undefined,
  Encoder7Bit = require("./encoder7bit"),
  OneWireUtils = require("./onewireutils"),
  xbee = require("../../node_modules/xbee-api/lib/xbee-api.js")    //añadido por arturo 17-12-2014 16:54
  SerialPort = null;

var xbeeAPI = new xbee.XBeeAPI({             //añadido por arturo 17-12-2014   16:54
    api_mode: 1
});



var newFrame = {    //añadido por arturo 17-12-2014   16:54
        type: 0x00, // xbee_api.constants.FRAME_TYPE.TX_REQUEST_64
        id: 0, // optional, nextFrameId() is called per default
        destination64: "0013A200406FB3A1",
        options: 0x00, // optional, 0x00 is default
        data: []
         /*,
        data1: {},
        data2:{}*/
    };



try {
  if (process.browser) {
    SerialPort = require("browser-serialport").SerialPort;
  } else {
    SerialPort = require("serialport").SerialPort;
  }
} catch (err) {
  SerialPort = null;
}

if (SerialPort == null) {
  console.log("It looks like serialport didn't compile properly. This is a common problem and its fix is well documented here https://github.com/voodootikigod/node-serialport#to-install");
  throw "Missing serialport dependency";
}

/**
 * constants
 */

var ANALOG_MAPPING_QUERY = 0x69,
ANALOG_MAPPING_RESPONSE = 0x6A,
ANALOG_MESSAGE = 0xE0,
CAPABILITY_QUERY = 0x6B,
CAPABILITY_RESPONSE = 0x6C,
DIGITAL_MESSAGE = 0x90,
END_SYSEX = 0xF7,
EXTENDED_ANALOG = 0x6F,
I2C_CONFIG = 0x78,
I2C_REPLY = 0x77,
I2C_REQUEST = 0x76,
ONEWIRE_CONFIG_REQUEST = 0x41,
ONEWIRE_DATA = 0x73,
ONEWIRE_DELAY_REQUEST_BIT = 0x10,
ONEWIRE_READ_REPLY = 0x43,
ONEWIRE_READ_REQUEST_BIT = 0x08,
ONEWIRE_RESET_REQUEST_BIT = 0x01,
ONEWIRE_SEARCH_ALARMS_REPLY = 0x45,
ONEWIRE_SEARCH_ALARMS_REQUEST = 0x44,
ONEWIRE_SEARCH_REPLY = 0x42,
ONEWIRE_SEARCH_REQUEST = 0x40,
ONEWIRE_WITHDATA_REQUEST_BITS = 0x3C,
ONEWIRE_WRITE_REQUEST_BIT = 0x20,
PIN_MODE = 0xF4,
PIN_STATE_QUERY = 0x6D,
PIN_STATE_RESPONSE = 0x6E,
PULSE_IN = 0x74,
QUERY_FIRMWARE = 0x79,
REPORT_ANALOG = 0xC0,
REPORT_DIGITAL = 0xD0,
REPORT_VERSION = 0xF9,
SAMPLING_INTERVAL = 0x7A,
DELIVERY_INTERVAL = 0x75,
SET_TIME = 0x80,
SAMPLES_PACKET = 0x7D,
SERVO_CONFIG = 0x70,
START_SYSEX = 0xF0,
STEPPER = 0x72,
STRING_DATA = 0x71,
INT_DATA = 0x74,
ERROR_TX = 0x60,
SYSTEM_RESET = 0xFF;

/**
 * MIDI_RESPONSE contains functions to be called when we receive a MIDI message from the arduino.
 * used as a switch object as seen here http://james.padolsey.com/javascript/how-to-avoid-switch-case-syndrome/
 * @private
 */

var MIDI_RESPONSE = {};

/**
 * Handles a REPORT_VERSION response and emits the reportversion event.  Also turns on all pins to start reporting
 * @private
 * @param {Board} board the current arduino board we are working with.
 */

MIDI_RESPONSE[REPORT_VERSION] = function(board) {
    //console.log("==>PARSE report version");
  console.log("1.-Response==>report version");
  board.version.major = board.currentBuffer[1];
  board.version.minor = board.currentBuffer[2];
  board.emit("reportversion");
};

/**
 * Handles a ANALOG_MESSAGE response and emits "analog-read" and "analog-read-"+n events where n is the pin number.
 * @private
 * @param {Board} board the current arduino board we are working with.
 */

MIDI_RESPONSE[ANALOG_MESSAGE] = function(board) {
  var value = board.currentBuffer[1] | (board.currentBuffer[2] << 7);
  var pin = board.currentBuffer[0] & 0x0F;
  if (board.pins[board.analogPins[pin]]) {
    board.pins[board.analogPins[pin]].value = value;
  }

  board.emit("analog-read-" + pin, value);
  board.emit("analog-read", {
    pin: pin,
    value: value
  });
};



/**
 * Handles a DIGITAL_MESSAGE response and emits:
 * "digital-read"
 * "digital-read-"+n
 *
 * Where n is the pin number.
 *
 * @private
 * @param {Board} board the current arduino board we are working with.
 */

MIDI_RESPONSE[DIGITAL_MESSAGE] = function(board) {
    console.log("01010101DigitalMsg");
  var port = (board.currentBuffer[0] & 0x0F);
  var portValue = board.currentBuffer[1] | (board.currentBuffer[2] << 7);

  for (var i = 0; i < 8; i++) {
    var pinNumber = 8 * port + i;
    var pin = board.pins[pinNumber];
    if (pin && (pin.mode === board.MODES.INPUT)) {
      pin.value = (portValue >> (i & 0x07)) & 0x01;
      board.emit("digital-read-" + pinNumber, pin.value);
      board.emit("digital-read", {
        pin: pinNumber,
        value: pin.value
      });
    }
  }
};

/**
 * SYSEX_RESPONSE contains functions to be called when we receive a SYSEX message from the arduino.
 * used as a switch object as seen here http://james.padolsey.com/javascript/how-to-avoid-switch-case-syndrome/
 * @private
 */

var SYSEX_RESPONSE = {};

SYSEX_RESPONSE[ERROR_TX] = function(board) {
    var errorCode = board.currentBuffer[2];
    var timeError = new Date((0x7d0 | board.currentBuffer[3]), board.currentBuffer[4], board.currentBuffer[5], board.currentBuffer[6], board.currentBuffer[7], board.currentBuffer[7], 0);
    board.emit("errorTx", {
        errorCode: errorCode,
        errorT: timeError
    });
}


SYSEX_RESPONSE[SAMPLES_PACKET] = function(board) {
    console.log("samplepacketReceived!!!!=>", board.currentBuffer);
    if (board.firstPayload==true || board.currentBuffer[4]==0){
        board.samplesCount = board.currentBuffer[2];
        board.numberChannels=board.currentBuffer[3];
        board.numPayloads=board.currentBuffer[4];
        var timeSP = new Date((0x7d0 | board.currentBuffer[5]), board.currentBuffer[6], board.currentBuffer[7], board.currentBuffer[8], board.currentBuffer[9], board.currentBuffer[10], 0);
        var pin=[];
        //var samples = new Array();
        var reading=false;
        var samplesRead=0;
        board.firstPayload=false;
        var iterator=9;
    } else {
        var iterator=0;
    }
    for(iterator; iterator<board.currentBuffer.length - 1;iterator++){
        if((board.currentBuffer[iterator]& 0xF0)==0xE0 || reading==true){
            if (reading==true){
                value= board.currentBuffer[iterator] | (board.currentBuffer[iterator+1] << 7)
                iterator++;
                samplesRead--;
                value=Number(parseFloat((value / 1023) * 5).toFixed(3));<commit_msg>nothing special<commit_after>var assign = require("object-assign");

/**
 * @author <NAME>
 */
/**
 * Module Dependencies
 */
var util = require("util"),
  Emitter = require("events").EventEmitter,
  chrome = chrome || undefined,
  Encoder7Bit = require("./encoder7bit"),
  OneWireUtils = require("./onewireutils"),
  xbee = require("../../node_modules/xbee-api/lib/xbee-api.js")    //añadido por arturo 17-12-2014 16:54
  SerialPort = null;

var xbeeAPI = new xbee.XBeeAPI({             //añadido por arturo 17-12-2014   16:54
    api_mode: 1
});



var newFrame = {    //añadido por arturo 17-12-2014   16:54
        type: 0x00, // xbee_api.constants.FRAME_TYPE.TX_REQUEST_64
        id: 0, // optional, nextFrameId() is called per default
        destination64: "0013A200406FB3A1",
        options: 0x00, // optional, 0x00 is default
        data: []
         /*,
        data1: {},
        data2:{}*/
    };



try {
  if (process.browser) {
    SerialPort = require("browser-serialport").SerialPort;
  } else {
    SerialPort = require("serialport").SerialPort;
  }
} catch (err) {
  SerialPort = null;
}

if (SerialPort == null) {
  console.log("It looks like serialport didn't compile properly. This is a common problem and its fix is well documented here https://github.com/voodootikigod/node-serialport#to-install");
  throw "Missing serialport dependency";
}

/**
 * constants
 */

var ANALOG_MAPPING_QUERY = 0x69,
ANALOG_MAPPING_RESPONSE = 0x6A,
ANALOG_MESSAGE = 0xE0,
CAPABILITY_QUERY = 0x6B,
CAPABILITY_RESPONSE = 0x6C,
DIGITAL_MESSAGE = 0x90,
END_SYSEX = 0xF7,
EXTENDED_ANALOG = 0x6F,
I2C_CONFIG = 0x78,
I2C_REPLY = 0x77,
I2C_REQUEST = 0x76,
ONEWIRE_CONFIG_REQUEST = 0x41,
ONEWIRE_DATA = 0x73,
ONEWIRE_DELAY_REQUEST_BIT = 0x10,
ONEWIRE_READ_REPLY = 0x43,
ONEWIRE_READ_REQUEST_BIT = 0x08,
ONEWIRE_RESET_REQUEST_BIT = 0x01,
ONEWIRE_SEARCH_ALARMS_REPLY = 0x45,
ONEWIRE_SEARCH_ALARMS_REQUEST = 0x44,
ONEWIRE_SEARCH_REPLY = 0x42,
ONEWIRE_SEARCH_REQUEST = 0x40,
ONEWIRE_WITHDATA_REQUEST_BITS = 0x3C,
ONEWIRE_WRITE_REQUEST_BIT = 0x20,
PIN_MODE = 0xF4,
PIN_STATE_QUERY = 0x6D,
PIN_STATE_RESPONSE = 0x6E,
PULSE_IN = 0x74,
QUERY_FIRMWARE = 0x79,
REPORT_ANALOG = 0xC0,
REPORT_DIGITAL = 0xD0,
REPORT_VERSION = 0xF9,
SAMPLING_INTERVAL = 0x7A,
DELIVERY_INTERVAL = 0x75,
SET_TIME = 0x80,
SAMPLES_PACKET = 0x7D,
SERVO_CONFIG = 0x70,
START_SYSEX = 0xF0,
STEPPER = 0x72,
STRING_DATA = 0x71,
INT_DATA = 0x74,
ERROR_TX = 0x60,
SYSTEM_RESET = 0xFF;

/**
 * MIDI_RESPONSE contains functions to be called when we receive a MIDI message from the arduino.
 * used as a switch object as seen here http://james.padolsey.com/javascript/how-to-avoid-switch-case-syndrome/
 * @private
 */

var MIDI_RESPONSE = {};

/**
 * Handles a REPORT_VERSION response and emits the reportversion event.  Also turns on all pins to start reporting
 * @private
 * @param {Board} board the current arduino board we are working with.
 */

MIDI_RESPONSE[REPORT_VERSION] = function(board) {
    //console.log("==>PARSE report version");
  console.log("1.-Response==>report version");
  board.version.major = board.currentBuffer[1];
  board.version.minor = board.currentBuffer[2];
  board.emit("reportversion");
};

/**
 * Handles a ANALOG_MESSAGE response and emits "analog-read" and "analog-read-"+n events where n is the pin number.
 * @private
 * @param {Board} board the current arduino board we are working with.
 */

MIDI_RESPONSE[ANALOG_MESSAGE] = function(board) {
  var value = board.currentBuffer[1] | (board.currentBuffer[2] << 7);
  var pin = board.currentBuffer[0] & 0x0F;
  if (board.pins[board.analogPins[pin]]) {
    board.pins[board.analogPins[pin]].value = value;
  }

  board.emit("analog-read-" + pin, value);
  board.emit("analog-read", {
    pin: pin,
    value: value
  });
};



/**
 * Handles a DIGITAL_MESSAGE response and emits:
 * "digital-read"
 * "digital-read-"+n
 *
 * Where n is the pin number.
 *
 * @private
 * @param {Board} board the current arduino board we are working with.
 */

MIDI_RESPONSE[DIGITAL_MESSAGE] = function(board) {
    console.log("01010101DigitalMsg");
  var port = (board.currentBuffer[0] & 0x0F);
  var portValue = board.currentBuffer[1] | (board.currentBuffer[2] << 7);

  for (var i = 0; i < 8; i++) {
    var pinNumber = 8 * port + i;
    var pin = board.pins[pinNumber];
    if (pin && (pin.mode === board.MODES.INPUT)) {
      pin.value = (portValue >> (i & 0x07)) & 0x01;
      board.emit("digital-read-" + pinNumber, pin.value);
      board.emit("digital-read", {
        pin: pinNumber,
        value: pin.value
      });
    }
  }
};

/**
 * SYSEX_RESPONSE contains functions to be called when we receive a SYSEX message from the arduino.
 * used as a switch object as seen here http://james.padolsey.com/javascript/how-to-avoid-switch-case-syndrome/
 * @private
 */

var SYSEX_RESPONSE = {};

SYSEX_RESPONSE[ERROR_TX] = function(board) {
    var errorCode = board.currentBuffer[2];
    var timeError = new Date((0x7d0 | board.currentBuffer[3]), board.currentBuffer[4], board.currentBuffer[5], board.currentBuffer[6], board.currentBuffer[7], board.currentBuffer[7], 0);
    board.emit("errorTx", {
        errorCode: errorCode,
        errorT: timeError
    });
}


SYSEX_RESPONSE[SAMPLES_PACKET] = function(board) {
    //console.log("samplepacketReceived!!!!=>", board.currentBuffer);
    if (board.firstPayload==true || board.currentBuffer[4]==0){
        board.samplesCount = board.currentBuffer[2];
        board.numberChannels=board.currentBuffer[3];
        board.numPayloads=board.currentBuffer[4];
        var timeSP = new Date((0x7d0 | board.currentBuffer[5]), board.currentBuffer[6], board.currentBuffer[7], board.currentBuffer[8], board.currentBuffer[9], board.currentBuffer[10], 0);
        var pin=[];
        //var samples = new Array();
        var reading=false;
        var samplesRead=0;
        board.firstPayload=false;
        var iterator=9;
    } else {
        var iterator=0;
    }
    for(iterator; iterator<board.currentBuffer.length - 1;iterator++){
        if((board.currentBuffer[iterator]& 0xF0)==0xE0 || reading==true){
            if (reading==true){
                value= board.currentBuffer[iterator] | (board.currentBuffer[iterator+1] << 7)
                iterator++;
                samplesRead--;
                value=Number(parseFloat((value / 1023) * 5).toFixed(3));
{'fraction_non_alphanumeric': 0.13470031545741326, 'fraction_numerical': 0.03990536277602524, 'mean_word_length': 3.5945652173913043, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 15, 'https://': 2, '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': '5411178', 'n_tokens_mistral': 4870, 'n_tokens_neox': 4502, 'n_words': 970}