initial commit
commit
31542d484c
|
@ -0,0 +1,28 @@
|
|||
#!/bin/bash
|
||||
i=0
|
||||
rmc=
|
||||
baud=
|
||||
#if [ -f /tmp/$1 ]; then rm /tmp/$1; fi
|
||||
while [ -z ${rmc} ]; do
|
||||
read line </dev/$1
|
||||
# line=$(head /dev/$1 -n1)
|
||||
# if [ -z ${line} ]; then rmc=3; fi
|
||||
if [ $(echo ${line}|grep \$G|wc -l) -gt 0 ]; then
|
||||
rmc=1
|
||||
baud=$(stty -F /dev/$1 speed)
|
||||
echo $(stty -F /dev/$1 speed) >/tmp/$1
|
||||
fi
|
||||
i=$(echo $i + 1|bc)
|
||||
if [ $i -gt 10 ]; then rmc=2; fi
|
||||
done
|
||||
|
||||
echo $rmc
|
||||
exit $rmc
|
||||
|
||||
#test=$(dd if=/dev/$1 bs=1 count=1000|grep RMC|wc -l)
|
||||
#if [ $test -gt 0 ]; then
|
||||
# exit 14
|
||||
#else
|
||||
# exit 0
|
||||
#fi
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
#!/bin/bash
|
||||
for i in /tmp/*.pid; do
|
||||
tp=$(cat $i)
|
||||
if [ $(ps ${tp}|grep ${tp}|wc -l) -eq 0 ]; then
|
||||
rm $i
|
||||
nohup /home/pi/gps/gps_raw.sh $(basename $i .pid) &>/dev/null &
|
||||
fi
|
||||
done
|
|
@ -0,0 +1,6 @@
|
|||
#!/bin/sh
|
||||
mysql -u gps -pgps -D gps -e "
|
||||
delete from gps_gga where sats is null or sats>15;
|
||||
delete from gps_gsv where ceil(prn)>prn or elevation is null or azimuth is null;
|
||||
delete from gps_rmc where receiver is null;
|
||||
"
|
|
@ -0,0 +1,5 @@
|
|||
#!/bin/sh
|
||||
|
||||
find /tmp -name "gps_*" -not -newermt '-120 seconds'|parallel -j3 /home/pi/gps/mysql_import.sh {}
|
||||
|
||||
#/home/pi/gps/gps_preanalyse.r
|
|
@ -0,0 +1,251 @@
|
|||
#!/usr/bin/r
|
||||
|
||||
gpsf<-list.files("/tmp","gps*")
|
||||
gpsf<-gpsf[(as.numeric(Sys.time())-unlist(lapply(paste("/tmp/",gpsf,sep=""),file.mtime)))>100]
|
||||
|
||||
txt2bl<-function(indata){
|
||||
instr<-strsplit(indata,"\\.")
|
||||
ins<-data.frame(a=unlist(lapply(1:length(instr),function(i){return(unlist(instr[[i]][1]))})),b=unlist(lapply(1:length(instr),function(i){return(unlist(instr[[i]][2]))})),stringsAsFactors=FALSE)
|
||||
# ins<-matrix(unlist(strsplit(indata,"\\.")),ncol=2,byrow=TRUE)
|
||||
if(sum(is.na(ins$a),na.rm=TRUE)>0)ins[is.na(ins$a),"a"]<-"000"
|
||||
if(sum(is.na(ins$b),na.rm=TRUE)>0)ins[is.na(ins$b),"b"]<-"000"
|
||||
if(sum(nchar(ins$a)<2,na.rm=TRUE)>0)ins[nchar(ins$a)<2,"a"]<-"000"
|
||||
if(sum(nchar(ins$b)<2,na.rm=TRUE)>0)ins[nchar(ins$b)<2,"b"]<-"000"
|
||||
if(sum(nchar(ins$b)>5,na.rm=TRUE)>0)ins[nchar(ins$b)>5,"b"]<-unlist(lapply(ins[nchar(ins$b)>5,"b"],function(i){return(substr(i,1,5))}))
|
||||
insec<-as.integer(paste(ins$b,sapply(6-nchar(ins$b),function(i){return(paste0(rep("0",i),collapse=""))}),sep=""))
|
||||
inmin<-as.integer(sapply(ins$a,function(i){return(substr(i,nchar(i)-1,nchar(i)))}))+
|
||||
60*as.integer(sapply(ins$a,function(i){return(substr(i,1,nchar(i)-2))}))
|
||||
out<-inmin*1e6+insec
|
||||
return(out)
|
||||
}
|
||||
dbCatchWriteTable<-function(db,table,indata,nfr=500){
|
||||
ncalls<-floor(nrow(indata)/nfr)
|
||||
rowi<-1:nrow(indata)
|
||||
for(i in 0:ncalls){
|
||||
win<-i*nfr+1:nfr
|
||||
win<-win[win%in%rowi]
|
||||
dbWriteTable(db,table,indata[win,],append=TRUE)
|
||||
}
|
||||
}
|
||||
|
||||
if(length(gpsf)>0){
|
||||
col_tel<-4
|
||||
rmcdf<-NULL
|
||||
ggsdf<-NULL
|
||||
gsvdf<-NULL
|
||||
gsadf<-NULL
|
||||
gstdf<-NULL
|
||||
grsdf<-NULL
|
||||
gbsdf<-NULL
|
||||
vtgdf<-NULL
|
||||
library(foreach)
|
||||
# library(RSQLite)
|
||||
library(doParallel)
|
||||
library(parallel)
|
||||
library(RMySQL)
|
||||
library(RSQLite)
|
||||
library(int64)
|
||||
cores<-max(c(1,detectCores()-1),na.rm=TRUE)
|
||||
if(is.infinite(cores))cores<-1
|
||||
registerDoParallel(cores)
|
||||
cl<-makeCluster(cores)
|
||||
|
||||
indata<-unlist(parLapply(cl,paste("/tmp/",gpsf,sep=""),readLines))
|
||||
|
||||
sid<-strsplit(indata,",")
|
||||
maxcol<-max(sapply(sid,length))
|
||||
clusterExport(cl,c("maxcol"))
|
||||
inmatrix<-as.data.frame(matrix(unlist(lapply(sid,function(i){out<-i;if(length(i)<maxcol){out<-c(i,rep(NA,maxcol-length(i)));};return(out)})),ncol=maxcol,nrow=length(sid),byrow=TRUE),stringsAsFactors=FALSE)
|
||||
inmatrix<-inmatrix[!is.na(inmatrix[,col_tel])&!is.na(inmatrix[,3]),]
|
||||
inmatrix<-inmatrix[rowSums(is.na(inmatrix))<(ncol(inmatrix)-5),]
|
||||
inmatrix<-inmatrix[(nchar(inmatrix[,col_tel])==5)&(nchar(inmatrix[,3])>1),]
|
||||
inmatrix<-inmatrix[grep("^G",inmatrix[,col_tel]),]
|
||||
inmatrix[,1]<-as.integer(inmatrix[,1])
|
||||
inmatrix[,2]<-as.int64(inmatrix[,2])
|
||||
inmatrix[,3]<-as.int64(inmatrix[,3])
|
||||
for(i in 2:3)inmatrix[,i]<-as.int64(inmatrix[,i])
|
||||
gc()
|
||||
|
||||
|
||||
inrmc<-inmatrix[grep("RMC",inmatrix[,col_tel]),]
|
||||
inrmc<-inrmc[(inrmc[,col_tel+2]=="A")&(inrmc[,col_tel+4]%in%c("N","S"))&(inrmc[,col_tel+6]%in%c("E","W")),]
|
||||
inrmc<-inrmc[!is.na(inrmc[,col_tel+1])&!is.na(inrmc[,col_tel+9]),]
|
||||
inrmc<-inrmc[(unlist(lapply(inrmc[,col_tel+3],function(i){return(length(unlist(strsplit(i,"\\."))))}))==2)&
|
||||
(unlist(lapply(inrmc[,col_tel+5],function(i){return(length(unlist(strsplit(i,"\\."))))}))==2),]
|
||||
if(nrow(inrmc)>0){
|
||||
clusterExport(cl,c("inrmc","col_tel"))
|
||||
rmcdf<-data.frame(uid=as.integer(inrmc[,1]),epoch=as.int64(inrmc[,3]),id=as.int64(inrmc[,2]),
|
||||
breite=txt2bl(inrmc[,col_tel+3]),laenge=txt2bl(inrmc[,col_tel+5]),velocity=round(as.numeric(inrmc[,col_tel+7])*1000),
|
||||
fix=as.numeric(inrmc[,col_tel+1]),system=substr(inrmc[,col_tel],2,2),
|
||||
fix_epoch=parSapply(cl,1:nrow(inrmc),function(i){
|
||||
rmct<-inrmc[i,col_tel+1]
|
||||
if(nchar(rmct)<6)rmct<-paste0(paste0(rep(0,6-nchar(rmct)),collapse=""),rmct)
|
||||
rmcd<-inrmc[i,col_tel+9]
|
||||
if(nchar(rmcd)<6)rmcd<-paste0(paste0(rep(0,6-nchar(rmcd)),collapse=""),rmcd)
|
||||
return(as.numeric(strptime(paste(rmcd,rmct,sep=""),format="%d%m%y%H%M%S",tz="GMT")))
|
||||
})
|
||||
,stringsAsFactors=FALSE)
|
||||
rmcdf<-rmcdf[(rmcdf$breite<=5400000000)&(rmcdf$laenge<=10800000000),]
|
||||
rm(inrmc)
|
||||
gc()
|
||||
}
|
||||
|
||||
ingga<-inmatrix[grep("GGA",inmatrix[,col_tel]),]
|
||||
ingga<-ingga[(ingga[,col_tel+10]=="M")&(ingga[,col_tel+3]%in%c("N","S"))&(ingga[,col_tel+5]%in%c("E","W"))&!is.na(ingga[,col_tel+1]),]
|
||||
ingga<-ingga[!is.na(ingga[,col_tel+1])&(nchar(ingga[,col_tel+1])%in%c(5,6)),]
|
||||
if(nrow(ingga)>0){
|
||||
clusterExport(cl,c("ingga","col_tel"))
|
||||
ggadf<-data.frame(uid=as.integer(ingga[,1]),epoch=as.int64(ingga[,3]),id=as.int64(ingga[,2]),
|
||||
fix=as.numeric(ingga[,col_tel+1]),breite=txt2bl(ingga[,col_tel+2]),laenge=txt2bl(ingga[,col_tel+4]),
|
||||
sats=as.numeric(ingga[,col_tel+7]),hdop=as.numeric(ingga[,col_tel+8]),hoehe=as.numeric(ingga[,col_tel+9])*1000,
|
||||
hoehe_datum=as.numeric(ingga[,col_tel+11])*1000,
|
||||
fix_epoch=parSapply(cl,1:nrow(ingga),function(i){
|
||||
# for(i in 1:nrow(ingga)){
|
||||
rmct<-ingga[i,col_tel+1]
|
||||
if(nchar(rmct)<6)rmct<-paste0(paste0(rep(0,6-nchar(rmct)),collapse=""),rmct)
|
||||
rmcd<-format(strptime(ingga[i,3],format="%s"),"%d%m%y")
|
||||
if(nchar(rmcd)<6)rmcd<-c(rep(0,6-nchar(rmcd)),rmcd)
|
||||
fixdat<-NA
|
||||
try(fixdat<-strptime(paste(rmcd,rmct,sep=""),format="%d%m%y%H%M%S",tz="GMT"))
|
||||
return(as.numeric(fixdat))
|
||||
})
|
||||
,stringsAsFactors=FALSE)
|
||||
ggadf<-ggadf[(ggadf$breite<=5400000000)&(ggadf$laenge<=10800000000),]
|
||||
rm(ingga)
|
||||
gc()
|
||||
}
|
||||
|
||||
ingsv<-inmatrix[grep("GSV",inmatrix[,col_tel]),]
|
||||
for(i in col_tel+1:3)ingsv[,i]<-as.numeric(ingsv[,i])
|
||||
ingsv<-ingsv[(nchar(ingsv[,col_tel])==5)&!is.na(ingsv[,col_tel+1])&!is.na(ingsv[,col_tel+2])&!is.na(ingsv[,col_tel+3]),]
|
||||
ingsv<-ingsv[(ingsv[,col_tel+1]<=6)&(ingsv[,col_tel+2]<=6)&(ingsv[,col_tel+3]>0),]
|
||||
ingsv<-ingsv[rowSums(!is.na(ingsv[,col_tel+4:16]))>0,]
|
||||
if(nrow(ingsv)>0){
|
||||
ingsv$system<-substr(ingsv[,col_tel],2,2)
|
||||
|
||||
gsvdf<-foreach(i=1:nrow(ingsv),.combine=rbind,.inorder=FALSE,.multicombine=TRUE,.packages=c("int64"))%dopar%{
|
||||
library(int64)
|
||||
tinv<-ingsv[i,9:ncol(ingsv)]
|
||||
tinv<-tinv[!names(tinv)%in%"system"]
|
||||
tinv<-tinv[!is.na(tinv)]
|
||||
tinv[nchar(tinv)==0]<-0
|
||||
tinv<-as.numeric(tinv)
|
||||
out<-data.frame(matrix(tinv,ncol=4,byrow=TRUE))
|
||||
names(out)<-c("PRN","elevation","azimuth","SNR")
|
||||
out$uid<-as.integer(ingsv[i,1])
|
||||
out$epoch<-as.int64(ingsv[i,2])
|
||||
out$id<-as.int64(ingsv[i,3])
|
||||
out$system<-ingsv[i,"system"]
|
||||
out$folge<-1:nrow(out)+(ingsv[i,col_tel+2]-1)*4
|
||||
return(out)}
|
||||
rm(ingsv)
|
||||
gc()
|
||||
}
|
||||
|
||||
ingsa<-inmatrix[grep("GSA",inmatrix[,col_tel]),]
|
||||
ingsa<-ingsa[!is.na(ingsa[,col_tel+13]),]
|
||||
ingsa<-ingsa[!is.na(ingsa[,col_tel]),]
|
||||
ingsa<-ingsa[!is.na(as.numeric(ingsa[,col_tel+4])),]
|
||||
if(nrow(ingsa)>0){
|
||||
gsadf<-data.frame(uid=as.numeric(ingsa[,1]),epoch=as.numeric(ingsa[,2]),id=as.numeric(ingsa[,3]),
|
||||
pdop=as.numeric(ingsa[,col_tel+15]),hdop=as.numeric(ingsa[,col_tel+16]),vdop=as.numeric(ingsa[,col_tel+17]),
|
||||
system=substr(ingsa[,5],3,3),
|
||||
sats=sapply(1:nrow(ingsa),function(i){
|
||||
tg<-ingsa[i,col_tel+3:14]
|
||||
tg<-as.numeric(tg[(nchar(tg)>0)&!is.na(tg)])
|
||||
tg<-tg[!is.na(tg)]
|
||||
tg<-sort(tg)
|
||||
return(paste(tg,collapse="_"))
|
||||
})
|
||||
,stringsAsFactors=FALSE)
|
||||
gsadf<-gsadf[nchar(gsadf$sats)>0,]
|
||||
rm(ingsa)
|
||||
gc()
|
||||
}
|
||||
|
||||
ingbs<-inmatrix[grep("GBS",inmatrix[,col_tel]),]
|
||||
if(nrow(ingbs)>0){
|
||||
gbsdf<-data.frame(uid=as.numeric(ingbs[,1]),epoch=as.numeric(ingbs[,2]),id=as.numeric(ingbs[,3]),
|
||||
system=substr(ingbs[,col_tel],3,3),lat_err=as.numeric(ingbs[,col_tel+2]),lon_err=as.numeric(ingbs[,col_tel+3]),
|
||||
alt_err=as.numeric(ingbs[,col_tel+4]),failing_prn=as.numeric(ingbs[,col_tel+5]),prob_fail=as.numeric(ingbs[,col_tel+6]),
|
||||
bias_fail=as.numeric(ingbs[,col_tel+7]),stringsAsFactors=FALSE)
|
||||
gbsdf<-gbsdf[rowSums(is.na(gbsdf),na.rm=TRUE)<4,]
|
||||
rm(ingbs)
|
||||
gc()
|
||||
}
|
||||
|
||||
ingrs<-inmatrix[grep("GRS",inmatrix[,col_tel]),]
|
||||
if(nrow(ingrs)>0){
|
||||
grsdf<-data.frame(receiver=ingrs[,1],uid=as.numeric(ingrs[,2]),epoch=as.numeric(ingrs[,3]),id=as.numeric(ingrs[,4]),
|
||||
system=substr(ingrs[,col_tel],2,2),fix=as.numeric(ingrs[,col_tel+2]),fgga=as.numeric(ingrs[,col_tel+1]),stringsAsFactors=FALSE)
|
||||
for(ig in 1:12)grsdf[,paste("S",ig,sep="")]<-as.numeric(ingrs[,7+ig])
|
||||
grsdf<-grsdf[rowSums(is.na(grsdf),na.rm=TRUE)<10,]
|
||||
rm(ingrs)
|
||||
gc()
|
||||
}
|
||||
|
||||
ingst<-inmatrix[grep("GST",inmatrix[,col_tel]),]
|
||||
if(nrow(ingst)>0){
|
||||
gstdf<-data.frame(receiver=ingst[,1],uid=as.numeric(ingst[,2]),epoch=as.numeric(ingst[,3]),id=as.numeric(ingst[,4]),
|
||||
system=substr(ingst[,col_tel],3,3),
|
||||
RMS=as.numeric(ingst[,col_tel+2]),lat_sigma=as.numeric(ingst[,col_tel+6]),lon_sigma=as.numeric(ingst[,col_tel+7]),
|
||||
height_sigma=as.numeric(ingst[,col_tel+8])
|
||||
,stringsAsFactors=FALSE)
|
||||
gstdf<-gstdf[!is.na(gstdf$RMS),]
|
||||
rm(ingst)
|
||||
gc()
|
||||
}
|
||||
invtg<-inmatrix[grep("VTG",inmatrix[,col_tel]),]
|
||||
if(nrow(invtg)>0){
|
||||
vtgdf<-data.frame(receiver=invtg[,1],uid=as.numeric(invtg[,2]),epoch=as.numeric(invtg[,3]),id=as.numeric(invtg[,4]),
|
||||
system=substr(invtg[,col_tel],2,2),
|
||||
course_true=as.numeric(invtg[,col_tel+1]),course_mag=as.numeric(invtg[,col_tel+3]),speed_kn=as.numeric(invtg[,col_tel+5]),
|
||||
speed_kmh=as.numeric(invtg[,col_tel+7])
|
||||
,stringsAsFactors=FALSE)
|
||||
rm(invtg)
|
||||
gc()
|
||||
}
|
||||
|
||||
# con = dbConnect(MySQL(), user='gps', password='gps', dbname='gps', host='localhost')
|
||||
con <- dbConnect(RSQLite::SQLite(), ":memory:")
|
||||
if(!is.null(rmcdf)){
|
||||
names(rmcdf)<-toupper(names(rmcdf))
|
||||
dbCatchWriteTable(con,"gps_rmc",rmcdf)
|
||||
}
|
||||
if(!is.null(ggadf)){
|
||||
names(ggadf)<-toupper(names(ggadf))
|
||||
dbCatchWriteTable(con,"gps_gga",ggadf)
|
||||
}
|
||||
if(!is.null(gbsdf)){
|
||||
names(gbsdf)<-toupper(names(gbsdf))
|
||||
dbCatchWriteTable(con,"gps_gbs",gbsdf)
|
||||
}
|
||||
if(!is.null(gsvdf)){
|
||||
names(gsvdf)<-toupper(names(gsvdf))
|
||||
dbCatchWriteTable(con,"gps_gsv",gsvdf)
|
||||
}
|
||||
if(!is.null(gsadf)){
|
||||
names(gsadf)<-toupper(names(gsadf))
|
||||
dbCatchWriteTable(con,"gps_gsa",gsadf)
|
||||
}
|
||||
if(!is.null(gstdf)){
|
||||
names(gstdf)<-toupper(names(gstdf))
|
||||
dbCatchWriteTable(con,"gps_gst",gstdf)
|
||||
}
|
||||
if(!is.null(grsdf)){
|
||||
names(grsdf)<-toupper(names(grsdf))
|
||||
dbCatchWriteTable(con,"gps_grs",grsdf)
|
||||
}
|
||||
if(!is.null(vtgdf)){
|
||||
names(vtgdf)<-toupper(names(vtgdf))
|
||||
dbCatchWriteTable(con,"gps_vtg",vtgdf)
|
||||
}
|
||||
dbDisconnect(con)
|
||||
|
||||
for(j in 0:floor(length(gpsf)/1000)){
|
||||
rgpsf<-gpsf[1:1000+j*1000]
|
||||
rgpsf<-rgpsf[!is.na(rgpsf)]
|
||||
system2("sudo",paste("rm ",paste("/tmp/",rgpsf,sep="",collapse=" "),sep=" ",collapse=" "))
|
||||
}
|
||||
# for(i in gpsf)system2("sudo",paste("rm /tmp/",i,sep=""))
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
library(foreach)
|
||||
library(RSQLite)
|
||||
library(doParallel)
|
||||
library(parallel)
|
||||
con <- dbConnect(RSQLite::SQLite(), "/home/pi/gps.sqlite",flags=SQLITE_RO)
|
||||
dbDisconnect(con)
|
|
@ -0,0 +1,5 @@
|
|||
#!/bin/sh
|
||||
|
||||
for i in /tmp/gps*; do
|
||||
nohup /home/pi/gps_raw.sh &
|
||||
done
|
|
@ -0,0 +1,27 @@
|
|||
#!/bin/bash
|
||||
#sleep 120
|
||||
sqlite_com="sqlite3 /home/pi/gps.sqlite"
|
||||
mysql_com="mysql -u gps -pgps -D gps -e"
|
||||
dbe=$(sqlite3 /home/pi/gps.sqlite "select max(epoch) from GPS_TTY;")
|
||||
if [ -z "$dbe" ]; then
|
||||
echo Anlegen TTY-Tabelle
|
||||
${sqlite_com} "create table GPS_TTY (uid integer,tty text,utc bigint,idvendor text,idmodel text,baud integer,path text);"
|
||||
fi
|
||||
if [ $(mysql -u gps -pgps -D gps -e "select * from information_schema.tables where table_schema='gps' and table_name='GPS_TTY';"|wc -l) -eq 0 ]; then
|
||||
${mysql_com} "create table gps.gpstty (uid smallint unsigned,tty text,utc bigint unsigned,idvendor text,idmodel text,baud mediumint unsigned,path text);"
|
||||
fi
|
||||
|
||||
for i in /dev/ttyACM*; do
|
||||
if [ $(udevadm info -a -q property --export -n $i|grep GNSS|wc -l) -gt 1 ]; then
|
||||
TTY=$(echo $i|cut -d/ -f3)
|
||||
uid=$(echo $(udevadm info --name=${i}|sed -n '/MAJOR/{s/[A-Z: =]*//;p}')*256+$(udevadm info --name=/dev/${TTY}|sed -n '/MINOR/{s/[A-Z: =]*//;p}')|bc)
|
||||
idp=$(udevadm info -a -q property --export -n $i|grep ID_MODEL_ID|cut -d= -f2|sed -e "s/'//g")
|
||||
idv=$(udevadm info -a -q property --export -n $i|grep ID_VENDOR_ID|cut -d= -f2|sed -e "s/'//g")
|
||||
idpath=$(udevadm info -a -q property --export -n $i|grep ID_PATH=|cut -d= -f2|sed -e "s/'//g")
|
||||
echo $(date +%s),${TTY},${idp},${idv},$i
|
||||
${sqlite_com} "insert into GPS_TTY (uid,tty,utc,idvendor,idmodel,baud,path) values (${uid},'${TTY}',$(date +%s),'${idp}','${idv}',$(stty -F ${i} speed),'${idpath}');"
|
||||
${mysql_com} "insert into gpstty (uid,tty,utc,idvendor,idmodel,baud,path) values (${uid},'${TTY}',$(date +%s),'${idp}','${idv}',$(stty -F ${i} speed),'${idpath}');"
|
||||
nohup /home/pi/gps/gps_raw5.sh ${TTY} &>/dev/null &
|
||||
fi
|
||||
done
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
#!/bin/bash
|
||||
echo $1 >>/home/pi/gps.log
|
||||
date +%s >>/home/pi/gps.log
|
||||
dbe=$(sqlite3 /home/pi/gps.sqlite "select max(epoch) from GPS_TTY;")
|
||||
if [ -z "$dbe" ]; then
|
||||
echo Anlegen TTY-Tabelle
|
||||
sqlite3 /home/pi/gps.sqlite "create table GPS_TTY (EPOCH REAL,TTY TEXT,IDPRODUCT TEXT,IDVENDOR TEST,BUS TEXT);"
|
||||
fi
|
||||
uda=$(udevadm info -a /dev/$1)
|
||||
echo $1
|
||||
if [ $(echo $uda|grep GNSS|wc -l) -gt 0 ]; then
|
||||
idp=$(echo $uda|grep idProduct|head -n1|cut -d= -f3|sed -e 's/"//g')
|
||||
idv=$(echo $uda|grep idVendor|head -n1|cut -d= -f3|sed -e 's/"//g')
|
||||
echo $(date +%s),${TTY},${idp},${idv},$i
|
||||
sqlite3 /home/pi/gps.sqlite "insert into GPS_TTY (EPOCH,TTY,IDPRODUCT,IDVENDOR,BUS) values ($(date +%s),'${TTY}','${idp}','${idv}','$i');"
|
||||
nohup /home/pi/gps/gps_raw3.sh $1 &
|
||||
fi
|
||||
|
||||
echo $1,$(date +%s) >>/home/pi/gps.log
|
|
@ -0,0 +1,15 @@
|
|||
#!/bin/bash
|
||||
dbe=$(sqlite3 /home/pi/gps.sqlite "select max(epoch) from GPS_TTY;")
|
||||
if [ -z "$dbe" ]; then
|
||||
echo Anlegen TTY-Tabelle
|
||||
sqlite3 /home/pi/gps.sqlite "create table GPS_TTY (EPOCH REAL,TTY TEXT,IDPRODUCT TEXT,IDVENDOR TEST,BUS TEXT);"
|
||||
fi
|
||||
sudo hcitool cc 00:0B:0D:88:95:E9
|
||||
sudo rfcomm bind /dev/rcomm0 00:0B:0D:88:95:E9
|
||||
echo $1
|
||||
idp=$(udevadm info -a /dev/rfcomm0|grep idProduct|head -n1|cut -d= -f3|sed -e 's/"//g')
|
||||
idv=$(udevadm info -a /dev/rfcomm0|grep idVendor|head -n1|cut -d= -f3|sed -e 's/"//g')
|
||||
echo $(date +%s),${TTY},${idp},${idv},$i
|
||||
sqlite3 /home/pi/gps.sqlite "insert into GPS_TTY (EPOCH,TTY,IDPRODUCT,IDVENDOR,BUS) values ($(date +%s),'${TTY}','${idp}','${idv}','$i');"
|
||||
nohup /home/pi/gps_raw2.sh rfcomm0 &
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
#!/bin/bash
|
||||
sqlite_com="sqlite3 /home/pi/gps.sqlite"
|
||||
mysql_com="mysql -u gps -pgps -D gps -e"
|
||||
TTY=$1
|
||||
rm /tmp/$1
|
||||
baud=16384
|
||||
for i in 4800 9600 19200 38400 57600 115200
|
||||
do
|
||||
echo $i
|
||||
stty $i -F /dev/${TTY}
|
||||
# tds=$(timeout 10s $(test=$(dd if=/dev/$1 bs=1 count=10000|grep RMC|wc -l);if [ $test -gt 0 ]; then exit 1; else exit 0; fi))
|
||||
timeout 10s /home/pi/gps/check_baud.sh ${TTY}
|
||||
# echo $?
|
||||
if [ $? -eq "1" ]; then
|
||||
echo Test
|
||||
baud=$i
|
||||
fi
|
||||
done
|
||||
#if [ -f /tmp/$1 ]; then
|
||||
# baud=$(cat /tmp/$1)
|
||||
#fi
|
||||
|
||||
#exit 1
|
||||
echo $baud
|
||||
#exit 1
|
||||
|
||||
if [ $baud -ne 16384 ]; then
|
||||
echo ${TTY}
|
||||
echo $baud
|
||||
stty $baud -F /dev/${TTY}
|
||||
dbe=$(sqlite3 /home/pi/gps.sqlite "select max(utc) from GPS_TTY;")
|
||||
if [ -z "$dbe" ]; then
|
||||
echo Anlegen TTY-Tabelle
|
||||
sqlite3 /home/pi/gps.sqlite "create table GPS_TTY (uid integer,tty text,utc integer,idvendor text,idmodel text,baud integer);"
|
||||
fi
|
||||
# TTY=$(echo $i|cut -d/ -f3)
|
||||
uid=$(echo $(udevadm info --name=/dev/${TTY}|sed -n '/MAJOR/{s/[A-Z: =]*//;p}')*256+$(udevadm info --name=/dev/${TTY}|sed -n '/MINOR/{s/[A-Z: =]*//;p}')|bc)
|
||||
idp=$(udevadm info -a -q property --export -n /dev/${TTY}|grep ID_MODEL_ID|cut -d= -f2|sed -e "s/'//g")
|
||||
idv=$(udevadm info -a -q property --export -n /dev/${TTY}|grep ID_VENDOR_ID|cut -d= -f2|sed -e "s/'//g")
|
||||
idpath=$(udevadm info -a -q property --export -n ${TTY}|grep ID_PATH=|cut -d= -f2|sed -e "s/'//g")
|
||||
echo $(date +%s),${TTY},${idp},${idv},$i
|
||||
${sqlite_com} "insert into GPS_TTY (uid,tty,utc,idvendor,idmodel,baud,path) values (${uid},'${TTY}',$(date +%s),'${idp}','${idv}',$(stty -F /dev/${TTY} speed),'${idpath}');"
|
||||
${mysql_com} "insert into gpstty (uid,tty,utc,idvendor,idmodel,baud,path) values (${uid},'${TTY}',$(date +%s),'${idp}','${idv}',$(stty -F /dev/${TTY} speed),'${idpath}');"
|
||||
nohup /home/pi/gps/gps_raw5.sh ${TTY} &
|
||||
fi
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/gawk -f
|
||||
BEGIN {FS =","
|
||||
OFS=","}
|
||||
/RMC/ {east=$9+0;gsub(/ \$/,"",$4);gsub(/^0/,"",$11);print $1,$2,$3,$4,int($5),$13,$7,east,$8,$10,$11,$12}
|
||||
/GGA/ {gsub(/ \$/,"",$4);gsub(/^0/,"",$11);gsub(/^0/,"",$8);print $1,$2,$3,$4,int($5),$6,$8,$7,$9,$11,$12,$13,$15}
|
||||
/GSA/ {gsub(/ \$/,"",$4);print $1,$2,$3,$4,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21}
|
||||
/GSV/ {gsub(/ \$/,"",$4);$5="";$6="";print $0}
|
||||
/GST/ {gsub(/ \$/,"",$4);print $0}
|
|
@ -0,0 +1,292 @@
|
|||
#!/usr/bin/r
|
||||
library(foreach)
|
||||
#library(RSQLite)
|
||||
library(doParallel)
|
||||
library(parallel)
|
||||
library(RMySQL)
|
||||
library(int64)
|
||||
source("lib_gps.r")
|
||||
cores<-max(c(1,detectCores()-1),na.rm=TRUE)
|
||||
if(is.infinite(cores))cores<-1
|
||||
registerDoParallel(cores)
|
||||
cl<-makeCluster(cores)
|
||||
|
||||
con = dbConnect(MySQL(), user='gps', password='gps', dbname='gps', host='localhost')
|
||||
|
||||
dbSendStatement(con,"update gpsin set raw=1;")
|
||||
|
||||
rmcin<-dbGetQuery(con,"select uid,cast(id as char) as id,cast(epoch as char) as epoch,telegram,payload from gpsin where telegram like '%RMC' and raw=1;")
|
||||
if(nrow(rmcin)>0){
|
||||
rmcin$id<-as.int64(rmcin$id)
|
||||
rmcin$epoch<-as.int64(rmcin$epoch)
|
||||
|
||||
sid<-strsplit(rmcin$payload,",")
|
||||
maxcol<-max(sapply(sid,length))
|
||||
clusterExport(cl,c("maxcol"))
|
||||
inrmc<-as.data.frame(matrix(unlist(lapply(sid,function(i){out<-i;if(length(i)<maxcol){out<-c(i,rep(NA,maxcol-length(i)));};return(out)})),ncol=maxcol,nrow=length(sid),byrow=TRUE),stringsAsFactors=FALSE)
|
||||
inrmc$id<-rmcin$id
|
||||
inrmc$uid<-rmcin$uid
|
||||
inrmc$epoch<-rmcin$epoch
|
||||
inrmc$telegram<-rmcin$telegram
|
||||
inrmc<-inrmc[!is.na(inrmc[,9])&!is.na(inrmc[,1]),]
|
||||
clusterExport(cl,c("inrmc"))
|
||||
rmcdf<-data.frame(uid=inrmc$uid,epoch=inrmc$epoch,id=inrmc$id,
|
||||
breite=txt2bl(inrmc[,3]),laenge=txt2bl(inrmc[,5]),velocity=round(as.numeric(inrmc[,7])*1000),
|
||||
fix=as.numeric(inrmc[,1]),system=substr(inrmc$telegram,2,2),
|
||||
fix_epoch=parSapply(cl,1:nrow(inrmc),function(i){
|
||||
rmct<-inrmc[i,1]
|
||||
if(nchar(rmct)<6)rmct<-paste0(paste0(rep(0,6-nchar(rmct)),collapse=""),rmct)
|
||||
rmcd<-inrmc[i,9]
|
||||
if(nchar(rmcd)<6)rmcd<-paste0(paste0(rep(0,6-nchar(rmcd)),collapse=""),rmcd)
|
||||
return(as.numeric(strptime(paste(rmcd,rmct,sep=""),format="%d%m%y%H%M%S",tz="GMT")))
|
||||
})
|
||||
,stringsAsFactors=FALSE)
|
||||
rmcdf<-rmcdf[(rmcdf$breite<=5400000000)&(rmcdf$laenge<=10800000000),]
|
||||
dbCatchWriteTable(con,"gpsrmc",rmcdf,nfr=1000)
|
||||
rm(rmcdf,inrmc,rmcin)
|
||||
gc()
|
||||
}
|
||||
rmcin<-dbGetQuery(con,"select uid,cast(id as char) as id,cast(epoch as char) as epoch,telegram,payload from gpsin where telegram like '%GGA' and raw=1;")
|
||||
if(nrow(rmcin)>0){
|
||||
rmcin$id<-as.int64(rmcin$id)
|
||||
rmcin$epoch<-as.int64(rmcin$epoch)
|
||||
|
||||
sid<-strsplit(rmcin$payload,",")
|
||||
maxcol<-max(sapply(sid,length))
|
||||
clusterExport(cl,c("maxcol"))
|
||||
inrmc<-as.data.frame(matrix(unlist(lapply(sid,function(i){out<-i;if(length(i)<maxcol){out<-c(i,rep(NA,maxcol-length(i)));};return(out)})),ncol=maxcol,nrow=length(sid),byrow=TRUE),stringsAsFactors=FALSE)
|
||||
inrmc$id<-rmcin$id
|
||||
inrmc$uid<-rmcin$uid
|
||||
inrmc$epoch<-rmcin$epoch
|
||||
inrmc$telegram<-rmcin$telegram
|
||||
|
||||
inrmc<-inrmc[(inrmc[,10]=="M")&(inrmc[,3]%in%c("N","S"))&(inrmc[,5]%in%c("E","W"))&!is.na(inrmc[,1])&!is.na(inrmc[,6]),]
|
||||
if(nrow(inrmc)>0){
|
||||
clusterExport(cl,c("inrmc"))
|
||||
ggadf<-data.frame(uid=inrmc$uid,epoch=inrmc$epoch,id=inrmc$id,
|
||||
fix=as.numeric(inrmc[,1]),breite=txt2bl(inrmc[,2]),laenge=txt2bl(inrmc[,4]),
|
||||
sats=as.numeric(inrmc[,7]),hdop=as.numeric(inrmc[,8]),hoehe=as.numeric(inrmc[,9])*1000,
|
||||
hoehe_datum=as.numeric(inrmc[,11])*1000,
|
||||
fix_epoch=parSapply(cl,1:nrow(inrmc),function(i){
|
||||
rmct<-inrmc[i,1]
|
||||
if(nchar(rmct)<6)rmct<-paste0(paste0(rep(0,6-nchar(rmct)),collapse=""),rmct)
|
||||
rmcd<-format(strptime(inrmc[i,"epoch"],format="%s"),"%d%m%y")
|
||||
if(nchar(rmcd)<6)rmcd<-c(rep(0,6-nchar(rmcd)),rmcd)
|
||||
fixdat<-NA
|
||||
try(fixdat<-strptime(paste(rmcd,rmct,sep=""),format="%d%m%y%H%M%S",tz="GMT"))
|
||||
return(as.numeric(fixdat))
|
||||
})
|
||||
,stringsAsFactors=FALSE)
|
||||
ggadf<-ggadf[(ggadf$breite<=5400000000)&(ggadf$laenge<=10800000000),]
|
||||
dbCatchWriteTable(con,"gpsgga",ggadf,nfr=1000)
|
||||
|
||||
rm(inrmc,ggadf,rmcin)
|
||||
gc()
|
||||
}
|
||||
}
|
||||
|
||||
rmcin<-dbGetQuery(con,"select uid,cast(id as char) as id,cast(epoch as char) as epoch,telegram,payload from gpsin where telegram like '%GSV' and raw=1;")
|
||||
if(nrow(rmcin)>0){
|
||||
# rmcin$id<-as.int64(rmcin$id)
|
||||
# rmcin$epoch<-as.int64(rmcin$epoch)
|
||||
|
||||
sid<-strsplit(rmcin$payload,",")
|
||||
maxcol<-max(sapply(sid,length))
|
||||
clusterExport(cl,c("maxcol"))
|
||||
inrmc<-as.data.frame(matrix(unlist(lapply(sid,function(i){out<-i;if(length(i)<maxcol){out<-c(i,rep(NA,maxcol-length(i)));};return(out)})),ncol=maxcol,nrow=length(sid),byrow=TRUE),stringsAsFactors=FALSE)
|
||||
inrmc$id<-rmcin$id
|
||||
inrmc$uid<-rmcin$uid
|
||||
inrmc$epoch<-rmcin$epoch
|
||||
inrmc$telegram<-rmcin$telegram
|
||||
|
||||
col_tel<-0
|
||||
for(i in col_tel+1:3)inrmc[,i]<-as.numeric(inrmc[,i])
|
||||
inrmc<-inrmc[!is.na(inrmc[,col_tel+1])&!is.na(inrmc[,col_tel+2])&!is.na(inrmc[,col_tel+3]),]
|
||||
inrmc<-inrmc[(inrmc[,col_tel+1]<=6)&(inrmc[,col_tel+2]<=6)&(inrmc[,col_tel+3]>0),]
|
||||
inrmc<-inrmc[rowSums(!is.na(inrmc[,col_tel+4:16]))>0,]
|
||||
if(nrow(inrmc)>0){
|
||||
inrmc$system<-substr(inrmc$telegram,2,2)
|
||||
|
||||
gsvdf<-foreach(i=0:3,.combine=rbind,.inorder=FALSE,.multicombine=TRUE)%dopar%{
|
||||
out<-inrmc[,i*4+0:3+4]
|
||||
names(out)<-c("prn","elevation","azimuth","snr")
|
||||
out<-cbind(out,inrmc[,c("uid","id","epoch","telegram","system")])
|
||||
out$folge<-i+1
|
||||
out$row<-inrmc[,2]-1
|
||||
return(out)
|
||||
}
|
||||
gsvdf<-gsvdf[!is.na(gsvdf$prn),]
|
||||
gsvdf$folge<-gsvdf$folge+gsvdf$row*4
|
||||
gsvdf$id<-as.int64(gsvdf$id)
|
||||
gsvdf$epoch<-as.int64(gsvdf$epoch)
|
||||
gsvdf<-gsvdf[,c("uid","id","epoch","system","folge","prn","elevation","azimuth","snr")]
|
||||
dbCatchWriteTable(con,"gpsgsv",gsvdf,nfr=1000)
|
||||
|
||||
rm(inrmc,rmcin,gsvdf)
|
||||
gc()
|
||||
}
|
||||
}
|
||||
|
||||
rmcin<-dbGetQuery(con,"select uid,cast(id as char) as id,cast(epoch as char) as epoch,telegram,payload from gpsin where telegram like '%GSA' and raw=1;")
|
||||
if(nrow(rmcin)>0){
|
||||
rmcin$id<-as.int64(rmcin$id)
|
||||
rmcin$epoch<-as.int64(rmcin$epoch)
|
||||
|
||||
sid<-strsplit(rmcin$payload,",")
|
||||
maxcol<-max(sapply(sid,length))
|
||||
clusterExport(cl,c("maxcol"))
|
||||
inrmc<-as.data.frame(matrix(unlist(lapply(sid,function(i){out<-i;if(length(i)<maxcol){out<-c(i,rep(NA,maxcol-length(i)));};return(out)})),ncol=maxcol,nrow=length(sid),byrow=TRUE),stringsAsFactors=FALSE)
|
||||
inrmc$id<-rmcin$id
|
||||
inrmc$uid<-rmcin$uid
|
||||
inrmc$epoch<-rmcin$epoch
|
||||
inrmc$telegram<-rmcin$telegram
|
||||
|
||||
col_tel<-0
|
||||
if(nrow(inrmc)>0){
|
||||
gsadf<-data.frame(uid=inrmc$uid,epoch=inrmc$epoch,id=inrmc$id,
|
||||
pdop=as.numeric(inrmc[,col_tel+15]),hdop=as.numeric(inrmc[,col_tel+16]),vdop=as.numeric(inrmc[,col_tel+17]),
|
||||
system=substr(inrmc$telegram,2,2),
|
||||
sats=sapply(1:nrow(inrmc),function(i){
|
||||
tg<-inrmc[i,col_tel+3:14]
|
||||
tg<-as.numeric(tg[(nchar(tg)>0)&!is.na(tg)])
|
||||
tg<-tg[!is.na(tg)]
|
||||
tg<-sort(tg)
|
||||
return(paste(tg,collapse="_"))
|
||||
})
|
||||
,stringsAsFactors=FALSE)
|
||||
gsadf<-gsadf[nchar(gsadf$sats)>0,]
|
||||
dbCatchWriteTable(con,"gpsgsa",gsadf)
|
||||
|
||||
rm(inrmc,rmcin,gsadf)
|
||||
gc()
|
||||
}
|
||||
}
|
||||
|
||||
rmcin<-dbGetQuery(con,"select uid,cast(id as char) as id,cast(epoch as char) as epoch,telegram,payload from gpsin where telegram like '%GBS' and raw=1;")
|
||||
if(nrow(rmcin)>0){
|
||||
rmcin$id<-as.int64(rmcin$id)
|
||||
rmcin$epoch<-as.int64(rmcin$epoch)
|
||||
|
||||
sid<-strsplit(rmcin$payload,",")
|
||||
maxcol<-max(sapply(sid,length))
|
||||
clusterExport(cl,c("maxcol"))
|
||||
inrmc<-as.data.frame(matrix(unlist(lapply(sid,function(i){out<-i;if(length(i)<maxcol){out<-c(i,rep(NA,maxcol-length(i)));};return(out)})),ncol=maxcol,nrow=length(sid),byrow=TRUE),stringsAsFactors=FALSE)
|
||||
inrmc$id<-rmcin$id
|
||||
inrmc$uid<-rmcin$uid
|
||||
inrmc$epoch<-rmcin$epoch
|
||||
inrmc$telegram<-rmcin$telegram
|
||||
col_tel<-0
|
||||
gbsdf<-data.frame(uid=inrmc$uid,epoch=inrmc$epoch,id=inrmc$id,
|
||||
system=substr(inrmc$telegram,2,2),lat_err=as.numeric(inrmc[,col_tel+2]),lon_err=as.numeric(inrmc[,col_tel+3]),
|
||||
alt_err=as.numeric(inrmc[,col_tel+4]),stringsAsFactors=FALSE)
|
||||
gbsdf<-gbsdf[rowSums(is.na(gbsdf),na.rm=TRUE)<4,]
|
||||
dbCatchWriteTable(con,"gpsgbs",gbsdf)
|
||||
|
||||
rm(gbsdf,inrmc,rmcin)
|
||||
gc()
|
||||
}
|
||||
|
||||
rmcin<-dbGetQuery(con,"select uid,cast(id as char) as id,cast(epoch as char) as epoch,telegram,payload from gpsin where telegram like '%GRS' and raw=1;")
|
||||
if(nrow(rmcin)>0){
|
||||
rmcin$id<-as.int64(rmcin$id)
|
||||
rmcin$epoch<-as.int64(rmcin$epoch)
|
||||
|
||||
sid<-strsplit(rmcin$payload,",")
|
||||
maxcol<-max(sapply(sid,length))
|
||||
clusterExport(cl,c("maxcol"))
|
||||
inrmc<-as.data.frame(matrix(unlist(lapply(sid,function(i){out<-i;if(length(i)<maxcol){out<-c(i,rep(NA,maxcol-length(i)));};return(out)})),ncol=maxcol,nrow=length(sid),byrow=TRUE),stringsAsFactors=FALSE)
|
||||
inrmc$id<-rmcin$id
|
||||
inrmc$uid<-rmcin$uid
|
||||
inrmc$epoch<-rmcin$epoch
|
||||
inrmc$telegram<-rmcin$telegram
|
||||
col_tel<-0
|
||||
if(nrow(inrmc)>0){
|
||||
grsdf<-data.frame(uid=inrmc$uid,epoch=inrmc$epoch,id=inrmc$id,
|
||||
system=substr(inrmc$telegram,2,2),fix=as.numeric(inrmc[,col_tel+2]),fgga=as.numeric(inrmc[,col_tel+1]),stringsAsFactors=FALSE)
|
||||
for(ig in 1:12)grsdf[,paste("S",ig,sep="")]<-as.numeric(inrmc[,2+ig])
|
||||
grsdf<-grsdf[rowSums(is.na(grsdf),na.rm=TRUE)<10,]
|
||||
dbCatchWriteTable(con,"gpsgrs",grsdf)
|
||||
|
||||
rm(grsdf,inrmc,rmcin)
|
||||
gc()
|
||||
}
|
||||
}
|
||||
|
||||
rmcin<-dbGetQuery(con,"select uid,cast(id as char) as id,cast(epoch as char) as epoch,telegram,payload from gpsin where telegram like '%GST' and raw=1;")
|
||||
if(nrow(rmcin)>0){
|
||||
rmcin$id<-as.int64(rmcin$id)
|
||||
rmcin$epoch<-as.int64(rmcin$epoch)
|
||||
|
||||
sid<-strsplit(rmcin$payload,",")
|
||||
maxcol<-max(sapply(sid,length))
|
||||
clusterExport(cl,c("maxcol"))
|
||||
inrmc<-as.data.frame(matrix(unlist(lapply(sid,function(i){out<-i;if(length(i)<maxcol){out<-c(i,rep(NA,maxcol-length(i)));};return(out)})),ncol=maxcol,nrow=length(sid),byrow=TRUE),stringsAsFactors=FALSE)
|
||||
inrmc$id<-rmcin$id
|
||||
inrmc$uid<-rmcin$uid
|
||||
inrmc$epoch<-rmcin$epoch
|
||||
inrmc$telegram<-rmcin$telegram
|
||||
col_tel<-0
|
||||
gstdf<-data.frame(uid=inrmc$uid,epoch=inrmc$epoch,id=inrmc$id,
|
||||
system=substr(inrmc$telegram,2,2),
|
||||
rms=as.numeric(inrmc[,col_tel+2]),lat_sigma=as.numeric(inrmc[,col_tel+6]),lon_sigma=as.numeric(inrmc[,col_tel+7]),
|
||||
height_sigma=as.numeric(inrmc[,col_tel+8])
|
||||
,stringsAsFactors=FALSE)
|
||||
gstdf<-gstdf[!is.na(gstdf$rms),]
|
||||
dbCatchWriteTable(con,"gpsgst",gstdf)
|
||||
|
||||
rm(gstdf,inrmc,rmcin)
|
||||
gc()
|
||||
}
|
||||
|
||||
rmcin<-dbGetQuery(con,"select uid,cast(id as char) as id,cast(epoch as char) as epoch,telegram,payload from gpsin where telegram like '%VTG' and raw=1;")
|
||||
if(nrow(rmcin)>0){
|
||||
rmcin$id<-as.int64(rmcin$id)
|
||||
rmcin$epoch<-as.int64(rmcin$epoch)
|
||||
|
||||
sid<-strsplit(rmcin$payload,",")
|
||||
maxcol<-max(sapply(sid,length))
|
||||
clusterExport(cl,c("maxcol"))
|
||||
inrmc<-as.data.frame(matrix(unlist(lapply(sid,function(i){out<-i;if(length(i)<maxcol){out<-c(i,rep(NA,maxcol-length(i)));};return(out)})),ncol=maxcol,nrow=length(sid),byrow=TRUE),stringsAsFactors=FALSE)
|
||||
inrmc$id<-rmcin$id
|
||||
inrmc$uid<-rmcin$uid
|
||||
inrmc$epoch<-rmcin$epoch
|
||||
inrmc$telegram<-rmcin$telegram
|
||||
col_tel<-0
|
||||
vtgdf<-data.frame(uid=inrmc$uid,epoch=inrmc$epoch,id=inrmc$id,
|
||||
system=substr(inrmc$telegram,2,2),
|
||||
course_true=as.numeric(inrmc[,col_tel+1]),course_mag=as.numeric(inrmc[,col_tel+3]),speed_kn=as.numeric(inrmc[,col_tel+5])*1000,
|
||||
speed_kmh=as.numeric(inrmc[,col_tel+7])*1000
|
||||
,stringsAsFactors=FALSE)
|
||||
dbCatchWriteTable(con,"gpsvtg",vtgdf)
|
||||
|
||||
rm(vtgdf,inrmc,rmcin)
|
||||
gc()
|
||||
}
|
||||
|
||||
|
||||
rmcin<-dbGetQuery(con,"select uid,cast(id as char) as id,cast(epoch as char) as epoch,telegram,payload from gpsin where telegram like '%GNS' and raw=1;")
|
||||
if(nrow(rmcin)>0){
|
||||
rmcin$id<-as.int64(rmcin$id)
|
||||
rmcin$epoch<-as.int64(rmcin$epoch)
|
||||
|
||||
sid<-strsplit(rmcin$payload,",")
|
||||
maxcol<-max(sapply(sid,length))
|
||||
clusterExport(cl,c("maxcol"))
|
||||
inrmc<-as.data.frame(matrix(unlist(lapply(sid,function(i){out<-i;if(length(i)<maxcol){out<-c(i,rep(NA,maxcol-length(i)));};return(out)})),ncol=maxcol,nrow=length(sid),byrow=TRUE),stringsAsFactors=FALSE)
|
||||
inrmc$id<-rmcin$id
|
||||
inrmc$uid<-rmcin$uid
|
||||
inrmc$epoch<-rmcin$epoch
|
||||
inrmc$telegram<-rmcin$telegram
|
||||
col_tel<-0
|
||||
gnsdf<-data.frame(uid=inrmc$uid,epoch=inrmc$epoch,id=inrmc$id,
|
||||
breite=txt2bl(inrmc[,col_tel+2]),laenge=txt2bl(inrmc[,col_tel+4]),mode=inrmc[,col_tel+6],sats=inrmc[,col_tel+7],hdop=as.numeric(inrmc[,col_tel+8]),
|
||||
hoehe=as.numeric(inrmc[,col_tel+9])*1000,hoehe_datum=as.numeric(inrmc[,col_tel+10])*1000
|
||||
,stringsAsFactors=FALSE)
|
||||
dbCatchWriteTable(con,"gpsgns",gnsdf,nfr=1000)
|
||||
|
||||
rm(gnsdf,inrmc,rmcin)
|
||||
gc()
|
||||
}
|
||||
|
||||
dbSendStatement(con,"delete from gpsin where raw=1;")
|
||||
dbDisconnect(con)
|
|
@ -0,0 +1,37 @@
|
|||
#!/bin/bash
|
||||
TTY=$1
|
||||
if [ ! -f /tmp/${TTY}.pid ]; then
|
||||
id=
|
||||
echo $$ > /tmp/${TTY}.pid
|
||||
uid=$(echo $(udevadm info --name=/dev/${TTY}|sed -n '/MAJOR/{s/[A-Z: =]*//;p}')*256+$(udevadm info --name=/dev/${TTY}|sed -n '/MINOR/{s/[A-Z: =]*//;p}')|bc)
|
||||
# id=${uid}$(date +%s%2N)
|
||||
exfile=$(date +%j%H%M)
|
||||
while IFS=$ read -r pre gline; do
|
||||
if [ ! -z "$gline" ]; then
|
||||
IFS=, read -r telegram payload <<< $gline
|
||||
if [[ "$telegram" != *"TXT"* ]]; then
|
||||
payload=${payload%\**}
|
||||
# echo $payload
|
||||
if [[ "$payload" != *"\$G"* ]]; then
|
||||
if [ ${#telegram} -eq 5 ]; then
|
||||
# echo $payload
|
||||
if [[ "$telegram" = *"RMC"* ]]; then
|
||||
if [[ "$gline" = *",A,"* ]]; then
|
||||
id=${uid}$(date +%s%2N)
|
||||
exfile=$(date +%j%H%M)
|
||||
else
|
||||
id=
|
||||
exfile=
|
||||
fi
|
||||
fi
|
||||
if [ ! -z "$id" ]; then
|
||||
echo ${uid},${id},$(date +%s%3N),${telegram},\;"${payload}"\; >>/tmp/gps_${uid}_${exfile}
|
||||
# mysql -u gps -pgps -D gps -e "insert into gpsin (uid,id,epoch,telegram,payload) values (${uid},${id},$(date +%s%3N),'${telegram}','${payload}');" #>>/tmp/gps_${uid}_${exfile}
|
||||
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done </dev/${TTY}
|
||||
fi
|
|
@ -0,0 +1,26 @@
|
|||
#!/bin/bash
|
||||
TTY=$1
|
||||
echo ${TTY}
|
||||
id=$(date +%N|cut -b 3-6)
|
||||
|
||||
grep G /dev/${TTY}|while read line
|
||||
do
|
||||
case $line in
|
||||
*RMC*)
|
||||
id=$(date +%N|cut -b 3-6)
|
||||
echo ${TTY},$(expr $(date +%s) - 1514764800).$(date +%N|cut -b -5),$id,$line |sed -e 's/tty//g;s/\.[0]*,/,/g;s/*.*//g;s/[,]*$//g;s/,0*/,/g' >> /tmp/gps_$(date +%j%H%M)
|
||||
;;
|
||||
*TXT*)
|
||||
;;
|
||||
*unknown*)
|
||||
;;
|
||||
*VTG*)
|
||||
;;
|
||||
*PUBX*)
|
||||
;;
|
||||
*G*)
|
||||
echo ${TTY},$(expr $(date +%s) - 1514764800).$(date +%N|cut -b -5),$id,$line |sed -e 's/tty//g;s/\.[0]*,/,/g;s/*.*//g;s/[,]*$//g;s/,0*/,/g' >> /tmp/gps_$(date +%j%H%M)
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
#!/bin/bash
|
||||
TTY=$1
|
||||
echo ${TTY}
|
||||
ntty=$(echo $TTY|sed -e 's/tty//g')
|
||||
#id=$(date +%N|cut -b 3-6)
|
||||
id="NOFIX"
|
||||
cpuserial=$(printf "%d\n" 0x$(cat /proc/cpuinfo |grep Serial|cut -d: -f2|sed -e 's/^ //'))
|
||||
ttymajor=$(udevadm info --name=/dev/ttyUSB1|sed -n '/MAJOR/{s/[A-Z: =]*//;p}')
|
||||
ttyminor=$(udevadm info --name=/dev/ttyUSB1|sed -n '/MINOR/{s/[A-Z: =]*//;p}')
|
||||
|
||||
grep G /dev/${TTY}|while read line
|
||||
do
|
||||
case $line in
|
||||
*TXT*,*unknown*,*VTG*,*PUBX*)
|
||||
;;
|
||||
*RMC*)
|
||||
if [ "$line" == "*,,,,*" ]; then
|
||||
id="NOFIX"
|
||||
else
|
||||
id=$(echo $(date +%s)$(echo $(date +%N|cut -b -3))${ttymajor}${ttyminor})
|
||||
echo $id
|
||||
echo "insert into gps.gpsin (cpuserial,interface,epoch,fixid,payload) values ($cpuserial,'$ntty',$(date +%s)$(date +%N|cut -b -3),$id,'$line');"|mysql -h pisql -u gps -pgps
|
||||
# echo "insert into gps.gpsin (cpuserial,interface,epoch,fixid,payload) values ($cpuserial,'$ntty',$(date +%s)$(date +%N|cut -b -3),$id,'$line');"
|
||||
# echo ${ntty},$(date +%s).$(date +%N|cut -b -3),$id,$line |sed -e 's/,[NWESAV]/,/g;s/\.[0]*,/,/g;s/*.*//g;s/,0*/,/g;s/[,]*$//g' >> /tmp/gps_$(date +%j%H%M)
|
||||
fi
|
||||
;;
|
||||
*GSV*)
|
||||
if [ "$id" != "NOFIX" ]; then
|
||||
echo "insert into gps.gpsin (cpuserial,interface,epoch,fixid,payload) values ($cpuserial,'$ntty',$(date +%s)$(date +%N|cut -b -3),$id,'$line');"|mysql -h pisql -u gps -pgps
|
||||
# echo ${ntty},$(date +%s).$(date +%N|cut -b -3),$id,$line |sed -e 's/*.*//g;s/,0*/,/g' >> /tmp/gps_$(date +%j%H%M)
|
||||
fi
|
||||
;;
|
||||
*GSA*)
|
||||
if [ "$id" != "NOFIX" ]; then
|
||||
echo "insert into gps.gpsin (cpuserial,interface,epoch,fixid,payload) values ($cpuserial,'$ntty',$(date +%s)$(date +%N|cut -b -3),$id,'$line');"|mysql -h pisql -u gps -pgps
|
||||
fi
|
||||
;;
|
||||
*GGA*)
|
||||
if [ "$id" != "NOFIX" ]; then
|
||||
echo "insert into gps.gpsin (cpuserial,interface,epoch,fixid,payload) values ($cpuserial,'$ntty',$(date +%s)$(date +%N|cut -b -3),$id,'$line');"|mysql -h pisql -u gps -pgps
|
||||
# echo ${ntty},$(date +%s).$(date +%N|cut -b -3),$id,$line |sed -e 's/,[MNESW]/,/g;s/*.*//g;s/,0*/,/g;s/\.[0]*,/,/g' >> /tmp/gps_$(date +%j%H%M)
|
||||
fi
|
||||
;;
|
||||
*GBS*)
|
||||
if [ "$id" != "NOFIX" ]; then
|
||||
echo "insert into gps.gpsin (cpuserial,interface,epoch,fixid,payload) values ($cpuserial,'$ntty',$(date +%s)$(date +%N|cut -b -3),$id,'$line');"|mysql -h pisql -u gps -pgps
|
||||
# echo ${ntty},$(date +%s).$(date +%N|cut -b -3),$id,$line |sed -e 's/*.*//g;s/,0*/,/g' >> /tmp/gps_$(date +%j%H%M)
|
||||
fi
|
||||
;;
|
||||
*GST*)
|
||||
if [ "$id" != "NOFIX" ]; then
|
||||
echo "insert into gps.gpsin (cpuserial,interface,epoch,fixid,payload) values ($cpuserial,'$ntty',$(date +%s)$(date +%N|cut -b -3),$id,'$line');"|mysql -h pisql -u gps -pgps
|
||||
# echo ${ntty},$(date +%s).$(date +%N|cut -b -3),$id,$line |sed -e 's/*.*//g;s/,0*/,/g' >> /tmp/gps_$(date +%j%H%M)
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
#!/bin/bash
|
||||
TTY=$1
|
||||
echo ${TTY}
|
||||
ntty=$(echo $TTY|sed -e 's/tty//g')
|
||||
#id=$(date +%N|cut -b 3-6)
|
||||
id="NOFIX"
|
||||
|
||||
grep G /dev/${TTY}|while read line
|
||||
do
|
||||
if [ "$line" == "*RMC*" ]; then
|
||||
if [ "$line" == "*,,,,*" ]; then
|
||||
id="NOFIX"
|
||||
else
|
||||
id=$(date +%N|cut -b 3-6)
|
||||
echo ${ntty},$(date +%s).$(date +%N|cut -b -3),$id,$line |sed -e 's/,[NWESAV]/,/g;s/\.[0]*,/,/g;s/*.*//g;s/,0*/,/g;s/[,]*$//g' >> /tmp/gps_$(date +%j%H%M)
|
||||
fi
|
||||
fi
|
||||
if [ "$id" != "NOFIX" ]; then
|
||||
case $line in
|
||||
*TXT*,*unknown*,*VTG*,*PUBX*)
|
||||
;;
|
||||
*GSV*)
|
||||
echo ${ntty},$(date +%s).$(date +%N|cut -b -3),$id,$line |sed -e 's/*.*//g;s/,0*/,/g' >> /tmp/gps_$(date +%j%H%M)
|
||||
;;
|
||||
*GSA*)
|
||||
echo ${ntty},$(date +%s).$(date +%N|cut -b -3),$id,$line |sed -e 's/*.*//g;s/,0*/,/g;s/\.[0]*,/,/g' >> /tmp/gps_$(date +%j%H%M)
|
||||
;;
|
||||
*GGA*)
|
||||
echo ${ntty},$(date +%s).$(date +%N|cut -b -3),$id,$line |sed -e 's/,[MNESW]/,/g;s/*.*//g;s/,0*/,/g;s/\.[0]*,/,/g' >> /tmp/gps_$(date +%j%H%M)
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
done
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
#!/bin/bash
|
||||
TTY=$1
|
||||
STTY=$(echo $TTY|sed -e 's/tty//g')
|
||||
if [ ! -f /tmp/${TTY}.pid ]; then
|
||||
id=
|
||||
echo $$ > /tmp/${TTY}.pid
|
||||
uid=$(echo $(udevadm info --name=/dev/${TTY}|sed -n '/MAJOR/{s/[A-Z: =]*//;p}')*256+$(udevadm info --name=/dev/${TTY}|sed -n '/MINOR/{s/[A-Z: =]*//;p}')|bc)
|
||||
# id=${uid}$(date +%s%2N)
|
||||
exfile=$(date +%j%H%M)
|
||||
cat /dev/${TTY}|unbuffer -p tr -dc "[:print:]\n"|unbuffer -p grep '^$G.RMC\|^$G.GS\|^$G.GGA\|^$G.GNS\|^$G.VTG\|^$G.ZDA'|ts %.s,${TTY},${uid},|unbuffer -p sed -e 's/*..//g'|split -a4 -d -l10000 - /tmp/${TTY}.
|
||||
fi
|
|
@ -0,0 +1,20 @@
|
|||
#!/bin/bash
|
||||
TTY=$1
|
||||
echo ${TTY}
|
||||
if [ ! -f /tmp/${TTY}.pid ]; then
|
||||
echo ${TTY}
|
||||
id=
|
||||
# echo $$ > /tmp/${TTY}.pid
|
||||
uid=$(echo $(udevadm info --name=/dev/${TTY}|sed -n '/MAJOR/{s/[A-Z: =]*//;p}')*256+$(udevadm info --name=/dev/${TTY}|sed -n '/MINOR/{s/[A-Z: =]*//;p}')|bc)
|
||||
id=$(date +%N|cut -b 3-6)
|
||||
exfile=$(date +%j%H%M)
|
||||
while IFS=$ read -r pre gline; do
|
||||
echo $gline
|
||||
if [ ! -z "$gline" ]; then
|
||||
gline=$(echo $gline|cut -d\* -f1)
|
||||
echo $gline
|
||||
telegram=$(echo $gline|cut -c3-5)
|
||||
echo $telegram
|
||||
fi
|
||||
done </dev/${TTY}
|
||||
fi
|
|
@ -0,0 +1,11 @@
|
|||
#!/bin/sh
|
||||
mysql -u gps -pgps -D gps -e "create table if not exists gps.gpsin (uid integer, id bigint, epoch bigint, telegram char(5),payload varchar(160),raw tinyint, index (uid,id,epoch,telegram,raw));"
|
||||
mysql -u gps -pgps -D gps -e "create table if not exists gps.gpsrmc (uid integer, id bigint, epoch bigint, breite bigint,laenge bigint,velocity integer,fix char(1),system char(1),fix_epoch integer,raw tinyint, index (uid,id,epoch,breite,laenge));"
|
||||
mysql -u gps -pgps -D gps -e "create table if not exists gps.gpsgga (uid integer, id bigint, epoch bigint, breite bigint,laenge bigint,fix integer,fix_epoch integer,sats tinyint,hdop decimal(3,3),hoehe integer,hoehe_datum integer,raw tinyint, index (uid,id,epoch,breite,laenge));"
|
||||
mysql -u gps -pgps -D gps -e "create table if not exists gps.gpsgsv (uid integer, id bigint, epoch bigint, prn smallint unsigned,elevation smallint unsigned,azimuth smallint unsigned,snr smallint unsigned,folge tinyint unsigned,system char(1),raw tinyint, index (uid,id,epoch,prn,system));"
|
||||
mysql -u gps -pgps -D gps -e "create table if not exists gps.gpsgsa (uid integer, id bigint, epoch bigint, system char(1),hdop decimal(5,3),vdop decimal(5,3),pdop decimal(5,3),sats varchar(50),raw tinyint, index (uid,id,epoch));"
|
||||
mysql -u gps -pgps -D gps -e "create table if not exists gps.gpsgbs (uid integer, id bigint, epoch bigint, system char(1),lat_err decimal(5,3),lon_err decimal(5,3),alt_err decimal(5,3),raw tinyint, index (uid,id,epoch));"
|
||||
mysql -u gps -pgps -D gps -e "create table if not exists gps.gpsgrs (uid integer, id bigint, epoch bigint, system char(1),fix integer,fgga integer,s1 numeric,s2 numeric,s3 numeric,s4 numeric,s5 numeric,s6 numeric,s7 numeric,s8 numeric,s9 numeric,s10 numeric,s11 numeric,s12 numeric,raw tinyint, index (uid,id,epoch));"
|
||||
mysql -u gps -pgps -D gps -e "create table if not exists gps.gpsgst (uid integer, id bigint, epoch bigint, system char(1),rms mediumint,lat_sigma decimal(5,3),lon_sigma decimal(5,3),height_sigma decimal(5,3),raw tinyint, index (uid,id,epoch));"
|
||||
mysql -u gps -pgps -D gps -e "create table if not exists gps.gpsvtg (uid integer, id bigint, epoch bigint, system char(1),course_true mediumint,course_mag mediumint,speed_kn integer unsigned,speed_kmh integer unsigned,raw tinyint, index (uid,id,epoch));"
|
||||
mysql -u gps -pgps -D gps -e "create table if not exists gps.gpsgns (uid integer, id bigint, epoch bigint, breite bigint,laenge bigint,fix integer,sats tinyint,hdop decimal(3,3),hoehe integer,hoehe_datum integer,mode varchar(8),raw tinyint, index (uid,id,epoch,breite,laenge));"
|
|
@ -0,0 +1,24 @@
|
|||
txt2bl<-function(indata){
|
||||
instr<-strsplit(indata,"\\.")
|
||||
ins<-data.frame(a=unlist(lapply(1:length(instr),function(i){return(unlist(instr[[i]][1]))})),b=unlist(lapply(1:length(instr),function(i){return(unlist(instr[[i]][2]))})),stringsAsFactors=FALSE)
|
||||
# ins<-matrix(unlist(strsplit(indata,"\\.")),ncol=2,byrow=TRUE)
|
||||
if(sum(is.na(ins$a),na.rm=TRUE)>0)ins[is.na(ins$a),"a"]<-"000"
|
||||
if(sum(is.na(ins$b),na.rm=TRUE)>0)ins[is.na(ins$b),"b"]<-"000"
|
||||
if(sum(nchar(ins$a)<2,na.rm=TRUE)>0)ins[nchar(ins$a)<2,"a"]<-"000"
|
||||
if(sum(nchar(ins$b)<2,na.rm=TRUE)>0)ins[nchar(ins$b)<2,"b"]<-"000"
|
||||
if(sum(nchar(ins$b)>5,na.rm=TRUE)>0)ins[nchar(ins$b)>5,"b"]<-unlist(lapply(ins[nchar(ins$b)>5,"b"],function(i){return(substr(i,1,5))}))
|
||||
insec<-as.integer(paste(ins$b,sapply(6-nchar(ins$b),function(i){return(paste0(rep("0",i),collapse=""))}),sep=""))
|
||||
inmin<-as.integer(sapply(ins$a,function(i){return(substr(i,nchar(i)-1,nchar(i)))}))+
|
||||
60*as.integer(sapply(ins$a,function(i){return(substr(i,1,nchar(i)-2))}))
|
||||
out<-inmin*1e6+insec
|
||||
return(out)
|
||||
}
|
||||
dbCatchWriteTable<-function(db,table,indata,nfr=500){
|
||||
ncalls<-floor(nrow(indata)/nfr)
|
||||
rowi<-1:nrow(indata)
|
||||
for(i in 0:ncalls){
|
||||
win<-i*nfr+1:nfr
|
||||
win<-win[win%in%rowi]
|
||||
dbWriteTable(db,table,indata[win,],append=TRUE,row.names=FALSE)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
mysql -u gps -pgps -D gps -e "load data local infile '$1' into table gpsin fields terminated by ',' enclosed by ';' (uid,id,epoch,telegram,payload);"
|
||||
rm $1
|
|
@ -0,0 +1,6 @@
|
|||
#!/bin/sh
|
||||
|
||||
/home/pi/gps/gps_init2.sh
|
||||
for u in /dev/ttyUSB*; do
|
||||
nohup /home/pi/gps/gps_init_ser.sh $(basename $u) &>/dev/null &
|
||||
done
|
Loading…
Reference in New Issue