/* function getValue() { GetRequest(); }*/ var g_lpr_name = ""; var request_live = null; function getalarmmotion_value() { var ipStr = '/getalarmmotion'; if (this.status == 404) { //request_live = setInterval(function () { /* if (navigator.userAgent.match("MSIE") || (!!window.ActiveXObject || "ActiveXObject" in window)) GetRequest_Http(); else*/ // GetRequest_WebSocket(); var replaceUrl = 'http://' + window.location.hostname + ':' + GetUrlPort() + '/Aida/lpr.html'; //alert(replaceUrl); parent.window.location.replace(replaceUrl); //}, 5000); } else { /* if (navigator.userAgent.match("MSIE") || (!!window.ActiveXObject || "ActiveXObject" in window)) GetRequest_Http(); else*/ GetRequest_WebSocket(); } } var TripwireTrafficMode = 0;//0:Traffic Light,1:Tripwire var TrafficLineMode = 0;//0:Rect,1:Line var g_Ctrl_InfoTrafficLight = [];//0:index,1:left,2:top,3:width,4:height,5:direct,6:Traffic Light var MAX_SIZE_POINTS = 6; var MAX_DETECTION_ZONE = 8; var G_VIEW_CANVAS_X = 640; var G_VIEW_CANVAS_Y = 480; var MAX_HEIGHT = G_VIEW_CANVAS_Y; var MAX_WIDTH = G_VIEW_CANVAS_X; var currentPointPosition1 = new Array(MAX_SIZE_POINTS); var currentPointPosition2 = new Array(MAX_SIZE_POINTS); var currentPointPosition3 = new Array(MAX_SIZE_POINTS); var currentPointPosition4 = new Array(MAX_SIZE_POINTS); var currentPointPosition5 = new Array(MAX_SIZE_POINTS); var currentPointPosition6 = new Array(MAX_SIZE_POINTS); var currentPointPosition7 = new Array(MAX_SIZE_POINTS); var currentPointPosition8 = new Array(MAX_SIZE_POINTS); var data_anpr = ""; var bbox_count = 0; var plate_count = 0; var plate_idx = 0; var ai_json; var complete_data = ""; var complete_flag = 0; var content_len = 0; var datas; var n1 = -1, n2 = -1 , n2_temp = -1; var wait_count = 0; var clear_count = 0; //sophia add 20201207 var MAX_LPR_ARRAY = 18; var MAX_LPR_SHIFT = 1; var LPR_Array = Array(MAX_LPR_ARRAY); var LPR_confidence_array = Array(MAX_LPR_ARRAY); var LPR_area_array = Array(MAX_LPR_ARRAY); var MAX_LPBMP_ARRAY = 18; var LPBMP_Array = Array(MAX_LPBMP_ARRAY); // lpr img path //var LPR_Array = Array(MAX_LPBMP_ARRAY); // lpr text //var LPRC_Array = Array(MAX_LPBMP_ARRAY); // lpr contry var just_change_lpr = 0; { for (var i = 0; i < MAX_LPR_ARRAY; i++) { LPR_Array[i] = "NULL"; LPR_confidence_array[i] = "NULL"; LPR_area_array[i] = "NULL"; } } {// LPBMP for (var i = 0; i < MAX_LPBMP_ARRAY; i++) { LPBMP_Array[i] = "NULL"; } } var g_drawing_canvas = { bounding_left: -1, bounding_top: -1, down_x: -1, down_y: -1, move_x: -1, move_y: -1, draw_x: -1, draw_y: -1, draw_w: -1, draw_h: -1, direct: 1 }; function push_lpr(mylpr,myarea,myconfidence) { for (var i = 0; i < MAX_LPR_ARRAY; i++) { if (LPR_Array[i] === "NULL") { LPR_Array[i] = mylpr; LPR_confidence_array[i] = myconfidence; LPR_area_array[i] = myarea; break; } else { if (i === MAX_LPR_ARRAY - 1) { for (var j = 0; j < MAX_LPR_ARRAY - 1; j++) { LPR_Array[j] = LPR_Array[j + 1]; LPR_confidence_array[j] = LPR_confidence_array[j + 1]; LPR_area_array[j] = LPR_area_array[j + 1]; } LPR_Array[j] = mylpr; LPR_confidence_array[j] = myconfidence; LPR_area_array[j] = myarea; } } } } function get_front_lpr() { var msg = ""; for (var i = MAX_LPR_ARRAY - 1; i >= MAX_LPR_SHIFT; i--) { if (LPR_Array[i] != "NULL") { if (LPR_area_array[i].length >= 1 && LPR_area_array[i] != "NULL") { msg += LPR_Array[i] + ", " + LPR_area_array[i] + ", " + LPR_confidence_array[i] + "
"; } else { msg += LPR_Array[i] + ", " + LPR_confidence_array[i] + "
"; } //console.log(LPR_Array[i], ", ", LPR_confidence_array[i]); //a113n } } return msg; } function validatingJSON(json) { var checkedjson; try { checkedjson = JSON.parse(json); //JSON parse only for try catch //console.log("json OK"); //console.log(json); } catch (e) { checkedjson = null; console.log(e);//the character would be drop sometimes, for example the label "class_id" may be "clas_id". //console.log(json); } return checkedjson; } function GetMaxWidth() { return MAX_WIDTH; } function GetMaxHeight() { return MAX_HEIGHT; } function GetAnpr() { if (!!data_anpr) { var complete_data = ""; complete_data = complete_data.concat(data_anpr); n1 = complete_data.indexOf('{"AiEngine"'); //n2 = complete_data.indexOf('"Count":'); n2_temp = complete_data.indexOf('"Count"'); n2 = complete_data.indexOf('}', n2_temp); var max_protected_objects = 1; if (n1 > 0 && n2_temp > 0 && n2 > 0 && (n1 + 7) < n2_temp && n2_temp < n2) { wait_count = 0; clear_count = 0; datas = complete_data.split(/\r\n|\r/); complete_data = ""; for (var i = datas.length-1; i >= 0; i--) { if (datas[i].length > 12 && datas[i].substring(0, 12) == '{"AiEngine":' && datas[i].length < 8192 * 8) { //datas[i].replace(/\\'/g, "'"); //datas[i].replace('\"', '"'); datas[i].replace('\n', ''); datas[i].replace('\r', ''); datas[i].replace('\t', ''); datas[i].replace('\\', ''); //var alarm_test = '{"AiEngine":[{"id":0,"channel_id":1,"camera_name":"","res_height":1080,"res_width":1920,"confidence":59,"engine_type":1,"label_name":"car","class_id":2,"obj_type":0,"obj_tracking_id":1,"obj_dwell_time":23,"color_id":0,"color":"","linked_plate":"","x":83,"y":136,"w":215,"h":168,"parent_idx":-1,"behavior_id":0},{"id":1,"channel_id":1,"camera_name":"","res_height":1080,"res_width":1920,"confidence":43,"engine_type":1,"label_name":"car","class_id":2,"obj_type":0,"obj_tracking_id":2,"obj_dwell_time":23,"color_id":0,"color":"","linked_plate":"","x":158,"y":538,"w":218,"h":144,"parent_idx":-1,"behavior_id":0},{"id":2,"channel_id":1,"camera_name":"","res_height":1080,"res_width":1920,"confidence":82,"engine_type":1,"label_name":"car","class_id":2,"obj_type":0,"obj_tracking_id":3,"obj_dwell_time":23,"color_id":0,"color":"","linked_plate":"","x":342,"y":175,"w":321,"h":196,"parent_idx":-1,"behavior_id":0},{"id":3,"channel_id":1,"camera_name":"","res_height":1080,"res_width":1920,"confidence":49,"engine_type":1,"label_name":"car","class_id":2,"obj_type":0,"obj_tracking_id":6,"obj_dwell_time":23,"color_id":0,"color":"","linked_plate":"","x":362,"y":578,"w":253,"h":132,"parent_idx":-1,"behavior_id":0},{"id":4,"channel_id":1,"camera_name":"","res_height":1080,"res_width":1920,"confidence":69,"engine_type":1,"label_name":"car","class_id":2,"obj_type":0,"obj_tracking_id":4,"obj_dwell_time":23,"color_id":0,"color":"","linked_plate":"","x":714,"y":608,"w":239,"h":130,"parent_idx":-1,"behavior_id":0},{"id":5,"channel_id":1,"camera_name":"","res_height":1080,"res_width":1920,"confidence":31,"engine_type":1,"label_name":"car","class_id":2,"obj_type":0,"obj_tracking_id":5,"obj_dwell_time":23,"color_id":0,"color":"","linked_plate":"","x":1035,"y":663,"w":340,"h":179,"parent_idx":-1,"behavior_id":0}],"Count":6}'; //ai_json = JSON.parse(alarm_test); var temp = null; temp = datas[i].slice(); //ai_json = JSON.parse(temp); ai_json = validatingJSON(temp); datas[i] = null; break; } } var AI_fps = ai_json.AI_fps; localStorage.setItem('AI_fps', AI_fps); var red_light = ai_json.red_light; if (ai_json != null) { bbox_count = ai_json.Count; } else { bbox_count = 0; } plate_count = 0; plate_idx = 0; for (var i = 0; i < bbox_count; i++) { if (ai_json.AiEngine[i]) { //console.log("ai_json.AiEngine[i] = " + ai_json.AiEngine[i]); //a113n //console.log("[a113n] " + ai_json.AiEngine[i].toString()) //a113n if (ai_json.AiEngine[i].parent_idx == -1) { if (ai_json.AiEngine[i].label_name == "L._Plate_USA" || ai_json.AiEngine[i].label_name == "L._Plate_MAC/MYS" || ai_json.AiEngine[i].label_name == "L._Plate_VNM" || ai_json.AiEngine[i].label_name == "L._Plate_EUR" || ai_json.AiEngine[i].label_name == "L._Plate_GBR" || ai_json.AiEngine[i].label_name == "L._Plate_JPN" || ai_json.AiEngine[i].label_name == "L._Plate_THA" || ai_json.AiEngine[i].label_name == "L._Plate_IDN" || ai_json.AiEngine[i].label_name == "L._Plate_IDN2" || ai_json.AiEngine[i].label_name == "L._Plate_BGD" || ai_json.AiEngine[i].label_name == "L._Plate_MEA" || ai_json.AiEngine[i].label_name == "L._Plate_PHL" || ai_json.AiEngine[i].label_name == "L._Plate_AUS" || ai_json.AiEngine[i].label_name == "L._Plate_CNT_1LINE" || ai_json.AiEngine[i].label_name == "L._Plate_CNT_2LINES" || ai_json.AiEngine[i].label_name == "L._Plate_CNT_3LINES" || ai_json.AiEngine[i].label_name == "L._Plate_CNT_VERTICAL" || ai_json.AiEngine[i].label_name == "L._Plate_CNT_USDOT" || ai_json.AiEngine[i].label_name == "ambulance" || ai_json.AiEngine[i].label_name == "face" || ai_json.AiEngine[i].label_name == "blank" || ai_json.AiEngine[i].label_name == "stop_sign" || ai_json.AiEngine[i].label_name == "qrcode" || ai_json.AiEngine[i].label_name == "barcode" || ai_json.AiEngine[i].label_name == "L._Plate_TWN") { if (ai_json.AiEngine[i].properties) { if (ai_json.AiEngine[i].properties.plate) { var plate_name = ""; if (ai_json.AiEngine[i].label_name == "ambulance") plate_name = plate_name.concat(ai_json.AiEngine[i].label_name); else if (ai_json.AiEngine[i].label_name == "blank") plate_name = plate_name.concat(ai_json.AiEngine[i].label_name); else if (ai_json.AiEngine[i].label_name == "stop_sign") plate_name = plate_name.concat(ai_json.AiEngine[i].label_name); else plate_name = plate_name.concat(ai_json.AiEngine[i].properties.plate); /* plate_name = plate_name.replace(/[「」‘’']/g, ''); if (plate_name === '' || plate_name === '0') { continue; }*/ //console.log("plate_name: " + plate_name); if (ai_json.AiEngine[i].behavior_id > 0 || localStorage.getItem("enable_only_once_to_post") == "No") { push_lpr(plate_name, ai_json.AiEngine[i].properties.area, ai_json.AiEngine[i].confidence.toString() + "%"); if (("LPR_BMP" in ai_json.AiEngine[i])) { push_LPBMP(ai_json.AiEngine[i]); set_lpr_content(get_lprimgnum()); // get_lprimgnum() returns the last index of img in LPBMP_Array } } AssignPlateObject(ai_json, i, plate_name); } } } } } } //RenderAllCanvas(); ai_json = null; } else { wait_count++; if (wait_count >= 3) { wait_count = 0; complete_data = ""; } clear_count++; if (clear_count >= 3) { clear_count = 0; //RefreshCanvasObject(max_protected_objects); } } } } function AssignPlateObject(ai_json, i_index, plate_name) { var x = parseInt(ai_json.AiEngine[i_index].x, 10); var y = parseInt(ai_json.AiEngine[i_index].y, 10); var w = parseInt(ai_json.AiEngine[i_index].w, 10); var h = parseInt(ai_json.AiEngine[i_index].h, 10); var text_y = parseInt((ai_json.AiEngine[i_index].y + ai_json.AiEngine[i_index].h), 10); //console.log(text_y); /*if (x * 0.25 <= 20) { x = 80; } else if (x * 0.25 >= 460) { x = 1840; } if (y * 0.3 <= 20) { y = 66; } else if (y * 0.3 >= 300) { y = 999; } if (x * 0.25 + w * 0.25 >= 460) { w = parseInt((460 - x * 0.25) * 4, 10); } if (y * 0.3 + h * 0.3 >= 300) { h = parseInt((300 - y * 0.3) * 3.33, 10); }*/ text_y = y - 66; var area_name = ""; var country_name = ""; var out_label = ""; if (ai_json.AiEngine[i_index].label_name == "L._Plate_USA" || ai_json.AiEngine[i_index].label_name == "L._Plate_THA" || ai_json.AiEngine[i_index].label_name == "L._Plate_BGD" || ai_json.AiEngine[i_index].label_name == "L._Plate_MEA" || ai_json.AiEngine[i_index].label_name == "L._Plate_AUS" || ai_json.AiEngine[i_index].label_name == "L._Plate_EUR" || ai_json.AiEngine[i_index].label_name == "L._Plate_JPN") { area_name = area_name.concat(ai_json.AiEngine[i_index].properties.area); country_name = country_name.concat(ai_json.AiEngine[i_index].properties.country); out_label = out_label.concat(plate_name, ", ", area_name, " ", country_name); } { var behavior_id = ai_json.AiEngine[i_index].behavior_id; if (ai_json.AiEngine[i_index].label_name == "L._Plate_USA" || ai_json.AiEngine[i_index].label_name == "L._Plate_THA" || ai_json.AiEngine[i_index].label_name == "L._Plate_BGD" || ai_json.AiEngine[i_index].label_name == "L._Plate_MEA" || ai_json.AiEngine[i_index].label_name == "L._Plate_AUS" || ai_json.AiEngine[i_index].label_name == "L._Plate_EUR" || ai_json.AiEngine[i_index].label_name == "L._Plate_JPN") { if (behavior_id >= 1) { /*canvasTripwire.add(insertTextLabel_Red(x * 0.25, text_y * 0.3, 50, 50, out_label + ", " + ai_json.AiEngine[i_index].confidence.toString() + "%")); canvasTripwire1.add(insertTextLabel_Red(x * 0.25, text_y * 0.3, 50, 50, out_label + ", " + ai_json.AiEngine[i_index].confidence.toString() + "%")); canvasTripwire2.add(insertTextLabel_Red(x * 0.25, text_y * 0.3, 50, 50, out_label + ", " + ai_json.AiEngine[i_index].confidence.toString() + "%")); canvasTripwire3.add(insertTextLabel_Red(x * 0.25, text_y * 0.3, 50, 50, out_label + ", " + ai_json.AiEngine[i_index].confidence.toString() + "%")); canvasTripwire4.add(insertTextLabel_Red(x * 0.25, text_y * 0.3, 50, 50, out_label + ", " + ai_json.AiEngine[i_index].confidence.toString() + "%")); canvasTripwire_all.add(insertTextLabel_Red(x * 0.25, text_y * 0.3, 50, 50, out_label + ", " + ai_json.AiEngine[i_index].confidence.toString() + "%"));*/ } else { /*canvasTripwire.add(insertTextLabel(x * 0.25, text_y * 0.3, 50, 50, out_label + ", " + ai_json.AiEngine[i_index].confidence.toString() + "%")); canvasTripwire1.add(insertTextLabel(x * 0.25, text_y * 0.3, 50, 50, out_label + ", " + ai_json.AiEngine[i_index].confidence.toString() + "%")); canvasTripwire2.add(insertTextLabel(x * 0.25, text_y * 0.3, 50, 50, out_label + ", " + ai_json.AiEngine[i_index].confidence.toString() + "%")); canvasTripwire3.add(insertTextLabel(x * 0.25, text_y * 0.3, 50, 50, out_label + ", " + ai_json.AiEngine[i_index].confidence.toString() + "%")); canvasTripwire4.add(insertTextLabel(x * 0.25, text_y * 0.3, 50, 50, out_label + ", " + ai_json.AiEngine[i_index].confidence.toString() + "%")); canvasTripwire_all.add(insertTextLabel(x * 0.25, text_y * 0.3, 50, 50, out_label + ", " + ai_json.AiEngine[i_index].confidence.toString() + "%"));*/ } } else { if (behavior_id >= 1) { /*canvasTripwire.add(insertTextLabel_Red(x * 0.25, text_y * 0.3, 50, 50, plate_name + ", " + ai_json.AiEngine[i_index].confidence.toString() + "%")); canvasTripwire1.add(insertTextLabel_Red(x * 0.25, text_y * 0.3, 50, 50, plate_name + ", " + ai_json.AiEngine[i_index].confidence.toString() + "%")); canvasTripwire2.add(insertTextLabel_Red(x * 0.25, text_y * 0.3, 50, 50, plate_name + ", " + ai_json.AiEngine[i_index].confidence.toString() + "%")); canvasTripwire3.add(insertTextLabel_Red(x * 0.25, text_y * 0.3, 50, 50, plate_name + ", " + ai_json.AiEngine[i_index].confidence.toString() + "%")); canvasTripwire4.add(insertTextLabel_Red(x * 0.25, text_y * 0.3, 50, 50, plate_name + ", " + ai_json.AiEngine[i_index].confidence.toString() + "%")); canvasTripwire_all.add(insertTextLabel_Red(x * 0.25, text_y * 0.3, 50, 50, plate_name + ", " + ai_json.AiEngine[i_index].confidence.toString() + "%"));*/ } else { /*canvasTripwire.add(insertTextLabel(x * 0.25, text_y * 0.3, 50, 50, plate_name + ", " + ai_json.AiEngine[i_index].confidence.toString() + "%")); canvasTripwire1.add(insertTextLabel(x * 0.25, text_y * 0.3, 50, 50, plate_name + ", " + ai_json.AiEngine[i_index].confidence.toString() + "%")); canvasTripwire2.add(insertTextLabel(x * 0.25, text_y * 0.3, 50, 50, plate_name + ", " + ai_json.AiEngine[i_index].confidence.toString() + "%")); canvasTripwire3.add(insertTextLabel(x * 0.25, text_y * 0.3, 50, 50, plate_name + ", " + ai_json.AiEngine[i_index].confidence.toString() + "%")); canvasTripwire4.add(insertTextLabel(x * 0.25, text_y * 0.3, 50, 50, plate_name + ", " + ai_json.AiEngine[i_index].confidence.toString() + "%")); canvasTripwire_all.add(insertTextLabel(x * 0.25, text_y * 0.3, 50, 50, plate_name + ", " + ai_json.AiEngine[i_index].confidence.toString() + "%"));*/ } } } } function GetUrlPort() { var url_href = window.location.href; var arr_url = url_href.split(":")[2].split("/")[0]; return arr_url; } /* var g_GetRequest = null; var g_h = -1; var g_m = -1; var g_s = -1; var g_ms = -1; var g_time_canvas = 250; var g_imgUrl = ""; var g_speed = 99999; var g_times_update_canvas = 0; var g_avg_speed = 7000; function GetRequest() { clearInterval(g_GetRequest); g_GetRequest = setInterval(function GetRequest_set_interval() { var current_page = localStorage.getItem('current_page'); //if (current_page === 'anpr_index') { //g_times_update_canvas++; data_anpr = sessionStorage.getItem('getalarmmotion_data'); GetAnpr(); var win_width = G_VIEW_CANVAS_X, win_height = G_VIEW_CANVAS_Y; //var imgUrl='../snap.jpg?'+Math.random(); //var imgUrl='./snap.jpg?'+Math.random(); var NowDate = new Date(); var h = NowDate.getHours(); var m = NowDate.getMinutes(); var s = NowDate.getSeconds(); var ms = NowDate.getMilliseconds(); //console.log("[anpr]snap_" + h + '_' + m + '_' + s); if (g_h == -1 || g_m == -1 || g_s == -1 || g_ms == -1) { g_h = h; g_m = m; g_s = s; g_ms = ms; } var imgUrl = 'http://' + window.location.hostname + ":" + GetUrlPort() + '/getimage_HD?' + 'lpr_' + h + '_' + m + '_' + s + '_' + ms; g_imgUrl = imgUrl; document.getElementById('destImage').src = g_imgUrl; imgUrl = null; } }, g_time_canvas); } */ function set_g_lpr_name(temp_lpr_name) { g_lpr_name = temp_lpr_name;//HTTP_TITLE01 } function set_one_lpr_content(img_num) { if (img_num > 0) { // img_num = -1 when there has no valid lpr imgs. if (img_num <= 1 || (img_num >= 2 && (LPR_Array[img_num - 1] != LPR_Array[img_num - 1 - 1]))) { var imgdiv = document.querySelector("#text_plate_info"); while (imgdiv.hasChildNodes()) { imgdiv.removeChild(imgdiv.firstChild); } for (var i = 0; i < img_num && i < MAX_LPR_SHIFT; i++) // img_num is from get_lprimgnum() which returns the last index of img in LPBMP_Array. { var index_lpr = img_num - i - 1; /* var imgObj = document.createElement("img"); imgObj.setAttribute("src", get_lprimgpath(index_lpr)); imgObj.style.height = "80px"; imgObj.style.width = "auto"; imgObj.style.marginLeft = "auto"; imgObj.style.marginRight = "auto"; */ var imgtext = document.createElement("h4");//LPR_Array[index_lpr] + ", " + LPR_confidence_array[index_lpr] var lpr_text = ""; lpr_text = g_lpr_name + ": " + LPR_Array[index_lpr] /*+ ", " + LPR_confidence_array[index_lpr]*/; if (LPR_area_array[index_lpr].length >= 1 && LPR_area_array[index_lpr] != "NULL") { var area_text = LPR_area_array[index_lpr]; lpr_text += ", " + area_text; //lpr_text += "\n"; imgtext.appendChild(document.createTextNode(lpr_text)); //imgtext.style = "white-space: pre;"; } else { //lpr_text += "\n"; imgtext.appendChild(document.createTextNode(lpr_text)); // imgtext.style = "white-space: pre;"; } //console.log(lpr_text); //imgdiv.appendChild(imgObj); imgdiv.appendChild(imgtext); just_change_lpr = 1; } } } } function set_just_change_lpr_to_zero() { just_change_lpr = 0; } function get_just_change_lpr() { return just_change_lpr; } function get_lprimgpath(index) { var imgpath = ""; if (LPBMP_Array[index] != "NULL") { imgpath = LPBMP_Array[index]; imgpath = imgpath.replace("/emmc/plugin", ".."); } // console.log(imgpath + " = " + LPBMP_Array[index] + "?"); return imgpath; } function get_lprimgnum(){ //return the last index which is valid. -1 if all invalid. var j = 0; for(j=0; j< MAX_LPBMP_ARRAY; j++){ if(LPBMP_Array[j] == "NULL") break; } //console.log("[get_lprimgnum] j = " + j); return j; //return the last index which is valid. -1 if all invalid. } var MAX_LPR_ALIVE_TIME = 1000; function lprimg_valid(date){ // can be rewrite to other valid check if needed. // console.log("[lprimg_valid]"); // console.log("inpute = " + date); var input_date = new Date(date); // console.log(input_date.toISOString()); var now_date = new Date(); // console.log(now_date.toISOString()); // console.log("pic and now time diff = " + (now_date - input_date)/1000/60/60 + " hours"); var valid = false; if(((now_date - input_date)/1000/60/60) < MAX_LPR_ALIVE_TIME){ valid = true; } return valid; } function push_LPBMP(jsonbuf){ //console.log("[push_LPBMP] jsonbuf = " + typeof jsonbuf); var new_LPBMP_path = jsonbuf.LPR_BMP; if (LPBMP_Array[MAX_LPBMP_ARRAY - 1] != "NULL") { var j = 0; for (j = 0; j < MAX_LPBMP_ARRAY - 1; j++) { LPBMP_Array[j] = LPBMP_Array[j + 1]; } LPBMP_Array[j] = new_LPBMP_path; } else{ for (var i = 0; i < MAX_LPBMP_ARRAY; i++) { if (LPBMP_Array[i] === "NULL") { LPBMP_Array[i] = new_LPBMP_path; break; } } } } function AiEngine_json_split(alarm_data){ // copied from alarm.js var datas; var ai_json; var complete_data = ""; var n1 = -1, n2 = -1, n2_temp = -1; complete_data = complete_data.concat(alarm_data); n1 = complete_data.indexOf('{"AiEngine"'); n2_temp = complete_data.indexOf('"Count"'); n2 = complete_data.indexOf('}', n2_temp); if (n1 > 0 && n2_temp > 0 && n2 > 0 && (n1 + 7) < n2_temp && n2_temp < n2) { datas = complete_data.split(/\r\n|\r/); complete_data = ""; for (var i = datas.length - 1; i >= 0; i--) { if (datas[i].length > 12 && datas[i].substring(0, 12) == '{"AiEngine":' && datas[i].length < 8192*8) { var temp = null; temp = datas[i].slice(); ai_json = JSON.parse(temp); //ai_json = validatingJSON(temp); datas[i] = null; break; } } } return ai_json; } function SetLPR(LPR_data){ //save ["INFORMATION"] into seeSionStorage for further use. var jsonbuf = null; try { jsonbuf = JSON.parse(LPR_data); //JSON parse only for try catch } catch (e) { jsonbuf = null; // console.log(e);//the character would be drop sometimes, for example the label "class_id" may be "clas_id". //console.log(json); } if(jsonbuf != null){ // save into session storage only if the data is valid json format sessionStorage.setItem('lprinfologlist_num', jsonbuf["LPR_COUNT"]); sessionStorage.setItem('lprinfologlist', JSON.stringify(jsonbuf["INFORMATION"])); //by saving jsonbuf["INFORMATION"], we can retrive other information like confidence in the future. // var test = JSON.parse(sessionStorage.getItem('lprinfologlist')); // console.log(test[0]); // console.log(test[0].LP_BMP); } } var ws = null; var wait_data = 0; function GetRequest_WebSocket() { // sessionStorage.setItem('getalarmmotion_data', ""); var data_temp = ""; wait_data = 0; console.log("GetRequest_WebSocket"); if ("WebSocket" in window) { //console.log("WebSocket is supported by your Browser!"); // Let us open a web socket if ( navigator.userAgent.indexOf( "nvr_auth=" ) != -1 ) ws = new WebSocket("ws://" + window.location.hostname + ":" + GetUrlPort() + "/getalarmmotion?" + navigator.userAgent ); else ws = new WebSocket("ws://" + window.location.hostname + ":" + GetUrlPort() + "/getalarmmotion"); keepAlive(); ws.onopen = function () { // Web Socket is connected, send data using send() //ws.send("Message to send"); console.log("ws.onopen..."); clearInterval(request_live); //clearInterval(reconnect_websocket); //websocket_reconnect_flag = 0; }; ws.onmessage = function (evt) { var received_msg = evt.data; //console.log("websocket:"); //console.log(received_msg); /* clearInterval(request_live); clearInterval(reconnect_websocket); websocket_reconnect_flag = 0;*/ data_temp = ""; data_temp = received_msg; //console.log("this.responseText.length: " + this.responseText.length.toString()); //console.log("readyState " + this.readyState.toString()); //sessionStorage.setItem('getalarmmotion_data', data_temp); data_anpr = data_temp GetAnpr(); var win_width = G_VIEW_CANVAS_X, win_height = G_VIEW_CANVAS_Y; //var imgUrl='../snap.jpg?'+Math.random(); //var imgUrl='./snap.jpg?'+Math.random(); var NowDate = new Date(); var h = NowDate.getHours(); var m = NowDate.getMinutes(); var s = NowDate.getSeconds(); var ms = NowDate.getMilliseconds(); //console.log("[anpr]snap_" + h + '_' + m + '_' + s); if (g_h == -1 || g_m == -1 || g_s == -1 || g_ms == -1) { g_h = h; g_m = m; g_s = s; g_ms = ms; } var imgUrl = 'http://' + window.location.hostname + ":" + GetUrlPort() + '/getimage_HD?' + 'lpr_' + h + '_' + m + '_' + s + '_' + ms; g_imgUrl = imgUrl; if (get_just_change_lpr() == 1) { document.getElementById('destImage').src = g_imgUrl; set_just_change_lpr_to_zero(); } //console.log("websocket here"); wait_data = 0; }; ws.onclose = function () { // websocket is closed. console.log("Connection is closed..."); cancelKeepAlive(); ws = null; setTimeout(function () { GetRequest_WebSocket(); }, 1000); //websocket_reconnect_flag = 1; //reConnect(); }; ws.onerror = function (e) { // websocket is error. console.log("Connection is error"); console.log(e); //cancelKeepAlive(); //websocket_reconnect_flag = 1; //reConnect(); ws.close(); } } else { // The browser doesn't support WebSocket //console.log("WebSocket NOT supported by your Browser!"); } } var timerID = 0; function keepAlive() { var timeout = 5000; //console.log("keepAlive:" + ws.readyState); //console.log("wait_data:" + wait_data.toString()); if (ws.readyState != 2)//fail receive wait_data++; if (wait_data >= 20) ws.close(); else timerID = setTimeout(keepAlive, timeout); } function cancelKeepAlive() { if (timerID) { clearTimeout(timerID); } }