@jprayner/piconet-nodejs / Modules / driver
- addListener
- close
- connect
- eventQueueCreate
- eventQueueDestroy
- eventQueueShift
- eventQueueWait
- readStatus
- removeListener
- setDebugEnabled
- setEconetStation
- setMode
- transmit
- waitForEvent
Ƭ EventMatcher: (event
: EconetEvent
) => boolean
▸ (event
): boolean
Use to filter events from the Econet driver.
Name | Type |
---|---|
event |
EconetEvent |
boolean
Ƭ EventQueue: Object
Holds an ordered set of events.
Name | Type |
---|---|
events |
EconetEvent [] |
listener |
Listener |
Ƭ Listener: (event
: EconetEvent
) => void
▸ (event
): void
Used to register a listener for events from the Econet driver.
Name | Type |
---|---|
event |
EconetEvent |
void
▸ addListener(listener
): void
Adds a new listener for events generated by the board.
Name | Type | Description |
---|---|---|
listener |
Listener |
The listener to add. |
void
▸ close(): Promise
<void
>
Disconnects from the board and closes the serial port.
Promise
<void
>
▸ connect(requestedDevice?
): Promise
<void
>
Connect the driver to the Piconet board.
This function must be successfully called before interacting with the Econet driver. The following steps are carried out:
- Open a serial connection to the board. If
requestedDevice
is not specified then an attempt will be made to autodetect it. This step may fail if the board is not connected or another application is using it. - The driver will then send a
STATUS
command to the board. This step may fail if the Raspberry Pi Pico has not been flashed with correct firmware (.uf2 image). - The driver will then compare the firmware version returned by the board against that of the driver using semantic versioning. If the versions are not compatible then an error will be thrown.
After connecting, the board will be in the STOP
operating mode. Remember to call setMode to
start it doing useful work.
Name | Type | Description |
---|---|---|
requestedDevice? |
string |
Optionally specifies the serial device for the Raspberry Pi Pico on the Piconet board. If left undefined then an attempt will be made to automatically detect it. |
Promise
<void
>
▸ eventQueueCreate(matcher
): EventQueue
Creates an event queue to store all events matching the specified criteria, ready for collection at the caller's convenience.
The queue should be destroyed using eventQueueDestroy when it is no longer needed to avoid consuming memory unnecessarily.
Name | Type | Description |
---|---|---|
matcher |
EventMatcher |
Specifies which events should be stored in the queue. |
A queue object which can be passed to the other eventQueueXXX
functions.
▸ eventQueueDestroy(queue
): void
Removes all events from queue and removes listener, preventing new events from being added.
Name | Type | Description |
---|---|---|
queue |
EventQueue |
The queue to destroy. |
void
▸ eventQueueShift(queue
): undefined
| EconetEvent
Removes an event from the queue, if one is available. Otherwise returns undefined
.
Name | Type | Description |
---|---|---|
queue |
EventQueue |
Queue to shift from. |
undefined
| EconetEvent
▸ eventQueueWait(queue
, timeoutMs
): Promise
<EconetEvent
>
Waits for a matching event with a timeout, removing it from the queue.
If no matching event is found within the specified timeout then an error is thrown.
Name | Type | Description |
---|---|---|
queue |
EventQueue |
The queue to wait on. |
timeoutMs |
number |
Maximum time to wait for a matching event in milliseconds. |
Promise
<EconetEvent
>
▸ readStatus(): Promise
<StatusEvent
>
Queries the current status of the board.
Promise
<StatusEvent
>
The current status of the board.
▸ removeListener(listener
): void
Removes a listener previously registered with addListener.
Name | Type | Description |
---|---|---|
listener |
Listener |
The listener to remove. |
void
▸ setDebugEnabled(enabled
): void
Enables/disables driver debug logging. When enabled, shows the raw data passing between the driver and the board.
Name | Type |
---|---|
enabled |
boolean |
void
▸ setEconetStation(station
): Promise
<void
>
Sets the Econet station number for the board so that it knows which received frames to generate events for and how to populate the "from address" of outbound frames.
The station number should be unique on the Econet network.
Name | Type | Description |
---|---|---|
station |
number |
The new Econet station number (an integer in range 1-254, inclusive). |
Promise
<void
>
▸ setMode(mode
): Promise
<void
>
Puts the board into a new operating mode.
The board can be in one of three operating modes:
-
STOP
- The board starts in this mode. No events are generated in response to network traffic, allowing the client to initialise configuration before proceeding. -
LISTEN
- The normal Econet station operating mode. The board generates events for broadcast frames or frames targeting the configured local Econet station number. You should normally set the station number before entering this mode: see setEconetStation. -
MONITOR
- The board generates an event for every frame received, regardless of its source or destination (promiscuous mode). Useful for capturing traffic between other stations like the BBC NETMON utility. A code example is provided for how to build such a utility.
Name | Type | Description |
---|---|---|
mode |
"MONITOR" | "STOP" | "LISTEN" |
The new operating mode. |
Promise
<void
>
▸ transmit(station
, network
, controlByte
, port
, data
, extraScoutData?
): Promise
<TxResultEvent
>
Implements an Econet TRANSMIT
operation.
This consists of a "four-way handshake":
- A "scout" frame sent from the board to the destination station. This includes a
controlByte
andport
which are used by the receiver to identify the type of data being sent. - Assuming the receiver is (a) connected to the network and listening for traffic and (b)
is configured to handle the
controlByte
/port
, it responds with a "scout ack" frame instructing the caller to proceed. - The board sends a frame containing the payload
data
to the destination station. - The receiver responds with a "data ack" frame confirming receipt of the data.
Name | Type | Description |
---|---|---|
station |
number |
Destination Econet station number (integer in range 1-254, inclusive). |
network |
number |
Destination Econet network number (0 for local network; only use other values if you have an appropriately configured Econet bridge). |
controlByte |
number |
Econet control byte (integer in range 0-255, inclusive). |
port |
number |
Econet port number (integer in range 0-255, inclusive). |
data |
Buffer |
Buffer containing binary payload data to send. |
extraScoutData? |
Buffer |
Optional extra data to include in the scout frame. This is useful for a small number of special operations such as NOTIFY. |
Promise
<TxResultEvent
>
Describes the result of the operation. If the operation was successful then the
success
flag is set to true
; otherwise the description
field describes the
error.
▸ waitForEvent(matcher
, timeoutMs
): Promise
<EconetEvent
>
Waits for a matching event with a timeout.
Name | Type | Description |
---|---|---|
matcher |
EventMatcher |
A function that returns true if the passed event matches the required criteria. |
timeoutMs |
number |
Maximum time to wait for a matching event in milliseconds. If no matching event is found within this period then the promise is rejected. |
Promise
<EconetEvent
>
The matching event.