diff --git a/Makefile b/Makefile index d27262a..25ab2aa 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,28 @@ default: @echo @echo " WARNING: this Makefile is for the maintainer. See INSTALL" +# @echo " wikipedia - Open the wikipedia entry on ${PKG}" + +#PYFILES_ALL := ${shell ls *.py} +#PYFILES := ${shell ls *.py | grep -v version} + +.PHONY: variables +variables: + @echo ${PKG}-py version: ${VERSION} + @echo PYTHONPATH $$PYTHONPATH + @echo SHELL ${SHELL} +# @echo PYFILES_ALL ${PYFILES_ALL} +# @echo PYFILES ${PYFILES} + +.PHONY: wikipedia +wikipedia: + open http://en.wikipedia.org/wiki/Automatic_Identification_System + +.PHONY: help +help: + @echo This only works on Mac OSX + open html/index.html + .PHONY: clean clean: rm -f ${PKG}-py.info MANIFEST @@ -48,6 +70,25 @@ check: @echo pychecker ${PKG} find . -name \*.py | xargs egrep '@(todo|bug)' +# pylint +# pychecker ${PKG} scripts + +build: test + @echo + @echo Building locally... + @echo + (cd ais;make) + (cd ais/sls;make) + (cd ais/ris;make) + -find . -name \*.pyc | xargs rm + rm -f MANIFEST + ./setup.py build + +install-home: build + @echo + @echo Installing in home area... + @echo + ./setup.py install --prefix ${HOME} sdist: test @echo diff --git a/aisutils/binary.py b/aisutils/binary.py index c6b2d55..723c924 100755 --- a/aisutils/binary.py +++ b/aisutils/binary.py @@ -63,7 +63,7 @@ def float2bitvec(floatval): # FIX: make this go in one step now that bitvector 1.3 is out. bvList = [] for i in range(4): - bv1 = setBitVectorSize(BitVector(intVal=ord(s[i])),8) + bv1 = setBitVectorSize(BitVector(intVal=ord(s[i])),8) #bv2 = BitVector(intVal=ord(s[i]),size=8) bvList.append(bv1) return joinBV(bvList) diff --git a/aisutils/uscg.py b/aisutils/uscg.py index 5ddd9ca..54af408 100755 --- a/aisutils/uscg.py +++ b/aisutils/uscg.py @@ -192,7 +192,10 @@ def __init__(self,nmeaStr=None): pass continue if c == 'S': - self.slotNumber = int(f[1:]) + try: + self.slotNumber = int(f[1:]) + except: + self.slotNumber = None continue if c == 'x': # I don't know what x is diff --git a/init.d/logais b/init.d/logais index b5fe086..d2e3c0a 100755 --- a/init.d/logais +++ b/init.d/logais @@ -20,13 +20,14 @@ RUNASUSER=data DAEMON=/home/$RUNASUSER/bin/serial-logger PIDDIR=/var/run/data PIDFILE=$PIDDIR/logais.pid +UDPOUT=localhost:2000 test -x $DAEMON || echo "ERROR: can not find logger daemon: $DAEMON" test -x $DAEMON || exit 5 UGID=$(getent passwd $RUNASUSER | cut -f 3,4 -d:) || true -STATION=nhjel +STATION=nhcml SUBDIR=$STATION @@ -44,7 +45,7 @@ case $1 in fi # FIX: make this read through a list of loggers to run with parameters # How to control all of the loggers in batch or one at a time? - start-stop-daemon --start --quiet --oknodo --chdir /home/${RUNASUSER}/projects/data/${SUBDIR}/ais --pidfile $PIDFILE --startas $DAEMON -c $RUNASUSER -- --pid-file $PIDFILE -l ais- -p /dev/ttyS2 --daemon --enable-tcp-out --timeout=300 --uscg-format --station-id=${STATION} -m + start-stop-daemon --start --quiet --oknodo --chdir /home/${RUNASUSER}/ais --pidfile $PIDFILE --startas $DAEMON -c $RUNASUSER -- --pid-file $PIDFILE -l ais -p /dev/ttyS4 --daemon --enable-tcp-out --timeout=300 --uscg-format --station-id=${STATION} -m --udp ${UDPOUT} log_end_msg $? ;; stop) diff --git a/scripts/serial-logger2.py b/scripts/serial-logger2.py index f610ec5..1eee822 100755 --- a/scripts/serial-logger2.py +++ b/scripts/serial-logger2.py @@ -23,6 +23,7 @@ import logging from lockfile import LockFailed from logger_handlers import MidnightRotatingFileHandler, PassThroughServerHandler +import socket class SerialLoggerFormatter: def __init__(self, uscgFormat=True, mark=True, stationId=None): @@ -80,6 +81,16 @@ def run(options): ptsh.setFormatter(formatter) logger.addHandler(ptsh) + if options.udpTarget is not None and ':' in options.udpTarget: + uaddr,uport = options.udpTarget.split(':',1) + uport = int(uport) + uaddr = (uaddr,uport) + udpSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + udpSocket.connect(uaddr) + else: + udpSocket = None + + if not options.daemonMode: ch = logging.StreamHandler() ch.setFormatter(formatter) @@ -91,6 +102,12 @@ def run(options): # logger.info("hello") line = ser.readline().strip() logger.info(line) + if udpSocket is not None: + try: + udpSocket.send(line+'\r\n') + except: + pass + def parseOptions(): from optparse import OptionParser @@ -140,6 +157,9 @@ def parseOptions(): default=os.path.abspath(os.path.curdir), help='daemon working directory [default: %default]') + #################### UDP + parser.add_option('--udp', dest='udpTarget', type='string', default=None, help='Send to address:port via UDP.') + #################### pts parser.add_option('--enable-tcp-out', dest='tcpOutput', default=False, action='store_true', help='Create a server that clients can connect to and receive data')