/*
 * Amazon FreeRTOS V1.4.7
 * Copyright (C) 2018 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * http://aws.amazon.com/freertos
 * http://www.FreeRTOS.org
 */

/**
 * @file aws_mqtt_agent_config.h
 * @brief MQTT agent config options.
 */

#ifndef _AWS_MQTT_AGENT_CONFIG_H_
#define _AWS_MQTT_AGENT_CONFIG_H_

#include "FreeRTOS.h"

/**
 * @brief Controls whether or not to report usage metrics to the
 * AWS IoT broker.
 *
 * If mqttconfigENABLE_METRICS is set to 1, a string containing
 * metric information will be included in the "username" field of
 * the MQTT connect messages.
 */
#define mqttconfigENABLE_METRICS    (1)

/**
 * @brief The maximum time an application task waits for sending a command to the
 * command queue and for receiving a notification from the MQTT task.
 *
 * An application task sends the command to the MQTT task over command queue and
 * then waits for a notification from the MQTT task. In case the MQTT task fails to
 * respond within in a reasonable amount of time, the application task should be
 * informed about the same. This timeout value is the maximum time a task waits for
 * the notification from the MQTT task. This value must be high to ensure that this
 * does not happen under normal operation and when it happens, we should disconnect
 * since we are sharing user provided pointers with the MQTT task which might be
 * invalid now onwards.
 * _TODO_ - Finalize what to do on Timeout.
 */
#define mqttOPERATION_TIMEOUT_MS                      (120000)

/**
 * @brief The maximum time interval in seconds allowed to elapse between 2 consecutive
 * control packets.
 */
#define mqttconfigKEEP_ALIVE_INTERVAL_SECONDS         (100)

/**
 * @brief Defines the frequency at which the client should send Keep Alive messages.
 *
 * Even though the maximum time allowed between 2 consecutive control packets
 * is defined by the mqttconfigKEEP_ALIVE_INTERVAL_SECONDS macro, the user
 * can and should send Keep Alive messages at a slightly faster rate to ensure
 * that the connection is not closed by the server because of network delays.
 * This macro defines the interval of inactivity after which a keep alive messages
 * is sent.
 */
#define mqttconfigKEEP_ALIVE_ACTUAL_INTERVAL_TICKS    (pdMS_TO_TICKS( 300000 ))

/**
 * @brief The maximum interval in ticks to wait for PINGRESP.
 *
 * If PINGRESP is not received within this much time after sending PINGREQ,
 * the client assumes that the PINGREQ timed out.
 */
#define mqttconfigKEEP_ALIVE_TIMEOUT_TICKS            (1000)

/**
 * @defgroup MQTTTask MQTT task configuration parameters.
 */
/** @{ */
//#define mqttconfigMQTT_TASK_STACK_DEPTH    ( configMINIMAL_STACK_SIZE * 4 )
#define mqttconfigMQTT_TASK_STACK_DEPTH    (2048)
#define mqttconfigMQTT_TASK_PRIORITY       (configMAX_PRIORITIES - 3)
/** @} */

/**
 * @brief Maximum number of MQTT clients that can exist simultaneously.
 */
//#define mqttconfigMAX_BROKERS            ( 4 ) //XXX
#define mqttconfigMAX_BROKERS            (2)

/**
 * @brief Maximum number of parallel operations per client.
 */
#define mqttconfigMAX_PARALLEL_OPS       (5)

/**
 * @brief Time in milliseconds after which the TCP send operation should timeout.
 */
#define mqttconfigTCP_SEND_TIMEOUT_MS    (20)
//#define mqttconfigTCP_SEND_TIMEOUT_MS    ( 20 )

/**
 * @brief Length of the buffer used to receive data.
 */
#define mqttconfigRX_BUFFER_SIZE         (1024)

/**
 * @brief The maximum time in ticks for which the MQTT task is permitted to block.
 */
#define mqttconfigMQTT_TASK_MAX_BLOCK_TICKS    (100)

#endif /* _AWS_MQTT_AGENT_CONFIG_H_ */
