3 import urllib # for url unquote
7 pi = pigpio.pi() # connect to local Pi
9 pi.set_mode(2, pigpio.OUTPUT)
11 gpio8period = 20 # period of 1 bit to achieve 45bps was 20
13 ColumnCurrentPosition = 1
16 # first we map ascii to the possible ascii chars
17 ascii_to_baudot_char = {
97 # then we map limted set to baudot
98 # see http://rabbit.eng.miami.edu/info/baudot.html
183 initialize teletype i/o
185 txbaudot("01000") # cr
187 txbaudot("00010") # lf
194 def motor_start(time_secs=0):
198 global MotorTimerCtr, MotorTimerVal
200 if (not MotorTimerCtr) :
201 gpio.output(PWR_RLY,gpio.LOW)
205 MotorTimerCtr = MotorTimerVal
207 MotorTimerCtr = time_secs
211 turn off motor, turn off data relay
214 gpio.output(PWR_RLY,gpio.HIGH)
216 gpio.output(DATA_RLY,gpio.HIGH)
225 test mapping tables by attempt to print out all possible codes
227 for i in range(0,256):
228 if (ascii_to_baudot_char.has_key(chr(i))): # if first reduce mapping table has key
229 a = ascii_to_baudot_char[chr(i)]
230 if (ascii_to_binstr.has_key(a)): # and 2nd reduce mapping table has key
231 b = ascii_to_binstr[a]
237 transmit one character to the teletype
245 micros = gpio8period*1000
247 wf.append(pigpio.pulse(0, 1<<gpio, 20000))
249 for b in reversed(c):
251 wf.append(pigpio.pulse(1<<gpio, 0, micros))
253 wf.append(pigpio.pulse(0, 1<<gpio, micros))
255 wf.append(pigpio.pulse(1<<gpio, 0, micros))
256 pi.wave_add_generic(wf)
258 wid = pi.wave_create()
261 pi.wave_send_once(wid)
263 while pi.wave_tx_busy():
273 if (ascii_to_baudot_char.has_key(chr(k))):
274 a = ascii_to_baudot_char[chr(k)]
275 if (ascii_to_binstr.has_key(a)): # and 2nd reduce mapping table has key
276 b = ascii_to_binstr[a]
282 def update_column_position():
284 keep track of column position so we can insert cr lf when necessary
286 global ColumnCurrentPosition, ColumnMax
287 ColumnCurrentPosition = ColumnCurrentPosition + 1
288 if ColumnCurrentPosition > ColumnMax:
291 ColumnCurrentPosition = 0;
304 Shift down to letters
314 send an ascii character
316 if (ascii_to_baudot_char.has_key(c)):
317 a = ascii_to_baudot_char[c]
318 if (ascii_to_binstr.has_key(a)): # and 2nd reduce mapping table has key
319 b = ascii_to_binstr[a]
321 if (a in needs_shift_up):
326 update_column_position()
332 send an ascii character
338 transmit an ascii string
340 de_uried_str = urllib.unquote(s)
341 for i in range(len(de_uried_str)):
342 tx_ascii_chr(de_uried_str[i])
347 transmit a control code 'lf' = line feed, 'cr' = carriage return, etc.
349 global ColumnCurrentPosition
352 ColumnCurrentPosition = 0
360 txbaudot('11011') # shift up
362 txbaudot('11111') # shift down
363 txbaudot('01000') # cr
364 txbaudot('00100') # space
372 txbaudot('01000') # cr
373 ColumnCurrentPosition = 0
378 update_column_position()
381 file = open("paz001.txt", "r")
383 lines = file.readlines()