예제 #1
0
def unlock_safe(safe: str):
    """
    Unlock the safe by withdrawing the bar a set distance
    :return:
    """
    #moveLock('R', 16)
    with open(os.path.join(safe_datadir.format(safe), 'locked.txt'),
              'w') as fo:
        fo.write('UNLOCKED\n')
    return
예제 #2
0
def lock_safe(safe: str):
    """
    Check switches are closed then lock the safe
    :return:
    """
    # while any([GPIO.input(hinge_switch_pin) == GPIO.HIGH, GPIO.input(lid_switch_pin) == GPIO.HIGH]):
    #     cannot_lock()
    #     sleep(0.5)
    # print('Locking now....')
    # while GPIO.input(lock_switch_pin) == GPIO.HIGH:
    #     moveLock('A', 1)
    with open(os.join(safe_datadir.format(safe), 'locked.txt'), 'w') as fo:
        fo.write('LOCKED\n')
    return
예제 #3
0
def get_safe_status(safe: str) -> Tuple[bool, bool, bool]:
    """
    Query the 'Virtual' microswitches to determine the safe status
    :return:
    """

    with open(os.path.join(safe_datadir.format(safe), 'status.txt'),
              'r') as fi:
        status_lst = fi.readline().strip().split(',')
        status = status_lst[0] == 'TRUE', status_lst[1] == 'TRUE', status_lst[
            2] == 'TRUE'
    # status = GPIO.input(lid_switch_pin) == GPIO.LOW, \
    #          GPIO.input(hinge_switch_pin) == GPIO.LOW, \
    #          GPIO.input(lock_switch_pin) == GPIO.LOW
    logging.debug(f'Safe status = {safe}/{status}')
    print(f'Safe status = {safe}/{status}')
    return status
예제 #4
0
def set_settings(settings_msg: str, safe: str):
    global scanfreq
    global reportfreq
    global proximityunit
    global displayproximity
    settings_changed = False
    settings_parts = settings_msg.split(':')
    if len(settings_parts) == 5:  # Only act if there are exactly 5 settings parts
        if '=' in settings_parts[1]:
            s1_parts = settings_parts[1].split('=')
            if s1_parts[0] == 'SCANFREQ':
                new_scanfreq = int(s1_parts[1])
                if new_scanfreq != scanfreq:
                    scanfreq = new_scanfreq
                    settings_changed = True
        if '=' in settings_parts[2]:
            s2_parts = settings_parts[2].split('=')
            if s2_parts[0] == 'REPORTFREQ':
                new_reportfreq = int(s2_parts[1])
                if new_reportfreq != reportfreq:
                    reportfreq = new_reportfreq
                    settings_changed = True
        if '=' in settings_parts[3]:
            s3_parts = settings_parts[3].split('=')
            if s3_parts[0] == 'PROXIMITYUNIT':
                new_proximityunit = s3_parts[1]
                if new_proximityunit != proximityunit:
                    proximityunit = new_proximityunit
                    settings_changed = True
        if '=' in settings_parts[4]:
            s4_parts = settings_parts[4].split('=')
            if s4_parts[0] == 'DISPLAYPROXIMITY':
                new_displayproximity = s4_parts[1] == 'TRUE'
                if new_displayproximity != displayproximity:
                    displayproximity = new_displayproximity
                    settings_changed = True
        if settings_changed:
            logging.debug(f'New settings = {scanfreq}, {reportfreq}, {proximityunit}, {displayproximity}')
            log_event(f'Settings{scanfreq}-{reportfreq}-{proximityunit}-{displayproximity}', safe)
            # Update the file of settings
            with open(os.path.join(safe_datadir.format(safe), 'settings.txt'), 'w') as fo:
                fo.write(f"{scanfreq},{reportfreq},{proximityunit},{displayproximity},{auth_to_unlock}," +
                         unlock_time.strftime('%Y,%m,%d,%H,%M,%S,%f') + '\n')

    return
예제 #5
0
def set_lights(n: str, safe: str):
    """
    Set the RPi lights to the parameters specified OFF, Green or 1-5 Red
    :param n:
    :return:
    """
    # light_settings = {'OFF': 0x00,
    #                   'G': 0x80,
    #                   '1R': 0x40,
    #                   '2R': 0x60,
    #                   '3R': 0x70,
    #                   '4R': 0x78,
    #                   '5R': 0x7C,
    #                   'ERR': 0x54}
    # GPIO.output(latchPin, GPIO.LOW) # Set 74HC595 to receive
    # shift_bits(dataPin, clockPin, LSBFIRST, light_settings[n])  # Shift the relevant definition byte to the 74HC595
    # GPIO.output(latchPin, GPIO.HIGH)    # Lock the 74HC595 / show the lights
    with open(os.path.join(safe_datadir.format(safe), 'lights.txt'),
              'w') as fo:
        fo.write(n + '\n')
    return
예제 #6
0
    event_log = {}

    # hardware_id = get_hardware_id()
    safes = [dir for dir in os.listdir(safe_data) if os.path.isdir(os.path.join(safe_data, dir))]
    print(safes)

    # set initial scan numbers to zero - allow one scan number for each safe being simulated.
    for safe in safes:
        scan_number[safe] = 0

    # Make a while True loop once everything is working

    for current_safe in safes:
        # Read settings - per safe
        # while True:
        with open(os.path.join(safe_datadir.format(current_safe), 'settings.txt'), 'r') as fi:
            parms = fi.readline().strip().split(',')
            print(f"{current_safe} - {parms}")
            scanfreq = int(parms[0])  # seconds
            reportfreq = int(parms[1])  # number of scanfreq periods
            proximityunit = parms[2]
            displayproximity = parms[3] == 'True'
            auth_to_unlock = parms[4] == 'True'
            unlock_time = datetime(int(parms[5]),
                                   int(parms[6]),
                                   int(parms[7]),
                                   int(parms[8]),
                                   int(parms[9]),
                                   int(parms[10]),
                                   int(parms[11])).replace(tzinfo=timezone.utc)
            # Need to work on the bits below