<commit_before>//***************//
// <NAME> //
//***************//
// -> construct JSON frame from URL
// 		-> check parameters (types / values)
//		-> return error frame to "web.js" if wrong
//		-> go on if good
// -> send query JSON frame to 'dao.js' (to Arduino)
// -> get answer JSON frame from 'dao.js' (from Arduino)
// -> transmit JSON answer to 'web.js'


// Imports modules
var util = require('util'),
// Import other layers
	dao = require('./dao');

// Commande format : {"id":"1","ac":"cl","pa":{"pin":"8","dur":"100","nb":"10"}}
//////// PUBLIC functions
// get arduino list
exports.arduinos = function() {
	util.log("METIER : arduinos");
}

// LED blink
exports.blink = function(idCommand, idArduino, pin, lenght, number) {
	// build json object
	var jsonObject = { id:idCommand, ac:"cl", pa:{pin:pin, dur:lenght, nb:number}};
	// send to "dao" and return result to "web"
	return dao.send(idArduino, JSON.stringify(jsonObject));
}

// READ command  {"id":"4","ac":"pr","pa":{"pin":"0","mod":"a"}}
exports.read = function(idCommand, idArduino, pin, mode) {
	// build json object
	var jsonObject = { id:idCommand, ac:"pr", pa:{pin:pin, dur:lenght, nb:number}};
	// send to "dao" and return result to "web"
	return dao.send(idArduino, JSON.stringify(jsonObject));
}

// WRITE command
exports.write = function(idCommand, idArduino, pin, mode, value) {
	// build json object
	var jsonObject = { id:idCommand, ac:"pw", pa:{pin:pin, mod:mode, val:value}};
	// send to "dao" and return result to "web"
	return dao.send(idArduino, JSON.stringify(jsonObject));
}
<commit_msg>arduinos function added<commit_after>//***************//
// <NAME> //
//***************//
// -> construct JSON frame from URL
// 		-> check parameters (types / values)
//		-> return error frame to "web.js" if wrong
//		-> go on if good
// -> send query JSON frame to 'dao.js' (to Arduino)
// -> get answer JSON frame from 'dao.js' (from Arduino)
// -> transmit JSON answer to 'web.js'


// Imports modules
var util = require('util'),
// Import other layers
	dao = require('./dao');

// Commande format : {"id":"1","ac":"cl","pa":{"pin":"8","dur":"100","nb":"10"}}
//////// PUBLIC functions
// get arduino list
exports.arduinos = function() {
	util.log("METIER : arduinos");
	var rawArduinos = dao.getArduinos();
	var arduinos = [];
	
	rawArduinos.forEach(function(ard) {
		var json = JSON.parse(ard); //transform data to json object
		var obj = { id: json.id, port: json.port, description: json.desc, ip: json.ip, mac: json.mac }; //create json object using the expected format
		arduinos.push(JSON.stringify(obj)); //transform json object into a string and put it into "arduinos" array
	});
	return arduinos;
}

// LED blink
exports.blink = function(idCommand, idArduino, pin, lenght, number) {
	// build json object
	var jsonObject = { id:idCommand, ac:"cl", pa:{pin:pin, dur:lenght, nb:number}};
	// send to "dao" and return result to "web"
	return dao.send(idArduino, JSON.stringify(jsonObject));
}

// READ command  {"id":"4","ac":"pr","pa":{"pin":"0","mod":"a"}}
exports.read = function(idCommand, idArduino, pin, mode) {
	// build json object
	var jsonObject = { id:idCommand, ac:"pr", pa:{pin:pin, dur:lenght, nb:number}};
	// send to "dao" and return result to "web"
	return dao.send(idArduino, JSON.stringify(jsonObject));
}

// WRITE command
exports.write = function(idCommand, idArduino, pin, mode, value) {
	// build json object
	var jsonObject = { id:idCommand, ac:"pw", pa:{pin:pin, mod:mode, val:value}};
	// send to "dao" and return result to "web"
	return dao.send(idArduino, JSON.stringify(jsonObject));
}

{'fraction_non_alphanumeric': 0.20477247502774695, 'fraction_numerical': 0.004994450610432853, 'mean_word_length': 4.0, 'pattern_counts': {'":': 22, '<': 5, '<?xml version=': 0, '>': 19, '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': '6052483', 'n_tokens_mistral': 1262, 'n_tokens_neox': 1234, 'n_words': 354}