<commit_before>'use strict';
const personalData = require('./personalData');
const webModel = require('./webModel');
const webModelFunctions = require('./webModelFunctions');
const robotModel = require('./robotModel');
const spawn = require('child_process').spawn;
const ipAddress = require('./ipAddress');

/*
 To get the state of all relays:
 switch_relay_name.sh all state
 Use this to populate a list of relays in webModel,
 and also get their names from
 personalData.relays
 */

class UsbRelay {
    constructor() {
        this.dataHolder = '';
        this.busy = false;
        this.script = __dirname + '/../scripts/switch_relay_name.sh';
        this.updateAllRelayState();
    }

    static findRelayName(relayNumber) {
        for (let key in personalData.relays) {
            if (personalData.relays.hasOwnProperty(key)) {
                if (personalData.relays[key] === relayNumber) {
                    return key;
                }
            }
        }
        return 'empty';
    }

    updateAllRelayState() {
        if (!this.busy) {
            this.busy = true;
            const process = spawn(this.script, ['all', 'state']);
            process.stdout.on('data', (data) => {
                if (data != '') {
                    this.dataHolder += data;
                }
            });

            process.stderr.on('data', (data) => {
                console.log(`UsbRelay output stderr: ${data}`);
            });

            process.on('close', (code) => {
                if (code === null || code === 0) {
                    let linesArray = this.dataHolder.split('\n');
                    let relayStatusArray = [];<commit_msg>Prevent node backend from checking USB Relay controller when it is disabled in personal settings.<commit_after>'use strict';
const personalData = require('./personalData');
const webModel = require('./webModel');
const webModelFunctions = require('./webModelFunctions');
const robotModel = require('./robotModel');
const spawn = require('child_process').spawn;
const ipAddress = require('./ipAddress');

/*
 To get the state of all relays:
 switch_relay_name.sh all state
 Use this to populate a list of relays in webModel,
 and also get their names from
 personalData.relays
 */

class UsbRelay {
    constructor() {
        this.dataHolder = '';
        this.busy = false;
        this.script = __dirname + '/../scripts/switch_relay_name.sh';
        this.updateAllRelayState();
    }

    static findRelayName(relayNumber) {
        for (let key in personalData.relays) {
            if (personalData.relays.hasOwnProperty(key)) {
                if (personalData.relays[key] === relayNumber) {
                    return key;
                }
            }
        }
        return 'empty';
    }

    updateAllRelayState() {
        if (personalData.useUSBrelay && !this.busy) {
            this.busy = true;
            const process = spawn(this.script, ['all', 'state']);
            process.stdout.on('data', (data) => {
                if (data != '') {
                    this.dataHolder += data;
                }
            });

            process.stderr.on('data', (data) => {
                console.log(`UsbRelay output stderr: ${data}`);
            });

            process.on('close', (code) => {
                if (code === null || code === 0) {
                    let linesArray = this.dataHolder.split('\n');
                    let relayStatusArray = [];
{'fraction_non_alphanumeric': 0.1337579617834395, 'fraction_numerical': 0.0005790387955993051, 'mean_word_length': 1.9454390451832908, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '1271869', 'n_tokens_mistral': 950, 'n_tokens_neox': 923, 'n_words': 229}