1.4.1 • Published 2 years ago

@mangar2/serialdevice v1.4.1

Weekly downloads
-
License
LGPL-3.0-or-later
Repository
github
Last release
2 years ago

Abstract

Interface service to communicate with several arduino or similar microcontroller based on a serial interface

Contents

Meta

Fileindex.js
AbstractInterface service to communicate with several arduino or similar microcontroller based on a serial interface
AuthorVolker Böhm
CopyrightCopyright ( c ) 2020 Volker Böhm
LicenseThis software is licensed under the GNU LESSER GENERAL PUBLIC LICENSE Version 3 . It is furnished "as is" , without any support , and with no warranty , express or implied , as to its usefulness for any purpose .

Callback definitions

Publish

Callback to publish messages to the mqtt broker

Publish Parameters

NameTypeDescription
messageMessagemessage to publish

Global functions

_deriveSubscribesFromCommandMap

readonly _deriveSubscribesFromCommandMap (commandMap, topicBegin, qos)

Creates a list of subscribes starting with topicBegin and ending with all strings of the commandMap

_deriveSubscribesFromCommandMap Parameters

NameTypeDescription
commandMapObjectmap commands to topic end strings
topicBeginstringbegin of the topic
qosnumberquality of service

_deriveSubscribesFromTopicMap

readonly _deriveSubscribesFromTopicMap (topicMap, qos) => {Object.<topic:qos>}

Derives subscriptions from a topic list

_deriveSubscribesFromTopicMap Parameters

NameTypeDescription
topicMapObject.<topic:string>object with topic properties
qos0, 1, 2quality of service for the subscription

_deriveSubscribesFromTopicMap returns

TypeDescription
Object.<topic:qos>object with topic : qos entries

lsb

lsb (value) => {integer}

Returns the number of the least significant bit of an integer

lsb Parameters

NameType
valueinteger

lsb returns

TypeDescription
integer-1 , if no bit set , else the position of the bit set ( starting with bit 0 )

prepare

prepare (config, serialDevice)

Creates a serial device object , if not already available

prepare Parameters

NameTypeAttributeDefaultDescription
configObjectserial device configuration settings
serialDeviceSerialDeviceoptionalnullserial device object

serialMessageToString

serialMessageToString (message) => {string}

Converts a serial message to a byte stream

serialMessageToString Parameters

NameTypeDescription
messageSerialMessagemessage to convert

serialMessageToString returns

TypeDescription
stringstring to transmit

switchMessageToString

switchMessageToString (message)

Calculates the switching string from a switch message

switchMessageToString Parameters

NameTypeDescription
messageSerialMessagemessage to convert

message properties

NameTypeDescription
valuenumbervalue used to identify the switch and the switching value

Class SerialDevice

new SerialDevice(options)

Creates a service class to communicate with several arduino over a serial bus

SerialDevice Parameters

NameTypeDescription
optionsObjectconfiguration options

options properties

NameTypeAttributeDefaultDescription
serialPortNamestringname of the port to use
baudrateintegeroptional57600baud rate to be used
qos0, 1, 2optional1quality of service to send messages
tracestringoptional'messages'trace level , supported : errors , messages , internal
keepAliveDelayInSecondsnumberoptional1delay between two keep alive messages to serial

SerialDevice Methods

_traceStringSendToSerial

_traceStringSendToSerial (serialString)

Traces a string send to the serial device

_traceStringSendToSerial Parameters
NameTypeDescription
serialStringstringstring send to serial device

close

async close ()

Stops the service

getSubscriptions

getSubscriptions () => {topic:qos}

Gets the list of required subscriptions for this service

getSubscriptions returns
TypeDescription
topic:qoslist of subscription strings

handleMessage

handleMessage (mqttMessage)

Processes an incoming mqtt message

handleMessage Parameters
NameTypeDescription
mqttMessageMessagemqtt message

on

on (event, callback)

Sets a callback .

on Parameters
NameTypeDescription
eventstringevent name ( not case sensitive ) for the callback ( supported : 'publish' )
callbackPublishfunction ( . . . parameter )
on throws
TypeDescription
Errorif the event is not supported
Errorif the callback is not 'function'

run

async run ()

Starts the server