/** * update noise */ static void update_noise() { // set noise for first time if(!noise_init) { noise_init = 1; noise_last_update_day = time_day(); noise_lifetime = drandom_rand_minmax(-SOLARPANEL_NOISE / 2, SOLARPANEL_NOISE / 2); noise_day = drandom_rand_minmax(-SOLARPANEL_NOISE / 2, SOLARPANEL_NOISE / 2); } // update noise when a new day begins if(noise_last_update_day != time_day()) { noise_last_update_day = time_day(); noise_day = drandom_rand_minmax(-SOLARPANEL_NOISE / 2, SOLARPANEL_NOISE / 2); } }
/* Return a well formatted string with a time difference at millisecond resolution */ char * elapsed_time (struct timeval * start, struct timeval * stop) { static char et [64]; time_t elapsed = delta_time_in_milliseconds (stop, start); if (time_day (elapsed)) sprintf (et, "%d days, %02d:%02d:%02d.%03ld", time_day (elapsed), time_hour (elapsed), time_min (elapsed), time_sec (elapsed), time_usec (elapsed)); else if (time_hour (elapsed)) sprintf (et, "%02d:%02d:%02d.%03ld", time_hour (elapsed), time_min (elapsed), time_sec (elapsed), time_usec (elapsed)); else if (time_min (elapsed)) sprintf (et, "%02d:%02d.%03ld", time_min (elapsed), time_sec (elapsed), time_usec (elapsed)); else if (time_sec (elapsed)) sprintf (et, "%d.%03d secs", time_sec (elapsed), time_msec (elapsed)); else sprintf (et, "%3d msecs", time_msec (elapsed)); return et; }
fpint solarpanel_capacity(long seconds) { #if SOLARPANEL_EMULATE update_noise(); // calculate energy of solar panel fpint fp_lat = 0xDEDC; // Darmstadt: 49.878667 * PI / 180 = 0.8705 fpint fp_energy = energy_brock(time_day(), time_minute(), fp_lat); fp_energy = energy_corrected(fp_energy, noise_lifetime + noise_day); // convert Watthours to Milliamperhours fpint fp_onethousand = 0x3E80000; fpint fp_mah = fpint_mul(fpint_div(fp_energy, fpint_to(SOLARPANEL_VOLT)), fp_onethousand); // scaled mAh down to timeframe fpint fp_hour = 0xE100000; // 1h in seconds return fpint_mul(fpint_div(fp_mah, fp_hour), fpint_to(seconds)); #else #error no real solarpanel implemented #endif }