<commit_before>// An singleton that contains and manages the sending of picpilot commands
var picpilot_config=require('../../config/picpilot-config');
var Network=require('../Network');
var Logger=require('../util/Logger');
var Validator=require('../util/Validator');

var Commands={
  checkConnection: function(){ //to make sure the data relay connection exists first (otherwise we'll prob get weird errors)
    if(Network.connections['data_relay']){
      return true;
    }
    else{
      Logger.warn('Cannot send command as the data_relay connection has not yet been established');
      return false;
    }
  },
  sendProtectedCommand:function(command){
    Network.connections['data_relay'].write(command+':'+picpilot_config.get('command_password')+'\<PASSWORD>');
  },
  sendCommand: function(command, value){
    if(this.checkConnection()){
      Network.connections['data_relay'].write(command+':'+value+'\r\n');
    }
  },
  sendRawCommand: function(command){
    if(this.checkConnection()){
      Network.connections['data_relay'].write(command+'\r\n');
    }
  },
  sendRoll: function(roll){
    if(Validator.isValidRoll(roll)){
      this.sendCommand('set_rollAngle',roll);
    }
    else{
      Logger.error('Command to not sent since invalid roll value detected! Roll:'+roll);
    }
  },
  sendPitch: function(pitch){
    if(Validator.isValidPitch(pitch)){
      this.sendCommand('set_pitchAngle',pitch);
    }
    else{
      Logger.error('Command to not sent since invalid pitch value detected! Pitch:'+pitch);
    }
  },
  sendHeading: function(heading){
    if(Validator.isValidHeading(heading)){
      this.sendCommand('set_heading',heading);
    }
    else{
      Logger.error('Command to not sent since invalid heading value detected! Heading:'+heading);
    }
  },<commit_msg>Added support for sending commands whilst in simulation mode<commit_after>// An singleton that contains and manages the sending of picpilot commands
var picpilot_config=require('../../config/picpilot-config');
var Network=require('../Network');
var Logger=require('../util/Logger');
var Validator=require('../util/Validator');
var SimulationManager=require("../SimulationManager");

var Commands={
  checkConnection: function(){ //to make sure the data relay connection exists first (otherwise we'll prob get weird errors)
    if(SimulationManager.simulationActive){ //just return false if the simulation is active
      return false;
    }

    if(Network.connections['data_relay']){
      return true;
    }
    else{
      Logger.warn('Cannot send command as the data_relay connection has not yet been established');
      return false;
    }
  },
  sendProtectedCommand:function(command){
    Network.connections['data_relay'].write(command+':'+picpilot_config.get('command_password')+'\r\n');
  },
  sendCommand: function(command, value){
    if(this.checkConnection()){
      Network.connections['data_relay'].write(command+':'+value+'\r\n');
    }
    if(SimulationManager.simulationActive){
      Logger.info('[Simulation] Successfully sent command '+command+':'+value+'\r\n')
    }
  },
  sendRawCommand: function(command){
    if(this.checkConnection()){
      Network.connections['data_relay'].write(command+'\r\n');
    }
    if(SimulationManager.simulationActive){
      Logger.info('[Simulation] Successfully sent command: '+command)
    }
  },
  sendRoll: function(roll){
    if(Validator.isValidRoll(roll)){
      this.sendCommand('set_rollAngle',roll);
    }
    else{
      Logger.error('Command to not sent since invalid roll value detected! Roll:'+roll);
    }
  },
  sendPitch: function(pitch){
    if(Validator.isValidPitch(pitch)){
      this.sendCommand('set_pitchAngle',pitch);
    }
    else{
      Logger.error('Command to not sent since invalid pitch value detected! Pitch:'+pitch);
    }
  },
  sendHeading: function(heading){
    if(Validator.isValidHeading(heading)){
      this.sendCommand('set_heading',heading);
    }
    else{
      Logger.error('Command to not sent since invalid heading value detected! Heading:'+heading);
    }
  },
{'fraction_non_alphanumeric': 0.14275184275184274, 'fraction_numerical': 0.0, 'mean_word_length': 4.057142857142857, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '2187986', 'n_tokens_mistral': 1201, 'n_tokens_neox': 1169, 'n_words': 259}