177 lines
5.8 KiB
JavaScript
177 lines
5.8 KiB
JavaScript
/*
|
|
This code snippet is taken from from the 'gettingStarted' BajaScript tutorial.
|
|
More information can be found by navigating to this ORD...
|
|
|
|
module://docDeveloper/doc/jsdoc/bajaux-ux/tutorial-gettingStarted.html
|
|
*/
|
|
let my_user_account_func, target_func;
|
|
var baja_alarm_device_number = [];
|
|
|
|
function MyBaja(){
|
|
this.setMyUserAccount = function(callBackFunc){
|
|
my_user_account_func = callBackFunc;
|
|
}
|
|
this.setCallBack = function(callBackFunc){
|
|
target_func = callBackFunc;
|
|
};
|
|
}
|
|
|
|
function update_baja_alarm_device_number(point) {
|
|
var target_device_number = point.getDisplayName().split('_').slice(0, 5).join('_');
|
|
|
|
var arr_point_alarm = point.getOutDisplay().split(' ');
|
|
if (arr_point_alarm[0] === "true") {
|
|
if(baja_alarm_device_number.indexOf(target_device_number) < 0){
|
|
baja_alarm_device_number.push(target_device_number);
|
|
}
|
|
} else if(arr_point_alarm[0] === "false") {
|
|
if(baja_alarm_device_number.indexOf(target_device_number) >=0){
|
|
baja_alarm_device_number.splice(baja_alarm_device_number.indexOf(target_device_number), 1);
|
|
}
|
|
}
|
|
|
|
console.log("baja_alarm_device_number", baja_alarm_device_number);
|
|
}
|
|
|
|
require(['baja!'], function (baja) {
|
|
/*=====================
|
|
* 取得使用者account - start
|
|
======================*/
|
|
var user_name = baja.getUserName();
|
|
my_user_account_func(user_name);
|
|
/*=====================
|
|
* 取得使用者account - end
|
|
======================*/
|
|
});
|
|
|
|
|
|
// Subscribe to a Ramp. When it changes, print out the results.
|
|
require(['baja!'], function (baja) {
|
|
"use strict";
|
|
|
|
// A Subscriber is used to listen to Component events in Niagara.
|
|
var sub = new baja.Subscriber();
|
|
|
|
//當有訂閱的點位值被修改執行的function
|
|
sub.attach('changed', function (prop) {
|
|
if (prop.getName() === 'out') { update(this); }
|
|
if (prop.getName() === 'out') { update_baja_alarm_device_number(this); } //
|
|
if (prop.getName() === 'pingHost') { updateIP(this); } //CCTV抓取IP位置
|
|
target_func(baja_alarm_device_number);
|
|
});
|
|
|
|
|
|
|
|
/*=====================
|
|
* 取得單一點位資料 - start
|
|
======================*/
|
|
// baja.Ord.make('local:|foxs:|station:|slot:/Arena/H/B/B4F/FE/H_B_B4F_2A_01/H_B_B4F_2A_01_ST').get({subscriber: sub})
|
|
// .then(update);
|
|
|
|
// The 'update' method is called whenever the text needs to be updated.
|
|
// function update(light) {
|
|
// $("#Ramp1").html(light.getOutDisplay());
|
|
// }
|
|
|
|
/*=====================
|
|
* 取得單一點位資料 - end
|
|
======================*/
|
|
|
|
|
|
/*=====================
|
|
* 指定路徑取得該路徑點位 - start
|
|
======================*/
|
|
baja.Ord.make("local:|foxs:|station:|slot:/Arena/H/B/B5F/$32A")
|
|
.get()
|
|
.then(function (folders) {
|
|
var batch = new baja.comm.Batch();
|
|
console.log("查看指定路徑資料夾資訊", folders);
|
|
console.log("取得指定路徑Slots", folders.getSlots())
|
|
|
|
folders.getSlots().eachValue(function (folder, index) {
|
|
|
|
if (index == 16) {
|
|
return
|
|
}
|
|
|
|
baja.Ord.make("local:|foxs:|station:|slot:" + folder.getSlotPath().getNames().join("/"))
|
|
.get()
|
|
.then(function (folder) {
|
|
console.log("folder", folder)
|
|
folder.getSlots().is("control:BooleanWritable").eachValue(function (point) {
|
|
|
|
console.log(folder.getDisplayName() + " point", point)
|
|
|
|
$("#auto-append-wrap").append(`<div id="${point.getDisplayName()}">
|
|
<label>${point.getDisplayName()}</label>
|
|
<div id="${point.getDisplayName()}-value" style="text-align: center;"></div>
|
|
</div>`)
|
|
sub.subscribe({
|
|
comps: point
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
function update(point) {
|
|
console.log("update function point:", point);
|
|
$(`#${point.getDisplayName()}-value`).html(point.getOutDisplay());
|
|
}
|
|
/*=====================
|
|
* 指定路徑取得該路徑點位 - end
|
|
======================*/
|
|
|
|
/*=====================
|
|
* 指定路徑取得該路徑CCTV的IP - start
|
|
======================*/
|
|
|
|
baja.Ord.make("local:|foxs:|station:|slot:/Arena/H/C/B5F/VRC")
|
|
.get()
|
|
.then(function (folders) {
|
|
console.log("CCTV");
|
|
console.log("查看指定路徑資料夾資訊", folders);
|
|
console.log("取得指定路徑Slots", folders.getSlots())
|
|
|
|
folders.getSlots().eachValue(function (folder, index) {
|
|
|
|
baja.Ord.make("local:|foxs:|station:|slot:" + folder.getSlotPath().getNames().join("/"))
|
|
.get()
|
|
.then(function (folder) {
|
|
console.log("folder", folder)
|
|
console.log("folder getSlots", folder.getSlots())
|
|
|
|
folder.getSlots().is("vykonPro:ConnectionFailover").eachValue(function (point) {
|
|
console.log(folder.getDisplayName() + " point", point)
|
|
|
|
$("#ip-auto-append-wrap").append(`<div id="${point.getDisplayName()}">
|
|
<label>${point.getDisplayName()}</label>
|
|
<div id="${point.getDisplayName()}-ip" style="text-align: center;"></div>
|
|
</div>`)
|
|
sub.subscribe({
|
|
comps: point
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
function updateIP(point){
|
|
console.log("updateIP function point:", point);
|
|
$(`#${point.getDisplayName()}-ip`).html(point.getPingHost());
|
|
}
|
|
|
|
/*=====================
|
|
* 指定路徑取得該路徑CCTV的IP - end
|
|
======================*/
|
|
|
|
// Unsubscribe the Component so we're no longer listening to live
|
|
// events.
|
|
// sub.unsubscribeAll();
|
|
|
|
// Detach all subscription handlers to ensure we don't unnecessarily
|
|
// create memory leaks.
|
|
// sub.detach();
|
|
|
|
});
|