#
# Generated by erpcgen 1.14.0 on Tue Apr 28 12:25:26 2026.
#
# AUTOGENERATED - DO NOT EDIT
#

import erpc
from . import common, interface

# Client for servo_service
class servo_serviceService(erpc.server.Service):
    def __init__(self, handler):
        super(servo_serviceService, self).__init__(interface.Iservo_service.SERVICE_ID)
        self._handler = handler
        self._methods = {
                interface.Iservo_service.SETCONSTRAINTS_ID: self._handle_setConstraints,
                interface.Iservo_service.SETPOSITIONGAIN_ID: self._handle_setPositionGain,
                interface.Iservo_service.SETMODE_ID: self._handle_setMode,
                interface.Iservo_service.SETUPDATEPERIODMS_ID: self._handle_setUpdatePeriodMs,
                interface.Iservo_service.MOVE_ID: self._handle_move,
                interface.Iservo_service.MOVEJ_ID: self._handle_moveJ,
            }

    def _handle_setConstraints(self, sequence, codec):
        # Read incoming parameters.
        id = codec.read_string()
        max_velocity_rad = codec.read_float()
        max_acceleration_rad = codec.read_float()
        max_jerk_rad = codec.read_float()

        # Invoke user implementation of remote function.
        _result = self._handler.setConstraints(id, max_velocity_rad, max_acceleration_rad, max_jerk_rad)

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

        # Construct reply message.
        codec.start_write_message(erpc.codec.MessageInfo(
            type=erpc.codec.MessageType.kReplyMessage,
            service=interface.Iservo_service.SERVICE_ID,
            request=interface.Iservo_service.SETCONSTRAINTS_ID,
            sequence=sequence))
        codec.write_bool(_result)

    def _handle_setPositionGain(self, sequence, codec):
        # Read incoming parameters.
        id = codec.read_string()
        position_gain = codec.read_float()

        # Invoke user implementation of remote function.
        _result = self._handler.setPositionGain(id, position_gain)

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

        # Construct reply message.
        codec.start_write_message(erpc.codec.MessageInfo(
            type=erpc.codec.MessageType.kReplyMessage,
            service=interface.Iservo_service.SERVICE_ID,
            request=interface.Iservo_service.SETPOSITIONGAIN_ID,
            sequence=sequence))
        codec.write_bool(_result)

    def _handle_setMode(self, sequence, codec):
        # Read incoming parameters.
        mode = codec.read_int32()

        # Invoke user implementation of remote function.
        _result = self._handler.setMode(mode)

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

        # Construct reply message.
        codec.start_write_message(erpc.codec.MessageInfo(
            type=erpc.codec.MessageType.kReplyMessage,
            service=interface.Iservo_service.SERVICE_ID,
            request=interface.Iservo_service.SETMODE_ID,
            sequence=sequence))
        codec.write_bool(_result)

    def _handle_setUpdatePeriodMs(self, sequence, codec):
        # Read incoming parameters.
        ms = codec.read_uint32()

        # Invoke user implementation of remote function.
        _result = self._handler.setUpdatePeriodMs(ms)

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

        # Construct reply message.
        codec.start_write_message(erpc.codec.MessageInfo(
            type=erpc.codec.MessageType.kReplyMessage,
            service=interface.Iservo_service.SERVICE_ID,
            request=interface.Iservo_service.SETUPDATEPERIODMS_ID,
            sequence=sequence))
        codec.write_bool(_result)

    def _handle_move(self, sequence, codec):
        # Read incoming parameters.
        _n0 = codec.start_read_list()
        cmds = []
        for _i0 in range(_n0):
            _v0 = common.ServoCmd()._read(codec)
            cmds.append(_v0)


        # Invoke user implementation of remote function.
        _result = self._handler.move(cmds)

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

        # Construct reply message.
        codec.start_write_message(erpc.codec.MessageInfo(
            type=erpc.codec.MessageType.kReplyMessage,
            service=interface.Iservo_service.SERVICE_ID,
            request=interface.Iservo_service.MOVE_ID,
            sequence=sequence))
        codec.write_int32(_result)

    def _handle_moveJ(self, sequence, codec):
        # Read incoming parameters.
        _n0 = codec.start_read_list()
        angles_rad = []
        for _i0 in range(_n0):
            _v0 = codec.read_float()
            angles_rad.append(_v0)


        # Invoke user implementation of remote function.
        _result = self._handler.moveJ(angles_rad)

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

        # Construct reply message.
        codec.start_write_message(erpc.codec.MessageInfo(
            type=erpc.codec.MessageType.kReplyMessage,
            service=interface.Iservo_service.SERVICE_ID,
            request=interface.Iservo_service.MOVEJ_ID,
            sequence=sequence))
        codec.write_int32(_result)


