//wireless.js April 2002

/*  
 Copyright Psand Ltd. 2002. Author: Spacepleb@psand.net).
Psand Limited, 54 Goodwin Road, Ramsgate, Kent, CT11 0JJ, United Kingdom.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/


//some kind of generic validation? 

var fC = 299792458/1.0008;           

//the speed of light in a vacuum
//reduced by the refractive index of air

function log10(fX) {
  // calculates base 10 logarithm
  
  return (Math.log(fX) / Math.log(10));
} 

function decimal(fX,iPlaces){
  // chops down to 2 decimal places - brutally
  // iPlaces not used yet **************

  return Math.round(fX*Math.pow(10,iPlaces)) / Math.pow(10,iPlaces);
  //return Math.floor(fX*1000)/1000;
}

function diam_circ(fDiam){
  //converts diameter to circumference
return fDiam * Math.PI;
}

function circ_diam(fCirc){
  //converts circumference to diameter
return fCirc / Math.PI;
}

function m_feet(x){
  //converts metres to feet
  
  return x / 0.3048; 
}

function feet_m(x){ 
  // converts feet to metres
  
  return x * 0.3048; 
}

function mm_inches(x){
  //converts millimetres to inches
  
  return x/25.4; 
}

function inches_mm(x){ 
  // converts inches to millimetres
  
  return x*25.4; 
}

function miles_metres(x){ //convert miles to metres
  // converts miles to metres
  
  return x*1609; 
}

function metres_miles(x){ //convert metres to miles
  // converts metres to miles
  
  return x/1609; 
}

function dbm_milliwatts (fDbm){
  // converts dBm to millWatts
  
  return Math.pow(10,fDbm / 10);
}

function dbm_watts (fDbm){
  // converts dBm to Watts
  
  return Math.pow (10,(fDbm - 30) / 10);
}

function milliwatts_dbm (fMilliwatts){
  // converts milliWatts to dBm
  
  return 10*(log10(fMilliwatts) / log10(10));
}

function fsl(fD, fF){
  
  // calculate free space loss in dB given:
  // distance in miles
  // frequency
  
  return 36.5 + 20*log10(fD) + 20*log10(fF);	
}

function fsl_d (fFsl){
  // calculates potential range in miles
  // from free space loss in dB
  // at at frequency of 2.44GHz
  
  return Math.pow (10, ((fFsl-104.2)/20));
}

function erp_dbm (fTransmit , fAntenna , fCable){
  
  // calculates effective radiated power in dBm given:
  // transmit power in dBm,
  // antenna gain in dBi,
  // and cable loss in dB
  
  return 1.0*(1.0*fTransmit + 1.0*fAntenna - 1.0*fCable);
} 










