Skip to content

Netcore Class

simen edited this page May 3, 2017 · 9 revisions

The Netcore Class is the abstraction for a network controller which provides methods for network management. The following table list the description for each method.


Netcore APIs

API Description
getName() Get netcore name.
isEnabled() To see if the netcore is enabled.
isRegistered() To see if the netcore has been registered to freebird.
isJoinable() To see if the netcore is currently allowing devices to join the network.
enable() Enable netcore. Transportation is active when netcore is enabled.
disable() Disable netcore. Any transportation will be inactivated.
dump() Dump information about this netcore.
start() Start the netcore.
stop() Stop the netcore.
reset() Reset the network controller.
permitJoin() Let the netcore allow devices to join its network.
remove() Remove a remote device from the network.
ban() Ban a device from the network.
unban() Unban a device.
ping() Ping a remote device.
maintain() Maintain all remote devices of the netcore.
getTraffic() Get traffic record of the netcore.
resetTraffic() Reset the traffic record.
getBlacklist() Get the blacklist of banned devices. This method returns an array of permanent addresses.
clearBlacklist() Clear the blacklist. This will simply unban all banned devices.
isBlacklisted() To see if a device is banned.

.getName()

Get netcore name.

Arguments:

  • none

Returns:

  • (String): Name of the netcore.

Examples:

nc.getName();  // 'my_netcore'



.isEnabled()

To see if the netcore is enabled.

Arguments:

  • none

Returns:

  • (Boolean): true if enabled, otherwise false.

Examples:

nc.isEnabled(); // true



.isRegistered()

To see if the netcore has been registered to freebird.

Arguments:

  • none

Returns:

  • (Boolean): true if registered, otherwise false.

Examples:

nc.isRegistered();  // false



.isJoinable()

To see if the netcore is currently allowing devices to join the network.

Arguments:

  • none

Returns:

  • (Boolean): true if network is currently joinable, otherwise false.

Examples:

nc.isJoinable();  // true



.enable()

Enable netcore. Transportation is active when netcore is enabled.

Arguments:

  • none

Returns:

  • (Object): netcore

Examples:

nc.enable();



.disable()

Disable netcore. Any transportation will be inactivated if netcore is disabled, and remote operations are inapplicable.

Arguments:

  • none

Returns:

  • (Object): netcore

Examples:

nc.disable();



.dump()

Dump information about this netcore.

Arguments:

  • none

Returns:

  • (Object): A data object to describe information about this netcore. The following table shows the properties of netcore information object.
Property Type Description
name String Netocre name.
enabled Boolean Tells if this device is enabled.
protocol Object Information of the used protocol.
startTime Number Device joined time, which is an UNIX(POSIX) time in second.

Examples:

nc.dump();

/*
{
    name: 'my_netcore',
    enabled: true,
    protocol: {
        phy: 'ieee802.15.1',
        nwk: 'ble'
    },
    startTime: 1490580460
}
*/


.start([callback])

Start the netcore. This is different from enable(), enable() is used to turn the transportation on. start() is highly depending on the low-layer driver of the network contoller, and is used to start the physical controller that establishes a network.

Arguments:

  1. callback (Function): function (err) {}. Get called after started.

Returns:

  • none

Examples:

nc.start(function (err) {
    if (!err)
        console.log('netcore is up');
    else
        console.log(err);
});



.stop([callback])

Stop the netcore. This is different from disable(), disable() is used to turn the transportation off. stop() is highly depending on the low-layer driver of the network contoller, and is used to stop the physical controller.

Arguments:

  1. callback (Function): function (err) {}. Get called after stopped.

Returns:

  • none

Examples:

nc.stop(function (err) {
    if (!err)
        console.log('netcore is down');
    else
        console.log(err);
});



.reset([mode], callback)

Reset the network 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. callback (Function): function (err) {}. Get called after reset is applied (not completely restarted). After netcore restarts successfully, nc.onReady() will be called.

Returns:

  • none

Examples:

nc.onReady = function () {
    console.log('Netcore is ready');
};

nc.reset(0, function (err) {
    if (!err)
        console.log('netcore starts to run its reset procedure');
    else
        console.log(err);
});



.permitJoin(duration[, callback])

Let the netcore 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 can immediately close the admission.
  2. callback (Function): function (err, timeLeft) {}. Get called when netcore starts/stops permitting device joining, where timeLeft is a number that indicates time left for device joining in seconds, e.g., 180.

Returns:

  • none

Examples:

nc.permitJoin(180, function (err, timeLeft) {
    if (!err)
        console.log(timeLeft);  // 180
});

nc.permitJoin(0, function (err, timeLeft) {
    if (!err)
        console.log(timeLeft);  // 0
});



.remove(permAddr[, callback])

Remove a device from the network.

Arguments:

  1. permAddr (String): Device permanent address
  2. callback (Function): function (err, permAddr) {}. Get called after device been removed, where permAddr is the permananet address of that device.

Returns:

  • none

Examples:

nc.remove('00:0c:29:ff:ed:7c', function (err, permAddr) {
    if (!err)
        console.log(permAddr);  // '00:0c:29:ff:ed:7c'
});



.ban(permAddr, callback)

Ban a device from the network. Once a device is banned, it can never join the network unless you unban it.

Arguments:

  1. permAddr (String): Device permanent address
  2. callback (Function): function (err, permAddr) {}. Get called after device been banned, where permAddr is the permananet address of that device.

Returns:

  • none

Examples:

nc.ban('00:0c:29:ff:ed:7c', function (err, permAddr) {
    if (!err)
        console.log(permAddr);  // '00:0c:29:ff:ed:7c'
});



.unban(permAddr, callback)

Unban a device.

Arguments:

  1. permAddr (String): Device permanent address
  2. callback (Function): function (err, permAddr) {}. Get called after device been unbanned, where permAddr is the permananet address of that device.

Returns:

  • none

Examples:

nc.unban('00:0c:29:ff:ed:7c', function (err, permAddr) {
    if (!err)
        console.log(permAddr);  // '00:0c:29:ff:ed:7c'
});



.ping(permAddr, callback)

Ping a remote device.

Arguments:

  1. permAddr (String): Device permanent address
  2. callback (Function): function (err, time) {}. Get called when ping response comes back, where time is the round-trip time in milliseconds, e.g., 16.

Returns:

  • none

Examples:

nc.ping('00:0c:29:ff:ed:7c', function (err, time) {
    if (!err)
        console.log(time);  // 42
});



.maintain([callback])

Maintain all devices of the netcore. This will refresh devices information by re-discovering the remote devices.

Arguments:

  1. callback (Function): function (err) {}. Get called after devices been maintained.

Returns:

  • none

Examples:

nc.maintain(function (err) {
    if (!err)
        console.log('netcore is maintained.')
});



.getTraffic()

Get traffic record of the netcore.

Arguments:

  • none

Returns:

  • (Object): Traffic record of this netcore.

Examples:

nc.getTraffic();
/*
{
    in: {
        hits: 1422,
        bytes: 896632
    },
    out: {
        hits: 884,
        bytes: 36650
    }
}
*/



.resetTraffic([dir])

Reset the traffic record.

Arguments:

  1. dir (String): If given with 'in', the incoming traffic will be reset, else if given with 'out', the outgoing traffic will be reset. Both incoming and outgoing traffic records will be reset if dir is not specified.

Returns:

  • (Object): netcore

Examples:

nc.resetTraffic();
nc.resetTraffic('in');
nc.resetTraffic('out');



.getBlacklist()

Get the blacklist of banned devices. This method returns an array of permanent addresses.

Arguments:

  • none

Returns:

  • (String[]): An array of permanent addresses of devices been banned.

Examples:

nc.getBlacklist();
// [ '0x12345678', '0xabcd5768', '0x1234abcd', '0x5678abcd' ]



.clearBlacklist()

Clear the blacklist. This will simply unban all banned devices.

Arguments:

  • none

Returns:

  • (Object): netcore

Examples:

nc.clearBlacklist();



.isBlacklisted(permAddr)

To see if a device is banned.

Arguments:

  1. permAddr (String): Permanent address of the device to look for.

Returns:

  • (Boolean): true if banned, otherwise false.

Examples:

nc.isBlacklisted('0x1234abcd'); // true
nc.isBlacklisted('0x2e3c5a11'); // false