From: Alexandru C. <cs...@us...> - 2002-12-08 18:18:13
|
Update of /cvsroot/groundstation/gpredict/src In directory sc8-pr-cvs1:/tmp/cvs-serv31538 Modified Files: satlist.c satmap.c Log Message: Made modules secure against missing satellites. Index: satlist.c =================================================================== RCS file: /cvsroot/groundstation/gpredict/src/satlist.c,v retrieving revision 1.123 retrieving revision 1.124 diff -C2 -d -r1.123 -r1.124 *** satlist.c 19 Sep 2002 21:36:04 -0000 1.123 --- satlist.c 8 Dec 2002 18:18:10 -0000 1.124 *************** *** 611,615 **** */ ! gchar **argv,*configfile; gint argc,i,index; --- 611,615 ---- */ ! gchar **argv,*configfile,*text; gint argc,i,index; *************** *** 626,634 **** } - for (i=0; i<argc; i++) { index = satdata_get_sat_index (0, argv[i]); ! if (index != -1) satlist_sat_append (clist, index); } g_free (configfile); --- 626,643 ---- } for (i=0; i<argc; i++) { + /* Get index of satellite and add to list if the + satellite really exists in our database + */ index = satdata_get_sat_index (0, argv[i]); ! if (index != -1) { satlist_sat_append (clist, index); + } + else { + text = g_strdup_printf (_("%s: Satellite %s not in database!"), + __FUNCTION__, argv[i]); + satlog_log (SAT_LOG_WARNING, text); + g_free (text); + } } g_free (configfile); Index: satmap.c =================================================================== RCS file: /cvsroot/groundstation/gpredict/src/satmap.c,v retrieving revision 1.58 retrieving revision 1.59 diff -C2 -d -r1.58 -r1.59 *** satmap.c 19 Sep 2002 21:36:04 -0000 1.58 --- satmap.c 8 Dec 2002 18:18:10 -0000 1.59 *************** *** 146,149 **** --- 146,152 ---- gint argc,i,timer,delay; guint gconf_id; + gint satindex; + gchar *logmsg; + /**** FIXME: If there is an open module with the specified name, the new *************** *** 314,421 **** /* create list of satellites */ for (i=0; i<argc; i++) { ! smsat = SATMAP_SAT (g_malloc (sizeof (satmap_sat_t))); ! smsat->name = g_strdup (argv[i]); ! smsat->index = satdata_get_sat_index (0, argv[i]); ! sat = satdata_get_sat (smsat->index); ! /* canvas group for this satellite (reference coords) */ ! smsat->group = gnome_canvas_item_new (GNOME_CANVAS_GROUP (mapgroup), ! gnome_canvas_group_get_type (), ! "x", CX (sat->lon), "y", CY (sat->lat), NULL); ! smsat->mark = gnome_canvas_item_new (GNOME_CANVAS_GROUP (smsat->group), ! gnome_canvas_rect_get_type (), ! "x1", -1.0, "y1", -1.0, ! "x2", 1.0, "y2", 1.0, ! "fill_color", "yellow", ! NULL); ! smsat->text = gnome_canvas_item_new (GNOME_CANVAS_GROUP (smsat->group), ! gnome_canvas_text_get_type (), ! "text", smsat->name, ! "x", 0.0, "y", 1.0, ! "anchor", GTK_ANCHOR_N, ! "font", "-*-clean-medium-r-*-*-12-*-*-*-*-*-*-*", ! "fill_color", "yellow", ! NULL); ! ! /* Range Circle Calculations ! Borrowed from gsat 0.9.0 by Xavier Crehueras, EB3CZS ! who borrowed from John Magliacane, KD2BD. ! */ ! ssplat = sat->lat*deg2rad; ! ssplong = sat->lon*deg2rad; ! beta = (0.5*sat->fp)/R0; ! ! for (azi=0; azi<SATMAP_RANGE_CIRCLE_POINTS; azi++) ! { ! azimuth = deg2rad*(double)azi; ! rangelat = asin(sin(ssplat)*cos(beta)+cos(azimuth)*sin(beta)*cos(ssplat)); ! num = cos(beta)-(sin(ssplat)*sin(rangelat)); ! dem = cos(ssplat)*cos(rangelat); ! ! if (azi==0 && (beta > HALFPI-ssplat)) ! rangelong = ssplong+PI; ! ! else if (azi==180 && (beta > HALFPI+ssplat)) ! rangelong = ssplong+PI; ! ! else if (fabs(num/dem) > 1.0) ! rangelong = ssplong; ! else { ! if ((180-azi) >= 0) ! rangelong = ssplong-arccos(num,dem); ! else ! rangelong = ssplong+arccos(num,dem); ! } ! while (rangelong < 0.0) ! rangelong += TWOPI; ! ! while (rangelong > (2.0*PI)) ! rangelong -= TWOPI; ! ! rangelat = rangelat/deg2rad; ! rangelong = rangelong/deg2rad; ! ! /* Convert range circle data to map-based ! coordinates and draw on map */ ! ! if (rangelong > 180.0) { ! rangelong = rangelong-180.0; ! sx = (gint)(800-(rangelong*800/360.0)); } ! else ! sx = (gint)((800/2.0)-(rangelong*800/360.0)); ! ! sy = (gint)((400/2.0)-(rangelat*400/180.0)); ! ! /* store position for Plot Range Circle*/ ! /**** FIXME: VERY SLOW!!!!! */ ! smsat->range[azi] = gnome_canvas_item_new (GNOME_CANVAS_GROUP (mapgroup), ! gnome_canvas_rect_get_type (), ! "x1", sx, "x2", sx, ! "y1", sy, "y2", sy, ! "fill_color", "yellow", ! "outline_color", "yellow", ! "width_pixels", 1, ! NULL); ! /* fixes bug #537372 */ ! if (sx < CX (sat->lon)) ! sx += SATMAP_MAP_WIDTH; ! /* Mirror the half circle to the left */ ! sx2 = sx-2*(sx-CX(sat->lon)); ! if (sx2 < 0.0) /* outside the map */ ! sx2 = SATMAP_MAP_WIDTH+sx2; ! smsat->range[azi+180] = gnome_canvas_item_new (GNOME_CANVAS_GROUP (mapgroup), ! gnome_canvas_rect_get_type (), ! "x1", sx2, "x2", sx2, ! "y1", sy, "y2", sy, ! "fill_color", "yellow", ! "outline_color", "yellow", ! "width_pixels", 1, ! NULL); ! } - slist = g_list_append (slist, smsat); } g_strfreev (argv); --- 317,434 ---- /* create list of satellites */ for (i=0; i<argc; i++) { ! /* check whether we really have this satellite in the database */ ! satindex = satdata_get_sat_index (0, argv[i]); ! if (satindex!= -1) { ! smsat = SATMAP_SAT (g_malloc (sizeof (satmap_sat_t))); ! smsat->name = g_strdup (argv[i]); ! smsat->index = satindex; ! sat = satdata_get_sat (smsat->index); ! /* canvas group for this satellite (reference coords) */ ! smsat->group = gnome_canvas_item_new (GNOME_CANVAS_GROUP (mapgroup), ! gnome_canvas_group_get_type (), ! "x", CX (sat->lon), "y", CY (sat->lat), NULL); ! smsat->mark = gnome_canvas_item_new (GNOME_CANVAS_GROUP (smsat->group), ! gnome_canvas_rect_get_type (), ! "x1", -1.0, "y1", -1.0, ! "x2", 1.0, "y2", 1.0, ! "fill_color", "yellow", ! NULL); ! smsat->text = gnome_canvas_item_new (GNOME_CANVAS_GROUP (smsat->group), ! gnome_canvas_text_get_type (), ! "text", smsat->name, ! "x", 0.0, "y", 1.0, ! "anchor", GTK_ANCHOR_N, ! "font", "-*-clean-medium-r-*-*-12-*-*-*-*-*-*-*", ! "fill_color", "yellow", ! NULL); ! /* Range Circle Calculations ! Borrowed from gsat 0.9.0 by Xavier Crehueras, EB3CZS ! who borrowed from John Magliacane, KD2BD. ! */ ! ssplat = sat->lat*deg2rad; ! ssplong = sat->lon*deg2rad; ! beta = (0.5*sat->fp)/R0; ! for (azi=0; azi<SATMAP_RANGE_CIRCLE_POINTS; azi++) { ! azimuth = deg2rad*(double)azi; ! rangelat = asin(sin(ssplat)*cos(beta)+cos(azimuth)*sin(beta)*cos(ssplat)); ! num = cos(beta)-(sin(ssplat)*sin(rangelat)); ! dem = cos(ssplat)*cos(rangelat); ! ! if (azi==0 && (beta > HALFPI-ssplat)) ! rangelong = ssplong+PI; ! ! else if (azi==180 && (beta > HALFPI+ssplat)) ! rangelong = ssplong+PI; ! ! else if (fabs(num/dem) > 1.0) ! rangelong = ssplong; ! ! else { ! if ((180-azi) >= 0) ! rangelong = ssplong-arccos(num,dem); ! else ! rangelong = ssplong+arccos(num,dem); ! } ! ! while (rangelong < 0.0) ! rangelong += TWOPI; ! ! while (rangelong > (2.0*PI)) ! rangelong -= TWOPI; ! ! rangelat = rangelat/deg2rad; ! rangelong = rangelong/deg2rad; ! ! /* Convert range circle data to map-based ! coordinates and draw on map */ ! ! if (rangelong > 180.0) ! { ! rangelong = rangelong-180.0; ! sx = (gint)(800-(rangelong*800/360.0)); ! } ! else ! sx = (gint)((800/2.0)-(rangelong*800/360.0)); ! ! sy = (gint)((400/2.0)-(rangelat*400/180.0)); ! ! /* store position for Plot Range Circle*/ ! /**** FIXME: VERY SLOW!!!!! */ ! smsat->range[azi] = gnome_canvas_item_new (GNOME_CANVAS_GROUP (mapgroup), ! gnome_canvas_rect_get_type (), ! "x1", sx, "x2", sx, ! "y1", sy, "y2", sy, ! "fill_color", "yellow", ! "outline_color", "yellow", ! "width_pixels", 1, ! NULL); ! /* fixes bug #537372 */ ! if (sx < CX (sat->lon)) ! sx += SATMAP_MAP_WIDTH; ! /* Mirror the half circle to the left */ ! sx2 = sx-2*(sx-CX(sat->lon)); ! if (sx2 < 0.0) /* outside the map */ ! sx2 = SATMAP_MAP_WIDTH+sx2; ! smsat->range[azi+180] = gnome_canvas_item_new (GNOME_CANVAS_GROUP (mapgroup), ! gnome_canvas_rect_get_type (), ! "x1", sx2, "x2", sx2, ! "y1", sy, "y2", sy, ! "fill_color", "yellow", ! "outline_color", "yellow", ! "width_pixels", 1, ! NULL); ! } ! slist = g_list_append (slist, smsat); ! } ! else { ! logmsg = g_strdup_printf (_("%s: Satellite %s not in database!"), ! __FUNCTION__, argv[i]); ! satlog_log (SAT_LOG_WARNING, logmsg); ! g_free (logmsg); } } g_strfreev (argv); *************** *** 721,724 **** --- 734,738 ---- gdouble deg2rad=1.74532925199e-2; guint azi; + gchar *logmsg; *************** *** 726,820 **** ssat = (satmap_sat_t *)list->data; sat = satdata_get_sat (ssat->index); ! if (!sat) ! return TRUE; ! ! gnome_canvas_item_set (ssat->group, ! "x", CX (sat->lon), ! "y", CY (sat->lat), ! NULL); ! /* we need to do this, other canvas won't get updated */ ! gnome_canvas_item_set (ssat->mark, ! "x1", -1.0, ! NULL); ! gnome_canvas_item_set (ssat->text, ! "x", 0.0, "y", 1.0, ! NULL); ! /* Range Circle Calculations ! Borrowed from gsat 0.9.0 by Xavier Crehueras, EB3CZS ! who borrowed from John Magliacane, KD2BD. ! */ ! /* as of CVS rev. 1.36 some optimizations have been done by alexc */ ! ssplat = sat->lat*deg2rad; ! ssplong = sat->lon*deg2rad; ! beta = (0.5*sat->fp)/R0; ! for (azi=0; azi<SATMAP_RANGE_CIRCLE_POINTS; azi++) ! { ! azimuth = deg2rad*(double)azi; ! rangelat = asin(sin(ssplat)*cos(beta)+cos(azimuth)*sin(beta)*cos(ssplat)); ! num = cos(beta)-(sin(ssplat)*sin(rangelat)); ! dem = cos(ssplat)*cos(rangelat); ! ! if (azi==0 && (beta > HALFPI-ssplat)) ! rangelong = ssplong+PI; ! ! else if (azi==180 && (beta > HALFPI+ssplat)) ! rangelong = ssplong+PI; ! ! else if (fabs(num/dem) > 1.0) ! rangelong = ssplong; ! ! else { ! if ((180) >= azi) ! rangelong = ssplong-arccos(num,dem); ! else ! rangelong = ssplong+arccos(num,dem); ! } ! ! while (rangelong < 0.0) ! rangelong += TWOPI; ! ! while (rangelong > (TWOPI)) ! rangelong -= TWOPI; ! ! rangelat = rangelat/deg2rad; ! rangelong = rangelong/deg2rad; ! /* Convert range circle data to map-based ! coordinates and draw on map */ ! if (rangelong > 180.0) { ! rangelong = rangelong-180.0; ! sx = (gint)(SATMAP_MAP_WIDTH-(rangelong*SATMAP_MAP_WIDTH/360.0)); ! } ! else ! sx = (gint)((SATMAP_MAP_WIDTH/2.0)-(rangelong*SATMAP_MAP_WIDTH/360.0)); ! ! sy = (gint)((SATMAP_MAP_HEIGHT/2.0)-(rangelat*SATMAP_MAP_HEIGHT/180.0)); ! ! /* store position for Plot Range Circle*/ ! /**** FIXME: VERY SLOW!!!!! */ /* gnome_canvas_item_set (ssat->range[azi], "x1", sx, "x2", sx, */ /* "y1", sy, "y2", sy, NULL); */ ! /* Let's try to access rect->re coordinates directly ... uuuhh... */ ! GNOME_CANVAS_RECT (ssat->range[azi])->re.x1 = sx; ! GNOME_CANVAS_RECT (ssat->range[azi])->re.x2 = sx; ! GNOME_CANVAS_RECT (ssat->range[azi])->re.y1 = sy; ! GNOME_CANVAS_RECT (ssat->range[azi])->re.y2 = sy; ! gnome_canvas_item_request_update (ssat->range[azi]); ! /* fixes bug #537372 */ ! if (sx < CX (sat->lon)) ! sx += SATMAP_MAP_WIDTH; ! /* Mirror the half circle to the left */ ! sx2 = sx-2*(sx-CX(sat->lon)); ! if (sx2 < 0.0) /* outside the map */ ! sx2 = SATMAP_MAP_WIDTH+sx2; ! /* TO SLOOOOW... */ /* gnome_canvas_item_set (ssat->range[azi+180], "x1", sx2, "x2", sx2, */ /* "y1", sy, "y2", sy, NULL); */ ! GNOME_CANVAS_RECT (ssat->range[azi+180])->re.x1 = sx2; ! GNOME_CANVAS_RECT (ssat->range[azi+180])->re.x2 = sx2; ! GNOME_CANVAS_RECT (ssat->range[azi+180])->re.y1 = sy; ! GNOME_CANVAS_RECT (ssat->range[azi+180])->re.y2 = sy; ! gnome_canvas_item_request_update (ssat->range[azi+180]); } list = g_list_next (list); --- 740,840 ---- ssat = (satmap_sat_t *)list->data; sat = satdata_get_sat (ssat->index); ! if (sat) { ! gnome_canvas_item_set (ssat->group, ! "x", CX (sat->lon), ! "y", CY (sat->lat), ! NULL); ! /* we need to do this, otherwise canvas won't get updated */ ! gnome_canvas_item_set (ssat->mark, ! "x1", -1.0, ! NULL); ! gnome_canvas_item_set (ssat->text, ! "x", 0.0, "y", 1.0, ! NULL); ! /* Range Circle Calculations ! Borrowed from gsat 0.9.0 by Xavier Crehueras, EB3CZS ! who borrowed from John Magliacane, KD2BD. ! */ ! /* as of CVS rev. 1.36 some optimizations have been done by alexc */ ! ssplat = sat->lat*deg2rad; ! ssplong = sat->lon*deg2rad; ! beta = (0.5*sat->fp)/R0; ! for (azi=0; azi<SATMAP_RANGE_CIRCLE_POINTS; azi++) { ! azimuth = deg2rad*(double)azi; ! rangelat = asin(sin(ssplat)*cos(beta)+cos(azimuth)*sin(beta)*cos(ssplat)); ! num = cos(beta)-(sin(ssplat)*sin(rangelat)); ! dem = cos(ssplat)*cos(rangelat); ! ! if (azi==0 && (beta > HALFPI-ssplat)) ! rangelong = ssplong+PI; ! ! else if (azi==180 && (beta > HALFPI+ssplat)) ! rangelong = ssplong+PI; ! ! else if (fabs(num/dem) > 1.0) ! rangelong = ssplong; ! ! else { ! if ((180) >= azi) ! rangelong = ssplong-arccos(num,dem); ! else ! rangelong = ssplong+arccos(num,dem); ! } ! ! while (rangelong < 0.0) ! rangelong += TWOPI; ! ! while (rangelong > (TWOPI)) ! rangelong -= TWOPI; ! ! rangelat = rangelat/deg2rad; ! rangelong = rangelong/deg2rad; ! ! /* Convert range circle data to map-based ! coordinates and draw on map */ ! if (rangelong > 180.0) ! { ! rangelong = rangelong-180.0; ! sx = (gint)(SATMAP_MAP_WIDTH-(rangelong*SATMAP_MAP_WIDTH/360.0)); ! } ! else ! sx = (gint)((SATMAP_MAP_WIDTH/2.0)-(rangelong*SATMAP_MAP_WIDTH/360.0)); ! ! sy = (gint)((SATMAP_MAP_HEIGHT/2.0)-(rangelat*SATMAP_MAP_HEIGHT/180.0)); ! ! /* store position for Plot Range Circle*/ ! /**** FIXME: VERY SLOW!!!!! */ /* gnome_canvas_item_set (ssat->range[azi], "x1", sx, "x2", sx, */ /* "y1", sy, "y2", sy, NULL); */ ! /* Let's try to access rect->re coordinates directly ... uuuhh... */ ! GNOME_CANVAS_RECT (ssat->range[azi])->re.x1 = sx; ! GNOME_CANVAS_RECT (ssat->range[azi])->re.x2 = sx; ! GNOME_CANVAS_RECT (ssat->range[azi])->re.y1 = sy; ! GNOME_CANVAS_RECT (ssat->range[azi])->re.y2 = sy; ! gnome_canvas_item_request_update (ssat->range[azi]); ! /* fixes bug #537372 */ ! if (sx < CX (sat->lon)) ! sx += SATMAP_MAP_WIDTH; ! /* Mirror the half circle to the left */ ! sx2 = sx-2*(sx-CX(sat->lon)); ! if (sx2 < 0.0) /* outside the map */ ! sx2 = SATMAP_MAP_WIDTH+sx2; ! /* TO SLOOOOW... */ /* gnome_canvas_item_set (ssat->range[azi+180], "x1", sx2, "x2", sx2, */ /* "y1", sy, "y2", sy, NULL); */ ! GNOME_CANVAS_RECT (ssat->range[azi+180])->re.x1 = sx2; ! GNOME_CANVAS_RECT (ssat->range[azi+180])->re.x2 = sx2; ! GNOME_CANVAS_RECT (ssat->range[azi+180])->re.y1 = sy; ! GNOME_CANVAS_RECT (ssat->range[azi+180])->re.y2 = sy; ! gnome_canvas_item_request_update (ssat->range[azi+180]); ! } ! } ! else { ! logmsg = g_strdup_printf (_("%s: Missing satellite detected. This satellite is now a zombie."), ! __FUNCTION__); ! satlog_log (SAT_LOG_WARNING, logmsg); ! g_free (logmsg); } list = g_list_next (list); |