Initial commit of files

This commit is contained in:
2021-01-22 10:16:20 -05:00
parent 32d165ec8f
commit ed92211680
534 changed files with 68563 additions and 19 deletions

34
.gitignore vendored
View File

@ -1,17 +1,9 @@
# Prerequisites
*.d
# Object files # Object files
*.o *.o
*.ko *.ko
*.obj *.obj
*.elf *.elf
# Linker output
*.ilk
*.map
*.exp
# Precompiled Headers # Precompiled Headers
*.gch *.gch
*.pch *.pch
@ -25,7 +17,7 @@
# Shared objects (inc. Windows DLLs) # Shared objects (inc. Windows DLLs)
*.dll *.dll
*.so *.so
*.so.* #*.so.*
*.dylib *.dylib
# Executables # Executables
@ -39,14 +31,18 @@
# Debug files # Debug files
*.dSYM/ *.dSYM/
*.su *.su
*.idb
*.pdb
# Kernel Module Compile Results # CMake files
*.mod* build
*.cmd CMakeLists.txt.user
.tmp_versions/ CMakeCache.txt
modules.order CMakeFiles
Module.symvers CMakeScripts
Mkfile.old Ignore
dkms.conf Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps

28
CMakeLists.txt Normal file
View File

@ -0,0 +1,28 @@
cmake_minimum_required(VERSION 3.7)
project(Cnomicon)
set(CMAKE_INSTALL_PREFIX /usr/local/cnomicon)
# list of header files
set(SUB_DIRS
src daemons #tests apps utils
)
foreach(SUB_DIR ${SUB_DIRS})
add_subdirectory(${SUB_DIR})
endforeach()
# installs
file(GLOB BIN_SCRIPTS "bin-scripts/*")
file(GLOB SBIN_SCRIPTS "sbin-scripts/*")
install(FILES ${BIN_SCRIPTS}
DESTINATION bin
PERMISSIONS WORLD_EXECUTE WORLD_READ OWNER_WRITE
)
install (FILES ${SBIN_SCRIPTS}
DESTINATION sbin
PERMISSIONS WORLD_EXECUTE WORLD_READ OWNER_WRITE
)
install(DIRECTORY include/ DESTINATION include)
install(DIRECTORY lib/ DESTINATION lib)

0
ChangeLog Normal file
View File

278
Doxyfile Normal file
View File

@ -0,0 +1,278 @@
# Doxyfile 1.5.1
#---------------------------------------------------------------------------
# Project related configuration options
#---------------------------------------------------------------------------
PROJECT_NAME = "ProbeStar Telematics Software"
PROJECT_NUMBER =
OUTPUT_DIRECTORY = doc/
CREATE_SUBDIRS = YES
OUTPUT_LANGUAGE = English
USE_WINDOWS_ENCODING = NO
BRIEF_MEMBER_DESC = YES
REPEAT_BRIEF = YES
ABBREVIATE_BRIEF = "The $name class" \
"The $name widget" \
"The $name file" \
is \
provides \
specifies \
contains \
represents \
a \
an \
the
ALWAYS_DETAILED_SEC = NO
INLINE_INHERITED_MEMB = NO
FULL_PATH_NAMES = YES
STRIP_FROM_PATH = /home/nprobert/
STRIP_FROM_INC_PATH =
SHORT_NAMES = NO
JAVADOC_AUTOBRIEF = NO
MULTILINE_CPP_IS_BRIEF = NO
DETAILS_AT_TOP = NO
INHERIT_DOCS = YES
SEPARATE_MEMBER_PAGES = NO
TAB_SIZE = 8
ALIASES =
OPTIMIZE_OUTPUT_FOR_C = NO
OPTIMIZE_OUTPUT_JAVA = NO
BUILTIN_STL_SUPPORT = YES
DISTRIBUTE_GROUP_DOC = NO
SUBGROUPING = YES
#---------------------------------------------------------------------------
# Build related configuration options
#---------------------------------------------------------------------------
EXTRACT_ALL = YES
EXTRACT_PRIVATE = YES
EXTRACT_STATIC = YES
EXTRACT_LOCAL_CLASSES = YES
EXTRACT_LOCAL_METHODS = NO
HIDE_UNDOC_MEMBERS = NO
HIDE_UNDOC_CLASSES = NO
HIDE_FRIEND_COMPOUNDS = NO
HIDE_IN_BODY_DOCS = NO
INTERNAL_DOCS = NO
CASE_SENSE_NAMES = YES
HIDE_SCOPE_NAMES = NO
SHOW_INCLUDE_FILES = YES
INLINE_INFO = YES
SORT_MEMBER_DOCS = YES
SORT_BRIEF_DOCS = NO
SORT_BY_SCOPE_NAME = NO
GENERATE_TODOLIST = YES
GENERATE_TESTLIST = YES
GENERATE_BUGLIST = YES
GENERATE_DEPRECATEDLIST= YES
ENABLED_SECTIONS =
MAX_INITIALIZER_LINES = 30
SHOW_USED_FILES = YES
SHOW_DIRECTORIES = YES
FILE_VERSION_FILTER =
#---------------------------------------------------------------------------
# configuration options related to warning and progress messages
#---------------------------------------------------------------------------
QUIET = NO
WARNINGS = YES
WARN_IF_UNDOCUMENTED = YES
WARN_IF_DOC_ERROR = YES
WARN_NO_PARAMDOC = NO
WARN_FORMAT = "$file:$line: $text"
WARN_LOGFILE =
#---------------------------------------------------------------------------
# configuration options related to the input files
#---------------------------------------------------------------------------
INPUT = include \
src \
apps \
daemons
FILE_PATTERNS = *.c \
*.cc \
*.cxx \
*.cpp \
*.c++ \
*.d \
*.java \
*.ii \
*.ixx \
*.ipp \
*.i++ \
*.inl \
*.h \
*.hh \
*.hxx \
*.hpp \
*.h++ \
*.idl \
*.odl \
*.cs \
*.php \
*.php3 \
*.inc \
*.m \
*.mm \
*.dox \
*.py \
*.C \
*.CC \
*.C++ \
*.II \
*.I++ \
*.H \
*.HH \
*.H++ \
*.CS \
*.PHP \
*.PHP3 \
*.M \
*.MM \
*.PY
RECURSIVE = YES
EXCLUDE =
EXCLUDE_SYMLINKS = NO
EXCLUDE_PATTERNS =
EXAMPLE_PATH =
EXAMPLE_PATTERNS = *
EXAMPLE_RECURSIVE = NO
IMAGE_PATH =
INPUT_FILTER =
FILTER_PATTERNS =
FILTER_SOURCE_FILES = NO
#---------------------------------------------------------------------------
# configuration options related to source browsing
#---------------------------------------------------------------------------
SOURCE_BROWSER = YES
INLINE_SOURCES = NO
STRIP_CODE_COMMENTS = YES
REFERENCED_BY_RELATION = YES
REFERENCES_RELATION = YES
REFERENCES_LINK_SOURCE = YES
USE_HTAGS = NO
VERBATIM_HEADERS = YES
#---------------------------------------------------------------------------
# configuration options related to the alphabetical class index
#---------------------------------------------------------------------------
ALPHABETICAL_INDEX = YES
COLS_IN_ALPHA_INDEX = 5
IGNORE_PREFIX =
#---------------------------------------------------------------------------
# configuration options related to the HTML output
#---------------------------------------------------------------------------
GENERATE_HTML = YES
HTML_OUTPUT = html
HTML_FILE_EXTENSION = .html
HTML_HEADER =
HTML_FOOTER =
HTML_STYLESHEET =
HTML_ALIGN_MEMBERS = YES
GENERATE_HTMLHELP = NO
CHM_FILE =
HHC_LOCATION =
GENERATE_CHI = NO
BINARY_TOC = NO
TOC_EXPAND = YES
DISABLE_INDEX = NO
ENUM_VALUES_PER_LINE = 4
GENERATE_TREEVIEW = YES
TREEVIEW_WIDTH = 250
#---------------------------------------------------------------------------
# configuration options related to the LaTeX output
#---------------------------------------------------------------------------
GENERATE_LATEX = YES
LATEX_OUTPUT = latex
LATEX_CMD_NAME = latex
MAKEINDEX_CMD_NAME = makeindex
COMPACT_LATEX = NO
PAPER_TYPE = a4wide
EXTRA_PACKAGES =
LATEX_HEADER =
PDF_HYPERLINKS = NO
USE_PDFLATEX = NO
LATEX_BATCHMODE = NO
LATEX_HIDE_INDICES = NO
#---------------------------------------------------------------------------
# configuration options related to the RTF output
#---------------------------------------------------------------------------
GENERATE_RTF = YES
RTF_OUTPUT = rtf
COMPACT_RTF = NO
RTF_HYPERLINKS = YES
RTF_STYLESHEET_FILE =
RTF_EXTENSIONS_FILE =
#---------------------------------------------------------------------------
# configuration options related to the man page output
#---------------------------------------------------------------------------
GENERATE_MAN = NO
MAN_OUTPUT = man
MAN_EXTENSION = .3
MAN_LINKS = NO
#---------------------------------------------------------------------------
# configuration options related to the XML output
#---------------------------------------------------------------------------
GENERATE_XML = YES
XML_OUTPUT = xml
XML_SCHEMA =
XML_DTD =
XML_PROGRAMLISTING = YES
#---------------------------------------------------------------------------
# configuration options for the AutoGen Definitions output
#---------------------------------------------------------------------------
GENERATE_AUTOGEN_DEF = NO
#---------------------------------------------------------------------------
# configuration options related to the Perl module output
#---------------------------------------------------------------------------
GENERATE_PERLMOD = NO
PERLMOD_LATEX = NO
PERLMOD_PRETTY = YES
PERLMOD_MAKEVAR_PREFIX =
#---------------------------------------------------------------------------
# Configuration options related to the preprocessor
#---------------------------------------------------------------------------
ENABLE_PREPROCESSING = YES
MACRO_EXPANSION = NO
EXPAND_ONLY_PREDEF = NO
SEARCH_INCLUDES = YES
INCLUDE_PATH =
INCLUDE_FILE_PATTERNS =
PREDEFINED =
EXPAND_AS_DEFINED =
SKIP_FUNCTION_MACROS = YES
#---------------------------------------------------------------------------
# Configuration::additions related to external references
#---------------------------------------------------------------------------
TAGFILES =
GENERATE_TAGFILE =
ALLEXTERNALS = NO
EXTERNAL_GROUPS = YES
PERL_PATH = /usr/bin/perl
#---------------------------------------------------------------------------
# Configuration options related to the dot tool
#---------------------------------------------------------------------------
CLASS_DIAGRAMS = YES
HIDE_UNDOC_RELATIONS = YES
HAVE_DOT = YES
CLASS_GRAPH = YES
COLLABORATION_GRAPH = YES
GROUP_GRAPHS = YES
UML_LOOK = YES
TEMPLATE_RELATIONS = NO
INCLUDE_GRAPH = YES
INCLUDED_BY_GRAPH = YES
CALL_GRAPH = YES
CALLER_GRAPH = NO
GRAPHICAL_HIERARCHY = YES
DIRECTORY_GRAPH = YES
DOT_IMAGE_FORMAT = png
DOT_PATH =
DOTFILE_DIRS =
MAX_DOT_GRAPH_WIDTH = 1024
MAX_DOT_GRAPH_HEIGHT = 1024
MAX_DOT_GRAPH_DEPTH = 1000
DOT_TRANSPARENT = NO
DOT_MULTI_TARGETS = YES
GENERATE_LEGEND = YES
DOT_CLEANUP = YES
#---------------------------------------------------------------------------
# Configuration::additions related to the search engine
#---------------------------------------------------------------------------
SEARCHENGINE = YES

0
README Normal file
View File

10
apps/CMakeLists.txt Normal file
View File

@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.7)
project(Cnomicon)
# list of header files
set(SUB_DIRS
)
foreach(SUB_DIR ${SUB_DIRS})
add_subdirectory(${SUB_DIR})
endforeach()

1
apps/bin Symbolic link
View File

@ -0,0 +1 @@
../bin

1
apps/include Symbolic link
View File

@ -0,0 +1 @@
../include

1
apps/lib Symbolic link
View File

@ -0,0 +1 @@
../lib

6
bin-scripts/can-down Executable file
View File

@ -0,0 +1,6 @@
#!/bin/sh
killall candump 2> /dev/null
ifconfig can0 down 2> /dev/null
ifconfig vcan0 down 2> /dev/null

5
bin-scripts/can-dump Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
can-info
candump -cae can0

5
bin-scripts/can-log-replay Executable file
View File

@ -0,0 +1,5 @@
#/bin/sh
echo "can-logging $1 replaying to CAN any indefinitely"
canplayer -l i -I $@

26
bin-scripts/can-log-start Executable file
View File

@ -0,0 +1,26 @@
#!/bin/sh
# log file name based on time
TIMESTAMP=`date +'%Y-%m-%d_%H%M%S'`
LOGDIR=.
LOGFILE=$LOGDIR/candump-$TIMESTAMP.log
PIDDIR=.
PIDFILE=$PIDDIR/can-log.pid
IF=any
# log directory
if [ ! -d $LOGDIR ]; then
echo "Please run cnomicon-setup!"
exit 1
fi
# kill if already running (restart)
if [ -f $PIDFILE ]; then
sudo pkill -F $PIDFILE
fi
# let 'er rip
candump -L -l any > $LOGFILE &
echo $! > $PIDFILE
echo "CANdump logging started to $LOGFILE"

12
bin-scripts/can-log-stop Executable file
View File

@ -0,0 +1,12 @@
#!/bin/sh
# log file name based on time
PIDDIR=.
PIDFILE=$PIDDIR/can-log.pid
# kill if already running (restart)
if [ -f $PIDFILE ]; then
pkill -F $PIDFILE
echo "CANdump logging stopped"
rm -f $PIDFILE
fi

5
bin-scripts/can-record Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
can-info
candump -l can0

4
bin-scripts/can-replay Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
canplayer -I $1 $2 $3 $4 $5 $6 $7 $8 $9

8
bin-scripts/can-status Executable file
View File

@ -0,0 +1,8 @@
#!/bin/sh
lspcan
ls -l /dev/pcan*
cat /proc/pcan
ifconfig can0
ifconfig vcan0
can-info

13
bin-scripts/can-up Executable file
View File

@ -0,0 +1,13 @@
#!/bin/sh
# PCAN
echo "Can0"
modprobe pcan
ip link set can0 up type can bitrate 500000
ifconfig can0 up
# VCAN
echo "Vcan0"
modprobe vcan
ip link add dev vcan0 type vcan
ip link set up vcan0

9
bin-scripts/nmea2kml Executable file
View File

@ -0,0 +1,9 @@
#!/bin/sh
for i in $@
do
BAS=`basename $i .nmea`
KML=$BAS.kml
gpsbabel -t -i nmea -f $i -o kml,units=m -f $KML
done

0
bin/keepme Normal file
View File

6
cbuild.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/sh
mkdir -p build lib
cd build
cmake ..
make

6
cclean.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/sh
rm -rf `find . -name CMakeCache.txt`
rm -rf `find . -name CMakeFiles`
rm -rf `find . -name cmake_install.cmake`
rm -rf `find . -name Makefile`

4
cinstall.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
cd build
sudo make install | grep -v "Up-to-date:"

7
daemons/.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
cand/cand
gpsd/gpsd
logd/logd
rtcmd/rtcmd
seriald/seriald
stdiod/stdiod
trackd/trackd

12
daemons/CMakeLists.txt Normal file
View File

@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.7)
project(Cnomicon)
set(CMAKE_INSTALL_PREFIX ../bin)
# list of header files
set(SUB_DIRS
logd seriald stdiod cand gpsd rtcmd
)
foreach(SUB_DIR ${SUB_DIRS})
add_subdirectory(${SUB_DIR})
endforeach()

View File

@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 3.7)
set(NAME cand)
project(Cnomicon-Daemon)
set(TARGET ${NAME})
set(CMAKE_INSTALL_PREFIX ..)
# includes
include_directories(
/usr/include/libxml2
../include/libcan++ ../include/libgps++ ../include/libnet++ ../include)
link_directories(../lib)
link_libraries(can++ gps++ net++ net emb kmlbase kmldom kmlengine xml2 pthread rt)
# sources
set(SRCS
CanDaemon.cpp
CanListener.cpp
CanRxListener.cpp
CanTxGenerator.cpp
)
# executables
add_executable(${TARGET} ${TARGET}.cpp ${SRCS})
install(TARGETS ${TARGET} DESTINATION sbin)

138
daemons/cand/CanDaemon.cpp Normal file
View File

@ -0,0 +1,138 @@
//****************************************************************************
// Copyright (C) 2007
// Nissan North America
// All Rights Reserved. Proprietary and Confidential.
//============================================================================
//****************************************************************************
// includes
//***************************************************************************/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <time.h>
#include <sys/timeb.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/types.h>
#include "CanDaemon.h"
#include "netlib.h"
//****************************************************************************
// defines
//***************************************************************************/
//****************************************************************************
// macros
//***************************************************************************/
//****************************************************************************
// structs & typedefs
//***************************************************************************/
typedef struct _Can2DsrcMap {
int Signal;
double Scale;
int Offset;
} Can2DsrcMap;
//****************************************************************************
// global constants
//***************************************************************************/
//****************************************************************************
// global variables
//***************************************************************************/
//****************************************************************************
// static constants
//***************************************************************************/
//****************************************************************************
// static variables
//***************************************************************************/
//****************************************************************************
// static functions
//***************************************************************************/
//****************************************************************************
// C++ functions
//***************************************************************************/
CanDaemon::CanDaemon()
{
/* open a log file */
log_open( CAND_NAME );
SetTimeout( 1000000L );
}
CanDaemon::~CanDaemon()
{
}
/* Server *******************************************************************/
void CanDaemon::DaemonStartup(void)
{
// start threads and detach
Vehicle.Start( &Can, true ); // Receive CAN messages
Generator.Start( NULL, true ); // Send TX packets
Receiver.Caster = this;
Receiver.Start( NULL, true ); // Receive RX and TX Echo packets
}
void CanDaemon::DaemonShutdown(void)
{
Receiver.Stop();
Generator.Stop();
Vehicle.Stop();
}
int CanDaemon::ServerSocket(void)
{
int nrec=0;
return nrec;
}
int CanDaemon::ServerTimeout(void)
{
if ( NumClients() )
{
// status
// char str[128];
// int n = snprintf( str, sizeof(str), "CANd: %ld sent, %ld recv\n",
// Generator.SentCount(), Echo.RecvCount() );
// ClientCast( str, n );
}
return 0;
}
int CanDaemon::ClientIn( int sock, const char *buf, int n )
{
// commands?
return 0;
}
void CanDaemon::ClientCast( const char *buf, int n )
{
TcpServer::ClientCast( buf, n );
}
/* other stuff **************************************************************/
int CanDaemon::CanOpen( const char *uri )
{
return Can.CanOpen( uri );
}

76
daemons/cand/CanDaemon.h Normal file
View File

@ -0,0 +1,76 @@
//****************************************************************************
// Copyright (C) 2012
// Nissan North America
// All Rights Reserved. Proprietary and Confidential.
//============================================================================
/* prevent multiple inclusions */
#ifndef __CanDaemon__
#define __CanDaemon__
/* includes *****************************************************************/
#include "TcpDaemon.h"
#include "CanDatabase.h"
#include "UdpCaster.h"
#include "CanListener.h"
#include "CanTxGenerator.h"
#include "CanRxListener.h"
/* defines ******************************************************************/
/* BSMPd */
#define CAND_NAME "cand"
#define CAND_SERVICE "cand"
#define CAND_PORT "2946"
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
/* c class definitions ******************************************************/
//
// Uses the Peak Systems CAN Linux driver and Nissan CAN data
//
class CanDaemon : public TcpDaemon {
// public data
public:
CanTxGenerator Generator;
CanRxListener Receiver;
CanListener Vehicle;
CanSocket Can;
// private data
private:
// public methods
public:
// constructors
CanDaemon();
// destructor
virtual ~CanDaemon();
// virtual functions
void DaemonStartup(void);
void DaemonShutdown(void);
int ClientIn( int sock, const char *buf, int n );
void ClientCast( const char *buf, int n );
int ServerSocket( void );
int ServerTimeout( void );
// public methods
int CanOpen( const char *can );
// static methods
// private methods
private:
};
#endif

View File

@ -0,0 +1,321 @@
//
// Linux Daemon
//
//****************************************************************************
// includes
//***************************************************************************/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdarg.h>
#include <fcntl.h>
#include <string.h>
#include <ctype.h>
#include <regex.h>
#include <time.h>
#include <sys/timeb.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "libxml/parser.h"
#include "libxml/tree.h"
#include "CanSignal.h"
#include "CanListener.h"
#include "CanRxListener.h"
#include "CanTxGenerator.h"
#include "CAN_Packet.h"
//****************************************************************************
// defines
//***************************************************************************/
#define MAX_DSRC_PARSERS 32
//****************************************************************************
// macros
//***************************************************************************/
//****************************************************************************
// structs & typedefs
//***************************************************************************/
//****************************************************************************
// global constants
//***************************************************************************/
//****************************************************************************
// global variables
//***************************************************************************/
// write into the TX buffer
CAN_Packet Can = {};
//****************************************************************************
// static constants
//***************************************************************************/
//****************************************************************************
// static variables
//***************************************************************************/
static int num_parsers = 0;
//****************************************************************************
// static functions
//***************************************************************************/
//****************************************************************************
// C++ functions
//***************************************************************************/
CanListener::CanListener()
{
m_accel_from_speed = false;
m_debug = false;
m_reverse = false;
}
CanListener::~CanListener()
{
}
bool CanListener::CanParser( CanSignal *pSig, const unsigned char *data )
{
// successful and valid conversion with new data
if (!pSig->isNew)
return false;
// data has changed
// if ( m_debug )
// printf( "%s (%x) = %g (%ld)\n", pSig->Name.c_str(), pSig->Address, dValue, lValue );
// match CAN signal to CAN_Packet an copy
return true;
}
int CanListener::CanMapping( const char *file )
{
// parse XML
xmlDocPtr doc = NULL;
xmlNodePtr root = NULL;
/*parse the file and get the DOM */
if ( file )
{
if ( !(doc = xmlParseFile( file )) )
{
log_printf( "CANd: %s read error", file );
return -1;
}
}
else
{ // m/s^2
log_printf( "CANd: %s file not found", file );
return -1;
}
xmlChar *dbc = NULL;
int error = 0;
// Get the root element node
root = xmlDocGetRootElement(doc);
if ( !root )
return -1;
// <CANd> only
if ( xmlStrcmp( root->name, (const xmlChar *)"HeartBeat" ) != 0 )
return -1;
/* walk the tree */
xmlNodePtr node = root->xmlChildrenNode;
while ( node )
{
if ( xmlStrcmp( node->name, (const xmlChar *)"text" ) == 0 )
;
else if ( xmlStrcmp( node->name, (const xmlChar *)"HeartBeat" ) == 0 )
; // <!-- comment -->
else if ( xmlStrcmp( node->name, (const xmlChar *)"Description" ) == 0 )
;
else if ( xmlStrcmp( node->name, (const xmlChar *)"Database" ) == 0 )
{
// database file name
dbc = xmlNodeGetContent( node );
}
else if ( xmlStrcmp( node->name, (const xmlChar *)"CAN" ) == 0 )
{
xmlNodePtr item = node->xmlChildrenNode;
while ( item )
{
// CAN Signals
if ( xmlStrcmp( item->name, (const xmlChar *)"text" ) == 0 )
;
else if ( xmlStrcmp( item->name, (const xmlChar *)"Message" ) == 0 )
{
// get name and address
xmlNodePtr message = item->xmlChildrenNode;
xmlChar *name = NULL;
xmlChar *address = NULL;
u_long addr = 0;
while ( message )
{
if ( xmlStrcmp( message->name, (const xmlChar *)"text" ) == 0 )
;
else if ( xmlStrcmp( message->name, (const xmlChar *)"Name" ) == 0 )
name = xmlNodeGetContent( message );
else if ( xmlStrcmp( message->name, (const xmlChar *)"Address" ) == 0 )
address = xmlNodeGetContent( message );
message = message->next;
}
// add filter by name and address
if ( address )
addr = strtol( (char *)address, NULL, 10 );
if ( name )
AddMsgFilter( (char *)name, addr, addr );
}
else if ( xmlStrcmp( item->name, (const xmlChar *)"Signal" ) == 0 )
{
// get name and address
xmlNodePtr signal = item->xmlChildrenNode;
xmlChar *name = NULL;
xmlChar *address = NULL;
u_long addr = 0;
while ( signal )
{
if ( xmlStrcmp( signal->name, (const xmlChar *)"text" ) == 0 )
;
else if ( xmlStrcmp( signal->name, (const xmlChar *)"Name" ) == 0 )
name = xmlNodeGetContent( signal );
else if ( xmlStrcmp( signal->name, (const xmlChar *)"Address" ) == 0 )
address = xmlNodeGetContent( signal );
signal = signal->next;
}
// add filter by name and address
if ( address )
addr = strtol( (char *)address, NULL, 10 );
if ( name )
AddSigFilter( (char *)name, addr, addr );
}
item = item->next;
}
}
else
{
error++;
break;
}
node = node->next;
}
// Load the database after the filters are loaded and parse everything!
if ( dbc )
{
int n = LoadDatabase( (char*)dbc );
if (n < 0)
{
log_printf( "CANd: Database \"%s\" open failed!", (char*)dbc );
error = 1;
}
}
else
{
log_printf( "CANd: No database!" );
error = 1;
}
/* free the document */
xmlFreeDoc(doc);
xmlCleanupParser();
// errors parsing
if ( error )
return -1;
if ( num_parsers )
{
log_printf( "CANd: Parsers found = %d", num_parsers );
}
else
{
log_printf( "CANd: Errors found or no work to do (no CAN signals)!" );
return 0;
}
return num_parsers;
}
void *CanListener::Run(void *arg)
{
pCan = (CanSocket*)arg;
// wait till other threads have time to start
sleep(1);
// subscribed marked signals
SubscribeCan( pCan );
pCan->Blocking(0); // does this even work?
// setup for select()
fd_set rfds;
struct timeval tv;
int retval;
FD_ZERO(&rfds);
// run forever
while(1)
{
// select()
FD_SET(pCan->m_sock, &rfds);
tv.tv_sec = 0;
tv.tv_usec = 10000;
retval = select(pCan->m_sock+1, &rfds, NULL, NULL, &tv);
if (retval == -1)
perror("select()");
else if (retval)
{
CanFrame frame[20];
int n, sigs = 0;
// frame from CAN device (will block on more than 1)
if ( (n = pCan->CanRawRead( frame, sizeof(frame)/sizeof(CanFrame) )) > 0 )
{
for ( int i=0 ; i<n ; i++ )
{
// convert matching addresses (might be more than 1 signal)
for ( u_int j=0 ; j<Messages.size() ; j++ )
{
if ( Messages[j]->Read(&frame[i]) )
{
for (u_int k=0 ; k<Messages[j]->Signals.size() ; k++)
{
if ( CanParser( Messages[j]->Signals[k], frame[i].data ) )
sigs++;
}
break;
}
}
}
}
}
}
return NULL;
}

View File

@ -0,0 +1,70 @@
//
// Linux Daemon
//
/* prevent multiple inclusions */
#ifndef __CanListener__
#define __CanListener__
/* includes *****************************************************************/
#include <pthread.h>
#include <muParser.h>
#include "netlib.h"
#include "Thread.h"
#include "Mutex.h"
#include "UdpCaster.h"
#include "CanSocket.h"
#include "CanDatabase.h"
#include "CanTxGenerator.h"
/* defines ******************************************************************/
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
/* c class definitions ******************************************************/
class CanListener : public Thread, public CanDatabase {
// public data
public:
bool m_accel_from_speed;
bool m_debug;
bool m_reverse;
// protected data
protected:
CanSocket *pCan;
// private data
private:
// private methods
// public methods
public:
// constructors
CanListener();
// destructor
virtual ~CanListener();
// public methods
bool CanParser( CanSignal *pSig, const unsigned char * );
int CanMapping( const char *file );
// virtual overrides
void *Run(void*);
private:
// signal catchers (do not override)
};
#endif

View File

@ -0,0 +1,107 @@
//
// Linux Daemon
//
//****************************************************************************
// includes
//***************************************************************************/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdarg.h>
#include <fcntl.h>
#include <string.h>
#include <time.h>
#include <sys/timeb.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "ClockTimer.h"
#include "CanRxListener.h"
//****************************************************************************
// defines
//***************************************************************************/
//****************************************************************************
// macros
//***************************************************************************/
//****************************************************************************
// structs & typedefs
//***************************************************************************/
//****************************************************************************
// global constants
//***************************************************************************/
//****************************************************************************
// global variables
//***************************************************************************/
//****************************************************************************
// static constants
//***************************************************************************/
//****************************************************************************
// static variables
//***************************************************************************/
extern CAN_Packet Can;
//****************************************************************************
// static functions
//***************************************************************************/
//****************************************************************************
// C++ functions
//***************************************************************************/
CanRxListener::CanRxListener()
{
m_debug = false;
nTxEcho = nRxBsm = nRxOem = 0;
}
CanRxListener::~CanRxListener()
{
}
// listener hooks
void *CanRxListener::Run(void *arg)
{
unsigned char buf[2048];
while(1)
{
// WSU RX or TX Echo packets
int nread = Recv( buf, sizeof(buf) );
if ( nread == 0 )
continue;
char timebuf[32];
if ( Logging.IsLogging() )
{
struct timeval tv;
struct tm tm;
gettimeofday( &tv, NULL );
gmtime_r( &tv.tv_sec, &tm );
sprintf( timebuf, "%4d/%02d/%02d-%02d:%02d:%02d.%03ld",
tm.tm_year+1900, tm.tm_mon, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec,
tv.tv_usec / 1000L
);
}
// incoming
}
return NULL;
}

View File

@ -0,0 +1,67 @@
//
// Linux Daemon
//
/* prevent multiple inclusions */
#ifndef __CanRxListener__
#define __CanRxListener__
/* includes *****************************************************************/
#include <pthread.h>
#include "netlib.h"
#include "Thread.h"
#include "Mutex.h"
#include "GpsPoint.h"
#include "UdpThread.h"
#include "TcpServer.h"
#include "UdpCaster.h"
#include "LogData.h"
#include "CAN_Packet.h"
/* defines ******************************************************************/
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
/* c class definitions ******************************************************/
class CanRxListener : public UdpThread {
// public data
public:
bool m_debug;
TcpServer *Caster;
UdpCaster Forward;
LogData Logging;
// protected data
protected:
int nTxEcho;
int nRxBsm;
int nRxOem;
// private data
private:
// private methods
// public methods
public:
// constructors
CanRxListener();
// destructor
virtual ~CanRxListener();
// virtual overrides
void *Run(void*);
private:
// signal catchers (do not override)
};
#endif

View File

@ -0,0 +1,139 @@
//
// Linux Daemon
//
//****************************************************************************
// includes
//***************************************************************************/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdarg.h>
#include <fcntl.h>
#include <string.h>
#include <time.h>
#include <sys/timeb.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "ClockTimer.h"
#include "CanTxGenerator.h"
//****************************************************************************
// defines
//***************************************************************************/
#ifndef min
#define min(A,B) ((A)<(B)?(A):(B))
#endif
//****************************************************************************
// macros
//***************************************************************************/
//****************************************************************************
// structs & typedefs
//***************************************************************************/
//****************************************************************************
// global constants
//***************************************************************************/
//****************************************************************************
// global variables
//***************************************************************************/
extern CAN_Packet Can;
//****************************************************************************
// static constants
//***************************************************************************/
//****************************************************************************
// static variables
//***************************************************************************/
static CanTxGenerator *Self = NULL;
//****************************************************************************
// static functions
//***************************************************************************/
//****************************************************************************
// C++ functions
//***************************************************************************/
CanTxGenerator::CanTxGenerator()
{
Self = this;
m_period = 100;
}
CanTxGenerator::~CanTxGenerator()
{
}
// generator itself
void *CanTxGenerator::Run(void *arg)
{
ClockTimer Loop;
Loop.Start( m_period * 1000 ); // usec
while (1)
{
// send out
SendTo( &Can, sizeof(Can) );
// log this message // log this message
if ( Logging.IsLogging() )
{
struct timeval tv;
struct tm tm;
gettimeofday( &tv, NULL );
gmtime_r( &tv.tv_sec, &tm );
char buf[32];
sprintf( buf, "%4d/%2d/%2d-%2d:%2d:%2d.%03ld",
tm.tm_year+1900, tm.tm_mon, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec,
tv.tv_usec / 1000L
);
Logging.LogPrintf( "%s,%s,%f,%f,%f,%f,%u,%f,%u,%f,%f,%f,%f,%f,%u,%u,%u,%f,%u,%f",
buf,
"TX",
0.0,
0.0,
0.0,
0.0,
0,
Can.fSpeed,
Can.byTransmission,
Can.fSteering,
Can.fAccelLongitudinal,
Can.fAccelLateral,
Can.fAccelVertical,
Can.fYawRate,
Can.wBrakeSystemStatus,
Can.wEventFlags,
Can.byExteriorLights,
Can.fThrottle,
Can.byFrontWipers,
0.0
);
}
// 100 msec, leave a little time to do the work
Loop.Sync();
// msleep( m_period - 10L );
}
return NULL;
}

View File

@ -0,0 +1,60 @@
//
// Linux Daemon
//
/* prevent multiple inclusions */
#ifndef __CanTxGenerator__
#define __CanTxGenerator__
/* includes *****************************************************************/
#include <pthread.h>
#include "Thread.h"
#include "Mutex.h"
#include "UdpCaster.h"
#include "UdpThread.h"
#include "LogData.h"
#include "CAN_Packet.h"
/* defines ******************************************************************/
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
/* c class definitions ******************************************************/
class CanTxGenerator : public UdpThread {
// public data
public:
LogData Logging;
unsigned long m_period;
// protected data
protected:
UdpClient *pCan;
// private data
private:
// public methods
public:
// constructors
CanTxGenerator();
// destructor
virtual ~CanTxGenerator();
// public methods
void SetPeriod(unsigned long period) {m_period=period;};
// virtual overrides
void *Run(void*);
// private methods
private:
};
#endif

File diff suppressed because one or more lines are too long

139
daemons/cand/bsmpbeat.xml Normal file
View File

@ -0,0 +1,139 @@
<HeartBeat>
<Description>Nissan/Infiniti Gen3</Description>
<Database>Infiniti_M37_JX35_ADAS.dbc</Database>
<CAN>
<!-- CAN Database Filter, messages to read
Not needed if DBC is edited to CAN messages needed -->
<Signal>
<Name>CABRESW</Name>
<Address>0x35D</Address>
</Signal>
<Signal>
<Name>TURN_IND</Name>
<Address>0x60D</Address>
</Signal>
<Signal>
<Name>FR_WIP_REQ</Name>
<Address>0x35D</Address>
</Signal>
<Signal>
<Name>HL_HIGH_REQ</Name>
<Address>0x60D</Address>
</Signal>
<Signal>
<Name>HL_LOW_REQ</Name>
<Address>0x60D</Address>
</Signal>
<Signal>
<Name>TAIL_L_REQ</Name>
<Address>0x60D</Address>
</Signal>
<Signal>
<Name>LONG_ACC_02</Name>
<Address>0x292</Address>
</Signal>
<Signal>
<Name>TRANS_ACC_02</Name>
<Address>0x292</Address>
</Signal>
<Signal>
<Name>YAW_RATE_02</Name>
<Address>0x292</Address>
</Signal>
<Signal>
<Name>ABSACT</Name>
<Address>0x354</Address>
</Signal>
<Signal>
<Name>V_APO</Name>
<Address>0x182</Address>
</Signal>
<Signal>
<Name>VSO</Name>
<Address>0x284</Address>
</Signal>
<Signal>
<Name>STRANGLE</Name>
<Address>0x002</Address>
</Signal>
<Signal>
<Name>TCSACT</Name>
<Address>0x245</Address>
</Signal>
<Signal>
<Name>VDCACT</Name>
<Address>0x245</Address>
</Signal>
<Signal>
<Name>OFF_SW</Name>
<Address>0x245</Address>
</Signal>
<Signal>
<Name>CURGP</Name>
<Address>0x174</Address>
</Signal>
</CAN>
<DSRC>
<!-- CAN Signal (real values) to DSRC Element conversion -->
<Element>
<Name>Speed</Name>
<Expr>VSO*0.277777778</Expr>
</Element>
<Element>
<Name>TransmissionState</Name>
<Expr>CURGP</Expr>
</Element>
<Element>
<Name>LateralAcceleration</Name>
<Expr>TRANS_ACC_02*9.80665</Expr>
</Element>
<Element>
<Name>LongitudinalAcceleration</Name>
<Expr>LONG_ACC_02*9.80665</Expr>
</Element>
<Element>
<Name>YawRate</Name>
<Expr>YAW_RATE_02*0.1</Expr>
</Element>
<Element>
<Name>BrakeAppliedStatus</Name>
<Expr>CABRESW*15</Expr>
</Element>
<Element>
<Name>TractionControlStatus</Name>
<Expr>OFF_SW?0:TCSACT+1</Expr>
</Element>
<Element>
<Name>AntilockBrakeStatus</Name>
<Expr>ABSACT?ABSACT+1:0</Expr>
</Element>
<Element>
<Name>StabilityControlStatus</Name>
<Expr>OFF_SW?0:VDCACT+1</Expr>
</Element>
<Element>
<Name>VehicleWidth</Name>
<Expr>1.85</Expr>
</Element>
<Element>
<Name>VehicleLength</Name>
<Expr>4.95</Expr>
</Element>
<Element>
<Name>SteeringWheelAngle</Name>
<Expr>STRANGLE</Expr>
</Element>
<Element>
<Name>AccelPedalPosition</Name>
<Expr>V_APO*0.39216</Expr>
</Element>
<Element>
<Name>ExteriorLights</Name>
<Expr>HL_LOW_REQ*1+HL_HIGH_REQ*2+TURN_IND*4+TAIL_L_REQ*128</Expr>
</Element>
<Element>
<Name>FrontWiperStatus</Name>
<Expr>FR_WIP_REQ</Expr>
</Element>
</DSRC>
</HeartBeat>

204
daemons/cand/cand.cpp Normal file
View File

@ -0,0 +1,204 @@
//
// CAN Daemon (cand.cpp)
//
// Neal Probert
//
// IPv4 for now, since clients will be localhost anyways
// IPv6 for testing
//
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <time.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include "CanDaemon.h"
#include "netlib.h"
extern int optind, opterr, optopt;
/*
* Note that we are doing a multi-client server so that it's possible to
* have several applications listening to CAN
*/
static const char *helptext =
"cand -m map.txt [options]\n"
"\t-a Acceleration calculated from speed\n"
"\t-b uri CAN Packet broadcast\n"
"\t-c can0 CAN Interface (default)\n"
"\t-d debug (foreground with stdio)\n"
"\t-f uri forward udp port (usually to MABX2)\n"
"\t-h help\n"
"\t-l uri UDP for TX Echo Listener (WSU BSM Proxy)\n"
"\t-m file.xml CAN to DSRC mapping file\n"
"\t-t period HeartBeat period in msec (default=100)\n"
"\t-v id Set Vehicle TempID (default=random)\n"
"\t-w uri UDP for TX Generator (WSU BSM Proxy)\n"
"\t-L logfile Message log file\n"
"\t-S service TCP service (default=2949)\n";
int main(int argc, char **argv)
{
char c; /* we have character */
int n;
/* options */
int debug = 0;
/* CAN */
const char *can = NULL; // "can0"
const char *mapping = NULL;
/* HB */
const char *tx = "udp://192.168.1.2:2735"; // to WSU
const char *rx = "udp://0.0.0.0:2736"; // from WSU
const char *tcp = CAND_PORT;
unsigned long period = 100UL;
const char *fwd = NULL; // "udp://192.168.1.10:2736"; // mABx2
// if we're doing CAN, we must be doing TX as well
if ( can )
tx = "udp://192.168.1.2:2735";
else
tx = NULL; // if we want to use dummy TX for testing
/* init hardware interface and daemon */
CanDaemon Can;
// add command line args
while ( (c = getopt( argc, argv, "ac:df:hl:m:tw:L:S:" )) > 0 )
{
switch ( c )
{
case 'a':
Can.Vehicle.m_accel_from_speed = false;
break;
case 'c':
can = optarg;
break;
case 'd':
debug = 1;
Can.Receiver.m_debug = Can.Vehicle.m_debug = true;
break;
case 'f':
fwd = optarg;
break;
case 'h':
puts( helptext );
exit(0);
break;
case 'l':
rx = optarg;
break;
case 'm':
mapping = optarg;
break;
case 't':
period = strtoul( optarg, NULL, 10 );
break;
case 'w':
if (strcmp(optarg, "-") == 0)
tx = "udp://192.168.1.2:2735";
else
tx = optarg;
break;
case 'L':
// Open log file (must be to logd!)
if ( Can.Receiver.Logging.LogOpen(optarg, 0) )
{
printf( "%s: Log file opened\n", optarg );
Can.Receiver.Logging.LogPrintf( "logtime,timestamp,type,id,latitude,longitude,elevation,heading,"
"speed,trans,steering,accel_long,accel_lat,accel_vert,yaw_rate,"
"brakes,event,lights,throttle,wipers,pp_radius" );
}
else
{
fprintf(stderr, "%s: log file open failed\n", optarg );
}
break;
case 'S':
tcp = optarg;
break;
default:
fprintf( stderr, "Unknown option -%c\n", c );
exit(1);
}
}
// CAN Database and Parsing
if ( mapping )
{
// Filter to reduce database
if ( (n = Can.Vehicle.CanMapping( mapping )) <= 0 )
{
fprintf( stderr, "Unable to load CAN database and DSRC mapping!\n");
exit(1);
}
}
else if ( can )
{
fprintf( stderr, "CAN to DSRC Mapping file is required!\n" );
exit(1);
}
// CAN device, can run without CAN for testing
if ( can )
{
if ( Can.Can.CanOpen( can ) < 0 )
{
fprintf( stderr, "Unable to open CAN device: %s!\n", can );
exit(1);
}
// fprintf( stderr, "CAN Max Filter = %d\n", CAN_MAX_FILTER );
}
else
{
fprintf( stderr, "Running without CAN, setting fake values\n" );
exit(1);
}
// TX sending
if ( tx )
{
// UDP
if ( Can.Generator.ConnectUri( tx ) < 0 )
{
fprintf( stderr, "Unable to connect to WSU BSM Proxy!\n" );
exit(1);
}
Can.Generator.SetPeriod( period );
}
else
fprintf( stderr, "Running without TX, RX listener only (TX Echo, RX Msg, OEM Echo)\n" );
// UDP broadcast
if ( rx )
Can.Receiver.ListenUri( rx );
else
fprintf( stderr, "Running with RX, sending TX only\n" );
// Forwarding to MABX2
if ( fwd )
{
if ( Can.Receiver.Forward.CasterUri( fwd ) >= 0 )
fprintf( stderr, "Forwarding packets to %s\n", fwd );
else
fprintf( stderr, "Forward open failed!\n" );
}
/* TCP Server */
if ( Can.StartService( CAND_NAME, NULL, tcp, debug ) >= 0 )
return Can.RunService();
return 1;
}

3
daemons/cand/candebug.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
./cand -c can0 -d -m bsmpbeat.xml

3
daemons/cand/debug.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
./cand -d -f udp://192.168.1.10:2736 -m bsmpbeat.xml

View File

@ -0,0 +1,26 @@
cmake_minimum_required(VERSION 3.7)
set(NAME gpsd)
project(Cnomicon-Daemon)
set(TARGET ${NAME})
set(CMAKE_INSTALL_PREFIX ..)
# includes
include_directories(
/usr/include/libxml2
../include/libgps++
../include/libnet++
../include)
link_directories(../lib)
link_libraries(gps++ net++ net emb kmlbase kmldom kmlengine xml2 pthread rt)
# sources
set(SRCS
GpsDaemon.cpp
)
# executables
add_executable(${TARGET} ${TARGET}.cpp ${SRCS})
install(TARGETS ${TARGET} DESTINATION sbin)

384
daemons/gpsd/GpsDaemon.cpp Normal file
View File

@ -0,0 +1,384 @@
//
// GPS Daemon
// Neal Probert
//
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <time.h>
#include <sys/timeb.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/types.h>
#include "UriParse.h"
#include "GpsDaemon.h"
#include "NmeaParser.h"
#include "ApplanixParser.h"
#include "FastraxParser.h"
#include "GarminParser.h"
#include "SirfParser.h"
#include "UbloxParser.h"
#include "netlib.h"
//****************************************************************************
// defines
//***************************************************************************/
//****************************************************************************
// macros
//***************************************************************************/
//****************************************************************************
// structs & typedefs
//***************************************************************************/
//****************************************************************************
// global constants
//***************************************************************************/
//****************************************************************************
// global variables
//***************************************************************************/
//****************************************************************************
// static constants
//***************************************************************************/
//****************************************************************************
// static variables
//***************************************************************************/
//****************************************************************************
// static functions
//***************************************************************************/
//****************************************************************************
// C++ functions
//***************************************************************************/
GpsDaemon::GpsDaemon()
{
log_open( GPSD_NAME );
clockset = 0;
msgcount = 0;
dgps_corr = true;
SourceIn = CorrIn = -1;
strcpy( Uri, "" );
nClients = 0;
SetClientTimeout(false); // don't reset timeout on client activity
}
GpsDaemon::~GpsDaemon()
{
Gps.GpsClose();
Log.LogClose();
}
/* NMEA **********************************************************************/
void GpsDaemon::PositionListener( const GpsPoint &Pos, const ErrorInfo &Err )
{
}
void GpsDaemon::TimeListener( const struct timeval &tv )
{
// good fix and time
if ( clockset && tv.tv_sec )
{
if ( getuid() == 0 )
settimeofday( &tv, NULL );
clockset = 0;
}
}
/* TCP ***********************************************************************/
int GpsDaemon::ServerTimeout(void)
{
// timeout (a bad thing)
DgpsReconnect();
return 0;
}
int GpsDaemon::ServerSocket(void)
{
char buf[2048];
int n = 0;
if ( IsSet( CorrIn ) )
{
// corrections
if ( dgps_corr )
// from RTCM server (once a minute)
n = Dgps.DgpsRead( buf, sizeof(buf) );
else
// from NTRIP server (once a minute)
n = Ntrip.NtripRead( (unsigned char *)buf, sizeof(buf) );
// xmit
if ( n > 0 )
Gps.GpsWrite( buf, n );
else if ( n == 0 )
{
if ( dgps_corr )
log_error( "Remote RTCM server closed!" );
else
log_error( "Remote NTRIP server closed!" );
DgpsReconnect();
}
ResetServerTimeout();
}
else if ( IsSet( SourceIn ) )
{
if ( gps_source )
// packet from GPS device
n = Gps.GpsRead( buf, sizeof(buf) );
else
// remote gpsd/glty
n = Gpsd.Recv( buf, sizeof(buf) );
if ( n > 0 && Parser && Parser->GpsParse(buf, n) > 0 )
{
msgcount++;
// 'cast
ClientCast( buf, n );
}
}
return n;
}
int GpsDaemon::ClientIn( int sock, const char *buf, int n )
{
// allows for NMEA playback via netcat
if ( *buf == '$' )
{
// broadcast it
Bcast.SendTo( buf, n );
// send to clients
TcpServer::ClientCast( buf, n );
}
else
{
// parse for commands?
// just log it
log_write( buf );
}
return n;
}
int GpsDaemon::ClientUp( int sock )
{
if ( nClients++ == 0 )
;
return 1;
}
void GpsDaemon::ClientDown( int sock )
{
// disconnect source
if ( --nClients <= 0 )
nClients = 0;
}
void GpsDaemon::ClientCast( const char *buf, int n )
{
// broadcast it
Bcast.SendTo( buf, n );
// send to clients
TcpServer::ClientCast( buf, n );
// log NMEA data with time stamp
Log.LogWrite( buf, n );
}
/* GPS ***********************************************************************/
int GpsDaemon::GpsOpen( const char *device, int baud )
{
UriParse parsed;
parsed.setRate( baud );
parsed.setUri( device );
const char *proto = parsed.getProto();
SourceIn = -1;
if ( !proto )
proto = "nmea";
// connect to gpsd?
if ( strcmp( proto, "gpsd" ) == 0 )
{
// does r mode for NMEA
SourceIn = Gpsd.GpsdConnect( parsed.getHost() );
proto = "nmea";
}
else if ( strcmp( proto, "glty" ) == 0 )
{
// put in NMEA mode
SourceIn = Gpsd.GpsdConnect( parsed.getHost() );
Gpsd.Send( "$PGLTY,NMEA\n", 12 );
proto = "pvii";
}
else
{
// open device
SourceIn = Gps.GpsOpen( parsed.getPath(), parsed.getRate() );
gps_source = true;
}
// check
if ( SourceIn < 0 )
return SourceIn;
bool binary = false;
// attach parser (should probably use a table)
if ( strcasecmp( proto, "nmea") == 0 )
{
// ascii
NmeaParser *parser = new NmeaParser();
Parser = (GpsParser *)parser;
}
else if ( strcasecmp( proto, "applanix") == 0 )
{
// binary
binary = true;
ApplanixParser *parser = new ApplanixParser();
Parser = (GpsParser *)parser;
}
else if ( strcasecmp( proto, "fastrax") == 0 )
{
// ascii
FastraxParser *parser = new FastraxParser();
Parser = (GpsParser *)parser;
}
else if ( strcasecmp( proto, "garmin") == 0 )
{
// ascii/binary
GarminParser *parser = new GarminParser();
Parser = (GpsParser *)parser;
}
else if ( strcasecmp( proto, "sirf") == 0 )
{
// binary
SirfParser *parser = new SirfParser();
Parser = (GpsParser *)parser;
}
else if ( strcasecmp( proto, "ublox") == 0 )
{
// ascii/binary
UbloxParser *parser = new UbloxParser();
Parser = (GpsParser *)parser;
}
else
{
// ascii
NmeaParser *parser = new NmeaParser();
Parser = (GpsParser *)parser;
}
// set mode
if ( binary )
Gps.SetCanonical( false, 0, 0 );
// subscribe
Parser->Subscribe( (GpsListener*)this );
// add listener
AddFd( SourceIn );
return SourceIn;
}
int GpsDaemon::DgpsConnect( const char *uri )
{
if ( !uri )
return -1;
// already connected?
if ( CorrIn >= 0 )
return CorrIn;
UriParse parsed;
parsed.setService( "2101" );
parsed.setUri( uri );
const char *proto = parsed.getProto();
if ( strcmp( proto, "dgps" ) == 0 || strcmp( proto, "dgpsip" ) == 0
|| strcmp( proto, "rtcmd" ) == 0 )
{
// RTCM server (dgpsip)
CorrIn = Dgps.DgpsConnect( parsed.getHost(), parsed.getService() );
dgps_corr = true;
}
else if ( strcmp( proto, "ntrip" ) == 0 )
{
// NTRIP caster
CorrIn = Ntrip.NtripConnect( uri );
dgps_corr = false;
}
// add listener
if ( CorrIn >= 0 )
{
strcpy( Uri, uri );
AddFd( CorrIn );
}
return CorrIn;
}
void GpsDaemon::DgpsDisconnect( void )
{
if ( CorrIn >= 0 )
;
else
return;
Dgps.DgpsClose();
Ntrip.NtripClose();
DelFd( CorrIn );
CorrIn = -1;
}
void GpsDaemon::DgpsReconnect( void )
{
if ( nClients == 0 || strlen(Uri) == 0 )
return;
log_printf( "Remote RTCM/NTRIP timed out, reconnecting" );
Dgps.DgpsClose();
Ntrip.NtripClose();
DelFd( CorrIn );
CorrIn = -1;
DgpsConnect( Uri );
}
int GpsDaemon::GpsBroadcast( const char *host )
{
const char *port = GPSD_SERVICE;
int sock = Bcast.Caster( host, port );
return sock;
}

121
daemons/gpsd/GpsDaemon.h Normal file
View File

@ -0,0 +1,121 @@
//
// GPS Daemon
// Neal Probert
//
/* prevent multiple inclusions */
#ifndef __GpsDaemon__
#define __GpsDaemon__
/* includes *****************************************************************/
#include "bzlib.h"
#include "TcpDaemon.h"
#include "UdpClient.h"
#include "UdpCaster.h"
#include "GpsDevice.h"
#include "GpsdClient.h"
#include "NmeaParser.h"
#include "SirfParser.h"
#include "ApplanixParser.h"
#include "DgpsClient.h"
#include "NtripClient.h"
#include "Logging.h"
/* defines ******************************************************************/
/* software details */
#define GPSD_NAME "gpsd"
#define GPSD_VERSION "0.1"
/* default service and port */
#define GPSD_SERVICE "gpsd"
#define GPSD_PORT "2947"
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
/* c class definitions ******************************************************/
//
// Uses the Peak Systems CAN Linux driver and Nissan CAN data
//
class GpsDaemon : public TcpDaemon, public GpsListener, public Logging {
// public data
public:
GpsdClient Gpsd;
GpsDevice Gps;
GpsParser *Parser;
DgpsClient Dgps;
NtripClient Ntrip;
// TrackClient Track;
// for corrections reconnect
char Uri[1024];
int nClients;
// private data
private:
bool gps_source; // 1=gps, 0=gpsd
bool dgps_corr; // 1=dpgs, 0=ntrip
// FDs
int SourceIn; // GpsdClient or GpsDevice
int CorrIn; // DpgsIn or NtripIn
int TrackOut; //
// UDP broadcast (data)
UdpCaster Bcast;
// misc
int clockset; // set to set clock from GPS
int msgcount;
// private methods
// static data
// public methods
public:
// constructors
GpsDaemon();
// destructor
virtual ~GpsDaemon();
// virtual functions
int ServerTimeout(void);
int ServerSocket(void);
int ClientIn( int sock, const char *buf, int n );
int ClientUp( int sock );
void ClientDown( int sock );
void ClientCast( const char *buf, int n );
// parser notifications
void PositionListener( const GpsPoint &Pos, const ErrorInfo &Err );
void TimeListener( const struct timeval &Time );
// public methods
void SetClock( void ) {clockset=1;};
int GpsOpen( const char *dev, int baud=38400 );
int GpsBroadcast( const char *host = NULL );
// corrections
int DgpsConnect( const char *host );
void DgpsDisconnect( void );
void DgpsReconnect( void );
int DgpsListen( const char *host = NULL );
// static methods
// private methods
private:
};
#endif

226
daemons/gpsd/gpsd.cpp Normal file
View File

@ -0,0 +1,226 @@
//
// GPS Daemon
// Neal Probert
//
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <arpa/inet.h>
#include "GpsDaemon.h"
#include "netlib.h"
extern int optind, opterr, optopt;
//
// Written because gpsd (http://gpsd.berlios.de/) is too fat
//
//
// GPS Server (port 2947 by default)
// ----------
//
static const char *helptext =
"This is GPSd, not the open source software gpsd:\n"
"gpsd -s /dev/ttyS0:57600 [options]\n"
"\t-d debug (foreground with stdio)\n"
"\t-h help\n"
"\t-l UDP listen for RTCM corrections\n"
"\t-m network broadcast GPS data\n"
"\t-o outfile output message log\n"
"\t-r uri dgpsip://host or ntrip://user@pw:host/ rtcm:/dev/ttyS1\n"
"\t-s port nmea:/dev/ttyS0:baud or sirf:/dev/ttyS0:baud\n"
"\t-t uri OpenGTS server\n"
"\t-w WDM DSRC listen for RTCM corrections\n"
"\t-S service TCP service (default=gpsd)\n"
"\tUse OSS gpsd, gpspipe and gpsfake to create and replay NMEA log files!\n";
int main(int argc, char **argv)
{
char c; /* we have character */
GpsDaemon Gps;
/* options */
int debug = 0; // run in foreground, leaves stdio open
int dsrc_wsm = 0;
int timeout = 15;
/* dgpsip server */
char *host = NULL;
/* service/port */
char *service = (char *)"gpsd";
/* serial port */
char *primary = NULL;
char *secondary = NULL;
int baud = 4800;
/* logging */
char *outfile = NULL;
/* udp broadcast */
char *mcast = NULL;
/* udp listener */
int listen = 0;
/* data */
char szBuf[1600];
bzero( szBuf, sizeof(szBuf) );
// add command line args
while ( (c = getopt( argc, argv, "cdhi:jlm:o:r:s:t:S:T:v" )) > 0 )
{
switch ( c )
{
case 'c': // clock set
Gps.SetClock();
break;
case 'd':
debug = 1;
break;
case 'h':
puts( helptext );
return 0;
case 'l': // udp/wdm listen
listen = 1;
break;
case 'm': // udp broadcast
mcast = optarg;
break;
case 'o':
outfile = optarg;
break;
case 'r': // rtcm-sc104 host
host = optarg;
break;
case 's': // serial device
if ( !primary )
primary = optarg;
else
secondary = optarg;
break;
case 'S':
service = optarg;
break;
case 'T':
timeout = atoi(optarg);
if ( timeout == 0 )
timeout = 30;
break;
case 'w': // DSRC WSM
fprintf( stderr, "DSRC WSM support not available!\n" );
listen = 1;
dsrc_wsm = 1;
break;
default:
fprintf( stderr, "Unknown option -%c\n", c );
exit(1);
}
}
// check options
if ( !primary )
{
fprintf( stderr, "Must have a GPS device to communicate with!\n" );
exit(1);
}
if ( mcast && listen )
{
fprintf( stderr, "Cannot do both UDP broadcast/multicast and listening!\n" );
exit(1);
}
// input
if ( primary )
{
// open GPS device on serial port
int serial = Gps.GpsOpen( primary, baud );
if ( serial < 0 )
{
fprintf( stderr, "Unable to open primary serial device: %s @ %d !\n", primary, baud );
if ( secondary )
{
serial = Gps.GpsOpen( secondary, baud ); // won't open till primary dies
if ( serial < 0 )
{
fprintf( stderr, "Unable to open secondary serial device: %s @ %d !\n", secondary, baud );
exit(1);
}
}
}
}
else
{
fprintf( stderr, "No task specified: use -l, -i <logfile> or -s <dev>!\n" );
exit(1);
}
// corrections
if ( host )
{
// RTCM server
int remote = Gps.DgpsConnect( host );
if ( remote < 0 )
{
fprintf( stderr, "Unable to connect to rtcm-sc104 source host: %s\n", host );
// exit(1);
}
Gps.SetTimeout( timeout * 1000000L );
}
else if ( listen )
{
if ( dsrc_wsm )
{
// listen on WSM control channel for DSRC MSG_RTCM_Corrections
}
else
{
}
}
// output
if ( mcast )
{
int bcast = Gps.GpsBroadcast( mcast );
if ( bcast < 0 )
{
fprintf( stderr, "Unable to create UDP broadcast!\n" );
exit(1);
}
}
// logging
if ( outfile )
Gps.LogOpen( outfile );
// TCP listener
if ( Gps.StartService( GPSD_NAME, NULL, service, debug ) >= 0 )
{
return Gps.RunService();
}
return 1;
}

1
daemons/include Symbolic link
View File

@ -0,0 +1 @@
../include

1
daemons/lib Symbolic link
View File

@ -0,0 +1 @@
../lib

View File

@ -0,0 +1,22 @@
cmake_minimum_required(VERSION 3.7)
set(NAME logd)
project(Cnomicon-Daemon)
set(TARGET ${NAME})
set(CMAKE_INSTALL_PREFIX ..)
# includes
include_directories(
/usr/include/libxml2
../include/libnet++ ../include)
link_directories(../lib)
link_libraries(net++ net pthread rt)
# sources
set(SRCS
LogDaemon.cpp
)
# executables
add_executable(${TARGET} ${TARGET}.cpp ${SRCS})
install(TARGETS ${TARGET} DESTINATION sbin)

139
daemons/logd/LogDaemon.cpp Normal file
View File

@ -0,0 +1,139 @@
//
// Log Daemon
// Neal Probert
//
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <time.h>
#include <sys/timeb.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/types.h>
#include "UriParse.h"
#include "LogDaemon.h"
#include "netlib.h"
//****************************************************************************
// defines
//***************************************************************************/
//****************************************************************************
// macros
//***************************************************************************/
//****************************************************************************
// structs & typedefs
//***************************************************************************/
//****************************************************************************
// global constants
//***************************************************************************/
//****************************************************************************
// global variables
//***************************************************************************/
//****************************************************************************
// static constants
//***************************************************************************/
//****************************************************************************
// static variables
//***************************************************************************/
//****************************************************************************
// static functions
//***************************************************************************/
//****************************************************************************
// C++ functions
//***************************************************************************/
LogDaemon::LogDaemon()
{
// logging
log_open( LOGD_NAME );
}
LogDaemon::~LogDaemon()
{
}
/* UDP ***********************************************************************/
int LogDaemon::ClientInOut( char *buf, int n, int max )
{
if ( n > 0 )
{
Dprintf( "%s\n", buf );
Log.LogWrite( buf, n );
}
// no response
return 0;
}
/* log ***********************************************************************/
int LogDaemon::LogOpen( const char *uri )
{
if ( Log.LogOpen( uri ) )
{
return 1;
}
return -1;
}
int LogDaemon::LogPlayback( void )
{
timeval tv;
tv.tv_sec = 0L;
tv.tv_usec = 0L;
// read log input
// send message
// if ( strlen( logbuf ) )
// ClientCast( logbuf, strlen(logbuf) );
// read next message
if ( Log.LogRead( &tv, logbuf, sizeof(logbuf) ) > 0 )
{
// is this first one?
if ( logcount == 0 )
{
// fudge it so it kicks off 10 seconds later
loglast.tv_sec = tv.tv_sec - 10;
loglast.tv_usec = tv.tv_usec;
}
logcount++;
// diff between this one and last
if ( loglast.tv_usec > tv.tv_usec )
{
// carry
tv.tv_sec--;
tv.tv_usec += 1000000L;
}
timeval sv = tv;
// diff is timeout period
tv.tv_sec = tv.tv_sec - loglast.tv_sec;
tv.tv_usec = tv.tv_usec - loglast.tv_usec;
// mark last log record
loglast = sv;
}
else
return 1;
// set next timeout
SetTimeout( tv );
return 1;
}

74
daemons/logd/LogDaemon.h Normal file
View File

@ -0,0 +1,74 @@
//
// Log Daemon
// Neal Probert
//
/* prevent multiple inclusions */
#ifndef __LogDaemon__
#define __LogDaemon__
/* includes *****************************************************************/
#include "UdpDaemon.h"
#include "LogData.h"
/* defines ******************************************************************/
#define LOGD_NAME "logd"
#define LOGD_SERVICE "logd"
#ifndef LOGD_PORT
#define LOGD_PORT "2940"
#endif
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
/* c class definitions ******************************************************/
//
// Listens to OBE HeartBeat messages
//
class LogDaemon : public UdpDaemon {
// public data
public:
// private data
private:
// Logging output
LogData Log;
// log playback
char logbuf[512];
timeval loglast;
unsigned int logcount;
// private methods
// static data
// public methods
public:
// constructors
LogDaemon();
// destructor
virtual ~LogDaemon();
// virtual functions
int ClientInOut( char *buf, int n, int max );
// public methods
int LogOpen( const char *uri );
int LogWrite( const char *log ) { return Log.LogWrite(log,strlen(log)); };
void SetBinary(void) { Log.SetBinary(); };
int LogPlayback( void );
// static methods
// private methods
private:
};
#endif

145
daemons/logd/logd.cpp Normal file
View File

@ -0,0 +1,145 @@
//
// Serial Daemon (similar to ser2net)
// Neal Probert
//
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <arpa/inet.h>
#include "LogDaemon.h"
#include "netlib.h"
extern int optind, opterr, optopt;
//
// any port
//
static const char *helptext =
"logd [options]\n"
"\t-d debug (foreground with stdio)\n"
"\t-h help\n"
"\t-i infile input log format:/path/to/file.log\n"
"\t-o logfile output log format:/path/to/file.log\n"
"\t-S service UDP service\n";
int main(int argc, char **argv)
{
char c; /* we have character */
LogDaemon Log;
/* options */
int debug = 0; // run in foreground, leaves stdio open
/* connections */
const char *file = NULL;
const char *log = NULL;
const char *service = LOGD_PORT;
// add command line args
while ( (c = getopt( argc, argv, "bdhi:o:S:" )) > 0 )
{
switch ( c )
{
case 'b':
Log.SetBinary();
break;
case 'd':
debug = 1;
break;
case 'h':
puts( helptext );
return 0;
case 'i':
file = optarg;
break;
case 'o':
log = optarg;
break;
case 'S':
service = optarg;
break;
default:
fprintf( stderr, "Unknown option -%c\n", c );
exit(1);
}
}
if ( log )
{
if ( Log.LogOpen( log ) < 0 )
{
fprintf( stderr, "Unable to open log file: %s!\n", log );
exit(1);
}
}
else
{
fprintf( stderr, "Must specify a MySQL connection: mysql://user:pass@host/database/table\n" );
exit(1);
}
if ( file )
{
char buf[4096];
int n = 0;
if ( strcmp( file, "-") == 0 )
{
while ( fgets(buf, sizeof(buf), stdin) )
{
Log.LogWrite( buf );
n++;
}
}
else
{
// import
FILE *import = fopen( file, "r" );
if ( import )
{
// read into database
while ( fgets( buf, sizeof(buf), import ) )
{
// check for header?
Log.LogWrite( buf );
n++;
}
printf( "Imported %d lines into log\n", n );
log_printf( "Imported %d lines into log\n", n );
}
else
{
fprintf( stderr, "Unable to import log data: %s\n", file );
return 1;
}
}
return 0;
}
else
{
// UDP listener
if ( Log.StartService( LOGD_NAME, "0.0.0.0", service, debug ) >= 0 )
return Log.RunService();
return 1;
}
return 0;
}

View File

@ -0,0 +1,22 @@
cmake_minimum_required(VERSION 3.7)
set(NAME rtcmd)
project(Cnomicon-Daemon)
set(TARGET ${NAME})
set(CMAKE_INSTALL_PREFIX ..)
# includes
include_directories(
/usr/include/libxml2
../include/libgps++ ../include/libnet++ ../include)
link_directories(../lib)
link_libraries(gps++ net++ net emb pthread rt)
# sources
set(SRCS
RtcmDaemon.cpp
)
# executables
add_executable(${TARGET} ${TARGET}.cpp ${SRCS})
install(TARGETS ${TARGET} DESTINATION sbin)

View File

@ -0,0 +1,307 @@
//
// RTCM Daemon
// Neal Probert
//
//****************************************************************************
// includes
//***************************************************************************/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <time.h>
#include <sys/timeb.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/types.h>
#include "UriParse.h"
#include "RtcmDaemon.h"
#include "netlib.h"
//****************************************************************************
// defines
//***************************************************************************/
//****************************************************************************
// macros
//***************************************************************************/
//****************************************************************************
// structs & typedefs
//***************************************************************************/
//****************************************************************************
// global constants
//***************************************************************************/
//****************************************************************************
// global variables
//***************************************************************************/
//****************************************************************************
// static constants
//***************************************************************************/
//****************************************************************************
// static variables
//***************************************************************************/
//****************************************************************************
// static functions
//***************************************************************************/
//****************************************************************************
// C++ functions
//***************************************************************************/
RtcmDaemon::RtcmDaemon()
{
log_open( RTCMD_NAME );
strcpy( Uri, "" );
SerialIn = DgpsIn = NtripIn = DgramIn = -1;
nClients = 0;
SetClientTimeout(false); // don't reset timeout on client activity
}
RtcmDaemon::~RtcmDaemon()
{
}
int RtcmDaemon::ServerTimeout(void)
{
// should not timeout, try reconnecting
if ( nClients > 0 )
RtcmReconnect();
else
RtcmDisconnect();
return 0;
}
int RtcmDaemon::ServerSocket(void)
{
char buf[2048];
int n = 0, xmit = 0;
if ( IsSet( DgpsIn ) )
{
// from RTCM server
n = Dgps.DgpsRead( buf, sizeof(buf) );
// xmit
if ( n > 0 )
xmit = n;
else if ( n == 0 )
{
log_error( "Remote RTCM server closed!" );
RtcmDisconnect();
}
else
{
log_error( "Remote RTCM server read error!" );
n = 0;
}
ResetServerTimeout();
}
else if ( IsSet( NtripIn ) )
{
// from NTRIP server
n = Ntrip.NtripRead( (unsigned char *)buf, sizeof(buf) );
// xmit
if ( n > 0 )
xmit = n;
else if ( n == 0 )
{
log_error( "Remote NTRIP server closed us!" );
RtcmDisconnect();
}
else
{
log_error( "Remote NTRIP server read error!" );
n = 0;
}
ResetServerTimeout();
}
else if ( IsSet( SerialIn ) )
{
// from base station
n = Rtcm.RtcmRead( buf, sizeof(buf) );
// xmit
if ( n > 0 )
xmit = n;
}
// pass on RTCM data
if ( xmit > 0 )
{
ClientCast( buf, xmit );
}
return n;
}
void RtcmDaemon::ClientCast( const char *buf, int n )
{
// broadcast it
Bcast.SendTo( buf, n );
// send to clients
TcpServer::ClientCast( buf, n );
}
int RtcmDaemon::ClientIn( int sock, const char *buf, int n )
{
if ( n <= 0 )
return 0;
// log messages from client, no responses
if ( *buf == '$' )
{
// update to OpenGTS
// logging
char name[128];
char out[1024];
// need to add ip address
SockName( sock, name, sizeof(name) );
n = snprintf( out, sizeof(out), "[%s] %s", name, buf );
Log.LogWrite( out, n );
}
else if ( n > 0 )
log_write( buf );
return 0;
}
int RtcmDaemon::ClientUp( int sock )
{
// connect source on demand
if ( nClients++ == 0 )
{
// re-connect
RtcmConnect( (const char *)Uri );
}
return 1;
}
void RtcmDaemon::ClientDown( int sock )
{
// disconnect source
if ( --nClients <= 0 )
{
RtcmDisconnect();
nClients = 0;
}
}
int RtcmDaemon::RtcmOpen( const char *uri )
{
// already connected?
if ( SerialIn >= 0 )
Rtcm.RtcmClose();
UriParse parsed;
parsed.setRate( 38400 );
parsed.setUri( uri );
// serial device
SerialIn = Rtcm.RtcmOpen( parsed.getPath(), parsed.getRate() );
// add listener
if ( SerialIn >= 0 )
{
strcpy( Uri, uri );
AddFd( SerialIn );
}
return SerialIn;
}
int RtcmDaemon::RtcmConnect( const char *uri )
{
// already connected?
if ( DgpsIn >= 0 )
return DgpsIn;
else if ( NtripIn >= 0 )
return NtripIn;
UriParse parsed;
parsed.setService( RTCMD_PORT );
parsed.setRate( 57600 );
parsed.setUri( uri );
const char *proto = parsed.getProto();
if ( strcmp( proto, "dgps" ) == 0 || strcmp( proto, "dgpsip" ) == 0 )
{
// RTCM server (dgpsip)
DgpsIn = Dgps.DgpsConnect( parsed.getHost(), parsed.getService() );
// add listener
if ( DgpsIn >= 0 )
{
strcpy( Uri, uri );
AddFd( DgpsIn );
}
return DgpsIn;
}
else if ( strcmp( proto, "ntrip" ) == 0 )
{
// NTRIP caster
NtripIn = Ntrip.NtripConnect( uri );
// add listener
if ( NtripIn >= 0 )
{
strcpy( Uri, uri );
AddFd( NtripIn );
}
return NtripIn;
}
return -1;
}
void RtcmDaemon::RtcmDisconnect( void )
{
if ( DgpsIn >= 0 || NtripIn >= 0 )
log_printf( "Remote RTCM/NTRIP dis-connected, no clients listening" );
else
return;
Dgps.DgpsClose();
DelFd( DgpsIn );
Ntrip.NtripClose();
DelFd( NtripIn );
DgpsIn = NtripIn = -1;
}
void RtcmDaemon::RtcmReconnect( void )
{
if ( nClients == 0 )
return;
log_printf( "Remote RTCM/NTRIP timed out, reconnecting" );
Dgps.DgpsClose();
DelFd( DgpsIn );
Ntrip.NtripClose();
DelFd( NtripIn );
DgpsIn = NtripIn = -1;
RtcmConnect( Uri );
}
int RtcmDaemon::RtcmBroadcast( const char *host, const char *port )
{
return Bcast.Caster( host, port );
}

View File

@ -0,0 +1,94 @@
//
// RTCM Daemon
// Neal Probert
//
/* prevent multiple inclusions */
#ifndef __RtcmDaemon__
#define __RtcmDaemon__
/* includes *****************************************************************/
#include "TcpDaemon.h"
#include "UdpClient.h"
#include "UdpCaster.h"
#include "GpsDevice.h"
#include "RtcmDevice.h"
#include "DgpsClient.h"
#include "NtripClient.h"
#include "Logging.h"
/* defines ******************************************************************/
/* software details */
#define RTCMD_NAME "rtcmd"
#define RTCMD_VERSION "0.1"
/* default service and port */
#define RTCMD_SERVICE "rtcm-sc104"
#define RTCMD_PORT "2101"
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
/* c class definitions ******************************************************/
//
// Uses the Peak Systems CAN Linux driver and Nissan CAN data
//
class RtcmDaemon : public TcpDaemon, public Logging {
// public data
public:
DgpsClient Dgps;
NtripClient Ntrip;
RtcmDevice Rtcm;
// private data
private:
char Uri[1024];
// FDs
int DgpsIn;
int SerialIn;
int DgramIn;
int NtripIn;
// UDP broadcast
UdpCaster Bcast;
int nClients;
// static data
// public methods
public:
// constructors
RtcmDaemon();
// destructor
virtual ~RtcmDaemon();
// virtual functions
int ServerTimeout(void);
int ServerSocket(void);
int ClientIn( int sock, const char *buf, int n );
void ClientCast( const char *buf, int n );
int ClientUp( int sock );
void ClientDown( int sock );
// public methods
int RtcmOpen( const char *uri ); // serial device
int RtcmConnect( const char *uri );
void RtcmDisconnect( void );
void RtcmReconnect( void );
int RtcmBroadcast( const char *host = NULL, const char *port = RTCMD_SERVICE );
// static methods
// private methods
private:
};
#endif

145
daemons/rtcmd/rtcmd.cpp Normal file
View File

@ -0,0 +1,145 @@
//
// RTCM Daemon (rtcmd.cpp)
// Neal Probert
//
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <arpa/inet.h>
#include "RtcmDaemon.h"
#include "netlib.h"
extern int optind, opterr, optopt;
//
// This was written because gpsd didn't have working RTCM104_SERVICE
// or the ability to do UDP broadcasts.
//
static const char *helptext =
"rtcm -r dgpsip://host [options]\n"
"\t-d debug (foreground with stdio)\n"
"\t-h help\n"
"\t-m network UDP broadcast RTCM data\n"
"\t-r uri dgpsip://host or ntrip://user@pass:host:port/mount\n"
"\t-t uri OpenGTS server\n"
"\t-w WDM DSRC broadcast RTCM corrections\n"
"\t-S service TCP service (default=2101)\n"
"\t-T timeout reconnect timeout in seconds (default=15)\n";
static RtcmDaemon Rtcm;
int main(int argc, char **argv)
{
char c; /* we have character */
/* options */
int debug = 0; // run in foreground, leaves stdio open
int dsrc_wsm = 0;
int timeout = 15;
/* dgpsip server */
char *host = NULL;
/* service/port */
char *service = (char *)"2101"; // "rtcm-sc104"
/* udp broadcast */
char *mcast = NULL;
/* log */
char *outfile = NULL;
// add command line args
while ( (c = getopt( argc, argv, "dhm:o:r:s:t:S:T:" )) > 0 )
{
switch ( c )
{
case 'd':
debug = 1;
break;
case 'h':
puts( helptext );
return 0;
case 'm': // udp broadcast
mcast = optarg;
break;
case 'o':
break;
case 'r': // rtcm-sc104 host
host = optarg;
break;
case 't':
break;
case 'S':
service = optarg;
break;
case 'T':
timeout = atoi(optarg);
if ( timeout == 0 )
timeout = 30;
break;
case 'w': // DSRC WSM broadcast or listen
fprintf( stderr, "DSRC WSM support not yet available!\n" );
// dsrc_wsm = 1;
break;
default:
fprintf( stderr, "Unknown option -%c\n", c );
exit(1);
}
}
// input
if ( host )
{
Rtcm.SetTimeout( timeout * 1000000L );
// RTCM server
int remote = Rtcm.RtcmConnect( host );
if ( remote < 0 )
{
fprintf( stderr, "Unable to connect to rtcm-sc104 source host: %s\n", host );
if ( debug )
exit(1);
}
}
// output
if ( mcast )
{
int bcast = Rtcm.RtcmBroadcast( mcast );
if ( bcast < 0 )
{
fprintf( stderr, "Unable to create UDP broadcast!\n" );
exit(1);
}
}
else if ( dsrc_wsm )
{
}
if ( outfile )
Rtcm.LogOpen( outfile, 0 );
// TCP listener
if ( Rtcm.StartService( RTCMD_NAME, NULL, service, debug ) >= 0 )
return Rtcm.RunService();
return 1;
}

7
daemons/rtcmd/test-mili.sh Executable file
View File

@ -0,0 +1,7 @@
!/bin/sh
rm /var/log/cnomicon/rtcmd.log
../../build/daemons/rtcmd/rtcmd -d -r ntrip://nprobert:p3x-mdotcors@148.149.0.87:10002/LIVONIA_RTCM2.3GPS
more /var/log/cnomicon/rtcmd.log

1
daemons/sbin Symbolic link
View File

@ -0,0 +1 @@
../sbin

View File

@ -0,0 +1,22 @@
cmake_minimum_required(VERSION 3.7)
set(NAME seriald)
project(Cnomicon-Daemon)
set(TARGET ${NAME})
set(CMAKE_INSTALL_PREFIX ..)
# includes
include_directories(
/usr/include/libxml2
../include/libnet++ ../include)
link_directories(../lib)
link_libraries(net++ net pthread rt)
# sources
set(SRCS
SerialDaemon.cpp
)
# executables
add_executable(${TARGET} ${TARGET}.cpp ${SRCS})
install(TARGETS ${TARGET} DESTINATION sbin)

View File

@ -0,0 +1,235 @@
//
// Serial Daemon
// Neal Probert
//
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <time.h>
#include <sys/timeb.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/types.h>
#include "UriParse.h"
#include "SerialDaemon.h"
#include "netlib.h"
//****************************************************************************
// defines
//***************************************************************************/
//****************************************************************************
// macros
//***************************************************************************/
//****************************************************************************
// structs & typedefs
//***************************************************************************/
//****************************************************************************
// global constants
//***************************************************************************/
//****************************************************************************
// global variables
//***************************************************************************/
//****************************************************************************
// static constants
//***************************************************************************/
//****************************************************************************
// static variables
//***************************************************************************/
//****************************************************************************
// static functions
//***************************************************************************/
//****************************************************************************
// C++ functions
//***************************************************************************/
SerialDaemon::SerialDaemon()
{
// logging
log_open( SERIALD_NAME );
m_SerialIn = m_RemoteIn = m_DgramIn = -1;
m_framed = 0;
bzero(m_Framing,sizeof(m_Framing));
}
SerialDaemon::~SerialDaemon()
{
if ( m_SerialIn >= 0 )
close( m_SerialIn );
}
/* TCP ***********************************************************************/
int SerialDaemon::ServerSocket(void)
{
char buf[2048];
int n = 0;
if ( IsSet( m_RemoteIn ) )
{
// from server
n = Client.Recv( buf, sizeof(buf) );
if ( n > 0 )
{
// send frame
if ( m_framed )
{
m_Framing[m_framed-2] = n >> 8;
m_Framing[m_framed-1] = n;
write( m_SerialIn, m_Framing, m_framed );
}
// send data
write( m_SerialIn, buf, n );
}
}
else if ( IsSet( m_SerialIn ) )
{
// data from device
n = read( m_SerialIn, buf, sizeof(buf) );
// parse data
if ( n>0 )
ClientCast( buf, n );
}
else if ( IsSet( m_DgramIn ) )
{
// packet from UDP broadcast
n = Dgram.RecvFrom( buf, sizeof(buf) );
// send to device
if ( n > 0 )
{
// send frame
if ( m_framed )
{
m_Framing[m_framed-2] = n >> 8;
m_Framing[m_framed-1] = n;
write( m_SerialIn, m_Framing, m_framed );
}
// send data
write( m_SerialIn, buf, n );
}
}
return n;
}
int SerialDaemon::ClientIn( int sock, const char *buf, int n )
{
return write( m_SerialIn, buf, n );
}
void SerialDaemon::ClientCast( const char *buf, int n )
{
// broadcast it
Bcast.SendTo( buf, n );
// send to clients
TcpServer::ClientCast( buf, n );
}
/* GPS ***********************************************************************/
int SerialDaemon::SerialOpen( const char *device, int baud )
{
UriParse parsed;
parsed.setRate( baud );
parsed.setUri( device );
int binary = 0;
// parse type
if ( strlen( parsed.getProto() ) )
{
if ( strcasecmp( parsed.getProto(), "binary" ) == 0 )
binary = 1;
}
// open device
m_SerialIn = serial_open( (char*)parsed.getPath(), parsed.getRate(), binary, binary?1:0 );
// check
if ( m_SerialIn < 0 )
return m_SerialIn;
// add listener
AddFd( m_SerialIn );
return m_SerialIn;
}
int SerialDaemon::TcpConnect( const char *uri )
{
UriParse parsed;
parsed.setUri( uri );
const char *proto = parsed.getProto();
if ( strcasecmp( proto, "http" ) == 0 ||
strcasecmp( proto, "https" ) == 0 )
{
// web site
}
else if ( strcasecmp( proto, "telnet" ) == 0 ||
strlen( proto ) == 0 )
{
// straight TCP client
m_RemoteIn = Client.Connect( parsed.getHost(), parsed.getService() );
}
return m_RemoteIn;
}
int SerialDaemon::UdpListen( const char *uri )
{
m_DgramIn = Dgram.ListenUri( uri );
if ( m_DgramIn > 0 )
AddFd( m_DgramIn );
return m_DgramIn;
}
int SerialDaemon::UdpBroadcast( const char *uri )
{
return Bcast.CasterUri( uri );
}
void SerialDaemon::SetFrame( const char *frame, int n )
{
if ( n )
{
// string
strncpy( m_Framing, frame, sizeof(m_Framing)-2 );
m_framed = strlen(m_Framing)+2;
}
else
{
// hex
unsigned long value = atol( frame );
m_framed = 6;
m_Framing[0] = value >> 24;
m_Framing[1] = value >> 16;
m_Framing[2] = value >> 8;
m_Framing[3] = value;
}
}

View File

@ -0,0 +1,92 @@
//
// Serial Daemon
// Neal Probert
//
/* prevent multiple inclusions */
#ifndef __SerialDaemon__
#define __SerialDaemon__
/* includes *****************************************************************/
#include "bzlib.h"
#include "TcpDaemon.h"
#include "TcpClient.h"
#include "UdpClient.h"
#include "UdpCaster.h"
#include "LogData.h"
/* defines ******************************************************************/
#define SERIALD_NAME "seriald"
#define SERIALD_SERVICE "seriald"
#define SERIALD_PORT "2942"
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
/* c class definitions ******************************************************/
//
// Uses the Peak Systems CAN Linux driver and Nissan CAN data
//
class SerialDaemon : public TcpDaemon {
// public data
public:
// private data
private:
// FDs
int m_SerialIn;
int m_RemoteIn;
int m_DgramIn;
// TCP client
TcpClient Client;
// UDP listen
UdpClient Dgram;
// UDP broadcast
UdpCaster Bcast;
// misc
int m_framed;
char m_Framing[8];
// private methods
// static data
// public methods
public:
// constructors
SerialDaemon();
// destructor
virtual ~SerialDaemon();
// virtual functions
int ServerSocket(void);
int ClientIn( int sock, const char *buf, int n );
void ClientCast( const char *buf, int n );
// public methods
int SerialOpen( const char *dev, int baud );
int TcpConnect( const char *uri );
int UdpBroadcast( const char *uri );
int UdpListen( const char *uri );
void SetFrame( const char *frame, int n=0 );
// static methods
// private methods
private:
};
#endif

175
daemons/seriald/seriald.cpp Normal file
View File

@ -0,0 +1,175 @@
//
// Serial Daemon (similar to ser2net)
// Neal Probert
//
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <arpa/inet.h>
#include "SerialDaemon.h"
#include "netlib.h"
extern int optind, opterr, optopt;
//
// port 2748
//
static const char *helptext =
"seriald -s /dev/ttyS0:57600 [options]\n"
"\t-d debug (foreground with stdio)\n"
"\t-h help\n"
"\t-l UDP listen for data\n"
"\t-m network broadcast data\n"
"\t-o outfile output message log\n"
"\t-r uri http://host.domain.com/\n"
"\t-s port /dev/ttyS0:baud\n"
"\t-S service TCP service\n";
int main(int argc, char **argv)
{
char c; /* we have character */
SerialDaemon Ser;
/* options */
int debug = 0; // run in foreground, leaves stdio open
/* dgpsip server */
char *host = NULL;
/* service/port */
char *service = (char *)SERIALD_PORT;
/* serial port */
char *primary = NULL;
int baud = 57600;
/* udp broadcast */
char *mcast = NULL;
/* udp listener */
int listen = 0;
// add command line args
while ( (c = getopt( argc, argv, "df:hm:lr:s:S:" )) > 0 )
{
switch ( c )
{
case 'd':
debug = 1;
break;
case 'f':
Ser.SetFrame( optarg );
break;
case 'h':
puts( helptext );
return 0;
case 'l': // udp/wdm listen
listen = 1;
break;
case 'm': // udp broadcast
mcast = optarg;
break;
case 'r': // remote host
host = optarg;
break;
case 's': // serial device
primary = optarg;
break;
case 'S':
service = optarg;
break;
default:
fprintf( stderr, "Unknown option -%c\n", c );
exit(1);
}
}
// check options
if ( !primary )
{
fprintf( stderr, "Must have a serial device to communicate with!\n" );
exit(1);
}
if ( mcast && listen )
{
fprintf( stderr, "Cannot do both UDP broadcast/multicast and listening!\n" );
exit(1);
}
// input
if ( primary )
{
// open GPS device on serial port
int serial = Ser.SerialOpen( primary, baud );
if ( serial < 0 )
{
fprintf( stderr, "Unable to open primary serial device: %s @ %d !\n", primary, baud );
exit(1);
}
}
else
{
fprintf( stderr, "No task specified: use -l or -s <dev>!\n" );
exit(1);
}
// corrections
if ( host )
{
// RTCM server
int remote = Ser.TcpConnect( host );
if ( remote < 0 )
{
fprintf( stderr, "Unable to connect to remote host: %s\n", host );
exit(1);
}
}
else if ( listen )
{
// listen on UDP broadcasts for RTCM corrrections
int dgram = Ser.UdpListen( NULL );
if ( dgram < 0 )
{
fprintf( stderr, "Unable to listen on UDP broadcast!\n" );
exit(1);
}
}
// output
if ( mcast )
{
int bcast = Ser.UdpBroadcast( mcast );
if ( bcast < 0 )
{
fprintf( stderr, "Unable to create UDP broadcast!\n" );
exit(1);
}
}
// TCP listener
if ( Ser.StartService( SERIALD_NAME, NULL, service, debug ) >= 0 )
return Ser.RunService();
return 1;
}

View File

@ -0,0 +1,22 @@
cmake_minimum_required(VERSION 3.7)
set(NAME stdiod)
project(Cnomicon-Daemon)
set(TARGET ${NAME})
set(CMAKE_INSTALL_PREFIX ..)
# includes
include_directories(
/usr/include/libxml2
../include/libnet++ ../include)
link_directories(../lib)
link_libraries(net++ net pthread rt)
# sources
set(SRCS
StdioDaemon.cpp
)
# executables
add_executable(${TARGET} ${TARGET}.cpp ${SRCS})
install(TARGETS ${TARGET} DESTINATION sbin)

View File

@ -0,0 +1,162 @@
//
// Stdio Daemon
// Neal Probert
//
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <time.h>
#include <sys/timeb.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/types.h>
#include "UriParse.h"
#include "StdioDaemon.h"
#include "netlib.h"
//****************************************************************************
// defines
//***************************************************************************/
//****************************************************************************
// macros
//***************************************************************************/
//****************************************************************************
// structs & typedefs
//***************************************************************************/
//****************************************************************************
// global constants
//***************************************************************************/
//****************************************************************************
// global variables
//***************************************************************************/
//****************************************************************************
// static constants
//***************************************************************************/
//****************************************************************************
// static variables
//***************************************************************************/
//****************************************************************************
// static functions
//***************************************************************************/
//****************************************************************************
// C++ functions
//***************************************************************************/
StdioDaemon::StdioDaemon()
{
// logging
log_open( STDIOD_NAME );
m_RemoteIn = m_DgramIn = -1;
m_Stdin = 0;
AddFd( m_Stdin );
}
StdioDaemon::~StdioDaemon()
{
}
/* TCP ***********************************************************************/
int StdioDaemon::ServerSocket(void)
{
char buf[2048];
int n = 0;
if ( IsSet( m_RemoteIn ) )
{
// from server (tbd)
int n = Client.Recv( buf, sizeof(buf) );
if ( n > 0 )
fputs( buf, stdout );
}
else if ( IsSet( m_Stdin ) )
{
// packet from GPS device
while ( fgets( buf, sizeof(buf), stdin ) )
{
int n = strlen( buf );
if ( n>0 )
ClientCast( buf, n );
}
}
else if ( IsSet( m_DgramIn ) )
{
// RTCM packet from UDP broadcast (once a minute)
int n = Dgram.RecvFrom( buf, sizeof(buf) );
// send to GPS device
if ( n > 0 )
fputs( buf, stdout );
}
return n;
}
int StdioDaemon::ClientIn( int sock, const char *buf, int n )
{
return fputs( buf, stdout );
}
void StdioDaemon::ClientCast( const char *buf, int n )
{
// broadcast it
Bcast.SendTo( buf, n );
// send to clients
TcpServer::ClientCast( buf, n );
}
/* GPS ***********************************************************************/
int StdioDaemon::TcpConnect( const char *uri )
{
UriParse parsed;
parsed.setUri( uri );
const char *proto = parsed.getProto();
if ( strcasecmp( proto, "http" ) == 0 ||
strcasecmp( proto, "https" ) == 0 )
{
// web site
}
else if ( strcasecmp( proto, "telnet" ) == 0 ||
strlen( proto ) == 0 )
{
// straight TCP client
m_RemoteIn = Client.Connect( parsed.getHost(), parsed.getService() );
}
return m_RemoteIn;
}
int StdioDaemon::UdpListen( const char *uri )
{
m_DgramIn = Dgram.ListenUri( uri );
if ( m_DgramIn > 0 )
AddFd( m_DgramIn );
return m_DgramIn;
}
int StdioDaemon::UdpBroadcast( const char *uri )
{
return Bcast.CasterUri( uri );
}

View File

@ -0,0 +1,87 @@
//
// Stdio Daemon
// Neal Probert
//
/* prevent multiple inclusions */
#ifndef __StdioDaemon__
#define __StdioDaemon__
/* includes *****************************************************************/
#include "bzlib.h"
#include "TcpDaemon.h"
#include "TcpClient.h"
#include "UdpClient.h"
#include "UdpCaster.h"
#include "LogData.h"
/* defines ******************************************************************/
#define STDIOD_NAME "stdiod"
#define STDIOD_SERVICE "stdiod"
#define STDIOD_PORT "2941"
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
/* c class definitions ******************************************************/
//
// Uses the Peak Systems CAN Linux driver and Nissan CAN data
//
class StdioDaemon : public TcpDaemon {
// public data
public:
// private data
private:
// FDs
int m_Stdin;
int m_RemoteIn;
int m_DgramIn;
// TCP client
TcpClient Client;
// UDP listen
UdpClient Dgram;
// UDP broadcast
UdpCaster Bcast;
// misc
// private methods
// static data
// public methods
public:
// constructors
StdioDaemon();
// destructor
virtual ~StdioDaemon();
// virtual functions
int ServerSocket(void);
int ClientIn( int sock, const char *buf, int n );
void ClientCast( const char *buf, int n );
// public methods
int TcpConnect( const char *uri );
int UdpBroadcast( const char *uri );
int UdpListen( const char *uri );
// static methods
// private methods
private:
};
#endif

140
daemons/stdiod/stdiod.cpp Normal file
View File

@ -0,0 +1,140 @@
//
// Stdio Daemon
// Neal Probert
//
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <arpa/inet.h>
#include "StdioDaemon.h"
#include "netlib.h"
extern int optind, opterr, optopt;
//
// any port
//
static const char *helptext =
"stdiod [options]\n"
"\t-d debug (foreground with stdio)\n"
"\t-h help\n"
"\t-l UDP listen for data\n"
"\t-m network broadcast data\n"
"\t-S service TCP service\n";
int main(int argc, char **argv)
{
char c; /* we have character */
StdioDaemon Std;
/* options */
int debug = 0; // run in foreground, leaves stdio open
/* dgpsip server */
char *host = NULL;
/* udp broadcast */
char *mcast = NULL;
/* udp listener */
char *listen = NULL;
/* server */
char *service = (char *)STDIOD_PORT;
// add command line args
while ( (c = getopt( argc, argv, "dhm:l:r:S:" )) > 0 )
{
switch ( c )
{
case 'd':
debug = 1;
break;
case 'h':
puts( helptext );
return 0;
case 'l': // udp listen
listen = optarg;
break;
case 'm': // udp broadcast
mcast = optarg;
break;
case 'r': // remote host
host = optarg;
break;
case 'S':
service = optarg;
break;
default:
fprintf( stderr, "Unknown option -%c\n", c );
exit(1);
}
}
// check options
if ( mcast && listen )
{
fprintf( stderr, "Cannot do both UDP broadcast/multicast and listening!\n" );
exit(1);
}
// input
// corrections
if ( host )
{
// RTCM server
int remote = Std.TcpConnect( host );
if ( remote < 0 )
{
fprintf( stderr, "Unable to connect to remote host: %s\n", host );
exit(1);
}
}
else if ( listen )
{
// listen on UDP broadcasts for RTCM corrrections
int dgram = Std.UdpListen( listen );
if ( dgram < 0 )
{
fprintf( stderr, "Unable to listen on UDP broadcast!\n" );
exit(1);
}
}
// output
if ( mcast )
{
int bcast = Std.UdpBroadcast( mcast );
if ( bcast < 0 )
{
fprintf( stderr, "Unable to create UDP broadcast!\n" );
exit(1);
}
}
// TCP listener
if ( Std.StartService( STDIOD_NAME, NULL, service, debug ) >= 0 )
return Std.RunService();
return 1;
}

View File

@ -0,0 +1,194 @@
//
// Track Daemon
// Neal Probert
//
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <time.h>
#include <sys/timeb.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/types.h>
#include "NmeaParser.h"
#include "UriParse.h"
#include "TrackDaemon.h"
#include "netlib.h"
//****************************************************************************
// defines
//***************************************************************************/
//****************************************************************************
// macros
//***************************************************************************/
//****************************************************************************
// structs & typedefs
//***************************************************************************/
//****************************************************************************
// global constants
//***************************************************************************/
//****************************************************************************
// global variables
//***************************************************************************/
//****************************************************************************
// static constants
//***************************************************************************/
//****************************************************************************
// static variables
//***************************************************************************/
//****************************************************************************
// static functions
//***************************************************************************/
//****************************************************************************
// C++ functions
//***************************************************************************/
TrackDaemon::TrackDaemon()
{
log_open( TRACKD_NAME );
gethostname( Id, sizeof(Id) );
}
TrackDaemon::~TrackDaemon()
{
}
/* UDP ***********************************************************************/
void TrackDaemon::PositionListener( const PositionFix &Pos, const ErrorInfo &Err )
{
char buf[256];
int n = 0;
char datetime[40];
// convert date & time (MySQL friendly)
struct tm *tmp = gmtime(&Pos.Time.tv_sec);
strftime( datetime, sizeof(datetime), "%Y-%m-%d,%T", tmp );
// convert to unicsv
n = snprintf( buf, sizeof(buf),
"%s,%s,%lf,%lf,%lf,%lf,%lf\n",
Id, // name
datetime, // time
Pos.Latitude, // lat
Pos.Longitude, // long
Pos.Altitude, // elev
Pos.Speed, // speed (m/sec -> kph)
Pos.Heading // heading
);
// send upstream
if ( TrackOut >= 0 )
Track.SendTo( buf, n );
// log locally
Log.LogWrite( buf, n );
}
void TrackDaemon::TimeListener( const struct timeval &tv )
{
}
int TrackDaemon::ServerSocket(void)
{
char buf[2048];
int n = 0;
if ( IsSet( GpsIn ) )
{
// Gpsd
if ( (n = Gpsd.Recv( buf, sizeof(buf) )) > 0 )
{
// use NMEA parser (should trigger on RMC or GGA)
Gps.Nmea.NmeaParse(buf);
}
}
return n;
}
int TrackDaemon::ClientInOut( char *buf, int n, int max )
{
// check
if ( n <= 0 )
return 0;
// parse $PVII
if ( buf[0] == '$' )
{
// use NMEA parser (should trigger on RMC or GGA)
Gps.Nmea.NmeaParse( buf );
}
else
{
// forward
if ( TrackOut >= 0 )
Track.SendTo( buf, n );
// log
Log.LogWrite( buf , n );
}
// no response
return 0;
}
/* GPS ***********************************************************************/
int TrackDaemon::GpsdServer( const char *uri )
{
UriParse parsed;
parsed.setProto( "gpsd" );
parsed.setService( "gpsd" );
parsed.setUri( uri );
bGpsd = 0;
const char *proto = parsed.getProto();
if ( !strlen(proto) )
proto = "gpsd";
GpsDeviceType type = Gps.Proto2Type( proto );
// open device
if ( strcmp( proto, "gpsd" ) == 0 || type == GPS_TYPE_UNDEF )
GpsIn = Gpsd.GpsdConnect( parsed.getHost() );
else
GpsIn = Gps.GpsOpen( parsed.getPath(), parsed.getRate(), type );
if ( GpsIn >= 0 )
AddFd( GpsIn );
return GpsIn;
}
int TrackDaemon::TrackOpen( const char *uri )
{
UriParse parsed;
parsed.setService( TRACKD_PORT );
parsed.setUri( uri );
// connect to remote web server to upload data
return TrackOut = Track.Connect( parsed.getHost(), TRACKD_PORT );
}
int TrackDaemon::LogOpen( const char *uri )
{
if ( Log.LogOpen( uri ) )
{
Log.LogFields( "name,date,time,lat,long,ele,speed,head" );
return 1;
}
return -1;
}

View File

@ -0,0 +1,89 @@
//
// Track Daemon
// Neal Probert
//
/* prevent multiple inclusions */
#ifndef __TrackDaemon__
#define __TrackDaemon__
/* includes *****************************************************************/
#include "bzlib.h"
#include "UdpDaemon.h"
#include "TcpClient.h"
#include "UdpClient.h"
#include "Logging.h"
#include "GpsdClient.h"
#include "GpsDevice.h"
/* defines ******************************************************************/
#define TRACKD_NAME "trackd"
#define TRACKD_SERVICE "trackd"
#define TRACKD_PORT "2948"
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
/* c class definitions ******************************************************/
//
// Listens to OBE HeartBeat messages
//
class TrackDaemon : public UdpDaemon, public GpsListener, public Logging {
// public data
public:
// private data
private:
// my name
char Id[32];
// Gpsd client
GpsdClient Gpsd; // direct from GPSd
GpsDevice Gps; // or from serial port
bool bGpsd; // true for Gpsd
int GpsIn; // Gpsd or Gps
// upstream trackd
UdpClient Track; // listener
int TrackOut;
// NMEA parsing
// private methods
// static data
// public methods
public:
// constructors
TrackDaemon();
// destructor
virtual ~TrackDaemon();
// virtual functions
int ServerSocket(void);
int ClientInOut( char *buf, int n, int max );
// public methods
int GpsdServer( const char *uri );
void PositionListener( const PositionFix &Pos, const ErrorInfo &Err );
void TimeListener( const struct timeval &Time );
void SetId( const char *id ) { strncpy(Id,id,sizeof(Id)-1); };
int TrackOpen( const char *uri );
int LogOpen( const char *uri );
// static methods
// private methods
private:
};
#endif

132
daemons/trackd/trackd.cpp Normal file
View File

@ -0,0 +1,132 @@
//
// Serial Daemon (similar to ser2net)
// Neal Probert
//
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <arpa/inet.h>
#include "TrackDaemon.h"
#include "netlib.h"
extern int optind, opterr, optopt;
//
// any port
//
static const char *helptext =
"stdiod [options]\n"
"\t-d debug (foreground with stdio)\n"
"\t-g host gpsd\n"
"\t-h help\n"
"\t-i id set my id\n"
"\t-c uri host:port source data (CardiacMonitor)\n"
"\t-o logfile format:/path/to/file.log\n"
"\t-r uri remote web host for upload\n"
"\t-S service TCP service\n";
int main(int argc, char **argv)
{
char c; /* we have character */
TrackDaemon Track;
/* options */
int debug = 0; // run in foreground, leaves stdio open
/* connections */
char *gpsd = NULL; // "localhost";
char *host = NULL;
char *id = NULL;
char *log = NULL;
char *service = TRACKD_PORT;
// add command line args
while ( (c = getopt( argc, argv, "dg:hi:o:r:S:" )) > 0 )
{
switch ( c )
{
case 'd':
debug = 1;
break;
case 'g':
gpsd = optarg;
break;
case 'h':
puts( helptext );
return 0;
case 'i':
id = optarg;
break;
case 'o':
log = optarg;
break;
case 'r':
host = optarg;
break;
case 'S':
service = optarg;
break;
default:
fprintf( stderr, "Unknown option -%c\n", c );
exit(1);
}
}
// set my id (hostname by default)
if ( id )
Track.SetId( id );
// monitor
if ( gpsd )
{
// GPSd
int remote = Track.GpsdServer( gpsd );
if ( remote < 0 )
{
fprintf( stderr, "Unable to connect to gpsd: %s\n", gpsd );
// exit(1);
}
}
// output
if ( host )
{
if ( Track.TrackOpen( host ) < 0 )
{
fprintf( stderr, "Unable to open vehicle location server: %s!\n", host );
// exit(1);
}
}
if ( log )
{
if ( !Track.LogOpen( log ) )
{
fprintf( stderr, "Unable to open log file: %s!\n", log );
exit(1);
}
}
// TCP listener
if ( Track.StartService( TRACKD_NAME, NULL, service, debug ) >= 0 )
return Track.RunService();
return 1;
}

2
etc/cnomicon.conf Normal file
View File

@ -0,0 +1,2 @@
# other libs
/usr/local/cnomicon/lib

61
include/CAN_Packet.h Normal file
View File

@ -0,0 +1,61 @@
#ifndef __CAN_PACKET_INCLUDE__
#define __CAN_PACKET_INCLUDE__
/******************************************************************************
* includes
*****************************************************************************/
#ifdef __linux__
#include <sys/types.h>
#endif
/******************************************************************************
* defines
*****************************************************************************/
/******************************************************************************
* structs & typedefs
*****************************************************************************/
// all data is network byte order (big endian)
typedef struct _CAN_Packet {
uint32_t dwCounter; // incrementing counter
// J2735 Part 1 floating point
float fSpeed; // meters/sec (m/s)
float fSteering; // degrees/sec
float fAccelLongitudinal; // meters/sec^2
float fAccelLateral; // meters/sec^2
float fAccelVertical; // meters/sec^2
float fYawRate; // degrees/sec
float fVehicleWidth;
float fVehicleLength;
// J2735 Part 2 floating point
float fThrottle; // %
// J2735 Part 1/2 integer
uint16_t wBrakeSystemStatus;
uint8_t byTransmission;
uint8_t byExteriorLights;
// J2735 Part 2 integer
uint16_t wEventFlags;
uint8_t byFrontWipers;
} __attribute__((packed)) CAN_Packet;
/******************************************************************************
* function prototypes
*****************************************************************************/
/* export C functions to C++ */
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
/******************************************************************************
* Macros
* ***************************************************************************/
#endif

77
include/asn1common.h Normal file
View File

@ -0,0 +1,77 @@
#ifndef __ASN1COMMON_INCLUDE__
#define __ASN1COMMON_INCLUDE__
/******************************************************************************
* includes
*****************************************************************************/
#include <stdio.h>
#include <stdint.h>
#include <sys/types.h>
#include <memory.h>
#include "embtypes.h"
/******************************************************************************
* defines
*****************************************************************************/
#define ASN1_UPER_ALIGNED 0
#define ASN1_APER_ALIGNED 1
#define ASN1_OER_ALIGNED 2
#define asn1_get_error(S) ((S)->error)
#define asn1_get_bits_consumed(O) ((O)->consumed)
#define asn1_get_bytes_consumed(O) ((O)->consumed?(((O)->consumed-1)/8+1):0)
#define asn1_init_extension(E) memset((E),0,sizeof(ASN1_Extension))
#define asn1_init_bitstream(E) memset((E),0,sizeof(ASN1_BitStream))
/******************************************************************************
* structs & typedefs
*****************************************************************************/
typedef struct _asn1_stream {
uint8_t *buf; // pointer to first byte
uint8_t *ptr; // pointer to current byte
uint8_t alloc; // set if alloc'd
uint8_t align; // alignment
uint8_t error; // set if error
uint16_t bit; // current bit in byte
uint16_t max; // maximum bits
uint16_t consumed;// bits consumed
} ASN1_Stream;
typedef struct _asn1_bitstream {
uint64_t value; // value
uint16_t max; // maximum bits
} ASN1_BitStream;
typedef struct _asn1_extension {
uint64_t value; // extension+option bits
uint8_t ellipses; // 0 or 1
uint8_t options; // # options
uint16_t length; // length of extension
} ASN1_Extension;
/******************************************************************************
* function prototypes
*****************************************************************************/
/* export C functions to C++ */
#ifdef __cplusplus
extern "C" {
#endif
void asn1_set_debug(uint8_t flag);
extern uint8_t _asn1_debug_on_;
#ifdef __cplusplus
}
#endif
/******************************************************************************
* Macros
* ***************************************************************************/
#endif

111
include/asn1oer.h Normal file
View File

@ -0,0 +1,111 @@
#ifndef __ASN1OER_INCLUDE__
#define __ASN1OER_INCLUDE__
/******************************************************************************
* includes
*****************************************************************************/
#include <stdio.h>
#include <stdint.h>
#include <sys/types.h>
#include <memory.h>
#include "embtypes.h"
#include "asn1common.h"
/******************************************************************************
* defines
*****************************************************************************/
#define oer_get_error(O) ((O)->error)
#define oer_get_bytes_consumed(O) asn1_get_bytes_consumed(O)
#define oer_init_extension(E) asn1_init_extension(E)
#define oer_init_bitstream(E) asn1_init_bitstream(E)
#define oer_get_signed_value(U,B,O) (((int64_t)uper_get_bits_stream(U,B))-O)
#define oer_get_unsigned_value(U,B) uper_get_bits_stream(U,B)
#define oer_get_char_value(O) ((int8_t)(oer_get_value(O,1)))
#define oer_get_int8_value(O) ((int8_t)(oer_get_value(O,1)))
#define oer_get_byte_value(O) ((uint8_t)(oer_get_value(O,1)))
#define oer_get_uint8_value(O) ((uint8_t)(oer_get_value(O,1)))
#define oer_get_short_value(O) ((int16_t)(oer_get_value(O,2)))
#define oer_get_int16_value(O) ((int16_t)(oer_get_value(O,2)))
#define oer_get_word_value(O) ((uint16_t)(oer_get_value(O,2)))
#define oer_get_uint16_value(O) ((uint16_t)(oer_get_value(O,2)))
#define oer_get_long_value(O) ((int32_t)(oer_get_value(O,4)))
#define oer_get_int32_value(O) ((int32_t)(oer_get_value(O,4)))
#define oer_get_dword_value(O) ((uint32_t)(oer_get_value(O,4)))
#define oer_get_uint32_value(O) ((uint32_t)(oer_get_value(O,4)))
#define oer_get_llong_value(O) ((int64_t)oer_get_value(O,8))
#define oer_get_int64_value(O) ((int64_t)oer_get_value(O,8))
#define oer_get_qword_value(O) ((uint64_t)oer_get_value(O,8))
#define oer_get_uint64_value(O) ((uint64_t)oer_get_value(O,8))
#define oer_get_string(O,B,N,X) oer_get_octet_stream(O,B,N,X)
#define oer_put_string(O,B,L,N,X) oer_put_octet_stream(O,B,L,N,X)
#define OER_Stream ASN1_Stream
#define OER_Extension ASN1_Extension
#define OER_BitStream ASN1_BitStream
/******************************************************************************
* structs & typedefs
*****************************************************************************/
/******************************************************************************
* function prototypes
*****************************************************************************/
/* export C functions to C++ */
#ifdef __cplusplus
extern "C" {
#endif
void oer_init_stream(OER_Stream *strm, uint8_t *ptr, uint max);
OER_Stream *uper_alloc_stream(uint8_t *ptr, uint max);
void oer_free_stream(OER_Stream *oer);
// DECODE
uint oer_get_length(OER_Stream *oer, uint *value);
uint64_t oer_get_value(OER_Stream *oer, uint size);
uint oer_get_data(OER_Stream *oer, uint8_t *data, uint max);
// ENCODE
uint oer_put_length(OER_Stream *oer, uint value);
void oer_put_value(OER_Stream *oer, uint64_t value, uint size);
void oer_put_data(OER_Stream *oer, uint8_t *data, uint length);
// EXTENSIONS
uint oer_get_extension(OER_Stream *uper, OER_Extension *ext, uint nbits, uint ellipses);
uint oer_get_ext_ellipses(OER_Extension *ext);
uint oer_get_ext_optional(OER_Extension *ext, uint bit);
uint oer_get_ext_length(OER_Stream *uper, OER_Extension *ext);
uint oer_get_ext_skip(OER_Stream *uper, OER_Extension *ext);
void oer_put_extension(OER_Stream *uper, OER_Extension *ext);
void oer_set_ext_ellipses(OER_Extension *ext);
void oer_set_ext_length(OER_Extension *ext, uint len);
void oer_set_ext_optional(OER_Extension *ext, uint option, uint val, uint nbits);
// OCTET
uint oer_get_octet_stream(OER_Stream *ptr, uint8_t *buf, uint min, uint max);
void oer_put_octet_stream(OER_Stream *ptr, uint8_t *buf, uint len, uint min, uint max);
// BIT STREAM
uint64_t oer_get_bitstream(OER_Stream *ptr, OER_BitStream *bs, uint max);
uint64_t oer_get_bit_bitstream(OER_BitStream *bs, uint bit);
void oer_put_bitstream(OER_Stream *ptr, OER_BitStream *bs);
void oer_set_bit_bitstream(OER_BitStream *bs, uint bit, uint max);
void oer_set_bits_bitstream(OER_BitStream *bs, uint64_t value, uint max);
#ifdef __cplusplus
}
#endif
/******************************************************************************
* Macros
* ***************************************************************************/
#endif

118
include/asn1uper.h Normal file
View File

@ -0,0 +1,118 @@
#ifndef __ASN1UPER_INCLUDE__
#define __ASN1UPER_INCLUDE__
/******************************************************************************
* includes
*****************************************************************************/
#include <stdio.h>
#include <stdint.h>
#include <sys/types.h>
#include <memory.h>
#include "embtypes.h"
#include "asn1common.h"
/******************************************************************************
* defines
*****************************************************************************/
#define uper_get_error(S) ((S)->error)
#define uper_get_bits_consumed(U) asn1_get_bits_consumed(U)
#define uper_get_bytes_consumed(U) asn1_get_bytes_consumed(U)
#define uper_get_bits_length(U,S) (uper_get_bits_stream(U,S)+1)
#define uper_put_bits_length(U,L,S) uper_put_bits_stream(U,(L)-1,S)
#define uper_init_extension(E) asn1_init_extension(E)
#define uper_init_bitstream(E) asn1_init_bitstream(E)
#define uper_get_signed_value(U,B,O) (((int64_t)uper_get_bits_stream(U,B))-O)
#define uper_get_unsigned_value(U,B) uper_get_bits_stream(U,B)
#define uper_get_char_value(O) ((int8_t)(uper_get_value(O,1)))
#define uper_get_int8_value(O) ((int8_t)(uper_get_value(O,1)))
#define uper_get_byte_value(O) ((uint8_t)(uper_get_value(O,1)))
#define uper_get_uint8_value(O) ((uint8_t)(uper_get_value(O,1)))
#define uper_get_short_value(O) ((int16_t)(uper_get_value(O,2)))
#define uper_get_int16_value(O) ((int16_t)(uper_get_value(O,2)))
#define uper_get_word_value(O) ((uint16_t)(uper_get_value(O,2)))
#define uper_get_uint16_value(O) ((uint16_t)(uper_get_value(O,2)))
#define uper_get_long_value(O) ((int32_t)(uper_get_value(O,4)))
#define uper_get_int32_value(O) ((int32_t)(uper_get_value(O,4)))
#define uper_get_dword_value(O) ((uint32_t)(uper_get_value(O,4)))
#define uper_get_uint32_value(O) ((uint32_t)(uper_get_value(O,4)))
#define uper_get_llong_value(O) ((int64_t)uper_get_value(O,8))
#define uper_get_int64_value(O) ((int64_t)uper_get_value(O,8))
#define uper_get_qword_value(O) ((uint64_t)uper_get_value(O,8))
#define uper_get_uint64_value(O) ((uint64_t)uper_get_value(O,8))
#define uper_get_string(O,B,N,X) uper_get_octet_stream(O,B,N,X)
#define uper_put_string(O,B,L,N,X) uper_put_octet_stream(O,B,L,N,X)
#define UPER_Stream ASN1_Stream
#define UPER_Extension ASN1_Extension
#define UPER_BitStream ASN1_BitStream
/******************************************************************************
* structs & typedefs
*****************************************************************************/
/******************************************************************************
* function prototypes
*****************************************************************************/
/* export C functions to C++ */
#ifdef __cplusplus
extern "C" {
#endif
void uper_init_stream(UPER_Stream *strm, uint8_t *ptr, uint max);
UPER_Stream *uper_alloc_stream(uint8_t *ptr, uint max);
void uper_free_stream(UPER_Stream *oer);
// DECODE
uint uper_get_bit_direct(const uint8_t *pkt, uint bit);
uint64_t uper_get_bits_direct(const uint8_t *pkt, uint bit, uint bits);
uint64_t uper_get_bits_stream(UPER_Stream *ptr, uint bits);
uint64_t uper_get_bits_stream_reverse(UPER_Stream *ptr, uint nbits);
uint uper_get_bytes_stream(UPER_Stream *uper, uint8_t *buf, uint nbytes);
// ENCODE
void uper_put_bit_direct(uint8_t *pkt, uint val, uint bit);
void uper_put_bits_direct(uint8_t *pkt, uint64_t value, uint bit, uint bits);
void uper_put_bits_stream(UPER_Stream *uper, uint64_t value, uint bits);
void uper_put_bytes_stream(UPER_Stream *uper, uint8_t *buf, uint nbytes);
// EXTENSIONS
uint uper_get_extension(UPER_Stream *uper, UPER_Extension *ext, uint nbits, uint ellipses);
uint uper_get_ext_ellipses(UPER_Extension *ext);
uint uper_get_ext_optional(UPER_Extension *ext, uint bit);
uint uper_get_ext_length(UPER_Stream *uper, UPER_Extension *ext);
uint uper_get_ext_skip(UPER_Stream *uper, UPER_Extension *ext);
void uper_put_extension(UPER_Stream *uper, UPER_Extension *ext);
void uper_set_ext_ellipses(UPER_Extension *ext);
void uper_set_ext_length(UPER_Extension *ext, uint len);
void uper_set_ext_optional(UPER_Extension *ext, uint option, uint val, uint nbits);
// OCTET
uint uper_get_octet_stream(UPER_Stream *ptr, uint8_t *buf, uint min, uint max);
void uper_put_octet_stream(UPER_Stream *uper, uint8_t *buf, uint len, uint min, uint max);
// BIT STREAM
uint64_t uper_get_bitstream(UPER_Stream *uper, UPER_BitStream *bs, uint max);
uint64_t uper_get_bit_bitstream(UPER_BitStream *bs, uint bit);
void uper_put_bitstream(UPER_Stream *uper, UPER_BitStream *bs);
void uper_set_bit_bitstream(UPER_BitStream *bs, uint bit, uint max);
void uper_set_bits_bitstream(UPER_BitStream *bs, uint64_t value, uint max);
#ifdef __cplusplus
}
#endif
/******************************************************************************
* Macros
* ***************************************************************************/
#endif

46
include/asnlib.h Normal file
View File

@ -0,0 +1,46 @@
#ifndef __ASNLIB_INCLUDE__
#define __ASNLIB_INCLUDE__
/******************************************************************************
* includes
*****************************************************************************/
#include <stdint.h>
#include <sys/types.h>
#include <memory.h>
/******************************************************************************
* defines
*****************************************************************************/
/******************************************************************************
* structs & typedefs
*****************************************************************************/
typedef struct _bit_struct {
const uint8_t *ptr;
int bit;
int max;
int consumed;
} UPER_Stream;
/******************************************************************************
* function prototypes
*****************************************************************************/
/* export C functions to C++ */
#ifdef __cplusplus
extern "C" {
#endif
int uper_get_bit(const uint8_t *pkt, int bit);
uint64_t uper_get_bits_direct(const uint8_t *pkt, int bit, int bits);
uint64_t uper_get_bits_stream(UPER_Stream *ptr, int bits)
#ifdef __cplusplus
}
#endif
/******************************************************************************
* Macros
* ***************************************************************************/
#endif

52
include/bitlib.h Normal file
View File

@ -0,0 +1,52 @@
#ifndef __BITLIB_INCLUDE__
#define __BITLIB_INCLUDE__
/******************************************************************************
* includes
*****************************************************************************/
#include <stdio.h>
#include <stdint.h>
#include <sys/types.h>
#include <memory.h>
#include "embtypes.h"
/******************************************************************************
* defines
*****************************************************************************/
/******************************************************************************
* structs & typedefs
*****************************************************************************/
typedef struct _bit_struct {
const uint8_t *ptr;
int bit;
int max;
int consumed;
} BIT_Stream;
/******************************************************************************
* function prototypes
*****************************************************************************/
/* export C functions to C++ */
#ifdef __cplusplus
extern "C" {
#endif
BYTE reverseByteBits(BYTE b);
void enableBitDebug(int flag);
int getBitDirect(const uint8_t *pkt, int bit);
uint64_t getBitsDirect(const uint8_t *pkt, int bit, int bits);
uint64_t getBitsStream(BIT_Stream *ptr, int bits);
#ifdef __cplusplus
}
#endif
/******************************************************************************
* Macros
* ***************************************************************************/
#endif

112
include/bytequeue.h Normal file
View File

@ -0,0 +1,112 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* BYTE Queue
*****************************************************************************/
/* prevent multiple inclusions */
#ifndef __EMBEDDED_BYTEQUEUE__
#define __EMBEDDED_BYTEQUEUE__
/*****************************************************************************
* includes
*****************************************************************************/
#include "embtypes.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
#define _QueuePut(Q,D) \
{ \
*((Q).pbyBuf+((Q).byFront++)) = (D); \
(Q).byCount++; \
if ( (Q).byFront == (Q).bySize ) \
(Q).byFront = 0; \
}
#define _QueueUnput(Q) \
{ \
if ( (Q).byFront == 0 ) \
(Q).byFront = (Q).bySize; \
*((Q).pbyBuf+(--(Q).byFront)) = (0); \
(Q).byCount--; \
}
#define _QueueGet(Q,D) \
{ \
(D) = *((Q).pbyBuf+((Q).byRear++)); \
(Q).byCount--; \
if ( (Q).byRear == (Q).bySize ) \
(Q).byRear = 0; \
}
#define _QueueUnget(Q,D) \
{ \
if ( (Q).byRear == 0 ) \
(Q).byRear = (Q).bySize; \
*((Q).pbyBuf+(--(Q).byRear)) = (D); \
(Q).byCount++; \
}
#define _QueueAlloc(Q,B,N) (Q).pbyBuf=(B);(Q).bySize=(N)
#define _QueueClear(Q) (Q).byCount=(Q).byFront=(Q).byRear=0
#define _QueueCount(Q) (Q).byCount
#define _QueueSize(Q) (Q).bySize
#define _QueueEmpty(Q) ((Q).byCount==0)
#define _QueueFull(Q) ((Q).byCount>=(Q).bySize)
#define QueueCount(Q) (Q)->byCount
#define QueueSize(Q) (Q)->bySize
#define QueueEmpty(Q) ((Q)->byCount==0)
#define QueueFull(Q) ((Q)->byCount>=(Q)->bySize)
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
typedef struct _Queue {
BYTE byCount;
BYTE byFront;
BYTE byRear;
BYTE bySize;
BYTE *pbyBuf;
} Queue;
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* C function prototypes
*****************************************************************************/
/* export C functions to C++ */
#ifdef __cplusplus
extern "C" {
#endif
void QueueAlloc( Queue *pQ, BYTE *pbyData, BYTE bySize );
void QueueClear( Queue *pQ );
BYTE QueueGet( Queue *pQ, BYTE *pbyData );
BYTE QueuePut( Queue *pQ, BYTE *pbyData );
BYTE QueueUnget( Queue *pQ, BYTE byData );
BYTE QueueUnput( Queue *pQ );
#ifdef __cpluscplus
}
#endif
#endif

81
include/bytestack.h Normal file
View File

@ -0,0 +1,81 @@
/*****************************************************************************
* Copyright (C) 2004-2005
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* BYTE Stack
*****************************************************************************/
/* prevent multiple inclusions */
#ifndef __EMBEDDED_BYTESTACK__
#define __EMBEDDED_BYTESTACK__
/*****************************************************************************
* includes
*****************************************************************************/
#include "embtypes.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
#define _StackPush(S,D) \
if ( (S).byCount < (S).bySize ) \
*((S).pbyBuf+((S).byCount++)) = (D);
#define _StackPop(S) ((S).byCount ? *((S).pbyBuf+(--(S).byCount)) : 0)
#define _StackAlloc(S,B,N) (S).pbyBuf=(B);(S).bySize=(N)
#define _StackClear(S) (S).byCount=0
#define _StackCount(S) (S).byCount
#define _StackSize(S) (S).bySize
#define _StackEmpty(S) ((S).byCount==0)
#define _StackFull(S) ((S).byCount>=(S).bySize)
#define StackClear(S) (S)->byCount=0
#define StackCount(S) (S)->byCount
#define StackSize(S) (S)->bySize
#define StackEmpty(S) ((S)->byCount==0)
#define StackFull(S) ((S)->byCount>=(S)->bySize)
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
typedef struct _Stack {
BYTE byCount;
BYTE bySize;
BYTE *pbyBuf;
} Stack;
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* C function prototypes
*****************************************************************************/
/* export C functions to C++ */
#ifdef __cplusplus
extern "C" {
#endif
void StackAlloc( Stack *pS, BYTE *pbyBuf, BYTE bySize );
BYTE StackPush( Stack *pS, BYTE *pbyData );
BYTE StackPop( Stack *pS, BYTE *pbyData );
#ifdef __cpluscplus
}
#endif
#endif

74
include/emblib.h Normal file
View File

@ -0,0 +1,74 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Multiplatform Embedded Data Types and Conversion
* Checksum and CRC Routines
*****************************************************************************/
/* prevent multiple inclusions */
#ifndef _EMBLIB_H_
#define _EMBLIB_H_
/*****************************************************************************
* includes
*****************************************************************************/
#include "embtypes.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/* useful one to have */
#define bin2bcd(d) (((((d)/10)<<4|(d)%10)))
#define bcd2bin(b) ((((b)>>4)*10)+((b)&0xf))
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* C function prototypes
*****************************************************************************/
/* export C functions to C++ */
#ifdef __cplusplus
extern "C" {
#endif
int chomp(char *s);
void base64(const unsigned char *in, char *out, int len);
int unbase64(const char *in, unsigned char *out, int max);
extern BYTE doCheckSum( const BYTE *pbyData, BYTE nBytes );
extern WORD doCheckSumW( const WORD *pwData, WORD nBytes );
extern BYTE doCRC8( BYTE byCrc, BYTE byData );
extern BYTE strCRC8( BYTE *pbyData, WORD nBytes, BYTE byInit );
extern WORD doCRC16( WORD wCrc, BYTE byData );
extern WORD strCRC16( BYTE *pbyData, WORD nBytes, WORD wInit );
short InterpolateShortTable( const short *psTbl, BYTE nPairs, short sData );
long InterpolateLongTable( const long *plTbl, BYTE nPairs, long lData );
BYTE reverseByteBits(BYTE b);
#ifdef __cplusplus
}
#endif
#endif

47
include/embstruct.h Normal file
View File

@ -0,0 +1,47 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Multiplatform Embedded Data Types and Conversion
* Checksum and CRC Routines
*****************************************************************************/
/* prevent multiple inclusions */
#ifndef _EMBSTRUCT_H_
#define _EMBSTRUCT_H_
/*****************************************************************************
* includes
*****************************************************************************/
#include "embtypes.h"
#include "bytequeue.h"
#include "bytestack.h"
/*****************************************************************************
* defines
*****************************************************************************/
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* C function prototypes
*****************************************************************************/
#endif

291
include/embtypes.h Normal file
View File

@ -0,0 +1,291 @@
/*****************************************************************************
* Copyright (C) 2008
* ProbeStar Telematics, LLC
* All Rights Reserved. Proprietary and Confidential.
*============================================================================
* Multiplatform Embedded Data Types and Conversion
* Checksum and CRC Routines
*****************************************************************************/
/* prevent multiple inclusions */
#ifndef _EMBTYPES_H_
#define _EMBTYPES_H_
/*****************************************************************************
* includes
*****************************************************************************/
#ifdef __linux__
#include <sys/types.h>
#endif
/*****************************************************************************
* defines
*****************************************************************************/
#ifndef NULL
#define NULL 0
#endif
#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif
#ifndef ON
#define ON 1
#define OFF 0
#endif
#ifdef __linux__
/* take out those keywords */
#define interrupt
#define near
#define far
#endif
/*****************************************************************************
* macros
*****************************************************************************/
/*****************************************************************************
* structs & typedefs
*****************************************************************************/
// data types
#ifdef __linux__
typedef unsigned char bit;
#else
typedef bit BOOL;
#endif
// ProbeStar Standard
typedef signed char CHAR;
typedef signed short SHORT;
typedef signed int INT;
typedef signed long LONG;
typedef signed long long LLONG;
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned int UINT;
typedef unsigned long DWORD;
typedef unsigned long long QWORD;
typedef signed char int8;
typedef signed short int16;
typedef signed long int32;
typedef signed long long int64;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned long uint32;
typedef unsigned long long uint64;
typedef signed char S8;
typedef signed short S16;
typedef signed long S32;
typedef signed long long S64;
typedef unsigned char U8;
typedef unsigned short U16;
typedef unsigned long U32;
typedef unsigned long long U64;
#ifdef BIG_ENDIAN
typedef union
{
WORD w;
SHORT s;
struct
{
BYTE h;
BYTE l;
}
b;
BYTE c[2];
} __attribute__((__packed__)) short_word;
typedef union
{
DWORD dw;
LONG l;
struct
{
WORD h;
WORD l;
}
w;
short s[2];
struct
{
short_word h;
short_word l;
}
sw;
struct
{
BYTE hh;
BYTE hl;
BYTE lh;
BYTE ll;
}
b;
BYTE c[4];
} __attribute__((__packed__)) long_dword;
typedef union
{
QWORD qw;
LLONG ll;
struct
{
DWORD h;
DWORD l;
} dw;
long l[2];
struct
{
WORD hh;
WORD hl;
WORD lh;
WORD ll;
}
w;
short s[4];
struct
{
short_word hh;
short_word hl;
short_word lh;
short_word ll;
}
sw;
struct
{
BYTE hhh;
BYTE hhl;
BYTE hlh;
BYTE hll;
BYTE lhh;
BYTE lhl;
BYTE llh;
BYTE lll;
}
b;
BYTE c[8];
} __attribute__((__packed__)) llong_qword;
#elif defined(LITTLE_ENDIAN)
// new
typedef union
{
WORD w;
SHORT s;
struct
{
BYTE l;
BYTE h;
}
b;
BYTE c[2];
} __attribute__((__packed__)) short_word;
typedef union
{
DWORD dw;
LONG l;
struct
{
WORD l;
WORD h;
}
w;
short s[2];
struct
{
short_word l;
short_word h;
}
sw;
struct
{
BYTE ll;
BYTE lh;
BYTE hl;
BYTE hh;
}
b;
BYTE c[4];
} __attribute__((__packed__)) long dword;
typedef union
{
QWORD qw;
LLONG ll;
struct
{
DWORD l;
DWORD h;
} dw;
long l[2];
struct
{
WORD ll;
WORD lh;
WORD hl;
WORD hh;
}
w;
short s[4];
struct
{
short_word ll;
short_word lh;
short_word hl;
short_word hh;
}
sw;
struct
{
BYTE lll;
BYTE llh;
BYTE lhl;
BYTE lhh;
BYTE hll;
BYTE hlh;
BYTE hhl;
BYTE hhh;
}
b;
BYTE c[8];
} __attribute__((__packed__)) llong_qword;
#endif
typedef union
{
BYTE byte;
struct {
unsigned b0:1;
unsigned b1:1;
unsigned b2:1;
unsigned b3:1;
unsigned b4:1;
unsigned b5:1;
unsigned b6:1;
unsigned b7:1;
} bits;
} byte_bits;
/*****************************************************************************
* global constants
*****************************************************************************/
/*****************************************************************************
* global variables
*****************************************************************************/
/*****************************************************************************
* C function prototypes
*****************************************************************************/
#endif

View File

@ -0,0 +1,63 @@
//****************************************************************************
// Copyright (C) 2007
// Nissan North America
// All Rights Reserved. Proprietary and Confidential.
//============================================================================
/* prevent multiple inclusions */
#ifndef __CanDatabase__
#define __CanDatabase__
/* includes *****************************************************************/
#include <sys/types.h>
#include <vector>
#include "CanSignal.h"
#include "CanSocket.h"
#include "DbcParser.h"
/* defines ******************************************************************/
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
/* c class definitions ******************************************************/
/**
* CAN class to handle database of CAN signals from DBC (.dbc) file
*/
class CanDatabase : public DbcParser {
// public data
public:
// private data
private:
// static data
// public methods
public:
// constructors
CanDatabase();
// destructor
virtual ~CanDatabase();
// virtual functions
// public methods
int FormatHeader( char *buf, int max );
int FormatMessage( char *buf, int max );
int SubscribeCan( CanSocket *pCan );
int ReadCan( CanSocket *pCan );
// static methods
// private methods
private:
};
#endif

View File

@ -0,0 +1,74 @@
//****************************************************************************
// Copyright (C) 2007
// Nissan North America
// All Rights Reserved. Proprietary and Confidential.
//============================================================================
/* prevent multiple inclusions */
#ifndef __CanMessage__
#define __CanMessage__
/* includes *****************************************************************/
#include <sys/types.h>
#include <string>
#include <vector>
#include "CanSignal.h"
#include "CanSocket.h"
/* defines ******************************************************************/
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
// based on .dbc data
/* c class definitions ******************************************************/
//
// Uses the Peak Systems CAN Linux driver and Nissan CAN data
//
class CanMessage {
// public data
public:
std::string Name; // Signal Name
std::string Module; // Module Name
u_int32_t Address; // 29 bits (standard or extended)
u_int8_t Data[64]; // Data
u_int Size; // DLC (CAN-FD > 8)
// list of signals in the message
std::vector<CanSignal *> Signals;
// private data
private:
// static data
// public methods
public:
// constructors
CanMessage();
// destructor
virtual ~CanMessage();
// virtual functions
// public methods
int Read(CanFrame *frame);
int Write(CanFrame *frame);
int Convert(CanFrame *frame) {return Read(frame);};
int Subscribe(void);
int Unsubscribe(void);
// static methods
// private methods
private:
};
#endif

View File

@ -0,0 +1,116 @@
//****************************************************************************
// Copyright (C) 2007
// Nissan North America
// All Rights Reserved. Proprietary and Confidential.
//============================================================================
/* prevent multiple inclusions */
#ifndef __CanSignal__
#define __CanSignal__
/* includes *****************************************************************/
#include <sys/types.h>
#include <string>
#include <vector>
//#include "BaseSignal.h"
//#include "VoltType.h"
#include "CanSocket.h"
/* defines ******************************************************************/
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
// based on .dbc data
/* c class definitions ******************************************************/
//
// Uses the Peak Systems CAN Linux driver and Nissan CAN data
//
#ifdef __BaseSignal__
class CanSignal : public BaseSignal, public VoltType {
#else
class CanSignal {
#endif
// public data
public:
std::string Name; // Signal Name
std::string Units; // Signal Units
u_int32_t Address; // 29 bits (standard or extended)
// data conversion (from .dbc file)
u_char StartBit; // 0..63
u_char NumBits; // 1..32
u_char BigEndian; // 0 = little endian (intel), 1 = big endian (moto)
u_char IsSigned; // 0 = unsigned, 1 = 2's Complement
double Scale; // scale
double Offset; // offset
// conversion help
u_char StartByte; // 0..7
u_char NumBytes; // 1..4
u_char HighBit; // 0..7
u_char LowBit; // #bits after
u_int64_t Mask; // 64 bit mask
u_int64_t Sign; // 64 bit sign mask
// status, data
u_char doSubscribe; // CanSocket filter
u_char isNew;
u_char isValid;
int32_t rawValue;
int64_t currValue;
int64_t lastValue;
double realValue;
// misc
u_int64_t activity; // activity counter
void *userData; // user data
int userIndex; // user index
// private data
private:
// static data
// public methods
public:
// constructors
CanSignal();
// destructor
virtual ~CanSignal();
// virtual functions
// public methods
int Init( void );
int Convert(CanFrame *frame) {return Read(frame->data);};
int Read(CanFrame *frame) {return Read(frame->data);};
int Read(const u_char *pbyData, long *ldata=NULL, double *ddata=NULL);
int Write(CanFrame *frame) {return Write(frame->data);};
int Write(u_char *pbyData);
int Write(long value, u_char *pbyData);
long Write(double value, u_char *pbyData);
void Subscribe(void) {doSubscribe=1;};
void Unsubscribe(void) {doSubscribe=0;};
#ifndef __VoltType__
void SetScaling( double scale=1.0, double offset=0.0 ) { Scale=scale; Offset=offset; };
double GetScale( void ) { return Scale; };
double GetOffset( void ) { return Offset; };
#endif
// static methods
// private methods
private:
};
#endif

View File

@ -0,0 +1,101 @@
//****************************************************************************
// Copyright (C) 2007
// Nissan North America
// All Rights Reserved. Proprietary and Confidential.
//============================================================================
/* prevent multiple inclusions */
#ifndef __CanSocket__
#define __CanSocket__
/* includes *****************************************************************/
#include <vector>
#include "netlib.h"
#include <linux/can.h>
#include <linux/can/raw.h>
#include <linux/can/bcm.h>
/* defines ******************************************************************/
#define CAN_MAX_FILTER 31
#define CAN_MAX_ADDRESSES 256
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
typedef struct can_filter CanFilter;
typedef struct can_frame CanFrame;
typedef struct _BcmFrame {
struct bcm_msg_head head;
struct can_frame frame;
} BcmFrame;
/* c class definitions ******************************************************/
//
// Uses the Peak Systems CAN Linux driver and Nissan CAN data
//
class CanSocket {
// public data
public:
int m_sock;
int m_proto;
// private data
private:
// device
int m_flags;
// errors
bool m_logerrs;
long m_errcount;
// static data
// public methods
public:
// constructors
CanSocket();
// destructor
virtual ~CanSocket();
// virtual functions
// public methods
void AddrFlags( u_long f ) { m_flags = f; };
int GetSock(void) {return m_sock;};
int GetSocket(void) {return m_sock;};
int GetProto(void) {return m_proto;};
int CanOpen( const char *dev="can0", int proto=CAN_RAW, int flags=0 );
void CanClose(void);
// misc
int ClearFilters( void );
int Blocking(bool block=true);
int NonBlocking(void) { return Blocking(false); };
int Loopback(bool loop=true);
int NoLoopback(void) { return Loopback(false); };
void LogErrors(bool logerrs=true) {m_logerrs = logerrs;};
// rx filter
int CanAddRx( u_int32_t addr );
int CanAddRx( const CanFilter *filter, int max=1 );
int CanDelRx( u_int32_t addr );
// raw
int CanRawRead( CanFrame *buf, int max=1 );
int CanRawWrite( const CanFrame *buf, int max=1 );
// bcm
int CanBcmRead( BcmFrame *msg, int max=1 );
int CanBcmWrite( BcmFrame *msg, int max=1 );
};
#endif

View File

@ -0,0 +1,87 @@
//****************************************************************************
// Copyright (C) 2007
// Nissan North America
// All Rights Reserved. Proprietary and Confidential.
//============================================================================
/* prevent multiple inclusions */
#ifndef __DbcParser__
#define __DbcParser__
/* includes *****************************************************************/
#include <regex.h>
#include <vector>
#include "CanMessage.h"
#include "CanSignal.h"
/* defines ******************************************************************/
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
// based on .dbc data
typedef struct _DbcFilter {
// signal information
char Name[32]; // Signal name
regex_t preg;
// address range
u_int32_t CanAddrLo; // 29 bits
u_int32_t CanAddrHi;
// data conversion
u_char StartBit; // 0..63
u_char NumBits; // 1..32
int found;
} DbcFilter;
/* c class definitions ******************************************************/
//
// Uses the Peak Systems CAN Linux driver and Nissan CAN data
//
class DbcParser {
// public data
public:
std::vector<DbcFilter *> MsgFilters; // message filter
std::vector<DbcFilter *> SigFilters; // signal filter
std::vector<CanMessage *> Messages;
std::vector<CanSignal *> Signals;
// private data
private:
// static data
// private methods
DbcFilter *AddFilter( char *name, u_int32_t addr1, u_int32_t addr2 );
// public methods
public:
// constructors
DbcParser();
// destructor
virtual ~DbcParser();
// virtual functions
// public methods
int AddMsgFilter( char *name, u_int32_t addr1, u_int32_t addr2 );
int AddSigFilter( char *name, u_int32_t addr1, u_int32_t addr2 );
int AddMessage( char *name, u_int32_t addr, u_int32_t size, char *module );
int AddSignal( char *name, char *units, u_int32_t addr, char start, char num, char endian, char sign, float scale, float offset );
int LoadDatabase( const char *file );
// static methods
// private methods
private:
};
#endif

View File

@ -0,0 +1,62 @@
//
// Linux GPS
//
/* prevent multiple inclusions */
#ifndef __ApplanixParser__
#define __ApplanixParser__
/* includes *****************************************************************/
#include <vector>
#include "netlib.h"
#include "GpsListener.h"
#include "GpsParser.h"
#include "NmeaParser.h"
#include "NmeaProtocol.h"
//#include "ApplanixProtocol.h"
/* defines ******************************************************************/
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
/* c class definitions ******************************************************/
//
class ApplanixParser : public NmeaParser {
// public data
public:
// protected data
protected:
// private data
private:
// data
u_char state; // parser state
// private methods
// public methods
public:
// constructors
ApplanixParser();
// destructor
virtual ~ApplanixParser();
// virtual functions
int GpsDecode( const char *buf, int max ) { return ApplanixDecode( (const u_char *)buf, max); };
int GpsParse( const char *buf, int max ) { return ApplanixParse( buf, max ); };
// public methods
int ApplanixDecode( const u_char *buf, int max );
int ApplanixParse( const char *buf, int max );
};
#endif

View File

@ -0,0 +1,56 @@
//
// Linux GPS
//
/* prevent multiple inclusions */
#ifndef __DgpsClient__
#define __DgpsClient__
/* includes *****************************************************************/
#include "TcpClient.h"
#include "netlib.h"
/* defines ******************************************************************/
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
/* c class definitions ******************************************************/
class DgpsClient : public TcpClient {
// public data
public:
// protected data
protected:
// private data
private:
unsigned long count;
// private methods
// static data
// public methods
public:
// constructors
DgpsClient();
// destructor
virtual ~DgpsClient();
// virtual functions
// public methods
int DgpsConnect( const char *host, const char *service );
void DgpsClose(void) {Close();};
int DgpsRead( char *buf, int max );
int DgpsWrite( const char *buf, int max );
};
#endif

View File

@ -0,0 +1,73 @@
//
// Linux GPS
//
/* prevent multiple inclusions */
#ifndef __FastraxParser__
#define __FastraxParser__
/* includes *****************************************************************/
#include <vector>
#include "netlib.h"
#include "GpsListener.h"
#include "GpsParser.h"
#include "NmeaParser.h"
#include "NmeaProtocol.h"
/* defines ******************************************************************/
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
/* c class definitions ******************************************************/
// Fastrax iTrax03
class NmeaSentencePFST : public NmeaSentence {
public:
char msg[4];
NmeaSentencePFST();
~NmeaSentencePFST();
int Decode( int argc, char *argv[] );
void Update( GpsPoint &PosData, ErrorInfo &ErrInfo, SatelliteInfo &SatInfo );
};
class FastraxParser : public NmeaParser {
// public data
public:
// protected data
protected:
// Fastrax iTrax03
NmeaSentencePFST PFST;
// private data
private:
// data
// private methods
// public methods
public:
// constructors
FastraxParser();
// destructor
virtual ~FastraxParser();
// virtual functions
int GpsDecode( const char *buf, int max ) { return FastraxDecode( (const u_char *)buf, max); };
int GpsParse( const char *buf, int max ) { return FastraxParse( buf, max ); };
// public methods
int FastraxDecode( const u_char *buf, int max );
int FastraxParse( const char *buf, int max );
};
#endif

View File

@ -0,0 +1,125 @@
//
// Linux GPS
//
/* prevent multiple inclusions */
#ifndef __GarminParser__
#define __GarminParser__
/* includes *****************************************************************/
#include <vector>
#include "netlib.h"
#include "GpsListener.h"
#include "GpsParser.h"
#include "NmeaParser.h"
#include "NmeaProtocol.h"
/* defines ******************************************************************/
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
/* c class definitions ******************************************************/
// Garmin
class NmeaSentencePGRME : public NmeaSentence {
public:
float horizontal;
char horizontal_unit[4];
float vertical;
char vertical_unit[4];
float three_dimensions;
char three_dimensions_unit[4];
NmeaSentencePGRME();
~NmeaSentencePGRME();
int Decode( int argc, char *argv[] );
void Update( GpsPoint &PosData, ErrorInfo &ErrInfo, SatelliteInfo &SatInfo );
};
class NmeaSentencePGRMF : public NmeaSentence {
public:
int week;
int seconds;
struct timespec utctime;
int leap;
double latitude;
double longitude;
char mode;
int type;
double speed;
double course;
double position_dilution;
double time_dilution;
NmeaSentencePGRMF();
~NmeaSentencePGRMF();
int Decode( int argc, char *argv[] );
void Update( GpsPoint &PosData, ErrorInfo &ErrInfo, SatelliteInfo &SatInfo );
};
class NmeaSentencePGRMM : public NmeaSentence {
public:
char datum[256];
NmeaSentencePGRMM();
~NmeaSentencePGRMM();
int Decode( int argc, char *argv[] );
void Update( GpsPoint &PosData, ErrorInfo &ErrInfo, SatelliteInfo &SatInfo );
};
class NmeaSentencePGRMZ : public NmeaSentence {
public:
NmeaSentencePGRMZ();
~NmeaSentencePGRMZ();
int Decode( int argc, char *argv[] );
void Update( GpsPoint &PosData, ErrorInfo &ErrInfo, SatelliteInfo &SatInfo );
};
// main class
class GarminParser : public NmeaParser {
// public data
public:
// protected data
protected:
// Garmin
NmeaSentencePGRME PGRME;
NmeaSentencePGRMF PGRMF;
NmeaSentencePGRMM PGRMM;
// private data
private:
// data
// private methods
// public methods
public:
// constructors
GarminParser();
// destructor
virtual ~GarminParser();
// virtual functions
int GpsDecode( const char *buf, int max ) { return GarminDecode( (const u_char *)buf, max); };
int GpsParse( const char *buf, int max ) { return GarminParse( buf, max ); };
// public methods
int GarminDecode( const u_char *buf, int max );
int GarminParse( const char *buf, int max );
};
#endif

View File

@ -0,0 +1,52 @@
//
// Linux GPS
//
/* prevent multiple inclusions */
#ifndef __GpsDevice__
#define __GpsDevice__
/* includes *****************************************************************/
#include "netlib.h"
#include "SerialIO.h"
/* defines ******************************************************************/
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
/* c class definitions ******************************************************/
class GpsDevice : public SerialIO {
// public data
public:
// parser
// protected data
protected:
// private data
private:
// private methods
// public methods
public:
// constructors
GpsDevice();
// destructor
virtual ~GpsDevice();
// virtual functions
// public methods
int GpsOpen( const char *dev, int baud=38400 );
int GpsRead( char *buf, int max ) {return Read(buf,max); };
int GpsWrite( const char *buf, int max ) {return Write(buf,max); };
void GpsClose(void) { Close(); };
};
#endif

View File

@ -0,0 +1,95 @@
//
// Linux GPS
//
/* prevent multiple inclusions */
#ifndef __GpsListener__
#define __GpsListener__
/* includes *****************************************************************/
#include <vector>
#include "netlib.h"
#include "GpsPoint.h"
/* defines ******************************************************************/
#define NMEA_MAX_SATELLITE 32
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
typedef struct _ErrorInfo {
// GPGSA dilution of precision (DOP)
double PositionDilution; // PDOP
double HorizontalDilution; // HDOP
double VerticalDilution; // VDOP
// GPGST standard deviation of error
double HorizontalDeviation; // largest
double VerticalDeviation;
// PUBX-01
double HorizontalAccuracy;
double VerticalAccuracy;
double TimeDilution; // TDOP
} ErrorInfo;
typedef struct _SatelliteInfo {
// GPGSV, PUBX-03
u_int Satellites;
struct {
char Id;
char Status;
double Elevation;
double Azimuth;
double Signal2noise;
} Satellite[NMEA_MAX_SATELLITE];
} SatelliteInfo;
/* c class definitions ******************************************************/
//
class GpsListener {
// public data
public:
// Position Data
GpsPoint PosData;
// Accuracy, Dilution, Error
ErrorInfo ErrInfo;
// Satellite info
SatelliteInfo SatInfo;
// protected data
protected:
// private data
private:
// private methods
// static data
// public methods
public:
// constructors
GpsListener();
// destructor
virtual ~GpsListener();
// virtual functions
virtual void PositionListener( const GpsPoint &Pos, const ErrorInfo &Err );
virtual void TimeListener( const struct timespec &Time );
// public methods
int GpsTime( struct timespec *tv ) {*tv=PosData.TimeStamp;return PosData.Fix;};
int GpsFix(void) {return PosData.Fix;};
};
#endif

View File

@ -0,0 +1,81 @@
//
// Linux GPS
//
/* prevent multiple inclusions */
#ifndef __GpsMath__
#define __GpsMath__
/* includes *****************************************************************/
#include <math.h>
#include <stdint.h>
#include "netlib.h"
/* defines ******************************************************************/
// degrees <-> radians
#define DEG2RAD(X) ((X)*M_PI/180.0)
#define RAD2DEG(X) ((X)*180.0/M_PI)
// (nautical mile to km) to meters per degree
#define MPERDEG (111.13285*1000.0)
#define EARTHRADIUS 6378100.0 // meters
// speed conversions
#define KNOTS_KPH 1.85200
#define KNOTS_METERSPERSEC (KNOTS_KPH*1000.0/3600.0)
#define KPH2MSEC(X) ((X)*0.277777778)
#define MSEC2KPH(X) ((X)/0.277777778)
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
/* c class definitions ******************************************************/
//
// GpsLinux because it depennds on GPSd, the HAMLIB and NMEAP libraries
//
class GpsMath {
// public data
public:
// parser
// protected data
protected:
// private data
private:
// static data
// private methods
// public methods
public:
// constructors
GpsMath();
// destructor
virtual ~GpsMath();
// virtual functions
// public methods
// static methods
static double Minutes2Degrees(char *value, char *side = NULL);
static void Degrees2Minutes(double deg, char *buf, int max, bool lat);
static timespec String2Time(const char *hhmmss, const char *ddmmyy);
static double Bearing( double lat1, double lon1, double lat2, double lon2 );
static double Distance( double lat1, double lon1, double lat2, double lon2 );
static double DistanceX( double lat1, double lon1, double lat2, double lon2 );
static double DistanceY( double lat1, double lon1, double lat2, double lon2 );
static double DistanceXY(double lat1, double lon1, double lat2, double lon2, double &x, double &y );
static double Travel( double *lat, double *lon, double *ele, double x, double y, double z);
};
#endif

View File

@ -0,0 +1,93 @@
//
// Linux GPS
//
//
/* prevent multiple inclusions */
#ifndef __GpsParser__
#define __GpsParser__
/* includes *****************************************************************/
#include <vector>
#include "netlib.h"
#include "GpsListener.h"
#include "NmeaProtocol.h"
/* defines ******************************************************************/
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
/* c class definitions ******************************************************/
//
class GpsParser : public NmeaProtocol {
// public data
public:
char Vendor[32];
char Product[32];
// Position Data
GpsPoint PosData;
// Accuracy, Dilution, Error
ErrorInfo ErrInfo;
// Satellite info
SatelliteInfo SatInfo;
protected:
// protected data
std::vector<GpsListener *> GpsListeners;
// incoming data buffer
u_char data[2048];
u_char lastc;
u_short numbytes; // current byte count
u_short totbytes; // expect byte count
u_short checksum;
u_long counter; // # parsed
// private data
private:
// private methods
// static data
// public methods
public:
// constructors
GpsParser();
// destructor
virtual ~GpsParser();
// virtual functions
virtual void GpsInit( void ) {};
virtual int GpsDecode( const char *buf, int max );
virtual int GpsParse( const char *buf, int max );
// public methods
// subscribe/unsubscribe
void Subscribe( GpsListener *ear ) {
GpsInit();
if (ear)
GpsListeners.push_back(ear);
};
int GetNumParsed(void) {return counter;};
// misc
int GpsTime( struct timespec *tv ) {*tv=PosData.TimeStamp;return PosData.Fix;};
int GpsFix(void) {return PosData.Fix;};
int Gps2Vii( char *buf, int max );
// static functions
};
#endif

123
include/libgps++/GpsPoint.h Normal file
View File

@ -0,0 +1,123 @@
//
// Linux GPS
//
/* prevent multiple inclusions */
#ifndef __GpsPoint__
#define __GpsPoint__
/* includes *****************************************************************/
#include "GpsMath.h"
/* defines ******************************************************************/
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
/* c class definitions ******************************************************/
//
// Gps Point on the planet
//
class GpsPoint : public GpsMath {
// public data
public:
timespec TimeStamp;
double Latitude;
double Longitude;
double Altitude;
double Speed; // m/sec
double Heading; // deg
// fix information (GpsListener) for point
int Fix; // GPGGA
int Mode; // GPGSA
int Type; // GPGSA
double Accel; // m/sec2
double Yaw; // deg/sec (-left, +right)
// parser
// protected data
protected:
// private data
private:
// static data
// private methods
// public methods
public:
// constructors
GpsPoint();
GpsPoint( double lat, double lon );
GpsPoint(const GpsPoint &copy);
// destructor
virtual ~GpsPoint();
// operators
GpsPoint &operator=(const GpsPoint &rhs);
// virtual functions
// public methods
double GetLatitude(void) {return Latitude;};
double GetLongitude(void) {return Longitude;};
double GetAltitude(void) {return Altitude;};
double GetElevation(void) {return Altitude;};
void GetPosition( double *lat, double *lon, double *elev=NULL );
double GetSpeed(void) {return Speed;};
double GetHeading(void) {return Heading;};
timespec GetTimeVal(void) {return TimeStamp;};
uint64_t GetTimeStamp(void) {return (TimeStamp.tv_sec*1000L)+(TimeStamp.tv_nsec/1000000L);};
time_t GetTimeStampSec(void) {return TimeStamp.tv_sec;};
void SetLatitude(double lat) {Latitude = lat;};
void SetLongitude(double lon) {Longitude = lon;};
void SetAltitude(double alt) {Altitude = alt;};
void SetElevation(double ele) {Altitude = ele;};
void SetPosition(double lat, double lon, double ele = 0.0)
{Latitude=lat;Longitude=lon;Altitude=ele;};
void SetSpeed(double spd) {Speed = spd;}; // kph
void SetHeading(double hdg) {Heading = hdg;};
void SetTimeStamp(timespec &tv) {TimeStamp=tv;};
void SetTimeStamp(time_t t) {TimeStamp.tv_sec=t;TimeStamp.tv_nsec=0;};
void SetTimeStamp(uint64_t t);
void SetTimeStamp(double t);
void SetTimeStamp(const char *str);
void AddMeters( double x, double y ); // add meters
void Extrapolate( double speed, double accel, double yaw, double time );
double Bearing( const GpsPoint &gpt ); // bearing to point
double Distance( const GpsPoint &gpt ); // distance to point
double Distance( double lat, double lon );
double Travel( double x, double y, double z );
double DistanceX( const GpsPoint &gpt )
{ return GpsMath::DistanceX(Latitude, Longitude, gpt.Latitude, gpt.Longitude); };
double DistanceY( const GpsPoint &gpt )
{ return GpsMath::DistanceY(Latitude, Longitude, gpt.Latitude, gpt.Longitude); };
double DistanceX(double lat, double lon)
{ return GpsMath::DistanceX(Latitude, Longitude, Latitude, lon); };
double DistanceY(double lat, double lon)
{ return GpsMath::DistanceY(Latitude, Longitude, lat, Longitude); };
double DistanceX(double lon)
{ return GpsMath::DistanceX(Latitude, Longitude, Latitude, lon); };
double DistanceY(double lat)
{ return GpsMath::DistanceY(Latitude, Longitude, lat, Longitude); };
double DistanceXY( const GpsPoint &gpt1, const GpsPoint &gpt2, double &x, double &y );
double DistanceXY( const GpsPoint &gpt1, double lat, double lon, double &x, double &y );
bool Inside( const GpsPoint polygon[], int num );
bool Traversed( GpsPoint &gpt, const GpsPoint polygon[], int num );
// static methods
};
#endif

View File

@ -0,0 +1,70 @@
//
// Linux GPS
//
/* prevent multiple inclusions */
#ifndef __GpsTrack__
#define __GpsTrack__
/* includes *****************************************************************/
#include <vector>
#include "GpsPoint.h"
/* defines ******************************************************************/
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
typedef std::vector<GpsPoint> GpsTrack_t;
/* c class definitions ******************************************************/
//
// GpsLinux because it depennds on GPSd, the HAMLIB and NMEAP libraries
//
class GpsTrack {
// public data
public:
char Name[64];
GpsTrack_t Points;
// parser
// protected data
protected:
// private data
private:
// static data
// private methods
// public methods
public:
// constructors
GpsTrack();
GpsTrack(const char *name);
GpsTrack(const GpsTrack &copy);
// destructor
virtual ~GpsTrack();
// operators
GpsTrack &operator=(const GpsTrack &rhs);
// virtual functions
// public methods
void SetName( const char *name ) { strncpy(Name,name,sizeof(Name)-1); };
int AddPoint( const GpsPoint &Pt );
int GenerateKML( const char *kmlfile );
int ParseKML( const char *kmlfile );
// static methods
};
#endif

View File

@ -0,0 +1,70 @@
//
// Linux GPS
//
/* prevent multiple inclusions */
#ifndef __GpsdClient__
#define __GpsdClient__
/* includes *****************************************************************/
#include "TcpClient.h"
#include "netlib.h"
/* defines ******************************************************************/
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
/* c class definitions ******************************************************/
//
// Connect to http://gpsd.berlios.de/ GPSD
//
class GpsdClient : public TcpClient {
// public data
public:
int Fix;
int Satellites;
struct timespec Time;
double Latitude;
double Longitude;
double Elevation;
double Heading;
double Speed;
// protected data
protected:
// private data
private:
// static data
// private methods
// public methods
public:
// constructors
GpsdClient();
GpsdClient( const char *host );
// destructor
virtual ~GpsdClient();
// virtual functions
// public methods
int GpsdParse( char *msg );
int GpsdConnect( const char *host = "localhost" );
int GpsdRead( void );
int GpsdWrite( const char *msg, int max );
int Gpsd2Vii( char *buf, int max );
};
#endif

View File

@ -0,0 +1,73 @@
//
// Linux GPS
//
/* prevent multiple inclusions */
#ifndef __KmlFile__
#define __KmlFile__
/* includes *****************************************************************/
#include <libxml/parser.h>
#include <libxml/tree.h>
#include "netlib.h"
#include "GpsTrack.h"
/* defines ******************************************************************/
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
/* c class definitions ******************************************************/
//
// GpsLinux because it depennds on GPSd, the HAMLIB and NMEAP libraries
//
class KmlFile {
// public data
public:
xmlDocPtr xmlDoc;
xmlNodePtr xmlRoot;
// folders we're interested in
xmlNodePtr xmlRoutes;
xmlNodePtr xmlTracks;
xmlNodePtr xmlWaypoints;
// parser
// protected data
protected:
FILE *fileKml;
// private data
private:
// static data
// private methods
// public methods
public:
// constructors
KmlFile();
// destructor
virtual ~KmlFile();
// virtual functions
// public methods
int Open( const char *file );
void Close( void );
int Create( const char *file );
GpsTrack *GetTracks(void);
// static methods
static time_t ParseTime( const char *time );
};
#endif

View File

@ -0,0 +1,86 @@
//
// Linux GPS
//
// NMEA Parser code stolen from Pascal Martin's RoadMap
//
/* prevent multiple inclusions */
#ifndef __NmeaParser__
#define __NmeaParser__
/* includes *****************************************************************/
#include <vector>
#include "netlib.h"
#include "GpsListener.h"
#include "GpsParser.h"
#include "NmeaProtocol.h"
#include "NmeaSentence.h"
/* defines ******************************************************************/
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
/* c class definitions ******************************************************/
//
class NmeaParser : public GpsParser {
// public data
public:
protected:
// private data
std::vector<NmeaSentence *> NmeaSentences;
// Standard
NmeaSentenceGPRMC GPRMC;
NmeaSentenceGPVTG GPVTG;
NmeaSentenceGPGGA GPGGA;
NmeaSentenceGPGSA GPGSA;
NmeaSentenceGPGSV GPGSV;
NmeaSentenceGPGLL GPGLL;
NmeaSentenceGPGST GPGST;
NmeaSentenceGPZDA GPZDA;
// private data
private:
// incoming data buffer
// NMEA record for notification
char posfixnmea[8];
char timefixnmea[8];
// private methods
// static data
// public methods
public:
// constructors
NmeaParser();
// destructor
virtual ~NmeaParser();
// virtual functions
int GpsDecode( const char *buf, int max ) { return NmeaDecode( buf, max ); };
int GpsParse( const char *buf, int max ) { return NmeaParse( buf, max ); };
// public methods
int NmeaDecode( const char *msg, int max );
int NmeaParse( const char *msg, int max );
// misc
void NmeaPosFix( const char *str )
{ strncpy(posfixnmea,str,sizeof(posfixnmea)-1);};
// static functions
static int CsvSplit( char *buf, char *field[], int max );
};
#endif

View File

@ -0,0 +1,50 @@
//
// Linux GPS
//
/* prevent multiple inclusions */
#ifndef __NmeaProtocol__
#define __NmeaProtocol__
/* includes *****************************************************************/
#include "netlib.h"
/* defines ******************************************************************/
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
/* c class definitions ******************************************************/
//
// GpsLinux because it depennds on GPSd, the HAMLIB and NMEAP libraries
//
class NmeaProtocol {
// public data
public:
// protected data
protected:
// private data
private:
// private methods
// public methods
public:
// constructors
NmeaProtocol();
// destructor
virtual ~NmeaProtocol();
// virtual functions
// public methods
static int NmeaChecksum( char *msg, int len, int max = 0 );
};
#endif

View File

@ -0,0 +1,197 @@
//
// Linux GPS
//
// NMEA Parser code stolen from Pascal Martin's RoadMap
//
/* prevent multiple inclusions */
#ifndef __NmeaSentence__
#define __NmeaSentence__
/* includes *****************************************************************/
#include <vector>
#include "GpsMath.h"
#include "GpsListener.h"
/* defines ******************************************************************/
#define NMEA_MAX_SATELLITE 32
#define NMEA_FIX_INVALID 0
#define NMEA_FIX_NOFIX 0
#define NMEA_FIX_GPS 1
#define NMEA_FIX_DGPS 2
#define NMEA_FIX_PPS 3
#define NMEA_FIX_RTK_FIXED 4
#define NMEA_FIX_RTK_FLOAT 5
#define NMEA_FIX_DEAD_RECKONING 6
#define NMEA_FIX_MANUAL 7
#define NMEA_FIX_SIMULATION 8
#define NMEA_MODE_AUTOMATIC 'A'
#define NMEA_MODE_DIFFERENTIAL 'D'
#define NMEA_MODE_ESTIMATED 'E' // dead reckoning
#define NMEA_MODE_MANUAL 'M'
#define NMEA_MODE_SIMULATED 'S'
#define NMEA_MODE_INVALID 'N'
#define NMEA_TYPE_INVALID 0
#define NMEA_TYPE_NOFIX 1
#define NMEA_TYPE_2D 2
#define NMEA_TYPE_3D 3
/* macros *******************************************************************/
#define DecodeCoordinate(A,B) GpsMath::Minutes2Degrees(A,B)
#define DecodeTime(A,B) GpsMath::String2Time(A,B)
/* structs & typedefs *******************************************************/
/* c class definitions ******************************************************/
class NmeaSentence {
public:
char name[8];
char argc;
char parsed; // just parsed flag
u_long counter;
timespec timestamp;
NmeaSentence();
virtual ~NmeaSentence();
virtual int Decode( int argc, char *argv[] );
virtual void Update( GpsPoint &PosData, ErrorInfo &ErrInfo, SatelliteInfo &SatInfo );
};
class NmeaSentenceGPGGA : public NmeaSentence {
public:
timespec fixtime;
double latitude; // decimal degrees
double longitude;
int quality;
int satellites;
float horizontal_dilution;
double altitude; // meters
double geoid;
NmeaSentenceGPGGA();
~NmeaSentenceGPGGA();
int Decode( int argc, char *argv[] );
void Update( GpsPoint &PosData, ErrorInfo &ErrInfo, SatelliteInfo &SatInfo );
};
class NmeaSentenceGPGLL : public NmeaSentence {
public:
double latitude;
double longitude;
timespec utctime;
char status;
char mode;
NmeaSentenceGPGLL();
~NmeaSentenceGPGLL();
int Decode( int argc, char *argv[] );
void Update( GpsPoint &PosData, ErrorInfo &ErrInfo, SatelliteInfo &SatInfo );
};
class NmeaSentenceGPGSA : public NmeaSentence {
public:
char mode;
char type;
char satellite[NMEA_MAX_SATELLITE];
float position_dilution;
float horizontal_dilution;
float vertical_dilution;
NmeaSentenceGPGSA();
~NmeaSentenceGPGSA();
int Decode( int argc, char *argv[] );
void Update( GpsPoint &PosData, ErrorInfo &ErrInfo, SatelliteInfo &SatInfo );
};
class NmeaSentenceGPGST : public NmeaSentence {
public:
timespec utctime;
// standard deviation of error
float rms_deviation;
float semimajor_deviation;
float semiminor_deviation;
float semimajor_orientation;
float latitude_deviation;
float longitude_deviation;
float altitude_deviation;
NmeaSentenceGPGST();
~NmeaSentenceGPGST();
int Decode( int argc, char *argv[] );
void Update( GpsPoint &PosData, ErrorInfo &ErrInfo, SatelliteInfo &SatInfo );
};
class NmeaSentenceGPGSV : public NmeaSentence {
public:
char total;
char sequence;
char satellites;
struct {
char id;
char elevation;
short azimuth;
short signal2noise;
} satellite[NMEA_MAX_SATELLITE];
NmeaSentenceGPGSV();
~NmeaSentenceGPGSV();
int Decode( int argc, char *argv[] );
void Update( GpsPoint &PosData, ErrorInfo &ErrInfo, SatelliteInfo &SatInfo );
};
class NmeaSentenceGPRMC : public NmeaSentence {
public:
timespec utctime;
char status;
double latitude;
double longitude;
double speed; // convert knots to kph
double course;
double variation;
NmeaSentenceGPRMC();
~NmeaSentenceGPRMC();
int Decode( int argc, char *argv[] );
void Update( GpsPoint &PosData, ErrorInfo &ErrInfo, SatelliteInfo &SatInfo );
};
class NmeaSentenceGPVTG : public NmeaSentence {
public:
double course;
double speed;
char mode;
NmeaSentenceGPVTG();
~NmeaSentenceGPVTG();
int Decode( int argc, char *argv[] );
void Update( GpsPoint &PosData, ErrorInfo &ErrInfo, SatelliteInfo &SatInfo );
};
class NmeaSentenceGPZDA : public NmeaSentence {
public:
timespec utctime;
NmeaSentenceGPZDA();
~NmeaSentenceGPZDA();
int Decode( int argc, char *argv[] );
void Update( GpsPoint &PosData, ErrorInfo &ErrInfo, SatelliteInfo &SatInfo );
};
#endif

View File

@ -0,0 +1,65 @@
//
// Linux GPS
//
/* prevent multiple inclusions */
#ifndef __NtripClient__
#define __NtripClient__
/* includes *****************************************************************/
#include "TcpClient.h"
#include "netlib.h"
/* defines ******************************************************************/
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
/* c class definitions ******************************************************/
//
// GpsLinux because it depennds on GPSd, the HAMLIB and NMEAP libraries
//
class NtripClient : public TcpClient {
// public data
public:
char Uri[1024];
protected:
unsigned long count;
// private data
private:
// private methods
// static data
// public methods
public:
// constructors
NtripClient();
// destructor
virtual ~NtripClient();
// virtual functions
// public methods
int NtripConnect( const char *host, const char *service,
const char *user = "anonymous", const char *pass = "",
const char *path = "" );
int NtripConnect( const char *uri );
int NtripReconnect( void ) {return NtripConnect( Uri ); };
void NtripClose(void) {Close();};
int NtripRead( unsigned char *buf, int max );
int NtripWrite( const unsigned char *buf, int max )
{return TcpClient::Send((const char *)buf,max);};
};
#endif

View File

@ -0,0 +1,62 @@
//
// Linux GPS
//
/* prevent multiple inclusions */
#ifndef __RtcmDevice__
#define __RtcmDevice__
/* includes *****************************************************************/
#include "TcpClient.h"
#include "netlib.h"
/* defines ******************************************************************/
/* macros *******************************************************************/
/* structs & typedefs *******************************************************/
/* c class definitions ******************************************************/
class RtcmDevice {
// public data
public:
// protected data
protected:
int SerialFd; // serial port
// private data
private:
// private methods
int SerialOpen( const char *dev, int baud );
int SerialRead( char *buf, int max );
void SerialClose( void );
// static data
// public methods
public:
// constructors
RtcmDevice();
// destructor
virtual ~RtcmDevice();
// virtual functions
// public methods
int GetFd(void) {return SerialFd;};
int RtcmOpen( const char *dev, int baud ) {return SerialOpen(dev,baud); };
void RtcmClose(void) {SerialClose();};
int RtcmRead( char *buf, int max );
int RtcmWrite( const char *buf, int max );
};
#endif

Some files were not shown because too many files have changed in this diff Show More