1 /* CWirc - X-Chat plugin for sending and receiving raw morse code over IRC 2 (c) Pierre-Philippe Coupard - 18/06/2003 3 4 Simulated propagation / signal strength evaluation routines 5 6 This program is distributed under the terms of the GNU General Public License 7 See the COPYING file for details 8 */ 9 #include <stdlib.h> 10 11 #include "propagation.h" 12 13 14 15 /* Definitions */ 16 #define HALF_SIGNAL_DROP_DISTANCE 200 /* km */ 17 #define SPORADICE_UPDATE_PERIOD 500 /* ms */ 18 19 20 21 /* Make up a signal strength (0 -> 100) from the distance in Km between sender 22 and receiver. The current simulation doesn't correspond to anything real but 23 allows us to not really exclude anybody anywhere in the world from being 24 received. */ cwirc_determine_signal_strength(int distance)25double cwirc_determine_signal_strength(int distance) 26 { 27 return(1/(1+((double)distance/HALF_SIGNAL_DROP_DISTANCE))); 28 } 29 30 31 32 /* Simulate sporadic-E. Here, we do it solely by attenuating the signal at 33 random */ cwirc_simulate_sporadicE(double * signal_strength,double ticklen)34void cwirc_simulate_sporadicE(double *signal_strength,double ticklen) 35 { 36 static double rnd_update_timeout=0; 37 static double dir=1; 38 static double attn=1; 39 40 if(rnd_update_timeout<=0) 41 { 42 dir=rand()>RAND_MAX/2?ticklen/300:0; 43 rnd_update_timeout=SPORADICE_UPDATE_PERIOD; 44 } 45 rnd_update_timeout-=ticklen; 46 47 attn=(attn+dir)/(1+ticklen/300); 48 49 if(*signal_strength<0.2) 50 *signal_strength*=attn; 51 } 52