Beispiel #1
0
#! /usr/bin/env python
from init.init import init
from loop.loop import loop
from init.state import state_entire
from postProc.postProcess import postProcess


#Run the rest of the program if the initialization is sucessful.

print "Anod Board UI program running..."
state = state_entire().progState
state = init()
if (state == False):
    print "Erorr: main.py did not recieve state from init.py"
else:
    dFile = loop(state)

postProcess(dFile)
Beispiel #2
0
    else:
        print "ERROR"

def init_test():
    print init()

def loop_getDate__test():
    print "Recieving data\n"
    getData()

if __name__ == "__main__":
    import sys
    sys.path.append('/Users/mldelibero/case/masters/anodBrd/ui')

    from init.state import state_entire
    bulkState = state_entire()
    
    from init.progConfig import testConfig_file
    from init.progConfig import template_file
    from init.progConfig import createState
    from init.progConfig import checkUsrParams
    from init.init import init

    from loop.loop import getData
    
#    state_test()
#    create_template_test()
#    matches_template_test()
#    check_usr_limits_test()
#    confirm_testParameters_test()
#    createState_test()
Beispiel #3
0
def loop(state):
    """ Run the main loop.

        state is the state variable as it exists in the loop fun.

    This consists of:

        1. Ending each test if time > time_test
        2. Retrieve data from the USB buffer
        3. Error checking
        4. Format data
        5. Output heartbeat
        6. Display Data if necessary
        7. sleep
    """

    class samps:
        def __init__(self):
            self.sPer = state["sampPer"]  # sample period
            print "Period: ", self.sPer
            self.stTime = state["stTime"]  # start time
            self.tlen = max(state["ch1_time"], state["ch2_time"])
            self.endTime = self.stTime + self.tlen

            self.nxtSamp = time() + state["sampPer"]
            self.samp = False  # need to take sample
            self.sampled = True  # just sampled

        def sampNow(self):
            """Should we take a sample now?"""
            self.samp = False
            if time() > self.nxtSamp:
                self.samp = True
                self.nxtSamp += state["sampPer"]

            return self.samp

    sampling = samps()
    runModes = state_entire().runMode

    print "\n//---------------------------------------"
    print "Starting Main Loop"
    print "//---------------------------------------"

    if state["ch1_on"] == 1:
        print "ch1 running for %s minutes" % (state["ch1_time"] / 60)
    else:
        print "ch1 --> OFF"
    if state["ch2_on"] == 1:
        print "ch2 running for %s minutes" % (state["ch2_time"] / 60)
    else:
        print "ch2 --> OFF"

    state["stTime"] = time()

    linit = loop_init(state, runModes)
    ser = linit[0]
    wrFile = linit[1]

    protocol = commprot()

    while state["ch1_on"] or state["ch2_on"]:
        chkTime(state)
        if sampling.sampNow():
            data = getData(state, runModes, protocol, ser)
            forData = formData(data)
            chkErr()
            wrData(forData, wrFile)
        beat()
        sleep()

    if state["runMode"] != runModes["spoofBrd"]:
        ser.close()
    print "\n//---------------------------------------"
    print "Main Loop Done"
    print "//---------------------------------------"

    return linit[2]  # filepath