Skip to content

Network Drivers

simen edited this page May 4, 2017 · 5 revisions

These document describes the signature and behavior of each netowrk management 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 netDrvs = {
    start: function(done) {},
    stop: function(done) {},
    reset: function(mode, done) {},
    permitJoin: function(duration, done) {},
    remove: function(permAddr, done) {},
    ban: function(permAddr, done) {},
    unban: function(permAddr, done) {},
    ping: function(permAddr, done) {}
}

, and then call nc.registerNetDrivers(netDrvs) to register them to the netcore.


Network Drivers

Driver Mandatory Signature Description
start required function(done) {} Start the low-layer network controller.
stop required function(done) {} Stop the low-layer network controller.
reset required function(mode, done) {} Reset the low-layer network controller.
permitJoin required function(duration, done) {} Let the controller allow devices to join the network.
remove required function(permAddr, done) {} Remove a device from the network.
ban optional function(permAddr, done) {} Ban a device from the network.
unban optional function(permAddr, done) {} Unban a device.
ping required function(permAddr, done) {} Ping a remote device.



start(done)

Start the low-layer network controller.

Arguments:

  1. done (Function): function (err) {}.

Returns:

  • none

Examples:

var netDrvs = {
    start: function (done) {
        // your implementation here

        done(null);  // call done when accomplished
    },
    // ...
};



stop(done)

Stop the low-layer network controller.

Arguments:

  1. done (Function): function (err) {}.

Returns:

  • none

Examples:

var netDrvs = {
    stop: function (done) {
        // your implementation here

        done(null);  // call done when accomplished
    },
    // ...
};



reset(mode, done)

Reset the low-layer controller.

Arguments:

  1. mode (Number): 0 for a soft reset and 1 for a hard reset. It will perform the soft reset if mode is not given.
  2. done (Function): function (err) {}.

Returns:

  • none

Examples:

var netDrvs = {
    reset: function (mode, done) {
        // your implementation here

        done(null);  // call done when accomplished
    },
    ...
};



permitJoin(duration, done)

Let the controller allow devices to join its network.

Arguments:

  1. duration (Number): Duration in seconds for the netcore to allow devices to join the network. Set it to 0 will immediately close the admission.
  2. done (Function): function (err, timeLeft) {}. timeLeft (Number) is a number that indicates time left for device joining in seconds.

Returns:

  • none

Examples:

var netDrvs = {
    permitJoin: function (duration, done) {
        // your implementation here

        done(null, timeLeft);  // call done with timeLeft when accomplished
    },
    // ...
};



remove(permAddr, done)

Remove a remote device from the network.

Arguments:

  1. permAddr (String): Device permanent address.
  2. done (Function): function (err, permAddr) {}. permAddr (String) is the permananet address of that device.

Returns:

  • none

Examples:

var netDrvs = {
    remove: function (permAddr, done) {
        // your implementation here

        // call done with device permanent address when accomplished
        done(null, permAddr);
    },
    // ...
};



ban(permAddr, done)

Ban a device from the network. This driver is optional.

Arguments:

  1. permAddr (String): Device permanent address.
  2. done (Function): function (err, permAddr) {}. permAddr (String) is the permananet address of that device.

Returns:

  • none

Examples:

var netDrvs = {
    ban: function (permAddr, done) {
        // your implementation here

        // call done with device permanent address when accomplished
        done(null, permAddr);
    },
    // ...
};



unban(permAddr, done)

Unban a device. This driver is optional.

Arguments:

  1. permAddr (String): Device permanent address.
  2. done (Function): function (err, permAddr) {}. permAddr (String) is the permananet address of that device.

Returns:

  • none

Examples:

var netDrvs = {
    unban: function (permAddr, done) {
        // your implementation here

        // call done with device permanent address when accomplished
        done(null, permAddr);
    },
    // ...
};



ping(permAddr, done)

Ping a remote device.

Arguments:

  1. permAddr (String): Device permanent address.
  2. done (Function): function (err, time) {}. time (Number) is the round-trip time in milliseconds, e.g., 16.

Returns:

  • none

Examples:

var netDrvs = {
    ping: function (permAddr, done) {
        // your implementation here

        // call done with the round-trip time when accomplished
        done(null, time);
    }
};