# -*- coding: utf-8 -*-
"""
    Implementation of RCON protocol init command

Copyright 2024 NXP
SPDX-License-Identifier: BSD-3-Clause

"""

import gdb   # @UnresolvedImport  # pylint: disable=F0401
import argparse
import binascii
import importlib

from rcon.gdbcommands.base_command import RconBase
from rcon.gdbcommands.cmd_name import CMD_RCON_INIT

###################################################################
######### RCON protocol init command
###################################################################
class RconInit(RconBase):
    """
usage: Initialize RCON communication protocol. [-h] No parameters.

S32DS RCON protocol Init.

    """

    def __init__(self):
        """
            Register new command with GDB
        """
        super(RconInit, self).__init__(CMD_RCON_INIT,
        gdb.COMMAND_USER, gdb.COMPLETE_FILENAME)
        parser = argparse.ArgumentParser(usage='[-h]',
                                         description='S32DS \
                                         S32DS RCON communication protocol Init command.')
        self._parser = parser

    def execute(self, args):
        #execute command
        RCON.RCON_PROTOCOL_INIT()

    def begin_command(self):
       gdb.write('Initializing communication protocol....\n')

    def end_command(self):
       gdb.write('Ending Initializing communication protocol....\n')

def create_command(RCONfilePath):
    """
        Instantiate RCON protocol Init command
    """
    global RCON 
    RCON = importlib.import_module(RCONfilePath[:-3])
    RconInit()
