2023-11-30 16:07:41 +08:00
|
|
|
import { store } from "../store";
|
|
|
|
|
2023-11-09 13:36:21 +08:00
|
|
|
export function randomInt(min, max, includeMax = false) {
|
2023-11-30 16:07:41 +08:00
|
|
|
let Fn = includeMax ? Math.ceil : Math.floor;
|
|
|
|
let num = Fn(Math.random() * max);
|
|
|
|
while (num < min) {
|
|
|
|
num = Fn(Math.random() * max);
|
|
|
|
}
|
|
|
|
return num;
|
2023-11-09 13:36:21 +08:00
|
|
|
}
|
|
|
|
|
2023-12-06 16:37:53 +08:00
|
|
|
/**
|
|
|
|
* new XClient('ws://192.168.1.12:8081/xc-screen/websocket/xc001', 'DCS')
|
|
|
|
*/
|
|
|
|
class XClient {
|
|
|
|
constructor(url, name, onmessage) {
|
|
|
|
this.url = url;
|
|
|
|
this.name = name;
|
|
|
|
this.ws = new WebSocket(url);
|
|
|
|
this.ws.onopen = () => {
|
|
|
|
console.log(`[*] ${this.name} ws connected`);
|
2023-11-30 16:07:41 +08:00
|
|
|
};
|
2023-12-06 16:37:53 +08:00
|
|
|
this.ws.onmessage = onmessage;
|
|
|
|
this.ws.onerror = (err) => {
|
|
|
|
console.log("[*] websocket error!", err, err.data);
|
2023-11-30 16:07:41 +08:00
|
|
|
};
|
2023-12-06 16:37:53 +08:00
|
|
|
this.ws.onclose = (e) => {
|
|
|
|
console.log(`[*] ${this.name} ws closed`);
|
2023-11-30 16:07:41 +08:00
|
|
|
};
|
|
|
|
}
|
2023-11-09 13:36:21 +08:00
|
|
|
}
|
2023-12-06 16:37:53 +08:00
|
|
|
|
|
|
|
new XClient(
|
|
|
|
"ws://192.168.1.12:8081/xc-screen/websocket/xc001",
|
|
|
|
"DCS_DATA",
|
|
|
|
(msg) => {
|
|
|
|
let serializedData = null;
|
|
|
|
try {
|
|
|
|
serializedData = JSON.parse(msg.data);
|
|
|
|
} catch (error) {
|
|
|
|
console.log("[*] websocket: [unable to serialize] ---> ", msg);
|
|
|
|
}
|
|
|
|
switch (serializedData?.type) {
|
|
|
|
case "KilnInfo": {
|
|
|
|
store.dispatch({
|
|
|
|
type: "kiln/setKilnInfo",
|
|
|
|
payload: serializedData.data,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "CombustionAirInfo": {
|
|
|
|
// 助燃风流量 实时
|
|
|
|
store.dispatch({
|
|
|
|
type: "combustionAir/setRuntime",
|
|
|
|
payload: serializedData.data.combustionAirNow, // []
|
|
|
|
});
|
|
|
|
// 助燃风流量 历史
|
|
|
|
store.dispatch({
|
|
|
|
type: "combustionAir/setHistory",
|
|
|
|
payload: serializedData.data.combustionAirHis, // {}
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "GasInfo": {
|
|
|
|
// 天然气流量 1 实时
|
|
|
|
store.dispatch({
|
|
|
|
type: "natGas/setGasIRuntime",
|
|
|
|
payload: serializedData.data.gas1Now,
|
|
|
|
});
|
|
|
|
// 天然气流量 1 历史
|
|
|
|
store.dispatch({
|
|
|
|
type: "natGas/setGasIHistory",
|
|
|
|
payload: serializedData.data.hisGas1,
|
|
|
|
});
|
|
|
|
// 天然气流量 2 实时
|
|
|
|
store.dispatch({
|
|
|
|
type: "natGas/setGasIIRuntime",
|
|
|
|
payload: serializedData.data.gas2Now,
|
|
|
|
});
|
|
|
|
// 天然气流量 2 历史
|
|
|
|
store.dispatch({
|
|
|
|
type: "natGas/setGasIIHistory",
|
|
|
|
payload: serializedData.data.hisGas2,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "FanFrequencyInfo": {
|
|
|
|
// 风机运行频率 暂时只有实时数据
|
|
|
|
store.dispatch({
|
|
|
|
type: "fanFrequence/setRuntime",
|
|
|
|
payload: serializedData.data.FanFrequencyInfo,
|
|
|
|
});
|
|
|
|
// 风机运行频率 历史 暂无
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "TopTempInfo": {
|
|
|
|
// 碹顶温度列表
|
|
|
|
store.dispatch({
|
|
|
|
type: "temperature/setTopTemp",
|
|
|
|
payload: serializedData.data.topTempInfo,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "BottomTempInfo": {
|
|
|
|
// 碹底温度列表
|
|
|
|
store.dispatch({
|
|
|
|
type: "temperature/setBottomTemp",
|
|
|
|
payload: serializedData.data.bottomTempInfo,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "FeederInfo": {
|
|
|
|
// 投料机信息
|
|
|
|
store.dispatch({
|
|
|
|
type: "feeder/setFeederInfo",
|
|
|
|
payload: serializedData.data,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "FireInfo": {
|
|
|
|
// 火向时间信息
|
|
|
|
store.dispatch({
|
|
|
|
type: "fireInfo/setFireInfo",
|
|
|
|
payload: serializedData.data,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "FanInfo": {
|
|
|
|
// 风机信息
|
|
|
|
store.dispatch({
|
|
|
|
type: "fanInfo/setInfo",
|
|
|
|
payload: serializedData.data,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
console.log("websocket message: [unknown] ---> ", msg.data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
new XClient(
|
|
|
|
"ws://192.168.1.74:48080/websocket/message?userId=ENERGY111",
|
|
|
|
"MES_DATA",
|
|
|
|
(msg) => {
|
|
|
|
let serializedData = null;
|
|
|
|
try {
|
|
|
|
serializedData = JSON.parse(msg.data);
|
|
|
|
} catch (error) {
|
|
|
|
console.log("[*] websocket: [unable to serialize] ---> ", msg);
|
|
|
|
}
|
|
|
|
switch (serializedData?.type) {
|
|
|
|
case "EnergyInfo": {
|
|
|
|
// 能耗数据
|
|
|
|
store.dispatch({
|
|
|
|
type: "energy/setInfo",
|
|
|
|
payload: serializedData.data,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
console.log("websocket message: [unknown] ---> ", msg.data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|