📄 gpsplot.c
字号:
pxy.x = i; c = chanBufRead( chHeadNow, i); if ( c.ch == ch) { bit = (c.i_prompt_20ms>0) ? 1 : -1; pxy.y = c.i_prompt_20ms * bit; pxy.r = 1.0f; pxy.g = 0.0f; pxy.b = 0.0f; Plot2dAdd( pxy); pxy.y = c.q_dith_20ms * bit; pxy.r = 0.0f; pxy.g = 1.0f; pxy.b = 0.0f; Plot2dAdd( pxy); pxy.y = c.q_prompt_20ms * bit; pxy.r = 1.0f; pxy.g = 1.0f; pxy.b = 0.0f; Plot2dAdd( pxy); pxy.y = c.q_dith_20ms * bit; pxy.r = 0.0f; pxy.g = 1.0f; pxy.b = 1.0f; Plot2dAdd( pxy); } } return;}/* * */static void doplotIp( void){ int i, bit; CHN_INFO c; PLOT2D pxy; INT16 chHeadNow; chHeadNow = Chn_RBuf->ch_head; for ( i=0; i<numSamples; i++) { pxy.x = i; c = chanBufRead( chHeadNow, i); if ( c.ch == ch) { bit = (c.i_prompt_20ms>0) ? 1 : -1; pxy.y = c.i_prompt_20ms * bit; pxy.r = 1.0f; pxy.g = 0.0f; pxy.b = 0.0f; Plot2dAdd( pxy); } } return;}// -------------------------------------------------------------------//// fill Plot2dBuf//static void gatherPlot2dData( void){ INT16 chHeadNow; PLOT2D pxy; if ( stop) return; pxy.r = 1.0f; pxy.g = 1.0f; pxy.b = 0.0f; chHeadNow = Chn_RBuf->ch_head; switch ( PlotOpt.what2plot) {// case plotIp:// break; case plotCarFrq: doplotCarFrq(); break; case plotCodFrq: doplotCodFrq(); break; case plotIp: doplotIp(); break; case plotIQp: doplotIQp(); break; case plotIQd: doplotIQd(); break; case plotTP: doplotTP(); break; case plotDM: doplotDM(); break; case plotDMi: doplotDMi(); break; case plotPDP: doplotPDP(); break; default: printf( "gpsplot: what2plot = %d\n", PlotOpt.what2plot); break; } return;}/* * * * */static int watchdog_barks( void){ int ret = 0; static INT16 watchdog_prv = -1; if ( Chn_RBuf->watchdog == watchdog_prv) ret = 1; watchdog_prv = Chn_RBuf->watchdog; return (ret);}//------------------------------------------------------------------------------// DrawGlScene// // The main OpenGL drawing function. This will be called whenever something// needs to be drawn. Currently we call this as the 'idle-thread', thus stuff// will be redrawn whenever the program is not doing anything else.//void DrawGLScene( void){// Clear The Screen And The Depth Buffer glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); // Reset The View glLoadIdentity();// Setup our viewing position// gluLookAt( 0.0, 0.0, zoom, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); gluLookAt( xPos, yPos, zoom, xPos, yPos, 0.0, 0.0, 1.0, 0.0); glRotatef( scene_x, 1.0, 0.0, 0.0); glRotatef( scene_y, 0.0, 1.0, 0.0); glRotatef( scene_z, 0.0, 0.0, 1.0); if ( numSamples == 0) { printf( "gpsplot: no data found! ( numSamples = %d)\n", numSamples); glutDestroyWindow( window); exit( 0); } if ( Chn_RBuf->ch_head < 0) { printf( "gpsplot: ring buffer not yet written to!\n"); glutDestroyWindow( window); exit( 0); } if ( watchdog_barks()) { printf( "gpsplot: ogr stopped!\n"); glutDestroyWindow( window); exit( 0); } gatherPlot2dData(); Plot2dDraw( PlotOpt); // swap the buffers to display, since double buffering is used. glutSwapBuffers(); // wait for some time pause(); return;}//------------------------------------------------------------------------------// keyPressed// // This function is called whenever a key is pressed//void keyPressed( unsigned char key, int x, int y) { /* printf("key: 0x%x\n",key); */ /* If escape is pressed, kill everything. */ switch ( key) { case ESCAPE : glutDestroyWindow( window); exit( 0); case '8' : rclick = 0;// scene_x += XANGLE; yPos += YPOS_STEP; break; case '2' : rclick = 0;// scene_x -= XANGLE; yPos -= YPOS_STEP;// printf( "gpsplot: yPos = %e\n", yPos); break; case '6' : rclick = 0;// scene_y += YANGLE; xPos += XPOS_STEP;// printf( "gpsplot: xPos = %e\n", xPos); break; case '4' : rclick = 0;// scene_y -= YANGLE; xPos -= XPOS_STEP; break; case '7' : rclick = 0; scene_z += ZANGLE; break; case '9' : rclick = 0; scene_z -= ZANGLE; break;// zoom in & out case 0x2b : // + key rclick = 0; zoom /= ZOOM_STEP; printf( "gpsplot: zoom = %e\n", zoom); break; case 0x2d : // - key rclick = 0; zoom *= ZOOM_STEP; printf( "gpsplot: zoom = %e\n", zoom); break; case 0x9 : //tab break; case '5' : scene_x = 0.0f; scene_y = 0.0f; scene_z = 0.0f; zoom = 17.0f; rclick = 1; break; case 'r' : scene_x = 0.0f; scene_y = 0.0f; scene_z = 0.0f; zoom = 10.0f; rclick = 1; break; case 's' : stop = !stop;// yNumPoints = numSamples;// polarNumPoints = numSamples * numDataItems; break; case 'h' : yNewHead += 10; break; case 'l' : yNewHead -= 10; if ( yNewHead < 0) yNewHead = 0; break; default : printf( "gpsplot: pressed key >%d<\n", key); break; }}//------------------------------------------------------------------------------// getOptions// // We use this function whenever we get input from argc and argv - it will// parse the input options correctly.//void getOptions( int argc, char ** argv) { int i; int opt; /* Initialise character pointers */ for ( i=0; i < 16; i++) { plotDataList[i] = malloc( sizeof(char)*MAX_STRING_LENGTH); if ( !plotDataList[i]) { printf( "gpsplot: malloc() failed!\n"); exit(-1); } } while ((opt = getopt( argc, argv, "c:s:t:p:")) != -1) { switch (opt) { case 'c' : ch = min( atoi( optarg), NOFCHN-1); printf( "gpsplot: ch[%d] will be plotted\n",ch); break; case 's' : numSamples = min( atoi( optarg), CHN_RBUF_LEN); printf( "gpsplot: [%d] Samples will be used\n", numSamples); break; case 'p' : strcpy( plotDataListRaw, optarg); readCharList( optarg, plotDataList, &numDataItems); printf( "gpsplot: [%d] items will be plotted\n", numDataItems); for ( i=0; i < numDataItems; i++) { /* --- Ip --- */ if ( strcmp( plotDataList[i], "CodFrq")==0) { PlotOpt.what2plot = plotCodFrq; PlotOpt.plotline = 1; PlotOpt.unitaspect = 0; } else if ( strcmp( plotDataList[i], "CarFrq")==0) { PlotOpt.what2plot = plotCarFrq; PlotOpt.plotline = 1; PlotOpt.unitaspect = 0; } /* --- Ip --- */ else if ( strcmp( plotDataList[i], "Ip")==0) { PlotOpt.what2plot = plotIp; PlotOpt.plotline = 1; PlotOpt.unitaspect = 0; } /* --- IQp --- */ else if ( strcmp( plotDataList[i], "IQp")==0) { PlotOpt.what2plot = plotIQp; PlotOpt.plotline = 0; PlotOpt.unitaspect = 1; } /* --- IQd --- */ else if ( strcmp( plotDataList[i], "IQd")==0) { PlotOpt.what2plot = plotIQd; PlotOpt.plotline = 0; PlotOpt.unitaspect = 1; } /* --- DM (C/A code correlation) --- */ else if ( strcmp( plotDataList[i], "DM") == 0) { PlotOpt.what2plot = plotDM; PlotOpt.plotline = 0; PlotOpt.unitaspect = 0; } else if ( strcmp( plotDataList[i], "DMi") == 0) { PlotOpt.what2plot = plotDMi; PlotOpt.plotline = 0; PlotOpt.unitaspect = 0; } else if ( strcmp( plotDataList[i], "PDP") == 0) { PlotOpt.what2plot = plotPDP; PlotOpt.plotline = 0; PlotOpt.unitaspect = 0; } else printf("gpsplot: unknown option parameter -p >%s<\n", plotDataList[i]); } break; case ':' : printf( "option needs a value\n"); exit(-1); break; case '?' : default : printf( "unknown option: %c\n", optopt); exit(-1); break; } } return;}// ------------------------------------------------------------------//// howto gpsplot//void usage( void){ printf( "usage: gpsplot [-c channel] [-s samples] [-p plotdata] \n\n"); printf( " c Channel : channel to work with, channel\n"); printf( " can range from 0 to %d [default:0]\n", NOFCHN-1); printf( " s Samples : Number of samples to plot. Samples \n"); printf( " can range from 1 to %d [default:%d]\n", CHN_RBUF_LEN, CHN_RBUF_LEN); printf( " p PlotData : What type of data to plot. \n"); printf( " PlotData can be : \n");#if 0 printf( " Ip : In-phase prompt\n"); printf( " Id : In-phase dither\n"); printf( " Qp : Quad-phase prompt\n"); printf( " Qd : Quad-phase dither\n"); printf( " PP : Prompt power\n"); printf( " TP : Total power\n"); printf( " P : Prompt data (polar)\n"); printf( " D : Dither data (polar)\n"); printf( " CA : Carrier doppler frequency\n"); printf( " CD : Code doppler frequency\n"); printf( " CAE : Carrier frequency error\n"); printf( " CDA : Code phase error\n");#endif printf( " Ip : In-phase prompt\n"); printf( " IQp : In-phase / quad-phase (prompt)\n"); printf( " IQd : In-phase / quad-phase (dither)\n"); printf( " DM : C/A code correlation (delay mapping mode)\n"); printf( " DMi : C/A code correlation (delay mapping mode)\n"); printf( " PDP : Prompt/dither power\n"); printf( " CodFrq : code frequency [HZ]\n"); printf( " CarFrq : code frequency [HZ]\n"); return;}//------------------------------------------------------------------------------//// main// int main( int argc, char **argv) { int i; printf( "gpsplot v0.1 by Stephan Esterhuizen\n"); printf( "OpenGL plotting tool for OpenGPS\n"); printf( "adapted to work with OpenGPSRec\n\n"); if ( argc <= 2) { usage(); return (0); } getOptions(argc, argv);/* Initialize GLUT state */ glutInit(&argc, argv); /* Select type of Display mode: * Double buffer * RGBA color * Alpha components supported * Depth buffered for automatic clipping */ glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); /* get a window */ glutInitWindowSize( W, H); /* the window starts at the upper left corner of the screen */ glutInitWindowPosition( 0, 0); /* Open a window */ window = glutCreateWindow( "OpenGPS Plotting Tool v0.1"); /* Register the function to do all our OpenGL drawing. */ glutDisplayFunc( &DrawGLScene); /* Go fullscreen. This is as soon as possible. *//* glutFullScreen(); *//* pause for 0.1 s */ setup_timer( 500000l);/* Even if there are no events, redraw our gl scene. */ glutIdleFunc( &DrawGLScene);/* Register the function called when our window is resized. */ glutReshapeFunc( &ReSizeGLScene);/* Register the function called when the keyboard is pressed. */ glutKeyboardFunc( &keyPressed);/* Initialize our window. */ InitGL(W, H); /* Init SM for OpenGPS communications */ init_user();/* Start Event Processing Engine */ glutMainLoop(); /* Remove SM */ cleanup();/* Free memory again */ for ( i=0; i < 16; i++) free( plotDataList[i]); return (1);}/* ------------------------------ End of File ----------------------------- */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -