diff --git a/.github/workflows/github-actions-demo.yml b/.github/workflows/github-actions-demo.yml
new file mode 100644
index 000000000..15a61d6b6
--- /dev/null
+++ b/.github/workflows/github-actions-demo.yml
@@ -0,0 +1,18 @@
+name: GitHub Actions Demo
+run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
+on: [push]
+jobs:
+ Explore-GitHub-Actions:
+ runs-on: ubuntu-latest
+ steps:
+ - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
+ - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
+ - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
+ - name: Check out repository code
+ uses: actions/checkout@v4
+ - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
+ - run: echo "🖥️ The workflow is now ready to test your code on the runner."
+ - name: List files in the repository
+ run: |
+ ls ${{ github.workspace }}
+ - run: echo "🍏 This job's status is ${{ job.status }}."
diff --git a/src/mbtrn/CMakeLists.txt b/src/mbtrn/CMakeLists.txt
index d6073fe2f..5c7e31f4e 100644
--- a/src/mbtrn/CMakeLists.txt
+++ b/src/mbtrn/CMakeLists.txt
@@ -181,7 +181,8 @@ target_link_libraries(mb1r_test PRIVATE mb1r m pthread)
#
add_executable(mb1-cli mb1r/mb1cli-app.c)
target_include_directories(mb1-cli PRIVATE ${CMAKE_SOURCE_DIR}/src/mbtrnframe
- ${CMAKE_SOURCE_DIR}/src/mbtrnav/trnw)
+ ${LibPROJ_INCLUDE_DIRS}
+ ${CMAKE_SOURCE_DIR}/src/mbtrnav/trnw)
target_link_libraries(mb1-cli PRIVATE mbtrnframe mb1r mb1 m pthread)
#
#------------------------------------------------------------------------------
diff --git a/src/mbtrn/tools/mbtrncfg/index.html b/src/mbtrn/tools/mbtrncfg/index.html
index 241475816..d42f09411 100644
--- a/src/mbtrn/tools/mbtrncfg/index.html
+++ b/src/mbtrn/tools/mbtrncfg/index.html
@@ -133,6 +133,31 @@
mbtrnpp Configuration Tool
+
+ platform-file
+
+
+
+
+ tide-model
+
+
+
+
+ statsec
+
+
+
+
+ statflags
+
+
+
+
+ delay
+
+
+
trn-en
@@ -151,11 +176,29 @@ mbtrnpp Configuration Tool
-
- trn-utm
-
-
-
+
+
+ use-proj
+
+ Y
+ N
+
+
+
+ projection
+
+
+
+
+ trn-crs
+
+
+
+
+ trn-utm
+
+
+
trn-map
@@ -230,7 +273,7 @@ mbtrnpp Configuration Tool
reinit-gain
- Y
+ Y
N
@@ -264,11 +307,6 @@ mbtrnpp Configuration Tool
-
- tide-model
-
-
-
trn-out
@@ -295,21 +333,6 @@ mbtrnpp Configuration Tool
-
- statsec
-
-
-
-
- statflags
-
-
-
-
- delay
-
-
-
diff --git a/src/mbtrn/tools/mbtrncfg/src/mbtrncfg.js b/src/mbtrn/tools/mbtrncfg/src/mbtrncfg.js
index 4546c0327..30ee839ae 100644
--- a/src/mbtrn/tools/mbtrncfg/src/mbtrncfg.js
+++ b/src/mbtrn/tools/mbtrncfg/src/mbtrncfg.js
@@ -219,6 +219,7 @@ help_topics["format"]="MB-System format id (datalist: -1; Teledyn 7k: 88 or 89;
help_topics["auv-sentry-em2040"]="Flag enabling use of special pressure depth encoding for EM2040 data collected on AUV Sentry";
help_topics["median-filter"]="Median filter settings\n\n\
filter_threshold/n_along/n_across";
+help_topics["platform-file"]="MB-System platform file path";
help_topics["output"]="MB-System output\n\
file:\n\n\
[filename may include SESSION for current yyyymmdd-hhmmss]\n\n\
@@ -249,6 +250,9 @@ help_topics["trn-sensor"]="TRN sensor type\n\
3: TRN_SENSOR_PENCIL\n\
4: TRN_SENSOR_HOMER\n\
5: TRN_SENSOR_DELTAT";
+help_topics["use-proj"]="Use libproj for TRN coordinate transformation";
+help_topics["projection"]="TRN coordinate projection ID";
+help_topics["trn-crs"]="TRN Proj CRS specifier string";
help_topics["trn-utm"]="TRN UTM zone (10:Monterey Bay)";
help_topics["mb-out"]="TRN MB1 output configuration\n\n\
Options for MB1 record output are selected using one or more comma separated values:\n\n\
@@ -427,11 +431,15 @@ function load_ctx(){
x.elements["format"].value="88";
x.elements["auv-sentry-em2040"].value="dis";
x.elements["median-filter"].value="0.10/9/3";
+ x.elements["platform-file"].value="";
x.elements["output"].value="file:mbtrnpp_SESSION.mb1";
x.elements["statsec"].value="30";
x.elements["statflags"].value="MSF_STATUS|MSF_EVENT|MSF_ASTAT|MSF_PSTAT";
x.elements["delay"].value="0";
x.elements["trn-sensor"].value="2";
+ x.elements["use-proj"].value="en";
+ x.elements["projection"].value="0";
+ x.elements["trn-crs"].value="UTM10N";
x.elements["trn-utm"].value="10";
x.elements["mb-out"].value="mb1svr:TRN_HOST:27000";
x.elements["trn-map"].value="TRN_MAPFILES/PortTiles";
@@ -495,11 +503,15 @@ function init_preset(key){
x.elements["format"].value="88";
x.elements["auv-sentry-em2040"].value="dis";
x.elements["median-filter"].value="0.10/9/3";
+ x.elements["platform-file"].value="";
x.elements["output"].value="file:mbtrnpp_SESSION.mb1";
x.elements["statsec"].value="30";
x.elements["statflags"].value="MSF_STATUS|MSF_EVENT|MSF_ASTAT|MSF_PSTAT";
x.elements["delay"].value="0";
x.elements["trn-sensor"].value="2";
+ x.elements["use-proj"].value="en";
+ x.elements["projection"].value="0";
+ x.elements["trn-crs"].value="UTM10N";
x.elements["trn-utm"].value="10";
x.elements["mb-out"].value="mb1svr:TRN_HOST:27000";
x.elements["trn-map"].value="TRN_MAPFILES/PortTiles";
@@ -589,6 +601,8 @@ function update(){
text += '--auv-sentry-em2040'+" ";
if(x.elements["median-filter"].value.length>0)
text += '--median-filter='+x.elements["median-filter"].value+" ";
+ if(x.elements["platform-file"].value.length>0)
+ text += '--platform-file='+x.elements["platform-file"].value+" ";
if(x.elements["statsec"].value.length>0)
text += '--statsec='+x.elements["statsec"].value+" ";
if(x.elements["statflags"].value.length>0)
@@ -605,6 +619,12 @@ function update(){
text += '--trn-dev='+x.elements["trn-dev"].value+" ";
if(x.elements["trn-sensor"].value.length>0)
text += '--trn-sensor='+x.elements["trn-sensor"].value+" ";
+ if(x.elements["use-proj"].value=='en')
+ text += '--use-proj'+" ";
+ if(x.elements["projection"].value.length>0)
+ text += '--projection='+x.elements["projection"].value+" ";
+ if(x.elements["trn-crs"].value.length>0)
+ text += '--trn-crs='+x.elements["trn-crs"].value+" ";
if(x.elements["trn-utm"].value.length>0)
text += '--trn-utm='+x.elements["trn-utm"].value+" ";
if(x.elements["trn-decn"].value.length>0)
@@ -791,14 +811,6 @@ function cfg2str(){
}
retval+="soundings="+x.elements["soundings"].value+"\n";
- retval+="\n";
- if(verbose){
- retval+="// opt median-filter [?]\n";
- retval+="// median filter parameters\n";
- retval+="// //\n";
- }
- retval+="median-filter="+x.elements["median-filter"].value+"\n";
-
retval+="\n";
if(verbose){
retval+="// opt format [int]\n";
@@ -808,63 +820,31 @@ function cfg2str(){
retval+="\n";
if(verbose){
- retval+="// opt auv-sentry-em2040 [none]\n";
- retval+="// enable/disable use of special pressure depth encoding for EM2040 data collected on AUV Sentry\n";
+ retval+="// opt median-filter [?]\n";
+ retval+="// median filter parameters\n";
+ retval+="// //\n";
}
- if(x.elements["auv-sentry-em2040"].value=="en")
- retval+="auv-sentry-em2040\n";
- else
- retval+="#auv-sentry-em2040\n";
+ retval+="median-filter="+x.elements["median-filter"].value+"\n";
retval+="\n";
if(verbose){
retval+="// opt platform-file [mb_path]\n";
- retval+="// description TBD\n";
+ retval+="// specify platform file\n";
}
- retval+="#platform-file=\n";
-
- retval+="\n";
- if(verbose){
- retval+="// opt platform-target-sensor [int]\n";
- retval+="// description TBD\n";
- }
- retval+="#platform-target-sensor=\n";
-
- retval+="\n";
- if(verbose){
- retval+="// opt projection\n";
- retval+="// cartographic(?) projection ID\n";
- }
- retval+="#projection=\n";
-
- retval+="\n";
- if(verbose){
- retval+="// opt mbhbn [int]\n";
- retval+="// MB1 server heartbeat modulus\n";
- retval+="// (timeout preferred, use mbhbt)\n";
- }
- retval+="#mbhbn\n";
-
- retval+="\n";
- if(verbose){
- retval+="// opt mbhbt [double]\n";
- retval+="// MB1 server heartbeat timeout (s)\n";
- }
- retval+="mbhbt="+x.elements["mbhbt"].value+"\n";
-
- retval+="\n";
- if(verbose){
- retval+="// opt trnhbt [double]\n";
- retval+="// TRN server heartbeat timeout (s)\n";
- }
- retval+="trnhbt="+x.elements["trnhbt"].value+"\n";
+ if(x.elements["platform-file"].value.length>0)
+ retval+="platform-file="+x.elements["platform-file"].value+"\n";
+ else
+ retval+="#platform-file=\n";
retval+="\n";
if(verbose){
- retval+="// opt trnuhbt [double]\n";
- retval+="// TRNU (udp update) server heartbeat timeout (s)\n";
+ retval+="// opt tide-model [path]\n";
+ retval+="// OTPS tide model file\n";
}
- retval+="trnuhbt="+x.elements["trnuhbt"].value+"\n";
+ if(x.elements["tide-model"].value.length>0)
+ retval+="tide-model="+x.elements["tide-model"].value+"\n";
+ else
+ retval+="#tide-model=\n";
retval+="\n";
if(verbose){
@@ -892,6 +872,24 @@ function cfg2str(){
}
retval+="statflags="+x.elements["statflags"].value+"\n";
+
+ retval+="\n";
+ if(verbose){
+ retval+="// opt auv-sentry-em2040 [none]\n";
+ retval+="// enable/disable use of special pressure depth encoding for EM2040 data collected on AUV Sentry\n";
+ }
+ if(x.elements["auv-sentry-em2040"].value=="en")
+ retval+="auv-sentry-em2040\n";
+ else
+ retval+="#auv-sentry-em2040\n";
+
+ retval+="\n";
+ if(verbose){
+ retval+="// opt platform-target-sensor [int]\n";
+ retval+="// description TBD\n";
+ }
+ retval+="#platform-target-sensor=\n";
+
retval+="\n";
if(verbose){
retval+="// opt trn-en [bool]\n";
@@ -923,6 +921,30 @@ function cfg2str(){
}
retval+="trn-sensor="+x.elements["trn-sensor"].value+"\n";
+ retval+="\n";
+ if(verbose){
+ retval+="// opt use-proj [bool]\n";
+ retval+="// Use libproj for coordinate transformation\n";
+ }
+ if(x.elements["use-proj"].value=="en")
+ retval+="use-proj\n";
+ else
+ retval+="#use-proj\n";
+
+ retval+="\n";
+ if(verbose){
+ retval+="// opt projection [int]\n";
+ retval+="// cartographic? projection ID for TRN processing (>=0)\n";
+ }
+ retval+="#projection="+x.elements["projection"].value+"\n";
+
+ retval+="\n";
+ if(verbose){
+ retval+="// opt trn-crs [string]\n";
+ retval+="// Proj CRS specifier for TRN processing\n";
+ }
+ retval+="trn-crs="+x.elements["trn-crs"].value+"\n";
+
retval+="\n";
if(verbose){
retval+="// opt trn-utm [long]\n";
@@ -1045,6 +1067,61 @@ function cfg2str(){
}
retval+="trn-eerr="+x.elements["trn-eerr"].value+"\n";
+ retval+="\n";
+ if(verbose){
+ retval+="// opt reinit-gain [none]\n";
+ retval+="// enable/disable gating TRN resets using sonar transmit gain\n";
+ }
+ if(x.elements["reinit-gain"].value=="en")
+ retval+="reinit-gain\n";
+ else
+ retval+="#reinit-gain\n";
+
+ retval+="\n";
+ if(verbose){
+ retval+="// opt reinit-file [bool]\n";
+ retval+="// reinitialize TRN every time a new\n";
+ retval+="// file is read when parsing a datalist\n";
+ }
+ retval+="reinit-file="+x.elements["reinit-file"].value+"\n";
+
+ retval+="\n";
+ if(verbose){
+ retval+="// opt reinit-xyoffset [double]\n";
+ retval+="// reinitialize TRN whenever the magnitude of the\n";
+ retval+="// lateral converged offset exceeds specified limit\n";
+ }
+ retval+="reinit-xyoffset="+x.elements["reinit-xyoffset"].value+"\n";
+
+ retval+="\n";
+ if(verbose){
+ retval+="// opt reinit-zoffset [double]\n";
+ retval+="// reinitialize TRN whenever the converged z-offset\n";
+ retval+="// is is outside specified range.\n";
+ }
+ retval+="reinit-zoffset="+x.elements["reinit-zoffset"].value+"\n";
+
+ retval+="\n";
+ if(verbose){
+ retval+="// opt reinit-search [double/double]\n";
+ retval+="// TRN reinit stdev limits\n";
+ }
+ retval+="reinit-search="+x.elements["reinit-search"].value+"\n";
+
+ retval+="\n";
+ if(verbose){
+ retval+="// opt covariance-magnitude-max [double]\n";
+ retval+="// TRN convergence max covariance limit\n";
+ }
+ retval+="covariance-magnitude-max="+x.elements["covariance-magnitude-max"].value+"\n";
+
+ retval+="\n";
+ if(verbose){
+ retval+="// opt convergence-repeat-min [int]\n";
+ retval+="// TRN convergence minimum repeat limit\n";
+ }
+ retval+="convergence-repeat-min="+x.elements["convergence-repeat-min"].value+"\n";
+
retval+="\n";
if(verbose){
retval+="// opt mb-out [?]\n";
@@ -1098,68 +1175,33 @@ function cfg2str(){
retval+="\n";
if(verbose){
- retval+="// opt reinit-gain [none]\n";
- retval+="// enable/disable gating TRN resets using sonar transmit gain\n";
- }
- if(x.elements["reinit-gain"].value=="en")
- retval+="reinit-gain\n";
- else
- retval+="#reinit-gain\n";
-
- retval+="\n";
- if(verbose){
- retval+="// opt reinit-file [bool]\n";
- retval+="// reinitialize TRN every time a new\n";
- retval+="// file is read when parsing a datalist\n";
- }
- retval+="reinit-file="+x.elements["reinit-file"].value+"\n";
-
- retval+="\n";
- if(verbose){
- retval+="// opt reinit-xyoffset [double]\n";
- retval+="// reinitialize TRN whenever the magnitude of the\n";
- retval+="// lateral converged offset exceeds specified limit\n";
- }
- retval+="reinit-xyoffset="+x.elements["reinit-xyoffset"].value+"\n";
-
- retval+="\n";
- if(verbose){
- retval+="// opt reinit-zoffset [double]\n";
- retval+="// reinitialize TRN whenever the converged z-offset\n";
- retval+="// is is outside specified range.\n";
+ retval+="// opt mbhbn [int]\n";
+ retval+="// MB1 server heartbeat modulus\n";
+ retval+="// (timeout preferred, use mbhbt)\n";
}
- retval+="reinit-zoffset="+x.elements["reinit-zoffset"].value+"\n";
+ retval+="#mbhbn\n";
retval+="\n";
if(verbose){
- retval+="// opt reinit-search [double/double]\n";
- retval+="// TRN reinit stdev limits\n";
+ retval+="// opt mbhbt [double]\n";
+ retval+="// MB1 server heartbeat timeout (s)\n";
}
- retval+="reinit-search="+x.elements["reinit-search"].value+"\n";
+ retval+="mbhbt="+x.elements["mbhbt"].value+"\n";
retval+="\n";
if(verbose){
- retval+="// opt covariance-magnitude-max [double]\n";
- retval+="// TRN convergence max covariance limit\n";
+ retval+="// opt trnhbt [double]\n";
+ retval+="// TRN server heartbeat timeout (s)\n";
}
- retval+="covariance-magnitude-max="+x.elements["covariance-magnitude-max"].value+"\n";
+ retval+="trnhbt="+x.elements["trnhbt"].value+"\n";
retval+="\n";
if(verbose){
- retval+="// opt convergence-repeat-min [int]\n";
- retval+="// TRN convergence minimum repeat limit\n";
+ retval+="// opt trnuhbt [double]\n";
+ retval+="// TRNU (udp update) server heartbeat timeout (s)\n";
}
- retval+="convergence-repeat-min="+x.elements["convergence-repeat-min"].value+"\n";
+ retval+="trnuhbt="+x.elements["trnuhbt"].value+"\n";
- retval+="\n";
- if(verbose){
- retval+="// opt tide-model [path]\n";
- retval+="// OTPS tide model file\n";
- }
- if(x.elements["tide-model"].value.length>0)
- retval+="tide-model="+x.elements["tide-model"].value+"\n";
- else
- retval+="#tide-model=\n";
return retval;
}
diff --git a/src/mbtrnav/CMakeLists.txt b/src/mbtrnav/CMakeLists.txt
index 97888fecc..c4504c8ae 100644
--- a/src/mbtrnav/CMakeLists.txt
+++ b/src/mbtrnav/CMakeLists.txt
@@ -236,6 +236,19 @@ target_link_libraries(tnav PRIVATE newmat qnx NetCDF::NetCDF)
#
#------------------------------------------------------------------------------
#
+# build geocon
+
+# specify library
+add_library(geocon
+ trnw/GeoCon.cpp
+)
+target_include_directories(geocon PRIVATE ${CMAKE_SOURCE_DIR}/src/mbtrnav/newmat
+ ${CMAKE_SOURCE_DIR}/src/mbtrnav/qnx-utils
+ ${LibPROJ_INCLUDE_DIRS})
+target_link_libraries(geocon PRIVATE newmat qnx LibPROJ::LibPROJ )
+#
+#------------------------------------------------------------------------------
+#
# build trnw (TRN C wrapper)
# specify library
@@ -250,7 +263,7 @@ target_include_directories(trnw PRIVATE ${CMAKE_SOURCE_DIR}/src/mbio
${CMAKE_SOURCE_DIR}/src/mbtrnav/newmat
${CMAKE_SOURCE_DIR}/src/mbtrnav/qnx-utils
${NetCDF_INCLUDE_DIRS})
-target_link_libraries(trnw PRIVATE tnav newmat qnx LibPROJ::LibPROJ NetCDF::NetCDF)
+target_link_libraries(trnw PRIVATE tnav newmat qnx geocon LibPROJ::LibPROJ NetCDF::NetCDF)
#
#------------------------------------------------------------------------------
#
@@ -262,7 +275,8 @@ add_library(netif
trnw/trnif_proto.c
)
target_include_directories(netif PRIVATE ${CMAKE_SOURCE_DIR}/src/mbtrnframe
- ${CMAKE_SOURCE_DIR}/src/mbtrnav/terrain-nav
+ ${LibPROJ_INCLUDE_DIRS}
+ ${CMAKE_SOURCE_DIR}/src/mbtrnav/terrain-nav
${CMAKE_SOURCE_DIR}/src/mbtrnutils)
target_link_libraries(netif PRIVATE mbtrnframe tnav trnw)
#
@@ -284,6 +298,7 @@ add_library(trnucli
trnw/trnu_cli.c
)
target_include_directories(trnucli PRIVATE ${CMAKE_SOURCE_DIR}/src/mbtrnframe
+ ${LibPROJ_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/src/mbtrnav/terrain-nav)
target_link_libraries(trnucli PRIVATE mbtrnframe netif)
#
@@ -299,6 +314,7 @@ add_library(trncli
target_include_directories(trncli PRIVATE
${CMAKE_SOURCE_DIR}/src/mbtrnframe
+${LibPROJ_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/src/mbtrnav/terrain-nav
${CMAKE_SOURCE_DIR}/src/mbtrnav/newmat
${CMAKE_SOURCE_DIR}/src/mbtrnav/qnx-utils
@@ -316,6 +332,7 @@ add_executable(trnucli-test
trnw/trnucli_test.c
)
target_include_directories(trnucli-test PRIVATE ${CMAKE_SOURCE_DIR}/src/mbtrnframe
+ ${LibPROJ_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/src/mbtrnav/terrain-nav)
target_link_libraries(trnucli-test PRIVATE mbtrnframe trnucli netif tnav trnw newmat qnx geolib LibPROJ::LibPROJ NetCDF::NetCDF)
#
@@ -328,6 +345,7 @@ add_executable(trnusvr-test
trnw/trnusvr_test.c
)
target_include_directories(trnusvr-test PRIVATE ${CMAKE_SOURCE_DIR}/src/mbtrnframe
+ ${LibPROJ_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/src/mbtrnav/terrain-nav)
target_link_libraries(trnusvr-test PRIVATE mbtrnframe netif tnav trnw newmat qnx geolib NetCDF::NetCDF)
@@ -344,6 +362,7 @@ add_library(trnwcli STATIC
trnw/trn_cli.c
)
target_include_directories(trnwcli PRIVATE
+${LibPROJ_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/src/mbtrnframe
${CMAKE_SOURCE_DIR}/src/mbtrnav/terrain-nav
${CMAKE_SOURCE_DIR}/src/mbtrnav/newmat
@@ -361,7 +380,7 @@ trnw/trncli_test.c
trnw/mb1_msg.c
)
-target_link_libraries(trncli-test PRIVATE mbtrnframe trnwcli newmat geolib trnw qnx mb1 tnav LibPROJ::LibPROJ NetCDF::NetCDF m)
+target_link_libraries(trncli-test PRIVATE mbtrnframe trnwcli newmat geolib trnw qnx mb1 tnav geocon LibPROJ::LibPROJ NetCDF::NetCDF m)
target_include_directories(trncli-test PRIVATE ${CMAKE_SOURCE_DIR}
${LibPROJ_INCLUDE_DIRS}
@@ -423,7 +442,12 @@ trnw/trnif_msg.c
target_link_libraries(trnif-test PRIVATE mbtrnframe netif newmat geolib trnw qnx mb1 tnav NetCDF::NetCDF)
-target_include_directories(trnif-test PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src/mbtrnframe trnw terrain-nav)
+target_include_directories(trnif-test PRIVATE
+${CMAKE_SOURCE_DIR}
+${LibPROJ_INCLUDE_DIRS}
+${CMAKE_SOURCE_DIR}/src/mbtrnframe
+trnw
+terrain-nav)
#
#------------------------------------------------------------------------------
#
@@ -440,6 +464,16 @@ target_include_directories(mb1rs PRIVATE ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}
#
#------------------------------------------------------------------------------
#
+# build geocon-test
+
+add_executable(geocon-test
+trnw/geocon_test.cpp
+)
+
+target_link_libraries(geocon-test PRIVATE geocon qnx)
+target_include_directories(geocon-test PRIVATE ${CMAKE_SOURCE_DIR}
+${LibPROJ_INCLUDE_DIRS} trnw qnx-utils)
+
# build mb1log-player
# specify build target
@@ -468,8 +502,8 @@ target_compile_options(mb1log-player PUBLIC
#------------------------------------------------------------------------------
# install it all
#
-install(TARGETS geolib newmat tnav qnx trnw netif mb1 trnucli trnwcli DESTINATION ${CMAKE_INSTALL_LIBDIR})
-install(TARGETS trnucli-test trnusvr-test trncli-test mmcpub mmcsub mcpub mcsub trnif-test mb1rs mb1log-player DESTINATION ${CMAKE_INSTALL_BINDIR})
+install(TARGETS geolib geocon newmat tnav qnx trnw netif mb1 trnucli trnwcli DESTINATION ${CMAKE_INSTALL_LIBDIR})
+install(TARGETS trnucli-test trnusvr-test trncli-test mmcpub mmcsub mcpub mcsub trnif-test mb1rs mb1log-player geocon-test DESTINATION ${CMAKE_INSTALL_BINDIR})
#
#------------------------------------------------------------------------------
diff --git a/src/mbtrnav/opt/rov/bathymetry_provider_IF.hpp b/src/mbtrnav/opt/rov/bathymetry_provider_IF.hpp
index b9ae6f294..0bd767431 100644
--- a/src/mbtrnav/opt/rov/bathymetry_provider_IF.hpp
+++ b/src/mbtrnav/opt/rov/bathymetry_provider_IF.hpp
@@ -91,8 +91,8 @@ class bath_info
ss << beam_count() << ",";
std::list::iterator it;
- int k=0;
- for(it=mBeamList.begin(); it!=mBeamList.end(); k++)
+
+ for(it=mBeamList.begin(); it!=mBeamList.end(); )
{
trn::beam_tup bt = static_cast (*it);
ss << std::get<0>(bt) << ":" << std::get<1>(bt);
@@ -118,8 +118,8 @@ class bath_info
ss << beam_count() << ",";
std::list::iterator it;
- int k=0;
- for(it=mBeamList.begin(); it!=mBeamList.end(); k++)
+
+ for(it=mBeamList.begin(); it!=mBeamList.end(); )
{
trn::beam_tup bt = static_cast (*it);
ss << std::get<0>(bt) << "," << std::get<1>(bt);
diff --git a/src/mbtrnav/opt/rov/mb1_provider_IF.hpp b/src/mbtrnav/opt/rov/mb1_provider_IF.hpp
index f16f76071..79b40fea8 100644
--- a/src/mbtrnav/opt/rov/mb1_provider_IF.hpp
+++ b/src/mbtrnav/opt/rov/mb1_provider_IF.hpp
@@ -141,8 +141,8 @@ class mb1_info
ss << beam_count() << ",";
std::list::iterator it;
- int k=0;
- for(it=mBeamList.begin(); it!=mBeamList.end(); k++)
+
+ for(it=mBeamList.begin(); it!=mBeamList.end(); )
{
trn::mb1_beam_tup bt = static_cast (*it);
ss << std::get<0>(bt) << ":" << std::get<1>(bt);
diff --git a/src/mbtrnav/opt/rov/plug-dvl.cpp b/src/mbtrnav/opt/rov/plug-dvl.cpp
index 3db481521..e8256abe7 100644
--- a/src/mbtrnav/opt/rov/plug-dvl.cpp
+++ b/src/mbtrnav/opt/rov/plug-dvl.cpp
@@ -146,7 +146,6 @@ void transform_dvl(trn::bath_info *bi, trn::att_info *ai, dvlgeo *geo, mb1_t *r_
int cb_proto_dvl(void *pargs)
{
int retval=-1;
- static uint32_t ping_number = 0;
TRN_NDPRINT(3, "%s:%d >>> Callback triggered <<<\n", __func__, __LINE__);
@@ -170,8 +169,6 @@ int cb_proto_dvl(void *pargs)
TRN_NDPRINT(TRNDL_PLUGOIDVL, "%s:%d processing ctx[%s]\n", __func__, __LINE__, ctx->ctx_key().c_str());
- int err_count = 0;
-
std::string *bkey[1] = {ctx->bath_input_chan(0)};
std::string *nkey = ctx->nav_input_chan(0);
std::string *akey[1] = {ctx->att_input_chan(0)};
@@ -180,7 +177,6 @@ int cb_proto_dvl(void *pargs)
if(bkey[0] == nullptr || nkey == nullptr || akey[0] == nullptr || vkey == nullptr)
{
TRN_NDPRINT(TRNDL_PLUGOIDVL, "%s:%d WARN - NULL input key\n", __func__, __LINE__);
- err_count++;
continue;
}
@@ -192,7 +188,6 @@ int cb_proto_dvl(void *pargs)
if(bi == nullptr || ni == nullptr || ai == nullptr || vi == nullptr)
{
fprintf(stderr,"%s:%d WARN - NULL info instance\n", __func__, __LINE__);
- err_count++;
}
@@ -216,9 +211,9 @@ int cb_proto_dvl(void *pargs)
// construct poseT/measT TRN inputs
-
- poseT *pt = trnx_utils::mb1_to_pose(snd, ai, (long)ctx->utm_zone());
- measT *mt = trnx_utils::mb1_to_meas(snd, ai, trn_type, (long)ctx->utm_zone());
+ GeoCon gcon(ctx->utm_zone());
+ poseT *pt = trnx_utils::mb1_to_pose(snd, ai, NULL, &gcon);
+ measT *mt = trnx_utils::mb1_to_meas(snd, ai, trn_type, &gcon);
// publish update TRN, publish estimate to TRN, LCM
ctx->pub_trn(nav_time, pt, mt, trn_type, xpp->pub_list(), cfg);
@@ -251,7 +246,5 @@ int cb_proto_dvl(void *pargs)
delete vi;
}
- ping_number++;
-
return retval;
}
diff --git a/src/mbtrnav/opt/rov/plug-idt.cpp b/src/mbtrnav/opt/rov/plug-idt.cpp
index 0812206c8..acfe2d213 100644
--- a/src/mbtrnav/opt/rov/plug-idt.cpp
+++ b/src/mbtrnav/opt/rov/plug-idt.cpp
@@ -158,8 +158,6 @@ int cb_proto_deltat(void *pargs)
TRN_NDPRINT(TRNDL_PLUGIDT, "%s:%d processing ctx[%s]\n", __func__, __LINE__, ctx->ctx_key().c_str());
- int err_count = 0;
-
std::string *bkey = ctx->bath_input_chan(0);
std::string *nkey = ctx->nav_input_chan(0);
std::string *akey = ctx->att_input_chan(0);
@@ -169,7 +167,6 @@ int cb_proto_deltat(void *pargs)
if(bkey == nullptr || nkey == nullptr || akey == nullptr)
{
TRN_NDPRINT(TRNDL_PLUGIDT, "%s:%d WARN - NULL input key\n", __func__, __LINE__);
- err_count++;
continue;
}
@@ -182,7 +179,6 @@ int cb_proto_deltat(void *pargs)
{
TRN_NDPRINT(TRNDL_PLUGIDT, "%s:%d WARN - NULL info instance\n", __func__, __LINE__);
TRN_NDPRINT(TRNDL_PLUGIDT, "%s:%d bi[%p] ni[%p] ai[%p] vi[%p]\n", __func__, __LINE__);
- err_count++;
}
std::string *bath_0_key = ctx->bath_input_chan(0);
@@ -242,8 +238,9 @@ int cb_proto_deltat(void *pargs)
// publish poseT/measT to trn-server
int trn_type = bp->bath_input_type();
- poseT *pt = trnx_utils::mb1_to_pose(snd, ai, (long)ctx->utm_zone());
- measT *mt = trnx_utils::mb1_to_meas(snd, ai, trn_type, (long)ctx->utm_zone());
+ GeoCon gcon(ctx->utm_zone());
+ poseT *pt = trnx_utils::mb1_to_pose(snd, ai, NULL, &gcon);
+ measT *mt = trnx_utils::mb1_to_meas(snd, ai, trn_type, &gcon);
if(cfg->debug() >= TRNDL_PLUGIDT ){
fprintf(stderr,"%s - >>>>>>> Publishing POSE:\n",__func__);
diff --git a/src/mbtrnav/opt/rov/plug-idtlass.cpp b/src/mbtrnav/opt/rov/plug-idtlass.cpp
index afc9352a5..fd19973ef 100644
--- a/src/mbtrnav/opt/rov/plug-idtlass.cpp
+++ b/src/mbtrnav/opt/rov/plug-idtlass.cpp
@@ -310,8 +310,6 @@ int cb_proto_idtlass(void *pargs)
TRN_NDPRINT(TRNDL_PLUGIDTLASS, "%s:%d processing ctx[%s]\n", __func__, __LINE__, ctx->ctx_key().c_str());
- int err_count = 0;
-
std::string *bkey[1] = {ctx->bath_input_chan(0)};
std::string *nkey[2] = {ctx->nav_input_chan(0),ctx->nav_input_chan(1)};
std::string *akey[2] = {ctx->att_input_chan(0), ctx->att_input_chan(1)};
@@ -330,7 +328,6 @@ int cb_proto_idtlass(void *pargs)
ss << (nkey[1]==nullptr ? " dkey[1]" : "");
ss << (vkey[0] == nullptr ? " vkey[0]" : "");
TRN_NDPRINT(TRNDL_PLUGIDTLASS, "%s:%d ERR - NULL input key: %s\n", __func__, __LINE__, ss.str().c_str());
- err_count++;
continue;
}
@@ -351,7 +348,6 @@ int cb_proto_idtlass(void *pargs)
ss << (ni[1] == nullptr ? " ni[1]" : "");
ss << (vi[0] == nullptr ? " vi[0]" : "");
TRN_NDPRINT(TRNDL_PLUGIDTLASS, "%s:%d WARN - NULL info instance: %s\n", __func__, __LINE__, ss.str().c_str());
- err_count++;
continue;
}
@@ -420,7 +416,6 @@ int cb_proto_idtlass(void *pargs)
// compute MB1 beam components in vehicle frame
if (transform_idtlass(bi, ai, bgeo, snd) != 0) {
TRN_NDPRINT(TRNDL_PLUGIDTLASS_H, "%s:%d ERR - transform_idtlass failed\n", __func__, __LINE__);
- err_count++;
cfg->stats().err_plugin_n++;
continue;
}
@@ -448,10 +443,9 @@ int cb_proto_idtlass(void *pargs)
// generate poseT/measT
// and publish to trn-server
- poseT *pt = trnx_utils::mb1_to_pose(snd, ai[0], vi[0], (long)ctx->utm_zone());
-
- measT *mt = trnx_utils::mb1_to_meas(snd, ai[0], trn_type[0], (long)ctx->utm_zone());
-
+ GeoCon gcon(ctx->utm_zone());
+ poseT *pt = trnx_utils::mb1_to_pose(snd, ai[0], vi[0], &gcon);
+ measT *mt = trnx_utils::mb1_to_meas(snd, ai[0], trn_type[0], &gcon);
if (pt != nullptr && mt != nullptr) {
diff --git a/src/mbtrnav/opt/rov/plug-lassmb.cpp b/src/mbtrnav/opt/rov/plug-lassmb.cpp
index a7444adf3..8d4a75860 100644
--- a/src/mbtrnav/opt/rov/plug-lassmb.cpp
+++ b/src/mbtrnav/opt/rov/plug-lassmb.cpp
@@ -190,8 +190,6 @@ int cb_proto_mblass(void *pargs)
TRN_NDPRINT(5, "%s:%d processing ctx[%s]\n", __func__, __LINE__, ctx->ctx_key().c_str());
- int err_count = 0;
-
std::string *bkey[2] = {ctx->bath_input_chan(0), ctx->bath_input_chan(1)};
std::string *nkey = ctx->nav_input_chan(0);
std::string *akey[2] = {ctx->att_input_chan(0), ctx->att_input_chan(1)};
@@ -208,7 +206,6 @@ int cb_proto_mblass(void *pargs)
ss << (akey[1]==nullptr ? " akey[1]" : "");
ss << (nkey==nullptr ? " nkey" : "");
TRN_NDPRINT(5, "%s:%d WARN - NULL input key: %s\n", __func__, __LINE__, ss.str().c_str());
- err_count++;
continue;
}
@@ -229,7 +226,6 @@ int cb_proto_mblass(void *pargs)
ss << (ni==nullptr ? " ni" : "");
ss << (vi==nullptr ? " vi" : "");
TRN_NDPRINT(5, "%s:%d WARN - NULL info instance: %s\n", __func__, __LINE__, ss.str().c_str());
- err_count++;
}
if(bkey[0] != nullptr && bi[0] != nullptr)
@@ -297,8 +293,9 @@ int cb_proto_mblass(void *pargs)
if(ctx->trncli_count() > 0){
// publish poseT/measT to trn-server
- poseT *pt = trnx_utils::mb1_to_pose(snd, ai[0], (long)ctx->utm_zone());
- measT *mt = trnx_utils::mb1_to_meas(snd, ai[0], trn_type[1], (long)ctx->utm_zone());
+ GeoCon gcon(ctx->utm_zone());
+ poseT *pt = trnx_utils::mb1_to_pose(snd, ai[0], NULL, &gcon);
+ measT *mt = trnx_utils::mb1_to_meas(snd, ai[0], trn_type[1], &gcon);
if(pt != nullptr && mt != nullptr){
diff --git a/src/mbtrnav/opt/rov/plug-oisled.cpp b/src/mbtrnav/opt/rov/plug-oisled.cpp
index 220257a69..9d03b3d91 100644
--- a/src/mbtrnav/opt/rov/plug-oisled.cpp
+++ b/src/mbtrnav/opt/rov/plug-oisled.cpp
@@ -186,8 +186,6 @@ int cb_proto_oisled(void *pargs) // dec 2022
TRN_NDPRINT(5, "%s:%d processing ctx[%s]\n", __func__, __LINE__, ctx->ctx_key().c_str());
- int err_count = 0;
-
std::string *bkey[2] = {ctx->bath_input_chan(0), ctx->bath_input_chan(1)};
std::string *nkey = ctx->nav_input_chan(0);
std::string *akey[2] = {ctx->att_input_chan(0), ctx->att_input_chan(1)};
@@ -203,7 +201,6 @@ int cb_proto_oisled(void *pargs) // dec 2022
ss << (akey[1]==nullptr ? " akey[1]" : "");
ss << (nkey==nullptr ? " nkey" : "");
TRN_NDPRINT(5, "%s:%d WARN - NULL input key: %s\n", __func__, __LINE__, ss.str().c_str());
- err_count++;
continue;
}
@@ -222,7 +219,6 @@ int cb_proto_oisled(void *pargs) // dec 2022
ss << (ni==nullptr ? " ni" : "");
ss << (vi==nullptr ? " vi" : "");
TRN_NDPRINT(5, "%s:%d WARN - NULL info instance\n", __func__, __LINE__);
- err_count++;
}
if(bkey[0] != nullptr && bi[0]!=nullptr)
@@ -279,8 +275,9 @@ int cb_proto_oisled(void *pargs) // dec 2022
if(ctx->trncli_count() > 0){
// publish poseT/measT to trn-server
- poseT *pt = trnx_utils::mb1_to_pose(snd, ai[0], (long)ctx->utm_zone());
- measT *mt = trnx_utils::mb1_to_meas(snd, ai[0], trn_type[1], (long)ctx->utm_zone());
+ GeoCon gcon(ctx->utm_zone());
+ poseT *pt = trnx_utils::mb1_to_pose(snd, ai[0],NULL, &gcon);
+ measT *mt = trnx_utils::mb1_to_meas(snd, ai[0], trn_type[1], &gcon);
if(pt != nullptr && mt != nullptr){
diff --git a/src/mbtrnav/opt/rov/plug-oisled2.cpp b/src/mbtrnav/opt/rov/plug-oisled2.cpp
index 30f74099e..313f4b419 100644
--- a/src/mbtrnav/opt/rov/plug-oisled2.cpp
+++ b/src/mbtrnav/opt/rov/plug-oisled2.cpp
@@ -190,8 +190,6 @@ int cb_proto_oisled2(void *pargs)
TRN_NDPRINT(5, "%s:%d processing ctx[%s]\n", __func__, __LINE__, ctx->ctx_key().c_str());
- int err_count = 0;
-
std::string *bkey[2] = {ctx->bath_input_chan(0), ctx->bath_input_chan(1)};
std::string *nkey = ctx->nav_input_chan(0);
std::string *akey[2] = {ctx->att_input_chan(0), ctx->att_input_chan(1)};
@@ -208,7 +206,6 @@ int cb_proto_oisled2(void *pargs)
ss << (akey[1]==nullptr ? " akey[1]" : "");
ss << (nkey==nullptr ? " nkey" : "");
TRN_NDPRINT(5, "%s:%d WARN - NULL input key: %s\n", __func__, __LINE__, ss.str().c_str());
- err_count++;
continue;
}
@@ -229,7 +226,6 @@ int cb_proto_oisled2(void *pargs)
ss << (ni==nullptr ? " ni" : "");
ss << (vi==nullptr ? " vi" : "");
TRN_NDPRINT(5, "%s:%d WARN - NULL info instance: %s\n", __func__, __LINE__, ss.str().c_str());
- err_count++;
}
if(bkey[0] != nullptr && bi[0] != nullptr)
@@ -296,8 +292,9 @@ int cb_proto_oisled2(void *pargs)
if(ctx->trncli_count() > 0){
// publish poseT/measT to trn-server
- poseT *pt = trnx_utils::mb1_to_pose(snd, ai[0], (long)ctx->utm_zone());
- measT *mt = trnx_utils::mb1_to_meas(snd, ai[0], trn_type[1], (long)ctx->utm_zone());
+ GeoCon gcon(ctx->utm_zone());
+ poseT *pt = trnx_utils::mb1_to_pose(snd, ai[0], NULL, &gcon);
+ measT *mt = trnx_utils::mb1_to_meas(snd, ai[0], trn_type[1], &gcon);
if(pt != nullptr && mt != nullptr){
diff --git a/src/mbtrnav/opt/rov/plug-oisledx.cpp b/src/mbtrnav/opt/rov/plug-oisledx.cpp
index b4b30387f..89b836f85 100644
--- a/src/mbtrnav/opt/rov/plug-oisledx.cpp
+++ b/src/mbtrnav/opt/rov/plug-oisledx.cpp
@@ -197,8 +197,6 @@ int cb_proto_oisledx(void *pargs)
TRN_NDPRINT(5, "%s:%d processing ctx[%s]\n", __func__, __LINE__, ctx->ctx_key().c_str());
- int err_count = 0;
-
std::string *bkey[2] = {ctx->bath_input_chan(0), ctx->bath_input_chan(1)};
std::string *nkey = ctx->nav_input_chan(0);
std::string *akey[2] = {ctx->att_input_chan(0), ctx->att_input_chan(1)};
@@ -215,7 +213,6 @@ int cb_proto_oisledx(void *pargs)
ss << (akey[1]==nullptr ? " akey[1]" : "");
ss << (nkey==nullptr ? " nkey" : "");
TRN_NDPRINT(5, "%s:%d WARN - NULL input key: %s\n", __func__, __LINE__, ss.str().c_str());
- err_count++;
continue;
}
@@ -236,7 +233,6 @@ int cb_proto_oisledx(void *pargs)
ss << (ni==nullptr ? " ni" : "");
ss << (vi==nullptr ? " vi" : "");
TRN_NDPRINT(5, "%s:%d WARN - NULL info instance: %s\n", __func__, __LINE__, ss.str().c_str());
- err_count++;
}
if(bkey[0] != nullptr && bi[0] != nullptr)
@@ -303,8 +299,9 @@ int cb_proto_oisledx(void *pargs)
if(ctx->trncli_count() > 0){
// publish poseT/measT to trn-server
- poseT *pt = trnx_utils::mb1_to_pose(snd, ai[0], (long)ctx->utm_zone());
- measT *mt = trnx_utils::mb1_to_meas(snd, ai[0], trn_type[1], (long)ctx->utm_zone());
+ GeoCon gcon(ctx->utm_zone());
+ poseT *pt = trnx_utils::mb1_to_pose(snd, ai[0], NULL, &gcon);
+ measT *mt = trnx_utils::mb1_to_meas(snd, ai[0], trn_type[1], &gcon);
if(pt != nullptr && mt != nullptr){
diff --git a/src/mbtrnav/opt/rov/plug-xmb1.cpp b/src/mbtrnav/opt/rov/plug-xmb1.cpp
index ee7bc403d..8d2eef564 100644
--- a/src/mbtrnav/opt/rov/plug-xmb1.cpp
+++ b/src/mbtrnav/opt/rov/plug-xmb1.cpp
@@ -187,8 +187,6 @@ int cb_proto_xmb1(void *pargs)
TRN_NDPRINT(5, "%s:%d processing ctx[%s]\n", __func__, __LINE__, ctx->ctx_key().c_str());
- int err_count = 0;
-
std::string *bkey[1] = {ctx->mb1_input_chan(0)};
std::string *nkey = ctx->nav_input_chan(0);
std::string *akey[2] = {ctx->att_input_chan(0), ctx->att_input_chan(1)};
@@ -203,7 +201,6 @@ int cb_proto_xmb1(void *pargs)
ss << (akey[1] == nullptr ? " akey[1]" : "");
ss << (nkey == nullptr ? " nkey" : "");
TRN_NDPRINT(5, "%s:%d WARN - NULL input key: %s\n", __func__, __LINE__, ss.str().c_str());
- err_count++;
continue;
}
@@ -222,7 +219,6 @@ int cb_proto_xmb1(void *pargs)
ss << (ni == nullptr ? " ni" : "");
ss << (vi == nullptr ? " vi" : "");
TRN_NDPRINT(5, "%s:%d WARN - NULL info instance: %s\n", __func__, __LINE__, ss.str().c_str());
- err_count++;
}
TRN_TRACE();
@@ -280,8 +276,9 @@ int cb_proto_xmb1(void *pargs)
if(ctx->trncli_count() > 0){
// publish poseT/measT to trn-server
- poseT *pt = trnx_utils::mb1_to_pose(snd, ai[0], (long)ctx->utm_zone());
- measT *mt = trnx_utils::mb1_to_meas(snd, ai[0], trn_type[0], (long)ctx->utm_zone());
+ GeoCon gcon(ctx->utm_zone());
+ poseT *pt = trnx_utils::mb1_to_pose(snd, ai[0], NULL, &gcon);
+ measT *mt = trnx_utils::mb1_to_meas(snd, ai[0], trn_type[0], &gcon);
if(pt != nullptr && mt != nullptr){
diff --git a/src/mbtrnav/opt/rov/trnx_plugin.hpp b/src/mbtrnav/opt/rov/trnx_plugin.hpp
index 83ad503e2..2cf8e48f5 100644
--- a/src/mbtrnav/opt/rov/trnx_plugin.hpp
+++ b/src/mbtrnav/opt/rov/trnx_plugin.hpp
@@ -4,6 +4,7 @@
#include "trnxpp.hpp"
#include "trn_debug.hpp"
#include "trnx_utils.hpp"
+#include "GeoCon.h"
#ifndef TRNX_PLUGIN_H
#define TRNX_PLUGIN_H
diff --git a/src/mbtrnav/opt/rov/trnx_utils.hpp b/src/mbtrnav/opt/rov/trnx_utils.hpp
index 76de801b4..3ced9f770 100644
--- a/src/mbtrnav/opt/rov/trnx_utils.hpp
+++ b/src/mbtrnav/opt/rov/trnx_utils.hpp
@@ -41,11 +41,11 @@
#include "trn_debug.hpp"
#include "geo_cfg.hpp"
#include "NavUtils.h"
+#include "GeoCon.h"
// /////////////////
// Macros
-
#ifndef DTR
#define DTR(x) ((x) * M_PI/180.)
#endif
@@ -311,8 +311,8 @@ class trnx_utils
std::list mBeamList = bi->beams_raw();
std::list::iterator it;
- int k=0;
- for(it=mBeamList.begin(); it!=mBeamList.end(); k++)
+
+ for(it=mBeamList.begin(); it!=mBeamList.end(); )
{
trn::beam_tup bt = static_cast (*it);
os << std::get<0>(bt) << "," << std::get<1>(bt);
@@ -407,8 +407,8 @@ class trnx_utils
std::list mBeamList = bi->beams_raw();
std::list::iterator it;
- int k=0;
- for(it=mBeamList.begin(); it!=mBeamList.end(); k++)
+
+ for(it=mBeamList.begin(); it!=mBeamList.end(); )
{
trn::beam_tup bt = static_cast (*it);
os << std::setw(wkey) << "[" << std::get<0>(bt) << "]";
@@ -1844,8 +1844,8 @@ class trnx_utils
ss << std::setprecision(4);
std::list::iterator it;
std::listbeam_list = bi->beams_raw();
- int k=0;
- for(it=beam_list.begin(); it!=beam_list.end(); k++)
+
+ for(it=beam_list.begin(); it!=beam_list.end();)
{
trn::beam_tup bt = static_cast (*it);
double range = std::get<1>(bt);
@@ -1946,13 +1946,13 @@ class trnx_utils
// returns new poseT; caller must release
// no vi arg for backwards compatibility with older handlers
// TODO: bring old handlers up to date with new mb1_to_pose
- static poseT *mb1_to_pose(mb1_t *src, trn::att_info *ai, long int utmZone)
- {
- return mb1_to_pose(src, ai, NULL, utmZone);
-
- }
+// static poseT *mb1_to_pose(mb1_t *src, trn::att_info *ai, long int utmZone)
+// {
+// return mb1_to_pose(src, ai, NULL, utmZone);
+//
+// }
- static poseT *mb1_to_pose(mb1_t *src, trn::att_info *ai, trn::vel_info *vi, long int utmZone)
+ static poseT *mb1_to_pose(mb1_t *src, trn::att_info *ai, trn::vel_info *vi, GeoCon *geocon)
{
if(nullptr == src)
return nullptr;
@@ -1963,9 +1963,9 @@ class trnx_utils
obj->time = src->ts;
- NavUtils::geoToUtm( Math::degToRad(src->lat),
+ geocon->geo_to_mp(Math::degToRad(src->lat),
Math::degToRad(src->lon),
- utmZone, &(obj->x), &(obj->y));
+ &(obj->x), &(obj->y));
obj->z = src->depth;
obj->phi = ai->roll();
@@ -2021,7 +2021,7 @@ class trnx_utils
}
// returns new measT; caller must release
- static measT *mb1_to_meas(mb1_t *src, trn::att_info *ai, int data_type, long int utmZone)
+ static measT *mb1_to_meas(mb1_t *src, trn::att_info *ai, int data_type, GeoCon *geocon)
{
if(nullptr == src)
return nullptr;
@@ -2038,9 +2038,9 @@ class trnx_utils
obj->psi = src->hdg;
obj->z = src->depth;
- NavUtils::geoToUtm( Math::degToRad(src->lat),
+ geocon->geo_to_mp(Math::degToRad(src->lat),
Math::degToRad(src->lon),
- utmZone, &(obj->x), &(obj->y));
+ &(obj->x), &(obj->y));
for(int i = 0; i < obj->numMeas; i++){
// TODO: fill in measT from ping...
diff --git a/src/mbtrnav/opt/rov/trnxpp_ctx.hpp b/src/mbtrnav/opt/rov/trnxpp_ctx.hpp
index 6e8e5c032..03b2033f9 100644
--- a/src/mbtrnav/opt/rov/trnxpp_ctx.hpp
+++ b/src/mbtrnav/opt/rov/trnxpp_ctx.hpp
@@ -1212,8 +1212,6 @@ class trnxpp_ctx
if(nullptr == sounding)
return retval;
- int err_count = 0;
-
if(mMB1SvrList.size() <= 0){
return 0;
}
@@ -1224,7 +1222,6 @@ class trnxpp_ctx
std::string key = std::get<0>(*it);
void *vp = std::get<5>(*it);
if(vp == nullptr){
- err_count++;
continue;
}
diff --git a/src/mbtrnav/trnw/GeoCon.cpp b/src/mbtrnav/trnw/GeoCon.cpp
new file mode 100644
index 000000000..6b7c57dbf
--- /dev/null
+++ b/src/mbtrnav/trnw/GeoCon.cpp
@@ -0,0 +1,596 @@
+// GeoCon.cpp
+//
+// GeoCon geo coordinate transformation implentation
+
+#include
+#include
+#include
+#include
+
+#include "GeoCon.h"
+#include "GeoCon.hpp"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+GeoConIF::GeoConIF()
+: m_type(GEO_UNKNOWN)
+, m_debug(0)
+{}
+
+void *GeoConIF::get_member(const char *key)
+{
+ std::cerr << __func__ << " not implemented for type " << typestr() << std::endl;
+ return nullptr;
+}
+
+int GeoConIF::set_member(const char *key, void *value)
+{
+ std::cerr << __func__ << " not implemented for type " << typestr() << std::endl;
+ return -1;
+}
+
+ void GeoConIF::auto_delete(const char *key, bool enable)
+{
+ std::cerr << __func__ << " not implemented for type " << typestr() << std::endl;
+}
+
+ void *GeoConIF::init(int argc, void **argv)
+{
+ std::cerr << __func__ << " not implemented for type " << typestr() << std::endl;
+ return nullptr;
+}
+
+GeoConType GeoConIF::type()
+{
+ return m_type;
+}
+
+ const char *GeoConIF::typestr()
+{
+ static const char *geotype_str[GEO_TYPES] =
+ {
+ "UNKNOWN","GCTP","PROJ"
+ };
+
+ if(m_type == GEO_GCTP)
+ return geotype_str[1];
+ if(m_type == GEO_PROJ)
+ return geotype_str[2];
+
+ return geotype_str[0];
+}
+
+void GeoConIF::set_debug(int level)
+{
+ m_debug = level;
+}
+
+int GeoConIF::debug()
+{
+ return m_debug;
+}
+
+#ifdef TRN_USE_PROJ
+
+GeoConProj::GeoConProj()
+: m_tcrs(nullptr)
+, m_proj_xfm(nullptr)
+, m_auto_delete_xfm(true)
+{
+ m_scrs = strdup(GEOIF_SCRS_DFL);
+ m_type = GEO_PROJ;
+}
+
+GeoConProj::GeoConProj(const char *tcrs)
+: m_proj_xfm(nullptr)
+, m_auto_delete_xfm(true)
+{
+ m_scrs = strdup(GEOIF_SCRS_DFL);
+ m_tcrs = (tcrs == NULL ? NULL : strdup(tcrs));
+ m_type = GEO_PROJ;
+}
+
+GeoConProj::GeoConProj(void *xfm, bool autodel)
+: m_proj_xfm(xfm)
+, m_tcrs(NULL)
+, m_auto_delete_xfm(autodel)
+{
+ m_scrs = strdup(GEOIF_SCRS_DFL);
+ m_type = GEO_PROJ;
+}
+
+GeoConProj::GeoConProj(void *xfm, bool autodel, const char *tcrs, const char *scrs)
+: m_proj_xfm(xfm)
+, m_auto_delete_xfm(autodel)
+{
+ m_scrs = scrs != NULL ? strdup(scrs) : strdup(GEOIF_SCRS_DFL);
+ m_tcrs = (tcrs == NULL ? NULL : strdup(tcrs));
+ m_type = GEO_PROJ;
+}
+
+GeoConProj::~GeoConProj()
+{
+ free(m_tcrs);
+ free(m_scrs);
+
+ if(m_auto_delete_xfm && m_proj_xfm != nullptr) {
+ proj_destroy((PJ *)m_proj_xfm);
+ }
+}
+
+int GeoConProj::geo_to_mp(double lat_rad, double lon_rad, double *r_northing_m, double *r_easting_m)
+{
+ if(r_northing_m == NULL || r_easting_m == NULL) {
+ std::cerr << typestr() << "::" << __func__ << " ERR invalid argument (NULL)" << std::endl;
+ return -1;
+ }
+
+ PJ_COORD cin = proj_coord(Math::radToDeg(lon_rad), Math::radToDeg(lat_rad), 0, 0);
+ PJ_COORD cout = proj_trans((PJ *)m_proj_xfm, PJ_FWD, cin);
+
+ // set output
+ *r_easting_m = cout.v[0];
+ *r_northing_m = cout.v[1];
+
+ if(debug() != 0)
+ std::cerr << typestr() << "::" << __func__ << " E,N: " << *r_easting_m << ", " << *r_northing_m << std::endl;
+ return 0;
+}
+
+int GeoConProj::mp_to_geo(double northing_m, double easting_m, double *r_lat_rad, double *r_lon_rad)
+{
+ if(r_lat_rad == NULL || r_lon_rad == NULL) {
+ std::cerr << typestr() << "::" << __func__ << " ERR invalid argument (NULL)" << std::endl;
+ return -1;
+ }
+
+ PJ_COORD cin = proj_coord(easting_m, northing_m, 0, 0);
+ PJ_COORD cout = proj_trans((PJ *)m_proj_xfm, PJ_INV, cin);
+
+ // set output
+ *r_lon_rad = Math::degToRad(cout.v[0]);
+ *r_lat_rad = Math::degToRad(cout.v[1]);
+
+ if(debug() != 0)
+ std::cerr << typestr() << "::" << __func__ << " lat,lon: " << Math::radToDeg(*r_lat_rad) << ", " << Math::radToDeg(*r_lon_rad) << std::endl;
+
+ return 0;
+}
+
+// key "XFM" returns (PJ *) m_proj_xfm
+void *GeoConProj::get_member(const char *key)
+{
+ if(strcasecmp(key, "XFM") == 0)
+ return m_proj_xfm;
+ if(strcasecmp(key, "SCRS") == 0)
+ return m_scrs;
+ if(strcasecmp(key, "TCRS") == 0)
+ return m_tcrs;
+ return nullptr;
+}
+
+int GeoConProj::set_member(const char *key, void *value)
+{
+ if(strcasecmp(key, "XFM") == 0) {
+ m_proj_xfm = value;
+ return 0;
+ } else if(strcasecmp(key, "SCRS") == 0) {
+ free(m_scrs);
+ m_scrs = strdup((const char *)value);
+ return 0;
+ }
+ if(strcasecmp(key, "TCRS") == 0) {
+ free(m_tcrs);
+ m_tcrs = strdup((const char *)value);
+ return 0;
+ }
+ return -1;
+}
+
+// default transform initialization
+// argv[0] : const char * : target crs
+// argv[1] : const char * : source crs
+void *GeoConProj::init(int argc, void **argv)
+{
+ const char *source_crs = (m_scrs != NULL ? m_scrs : GEOIF_SCRS_DFL);
+ const char *target_crs = (m_tcrs != NULL ? m_tcrs : GEOIF_TCRS_DFL);
+
+ if(argc > 0 && argv != nullptr) {
+ for(int i = 0; i < argc; i++)
+ {
+ if(i == 0 && argv[1] != nullptr) {
+ target_crs = (const char *)argv[i];
+
+ if(m_tcrs != nullptr)
+ free(m_tcrs);
+ m_tcrs = strdup(target_crs);
+
+ } else if(i == 1 && argv[i] != nullptr) {
+ source_crs = (const char *)argv[i];
+
+ if(m_scrs != nullptr)
+ free(m_scrs);
+ m_scrs = strdup(source_crs);
+ } else {
+ break;
+ }
+ }
+ }
+
+ if(debug() != 0)
+ std::cerr << typestr() << "::" << __func__ << " scrs: " << source_crs << " tcrs: " << target_crs << std::endl;
+
+ PJ *p = proj_create_crs_to_crs(PJ_DEFAULT_CTX, source_crs, target_crs, 0);
+
+ if(p != NULL){
+ m_proj_xfm = (void *) proj_normalize_for_visualization(PJ_DEFAULT_CTX, p);
+
+ if(debug() != 0)
+ std::cerr << typestr() << "::" << __func__ << " m_proj_xfm: " << (void *)m_proj_xfm << std::endl;
+
+ } else {
+ fprintf(stderr, "%s:%d - ERR proj_create_crs_to_crs failed src: %s tgt: %s\n", __func__, __LINE__, source_crs, target_crs);
+ }
+ return m_proj_xfm;
+}
+
+// key "XFM" sets auto delete for m_proj_xfm
+void GeoConProj::auto_delete(const char *key, bool enable)
+{
+ if(strcasecmp(key, "XFM") == 0)
+ m_auto_delete_xfm = enable;
+}
+#endif
+
+GeoConGCTP::GeoConGCTP()
+: m_utm(10)
+{
+ m_type = GEO_GCTP;
+}
+
+GeoConGCTP::GeoConGCTP(long int utm)
+: m_utm(utm)
+{
+ m_type = GEO_GCTP;
+}
+
+GeoConGCTP::~GeoConGCTP()
+{}
+
+int GeoConGCTP::geo_to_mp(double lat_rad, double lon_rad, double *r_northing, double *r_easting)
+{
+ if(debug() != 0)
+ std::cerr << typestr() << "::" << __func__ << " utm:" << m_utm << std::endl;
+
+ if(r_northing == NULL || r_easting == NULL) {
+ std::cerr << typestr() << "::" << __func__ << " ERR invalid argument (NULL)" << std::endl;
+ return -1;
+ }
+
+ int retval = NavUtils::geoToUtm(lat_rad, lon_rad, m_utm, r_northing, r_easting);
+
+ if(debug() != 0)
+ std::cerr << typestr() << "::" << __func__ << " ret:" << retval << " E,N: " << *r_easting << ", " << *r_northing << std::endl;
+
+ return retval;
+}
+
+int GeoConGCTP::mp_to_geo(double northing_m, double easting_m, double *r_lat_rad, double *r_lon_rad)
+{
+ if(debug() != 0)
+ std::cerr << typestr() << "::" << __func__ << " utm:" << m_utm << std::endl;
+
+ if(r_lat_rad == NULL || r_lon_rad == NULL)
+ return -1;
+
+ int retval = NavUtils::utmToGeo(northing_m, easting_m, m_utm, r_lat_rad, r_lon_rad);
+
+ if(debug() != 0)
+ std::cerr << typestr() << "::" << __func__ << " ret: " << retval << " lat,lon: " << Math::radToDeg(*r_lat_rad) << ", " << Math::radToDeg(*r_lon_rad) << std::endl;
+
+ return retval;
+}
+
+GeoCon::GeoCon()
+: m_geocon(nullptr)
+{}
+
+// implementation backed by GCTP library (via NavUtils)
+GeoCon::GeoCon(long int utm)
+{
+ // create a GCTP instance
+ m_geocon = new GeoConGCTP(utm);
+}
+
+#ifdef TRN_USE_PROJ
+// implementation backed by libproj coordinate transform (PJ *)
+GeoCon::GeoCon(const char *tcrs)
+{
+ // create a PROJ instance
+ m_geocon = new GeoConProj(tcrs);
+}
+
+GeoCon::GeoCon(void *xfm, bool autodel, const char *tcrs, const char *scrs)
+{
+ // create a PROJ instance
+ m_geocon = new GeoConProj(xfm, autodel, tcrs, scrs);
+}
+
+GeoCon::GeoCon(void *xfm, bool autodel)
+{
+ // create a PROJ instance
+ m_geocon = new GeoConProj(xfm, autodel);
+}
+#else
+// if libproj is not available, disable proj implementation
+GeoCon::GeoCon(const char *tcrs)
+: m_geocon(nullptr)
+{
+ std::cerr << __func__ << ": ERR proj not supported; build using -DTRN_USE_PROJ" << std::endl;
+}
+#endif
+
+GeoCon::~GeoCon()
+{
+ if(m_geocon != nullptr)
+ delete m_geocon;
+}
+
+// lat/lon to mercator projection
+int GeoCon::geo_to_mp(double lat_rad, double lon_rad, double *r_northing_m, double *r_easting_m)
+{
+ if(m_geocon == NULL) {
+ std::cerr << __func__ << ": ERR NULL instance" << std::endl;
+ return -1;
+ }
+
+ return m_geocon->geo_to_mp(lat_rad, lon_rad, r_northing_m, r_easting_m);
+}
+
+// mercator projection to lat/lon
+int GeoCon::mp_to_geo(double northing_m, double easting_m, double *r_lat_rad, double *r_lon_rad)
+{
+ if(m_geocon == NULL) {
+ std::cerr << __func__ << ": ERR NULL instance" << std::endl;
+ return -1;
+ }
+
+ return m_geocon->mp_to_geo(northing_m, easting_m, r_lat_rad, r_lon_rad);
+}
+
+// get a pointer to a member (optional; keys defined per implementation)
+void *GeoCon::get_member(const char *key)
+{
+ if(m_geocon == NULL) {
+ std::cerr << __func__ << ": ERR NULL instance" << std::endl;
+ return nullptr;
+ }
+ return m_geocon->get_member(key);
+}
+
+int GeoCon::set_member(const char *key, void *value)
+{
+ if(m_geocon == NULL) {
+ std::cerr << __func__ << ": ERR NULL instance" << std::endl;
+ return -1;
+ }
+ return m_geocon->set_member(key, value);
+}
+
+// initialize (optional; argments defined per implementation)
+void *GeoCon::init(int argc, void **argv)
+{
+ if(m_geocon == NULL) {
+ std::cerr << __func__ << ": ERR NULL instance" << std::endl;
+ return nullptr;
+ }
+ return m_geocon->init(argc, argv);
+}
+
+// enable/disable deletion of members (optional; keys defined per implementation)
+void GeoCon::auto_delete(const char *key, bool enable)
+{
+ if(m_geocon == NULL) {
+ std::cerr << __func__ << ": ERR NULL instance" << std::endl;
+ return;
+ }
+
+ m_geocon->auto_delete(key, enable);
+}
+
+// get string representation of underlying type
+const char *GeoCon::typestr()
+{
+ if(m_geocon == NULL) {
+ return "UNKNOWN";
+ }
+ return m_geocon->typestr();
+}
+
+void GeoCon::set_debug(int level)
+{
+ if(m_geocon == NULL) {
+ return;
+ }
+ m_geocon->set_debug(level);
+}
+
+int GeoCon::debug()
+{
+ if(m_geocon == NULL) {
+ return -1;
+ }
+ return m_geocon->debug();
+}
+
+struct wgeocon_s {
+ void *obj;
+};
+
+wgeocon_t *wgeocon_new_gctp(long int utm)
+{
+ wgeocon_t *m = (wgeocon_t *)malloc(sizeof(*m));
+ if(NULL!=m){
+ memset(m,0,sizeof(*m));
+ GeoCon *obj = new GeoCon(utm);
+ m->obj = obj;
+ }
+ return m;
+}
+
+wgeocon_t *wgeocon_new_proj(const char *crs)
+{
+ wgeocon_t *m = (wgeocon_t *)malloc(sizeof(*m));
+ if(NULL!=m){
+ memset(m,0,sizeof(*m));
+ GeoCon *obj = new GeoCon(crs);
+ m->obj = obj;
+ }
+ return m;
+}
+
+wgeocon_t *wgeocon_inew_proj(void *xfm, bool autodel, const char *tcrs, const char *scrs)
+{
+ wgeocon_t *m = (wgeocon_t *)malloc(sizeof(*m));
+ if(NULL!=m){
+ memset(m,0,sizeof(*m));
+ GeoCon *obj = new GeoCon(xfm, autodel, tcrs, scrs);
+ m->obj = obj;
+ }
+ return m;
+}
+
+wgeocon_t *wgeocon_xnew_proj(void *xfm, bool autodel)
+{
+ wgeocon_t *m = (wgeocon_t *)malloc(sizeof(*m));
+ if(NULL!=m){
+ memset(m,0,sizeof(*m));
+ GeoCon *obj = new GeoCon(xfm, autodel);
+ m->obj = obj;
+ }
+ return m;
+}
+void wgeocon_delete(wgeocon_t *self)
+{
+ if (NULL!=self){
+ delete static_cast(self->obj);
+ free(self);
+ }
+}
+
+GeoConType wgeocon_type(wgeocon_t *self)
+{
+ if(NULL!=self){
+ GeoCon *obj = static_cast(self->obj);
+ if(obj != NULL) {
+ return obj->type();
+ }
+ }
+ return GEO_UNKNOWN;
+}
+
+const char *wgeocon_typestr(wgeocon_t *self)
+{
+ if(NULL!=self){
+ GeoCon *obj = static_cast(self->obj);
+ if(obj != NULL) {
+ return obj->typestr();
+ }
+ }
+ return NULL;
+}
+
+void wgeocon_set_debug(wgeocon_t *self, int level)
+{
+ if(NULL!=self){
+ GeoCon *obj = static_cast(self->obj);
+ if(obj != NULL) {
+ return obj->set_debug(level);
+ }
+ }
+}
+int wgeocon_debug(wgeocon_t *self)
+{
+ if(NULL!=self){
+ GeoCon *obj = static_cast(self->obj);
+ if(obj != NULL) {
+ return obj->debug();
+ }
+ }
+ return -1;
+}
+
+int wgeocon_geo_to_mp(wgeocon_t *self, double lat_rad, double lon_rad, double *r_northing_m, double *r_easting_m)
+{
+ if(NULL!=self){
+ GeoCon *obj = static_cast(self->obj);
+ if(obj != NULL) {
+ return obj->geo_to_mp(lat_rad, lon_rad, r_northing_m, r_easting_m);
+ }
+ }
+ return -1;
+}
+
+int wgeocon_mp_to_geo(wgeocon_t *self, double northing_m, double easting_m, double *r_lat_rad, double *r_lon_rad)
+{
+ if(NULL!=self){
+ GeoCon *obj = static_cast(self->obj);
+ if(obj != NULL) {
+ return obj->mp_to_geo(northing_m, easting_m, r_lat_rad, r_lon_rad);
+ }
+ }
+ return -1;
+}
+
+int wgeocon_navutils_geoToUtm(double lat_rad, double lon_rad, long int utm_zone, double *r_northing_m, double *r_easting_m)
+{
+ return NavUtils::geoToUtm(lat_rad, lon_rad, utm_zone, r_northing_m, r_easting_m);
+}
+
+void *wgeocon_get_member(wgeocon_t *self, const char *key)
+{
+ if(NULL!=self){
+ GeoCon *obj = static_cast(self->obj);
+ if(obj != NULL) {
+ return obj->get_member(key);
+ }
+ }
+ return NULL;
+}
+
+int wgeocon_set_member(wgeocon_t *self, const char *key, void *value)
+{
+ if(NULL!=self){
+ GeoCon *obj = static_cast(self->obj);
+ if(obj != NULL) {
+ return obj->set_member(key, value);
+ }
+ }
+ return -1;
+}
+
+void wgeocon_auto_delete(wgeocon_t *self, const char *key, bool enable)
+{
+ if(NULL!=self){
+ GeoCon *obj = static_cast(self->obj);
+ if(obj != NULL) {
+ obj->auto_delete(key, enable);
+ }
+ }
+}
+
+void *wgeocon_init(wgeocon_t *self, int argc, void **argv)
+{
+ if(NULL!=self){
+ GeoCon *obj = static_cast(self->obj);
+ if(obj != NULL) {
+ return obj->init(argc, argv);
+ }
+ }
+ return NULL;
+}
+#ifdef __cplusplus
+}
+#endif
diff --git a/src/mbtrnav/trnw/GeoCon.h b/src/mbtrnav/trnw/GeoCon.h
new file mode 100644
index 000000000..25a4ad7e4
--- /dev/null
+++ b/src/mbtrnav/trnw/GeoCon.h
@@ -0,0 +1,97 @@
+// GeoCon.hpp
+//
+// C API for GeoCon class
+// Wraps GCTP and Proj geo coordinate transformations
+// i.e. lat/lon <> mercator projection, e.g. utm).
+// See also GeoCon.hpp
+
+#include
+#include
+#ifdef TRN_USE_PROJ
+#include
+#endif
+
+#ifndef GEOCON_H
+#define GEOCON_H
+
+// CRS: UTM10N (Monterey Bay)
+#define GEOIF_TCRS_UTM10N "EPSG:32610"
+// CRS: UTM9N (Axial Seamount)
+#define GEOIF_TCRS_UTM9N "EPSG:32609"
+
+// default source CRS (lon/lat using WGS84)"
+#define GEOIF_SCRS_DFL "+proj=lonlat +datum=WGS84"
+// default target CRS (UTM zone 10N)
+#define GEOIF_TCRS_DFL GEOIF_TCRS_UTM10N
+
+// GeoCon implentation ID type
+typedef enum {
+ GEO_UNKNOWN,
+ GEO_GCTP,
+ GEO_PROJ,
+ GEO_TYPES
+}GeoConType;
+
+// C GeoCon instance type
+struct wgeocon_s;
+typedef struct wgeocon_s wgeocon_t;
+
+// GeoCon callback function types; alternative to GeoCon API and wrappers
+// supported by trnw, trn_cli
+// Application provides coordinate conversion callbacks using library of choice (GCTP, PROJ, etc.)
+typedef int (*GeoToTMCallback)(double lat_rad, double lon_rad, double *r_northing_m, double *r_easting_m);
+typedef int (*TMToGeoCallback)(double northing_m, double easting_m, double *r_lat_rad, double *r_lon_rad);
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// GeoCon C API
+
+// GCTP instance (caller must free using wgeocon_destroy)
+wgeocon_t *wgeocon_new_gctp(long int utm);
+
+// PROJ instance (caller must free using wgeocon_destroy)
+wgeocon_t *wgeocon_new_proj(const char *tcrs);
+wgeocon_t *wgeocon_inew_proj(void *xfm, bool autodel, const char *tcrs, const char *scrs);
+wgeocon_t *wgeocon_xnew_proj(void *xfm, bool autodel);
+
+// release GeoConverter instance
+void wgeocon_delete(wgeocon_t *self);
+
+// get implentation type ID
+GeoConType wgeocon_type(wgeocon_t *self);
+
+// get implentation type name
+const char *wgeocon_typestr(wgeocon_t *self);
+// set debug level
+void wgeocon_set_debug(wgeocon_t *self, int debug);
+// get debug level
+int wgeocon_debug(wgeocon_t *self);
+
+// lat/lon to mercator projection
+int wgeocon_geo_to_mp(wgeocon_t *self, double lat_rad, double lon_rad, double *r_northing_m, double *r_easting_m);
+
+// mercator projection to lat/lon
+int wgeocon_mp_to_geo(wgeocon_t *self, double northing_m, double easting_m, double *r_lat_rad, double *r_lon_rad);
+
+// lat/lon to mercator projection (wraps NavUtils::GeoToUtm directly, w/o underlying object; for use with callbacks)
+int wgeocon_navutils_geoToUtm(double lat_rad, double lon_rad, long int utm_zone, double *r_northing_m, double *r_easting_m);
+
+// get a pointer to a member (optional; keys defined per implementation)
+void *wgeocon_get_member(wgeocon_t *self, const char *key);
+
+// set a member (optional; keys defined per implementation)
+int wgeocon_set_member(wgeocon_t *self, const char *key, void *value);
+
+// initialize (optional; argments defined per implementation)
+void *wgeocon_init(wgeocon_t *self, int argc, void **argv);
+
+// enable/disable deletion of members (optional; keys defined per implementation)
+void wgeocon_auto_delete(wgeocon_t *self, const char *key, bool enable);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // GEOCONVERTER_H
diff --git a/src/mbtrnav/trnw/GeoCon.hpp b/src/mbtrnav/trnw/GeoCon.hpp
new file mode 100644
index 000000000..680563787
--- /dev/null
+++ b/src/mbtrnav/trnw/GeoCon.hpp
@@ -0,0 +1,201 @@
+// GeoCon.hpp
+//
+// Wraps GCTP and Proj geo coordinate transformations
+// i.e. lat/lon <> mercator projection, e.g. utm).
+// Includes C++ and C APIs (see GeoCon.h).
+// trnw mb1_to_pose/meas now takes a wgeocon_t (C geoconverter)
+// reference argument instead of utmZone. T
+// The underlying implementation may be GCTP or Proj, and
+// may be selected at run time
+
+#include
+#include
+#include
+#ifdef TRN_USE_PROJ
+#include
+#endif
+#include
+#include
+#include "GeoCon.h"
+
+#ifndef GEOCON_HPP
+#define GEOCON_HPP
+
+// GeoConIF
+// Virtual base class (interface)
+// Wraps various implementations for
+// geo-coordinate transformation e.g. libproj, gctp
+class GeoConIF
+{
+
+public:
+ GeoConIF();
+
+ virtual ~GeoConIF()
+ {}
+
+ // convert lat/lon to mercator projection (e.g. UTM)
+ virtual int geo_to_mp(double lat_rad, double lon_rad, double *r_northing_m, double *r_easting_m) = 0;
+ // convert mercator projection to lat/lon
+ virtual int mp_to_geo(double northing_m, double easting_m, double *r_lat_rad, double *r_lon_rad) = 0;
+
+ // get underlying context member
+ // for implementations that have one.
+ // Enables caller to manage context initialization/destruction
+ virtual void *get_member(const char *key);
+ // set underlying member for implementations that support it
+ virtual int set_member(const char *key, void *value);
+
+ // if true, caller will manage release of context resources
+ virtual void auto_delete(const char *key, bool enable);
+
+ // perform default initialization of underlying ctx
+ virtual void *init(int argc, void **argv);
+
+ // implementation type ID
+ GeoConType type();
+
+ // debug level
+ void set_debug(int level);
+ int debug();
+
+ // type ID name (null terminated string)
+ virtual const char *typestr();
+
+protected:
+
+ GeoConType m_type;
+ int m_debug;
+};
+
+#ifdef TRN_USE_PROJ
+// GeoConProj
+// Implementation backed by libproj coordinate transform (PJ*).
+// callers may opt to manage (initialize, destroy) the underlying transform,
+// or use the class implementation.
+//
+// get_member keys:
+// "XFM" : transform pointer (PJ*)
+//
+// auto_delete keys:
+// "XFM" : transform pointer (PJ*)
+//
+// init argments:
+// argv[0] : source CRS (const char *) optional, default GEOIF_WGS_DFL
+// argv[1] : target CRS (const char *) optional, default m_crs
+
+class GeoConProj : public GeoConIF
+{
+public:
+ GeoConProj();
+
+ GeoConProj(const char *tcrs);
+ GeoConProj(void *xfm, bool autodel);
+ GeoConProj(void *xfm, bool autodel, const char *tcrs, const char *scrs=NULL);
+
+ ~GeoConProj() override;
+
+ int geo_to_mp(double lat_rad, double lon_rad, double *r_northing, double *r_easting) override;
+
+ int mp_to_geo(double northing_m, double easting_m, double *r_lat_rad, double *r_lon_rad) override;
+
+ // "XFM" returns (PJ *) m_proj_xfm
+ void *get_member(const char *key) override;
+ int set_member(const char *key, void *value) override;
+
+ // argv[0] : const char * : target crs
+ // argv[1] : const char * : source crs
+ virtual void *init(int argc, void **argv) override;
+
+ void auto_delete(const char *key, bool enable) override;
+
+private:
+ char *m_scrs;
+ char *m_tcrs;
+ void *m_proj_xfm;
+ bool m_auto_delete_xfm;
+};
+#endif // TRN_USE_PROJ
+
+// GeoConGCTP
+// implementation backed by GCTP library (via NavUtils)
+//
+// get_member keys: not implemented
+//
+// auto_delete keys: not implemented
+//
+// init argments: not implemented
+
+class GeoConGCTP : public GeoConIF
+{
+public:
+ GeoConGCTP();
+
+ GeoConGCTP(long int utm);
+
+ ~GeoConGCTP() override;
+
+ int geo_to_mp(double lat_rad, double lon_rad, double *r_northing, double *r_easting) override;
+
+ int mp_to_geo(double northing_m, double easting_m, double *r_lat_rad, double *r_lon_rad) override;
+
+private:
+ long int m_utm;
+};
+
+// GeoCon
+// Concrete implementation for GeoConIF
+// The underlying implementation is determined by the
+// constructor used.
+class GeoCon : public GeoConIF
+{
+
+public:
+
+ GeoCon();
+
+ // implementation backed by GCTP library (via NavUtils)
+ GeoCon(long int utm);
+
+ // implementation backed by PROJ library
+ // if libproj is not available, disable proj implementation
+ GeoCon(const char *crs);
+ // initializing PROJ implementation
+ // tcrs: target CRS
+ // scrs: source CRS
+ // autodel: delete transform when instance destroyed (else caller must destroy)
+ GeoCon(void *xfm, bool autodel, const char *tcrs, const char *scrs=NULL);
+ GeoCon(void *xfm, bool autodel);
+
+ ~GeoCon() override;
+
+ // lat/lon to mercator projection
+ int geo_to_mp(double lat_rad, double lon_rad, double *r_northing_m, double *r_easting_m) override;
+
+ // mercator projection to lat/lon
+ int mp_to_geo(double northing_m, double easting_m, double *r_lat_rad, double *r_lon_rad) override;
+
+ // get a pointer to a member (optional; keys defined per implementation)
+ void *get_member(const char *key) override;
+ int set_member(const char *key, void *value) override;
+
+ // initialize (optional; argments defined per implementation)
+ void *init(int argc, void **argv) override;
+
+ // enable/disable deletion of members (optional; keys defined per implementation)
+ void auto_delete(const char *key, bool enable) override;
+
+ // get string representation of underlying type
+ const char *typestr() override;
+
+ // debug level accessors
+ void set_debug(int level);
+ int debug();
+
+private:
+ // underlying implementation
+ GeoConIF *m_geocon;
+};
+
+#endif //
+
diff --git a/src/mbtrnav/trnw/Makefile b/src/mbtrnav/trnw/Makefile
index c8eff84ba..fab68142b 100755
--- a/src/mbtrnav/trnw/Makefile
+++ b/src/mbtrnav/trnw/Makefile
@@ -13,6 +13,7 @@ OPT_TRN_BUILD=-DLIBTRN_BUILD=$(build_date)
mb1rs_ver ?=0.0.0b1
OPT_MB1RS_VER=-DMB1RS_VER=$(mb1rs_ver)
OPT_MB1RS_BUILD=-DMB1RS_BUILD=$(build_date)
+OPT_USE_PROJ=-DTRN_USE_PROJ
# C standard e.g. -std=c99 -std=gnu99
# may be needed for Cygwin (e.g. for loop declare/init)
@@ -51,7 +52,7 @@ $(info "INFO +++ using NETIF_MMDEBUG")
endif
# Build options
-BUILD_RELEASE_OPTIONS = $(STD) -D_GNU_SOURCE $(OPT_TRN_VER) $(OPT_TRN_BUILD) $(OPT_NETIF_MMDEBUG) $(OPT_MB1RS_VER) $(OPT_MB1RS_BUILD)
+BUILD_RELEASE_OPTIONS = $(STD) -D_GNU_SOURCE $(OPT_TRN_VER) $(OPT_TRN_BUILD) $(OPT_NETIF_MMDEBUG) $(OPT_MB1RS_VER) $(OPT_MB1RS_BUILD) $(OPT_USE_PROJ)
BUILD_DEBUG_OPTIONS = $(BUILD_RELEASE_OPTIONS) -DWITH_PDEBUG
BUILD_OPTIONS = $(BUILD_RELEASE_OPTIONS)
@@ -70,6 +71,7 @@ BUILD_DIR=../build
QNX_DIR=../qnx-utils
NEWMAT_DIR=../newmat
TNAV_DIR=../terrain-nav
+PROJ_INC_DIR=/opt/local/lib/proj9/include
# mframe is required to build TRN clients
# MFRAME_INC_DIR: location of mframe headers
@@ -87,9 +89,19 @@ endif
MFRAME_LIB=# $(MFRAME_LIB_DIR)/libmframe.a
+ifndef PROJ_INC_DIR
+PROJ_INC_DIR=/opt/local/lib/proj9/include
+endif
+
+ifndef PROJ_LIB_DIR
+PROJ_LIB_DIR=/opt/local/lib/proj9/lib
+endif
+
+PROJ_LIB=-lproj
+
# Compilation Options
CXX = gcc
-CPP = g++
+CPP = g++ -std=c++11
# compile and link with -pg for profiling support
# then do gprof gmon.out for profile output to console
#GPROF= -pg
@@ -98,20 +110,26 @@ WARN_FLAGS=-Wall
# Compiler flags
CFLAGS = -g -O2 $(WARN_FLAGS) $(GPROF) $(BUILD_OPTIONS) $(OS_CFLAGS)
-INC_PATHS = -I. -I$(MFRAME_INC_DIR) -I$(TNAV_DIR) -I$(NEWMAT_DIR) -I$(QNX_DIR) $(OS_INC_PATH)
+INC_PATHS = -I. -I$(MFRAME_INC_DIR) -I$(TNAV_DIR) -I$(NEWMAT_DIR) -I$(QNX_DIR) -I$(PROJ_INC_DIR) $(OS_INC_PATH)
# Linker flags
LD_FLAGS = -g $(GPROF)
-LIB_PATHS = -L$(OUTPUT_DIR) -L$(MFRAME_LIB_DIR) $(OS_LIB_PATH) -L/usr/local/lib
+LIB_PATHS = -L$(OUTPUT_DIR) -L$(MFRAME_LIB_DIR) -L$(PROJ_LIB_DIR) $(OS_LIB_PATH) -L/usr/local/lib
########################################
# Target Definitions
+# libgcon: Geoconversion wrapper for NavUtils/GCTP, PROJ
+LIBGCON=libgcon.a
+LIBGCON_SRC = GeoCon.cpp
+LIBGCON_OBJ=$(LIBGCON_SRC:%.cpp=$(BUILD_DIR)/%.o)
+LIBGCON_LIBS = -lqnx $(PROJ_LIB)
+
# libtrnw: TRN C wrappers
LIBTRNW=libtrnw.a
LIBTRNW_SRC=trnw.cpp
LIBTRNW_OBJ=$(LIBTRNW_SRC:%.cpp=$(BUILD_DIR)/%.o)
-LIBTRNW_LIBS = -ltrn -lqnx -lnewmat -lpthread
+LIBTRNW_LIBS = -ltrn -lqnx -lnewmat $(PROJ_LIB) -lpthread
LIBMB1=libmb1.a
LIBMB1_SRC = mb1_msg.c
@@ -151,7 +169,7 @@ LIBTRNCLI_LIBS = -lmframe -lpthread -lm
TRNCLI_TEST=trncli-test
TRNCLI_TEST_SRC=trncli_test.c mb1_msg.c
TRNCLI_TEST_OBJ=$(TRNCLI_TEST_SRC:%.c=$(BUILD_DIR)/%.o)
-TRNCLI_TEST_LIBS = -lmframe -ltrnw -lpthread -lm -lqnx -lnewmat -ltrn -ltrncli -lnetcdf -lgeolib -lstdc++
+TRNCLI_TEST_LIBS = -lmframe -ltrnw -lpthread -lm -lqnx -lnewmat -ltrn -ltrncli -lgcon -lnetcdf -lgeolib $(PROJ_LIB) -lstdc++
# libtrnucli: TRNU client lib
LIBTRNUCLI=libtrnucli.a
@@ -169,13 +187,13 @@ LIBNETIF_LIBS =
TRNUCLI_TEST=trnucli-test
TRNUCLI_TEST_SRC=trnucli_test.c
TRNUCLI_TEST_OBJ=$(TRNUCLI_TEST_SRC:%.c=$(BUILD_DIR)/%.o)
-TRNUCLI_TEST_LIBS = -lnetif -ltrnucli -lmframe -lpthread -lm -lqnx -lnewmat -ltrn -ltrncli -lnetcdf -lgeolib -lstdc++
+TRNUCLI_TEST_LIBS = -lnetif -ltrnucli -lmframe -lpthread -lm -lqnx -lnewmat -ltrn -ltrncli -lnetcdf -lgeolib $(PROJ_LIB) -lstdc++
# trnusvr-test: trnu_cli test server
TRNUSVR_TEST=trnusvr-test
TRNUSVR_TEST_SRC=trnusvr_test.c netif.c trnif_msg.c trnif_proto.c
TRNUSVR_TEST_OBJ=$(TRNUSVR_TEST_SRC:%.c=$(BUILD_DIR)/%.o)
-TRNUSVR_TEST_LIBS = -lmframe -ltrnw -lpthread -lm -lqnx -lnewmat -ltrn -ltrncli -lnetcdf -lgeolib -lstdc++
+TRNUSVR_TEST_LIBS = -lmframe -ltrnw -lpthread -lm -lqnx -lnewmat -ltrn -ltrncli -lnetcdf -lgeolib $(PROJ_LIB) -lstdc++
# mcpub: multicast test publisher
MCPUB=mcpub
@@ -204,7 +222,7 @@ MMCSUB_LIBS = $(MFRAME_LIB) -lmframe -lm -lstdc++
TRNIF_TEST=trnif-test
TRNIF_TEST_SRC=trnif_test.c trnif_proto.c trnif_msg.c
TRNIF_TEST_OBJ = $(TRNIF_TEST_SRC:%.c=$(BUILD_DIR)/%.o)
-TRNIF_TEST_LIBS = -lnetif -lmframe -ltrnw -lpthread -lm -lqnx -lnewmat -ltrn -lnetcdf -lgeolib -lstdc++
+TRNIF_TEST_LIBS = -lnetif -lmframe -ltrnw -lpthread -lm -lqnx -lnewmat -ltrn -lnetcdf -lgeolib -lgcon $(PROJ_LIB) -lstdc++
MB1RS=mb1rs
MB1RS_SRC=mb1_msg.c mb1rs.c mb1rs-app.c
@@ -227,6 +245,7 @@ $(MB1RS_SRC)
TRNC_TARGETS+= $(OUTPUT_DIR)/$(LIBTRNCLI) \
$(OUTPUT_DIR)/$(LIBTRNUCLI) \
+$(OUTPUT_DIR)/$(LIBGCON) \
$(OUTPUT_DIR)/$(TRNCLI_TEST) \
$(OUTPUT_DIR)/$(TRNUCLI_TEST)\
$(OUTPUT_DIR)/$(TRNUSVR_TEST) \
@@ -258,8 +277,8 @@ CLEANUP = gmon.out
########################################
# Rules: build targets
-all: $(OUTPUT_DIR)/$(LIBTRNW) $(OUTPUT_DIR)/$(LIBMB1)
-
+all: $(OUTPUT_DIR)/$(LIBTRNW) $(OUTPUT_DIR)/$(LIBMB1) $(OUTPUT_DIR)/$(LIBGCON)
+
trnc: $(OUTPUT_DIR)/$(LIBTRNW) $(OUTPUT_DIR)/$(LIBNETIF) $(TRNC_TARGETS)
@echo building $@...
@@ -284,6 +303,11 @@ $(OUTPUT_DIR)/$(LIBTRNCLI): $(LIBTRNCLI_OBJ)
@echo building $@...
ar rcs $@ $(LIBTRNCLI_OBJ) $(BUILD_DIR)/*.o
+# build GeoConverter library
+$(OUTPUT_DIR)/$(LIBGCON): $(LIBGCON_OBJ)
+ @echo building $@...
+ ar -r $@ $(LIBGCON_OBJ)
+
# build trncli-test utility
$(OUTPUT_DIR)/$(TRNCLI_TEST): $(TRNCLI_TEST_OBJ) $(LIBTRNW_OBJ) $(LIBTRNCLI_OBJ)
@echo building $@...
diff --git a/src/mbtrnav/trnw/geocon_test.cpp b/src/mbtrnav/trnw/geocon_test.cpp
new file mode 100644
index 000000000..8259e7d9b
--- /dev/null
+++ b/src/mbtrnav/trnw/geocon_test.cpp
@@ -0,0 +1,143 @@
+
+// geocon_test
+// Test and demonstrate GeoCon C++ and C APIs
+// build using
+// w/ proj
+// g++ -g -O0 -std=c++11 -I../qnx-utils -I/opt/local/lib/proj9/include -DTRN_USE_PROJ -o geocon-test geocon_test.cpp GeoCon.cpp -L/opt/local/lib/proj9/lib -lproj -L../bin -lgeolib -lqnx
+// w/o proj
+// g++ -g -O0 -std=c++11 -I../qnx-utils -o geocon-test geocon_test.cpp GeoCon.cpp -L../bin -lgeolib -lqnx
+
+#include
+#include
+#include
+#include "GeoCon.hpp"
+#include "GeoCon.h"
+
+static const char *SOURCE_CRS_DFL = GEOIF_SCRS_DFL;
+static const char *TARGET_CRS_DFL = GEOIF_TCRS_DFL;
+static double LAT_DFL = 0.; //84.
+static double LON_DFL = -126.;//-120.
+static int DEBUG_DFL = 0;
+
+void use_cpp(GeoCon *gcon, double lat_d=LAT_DFL, double lon_d=LON_DFL);
+void use_c(wgeocon_t *gcon, double lat_d=LAT_DFL, double lon_d=LON_DFL);
+
+void use_cpp(GeoCon *gcon, double lat_d, double lon_d)
+{
+// double lat_d=TEST_LAT, lon_d=TEST_LON;
+ double lat_r=Math::degToRad(lat_d), lon_r=Math::degToRad(lon_d);
+ double nor=0, eas=0;
+
+ if(gcon != nullptr) {
+ std::cerr << __func__ << ": using type " << gcon->typestr() << std::endl;
+
+ gcon->geo_to_mp(lat_r, lon_r, &nor, &eas);
+ std::cerr << __func__ << ": geo to mp" << std::endl;
+ std::cerr << __func__ << ": lat/lon " << lat_d << "/" << lon_d << std::endl;
+ std::cerr << __func__ << ": nor/eas " << nor << "/" << eas << std::endl;
+
+ lat_r = 0;
+ lon_r = 0;
+
+ gcon->mp_to_geo(nor, eas, &lat_r, &lon_r);
+ lat_d = Math::radToDeg(lat_r);
+ lon_d = Math::radToDeg(lon_r);
+ std::cerr << __func__ << ": mp to geo" << std::endl;
+ std::cerr << __func__ << ": lat/lon " << lat_d << "/" << lon_d << std::endl;
+ std::cerr << __func__ << ": nor/eas " << nor << "/" << eas << std::endl;
+ } else {
+ std::cerr << __func__ << ": GeoCon is NULL" << std::endl;
+ }
+}
+
+void use_c(wgeocon_t *gcon, double lat_d, double lon_d)
+{
+// double lat_d=TEST_LAT, lon_d=TEST_LON;
+ double lat_r=Math::degToRad(lat_d), lon_r=Math::degToRad(lon_d);
+ double nor=0, eas=0;
+
+ if(gcon != nullptr) {
+ std::cerr << __func__ << ": using type " << (int)wgeocon_type(gcon) << "/" << wgeocon_typestr(gcon) << std::endl;
+
+ wgeocon_geo_to_mp(gcon, lat_r, lon_r, &nor, &eas);
+ std::cerr << __func__ << ": geo to mp" << std::endl;
+ std::cerr << __func__ << ": lat/lon " << lat_d << "/" << lon_d << std::endl;
+ std::cerr << __func__ << ": nor/eas " << nor << "/" << eas << std::endl;
+
+ lat_r = 0;
+ lon_r = 0;
+
+ wgeocon_mp_to_geo(gcon, nor, eas, &lat_r, &lon_r);
+ lat_d = Math::radToDeg(lat_r);
+ lon_d = Math::radToDeg(lon_r);
+ std::cerr << __func__ << ": mp to geo" << std::endl;
+ std::cerr << __func__ << ": lat/lon " << lat_d << "/" << lon_d << std::endl;
+ std::cerr << __func__ << ": nor/eas " << nor << "/" << eas << std::endl;
+ } else {
+ std::cerr << __func__ << ": GeoCon is NULL" << std::endl;
+ }
+}
+
+int main(int argc, char **argv)
+{
+ void **av = (void **)malloc(2 * sizeof(void *));
+ av[0] = (void *)TARGET_CRS_DFL;
+ av[1] = (void *)SOURCE_CRS_DFL;
+
+ int debug = DEBUG_DFL;
+ double lat_d = LAT_DFL;
+ double lon_d = LON_DFL;
+
+ for(int i=0; i < argc; i++) {
+ if(sscanf(argv[i], "--debug=%d", &debug) == 1) {
+ } else if(sscanf(argv[i], "--lat=%lf", &lat_d) == 1) {
+ } else if(sscanf(argv[i], "--lon=%lf", &lon_d) == 1) {
+ }
+ }
+
+ // test C++ API
+
+ std::cerr << "# gctp_i" << std::endl;
+ GeoCon *gctp_i = new GeoCon(10);
+ gctp_i->set_debug(debug);
+
+ use_cpp(gctp_i, lat_d, lon_d);
+
+ std::cerr << std::endl;
+
+ std::cerr << "# proj_i" << std::endl;
+ GeoCon *proj_i = new GeoCon(GEOIF_TCRS_DFL);
+ proj_i->set_debug(debug);
+ proj_i->init(2, av);
+
+ use_cpp(proj_i, lat_d, lon_d);
+
+ if(gctp_i != NULL)
+ delete gctp_i;
+
+ if(proj_i != NULL)
+ delete proj_i;
+
+ // test C API
+
+ wgeocon_t *gctp_c = wgeocon_new_gctp(10);
+ wgeocon_set_debug(gctp_c, debug);
+
+ wgeocon_t *proj_c = wgeocon_new_proj(GEOIF_TCRS_DFL);
+ wgeocon_set_debug(proj_c, debug);
+ wgeocon_init(proj_c, 2, av);
+
+ std::cerr << std::endl;
+ use_c(gctp_c, lat_d, lon_d);
+
+ std::cerr << std::endl;
+ use_c(proj_c, lat_d, lon_d);
+
+ std::cerr << std::endl;
+
+ wgeocon_delete(gctp_c);
+ wgeocon_delete(proj_c);
+
+ free(av);
+ return 0;
+}
diff --git a/src/mbtrnav/trnw/mb1rs.c b/src/mbtrnav/trnw/mb1rs.c
index 7c0b6caa9..a00d3ac0e 100644
--- a/src/mbtrnav/trnw/mb1rs.c
+++ b/src/mbtrnav/trnw/mb1rs.c
@@ -157,7 +157,7 @@ int64_t s_file_frame_fn(mb1rs_ctx_t *ctx, byte *r_buf, uint32_t len)
uint32_t readlen = 1;
uint32_t record_bytes=0;
int64_t read_bytes=0;
- uint32_t sync_bytes=0;
+// uint32_t sync_bytes=0;
mb1_t *dest = mb1_new(MB1_MAX_BEAMS);
// sync to start of record
@@ -170,9 +170,10 @@ int64_t s_file_frame_fn(mb1rs_ctx_t *ctx, byte *r_buf, uint32_t len)
bp++;
readlen=MB1_HEADER_BYTES-1;
break;
- }else{
- sync_bytes++;
}
+// else{
+// sync_bytes++;
+// }
}
// if start of sync found, read header (fixed-length sounding bytes)
diff --git a/src/mbtrnav/trnw/trn_cli.c b/src/mbtrnav/trnw/trn_cli.c
index 6412fa602..4ba880b12 100644
--- a/src/mbtrnav/trnw/trn_cli.c
+++ b/src/mbtrnav/trnw/trn_cli.c
@@ -126,34 +126,32 @@ static int32_t s_trncli_send_recv(trncli_t *self, byte *msg, int32_t len, bool b
return retval;
}// end function s_trncli_send_recv
-#ifdef TRN_USE_PROJ
-trncli_t *trncli_new(void *pjptr)
+trncli_t *trncli_new(long int utm_zone)
{
trncli_t *instance=(trncli_t *)malloc(sizeof(trncli_t));
if(NULL!=instance){
memset(instance,0,sizeof(trncli_t));
instance->measurement = NULL;
- instance->pjptr=pjptr;
+ instance->utm_zone=utm_zone;
instance->trn = msock_connection_new();
}
-
+
return instance;
}// end function trncli_new
-#else
-trncli_t *trncli_new(long int utm_zone)
+trncli_t *trncli_gcnew(wgeocon_t *gcon)
{
trncli_t *instance=(trncli_t *)malloc(sizeof(trncli_t));
if(NULL!=instance){
memset(instance,0,sizeof(trncli_t));
instance->measurement = NULL;
- instance->utm_zone=utm_zone;
+ instance->utm_zone=0;
instance->trn = msock_connection_new();
+ instance->geocon = gcon;
}
-
+
return instance;
}// end function trncli_new
-#endif
void trncli_destroy(trncli_t **pself)
{
@@ -220,16 +218,11 @@ int trncli_send_update(trncli_t *self, mb1_t *src, wposet_t **pt_out, wmeast_t *
if(NULL!=self && NULL!=src && NULL!=pt_out && NULL!=mt_out){
int test=-1;
-#ifdef TRN_USE_PROJ
- if( (test = wmeast_mb1_to_meas(mt_out, src, self->pjptr)) == 0){
-#else
- if( (test = wmeast_mb1_to_meas(mt_out, src, self->utm_zone)) == 0){
-#endif
-#ifdef TRN_USE_PROJ
- if( (test = wposet_mb1_to_pose(pt_out, src, self->pjptr)) == 0){
-#else
- if( (test = wposet_mb1_to_pose(pt_out, src, self->utm_zone)) == 0){
-#endif
+ if( (test = wmeast_mb1_to_meas(mt_out, src, self->geocon)) == 0){
+ // if( (test = wmeast_mb1_to_meas(mt_out, src, self->utm_zone)) == 0){
+
+ if( (test = wposet_mb1_to_pose(pt_out, src, self->geocon)) == 0){
+ // if( (test = wposet_mb1_to_pose(pt_out, src, self->utm_zone)) == 0){
// must do motion update first if pt time <= mt time
if(trncli_update_motion(self, *pt_out) > 0){
@@ -450,7 +443,7 @@ int trncli_triplet_set(trncli_t *self, int msg_type, d_triplet_t *src)
if( wcommst_cdata_unserialize(&ct_dat,(char *)msg)==0 && NULL!=ct_dat){
retval = ( (ct_dat->msg_type==TRN_MSG_ACK) ? 0 : -1);
}
- // release cdata resources
+ // release cdata resourcess
if(NULL!=ct_dat){
wcommst_cdata_destroy(&ct_dat);
}
@@ -465,17 +458,10 @@ int trncli_triplet_set(trncli_t *self, int msg_type, d_triplet_t *src)
return retval;
}// end function trncli_triplet_set
-#ifdef TRN_USE_PROJ
-int trncli_mb1_to_meas(wmeast_t **dest, mb1_t *src, void *pjptr)
-{
- return wmeast_mb1_to_meas(dest, src, pjptr);
-}// end function trncli_mb1_to_meas
-#else
-int trncli_mb1_to_meas(wmeast_t **dest, mb1_t *src, long int utmZone)
-{
- return wmeast_mb1_to_meas(dest, src,utmZone);
-}// end function trncli_mb1_to_meas
-#endif
+//int trncli_mb1_to_meas(wmeast_t **dest, mb1_t *src, long int utmZone)
+//{
+// return wmeast_mb1_to_meas(dest, src,utmZone);
+//}// end function trncli_mb1_to_meas
int trncli_cdata_to_pose(wposet_t **dest, pt_cdata_t *src)
{
@@ -693,18 +679,6 @@ int trncli_set_filter_gradient(trncli_t *self, int value)
return trncli_ptype_set(self,TRN_MSG_FILT_GRD, value);
} // end function
-#ifdef TRN_USE_PROJ
-int trncli_set_crs(trncli_t *self, void *pjptr)
-{
- int retval=-1;
- if(NULL!=self){
- self->pjptr=pjptr;
- retval=0;
- }
- return retval;
-} // end function
-
-#else
int trncli_set_utm(trncli_t *self, long int utm_zone)
{
int retval=-1;
@@ -714,7 +688,6 @@ int trncli_set_utm(trncli_t *self, long int utm_zone)
}
return retval;
} // end function
-#endif
int trncli_get_init_stddev_xyz(trncli_t *self, d_triplet_t *dest)
{
diff --git a/src/mbtrnav/trnw/trn_cli.h b/src/mbtrnav/trnw/trn_cli.h
index c87954ea4..dec2071c0 100644
--- a/src/mbtrnav/trnw/trn_cli.h
+++ b/src/mbtrnav/trnw/trn_cli.h
@@ -70,19 +70,16 @@
#include "trnw.h"
#include "mb1_msg.h"
#include "msocket.h"
+#include "GeoCon.h"
/////////////////////////
// Macros
/////////////////////////
#define TRNCLI_NBEAMS 25
-
-#ifdef TRN_USE_PROJ
-#define TRNCLI_CRS_DFL "UTM10N"
-#else
#define UTM_MONTEREY_BAY 10L
#define UTM_AXIAL 12L
+
#define TRNCLI_UTM_DFL UTM_MONTEREY_BAY
-#endif
/////////////////////////
// Type Definitions
@@ -90,12 +87,9 @@
typedef struct trncli_s{
msock_connection_t *trn;
-#ifdef TRN_USE_PROJ
- void *pjptr;
-#else
long int utm_zone;
-#endif
wmeast_t *measurement;
+ wgeocon_t *geocon;
}trncli_t;
/////////////////////////
@@ -105,12 +99,8 @@ typedef struct trncli_s{
#ifdef __cplusplus
extern "C" {
#endif
-
-#ifdef TRN_USE_PROJ
- trncli_t *trncli_new(void *pjptr);
-#else
trncli_t *trncli_new(long int utm_zone);
-#endif
+ trncli_t *trncli_gcnew(wgeocon_t *gcon);
void trncli_destroy(trncli_t **pself);
int trncli_connect(trncli_t *self, char *host, int port);
int trncli_disconnect(trncli_t *self);
@@ -130,11 +120,7 @@ extern "C" {
int trncli_ptype_set(trncli_t *self, int msg_type, int param);
// Conversion helper functions
-#ifdef TRN_USE_PROJ
- int trncli_mb1_to_meas(wmeast_t **dest, mb1_t *src, void *pjptr);
-#else
- int trncli_mb1_to_meas(wmeast_t **dest, mb1_t *src, long int utmZone);
-#endif
+// int trncli_mb1_to_meas(wmeast_t **dest, mb1_t *src, long int utmZone);
int trncli_cdata_to_pose(wposet_t **dest, pt_cdata_t *src);
int trncli_cdata_to_meas(wmeast_t **dest, mt_cdata_t *src);
@@ -174,13 +160,8 @@ extern "C" {
int trncli_set_vdr(trncli_t *self, int value);
// set filter gradient
int trncli_set_filter_gradient(trncli_t *self, int value);
-#ifdef TRN_USE_PROJ
- // set CRS
- int trncli_set_crs(trncli_t *self, void *pjptr);
-#else
// set UTM zone
int trncli_set_utm(trncli_t *self, long int utm_zone);
-#endif
// get init xyz (reinit variance bounds)
int trncli_get_init_stddev_xyz(trncli_t *self, d_triplet_t *dest);
// set init xyz (reinit variance bounds)
diff --git a/src/mbtrnav/trnw/trncli_test.c b/src/mbtrnav/trnw/trncli_test.c
index 640c498b6..86cd32083 100644
--- a/src/mbtrnav/trnw/trncli_test.c
+++ b/src/mbtrnav/trnw/trncli_test.c
@@ -73,9 +73,6 @@
#include "msocket.h"
#include "mlog.h"
#include "mb1_msg.h"
-#ifdef TRN_USE_PROJ
-#include "proj.h"
-#endif
/////////////////////////
// Macros
@@ -121,7 +118,6 @@
#define TRNCLI_TEST_LOG_DIR "."
#define TRNCLI_TEST_LOG_EXT ".log"
#define TRNCLI_TEST_IFILE "./test.mb1"
-#define TRNCLI_TEST_TRNCFG_CRS "UTM10N"
#define TRNCLI_TEST_TRNCFG_MAP "PortTiles"
#define TRNCLI_TEST_TRNCFG_CFG "mappingAUV_specs.cfg"
#define TRNCLI_TEST_TRNCFG_PARTICLES "particles.cfg"
@@ -187,15 +183,9 @@ typedef struct app_cfg_s{
/// @var app_cfg_s::est_n
/// @brief TBD
int est_n;
-#ifdef TRN_USE_PROJ
- /// @var app_cfg_s::crs
- /// @brief TBD
- char *crs;
-#else
/// @var app_cfg_s::utm
/// @brief TBD
long int utm;
-#endif
/// @var app_cfg_s::log_cfg
/// @brief TBD
mlog_config_t *log_cfg;
@@ -253,10 +243,6 @@ static trncli_t **s_get_trncli_instance(app_cfg_t *cfg, bool force_new);
static void s_init_log(int argc, char **argv, app_cfg_t *cfg);
static int s_app_main(app_cfg_t *cfg);
-#ifdef TRN_USE_PROJ
-static void *pjptr = NULL;
-#endif
-
/////////////////////////
// Imports
/////////////////////////
@@ -305,6 +291,9 @@ static void s_show_help()
" --cfg : TRN devices config file\n"
" --par : TRN particle file\n"
" --logdir : TRN log directory suffix (TRN-.nnn)\n"
+ " --use_proj : Use proj instead of GCTP\n"
+ " --projection : projection\n"
+ " --trn-crs : Proj CRS\n"
" --trn-ftype : TRN filter type:\n"
" 0: TRN_FILT_NONE\n"
" 1: TRN_FILT_POINTMASS\n"
@@ -321,11 +310,7 @@ static void s_show_help()
" 2: TRN_MWEIGHT_CROSSBEAM\n"
" 3: TRN_MWEIGHT_SUBCLOUD_SHANDOR\n"
" 4: TRN_MWEIGHT_SUBCLOUD_NISON\n"
-#ifdef TRN_USE_PROJ
- " --trn-crs : TRN CRS (Coordinate Reference System)\n"
-#else
" --trn-utm : TRN UTM zone\n"
-#endif
" --trn-ncov : TRN max northing covariance\n"
" --trn-nerr : TRN max northing error\n"
" --trn-ecov : TRN max easing covariance\n"
@@ -407,13 +392,12 @@ static void parse_args(int argc, char **argv, app_cfg_t *cfg)
{"cfg", required_argument, NULL, 0},
{"par", required_argument, NULL, 0},
{"logdir", required_argument, NULL, 0},
+ {"use-proj", required_argument, NULL, 0},
+ {"projection", required_argument, NULL, 0},
+ {"trn-crs", required_argument, NULL, 0},
{"trn-ftype", required_argument, NULL, 0},
{"trn-mtype", required_argument, NULL, 0},
-#ifdef TRN_USE_PROJ
- {"trn-crs", required_argument, NULL, 0},
-#else
{"trn-utm", required_argument, NULL, 0},
-#endif
{"trn-freinit", required_argument, NULL, 0},
{"trn-fgrade", required_argument, NULL, 0},
{"trn-mw", required_argument, NULL, 0},
@@ -514,34 +498,6 @@ static void parse_args(int argc, char **argv, app_cfg_t *cfg)
}
}
}
-#ifdef TRN_USE_PROJ
- // crs
- else if (strcmp("trn-crs", options[option_index].name) == 0) {
- if(NULL!=cfg->trn_cfg->crs){
- free(cfg->trn_cfg->crs);
- }
- cfg->trn_cfg->crs=strdup(optarg);
- }
- // utm
- else if (strcmp("trn-utm", options[option_index].name) == 0) {
- int utm_zone = 0;
- if(sscanf(optarg,"%d",&utm_zone)==1){
- char proj_string[1024] = "";
- if (utm_zone > 0 && utm_zone <= 60)
- sprintf(proj_string, "UTM%2.2dN", utm_zone);
- if (utm_zone < 0 && utm_zone >= -60)
- sprintf(proj_string, "UTM%2.2dS", -utm_zone);
- if( strlen(proj_string) > 0)
- cfg->trn_cfg->crs=strdup(proj_string);
- }
- }
-#else
- // utm
- else if (strcmp("trn-utm", options[option_index].name) == 0) {
- if(sscanf(optarg,"%ld",&cfg->utm) == 1)
- cfg->trn_cfg->utm_zone=cfg->utm;
- }
-#endif
// map
else if (strcmp("map", options[option_index].name) == 0) {
if(NULL!=cfg->trn_cfg->map_file){
@@ -570,6 +526,41 @@ static void parse_args(int argc, char **argv, app_cfg_t *cfg)
}
cfg->trn_cfg->log_dir=strdup(optarg);
}
+ // use-proj
+ else if (strcmp("use-proj", options[option_index].name) == 0) {
+
+ cfg->trn_cfg->use_proj=true;
+
+ sscanf(optarg,"%c",&cmnem);
+ switch (cmnem) {
+ case 'y':
+ case 'Y':
+ case '1':
+ cfg->trn_cfg->use_proj=true;
+ break;
+
+ case 'n':
+ case 'N':
+ case '0':
+ cfg->trn_cfg->use_proj=false;
+ break;
+ default:
+ fprintf(stderr, "ERR - invalid use-proj[%c]\n", cmnem);
+ break;
+ }
+
+ }
+ // trn-crs
+ else if (strcmp("trn-crs", options[option_index].name) == 0) {
+ if(NULL!=cfg->trn_cfg->trn_crs){
+ free(cfg->trn_cfg->trn_crs);
+ }
+ cfg->trn_cfg->trn_crs=strdup(optarg);
+ }
+ // trn-crs
+ else if (strcmp("projection", options[option_index].name) == 0) {
+ sscanf(optarg, "%d", &cfg->trn_cfg->projection);
+ }
// ftype
else if (strcmp("trn-ftype", options[option_index].name) == 0) {
sscanf(optarg,"%c",&cmnem);
@@ -618,6 +609,11 @@ static void parse_args(int argc, char **argv, app_cfg_t *cfg)
break;
}
}
+ // utm
+ else if (strcmp("trn-utm", options[option_index].name) == 0) {
+ if(sscanf(optarg,"%ld",&cfg->utm) == 1)
+ cfg->trn_cfg->utm_zone=cfg->utm;
+ }
// freinit
else if (strcmp("trn-freinit", options[option_index].name) == 0) {
sscanf(optarg,"%c",&cmnem);
@@ -744,11 +740,9 @@ static void parse_args(int argc, char **argv, app_cfg_t *cfg)
s_dbg_printf(stderr, cfg->verbose, "mode [%c]\n", (char)cfg->mode);
s_dbg_printf(stderr, cfg->verbose, "host [%s]\n", cfg->trn_cfg->trn_host);
s_dbg_printf(stderr, cfg->verbose, "port [%d]\n", cfg->trn_cfg->trn_port);
-#ifdef TRN_USE_PROJ
- s_dbg_printf(stderr, cfg->verbose, "crs [%s]\n", cfg->trn_cfg->crs);
-#else
- s_dbg_printf(stderr, cfg->verbose, "utm [%ld]\n", cfg->trn_cfg->utm_zone);
-#endif
+ s_dbg_printf(stderr, cfg->verbose, "use-proj [%d]\n", (cfg->trn_cfg->use_proj?"Y":"N"));
+ s_dbg_printf(stderr, cfg->verbose, "projection [%d]\n",cfg->trn_cfg->projection);
+ s_dbg_printf(stderr, cfg->verbose, "crs [%s]\n", cfg->trn_cfg->trn_crs);
s_dbg_printf(stderr, cfg->verbose, "map [%s]\n", cfg->trn_cfg->map_file);
s_dbg_printf(stderr, cfg->verbose, "cfg [%s]\n", cfg->trn_cfg->cfg_file);
s_dbg_printf(stderr, cfg->verbose, "particles [%s]\n", cfg->trn_cfg->particles_file);
@@ -758,6 +752,7 @@ static void parse_args(int argc, char **argv, app_cfg_t *cfg)
s_dbg_printf(stderr, cfg->verbose, "freinit [%d]\n", cfg->trn_cfg->filter_reinit);
s_dbg_printf(stderr, cfg->verbose, "fgrade [%d]\n", cfg->trn_cfg->filter_grade);
s_dbg_printf(stderr, cfg->verbose, "mw [%d]\n", cfg->trn_cfg->mod_weight);
+ s_dbg_printf(stderr, cfg->verbose, "utm [%ld]\n", cfg->trn_cfg->utm_zone);
s_dbg_printf(stderr, cfg->verbose, "ncov [%.3lf]\n", cfg->trn_cfg->max_northing_cov);
s_dbg_printf(stderr, cfg->verbose, "nerr [%.3lf]\n", cfg->trn_cfg->max_northing_err);
s_dbg_printf(stderr, cfg->verbose, "ecov [%.3lf]\n", cfg->trn_cfg->max_easting_cov);
@@ -813,11 +808,7 @@ static app_cfg_t *app_cfg_new()
instance->log_name=strdup(TRNCLI_TEST_LOG_NAME);
instance->log_dir=strdup(TRNCLI_TEST_LOG_DIR);
instance->log_path=(char *)malloc(LOG_PATH_BYTES);
-#ifdef TRN_USE_PROJ
- instance->crs=TRNCLI_CRS_DFL;
-#else
instance->utm=TRNCLI_UTM_DFL;
-#endif
instance->state_n=0;
instance->tcli_connect_retries = TRNCLI_CONNECT_RETRIES;
instance->mb1_read_retries = MB1_READ_RETRIES;
@@ -825,12 +816,6 @@ static app_cfg_t *app_cfg_new()
instance->trn_cfg=trncfg_dnew();
-#ifdef TRN_USE_PROJ
- if(NULL!=instance->trn_cfg->crs)free(instance->trn_cfg->crs);
- instance->trn_cfg->crs = strdup(TRNCLI_TEST_TRNCFG_CRS);
-#else
- instance->trn_cfg->utm_zone = instance->utm;
-#endif
if(NULL!=instance->trn_cfg->map_file)free(instance->trn_cfg->map_file);
instance->trn_cfg->map_file=strdup(TRNCLI_TEST_TRNCFG_MAP);
if(NULL!=instance->trn_cfg->cfg_file)free(instance->trn_cfg->cfg_file);
@@ -841,6 +826,7 @@ static app_cfg_t *app_cfg_new()
instance->trn_cfg->log_dir=strdup(TRNCLI_TEST_TRNCFG_LOGDIR);
instance->trn_cfg->map_type = TRN_MAP_BO;
instance->trn_cfg->filter_type = TRN_FILT_PARTICLE;
+ instance->trn_cfg->utm_zone = instance->utm;
instance->trn_cfg->mod_weight = TRN_MWEIGHT_NONE;
instance->trn_cfg->filter_reinit = TRN_FILT_REINIT_EN;
instance->trn_cfg->filter_grade = TRN_GRD_HIGH;
@@ -1232,11 +1218,17 @@ static int s_trncli_show_trn_update(trncli_t *tcli, mb1_t *mb1, app_cfg_t *cfg)
}
} else {
-#ifdef TRN_USE_PROJ
- wposet_mb1_to_pose(&pt, mb1, pjptr);
-#else
- wposet_mb1_to_pose(&pt, mb1, cfg->utm);
-#endif
+ // TODO: implement configuation support for libproj (--proj-crs, --use-proj)
+ wgeocon_t *geocon = NULL;
+ if(cfg->trn_cfg->use_proj) {
+ // TODO: set source CRS
+ geocon = wgeocon_new_proj(cfg->trn_cfg->trn_crs);
+ wgeocon_init(geocon, 0, NULL);
+ } else {
+ geocon = wgeocon_new_gctp(cfg->utm);
+ }
+ wposet_mb1_to_pose(&pt, mb1, geocon);
+ wgeocon_delete(geocon);
}
test = trncli_get_bias_estimates(tcli, pt, &pt_dat, &mle_dat, &mse_dat);
@@ -1574,21 +1566,13 @@ static trncli_t **s_get_trncli_instance(app_cfg_t *cfg, bool force_new)
static trncli_t *tcli_instance = NULL;
if(NULL == tcli_instance){
-#ifdef TRN_USE_PROJ
- tcli_instance = trncli_new(pjptr);
-#else
tcli_instance = trncli_new(cfg->utm);
-#endif
tcli_connected = false;
tcli_initialized = false;
} else if(force_new){
trncli_disconnect(tcli_instance);
trncli_destroy(&tcli_instance);
-#ifdef TRN_USE_PROJ
- tcli_instance = trncli_new(pjptr);
-#else
tcli_instance = trncli_new(cfg->utm);
-#endif
tcli_connected = false;
tcli_initialized = false;
}
@@ -1765,15 +1749,9 @@ int main(int argc, char **argv)
// parse command line args (update config)
parse_args(argc, argv, cfg);
+
s_init_log(argc,argv,cfg);
- // set crs
-#ifdef TRN_USE_PROJ
- PJ *p = proj_create_crs_to_crs(PJ_DEFAULT_CTX, "EPSG:4326", cfg->crs, 0);
- pjptr = (void *) proj_normalize_for_visualization(PJ_DEFAULT_CTX, p);
- proj_destroy(p);
-#endif
-
s_app_main(cfg);
const char *log_path = mlog_path(cfg->log_id);
@@ -1789,10 +1767,6 @@ int main(int argc, char **argv)
fprintf(stderr, "ERR - could not remove log [%s] [%d:%s]\n", log_path, errno, strerror(errno));
}
}
-
-#ifdef TRN_USE_PROJ
- proj_destroy(pjptr);
-#endif
app_cfg_destroy(&cfg);
diff --git a/src/mbtrnav/trnw/trnif_test.c b/src/mbtrnav/trnw/trnif_test.c
index f795e2adc..a750d7286 100644
--- a/src/mbtrnav/trnw/trnif_test.c
+++ b/src/mbtrnav/trnw/trnif_test.c
@@ -109,9 +109,6 @@ typedef struct app_cfg_s{
msock_socket_t *cli;
char *host;
int port;
-#ifdef TRN_USE_PROJ
- char *crs;
-#endif
char *map;
char *cfg;
char *particles;
@@ -143,9 +140,6 @@ static void s_show_help()
"--help : output help message\n"
"--version : output version info\n"
"--host=ip:n : TRN server host:port\n"
-#ifdef TRN_USE_PROJ
- "--crs=s : CRS (Coordinate Reference System) used for map [*]\n"
-#endif
"--map=s : map file/directory [*]\n"
"--cfg=s : config file [*]\n"
"--particles=s : particles file [*]\n"
@@ -177,9 +171,6 @@ void parse_args(int argc, char **argv, app_cfg_t *cfg)
{"help", no_argument, NULL, 0},
{"version", no_argument, NULL, 0},
{"host", required_argument, NULL, 0},
-#ifdef TRN_USE_PROJ
- {"crs", required_argument, NULL, 0},
-#endif
{"map", required_argument, NULL, 0},
{"cfg", required_argument, NULL, 0},
{"particles", required_argument, NULL, 0},
@@ -224,13 +215,6 @@ void parse_args(int argc, char **argv, app_cfg_t *cfg)
free(hsave);
}
}
-#ifdef TRN_USE_PROJ
- // crs
- else if (strcmp("crs", options[option_index].name) == 0) {
- if(NULL!=cfg->crs)free(cfg->crs);
- cfg->crs=(NULL==optarg?NULL:strdup(optarg));
- }
-#endif
// map
else if (strcmp("map", options[option_index].name) == 0) {
if(NULL!=cfg->map)free(cfg->map);
@@ -271,13 +255,10 @@ void parse_args(int argc, char **argv, app_cfg_t *cfg)
fprintf(stderr,"verbose [%d]\n",cfg->verbose);
fprintf(stderr,"host [%s]\n",cfg->host);
fprintf(stderr,"port [%d]\n",cfg->port);
-#ifdef TRN_USE_PROJ
- fprintf(stderr,"crs [%s]\n",cfg->crs);
-#endif
fprintf(stderr,"map [%s]\n",cfg->map);
fprintf(stderr,"cfg [%s]\n",cfg->cfg);
- fprintf(stderr,"particles [%s]\n",cfg->particles);
- fprintf(stderr,"logdir [%s]\n",cfg->logdir);
+ fprintf(stderr,"particles [%s]\n",cfg->map);
+ fprintf(stderr,"logdir [%s]\n",cfg->map);
}
// End function parse_args
@@ -501,11 +482,10 @@ static int s_app_main(app_cfg_t *cfg)
trn_config_t *trn_cfg = trncfg_new(cfg->host,
cfg->port,
-#ifdef TRN_USE_PROJ
- cfg->crs,
-#else
+ false,
+ 0,
+ NULL,
10L,
-#endif
TRN_SENSOR_MB,
TRN_MAP_BO,
TRN_FILT_PARTICLE,
@@ -588,9 +568,6 @@ int main(int argc, char **argv)
// msock_socket_t *cli;
// char *host;
// int port;
-#ifdef TRN_USE_PROJ
-// char *crs;
-#endif
// char *map;
// char *cfg;
// char *particles;
@@ -607,9 +584,6 @@ int main(int argc, char **argv)
NULL,
NULL,
NULL,
-#ifdef TRN_USE_PROJ
- NULL,
-#endif
strdup("logs")
};
app_cfg_t *cfg = &cfg_s;
@@ -619,9 +593,6 @@ int main(int argc, char **argv)
parse_args(argc,argv,cfg);
s_app_main(cfg);
if(NULL!=cfg->host)free(cfg->host);
-#ifdef TRN_USE_PROJ
- if(NULL!=cfg->crs)free(cfg->crs);
-#endif
if(NULL!=cfg->map)free(cfg->map);
if(NULL!=cfg->cfg)free(cfg->cfg);
if(NULL!=cfg->particles)free(cfg->particles);
diff --git a/src/mbtrnav/trnw/trnw.cpp b/src/mbtrnav/trnw/trnw.cpp
index 453a3df81..eb631d4aa 100644
--- a/src/mbtrnav/trnw/trnw.cpp
+++ b/src/mbtrnav/trnw/trnw.cpp
@@ -68,9 +68,6 @@
#include
#include
-#ifdef TRN_USE_PROJ
-#include "proj.h"
-#endif
#include "trnw.h"
#include "TerrainNav.h"
#include "NavUtils.h"
@@ -1152,94 +1149,95 @@ int wposet_pose_to_cdata(pt_cdata_t **dest, wposet_t *src)
return retval;
}
-#ifdef TRN_USE_PROJ
-int wposet_mb1_to_pose(wposet_t **dest, mb1_t *src, void *pjptr)
+static int wposet_mb1_fill_pose(poseT *dest, mb1_t *src, double easting_m, double northing_m)
{
- int retval=-1;
- if(NULL!=dest && NULL!=src && NULL!=pjptr){
+ int retval = -1;
+
+ if(dest != NULL && src != NULL) {
+ dest->time = src->ts;
+ dest->x = easting_m;
+ dest->y = northing_m;
+ dest->z = src->depth;
+ dest->phi=0.0;
+ dest->theta=0.0;
+ dest->psi=src->hdg;
+ dest->gpsValid=(dest->z<2?true:false);
+ dest->bottomLock=true;
+ dest->dvlValid=true;
+ // TRN can't intialize if vx == 0
+ dest->vx = 0.01;
+ dest->vy = 0.;
+ dest->vz = 0.;
+ // wx not required; can use these (how determined?)
+ // dest->wx = -3.332e-002;
+ // dest->wy = -9.155e-003;
+ // dest->wz = -3.076e-002;
+ dest->wx = 0.;
+ dest->wy = 0.;
+ dest->wz = 0.;
+
+ retval = 0;
+ }
+ return retval;
+}
+
+int wposet_mb1_to_pose(wposet_t **dest, mb1_t *src, wgeocon_t *geocon)
+{
+ int retval = -1;
+
+ if(NULL != dest && NULL != src){
+
wposet_t *pose = (wposet_t *)(*dest);
- if(NULL==pose){
- pose=wposet_dnew();
- *dest=pose;
+
+ if(NULL == pose){
+ pose = wposet_dnew();
+ *dest = pose;
}
- if(NULL!=pose){
+
+ if(NULL != pose){
poseT *obj = static_cast(pose->obj);
- obj->time = src->ts;
- PJ *p = (PJ *) pjptr;
- PJ_COORD c;
- c.v[0] = src->lon;
- c.v[1] = src->lat;
- c = proj_trans(p, PJ_FWD, c);
- obj->x = c.v[1];
- obj->y = c.v[0];
- obj->z = src->depth;
- obj->phi=0.0;
- obj->theta=0.0;
- obj->psi=src->hdg;
- obj->gpsValid=(obj->z<2?true:false);
- obj->bottomLock=true;
- obj->dvlValid=true;
- // TRN can't intialize if vx == 0
- obj->vx = 0.01;
- obj->vy = 0.;
- obj->vz = 0.;
- // wx not required; can use these (how determined?)
- // obj->wx = -3.332e-002;
- // obj->wy = -9.155e-003;
- // obj->wz = -3.076e-002;
- obj->wx = 0.;
- obj->wy = 0.;
- obj->wz = 0.;
- retval=0;
- }
+ double easting_m = 0.;
+ double northing_m = 0.;
+ wgeocon_geo_to_mp(geocon, Math::degToRad(src->lat),
+ Math::degToRad(src->lon),
+ &easting_m, &northing_m);
+
+ retval = wposet_mb1_fill_pose(obj, src, easting_m, northing_m);
+ }
}
return retval;
}
-#else
-int wposet_mb1_to_pose(wposet_t **dest, mb1_t *src, long int utmZone)
+int wposet_mb1_to_pose_cb(wposet_t **dest, mb1_t *src, GeoToTMCallback geocon)
{
- int retval=-1;
- if(NULL!=dest && NULL!=src){
+ int retval = -1;
+
+ if(NULL != dest && NULL != src){
+
wposet_t *pose = (wposet_t *)(*dest);
- if(NULL==pose){
- pose=wposet_dnew();
- *dest=pose;
+
+ if(NULL == pose){
+ pose = wposet_dnew();
+ *dest = pose;
}
- if(NULL!=pose){
+
+ if(NULL != pose){
poseT *obj = static_cast(pose->obj);
- obj->time = src->ts;
- NavUtils::geoToUtm( Math::degToRad(src->lat),
- Math::degToRad(src->lon),
- utmZone, &(obj->x), &(obj->y));
- obj->z = src->depth;
- obj->phi=0.0;
- obj->theta=0.0;
- obj->psi=src->hdg;
- obj->gpsValid=(obj->z<2?true:false);
- obj->bottomLock=true;
- obj->dvlValid=true;
- // TRN can't intialize if vx == 0
- obj->vx = 0.01;
- obj->vy = 0.;
- obj->vz = 0.;
- // wx not required; can use these (how determined?)
- // obj->wx = -3.332e-002;
- // obj->wy = -9.155e-003;
- // obj->wz = -3.076e-002;
- obj->wx = 0.;
- obj->wy = 0.;
- obj->wz = 0.;
- retval=0;
- }
+ double easting_m = 0.;
+ double northing_m = 0.;
+ geocon(Math::degToRad(src->lat),
+ Math::degToRad(src->lon),
+ &easting_m, &northing_m);
+
+ retval = wposet_mb1_fill_pose(obj, src, easting_m, northing_m);
+ }
}
return retval;
}
-#endif
int wposet_msg_to_pose(wposet_t **dest, char *src)
{
@@ -1479,95 +1477,99 @@ int wmeast_meas_to_cdata(mt_cdata_t **dest, wmeast_t *src)
return retval;
}
-#ifdef TRN_USE_PROJ
-int wmeast_mb1_to_meas(wmeast_t **dest, mb1_t *src, void *pjptr)
+static int wmeast_mb1_fill_meas(measT *dest, mb1_t *src, double easting_m, double northing_m)
+{
+ int retval = -1;
+
+ if(dest != NULL && src != NULL) {
+ dest->time = src->ts;
+ dest->ping_number = src->ping_number;
+ dest->dataType=2;
+ dest->z=src->depth;
+
+ dest->x = easting_m;
+ dest->y = northing_m;
+
+ for(int i=0;inumMeas;i++){
+ // TODO: fill in measT from ping...
+ dest->beamNums[i] = src->beams[i].beam_num;
+ dest->alongTrack[i] = src->beams[i].rhox;
+ dest->crossTrack[i] = src->beams[i].rhoy;
+ dest->altitudes[i] = src->beams[i].rhoz;
+ double rho[3] = {dest->alongTrack[i], dest->crossTrack[i], dest->altitudes[i]};
+ double rhoNorm = vnorm( rho );
+ dest->ranges[i] = rhoNorm;
+ // [rhoNorm = sqrt(ax^2 + ay^2 + az^2)] (i.e. range magnitude)
+ dest->measStatus[i] = (rhoNorm > 1 ? true : false);
+ // obj->covariance[i] = 0.0;
+ // obj->alphas[i] = 0.0;
+ }
+ retval = 0;
+ }
+ return retval;
+}
+
+int wmeast_mb1_to_meas(wmeast_t **dest, mb1_t *src, wgeocon_t *geocon)
{
int retval=-1;
- if(NULL!=dest && NULL!=src && NULL!=pjptr){
+
+ if(NULL != dest && NULL != src){
+
wmeast_t *meas = (wmeast_t *)(*dest);
- if(NULL==meas){
- meas=wmeast_new(src->nbeams);
- *dest=meas;
+
+ if(NULL == meas){
+ meas = wmeast_new(src->nbeams);
+ *dest = meas;
}
- if(NULL!=meas){
- int i=0;
+
+ if(NULL != meas){
+
measT *obj = static_cast(meas->obj);
- obj->time = src->ts;
- obj->ping_number = src->ping_number;
- obj->dataType=2;
- PJ *p = (PJ *) pjptr;
- PJ_COORD c;
- c.v[0] = src->lon;
- c.v[1] = src->lat;
- c = proj_trans(p, PJ_FWD, c);
- obj->x = c.v[1];
- obj->y = c.v[0];
- obj->z=src->depth;
- for(i=0;inumMeas;i++){
- // TODO: fill in measT from ping...
- obj->beamNums[i] = src->beams[i].beam_num;
- obj->alongTrack[i] = src->beams[i].rhox;
- obj->crossTrack[i] = src->beams[i].rhoy;
- obj->altitudes[i] = src->beams[i].rhoz;
- double rho[3] = {obj->alongTrack[i], obj->crossTrack[i], obj->altitudes[i]};
- double rhoNorm = vnorm( rho );
- obj->ranges[i] = rhoNorm;
- // [rhoNorm = sqrt(ax^2 + ay^2 + az^2)] (i.e. range magnitude)
- obj->measStatus[i] = rhoNorm>1?true:false;
-// obj->covariance[i] = 0.0;
-// obj->alphas[i] = 0.0;
- }
- retval=0;
- }
+ double easting_m = 0.;
+ double northing_m = 0.;
+ wgeocon_geo_to_mp(geocon, Math::degToRad(src->lat),
+ Math::degToRad(src->lon),
+ &easting_m, &northing_m);
+
+ retval = wmeast_mb1_fill_meas(obj, src, easting_m, northing_m);
+ }
}
return retval;
}
-#else
-int wmeast_mb1_to_meas(wmeast_t **dest, mb1_t *src, long int utmZone)
+int wmeast_mb1_to_meas_cb(wmeast_t **dest, mb1_t *src, GeoToTMCallback geocon)
{
- int retval=-1;
- if(NULL!=dest && NULL!=src){
+ int retval = -1;
+
+ if(NULL != dest && NULL != src){
+
wmeast_t *meas = (wmeast_t *)(*dest);
- if(NULL==meas){
- meas=wmeast_new(src->nbeams);
- *dest=meas;
+
+ if(NULL == meas){
+ meas = wmeast_new(src->nbeams);
+ *dest = meas;
}
- if(NULL!=meas){
- int i=0;
+
+ if(NULL != meas){
+
measT *obj = static_cast(meas->obj);
- obj->time = src->ts;
- obj->ping_number = src->ping_number;
- obj->dataType=2;
- obj->z=src->depth;
- NavUtils::geoToUtm( Math::degToRad(src->lat),
- Math::degToRad(src->lon),
- utmZone, &(obj->x), &(obj->y));
- for(i=0;inumMeas;i++){
- // TODO: fill in measT from ping...
- obj->beamNums[i] = src->beams[i].beam_num;
- obj->alongTrack[i] = src->beams[i].rhox;
- obj->crossTrack[i] = src->beams[i].rhoy;
- obj->altitudes[i] = src->beams[i].rhoz;
- double rho[3] = {obj->alongTrack[i], obj->crossTrack[i], obj->altitudes[i]};
- double rhoNorm = vnorm( rho );
- obj->ranges[i] = rhoNorm;
- // [rhoNorm = sqrt(ax^2 + ay^2 + az^2)] (i.e. range magnitude)
- obj->measStatus[i] = rhoNorm>1?true:false;
-// obj->covariance[i] = 0.0;
-// obj->alphas[i] = 0.0;
- }
+ double easting_m = 0.;
+ double northing_m = 0.;
- retval=0;
+ geocon(Math::degToRad(src->lat),
+ Math::degToRad(src->lon),
+ &easting_m, &northing_m);
+
+ retval = wmeast_mb1_fill_meas(obj, src, easting_m, northing_m);
}
}
return retval;
}
-#endif
+
int wmeast_msg_to_meas(wmeast_t **dest, char *src)
{
@@ -1848,14 +1850,10 @@ trn_config_t *trncfg_dnew()
return instance;
}
-trn_config_t *trncfg_new(char *host,
- int port,
-#ifdef TRN_USE_PROJ
- char *crs,
-#else
- long int utm_zone,
-#endif
- int map_type,
+trn_config_t *trncfg_new(char *host,int port,
+ bool use_proj,
+ int projection, char *crs,
+ long int utm_zone, int map_type,
int sensor_type,
int filter_type,
int filter_grade,
@@ -1877,6 +1875,9 @@ trn_config_t *trncfg_new(char *host,
if(NULL!=instance){
instance->trn_host=(NULL!=host?strdup(host):NULL);
instance->trn_port=port;
+ instance->use_proj = use_proj;
+ instance->projection = projection;
+ instance->trn_crs = (NULL != crs ? strdup(crs) : NULL);
instance->map_file=(NULL!=map_file?strdup(map_file):strdup("map.dfl"));
instance->cfg_file=(NULL!=cfg_file?strdup(cfg_file):strdup("cfg.dfl"));
instance->particles_file=(NULL!=particles_file?strdup(particles_file):strdup("particles.dfl"));
@@ -1884,12 +1885,7 @@ trn_config_t *trncfg_new(char *host,
instance->sensor_type=sensor_type;
instance->filter_type=filter_type;
instance->map_type=map_type;
-#ifdef TRN_USE_PROJ
- instance->crs=(NULL!=crs?strdup(crs):strdup("UTM10N"));
-#else
instance->utm_zone=utm_zone;
-#endif
-
instance->mod_weight=mod_weight;
instance->filter_reinit=filter_reinit;
instance->filter_grade=filter_grade;
@@ -1911,6 +1907,8 @@ void trncfg_destroy(trn_config_t **pself)
if(NULL!=self->trn_host)
free(self->trn_host);
+ if(NULL!=self->trn_crs)
+ free(self->trn_crs);
if(NULL!=self->map_file)
free(self->map_file);
if(NULL!=self->particles_file)
@@ -1929,45 +1927,23 @@ void trncfg_destroy(trn_config_t **pself)
void trncfg_show(trn_config_t *obj, bool verbose, int indent)
{
if (NULL != obj) {
- fprintf(stderr,"%*s[self %10p]\n",indent,(indent>0?" ":""), obj);
- fprintf(stderr,"%*s[host %10s]\n",indent,(indent>0?" ":""), obj->trn_host);
- fprintf(stderr,"%*s[port %10d]\n",indent,(indent>0?" ":""), obj->trn_port);
-#ifdef TRN_USE_PROJ
- fprintf(stderr,"%*s[crs %10s]\n",indent,(indent>0?" ":""), obj->crs);
-#else
- fprintf(stderr,"%*s[utm %10ld]\n",indent,(indent>0?" ":""), obj->utm_zone);
-#endif
- fprintf(stderr,"%*s[mtype %10d]\n",indent,(indent>0?" ":""), obj->map_type);
- fprintf(stderr,"%*s[ftype %10d]\n",indent,(indent>0?" ":""), obj->filter_type);
- fprintf(stderr,"%*s[map_file %10s]\n",indent,(indent>0?" ":""), obj->map_file);
- fprintf(stderr,"%*s[cfg_file %10s]\n",indent,(indent>0?" ":""), obj->cfg_file);
- fprintf(stderr,"%*s[part_file %10s]\n",indent,(indent>0?" ":""), obj->particles_file);
- fprintf(stderr,"%*s[log_dir %10s]\n",indent,(indent>0?" ":""), obj->log_dir);
- fprintf(stderr,"%*s[maxNcov %10s%.3lf]\n",indent,(indent>0?" ":""), "",obj->max_northing_cov);
- fprintf(stderr,"%*s[maxNerr %10s%.3lf]\n",indent,(indent>0?" ":""), "",obj->max_northing_err);
- fprintf(stderr,"%*s[maxEcov %10s%.3lf]\n",indent,(indent>0?" ":""), "",obj->max_easting_cov);
- fprintf(stderr,"%*s[maxEerr %10s%.3lf]\n",indent,(indent>0?" ":""), "",obj->max_easting_err);
- }
-}
-
-int trnw_utm_to_geo(double northing, double easting, long utmZone,
- double *lat_deg, double *lon_deg)
-{
-// return NavUtils::utmToGeo(northing,easting,utmZone,lat_rad,lon_rad);
- double lat_rad=0.0;
- double lon_rad=0.0;
-
- int retval=NavUtils::utmToGeo(northing,easting,utmZone,&lat_rad,&lon_rad);
- *lat_deg=Math::radToDeg(lat_rad);
- *lon_deg=Math::radToDeg(lon_rad);
- return retval;
+ fprintf(stderr,"%*s[self %10p]\n",indent,(indent>0?" ":""), obj);
+ fprintf(stderr,"%*s[host %10s]\n",indent,(indent>0?" ":""), obj->trn_host);
+ fprintf(stderr,"%*s[port %10d]\n",indent,(indent>0?" ":""), obj->trn_port);
+ fprintf(stderr,"%*s[use_proj %10c]\n",indent,(indent>0?" ":""), (obj->use_proj ? 'Y' : 'N'));
+ fprintf(stderr,"%*s[projection %10d]\n",indent,(indent>0?" ":""), obj->projection);
+ fprintf(stderr,"%*s[trn_crs %10s]\n",indent,(indent>0?" ":""), (obj->trn_crs != NULL ? obj->trn_crs : ""));
+ fprintf(stderr,"%*s[utm %10ld]\n",indent,(indent>0?" ":""), obj->utm_zone);
+ fprintf(stderr,"%*s[mtype %10d]\n",indent,(indent>0?" ":""), obj->map_type);
+ fprintf(stderr,"%*s[ftype %10d]\n",indent,(indent>0?" ":""), obj->filter_type);
+ fprintf(stderr,"%*s[map_file %10s]\n",indent,(indent>0?" ":""), obj->map_file);
+ fprintf(stderr,"%*s[cfg_file %10s]\n",indent,(indent>0?" ":""), obj->cfg_file);
+ fprintf(stderr,"%*s[part_file %10s]\n",indent,(indent>0?" ":""), obj->particles_file);
+ fprintf(stderr,"%*s[log_dir %10s]\n",indent,(indent>0?" ":""), obj->log_dir);
+ fprintf(stderr,"%*s[maxNcov %10s%.3lf]\n",indent,(indent>0?" ":""), "",obj->max_northing_cov);
+ fprintf(stderr,"%*s[maxNerr %10s%.3lf]\n",indent,(indent>0?" ":""), "",obj->max_northing_err);
+ fprintf(stderr,"%*s[maxEcov %10s%.3lf]\n",indent,(indent>0?" ":""), "",obj->max_easting_cov);
+ fprintf(stderr,"%*s[maxEerr %10s%.3lf]\n",indent,(indent>0?" ":""), "",obj->max_easting_err);
+ }
}
-// End function trnw_utmToGeo
-int trnw_geo_to_utm(double lat_deg, double lon_deg, long int utmZone, double *northing, double *easting)
-{
- return NavUtils::geoToUtm( Math::degToRad(lat_deg),
- Math::degToRad(lon_deg),
- utmZone, northing, easting);
-}
-// End function trnw_utmToGeo
diff --git a/src/mbtrnav/trnw/trnw.h b/src/mbtrnav/trnw/trnw.h
index b94119fc2..3ec247f24 100644
--- a/src/mbtrnav/trnw/trnw.h
+++ b/src/mbtrnav/trnw/trnw.h
@@ -96,6 +96,7 @@
#endif
#include "mb1_msg.h"
#include "trn_msg.h"
+#include "GeoCon.h"
/////////////////////////
// Macros
@@ -133,6 +134,9 @@ typedef enum {
typedef struct trn_config_s{
char *trn_host;
int trn_port;
+ bool use_proj;
+ int projection;
+ char *trn_crs;
char *map_file;
char *cfg_file;
char *particles_file;
@@ -140,11 +144,7 @@ typedef struct trn_config_s{
int sensor_type;
int filter_type;
int map_type;
-#ifdef TRN_USE_PROJ
- char *crs;
-#else
long int utm_zone;
-#endif
int mod_weight;
int filter_reinit;
int filter_grade;
@@ -164,11 +164,10 @@ extern "C" {
// TRN config API
trn_config_t *trncfg_dnew();
trn_config_t *trncfg_new(char *host, int port,
-#ifdef TRN_USE_PROJ
- char *crs,
-#else
+ bool use_proj,
+ int projection,
+ char *trn_crs,
long int utm_zone,
-#endif
int map_type,
int sensor_type,
int filter_type,
@@ -256,11 +255,9 @@ extern "C" {
void wposet_show(wposet_t *self, bool verbose, int indent);
int wposet_cdata_to_pose(wposet_t **dest, pt_cdata_t *src);
int wposet_pose_to_cdata(pt_cdata_t **dest, wposet_t *src);
-#ifdef TRN_USE_PROJ
- int wposet_mb1_to_pose(wposet_t **dest, mb1_t *src, void *pjptr);
-#else
- int wposet_mb1_to_pose(wposet_t **dest, mb1_t *src, long int utmZone);
-#endif
+ // int wposet_mb1_to_pose(wposet_t **dest, mb1_t *src, long int utmZone);
+ int wposet_mb1_to_pose(wposet_t **dest, mb1_t *src, wgeocon_t *geocon);
+ int wposet_mb1_to_pose_cb(wposet_t **dest, mb1_t *src, GeoToTMCallback geocon);
int wposet_msg_to_pose(wposet_t **dest, char *src);
int wposet_serialize(char **dest, wposet_t *src, int len);
int wposet_unserialize(wposet_t **dest, char *src, int len);
@@ -272,11 +269,9 @@ extern "C" {
void wmeast_show(wmeast_t *self, bool verbose, int indent);
int wmeast_cdata_to_meas(wmeast_t **dest, mt_cdata_t *src);
int wmeast_meas_to_cdata(mt_cdata_t **dest, wmeast_t *src);
-#ifdef TRN_USE_PROJ
- int wmeast_mb1_to_meas(wmeast_t **dest, mb1_t *src, void *pjptr);
-#else
- int wmeast_mb1_to_meas(wmeast_t **dest, mb1_t *src, long int utmZone);
-#endif
+ // int wmeast_mb1_to_meas(wmeast_t **dest, mb1_t *src, long int utmZone);
+ int wmeast_mb1_to_meas(wmeast_t **dest, mb1_t *src, wgeocon_t *geocon);
+ int wmeast_mb1_to_meas_cb(wmeast_t **dest, mb1_t *src, GeoToTMCallback geocon);
int wmeast_msg_to_meas(wmeast_t **dest, char *src);
int wmeast_serialize(char **dest, wmeast_t *src, int len);
int wmeast_unserialize(wmeast_t **dest, char *src, int len);
@@ -299,8 +294,8 @@ extern "C" {
void trnw_msg_show(char *msg, bool verbose, int indent);
// utils
- int trnw_utm_to_geo(double northing, double easting, long utmZone, double *lat_deg, double *lon_deg);
- int trnw_geo_to_utm(double lat_deg, double lon_deg, long int utmZone, double *northing, double *easting);
+// int trnw_utm_to_geo(double northing, double easting, long utmZone, double *lat_deg, double *lon_deg);
+// int trnw_geo_to_utm(double lat_deg, double lon_deg, long int utmZone, double *northing, double *easting);
#ifdef __cplusplus
diff --git a/src/mbtrnav/utils/csvlog_player.cpp b/src/mbtrnav/utils/csvlog_player.cpp
index 0be0249c7..60d0fa2a4 100644
--- a/src/mbtrnav/utils/csvlog_player.cpp
+++ b/src/mbtrnav/utils/csvlog_player.cpp
@@ -1143,7 +1143,7 @@ class CSVLogPlayer
dest->psi_dot_berg = 0.;
const parse_kv_t *pcur = dval_map;
- int i=0;
+
while(pcur->key != NULL) {
const char *fmt = map_fmt(map, pcur->key);
int idx = map_idx(map, pcur->key);
@@ -1157,11 +1157,10 @@ class CSVLogPlayer
}
pcur++;
- i++;
}
pcur = bval_map;
- i=0;
+
while(pcur->key != NULL) {
const char *fmt = map_fmt(map, pcur->key);
int idx = map_idx(map, pcur->key);
@@ -1178,7 +1177,6 @@ class CSVLogPlayer
}
pcur++;
- i++;
}
if(dest->z < 2.) {
@@ -1441,7 +1439,7 @@ class CSVLogPlayer
dest->dataType = mConfig.trn_sensor();
parse_kv_t *cur = dval_map;
- int i=0;
+
while(cur->key != NULL) {
const char *fmt = map_fmt(map, cur->key);
int idx = map_idx(map, cur->key);
@@ -1455,11 +1453,10 @@ class CSVLogPlayer
}
cur++;
- i++;
}
cur = uval_map;
- i=0;
+
while(cur->key != NULL) {
const char *fmt = map_fmt(map, cur->key);
int idx = map_idx(map, cur->key);
@@ -1473,7 +1470,6 @@ class CSVLogPlayer
}
cur++;
- i++;
}
diff --git a/src/mbtrnutils/CMakeLists.txt b/src/mbtrnutils/CMakeLists.txt
index 471013331..0654a4650 100644
--- a/src/mbtrnutils/CMakeLists.txt
+++ b/src/mbtrnutils/CMakeLists.txt
@@ -50,7 +50,7 @@ target_include_directories(mbtrnpp PRIVATE ${NetCDF_INCLUDE_DIRS} ${libPROJ_INCL
${CMAKE_SOURCE_DIR}/src/mbtrnav/utils
${CMAKE_SOURCE_DIR}/src/mbtrn/mb1r )
target_compile_definitions(mbtrnpp PRIVATE WITH_MBTNAV)
-target_link_libraries(mbtrnpp PRIVATE mbio mbaux trnw qnx newmat tnav geolib netif r7kr mb1r qnx mbtrnframe NetCDF::NetCDF LibPROJ::LibPROJ )
+target_link_libraries(mbtrnpp PRIVATE mbio mbaux trnw qnx newmat tnav geolib netif r7kr mb1r qnx mbtrnframe geocon NetCDF::NetCDF LibPROJ::LibPROJ )
#------------------------------------------------------------------------------
diff --git a/src/mbtrnutils/mbtrnpp.c b/src/mbtrnutils/mbtrnpp.c
index 5b46bcd24..089af8b4e 100644
--- a/src/mbtrnutils/mbtrnpp.c
+++ b/src/mbtrnutils/mbtrnpp.c
@@ -49,6 +49,7 @@
#include
#include
#include
+#include
#include "mb_status.h"
#include "mb_format.h"
@@ -79,6 +80,7 @@
#include "mb1_msg.h"
#include "mb1-reader.h"
#endif // WITH_MBTNAV
+#include "GeoCon.h"
// Features
#ifndef WITHOUT_MB1_READER
@@ -197,14 +199,18 @@ typedef struct mbtrnpp_opts_s{
// opt "trn-en"
bool trn_en;
-#ifdef TRN_USE_PROJ
+ // opt "useproj"
+ bool use_proj;
+
+ // opt "projection"
+ int projection;
+
// opt "trn-crs"
char *trn_crs;
-#else
+
// opt "trn-utm"
long int trn_utm;
-#endif
-
+
// opt "trn-map"
char *trn_map;
@@ -420,13 +426,17 @@ typedef struct mbtrnpp_cfg_s{
// TRN processing enable
bool trn_enable;
-#ifdef TRN_USE_PROJ
+ // use proj instead of GCTP
+ bool use_proj;
+
+ // projection
+ int projection;
+
// TRN CRS
char *trn_crs;
-#else
+
// TRN UTM zone
long int trn_utm_zone;
-#endif
// TRN map type
int trn_mtype;
@@ -577,6 +587,8 @@ s=NULL;\
#define OPT_TIDE_MODEL_DFL NULL
#define OPT_LOG_DIRECTORY_DFL "."
#define OPT_OUTPUT_DFL NULL
+#define OPT_USE_PROJ_DFL true
+#define OPT_PROJECTION_DFL 0
#define OPT_SWATH_WIDTH_DFL 90
#define OPT_SOUNDINGS_DFL 11
#define OPT_MEDIAN_FILTER_DFL NULL
@@ -590,11 +602,8 @@ s=NULL;\
#define OPT_STATFLAGS_DFL MBTRNPP_STAT_FLAGS_DFL
#define OPT_STATFLAG_STR_DFL "MSF_STATUS|MSF_EVENT|MSF_ASTAT|MSF_PSTAT"
#define OPT_TRN_EN_DFL true
-#ifdef TRN_USE_PROJ
#define OPT_TRN_CRS_DFL TRN_CRS_DFL
-#else
#define OPT_TRN_UTM_DFL TRN_UTM_DFL
-#endif
#define OPT_MAP_DFL NULL
#define OPT_CFG_DFL NULL
#define OPT_PAR_DFL NULL
@@ -668,13 +677,12 @@ s=NULL;\
#define MBTRNPP_LOG_EXT ".log"
#ifdef WITH_MBTNAV
-#ifdef TRN_USE_PROJ
+#define USE_PROJ_DFL true
+#define PROJECTION_DFL 0
#define TRN_CRS_DFL "UTM10N"
-#else
#define UTM_MONTEREY_BAY 10L
#define UTM_AXIAL 12L
#define TRN_UTM_DFL UTM_MONTEREY_BAY
-#endif
#define TRN_MTYPE_DFL TRN_MAP_BO
#define TRN_SENSOR_TYPE_DFL TRN_SENSOR_MB
@@ -940,6 +948,8 @@ static double stats_prev_end = 0.0;
static double stats_prev_start = 0.0;
// system clock resolution logging enable/disable
static bool log_clock_res = true;
+// user (signal) interrupt flag
+static bool g_interrupted = false;
#ifdef MST_STATS_EN
#define MBTRNPP_UPDATE_STATS(p, l, f) (mbtrnpp_update_stats(p, l, f))
@@ -1064,13 +1074,22 @@ int mbtrnpp_trnu_pubempty_osocket(double time, double lat, double lon, double de
char *mbtrnpp_trn_updatestr(char *dest, int len, trn_update_t *update, int indent);
#endif // WITH_MBTNAV
-#ifdef TRN_USE_PROJ
-/* TRN uses a projected coordinate system - the navigation must be transformed from
- geographic coordinates to the Coordinate Reference System (CRS) used for the reference
- map. The pointer pjptr points to a Proj context that that is used for forward and
- inverse transforms from Geographic to the TRN CRS. */
-void *pjptr = NULL;
-#endif
+// TRN uses a projected coordinate system - the navigation must be transformed from
+// geographic coordinates to the Coordinate Reference System (CRS) used for the reference
+// map. The pointer pjptr points to a Proj context that that is used for forward and
+// inverse transforms from Geographic to the TRN CRS.
+
+static void *pjptr = NULL;
+
+#define DEGTORAD(d) (d * M_PI/180.)
+#define RADTODEG(r) (r * 180./M_PI)
+
+// geographic coordinate transform callbacks (GeoToTMCallback)
+int mbtrnpp_geo_to_tm_proj(double lat_rad, double lon_rad, double *r_northing_m, double *r_easting_m);
+int mbtrnpp_geo_to_tm_gctp(double lat_rad, double lon_rad, double *r_northing_m, double *r_easting_m);
+
+// pointer to selected geographic coordinate transform callback
+GeoToTMCallback mbtrnpp_geo_to_tm = mbtrnpp_geo_to_tm_proj;
// TRN reinit flag - forces reinitializing the TRN filter
bool reinit_flag=true;
@@ -1517,11 +1536,10 @@ static int s_mbtrnpp_init_cfg(mbtrnpp_cfg_t *cfg)
cfg->trn_status_interval_sec=MBTRNPP_STAT_PERIOD_SEC;
cfg->mbtrnpp_stat_flags=MBTRNPP_STAT_FLAGS_DFL;
cfg->trn_enable=false;
-#ifdef TRN_USE_PROJ
+ cfg->use_proj=USE_PROJ_DFL;
+ cfg->projection=PROJECTION_DFL;
cfg->trn_crs=strdup(TRN_CRS_DFL);
-#else
cfg->trn_utm_zone=TRN_UTM_DFL;
-#endif
cfg->trn_mtype=TRN_MTYPE_DFL;
cfg->trn_sensor_type=TRN_SENSOR_TYPE_DFL;
cfg->trn_ftype=TRN_FTYPE_DFL;
@@ -1580,11 +1598,10 @@ static int s_mbtrnpp_init_opts(mbtrnpp_opts_t *opts)
opts->statflags_str=strdup(OPT_STATFLAG_STR_DFL);
opts->statflags=OPT_STATFLAGS_DFL;
opts->trn_en=OPT_TRN_EN_DFL;
-#ifdef TRN_USE_PROJ
+ opts->use_proj=OPT_USE_PROJ_DFL;
+ opts->projection=OPT_PROJECTION_DFL;
opts->trn_crs=strdup(OPT_TRN_CRS_DFL);
-#else
opts->trn_utm=OPT_TRN_UTM_DFL;
-#endif
opts->trn_map=CHK_STRDUP(OPT_MAP_DFL);
opts->trn_cfg=CHK_STRDUP(OPT_CFG_DFL);
opts->trn_par=CHK_STRDUP(OPT_PAR_DFL);
@@ -1671,19 +1688,16 @@ static int s_mbtrnpp_cfgstr(char **pdest, size_t olen, mbtrnpp_cfg_t *self, cons
mbb_printf(optr, "%s%*s%*s%s%*d%s", pre, indent, (indent>0?" ":""), wkey, "verbose", sep, wval, self->verbose, del);
mbb_printf(optr, "%s%*s%*s%s%*d%s", pre, indent, (indent>0?" ":""), wkey, "input_mode", sep, wval, self->input_mode, del);
mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "input", sep, wval, self->input, del);
- mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "socket_definition", sep, wval, self->socket_definition, del);
- mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "output_mb1_file", sep, wval, self->output_mb1_file, del);
- mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "output_trn_file", sep, wval, self->output_trn_file, del);
+
mbb_printf(optr, "%s%*s%*s%s%*d%s", pre, indent, (indent>0?" ":""), wkey, "format", sep, wval, self->format, del);
- mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "platform-file", sep, wval, self->platform_file, del);
+ mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "socket_definition", sep, wval, self->socket_definition, del);
mbb_printf(optr, "%s%*s%*s%s%*c%s", pre, indent, (indent>0?" ":""), wkey, "use_platform_file", sep, wval, BOOL2YNC(self->use_platform_file), del);
+ mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "platform-file", sep, wval, self->platform_file, del);
mbb_printf(optr, "%s%*s%*s%s%*d%s", pre, indent, (indent>0?" ":""), wkey, "platform-target-sensor", sep, wval, self->target_sensor, del);
- mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "tide-model", sep, wval, self->tide_model, del);
- mbb_printf(optr, "%s%*s%*s%s%*c%s", pre, indent, (indent>0?" ":""), wkey, "use_tide_model", sep, wval, BOOL2YNC(self->use_tide_model), del);
mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "log-directory", sep, wval, self->log_directory, del);
- mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "trn_log_dir", sep, wval, self->trn_log_dir, del);
- mbb_printf(optr, "%s%*s%*s%s%*c%s", pre, indent, (indent>0?" ":""), wkey, "make_logs", sep, wval, BOOL2YNC(self->make_logs), del);
- mbb_printf(optr, "%s%*s%*s%s%*c%s", pre, indent, (indent>0?" ":""), wkey, "platform-file", sep, wval, BOOL2YNC(self->make_logs), del);
+ mbb_printf(optr, "%s%*s%*s%s%*c%s", pre, indent, (indent>0?" ":""), wkey, "use_tide_model", sep, wval, BOOL2YNC(self->use_tide_model), del);
+ mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "tide-model", sep, wval, self->tide_model, del);
+
mbb_printf(optr, "%s%*s%*s%s%*.2lf%s", pre, indent, (indent>0?" ":""), wkey, "swath-width", sep, wval, self->swath_width, del);
mbb_printf(optr, "%s%*s%*s%s%*d%s", pre, indent, (indent>0?" ":""), wkey, "n_output_soundings", sep, wval, self->n_output_soundings, del);
mbb_printf(optr, "%s%*s%*s%s%*.2lf%s", pre, indent, (indent>0?" ":""), wkey, "median_filter_threshold", sep, wval, self->median_filter_threshold, del);
@@ -1691,31 +1705,20 @@ static int s_mbtrnpp_cfgstr(char **pdest, size_t olen, mbtrnpp_cfg_t *self, cons
mbb_printf(optr, "%s%*s%*s%s%*d%s", pre, indent, (indent>0?" ":""), wkey, "median_filter_n_along", sep, wval, self->median_filter_n_along, del);
mbb_printf(optr, "%s%*s%*s%s%*c%s", pre, indent, (indent>0?" ":""), wkey, "median_filter_en", sep, wval, BOOL2YNC(self->median_filter_en), del);
mbb_printf(optr, "%s%*s%*s%s%*d%s", pre, indent, (indent>0?" ":""), wkey, "n_buffer_max", sep, wval, self->n_buffer_max, del);
- mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "mb1svr_host", sep, wval, self->mb1svr_host, del);
- mbb_printf(optr, "%s%*s%*s%s%*d%s", pre, indent, (indent>0?" ":""), wkey, "mb1svr_port", sep, wval, self->mb1svr_port, del);
-
- mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "trnsvr_host", sep, wval, self->trnsvr_host, del);
- mbb_printf(optr, "%s%*s%*s%s%*d%s", pre, indent, (indent>0?" ":""), wkey, "trnsvr_port", sep, wval, self->trnsvr_port, del);
- mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "trnusvr_host", sep, wval, self->trnusvr_host, del);
- mbb_printf(optr, "%s%*s%*s%s%*d%s", pre, indent, (indent>0?" ":""), wkey, "trnusvr_port", sep, wval, self->trnusvr_port, del);
- mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "trnumsvr_group", sep, wval, self->trnumsvr_group, del);
- mbb_printf(optr, "%s%*s%*s%s%*d%s", pre, indent, (indent>0?" ":""), wkey, "trnumsvr_port", sep, wval, self->trnumsvr_port, del);
- mbb_printf(optr, "%s%*s%*s%s%*d%s", pre, indent, (indent>0?" ":""), wkey, "trnumsvr_ttl", sep, wval, self->trnumsvr_ttl, del);
- mbb_printf(optr, "%s%*s%*s%s%*X%s", pre, indent, (indent>0?" ":""), wkey, "output_flags", sep, wval, self->output_flags, del);
- mbb_printf(optr, "%s%*s%*s%s%*d%s", pre, indent, (indent>0?" ":""), wkey, "mbsvr_hbtok", sep, wval, self->mbsvr_hbtok, del);
- mbb_printf(optr, "%s%*s%*s%s%*.2lf%s", pre, indent, (indent>0?" ":""), wkey, "mbsvr_hbto", sep, wval, self->mbsvr_hbto, del);
- mbb_printf(optr, "%s%*s%*s%s%*.2lf%s", pre, indent, (indent>0?" ":""), wkey, "trnsvr_hbto", sep, wval, self->trnsvr_hbto, del);
- mbb_printf(optr, "%s%*s%*s%s%*.2lf%s", pre, indent, (indent>0?" ":""), wkey, "trnusvr_hbto", sep, wval, self->trnusvr_hbto, del);
mbb_printf(optr, "%s%*s%*s%s%*"PRId64"%s", pre, indent, (indent>0?" ":""), wkey, "mbtrnpp_loop_delay_msec", sep, wval, self->mbtrnpp_loop_delay_msec, del);
mbb_printf(optr, "%s%*s%*s%s%*.2lf%s", pre, indent, (indent>0?" ":""), wkey, "trn_status_interval_sec", sep, wval, self->trn_status_interval_sec, del);
mbb_printf(optr, "%s%*s%*s%s%*X%s", pre, indent, (indent>0?" ":""), wkey, "mbtrnpp_stat_flags", sep, wval, self->mbtrnpp_stat_flags, del);
- mbb_printf(optr, "%s%*s%*s%s%*s/%d%s", pre, indent, (indent>0?" ":""), wkey, "trn_dev", sep, wval, r7k_devidstr(self->trn_dev), self->trn_dev, del);
+
mbb_printf(optr, "%s%*s%*s%s%*c%s", pre, indent, (indent>0?" ":""), wkey, "trn_enable", sep, wval, BOOL2YNC(self->trn_enable), del);
-#ifdef TRN_USE_PROJ
+ mbb_printf(optr, "%s%*s%*s%s%*s/%d%s", pre, indent, (indent>0?" ":""), wkey, "trn_dev", sep, wval, r7k_devidstr(self->trn_dev), self->trn_dev, del);
+ mbb_printf(optr, "%s%*s%*s%s%*c%s", pre, indent, (indent>0?" ":""), wkey, "use_proj", sep, wval, BOOL2YNC(self->use_proj), del);
+ mbb_printf(optr, "%s%*s%*s%s%*d%s", pre, indent, (indent>0?" ":""), wkey, "projection", sep, wval, self->projection, del);
mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "trn_crs", sep, wval, self->trn_crs, del);
-#else
- mbb_printf(optr, "%s%*s%*s%s%*ld%s", pre, indent, (indent>0?" ":""), wkey, "trn_utm_zone", sep, wval, self->trn_utm_zone, del);
-#endif
+ mbb_printf(optr, "%s%*s%*s%s%*ld%s", pre, indent, (indent>0?" ":""), wkey, "trn_utm_zone", sep, wval, self->trn_utm_zone, del);
+ mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "trn_map_file", sep, wval, self->trn_map_file, del);
+ mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "trn_cfg_file", sep, wval, self->trn_cfg_file, del);
+ mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "trn_particles_file", sep, wval, self->trn_particles_file, del);
+ mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "trn_mission_dir", sep, wval, self->trn_mission_id, del);
mbb_printf(optr, "%s%*s%*s%s%*d%s", pre, indent, (indent>0?" ":""), wkey, "trn_mtype", sep, wval, self->trn_mtype, del);
mbb_printf(optr, "%s%*s%*s%s%*d%s", pre, indent, (indent>0?" ":""), wkey, "trn_sensor_type", sep, wval, self->trn_sensor_type, del);
mbb_printf(optr, "%s%*s%*s%s%*d%s", pre, indent, (indent>0?" ":""), wkey, "trn_ftype", sep, wval, self->trn_ftype, del);
@@ -1726,10 +1729,6 @@ static int s_mbtrnpp_cfgstr(char **pdest, size_t olen, mbtrnpp_cfg_t *self, cons
mbb_printf(optr, "%s%*s%*s%s%*.2lf%s", pre, indent, (indent>0?" ":""), wkey, "trn_max_nerr", sep, wval, self->trn_max_nerr, del);
mbb_printf(optr, "%s%*s%*s%s%*.2lf%s", pre, indent, (indent>0?" ":""), wkey, "trn_max_ecov", sep, wval, self->trn_max_ecov, del);
mbb_printf(optr, "%s%*s%*s%s%*.2lf%s", pre, indent, (indent>0?" ":""), wkey, "trn_max_eerr", sep, wval, self->trn_max_eerr, del);
- mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "trn_map_file", sep, wval, self->trn_map_file, del);
- mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "trn_cfg_file", sep, wval, self->trn_cfg_file, del);
- mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "trn_particles_file", sep, wval, self->trn_particles_file, del);
- mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "trn_mission_dir", sep, wval, self->trn_mission_id, del);
mbb_printf(optr, "%s%*s%*s%s%*u%s", pre, indent, (indent>0?" ":""), wkey, "trn_decn", sep, wval, self->trn_decn, del);
mbb_printf(optr, "%s%*s%*s%s%*.2lf%s", pre, indent, (indent>0?" ":""), wkey, "trn_decs", sep, wval, self->trn_decs, del);
mbb_printf(optr, "%s%*s%*s%s%*.2lf%s", pre, indent, (indent>0?" ":""), wkey, "covariance_magnitude_max", sep, wval, self->covariance_magnitude_max, del);
@@ -1744,6 +1743,27 @@ static int s_mbtrnpp_cfgstr(char **pdest, size_t olen, mbtrnpp_cfg_t *self, cons
mbb_printf(optr, "%s%*s%*s%s%*.2lf%s", pre, indent, (indent>0?" ":""), wkey, "reinit_zoffset_min", sep, wval, self->reinit_zoffset_min, del);
mbb_printf(optr, "%s%*s%*s%s%*.2lf%s", pre, indent, (indent>0?" ":""), wkey, "reinit_zoffset_max", sep, wval, self->reinit_zoffset_max, del);
mbb_printf(optr, "%s%*s%*s%s%*c%s", pre, indent, (indent>0?" ":""), wkey, "random_offset_enable", sep, wval, BOOL2YNC(self->random_offset_enable), del);
+
+ mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "output_mb1_file", sep, wval, self->output_mb1_file, del);
+ mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "output_trn_file", sep, wval, self->output_trn_file, del);
+ mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "trn_log_dir", sep, wval, self->trn_log_dir, del);
+ mbb_printf(optr, "%s%*s%*s%s%*c%s", pre, indent, (indent>0?" ":""), wkey, "make_logs", sep, wval, BOOL2YNC(self->make_logs), del);
+ mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "mb1svr_host", sep, wval, self->mb1svr_host, del);
+ mbb_printf(optr, "%s%*s%*s%s%*d%s", pre, indent, (indent>0?" ":""), wkey, "mb1svr_port", sep, wval, self->mb1svr_port, del);
+
+ mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "trnsvr_host", sep, wval, self->trnsvr_host, del);
+ mbb_printf(optr, "%s%*s%*s%s%*d%s", pre, indent, (indent>0?" ":""), wkey, "trnsvr_port", sep, wval, self->trnsvr_port, del);
+ mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "trnusvr_host", sep, wval, self->trnusvr_host, del);
+ mbb_printf(optr, "%s%*s%*s%s%*d%s", pre, indent, (indent>0?" ":""), wkey, "trnusvr_port", sep, wval, self->trnusvr_port, del);
+ mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "trnumsvr_group", sep, wval, self->trnumsvr_group, del);
+ mbb_printf(optr, "%s%*s%*s%s%*d%s", pre, indent, (indent>0?" ":""), wkey, "trnumsvr_port", sep, wval, self->trnumsvr_port, del);
+ mbb_printf(optr, "%s%*s%*s%s%*d%s", pre, indent, (indent>0?" ":""), wkey, "trnumsvr_ttl", sep, wval, self->trnumsvr_ttl, del);
+ mbb_printf(optr, "%s%*s%*s%s%*X%s", pre, indent, (indent>0?" ":""), wkey, "output_flags", sep, wval, self->output_flags, del);
+ mbb_printf(optr, "%s%*s%*s%s%*d%s", pre, indent, (indent>0?" ":""), wkey, "mbsvr_hbtok", sep, wval, self->mbsvr_hbtok, del);
+ mbb_printf(optr, "%s%*s%*s%s%*.2lf%s", pre, indent, (indent>0?" ":""), wkey, "mbsvr_hbto", sep, wval, self->mbsvr_hbto, del);
+ mbb_printf(optr, "%s%*s%*s%s%*.2lf%s", pre, indent, (indent>0?" ":""), wkey, "trnsvr_hbto", sep, wval, self->trnsvr_hbto, del);
+ mbb_printf(optr, "%s%*s%*s%s%*.2lf%s", pre, indent, (indent>0?" ":""), wkey, "trnusvr_hbto", sep, wval, self->trnusvr_hbto, del);
+
size_t slen = mbb_length(optr);
if(NULL == *pdest){
// set dest buffer (malloc'd, caller must free)
@@ -1784,24 +1804,19 @@ static int s_mbtrnpp_optstr(char **pdest, size_t olen, mbtrnpp_opts_t *self, con
mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "log-directory", sep, wval, self->log_directory, del);
mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "tide-model", sep, wval, self->tide_model, del);
mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "output", sep, wval, self->output, del);
+ mbb_printf(optr, "%s%*s%*s%s%*d%s", pre, indent, (indent>0?" ":""), wkey, "projection", sep, wval, self->projection, del);
mbb_printf(optr, "%s%*s%*s%s%*.2lf%s", pre, indent, (indent>0?" ":""), wkey, "swath-width", sep, wval, self->swath_width, del);
mbb_printf(optr, "%s%*s%*s%s%*d%s", pre, indent, (indent>0?" ":""), wkey, "soundings", sep, wval, self->soundings, del);
mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "median-filter", sep, wval, self->median_filter, del);
- mbb_printf(optr, "%s%*s%*s%s%*d%s", pre, indent, (indent>0?" ":""), wkey, "mbhbn", sep, wval, self->mbhbn, del);
- mbb_printf(optr, "%s%*s%*s%s%*.2lf%s", pre, indent, (indent>0?" ":""), wkey, "mbhbt", sep, wval, self->mbhbt, del);
- mbb_printf(optr, "%s%*s%*s%s%*.2lf%s", pre, indent, (indent>0?" ":""), wkey, "trnhbt", sep, wval, self->trnhbt, del);
- mbb_printf(optr, "%s%*s%*s%s%*.2lf%s", pre, indent, (indent>0?" ":""), wkey, "trnuhbt", sep, wval, self->trnuhbt, del);
- mbb_printf(optr, "%s%*s%*s%s%*d%s", pre, indent, (indent>0?" ":""), wkey, "trnumttl", sep, wval, self->trnumttl, del);
+
mbb_printf(optr, "%s%*s%*s%s%*"PRId64"%s", pre, indent, (indent>0?" ":""), wkey, "delay", sep, wval, self->delay, del);
mbb_printf(optr, "%s%*s%*s%s%*.2lf%s", pre, indent, (indent>0?" ":""), wkey, "statsec", sep, wval, self->statsec, del);
mbb_printf(optr, "%s%*s%*s%s%*X/%s%s", pre, indent, (indent>0?" ":""), wkey, "statflags", sep, wval, self->statflags, self->statflags_str, del);
+
mbb_printf(optr, "%s%*s%*s%s%*c%s", pre, indent, (indent>0?" ":""), wkey, "trn-en", sep, wval, BOOL2YNC(self->trn_en), del);
mbb_printf(optr, "%s%*s%*s%s%*s/%d%s", pre, indent, (indent>0?" ":""), wkey, "trn-dev", sep, wval, r7k_devidstr(self->trn_dev), self->trn_dev, del);
-#ifdef TRN_USE_PROJ
mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "trn-crs", sep, wval, self->trn_crs, del);
-#else
mbb_printf(optr, "%s%*s%*s%s%*ld%s", pre, indent, (indent>0?" ":""), wkey, "trn-utm", sep, wval, self->trn_utm, del);
-#endif
mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "trn-map", sep, wval, self->trn_map, del);
mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "trn-cfg", sep, wval, self->trn_cfg, del);
mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "trn-par", sep, wval, self->trn_par, del);
@@ -1816,8 +1831,6 @@ static int s_mbtrnpp_optstr(char **pdest, size_t olen, mbtrnpp_opts_t *self, con
mbb_printf(optr, "%s%*s%*s%s%*.2lf%s", pre, indent, (indent>0?" ":""), wkey, "trn-nerr", sep, wval, self->trn_nerr, del);
mbb_printf(optr, "%s%*s%*s%s%*.2lf%s", pre, indent, (indent>0?" ":""), wkey, "trn-ecov", sep, wval, self->trn_ecov, del);
mbb_printf(optr, "%s%*s%*s%s%*.2lf%s", pre, indent, (indent>0?" ":""), wkey, "trn-eerr", sep, wval, self->trn_eerr, del);
- mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "mb-out", sep, wval, self->mb_out, del);
- mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "trn-out", sep, wval, self->trn_out, del);
mbb_printf(optr, "%s%*s%*s%s%*u%s", pre, indent, (indent>0?" ":""), wkey, "trn-decn", sep, wval, self->trn_decn, del);
mbb_printf(optr, "%s%*s%*s%s%*.2lf%s", pre, indent, (indent>0?" ":""), wkey, "trn-decs", sep, wval, self->trn_decs, del);
mbb_printf(optr, "%s%*s%*s%s%*.2lf%s", pre, indent, (indent>0?" ":""), wkey, "covariance-magnitude-max", sep, wval, self->covariance_magnitude_max, del);
@@ -1832,6 +1845,13 @@ static int s_mbtrnpp_optstr(char **pdest, size_t olen, mbtrnpp_opts_t *self, con
mbb_printf(optr, "%s%*s%*s%s%*.2lf%s", pre, indent, (indent>0?" ":""), wkey, "reinit_zoffset_min", sep, wval, self->reinit_zoffset_min, del);
mbb_printf(optr, "%s%*s%*s%s%*.2lf%s", pre, indent, (indent>0?" ":""), wkey, "reinit_zoffset_max", sep, wval, self->reinit_zoffset_max, del);
mbb_printf(optr, "%s%*s%*s%s%*c%s", pre, indent, (indent>0?" ":""), wkey, "random_offset_enable", sep, wval, BOOL2YNC(self->random_offset_enable), del);
+ mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "mb-out", sep, wval, self->mb_out, del);
+ mbb_printf(optr, "%s%*s%*s%s%*s%s", pre, indent, (indent>0?" ":""), wkey, "trn-out", sep, wval, self->trn_out, del);
+ mbb_printf(optr, "%s%*s%*s%s%*d%s", pre, indent, (indent>0?" ":""), wkey, "mbhbn", sep, wval, self->mbhbn, del);
+ mbb_printf(optr, "%s%*s%*s%s%*.2lf%s", pre, indent, (indent>0?" ":""), wkey, "mbhbt", sep, wval, self->mbhbt, del);
+ mbb_printf(optr, "%s%*s%*s%s%*.2lf%s", pre, indent, (indent>0?" ":""), wkey, "trnhbt", sep, wval, self->trnhbt, del);
+ mbb_printf(optr, "%s%*s%*s%s%*.2lf%s", pre, indent, (indent>0?" ":""), wkey, "trnuhbt", sep, wval, self->trnuhbt, del);
+ mbb_printf(optr, "%s%*s%*s%s%*d%s", pre, indent, (indent>0?" ":""), wkey, "trnumttl", sep, wval, self->trnumttl, del);
mbb_printf(optr, "%s%*s%*s%s%*c%s", pre, indent, (indent>0?" ":""), wkey, "help", sep, wval, BOOL2YNC(self->help), del);
size_t slen = mbb_length(optr);
if(NULL == *pdest){
@@ -2381,6 +2401,11 @@ static int s_mbtrnpp_kvparse_fn(char *key, char *val, void *cfg)
retval=0;
}
}
+ else if(strcmp(key,"projection")==0 ){
+ if(sscanf(val,"%d",&opts->projection)==1){
+ retval=0;
+ }
+ }
else if(strcmp(key,"swath-width")==0 || strcmp(key,"swath")==0 ){
if(sscanf(val,"%lf",&opts->swath_width)==1){
retval=0;
@@ -2452,16 +2477,24 @@ static int s_mbtrnpp_kvparse_fn(char *key, char *val, void *cfg)
retval=0;
}
}
-#ifdef TRN_USE_PROJ
+ else if(strcmp(key,"use-proj")==0 ){
+ if( mkvc_parse_bool(val,&opts->use_proj)==0){
+ retval=0;
+ } else {
+ opts->use_proj=true;
+ retval=0;
+ }
+ }
else if(strcmp(key,"trn-crs")==0 ){
MEM_CHKFREE(opts->trn_crs);
if( (opts->trn_crs=CHK_STRDUP(val)) != NULL){
retval=0;
}
- }
+ }
else if(strcmp(key,"trn-utm")==0 ){
int utm_zone;
if(sscanf(val,"%d",&utm_zone)==1){
+ opts->trn_utm = utm_zone;
mb_path proj_string = "";
if (utm_zone > 0 && utm_zone <= 60)
sprintf(proj_string, "UTM%2.2dN", utm_zone);
@@ -2472,13 +2505,6 @@ static int s_mbtrnpp_kvparse_fn(char *key, char *val, void *cfg)
}
}
}
-#else
- else if(strcmp(key,"trn-utm")==0 ){
- if(sscanf(val,"%ld",&opts->trn_utm)==1){
- retval=0;
- }
- }
-#endif
else if(strcmp(key,"trn-map")==0 ){
MEM_CHKFREE(opts->trn_map);
if( (opts->trn_map=CHK_STRDUP(val)) != NULL){
@@ -2752,14 +2778,13 @@ static int s_mbtrnpp_configure(mbtrnpp_cfg_t *cfg, mbtrnpp_opts_t *opts)
cfg->mbtrnpp_stat_flags = opts->statflags;
// trn-en
cfg->trn_enable = opts->trn_en;
-#ifdef TRN_USE_PROJ
+ // use-proj
+ cfg->use_proj = opts->use_proj;
// trn-crs
MEM_CHKFREE(cfg->trn_crs);
cfg->trn_crs = CHK_STRDUP(opts->trn_crs);
-#else
// trn-utm
cfg->trn_utm_zone = opts->trn_utm;
-#endif
// trn-mtype
cfg->trn_mtype = opts->trn_mtype;
// trn-ftype
@@ -2937,17 +2962,14 @@ static int s_mbtrnpp_validate_config(mbtrnpp_cfg_t *cfg)
err_count++;
fprintf(stderr,"ERR - trn_cfg_file not set\n");
}
-#ifdef TRN_USE_PROJ
- if(NULL==cfg->trn_crs){
+ if(NULL==cfg->trn_crs && cfg->use_proj){
err_count++;
fprintf(stderr,"ERR - trn_crs not set\n");
}
-#else
if(cfg->trn_utm_zone<1 || cfg->trn_utm_zone>60){
err_count++;
fprintf(stderr,"ERR - invalid trn_utm_zone [%ld] valid range 1-60\n",cfg->trn_utm_zone);
}
-#endif
if(cfg->trn_mtype<1 || cfg->trn_mtype>2){
err_count++;
fprintf(stderr,"ERR - invalid trn_mtype [%d] valid range 1-2\n",cfg->trn_mtype);
@@ -3078,9 +3100,22 @@ static void s_mbtrnpp_exit(int error)
exit(error);
}
+static void s_sig_handler(int sig)
+{
+ switch (sig)
+ {
+ case SIGINT:
+ // user interrupt (CTRL-C); set flag to end processing loop(s)
+ g_interrupted = true;
+ break;
+ default:
+ break;
+ }
+}
/*--------------------------------------------------------------------*/
int main(int argc, char **argv) {
+
char usage_message[] = "mbtrnpp \n"
"\t--verbose\n"
"\t--help\n"
@@ -3097,14 +3132,12 @@ int main(int argc, char **argv) {
"\t--tide-model=file\n"
"\t--statsec=d.d\n"
"\t--statflags=\n"
- "\t--hbeat=n\n"
- "\t--mbhbn=n\n"
- "\t--mbhbt=d.d\n"
- "\t--trnhbt=n\n"
- "\t--trnuhbt=n\n"
"\t--delay=n\n"
"\t--trn-en\n"
"\t--trn-dev=s\n"
+ "\t--use-proj[=b]\n"
+ "\t--projection=projection_id\n"
+ "\t--trn-crs=s\n"
"\t--trn-utm\n"
"\t--trn-map\n"
"\t--trn-par\n"
@@ -3120,8 +3153,6 @@ int main(int argc, char **argv) {
"\t--trn-nerr\n"
"\t--trn-ecov\n"
"\t--trn-eerr\n"
- "\t--mb-out=mb1svr[:host:port]/mb1/reson\n"
- "\t--trn-out=trnsvr[:host:port]/trnusvr[:host:port]/trnumsvr[:group:port:ttl]/trnu/sout/serr/debug\n"
"\t--trn-decn\n"
"\t--trn-decs\n"
"\t--covariance-magnitude-max=covariance_magnitude_max\n"
@@ -3131,7 +3162,14 @@ int main(int argc, char **argv) {
"\t--reinit-file\n"
"\t--reinit-xyoffset=xyoffset_max\n"
"\t--reinit-zoffset=offset_z_min/offset_z_max\n"
- "\t--random-offset\n";
+ "\t--random-offset\n"
+ "\t--mb-out=mb1svr[:host:port]/mb1/reson\n"
+ "\t--trn-out=trnsvr[:host:port]/trnusvr[:host:port]/trnumsvr[:group:port:ttl]/trnu/sout/serr/debug\n"
+ "\t--hbeat=n\n"
+ "\t--mbhbn=n\n"
+ "\t--mbhbt=d.d\n"
+ "\t--trnhbt=n\n"
+ "\t--trnuhbt=n\n";
extern char WIN_DECLSPEC *optarg;
// int option_index;
int errflg = 0;
@@ -3233,7 +3271,7 @@ int main(int argc, char **argv) {
/* mb1 output write control parameters */
FILE *output_mb1_fp = NULL;
char *output_buffer = NULL;
- size_t n_output_buffer_alloc = 0;
+ int n_output_buffer_alloc = 0;
size_t mb1_size, index;
unsigned int checksum;
@@ -3279,6 +3317,8 @@ int main(int argc, char **argv) {
speedmin = 0.0;
timegap = 1000000000.0;
+ signal(SIGINT, s_sig_handler);
+
#ifdef WITH_TEST_MNEM_SUB
fprintf(stderr, "%s:%d - TODO - REMOVE MNEM-SUB TEST\n",__func__,__LINE__);
s_test_mnem();
@@ -3421,11 +3461,10 @@ int main(int argc, char **argv) {
#ifdef WITH_MBTNAV
trn_cfg = trncfg_new(NULL, -1,
-#ifdef TRN_USE_PROJ
+ mbtrn_cfg->use_proj,
+ mbtrn_cfg->projection,
mbtrn_cfg->trn_crs,
-#else
mbtrn_cfg->trn_utm_zone,
-#endif
mbtrn_cfg->trn_mtype,
mbtrn_cfg->trn_sensor_type, mbtrn_cfg->trn_ftype, mbtrn_cfg->trn_fgrade,
mbtrn_cfg->trn_freinit,mbtrn_cfg->trn_mweight,
@@ -3616,12 +3655,20 @@ int main(int argc, char **argv) {
}
}
-#ifdef TRN_USE_PROJ
- /* initialize Proj transformation between Geographic coordinates (longitude and
- latitude in WGS84) and the Coordinate Reference System (CRS) used for the
- TRN reference map */
- mb_proj_init(mbtrn_cfg->verbose, mbtrn_cfg->trn_crs, &pjptr, &error);
-#endif
+ if(mbtrn_cfg->use_proj){
+
+ // initialize Proj transformation between Geographic coordinates (longitude and
+ // latitude in WGS84) and the Coordinate Reference System (CRS) used for the
+ // TRN reference map
+ mb_proj_init(mbtrn_cfg->verbose, mbtrn_cfg->trn_crs, &pjptr, &error);
+
+ // select PROJ transform callback for TRN
+ mbtrnpp_geo_to_tm = mbtrnpp_geo_to_tm_proj;
+
+ } else {
+ // select GCTP transform callback for TRN
+ mbtrnpp_geo_to_tm = mbtrnpp_geo_to_tm_gctp;
+ }
/* initialize output */
if ( OUTPUT_FLAG_SET(OUTPUT_MBSYS_STDOUT)) {
@@ -3751,6 +3798,11 @@ int main(int argc, char **argv) {
bool nav_offset_init = false;
if (mbtrn_cfg->random_offset_enable) {
srand(time(0) / getpid());
+ // TODO: what is the intent of this loop? (klh)
+ for (int i=0; i < 100; i++) {
+ int j = rand();
+ j+=1; // silence unused variable warning
+ }
double nav_offset_mag = mbtrn_cfg->reinit_xyoffset_max * ((double)rand()) / ((double)RAND_MAX);
double nav_offset_bearing = 2.0 * M_PI * ((double)rand()) / ((double)RAND_MAX);
nav_offset_east = nav_offset_mag * sin(nav_offset_bearing);
@@ -3770,7 +3822,7 @@ int main(int argc, char **argv) {
int idataread = 0;
/* loop over all files to be read */
- while (read_data == true) {
+ while (read_data == true && !g_interrupted) {
char log_message[LOG_MSG_BUF_SZ];
memset(log_message,0,LOG_MSG_BUF_SZ);
@@ -4053,7 +4105,7 @@ int main(int argc, char **argv) {
bool done = false;
int num_kinds_read[MB_DATA_KINDS + 1] = { 0 };
int num_kinds_read_tot[MB_DATA_KINDS + 1] = { 0 };
- while (!done) {
+ while (!done && !g_interrupted) {
/* open new log file if it is time */
if (mbtrn_cfg->make_logs == true) {
@@ -4642,50 +4694,49 @@ int main(int argc, char **argv) {
// empty the ring buffer
ndata = 0;
- }
- else {
- status = mb_close(mbtrn_cfg->verbose, &imbio_ptr, &error);
+ } else {
+ status = mb_close(mbtrn_cfg->verbose, &imbio_ptr, &error);
- // empty the ring buffer
- ndata = 0;
+ // empty the ring buffer
+ ndata = 0;
- sprintf(log_message, "Multibeam File <%s> of format <%d> closed", ifile, mbtrn_cfg->format);
- mlog_tprintf(mbtrnpp_mlog_id,"i,closing file/format [%s/%d]\n", ifile, mbtrn_cfg->format);
+ sprintf(log_message, "Multibeam File <%s> of format <%d> closed", ifile, mbtrn_cfg->format);
+ mlog_tprintf(mbtrnpp_mlog_id,"i,closing file/format [%s/%d]\n", ifile, mbtrn_cfg->format);
- if (logfp != NULL) {
- mbtrnpp_postlog(mbtrn_cfg->verbose, logfp, log_message, &error);
- fflush(logfp);
- }
- fprintf(stderr, "%s\n", log_message);
-
- // force a reinit when data from the next file is opened
- if (mbtrn_cfg->reinit_file_enable && !reinit_flag) {
- fprintf(stderr, "--Reinit set due to closing input swath file\n");
- mlog_tprintf(mbtrnpp_mlog_id,"i,mbtrnpp: set reinit due to closing input swath file [%s]\n", ifile);
- MST_COUNTER_INC(app_stats->stats->events[MBTPP_EV_MB_EOF]);
- reinit_flag = true;
- }
+ if (logfp != NULL) {
+ mbtrnpp_postlog(mbtrn_cfg->verbose, logfp, log_message, &error);
+ fflush(logfp);
+ }
+ fprintf(stderr, "%s\n", log_message);
- /* give the statistics */
- /* figure out whether and what to read next */
- if (read_datalist == true) {
- if ((status = mb_datalist_read(mbtrn_cfg->verbose, datalist, ifile, dfile, &mbtrn_cfg->format, &file_weight, &error)) == MB_SUCCESS) {
- MX_DEBUG("read_datalist status[%d] - continuing\n", status);
- read_data = true;
- }
- else {
- MX_DEBUG("read_datalist status[%d] - done\n", status);
- read_data = false;
- }
- }
- else {
- MX_MMSG(MXDEBUG, "read_datalist == NO\n");
- read_data = false;
- }
- mlog_tprintf(mbtrnpp_mlog_id,"i,read_datalist[%s] read_data[%s] status[%d] ifile[%s] dfile[%s] error[%d]\n",
- (read_datalist?"Y":"N"),(read_data?"Y":"N"),status,ifile,dfile,error );
+ // force a reinit when data from the next file is opened
+ if (mbtrn_cfg->reinit_file_enable && !reinit_flag) {
+ fprintf(stderr, "--Reinit set due to closing input swath file\n");
+ mlog_tprintf(mbtrnpp_mlog_id,"i,mbtrnpp: set reinit due to closing input swath file [%s]\n", ifile);
+ MST_COUNTER_INC(app_stats->stats->events[MBTPP_EV_MB_EOF]);
+ reinit_flag = true;
+ }
- }
+ /* give the statistics */
+ /* figure out whether and what to read next */
+ if (read_datalist == true) {
+ if ((status = mb_datalist_read(mbtrn_cfg->verbose, datalist, ifile, dfile, &mbtrn_cfg->format, &file_weight, &error)) == MB_SUCCESS) {
+ MX_DEBUG("read_datalist status[%d] - continuing\n", status);
+ read_data = true;
+ }
+ else {
+ MX_DEBUG("read_datalist status[%d] - done\n", status);
+ read_data = false;
+ }
+ }
+ else {
+ MX_MMSG(MXDEBUG, "read_datalist == NO\n");
+ read_data = false;
+ }
+ mlog_tprintf(mbtrnpp_mlog_id,"i,read_datalist[%s] read_data[%s] status[%d] ifile[%s] dfile[%s] error[%d]\n",
+ (read_datalist?"Y":"N"),(read_data?"Y":"N"),status,ifile,dfile,error );
+
+ }
/* end loop over files in list */
}
@@ -4741,9 +4792,10 @@ int main(int argc, char **argv) {
fclose(output_trn_fp);
#endif
-#ifdef TRN_USE_PROJ
- mb_proj_free(mbtrn_cfg->verbose, &pjptr, &error);
-#endif
+ // release coordinate transformation resources
+ if(mbtrn_cfg->use_proj) {
+ mb_proj_free(mbtrn_cfg->verbose, &pjptr, &error);
+ }
/* deallocate arrays allocated with mb_mallocd() */
if (median_filter_soundings != NULL) {
@@ -4784,6 +4836,36 @@ int main(int argc, char **argv) {
}
/*--------------------------------------------------------------------*/
+// PROJ coordinate transform callback (uses global/static var pjptr)
+int mbtrnpp_geo_to_tm_proj(double lat_rad, double lon_rad, double *r_northing_m, double *r_easting_m)
+{
+ if( pjptr == NULL || r_northing_m == NULL || r_easting_m == NULL) {
+ fprintf(stderr, "%s: ERR invalid argument (NULL)\n", __func__);
+ return -1;
+ }
+
+ PJ_COORD cin = proj_coord(RADTODEG(lon_rad), RADTODEG(lat_rad), 0, 0);
+ PJ_COORD cout = proj_trans((PJ *)pjptr, PJ_FWD, cin);
+
+ // set output
+ *r_easting_m = cout.v[0];
+ *r_northing_m = cout.v[1];
+
+ return 0;
+}
+
+// GCTP coordinate transform callback (uses global/static var pjptr)
+int mbtrnpp_geo_to_tm_gctp(double lat_rad, double lon_rad, double *r_northing_m, double *r_easting_m)
+{
+ if(r_northing_m == NULL || r_easting_m == NULL) {
+ fprintf(stderr, "%s: ERR invalid argument (NULL)\n", __func__);
+ return -1;
+ }
+
+ int retval = wgeocon_navutils_geoToUtm(lat_rad, lon_rad, mbtrn_cfg->trn_utm_zone, r_northing_m, r_easting_m);
+ return retval;
+}
+
int mbtrnpp_openlog(int verbose, mb_path log_directory, FILE **logfp, int *error) {
/* local variables */
@@ -6180,14 +6262,10 @@ int mbtrnpp_trn_publish(trn_update_t *pstate, trn_config_t *cfg)
double navlat;
double trnlon;
double trnlat;
-#ifdef TRN_USE_PROJ
int proj_error = MB_ERROR_NO_ERROR;
- mb_proj_inverse(0, pjptr, pstate->pt_dat->y, pstate->pt_dat->x, &navlon, &navlat, &proj_error);
- mb_proj_inverse(0, pjptr, pstate->mse_dat->y, pstate->mse_dat->x, &trnlon, &trnlat, &proj_error);
-#else
- trnw_utm_to_geo(pstate->pt_dat->x, pstate->pt_dat->y, cfg->utm_zone, &navlat, &navlon);
- trnw_utm_to_geo(pstate->mse_dat->x, pstate->mse_dat->y, cfg->utm_zone, &trnlat, &trnlon);
-#endif
+
+ mb_proj_inverse(0, pjptr, pstate->pt_dat->y, pstate->pt_dat->x, &navlon, &navlat, &proj_error);
+ mb_proj_inverse(0, pjptr, pstate->mse_dat->y, pstate->mse_dat->x, &trnlon, &trnlat, &proj_error);
// NOTE: TRN convention is x:northing y:easting z:down
// Output here is in order easting northing z
@@ -6259,30 +6337,22 @@ int mbtrnpp_trn_update(wtnav_t *self, mb1_t *src, wposet_t **pt_out, wmeast_t **
if (NULL != self && NULL != src && NULL != pt_out && NULL != mt_out) {
int test = -1;
-#ifdef TRN_USE_PROJ
- if ((test = wmeast_mb1_to_meas(mt_out, src, pjptr)) == 0) {
-#else
- if ((test = wmeast_mb1_to_meas(mt_out, src, cfg->utm_zone)) == 0) {
-#endif
+ if ((test = wmeast_mb1_to_meas_cb(mt_out, src, mbtrnpp_geo_to_tm)) == 0) {
-#ifdef TRN_USE_PROJ
- if ((test = wposet_mb1_to_pose(pt_out, src, pjptr)) == 0) {
-#else
- if ((test = wposet_mb1_to_pose(pt_out, src, cfg->utm_zone)) == 0) {
-#endif
- // must do motion update first if pt time <= mt time
- wtnav_motion_update(self, *pt_out);
- wtnav_meas_update(self, *mt_out, cfg->sensor_type);
- // fprintf(stderr,"%s:%d DONE [PT, MT]\n",__FUNCTION__,__LINE__);
- // wposet_show(*pt_out,true,5);
- // wmeast_show(*mt_out,true,5);
- retval = 0;
- }
- else {
- MX_DEBUG("wposet_mb1_to_pose failed [%d]\n", test);
- mlog_tprintf(trnu_alog_id,"ERR: mb1_to_pose failed [%d]\n", test);
+ if ((test = wposet_mb1_to_pose_cb(pt_out, src, mbtrnpp_geo_to_tm)) == 0) {
+ // must do motion update first if pt time <= mt time
+ wtnav_motion_update(self, *pt_out);
+ wtnav_meas_update(self, *mt_out, cfg->sensor_type);
+ // fprintf(stderr,"%s:%d DONE [PT, MT]\n",__FUNCTION__,__LINE__);
+ // wposet_show(*pt_out,true,5);
+ // wmeast_show(*mt_out,true,5);
+ retval = 0;
+ }
+ else {
+ MX_DEBUG("wposet_mb1_to_pose failed [%d]\n", test);
+ mlog_tprintf(trnu_alog_id,"ERR: mb1_to_pose failed [%d]\n", test);
+ }
}
- }
else {
MX_DEBUG("wmeast_mb1_to_meas failed [%d]\n", test);
mlog_tprintf(trnu_alog_id,"ERR: mb1_to_meas failed [%d]\n", test);
@@ -6781,7 +6851,7 @@ int mbtrnpp_reson7kr_input_read(int verbose, void *mbio_ptr, size_t *size, char
if(!read_err){
// return bytes requested:
// smaller of bytes read and bytes remaining
- size_t bytes_rem = (size_t)(frame_buf + fb_pdrf->size - fb_pread);
+ int64_t bytes_rem = (int64_t)(frame_buf + fb_pdrf->size - fb_pread);
size_t readlen = (*size <= bytes_rem ? *size : bytes_rem);
if(readlen > 0){
memcpy(buffer, fb_pread, readlen);
@@ -7684,7 +7754,7 @@ int mbtrnpp_em710raw_input_read(int verbose, void *mbio_ptr, size_t *size,
}
if(!read_err){
- size_t bytes_rem = frame_buf + frame_len - fb_pread;
+ int64_t bytes_rem = frame_buf + frame_len - fb_pread;
size_t readlen = (*size <= bytes_rem ? *size : bytes_rem);
if(readlen > 0){
memcpy(buffer, fb_pread, readlen);
@@ -8706,7 +8776,7 @@ int mbtrnpp_em710raw_input_read_ser(int verbose, void *mbio_ptr, size_t *size,
}
if(!read_err){
- size_t bytes_rem = frame_buf + frame_len - fb_pread;
+ int64_t bytes_rem = frame_buf + frame_len - fb_pread;
size_t readlen = (*size <= bytes_rem ? *size : bytes_rem);
if(readlen > 0){
memcpy(buffer, fb_pread, readlen);