<commit_before>/*
 * Boardfarm Management application
 * Copyright (c) 2016 <NAME> <<EMAIL>>
 *
 * License:
 *   MIT: https://opensource.org/licenses/MIT
 *   See the LICENSE file in the project's top-level directory for details.
 */

var power = require("./Power");
var ipower = require("./IPowerPort");
var exec = require('child_process').exec;

qx.Class.define("sn.boardfarm.backend.power.Ykush",
{
	extend : qx.core.Object,
	implement : [ sn.boardfarm.backend.power.IPowerAdapter ],

	construct : function(serial)
	{
		var pwr = sn.boardfarm.backend.power.Power.getInstance();

		console.log("Power: added Ykush hub " + serial);
		this.setAdapterIdent("ykush:"+serial);
		this.setSerial(serial);
		this.__states = { 0 : -1, 1 : -1, 2 : -1 };

		pwr.addAdapter(this.getAdapterIdent(), this);
	},

	events :
	{
		"adapterPowerChanged" : "qx.event.type.Data",
		"adapterPortStateChanged" : "qx.event.type.Data"
	},

	properties :
	{
		adapterIdent : {},
		serial : {}
	},

	members :
	{
		adapterReadPower : function()
		{
			/* can't read power measurements */
			this.fireDataEvent("adapterPowerChanged", 0);
		},

		__states : {},

		adapterReadState : function()
		{
			var child;
			var serial = this.getSerial();
			var base = this;
			child = exec("ykush -s " + serial + " -g a", function (error, stdout, stderr)
			{
				if (error !== null) {
					console.log("ykush command returned " + error);
					this.__states = { 0 : -1, 1 : -1, 2 : -1 };
					return;
				}

				var data = stdout.split("\n");
				for (var i = 0; i < 3; i++) {
					var state = (data[i].indexOf(": DOWN") != -1) ? 0 : 1;
					base.__states[i] = state;
				}
			});
		},

		__ports : {},

		adapterAddPort : function(port, obj)
		{
			if (this.__ports[port])
				throw "Port "+port+" already set on "+this.getIdent();

			this.__ports[port] = obj;
		},

		adapterGetPortNum : function()
		{
			 return 3;
		},

		adapterGetPort : function(port)
		{
			if (!this.__ports[port])
				throw "Port "+port+" not set on "+this.getIdent();

			return this.__ports[port];
		},

		adapterGetPortState : function(port)
		{
			return this.__states[port];
		},

		adapterSetPortState : function(port, newState)
		{
			var child;<commit_msg>YKush: use correct property in Exception strings<commit_after>/*
 * Boardfarm Management application
 * Copyright (c) 2016 <NAME> <<EMAIL>>
 *
 * License:
 *   MIT: https://opensource.org/licenses/MIT
 *   See the LICENSE file in the project's top-level directory for details.
 */

var power = require("./Power");
var ipower = require("./IPowerPort");
var exec = require('child_process').exec;

qx.Class.define("sn.boardfarm.backend.power.Ykush",
{
	extend : qx.core.Object,
	implement : [ sn.boardfarm.backend.power.IPowerAdapter ],

	construct : function(serial)
	{
		var pwr = sn.boardfarm.backend.power.Power.getInstance();

		console.log("Power: added Ykush hub " + serial);
		this.setAdapterIdent("ykush:"+serial);
		this.setSerial(serial);
		this.__states = { 0 : -1, 1 : -1, 2 : -1 };

		pwr.addAdapter(this.getAdapterIdent(), this);
	},

	events :
	{
		"adapterPowerChanged" : "qx.event.type.Data",
		"adapterPortStateChanged" : "qx.event.type.Data"
	},

	properties :
	{
		adapterIdent : {},
		serial : {}
	},

	members :
	{
		adapterReadPower : function()
		{
			/* can't read power measurements */
			this.fireDataEvent("adapterPowerChanged", 0);
		},

		__states : {},

		adapterReadState : function()
		{
			var child;
			var serial = this.getSerial();
			var base = this;
			child = exec("ykush -s " + serial + " -g a", function (error, stdout, stderr)
			{
				if (error !== null) {
					console.log("ykush command returned " + error);
					this.__states = { 0 : -1, 1 : -1, 2 : -1 };
					return;
				}

				var data = stdout.split("\n");
				for (var i = 0; i < 3; i++) {
					var state = (data[i].indexOf(": DOWN") != -1) ? 0 : 1;
					base.__states[i] = state;
				}
			});
		},

		__ports : {},

		adapterAddPort : function(port, obj)
		{
			if (this.__ports[port])
				throw "Port "+port+" already set on "+this.getAdapterIdent();

			this.__ports[port] = obj;
		},

		adapterGetPortNum : function()
		{
			 return 3;
		},

		adapterGetPort : function(port)
		{
			if (!this.__ports[port])
				throw "Port "+port+" not set on "+this.getAdapterIdent();

			return this.__ports[port];
		},

		adapterGetPortState : function(port)
		{
			return this.__states[port];
		},

		adapterSetPortState : function(port, newState)
		{
			var child;
{'fraction_non_alphanumeric': 0.16730123180291154, 'fraction_numerical': 0.010302351623740201, 'mean_word_length': 3.0860018298261664, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 2, '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': '5004986', 'n_tokens_mistral': 1812, 'n_tokens_neox': 1532, 'n_words': 347}