From d75ac2652028cc52c400d555e830b8c32bc47ad8 Mon Sep 17 00:00:00 2001 From: chad-iris Date: Tue, 18 Feb 2020 08:58:10 -0800 Subject: [PATCH] Start inline documentation --- ChangeLog | 4 + libslink.h | 546 ++++++++++++++++++++++++++++------------------------- 2 files changed, 293 insertions(+), 257 deletions(-) diff --git a/ChangeLog b/ChangeLog index c90c9b3..ac77d06 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2020.048: + - Support M SEED quality code. + - Fix segfault in sl_msr_print() when no record passed. + 2020.047: - Determine received record length automatically, a pre-determined record length is no longer needed. diff --git a/libslink.h b/libslink.h index a97a452..1a0b16a 100644 --- a/libslink.h +++ b/libslink.h @@ -31,6 +31,13 @@ extern "C" { #define LIBSLINK_VERSION "2.7.0" /**< libslink version */ #define LIBSLINK_RELEASE "2020.046" /**< libslink release date */ +/** @defgroup seedlink-connection SeedLink Connection */ +/** @defgroup connection-state Connection State */ +/** @defgroup logging Central Logging */ +/** @defgroup miniseed-record miniSEED Records */ +/** @defgroup utility-functions General Utility Functions */ + + /* Portability to the XScale (ARM) architecture requires a packed * attribute in certain places but this only works with GCC for now. */ #if defined (__GNUC__) @@ -47,10 +54,6 @@ extern "C" { #include #include -/** @def PRIsize_t - @brief A printf() macro for portably printing size_t values */ -#define PRIsize_t "zu" - #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) #define SLP_WIN 1 #endif @@ -63,14 +66,6 @@ extern "C" { #include #include - /* Re-define print conversion for size_t values */ - #undef PRIsize_t - #if defined(WIN64) || defined(_WIN64) - #define PRIsize_t "I64u" - #else - #define PRIsize_t "I32u" - #endif - /* For MSVC 2012 and earlier define standard int types, otherwise use inttypes.h */ #if defined(_MSC_VER) && _MSC_VER <= 1700 typedef signed char int8_t; @@ -129,62 +124,253 @@ extern "C" { #endif -/** @def SOCKET - @brief Use int for SOCKET if platform includes have not defined it */ +/* Use int for SOCKET if not already defined */ #ifndef SOCKET +/** @def SOCKET + @brief A portable type for a socket descriptor */ #define SOCKET int #endif +/** @addtogroup logging + @brief Central logging functions for the library and calling programs + + This central logging facility is used for all logging performed by + the library. + + The logging can be configured to send messages to arbitrary + functions, referred to as \c log_print() and \c diag_print(). + This allows output to be re-directed to other logging systems if + needed. + + It is also possible to assign prefixes to log messages for + identification, referred to as \c logprefix and \c errprefix. + + @anchor logging-levels + Three message levels are recognized: + - 0 : Normal log messages, printed using \c log_print() with \c logprefix + - 1 : Diagnostic messages, printed using \c diag_print() with \c logprefix + - 2+ : Error messages, printed using \c diag_print() with \c errprefix + + It is the task of the \c sl_log(), \c sl_ms_log_l(), and + \c sl_ms_log_rl() functions to format a message using printf + conventions and pass the formatted string to the appropriate + printing function. + + @{ */ + +/** @brief Logging parameters */ +typedef struct SLlog_s +{ + void (*log_print) (); /**< Log message printing function */ + const char *logprefix; /**< Log message message prefix */ + void (*diag_print) (); /**< Warning & error message printing function */ + const char *errprefix; /**< Warning & error message prefix */ + int verbosity; /**< Logging verbosity */ +} SLlog; +/** @} */ + +/** @addtogroup seedlink-connection + @brief Definitions and functions related to SeedLink connections + @{ */ + #define SL_DEFAULT_HOST "localhost" /**< Default host for libslink */ #define SL_DEFAULT_PORT "18000" /**< Default port for libslink */ - -#define SLRECSIZEMIN 48 /* Min supported miniSEED record size */ -#define SLRECSIZEMAX 4096 /* Max supported miniSEED record size */ -#define SLRECSIZE 512 /* Default miniSEED record size */ -#define MAX_HEADER_SIZE 128 /* Max record header size */ -#define SLHEADSIZE 8 /* SeedLink header size */ -#define SELSIZE 8 /* Maximum selector size */ -#define BUFSIZE 8192 /* Size of receiving buffer */ -#define SIGNATURE "SL" /* SeedLink header signature */ -#define INFOSIGNATURE "SLINFO" /* SeedLink INFO packet signature */ -#define MAX_LOG_MSG_LENGTH 200 /* Maximum length of log messages */ +#define SLRECSIZEMIN 48 /**< Min supported miniSEED record size */ +#define SLRECSIZEMAX 4096 /**< Max supported miniSEED record size */ +#define SLRECSIZE 512 /**< Default miniSEED record size */ +#define MAX_HEADER_SIZE 128 /**< Max record header size */ +#define SLHEADSIZE 8 /**< SeedLink header size */ +#define SELSIZE 8 /**< Maximum selector size */ +#define BUFSIZE 8192 /**< Size of receiving buffer */ +#define SIGNATURE "SL" /**< SeedLink header signature */ +#define INFOSIGNATURE "SLINFO" /**< SeedLink INFO packet signature */ +#define MAX_LOG_MSG_LENGTH 200 /**< Maximum length of log messages */ /* Return values for sl_collect() and sl_collect_nb() */ -#define SLPACKET 1 -#define SLTERMINATE 0 -#define SLNOPACKET -1 +#define SLPACKET 1 /**< sl_collect()/sl_collect_nb() return value when SLpacket is returned */ +#define SLTERMINATE 0 /**< sl_collect()/sl_collect_nb() return value on connection termination or error */ +#define SLNOPACKET -1 /**< sl_collect_nb() return value when no packet is available */ /* SeedLink packet types */ -#define SLDATA 0 /* waveform data record */ -#define SLDET 1 /* detection record */ -#define SLCAL 2 /* calibration record */ -#define SLTIM 3 /* timing record */ -#define SLMSG 4 /* message record */ -#define SLBLK 5 /* general record */ -#define SLNUM 6 /* used as the error indicator (same as SLCHA) */ -#define SLCHA 6 /* for requesting channel info or detectors */ -#define SLINF 7 /* a non-terminating XML formatted message in a miniSEED - log record, used for INFO responses */ -#define SLINFT 8 /* a terminating XML formatted message in a miniSEED log - record, used for INFO responses */ -#define SLKEEP 9 /* an XML formatted message in a miniSEED log - record, used for keepalive/heartbeat responses */ +#define SLDATA 0 /**< SeedLink packet: waveform data record */ +#define SLDET 1 /**< SeedLink packet: detection record */ +#define SLCAL 2 /**< SeedLink packet: calibration record */ +#define SLTIM 3 /**< SeedLink packet: timing record */ +#define SLMSG 4 /**< SeedLink packet: message record */ +#define SLBLK 5 /**< SeedLink packet: general record */ +#define SLNUM 6 /**< SeedLink packet: used as the error indicator (same as SLCHA) */ +#define SLCHA 6 /**< SeedLink packet: for requesting channel info or detectors */ +#define SLINF 7 /**< SeedLink packet: a non-terminating XML formatted message in a miniSEED + log record, used for INFO responses */ +#define SLINFT 8 /**< SeedLink packet: a terminating XML formatted message in a miniSEED log + record, used for INFO responses */ +#define SLKEEP 9 /**< SeedLink packet: an XML formatted message in a miniSEED log + record, used for keepalive/heartbeat responses */ /* The station and network code used for uni-station mode */ -#define UNISTATION "UNI" -#define UNINETWORK "XX" +#define UNISTATION "UNI" /**< Station code for uni-station mode */ +#define UNINETWORK "XX" /**< Network code for uni-station mode */ + +/** @brief SeedLink packet */ +typedef struct slpacket_s +{ + char *slhead; /**< SeedLink header */ + char *msrecord; /**< miniSEED record */ + int reclen; /**< miniSEED record length */ +} SLpacket; + +/** @brief Stream information */ +typedef struct slstream_s +{ + char *net; /**< The network code */ + char *sta; /**< The station code */ + char *selectors; /**< SeedLink style selectors for this station */ + int seqnum; /**< SeedLink sequence number for this station */ + char timestamp[30]; /**< Time stamp of last packet received */ + struct slstream_s *next; /**< The next station in the chain */ +} SLstream; + +/** @brief Persistent connection state information */ +typedef struct stat_s +{ + char databuf[BUFSIZE]; /**< Data buffer for received packets */ + int recptr; /**< Receive pointer for databuf */ + int sendptr; /**< Send pointer for databuf */ + SLpacket slpack; /**< Transient, client-specific SLPacket pointers */ + int8_t expect_info; /**< Do we expect an INFO response? */ + + int8_t netto_trig; /**< Network timeout trigger */ + int8_t netdly_trig; /**< Network re-connect delay trigger */ + int8_t keepalive_trig; /**< Send keepalive trigger */ + + double netto_time; /**< Network timeout time stamp */ + double netdly_time; /**< Network re-connect delay time stamp */ + double keepalive_time; /**< Keepalive time stamp */ + + enum /**< Connection state */ + { + SL_DOWN, SL_UP, SL_DATA + } + sl_state; + + enum /**< INFO query state */ + { + NoQuery, InfoQuery, KeepAliveQuery + } + query_mode; + +} SLstat; + +/** @brief SeedLink connection description */ +typedef struct slcd_s +{ + SLstream *streams; /**< Pointer to stream chain (a linked list of structs) */ + char *sladdr; /**< The host:port of SeedLink server */ + char *begin_time; /**< Beginning of time window */ + char *end_time; /**< End of time window */ + + int8_t resume; /**< Boolean flag to control resuming with seq. numbers */ + int8_t multistation; /**< Boolean flag to indicate multistation mode */ + int8_t dialup; /**< Boolean flag to indicate dial-up mode */ + int8_t batchmode; /**< Batch mode (1 - requested, 2 - activated) */ + int8_t lastpkttime; /**< Boolean flag to control last packet time usage */ + int8_t terminate; /**< Boolean flag to control connection termination */ + + int keepalive; /**< Interval to send keepalive/heartbeat (secs) */ + int iotimeout; /**< Timeout for network I/O operations (seconds) */ + int netto; /**< Network timeout (secs) */ + int netdly; /**< Network reconnect delay (secs) */ + + float protocol_ver; /**< Version of the SeedLink protocol in use */ + const char *info; /**< INFO level to request */ + SOCKET link; /**< The network socket descriptor */ + SLstat *stat; /**< Persistent state information */ + SLlog *log; /**< Logging parameters */ +} SLCD; + +extern int sl_collect (SLCD *slconn, SLpacket **slpack); +extern int sl_collect_nb (SLCD *slconn, SLpacket **slpack); +extern int sl_collect_nb_size (SLCD *slconn, SLpacket **slpack, int maxrecsize); +extern SLCD *sl_newslcd (void); +extern void sl_freeslcd (SLCD *slconn); +extern int sl_addstream (SLCD *slconn, const char *net, const char *sta, + const char *selectors, int seqnum, + const char *timestamp); +extern int sl_setuniparams (SLCD *slconn, const char *selectors, + int seqnum, const char *timestamp); +extern int sl_request_info (SLCD *slconn, const char *infostr); +extern int sl_sequence (const SLpacket *); +extern int sl_packettype (const SLpacket *); +extern void sl_terminate (SLCD *slconn); + +extern int sl_read_streamlist (SLCD *slconn, const char *streamfile, + const char *defselect); +extern int sl_parse_streamlist (SLCD *slconn, const char *streamlist, + const char *defselect); + +extern int sl_configlink (SLCD *slconn); +extern int sl_send_info (SLCD *slconn, const char *info_level, + int verbose); +extern SOCKET sl_connect (SLCD *slconn, int sayhello); +extern int sl_disconnect (SLCD *slconn); +extern int sl_ping (SLCD *slconn, char *serverid, char *site); +extern int sl_senddata (SLCD *slconn, void *buffer, size_t buflen, + const char *ident, void *resp, int resplen); +extern int sl_recvdata (SLCD *slconn, void *buffer, size_t maxbytes, + const char *ident); +extern int sl_recvresp (SLCD *slconn, void *buffer, size_t maxbytes, + const char *command, const char *ident); +/** @} */ + +/** @addtogroup logging + @{ */ + +#if defined(__GNUC__) || defined(__clang__) +__attribute__((__format__ (__printf__, 3, 4))) +#endif +extern int sl_log (int level, int verb, const char *format, ...); +#if defined(__GNUC__) || defined(__clang__) +__attribute__((__format__ (__printf__, 4, 5))) +#endif +extern int sl_log_r (const SLCD * slconn, int level, int verb, const char *format, ...); +#if defined(__GNUC__) || defined(__clang__) +__attribute__ ((__format__ (__printf__, 4, 5))) +#endif + +extern int sl_log_rl (SLlog *log, int level, int verb, const char *format, ...); +extern void sl_loginit (int verbosity, + void (*log_print) (const char *), const char *logprefix, + void (*diag_print) (const char *), const char *errprefix); +extern void sl_loginit_r (SLCD *slconn, int verbosity, + void (*log_print) (const char *), const char *logprefix, + void (*diag_print) (const char *), const char *errprefix); +extern SLlog *sl_loginit_rl (SLlog *log, int verbosity, + void (*log_print) (const char *), const char *logprefix, + void (*diag_print) (const char *), const char *errprefix); +/** @} */ + +/** @addtogroup connection-state + @brief Basic functionality for saving and recovering connections + + @{ */ +extern int sl_recoverstate (SLCD *slconn, const char *statefile); +extern int sl_savestate (SLCD *slconn, const char *statefile); +/** @} */ -/* SEED structures */ +/** @addtogroup miniseed-record + @brief Basic functionality for handling mini SEED records -/* Generic struct for head of blockettes */ + @{ */ + +/** @brief Generic struct for header of miniSEED 2 blockettes */ struct sl_blkt_head_s { uint16_t blkt_type; uint16_t next_blkt; } SLP_PACKED; -/* SEED binary time (10 bytes) */ +/** @brief SEED binary time (10 bytes) */ struct sl_btime_s { uint16_t year; @@ -196,7 +382,7 @@ struct sl_btime_s uint16_t fract; } SLP_PACKED; -/* 100 Blockette (12 bytes) */ +/** @brief 100 Blockette (12 bytes) */ struct sl_blkt_100_s { uint16_t blkt_type; @@ -206,7 +392,7 @@ struct sl_blkt_100_s uint8_t reserved[3]; } SLP_PACKED; -/* 1000 Blockette (8 bytes) */ +/** @brief 1000 Blockette (8 bytes) */ struct sl_blkt_1000_s { uint16_t blkt_type; @@ -217,7 +403,7 @@ struct sl_blkt_1000_s uint8_t reserved; } SLP_PACKED; -/* 1001 Blockette (8 bytes) */ +/** @brief 1001 Blockette (8 bytes) */ struct sl_blkt_1001_s { uint16_t blkt_type; @@ -228,7 +414,7 @@ struct sl_blkt_1001_s int8_t frame_cnt; } SLP_PACKED; -/* Fixed section data of header (48 bytes) */ +/** @brief Fixed section of data header for miniSEED 2 (48 bytes) */ struct sl_fsdh_s { char sequence_number[6]; @@ -251,229 +437,75 @@ struct sl_fsdh_s uint16_t begin_blockette; } SLP_PACKED; -/* SeedLink packet, sequence number followed by miniSEED record */ -typedef struct slpacket_s -{ - char *slhead; /* SeedLink header */ - char *msrecord; /* miniSEED record */ - int reclen; /* miniSEED record length */ -} SLpacket; - -/* Stream information */ -typedef struct slstream_s -{ - char *net; /* The network code */ - char *sta; /* The station code */ - char *selectors; /* SeedLink style selectors for this station */ - int seqnum; /* SeedLink sequence number for this station */ - char timestamp[30]; /* Time stamp of last packet received */ - struct slstream_s *next; /* The next station in the chain */ -} SLstream; - -/* Persistent connection state information */ -typedef struct stat_s -{ - char databuf[BUFSIZE]; /* Data buffer for received packets */ - int recptr; /* Receive pointer for databuf */ - int sendptr; /* Send pointer for databuf */ - SLpacket slpack; /**< Transient, client-specific SLPacket pointers */ - int8_t expect_info; /* Do we expect an INFO response? */ - - int8_t netto_trig; /* Network timeout trigger */ - int8_t netdly_trig; /* Network re-connect delay trigger */ - int8_t keepalive_trig; /* Send keepalive trigger */ - - double netto_time; /* Network timeout time stamp */ - double netdly_time; /* Network re-connect delay time stamp */ - double keepalive_time; /* Keepalive time stamp */ - - enum /* Connection state */ - { - SL_DOWN, SL_UP, SL_DATA - } - sl_state; - - enum /* INFO query state */ - { - NoQuery, InfoQuery, KeepAliveQuery - } - query_mode; - -} SLstat; - -/* Logging parameters */ -typedef struct SLlog_s -{ - void (*log_print)(); - const char * logprefix; - void (*diag_print)(); - const char * errprefix; - int verbosity; -} SLlog; - -/* SeedLink connection description */ -typedef struct slcd_s -{ - SLstream *streams; /* Pointer to stream chain (a linked list of structs) */ - char *sladdr; /* The host:port of SeedLink server */ - char *begin_time; /* Beginning of time window */ - char *end_time; /* End of time window */ - - int8_t resume; /* Boolean flag to control resuming with seq. numbers */ - int8_t multistation; /* Boolean flag to indicate multistation mode */ - int8_t dialup; /* Boolean flag to indicate dial-up mode */ - int8_t batchmode; /* Batch mode (1 - requested, 2 - activated) */ - int8_t lastpkttime; /* Boolean flag to control last packet time usage */ - int8_t terminate; /* Boolean flag to control connection termination */ - - int keepalive; /* Interval to send keepalive/heartbeat (secs) */ - int iotimeout; /**< Timeout for network I/O operations (seconds) */ - int netto; /* Network timeout (secs) */ - int netdly; /* Network reconnect delay (secs) */ - - float protocol_ver; /* Version of the SeedLink protocol in use */ - const char *info; /* INFO level to request */ - SOCKET link; /* The network socket descriptor */ - SLstat *stat; /* Persistent state information */ - SLlog *log; /* Logging parameters */ -} SLCD; - -/* slutils.c */ -extern int sl_collect (SLCD * slconn, SLpacket ** slpack); -extern int sl_collect_nb (SLCD * slconn, SLpacket ** slpack); -extern int sl_collect_nb_size (SLCD * slconn, SLpacket ** slpack, int maxrecsize); -extern SLCD * sl_newslcd (void); -extern void sl_freeslcd (SLCD * slconn); -extern int sl_addstream (SLCD * slconn, const char *net, const char *sta, - const char *selectors, int seqnum, - const char *timestamp); -extern int sl_setuniparams (SLCD * slconn, const char *selectors, - int seqnum, const char *timestamp); -extern int sl_request_info (SLCD * slconn, const char * infostr); -extern int sl_sequence (const SLpacket *); -extern int sl_packettype (const SLpacket *); -extern void sl_terminate (SLCD * slconn); - -/* config.c */ -extern int sl_read_streamlist (SLCD *slconn, const char *streamfile, - const char *defselect); -extern int sl_parse_streamlist (SLCD *slconn, const char *streamlist, - const char *defselect); - -/* network.c */ -extern int sl_configlink (SLCD * slconn); -extern int sl_send_info (SLCD * slconn, const char * info_level, - int verbose); -extern SOCKET sl_connect (SLCD * slconn, int sayhello); -extern int sl_disconnect (SLCD * slconn); -extern int sl_ping (SLCD * slconn, char *serverid, char *site); -extern int sl_senddata (SLCD * slconn, void *buffer, size_t buflen, - const char *ident, void *resp, int resplen); -extern int sl_recvdata (SLCD * slconn, void *buffer, size_t maxbytes, - const char *ident); -extern int sl_recvresp (SLCD * slconn, void *buffer, size_t maxbytes, - const char *command, const char *ident); - -/* genutils.c */ -extern double sl_dtime (void); -extern int sl_doy2md (int year, int jday, int *month, int *mday); -extern int sl_checkversion (const SLCD * slconn, float version); -extern int sl_checkslcd (const SLCD * slconn); -extern int sl_readline (int fd, char *buffer, int buflen); - -/* logging.c */ -#if defined(__GNUC__) || defined(__clang__) -__attribute__((__format__ (__printf__, 3, 4))) -#endif -extern int sl_log (int level, int verb, const char *format, ...); -#if defined(__GNUC__) || defined(__clang__) -__attribute__((__format__ (__printf__, 4, 5))) -#endif -extern int sl_log_r (const SLCD * slconn, int level, int verb, const char *format, ...); -#if defined(__GNUC__) || defined(__clang__) -__attribute__((__format__ (__printf__, 4, 5))) -#endif -extern int sl_log_rl (SLlog * log, int level, int verb, const char *format, ...); -extern void sl_loginit (int verbosity, - void (*log_print)(const char*), const char * logprefix, - void (*diag_print)(const char*), const char * errprefix); -extern void sl_loginit_r (SLCD * slconn, int verbosity, - void (*log_print)(const char*), const char * logprefix, - void (*diag_print)(const char*), const char * errprefix); -extern SLlog *sl_loginit_rl (SLlog * log, int verbosity, - void (*log_print)(const char*), const char * logprefix, - void (*diag_print)(const char*), const char * errprefix); - -/* statefile.c */ -extern int sl_recoverstate (SLCD *slconn, const char *statefile); -extern int sl_savestate (SLCD *slconn, const char *statefile); - - -/* msrecord.c */ - /* Unpacking/decompression error flag values */ -#define MSD_NOERROR 0 /* No errors */ -#define MSD_UNKNOWNFORMAT -1 /* Unknown data format */ -#define MSD_SAMPMISMATCH -2 /* Num. samples in header is not the number unpacked */ -#define MSD_BADSAMPCOUNT -4 /* Sample count is bad, negative? */ -#define MSD_STBADLASTMATCH -5 /* Steim, last sample does not match */ -#define MSD_STBADCOMPFLAG -6 /* Steim, invalid compression flag(s) */ +#define MSD_NOERROR 0 /**< No errors */ +#define MSD_UNKNOWNFORMAT -1 /**< Unknown data format */ +#define MSD_SAMPMISMATCH -2 /**< Num. samples in header is not the number unpacked */ +#define MSD_BADSAMPCOUNT -4 /**< Sample count is bad, negative? */ +#define MSD_STBADLASTMATCH -5 /**< Steim, last sample does not match */ +#define MSD_STBADCOMPFLAG -6 /**< Steim, invalid compression flag(s) */ typedef struct SLMSrecord_s { - const char *msrecord; /* Pointer to original record */ - struct sl_fsdh_s fsdh; /* Fixed Section of Data Header */ - struct sl_blkt_100_s *Blkt100; /* Blockette 100, if present */ - struct sl_blkt_1000_s *Blkt1000; /* Blockette 1000, if present */ - struct sl_blkt_1001_s *Blkt1001; /* Blockette 1001, if present */ - int32_t *datasamples; /* Unpacked 32-bit data samples */ - int32_t numsamples; /* Number of unpacked samples */ - int8_t unpackerr; /* Unpacking/decompression error flag */ -} -SLMSrecord; - -extern SLMSrecord* sl_msr_new (void); -extern void sl_msr_free (SLMSrecord ** msr); -extern SLMSrecord* sl_msr_parse (SLlog * log, const char * msrecord, SLMSrecord ** msr, - int8_t blktflag, int8_t unpackflag); -extern SLMSrecord* sl_msr_parse_size (SLlog * log, const char * msrecord, SLMSrecord ** msr, - int8_t blktflag, int8_t unpackflag, int slrecsize); -extern int sl_msr_print (SLlog * log, SLMSrecord * msr, int details); -extern char* sl_msr_srcname (SLMSrecord * msr, char * srcname, int8_t quality); -extern int sl_msr_dsamprate (SLMSrecord * msr, double * samprate); -extern double sl_msr_dnomsamprate (SLMSrecord * msr); -extern double sl_msr_depochstime (SLMSrecord * msr); - + const char *msrecord; /**< Pointer to original record */ + struct sl_fsdh_s fsdh; /**< Fixed Section of Data Header */ + struct sl_blkt_100_s *Blkt100; /**< Blockette 100, if present */ + struct sl_blkt_1000_s *Blkt1000; /**< Blockette 1000, if present */ + struct sl_blkt_1001_s *Blkt1001; /**< Blockette 1001, if present */ + int32_t *datasamples; /**< Unpacked 32-bit data samples */ + int32_t numsamples; /**< Number of unpacked samples */ + int8_t unpackerr; /**< Unpacking/decompression error flag */ +} SLMSrecord; + +extern SLMSrecord *sl_msr_new (void); +extern void sl_msr_free (SLMSrecord **msr); +extern SLMSrecord *sl_msr_parse (SLlog *log, const char *msrecord, SLMSrecord **msr, + int8_t blktflag, int8_t unpackflag); +extern SLMSrecord *sl_msr_parse_size (SLlog *log, const char *msrecord, SLMSrecord **msr, + int8_t blktflag, int8_t unpackflag, int slrecsize); +extern int sl_msr_print (SLlog *log, SLMSrecord *msr, int details); +extern char *sl_msr_srcname (SLMSrecord *msr, char *srcname, int8_t quality); +extern int sl_msr_dsamprate (SLMSrecord *msr, double *samprate); +extern double sl_msr_dnomsamprate (SLMSrecord *msr); +extern double sl_msr_depochstime (SLMSrecord *msr); +/** @} */ + +/** @addtogroup utility-functions + @brief General utilities + + @{ */ -/* strutils.c */ +extern double sl_dtime (void); +extern int sl_doy2md (int year, int jday, int *month, int *mday); +extern int sl_checkversion (const SLCD *slconn, float version); +extern int sl_checkslcd (const SLCD *slconn); +extern int sl_readline (int fd, char *buffer, int buflen); -/* For a linked list of strings, as filled by strparse() */ +/*@ @brief For a linked list of strings, as filled by strparse() */ typedef struct SLstrlist_s { char *element; struct SLstrlist_s *next; } SLstrlist; -extern int sl_strparse(const char *string, const char *delim, SLstrlist **list); -extern int sl_strncpclean(char *dest, const char *source, int length); - -/* gswap.c */ +extern int sl_strparse (const char *string, const char *delim, SLstrlist **list); +extern int sl_strncpclean (char *dest, const char *source, int length); /* Generic byte swapping routines */ -extern void sl_gswap2 ( void *data2 ); -extern void sl_gswap3 ( void *data3 ); -extern void sl_gswap4 ( void *data4 ); -extern void sl_gswap8 ( void *data8 ); +extern void sl_gswap2 (void *data2); +extern void sl_gswap3 (void *data3); +extern void sl_gswap4 (void *data4); +extern void sl_gswap8 (void *data8); /* Generic byte swapping routines for memory aligned quantities */ -extern void sl_gswap2a ( void *data2 ); -extern void sl_gswap4a ( void *data4 ); -extern void sl_gswap8a ( void *data8 ); +extern void sl_gswap2a (void *data2); +extern void sl_gswap4a (void *data4); +extern void sl_gswap8a (void *data8); /* Byte swap macro for the BTime struct */ -#define SL_SWAPBTIME(x) \ - sl_gswap2 (x.year); \ - sl_gswap2 (x.day); \ +#define SL_SWAPBTIME(x) \ + sl_gswap2 (x.year); \ + sl_gswap2 (x.day); \ sl_gswap2 (x.fract); - +/** @} */ #ifdef __cplusplus }