The project is web part of SmartTank opensource project.
Table of Contents generated with DocToc
# install dependencies
npm install
# serve with hot reload at localhost:8080
npm run dev
# build for production with minification
npm run build
# build for production and view the bundle analyzer report
npm run build --report
UBUS is universal bus for communicate between different nodes. Any device can provide the role. Include WEB browser. When you send message to the bus, all nodes receive it. Important - message will be delivered when node is subscriber for this message.
//Send message to UBUS with type "hello" and message "cargo"
window.$bus.$emit(window.$consts.EVENTS.UBUS_MESSAGE, "hello", "cargo");
//Receiving and showing message from UBUS
window.$bus.$on(window.$consts.EVENTS.UBUS_MESSAGE, function(type, messages) {
console.log(`${type}:${messages}`);
}); ...
"scripts" : {
"subscriptions" : ["hello"],
"entry" : "main",
"modules" : {
"main": {
"source": "scripts/main.js",
"optimize": false
}
}
}
... //Importing UBUS listener function
let listener = ffi('void listener(void (*)(char*, char*, userdata), userdata)');
//When message will received, function will call callback function
listener(function(event, content, data) {
if(event === "hello"){
print(event, ":", data);
}
}, null);
//Importing UBUS send function
let emit = ffi('void emit(char*, char*)');
//Sending message to UBUS
emit('my-script-ready', null);All broadcast system messages is defined in window.$const.UBUS
- $-current-time - (CURRENT_TIME) Contains epoch time (ms). Happens when the time is synchronized.
- $-online - (IS_ONLINE) No content. Happens when the controller connected to Internet.
- $-offline - (IS_OFFLINE) No content. Happens when the controller disconnected.
- $-script-error - (SCRIPT_ERROR) Contains error text. Happens when the script generates an error.
window.$bus.$on(window.$consts.EVENTS.UBUS_MESSAGE, function(type, messages) {
switch(type){
case window.$consts.UBUS.CURRENT_TIME:
console.log('Now is ', new Date(1 * messages));
break;
case window.$consts.UBUS.SCRIPT_ERROR:
console.error('Script error: ', messages);
break;
}
});- $-started - No content. Happens when the controller starts or script installed.
let listener = ffi('void listener(void (*)(char*, char*, userdata), userdata)');
listener(function(event, content, data) {
if(event === "$-started"){
print("Controller is ready!");
}
}, null);For a detailed explanation on how things work, check out the guide and docs for vue-loader.