bool SetTime::recover_system_time() { backups1->wYear=setting->getValue("back1_year",2013); backups1->wMonth=setting->getValue("back1_mon",1); backups1->wDay=setting->getValue("back1_day",1); backups1->wHour=setting->getValue("back1_hour",0); backups1->wMinute=setting->getValue("back1_min",0); backups1->wSecond=setting->getValue("back1_second",0); backups2->wYear=setting->getValue("back2_year",2013); backups2->wMonth=setting->getValue("back2_mon",1); backups2->wDay=setting->getValue("back2_day",1); backups2->wHour=setting->getValue("back2_hour",0); backups2->wMinute=setting->getValue("back2_min",0); backups2->wSecond=setting->getValue("back2_second",0); qDebug()<<"back1:"<<backups1->wMonth<<backups1->wDay<<backups1->wHour<<backups1->wMinute<<backups1->wSecond; qDebug()<<"back2:"<<backups2->wMonth<<backups2->wDay<<backups2->wHour<<backups2->wMinute<<backups2->wSecond; GetSystemTime(st); qDebug()<<"st:"<<st->wMonth<<st->wDay<<st->wHour<<st->wMinute<<st->wSecond; st=time_addition(time_subduction(st,backups2),backups1); qDebug()<<"st:"<<st->wMonth<<st->wDay<<st->wHour<<st->wMinute<<st->wSecond; if(!SetSystemTime(st)) return false; else return true; }
/*Find closest asset and print it*/ void find_best_match(rescue_asset *assets,ship ship_in_trouble,int num_assets,mayday_call md_call,char type) { /*The time required to help the ship in trouble. */ int time_to_help; /* Make it match the type( helicopter or boat)*/ time_to_help = (type == 'H') ? md_call.t_heli:md_call.t_boat; /*Int to act as a boolean, to see if we have closest asset set.*/ int best_asset_is_set=0; /* Initialise the best distance,deploy time and arrive time. */ double best_distance=0; double best_arrive_time=0; double best_deploy_time=0; rescue_asset *best_match; int i=0; /*Loop over all the rescue assets*/ for(i ; i<num_assets; i++){ /*Filter those that are the type( helicopter or a boat)*/ if(assets[i].type==type) { /*For each asset*/ /*calculate the distance to the ship in trouble*/ double distance_to_asset=great_circle(assets[i].loc,ship_in_trouble.loc); /*get the max deploy time*/ double max_deploy_time=(double)assets[i].max_deployment_time ; /*calculate the arrive time*/ double arrive_time=time_to_arrive(distance_to_asset,assets[i].speed); /*calculate the deploy time */ double deploy_time= calculate_required_time(distance_to_asset,assets[i].speed,time_to_help,type); /* Check if the deployment time is enough to save the ship */ if( deploy_time > max_deploy_time ) { continue; } /*If there is not best, and the deploy time * is enough to return safely set it to be the best match.*/ if ( best_asset_is_set == 0 ) { best_distance=distance_to_asset; best_match=&assets[i]; best_arrive_time=arrive_time; best_asset_is_set=1; best_deploy_time=deploy_time; } /* If the deploy time is enough , and the arrive time is faster, * make this asset to be the best match */ else if(best_arrive_time >= arrive_time) { best_distance=distance_to_asset; best_match=&assets[i]; best_arrive_time=arrive_time; best_deploy_time=deploy_time; } } } int arrive_in_minutes=(int)best_arrive_time; /*Calculate the arrival time*/ time time_of_arrival=time_addition(md_call.the_time,arrive_in_minutes); /*print the result*/ print_best_asset(best_match->callsign,best_distance,time_of_arrival,type); }