# Copyright (c) 2014-2016, Freescale Semiconductor, Inc.
# Copyright 2016 NXP
# All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause

#
# Generated by erpcgen 1.7.3 on Mon Sep 23 13:00:45 2019.
#
# AUTOGENERATED - DO NOT EDIT
#

import erpc
from . import common, interface

# Client for remote_control_app_0
class remote_control_app_0Service(erpc.server.Service):
    def __init__(self, handler):
        super(remote_control_app_0Service, self).__init__(interface.Iremote_control_app_0.SERVICE_ID)
        self._handler = handler
        self._methods = {
                interface.Iremote_control_app_0.GET_BOARD_CONFIG_ID: self._handle_get_board_config,
                interface.Iremote_control_app_0.GET_ADC_CONFIG_ID: self._handle_get_adc_config,
                interface.Iremote_control_app_0.CONVERT_DAC_ADC_ID: self._handle_convert_dac_adc,
                interface.Iremote_control_app_0.READ_MAG_ACCEL_ID: self._handle_read_mag_accel,
                interface.Iremote_control_app_0.SET_LED_ID: self._handle_set_led,
            }

    def _handle_get_board_config(self, sequence, codec):
        # Create reference objects to pass into handler for out/inout parameters.
        config = erpc.Reference()

        # Read incoming parameters.

        # Invoke user implementation of remote function.
        self._handler.get_board_config(config)

        # Prepare codec for reply message.
        codec.reset()

        # Construct reply message.
        codec.start_write_message(erpc.codec.MessageInfo(
            type=erpc.codec.MessageType.kReplyMessage,
            service=interface.Iremote_control_app_0.SERVICE_ID,
            request=interface.Iremote_control_app_0.GET_BOARD_CONFIG_ID,
            sequence=sequence))
        if config.value is None:
            raise ValueError("config is None")
        config.value._write(codec)

    def _handle_get_adc_config(self, sequence, codec):
        # Create reference objects to pass into handler for out/inout parameters.
        config = erpc.Reference()

        # Read incoming parameters.

        # Invoke user implementation of remote function.
        self._handler.get_adc_config(config)

        # Prepare codec for reply message.
        codec.reset()

        # Construct reply message.
        codec.start_write_message(erpc.codec.MessageInfo(
            type=erpc.codec.MessageType.kReplyMessage,
            service=interface.Iremote_control_app_0.SERVICE_ID,
            request=interface.Iremote_control_app_0.GET_ADC_CONFIG_ID,
            sequence=sequence))
        if config.value is None:
            raise ValueError("config is None")
        config.value._write(codec)

    def _handle_convert_dac_adc(self, sequence, codec):
        # Create reference objects to pass into handler for out/inout parameters.
        result = erpc.Reference()

        # Read incoming parameters.
        numberToConvert = codec.read_uint32()

        # Invoke user implementation of remote function.
        self._handler.convert_dac_adc(numberToConvert, result)

        # Prepare codec for reply message.
        codec.reset()

        # Construct reply message.
        codec.start_write_message(erpc.codec.MessageInfo(
            type=erpc.codec.MessageType.kReplyMessage,
            service=interface.Iremote_control_app_0.SERVICE_ID,
            request=interface.Iremote_control_app_0.CONVERT_DAC_ADC_ID,
            sequence=sequence))
        if result.value is None:
            raise ValueError("result is None")
        codec.write_uint32(result.value)

    def _handle_read_mag_accel(self, sequence, codec):
        # Create reference objects to pass into handler for out/inout parameters.
        results = erpc.Reference()
        status = erpc.Reference()

        # Read incoming parameters.

        # Invoke user implementation of remote function.
        self._handler.read_mag_accel(results, status)

        # Prepare codec for reply message.
        codec.reset()

        # Construct reply message.
        codec.start_write_message(erpc.codec.MessageInfo(
            type=erpc.codec.MessageType.kReplyMessage,
            service=interface.Iremote_control_app_0.SERVICE_ID,
            request=interface.Iremote_control_app_0.READ_MAG_ACCEL_ID,
            sequence=sequence))
        if results.value is None:
            raise ValueError("results is None")
        results.value._write(codec)
        if status.value is None:
            raise ValueError("status is None")
        codec.write_bool(status.value)

    def _handle_set_led(self, sequence, codec):
        # Read incoming parameters.
        whichLed = codec.read_uint8()

        # Invoke user implementation of remote function.
        self._handler.set_led(whichLed)


