/****************************************************************************** * Copyright (c) 2008 by System Helmholz GmbH. * * This software is copyrighted by and is the sole property of Systeme * Helmholz GmbH. All rights, title, ownership, or other interests in the * software remain the property of Systeme Helmholz GmbH. This software * may only be used in accordance with the corresponding license agreement. * Any unauthorized use, duplication, transmission, distribution, or * disclosure of this software is expressly forbidden. * * This Copyright notice may not be removed or modified without prior * written consent of Systeme Helmholz GmbH. * * Systeme Helmholz GmbH, reserves the right to modify this software * without notice. * * Systeme Helmholz GmbH Phone: +49 9135 7380 0 * Hannberger Weg 2 Fax: +49 9135 7380 50 * 91091 Großenseebach Web: http://www.helmholz.de * Germany Email: info@helmholz.de * ****************************************************************************** * * Projekt : NETLink WLAN for NetARM processor * Copyright: Systeme Helmholz GmbH * Author : Ehser * Version : 1.0 / 10.11.08 * File : diagnostic-js.htm * * * Javascript tool to get the diagnistic information from the NETlink ADapter */ var DIAG_CYCLIC_INTERVAL = 350; var g_diagnosticActive = null; var DIAGNOSTIC_MSG_OK = 0; var NO_MORE_DIAGNOSTIC_MSG = 1; var DIAGNOSTIC_ERR = 2; // // create new diagnostic_msg array // var ar_diagnostic_msg = new Array(); var g_next_diagnostic_index = 0; var g_row_counter = 0; var g_transfer_counter = 0; var g_clearlist = 0; var g_xmlDiagnostic; var g_summertime_table = new Array(); var bWaitForResponse; var APPLICATION_START = 1; var DIAG_GO_ONLINE_AFTER_BOOTUP = 13; var DIAG_RFC_LOGIN_SINGLE_MASTER = 14; var DIAG_LOGIN_AUTO_BAUD = 15; var DIAG_LOGIN_SINGLE_MASTER = 16; var DIAG_LOGOUT_SUCCESS = 17; var DIAG_LOGOUT_FAILED = 18; var DIAG_GO_ONLINE_FAILED = 19; var DIAG_GO_ONLINE = 20; var DIAG_GO_OFFLINE = 21; var DIAG_BAUDRATE_DETECTED = 22; var DIAG_BAUDRATE_NOT_DETECTED = 23; var DIAG_BUSPARAMETER_DETECTED = 24; var DIAG_BUSPARAMETER_NOT_DETECTED = 25; var DIAG_DIRECT_STATION_DETECTED = 26; var DIAG_SINGLE_MASTER_WRONG_BAUDRATE = 27; var DIAG_GOONLINE_STOPPED = 28; var DIAG_LIFELIST_STOPPED = 29; var DIAG_WLAN_CONFIGURATION = 30; var DIAG_WLAN_CANNOT_ENTER_MONITOR_MODE = 31; var DIAG_TOO_MANY_TCP_CONNECTIONS = 32; var DIAG_TOO_MANY_MPI_CONNECTIONS = 33; var DIAG_LOGIN_STOPPED_BY_HOST = 34; var DIAG_CONNECTION_TO_REMOTE_NETLINK = 35; var DIAG_NO_CONNECTION_TO_REMOTE_NETLINK = 36; var DIAG_PLCPLC_INVALID_PARA = 37; var DIAG_TARGET_REFUSED_CONNECT = 38; var DIAG_TARGET_NOT_EXISTS = 39; var DIAG_CONNECTION_TO_LOCAL_PLC = 40; var DIAG_INTRUSION_DETECTED = 41; var DIAG_BAUDRATE_NOT_DETECTED_BUT_ACTIVITY = 42; var DIAG_STATION_NOT_FOUND = 43; var DIAG_CONNECTION_TO_REMOTE_PLC = 44; var DIAG_NO_CONNECTION_TO_REMOTE_PLC = 45; var DIAG_WRITE_PROTECTION_ACTIVED = 46; var DIAG_WRITE_PROTECTION_FIRED = 47; var DIAG_NOT_IN_TCP_ACCESS_LIST = 48; var DIAG_SLAVEDATA_OVERFLOW = 49; var DIAG_LIFELIST_STOPPED_PBERROR = 50; var DIAG_WRONG_DP_PROFIL = 51; var DIAG_OUT_OF_RESOURCE = 52; var DIAG_LOCAL_MPIADDRESS_INUSE = 53; var DIAG_TOKEN_NOT_TOGGLED = 54; var DIAG_DP_RESPONSE_ERR = 55; var DIAG_DOUBLE_TOKEN = 56; var DIAG_LINK_STATUS = 97; var MPI_HSA_ERROR = 98; var MPI_MAC_RESET = 99; var DIAG_LIST_CLEARED = 100; // // stuff diagnostic_msg array entries with objects // function fillDiagnosticArray() { createDiagnosticEntry(APPLICATION_START, "System start-up..."); createDiagnosticEntry(DIAG_GO_ONLINE_AFTER_BOOTUP, "Going online after bootup, Autobaud: own address = %1."); createDiagnosticEntry(DIAG_RFC_LOGIN_SINGLE_MASTER, "Login Single Master ( at bootup): own address = %1, baud rate = %2, HSA = %3."); createDiagnosticEntry(DIAG_LOGIN_AUTO_BAUD, "Going online with detected bus parameters: own address = %1."); createDiagnosticEntry(DIAG_LOGIN_SINGLE_MASTER, "Going online as Single Master: own address = %1, baud rate= %2, HSA = %3."); createDiagnosticEntry(DIAG_LOGOUT_SUCCESS, "Successfully gone offline."); createDiagnosticEntry(DIAG_LOGOUT_FAILED, "Going offline failed, %1 other connections are running."); createDiagnosticEntry(DIAG_GO_ONLINE_FAILED, "Going online failed!"); createDiagnosticEntry(DIAG_GO_ONLINE, "Successfully gone online."); createDiagnosticEntry(DIAG_GO_OFFLINE, "Going Offline."); createDiagnosticEntry(DIAG_BAUDRATE_DETECTED, "Baud rate detected: %1."); createDiagnosticEntry(DIAG_BAUDRATE_NOT_DETECTED, "No baud rate detected!"); createDiagnosticEntry(DIAG_BAUDRATE_NOT_DETECTED_BUT_ACTIVITY, "No baud rate detected, but bus activity: %1 received frames doesn't match to any baud rate. (Check terminating resistors!)."); createDiagnosticEntry(DIAG_BUSPARAMETER_DETECTED, "Bus parameters received: from PLC = %1, baud rate= %2, HSA = %3."); createDiagnosticEntry(DIAG_BUSPARAMETER_NOT_DETECTED,"No bus parameters detected -> Autobaud not possible!"); createDiagnosticEntry(DIAG_DIRECT_STATION_DETECTED, "Direct station detected: %1"); createDiagnosticEntry(DIAG_SINGLE_MASTER_WRONG_BAUDRATE,"Single Master: Wrong baud rate: %1."); createDiagnosticEntry(DIAG_GOONLINE_STOPPED, "Going online canceled by application. Check timeout in PG/PC interface!"); createDiagnosticEntry(DIAG_LIFELIST_STOPPED, "Getting Lifelist canceled by application. Check timeout in PG/PC interface!"); createDiagnosticEntry(DIAG_LIFELIST_STOPPED_PBERROR,"Getting Lifelist canceled by profibus error, check of double MPI addresses!"); createDiagnosticEntry(DIAG_WRONG_DP_PROFIL, "MPI_MAC_RESET: Framingerror, maybe wrong Profil MPI/PB!"); createDiagnosticEntry(DIAG_OUT_OF_RESOURCE, "Timer/Order events: out of resource."); createDiagnosticEntry(DIAG_LOCAL_MPIADDRESS_INUSE, "MPI address of NETLink already in use!"); createDiagnosticEntry(DIAG_TOKEN_NOT_TOGGLED, "PROFIBUS token has not toggled."); createDiagnosticEntry(DIAG_DP_RESPONSE_ERR , "PROFIBUS response error."); createDiagnosticEntry(DIAG_DOUBLE_TOKEN , "PROFIBUS double token (check termination resistors)."); createDiagnosticEntry(DIAG_WLAN_CONFIGURATION, "WLAN configuration failed."); createDiagnosticEntry(DIAG_WLAN_CANNOT_ENTER_MONITOR_MODE,"WLAN configuration - cannot enter monitor mode."); createDiagnosticEntry(DIAG_TOO_MANY_TCP_CONNECTIONS, "Too many TCP/IP connections, maximum of 16 connections are allowed."); createDiagnosticEntry(DIAG_TOO_MANY_MPI_CONNECTIONS, "Too many MPI connections, maximum of 32 connections are allowed."); createDiagnosticEntry(DIAG_LOGIN_STOPPED_BY_HOST, "Login interrupted by host (check timeout!)."); createDiagnosticEntry(DIAG_CONNECTION_TO_REMOTE_NETLINK, "PLC-PLC: Successfully connected to remote NETLink adapter: %1.%2.%3.%4"); createDiagnosticEntry(DIAG_NO_CONNECTION_TO_REMOTE_NETLINK, "PLC-PLC: No connection to remote NETLink adapter: %1.%2.%3.%4"); createDiagnosticEntry(DIAG_CONNECTION_TO_LOCAL_PLC, "PLC-PLC: Successful connected to local PLC: %1"); createDiagnosticEntry(DIAG_NO_CONNECTION_TO_REMOTE_PLC,"PLC-PLC: No connection to remote PLC: %1"); createDiagnosticEntry(DIAG_CONNECTION_TO_REMOTE_PLC, "PLC-PLC: Connection established to remote PLC: %1"); createDiagnosticEntry(DIAG_PLCPLC_INVALID_PARA, "PLC-PLC: Parameter VAR_ADDR is invalid or length != 10."); createDiagnosticEntry(DIAG_TARGET_REFUSED_CONNECT, "PLC-PLC: Remote IP device refused connection, is RFC protocol activated?"); createDiagnosticEntry(DIAG_TARGET_NOT_EXISTS, "PLC-PLC: Remote IP device doesn't exist."); createDiagnosticEntry(DIAG_INTRUSION_DETECTED, "Intrusion detected: Invalid telegram data in received frame detected (frame ignored)."); createDiagnosticEntry(DIAG_STATION_NOT_FOUND, "Requested station %1 is NOT online!"); createDiagnosticEntry(DIAG_WRITE_PROTECTION_ACTIVED, "PLC write protection is activated!"); createDiagnosticEntry(DIAG_WRITE_PROTECTION_FIRED, "PLC write protection fired!."); createDiagnosticEntry(DIAG_NOT_IN_TCP_ACCESS_LIST, "Incoming Device %1.%2.%3.%4 not in TCP access list (Security Page)!"); createDiagnosticEntry(DIAG_SLAVEDATA_OVERFLOW, "Slave data overflow %1 , max. 238 bytes allowed!"); createDiagnosticEntry(MPI_HSA_ERROR, "MPI_HSA_ERROR: MPI chip went offline!"); createDiagnosticEntry(MPI_MAC_RESET, "MPI_MAC_RESET: MPI chip went offline!"); createDiagnosticEntry(DIAG_LIST_CLEARED, "Diagnostic List cleared."); createDiagnosticEntry(9999,"Exception occured: %1 "); } function startGetDiagnosticMsg() { // put diagnostic msg's to the appropriate array fillDiagnosticArray(); // // put 3 summertime objects to the g_summertime_table // they will be used later to calculate the correct time // setSummertimeTable(); if (g_diagnosticActive != null) { stopDiagnosticRead(); return; } // // // g_diagnosticActive = window.setInterval("CyclicGetDiagnostics()", DIAG_CYCLIC_INTERVAL); // CyclicGetDiagnostics(); } // // define diagnostic id/msg object // function diagnostic_msg_obj(id, msg) { this.msg_id = id; this.msg_text = msg; } function createDiagnosticEntry(id, msg) { ar_diagnostic_msg.push(new diagnostic_msg_obj(id, msg)); } /** */ function CyclicGetDiagnostics() { var getDiagnosticXML; if (bWaitForResponse == true) { return; // do nothing last read is still not back } bWaitForResponse = true; if (g_clearlist == 1) { getDiagnosticXML = "xmlRequest=\n"; getDiagnosticXML += "\n"; removeAllRows(); g_clearlist = 0; } else { getDiagnosticXML = "xmlRequest="; getDiagnosticXML += "\n"; } setNetlinkResponseFunction(null); // set callback function for responses // g_xmlDiagnostic = askNETLink("/netlink/diagnostic/diagnostic.xml", true); // PC - Test Version , send syncron! (asyncron = false) g_xmlDiagnostic = askNETLink(getDiagnosticXML, true); // NETLink Version, send syncron! (asyncron = false) bWaitForResponse = false; // transfer ready } // END CyclicGetDiagnostics() /** /** */ function stopDiagnosticRead() { window.clearInterval(g_diagnosticActive); g_diagnosticActive = null; } function btnClearList() { g_clearlist = 1; } /** */ function showDiagnosticInformation(xmlVariables) { var NetlinkChild; var i; var iReturn; iReturn = checkDiagnosticResponse("showDiagnosticInformation", xmlVariables); switch(iReturn) { case DIAGNOSTIC_MSG_OK: { NetlinkChild = getElement(xmlVariables, "NETLink"); readNode = getElement(NetlinkChild, "diagnostic"); if (readNode.length > 0) { // look for Read-Child readDiagnostic(readNode); } } break; case DIAGNOSTIC_ERR: { stopCyclicRead(); } break; case NO_MORE_DIAGNOSTIC_MSG: { // // no more diagnostic msg // slow down request cycles // } break; } } /** */ function readDiagnostic(ReadNode) { var current_diagnostic_index; var diag_currtime; var diag_time; var diag_id; var diag_id_dec; var diag_time_70ms; var diag_time_ms; var now; var currentTime; var msgTime; var msgDate; var msgDateString; var SummerTimeOffset; var arDiagValues; var cnt_values; var NodeName; var diag_msg; var ar_length; var i; // // get diagnostic information from received XML information // // // get diagnostic index // current_diagnostic_index = getAttribute(ReadNode, "diag_index"); g_next_diagnostic_index = parseInt(current_diagnostic_index,10) + 1; // // get time of diagnostic info // diag_currtime = getAttribute(ReadNode, "diag_currtime"); // get current time of adapter in 70ms units diag_time = getAttribute(ReadNode, "diag_time"); // get time elapsed from start up to now in 70ms units diag_time_70ms = parseInt(diag_currtime,10) - parseInt(diag_time,10); diag_time_ms = diag_time_70ms * 70; now = new Date(); currentTime = now.getTime(); // current time SummerTimeOffset = getSummerTimeOffset(currentTime - diag_time_ms); // pass time when msg was created msgTime = Math.floor(currentTime - diag_time_ms + SummerTimeOffset); // adjust summertime offset to GMT time msgDate = new Date(msgTime); msgDateString = msgDate.toGMTString(); // // take only the important part of the "Date" object // i = msgDateString.indexOf("GMT"); if (i<1) i = msgDateString.indexOf("UTC"); if (i > 0) msgDateString = msgDateString.substring(0,i); // // get ID of diagnostic info // diag_id = getAttribute(ReadNode, "diag_id"); diag_id_dec = parseInt(diag_id,10); // diag_id comes in dez-format if (diag_id_dec == 45) { } // // get values of diagnostic info (diag_info) // // diag_value = getAttribute(ReadNode, "diag_value"); arDiagValues = getChildElements(ReadNode, "*"); cnt_values = arDiagValues.length; // // now create a new entry into the diagnostic information table // ar_length = ar_diagnostic_msg.length; for (i=0; i 50) { // // don't add new rows, but delete the last row // removeLastRow(); } insertTableRow(msgDateString, diag_msg); /* if (g_row_counter == 1) removeLastRow(); */ } /** */ function checkDiagnosticResponse(instance_name, xmlResponse) { var NetlinkChild; var error_no; var error_text; var iReturn = DIAGNOSTIC_ERR; if (xmlResponse.length == 0) { return NO_MORE_DIAGNOSTIC_MSG; } NetlinkChild = getElement(xmlResponse, "NETLink"); if (NetlinkChild.length == 0) { alert("checkResponse(): " + instance_name + "-> missing root node 'NETLink')"); return iReturn; } NetlinkResponse = getElement(NetlinkChild, "response"); if (NetlinkResponse.length == 0) { alert("checkResponse(): " + instance_name + "-> no response element)"); return iReturn; } error_no = getAttribute(NetlinkResponse,"error_no"); var nbr = parseInt(error_no, 10); if (nbr == 0) { iReturn = DIAGNOSTIC_MSG_OK; // response with data } else { switch(nbr) { case NO_MORE_DIAGNOSTIC_MSG: iReturn = NO_MORE_DIAGNOSTIC_MSG; break; default: alert("checkResponse(): " + instance_name + "-> xmlResponse with error number: " + error_no); } } return iReturn; } function insertTableRow(date_time, dignostic_msg) { var htmlElement; var newCell; var newRow; var i; htmlElement = document.getElementById("idDiagnosticTable"); newRow = htmlElement.insertRow(0); // insert row at the top (index = 0) // create date-time cell newCell = newRow.insertCell(0); newCell.width = "25%"; newCell.innerHTML = date_time; // create diagnosic msg cell newCell = newRow.insertCell(1); newCell.innerHTML = dignostic_msg; g_row_counter = g_row_counter + 1; } function removeLastRow() { var htmlElement; htmlElement = document.getElementById("idDiagnosticTable"); g_row_counter = g_row_counter - 1; htmlElement.deleteRow(g_row_counter); // delete last row } function removeAllRows() { var htmlElement; htmlElement = document.getElementById("idDiagnosticTable"); while(g_row_counter > 0) { g_row_counter = g_row_counter - 1; htmlElement.deleteRow(g_row_counter); // delete last row } } /* Description: returns the offset of the summer/winter time in millisecs */ function getSummerTimeOffset(thisTime) /* § 2 (1) Die mitteleuropäische Sommerzeit beginnt jeweils am letzten Sonntag im März um 2 Uhr mitteleuropäischer Zeit. Im Zeitpunkt des Beginns der Sommerzeit wird die Stundenzählung um eine Stunde von 2 Uhr auf 3 Uhr vorgestellt. (2) Die mitteleuropäische Sommerzeit endet jeweils am letzten Sonntag im Oktober um 3 Uhr mitteleuropäischer Sommerzeit. Im Zeitpunkt des Endes der Sommerzeit wird die Stundenzählung um 1 Stunde von 3 Uhr auf 2 Uhr zurückgestellt. Die Stunde von 2 Uhr bis 3 Uhr erscheint dabei zweimal. Die erste Stunde (von 2 Uhr bis 3 Uhr mitteleuropäischer Sommerzeit) wird mit 2 A und die zweite Stunde (von 2 Uhr bis 3 Uhr) mitteleuropäischer Zeit) mit 2 B bezeichnet. */ { var thisDate; var thisYear; var offset; var tableYear; var index; var offset; thisDate = new Date(thisTime); thisYear = thisDate.getFullYear(); // // now find thisYear in the summertime table // index = 1; // the default index is the current year for (i=0; i<3; i++) { if (g_summertime_table[i].year == thisYear) { index = i; break; } } offset = 60 * 60 * 1000; // set wintertime offset: is 1h (60min * 60sec *1000 millisecs) if (thisTime > g_summertime_table[index].summertime_start && thisTime < g_summertime_table[index].summertime_end) { // we are in summertime offset *= 2; // offset is 2h } return offset; } function setSummertimeTable() { var fullYear; var start; var end; var currentDate; currentDate = new Date(); fullYear = currentDate.getFullYear() - 1; // // put 3 summertime objects to the g_summertime_table // they will be used later to calculate the correct time // for (i=0; i<3; i++) { start = getLastSunday(new Date(fullYear+i,2,31)); // set a date object to last day of March end = getLastSunday(new Date(fullYear+i,9,31)); // set a date object to last day of October g_summertime_table[i] = new SUMMER_TIME_OBJ(fullYear+i, start, end); } } function getLastSunday(thisDate) { var difference; var DayOfTheWeek; var TimeLastDayOfMarch; var SummerTimeStart; DayOfTheWeek = thisDate.getDay(); // 0 = sun, 1 = mon .... TimeLastDayOfMarch = thisDate.getTime(); // // substract difference of the number of days from last day in March to the last sunday in March // // if DayOfTheWeek equals 0, last day of March is a Sunday difference = DayOfTheWeek * 24 * 60 * 60 * 1000; SummerTimeStart = TimeLastDayOfMarch - difference; return SummerTimeStart; } function SUMMER_TIME_OBJ(year, summertime_start, summertime_end) { this.year = year; // the year where summertime_start and end are valid this.summertime_start = summertime_start; // none, WEP, WPA, WPA2 this.summertime_end = summertime_end; // siehe oben }