| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- function hex2float(num) {
- var sign = (num & 0x80000000) ? -1 : 1;
- var exponent = ((num >> 23) & 0xff) - 127;
- var mantissa = 1 + ((num & 0x7fffff) / 0x7fffff);
- return sign * mantissa * Math.pow(2, exponent);
- }
- function float2hex(num) {
- if (num == "")
- return "";
- num = parseFloat(num);
- if (isNaN(num) == true)
- return "Error";
- if (num == 0)
- return "00000000";
- let s, e, m;
- if (num > 0)
- s = 0;
- else {
- s = 1;
- num = 0 - num;
- }
- m = num.toString(2);
- if (m >= 1) {
- if (m.indexOf(".") == -1)
- m = m + ".0";
- e = m.indexOf(".") - 1;
- } else
- e = 1 - m.indexOf("1");
- if (e >= 0)
- m = m.replace(".", "");
- else
- m = m.substring(m.indexOf("1"));
- if (m.length > 24)
- m = m.substr(0, 24);
- else
- m = FillString(m, "0", 24, false)
- m = m.substring(1);
- e = (e + 127).toString(2);
- e = FillString(e, "0", 8, true);
- var r = parseInt(s + e + m, 2).toString(16);
- r = FillString(r, "0", 8, true);
- return parseInt(r, 16);
- // return HEX.InsertString(r, "", 2).toUpperCase();
- }
- function roundFun(value, n) {
- // if (value == 0 || value == undefined || value == null || value < 1e-10) {
- if (value == 0 || value == undefined || value == null || (value < 1e-10 && value > -1e-10)) {
- let num = "0.";
- num = num.padEnd(n + 2, "0");
- return num;
- }
- else {
- let num = Math.round(value * Math.pow(10, n)) / Math.pow(10, n);
- num = num.toString().split(".");
- if (num[1]) {
- num[1] = num[1].padEnd(n, "0");
- return (num[0] + "." + num[1]);
- }
- else {
- num += ".";
- num = num.padEnd(num.length + n, "0");
- return num;
- }
- }
- }
- function FillString(t, c, n, b) {
- if ((t == "") || (c.length != 1) || (n <= t.length))
- return t;
- let l = t.length;
- for (var i = 0; i < n - l; i++) {
- if (b == true)
- t = c + t;
- else
- t += c;
- }
- return t;
- }
- function GenCrc16Modbus(buf, len) {
- let crcValue = 0xFFFF;
- for (let i = 0; i < len; i++) {
- crcValue ^= buf[i] & 0xFFFF;
- for (let j = 0; j < 8; j++) {
- if (crcValue & 0x0001) {
- crcValue >>= 1;
- crcValue ^= 0xA001;
- }
- else {
- crcValue >>= 1;
- }
- }
- }
- return crcValue;
- }
- function GenCrc16ModbusHL(buf, size, highLow) {
- if (highLow)
- return ((GenCrc16Modbus(buf, size) & 0x00FF));
- return ((GenCrc16Modbus(buf, size) >> 8) & 0xFF);
- }
- function CheckCrc16Modbus(buf, size) {
- let tempCrc = GenCrc16Modbus(buf, size - 2);
- let CRC_L = (tempCrc & 0x00FF);
- let CRC_H = ((tempCrc >> 8) & 0xFF);
- if ((buf[size - 2] == CRC_L) && (buf[size - 1] == CRC_H))
- return 0;
- return 1;
- }
- function TimeFormat(time = +new Date()) {
- var date = mbFloatChange_u.u8_t[0](time + 8 * 3600 * 1000);
- return date.toJSON().replace('T', ' ').replace('Z', '');
- }
- function GetCookie(name) {
- var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
- if (arr = document.cookie.match(reg)) {
- return (arr[2]);
- } else {
- return null;
- }
- }
- function SetCookie(name, value) {
- document.cookie = name + "=" + value;
- }
- function ClearAllCookies() {
- var keys = document.cookie.match(/[^ =;]+(?=\=)/g);
- if (keys) {
- for (var i = keys.length; i--;)
- document.cookie = keys[i] + '=0;expires=' + new Date(0).toUTCString()
- }
- // document.cookie = keys[i] + '=0;path=/;expires=' + new Date(0).toUTCString(); //清除当前域名下的,例如:m.kevis.com
- // document.cookie = keys[i] + '=0;path=/;domain=' + document.domain + ';expires=' + new Date(0).toUTCString(); //清除当前域名下的,例如 .m.kevis.com
- // document.cookie = keys[i] + '=0;path=/;domain=kevis.com;expires=' + new Date(0).toUTCString(); //清除一级域名下的或指定的,例如 .kevis.com
- console.log("Clear All Cookies");
- }
- function HintWindow(str, timeMs) {
- HintWindowClear();
- var hintWindow = document.createElement("div");
- hintWindow.id = "hintWindow";
- document.body.appendChild(hintWindow);
- hintWindow.innerHTML = str;
- hintWindow.style.color = "white";
- hintWindow.style.backgroundColor = "grey";
- hintWindow.style.textAlign = "center";
- hintWindow.style.position = "absolute";
- // hintWindow.style.top = "50%";
- // hintWindow.style.left = "50%";
- hintWindow.style.bottom = "0";
- hintWindow.style.right = "0";
- hintWindow.style.transform = "translate(-50%, -50%)";
- hintWindow.style.padding = "1%";
- hintWindow.style.borderRadius = "3px";
- hintWindow.style.zIndex = 101;
- hintWindowId = setTimeout('\
- if (document.getElementById("hintWindow") != null) {\
- document.body.removeChild(document.getElementById("hintWindow"));\
- }', timeMs);
- }
- function HintWindowClear() {
- if (document.getElementById("hintWindow") != null) {
- document.body.removeChild(document.getElementById("hintWindow"));
- clearTimeout(hintWindowId);
- }
- }
- function ReadTextFile(fileName) {
- // console.log(fileName);
- var readContent = null;
- var rawFile = new XMLHttpRequest();
- try {
- rawFile.open("GET", fileName, false);
- rawFile.onreadystatechange = function () {
- if (rawFile.readyState === 4) {
- if (rawFile.status === 200 || rawFile.status == 0) {
- readContent = rawFile.responseText;
- // readContent = JSON.parse(rawFile.responseText);
- // console.log(readContent);
- }
- }
- }
- rawFile.send(null);
- } catch (error) { }
- return readContent;
- }
- function TableRowShowHide(eTable, iRow, showHide) {
- if (showHide == true)
- document.getElementById(eTable).rows[iRow].style.display = "table-row";
- else
- document.getElementById(eTable).rows[iRow].style.display = "none";
- }
- function TableColShowHide(eTable, iCol, showHide) {
- for (let i = 0; i < document.getElementById(eTable).rows.length; i++) {
- if (showHide == true)
- document.getElementById(eTable).rows[i].cells[iCol].style.display = "table-cell";
- else
- document.getElementById(eTable).rows[i].cells[iCol].style.display = "none";
- }
- }
- function HtmlGetMyPath() {
- // console.log(location.href.replace(HtmlFetMyName(), ""));
- return location.href.replace(HtmlFetMyName(), "");
- }
- function HtmlFetMyName() {
- var str = location.href.split('/');
- // console.log(str[str.length - 1]);
- return str[str.length - 1];
- }
- function HtmlGetMySrc() {
- // console.log(location.href);
- return location.href;
- }
- // HtmlGetMyPath();
- // HtmlFetMyName();
- // HtmlGetMySrc();
- function JsGetMyPath() {
- var scriptSrc = document.getElementsByTagName('script')[document.getElementsByTagName('script').length - 1].src;
- var jsName = scriptSrc.split('/')[scriptSrc.split('/').length - 1];
- // console.log(scriptSrc.replace(jsName, ''));
- return scriptSrc.replace(jsName, '');
- }
- function JsGetMyName() {
- var scriptSrc = document.getElementsByTagName('script')[document.getElementsByTagName('script').length - 1].src;
- var jsName = scriptSrc.split('/')[scriptSrc.split('/').length - 1];
- // console.log(jsName);
- return jsName;
- }
- function JsGetMySrc() {
- var scriptSrc = document.getElementsByTagName('script')[document.getElementsByTagName('script').length - 1].src;
- // console.log(scriptSrc);
- return scriptSrc;
- }
- // JsGetMyPath();
- // JsGetMyName();
- // JsGetMySrc();
- function StringToFloatArray(str) {
- var tempArray = new Float32Array(str.split(',').length);
- for (let i in str.split(','))
- tempArray[i] = parseFloat(str.split(',')[i]);
- return tempArray;
- }
- function ALGO_NumberSuitScop(valueIn, scopMin, scopMax, step) {
- while (valueIn < scopMin || valueIn > scopMax) {
- if (valueIn < scopMin)
- valueIn += step;
- else if (valueIn > scopMax)
- valueIn -= step;
- }
- return valueIn;
- }
- function NumberTo5(num) {
- // num = parseInt(num);
- if (num % 10 <= 2.5)
- return parseInt(num / 10) * 10;
- else if (num % 10 > 2.5 && num % 10 <= 7.5)
- return (parseInt(num / 10) * 10) + 5;
- else if (num % 10 > 7.5)
- return (parseInt(num / 10) * 10) + 10;
- }
|