From b86fe6f3fc550855c14cb6eba573db2ed4c0b523 Mon Sep 17 00:00:00 2001 From: Markus Birth Date: Tue, 9 Sep 2014 17:51:11 +0200 Subject: [PATCH] Initial commit --- IPTCMessage.py | 9 +++++++++ README.md | 28 +++++++++++++++++++++++++++ setbaud.sh | 3 +++ tty2newsml.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 91 insertions(+) create mode 100644 IPTCMessage.py create mode 100644 README.md create mode 100755 setbaud.sh create mode 100755 tty2newsml.py diff --git a/IPTCMessage.py b/IPTCMessage.py new file mode 100644 index 0000000..2918fec --- /dev/null +++ b/IPTCMessage.py @@ -0,0 +1,9 @@ +#!/bin/env python3 +# -*- coding: utf-8 -*- + +class IPTCMessage(object): + def __init__(self): + print("Hello world!") + +if __name__=='__main__': + print("Testmode!") diff --git a/README.md b/README.md new file mode 100644 index 0000000..5072839 --- /dev/null +++ b/README.md @@ -0,0 +1,28 @@ +tty2NewsML +========== + +Prerequisites +------------- + +* Python 3 +* PySerial + * `yum install python-setuptools` + * `easy_install pyserial` + * or `pip install pyserial` + + +Communication parameters: +* 4800 baud +* 8 data bits +* no parity +* 1 stop bit + +Format: [IPTC 7901](http://www.iptc.org/site/News_Exchange_Formats/IPTC_7901/Specification/) + +Priorities +---------- + +* 5 - Normal +* 4 - Dringend +* 3 - Vorrang +* 2 - Blitz/Eil diff --git a/setbaud.sh b/setbaud.sh new file mode 100755 index 0000000..e00f311 --- /dev/null +++ b/setbaud.sh @@ -0,0 +1,3 @@ +#!/bin/sh +# 4800 kbps 8N1 +stty -F /dev/tty701 4800 cs8 -parenb -cstopb diff --git a/tty2newsml.py b/tty2newsml.py new file mode 100755 index 0000000..de3dc0f --- /dev/null +++ b/tty2newsml.py @@ -0,0 +1,51 @@ +#!/bin/env python3 +# -*- coding: utf-8 -*- + +import serial +import IPTCMessage + +class _main(object): + def __init__(self, port='/dev/tty706'): + self.openPort(port) + while True: + msg = self.waitForStart() + msg += self.readUntilEOM() + print("This is the message: %s" % repr(msg)) + + def openPort(self, port): + self.port = serial.Serial(port, baudrate=4800, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, timeout=None) + print("%s opened with %i baud. Timeout is %s seconds." % (self.port.name, self.port.baudrate, self.port.timeout)) + + def waitForStart(self): + print("Waiting for start indicator: ", end='', flush=True) + while True: + byte = self.port.read() + print(".", end='', flush=True) + if byte == b'\x01': + print("Found.") + return byte + + def readUntilEOM(self): + print("Reading data until EOM.", end='', flush=True) + msg = b'' + ctr = 0 + while True: + byte = self.port.read() + ctr+=1 + if ctr % 10 is 0: + print(".", end='', flush=True) + if byte == b'\x01': + print("PROBLEM: Got start indicator, but message not yet finished.") + break + msg += byte + if byte == b'\x04': + break + print("Got %i bytes." % len(msg)) + return msg + + def readLine(self): + rcv = self.port.readline() + print("Got: %s" % repr(rcv)) + +if __name__=='__main__': + _main()