⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gpsplot.c

📁 The OpenGPSRec receiver software runs on the real time operating system RTAI-Linux. It compiles with
💻 C
📖 第 1 页 / 共 2 页
字号:
/* ************************************************************************    *                                                                      *   *                            OpenGPS Receiver                          *   *                                                                      *   * -------------------------------------------------------------------- *   *                                                                      *   *    Module:   gpsplot.c                                               *   *                                                                      *   *   Version:   0.1                                                     *   *                                                                      *   *      Date:   09.12.02                                                *   *                                                                      *   *    Author:   S. Esterhuizen, G. Beyerle                              *   *                                                                      *   * -------------------------------------------------------------------- *   *                                                                      *   * Copyright (C) 2003  S. Esterhuizen, G. Beyerle                       *   *                                                                      *   * This program is free software; you can redistribute it and/or modify *   * it under the terms of the GNU General Public License as published by *   * the Free Software Foundation; either version 2 of the License, or    *   * (at your option) any later version.                                  *   *                                                                      *   * This program is distributed in the hope that it will be useful,      *   * but WITHOUT ANY WARRANTY; without even the implied warranty of       *   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *   * GNU General Public License for more details.                         *   *                                                                      *   * You should have received a copy of the GNU General Public License    *   * along with this program; if not, write to the Free Software          *   * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.            *   *                                                                      *   * -------------------------------------------------------------------- *   *                                                                      *   *                         Plotting routine                             *   *                                                                      *   ************************************************************************ *//* ******************************* changes ********************************   09.12.03 - adapted to OpenGPSRec   ************************************************************************ *//* ----------------------------- includes --------------------------------- */#include <stdio.h>#include <stdlib.h>#include <stdarg.h>#include <math.h>#include <string.h>#include <time.h>#include <assert.h>#include <unistd.h>#include <fcntl.h>#include <signal.h>#include <sys/time.h>#include <sys/types.h>#include <sys/mman.h>#include <sys/stat.h>#include <GL/glut.h>     // Header File For The GLUT Library #include <GL/gl.h>       // Header File For The OpenGL32 Library#include <GL/glu.h>      // Header File For The GLu32 Library#include "../include/port.h"#include "../include/ogr_defines.h"#include "../include/ogr_structs.h"#include "defines.h"#define _MAIN_# include "globals.h"# include "plot2d.h"# include "rtai_functions.h"#undef _MAIN_#include "opengl_functions.h"/* ------------------------------- defines -------------------------------- *//* ASCII code for the escape key. */#define ESCAPE 27#define XANGLE 5#define ZANGLE 5#define YANGLE 5#define ZOOM_STEP 1.2#define XPOS_STEP 0.2#define YPOS_STEP 0.2#define CARR_FREQRES CARFRQRES#define CODE_FREQRES CODFRQRES   //#define CARFRQRES       42.574746268e-3  // GP2021 car. frq. resolution //#define CODFRQRES       85.149495e-3     // GP2021 code frq. resolution#define CARRIER_REF_HZ     (0x1f7b1b9L * CARFRQRES)#define CODE_REF_HZ        (0x16ea4a8L * CODFRQRES)enum{  plotCodFrq,  plotCarFrq,  plotIp,  plotIQp,  plotIQd,  plotTP,  plotDM,  plotDMi,  plotPDP};/* ------------------------------- globals -------------------------------- *//* type of figure used *///static int figPolar         = FALSE,//           figY             = FALSE,//           figXY            = FALSE;/* quantities to plot *///static int LineFlag = 1,//           what2plot;static float zoom = 10.0, xPos = 0.0, yPos = 0.0;static PLOTOPT PlotOpt;/* ----------------------------- procedures ------------------------------- *//* * dummy signal handler */void dummy_hndl( int sig){  return;}/* *  setup alarm clock: user prc is woken up every 'interval' us */static void setup_timer( long interval){//  check every 'interval' usec  struct sigaction sigact;  struct itimerval time;//  make sure SIGALRM doesn't kill user prc  sigact.sa_flags = 0;   sigemptyset( &sigact.sa_mask);  sigaddset( &sigact.sa_mask, SIGALRM);  sigact.sa_handler = dummy_hndl;  sigaction( SIGALRM, &sigact, 0);  time.it_interval.tv_sec  = 0;     time.it_interval.tv_usec = interval;     time.it_value.tv_sec     = 0;     time.it_value.tv_usec    = interval;  setitimer( ITIMER_REAL, &time, NULL);  return;}//------------------------------------------------------------------------------//   InitGL//  // This is the generic OpenGL initialisation function//static void InitGL( int Width, int Height)          // We call this right after our OpenGL window is created.{  GLfloat mat_specular[]   = {90.3, 2, 3, 3};  GLfloat mat_shininess[]  = { 50.0 };  GLfloat light_position[] = {4.0, 4.0, 4.0, 0.0};  GLfloat white_light[]    = {1.0, 1.0, 1.0, 1.0};  glClearColor( 0.0f, 0.0f, 0.0f, 0.0f); // This Will Clear The Background Color To Black  glClearDepth( 1.0);                    // Enables Clearing Of The Depth Buffer  glDepthFunc( GL_LESS);                 // The Type Of Depth Test To Do  glEnable( GL_DEPTH_TEST);              // Enables Depth Testing  glShadeModel( GL_SMOOTH);              // Enables Smooth Color Shading  glMatrixMode( GL_PROJECTION);  glLoadIdentity();                     // Reset The Projection Matrix// Calculate The Aspect Ratio Of The Window  gluPerspective( 45.0f, (GLfloat)Width / (GLfloat)Height, 0.1f, 100.0f);    glMatrixMode( GL_MODELVIEW);    glMaterialfv( GL_FRONT, GL_SPECULAR, mat_specular);  glMaterialfv( GL_FRONT, GL_SHININESS, mat_shininess);  glLightfv( GL_LIGHT0, GL_POSITION, light_position);  glLightfv( GL_LIGHT0, GL_DIFFUSE, white_light);  glLightfv( GL_LIGHT0, GL_SPECULAR, white_light);   glLightfv( GL_LIGHT0, GL_AMBIENT, white_light);    //glEnable( GL_LIGHTING);   glEnable( GL_LIGHT0);    return;}//------------------------------------------------------------------------------//   ReSizeGLScene//  // This function gets called whenever the OpenGL window is resizedvoid ReSizeGLScene( int Width, int Height){  W = Width;  H = Height;  if ( Height == 0)        // Prevent A Divide By Zero If The Window Is Too Small    Height = 1;  glViewport( 0, 0, Width, Height);    // Reset The Current Viewport And Perspective Transformation  glMatrixMode( GL_PROJECTION);  glLoadIdentity();  gluPerspective( 45.0f, (GLfloat)Width / (GLfloat)Height, 0.1f, 100.0f);  glMatrixMode( GL_MODELVIEW);  return;}/* * */static void doplotCarFrq( void){  int i;  CHN_INFO c;  PLOT2D pxy;  INT16 chHeadNow;     chHeadNow  = Chn_RBuf->ch_head;  for ( i=0; i<numSamples; i++)   {    c = chanBufRead( chHeadNow, i);    if ( c.ch == ch)    {      pxy.x = i;      pxy.y = c.car_frq * CARFRQRES - CARRIER_REF_HZ;      pxy.r = 1.0f;      pxy.g = 0.0f;      pxy.b = 0.0f;      Plot2dAdd( pxy);    }  }  return;}/* * */static void doplotCodFrq( void){  int i;  CHN_INFO c;  PLOT2D pxy;  INT16 chHeadNow;     chHeadNow  = Chn_RBuf->ch_head;  for ( i=0; i<numSamples; i++)   {    c = chanBufRead( chHeadNow, i);    if ( c.ch == ch)    {      pxy.x = i;      pxy.y = c.cod_frq * CODFRQRES - CODE_REF_HZ;       pxy.r = 0.0f;      pxy.g = 1.0f;      pxy.b = 0.0f;      Plot2dAdd( pxy);    }  }  return;}/* * */static void doplotIQd( void){  int i;  CHN_INFO c;  PLOT2D pxy;  INT16 chHeadNow;     chHeadNow  = Chn_RBuf->ch_head;  for ( i=0; i<numSamples; i++)   {    c = chanBufRead( chHeadNow, i);    if ( c.ch == ch)    {      pxy.x = c.i_dith_20ms;      pxy.y = c.q_dith_20ms;      pxy.r = 1.0f;      pxy.g = 1.0f;      pxy.b = 0.0f;      Plot2dAdd( pxy);    }  }  return;}/* * */static void doplotIQp( void){  int i;  CHN_INFO c;  PLOT2D pxy;  INT16 chHeadNow;     chHeadNow  = Chn_RBuf->ch_head;  for ( i=0; i<numSamples; i++)   {    c = chanBufRead( chHeadNow, i);    if ( c.ch == ch)    {      pxy.x = c.i_prompt_20ms;      pxy.y = c.q_prompt_20ms;      pxy.r = 1.0f;      pxy.g = 1.0f;      pxy.b = 0.0f;      Plot2dAdd( pxy);    }  }  return;}/* * */static void doplotTP( void){  int i;  CHN_INFO c;  PLOT2D pxy;  INT16 chHeadNow;     chHeadNow  = Chn_RBuf->ch_head;  for ( i=0; i<numSamples; i++)   {    c = chanBufRead( chHeadNow, i);    if ( c.ch == ch)    {/* total power vs. code phase*/      pxy.y = sqrt( (c.i_prompt+c.i_dith) * (c.i_prompt+c.i_dith) +                     (c.q_prompt+c.q_dith) * (c.q_prompt+c.q_dith));      pxy.x = 1024 * c.code_phase + c.code_dco_phase;/* make the colour look cool */      pxy.r = 1.0f;      pxy.g = 1.0f;      pxy.b = 0.0f;      Plot2dAdd( pxy);    }  }  return;}/* * */static void doplotDM( void){  int i, j, k;  CHN_INFO c;  PLOT2D tmppxy[2*NOFCHN];  INT16 chHeadNow;   double masterx = 0.0;  chHeadNow  = Chn_RBuf->ch_head;  for ( i=0; i<numSamples; i++)   {// overwrite command line option    ch = Chn_RBuf->leadch;    c = chanBufReadRev( 0, i);//    Chn_Info.code_phase     : code phase: 0,...,2045; 2046 halfchips//    Chn_Info.code_dco_phase : code frc. phs: 0,...,1023; 1024 = halfchip/* amplitude vs. code delay */    j = i % NOFCHN;    tmppxy[j].y        = sqrt( 1.0 * c.i_prompt_20ms * c.i_prompt_20ms +                                 1.0 * c.q_prompt_20ms * c.q_prompt_20ms);    tmppxy[j].x        = (1024.0 * c.code_phase + c.code_dco_phase ) / 2046.0;    if ( ch == c.ch)    {      masterx = tmppxy[j].x; // FIXME : how do I make visible points plotted on top of white line?      masterx = masterx - 0.02;  //        printf( "i=%d, j=%d, m=%e\n", i, j, masterx);     }      tmppxy[j+NOFCHN].y = sqrt( 1.0 * c.i_dith_20ms * c.i_dith_20ms +                                1.0 * c.q_dith_20ms * c.q_dith_20ms);    tmppxy[j+NOFCHN].x = tmppxy[j].x + 0.5;// last element!    if ( j == NOFCHN-1)    {      for ( k=0; k<2*NOFCHN; k++)       {        tmppxy[k].x = masterx - tmppxy[k].x;  // in chips                if ( (k % NOFCHN) == ch)        {          tmppxy[k].r = 1.0f;          tmppxy[k].g = 0.0f;          tmppxy[k].b = 0.0f;        }          else if ( k < NOFCHN)        {          tmppxy[k].r = 0.0f;          tmppxy[k].g = 1.0f;          tmppxy[k].b = 0.0f;        }          else        {          tmppxy[k].r = 0.0f;          tmppxy[k].g = 0.0f;          tmppxy[k].b = 1.0f;        }  // ignore outlier        if ( tmppxy[k].y < 20000.0)                    Plot2dAdd( tmppxy[k]);      }      }  // --- if ( j == NOFCHN-1) ---    }    // --- if ( plotDM)  ---  return;}/* * */static void doplotDMi( void){  int i, j, k, bit = 1;  CHN_INFO c;  PLOT2D tmppxy[2*NOFCHN];  INT16 chHeadNow;   double masterx = 0.0;  chHeadNow  = Chn_RBuf->ch_head;  for ( i=0; i<numSamples; i++)   {// overwrite command line option    ch = Chn_RBuf->leadch;    c = chanBufReadRev( 0, i);//    Chn_Info.code_phase     : code phase: 0,...,2045; 2046 halfchips//    Chn_Info.code_dco_phase : code frc. phs: 0,...,1023; 1024 = halfchip/* amplitude vs. code delay */    j = i % NOFCHN;    tmppxy[j].y        = c.i_prompt_20ms;        tmppxy[j].x        = (1024.0 * c.code_phase + c.code_dco_phase ) / 2046.0;    if ( ch == c.ch)    {      masterx = tmppxy[j].x; // FIXME : how do I make visible points plotted on top of white line?      masterx = masterx - 0.01;        bit = (tmppxy[j].y<0) ? -1 : 1;//        printf( "i=%d, j=%d, m=%e\n", i, j, masterx);     }      tmppxy[j+NOFCHN].y = c.i_dith_20ms;    tmppxy[j+NOFCHN].x = tmppxy[j].x + 0.5;// last element!    if ( j == NOFCHN-1)    {      for ( k=0; k<2*NOFCHN; k++)       {        tmppxy[k].x = masterx - tmppxy[k].x;  // in chips        tmppxy[k].y *= bit;  // remove nav bit                if ( (k % NOFCHN) == ch)        {          tmppxy[k].r = 1.0f;          tmppxy[k].g = 0.0f;          tmppxy[k].b = 0.0f;        }          else if ( k < NOFCHN)        {          tmppxy[k].r = 0.0f;          tmppxy[k].g = 1.0f;          tmppxy[k].b = 0.0f;        }          else        {          tmppxy[k].r = 0.0f;          tmppxy[k].g = 0.0f;          tmppxy[k].b = 1.0f;        }  // ignore outlier        if ( tmppxy[k].y < 20000.0 && tmppxy[k].y > -20000.0)                    Plot2dAdd( tmppxy[k]);      }      }  // --- if ( j == NOFCHN-1) ---    }    // --- if ( plotDMi)  ---  return;}/* * */static void doplotPDP( void){  int i, bit;  CHN_INFO c;  PLOT2D pxy;  INT16 chHeadNow;     chHeadNow  = Chn_RBuf->ch_head;  for ( i=0; i<numSamples; i++)   {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -