/*
 * lib60870_config.h
 */

#ifndef CONFIG_LIB60870_CONFIG_H_
#define CONFIG_LIB60870_CONFIG_H_


/* print debugging information with printf if set to 1 */
#define CONFIG_DEBUG_OUTPUT 0

/**
 * Configure CS104 slave to allocate memory from static memory pool (don't use dynamic memory)
 *
 * Note: This setting will create different memory pools for objects like client connections,
 * ASDU queues, and slave instances. The following settings have to be defined also:
 * - \ref CONFIG_CS104_SLAVE_POOL_SIZE (number of slave instances)
 * - \ref CONFIG_CS104_MESSAGE_QUEUE_POOL_SIZE (message queue pool size)
 * - \ref CONFIG_CS104_MESSAGE_QUEUE_SIZE (size of ASDU message queue)
 * - \ref CONFIG_CS104_MESSAGE_QUEUE_HIGH_PRIO_SIZE (size of high priority message queue)
 * - \ref CONFIG_CS104_MAX_K_BUFFER_SIZE (size of k-buffer - restricts the maximum value of the k parameter!)
 *
 */
#define CONFIG_CS104_SLAVE_POOL 0

/**
 * Define the number of slave instances that are available in the pool
 */
#define CONFIG_CS104_SLAVE_POOL_SIZE 1

/**
 * Define the number of message queues in the pool to be shared between different slaves
 */
#define CONFIG_CS104_MESSAGE_QUEUE_POOL_SIZE 1

/**
 * Define the default size for the slave (outstation) message queue. This is used also
 * to buffer ASDUs in the case when the connection is lost.
 *
 * For each queued message about 256 bytes of memory are required.
 */
#define CONFIG_CS104_MESSAGE_QUEUE_SIZE 100

/**
 * This is a connection specific ASDU queue for the slave (outstation). It is used for connection
 * specific ASDUs like those that are automatically generated by the stack or created in
 * the slave side callback. The messages in the queue are removed when the connection is lost.
 *
 * For each queued message about 256 bytes of memory are required.
 */
#define CONFIG_CS104_MESSAGE_QUEUE_HIGH_PRIO_SIZE 50

/**
 * \brief This parameter restricts the k-buffer size when \ref CONFIG_CS104_SLAVE_POOL is enabled
 *
 * The actual size of the k-buffer (corresponding to the APCI parameter k) is defined by the runtime parameter.
 * However the runtime parameter is restricted to the maximum of this value.
 */
#define CONFIG_CS104_MAX_K_BUFFER_SIZE 30

/**
 * Compile the library to use threads. This will require semaphore support
 */
#define CONFIG_USE_THREADS 1

/**
 * Compile the library using semaphore to protect critical objects.
 * Required when CONFIG_USE_THREADS = 1.
 */
#define CONFIG_USE_SEMAPHORES 1

/**
 * Use a separate thread to call the callback functions. This allows the user
 * to have a more natural program flow in the callback function. Otherwise callback
 * functions have to return immediately and send functions called from the callback
 * may not work when the send message queue is full.
 */
#define CONFIG_SLAVE_USE_SEPARATE_CALLBACK_THREAD 0

/**
 * Queue to store received ASDUs before passing them to the user provided callback.
 */
#define CONFIG_SLAVE_SEPARATE_CALLBACK_THREAD_QUEUE_SIZE 12



/**
 * Compile library with support for SINGLE_REDUNDANCY_GROUP server mode (only CS104 server)
 */
#define CONFIG_CS104_SUPPORT_SERVER_MODE_SINGLE_REDUNDANCY_GROUP 1

/**
 * Compile library with support for MULTIPLE_REDUNDANCY_GROUPS server mode (only CS104 server)
 */
#define CONFIG_CS104_SUPPORT_SERVER_MODE_MULTIPLE_REDUNDANCY_GROUPS 1

/**
 * Compile library with support for CONNECTION_IS_REDUNDANCY_GROUP server mode (only CS104 server)
 */
#define CONFIG_CS104_SUPPORT_SERVER_MODE_CONNECTION_IS_REDUNDANCY_GROUP 1

/**
 * Set the maximum number of client connections
 */
#define CONFIG_CS104_MAX_CLIENT_CONNECTIONS 5

/* activate TCP keep alive mechanism. 1 -> activate */
#define CONFIG_ACTIVATE_TCP_KEEPALIVE 0

/* time (in s) between last message and first keepalive message */
#define CONFIG_TCP_KEEPALIVE_IDLE 5

/* time between subsequent keepalive messages if no ack received */
#define CONFIG_TCP_KEEPALIVE_INTERVAL 2

/* number of not missing keepalive responses until socket is considered dead */
#define CONFIG_TCP_KEEPALIVE_CNT 2


#endif /* CONFIG_LIB60870_CONFIG_H_ */
