<commit_before>'''
The GatewayApi defines high level functions, these are used by the interface
and call the master_api to complete the actions. 

Created on Sep 16, 2012

@author: fryckbos
'''
import logging
LOGGER = logging.getLogger("openmotics")

import time as pytime
from threading import Timer

import master_api
from outputs import OutputStatus
from master_communicator import BackgroundConsumer, CommunicationTimedOutException 

class GatewayApi:
    """ The GatewayApi combines master_api functions into high level functions. """
    
    def __init__(self, master_communicator):
        self.__master_communicator = master_communicator
    
        self.__last_maintenance_send_time = 0
        self.__maintenance_timeout_timer = None
        
        self.__output_status = None
        self.__master_communicator.register_consumer(
                    BackgroundConsumer(master_api.output_list(), 0, self.__update_outputs))
        
        self.init_master()
    
    def init_master(self):
        """ Initialize the master: disable the async RO messages. """
        try:
            eeprom_data = self.__master_communicator.do_command(master_api.eeprom_list(),
                { "bank" : 0 })['data']
            
            if eeprom_data[11] != chr(255):
                LOGGER.info("Disabling async RO messages.")
                self.__master_communicator.do_command(master_api.write_eeprom(),
                    { "bank" : 0, "address": 11, "data": chr(255) })
                
                self.__master_communicator.do_command(master_api.activate_eeprom(), { 'eep' : 0 })
        except CommunicationTimedOutException:<commit_msg>Set the automatic response OL bit when master is initialized.<commit_after>'''
The GatewayApi defines high level functions, these are used by the interface
and call the master_api to complete the actions. 

Created on Sep 16, 2012

@author: fryckbos
'''
import logging
LOGGER = logging.getLogger("openmotics")

import time as pytime
from threading import Timer

import master_api
from outputs import OutputStatus
from master_communicator import BackgroundConsumer, CommunicationTimedOutException 

class GatewayApi:
    """ The GatewayApi combines master_api functions into high level functions. """
    
    def __init__(self, master_communicator):
        self.__master_communicator = master_communicator
    
        self.__last_maintenance_send_time = 0
        self.__maintenance_timeout_timer = None
        
        self.__output_status = None
        self.__master_communicator.register_consumer(
                    BackgroundConsumer(master_api.output_list(), 0, self.__update_outputs))
        
        self.init_master()
    
    def init_master(self):
        """ Initialize the master: disable the async RO messages, enable async OL messages. """
        try:
            eeprom_data = self.__master_communicator.do_command(master_api.eeprom_list(),
                { "bank" : 0 })['data']
            
            write = False
            
            if eeprom_data[11] != chr(255):
                LOGGER.info("Disabling async RO messages.")
                self.__master_communicator.do_command(master_api.write_eeprom(),
                    { "bank" : 0, "address": 11, "data": chr(255) })
                write = True
            
            if eeprom_data[18] != chr(0):
                LOGGER.info("Enabling async OL messages.")
                self.__master_communicator.do_command(master_api.write_eeprom(),
                    { "bank" : 0, "address": 18, "data": chr(0) })
                write = True
                
            if write:
                self.__master_communicator.do_command(master_api.activate_eeprom(), { 'eep' : 0 })
            
        except CommunicationTimedOutException:
{'fraction_non_alphanumeric': 0.08293713681986266, 'fraction_numerical': 0.012942419440042261, 'mean_word_length': 2.493542435424354, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4481963', 'n_tokens_mistral': 1080, 'n_tokens_neox': 985, 'n_words': 260}