Skip to content

Device Drivers

simen edited this page May 4, 2017 · 4 revisions

These document describes the signature and behavior of each device operation driver should have.

The netcore implementors have responsibility to implement these drivers. After the drivers are ready, you can put them into an object in the shape of

var devDrvs = {
    read: function(done) {},
    write: function(done) {},
    identify: function(mode, done) {}
}

, and then call nc.registerDevDrivers(devDrvs) to register them to the netcore.


Device Operation Drivers

Driver Mandatory Signature Description
read required function(permAddr, attrName, done) {} Read device attribute from the remote device.
write required function(permAddr, attrName, val, done) {} Remotely write a value to an attribute on the device.
identify optional function(permAddr, done) {} Identify a device in the network.



read(permAddr, attrName, done)

Read the device attribute from a remote device.

Arguments:

  1. permAddr (String): Device permanent address.
  2. attrName (String): Attribute name.
  3. done (Function): function (err, val) {}. val (Depends) is the attribute value.

Returns:

  • none

Examples:

var devDrvs = {
    read: function (permAddr, attrName, done) {
        // your implementation here

        // call done with the read data when operation accomplished
        done(null, data);
    },
    ...
};



write(permAddr, attrName, val, done)

Remotely write a value to the attribute on a device.

Arguments:

  1. permAddr (String): Device permanent address.
  2. attrName (String): Attribute name.
  3. val (Depends): Attribute value to write to the device.
  4. done (Function): function (err[, val]) {}. val (Depends) is the written value. Returns:
  • none

Examples:

var devDrvs = {
    write: function (permAddr, attrName, val, done) {
        // your implementation here

        // call done (with the written data) when operation accomplished
        done(null[, data]);  // data is optional but highly recommanded
    },
    ...
};



identify(permAddr, done)

Identify a device in the network. If remote device does not implement this feature, it would be inapplicable.

Arguments:

  1. permAddr (String): Device permanent address.
  2. done (Function): function (err, permAddr) {}. permAddr (String) is the permanent address which device to be identified.

Returns:

  • none

Examples:

var devDrvs = {
    identify: function (permAddr, done) {
        // your implementation here

        // call done with the device permAddr when operation accomplished
        done(null, permAddr);
    },
    ...
};