DesktopSDK

Methods

abortDelay()

Use it to stop an active delay.

abortSubscriptions() → {Promise}

Removes all subscriptions so far recorded. Subscriptions are also created when you register for onData events. So calling this method will stop all your onData event listeners.

APICall(method, argvs, sourceBlock) → {Promise}

Executes a hardware API function.
Parameters:
Name Type Description
method String the name of the method to execute
argvs Array list of arguments expected by the method.
sourceBlock Object required (only) when calling block's functions. Contains a list of properties to identify the block.
Properties
Name Type Description
address Number the BCL address of the block
uid Object the block's uid

broadcast(room, data) → {Promise}

Part of the Broadcaster service. Sends data to all clients in the Kitsi net. Use this method to send data to other clients connected to the same Hub.
Parameters:
Name Type Description
room String the name of the room to broadcast to
data Any the data to transmit.
Example
// Sends a message to any client listening on the room
const {SDK} = require('KitsuneiSDK/kitsunei-desktop-sdk');
SDK.connect('127.0.0.1').then(async ()=>{
	await SDK.broadcast('testRoom', 'Hello');
	// Other clients should listen with:
	// await SDK.listen('testRoom', (data)=>{
	//	console.log("Sender said: ", data);
	// });
});

delay(the) → {Promise}

When used with 'await', pauses the execution for the given amount of time.
Parameters:
Name Type Description
the Number number of milliseconds to wait for
Example
// Waits 2 seconds before moving the car backwards
// After requiring the SDK and SDK.connect()....
moveCarForward();					// Unspecified method
await SDK.delay(2000);			// 2 seconds
moveCarBackwards(); 				// Unspecified method

listBlocks() → {Promise}

Returns a list of connected blocks regardless of the radio they are attached to.
Example
const {SDK} = require('KitsuneiSDK/kitsunei-desktop-sdk');
SDK.connect('127.0.0.1').then(async ()=>{
	var blocks = await SDK.listBlocks();
 console.log("Online Blocks: ", blocks);
});

listen(room, cb) → {Promise}

Broadcaster service Subscribes to a particular channel. use @broadcast() to send data to the channel
Parameters:
Name Type Description
room String the name of the room to listen data from
cb function an event handler to call when data is sent to the room.

listNodes() → {Promise}

Returns a Promise that will resolve with the list of connected nodes and their slave blocks

offData(block) → {Promise}

Terminates a subscription
Parameters:
Name Type Description
block Object the same object used when creating the onData subscription

onData(block, callback)

Registers an event listener to be called every time the hardware block produces data.
Parameters:
Name Type Description
block Object the representation of the block to listen data from. NOTE: This object will be modified and a property added to record the id of the subscription.
Properties
Name Type Description
address Number the BCL address
uid Object the blocks uid
Properties
Name Type Description
high Number
med Number
low Number
callback function the function to call when data is produced. Usually, the argument passed is an Object type but may vary depending on the block
Example
// Reads data from an IMU block
const {SDK, BlockType} = require('KitsuneiSDK/kitsunei-desktop-sdk');
SDK.connect('127.0.0.1').then(async ()=>{
	const imu = await SDK.waitForBlock(BlockType.IMU);
	SDK.onData(imu, function(data){
		console.log("X: %d, Y: %d, Z: %d", data.x, data.y, data.z);
	});
});

onError(cb)

Registers an event lister to overwrite all promise rejections
Parameters:
Name Type Description
cb function a function to call when an error occurs.

readSettings(block) → {Promise.<Object>}

Reads the settings from a hardware block
Parameters:
Name Type Description
block Object the block to read settings from
Properties
Name Type Description
uid Object the block's unique identifier
Example
const {SDK, BlockType} = require('KitsuneiSDK/kitsunei-desktop-sdk');
SDK.connect('127.0.0.1').then(async ()=>{
	const block = await SDK.waitForBlock(BlockType.IMU);
	const settings = await SDK.readSettings(block);
	console.log("Settings: ", settings);
});

saveSettings(block) → {Promise.<Object>}

Overwrites the settings of a hardware block
Parameters:
Name Type Description
block Object the block to save settings into
Properties
Name Type Description
uid Object the block's unique identifier
Example
// Disables the Block's LED blinking
const {SDK, BlockType} = require('KitsuneiSDK/kitsunei-desktop-sdk');
SDK.connect('127.0.0.1').then(async ()=>{
	const imuBlock = await SDK.waitForBlock(BlockType.IMU);
	const settings = await SDK.readSettings(imuBlock);
	settings.BlinkLED = 0;				// Disable blinking
	await SDK.saveSettings(imuBlock, settings);
});

stopListening(room) → {Promise}

Cancels a broadcaster event listener (@listen())
Parameters:
Name Type Description
room String the name of the room used to listen data from.

subscribe(eventName, block)

Used to subscribe to particular events issued by the Hub or blocks such as block connection/disconnection, network status, etc.
Parameters:
Name Type Description
eventName module:DesktopSDK.HubEvent the name of the event to listen for
block Object An object with all the valid Block properties. Use waitForBlock to obtain a valid object.
Properties
Name Type Description
uid Object The unique identifier of the block
Properties
Name Type Description
high Object
med Object
low Object
address Number The block's BCL address

waitForBlock(serial, optionsopt) → {Object}

Gets a list of online devices from the hub and checks if any of them has the same serial as the provided one.
Parameters:
Name Type Attributes Description
serial module:DesktopSDK.BlockType The block type to wait for.
options Object <optional>
An object that contains other properties to be matched.
Properties
Name Type Description
uid Object A block UID with high, low and med properties
Properties
Name Type Description
high Number
med Number
low Number
address Number The block's BCL address.
node Object An object with the properties of the node. Use it to specify that the block you are looking for MUST be connected to a node (radio) with the given properties.
Properties
Name Type Description
uid Object The radio's UID
Examples
// Waits for any temperature block
const {SDK, BlockType} = require('KitsuneiSDK/kitsunei-desktop-sdk');
SDK.connect('127.0.0.1').then(async ()=>{
	const serial = BlockType.Temperature;
	const temperature = await SDK.waitForBlock(serial);
	console.log("Temperature block online: ", temperature);
});
// Waits for a specific temperature block
const {SDK, BlockType} = require('KitsuneiSDK/kitsunei-desktop-sdk');
SDK.connect('127.0.0.1').then(async ()=>{
	const serial = BlockType.Temperature;
	const blockUid = {uid: {high: 123, med: 456, low: 789}};
	const temperature = await SDK.waitForBlock(serial, blockUid);
	console.log("Temperature block online: ", temperature);
});

waitForBlocks(list, optionsopt) → {Promise.<Array>}

Waits for the given list of block types to be loaded
Parameters:
Name Type Attributes Description
list Array.<module:DesktopSDK.BlockType> list of block types to wait for.
options Array.<Object> <optional>
an array of options that must match the amount of items in @list. It specifies additional properties to match against the found block such as uid, address, etc.

Type Definitions

BlockType :Number

Representation of all block types
Properties:
Name Type Description
WiFiRadio1 Number 48
WiFiRadio2 Number 49
MotorDriver Number 135
MotorDriver2 Number 134
IMU Number 130
Touch Number 125
IR2 Number 121
LEDMatrix Number 110
Temperature Number 105
Breadboard Number 136
PowerStation Number 145

HubEvent :String

Different type of events that can be subscribed to using @subscribe
Properties:
Name Type Description
"network:blockAdded" String Triggered when a new block is connected
"network:blockRemoved" String A block is disconnected
"network:blockActive" String Triggered every second to inform the block is still online and sending data.
"network:nodeAdded" String Triggered when a new radio type joins the network
"network:nodeRemoved" String Triggered when a radio type is disconnected
"network:status" String Triggered once with information about the network: number of radios and blocks