From f15bd4e6d890a39a962d7d853656ef92a2de2265 Mon Sep 17 00:00:00 2001 From: Dan White Date: Wed, 15 May 2013 19:26:45 -0500 Subject: [PATCH] co-simulation framework start --- msp4th/cosim.py | 96 +++++++++++++++++++++++++++++++++++++++++++++++++ msp4th/pc4th | 18 +++++++--- 2 files changed, 110 insertions(+), 4 deletions(-) create mode 100644 msp4th/cosim.py diff --git a/msp4th/cosim.py b/msp4th/cosim.py new file mode 100644 index 0000000..1a327f6 --- /dev/null +++ b/msp4th/cosim.py @@ -0,0 +1,96 @@ +#!/usr/bin/env python + +import os +import sys +import signal +import time + +import pexpect + + +atoi = pexpect.spawn('miniterm.py', + ['--rts=0', '/dev/ttyUSB3', '4800'], + logfile=open('ns430.log', 'w'), + timeout=5) + +pc = pexpect.spawn('./pc4th', + logfile=open('pc4th.log', 'w'), + timeout=5) + +time.sleep(0.2) +atoi.send(r'') +time.sleep(0.1) +atoi.send(r'') +time.sleep(0.1) + +def cleanup(): + os.system('killall _pc4th > /dev/null 2>&1') + atoi.close(force=True) + pc.close(force=True) + + +def print_side(a, b): + alines = [x.rstrip() for x in a.split('\n')] + blines = [x.rstrip() for x in b.split('\n')] + + alen = len(alines) + blen = len(blines) + + alines.extend([''] * max(blen - alen, 0)) + blines.extend([''] * max(alen - blen, 0)) + + for (aline, bline) in zip(alines, blines): + if aline == bline: + eq = '=' + else: + eq = '!' + + s = '%-80s %s %-80s' % (aline, eq, bline) + print s + +def prompt(p): + p.expect([r'\r\n>', pexpect.EOF]) + +def send(p, s): + p.send(s) + +def interact(p): + print '*** Interacting with:', ' '.join(p.args) + print '*** escape is ^]' + p.interact() + + +try: + # side-by-side output + prompt(atoi) + prompt(pc) + print_side(' '.join(atoi.args), ' '.join(pc.args)) + for line in open('tests.4th'): + s = line.rstrip() + s += '\r' + + for n in (pc, atoi): + #for n in (pc, ): + send(n, s) + if s.startswith('bye'): + #things don't match after this + break + prompt(n) + + if 0: + print + print 's :', s.rstrip() + print 'pc :', pc.before + print 'atoi:', atoi.before + + print_side(atoi.before, pc.before) + + +except pexpect.TIMEOUT: + print '** TIMEOUT **' + cleanup() + +#interact(pc) +#interact(atoi) + +cleanup() diff --git a/msp4th/pc4th b/msp4th/pc4th index 5d1b5a9..019a4b8 100755 --- a/msp4th/pc4th +++ b/msp4th/pc4th @@ -1,7 +1,17 @@ #!/bin/bash -make _pc4th >/dev/null && ( - OLD_STTY=$(stty -g) +OLD_STTY=$(stty -g) + +function cleanup { + stty "$OLD_STTY" + exit $1 +} + +trap cleanup SIGHUP SIGINT SIGTERM + +make _pc4th >/dev/null + +if [ $? -eq 0 ]; then stty cbreak stty -echo stty -icrnl @@ -11,6 +21,6 @@ make _pc4th >/dev/null && ( else ./_pc4th < $1 fi +fi - stty "$OLD_STTY" - ) +cleanup $? -- 2.25.1