Merge 759dd3b965
into 899c364092
This commit is contained in:
commit
2136289a5a
147
.gitignore
vendored
147
.gitignore
vendored
@ -39,8 +39,155 @@ gps-sdr-sim-lut
|
||||
# Temporary files
|
||||
*.swp
|
||||
|
||||
*~
|
||||
<<<<<<< HEAD
|
||||
# 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/*
|
||||
|
||||
# Last used USER_MOTION_SIZE variable
|
||||
.user-motion-size
|
||||
=======
|
||||
|
||||
# Python bytecodes
|
||||
*.pyc
|
||||
>>>>>>> 33aa99cdff44ab8f8ced315ff0b7ea047ef92403
|
||||
|
3
Makefile
3
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 $@
|
||||
|
53
README.md
53
README.md
@ -1,23 +1,47 @@
|
||||
# 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
|
||||
[ADALM-Pluto](https://wiki.analog.com/university/tools/pluto), [bladeRF](http://nuand.com/), [HackRF](https://github.com/mossmann/hackrf/wiki), and [USRP](http://www.ettus.com/).
|
||||
|
||||
### Windows build instructions
|
||||
|
||||
1. Start Visual Studio.
|
||||
2. Create an empty project for a console application.
|
||||
3. On the Solution Explorer at right, add "gpssim.c" and "getopt.c" to the Souce Files folder.
|
||||
4. Select "Release" in Solution Configurations drop-down list.
|
||||
5. Build the solution.
|
||||
|
||||
### Building with GCC
|
||||
### Building with make
|
||||
|
||||
```
|
||||
$ gcc gpssim.c -lm -O3 -o gps-sdr-sim
|
||||
$ make
|
||||
```
|
||||
|
||||
|
||||
### 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.
|
||||
|
||||
Or visit http://127.0.0.1:8080/static/googlemap.html to use the google Online map.
|
||||
|
||||
You can also 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 +58,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 +111,8 @@ Options:
|
||||
-b <iq_bits> I/Q data format [1/8/16] (default: 16)
|
||||
-i Disable ionospheric delay for spacecraft scenario
|
||||
-v Show details about simulated channels
|
||||
-n <port> Use TCP connection to Gnuradio TCP-Source for realtime simulation.
|
||||
-w <port> Connect with map server(/mapserver/mapper.py) by UDP (default port 5678).
|
||||
```
|
||||
|
||||
The user motion can be specified in either dynamic or static mode:
|
||||
@ -102,6 +129,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
|
||||
|
1676
brmu1360.19n
Normal file
1676
brmu1360.19n
Normal file
File diff suppressed because it is too large
Load Diff
77
gpssim.c
77
gpssim.c
@ -11,6 +11,8 @@
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include "gpssim.h"
|
||||
#include "socket.c"
|
||||
#include <pthread.h>
|
||||
|
||||
int sinTable512[] = {
|
||||
2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47,
|
||||
@ -1663,12 +1665,14 @@ void usage(void)
|
||||
" -s <frequency> Sampling frequency [Hz] (default: 2600000)\n"
|
||||
" -b <iq_bits> 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 <port> Use TCP connect to Gnuradio TCP-Source for\n realtime simulation.\n"
|
||||
" -w <port> Connect with map server(/mapserver/mapper.py) by UDP (default port 5678).\n",
|
||||
(double)((USER_MOTION_SIZE)/10.0),(int)STATIC_MAX_DURATION);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned short mapport=5678;
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
clock_t tstart,tend;
|
||||
@ -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;
|
||||
unsigned 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,27 @@ int main(int argc, char *argv[])
|
||||
case '?':
|
||||
usage();
|
||||
exit(1);
|
||||
case 'n':
|
||||
sscanf(optarg,"%hd",&port);
|
||||
|
||||
usesocket=true;
|
||||
break;
|
||||
case 'w':
|
||||
sscanf(optarg,"%hd",&mapport);
|
||||
staticLocationMode = TRUE;
|
||||
webflag=1;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(webflag==1){
|
||||
pthread_t th;
|
||||
pthread_create(&th,NULL,(void *)threadrecv,(void *) &mapport);
|
||||
}
|
||||
if(usesocket==1)
|
||||
sockc=sockinit(port);
|
||||
|
||||
if (navfile[0]==0)
|
||||
{
|
||||
@ -1866,7 +1893,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);
|
||||
@ -2097,7 +2124,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)){
|
||||
@ -2109,7 +2136,7 @@ int main(int argc, char *argv[])
|
||||
}else{
|
||||
fp = stdout;
|
||||
}
|
||||
|
||||
}
|
||||
////////////////////////////////////////////////////////////
|
||||
// Initialize channels
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -2147,7 +2174,7 @@ int main(int argc, char *argv[])
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
tstart = clock();
|
||||
|
||||
long int timestart=timem();
|
||||
// Update receiver time
|
||||
grx = incGpsTime(grx, 0.1);
|
||||
|
||||
@ -2263,7 +2290,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++)
|
||||
{
|
||||
@ -2275,17 +2302,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;l<iq_buff_size*2;l++){
|
||||
datap[l]=(float)iq_buff[l];
|
||||
}
|
||||
socksend(sockc,datap,iq_buff_size*2*sizeof(float));
|
||||
free(datap);
|
||||
}
|
||||
|
||||
//
|
||||
// Update navigation message and channel allocation every 30 seconds
|
||||
@ -2343,7 +2379,16 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(subGpsTime(grx, g0)-(float)(timem()-timestart)/1000>0.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);
|
||||
|
||||
@ -2351,7 +2396,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");
|
||||
@ -2360,10 +2405,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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
5
gpssim.h
5
gpssim.h
@ -1,11 +1,12 @@
|
||||
#ifndef GPSSIM_H
|
||||
#define GPSSIM_H
|
||||
|
||||
#define FLOAT_CARR_PHASE // For RKT simulation. Higher computational load, but smoother carrier phase.
|
||||
//#define FLOAT_CARR_PHASE // For RKT simulation. Higher computational load, but smoother carrier phase.
|
||||
|
||||
#define TRUE (1)
|
||||
#define FALSE (0)
|
||||
|
||||
#define true (1)
|
||||
#define false (0)
|
||||
/*! \brief Maximum length of a line in a text file (RINEX, motion) */
|
||||
#define MAX_CHAR (100)
|
||||
|
||||
|
48
mapserver/mapper.py
Executable file
48
mapserver/mapper.py
Executable file
@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env python
|
||||
from __future__ import print_function
|
||||
import socket
|
||||
import struct
|
||||
import time
|
||||
import web
|
||||
HOST = 'localhost'
|
||||
PORT = 5678
|
||||
BUFFSIZE = 1024
|
||||
ADDR = (HOST, PORT)
|
||||
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
|
||||
urls = (
|
||||
'/', 'index',
|
||||
'/post', 'post',
|
||||
'/static/*', 'static',
|
||||
)
|
||||
app = web.application(urls, globals())
|
||||
|
||||
|
||||
class index:
|
||||
def GET(self):
|
||||
raise web.seeother('/static/baidumap.html')
|
||||
|
||||
|
||||
class post:
|
||||
def POST(self):
|
||||
inn = web.input()
|
||||
lon = float(inn.get('lon'))
|
||||
lat = float(inn.get('lat'))
|
||||
h = float(inn.get('hgt'))
|
||||
data = struct.pack('ddd', lat, lon, h)
|
||||
sock.sendto(data, ADDR)
|
||||
print(lon, lat, h)
|
||||
|
||||
|
||||
class static:
|
||||
def GET(self, media, file):
|
||||
try:
|
||||
f = open(media + '/' + file, 'r')
|
||||
return f.read()
|
||||
except:
|
||||
return '404'
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
160
mapserver/static/baidumap.html
Normal file
160
mapserver/static/baidumap.html
Normal file
@ -0,0 +1,160 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
|
||||
<title>百度地图</title>
|
||||
<!--引用百度地图API-->
|
||||
<style type="text/css">
|
||||
html,body{margin:0;padding:0;}
|
||||
.iw_poi_title {color:#CC5522;font-size:14px;font-weight:bold;overflow:hidden;padding-right:13px;white-space:nowrap}
|
||||
.iw_poi_content {font:12px arial,sans-serif;overflow:visible;padding-top:4px;white-space:-moz-pre-wrap;word-wrap:break-word}
|
||||
</style>
|
||||
<script type="text/javascript" src="http://api.map.baidu.com/api?key=&v=1.1&services=true"></script>
|
||||
<link rel="stylesheet" href="./jqueryui.css">
|
||||
<script src="./jquery.js"></script>
|
||||
<script src="./jqueryui.js"></script>
|
||||
<script src="./index.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<!--百度地图容器-->
|
||||
<center>
|
||||
<div style="width:1000px;height:650px;border:#ccc solid 1px;">
|
||||
<div style="width:800px;height:600px;border:#ccc solid 1px;" id="dituContent"></div>
|
||||
<br>
|
||||
高度:<br>
|
||||
<div id="slider"></div>
|
||||
速度:<br>
|
||||
<div id="slider-speed"></div><br>
|
||||
</div>
|
||||
<br>
|
||||
<br><br>
|
||||
位置:(lat,lon,hgt)
|
||||
<p id="pp"></p>
|
||||
<button onclick="start()">START</button>
|
||||
</center>
|
||||
</body>
|
||||
<script type="text/javascript">
|
||||
//创建和初始化地图函数:
|
||||
function initMap(){
|
||||
createMap();//创建地图
|
||||
setMapEvent();//设置地图事件
|
||||
addMapControl();//向地图添加控件
|
||||
}
|
||||
|
||||
//创建地图函数:
|
||||
function createMap(){
|
||||
var map = new BMap.Map("dituContent");//在百度地图容器中创建一个地图
|
||||
var point = new BMap.Point(104.50553,34.39016);//定义一个中心点坐标
|
||||
map.centerAndZoom(point,5);//设定地图的中心点和坐标并将地图显示在地图容器中
|
||||
window.map = map;//将map变量存储在全局
|
||||
}
|
||||
|
||||
//地图事件设置函数:
|
||||
function setMapEvent(){
|
||||
map.enableDragging();//启用地图拖拽事件,默认启用(可不写)
|
||||
map.enableScrollWheelZoom();//启用地图滚轮放大缩小
|
||||
map.disableDoubleClickZoom();//启用鼠标双击放大,默认启用(可不写)
|
||||
map.enableKeyboard();//启用键盘上下左右键移动地图
|
||||
}
|
||||
|
||||
//地图控件添加函数:
|
||||
function addMapControl(){
|
||||
//向地图中添加缩放控件
|
||||
var ctrl_nav = new BMap.NavigationControl({anchor:BMAP_ANCHOR_TOP_LEFT,type:BMAP_NAVIGATION_CONTROL_LARGE});
|
||||
map.addControl(ctrl_nav);
|
||||
//向地图中添加缩略图控件
|
||||
//向地图中添加比例尺控件
|
||||
var ctrl_sca = new BMap.ScaleControl({anchor:BMAP_ANCHOR_BOTTOM_LEFT});
|
||||
map.addControl(ctrl_sca);
|
||||
}
|
||||
|
||||
var lat=39.0;
|
||||
var lon=116.0;
|
||||
var hgt=100.0;
|
||||
var points=[];
|
||||
var d2m=2*Math.PI*6371000/360;
|
||||
function d2l(a){//degree to linear
|
||||
return {x:a.lon*d2m,y:a.lat*d2m,z:a.alt};
|
||||
}
|
||||
function l2d(a){
|
||||
return {lon:a.x/d2m,lat:a.y/d2m,alt:a.z};
|
||||
}
|
||||
function ladd(a,b){//linear substrate
|
||||
return {x:a.x+b.x,y:a.y+b.y,z:a.z+b.z};
|
||||
}
|
||||
function lsub(a,b){
|
||||
return {x:a.x-b.x,y:a.y-b.y,z:a.z-b.z};
|
||||
}
|
||||
function lmul(a,b){
|
||||
return {x:a.x*b,y:a.y*b,z:a.z*b};
|
||||
}
|
||||
|
||||
|
||||
function ll(a){
|
||||
return Math.sqrt(a.x*a.x+a.y*a.y+a.z*a.z);
|
||||
}
|
||||
function norm(l){
|
||||
var lll=ll(l);
|
||||
return {x:l.x/lll,y:l.y/lll,z:l.z/lll};
|
||||
}
|
||||
var lt=0;
|
||||
var st=0;
|
||||
var pos=d2l({lon:139,lat:32,alt:10});
|
||||
var des=pos;
|
||||
var vec={x:0,y:0,z:0};
|
||||
var lines=[];
|
||||
|
||||
initMap();//创建和初始化地图
|
||||
var mainmarker = new BMap.Marker(new BMap.Point(lon,lat));
|
||||
var mlabel = new BMap.Label("main",{offset:new BMap.Size(20,-10)});
|
||||
map.addOverlay(mainmarker);
|
||||
mainmarker.setLabel(mlabel);
|
||||
map.addEventListener("click",function(e){
|
||||
des=d2l({lon:e.point.lng,lat:e.point.lat,alt:20});
|
||||
vec=norm(lsub(des,pos));
|
||||
console.log(e.point.lng+","+e.point.lat);
|
||||
});
|
||||
map.addEventListener("dblclick",function(e){
|
||||
pos=d2l({lon:e.point.lng,lat:e.point.lat,alt:20});
|
||||
console.log(e.point.lng+","+e.point.lat);
|
||||
});
|
||||
function post(){
|
||||
|
||||
//hgt=$("#slider").slider("value");
|
||||
if(ll(lsub(des,pos))>=10){
|
||||
map.clearOverlays();
|
||||
pos=ladd(pos,lmul(vec,$("#slider-speed").slider("value")/10))
|
||||
lonb=l2d(pos).lon;
|
||||
latb=l2d(pos).lat;
|
||||
alt=l2d(pos).alt;
|
||||
var gcj = coordtransform.bd09togcj02(lonb,latb);
|
||||
var wgs = coordtransform.gcj02towgs84(gcj[0],gcj[1]);
|
||||
lon=wgs[0];
|
||||
lat=wgs[1];
|
||||
//mainmarker.setPosition(new BMap.Point(lon,lat));
|
||||
marker = new BMap.Marker(new BMap.Point(lonb,latb));
|
||||
map.addOverlay(marker);
|
||||
//console.log(lon+","+lat);
|
||||
}
|
||||
$("#pp").html("lon:"+lon+" lat:"+lat+" hgt:"+hgt+"spd:"+$("#slider-speed").slider("value")/10);
|
||||
$.post("/post",{"lon":lon,"lat":lat,"hgt":hgt});
|
||||
$("#pp").html("lon:"+lon+" lat:"+lat+" hgt:"+hgt+"spd:"+$("#slider-speed").slider("value")/10);
|
||||
}
|
||||
$(function() {
|
||||
$( "#slider" ).slider({
|
||||
min: -1000,
|
||||
max: 8848,
|
||||
value: 10,
|
||||
});
|
||||
$( "#slider-speed" ).slider({
|
||||
min: 0,
|
||||
max: 100,
|
||||
value: 0,
|
||||
});
|
||||
setInterval(post,100);
|
||||
});
|
||||
</script>
|
||||
|
||||
</html>
|
91
mapserver/static/googlemap.html
Normal file
91
mapserver/static/googlemap.html
Normal file
@ -0,0 +1,91 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Choose Your Location</title>
|
||||
<script
|
||||
type="text/javascript"
|
||||
src="https://maps.googleapis.com/maps/api/js?key="
|
||||
></script>
|
||||
<script>
|
||||
// hack Google Maps to bypass API v3 key (needed since 22 June 2016 http://googlegeodevelopers.blogspot.com.es/2016/06/building-for-scale-updates-to-google.html)
|
||||
var target = document.head;
|
||||
var observer = new MutationObserver(function(mutations) {
|
||||
for (var i = 0; mutations[i]; ++i) {
|
||||
// notify when script to hack is added in HTML head
|
||||
if (
|
||||
mutations[i].addedNodes[0].nodeName == "SCRIPT" &&
|
||||
mutations[i].addedNodes[0].src.match(
|
||||
/\/AuthenticationService.Authenticate?/g
|
||||
)
|
||||
) {
|
||||
var str = mutations[i].addedNodes[0].src.match(
|
||||
/[?&]callback=.*[&$]/g
|
||||
);
|
||||
if (str) {
|
||||
if (str[0][str[0].length - 1] == "&") {
|
||||
str = str[0].substring(10, str[0].length - 1);
|
||||
} else {
|
||||
str = str[0].substring(10);
|
||||
}
|
||||
var split = str.split(".");
|
||||
var object = split[0];
|
||||
var method = split[1];
|
||||
window[object][method] = null; // remove censorship message function _xdc_._jmzdv6 (AJAX callback name "_jmzdv6" differs depending on URL)
|
||||
//window[object] = {}; // when we removed the complete object _xdc_, Google Maps tiles did not load when we moved the map with the mouse (no problem with OpenStreetMap)
|
||||
}
|
||||
observer.disconnect();
|
||||
}
|
||||
}
|
||||
});
|
||||
var config = { attributes: true, childList: true, characterData: true };
|
||||
observer.observe(target, config);
|
||||
</script>
|
||||
<script src="https://unpkg.com/location-picker/dist/location-picker.min.js"></script>
|
||||
<script src="./jquery.js"></script>
|
||||
<script src="./jqueryui.js"></script>
|
||||
<style type="text/css">
|
||||
#map {
|
||||
width: 100%;
|
||||
height: 600px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="map"></div>
|
||||
<br />
|
||||
<button id="confirmPosition">Confirm Position</button>
|
||||
<br />
|
||||
<p>Cursor position: <span id="onIdlePositionView"></span></p>
|
||||
<p>Confirmed position: <span id="onClickPositionView"></span></p>
|
||||
<script>
|
||||
var confirmBtn = document.getElementById("confirmPosition");
|
||||
var onClickPositionView = document.getElementById("onClickPositionView");
|
||||
var onIdlePositionView = document.getElementById("onIdlePositionView");
|
||||
var map = document.getElementById("map");
|
||||
var lp = new locationPicker(
|
||||
map,
|
||||
{
|
||||
setCurrentPosition: true,
|
||||
lat: 39.9077,
|
||||
lng: 116.3974
|
||||
},
|
||||
{
|
||||
zoom: 15
|
||||
}
|
||||
);
|
||||
confirmBtn.onclick = function() {
|
||||
var location = lp.getMarkerPosition();
|
||||
onClickPositionView.innerHTML =
|
||||
"The chosen location is " + location.lat + "," + location.lng;
|
||||
$.post("/post", { lon: location.lng, lat: location.lat, hgt: 100 });
|
||||
};
|
||||
google.maps.event.addListener(lp.map, "idle", function(event) {
|
||||
var location = lp.getMarkerPosition();
|
||||
onIdlePositionView.innerHTML =
|
||||
"The chosen location is " + location.lat + "," + location.lng;
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
153
mapserver/static/index.js
Normal file
153
mapserver/static/index.js
Normal file
@ -0,0 +1,153 @@
|
||||
/**
|
||||
* Created by Wandergis on 2015/7/8.
|
||||
* 提供了百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换
|
||||
*/
|
||||
//UMD魔法代码
|
||||
// if the module has no dependencies, the above pattern can be simplified to
|
||||
(function (root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define([], factory);
|
||||
} else if (typeof module === 'object' && module.exports) {
|
||||
// Node. Does not work with strict CommonJS, but
|
||||
// only CommonJS-like environments that support module.exports,
|
||||
// like Node.
|
||||
module.exports = factory();
|
||||
} else {
|
||||
// Browser globals (root is window)
|
||||
root.coordtransform = factory();
|
||||
}
|
||||
}(this, function () {
|
||||
//定义一些常量
|
||||
var x_PI = 3.14159265358979324 * 3000.0 / 180.0;
|
||||
var PI = 3.1415926535897932384626;
|
||||
var a = 6378245.0;
|
||||
var ee = 0.00669342162296594323;
|
||||
/**
|
||||
* 百度坐标系 (BD-09) 与 火星坐标系 (GCJ-02)的转换
|
||||
* 即 百度 转 谷歌、高德
|
||||
* @param bd_lon
|
||||
* @param bd_lat
|
||||
* @returns {*[]}
|
||||
*/
|
||||
var bd09togcj02 = function bd09togcj02(bd_lon, bd_lat) {
|
||||
var bd_lon = +bd_lon;
|
||||
var bd_lat = +bd_lat;
|
||||
var x = bd_lon - 0.0065;
|
||||
var y = bd_lat - 0.006;
|
||||
var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_PI);
|
||||
var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_PI);
|
||||
var gg_lng = z * Math.cos(theta);
|
||||
var gg_lat = z * Math.sin(theta);
|
||||
return [gg_lng, gg_lat]
|
||||
};
|
||||
|
||||
/**
|
||||
* 火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换
|
||||
* 即谷歌、高德 转 百度
|
||||
* @param lng
|
||||
* @param lat
|
||||
* @returns {*[]}
|
||||
*/
|
||||
var gcj02tobd09 = function gcj02tobd09(lng, lat) {
|
||||
var lat = +lat;
|
||||
var lng = +lng;
|
||||
var z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * x_PI);
|
||||
var theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * x_PI);
|
||||
var bd_lng = z * Math.cos(theta) + 0.0065;
|
||||
var bd_lat = z * Math.sin(theta) + 0.006;
|
||||
return [bd_lng, bd_lat]
|
||||
};
|
||||
|
||||
/**
|
||||
* WGS84转GCj02
|
||||
* @param lng
|
||||
* @param lat
|
||||
* @returns {*[]}
|
||||
*/
|
||||
var wgs84togcj02 = function wgs84togcj02(lng, lat) {
|
||||
var lat = +lat;
|
||||
var lng = +lng;
|
||||
if (out_of_china(lng, lat)) {
|
||||
return [lng, lat]
|
||||
} else {
|
||||
var dlat = transformlat(lng - 105.0, lat - 35.0);
|
||||
var dlng = transformlng(lng - 105.0, lat - 35.0);
|
||||
var radlat = lat / 180.0 * PI;
|
||||
var magic = Math.sin(radlat);
|
||||
magic = 1 - ee * magic * magic;
|
||||
var sqrtmagic = Math.sqrt(magic);
|
||||
dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * PI);
|
||||
dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * PI);
|
||||
var mglat = lat + dlat;
|
||||
var mglng = lng + dlng;
|
||||
return [mglng, mglat]
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* GCJ02 转换为 WGS84
|
||||
* @param lng
|
||||
* @param lat
|
||||
* @returns {*[]}
|
||||
*/
|
||||
var gcj02towgs84 = function gcj02towgs84(lng, lat) {
|
||||
var lat = +lat;
|
||||
var lng = +lng;
|
||||
if (out_of_china(lng, lat)) {
|
||||
return [lng, lat]
|
||||
} else {
|
||||
var dlat = transformlat(lng - 105.0, lat - 35.0);
|
||||
var dlng = transformlng(lng - 105.0, lat - 35.0);
|
||||
var radlat = lat / 180.0 * PI;
|
||||
var magic = Math.sin(radlat);
|
||||
magic = 1 - ee * magic * magic;
|
||||
var sqrtmagic = Math.sqrt(magic);
|
||||
dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * PI);
|
||||
dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * PI);
|
||||
var mglat = lat + dlat;
|
||||
var mglng = lng + dlng;
|
||||
return [lng * 2 - mglng, lat * 2 - mglat]
|
||||
}
|
||||
};
|
||||
|
||||
var transformlat = function transformlat(lng, lat) {
|
||||
var lat = +lat;
|
||||
var lng = +lng;
|
||||
var ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * Math.sqrt(Math.abs(lng));
|
||||
ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
|
||||
ret += (20.0 * Math.sin(lat * PI) + 40.0 * Math.sin(lat / 3.0 * PI)) * 2.0 / 3.0;
|
||||
ret += (160.0 * Math.sin(lat / 12.0 * PI) + 320 * Math.sin(lat * PI / 30.0)) * 2.0 / 3.0;
|
||||
return ret
|
||||
};
|
||||
|
||||
var transformlng = function transformlng(lng, lat) {
|
||||
var lat = +lat;
|
||||
var lng = +lng;
|
||||
var ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math.sqrt(Math.abs(lng));
|
||||
ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
|
||||
ret += (20.0 * Math.sin(lng * PI) + 40.0 * Math.sin(lng / 3.0 * PI)) * 2.0 / 3.0;
|
||||
ret += (150.0 * Math.sin(lng / 12.0 * PI) + 300.0 * Math.sin(lng / 30.0 * PI)) * 2.0 / 3.0;
|
||||
return ret
|
||||
};
|
||||
|
||||
/**
|
||||
* 判断是否在国内,不在国内则不做偏移
|
||||
* @param lng
|
||||
* @param lat
|
||||
* @returns {boolean}
|
||||
*/
|
||||
var out_of_china = function out_of_china(lng, lat) {
|
||||
var lat = +lat;
|
||||
var lng = +lng;
|
||||
// 纬度3.86~53.55,经度73.66~135.05
|
||||
return !(lng > 73.66 && lng < 135.05 && lat > 3.86 && lat < 53.55);
|
||||
};
|
||||
|
||||
return {
|
||||
bd09togcj02: bd09togcj02,
|
||||
gcj02tobd09: gcj02tobd09,
|
||||
wgs84togcj02: wgs84togcj02,
|
||||
gcj02towgs84: gcj02towgs84
|
||||
}
|
||||
}));
|
9597
mapserver/static/jquery.js
vendored
Normal file
9597
mapserver/static/jquery.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1179
mapserver/static/jqueryui.css
Normal file
1179
mapserver/static/jqueryui.css
Normal file
File diff suppressed because it is too large
Load Diff
15009
mapserver/static/jqueryui.js
vendored
Normal file
15009
mapserver/static/jqueryui.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
17
mapserver/static/node_modules/coordtransform/.gitattributes
generated
vendored
Normal file
17
mapserver/static/node_modules/coordtransform/.gitattributes
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
# Auto detect text files and perform LF normalization
|
||||
* text=auto
|
||||
|
||||
# Custom for Visual Studio
|
||||
*.cs diff=csharp
|
||||
|
||||
# Standard to msysgit
|
||||
*.doc diff=astextplain
|
||||
*.DOC diff=astextplain
|
||||
*.docx diff=astextplain
|
||||
*.DOCX diff=astextplain
|
||||
*.dot diff=astextplain
|
||||
*.DOT diff=astextplain
|
||||
*.pdf diff=astextplain
|
||||
*.PDF diff=astextplain
|
||||
*.rtf diff=astextplain
|
||||
*.RTF diff=astextplain
|
75
mapserver/static/node_modules/coordtransform/.npmignore
generated
vendored
Normal file
75
mapserver/static/node_modules/coordtransform/.npmignore
generated
vendored
Normal file
@ -0,0 +1,75 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directory
|
||||
# Commenting this out is preferred by some people, see
|
||||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
|
||||
node_modules
|
||||
|
||||
# Users Environment Variables
|
||||
.lock-wscript
|
||||
|
||||
# =========================
|
||||
# Operating System Files
|
||||
# =========================
|
||||
|
||||
# OSX
|
||||
# =========================
|
||||
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear on external disk
|
||||
.Spotlight-V100
|
||||
.Trashes
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
# Windows
|
||||
# =========================
|
||||
|
||||
# Windows image file caches
|
||||
Thumbs.db
|
||||
ehthumbs.db
|
||||
|
||||
# Folder config file
|
||||
Desktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
22
mapserver/static/node_modules/coordtransform/LICENSE
generated
vendored
Normal file
22
mapserver/static/node_modules/coordtransform/LICENSE
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 记忆的残骸
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
130
mapserver/static/node_modules/coordtransform/README.md
generated
vendored
Normal file
130
mapserver/static/node_modules/coordtransform/README.md
generated
vendored
Normal file
@ -0,0 +1,130 @@
|
||||
# coordtransform 坐标转换
|
||||
****
|
||||
一个提供了百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换的工具模块。
|
||||
|
||||
python版本:https://github.com/wandergis/coordTransform_py
|
||||
|
||||
命令行版本:https://github.com/wandergis/coordtransform-cli
|
||||
****
|
||||
## **支持node、浏览器(AMD方式和直接引用方式)**
|
||||
- GitHub地址:https://github.com/wandergis/coordtransform
|
||||
- npm地址:https://www.npmjs.com/package/coordtransform
|
||||
- 项目主页:http://wandergis.github.io/coordtransform/
|
||||
|
||||
## 为什么写这个模块
|
||||
|
||||
随着移动互联网的兴起,几乎每一个app都会去收集用户位置,如果恰好你在处理与地理定位相关的代码,并且不了解地理坐标系的话,肯定要被我大天朝各种坐标系搞晕。写这个模块的目的也是因为项目中app获取的坐标是百度sdk获取的,在做webgis可视化的时候各种偏,各种坐标不对,叠加错位。
|
||||
|
||||
## 当前互联网地图的坐标系现状
|
||||
### 地球坐标 (WGS84)
|
||||
- 国际标准,从 GPS 设备中取出的数据的坐标系
|
||||
- 国际地图提供商使用的坐标系
|
||||
|
||||
### 火星坐标 (GCJ-02)也叫国测局坐标系
|
||||
- 中国标准,从国行移动设备中定位获取的坐标数据使用这个坐标系
|
||||
- 国家规定: 国内出版的各种地图系统(包括电子形式),必须至少采用GCJ-02对地理位置进行首次加密。
|
||||
|
||||
###百度坐标 (BD-09)
|
||||
- 百度标准,百度 SDK,百度地图,Geocoding 使用
|
||||
- (本来就乱了,百度又在火星坐标上来个二次加密)
|
||||
|
||||
## 开发过程需要注意的事
|
||||
- 从设备获取经纬度(GPS)坐标
|
||||
|
||||
如果使用的是百度sdk那么可以获得百度坐标(bd09)或者火星坐标(GCJ02),默认是bd09
|
||||
如果使用的是ios的原生定位库,那么获得的坐标是WGS84
|
||||
如果使用的是高德sdk,那么获取的坐标是GCJ02
|
||||
- 互联网在线地图使用的坐标系
|
||||
|
||||
火星坐标系:
|
||||
iOS 地图(其实是高德)
|
||||
Google国内地图(.cn域名下)
|
||||
搜搜、阿里云、高德地图、腾讯
|
||||
百度坐标系:
|
||||
当然只有百度地图
|
||||
WGS84坐标系:
|
||||
国际标准,谷歌国外地图、osm地图等国外的地图一般都是这个
|
||||
# 举个例子
|
||||
笔者所在的公司app使用的是百度的sdk,需要对定位坐标做web可视化效果,百度地图提供的js api满足不了需求,选用leaflet来做可视化,这里要说到百度地图了,它使用的坐标系和切图的原点都不一致,并且其加偏还是非线性的,因此无法利用常用的加载方法去加载,放弃使用它的底图,选用了符合标准的高德底图,高德底图使用的是国测局坐标也就是GCJ02坐标系,如果简单的将app获取的经纬度叠加上去,就有可能你本来在百度大厦的位置就显示在西二旗地铁站了甚至更远,因此需要将bd09转成gcj02坐标系,这个时候这个库就有了用武之地,对点批量转换再加载到底图上,就可以让点显示在本应该出现的位置。
|
||||
|
||||
另外如果你拿到了一些WGS84的坐标,想加载到各种底图上就可以根据这个库在底图坐标系和你的数据坐标系之间进行转换。希望对大家有用吧。
|
||||
|
||||
****
|
||||
|
||||
|
||||
### 安装(install)
|
||||
|
||||
```
|
||||
npm install coordtransform
|
||||
```
|
||||
|
||||
|
||||
### 示例用法(Example&Usage)
|
||||
1 NodeJs用法
|
||||
|
||||
```
|
||||
//国测局坐标(火星坐标,比如高德地图在用),百度坐标,wgs84坐标(谷歌国外以及绝大部分国外在线地图使用的坐标)
|
||||
var coordtransform=require('coordtransform');
|
||||
//百度经纬度坐标转国测局坐标
|
||||
var bd09togcj02=coordtransform.bd09togcj02(116.404, 39.915);
|
||||
//国测局坐标转百度经纬度坐标
|
||||
var gcj02tobd09=coordtransform.gcj02tobd09(116.404, 39.915);
|
||||
//wgs84转国测局坐标
|
||||
var wgs84togcj02=coordtransform.wgs84togcj02(116.404, 39.915);
|
||||
//国测局坐标转wgs84坐标
|
||||
var gcj02towgs84=coordtransform.gcj02towgs84(116.404, 39.915);
|
||||
console.log(bd09togcj02);
|
||||
console.log(gcj02tobd09);
|
||||
console.log(wgs84togcj02);
|
||||
console.log(gcj02towgs84);
|
||||
//result
|
||||
//bd09togcj02: [ 116.39762729119315, 39.90865673957631 ]
|
||||
//gcj02tobd09: [ 116.41036949371029, 39.92133699351021 ]
|
||||
//wgs84togcj02: [ 116.41024449916938, 39.91640428150164 ]
|
||||
//gcj02towgs84: [ 116.39775550083061, 39.91359571849836 ]
|
||||
```
|
||||
2 浏览器用法
|
||||
直接引用目录内的index.js,会有一个coordtransform的全局对象暴露出来,也支持用AMD加载器加载
|
||||
|
||||
```
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>coordTransform</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>请按F12打开控制台查看结果</h1>
|
||||
<script src="index.js"></script>
|
||||
<script>
|
||||
//国测局坐标(火星坐标,比如高德地图在用),百度坐标,wgs84坐标(谷歌国外以及绝大部分国外在线地图使用的坐标)
|
||||
//百度经纬度坐标转国测局坐标
|
||||
var bd09togcj02 = coordtransform.bd09togcj02(116.404, 39.915);
|
||||
//国测局坐标转百度经纬度坐标
|
||||
var gcj02tobd09 = coordtransform.gcj02tobd09(116.404, 39.915);
|
||||
//wgs84转国测局坐标
|
||||
var wgs84togcj02 = coordtransform.wgs84togcj02(116.404, 39.915);
|
||||
//国测局坐标转wgs84坐标
|
||||
var gcj02towgs84 = coordtransform.gcj02towgs84(116.404, 39.915);
|
||||
console.log(bd09togcj02);
|
||||
console.log(gcj02tobd09);
|
||||
console.log(wgs84togcj02);
|
||||
console.log(gcj02towgs84);
|
||||
//result
|
||||
//bd09togcj02: [ 116.39762729119315, 39.90865673957631 ]
|
||||
//gcj02tobd09: [ 116.41036949371029, 39.92133699351021 ]
|
||||
//wgs84togcj02: [ 116.41024449916938, 39.91640428150164 ]
|
||||
//gcj02towgs84: [ 116.39775550083061, 39.91359571849836 ]
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
### todos
|
||||
- 墨卡托坐标
|
||||
- geojson转换
|
||||
- 批量转换
|
||||
- turf插件
|
||||
- leaflet插件
|
||||
|
||||
### sometipes
|
||||
对于做GIS的人来说,底图对我们还是很重要的,有时候看国外的底图很好看,换上之后发现坐标位置全部不对,因此写了这个包帮助大家完成坐标的转换,也准备写成一个leaflet的扩展,方便大家的使用,喜欢的童鞋请star,O(∩_∩)O
|
153
mapserver/static/node_modules/coordtransform/index.js
generated
vendored
Normal file
153
mapserver/static/node_modules/coordtransform/index.js
generated
vendored
Normal file
@ -0,0 +1,153 @@
|
||||
/**
|
||||
* Created by Wandergis on 2015/7/8.
|
||||
* 提供了百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换
|
||||
*/
|
||||
//UMD魔法代码
|
||||
// if the module has no dependencies, the above pattern can be simplified to
|
||||
(function (root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define([], factory);
|
||||
} else if (typeof module === 'object' && module.exports) {
|
||||
// Node. Does not work with strict CommonJS, but
|
||||
// only CommonJS-like environments that support module.exports,
|
||||
// like Node.
|
||||
module.exports = factory();
|
||||
} else {
|
||||
// Browser globals (root is window)
|
||||
root.coordtransform = factory();
|
||||
}
|
||||
}(this, function () {
|
||||
//定义一些常量
|
||||
var x_PI = 3.14159265358979324 * 3000.0 / 180.0;
|
||||
var PI = 3.1415926535897932384626;
|
||||
var a = 6378245.0;
|
||||
var ee = 0.00669342162296594323;
|
||||
/**
|
||||
* 百度坐标系 (BD-09) 与 火星坐标系 (GCJ-02)的转换
|
||||
* 即 百度 转 谷歌、高德
|
||||
* @param bd_lon
|
||||
* @param bd_lat
|
||||
* @returns {*[]}
|
||||
*/
|
||||
var bd09togcj02 = function bd09togcj02(bd_lon, bd_lat) {
|
||||
var bd_lon = +bd_lon;
|
||||
var bd_lat = +bd_lat;
|
||||
var x = bd_lon - 0.0065;
|
||||
var y = bd_lat - 0.006;
|
||||
var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_PI);
|
||||
var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_PI);
|
||||
var gg_lng = z * Math.cos(theta);
|
||||
var gg_lat = z * Math.sin(theta);
|
||||
return [gg_lng, gg_lat]
|
||||
};
|
||||
|
||||
/**
|
||||
* 火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换
|
||||
* 即谷歌、高德 转 百度
|
||||
* @param lng
|
||||
* @param lat
|
||||
* @returns {*[]}
|
||||
*/
|
||||
var gcj02tobd09 = function gcj02tobd09(lng, lat) {
|
||||
var lat = +lat;
|
||||
var lng = +lng;
|
||||
var z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * x_PI);
|
||||
var theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * x_PI);
|
||||
var bd_lng = z * Math.cos(theta) + 0.0065;
|
||||
var bd_lat = z * Math.sin(theta) + 0.006;
|
||||
return [bd_lng, bd_lat]
|
||||
};
|
||||
|
||||
/**
|
||||
* WGS84转GCj02
|
||||
* @param lng
|
||||
* @param lat
|
||||
* @returns {*[]}
|
||||
*/
|
||||
var wgs84togcj02 = function wgs84togcj02(lng, lat) {
|
||||
var lat = +lat;
|
||||
var lng = +lng;
|
||||
if (out_of_china(lng, lat)) {
|
||||
return [lng, lat]
|
||||
} else {
|
||||
var dlat = transformlat(lng - 105.0, lat - 35.0);
|
||||
var dlng = transformlng(lng - 105.0, lat - 35.0);
|
||||
var radlat = lat / 180.0 * PI;
|
||||
var magic = Math.sin(radlat);
|
||||
magic = 1 - ee * magic * magic;
|
||||
var sqrtmagic = Math.sqrt(magic);
|
||||
dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * PI);
|
||||
dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * PI);
|
||||
var mglat = lat + dlat;
|
||||
var mglng = lng + dlng;
|
||||
return [mglng, mglat]
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* GCJ02 转换为 WGS84
|
||||
* @param lng
|
||||
* @param lat
|
||||
* @returns {*[]}
|
||||
*/
|
||||
var gcj02towgs84 = function gcj02towgs84(lng, lat) {
|
||||
var lat = +lat;
|
||||
var lng = +lng;
|
||||
if (out_of_china(lng, lat)) {
|
||||
return [lng, lat]
|
||||
} else {
|
||||
var dlat = transformlat(lng - 105.0, lat - 35.0);
|
||||
var dlng = transformlng(lng - 105.0, lat - 35.0);
|
||||
var radlat = lat / 180.0 * PI;
|
||||
var magic = Math.sin(radlat);
|
||||
magic = 1 - ee * magic * magic;
|
||||
var sqrtmagic = Math.sqrt(magic);
|
||||
dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * PI);
|
||||
dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * PI);
|
||||
var mglat = lat + dlat;
|
||||
var mglng = lng + dlng;
|
||||
return [lng * 2 - mglng, lat * 2 - mglat]
|
||||
}
|
||||
};
|
||||
|
||||
var transformlat = function transformlat(lng, lat) {
|
||||
var lat = +lat;
|
||||
var lng = +lng;
|
||||
var ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * Math.sqrt(Math.abs(lng));
|
||||
ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
|
||||
ret += (20.0 * Math.sin(lat * PI) + 40.0 * Math.sin(lat / 3.0 * PI)) * 2.0 / 3.0;
|
||||
ret += (160.0 * Math.sin(lat / 12.0 * PI) + 320 * Math.sin(lat * PI / 30.0)) * 2.0 / 3.0;
|
||||
return ret
|
||||
};
|
||||
|
||||
var transformlng = function transformlng(lng, lat) {
|
||||
var lat = +lat;
|
||||
var lng = +lng;
|
||||
var ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math.sqrt(Math.abs(lng));
|
||||
ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
|
||||
ret += (20.0 * Math.sin(lng * PI) + 40.0 * Math.sin(lng / 3.0 * PI)) * 2.0 / 3.0;
|
||||
ret += (150.0 * Math.sin(lng / 12.0 * PI) + 300.0 * Math.sin(lng / 30.0 * PI)) * 2.0 / 3.0;
|
||||
return ret
|
||||
};
|
||||
|
||||
/**
|
||||
* 判断是否在国内,不在国内则不做偏移
|
||||
* @param lng
|
||||
* @param lat
|
||||
* @returns {boolean}
|
||||
*/
|
||||
var out_of_china = function out_of_china(lng, lat) {
|
||||
var lat = +lat;
|
||||
var lng = +lng;
|
||||
// 纬度3.86~53.55,经度73.66~135.05
|
||||
return !(lng > 73.66 && lng < 135.05 && lat > 3.86 && lat < 53.55);
|
||||
};
|
||||
|
||||
return {
|
||||
bd09togcj02: bd09togcj02,
|
||||
gcj02tobd09: gcj02tobd09,
|
||||
wgs84togcj02: wgs84togcj02,
|
||||
gcj02towgs84: gcj02towgs84
|
||||
}
|
||||
}));
|
54
mapserver/static/node_modules/coordtransform/package.json
generated
vendored
Normal file
54
mapserver/static/node_modules/coordtransform/package.json
generated
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
{
|
||||
"_from": "coordtransform",
|
||||
"_id": "coordtransform@2.1.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-CQNJzWKx3AX65HspG/nwt86Cf2Y=",
|
||||
"_location": "/coordtransform",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "tag",
|
||||
"registry": true,
|
||||
"raw": "coordtransform",
|
||||
"name": "coordtransform",
|
||||
"escapedName": "coordtransform",
|
||||
"rawSpec": "",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "latest"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"#USER",
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/coordtransform/-/coordtransform-2.1.2.tgz",
|
||||
"_shasum": "090349cd62b1dc05fae47b291bf9f0b7ce827f66",
|
||||
"_spec": "coordtransform",
|
||||
"_where": "/home/gym/下载/gps-sdr-sim-realtime/mapserver/static",
|
||||
"author": {
|
||||
"name": "wandergis"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/wandergis/coordtransform/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "A common coordinate systems conversion module!",
|
||||
"homepage": "http://wandergis.github.io/coordtransform",
|
||||
"keywords": [
|
||||
"coordinate",
|
||||
"wgs84",
|
||||
"bd09",
|
||||
"gcj02",
|
||||
"transform"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "coordtransform",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://wandergis@github.com/wandergis/coordtransform.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node test/app.js"
|
||||
},
|
||||
"version": "2.1.2"
|
||||
}
|
22
mapserver/static/node_modules/coordtransform/test/app.js
generated
vendored
Normal file
22
mapserver/static/node_modules/coordtransform/test/app.js
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Created by WangMing on 15/11/17.
|
||||
*/
|
||||
//国测局坐标(火星坐标,比如高德地图在用),百度坐标,wgs84坐标(谷歌国外以及绝大部分国外在线地图使用的坐标)
|
||||
var coordtransform = require('../index');
|
||||
//百度经纬度坐标转国测局坐标
|
||||
var bd09togcj02 = coordtransform.bd09togcj02(116.404, 39.915);
|
||||
//国测局坐标转百度经纬度坐标
|
||||
var gcj02tobd09 = coordtransform.gcj02tobd09(116.404, 39.915);
|
||||
//wgs84转国测局坐标
|
||||
var wgs84togcj02 = coordtransform.wgs84togcj02(116.404, 39.915);
|
||||
//国测局坐标转wgs84坐标
|
||||
var gcj02towgs84 = coordtransform.gcj02towgs84(116.404, 39.915);
|
||||
console.log(bd09togcj02);
|
||||
console.log(gcj02tobd09);
|
||||
console.log(wgs84togcj02);
|
||||
console.log(gcj02towgs84);
|
||||
//result
|
||||
//bd09togcj02: [ 116.39762729119315, 39.90865673957631 ]
|
||||
//gcj02tobd09: [ 116.41036949371029, 39.92133699351021 ]
|
||||
//wgs84togcj02: [ 116.41024449916938, 39.91640428150164 ]
|
||||
//gcj02towgs84: [ 116.39775550083061, 39.91359571849836 ]
|
31
mapserver/static/node_modules/coordtransform/test/index.html
generated
vendored
Normal file
31
mapserver/static/node_modules/coordtransform/test/index.html
generated
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>coordTransform</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>请按F12打开控制台查看结果!(Please open console by F12!)</h1>
|
||||
<script src="../index.js"></script>
|
||||
<script>
|
||||
//国测局坐标(火星坐标,比如高德地图在用),百度坐标,wgs84坐标(谷歌国外以及绝大部分国外在线地图使用的坐标)
|
||||
//百度经纬度坐标转国测局坐标
|
||||
var bd09togcj02 = coordtransform.bd09togcj02(116.404, 39.915);
|
||||
//国测局坐标转百度经纬度坐标
|
||||
var gcj02tobd09 = coordtransform.gcj02tobd09(116.404, 39.915);
|
||||
//wgs84转国测局坐标
|
||||
var wgs84togcj02 = coordtransform.wgs84togcj02(116.404, 39.915);
|
||||
//国测局坐标转wgs84坐标
|
||||
var gcj02towgs84 = coordtransform.gcj02towgs84(116.404, 39.915);
|
||||
console.log(bd09togcj02);
|
||||
console.log(gcj02tobd09);
|
||||
console.log(wgs84togcj02);
|
||||
console.log(gcj02towgs84);
|
||||
//result
|
||||
//bd09togcj02: [ 116.39762729119315, 39.90865673957631 ]
|
||||
//gcj02tobd09: [ 116.41036949371029, 39.92133699351021 ]
|
||||
//wgs84togcj02: [ 116.41024449916938, 39.91640428150164 ]
|
||||
//gcj02towgs84: [ 116.39775550083061, 39.91359571849836 ]
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
10
mapserver/static/package-lock.json
generated
Normal file
10
mapserver/static/package-lock.json
generated
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"lockfileVersion": 1,
|
||||
"dependencies": {
|
||||
"coordtransform": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/coordtransform/-/coordtransform-2.1.2.tgz",
|
||||
"integrity": "sha1-CQNJzWKx3AX65HspG/nwt86Cf2Y="
|
||||
}
|
||||
}
|
||||
}
|
3571
rtk/eil41040.17n
Normal file
3571
rtk/eil41040.17n
Normal file
File diff suppressed because it is too large
Load Diff
76
socket.c
Normal file
76
socket.c
Normal file
@ -0,0 +1,76 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <stdio.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/shm.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
|
||||
|
||||
int sockinit(short port)
|
||||
{
|
||||
int sock = socket(AF_INET,SOCK_STREAM, 0);
|
||||
struct sockaddr_in servaddr;
|
||||
memset(&servaddr, 0, sizeof(servaddr));
|
||||
servaddr.sin_family = AF_INET;
|
||||
servaddr.sin_port = htons(port);
|
||||
servaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
|
||||
if (connect(sock, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0)
|
||||
{
|
||||
perror("connect");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
return sock;
|
||||
}
|
||||
void sockclose(int s){
|
||||
close(s);
|
||||
}
|
||||
void socksend(int s,void *dataa,int siz){
|
||||
send(s,dataa,siz,0);
|
||||
}
|
||||
|
||||
long int timem(){
|
||||
struct timeval t;
|
||||
gettimeofday(&t, NULL);
|
||||
return t.tv_sec*1000+t.tv_usec/1000;
|
||||
}
|
||||
|
||||
int udpinit(short port){
|
||||
int sock = socket(AF_INET,SOCK_DGRAM, 0);
|
||||
struct sockaddr_in servaddr;
|
||||
memset(&servaddr, 0, sizeof(servaddr));
|
||||
servaddr.sin_family = AF_INET;
|
||||
servaddr.sin_port = htons(port);
|
||||
servaddr.sin_addr.s_addr = INADDR_ANY;
|
||||
if (bind(sock, (struct sockaddr *)&servaddr, sizeof(servaddr))<0){
|
||||
perror("connect");
|
||||
exit(1);
|
||||
}
|
||||
return sock;
|
||||
}
|
||||
int udprecv(int s,void *dataa,int siz){
|
||||
struct sockaddr from;
|
||||
return recvfrom(s, dataa, siz, 0,&from,0);
|
||||
}
|
||||
|
||||
double llhr[3]={39.68,139,76};
|
||||
|
||||
void threadrecv(void *p){
|
||||
short port=*(short*)p;
|
||||
int s=udpinit(port);
|
||||
printf("listening on port %d\n",port);
|
||||
while(1){
|
||||
udprecv(s,llhr,3*sizeof(double));
|
||||
//printf("%lf%lf%lf\n",llhr[0],llhr[1],llhr[2]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
206
top_block.py
Executable file
206
top_block.py
Executable file
@ -0,0 +1,206 @@
|
||||
#!/usr/bin/env python2
|
||||
# -*- coding: utf-8 -*-
|
||||
##################################################
|
||||
# GNU Radio Python Flow Graph
|
||||
# Title: Top Block
|
||||
# Generated: Fri Nov 13 09:08:57 2020
|
||||
##################################################
|
||||
|
||||
if __name__ == '__main__':
|
||||
import ctypes
|
||||
import sys
|
||||
if sys.platform.startswith('linux'):
|
||||
try:
|
||||
x11 = ctypes.cdll.LoadLibrary('libX11.so')
|
||||
x11.XInitThreads()
|
||||
except:
|
||||
print "Warning: failed to XInitThreads()"
|
||||
|
||||
from PyQt4 import Qt
|
||||
from gnuradio import eng_notation
|
||||
from gnuradio import gr
|
||||
from gnuradio import qtgui
|
||||
from gnuradio.eng_option import eng_option
|
||||
from gnuradio.filter import firdes
|
||||
from grc_gnuradio import blks2 as grc_blks2
|
||||
from optparse import OptionParser
|
||||
import osmosdr
|
||||
import sip
|
||||
import sys
|
||||
import time
|
||||
|
||||
|
||||
class top_block(gr.top_block, Qt.QWidget):
|
||||
|
||||
def __init__(self):
|
||||
gr.top_block.__init__(self, "Top Block")
|
||||
Qt.QWidget.__init__(self)
|
||||
self.setWindowTitle("Top Block")
|
||||
try:
|
||||
self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
|
||||
except:
|
||||
pass
|
||||
self.top_scroll_layout = Qt.QVBoxLayout()
|
||||
self.setLayout(self.top_scroll_layout)
|
||||
self.top_scroll = Qt.QScrollArea()
|
||||
self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
|
||||
self.top_scroll_layout.addWidget(self.top_scroll)
|
||||
self.top_scroll.setWidgetResizable(True)
|
||||
self.top_widget = Qt.QWidget()
|
||||
self.top_scroll.setWidget(self.top_widget)
|
||||
self.top_layout = Qt.QVBoxLayout(self.top_widget)
|
||||
self.top_grid_layout = Qt.QGridLayout()
|
||||
self.top_layout.addLayout(self.top_grid_layout)
|
||||
|
||||
self.settings = Qt.QSettings("GNU Radio", "top_block")
|
||||
self.restoreGeometry(self.settings.value("geometry").toByteArray())
|
||||
|
||||
##################################################
|
||||
# Variables
|
||||
##################################################
|
||||
self.samp_rate = samp_rate = 2600000
|
||||
|
||||
##################################################
|
||||
# Blocks
|
||||
##################################################
|
||||
self.qtgui_waterfall_sink_x_0 = qtgui.waterfall_sink_c(
|
||||
1024, #size
|
||||
firdes.WIN_BLACKMAN_hARRIS, #wintype
|
||||
0, #fc
|
||||
samp_rate, #bw
|
||||
"", #name
|
||||
1 #number of inputs
|
||||
)
|
||||
self.qtgui_waterfall_sink_x_0.set_update_time(0.10)
|
||||
self.qtgui_waterfall_sink_x_0.enable_grid(False)
|
||||
self.qtgui_waterfall_sink_x_0.enable_axis_labels(True)
|
||||
|
||||
if not True:
|
||||
self.qtgui_waterfall_sink_x_0.disable_legend()
|
||||
|
||||
if "complex" == "float" or "complex" == "msg_float":
|
||||
self.qtgui_waterfall_sink_x_0.set_plot_pos_half(not True)
|
||||
|
||||
labels = ['', '', '', '', '',
|
||||
'', '', '', '', '']
|
||||
colors = [0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0]
|
||||
alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
|
||||
1.0, 1.0, 1.0, 1.0, 1.0]
|
||||
for i in xrange(1):
|
||||
if len(labels[i]) == 0:
|
||||
self.qtgui_waterfall_sink_x_0.set_line_label(i, "Data {0}".format(i))
|
||||
else:
|
||||
self.qtgui_waterfall_sink_x_0.set_line_label(i, labels[i])
|
||||
self.qtgui_waterfall_sink_x_0.set_color_map(i, colors[i])
|
||||
self.qtgui_waterfall_sink_x_0.set_line_alpha(i, alphas[i])
|
||||
|
||||
self.qtgui_waterfall_sink_x_0.set_intensity_range(-140, 10)
|
||||
|
||||
self._qtgui_waterfall_sink_x_0_win = sip.wrapinstance(self.qtgui_waterfall_sink_x_0.pyqwidget(), Qt.QWidget)
|
||||
self.top_layout.addWidget(self._qtgui_waterfall_sink_x_0_win)
|
||||
self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c(
|
||||
1024, #size
|
||||
firdes.WIN_BLACKMAN_hARRIS, #wintype
|
||||
0, #fc
|
||||
samp_rate, #bw
|
||||
"", #name
|
||||
1 #number of inputs
|
||||
)
|
||||
self.qtgui_freq_sink_x_0.set_update_time(0.10)
|
||||
self.qtgui_freq_sink_x_0.set_y_axis(-30, 40)
|
||||
self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB')
|
||||
self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "")
|
||||
self.qtgui_freq_sink_x_0.enable_autoscale(False)
|
||||
self.qtgui_freq_sink_x_0.enable_grid(False)
|
||||
self.qtgui_freq_sink_x_0.set_fft_average(1.0)
|
||||
self.qtgui_freq_sink_x_0.enable_axis_labels(True)
|
||||
self.qtgui_freq_sink_x_0.enable_control_panel(False)
|
||||
|
||||
if not True:
|
||||
self.qtgui_freq_sink_x_0.disable_legend()
|
||||
|
||||
if "complex" == "float" or "complex" == "msg_float":
|
||||
self.qtgui_freq_sink_x_0.set_plot_pos_half(not True)
|
||||
|
||||
labels = ['', '', '', '', '',
|
||||
'', '', '', '', '']
|
||||
widths = [1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1]
|
||||
colors = ["blue", "red", "green", "black", "cyan",
|
||||
"magenta", "yellow", "dark red", "dark green", "dark blue"]
|
||||
alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
|
||||
1.0, 1.0, 1.0, 1.0, 1.0]
|
||||
for i in xrange(1):
|
||||
if len(labels[i]) == 0:
|
||||
self.qtgui_freq_sink_x_0.set_line_label(i, "Data {0}".format(i))
|
||||
else:
|
||||
self.qtgui_freq_sink_x_0.set_line_label(i, labels[i])
|
||||
self.qtgui_freq_sink_x_0.set_line_width(i, widths[i])
|
||||
self.qtgui_freq_sink_x_0.set_line_color(i, colors[i])
|
||||
self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i])
|
||||
|
||||
self._qtgui_freq_sink_x_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget)
|
||||
self.top_layout.addWidget(self._qtgui_freq_sink_x_0_win)
|
||||
self.osmosdr_sink_0 = osmosdr.sink( args="numchan=" + str(1) + " " + 'hackrf=81320f' )
|
||||
self.osmosdr_sink_0.set_clock_source('external', 0)
|
||||
self.osmosdr_sink_0.set_sample_rate(samp_rate)
|
||||
self.osmosdr_sink_0.set_center_freq(1575420000, 0)
|
||||
self.osmosdr_sink_0.set_freq_corr(0, 0)
|
||||
self.osmosdr_sink_0.set_gain(17, 0)
|
||||
self.osmosdr_sink_0.set_if_gain(20, 0)
|
||||
self.osmosdr_sink_0.set_bb_gain(20, 0)
|
||||
self.osmosdr_sink_0.set_antenna('RX/TX', 0)
|
||||
self.osmosdr_sink_0.set_bandwidth(2600000, 0)
|
||||
|
||||
self.blks2_tcp_source_0 = grc_blks2.tcp_source(
|
||||
itemsize=gr.sizeof_gr_complex*1,
|
||||
addr='127.0.0.1',
|
||||
port=1234,
|
||||
server=True,
|
||||
)
|
||||
(self.blks2_tcp_source_0).set_max_output_buffer(10000)
|
||||
|
||||
##################################################
|
||||
# Connections
|
||||
##################################################
|
||||
self.connect((self.blks2_tcp_source_0, 0), (self.osmosdr_sink_0, 0))
|
||||
self.connect((self.blks2_tcp_source_0, 0), (self.qtgui_freq_sink_x_0, 0))
|
||||
self.connect((self.blks2_tcp_source_0, 0), (self.qtgui_waterfall_sink_x_0, 0))
|
||||
|
||||
def closeEvent(self, event):
|
||||
self.settings = Qt.QSettings("GNU Radio", "top_block")
|
||||
self.settings.setValue("geometry", self.saveGeometry())
|
||||
event.accept()
|
||||
|
||||
def get_samp_rate(self):
|
||||
return self.samp_rate
|
||||
|
||||
def set_samp_rate(self, samp_rate):
|
||||
self.samp_rate = samp_rate
|
||||
self.qtgui_waterfall_sink_x_0.set_frequency_range(0, self.samp_rate)
|
||||
self.qtgui_freq_sink_x_0.set_frequency_range(0, self.samp_rate)
|
||||
self.osmosdr_sink_0.set_sample_rate(self.samp_rate)
|
||||
|
||||
|
||||
def main(top_block_cls=top_block, options=None):
|
||||
|
||||
from distutils.version import StrictVersion
|
||||
if StrictVersion(Qt.qVersion()) >= StrictVersion("4.5.0"):
|
||||
style = gr.prefs().get_string('qtgui', 'style', 'raster')
|
||||
Qt.QApplication.setGraphicsSystem(style)
|
||||
qapp = Qt.QApplication(sys.argv)
|
||||
|
||||
tb = top_block_cls()
|
||||
tb.start()
|
||||
tb.show()
|
||||
|
||||
def quitting():
|
||||
tb.stop()
|
||||
tb.wait()
|
||||
qapp.connect(qapp, Qt.SIGNAL("aboutToQuit()"), quitting)
|
||||
qapp.exec_()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
28807
tro11110.17n
Normal file
28807
tro11110.17n
Normal file
File diff suppressed because it is too large
Load Diff
1208
wslb1110.17n
Normal file
1208
wslb1110.17n
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user