From a12c46726bdbbd7c57a15cbe7b0f5cb77155455f Mon Sep 17 00:00:00 2001 From: gym Date: Wed, 12 Jan 2022 01:38:40 -0100 Subject: [PATCH] merge --- .gitignore | 141 +++++++++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 3 +- README.md | 42 +++++++++++++++- gpssim.c | 74 +++++++++++++++++++++++----- 4 files changed, 244 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 08869a8..df84c8b 100644 --- a/.gitignore +++ b/.gitignore @@ -39,6 +39,147 @@ gps-sdr-sim-lut # Temporary files *.swp +*~ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + + # Netbeans project folder nbproject/* diff --git a/Makefile b/Makefile index cebef54..98f5fdb 100644 --- a/Makefile +++ b/Makefile @@ -5,11 +5,12 @@ all: gps-sdr-sim SHELL=/bin/bash CC=gcc +LDFLAGS=-lm -lpthread CFLAGS=-O3 -Wall -D_FILE_OFFSET_BITS=64 ifdef USER_MOTION_SIZE CFLAGS+=-DUSER_MOTION_SIZE=$(USER_MOTION_SIZE) endif -LDFLAGS=-lm + gps-sdr-sim: gpssim.o ${CC} $< ${LDFLAGS} -o $@ diff --git a/README.md b/README.md index b4e7700..079a1f1 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# GPS-SDR-SIM +# GPS-SDR-SIM realtime GPS-SDR-SIM generates GPS baseband signal data streams, which can be converted to RF using software-defined radio (SDR) platforms, such as @@ -15,9 +15,38 @@ to RF using software-defined radio (SDR) platforms, such as ### Building with GCC ``` -$ gcc gpssim.c -lm -O3 -o gps-sdr-sim +$ gcc gpssim.c -lm -lpthread -O3 -o gps-sdr-sim ``` + +### Realtime by Gnuradio + +Use -n option can connect to a TCP source in Gnuradio for realtime simulation. + +The tcp source should be set in "Server" mode. + +See tcp.grc as an example. + +### Map + +Run gps-sdr-sim with -w option, and + +cd into /mapserver, and run + +``` +python mapper.py +``` + +Then visit http://127.0.0.1:8080/static/baidumap.html to use the Online map. + +You can write an map which can POST data to http://127.0.0.1:8080/post like this + +``` +lon=116&lat=39&hgt=10 +``` + + + ### Using bigger user motion files In order to use user motion files with more than 30000 samples (at 10Hz), the `USER_MOTION_SIZE` @@ -34,6 +63,7 @@ This variable can also be set when compiling directly with GCC: $ gcc gpssim.c -lm -O3 -o gps-sdr-sim -DUSER_MOTION_SIZE=4000 ``` + ### Generating the GPS signal file A user-defined trajectory can be specified in either a CSV file, which contains @@ -86,6 +116,8 @@ Options: -b I/Q data format [1/8/16] (default: 16) -i Disable ionospheric delay for spacecraft scenario -v Show details about simulated channels + -n Use TCP connection to Gnuradio TCP-Source for realtime simulation. + -w Connect with map server(/mapserver/mapper.py) by udp on port 5678. ``` The user motion can be specified in either dynamic or static mode: @@ -102,6 +134,12 @@ The user motion can be specified in either dynamic or static mode: > gps-sdr-sim -e brdc3540.14n -l 30.286502,120.032669,100 ``` +Use Gnuradio to realtime simulate 3000s: + +``` +> gps-sdr-sim -e brdc3540.14n -l 30.286502,120.032669,100 -n 1234 -d 3000 +``` + ### Transmitting the samples The TX port of a particular SDR platform is connected to the GPS receiver diff --git a/gpssim.c b/gpssim.c index 6cb725b..c37435e 100644 --- a/gpssim.c +++ b/gpssim.c @@ -11,6 +11,8 @@ #include #endif #include "gpssim.h" +#include "socket.c" +#include int sinTable512[] = { 2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47, @@ -1663,8 +1665,10 @@ void usage(void) " -s Sampling frequency [Hz] (default: 2600000)\n" " -b I/Q data format [1/8/16] (default: 16)\n" " -i Disable ionospheric delay for spacecraft scenario\n" - " -v Show details about simulated channels\n", - ((double)USER_MOTION_SIZE) / 10.0, STATIC_MAX_DURATION); + " -v Show details about simulated channels\n" + " -n Use TCP connect to Gnuradio TCP-Source for\n realtime simulation.\n" + "-w Connect with map server(/mapserver/mapper.py) by udp on port 5678.\n", + (double)((USER_MOTION_SIZE)/10.0),(int)STATIC_MAX_DURATION); return; } @@ -1730,6 +1734,12 @@ int main(int argc, char *argv[]) int timeoverwrite = FALSE; // Overwrite the TOC and TOE in the RINEX file ionoutc_t ionoutc; + + + int usesocket=false; + int webflag=0; + int sockc=0; + short port=1234; //////////////////////////////////////////////////////////// // Read options @@ -1753,7 +1763,7 @@ int main(int argc, char *argv[]) exit(1); } - while ((result=getopt(argc,argv,"e:u:g:c:l:o:s:b:T:t:d:iv"))!=-1) + while ((result=getopt(argc,argv,"e:u:g:c:l:o:s:b:T:t:d:ivn:w"))!=-1) { switch (result) { @@ -1846,10 +1856,26 @@ int main(int argc, char *argv[]) case '?': usage(); exit(1); + case 'n': + sscanf(optarg,"%hd",&port); + + usesocket=true; + break; + case 'w': + staticLocationMode = TRUE; + webflag=1; + break; + default: break; } } + if(webflag==1){ + pthread_t th; + pthread_create(&th,NULL,(void *)threadrecv,NULL); + } + if(usesocket==1) + sockc=sockinit(port); if (navfile[0]==0) { @@ -1866,7 +1892,7 @@ int main(int argc, char *argv[]) llh[2] = 10.0; } - if (duration<0.0 || (duration>((double)USER_MOTION_SIZE)/10.0 && !staticLocationMode) || (duration>STATIC_MAX_DURATION && staticLocationMode)) + if (duration<0.0 || (duration>((double)USER_MOTION_SIZE)/10.0 && !staticLocationMode) || (duration>STATIC_MAX_DURATION && staticLocationMode&&usesocket==false)) { fprintf(stderr, "ERROR: Invalid duration.\n"); exit(1); @@ -2092,7 +2118,7 @@ int main(int argc, char *argv[]) exit(1); } } - + if(usesocket==false){ // Open output file // "-" can be used as name for stdout if(strcmp("-", outfile)){ @@ -2104,7 +2130,7 @@ int main(int argc, char *argv[]) }else{ fp = stdout; } - + } //////////////////////////////////////////////////////////// // Initialize channels //////////////////////////////////////////////////////////// @@ -2142,7 +2168,7 @@ int main(int argc, char *argv[]) //////////////////////////////////////////////////////////// tstart = clock(); - + long int timestart=timem(); // Update receiver time grx = incGpsTime(grx, 0.1); @@ -2258,7 +2284,7 @@ int main(int argc, char *argv[]) iq_buff[isamp*2+1] = (short)q_acc; } - if (data_format==SC01) + if (data_format==SC01&&usesocket==false) { for (isamp=0; isamp<2*iq_buff_size; isamp++) { @@ -2270,17 +2296,26 @@ int main(int argc, char *argv[]) fwrite(iq8_buff, 1, iq_buff_size/4, fp); } - else if (data_format==SC08) + else if (data_format==SC08&&usesocket==false) { for (isamp=0; isamp<2*iq_buff_size; isamp++) iq8_buff[isamp] = iq_buff[isamp]>>4; // 12-bit bladeRF -> 8-bit HackRF fwrite(iq8_buff, 1, 2*iq_buff_size, fp); } - else // data_format==SC16 + else if(data_format==SC16&&usesocket==false) { fwrite(iq_buff, 2, 2*iq_buff_size, fp); } + if(usesocket==true){ + float *datap=(float*)calloc(iq_buff_size*2,sizeof(float)); + int l=0; + for(l=0;l0.1&&usesocket==true){ + usleep(100000); + } + + if(webflag==1){ + memcpy(llh,llhr,3*sizeof(double)); + llh[0] = llh[0] / R2D; // convert to RAD + llh[1] = llh[1] / R2D; // convert to RAD + llh2xyz(llh,xyz[0]); + } // Update receiver time grx = incGpsTime(grx, 0.1); @@ -2346,7 +2390,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "\rTime into run = %4.1f", subGpsTime(grx, g0)); fflush(stdout); } - + tend = clock(); fprintf(stderr, "\nDone!\n"); @@ -2355,10 +2399,14 @@ int main(int argc, char *argv[]) free(iq_buff); // Close file + if(usesocket==false) fclose(fp); - + else sockclose(sockc); // Process time fprintf(stderr, "Process time = %.1f [sec]\n", (double)(tend-tstart)/CLOCKS_PER_SEC); return(0); } + + +