Commit e47640e8 authored by rtn's avatar rtn

updated the pager control function to use colored text module rather than colorconsole

to make it more portable
parent 5ddbacda
......@@ -5,12 +5,19 @@ import serial
import pprint
import sys
from colorconsole import terminal
from colored import fg, bg, attr
# global colours
res=attr('reset')
# tty open now coded as a function
#
# Achtung! still uses screen object for colour printing
# colored module used here instead of colorconsole/screen object
# just in case there isn't a global screen object available
#
# which works as its declared globally but probably should use colorize or something else instead
def page(ttydev,capcode,function,repeats,message):
#
# create msg bytearray (NB: there should be more error
......@@ -22,13 +29,13 @@ def page(ttydev,capcode,function,repeats,message):
msg+=(b'%01d' % repeats)+(b' ')
msg+=(message)+(b'\r')
print ("attempting to open tty:",ttydev)
print (fg(80)+"attempting to open tty:",ttydev)
# serial port open with error checking this time
try:
ser = serial.Serial(ttydev, timeout=3)
except serial.SerialException:
screen.reset_colors()
print(res)
sys.exit("** ERROR: cannot open tty\n\n")
# if we got here everything is OK
......@@ -39,20 +46,17 @@ def page(ttydev,capcode,function,repeats,message):
# ser.setRTS(False)
#
# get the lines from the buffer
screen.xterm256_set_fg_color(0x0b)
screen.xterm256_set_bk_color(0x15)
print ("** tty open OK: Connecting to Arduino and checking TX startup**")
screen.xterm256_set_fg_color(0xbe)
screen.xterm256_set_bk_color(0)
print ("\n")
print (fg(0x0b),bg(0x15))
print ('** tty open OK: Connecting to Arduino and checking TX startup**'+res)
ibuf = ser.readlines()
print (fg(202))
pprint.pprint(ibuf)
# check to see what came down comms line is expected
if ibuf[0] != (b'RF22 init OK\r\n'):
screen.reset_colors()
print(res)
sys.exit("** ERROR: RF22 init error\n\n")
if ibuf[-1] != (b'F <freqmhz> <freq100Hz>\r\n'):
screen.reset_colors()
print(res)
sys.exit("** ERROR: RF22 comms error\n\n")
# if TX has correctly initialised now send message
ser.write(msg)
......@@ -60,28 +64,23 @@ def page(ttydev,capcode,function,repeats,message):
# but with a \n after it
# if it hasn't something has gone wrong
check=ser.readline()
screen.xterm256_set_fg_color(0x50)
# screen.xterm256_set_bk_color(0x15)
print('<< from tty:',check)
print(fg(0x50),'<< from tty:',fg(0x72),bg(0x08),check,res,fg(0x52))
if check != (msg+b'\n'):
screen.reset_colors()
print(res)
sys.exit("** ERROR: pager comms error\n\n")
screen.xterm256_set_fg_color(0x2d)
print("\ncomms OK\n")
print (' ++ comms OK ++')
# get data returned over comms link
# and now echo it with some pretty colours :)
colindex=0x70
while True:
data=ser.readline()
screen.xterm256_set_fg_color(colindex)
print('<< from tty:',data)
print (fg(0x30),'<< from tty:',fg(colindex),data)
colindex += 1
if data==(b'F <freqmhz> <freq100Hz>\r\n'):
break
screen.xterm256_set_fg_color(0xbf)
# all done, close tty
print("**message sent correctly**\n")
# all done, close tty
print (fg(0x28),'** message sent correctly **\n')
ser.close()
#
......@@ -95,9 +94,9 @@ def page(ttydev,capcode,function,repeats,message):
screen = terminal.get_terminal(conEmu=False)
screen.clear()
screen.xterm256_set_fg_color(108)
screen.xterm256_set_bk_color(8)
screen.print_at(0,0,"rtn telecom : pagertest 0.10")
screen.xterm256_set_fg_color(0x52)
screen.xterm256_set_bk_color(0x08)
screen.print_at(0,0,"rtn telecom : pagertest 1.00")
screen.xterm256_set_bk_color(0)
screen.xterm256_set_fg_color(7)
screen.gotoXY(0,2)
......@@ -112,10 +111,11 @@ repeats = 1
message = b'rtn: miauw naar de maan!<<<pagertest>>>'
ttydev="/dev/ttyACM0"
page(ttydev,capcode,function,repeats,message)
screen.reset_colors()
print(res)
function = 3
repeats = 1
message = b'this is another test msg<<<pagertest>>>'
page(ttydev,capcode,function,repeats,message)
screen.reset_colors()
print (fg(0xc8),'\n++ Script completed sucessfully ++\n',res)
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