Ejemplo n.º 1
0
    def process(mc_request, mc_response):
        # print('Inside process Method of Micro-controller Interface Class')
        logg = PyLogs(__name__).get_pylogger()
        logg.info('Inside process Method of Micro-controller Interface Class')
        socket_context = mc_request.socket_context

        mc_param_obj = MicroParameters()
        ref_device_param = None
        ref_device_state = None
        ref_device_type_id2states = None
        ref_mc_param = None
        ref_mc_signal = None
        device_signal = None
        device_state_signal = None
        module_signal = None
        # noinspection PyBroadException
        try:
            """
                Loading Device Parameters
            """
            logg.info('Loading Device Params')
            device_param_file = mc_param_obj.get_device_params_file_name()
            ref_device_param = loadparamfile.LoadParamsFile(device_param_file)
            print(ref_device_param)

            """
                Loading Device Type States Parameters
            """
            logg.info('Loading Device Type States Parameters')
            device_state_file = mc_param_obj.get_device_states_file_name()
            ref_device_state = loadparamfile.LoadParamsFile(device_state_file)
            print(ref_device_state)

            """
                Loading Device Type Parameters
            """
            logg.info('Loading Device Type Parameters')
            device_type_id2states_file = mc_param_obj.get_device_type_id2states_file_name()
            ref_device_type_id2states = loadparamfile.LoadParamsFile(device_type_id2states_file)
            print(ref_device_type_id2states)

            """
                Loading MicroController Parameters
            """
            logg.info('Loading MicroController Parameters')
            mc_param_file = mc_param_obj.get_microcontroller_params_file_name()
            ref_mc_param = loadparamfile.LoadParamsFile(mc_param_file)
            print(ref_mc_param)

            """
                Loading MicroController Hardware Signals Parameters
            """
            logg.info('Loading MicroController Hardware Signals Parameters')
            mc_signal_file = mc_param_obj.get_microcontroller_signals_file_name()
            ref_mc_signal = loadparamfile.LoadParamsFile(mc_signal_file)
            print(ref_mc_signal)
        except ValueError as mc_error_msg:
            error_source = "process method in Executor of MicroController"
            error_type = mc_error_msg.__class__.__name__
            error_msg = "ValueError, params file load error"
            logg.error('Param files load error, Reason: ' + error_type)
            process_failure(error_source, error_type, error_msg, socket_context, logg)
        except TypeError as mc_error_msg:
            error_source = "process method in Executor of MicroController"
            error_type = mc_error_msg.__class__.__name__
            error_msg = "TypeError, param file load error"
            logg.error('Param files load error, Reason: ' + error_type)
            process_failure(error_source, error_type, error_msg, socket_context, logg)
        except EOFError as mc_error_msg:
            error_source = "process method in Executor of MicroController"
            error_type = mc_error_msg.__class__.__name__
            error_msg = "EOFError, params file is empty"
            logg.error('Param files load error, Reason: ' + error_type)
            process_failure(error_source, error_type, error_msg, socket_context, logg)
        except IOError as mc_error_msg:
            error_source = "process method in Executor of MicroController"
            error_type = mc_error_msg.__class__.__name__
            error_msg = "IOError, loding param file error"
            logg.error('Param files load error, Reason: ' + error_type)
            process_failure(error_source, error_type, error_msg, socket_context, logg)
        except AttributeError as mc_error_msg:
            error_source = "process method in Executor of MicroController"
            error_type = mc_error_msg.__class__.__name__
            error_msg = "AttributeError while Fetching param files"
            logg.error('Param files load error, Reason: ' + error_type)
            process_failure(error_source, error_type, error_msg, socket_context, logg)
        except:
            error_source = "process method in Executor of MicroController"
            error_type = sys.exc_info()[0].__name__
            error_msg = "Unexpected Error while Fetching params files"
            logg.error('Param files load error, Reason: ' + error_type)
            process_failure(error_source, error_type, error_msg, socket_context, logg)

        # noinspection PyBroadException
        try:
            """
                Fetching Device Type Id, Module Id(MicroController Id) and Device
                Signal Id for Further Processing
            """
            device_type_id = mc_param_obj.get_device_type_id(mc_request.device_id, ref_device_param)
            module_id = mc_param_obj.get_micontroller_id(mc_request.device_id, ref_device_param)
            print('data is: {} : {} '.format(device_type_id, module_id))

            """
                Now Fetching Device Type States IDs and Signal IDs for Device,
                Device States and MicrController
            """
            device_signal_id = mc_param_obj.get_device_signal_id(mc_request.device_id, ref_device_param)
            device_type_state_id = mc_param_obj.get_device_type_state_id(device_type_id, ref_device_type_id2states)
            device_state_signal_id = mc_param_obj.get_devcie_state_signal_id(device_type_state_id,
                                                                             mc_request.desired_device_state,
                                                                             ref_device_state)
            module_signal_id = mc_param_obj.get_microcontroller_signal_id(module_id, ref_mc_param)

            """
                Finally Fetching Hardware Triggering MicrController Signal for device,
                Device state and MicroController
            """
            device_signal = mc_param_obj.get_hex_device_id_signal(device_signal_id, ref_mc_signal)
            device_state_signal = mc_param_obj.get_hex_device_state_signal(device_state_signal_id, ref_mc_signal)
            module_signal = mc_param_obj.get_hex_microcontroller_signal(module_signal_id, ref_mc_signal)
        except ValueError as mc_error_msg:
            error_source = "process method in Executor of MicroController"
            error_type = mc_error_msg.__class__.__name__
            error_msg = "ValueError, params file load error"
            logg.error('Param files fetch value error, Reason: ' + error_type)
            process_failure(error_source, error_type, error_msg, socket_context, logg)
        except TypeError as mc_error_msg:
            error_source = "process method in Executor of MicroController"
            error_type = mc_error_msg.__class__.__name__
            logg.error('Param files fetch value error, Reason: ' + error_type)
            error_msg = "TypeError, param file load error"
            process_failure(error_source, error_type, error_msg, socket_context, logg)
        except KeyError as mc_error_msg:
            error_source = "process method in Executor of MicroController"
            error_type = mc_error_msg.__class__.__name__
            error_msg = "KeyError, param file load error"
            logg.error('Param files fetch value error, Reason: ' + error_type)
            process_failure(error_source, error_type, error_msg, socket_context, logg)
        except IndexError as mc_error_msg:
            error_source = "process method in Executor of MicroController"
            error_type = mc_error_msg.__class__.__name__
            error_msg = "IndexError, param file load error"
            logg.error('Param files fetch value error, Reason: ' + error_type)
            process_failure(error_source, error_type, error_msg, socket_context, logg)
        except EOFError as mc_error_msg:
            error_source = "process method in Executor of MicroController"
            error_type = mc_error_msg.__class__.__name__
            error_msg = "EOFError, params file is empty"
            logg.error('Param files fetch value error, Reason: ' + error_type)
            process_failure(error_source, error_type, error_msg, socket_context, logg)
        except IOError as mc_error_msg:
            error_source = "process method in Executor of MicroController"
            error_type = mc_error_msg.__class__.__name__
            error_msg = "IOError, loding param file error"
            logg.error('Param files fetch value error, Reason: ' + error_type)
            process_failure(error_source, error_type, error_msg, socket_context, logg)
        except AttributeError as mc_error_msg:
            error_source = "process method in Executor of MicroController"
            error_type = mc_error_msg.__class__.__name__
            error_msg = "AttributeError while Fetching param files"
            logg.error('Param files fetch value error, Reason: ' + error_type)
            process_failure(error_source, error_type, error_msg, socket_context, logg)
        except:
            error_source = "process method in Executor of MicroController"
            error_type = sys.exc_info()[0].__name__
            error_msg = "Unexpected Error while Fetching params files"
            logg.error('Param files fetch value error, Reason: ' + error_type)
            process_failure(error_source, error_type, error_msg, socket_context, logg)

        """
            Passing These Control Signals To MicroController Module for Hardware
            Processing(Calling Send data Function to Send signal to MicroController)
            Write Response of MicroController in Response Class for Further Decision
            Making
        """
        # noinspection PyBroadException
        try:
            logg.info('Passing Control Signals to Micro-controller')
            mc_obj = Microcontroller(device_signal, device_state_signal, module_signal)
            mc_obj.send_data()
        except:
            error_source = "process method in Executor of MicroController"
            error_type = sys.exc_info()[0].__name__
            error_msg = "Unexpected Error while Hardware Processing"
            logg.error('Error while Hradware Processing, Reason: ' + error_type)
            process_failure(error_source, error_type, error_msg, socket_context, logg)

        """
            For Time being HardCoded Positive Acknowledgement have been
            sent back.
            At time of actual Processing, please change Accordingly
        """
        logg.info('Returning Positivve Response from Mixro-Controller Module to Service')
        mc_response.response_message = "OK"
        return mc_response
Ejemplo n.º 2
0
 def process_exception(self):
     # print('Inside process_exception method of ReqParserException')
     logg = PyLogs(__name__).get_pylogger()
     logg.error('Inside process_exception method of ReqParserException')
     self.trigger_response(logg)