testScript.py 2.08 KB
Newer Older
Thanassis Tsiodras's avatar
Thanassis Tsiodras committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
#!/usr/bin/env python
#
# Automatically generated Python sequence chart (MSC) implementation

import os
import sys
import signal

taste_inst = os.popen('taste-config --prefix').readlines()[0].strip()
sys.path.append(taste_inst+'/share/asn1-editor')

from Scenario import Scenario, PollerThread
from PySide.QtCore import QCoreApplication, Qt
from udpcontroller import tasteUDP

status = 0
# Generated due to "user_trace_201212131443.msc"
# From the section: MSCDOCUMENT automade


@Scenario
def Exercise_user(self):
    '''user processing'''
    global status
    self.sendMsg('Manual_Control', '{ door door-open, direction down, brake off, motor on }', lineNo=17)
    self.sendMsg('Start', 'nb-of-cycle:100', lineNo=18)
    while True:
        (msgId, val) = self.getNextMsg(timeout=1)
        if not msgId:
            break
        if msgId == 'position':
            continue
        elif msgId == 'door_status':
            print 'Received door status, value=', val.Get()
    return 0

def runScenario(udpController=None, callback=None):
    global user
    global poller
    poller = None
    if udpController:
        user = Exercise_user()
        udpController.slots.append(user.Q)
        user.wait()
        udpController.slots.remove(user.Q)
        if callback:
            user.done.connect(callback)
        return user.status
    else:
    # Use old-style message queue
        poller = PollerThread()
        user = Exercise_user()
        if callback:
            user.done.connect(callback)
        poller.slots.append(user.Q)
        poller.start()
        user.start()

def killThreads():
    global user
    user.wait()
    user = None
    if poller:
        poller._bDie = True
        poller.wait()


if __name__ == "__main__":
    signal.signal(signal.SIGINT, signal.SIG_DFL)
    udpController = None
    if '--udp' in sys.argv:
        # Create UDP Controller with default IP/Port values (127.0.0.1:7755:7756)
        udpController = tasteUDP()
    app = QCoreApplication(sys.argv)
    app.aboutToQuit.connect(killThreads)
    status = runScenario(udpController, app.quit)
    app.exec_()
    sys.exit(status)