Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion aisutils/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion aisutils/uscg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions init.d/logais
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions scripts/serial-logger2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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')
Expand Down