Level 5 - Create a Brand/Model Specific Worker

Level 5 workers are concrete implementations that handle actual device communication for specific hardware brands or models.

B.1. Repository Naming Convention

Level 4 repositories follow strict naming patterns (see Naming Conventions).

miningos-wrk-{devicetype}-{brand}

Examples:

For complete specifications of all supported devices, see Supported Devices.

Note: No tpl in the name — Level 5 workers are concrete, not templates.

B.2. Worker File Naming Convention

Worker files follow a reverse naming pattern based on wtype:

Resolution Example:

For brands with multiple models requiring separate workers:

Example (Schneider with multiple models):

B.3. Directory Structure

A Level 5 implementation repository follows this structure:

B.4. Package.json Structure

To create a package.json for a Level 5 worker:

  1. Open a text editor and create the following structure:

  1. Replace {devicetype} and {brand} with your specific values.

  2. Update the author and maintainers fields.

  3. Save the file as package.json.

Note: The dependency is the Level 4 template (miningos-tpl-wrk-{devicetype}), not the Level 3 thing worker.

B.5. Main Worker Implementation

To create the main worker file:

  1. Create workers/{brand}.rack.{devicetype}.wrk.js.

  2. Add the following implementation, replacing placeholders:

B.6. Device Library Class

Create a device library class that handles protocol communication (workers/lib/{brand}.js):

B.7. Protocol Facilities

Level 5 workers typically require protocol-specific facilities. Add them in init():

Modbus TCP (Industrial Devices)

  1. In your worker's init() method:

HTTP/REST API

  1. In your worker's init() method:

WebSocket

  1. In your worker's init() method:

B.8. Configuration Templates

base.thing.json.example

  1. Create or edit config/base.thing.json.example:

facs/modbus.config.json.example (if using Modbus)

  1. Create config/facs/modbus.config.json.example:

B.9. Testing Infrastructure

Level 5 tests inherit from Level 4 and add brand-specific cases:

Level 5 tests inherit from Level 4 and add brand-specific cases. For complete testing guidelines, see Testing & Linting Guidelines.

tests/utils.js

To extend the parent test utilities:

  1. Create tests/utils.js:

tests/{brand}.spec.js

To create the main test file:

  1. Create tests/{brand}.spec.js:

tests/executors.js

To extend parent executors:

  1. Create tests/executors.js:

tests/cases/{feature}.js

To add a test case:

  1. Create tests/cases/{feature}.js:

B.10. Worker Entry Point

worker.js

  1. Create the worker.js entry point:

For multimodel repositories, create separate entry points:

worker-pm5340.js

  1. Create a model-specific entry point:

B.11. Implementation Requirements Summary

Each Level 5 implementation must:

Requirement
Method or Location
Purpose

Add protocol facility

init() with setInitFacs()

Enable device communication

Extend type definition

getThingType()

Return super.getThingType() + '-{brand}'

Implement connection

connectThing(thg)

Create device controller, assign to thg.ctrl

Implement data collection

collectThingSnap(thg)

Return { success, stats, config }

Define device info

selectThingInfo(thg)

Return connection or device metadata

Add brand tags

getThingTags()

Return brand-specific tags

B.12. Level 5 Checklist

Last updated