From cabb90c1240015ee5cd17d91573588527bcc2482 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C5=ABnas=20Ma=C5=BEeikis?= Date: Tue, 21 May 2019 17:41:21 +0300 Subject: Protocol: changes to interface and some re-implementation. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Most functions exposed in protocol.h take a connection descriptor (cd_t) as first argument. This allows for multiple connections. Device gets only one connection which means that cd_t is effectively 0 all the time. Additionaly, any function that actually does anything with a connection descriptor instead of just passing it to another function must be implemented separately in device and daemon. Signed-off-by: Ramūnas Mažeikis --- include/protocol.h | 58 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 15 deletions(-) (limited to 'include/protocol.h') diff --git a/include/protocol.h b/include/protocol.h index ac83154..60d31ea 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -23,15 +23,28 @@ #include -#define E_TLV_OVERFLOW (1 << 0) -#define E_UNKNOWN_TYPE (1 << 1) +#define E_TLV_OVERFLOW (1 << 0) +#define E_UNKNOWN_TYPE (1 << 1) +#define E_IVALID_DESCRIPTOR (1 << 2) +/** + * Regular packets contain tlv's defined by tlv_type. + * + * Hearbeat packet tell daemon that device is still alive and listening. + * + * Discovery packets are used for what they say. + */ enum packet_type { REGURAL, HEARTBEAT, DISCOVERY }; +/** + * Connection descriptor. + */ +typedef unsigned int cd_t; + /** * Message sequence number since beggining of sesssion. * @@ -40,13 +53,16 @@ enum packet_type { typedef unsigned int msg_idx_t; enum tlv_type { - /** NULL-terminated string. */ + /** + * NULL-terminated string. To be put in a queue to display on the + * screen. + */ TEXT, /** Fixed point. 1 decimal digit of precision. */ FPI1, - /** Literally time_t*/ + /** Literally time_t */ TIMESTAMP, /** Represents a request for lost message. Data is unsigned integer @@ -54,51 +70,63 @@ enum tlv_type { */ REQUEST, - /** Response to request. Begins with unsigned integer that represents + /** + * Response to request. Begins with unsigned integer that represents * which message is being repeated and the actual null-terminated * message after that. */ REPLY, - /** UUID that represents a particular device. + /** + * UUID that represents a particular device. */ UUID }; +/** + * Packet data itself is a special type of tlv. A packet is either regular, + * hearbeat or discovery. + */ struct packet_data { enum packet_type type; size_t packet_size; char *data; /* Bytes representing tlv's */ }; +/** + * Literally type-length-value + * */ struct tlv { enum tlv_type type; size_t length; void *data; }; -/* +/** * Reads last packets received, parses and stores them to be later retreived * via get_tlv. * */ -void get_last_data(void); +void get_last_data(cd_t connection); -/* Returns tlv's parsed by get_last_data. Returned tlv is only valid until +/** Returns tlv's parsed by get_last_data. Returned tlv is only valid until * next call to get_tlv. * */ struct tlv * get_tlv(void); -/* Any modifications made to the pending outgoing packet are nullified. +/** + * Any modifications made to the pending outgoing packet are nullified. * */ -void clear_data(void); +void clear_data(cd_t connection); -/* Appends data to the next packet to be sent. Type of data is determined by +/** + * Appends data to the next packet to be sent. Type of data is determined by * enum tlv_type. * */ -int push_data(const char *data, enum tlv_type); +int push_data(cd_t connection, const char *data, enum tlv_type); -/* Sends packet towards the other end. +/** + * Sends packet towards the other end. * */ -void flush_data(void); +void flush_data(cd_t connection); #endif /* PROTOCOL_H_INCLUDED */ -- cgit v1.2.3