Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lba-cli

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lba-cli - npm Package Compare versions

Comparing version 0.2.2 to 2.0.0

lib/arduino/arduino.d.ts

73

lib/commands/start.js

@@ -37,12 +37,13 @@ "use strict";

const prosim_1 = require("../prosim");
const Serial_1 = __importDefault(require("../Serial"));
const IOCP_1 = __importDefault(require("../IOCP"));
const logger = __importStar(require("../logger"));
const arduino = __importStar(require("../arduino"));
let store = {};
let pinToIOCP = {};
let pinToDevice = {};
let iocpToPin = {};
let invertedOutput = {};
let iocpToName = {};
let devicePinToType = {};
let iocpClient;
const devices = {};
const start = () => __awaiter(void 0, void 0, void 0, function* () {

@@ -55,4 +56,23 @@ logger.system('Starting...');

initLookups(controls);
initSerial(config);
logger.system('Connecting to IOCP server...');
iocpClient = new IOCP_1.default({
hostAddress: config.iocp.hostname,
port: config.iocp.port
});
yield iocpClient.connect();
logger.system('Initializing Arduino...');
yield arduino.initialize(config, handleArduinoEvent);
initIOCP(config);
logger.system(`
_ __ _ _____ _____ ______
| | /_/| | /\ |_ _| __ \| ____|
| | ___| |__ _ __ ____ _ __ / \ | | | |__) | |__
| | / _ \ '_ \| '__/ _//\| '_ \ / /\ \ | | | _ /| __|
| |___| __/ |_) | | | (//) | | | |/ ____ \ _| |_| | \ \| |____
|______\___|_.__/|_| \//__/|_| |_/_/ \_\_____|_| \_\______|
`.trim());
});

@@ -66,3 +86,5 @@ exports.start = start;

pinToIOCP[cc.pin] = cc.iocp;
pinToDevice[cc.pin] = cc.arduino || '';
iocpToName[cc.iocp] = kk;
devicePinToType[`${cc.arduino}::${cc.pin}`] = cc.type || '';
if (cc.inverted) {

@@ -74,37 +96,28 @@ invertedOutput[cc.iocp] = true;

};
const initSerial = (config) => __awaiter(void 0, void 0, void 0, function* () {
logger.system('Connecting to Arduino mega1...');
const mega1 = new Serial_1.default(config.arduino.mega1.path);
mega1.addListener(ee => {
const iocpVariable = pinToIOCP[ee.pin];
if (iocpVariable) {
exports.setValue(iocpVariable, parseInt(`${ee.value}`));
}
else {
logger.error(`Unassigned pin ${ee.pin}`);
}
});
devices.mega1 = mega1;
while (mega1.port.isOpen === false && mega1.isReady) {
const handleArduinoEvent = (ee) => {
const iocpVariable = pinToIOCP[ee.pin];
if (iocpVariable) {
exports.setValue(iocpVariable, parseInt(`${ee.value}`));
}
});
else {
console.log(ee);
logger.error(`Unassigned pin ${ee.pin}`);
}
};
const initIOCP = (config) => {
logger.system('Connecting to IOCP server...');
iocpClient = new IOCP_1.default({
hostAddress: config.iocp.hostname,
port: config.iocp.port
});
const iocpVariableSubscriptions = Object.values(config.controls)
.filter(cc => cc.type === 'led' || cc.type === 'guage')
.filter(cc => cc.type === 'led' || cc.type === 'gauge')
.map(cc => pinToIOCP[cc.pin])
.filter(cc => !!cc);
iocpClient.addVariableSubscriptions(iocpVariableSubscriptions, (iocpVariable, value) => {
iocpClient.addVariableSubscriptions(iocpVariableSubscriptions, (iocpVariable, value) => __awaiter(void 0, void 0, void 0, function* () {
const pin = iocpToPin[iocpVariable];
if (!pin) {
const device = pinToDevice[pin];
if (!pin || !device) {
return;
}
devices.mega1.send(pin, value);
const onLabel = value > 1 ? value : '[On]';
logger.debug(` > ${iocpToName[iocpVariable]} ${value === 0 ? '[Off]' : onLabel}`);
});
logger.debug(` -> ${iocpToName[iocpVariable]} ${value === 0 ? '[Off]' : onLabel}`);
const type = devicePinToType[`${device}::${pin}`] || '';
yield arduino.send(device, pin, type, value);
}));
};

@@ -120,3 +133,3 @@ const setValue = (iocpVariable, value) => __awaiter(void 0, void 0, void 0, function* () {

yield iocpClient.setVariable(iocpVariable, nextValue);
logger.debug(` > ${iocpToName[iocpVariable]} ${nextValue === 0 ? '[Off]' : '[On]'}`);
logger.debug(` <- ${iocpToName[iocpVariable]} ${nextValue === 0 ? '[Off]' : '[On]'}`);
}

@@ -123,0 +136,0 @@ }

@@ -137,9 +137,15 @@ "use strict";

if (message.startsWith('Arn.Resp:')) {
const chunks = message.replace('Arn.Resp:', '').replace(':', '').trim().split('=');
const iocpVariable = parseInt(chunks[0]);
const value = parseInt(chunks[1]);
const cb = this.subscriptions[iocpVariable];
if (cb) {
cb(iocpVariable, value);
}
message.replace('Arn.Resp:', '')
.trim()
.split(':')
.filter(cc => !!cc)
.forEach(cc => {
const chunks = cc.trim().split('=');
const iocpVariable = parseInt(chunks[0]);
const value = parseInt(chunks[1]);
const cb = this.subscriptions[iocpVariable];
if (cb) {
cb(iocpVariable, value);
}
});
}

@@ -146,0 +152,0 @@ }

@@ -24,2 +24,3 @@ import { LbaConfig } from './types';

inverted: boolean;
type: string | undefined;
};

@@ -26,0 +27,0 @@ }

@@ -52,3 +52,4 @@ "use strict";

pin: control.pin,
inverted: control.inverted || false
inverted: control.inverted || false,
type: control.type
}

@@ -55,0 +56,0 @@ };

@@ -13,3 +13,3 @@ export interface LbaConfig {

}
interface ArduinoConfig {
export interface ArduinoConfig {
[name: string]: {

@@ -26,3 +26,3 @@ path: string;

inverted?: boolean;
type?: 'led' | 'guage';
type?: 'led' | 'gauge' | 'switch';
}

@@ -29,0 +29,0 @@ export interface ControlsStore {

{
"name": "lba-cli",
"version": "0.2.2",
"version": "2.0.0",
"author": "Lebronaire",

@@ -5,0 +5,0 @@ "repository": "https://github.com/lebronaire/flight-control-system/tree/main/packages/cli",

import { getConfig } from '../config';
import { prosimIOCPMapping, ProsimIOCP } from '../prosim';
import Serial from '../Serial';
import IOCP from '../IOCP';
import { ControlsStore, LbaConfig } from '../types';
import * as logger from '../logger';
import * as arduino from '../arduino';
import { SerialDataEvent } from '../arduino/Serial';
let store: ControlsStore = {};
let pinToIOCP: { [pin: number]: number } = {};
let pinToDevice: { [pin: number]: string } = {};
let iocpToPin: { [iocpVariable: number]: number } = {};
let invertedOutput: { [iocpVariable: number]: boolean } = {};
let iocpToName: { [iocpVariable: number]: string } = {};
let devicePinToType: { [devicePin: string]: string } = {};
let iocpClient: IOCP;
const devices: { [name: string]: Serial } = {};

@@ -27,4 +29,27 @@ export const start = async () => {

initLookups(controls);
initSerial(config);
logger.system('Connecting to IOCP server...');
iocpClient = new IOCP({
hostAddress: config.iocp.hostname,
port: config.iocp.port
});
await iocpClient.connect();
logger.system('Initializing Arduino...');
await arduino.initialize(config, handleArduinoEvent);
initIOCP(config);
logger.system(`
_ __ _ _____ _____ ______
| | /_/| | /\ |_ _| __ \| ____|
| | ___| |__ _ __ ____ _ __ / \ | | | |__) | |__
| | / _ \ '_ \| '__/ _//\| '_ \ / /\ \ | | | _ /| __|
| |___| __/ |_) | | | (//) | | | |/ ____ \ _| |_| | \ \| |____
|______\___|_.__/|_| \//__/|_| |_/_/ \_\_____|_| \_\______|
`.trim());
};

@@ -39,3 +64,5 @@

pinToIOCP[cc.pin] = cc.iocp;
pinToDevice[cc.pin] = cc.arduino || '';
iocpToName[cc.iocp] = kk;
devicePinToType[`${cc.arduino}::${cc.pin}`] = cc.type || '';

@@ -49,42 +76,27 @@ if (cc.inverted) {

const initSerial = async (config: LbaConfig): Promise<void> => {
logger.system('Connecting to Arduino mega1...');
const mega1 = new Serial(config.arduino.mega1.path);
const handleArduinoEvent = (ee: SerialDataEvent) => {
const iocpVariable = pinToIOCP[ee.pin];
mega1.addListener(ee => {
const iocpVariable = pinToIOCP[ee.pin];
if (iocpVariable) {
setValue(iocpVariable, parseInt(`${ee.value}`));
}
else {
// TODO: Map these correctly in prosim or update the config.xml
logger.error(`Unassigned pin ${ee.pin}`);
}
});
devices.mega1 = mega1;
while (mega1.port.isOpen === false && mega1.isReady) {
// wait...
if (iocpVariable) {
setValue(iocpVariable, parseInt(`${ee.value}`));
}
else {
// TODO: Map these correctly in prosim or update the config.xml
console.log(ee);
logger.error(`Unassigned pin ${ee.pin}`);
}
};
const initIOCP = (config: LbaConfig) => {
logger.system('Connecting to IOCP server...');
iocpClient = new IOCP({
hostAddress: config.iocp.hostname,
port: config.iocp.port
});
const iocpVariableSubscriptions = Object.values(config.controls)
.filter(cc => cc.type === 'led' || cc.type === 'guage')
.filter(cc => cc.type === 'led' || cc.type === 'gauge')
.map(cc => pinToIOCP[cc.pin])
.filter(cc => !!cc);
iocpClient.addVariableSubscriptions(iocpVariableSubscriptions, (iocpVariable: number, value: number) => {
iocpClient.addVariableSubscriptions(iocpVariableSubscriptions, async (iocpVariable: number, value: number) => {
// Send new value to the appropriate pin via serial
const pin = iocpToPin[iocpVariable];
const device = pinToDevice[pin];
if (!pin) {
if (!pin || !device) {
// Don't know the pin so can't do anything with the information

@@ -94,7 +106,8 @@ return;

devices.mega1.send(pin, value);
const onLabel = value > 1 ? value : '[On]';
logger.debug(` > ${iocpToName[iocpVariable]} ${value === 0 ? '[Off]' : onLabel}`);
logger.debug(` -> ${iocpToName[iocpVariable]} ${value === 0 ? '[Off]' : onLabel}`);
const type = devicePinToType[`${device}::${pin}`] || '';
await arduino.send(device, pin, type, value);
});

@@ -115,3 +128,3 @@ };

logger.debug(` > ${iocpToName[iocpVariable]} ${nextValue === 0 ? '[Off]' : '[On]'}`);
logger.debug(` <- ${iocpToName[iocpVariable]} ${nextValue === 0 ? '[Off]' : '[On]'}`);
}

@@ -118,0 +131,0 @@ } catch (error) {

@@ -152,13 +152,19 @@ import net from 'net';

if (message.startsWith('Arn.Resp:')) {
const chunks = message.replace('Arn.Resp:', '').replace(':', '').trim().split('=');
const iocpVariable: IOCPVariable = parseInt(chunks[0]);
const value: number = parseInt(chunks[1]);
message.replace('Arn.Resp:', '')
.trim()
.split(':')
.filter(cc => !!cc)
.forEach(cc => {
const chunks = cc.trim().split('=');
const iocpVariable: IOCPVariable = parseInt(chunks[0]);
const value: number = parseInt(chunks[1]);
const cb = this.subscriptions[iocpVariable];
const cb = this.subscriptions[iocpVariable];
if (cb) {
cb(iocpVariable, value);
}
if (cb) {
cb(iocpVariable, value);
}
});
}
}
}

@@ -30,2 +30,3 @@ import path from 'path';

inverted: boolean;
type: string | undefined;
};

@@ -73,3 +74,4 @@ };

pin: control.pin,
inverted: control.inverted || false
inverted: control.inverted || false,
type: control.type
}

@@ -76,0 +78,0 @@ };

@@ -15,3 +15,3 @@ export interface LbaConfig {

interface ArduinoConfig {
export interface ArduinoConfig {
[name: string]: {

@@ -30,3 +30,3 @@ path: string;

inverted?: boolean;
type?: 'led' | 'guage';
type?: 'led' | 'gauge' | 'switch';
}

@@ -33,0 +33,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc