Commit 5ddbacda authored by rtn's avatar rtn

better comments and colour display tidied up slightly

correcte username
parent bd1bf940
......@@ -8,6 +8,9 @@ from colorconsole import terminal
# tty open now coded as a function
#
# Achtung! still uses screen object for colour printing
#
# 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
......@@ -28,11 +31,14 @@ def page(ttydev,capcode,function,repeats,message):
screen.reset_colors()
sys.exit("** ERROR: cannot open tty\n\n")
#if we got here everything is OK
# now flip RTS to reset the Arduino again
ser.setRTS(True)
ser.setRTS(False)
# get the lines from the buffer
# if we got here everything is OK
# RTS/DTR does not actually need to be flipped
# as opening the tty does that anyway
# which saves some time starting up the arduino comms
# ser.setRTS(True)
# 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**")
......@@ -41,30 +47,30 @@ def page(ttydev,capcode,function,repeats,message):
print ("\n")
ibuf = ser.readlines()
pprint.pprint(ibuf)
# check to see what came down comms line is expected
# check to see what came down comms line is expected
if ibuf[0] != (b'RF22 init OK\r\n'):
screen.reset_colors()
sys.exit("** ERROR: RF22 init error\n\n")
if ibuf[-1] != (b'F <freqmhz> <freq100Hz>\r\n'):
screen.reset_colors()
sys.exit("** ERROR: RF22 comms error\n\n")
# now send message
# if TX has correctly initialised now send message
ser.write(msg)
# get a line back from TTY, it should be exactly same as msg
# but with a \n after it
# if it hasn't something has gone wrong
# get a line back from TTY, it should be exactly same as msg
# 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)
# screen.xterm256_set_bk_color(0x15)
print('<< from tty:',check)
if check != (msg+b'\n'):
screen.reset_colors()
sys.exit("** ERROR: pager comms error\n\n")
screen.xterm256_set_bk_color(0)
screen.xterm256_set_fg_color(0x2d)
print("comms OK\n")
# get data returned over comms link
# and now echo it with some pretty colours :)
print("\ncomms OK\n")
# get data returned over comms link
# and now echo it with some pretty colours :)
colindex=0x70
while True:
data=ser.readline()
......@@ -74,7 +80,9 @@ def page(ttydev,capcode,function,repeats,message):
if data==(b'F <freqmhz> <freq100Hz>\r\n'):
break
screen.xterm256_set_fg_color(0xbf)
# all done, close tty
print("**message sent correctly**\n")
ser.close()
#
# main code now starts here
......@@ -92,7 +100,7 @@ screen.xterm256_set_bk_color(8)
screen.print_at(0,0,"rtn telecom : pagertest 0.10")
screen.xterm256_set_bk_color(0)
screen.xterm256_set_fg_color(7)
screen.gotoXY(0,5)
screen.gotoXY(0,2)
screen.xterm256_set_fg_color(0x28)
#
# message now split into capcode, function (0-3), repeats
......@@ -100,8 +108,14 @@ screen.xterm256_set_fg_color(0x28)
#
capcode = 20008
function = 2
repeats = 2
repeats = 1
message = b'rtn: miauw naar de maan!<<<pagertest>>>'
ttydev="/dev/ttyACM0"
page(ttydev,capcode,function,repeats,message)
screen.reset_colors()
function = 3
repeats = 1
message = b'this is another test msg<<<pagertest>>>'
page(ttydev,capcode,function,repeats,message)
screen.reset_colors()
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