711 lines
30 KiB
JavaScript
711 lines
30 KiB
JavaScript
|
||
// import { parseXml, xml2json } from '/xml2json';
|
||
|
||
let baja_my_user_account_func, //設定使用者帳號
|
||
baja_prepare_specify_subscribe_devices = [], //設定要訂閱的設備
|
||
baja_subscribe_device_callback_func, //設定BQL訂閱之後要回傳的Function
|
||
baja_all_emergency_devices = [], //所有緊急應變的設備
|
||
baja_emergency_alarm_func, //設定回傳的緊急應變設備編號Function
|
||
baja_target_func, //設定回傳指定訂閱設備編號Function
|
||
baja_target_range_raw_data_func, //設定要回傳的設備點位區間RawData
|
||
baja_specify_subscribe_real_time_device = [], //設定即時顯示的設備
|
||
baja_target_real_time_func, //設定回傳即時顯示設備的Function
|
||
baja_numberic_raw_data_func, //設定回傳取得數值型的Function
|
||
baja_boolean_raw_data_func; //設定回傳取得布林的Function
|
||
|
||
var baja_specify_alarm_device_number = [];
|
||
var baja_emergency_alarm_device_number = []; //要回傳的緊急應變的異常設備
|
||
var baja_specify_real_time_device_number = [];
|
||
var baja_numberic_raw_data = []; //取得數值型RawData
|
||
var baja_boolean_raw_data = []; //取得布林RawData
|
||
|
||
var user_name = "";
|
||
var ordPath; //當前點選選單的tag,用來抓出設備路徑,例如:旅館棟->H,消防偵煙器->F3
|
||
// var baseApiUrl = "http://60.251.164.125:8848/";
|
||
//var baseApiUrl2 = "http://192.168.122.197:80/";
|
||
var baseApiUrl2 = "http://192.168.0.136:80/";
|
||
|
||
|
||
|
||
|
||
/**
|
||
* 使用者透過BQL指定路徑去訂閱設備點位
|
||
*/
|
||
function BajaTest() {
|
||
require(['baja!'], function (baja) {
|
||
"use strict";
|
||
|
||
var init_start = new Date(Date.now())
|
||
$("#init-timestamp").html(init_start.toISOString());
|
||
|
||
var render_start, render_finish;
|
||
|
||
// A Subscriber is used to listen to Component events in Niagara.
|
||
var sub = new baja.Subscriber();
|
||
var sub2 = new baja.Subscriber();
|
||
|
||
// This shows a dialog. The function passed into 'showOk' is used to generate the dialog
|
||
// box's content.
|
||
|
||
// The 'update' method is called whenever the text needs to be updated.
|
||
function update(ramp) {
|
||
|
||
$("#update-point-name").html(ramp.getDisplayName());
|
||
$("#update-point-value").html(ramp.getOutDisplay());
|
||
|
||
console.log(`#${ramp.getDisplayName()}-value`)
|
||
$(`#${ramp.getDisplayName()}-value`).html(ramp.getOutDisplay());
|
||
}
|
||
|
||
// Called whenever the Ramp changes.
|
||
sub.attach('changed', function (prop) {
|
||
if (prop.getName() === 'out') { update(this); }
|
||
});
|
||
|
||
//使用bql語法
|
||
//baja.Ord.make('ip:greencloud.fic.com.tw|foxs:|station:|slot:/Arena/H/F3|bql:select name, displayname, slotPath, out.value, out from control:ControlPoint')
|
||
//baja.Ord.make('local:|foxs:|station:|slot:/TPE/B1/ME/M10/U1F/NA/TPE_B1_ME_M10_U1F_NA_FCU_N1|bql:select toPathString, name, displayname, slotPath, out.value, out from control:ControlPoint')
|
||
//baja.Ord.make('local:|foxs:|station:|slot:/TPE/B1|bql:select toPathString, name, displayname, slotPath, out.value, out from control:ControlPoint')
|
||
//baja.Ord.make('local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, msgText, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState')
|
||
// baja.Ord.make('ip:greencloud.fic.com.tw|foxs:|station:|slot:/Arena/H/E1/B1F/TestData/H_E1_B1F_TestData_Data|bql:select slotPath,out.value from control:NumericWritable')
|
||
// .get(
|
||
// function (table) {
|
||
// var tableStart, tableFinish;
|
||
// var subStart, subFinish;
|
||
// var readBqlFinish = new Date(Date.now());
|
||
// $("#readPath-finish-timestamp").html(readBqlFinish.toISOString());
|
||
// $("#readPath-finish-time").html((readBqlFinish.getTime() - init_start.getTime()) / 1000 + "sec");
|
||
|
||
// table.cursor({
|
||
// before: function () {
|
||
// tableStart = new Date(Date.now());
|
||
// $("#table-start-timestamp").html(tableStart.toISOString());
|
||
|
||
// subStart = new Date(Date.now());
|
||
// $("#sub-start-timestamp").html(subStart.toISOString());
|
||
|
||
// render_start = new Date(Date.now());
|
||
// },
|
||
// each: function (item, index) {
|
||
|
||
// // console.log("local:|foxs:|station:|" + this.getDisplay("slotPath"));
|
||
// baja.Ord.make("local:|foxs:|station:|" + this.getDisplay("slotPath"))
|
||
// .get()
|
||
// .then(function (component) {
|
||
// //紀錄 未render前花費約5秒
|
||
// $("#render-points").append(`
|
||
// <div>
|
||
// <label>${component.getDisplayName()+' - ' +component.getDisplay("toPathString")}</label>
|
||
// <div id="${component.getDisplayName()}-value" style="text-align: center;">${component.getOutDisplay()}</div>
|
||
// </div>
|
||
// `);
|
||
|
||
// sub.subscribe({
|
||
// comps: component,
|
||
// });
|
||
|
||
// $("#sub-point-name").html(component.getDisplayName());
|
||
|
||
// subFinish = new Date(Date.now());
|
||
// $("#sub-finish-timestamp").html(subFinish.toISOString()); $("#sub-finish-timestamp").html(subFinish.toISOString());
|
||
// $("#sub-time").html((subFinish.getTime() - subStart.getTime()) / 1000 + "sec");
|
||
// });
|
||
// },
|
||
// after: function () {
|
||
// tableFinish = new Date(Date.now());
|
||
// $("#table-finish-timestamp").html(tableFinish.toISOString());
|
||
// $("#table-time").html((tableFinish.getTime() - tableStart.getTime()) / 1000 + "sec");
|
||
// },
|
||
// limit: -1,
|
||
// offset: 0
|
||
// });
|
||
// })
|
||
|
||
|
||
|
||
// sub2.attach('changed', function (prop) {
|
||
// if (prop.getName() === 'out') { update(this); }
|
||
// });
|
||
|
||
// var read_folder_start = new Date(Date.now())
|
||
// $("#read-folder-start-timestamp").html(read_folder_start.toISOString());
|
||
//讀取單一資料夾
|
||
//baja.Ord.make('local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, msgText, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState')
|
||
// baja.Ord.make('local:|foxs:|station:|slot:/Arena/H/E1/B1F/TestData/H_E1_B1F_TestData_Data')
|
||
// .get()
|
||
// .then(function (folder) {
|
||
// var read_folder_finish = new Date(Date.now())
|
||
// $("#read-folder-finish-timestamp").html(read_folder_finish.toISOString());
|
||
// $("#read-folder-time").html((read_folder_finish.getTime() - read_folder_start.getTime()) / 1000 + "sec");
|
||
|
||
// var batch = new baja.comm.Batch();
|
||
|
||
// var sub2Start = new Date(Date.now())
|
||
// $("#folder-sub-start-timestamp").html(sub2Start.toISOString());
|
||
// folder.getSlots().isComponent().eachValue(function (point) {
|
||
// $("#folder-sub-point-name").html(point.getDisplayName());
|
||
// sub2.subscribe({
|
||
// comps: point,
|
||
// batch: batch
|
||
// });
|
||
|
||
// var sub2Finish = new Date(Date.now());
|
||
// $("#folder-sub-finish-timestamp").html(sub2Finish.toISOString());
|
||
// $("#folder-sub-time").html((sub2Finish.getTime() - sub2Start.getTime()) / 1000 + "sec");
|
||
// });
|
||
// });
|
||
});
|
||
}
|
||
|
||
//設定開關
|
||
// function TestBajaAlarm() {
|
||
// require(['baja!'], function (baja) {
|
||
// var sub = new baja.Subscriber();
|
||
|
||
// /**
|
||
// * 針對傳入設備抓取點位
|
||
// */
|
||
// //baja.Ord.make("local:|foxs:|station:|slot:/Arena/" + device_number_split.slice(0, 4).join("/") + "/" + device.device_number)
|
||
// baja.Ord.make('local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, msgText, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState')
|
||
// .get()
|
||
// .then(function (folder) {
|
||
// folder.getSlots().isComponent().eachValue(function (point) {
|
||
// if (point.getDisplayName() == "SSC") {
|
||
// sub.subscribe({
|
||
// comps: point,
|
||
// });
|
||
// }
|
||
// });
|
||
// });
|
||
|
||
// });
|
||
// }
|
||
|
||
// function TestBajaAlarm() {
|
||
// require(['baja!'], function (baja) {
|
||
// baja.Ord.make("local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, msgText, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState")
|
||
// // baja.Ord.make("local:|foxs:|station:|slot:/Arena|bql:select * from control:BooleanWritable where parent.name like 'H_%'")
|
||
// .get(function (table) {
|
||
// table.cursor({
|
||
// before: function () {
|
||
// },
|
||
// each: function (item, index) {
|
||
|
||
// //用來查看顯示內容
|
||
// var temp_value = this.getDisplay("toString");
|
||
// var facets = this.getDisplay("facets");
|
||
|
||
// var facets_split = this.getDisplay("facets").split(',');
|
||
// var facets_arr = [];
|
||
// facets_split.forEach(function (item, index) {
|
||
// facets_arr.push(item.split('='));
|
||
// });
|
||
|
||
// var facets = facets_arr.reduce((obj, cur) => ({ ...obj, [cur[0]]: cur[1] }), {})
|
||
// let point_value = Object.keys(facets).find(k => facets[k] === temp_value.split(" ")[0]);
|
||
// var device_index = 0;
|
||
// // var device_index = baja_boolean_raw_data.findIndex(x => x.device_number == this.getDisplay("parent$2ename"))
|
||
|
||
// if (device_index > -1) { //有device_number 去更新或新增point
|
||
// //var point_index = baja_boolean_raw_data[device_index].points.findIndex(x => x.name == this.getDisplay("displayName"))
|
||
|
||
// if (point_index > -1) { //有point點位,修改其值
|
||
// //baja_boolean_raw_data[device_index].points[point_index].value = point_value;
|
||
// }
|
||
// else {
|
||
// var point = {
|
||
// "name": this.getDisplay("displayName"),
|
||
// "value": point_value
|
||
// }
|
||
// //baja_boolean_raw_data[device_index].points.push(point)
|
||
// }
|
||
// }
|
||
// else { //沒有直接新增該device_number及points
|
||
// var device = {
|
||
// "device_number": this.getDisplay("parent$2ename"),
|
||
// "points": [{
|
||
// "name": this.getDisplay("displayName"),
|
||
// "value": point_value
|
||
// }]
|
||
// }
|
||
|
||
// //baja_boolean_raw_data.push(device);
|
||
// }
|
||
|
||
// },
|
||
// after: function () {
|
||
// //baja_boolean_raw_data_func(baja_boolean_raw_data);
|
||
// },
|
||
// limit: -1,
|
||
// offset: 0
|
||
// });
|
||
// });
|
||
// });
|
||
// }
|
||
|
||
function getHistoryDataByBaja(devicePath, startDate_millisecond, endDate_millisecond, deviceName, company, callback) {
|
||
var result = "";
|
||
var ss = "";
|
||
var index = 0;
|
||
|
||
require(['baja!'], function (baja) {
|
||
baja.Ord.make('local:|foxs:|history:/' + company + '/' + devicePath + '|bql:select * from control:ControlPoint where timestamp.millis > ' + startDate_millisecond + ' and timestamp.millis < ' + endDate_millisecond).get()
|
||
.then(function (table) {
|
||
return table.cursor({
|
||
each: function (record) {
|
||
ss += ', "' + index + '": {"deviceName":"'+ deviceName + '", "value":' + record.get('value') +', "timestamp":"' + record.get('timestamp') + '"}';
|
||
index++;
|
||
},
|
||
after: function () {
|
||
result += '{' + '"count": ' + index;
|
||
result += ss;
|
||
result += '}';
|
||
if(typeof callback === 'function') {
|
||
callback(result);
|
||
}
|
||
}
|
||
});
|
||
});
|
||
});
|
||
|
||
}
|
||
|
||
function getAlarmByBaja(startDate_millisecond, endDate_millisecond, isRecover, isAck, alarmClass, callback) {
|
||
var result = "";
|
||
var ss = "";
|
||
let sourceTmp;
|
||
var bfName = "", sourceName = "";
|
||
var index = 0;
|
||
var recoverState = isRecover ? "!= null" : "= null"
|
||
var ackState = isAck ? "= 1" : "!= 1";
|
||
|
||
require(['baja!'], function (baja) {//" and ackState = '" + ackState +
|
||
baja.Ord.make("local:|foxs:|alarm:|bql:select timestamp, ackState, alarmClass, alarmClassDisplayName, alarmValue, alarmData, alarmData.sourceName, uuid, alarmData.msgText, alarmData.numericValue, alarmData.presentValue, alarmData.status, alarmData.toState, normalTime from openAlarms where alarmClass = '" + alarmClass + "' and timestamp.millis > " + startDate_millisecond + " and timestamp.millis < " + endDate_millisecond + " and normalTime " + recoverState + " order by timestamp asc").get()
|
||
//baja.Ord.make("local:|foxs:|alarm:|bql:select *").get()
|
||
.then(function (table) {
|
||
return table.cursor({
|
||
each: function (record) {
|
||
sourceTmp = (record.get('alarmData').get('sourceName')).toString().split('_');
|
||
bfName = sourceTmp[1] + "-" + sourceTmp[4];
|
||
sourceName = sourceTmp[7] + "-" + sourceTmp[8];
|
||
ss += ', "' + index + '": {"buildingFloorName_zh":"' + bfName + '", "uuid":"' + record.get('uuid') + '", "timestamp":"' + record.get('timestamp') + '", "alarmClass":"' + record.get('alarmClass') + '", "sourceName_zh":"' + sourceName + '", "msgText":"' + record.get('alarmData').get('msgText') + '", "ackState":"' + record.get('ackState') + '", "normalTime":"' + record.get('normalTime') + '"}';
|
||
index++;
|
||
},
|
||
after: function () {
|
||
result += '{' + '"count": ' + index;
|
||
result += ss;
|
||
result += '}';
|
||
if(typeof callback === 'function') {
|
||
callback(result);
|
||
}
|
||
}
|
||
});
|
||
});
|
||
});
|
||
}
|
||
|
||
function getOneDeviceAlarmTop10ByBaja(devicePath, callback) {
|
||
var result = "";
|
||
var ss = "";
|
||
var index = 0;
|
||
//var ackState = isAck ? "= 1" : "!= 1";
|
||
|
||
require(['baja!'], function (baja) {//" and ackState = '" + ackState +
|
||
baja.Ord.make("local:|foxs:|alarm:|bql:select top 10 timestamp, ackState, alarmData, alarmData.sourceName, sourceState, uuid, alarmData.msgText, normalTime where alarmData.sourceName like '%" + devicePath + "%' order by timestamp desc").get()
|
||
//baja.Ord.make("local:|foxs:|alarm:|bql:select *").get()
|
||
.then(function (table) {
|
||
return table.cursor({
|
||
each: function (record) {
|
||
// sourceTmp = (record.get('alarmData').get('sourceName')).toString().split('_');
|
||
// bfName = sourceTmp[1] + "-" + sourceTmp[4];
|
||
// sourceName = sourceTmp[7] + "-" + sourceTmp[8];
|
||
ss += ', "' + index + '": {"uuid":"' + record.get('uuid') + '", "timestamp":"' + record.get('timestamp') + '", "sourceName":"' + record.get('alarmData').get('sourceName') + '", "sourceState":"' + record.get('sourceState') + '", "msgText":"' + record.get('alarmData').get('msgText') + '", "ackState":"' + record.get('ackState') + '", "normalTime":"' + record.get('normalTime') + '"}';
|
||
index++;
|
||
},
|
||
after: function () {
|
||
result += '{' + '"count": ' + index;
|
||
result += ss;
|
||
result += '}';
|
||
if(typeof callback === 'function') {
|
||
callback(result);
|
||
}
|
||
}
|
||
});
|
||
});
|
||
});
|
||
}
|
||
|
||
function getOneSystemAlarmStateByBaja(systemPath, callback) {
|
||
var result = "";
|
||
var ss = "";
|
||
var index = 0;
|
||
|
||
require(['baja!'], function (baja) {
|
||
baja.Ord.make("local:|foxs:|alarm:|bql:select timestamp, ackState, alarmData, alarmData.sourceName, sourceState, uuid, alarmData.msgText, normalTime where alarmData.sourceName like '%" + systemPath + "%' order by timestamp desc").get()
|
||
.then(function (table) {
|
||
return table.cursor({
|
||
each: function (record) {
|
||
ss += ', "' + index + '": {"uuid":"' + record.get('uuid') + '", "sourceName":"' + record.get('alarmData').get('sourceName') + '", "sourceState":"' + record.get('sourceState') + '"}';
|
||
index++;
|
||
},
|
||
after: function () {
|
||
result += '{' + '"count": ' + index;
|
||
result += ss;
|
||
result += '}';
|
||
if(typeof callback === 'function') {
|
||
callback(result);
|
||
}
|
||
}
|
||
});
|
||
});
|
||
});
|
||
}
|
||
|
||
function getOneDeviceAlarmStateByBaja(devicePath, callback) {
|
||
var result = "";
|
||
var ss = "";
|
||
var index = 0;
|
||
|
||
require(['baja!'], function (baja) {
|
||
baja.Ord.make("local:|foxs:|alarm:|bql:select top 1 timestamp, ackState, alarmData, alarmData.sourceName, sourceState, uuid, alarmData.msgText, normalTime where alarmData.sourceName like '%" + devicePath + "%' order by timestamp desc").get()
|
||
.then(function (table) {
|
||
return table.cursor({
|
||
each: function (record) {
|
||
if (index == 0)
|
||
ss += '{"uuid":"' + record.get('uuid') + '", "msgText":"' + record.get('alarmData').get('msgText') + '", "ackState":"' + record.get('ackState') + '", "timestamp":"' + record.get('timestamp') + '"}';
|
||
else
|
||
ss += ',{"uuid":"' + record.get('uuid') + '", "msgText":"' + record.get('alarmData').get('msgText') + '", "ackState":"' + record.get('ackState') + '", "timestamp":"' + record.get('timestamp') + '"}';
|
||
index++;
|
||
},
|
||
after: function () {
|
||
result += '{' + '"count": ' + index +', data:[';
|
||
|
||
result += ss+']';
|
||
result += '}';
|
||
if (typeof callback === 'function') {
|
||
callback(result);
|
||
}
|
||
}
|
||
});
|
||
});
|
||
});
|
||
}
|
||
|
||
|
||
|
||
//local:|foxs:|alarm:|bql:select timestamp, ackState, alarmData.sourceName, uuid, alarmData.msgText, normalTime where alarmData.sourceName != 'TPE_B1_ELEV_EL_R2F_NA_ELEV1_N1_TRIP' order by timestamp desc
|
||
// function testByBaja(devicePath, callback) {
|
||
// var result = "";
|
||
// var ss = "";
|
||
// var index = 0;
|
||
// //var ackState = isAck ? "= 1" : "!= 1";
|
||
|
||
// require(['baja!'], function (baja) {//" and ackState = '" + ackState +
|
||
// baja.Ord.make("local:|foxs:|alarm:|bql:select timestamp, ackState, alarmData, alarmData.sourceName, sourceState, uuid, alarmData.msgText, normalTime where alarmData.sourceName != 'TPE_B1_ELEV_EL_R2F_NA_ELEV1_N1_TRIP' order by timestamp desc").get()
|
||
// //baja.Ord.make("local:|foxs:|alarm:|bql:select *").get()
|
||
// .then(function (table) {
|
||
// return table.cursor({
|
||
// each: function (record) {
|
||
// // sourceTmp = (record.get('alarmData').get('sourceName')).toString().split('_');
|
||
// // bfName = sourceTmp[1] + "-" + sourceTmp[4];
|
||
// // sourceName = sourceTmp[7] + "-" + sourceTmp[8];
|
||
// ss += ', "' + index + '": {"uuid":"' + record.get('uuid') + '", "timestamp":"' + record.get('timestamp') + '", "sourceName":"' + record.get('alarmData').get('sourceName') + '", "sourceState":"' + record.get('sourceState') + '", "msgText":"' + record.get('alarmData').get('msgText') + '", "ackState":"' + record.get('ackState') + '", "normalTime":"' + record.get('normalTime') + '"}';
|
||
// index++;
|
||
// },
|
||
// after: function () {
|
||
// result += '{' + '"count": ' + index;
|
||
// result += ss;
|
||
// result += '}';
|
||
// if(typeof callback === 'function') {
|
||
// callback(result);
|
||
// }
|
||
// }
|
||
// });
|
||
// });
|
||
// });
|
||
// }
|
||
/*let baja_subscribe_device_callback_func; //設定BQL訂閱之後要回傳的Function*/
|
||
var ordPath; //當前點選選單的tag,用來抓出設備路徑,例如:旅館棟->H,消防偵煙器->F3
|
||
|
||
function subscription() {
|
||
// 20220929 改用BQL的方式去訂閱
|
||
this.setSubscribeDevicesByBql = function (tempOrdPath) {
|
||
ordPath = tempOrdPath;
|
||
BajaSubscribeDevicesByBql();
|
||
};
|
||
//20220929 BQL去訂閱回傳的Function
|
||
this.setSubscribeDevicesCallBack = function (callBackFunc) {
|
||
if (callBackFunc != undefined && callBackFunc != null) {
|
||
baja_subscribe_device_callback_func = callBackFunc;
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 使用者透過BQL指定路徑去訂閱設備點位
|
||
*/
|
||
function BajaSubscribeDevicesByBql() {
|
||
require(['baja!'], function (baja) {
|
||
console.log("進入Function 準備執行BQL訂閱");
|
||
var init_start = new Date(Date.now());
|
||
var sub = new baja.Subscriber();
|
||
|
||
sub.attach('changed', function (prop) {
|
||
if (prop.getName() === 'out') {
|
||
var out_value = this.getOutDisplay();
|
||
var target_device_number = this.$parent.getDisplayName().split('_').slice(0, 5).join('_');
|
||
var point_name = this.getDisplayName();
|
||
|
||
//依據Facets判斷回傳的內容值為何
|
||
var facets_split = this.getFacets1().$cEncStr.split('|');
|
||
var facets_arr = [];
|
||
facets_split.forEach(function (item, index) {
|
||
facets_arr.push(item.split('=s:'));
|
||
});
|
||
|
||
var facets = facets_arr.reduce((obj, cur) => ({ ...obj, [cur[0]]: cur[1] }), {})
|
||
|
||
var point_out_split = this.getOutDisplay().split(' ');
|
||
|
||
let key = Object.keys(facets).find(k => facets[k] === point_out_split[0]);
|
||
|
||
if (key == undefined) {
|
||
key = point_out_split[0];
|
||
}
|
||
|
||
var modify_target_device = {
|
||
"device_number": target_device_number ? target_device_number : null,
|
||
"point_name": point_name ? point_name : null,
|
||
"value": key
|
||
}
|
||
|
||
if (baja_subscribe_device_callback_func != undefined && baja_subscribe_device_callback_func != null) {
|
||
baja_subscribe_device_callback_func(modify_target_device, true); //第2參數用在平面圖,刷新畫面
|
||
}
|
||
}
|
||
});
|
||
|
||
//使用bql語法
|
||
// var building_tag = "H";
|
||
// var system_tag = "M10";
|
||
// baja.Ord.make(`ip:greencloud.fic.com.tw|foxs:|station:|slot:/Arena/${building_tag}/${system_tag}|bql:select name, displayname, slotPath, out.value, out from control:ControlPoint`)
|
||
console.log(`local:|foxs:|station:|slot:/Arena/${ordPath.building_tag}/${ordPath.system_tag}|bql:select name, displayname, slotPath, out.value, out, facets from control:ControlPoint`);
|
||
baja.Ord.make(`local:|foxs:|station:|slot:/Arena/${ordPath.building_tag}/${ordPath.system_tag}|bql:select name, displayname, slotPath, out.value, out, facets from control:ControlPoint`)
|
||
.get(
|
||
function (table) {
|
||
var tableStart, tableFinish;
|
||
var subStart, subFinish;
|
||
var component_index = 0;
|
||
var total_component_index = 0;
|
||
var readBqlFinish = new Date(Date.now());
|
||
// $("#readPath-finish-timestamp").html(readBqlFinish.toISOString());
|
||
// $("#readPath-finish-time").html((readBqlFinish.getTime() - init_start.getTime()) / 1000 + "sec");
|
||
console.log("讀取路徑完成-花費時間", (readBqlFinish.getTime() - init_start.getTime()) / 1000 + "sec");
|
||
|
||
table.cursor({
|
||
before: function () {
|
||
tableStart = new Date(Date.now());
|
||
$("#table-start-timestamp").html(tableStart.toISOString());
|
||
render_start = new Date(Date.now());
|
||
},
|
||
each: function (item, index) {
|
||
if (index < 1) {
|
||
subStart = new Date(Date.now());
|
||
$("#sub-start").html(subStart.toISOString());
|
||
}
|
||
$("#sub-number").html(index + 1);
|
||
total_component_index = index;
|
||
|
||
|
||
var target_device_number_split = this.getDisplay("slotPath").split('/');
|
||
var target_device_number = target_device_number_split[target_device_number_split.length - 2];
|
||
console.log(target_device_number);
|
||
var point_name = this.getDisplay("name");
|
||
var facets = this.getDisplay("facets");
|
||
|
||
//依據Facets判斷回傳的內容值為何
|
||
var facets_split = facets.split(',');
|
||
var facets_arr = [];
|
||
facets_split.forEach(function (item, index) {
|
||
facets_arr.push(item.split('='));
|
||
});
|
||
|
||
facets = facets_arr.reduce((obj, cur) => ({ ...obj, [cur[0]]: cur[1] }), {})
|
||
|
||
var point_out_split = this.getDisplay("out").split(' ');
|
||
|
||
let key = Object.keys(facets).find(k => facets[k] === point_out_split[0]);
|
||
|
||
if (key == undefined) {
|
||
key = point_out_split[0];
|
||
}
|
||
|
||
var modify_target_device = {
|
||
"device_number": target_device_number ? target_device_number : null,
|
||
"point_name": point_name ? point_name : null,
|
||
"value": key
|
||
}
|
||
|
||
//取得component當下就更新設備點位
|
||
if (baja_subscribe_device_callback_func != undefined && baja_subscribe_device_callback_func != null) {
|
||
baja_subscribe_device_callback_func(modify_target_device);
|
||
}
|
||
|
||
|
||
baja.Ord.make("local:|foxs:|station:|" + this.getDisplay("slotPath"))
|
||
.get()
|
||
.then(function (component) {
|
||
component_index++;
|
||
var target_device_number = component.$parent.getDisplayName().split('_').slice(0, 5).join('_');
|
||
var point_name = component.getDisplayName();
|
||
|
||
// //依據Facets判斷回傳的內容值為何
|
||
// var facets_split = component.getFacets1().$cEncStr.split('|');
|
||
// var facets_arr = [];
|
||
// facets_split.forEach(function (item, index) {
|
||
// facets_arr.push(item.split('=s:'));
|
||
// });
|
||
|
||
// var facets = facets_arr.reduce((obj, cur) => ({ ...obj, [cur[0]]: cur[1] }), {})
|
||
|
||
// var point_out_split = component.getOutDisplay().split(' ');
|
||
|
||
// let key = Object.keys(facets).find(k => facets[k] === point_out_split[0]);
|
||
|
||
// if (key == undefined) {
|
||
// key = point_out_split[0];
|
||
// }
|
||
|
||
// var modify_target_device = {
|
||
// "device_number": target_device_number ? target_device_number : null,
|
||
// "point_name": point_name ? point_name : null,
|
||
// "value": key
|
||
// }
|
||
|
||
// //取得component當下就更新設備點位
|
||
// if (baja_subscribe_device_callback_func != undefined && baja_subscribe_device_callback_func != null) {
|
||
// if (component_index == total_component_index) {
|
||
// baja_subscribe_device_callback_func(modify_target_device, true);
|
||
// }
|
||
// else {
|
||
// baja_subscribe_device_callback_func(modify_target_device);
|
||
// }
|
||
// }
|
||
|
||
sub.subscribe({
|
||
comps: component,
|
||
});
|
||
|
||
subFinish = new Date(Date.now());
|
||
$("#sub-end").html(subFinish.toISOString());
|
||
$("#sub-time").html((subFinish.getTime() - subStart.getTime()) / 1000 + "sec");
|
||
// console.log("訂閱完成時間", (subFinish.getTime() - subStart.getTime()) / 1000 + "sec");
|
||
});
|
||
},
|
||
after: function () {
|
||
tableFinish = new Date(Date.now());
|
||
// $("#table-finish-timestamp").html(tableFinish.toISOString());
|
||
// $("#table-time").html((tableFinish.getTime() - tableStart.getTime()) / 1000 + "sec");
|
||
console.log("表格完成時間", (tableFinish.getTime() - tableStart.getTime()) / 1000 + "sec");
|
||
},
|
||
limit: -1,
|
||
offset: 0
|
||
});
|
||
});
|
||
});
|
||
}
|
||
|
||
|
||
|
||
|
||
var result = "";
|
||
function BajaSubscription() {
|
||
|
||
|
||
var settings = {
|
||
"url": "http://localhost:8080/obix/watchService/make/",
|
||
"method": "POST",
|
||
"timeout": 0,
|
||
"headers": {
|
||
"Authorization": "Basic b2JpeFVzZXI6QWRtaW4xMjM0NTY=",
|
||
"Cookie": "JSESSIONID=fd355d0063a6bfab6909844e838f696786ad487bf9e1e8d8ce"
|
||
},
|
||
};
|
||
|
||
$.ajax(settings).done(function (response) {
|
||
//console.log(response);
|
||
let splitStr = response.getElementsByName("lease")[0].attributes.href.nodeValue.split("watch");
|
||
console.log("href:" + response.getElementsByName("lease")[0].attributes.href.nodeValue);
|
||
var str = splitStr[2];
|
||
var index = 0;
|
||
while(str[index] != "/"){
|
||
result += str[index++];
|
||
}
|
||
//response.getElementsByName("lease")[0].attributes.href.nodeValue[position+5]
|
||
console.log(result);
|
||
step2();
|
||
});
|
||
}
|
||
|
||
function step2() {
|
||
var settings1 = {
|
||
"url": "http://localhost:8080/obix/watchService/defaultLeaseTime/",
|
||
"method": "PUT",
|
||
"timeout": 0,
|
||
"headers": {
|
||
"Authorization": "Basic b2JpeFVzZXI6QWRtaW4xMjM0NTY=",
|
||
"Content-Type": "text/plain",
|
||
"Cookie": "JSESSIONID=b4a7150d89d8dd8fd54fdce510f12b3d3a7462d46060852de5"
|
||
},
|
||
"data": "<reltime val=\"PT24H0S\" />",
|
||
};
|
||
|
||
$.ajax(settings1).done(function (response) {
|
||
console.log("step2: " + response);
|
||
step3();
|
||
});
|
||
}
|
||
|
||
function step3() {
|
||
var settings2 = {
|
||
"url": "http://localhost:8080/obix/watchService/watch" + result + "/lease/",
|
||
"method": "PUT",
|
||
"timeout": 0,
|
||
"headers": {
|
||
"Authorization": "Basic b2JpeFVzZXI6QWRtaW4xMjM0NTY=",
|
||
"Content-Type": "text/plain",
|
||
"Cookie": "JSESSIONID=bc6daf759e226629aa65192d579e57c4744074966c43536151"
|
||
},
|
||
"data": "<reltime val=\"PT24H0S\" />",
|
||
};
|
||
|
||
$.ajax(settings2).done(function (response) {
|
||
console.log("step3: " + response);
|
||
// var xml = response;
|
||
// dom = parseXml(xml);
|
||
// json = xml2json(dom);
|
||
// console.log("result : " + json);
|
||
// let data = xml2json(parseXml(response), '')
|
||
// console.log(JSON.parse(data));
|
||
step4();
|
||
});
|
||
}
|
||
|
||
function step4() {
|
||
var settings3 = {
|
||
"url": "http://localhost:8080/obix/watchService/watch" + result + "/add/",
|
||
"method": "POST",
|
||
"timeout": 0,
|
||
"headers": {
|
||
"Authorization": "Basic b2JpeFVzZXI6QWRtaW4xMjM0NTY=",
|
||
"Content-Type": "text/plain",
|
||
"Cookie": "JSESSIONID=9d365b2475d2b4c15f20286c0a2800abecb850072de8853091"
|
||
},
|
||
|
||
};
|
||
|
||
$.ajax(settings3).done(function (response) {
|
||
console.log("step4: " + response);
|
||
});
|
||
}
|