/*!
 * \file      LmhPackage.h
 *
 * \brief     Defines the packages API
 *
 * \copyright Revised BSD License, see section \ref LICENSE.
 *
 * \code
 *                ______                              _
 *               / _____)             _              | |
 *              ( (____  _____ ____ _| |_ _____  ____| |__
 *               \____ \| ___ |    (_   _) ___ |/ ___)  _ \
 *               _____) ) ____| | | || |_| ____( (___| | | |
 *              (______/|_____)_|_|_| \__)_____)\____)_| |_|
 *              (C)2013-2018 Semtech
 *
 * \endcode
 *
 * \author    Miguel Luis ( Semtech )
 */
/**
  ******************************************************************************
  *
  *          Portions COPYRIGHT 2020 STMicroelectronics
  *
  * @file    LmhPackage.h
  * @author  MCD Application Team
  * @brief   Header for Package definition API
  ******************************************************************************
  */
#ifndef __LMH_PACKAGE_H__
#define __LMH_PACKAGE_H__

#include <stdint.h>
#include <stdbool.h>
#include "LmHandlerTypes.h"

/*!
 * Maximum number of packages
 */
#define PKG_MAX_NUMBER                              5

typedef struct LmhPackage_s
{
    uint8_t Port;
    /*
     *=========================================================================
     * Below callbacks must be initialized in package variable declaration
     *=========================================================================
     */

    /*!
     * Initializes the package with provided parameters
     *
     * \param [IN] params            Pointer to the package parameters
     * \param [IN] dataBuffer        Pointer to main application buffer
     * \param [IN] dataBufferMaxSize Main application buffer maximum size
     */
    void ( *Init )( void *params, uint8_t *dataBuffer, uint8_t dataBufferMaxSize );
    /*!
     * Returns the current package initialization status.
     *
     * \retval status Package initialization status
     *                [true: Initialized, false: Not initialized]
     */
    bool ( *IsInitialized )( void );
    /*!
     * Returns the package operation status.
     *
     * \retval status Package operation status
     *                [true: Running, false: Not running]
     */
    bool ( *IsRunning )( void );
    /*!
     * Processes the internal package events.
     */
    void ( *Process )( void );
    /*!
     * Notify the LmHandler process through an event
     */
    void ( *OnPackageProcessEvent )( void );
    /*!
     * Processes the MCSP Confirm
     *
     * \param [IN] mcpsConfirm MCPS confirmation primitive data
     */
    void ( *OnMcpsConfirmProcess )( McpsConfirm_t *mcpsConfirm );
    /*!
     * Processes the MCPS Indication
     *
     * \param [IN] mcpsIndication     MCPS indication primitive data
     */
    void ( *OnMcpsIndicationProcess )( McpsIndication_t *mcpsIndication );
    /*!
     * Processes the MLME Confirm
     *
     * \param [IN] mlmeConfirm MLME confirmation primitive data
     */
    void ( *OnMlmeConfirmProcess )( MlmeConfirm_t *mlmeConfirm );

    /*
     *=========================================================================
     * Below callbacks must be initialized in LmHandler initialization with
     * provideded LmHandlerSend and OnMacRequest functions
     *=========================================================================
     */

    /*!
    * Join a LoRa Network in classA
    *
    * \Note if the device is ABP, this is a pass through function
    * 
    * \param [IN] isOtaa Indicates which activation mode must be used
    */
    void ( *OnJoinRequest )( ActivationType_t mode );
    /*!
     * Instructs the MAC layer to send a ClassA uplink
     *
     * \param [IN] appData Data to be sent
     * \param [IN] isTxConfirmed Indicates if the uplink requires an acknowledgement
     *
     * \retval status Returns \ref LORAMAC_HANDLER_SUCCESS if request has been
     *                processed else \ref LORAMAC_HANDLER_ERROR
     */
    LmHandlerErrorStatus_t ( *OnSendRequest )( LmHandlerAppData_t *appData, LmHandlerMsgTypes_t isTxConfirmed, TimerTime_t *nextTxIn, bool allowDelayedTx );
    /*!
    * Requests network server time update
    *
    * \retval status Returns \ref LORAMAC_HANDLER_SET if joined else \ref LORAMAC_HANDLER_RESET
    */
    LmHandlerErrorStatus_t ( *OnDeviceTimeRequest )( void );
    /*!
     * Notifies the upper layer that the system time has been updated.
     */
    void ( *OnSysTimeUpdate )( void );
}LmhPackage_t;

#endif // __LMH_PACKAGE_H__
