from collections import namedtuple

Device = namedtuple('Device', 'addr_str addr last_heard')

bluesync_uuid = [0x92, 0xb8, 0xb4, 0xf7, 0xd9, 
    0x96, 0xb3, 0xaf, 0x24, 0x48, 
    0x03, 0x20, 0x35, 0x74, 0x67, 
    0x86]

timestamp_uuid = [0x6e, 0x16, 0x71, 0x8f, 0xb9, 
    0xde, 0x2b, 0x92, 0xa0, 0x4b, 
    0x9d, 0x92, 0xaa, 0x49, 0xd4, 
    0x63]

trigger_scanning_uuid = [0x04, 0x48, 0x2f, 0x9a, 0x2e, 
    0x35, 0xc7, 0xa8, 0xcd, 0x4c, 
    0x4b, 0x90, 0x9a, 0xcb, 0xec, 
    0xe8]

reference_time_uuid = [0x1d, 0x4f, 0xc4, 0xeb, 0xf5, 
    0x2c, 0x94, 0xb9, 0xfc, 0x42, 
    0xca, 0x9e, 0x4a, 0x3b, 0xd9, 
    0x33]

bluesync_slave_adv_data = [
    0x02, 0x01, 0x06, 0x02, 0x0A, 0x03,
    0x06, 0xFF, 0xFF, 0xFF, 0xBE, 0xEF, 0xFE
]

bluesync_master_adv_data_prefix = [
    0x02, 0x01, 0x06,
    0x0A, 0xFF, 0xFF, 0xFF, 0xBE, 0xEF, 0xEF
]

sequence_number_uuid = [
    0x4e, 0x14, 0x6c, 0xa0, 0x98,
    0xa2, 0xd7, 0x83, 0x81, 0x4f, 
    0xc1, 0x48, 0xd2, 0x10, 0x9c, 
    0xaa
]

standard_flag_uuid = [
    0x0b, 0xd1, 0x67, 0xa6, 0xfb, 
    0xbb, 0xe5, 0x9a, 0x64, 0x46, 
    0x0d, 0x3d, 0xf2, 0x73, 0xc9, 
    0xe7
]

def array_to_integer(array):
    bytes = len(array)
    if bytes > 4:
        bytes = 4
    return sum([array[i] << (8*i) for i in range(0,bytes)])

def integer_to_array(integer):
    return [int((integer & (0xFF << 8*i)) >> 8*i) for i in range (0,4)]