/*! * \file msg_impl.h * * Contain all the implementation specific types * * \author: Christos Choutouridis 8997 */ #ifndef __msg_impl__ #define __msg_impl__ #include #include #include #include /*! * General options */ //! @{ #define LISTENER_PORT 2288 //!< The server port #define MSG_TEXT_SIZE 256 //!< Maximum size of each message #define MSG_LIST_SIZE 2000 //!< Maximum size of message history buffer #define DEVICE_LIST_SIZE 100 //!< Maximum size of the device list #define MSG_DELIMITER '_' //!< Message delimiter #define ADHOC_NET_A 10 //!< [A.B.C.D] #define ADHOC_NET_B 0 #define ADHOC_NET_C 0 #define ADHOC_NET_D 0 //#define NO_DEBUG 1 //! @} /*! * Helper macros */ #define _MK_ADHOC_SUBNET(A, B, C, D) (((A)<<24) | ((B)<<16) | ((C)<<8) | (D)) #define _adhoc_subnet _MK_ADHOC_SUBNET(ADHOC_NET_A, ADHOC_NET_B, ADHOC_NET_C, ADHOC_NET_D) /*! * Messenger types */ //! @{ /*! * Application status type */ typedef enum { MSG_OK =0, //!< Indicate success MSG_ERROR //!< Indicate error } status_t; typedef bool bool_t; //!< Boolean type typedef char char_t; //!< Application wide character type typedef uint32_t aem_t; //!< AEM data type typedef int64_t tstamp_t; //!< UNIX time in 64 bit wide signed integer /*! * IP wrapper type */ typedef struct { uint16_t A, B, C, D; }devIP_t; /*! * A RTES node device representation * \note * Objects of this type are also acting as fwd list nodes. */ typedef struct device { aem_t id; //!< AEM of the device struct device* next; //!< link to the next linked device on the chain } device_t; typedef device_t* devList_t; //!< device list alias /*! * \brief * Core message representation as it described in the requirements * * Object of this type constructed upon creation or when receiving a message. * \note * associate functions -- mutable-like interface: * \sa cMsg_parse() used for parsing and creation * \sa cMsg_getFromAEM() used as fromAEM getter * \sa cMsg_getToAEM() used as toAEM getter * \sa cMsg_getTs() used as timestamp getter * \sa cMsg_getText() used as text getter */ typedef struct { aem_t from; //!< sender's AEM aem_t to; //!< destination AEM tstamp_t ts; //!< UNIX timestamp compatible size_t text; //!< text offset char_t msg[MSG_TEXT_SIZE]; //!< The actual message stream } cMsg_t; /*! * \brief * Mid and application layer message representation * * This type */ typedef struct { device_t sender; //!< The sender's device devList_t recipients; //!< List of all devices the message has reach cMsg_t cMsg; //!< actual message payload } msg_t; typedef int32_t mIter_t; //!< message list iterator type /*! * \brief Message list * * This holds the last \a MSG_LIST_SIZE messages exchanged from this * device(including the ones we have create). * * With this we create a 2 dimensional map of msg/dev where each item * of the list is linked with all the devices reached by us as a fwd-list. * The items on the msgList are: * - Messages we create * - Messages received by the listener * * Here we define 2 directions for iteration. The message direction and the device * direction. * * Every node on the msgList.m array represents a message. Every node in the device * list inside msgList[m].recipients represent devices we don't anymore need to send * the current message to them. * * Layout example: * * msgList.m * [ 0 ] --> [devx] --> [devy] -- >0 * | [ 1 ] --> [devy] -- > 0 * time | [ 2 ] --> 0 * [*1] | [ 3 ] ... * \|/ * ... * * [MAX] * * [*1]: msgList is actually implemented as a ring buffer so in that * content, "time is a loop". */ typedef struct { msg_t m[MSG_LIST_SIZE]; //!< The actual data representation mIter_t last; //!< A ring buffer iterator marking the last item on .m size_t size; } msgList_t; //! @} /*! * Client types */ //! @{ #define PING_PKT_S (64) #define PING_MSG_S (PING_PKT_S - sizeof(struct icmphdr)) typedef struct { struct icmphdr hdr; char msg[PING_MSG_S]; }ping_pkt_t; //! @} /*! * Application settings */ //! @{ typedef enum { OUTLEVEL_0, //!< Output only results [default] OUTLEVEL_1, //!< Output results and every message also OUTLEVEL_2 //!< Debug level, use with care! }outLevel_en; typedef struct { uint16_t port; time_t duration; time_t msgInterval; outLevel_en outLevel; }settings_t; extern settings_t settings; #define settings_init(s) s = { \ .port = 2288, \ .duration = 7200, \ .msgInterval = 60, \ .outLevel = OUTLEVEL_1 \ } //! @} #endif /* __msg_impl__ */