///
/// @file cli_api.c
/// @authors k. Headley
/// @date 05 dec 2019

/// Command line interface API definitions

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


/////////////////////////
// Terms of use
/////////////////////////
/*
 Copyright Information

 Copyright 2002-2019 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.
 */

/////////////////////////
// Headers
/////////////////////////
#include <stddef.h>
#include "cwgsys.h"
#include "cli_api.h"
#include "cli_impl.h"
#include "fileutils.h"
#include "proto.h"
#include "log.h"

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

// These macros should only be defined for
// application main files rather than general C files
/*
 /// @def PRODUCT
 /// @brief header software product name
 #define PRODUCT "carbonwg"

 /// @def COPYRIGHT
 /// @brief header software copyright info
 #define COPYRIGHT "Copyright 2002-2019 MBARI Monterey Bay Aquarium Research Institute, all rights reserved."
 /// @def NOWARRANTY
 /// @brief header software terms of use
 #define NOWARRANTY  \
 "This program is distributed in the hope that it will be useful,\n"\
 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"\
 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"\
 "GNU General Public License for more details (http://www.gnu.org/licenses/gpl-3.0.html)\n"
 */

/////////////////////////
// Declarations
/////////////////////////

/////////////////////////
// Imports
/////////////////////////

/////////////////////////
// Module Global Variables
/////////////////////////

/// command structures
/// Commands are not case sensitive but can only use alphanumeric and '_'
/// alternate names may be separated by '|'
/// pointed to functions must take a char* and return an ErrCode

const CmdStruct cmdsRoot[] ={
    // Root commands
    {"GET", cli_get},
    {"SET", cli_set},
    {"CLEAR|CLR", cli_clr},
    {"PULSE", cli_pulse},
    {"LI", cli_li},
    {"SCR", cli_script},

    // measurement
    {"MDIO",cli_mdio},
    {"MMEAS",cli_mmeas},

    // IO, data queue
    {"CREG", cli_creg},
    {"DREG", cli_dreg},
    {"FREG", cli_freg},
    {"QCOUNT", cli_qcount},
    {"QPOP", cli_qpop},
    {"QPEEK", cli_qpeek},
    {"QSHOW", log_qshow_cmd},
    {"QCLEAR", cli_qclear},

    // configuration, logging
    {"CFGEX",cli_cfg_export},
    {"LOG", cli_log},
#ifdef WITH_LOG_UTILS
    {"LCAT", cli_lcat},
    {"LLESS", cli_lless},
    {"LINSPECT|LINFO", cli_linfo},
    {"LSEQ", cli_lseq},
    {"LSETSEQ", cli_lsetseq},
#endif
    {"LSHOW", cli_lshow},
    {"LSEG", cli_lseg},

    // file system
    {"UPLOAD", cli_upload},
    {"LS|DIR", cli_ls},
#ifdef WITH_XCAT
    {"CAT", cli_xcat},
#else
    {"CAT|FSHOW", cli_cat},
#endif
    {"FSIZE", cli_fsize},
    {"LESS", cli_less},
    {"LC", cli_line_count},
    {"CP|COPY|MV", cli_cp},
    {"REN", frename},
    {"DSTAT", dstat},
    {"RM|DELETE", fdelete},

    // diagnostics
    {"HELP|?", cli_help},
#ifdef WITH_UI_HISTORY
    {"HIST|!", cli_history},
#endif // WITH_UI_HISTORY
    {"CON", cli_con},
    {"CRON", cli_cron},
    {"DEBUG", cli_set_debug},
    {"PMEM", pshow},
#ifdef WITH_UI_ECHO
    {"ECHO", cli_echo},
#endif //WITH_UI_ECHO
    {"PRINT", cli_print},
    {"PRINTLN", cli_println},
    {"VER", cli_version},
    {"UPTIME", cli_uptime},
    {"RESET", cli_reset},
    {"HELLO", cli_hello},
    {"SWEEP", cli_sweep},
    {"PROTO", proto_test},
    {"TEST", cli_test},
    {"SLEEP", cli_sleep},
    {"", NULL}
};

const CmdStruct cmdsGet[] ={
    {"ANALOG|AD", cli_get_analog},
    {"BITS", cli_get_bits},
//    {"DATA", cli_get_data},
    {"ERR", cli_get_err},
    {"NEXT", cli_get_next_event},
    {"SER", cli_get_ser},
    {"TIME", cli_get_time},
    {"DATE", cli_get_time},
    {"VAR", cli_get_var},
    {"PRINT", cli_get_print},
    {"", NULL}
};

const CmdStruct cmdsSet[] ={
    {"BAUD", cli_set_baud},
    {"BITS", cli_set_bits},
    {"SER", cli_set_ser},
    {"TIME", cli_set_time},
    {"DATE", cli_set_time},
    {"VAR", cli_set_var},
    {"PRINT", cli_set_print},
    {"", NULL}
};

const CmdStruct cmdsClr[] ={
    {"BITS", cli_clr_bits},
    {"", NULL}
};

const CmdStruct cmdsPulse[] ={
    {"BITS", cli_pulse_bits},
    {"NBITS", cli_pulse_nbits},
};

const CmdStruct cmdsLi[] ={
    {"INIT", cli_licor_init},
    // take measurement type out n delay
    {"OR|RATE", cli_licor_or},
    {"STAT", cli_licor_stat},
    // get last measurement
    {"MODEL", cli_licor_model},
    {"CAL", cli_licor_cal},
    {"", NULL}
};

const CmdStruct cmdsTest[] ={
    {"BITS", cli_test_bits},
    {"", NULL}
};

const ScrCmdStruct cmdsScr[] ={
    {"LOAD", cli_scr_load},
    {"UNLOAD", cli_scr_unload},
    {"RUN", cli_scr_run},
    {"JOG", cli_scr_jog},
    {"DELAY", cli_scr_delay},
    {"PAUSE", cli_scr_pause},
    {"RESUME", cli_scr_resume},
    {"RESET", cli_scr_reset},
    {"KILL", cli_scr_kill},
    {"END", cli_scr_end},
    {"SHOW", cli_scr_show},
    {"SDEBUG", cli_scr_sdebug},
//    {"MACRO", cli_scr_macro},
    {"SCH|SCHEDULE", cli_scr_schedule},
    {"STAT", cli_scr_stat},
    {"SYNC", cli_scr_sync},
    {"GOTO", cli_scr_goto},
    {"IF", cli_scr_if},
//    {"FWD|+", cli_scr_NOP},
//    {"REV|-", cli_scr_NOP},
//
//    {"LAST", cli_scr_NOP},
//    {"LIST", cli_scr_NOP},
//    {"CALL", cli_scr_NOP},
     {"", NULL}
};

/////////////////////////
// Function Definitions
/////////////////////////


