#neurons-engine
Neurons Engine is the JavaScript implementation of neurons central processing block, which runs on both Node and browser environment. It includes two parts:
- Logic Engine.
- Neurons binary protocol implementation.
- Neurons blocks auto discovery and management.
- Communication drivers used for running on different platforms.
- Flow Engine.
- Provide Flow-based API to easy Programming.
- install NodeJS environment.
- run
node cli.js
. - connect the blocks with serial port.
- copy
browser/neurons_engine.js
to your project. - add
<script src="/path/to/neurons_engine.js"></script>
in your html<head>
tag.
see 'example'
var engine = require('./lib/engine/logic').create(
{"driver": "serial", "loglevel": "DEBUG"}
);
var engine = createNeuronsLogicEngine(
{"driver": "makeblockhd", "loglevel": "DEBUG"}
);
#### configuration
* `driver`: the driver to use ,currently support
* **serial**(Node Only),
* **tcpsocket**(Node Only),
* **cordovable**(Makeblock Neuron App Only),
* **cordovatcp**(Makeblock Neuron App Only),
* `loglevel`: the loglevel to set ,when set, will not print the log which priority lower than set.
* currently support loglevel
* **TRACE**,
* **DEBUG**,
* **INFO**,
* **WARN**,
* **ERROR**,
* **FATAL**
Get all active blocks and their values. Example result:
{
"1_KEY_BUTTON": [
{press: 0}
],
"TEMPERATURE": [
{temperature: 27}
],
"HUMITURE": [
{temperature_humidity: [27,70]}
],
}
Queries a block's substatus by name. if idx is provided, will return the status of the {idx}th block of the name. If the required block does not exist, will return null
.
Return the values array of the block if block exists. eg: [1, 34]
.
Sends a command to block of name given. Only works for blocks with sub command.
name
: the name of the block type. eg: "MOTORS"command
: the name of the block command, eg: "SET_SPEED"params
: [array],the params of the block command, eg: [100,-100] //port1 port2
use Engine.on(event, callback)
to register an event handler.
support events:
callback(name, idx)
name
: the name of block typeidx
: the {idx}th block
callback(error)
callback(list)
list
: the active blocks list. seeEngine.getActiveBlocks
callback(name, idx, values)
values
: see Engine.GetBlockStatus
callback({name: $name, idx: $idx, state: $state})
All support electronic blocks are defined in lib/blocks/electronic
folder by JSON objects. You can define your own block for extension:
var example = {
name: 'example', // the block name, MUST be unique
type: 0x00, // the block type id
subtype: 0x01, // the block subtype id , optional.
status: ['byte', 'BYTE', 'short', 'float'] // the block status values type definition.
};
For blocks will sub status:
var example2 = {
// the name of the block, must not be unique.
name: 'example2',
// the typeid of block.
type: 0x00,
// subtypeid of block, optional.
// subtype: 0x01,
// available sub status' datatype.
status: {
'sub1' : {
'subid': 0x01,
'datatype': ['float']
},
'sub2' : {
'subid': 0x02,
'datatype' : ['byte', 'BYTE', 'short', 'float']
}
}
};
For blocks with sub command:
var example3 = {
// the name of the block, must not be unique.
name: 'example3',
// the typeid of block.
type: 0x01,
// subtypeid of block, optional.
// subtype: 0x01,
// available sub status' datatype.
status: {
'sub1' : {
'subid': 0x01,
'datatype': ['float']
},
'sub2' : {
'subid': 0x02,
'datatype' : ['byte', 'BYTE', 'short', 'float']
}
},
// block's commands
commands: {
'command1': {
'commandid': 0x01,
'datatype': ['float']
},
'command2' : {
'commandid': 0x02,
'datatype' : ['byte', 'BYTE', 'short', 'float']
}
}
};
supported value type:
- "byte": 7bit/byte byte
- "BYTE": 8bit/byte byte (only use when the byte length < 128)
- "short": 7bit/byte short
- "SHORT": 7bit/byte short, but ignore most significant byte (only use when the MSB is 0x00)
- "long": 0x11111111 // 7bit/byte long
- "float": 7bit/byte float
- "double": 7bit/byte double
- "string": 7bit/byte byte array, in TLV format
gulp test
gulp jshint
gulp browserify
gulp compress