Commit 63622290 authored by rtn's avatar rtn

now recoded the serial comms bit as a function

parent 50700f21
...@@ -6,15 +6,81 @@ import pprint ...@@ -6,15 +6,81 @@ import pprint
import sys import sys
from colorconsole import terminal from colorconsole import terminal
# tty open now coded as a function
# #
# message data now here def page(ttydev,capcode,function,repeats,message):
# #
# create msg bytearray (NB: there should be more error
# checking here
#
msg=(b'P ')
msg+=(b'%07d' % capcode)+(b' ')
msg+=(b'%01d' % function)+(b' ')
msg+=(b'%01d' % repeats)+(b' ')
msg+=(message)+(b'\r')
print ("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()
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
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")
ibuf = ser.readlines()
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()
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
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
check=ser.readline()
screen.xterm256_set_fg_color(0x50)
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 :)
colindex=0x70
while True:
data=ser.readline()
screen.xterm256_set_fg_color(colindex)
print('<< from tty:',data)
colindex += 1
if data==(b'F <freqmhz> <freq100Hz>\r\n'):
break
screen.xterm256_set_fg_color(0xbf)
print("**message sent correctly**\n")
#
# main code now starts here
#
#
capcode = 20008
function = 1
repeats = 2
# message = b'0123456789----------0123456789----------'
message = b'rtn: miauw naar de maan!<<<pagertest>>>'
# #
# initialise the screen # initialise the screen
# #
...@@ -27,84 +93,15 @@ screen.print_at(0,0,"rtn telecom : pagertest 0.10") ...@@ -27,84 +93,15 @@ screen.print_at(0,0,"rtn telecom : pagertest 0.10")
screen.xterm256_set_bk_color(0) screen.xterm256_set_bk_color(0)
screen.xterm256_set_fg_color(7) screen.xterm256_set_fg_color(7)
screen.gotoXY(0,5) screen.gotoXY(0,5)
screen.xterm256_set_fg_color(0x28)
# #
# tty to open as string rather than hardcoded) # message now split into capcode, function (0-3), repeats
ttydev="/dev/ttyACM0" # and 40 character bytearray
# #
print ("attempting to open tty:",ttydev) capcode = 20008
print ("\n") function = 1
# serial port open with error checking this time repeats = 2
message = b'rtn: miauw naar de maan!<<<pagertest>>>'
try: ttydev="/dev/ttyACM0"
ser = serial.Serial(ttydev, timeout=3) page(ttydev,capcode,function,repeats,message)
except serial.SerialException:
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
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")
ibuf = ser.readlines()
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()
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")
screen.xterm256_set_fg_color(0x28)
# create message to send down comms line (warning, still no error checking!)
# msg = (b'P 0020008 1 2 0123456789*****-----01234567899876543210\r')
msg=(b'P ')
msg+=(b'%07d' % capcode)+(b' ')
msg+=(b'%01d' % function)+(b' ')
msg+=(b'%01d' % repeats)+(b' ')
msg+=(message)+(b'\r')
#import pdb; pdb.set_trace()
# 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
check=ser.readline()
screen.xterm256_set_fg_color(0x50)
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 :)
colindex=0x70
while True:
data=ser.readline()
screen.xterm256_set_fg_color(colindex)
print('<< from tty:',data)
colindex += 1
if data==(b'F <freqmhz> <freq100Hz>\r\n'):
break
screen.xterm256_set_fg_color(0xbf)
print("\n**message sent correctly**\n")
screen.reset_colors() 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