<commit_before>/**
 * Ninja Blocks arduino controller
 */

var 
	stream = require('stream')
	, util = require('util')
;

function platform(opts, app) {
	
	this.app = app;
	this.log = app.log;
	this.id = opts.id;

	this.newDevice = function newDevice(dev) {

		if(dev.id != 'arduino') { return; }

		app.log.debug("Initializing arduino...");

		dev.on('open', this.onOpen);
		dev.on('close', this.onClose);
		dev.on('error', this.onError);
		dev.on('data', this.onData);

	};

	this.onData = function onData(data) {

		var 
			json = this.getJSON(data)
			, type = Object.keys(json)[0] || undefined
		;

		if(!json || !type) {

			this.log.debug("Ignoring unexpected JSON (%s)", json);
			return;
		}

		this.dataEvent(type, json);
	};

	stream.call(this);

	app.on('serial::new', this.newDevice);

};

util.inherits(platform, stream);<commit_msg>Fix load order of platform & serial modules.<commit_after>/**
 * Ninja Blocks arduino controller
 */

var 
	stream = require('stream')
	, util = require('util')
;

function platform(opts, app) {
	
	this.app = app;
	this.log = app.log;
	this.id = opts.id;

	this.newDevice = function newDevice(dev) {

		if(dev.id != 'arduino') { return; }

		app.log.debug("Initializing arduino...");

		dev.on('open', this.onOpen);
		dev.on('close', this.onClose);
		dev.on('error', this.onError);
		dev.on('data', this.onData);

	};

	this.onData = function onData(data) {

		var 
			json = this.getJSON(data)
			, type = Object.keys(json)[0] || undefined
		;

		if(!json || !type) {

			this.log.debug("Ignoring unexpected JSON (%s)", json);
			return;
		}

		this.dataEvent(type, json);
	};

	this.onOpen = function onOpen() {

		this.log.debug("Arduino initialized");
	};

	this.onClose = function onClose() {

		this.log.debug("Arduino disconnected");
	};

	this.onError = function onError(err) {

		this.log.error("Arduino error: %s", err);
	};

	stream.call(this);
	app.on('serial::new', this.newDevice);

};

util.inherits(platform, stream);
{'fraction_non_alphanumeric': 0.18746841839312783, 'fraction_numerical': 0.001010611419909045, 'mean_word_length': 3.593967517401392, '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': '3204770', 'n_tokens_mistral': 804, 'n_tokens_neox': 719, 'n_words': 140}