📄 sats.c
字号:
/* ***************************************************** * * SaVi by Robert Thurman (thurman@geom.umn.edu) and * Patrick Worfolk (worfolk@alum.mit.edu). * * Copyright (c) 1997 by The Geometry Center. * This file is part of SaVi. SaVi is free software; * you can redistribute it and/or modify it only under * the terms given in the file COPYRIGHT which you should * have received along with this file. SaVi may be * obtained from: * http://savi.sourceforge.net/ * http://www.geom.uiuc.edu/locate/SaVi * ***************************************************** * * sats.c * * $Id: sats.c,v 1.20 2005/02/03 02:22:28 lloydwood Exp $ */#include <stdlib.h>#include <sys/time.h>#include <math.h>/* for select *//*#include <unistd.h>#include <sys/types.h>#include <bstring.h>*/#include "globals.h"#include "constants.h"#include "utils.h"#include "coverage_vis.h"#include "fisheye.h"#include "gv_utils.h"#include "Satellite.h"#include "sats.h"#include "stats_utils.h"#include "savi.h"extern void time_update(const double ttime);unsigned int geomview_flag = FALSE;static double direction; /* 1.0 = FORWARDS, -1.0 = BACKWARDS *//* * Central body parameter - global from the parameters panel. It should * be initialized in the following routine so it can be reset at runtime */static CentralBody CB = { EARTH_RADIUS, EARTH_ROTATION_RATE, EARTH_MU, EARTH_OBLATENESS };static Constellation constellation = { 0, 0, 0, (Satellite_list) NULL, &CB };static double ttime = 0.0;static unsigned int realtime_flag = FALSE;static double realtime = 0;static Satellite sats_n(int n);static char OK_str[] = "OK";static const int Forward = 1.0;static const int Backward = -1.0;/* * forwards_cmd */char *forwards_cmd(int argc, char *argv[]){ if (!motion) { motion = TRUE; direction = Forward; set_realtime(); return OK_str; } return EMPTY_str;}/* * backwards_cmd */char *backwards_cmd(int argc, char *argv[]){ if (!motion) { motion = TRUE; direction = Backward; set_realtime(); return OK_str; } return EMPTY_str;}/* * forwards_step_cmd */char *forwards_step_cmd(int argc, char *argv[]){ if (!motion) { motion = TRUE; single_step = TRUE; direction = Forward; sats_update(); /* call twice to compute and move */ sats_update(); return OK_str; } return EMPTY_str;}/* * backwards_step_cmd */char *backwards_step_cmd(int argc, char *argv[]){ if (!motion) { motion = TRUE; single_step = TRUE; direction = Backward; sats_update(); /* call twice to compute and move */ sats_update(); return OK_str; } return EMPTY_str;}/* * reset_cmd */char *reset_cmd(int argc, char *argv[]){ reset = TRUE; return OK_str;}/* * stop_cmd */char *stop_cmd(int argc, char *argv[]){ if (motion) { sats_update(); /* call twice to compute and move */ sats_update(); motion = FALSE; return OK_str; } return EMPTY_str;}/* * set_realtime */voidset_realtime(){ struct timeval tv; gettimeofday(&tv, NULL); realtime = tv.tv_sec + tv.tv_usec / 1000000.0;;}/* * realtime_on_cmd */char *realtime_on_cmd(int argc, char *argv[]){ if (realtime_flag) return EMPTY_str; realtime_flag = TRUE; set_realtime(); return EMPTY_str;}/* * realtime_off_cmd */char *realtime_off_cmd(int argc, char *argv[]){ if (!realtime_flag) return EMPTY_str; realtime_flag = FALSE; return EMPTY_str;}/* * geomview_on_cmd */char *geomview_on_cmd(int argc, char *argv[]){ if (!geomview_module) return EMPTY_str; geomview_set_flag(TRUE); /* plot all satellites */ gv_begin(); gv_trans_list_create(constellation.satellites); earth_place(ttime, constellation.pcb); gv_end(); return EMPTY_str;}/* * geomview_off */char *geomview_off_cmd(int argc, char *argv[]){ geomview_set_flag(FALSE); return EMPTY_str;}/* * geomview_set_flag(int flag) */voidgeomview_set_flag(int flag){ geomview_flag = flag;}/* * set_time() * * Sets time variable and makes sure window displays it */voidset_time(double t){ ttime = t; time_update(t);}/* * current_time() * * Returns current value of time variable. */doublecurrent_time(){ return (ttime);}/* * get_constellation * * Returns a pointer to the constellation */Constellation *get_constellation(){ return &constellation;}/* * get_central_body_radius * */doubleget_central_body_radius(){ return constellation.pcb->radius;}/* * satellite_init * * Create initial example satellite */voidsatellite_init(){ Satellite s; OrbitalElements oe = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; /* put at some fixed distance above the Earth */ oe.a = 1.2 * get_central_body_radius(); /* install one satellite */ s = satellite_create(0, &oe, constellation.pcb); constellation_add(&constellation, s); constellation_compute_positions(&constellation, ttime); /* display all satellites only if geomview is running */ /* place first so that they are created in the correct positions */ if (geomview_module) { gv_trans_list_create(constellation.satellites); gv_sat_list_create(&constellation); }}/* * sats_init * * Create initial configuration */voidsats_init(){ /* set time */ set_time(0.0); /* set size of coverage map */ if (coverage_large_map) { Image_Width = IMAGE_LARGE_WIDTH; Image_Height = IMAGE_LARGE_HEIGHT; } else { Image_Width = IMAGE_WIDTH; Image_Height = IMAGE_HEIGHT; }}/* * sats_update * * loop called repeatedly to update the configuration and * display of the satellites * */unsigned intsats_update(){ /* * Unit of time is second-dev-tes. */ unsigned int i; static unsigned int computed = FALSE; static double computed_time = 0.0; static double old_delta_t = 0.0; static double old_ttime = 0.0; static int old_direction = 0; double oldt; if (reset) { set_time(0.0); computed_time = 0.0; init_coverage_time(); computed = FALSE; reset = FALSE; constellation_compute_positions(&constellation, ttime); tracks_compute(constellation.satellites, constellation.pcb); fisheye_display(constellation.satellites, FALSE, constellation.pcb); clear_coverage(); coverage_compute(constellation.satellites, FALSE, constellation.pcb); if (geomview_flag) { gv_start(); if (transforms_needed) { gv_trans_list_create(constellation.satellites); } for (i = 0; i < N_VIEW_MODULES; i++) { if (view_modules[i].relocate_fn) view_modules[i].relocate_fn(&constellation); } gv_delayed_view_update(); earth_place(ttime, constellation.pcb); /* updates display, sends scratchfile if necessary. */ coverage_display(constellation.satellites, FALSE, constellation.pcb); gv_stop(); gv_set_ready(); } else { /* we're not talking to Geomview, but still need to draw coverage */ coverage_display(constellation.satellites, FALSE, constellation.pcb); } project_tracks_reset(); } else if (motion) { if (computed && !realtime_flag && ((old_ttime != ttime) || (old_delta_t != delta_t) || (old_direction != direction))) computed = FALSE; if (!computed) { if (!realtime_flag || single_step) { computed_time = ttime + direction * delta_t; old_ttime = ttime; old_delta_t = delta_t; old_direction = direction; } else { oldt = realtime; set_realtime(); computed_time = ttime + direction * (realtime - oldt) * delta_t; } constellation_compute_positions(&constellation, computed_time); coverage_decay(); coverage_compute(constellation.satellites, FALSE, constellation.pcb); tracks_compute(constellation.satellites, constellation.pcb); computed = TRUE; /* Pause briefly to avoid saturating the CPU. */ millisleep(1); } else { if (!geomview_flag || gv_ready()) { set_time(computed_time); fisheye_display(constellation.satellites, FALSE, constellation.pcb); /* plot all satellites */ if (geomview_flag) { gv_start(); if (transforms_needed) { gv_trans_list_create(constellation.satellites); } for (i = 0; i < N_VIEW_MODULES; i++) { if (view_modules[i].relocate_fn) view_modules[i].relocate_fn(&constellation); } gv_delayed_view_update(); earth_place(ttime, constellation.pcb); /* updates display, sends scratchfile if necessary. */ coverage_display(constellation.satellites, FALSE, constellation.pcb); gv_stop(); gv_set_ready(); } else { /* we're not talking to Geomview, but still need to draw coverage */ coverage_display(constellation.satellites, FALSE, constellation.pcb); } if (single_step) { single_step = FALSE; motion = FALSE; } computed = FALSE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -