-
Notifications
You must be signed in to change notification settings - Fork 2
Netcore Class
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.
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. |
Get netcore name.
Arguments:
- none
Returns:
- (String): Name of the netcore.
Examples:
nc.getName(); // 'my_netcore'
To see if the netcore is enabled.
Arguments:
- none
Returns:
- (Boolean):
true
if enabled, otherwisefalse
.
Examples:
nc.isEnabled(); // true
To see if the netcore has been registered to freebird.
Arguments:
- none
Returns:
- (Boolean):
true
if registered, otherwisefalse
.
Examples:
nc.isRegistered(); // false
To see if the netcore is currently allowing devices to join the network.
Arguments:
- none
Returns:
- (Boolean):
true
if network is currently joinable, otherwisefalse
.
Examples:
nc.isJoinable(); // true
Enable netcore. Transportation is active when netcore is enabled.
Arguments:
- none
Returns:
- (Object): netcore
Examples:
nc.enable();
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 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 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:
-
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 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:
-
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 the network controller.
Arguments:
-
mode
(Number):0
for a soft reset and1
for a hard reset. It will perform the soft reset ifmode
is not given. -
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);
});
Let the netcore allow devices to join its network.
Arguments:
-
duration
(Number): Duration in seconds for the netcore to allow devices to join the network. Set it to0
can immediately close the admission. -
callback
(Function):function (err, timeLeft) {}
. Get called when netcore starts/stops permitting device joining, wheretimeLeft
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 a device from the network.
Arguments:
-
permAddr
(String): Device permanent address -
callback
(Function):function (err, permAddr) {}
. Get called after device been removed, wherepermAddr
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 a device from the network. Once a device is banned, it can never join the network unless you unban it.
Arguments:
-
permAddr
(String): Device permanent address -
callback
(Function):function (err, permAddr) {}
. Get called after device been banned, wherepermAddr
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 a device.
Arguments:
-
permAddr
(String): Device permanent address -
callback
(Function):function (err, permAddr) {}
. Get called after device been unbanned, wherepermAddr
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 a remote device.
Arguments:
-
permAddr
(String): Device permanent address -
callback
(Function):function (err, time) {}
. Get called when ping response comes back, wheretime
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 all devices of the netcore. This will refresh devices information by re-discovering the remote devices.
Arguments:
-
callback
(Function):function (err) {}
. Get called after devices been maintained.
Returns:
- none
Examples:
nc.maintain(function (err) {
if (!err)
console.log('netcore is maintained.')
});
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
}
}
*/
Reset the traffic record.
Arguments:
-
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 ifdir
is not specified.
Returns:
- (Object): netcore
Examples:
nc.resetTraffic();
nc.resetTraffic('in');
nc.resetTraffic('out');
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' ]
Clear the blacklist. This will simply unban all banned devices.
Arguments:
- none
Returns:
- (Object): netcore
Examples:
nc.clearBlacklist();
To see if a device is banned.
Arguments:
-
permAddr
(String): Permanent address of the device to look for.
Returns:
- (Boolean):
true
if banned, otherwisefalse
.
Examples:
nc.isBlacklisted('0x1234abcd'); // true
nc.isBlacklisted('0x2e3c5a11'); // false
freebird team
Overview
Main Classes
Design Your Own Netcore
- Workflow
- APIs for Implementer
- Unified data model
- What should be implemented
Appendix
- Device data object format
- Gadget data object format