Exemplo n.º 1
0
def config_measurement():
    #
    # GETTING TIME AND STATE OF CONTROLLER
    #
    global logger, rtc, sd, T_exec, T_meas, logfile_new
    logger.info('Config_measurement...')

    # GETTING STATE AND TIME FROM CTLR
    stateCTLR = None
    wdt = WDT(timeout=25 * 1000)
    while stateCTLR not in [2, 4]:
        response = None
        while not response:
            requests = 'get,state;get,time;set,state{},1'.format(iACC)
            logger.info('sending request to CTLR: "{}"...'.format(requests))
            try:
                response = socket_client.request(requests)
            except:
                logger.exception('1st request failed.')
            # try:
            #     response = socket_client.request(requests)
            # except OSError as exc:
            #     # if exc.args[0] ==
            #     pass
            # except:
            #     raise
            time.sleep(1)
        response_list = response.split(';')
        stateCTLR = int(response_list[0])
        time_gps = int(response_list[1])
        rtc.init(time.localtime(time_gps))
        logger.info('stateCTLR = {} and time={}'.format(stateCTLR, rtc.now()))
    wdt.feed()
    wdt = WDT(timeout=wdt_timeout)

    # RENAME LOGFILE
    logfile_new = '/sd/log/{}.log'.format(datetime_string(time.time()))
    logging.fclose()
    os.rename(logfile, logfile_new)
    logging.basicConfig(level=logging.DEBUG, filename=logfile_new)

    if stateCTLR == 2:
        T_exec = 60 * 5
        T_meas = 20
    elif stateCTLR == 4:
        T_exec = 60 * 60
        T_meas = 60 * 3
    gc.collect()

    return
Exemplo n.º 2
0
def config_measurement():
    #
    # GETTING TIME AND STATE OF CONTROLLER
    #
    global logger, rtc, sd, T_exec, T_meas, logfile_new
    logger.info('Config_measurement...')

    # GETTING STATE AND TIME FROM CTLR
    stateCTLR = None
    while stateCTLR not in [2, 4]:
        response = None
        while not response:
            requests = 'get,state;get,time;set,state{},1'.format(iACC)
            response = socket_client.request(requests)
            logger.info('request sent to CTLR:{}...'.format(requests))
            time.sleep(1)
        response_list = response.split(';')
        stateCTLR = int(response_list[0])
        time_gps = int(response_list[1])
        rtc.init(time.localtime(time_gps))
        logger.info('stateCTLR={} and time={}'.format(stateCTLR, rtc.now()))

    logger.info('Starting ACC node job...')
    # RENAME LOGFILE
    logfile_new = '/sd/log/{}.log'.format(datetime_string(time.time()))
    logging.fclose()
    os.rename(logfile, logfile_new)
    logging.basicConfig(level=logging.DEBUG, filename=logfile_new)

    if stateCTLR == 2:
        T_exec = 60
        T_meas = 5
    elif stateCTLR == 4:
        T_exec = 3600
        T_meas = 60 * 3
    return
Exemplo n.º 3
0
    logger.info('time_next = {}'.format(datetime_string(T_next)))
    logger.info("Going to Sleep for {} seconds...".format(T_next - 40 -
                                                          (T_now)))
    time.sleep(3)

    ACC.py.setup_sleep(T_next - 40 - (T_now + 3))
    ACC.py.go_to_sleep()
    return


try:
    setup()
    config_measurement()
    measure()
    store_to_SD()
    send_file()
    deep_sleep()
except Exception:
    logger.exception('Unknown exception caught for emailing...')
    logging.fclose()

    to = '*****@*****.**'
    subject = 'WG: Exception Report from GCAM{}-ACC{}'.format(iCAM, iACC)
    logger.info('logfile_new={}'.format(logfile_new))
    with open(logfile_new, 'r') as file:
        logs = file.read()
    contents = 'Log file\n--------\n' + logs
    gmail.send(to, subject, contents)
finally:
    deep_sleep_exception()
Exemplo n.º 4
0
def config_measurement():
    #
    # GETTING TIME AND STATE OF CONTROLLER
    #
    global logger, rtc, sd, T_exec, T_meas, logfile_new
    global acc, acc_d, wdt_timeout


    logger.info('Config_measurement...')

    # GETTING STATE AND TIME FROM CTLR
    stateCTLR = None
    wdt = WDT(timeout=25*1000)
    while True:
        requests = 'get,state;get,time;set,state{},1'.format(iACC)
        logger.info('sending request to CTLR: "{}"...'.format(requests))
        try:
            response = socket_client.request(requests)
        except:
            logger.exception('The Step1 Request failed.')
        if response:
            response_ = response.split(';')
            stateCTLR = int(response_[0])
            if stateCTLR not in [1]:
                time_gps = int(response_[1])
                rtc.init(time.localtime(time_gps))
                break
        time.sleep(1)
    logger.info('stateCTLR = {} and time={}'.format(stateCTLR,rtc.now()))
    wdt.feed()

    # RENAME LOGFILE
    logfile_new = '/sd/log/{}.log'.format(datetime_string(time.time()))
    logging.fclose()
    os.rename(logfile,logfile_new)
    logging.basicConfig(level=logging.DEBUG,filename=logfile_new)

    logger.info('stateCTLR={}'.format(stateCTLR))

    if stateCTLR in [2,8]:
        logger.info('stateCTLR in [2,8]={}'.format(stateCTLR in [2,8]))
        T_exec = 60*5
        T_meas = 20
        # T_meas = 60*3
        # T_meas = 10
    elif stateCTLR in [4]:
        T_exec = 60*10
        T_meas = 60*1
    elif stateCTLR in [3,5,6,7]:
        logger.info('stateCTLR in [3,5,6,7]={}'.format(stateCTLR in [3,5,6,7]))
        T_exec = 60*10
        T_meas = 60*1
        deep_sleep()

    wdt_timeout = int(T_exec*1000*1.5)
    wdt = WDT(timeout=wdt_timeout)
    acc   = [array.array('f', [0.0 for j in range(T_meas*100)]) for i in range(3)]
    acc_d = [array.array('f', [0.0 for j in range(T_meas*100)]) for i in range(3)]

    gc.collect()

    return