///
/// @file logutils.h
/// @authors k. headley
/// @date 01 mar 2020

/// Cross-platform Carbon Waveglider log utilities

/// @sa doxygen-examples.c for more examples of Doxygen markup


/////////////////////////
// Terms of use
/////////////////////////
/*
 Copyright Information
  
 Copyright 2002-2020 MBARI
 Monterey Bay Aquarium Research Institute, all rights reserved.
 
 Terms of Use
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 3 of the License, or
 (at your option) any later version. You can access the GPLv3 license at
 http://www.gnu.org/licenses/gpl-3.0.html
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details
 (http://www.gnu.org/licenses/gpl-3.0.html)
 
 MBARI provides the documentation and software code "as is", with no warranty,
 express or implied, as to the software, title, non-infringement of third party
 rights, merchantability, or fitness for any particular purpose, the accuracy of
 the code, or the performance or results which you may obtain from its use. You
 assume the entire risk associated with use of the code, and you agree to be
 responsible for the entire cost of repair or servicing of the program with
 which you are using the code.
 
 In no event shall MBARI be liable for any damages, whether general, special,
 incidental or consequential damages, arising out of your use of the software,
 including, but not limited to, the loss or corruption of your data or damages
 of any kind resulting from use of the software, any prohibited use, or your
 inability to use the software. You agree to defend, indemnify and hold harmless
 MBARI and its officers, directors, and employees against any claim, loss,
 liability or expense, including attorneys' fees, resulting from loss of or
 damage to property or the injury to or death of any person arising out of the
 use of the software.
 
 The MBARI software is provided without obligation on the part of the
 Monterey Bay Aquarium Research Institute to assist in its use, correction,
 modification, or enhancement.
 
 MBARI assumes no responsibility or liability for any third party and/or
 commercial software required for the database or applications. Licensee agrees
 to obtain and maintain valid licenses for any additional third party software
 required.
 */

// Always do this
#ifndef LOGUTILS_H
#define LOGUTILS_H

/////////////////////////
// Includes 
/////////////////////////
#include "cwg-shared.h"
#include "licor8xx-shared.h"

/////////////////////////
// Macros
/////////////////////////

/////////////////////////
// Type Definitions
/////////////////////////
typedef enum{
    LINF_REC_COUNTER=0x01,
    LINF_CSV_HEADER =0x02,
    LINF_FMT_PRETTY =0x04,
    LINF_FMT_CSV    =0x08,
    LINF_TIME_POSIX =0x10,
    LINF_TIME_ISO   =0x20,
    LINF_FMT_FLAGS  =0x0C,
    LINF_TIME_FLAGS =0x30
}linfo_flags;

enum{R_RMID_INVAL=0,R_RMID_NONE,R_RMID_SAMPLE,R_RMID_SCAL,R_RMID_ZCAL,
    R_RTID_INVAL, R_RTID_ZRECV1,RBIN_COUNT};

enum{E_SYNC=0,E_TMZERO,E_TMMONO,E_CTINVAL,E_SEQMONO,E_LENINVAL,
    E_RTID,E_RMID,EBIN_COUNT};

enum{T_FIRST=0,T_LAST,T_RNGSTART,T_RNGEND,TBIN_COUNT};

enum{SEQ_FIRST=0,SEQ_LAST,SEQ_RNGSTART,SEQ_RNGEND,SQBIN_COUNT};

typedef struct linfo_stats_s{
    uint32_t fsize;
    uint64_t time_bin[TBIN_COUNT];
    uint32_t seq_bin[SQBIN_COUNT];
    int record_bin[RBIN_COUNT];
    int err_bin[EBIN_COUNT];
    int record_count;
    int error_count;
    uint32_t seq_last;
    uint64_t time_last;
}linfo_stats_t;

/////////////////////////
// Exports
/////////////////////////

#ifdef __cplusplus
extern "C" {
#endif
    
extern bool g_logutils_interrupt;
extern const char *linfo_rbin_names[RBIN_COUNT];
extern const char *linfo_ebin_names[EBIN_COUNT];

return_code_t lu_lless(char *fpath, queue_output_flag flags);
return_code_t lu_lcat(char *fpath,  int start,  int count, queue_output_flag oflags);
return_code_t lu_linfo(char *fpath, linfo_flags oflags, linfo_stats_t *r_stats);

#ifdef __cplusplus
}
#endif

#endif // THIS_FILE

