<commit_before>var debug           = require('debug')('connman-simplified:wifi');
var async           = require('async');
var util            = require("util");
var Base            = require('./Base');
var ms              = require('ms');
var configFiles     = require('./ConfigFiles.js');
var Parser          = require('./Parser');

var _super = Base.prototype;

var _timeoutWiFiEnable = 3000;
var _scanRetryTimeout = 1000; //5000;
var _numScanRetries = 5; //3;
var _getServiceRetryTimeout = _scanRetryTimeout;
var _numGetServiceRetries = _numScanRetries;
var _servicesCache = []; // cache of services, use while tethering

/** https://kernel.googlesource.com/pub/scm/network/connman/connman/+/1.14/doc/service-api.txt
 *  string State [readonly]
 *     The service state information.
 *     Valid states are "idle", "failure", "association", "configuration", "ready", "disconnect" and "online".
 */
var STATES = {
  IDLE: 'idle',
  FAILURE: 'failure',
  ASSOCIATION: 'association',
  CONFIGURATION: 'configuration',
  READY: 'ready',
  DISCONNECT: 'disconnect',
  ONLINE: 'online',
};

module.exports = WiFi;
module.exports.STATES = STATES;

function WiFi(connman) {
  Base.call(this);
  this.connman = connman;
}

util.inherits(WiFi, Base);

WiFi.prototype.init = function(callback) {
  debug("init");
  var self = this;
  // Retrieve WiFi technology
  // https://kernel.googlesource.com/pub/scm/network/connman/connman/+/1.14/doc/technology-api.txt
  var tech = self.connman.technologies.WiFi;
  if(tech === undefined) {
    if(callback) callback(new Error("No WiFi hardware available"));
    return;
  }
  _super.init.call(self,tech,function(err,properties) {
    if(properties.powered) { // already powered? 
      if(callback) callback(err,properties);
    } else {
      self.enable(function(err) {
        if(callback) callback(err,properties);
      });
    }
  });
  self.on('services',onServices);
};
WiFi.prototype.enable = function(callback) {
  // Note: Hostmodule tries this 3 times?
  this.setProperty('Powered', true, function(err) {
    //debug("WiFi setProperty 'Powered' true response: ",err);
    // delay, probably because of: https://01.org/jira/browse/CM-644
    setTimeout(callback, _timeoutWiFiEnable, err);
  });
};
WiFi.prototype.disable = function(callback) {
  this.setProperty('Powered', false, callback);
};<commit_msg>Powering the wifi error logging and comments<commit_after>var debug           = require('debug')('connman-simplified:wifi');
var async           = require('async');
var util            = require("util");
var Base            = require('./Base');
var ms              = require('ms');
var configFiles     = require('./ConfigFiles.js');
var Parser          = require('./Parser');

var _super = Base.prototype;

var _timeoutWiFiEnable = 3000;
var _scanRetryTimeout = 1000; //5000;
var _numScanRetries = 5; //3;
var _getServiceRetryTimeout = _scanRetryTimeout;
var _numGetServiceRetries = _numScanRetries;
var _servicesCache = []; // cache of services, use while tethering

/** https://kernel.googlesource.com/pub/scm/network/connman/connman/+/1.14/doc/service-api.txt
 *  string State [readonly]
 *     The service state information.
 *     Valid states are "idle", "failure", "association", "configuration", "ready", "disconnect" and "online".
 */
var STATES = {
  IDLE: 'idle',
  FAILURE: 'failure',
  ASSOCIATION: 'association',
  CONFIGURATION: 'configuration',
  READY: 'ready',
  DISCONNECT: 'disconnect',
  ONLINE: 'online',
};

module.exports = WiFi;
module.exports.STATES = STATES;

function WiFi(connman) {
  Base.call(this);
  this.connman = connman;
}

util.inherits(WiFi, Base);

WiFi.prototype.init = function(callback) {
  debug("init");
  var self = this;
  // Retrieve WiFi technology
  // https://kernel.googlesource.com/pub/scm/network/connman/connman/+/1.14/doc/technology-api.txt
  var tech = self.connman.technologies.WiFi;
  if(tech === undefined) {
    if(callback) callback(new Error("No WiFi hardware available"));
    return;
  }
  _super.init.call(self,tech,function(err,properties) {
    if(properties.powered) { // already powered? 
      if(callback) callback(err,properties);
    } else {
      self.enable(function(err) {
        if(callback) callback(err,properties);
      });
    }
  });
  self.on('services',onServices);
};
WiFi.prototype.enable = function(callback) {
  this.setProperty('Powered', true, function(err) {
    // Sometimes this failes, our hypothesis is that 
    // this is usually caused by a shortage of power 
    if(err) {
      debug('[Error] Enabling wifi failed: ',err);
    }
    // delay, probably because of: https://01.org/jira/browse/CM-644
    setTimeout(callback, _timeoutWiFiEnable, err);
  });
};
WiFi.prototype.disable = function(callback) {
  this.setProperty('Powered', false, callback);
};
{'fraction_non_alphanumeric': 0.1520066541900603, 'fraction_numerical': 0.010605115408608859, 'mean_word_length': 3.6339113680154145, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, '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': '7336329', 'n_tokens_mistral': 1587, 'n_tokens_neox': 1528, 'n_words': 332}