<commit_before>/*
Apache License
                           Version 2.0, January 2004
                        http://www.apache.org/licenses/

Copyright (c) 2014 <NAME>
*/

var autobahn = require('autobahn');
var express = require('express');


s4t_wamp_server = function(){


}

s4t_wamp_server.prototype.start = function(restPort, wamp_router_url){


   var boards = {};
   var getIP = require('./getIP.js');
   var IPLocal = getIP('eth0', 'IPv4');

   //var url_wamp_router = "ws://172.17.3.139:8181/ws";  //example of url wamp router

   var connection = new autobahn.Connection({
      //url: url_wamp_router,
      url:wamp_router_url,
      realm: "s4t"
   });

   var topic_command = 'board.command'
   var topic_connection = 'board.connection'

   connection.onopen = function (session, details) {


   	var rest = express();

      rest.get('/', function (req, res){
         res.send('API: <br> http://'+IPLocal+':'+restPort+'/list   for board list');
      });

      rest.get('')


   	rest.get('/command/', function (req, res){

         //DEBUG Message
   		//console.log('POST::::'+req.originalUrl);
   		
         var board = req.query.board;
   		var command = req.query.command;
         var pin = req.query.pin;
         var mode = req.query.mode;
         var value = req.query.val;
         var op = req.query.op;
         var tmis = req.query.tmis;
         var nmis = req.query.nmis;

         res.type('application/json');

   		if(boards[board] != undefined){
   			//DEBUG Message
            //console.log("ID exsist");
            //console.log(command);
            switch(command){
               case 'ssh':
                  var response = {
                     ip: IPLocal,
                     port: {},
                     service:'ssh'
                  }
                  //random port for reverse service
   			      var port = randomIntInc(6000,7000);
   			      session.publish(topic_command, [board, command, port]);
                  response.port = port;
                  res.send(JSON.stringify(response));

                  //res.send("ssh -p "+port+" root@"+IPLocal);
                  //res.json(IPLocal+':'+port);

                  break;

               case 'ideino':
                  var response = {
                     ip: IPLocal,
                     port: {},
                     service:'ideino'
                  }
                  var port = randomIntInc(6000,7000);
                  session.publish(topic_command, [board, command, port]);
                  response.port = port;
                  res.send(JSON.stringify(response));
                  //res.send("http://"+IPLocal+":"+port);
                  //res.json(IPLocal+':'+port);
                  break;

               case 'osjs':
                  var response = {
                     ip: IPLocal,
                     port: {},
                     service:'osjs'
                  }
                  var port = randomIntInc(6000,7000);
                  session.publish(topic_command, [board, command, port]);
                  response.port = port;
                  res.send(JSON.stringify(response));
                  //res.send("http://"+IPLocal+":"+port);
                  //res.json(IPLocal+':'+port);
                  break;

               case 'mode':
                  var response = {
                     result: {}
                  }

                  session.call(board+'.command.rpc.setmode', [pin, mode]).then(
                     function(result){
                        response.result = result;
                        res.send(JSON.stringify(response));
                     } , session.log);
                  break;

               //Analog
               case 'analog':
                  var response = {
                     result: {}
                  }
                  if(value!=undefined){//WRITE
                     console.log('ANALOG WRITE');
                     session.call(board+'.command.rpc.write.analog', [board, command, pin, value]).then(
                        function(result){
                           response.result = result;
                           res.send(JSON.stringify(response));
                     } , session.log);
                  }
                  else{
                  //DEBUG message
                  console.log('ANALOG READ');
                  session.call(board+'.command.rpc.read.analog', [board, command, pin]).then(
                     function(result){
                        response.result = result;
                        res.send(JSON.stringify(response));
                     }, session.log);
                  }
                  break;

               //Misure
               case: 'misura':
                  var response = {
                     result: {}
                  }
                  console.log('MISURE'):
                  session.publish(topic_command, [board, commad, pin, op, tmis, nmis]);
                  response.result = [board, commad, pin, op, tmis, nmis];
                  res.send(JSON.stringify(response));
                  break;

               case: 'turnMotor':
                  var response = {
                     result: {}
                  }
                  console.log('TURN MOTOR'):
                  session.publish(topic_command, [board, commad, pin, value]);
                  response.result = [board, commad, pin, value];
                  res.send(JSON.stringify(response));
                  break;
                  
               //Digital
               case 'digital':
                  var response = {
                        result: {}
                  }

                  if(value!=undefined){//WRITE
                     //DEBUG Message
                     console.log('DIGITAL WRITE');
                     session.call(board+'.command.rpc.write.digital', [board, command, pin, value]).then(
                        function(result){
                           response.result = result;
                           res.send(JSON.stringify(response));
                     } , session.log);
                  }
                  else{
                     //DEBUG Message
                     console.log('DIGITAL READ');
                     session.call(board+'.command.rpc.read.digital', [board, command, pin]).then(
                        function(result){
                           response.result = result;
                           res.send(JSON.stringify(response));<commit_msg>removed some typo<commit_after>/*
Apache License
                           Version 2.0, January 2004
                        http://www.apache.org/licenses/

Copyright (c) 2014 <NAME>
*/

var autobahn = require('autobahn');
var express = require('express');


s4t_wamp_server = function(){


}

s4t_wamp_server.prototype.start = function(restPort, wamp_router_url){


   var boards = {};
   var getIP = require('./getIP.js');
   var IPLocal = getIP('eth0', 'IPv4');

   //var url_wamp_router = "ws://172.17.3.139:8181/ws";  //example of url wamp router

   var connection = new autobahn.Connection({
      //url: url_wamp_router,
      url:wamp_router_url,
      realm: "s4t"
   });

   var topic_command = 'board.command'
   var topic_connection = 'board.connection'

   connection.onopen = function (session, details) {


   	var rest = express();

      rest.get('/', function (req, res){
         res.send('API: <br> http://'+IPLocal+':'+restPort+'/list   for board list');
      });

      rest.get('')


   	rest.get('/command/', function (req, res){

         //DEBUG Message
   		//console.log('POST::::'+req.originalUrl);
   		
         var board = req.query.board;
   		var command = req.query.command;
         var pin = req.query.pin;
         var mode = req.query.mode;
         var value = req.query.val;
         var op = req.query.op;
         var tmis = req.query.tmis;
         var nmis = req.query.nmis;

         res.type('application/json');

   		if(boards[board] != undefined){
   			//DEBUG Message
            //console.log("ID exsist");
            //console.log(command);
            switch(command){
               case 'ssh':
                  var response = {
                     ip: IPLocal,
                     port: {},
                     service:'ssh'
                  }
                  //random port for reverse service
   			      var port = randomIntInc(6000,7000);
   			      session.publish(topic_command, [board, command, port]);
                  response.port = port;
                  res.send(JSON.stringify(response));

                  //res.send("ssh -p "+port+" root@"+IPLocal);
                  //res.json(IPLocal+':'+port);

                  break;

               case 'ideino':
                  var response = {
                     ip: IPLocal,
                     port: {},
                     service:'ideino'
                  }
                  var port = randomIntInc(6000,7000);
                  session.publish(topic_command, [board, command, port]);
                  response.port = port;
                  res.send(JSON.stringify(response));
                  //res.send("http://"+IPLocal+":"+port);
                  //res.json(IPLocal+':'+port);
                  break;

               case 'osjs':
                  var response = {
                     ip: IPLocal,
                     port: {},
                     service:'osjs'
                  }
                  var port = randomIntInc(6000,7000);
                  session.publish(topic_command, [board, command, port]);
                  response.port = port;
                  res.send(JSON.stringify(response));
                  //res.send("http://"+IPLocal+":"+port);
                  //res.json(IPLocal+':'+port);
                  break;

               case 'mode':
                  var response = {
                     result: {}
                  }

                  session.call(board+'.command.rpc.setmode', [pin, mode]).then(
                     function(result){
                        response.result = result;
                        res.send(JSON.stringify(response));
                     } , session.log);
                  break;

               //Analog
               case 'analog':
                  var response = {
                     result: {}
                  }
                  if(value!=undefined){//WRITE
                     console.log('ANALOG WRITE');
                     session.call(board+'.command.rpc.write.analog', [board, command, pin, value]).then(
                        function(result){
                           response.result = result;
                           res.send(JSON.stringify(response));
                     } , session.log);
                  }
                  else{
                  //DEBUG message
                  console.log('ANALOG READ');
                  session.call(board+'.command.rpc.read.analog', [board, command, pin]).then(
                     function(result){
                        response.result = result;
                        res.send(JSON.stringify(response));
                     }, session.log);
                  }
                  break;

               //Misure
               case: 'misura':
                  var response = {
                     result: {}
                  }
                  console.log('MISURE');
                  session.publish(topic_command, [board, commad, pin, op, tmis, nmis]);
                  response.result = [board, commad, pin, op, tmis, nmis];
                  res.send(JSON.stringify(response));
                  break;

               case: 'turnMotor':
                  var response = {
                     result: {}
                  }
                  console.log('TURN MOTOR');
                  session.publish(topic_command, [board, commad, pin, value]);
                  response.result = [board, commad, pin, value];
                  res.send(JSON.stringify(response));
                  break;
                  
               //Digital
               case 'digital':
                  var response = {
                        result: {}
                  }

                  if(value!=undefined){//WRITE
                     //DEBUG Message
                     console.log('DIGITAL WRITE');
                     session.call(board+'.command.rpc.write.digital', [board, command, pin, value]).then(
                        function(result){
                           response.result = result;
                           res.send(JSON.stringify(response));
                     } , session.log);
                  }
                  else{
                     //DEBUG Message
                     console.log('DIGITAL READ');
                     session.call(board+'.command.rpc.read.digital', [board, command, pin]).then(
                        function(result){
                           response.result = result;
                           res.send(JSON.stringify(response));
{'fraction_non_alphanumeric': 0.12224788298691301, 'fraction_numerical': 0.00800615858352579, 'mean_word_length': 1.1092709855496021, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, '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': '3181833', 'n_tokens_mistral': 3480, 'n_tokens_neox': 3124, 'n_words': 617}