Example #1
0
def testscenario6():
    if (getPotLum() != 0):
        FILE = open('TC1_ONOFF1_SUB_2.txt', 'a')
        print('Blue LED still on.\nLED Power: {}'.format(getPotLum()),
              file=FILE)
        return False
    else:
        if (getBatLvl() < 3.8):
            rtime = random.randint(2, 9)
            rhex = hex(rtime)[2:]
            if (len(rhex) < 2):
                rhex = '0' + rhex
            set_config('01', '12', rhex)
            time.sleep(rtime / 10)

            time.sleep(1)
            buz = getBuzzer()
            if (len(buz) == 0):
                FILE = open('TC1_ONOFF1_SUB_2.txt', 'a')
                print('No beeps.\nRandom time: {}'.format(rtime), file=FILE)
                FILE.close()
                return False
            else:
                if (getPotLum() != 0):
                    FILE = open('TC1_ONOFF1_SUB_2.txt', 'a')
                    print('{}\t{}'.format(getPotLum(), rtime), file=FILE)
                    FILE.close()
                    return False
                else:
                    return True
        else:
            FILE = open('TC1_ONOFF1_SUB_2.txt', 'a')
            print('Battery above 3.8V', file=FILE)
            FILE.close()
            return False
Example #2
0
def testscenario4():
    set_config('01', '11', '02')
    time.sleep(0.2)

    panel = getPanel()
    profile = switchCase2(str(panel))
    if (profile == 'invalid configuration'):
        FILE = open('TC2_ONOFF_1.txt', 'a')
        print('Unexpected profile value', file=FILE)
        FILE.close()
        return False

    set_config('01', '12', '02')
    time.sleep(0.2)

    rtime = random.randint(1, profile - 2)
    time.sleep(rtime)

    set_config('01', '12', '02')
    time.sleep(0.2)

    if (getPotLum() != 0):
        FILE = open('TC2_ONOFF_2.txt', 'a')
        print('Blue LED is on: {}\t{}\t{}'.format(profile, rtime, getPotLum()),
              file=FILE)
        FILE.close()
        return False
    else:
        return True
Example #3
0
def testscenario9():
    rtime = random.randint(2, 9)
    rhex = hex(rtime)[2:]
    if (len(rhex) < 2):
        rhex = '0' + rhex

    set_config('01', '12', '02')
    time.sleep(0.2)

    time.sleep(0.55)

    if (getPotLum() == 0):
        FILE = open('TC1_ONOFF2_SUB_1.txt', 'a')
        print('{}'.format(getPotLum()), file=FILE)
        FILE.close()
        return False
    else:
        time.sleep(5)

        set_config('01', '12', rhex)
        time.sleep(rtime / 10)

        if (getPotLum() != 0):
            print(getPotLum(), file=FILE)
            FILE.close()
            return False
        else:
            return True
Example #4
0
def maskSelect(profile):
    now = time.time()
    future = now + profile
    if (profile == 10):
        while (now < future):
            if (mask10(getPotLum(), (time.time() - now + 3))):
                continue
            else:
                return False
        return True
    elif (profile == future):
        while (now < future):
            data = getPotLum()
            if (mask20(data, (time.time() - now + 3))):
                now = time.time()
            else:
                return False
        return True
    elif (profile == 40):
        while (now < future):
            if (mask40(getPotLum(), (time.time() - now + 3))):
                continue
            else:
                return False
        return True
    elif (profile == 60):
        while (now < future):
            if (mask60(getPotLum(), (time.time() - now + 3))):
                continue
            else:
                return False
Example #5
0
def testscenario3():
    rtime = random.randint(10, 30)
    rhex = hex(rtime)[2:]
    if (len(rhex) < 2):
        rhex = '0' + rhex

    set_config('01', '12', '0A')
    time.sleep(1)
    panel_before = getPanel()

    time.sleep(5)

    set_config('01', '11', rhex)
    time.sleep(rtime / 10)

    buz = getBuzzer()

    if (len(buz) == 0
        ):  #mudar depois para um teste com o período correto do buzzer
        FILE = open('TC1_SETA1_SUB_3.txt', 'a')
        print('No beeps', file=FILE)
        print('{}\n'.format(rtime), file=FILE)
        return False
    else:
        vbat = getBatLvl()
        print(vbat)
        if (vbat < 3.8 and getPotLum() > 0):
            FILE = open('TC1_SETA1_SUB_3.txt', 'a')
            print('Blue LED on although battery below 3.8V', file=FILE)
            print('{}\n'.format(vbat), file=FILE)
            FILE.close()
            return False
        elif (vbat < 3.8 and getPotLum() == 0):
            panel_after = getPanel()
            i, j = getIndex(panel_before, panel_after)
            if ((j - i) == 1 or (i - j) == 3):
                print("teste ok")
                return True
            else:
                FILE = open('TC1_SETA1_SUB_3.txt', 'a')
                print(
                    'falha. a ativacao de seta 1 vez nao mudou o perfil na ordem estabelecida',
                    file=FILE)
                print('Random time: {}\tPanel before: {}\tPanel after: {}'.
                      format(rtime, panel_before, panel_after))
                return False
        else:
            FILE = open('TC1_SETA1_SUB_3.txt', 'a')
            print(
                'Unexpected behavior\nBattery: {}\t LED Power:{}\t Panel before: {}\tPanel after: {}'
                .format(vbat, getPotLum(), panel_after, panel_before),
                file=FILE)
            FILE.close()
            return False
Example #6
0
def testscenario4():
    if (getPotLum() != 0):
        FILE = open('TC1_SETA2_SUB_1.txt', 'a')
        print('Blue LED not on yet', file=FILE)
        FILE.write('{}\n'.format(getPotLum()))
        FILE.close()
        return False
    else:
        set_config('01', '11', '02')
        time.sleep(0.2)
        panel_before = getPanel()

        set_config('01', '12', '15')
        time.sleep(1.5)

        rtime = random.randint(10, 15)
        rhex = hex(rtime)[2:]
        if (len(rhex) < 2):
            rhex = '0' + rhex

        set_config('01', '11', rhex)
        time.sleep(rtime / 10)
        time.sleep(3)

        set_config('01', '12', '0a')
        time.sleep(2)

        set_config('01', '12', '0a')
        time.sleep(1)

        panel_after = getPanel()

        if (panel_before != panel_after):
            FILE = open('TC1_SETA2_SUB_1.txt', 'a')
            print('SETA caused change during battery monitoring', file=FILE)
            FILE.write(
                'Panel before: {}\tPanel after: {}\tRandom time:{}\n'.format(
                    panel_before, panel_after, rtime))
            FILE.close()
            return False
        else:
            print('teste passou')
            return True
Example #7
0
def testscenario10():
    set_config('01', '11', '02')
    time.sleep(0.2)

    profile = switchCase2(str(getPanel()))
    if (profile == 'invalid configuration'):
        FILE = open('TC1_ONOFF2_SUB_2.txt', 'a')
        print(profile, file=FILE)
        FILE.close()
        return False

    #Escolha de um momento aleatório para começar a pressionar o botão ON/OFF
    press = random.randint(2, profile)

    #Escolha do momento de soltar o botão ON/OFF
    release = profile - press
    rhex = hex(release * 10 + random.randint(2, 9))[2:]
    if (len(rhex) % 2 != 0):
        rhex = '0' + rhex

    set_config('01', '12', '02')
    time.sleep(0.2)
    time.sleep(press)
    set_config('01', '12', rhex)
    time.sleep(release)

    # Desliga o LED de cura
    set_config('01', '12', '02')
    time.sleep(0.2)
    time.sleep(5)

    if (getPotLum() == 0):
        set_config('01', '12', '02')
        time.sleep(0.2)
        FILE = open('TC1_ONOFF2_SUB_2.txt', 'a')
        print('{}\t{}\t{}'.format(profile, press, release), file=FILE)
        FILE.close()
        return False
    else:
        return True
Example #8
0
def getCurve(profile):
    zero = time.time()
    future = zero + profile
    
    if(profile == 20 or profile == 40):
        time.sleep(1)
    
    now = time.time()
    profcurve = []
        
    while(now <= future):
        p = getPotLum()
        now = time.time()
        t = now - zero
        profcurve.append((t, p))
    FILE = open('data.txt', 'a')
    for l in profcurve:
        FILE.write(str(l[0])+'; ')
        FILE.write(str(l[1])+'\n')
    FILE.write('\n')
    FILE.close()
    return profcurve
Example #9
0
def testscenario2():
    set_config('01', '12', '02')
    time.sleep(0.2)
    set_config('01', '12', '02')
    time.sleep(0.2)

    panel_before = switchCase2(str(getPanel()))

    set_config('01', '12', '02')
    time.sleep(0.2)

    time.sleep(5)

    set_config('01', '11', '02')
    time.sleep(0.2)
    panel_after = switchCase2(str(getPanel()))

    if (getPotLum() == 0):
        FILE = open('TC2_SETA_2.txt', 'a')
        print('Panel before: {}\tPanel after: {}'.format(
            panel_before, panel_after),
              file=FILE)
        FILE.close()
        return False
    if (panel_after == 'invalid configuration'
            or panel_before == 'invalid configuration'):
        FILE = open('TC2_SETA_2.txt', 'a')
        print('Panel before: {}\tPanel after: {}'.format(
            panel_before, panel_after),
              file=FILE)
        FILE.close()
        return False
    else:
        buz = getBuzzer()
        if (len(buz) == 0):
            print('No beeps', file=FILE)
            FILE.close()
            return False
        else:
            if (panel_before == 10):
                if (panel_after == 20):
                    return True
                else:
                    print(panel_before, '\t', panel_after, file=FILE)
                    return False
            elif (panel_before == 20):
                if (panel_after == 40):
                    return True
                else:
                    print(panel_before, '\t', panel_after, file=FILE)
                    return False
            elif (panel_before == 40):
                if (panel_after == 60):
                    return True
                else:
                    print(panel_before, '\t', panel_after, file=FILE)
                    return False
            elif (panel_before == 60):
                if (panel_after == 10):
                    return True
                else:
                    print(panel_before, '\t', panel_after, file=FILE)
                    return False
            else:
                return False
Example #10
0
def testscenario5():
    if (getPotLum() != 0):
        FILE = open('TC1_ONOFF1_SUB_1.txt', 'a')
        FILE.write('Blue LED is not on yet;\nLED power: {}\n'.format(
            getPotLum()))
        FILE.close()
        return False
    else:
        rtime = random.randint(2, 9)
        rhex = hex(rtime)[2:]
        if (len(rhex) < 2):
            rhex = '0' + rhex

        set_config('01', '12', rhex)
        time.sleep(rtime / 10)
        panel = getPanel()
        panel = str(panel)
        profile = switchCase2(panel)
        if (profile == 'invalid configuration'):
            FILE = open('TC1_ONOFF1_SUB_1.txt', 'a')
            print(
                'Invalid configuration for panel.\nPanel: {}\tRandom time: {}\n'
                .format(panel, rtime),
                file=FILE)
            FILE.close()
            return False

        curve = getCurve(profile)

        for i in range(len(curve)):
            if (curve[i][1] == 0):
                if (i > 0 and i < len(curve) - 1):
                    curve[i][1] = (curve[i - 1][1] + curve[i + 1][1]) / 2

        set_config('01', '11', '02')
        time.sleep(0.2)
        flag = []

        if (profile == 10):
            for c in curve:
                if (mask10(c[1], c[0])):
                    flag.append(1)
                else:
                    FILE = open('TC1_ONOFF1_SUB_1.txt', 'a')
                    print(
                        'Power error.\nElapsed time: {}\tLED power: {}\t Profile: {}'
                        .format(c[0], c[1], profile),
                        file=FILE)
                    FILE.close()
                    flag.append(0)
        elif (profile == 20):
            for c in curve:
                if (mask20(c[1], c[0])):
                    flag.append(1)
                else:
                    FILE = open('TC1_ONOFF1_SUB_1.txt', 'a')
                    print(
                        'Power error.\nElapsed time: {}\tLED power: {}\t Profile: {}'
                        .format(c[0], c[1], profile),
                        file=FILE)
                    FILE.close()
                    flag.append(0)
        elif (profile == 40):
            for c in curve:
                if (mask40(c[1], c[0])):
                    flag.append(1)
                else:
                    FILE = open('TC1_ONOFF1_SUB_1.txt', 'a')
                    print(
                        'Power error.\nElapsed time: {}\tLED power: {}\t Profile: {}'
                        .format(c[0], c[1], profile),
                        file=FILE)
                    FILE.close()
                    flag.append(0)
        else:
            for c in curve:
                if (mask60(c[1], c[0])):
                    flag.append(1)
                else:
                    FILE = open('TC1_ONOFF1_SUB_1.txt', 'a')
                    print(
                        'Power error.\nElapsed time: {}\tLED power: {}\t Profile: {}'
                        .format(c[0], c[1], profile),
                        file=FILE)
                    FILE.close()
                    flag.append(0)
        if (min(flag) == 1):
            return True
        else:
            return False