Commit 606af06a authored by ZettaScript's avatar ZettaScript

Add tools

parent c8eabee5
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Copyright 2017-2018 Pascal Engélibert
Raspberry Pi - Minitel console
See datasheet:
http://pila.fr/content/interface_usb_minitel/specifications%20techniques%20d%27utilisation%20du%20minitel.pdf
"""
from sys import stdout, stdin, stderr
import tty, termios
import minitel_driver as minitel
fdin = stdin.fileno()
old_settings = termios.tcgetattr(fdin)
tty.setraw(fdin)
minitel.initSerial()
loop = True
while loop:
try:
for c in stdin.read(1):
if c == '\x03':
loop = False
break
minitel.sendbuf.databuf.append(ord(c))
except (UnicodeDecodeError, UnicodeEncodeError):
stderr.write("En mode tele-informatique, le Minitel ne supporte pas l'ASCII etendu.")
stderr.flush()
minitel.stop()
termios.tcsetattr(fdin, termios.TCSADRAIN, old_settings)
......@@ -10,7 +10,7 @@ http://pila.fr/content/interface_usb_minitel/specifications%20techniques%20d%27u
from time import sleep, time
from threading import Thread, RLock
import RPi.GPIO as gpio
from sys import stdout, stderr
from sys import stdout
FREQ = 1200# frequency (Hz)
PULSE = 1/FREQ# pulse duration (s)
......@@ -22,11 +22,16 @@ RX = 20# input pin (RPi in, Minitel out)
lock = RLock()
def writef(data):
stdout.write(data)
stdout.flush()
# outf: output function
class RecBuf(Thread):
def __init__(self):
def __init__(self, outf=writef):
Thread.__init__(self)
self.databuf = []
self.work = True
self.outf = outf
def run(self):
a = False
......@@ -60,9 +65,10 @@ class RecBuf(Thread):
c += [v] * round(n/6)
while len(c) >= 10 and c[0] == 0 and c[9] == 1:
if (c[1]+c[2]+c[3]+c[4]+c[5]+c[6]+c[7])&1 == c[8]:
stdout.write(chr(c[1]|(c[2]<<1)|(c[3]<<2)|(c[4]<<3)|(c[5]<<4)|(c[6]<<5)|(c[7]<<6)))
#stdout.write(chr(c[1]|(c[2]<<1)|(c[3]<<2)|(c[4]<<3)|(c[5]<<4)|(c[6]<<5)|(c[7]<<6)))
#stdout.write(hex(c[1]|(c[2]<<1)|(c[3]<<2)|(c[4]<<3)|(c[5]<<4)|(c[6]<<5)|(c[7]<<6))+" ")
stdout.flush()
#stdout.flush()
self.outf(chr(c[1]|(c[2]<<1)|(c[3]<<2)|(c[4]<<3)|(c[5]<<4)|(c[6]<<5)|(c[7]<<6)))
c = c[10:]
s = []
sleep(PULSE2)
......@@ -77,8 +83,8 @@ class SendBuf(Thread):
bytebuf = []
outgpio = gpio.output
tx_high = False
LOW = gpio.HIGH
HIGH = gpio.LOW
LOW = gpio.LOW
HIGH = gpio.HIGH
while self.work:
if len(bytebuf) > 0:
if bytebuf.pop(0):
......@@ -91,7 +97,8 @@ class SendBuf(Thread):
d = self.databuf.pop(0)
if d != -1:
#bytebuf = [1,d&0x40,d&0x20,d&0x10,d&0x08,d&0x04,d&0x02,d&0x01, ((d&0x40)+(d&0x20)+(d&0x10)+(d&0x08)+(d&0x04)+(d&0x02)+(d&0x01))&1]
bytebuf = [0, d&0x01,d&0x02,d&0x04,d&0x08,d&0x10,d&0x20,d&0x40, ((d&0x40)+(d&0x20)+(d&0x10)+(d&0x08)+(d&0x04)+(d&0x02)+(d&0x01))&1,1]
#bytebuf = [0, d&0x01,d&0x02,d&0x04,d&0x08,d&0x10,d&0x20,d&0x40, ((d&0x40)+(d&0x20)+(d&0x10)+(d&0x08)+(d&0x04)+(d&0x02)+(d&0x01))&1,1]
bytebuf = [0, d&0x01,d&0x02,d&0x04,d&0x08,d&0x10,d&0x20,d&0x40, 1]
#sleep(PULSE/2)
#if tx_high:
# outgpio(TX, LOW)
......@@ -107,7 +114,8 @@ sendbuf = SendBuf()
recbuf = RecBuf()
# Init GPIO and start the com thread
def initSerial():
def initSerial(outf=writef):
recbuf.outf = outf
gpio.setwarnings(False)
gpio.setmode(gpio.BCM)
gpio.setup(TX, gpio.OUT, initial=gpio.HIGH)
......@@ -124,18 +132,3 @@ def stop():
gpio.cleanup()
busy = sendbuf.busy
initSerial()
try:
while True:
try:
for c in input():
sendbuf.databuf.append(ord(c))
except (UnicodeDecodeError, UnicodeEncodeError):
stderr.write("En mode tele-informatique, le Minitel ne supporte pas l'ASCII etendu.")
stderr.flush()
except KeyboardInterrupt:
stderr.write("KeyboardInterrupt\n")
stderr.flush()
stop()
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Copyright 2017-2018 Pascal Engélibert
Raspberry Pi - Minitel FIFO
See datasheet:
http://pila.fr/content/interface_usb_minitel/specifications%20techniques%20d%27utilisation%20du%20minitel.pdf
"""
from sys import stderr
import os, errno
import minitel_driver as minitel
try:
os.mkfifo("minitel_out")
except FileExistsError:
True
try:
os.mkfifo("minitel_in")
except FileExistsError:
True
BUFFER = 1024
fifo_out = os.open("minitel_out", os.O_RDONLY | os.O_NONBLOCK)
fifo_in = os.open("minitel_in", os.O_WRONLY | os.O_APPEND)
def outf(data):
os.write(fifo_in, data)
minitel.initSerial(outf)
loop = True
while loop:
try:
for c in os.read(fifo_out, BUFFER):
if c == 3:
loop = False
break
minitel.sendbuf.databuf.append(c)
except (UnicodeDecodeError, UnicodeEncodeError):
stderr.write("En mode tele-informatique, le Minitel ne supporte pas l'ASCII etendu.\n")
stderr.flush()
fifo_out.close()
fifo_in.close()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment