pari: branch asterisknow r2038 - /branches/asterisknow/config/digital.html

SVN commits to the Asterisk-GUI project asterisk-gui-commits at lists.digium.com
Wed Dec 26 14:13:26 CST 2007


Author: pari
Date: Wed Dec 26 14:13:26 2007
New Revision: 2038

URL: http://svn.digium.com/view/asterisk-gui?view=rev&rev=2038
Log:
detect hardware changes

Modified:
    branches/asterisknow/config/digital.html

Modified: branches/asterisknow/config/digital.html
URL: http://svn.digium.com/view/asterisk-gui/branches/asterisknow/config/digital.html?view=diff&rev=2038&r1=2037&r2=2038
==============================================================================
--- branches/asterisknow/config/digital.html (original)
+++ branches/asterisknow/config/digital.html Wed Dec 26 14:13:26 2007
@@ -112,10 +112,60 @@
 var GROUPS = [];
 var NEWGROUPNUMBER;
 var CURRENT_SPAN; // span being edited
-var CONFIGUREDHARDWARE = {};
+var CONFIGUREDHARDWARE = {}; // configuration read from an existing hwcfgfile (if exists)
 var DETECTEDHARDWARE = {};
 var hwcfgfile = 'gui_confighw.conf'; // file to store configured hardware information
 var spans_todelete = []; // we delete all the span_x entries in users.conf (and their extensions.conf counter parts) before writing back any new information.
+var hwchanged = true ; // -1 for no previous configuration found (first time), true for detected hardware changes, false for no hardware changes
+
+function detectHwChanges(){ // compare DETECTEDHARDWARE vs CONFIGUREDHARDWARE 
+// returns true if a hardware change is detected and false if there are no hardware changes
+// we can actually check a lot of things here like
+	// [A] check if - any cards are missing 
+	//	if yes - delete all existing configuration and ask the user to reconfigure from scratch
+
+	// [B] check if - any cards are added  - if something is added 
+	//	- check if the basechan of configured hardware matches with basechan of detected hardware
+	//	- if (matches) { 
+	//		no need to delete existing configuration - just present the current card information as detected/configured and new card as unconfigured 
+	//	}else{ 
+	//		delete all existing configuration and ask the user to reconfigure from scratch 
+	//	}
+
+	// [C] if all the cards match - check if basechan of detected hardware matches with basechan of configured hardware
+	//	- if does not match - delete all existing configuration and ask the user to reconfigure from scratch
+// BUT to avoid all the complexity and to keep things simple (atleast for now) - we will just do [c]
+	// check if the devices match 
+	// check if the basechan match for all the devices
+	var configured_devices = [];
+	var detected_devices = [];
+	for( var l in CONFIGUREDHARDWARE ){ if(CONFIGUREDHARDWARE.hasOwnProperty(l)){ 
+		configured_devices.push( CONFIGUREDHARDWARE[l]['device'] + '::' + CONFIGUREDHARDWARE[l]['basechan'] ); 
+		// this way we can check for whether both device and the basechan are matching in one go
+	}}
+	for( var l in DETECTEDHARDWARE ){ if(DETECTEDHARDWARE.hasOwnProperty(l)){ 
+		detected_devices.push( DETECTEDHARDWARE[l]['device'] + '::' + DETECTEDHARDWARE[l]['basechan']  ); 
+	}}
+	configured_devices.sort(); detected_devices.sort();
+	if( !configured_devices.length && !detected_devices.length){ return false; }
+	if(configured_devices.length == detected_devices.length){
+		for(var l=0; l < configured_devices.length; l++){
+			if(configured_devices[l] != detected_devices[l]){ // devices does not match - but the number of devices match
+				//console.log("DEVICES or basechans does not MATCHED"); //
+				return true;
+			}
+		}
+		//console.log("DEVICES and basechans MATCH"); 
+		return false;
+	}else{	
+		//console.log("DEVICES or basechans does not MATCHED"); 
+		return true;
+	}
+}
+
+
+
+
 
 function verify_priChLimit(){
 	var l = String(CURRENT_SPAN);
@@ -299,6 +349,17 @@
 		_$('cancel_b').disabled = false;
 	}
 
+	if(foo_spans && hwchanged == -1){ // no previous hardware information found - configuring for the first time
+		gui_alert('Please configure your hardware using the Edit button(s)' + '<BR>'+
+			   "When done click on the 'Apply Changes'" );
+	}else{ // if previous config file found 
+		if(foo_spans && hwchanged){ //
+			gui_alert('Hardware Changes detected !! <BR><BR>' +
+				'When you "Apply Changes" all your previous settings will be over written' );
+		}else{ // no hardware changes detected
+			//gui_alert('No Hardware Changes detected !! ');
+		}
+	}
 }
 
 function localajaxinit(){
@@ -338,19 +399,38 @@
 	ASTGUI.events.add( _$('edit_DefinedChans'), "change", edit_DefinedChans_changed );
 
 	parent.loadscreen(this);
-	//loadConfigFiles.readApplyzap();
-	loadConfigFiles.runZtscan();
+	loadConfigFiles.load_hwcfgfile(); // try to load last detected/configured hardware information
 }
 
 var loadConfigFiles = {
-	// read applyzap.conf (if exists) - so that the GUI knows the last configured hardware
+	// read hwcfgfile (if exists) into CONFIGUREDHARDWARE - so that the GUI knows the last configured hardware
 	// run ztscan - to detect digital cards
-	// read ztscan.conf - read spans information - also set the max , min values for each span
-	//   see if the number of spans in ztscan.conf matches with that from applyzap.conf 
+	// read ztscan.conf - store hardware information in DETECTEDHARDWARE, read spans information - also set the max , min values for each span
+	//   see if the hardware matches with that from CONFIGUREDHARDWARE 
 	//   (this way we know if any changes in digital hardware since the gui was last used)
 	// read users.conf - and read spans information 
 	//   check if the channels in zapchan are within max and min
 	//   if yes then set the current range values
+	load_hwcfgfile: function(){ // read hwcfgfile (if exists) into CONFIGUREDHARDWARE 
+		var hwcfgfile_parse = function(n){
+			if( n == "ERROR: CONFIG FILE NOT FOUND"){
+				// hwcfgfile does not exist, proceed to Ztscan
+				hwchanged = -1;
+				loadConfigFiles.runZtscan();
+				return;
+			}
+			CONFIGUREDHARDWARE = {};
+			for( var l in n ){ if(n.hasOwnProperty(l)){ // l is location
+				CONFIGUREDHARDWARE[l] = {};
+				CONFIGUREDHARDWARE[l]['device'] = n[l]['device'];
+				CONFIGUREDHARDWARE[l]['basechan'] = n[l]['basechan'];
+			}}
+			loadConfigFiles.runZtscan();
+		};
+		config2json(hwcfgfile, 1, hwcfgfile_parse);
+		
+	},
+
 	runZtscan: function(){
 		parent.astmanEngine.run_tool(asterisk_guiZtscan + '; touch /etc/asterisk/applyzap.conf', function(t) { // run ztscan and then try loading ztscan.conf
 			setTimeout( function(){ loadConfigFiles.readZtscanConf(); } , 700); // leave some time for ztscan to generate ztscan.conf
@@ -413,6 +493,11 @@
 					}
 				}}
 			}}
+
+			if(hwchanged != -1){
+				hwchanged = detectHwChanges();
+			}
+
 			loadConfigFiles.readUsersConf(); // read span_x (where T1/E1 trunks are defined)
 		};
 		config2json("ztscan.conf", 1, digitalparse);




More information about the asterisk-gui-commits mailing list