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

jacdac-ts

Package Overview
Dependencies
Maintainers
1
Versions
497
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jacdac-ts - npm Package Compare versions

Comparing version 1.0.11 to 1.0.12

dist/types/buffer.d.ts

42

dist/types/constants.d.ts

@@ -20,2 +20,5 @@ export declare const REG_INTENSITY = 1;

export declare const CMD_CTRL_RESET = 130;
export declare const CMD_CONSOLE_REG = 128;
export declare const CMD_CONSOLE_MESSAGE_DBG = 128;
export declare const CMD_CONSOLE_SET_MIN_PRIORITY: number;
export declare const STREAM_PORT_SHIFT = 7;

@@ -35,3 +38,3 @@ export declare const STREAM_COUNTER_MASK = 31;

export declare const JD_FRAME_FLAG_IDENTIFIER_IS_SERVICE_CLASS = 4;
export declare const enum ConsolePriority {
export declare enum ConsolePriority {
Debug = 0,

@@ -43,1 +46,38 @@ Log = 1,

}
/** known service numbers */
export declare const JD_SERVICE_CTRL = 0;
export declare const JD_SERVICE_LOGGER = 316415946;
export declare const JD_SERVICE_BATTERY = 489302733;
export declare const JD_SERVICE_ACCELEROMETER = 521405449;
export declare const JD_SERVICE_BUTTON = 343122531;
export declare const JD_SERVICE_TOUCHBUTTON = 319616446;
export declare const JD_SERVICE_LIGHT_SENSOR = 367501567;
export declare const JD_SERVICE_MICROPHONE = 442259558;
export declare const JD_SERVICE_THERMOMETER = 337754823;
export declare const JD_SERVICE_SWITCH = 337740146;
export declare const JD_SERVICE_PIXEL = 392756159;
export declare const JD_SERVICE_HAPTIC = 292230307;
export declare const JD_SERVICE_LIGHT = 309264608;
export declare const JD_SERVICE_KEYBOARD = 451182893;
export declare const JD_SERVICE_MOUSE = 347903935;
export declare const JD_SERVICE_GAMEPAD = 268773352;
export declare const JD_SERVICE_MUSIC = 458731991;
export declare const JD_SERVICE_SERVO = 318542083;
export declare const JD_SERVICE_CONTROLLER = 411755704;
export declare const JD_SERVICE_LCD = 416622668;
export declare const JD_SERVICE_MESSAGE_BUS = 291286005;
export declare const JD_SERVICE_COLOR_SENSOR = 349625762;
export declare const JD_SERVICE_LIGHT_SPECTRUM_SENSOR = 385485837;
export declare const JD_SERVICE_PROXIMITY = 348223771;
export declare const JD_SERVICE_TOUCH_BUTTONS = 449530325;
export declare const JD_SERVICE_SERVOS = 405375192;
export declare const JD_SERVICE_ROTARY_ENCODER = 284830153;
export declare const JD_SERVICE_DNS = 293022141;
export declare const JD_SERVICE_PWM_LIGHT = 531985491;
export declare const JD_SERVICE_BOOTLOADER = 536516936;
export declare const JD_SERVICE_ARCADE_CONTROLS = 501915758;
export declare const JD_SERVICE_POWER = 530893146;
export declare const JD_SERVICE_SLIDER = 522667846;
export declare const JD_SERVICE_MOTOR = 385895640;
export declare const JD_SERVICE_TCP = 457422603;
export declare const JD_SERVICE_WIFI = 413852154;

15

dist/types/device.d.ts

@@ -23,2 +23,8 @@ /// <reference types="node" />

/**
* Event containing an event from a sensor
* @param event
* @param listener
*/
on(event: 'packetevent', listener: (packet: Packet) => void): boolean;
/**
* Event emitted when a device is detected on the bus. The information on the device might not be fully populated yet.

@@ -40,3 +46,3 @@ * @param event

*/
on(event: 'announce', listener: (device: Device) => void): boolean;
on(event: 'deviceannounce', listener: (device: Device) => void): boolean;
}

@@ -52,3 +58,3 @@ /**

private _gcInterval;
consolePriority: ConsolePriority;
private _minConsolePriority;
/**

@@ -60,2 +66,5 @@ * Creates the bus with the given transport

get timestamp(): number;
get minConsolePriority(): ConsolePriority;
set minConsolePriority(priority: ConsolePriority);
private pingLoggers;
sendPacket(p: Packet): Promise<void>;

@@ -83,3 +92,3 @@ disconnect(): Promise<void>;

lookupName(id: string): string;
log(msg: any, ...optionalArgs: any[]): void;
log(msg: any): void;
}

@@ -86,0 +95,0 @@ export declare class Device {

export * from './constants';
export * from './utils';
export * from './buffer';
export * from './msgpack';
export * from './struct';
export * from './eventemitter';
export * from './utils';
export * from './packet';
export * from './device';
export * from './hf2';
export * from './sensor';
export * from './pretty';

@@ -1,3 +0,3 @@

import { NumberFormat } from "./utils";
import { Device, Bus } from "./device";
import { NumberFormat } from "./buffer";
export declare class Packet {

@@ -43,2 +43,3 @@ _header: Uint8Array;

static fromFrame(frame: Uint8Array, timestamp: number): Packet[];
static packed(service_command: number, fmt: string, nums: number[]): Packet;
}
import { Packet } from "./packet";
import { Device } from "./device";
export declare function decodePacketData(pkt: Packet): string;
export declare function serviceName(n: number): string;

@@ -4,0 +5,0 @@ export declare function commandName(n: number): string;

@@ -43,21 +43,2 @@ export declare function error(msg: string): void;

export declare function decodeU32LE(buf: Uint8Array): number[];
export declare const enum NumberFormat {
Int8LE = 1,
UInt8LE = 2,
Int16LE = 3,
UInt16LE = 4,
Int32LE = 5,
Int8BE = 6,
UInt8BE = 7,
Int16BE = 8,
UInt16BE = 9,
Int32BE = 10,
UInt32LE = 11,
UInt32BE = 12,
Float32LE = 13,
Float64LE = 14,
Float32BE = 15,
Float64BE = 16
}
export declare function getNumber(buf: ArrayLike<number>, fmt: NumberFormat, offset: number): number;
export declare function bufferToString(buf: Uint8Array): string;

@@ -64,0 +45,0 @@ export declare function bufferConcat(a: Uint8Array, b: Uint8Array): Uint8Array;

{
"name": "jacdac-ts",
"version": "1.0.11",
"version": "1.0.12",
"description": "",

@@ -5,0 +5,0 @@ "keywords": [],

@@ -53,2 +53,6 @@

export const CMD_CONSOLE_REG = 0x80
export const CMD_CONSOLE_MESSAGE_DBG = 0x80
export const CMD_CONSOLE_SET_MIN_PRIORITY = 0x2000 | CMD_CONSOLE_REG
export const STREAM_PORT_SHIFT = 7

@@ -76,3 +80,3 @@ export const STREAM_COUNTER_MASK = 0x001f

export const enum ConsolePriority {
export enum ConsolePriority {
Debug = 0,

@@ -83,2 +87,40 @@ Log = 1,

Silent = 4
}
}
/** known service numbers */
export const JD_SERVICE_CTRL = 0;
export const JD_SERVICE_LOGGER = 0x12dc1fca;
export const JD_SERVICE_BATTERY = 0x1d2a2acd;
export const JD_SERVICE_ACCELEROMETER = 0x1f140409;
export const JD_SERVICE_BUTTON = 0x1473a263;
export const JD_SERVICE_TOUCHBUTTON = 0x130cf5be;
export const JD_SERVICE_LIGHT_SENSOR = 0x15e7a0ff;
export const JD_SERVICE_MICROPHONE = 0x1a5c5866;
export const JD_SERVICE_THERMOMETER = 0x1421bac7;
export const JD_SERVICE_SWITCH = 0x14218172;
export const JD_SERVICE_PIXEL = 0x1768fbbf;
export const JD_SERVICE_HAPTIC = 0x116b14a3;
export const JD_SERVICE_LIGHT = 0x126f00e0;
export const JD_SERVICE_KEYBOARD = 0x1ae4812d;
export const JD_SERVICE_MOUSE = 0x14bc97bf;
export const JD_SERVICE_GAMEPAD = 0x100527e8;
export const JD_SERVICE_MUSIC = 0x1b57b1d7;
export const JD_SERVICE_SERVO = 0x12fc9103;
export const JD_SERVICE_CONTROLLER = 0x188ae4b8;
export const JD_SERVICE_LCD = 0x18d5284c;
export const JD_SERVICE_MESSAGE_BUS = 0x115cabf5;
export const JD_SERVICE_COLOR_SENSOR = 0x14d6dda2;
export const JD_SERVICE_LIGHT_SPECTRUM_SENSOR = 0x16fa0c0d;
export const JD_SERVICE_PROXIMITY = 0x14c1791b;
export const JD_SERVICE_TOUCH_BUTTONS = 0x1acb49d5;
export const JD_SERVICE_SERVOS = 0x182988d8;
export const JD_SERVICE_ROTARY_ENCODER = 0x10fa29c9;
export const JD_SERVICE_DNS = 0x117729bd;
export const JD_SERVICE_PWM_LIGHT = 0x1fb57453;
export const JD_SERVICE_BOOTLOADER = 0x1ffa9948;
export const JD_SERVICE_ARCADE_CONTROLS = 0x1deaa06e;
export const JD_SERVICE_POWER = 0x1fa4c95a;
export const JD_SERVICE_SLIDER = 0x1f274746;
export const JD_SERVICE_MOTOR = 0x17004cd8;
export const JD_SERVICE_TCP = 0x1b43b70b;
export const JD_SERVICE_WIFI = 0x18aae1fa;
import { Packet } from "./packet"
import { JD_SERVICE_NUMBER_CTRL, CMD_ADVERTISEMENT_DATA, ConsolePriority } from "./constants"
import { hash, fromHex, idiv, getNumber, NumberFormat, read32, SMap, bufferEq } from "./utils"
import { JD_SERVICE_NUMBER_CTRL, CMD_ADVERTISEMENT_DATA, ConsolePriority, CMD_CONSOLE_SET_MIN_PRIORITY, JD_SERVICE_LOGGER, CMD_EVENT } from "./constants"
import { hash, fromHex, idiv, read32, SMap, bufferEq } from "./utils"
import { EventEmitter } from "./eventemitter"
import { getNumber, NumberFormat } from "./buffer";

@@ -27,2 +28,9 @@ export interface BusOptions {

/**
* Event containing an event from a sensor
* @param event
* @param listener
*/
on(event: 'packetevent', listener: (packet: Packet) => void): boolean;
/**
* Event emitted when a device is detected on the bus. The information on the device might not be fully populated yet.

@@ -46,3 +54,3 @@ * @param event

*/
on(event: 'announce', listener: (device: Device) => void): boolean;
on(event: 'deviceannounce', listener: (device: Device) => void): boolean;
}

@@ -58,3 +66,3 @@

private _gcInterval: any;
consolePriority = ConsolePriority.Log;
private _minConsolePriority = ConsolePriority.Log;

@@ -68,2 +76,4 @@ /**

this._startTime = Date.now();
this.on('deviceannounce', () => this.pingLoggers());
}

@@ -75,2 +85,19 @@

get minConsolePriority(): ConsolePriority {
return this._minConsolePriority;
}
set minConsolePriority(priority: ConsolePriority) {
if (priority !== this._minConsolePriority) {
this._minConsolePriority = priority;
}
}
private pingLoggers() {
if (this._minConsolePriority < ConsolePriority.Silent) {
const pkt = Packet.packed(CMD_CONSOLE_SET_MIN_PRIORITY, "i", [this._minConsolePriority]);
pkt.sendAsMultiCommandAsync(this, JD_SERVICE_LOGGER);
}
}
sendPacket(p: Packet) {

@@ -142,3 +169,3 @@ return this.options.sendPacket(p);

dev.lastServiceUpdate = pkt.timestamp
this.emit('announce', dev);
this.emit('deviceannounce', dev);
}

@@ -148,3 +175,6 @@ }

}
this.emit('packet', pkt)
// don't spam with duplicate advertisement events
if (pkt.service_command !== CMD_ADVERTISEMENT_DATA) {
this.emit('packet', pkt)
}
}

@@ -160,10 +190,9 @@

log(msg: any, ...optionalArgs: any[]) {
if (this.consolePriority > ConsolePriority.Log)
log(msg: any) {
if (this._minConsolePriority > ConsolePriority.Log)
return
console.log(msg, optionalArgs);
console.log(msg);
}
}
export class Device {

@@ -170,0 +199,0 @@ connected: boolean;

export * from './constants'
export * from './utils'
export * from './buffer'
export * from './msgpack'
export * from './struct'
export * from './eventemitter'
export * from './utils'
export * from './packet'
export * from './device'
export * from './hf2'
export * from './sensor'
export * from './pretty'

@@ -1,2 +0,2 @@

import { warn, crc, ALIGN, write16, bufferConcat, toHex, fromHex, error, read32, read16, NumberFormat, getNumber, write32 } from "./utils";
import { warn, crc, ALIGN, write16, bufferConcat, toHex, fromHex, error, read32, read16, write32 } from "./utils";
import {

@@ -13,2 +13,4 @@ JD_FRAME_FLAG_COMMAND,

import { Device, Bus } from "./device";
import { NumberFormat, getNumber } from "./buffer";
import { pack } from "./struct";

@@ -221,2 +223,6 @@ export class Packet {

}
static packed(service_command: number, fmt: string, nums: number[]) {
return Packet.from(service_command, pack(fmt, nums))
}
}

@@ -223,0 +229,0 @@

@@ -9,37 +9,37 @@ import * as U from "./utils"

CTRL: 0,
LOGGER: 0x12dc1fca,
BATTERY: 0x1d2a2acd,
ACCELEROMETER: 0x1f140409,
BUTTON: 0x1473a263,
TOUCHBUTTON: 0x130cf5be,
LIGHT_SENSOR: 0x15e7a0ff,
MICROPHONE: 0x1a5c5866,
THERMOMETER: 0x1421bac7,
SWITCH: 0x14218172,
PIXEL: 0x1768fbbf,
HAPTIC: 0x116b14a3,
LIGHT: 0x126f00e0,
KEYBOARD: 0x1ae4812d,
MOUSE: 0x14bc97bf,
GAMEPAD: 0x100527e8,
MUSIC: 0x1b57b1d7,
SERVO: 0x12fc9103,
CONTROLLER: 0x188ae4b8,
LCD: 0x18d5284c,
MESSAGE_BUS: 0x115cabf5,
COLOR_SENSOR: 0x14d6dda2,
LIGHT_SPECTRUM_SENSOR: 0x16fa0c0d,
PROXIMITY: 0x14c1791b,
TOUCH_BUTTONS: 0x1acb49d5,
SERVOS: 0x182988d8,
ROTARY_ENCODER: 0x10fa29c9,
DNS: 0x117729bd,
PWM_LIGHT: 0x1fb57453,
BOOTLOADER: 0x1ffa9948,
ARCADE_CONTROLS: 0x1deaa06e,
POWER: 0x1fa4c95a,
SLIDER: 0x1f274746,
MOTOR: 0x17004cd8,
TCP: 0x1b43b70b,
WIFI: 0x18aae1fa,
LOGGER: jd.JD_SERVICE_LOGGER,
BATTERY: jd.JD_SERVICE_BATTERY,
ACCELEROMETER: jd.JD_SERVICE_ACCELEROMETER,
BUTTON: jd.JD_SERVICE_BUTTON,
TOUCHBUTTON: jd.JD_SERVICE_TOUCHBUTTON,
LIGHT_SENSOR: jd.JD_SERVICE_LIGHT_SENSOR,
MICROPHONE: jd.JD_SERVICE_MICROPHONE,
THERMOMETER: jd.JD_SERVICE_THERMOMETER,
SWITCH: jd.JD_SERVICE_SWITCH,
PIXEL: jd.JD_SERVICE_PIXEL,
HAPTIC: jd.JD_SERVICE_HAPTIC,
LIGHT: jd.JD_SERVICE_LIGHT,
KEYBOARD: jd.JD_SERVICE_KEYBOARD,
MOUSE: jd.JD_SERVICE_MOUSE,
GAMEPAD: jd.JD_SERVICE_GAMEPAD,
MUSIC: jd.JD_SERVICE_MUSIC,
SERVO: jd.JD_SERVICE_SERVO,
CONTROLLER: jd.JD_SERVICE_CONTROLLER,
LCD: jd.JD_SERVICE_LCD,
MESSAGE_BUS: jd.JD_SERVICE_MESSAGE_BUS,
COLOR_SENSOR: jd.JD_SERVICE_COLOR_SENSOR,
LIGHT_SPECTRUM_SENSOR: jd.JD_SERVICE_LIGHT_SPECTRUM_SENSOR,
PROXIMITY: jd.JD_SERVICE_PROXIMITY,
TOUCH_BUTTONS: jd.JD_SERVICE_TOUCH_BUTTONS,
SERVOS: jd.JD_SERVICE_SERVOS,
ROTARY_ENCODER: jd.JD_SERVICE_ROTARY_ENCODER,
DNS: jd.JD_SERVICE_DNS,
PWM_LIGHT: jd.JD_SERVICE_PWM_LIGHT,
BOOTLOADER: jd.JD_SERVICE_BOOTLOADER,
ARCADE_CONTROLS: jd.JD_SERVICE_ARCADE_CONTROLS,
POWER: jd.JD_SERVICE_POWER,
SLIDER: jd.JD_SERVICE_SLIDER,
MOTOR: jd.JD_SERVICE_MOTOR,
TCP: jd.JD_SERVICE_TCP,
WIFI: jd.JD_SERVICE_WIFI,
}

@@ -88,2 +88,9 @@

export function decodePacketData(pkt: Packet): string {
const serv_id = serviceName(pkt?.dev?.serviceClassAt(pkt.service_number));
const decoder = serv_decoders[serv_id];
const decoded = decoder ? decoder(pkt) : null
return decoded;
}
function reverseLookup(map: U.SMap<number>, n: number) {

@@ -90,0 +97,0 @@ for (let k of Object.keys(map)) {

@@ -279,42 +279,2 @@ export function error(msg: string) {

export const enum NumberFormat {
Int8LE = 1,
UInt8LE = 2,
Int16LE = 3,
UInt16LE = 4,
Int32LE = 5,
Int8BE = 6,
UInt8BE = 7,
Int16BE = 8,
UInt16BE = 9,
Int32BE = 10,
UInt32LE = 11,
UInt32BE = 12,
Float32LE = 13,
Float64LE = 14,
Float32BE = 15,
Float64BE = 16,
}
export function getNumber(buf: ArrayLike<number>, fmt: NumberFormat, offset: number) {
switch (fmt) {
case NumberFormat.UInt8BE:
case NumberFormat.UInt8LE:
return buf[offset]
case NumberFormat.Int8BE:
case NumberFormat.Int8LE:
return (buf[offset] << 24) >> 24
case NumberFormat.UInt16LE:
return read16(buf, offset)
case NumberFormat.Int16LE:
return (read16(buf, offset) << 16) >> 16
case NumberFormat.UInt32LE:
return read32(buf, offset)
case NumberFormat.Int32LE:
return read32(buf, offset) >> 0
default:
throw new Error("unsupported fmt:" + fmt)
}
}
export function bufferToString(buf: Uint8Array) {

@@ -321,0 +281,0 @@ return fromUTF8(uint8ArrayToString(buf))

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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