-
Notifications
You must be signed in to change notification settings - Fork 2
APIs for Implementer
This document gives the Netcore APIs for implementers to call, not for Netcore users!
API | Description |
---|---|
Create a netcore | Use require('freebird-base').createNetcore() to create a new instance of Netcore. |
registerNetDrivers() | Register network drivers to the netcore. |
registerDevDrivers() | Register device drivers to the netcore. |
registerGadDrivers() | Register gadget drivers to the netcore. |
commitReady() | Tell the netcore that the network controller is ready. |
commitDevNetChanging() | When a device changes any of its network information, tell the netcore. |
commitDevIncoming() | When a device is coming into the network, tell the netcore. |
commitDevLeaving() | When a device is leaving from the network, tell the netcore. |
commitGadIncoming() | When a gadget is coming into the network, tell the netcore. |
commitDevReporting() | When a device reports its attribtue(s), tell the netcore. |
commitGadReporting() | When a gadget reports its attribtue(s), tell the netcore. |
dangerouslyCommitGadReporting() | When a gadget reports its attribtue(s), tell the netcore. If attribute does not exist, netcore will append it to the gadget. |
Create a new instance of Netcore.
Arguments:
-
name
(String): Netcore name. -
controller
(Object): Low-level controller. e.g., ble-shepherd. -
protocol
(Object): Information of the used protocolProperty Type Mandatory Description phy String Required Physic layer dll String Optional Data link layer nwk String Required Network layer tl String Optional Transportation layer sl String Optional Session layer pl String Optional Presentation layer apl String Optional Application layer -
opt
(Object): Reserved.
Returns:
- (Object): netcore
Examples:
// Network raw controller
var BShepherd = require('ble-shepherd'),
controller = new BShepherd('noble');
// Freebird netcore
var fbBase = require('freebird-base'),
nc;
var nc = fbBase.createNetcore('freebird-netcore-ble', controller, {
phy: 'bluetooth smart',
nwk: 'ble'
});
Register network drivers to the netcore.
Arguments:
-
netDrvs
(Object): An object contains all network management drivers required by the netcore. Please see Network Driver Section for more details on signature and behavior of each driver.
Property | Type | Mandatory | Description |
---|---|---|---|
start | Function | required | Driver to start the network controller |
stop | Function | required | Driver to stop the network controller |
reset | Function | required | Driver to reset the network controller |
permitJoin | Function | required | Driver to allow devices to join the network |
remove | Function | required | Driver to remove a device from the network |
ping | Function | required | Driver to ping a device in the network |
ban | Function | optional | Driver to ban a device from the network |
unban | Function | optional | Driver to unban a device from the network |
Returns:
- (Object): netcore
Examples:
var netDrvs = {
start: function (done) {
// your implementation
},
stop: function (done) {
// your implementation
},
reset: function (mode, done) {
// your implementation
},
permitJoin: function (duration, done) {
// your implementation
},
remove: function (permAddr, done) {
// your implementation
},
ping: function (permAddr, done) {
// your implementation
}
};
nc.registerNetDrivers(netDrvs);
Register device drivers to the netcore.
Arguments:
-
drvs
(Object): An object contains all device operation drivers required by the netcore. Please see Device Driver Section for more details on signature and behavior of each driver.
Property | Type | Mandatory | Description |
---|---|---|---|
read | Function | required | Driver to read an attribute from a remote device |
write | Function | required | Driver to write an attribute value to a remote device |
identify | Function | optional | Driver to identify a remote device. This method is optional. If the device supoorts identifying mode, it may, for example, start to blink a led to get users attention. |
Returns:
- (Object): netcore
Examples:
var devDrvs = {
read: function (permAddr, attrName, done) {
// your implementation
},
write: function (permAddr, attrName, val, done) {
// your implementation
},
identify: function (permAddr, done) {
// your implementation
}
};
nc.registerDevDrivers(devDrvs);
Register gadget drivers to the netcore.
Arguments:
-
drvs
(Object): An object contains all gadget operation drivers required by the netcore. Please see Gadget Driver Section for more details on signature and behavior of each driver.
Property | Type | Mandatory | Description |
---|---|---|---|
read | Function | required | Driver to read an attribute from a remote gadget |
write | Function | required | Driver to write an attribute value to a remote gadget |
exec | Function | optional | Driver to invoke a procedure on a remote gadget |
readReportCfg | Function | optional | Driver to read the report configuration of a remote gadget |
writeReportCfg | Function | optional | Driver to write the report configuration to a remote gadget |
Returns:
- (Object): netcore
Examples:
var gadDrvs = {
read: function (permAddr, auxId, attrName, done) {
// your implementation
},
write: function (permAddr, auxId, attrName, val, done) {
// your implementation
},
exec: function (permAddr, auxId, attrName, args, done) {
// your implementation
},
readReportCfg: function (permAddr, auxId, attrName, done) {
// your implementation
},
writeReportCfg: function (permAddr, auxId, attrName, cfg, done) {
// your implementation
}
};
nc.registerDevDrivers(gadDrvs);
Call commitReady to tell netcore that the network controller is ready. Everytime when netcore starts, reboots, or resets, it must call nc.commitReady()
to let the netcore know if it is ready.
Arguments:
- none
Returns:
- none
Examples:
nc.commitReady();
Commit the device network information changes.
Arguments:
-
permAddr
(String): Permanent address of the device. -
changes
(Object): Network information changes, which is an object in the shape of{ role, parent, maySleep, sleepPeriod, status, address: { dynamic } }
and partial changes is acceptable.
Returns:
- (Boolean):
true
for a success, otherwisefalse
for failure.
Examples:
// commit a status change
nc.commitDevNetChanging('0x0123456789', { status: 'online' });
// commit some changes at once
nc.commitDevNetChanging('0x0123456789', {
status: 'online',
parent: '0xabcd12345',
role: 'end-device'
});
Commit a device incoming message to netcore when a device is coming in.
Arguments:
-
permAddr
(String): Permanent address of the device. -
rawDev
(Object): Raw device data given by the low-layer controller.
Returns:
- (Boolean):
true
for a success, otherwisefalse
for failure.
Examples:
nc.commitDevIncoming('0x0123456789', rawDev); // rawDev is an object from the controller
Commit a device leaving message to netcore when a device is leaving from the network.
Arguments:
-
permAddr
(String): Permanent address of the device.
Returns:
- (Boolean):
true
for a success, otherwisefalse
for failure.
Examples:
nc.commitDevLeaving('0x0123456789');
Commit a gadget incoming message to netcore when a gadget is coming in.
Arguments:
-
permAddr
(String): Permanent address of which device is the gadget hosted on. -
auxId
(String | Number): Auxiliary id of the gadget. This id is to uniquely identify a gadget on the device. -
rawGad
(Object): Raw gadget data given by the low-layer controller.
Returns:
- (Boolean):
true
for a success, otherwisefalse
for failure.
Examples:
nc.commitGadIncoming('0x0123456789', 'temperature/0', rawGad);
Commit a device reporting message to netcore when a device attribtue(s) report is received.
Arguments:
-
permAddr
(String): Permanent address of the device. -
devAttrs
(Object): Attribtue(s) report from the remote device.
Returns:
- (Boolean):
true
for a success, otherwisefalse
for failure.
Examples:
nc.commitDevReporting('0x0123456789', { manufacturer: 'xxx' });
Commit a gadget reporting message to netcore when a gadget attribtue(s) report is received.
Arguments:
-
permAddr
(String): Permanent address of which device is the gadget hosted on. -
auxId
(String | Number): Auxiliary id of the gadget. This id is to uniquely identify a gadget on the device. -
gadAttrs
(Object): Attribtue(s) report from the remote gadget.
Returns:
- (Boolean):
true
for a success, otherwisefalse
for failure.
Examples:
nc.commitGadReporting('0x0123456789', 'temperature/0', { sensorValue: 27.8 });
Dangerously commit a gadget reporting message to netcore when a gadget attribtue(s) report is received. This will append new attribute(s) to the gadget if the reported attribute(s) does not exist. Use this API as you do know what you are doing.
Arguments:
-
permAddr
(String): Permanent address of which device is the gadget hosted on. -
auxId
(String | Number): Auxiliary id of the gadget. This id is to uniquely identify a gadget on the device. -
gadAttrs
(Object): Attribtue(s) report from the remote gadget.
Returns:
- (Boolean):
true
for a success, otherwisefalse
for failure.
Examples:
nc.dangerouslyCommitGadReporting('0x12345678abcde', 'dIn/6', {
xx: 1,
yy: 2
});
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