/************************************************************************/
/* Copyright 2012-2018 MBARI											*/
/************************************************************************/
/* Summary	: User Command Table for BEDS2 on PIC32MX470				*/
/* Filename : bedsCmdTbl.h												*/
/* Author	: Robert Herlien (rah)										*/
/* Project	: Benthic Event Detection System (BEDS)						*/
/* Revision : 1.0														*/
/* Created	: 02/28/2018												*/
/*																			*/
/* MBARI provides this documentation and code "as is", with no warranty,	*/
/* express or implied, of its quality or consistency. It is provided without*/
/* support and without obligation on the part of the Monterey Bay Aquarium	*/
/* Research Institute to assist in its use, correction, modification, or	*/
/* enhancement. This information should not be published or distributed to	*/
/* third parties without specific written permission from MBARI.			*/
/*																			*/
/************************************************************************/
/* Modification History:												*/
/* 17sep2012 rah - created from Persistor "toPico" stationery and Oasis */
/* 28feb2018 rah - Ported to BEDS2 on PIC32MX470						*/
/************************************************************************/

#ifndef INCbedsCmdTblh
#define INCbedCmdTblIh		1

#include <mbariTypes.h>
#include <beds.h>
#include <bedsUI.h>
#include <bedsCmd.h>
#include <clock.h>
#include <fileUtils.h>
#include <variable.h>
#include <bedsDiag.h>
#include <ymodem.h>


/****************************************/
/*		Command Table					*/
/****************************************/

const CmdEntry	cmdTbl[] =
{
	{"DIR", usrDir, "Directory command"},
	{"TYPE", usrType, "Type a file"},
	{"DEL", usrDelete, "Delete file(s), also ERA"},
	{"ERA", usrDelete, NULL},
	{"REN", usrRename, "Rename file"},
	{"COPY", usrCopy, "Copy file"},
	{"MORE", usrMore, "Type file to screen with breaks"},
	{"TAIL", usrTail, "Tail <n> <file>"},
	{"DUMP", usrHexDump, "Hex dump file"},
	{"CD", usrChdir, "Change working directory"},
	{"CHDIR", usrChdir, NULL},
	{"PWD", usrPwd, "Print working directory"},
	{"MD", usrMkdir, "Make new directory"},
	{"MKDIR", usrMkdir, NULL},
	{"ANALOG", analogCmd, "ANALOG [-a<avg>] [-n<nchans>] [-p[pwrOnDelay]] <chan>"},
	{"VAR", varCmd, "Display or set variable"},
	{"VARS", varCmd, NULL},
	{"VARIABLE", varCmd, NULL},
	{"TIME", timeCmd, "get or set time, TIME yyyy/mm/dd hh:mm:ss"},
	{"DATE", timeCmd, "alias for TIME"},
	{"EVENT", EventCmd, "Get Events"},
	{"EVENTS", EventCmd, NULL},
	{"WATCH", WatchCmd, "Get Events"},
	{"SYSRECS", SysRecCmd, "Get System Records"},
	{"SYSREC", SysRecCmd, NULL},
	{"DEPLOY", DeployCmd, "Turn on/off or query Deployment mode"},
	{"UPTIME", uptimeCmd, "System Uptime"},
	{"YS", ymdmSend, "Send Files via YModem"},
	{"YR", ymdmRcv, "Receive Files via YModem"},
	{"ZS", ZSCmd, "ZModem send"},
	{"SZ", ZSCmd, NULL},
	{"QUIT", quitCmd, "Exit user interface (Also Q)"},
	{"Q", quitCmd, NULL},
	{"RESET", resetCmd, "Reset the system"},
	{"RECOVER", recoverCmd, "Recover the system"},
	{"SYSLOG", syslogCmd, "Log a message to syslog"},
	{"DIAG", bedsDiagnostic, "Run diagnostic menu"},
	{"DeleteLine", deleteLine, "DeleteLine <line> <file>"},
	{"DeleteChars", deleteChars, "DeleteChars <line> <file> [numChars]"},
	{"InsertLine", insertLine, "InsertLine <line> <file>"},
	{"InsertChars", insertChars, "InsertChars <line> <file> [numChars]"},
#ifdef DEBUG_TIME
	{"TIMETEST", timeTestCmd, NULL},
	{"DURTEST", durTestCmd, NULL},
#endif
	{"HELP", helpCmd, "Help (also H or ?)"},
	{"H", helpCmd, NULL},
	{"?", helpCmd, NULL},
	{"TEST", cmdTest, NULL}
};


#if 0
/********* Notes on privLevel (PRV LEV REQ in table) ************/
/*																*/
/* privLevel is a signed char, can be 0 to 127					*/
/*																*/
/* Our use:														*/
/* Connection on the acoustic modem port execute at priv level 0*/
/* Connection on the debug port, which can only happen in the lab,*/
/* execute at priv level 20										*/
/* Anyone can execute the PRIV command, which sets the priv level*/
/* This allows you to do dangerous stuff, but you have to want to*/
/*																*/
/* Command privs set according to the following:				*/
/*	0 = commands we want to execute during deployment			*/
/* 10 = File I/O commands, including delete, etc				*/
/* 20 = debug commands, including port and memory commands		*/
/* 99 = dangerous commands, including BOOT and RESET			*/
/****************************************************************/

MLocal CmdTable ToPicoCmdTable[] = 
{
//------------------------------------------------------------------------------------
//		BEDS Commands follow:
//				Command entries can actually go anywhere in the table, but placing them
//				at the top has them show firs in the help command.
//------------------------------------------------------------------------------------

		,"DECODE"		, DecodeCmd,		1, 0,  0,  0,		"Decode data file"
		,"DECIMATE"		, DecimateCmd,		1, 0,  0,  10,		"Decimate and split files"
		,"SPLIT"		, DecimateCmd,		1, 0,  0,  10,		"Split and decimate files"

		// Modem testing
		,"SREG"			, SRegCmd,			1, 0,  0, 10,		""

// BEDS Time commands
		,"SETPCLK", BEDSSetPicoClkFromAccurateClk, 0, 100, 1, 0, "Set PicoDOS RTC from accurate RTC"
		,"SETACLK", BEDSSetAccurateClkFromPicoClk, 0, 100, 1, 0, "Set accurate RTC from PicoDOS RTC"

//------------------------------------------------------------------------------------
//		STANDARD PICODOS COMMANDS FOLLOW: (comment them out to remove or override)
//------------------------------------------------------------------------------------

		,"APP"			, PDCGoCmd,			0, 99, 0,	16,		"run flash app [args...]"
		,"ATTRIB"		, PDCAttribCmd,		0, 10, 0,	0,		"[+ - RASH] [d:][p][name]"
		,"BACKROM"		, PDCBackROMCmd,	0, 10, 0,	16,		"[d:][path] [/SAVI]"
		,"BAUD"			, PDCBaudCmd,		0, 20, 0,	10,		"[newrate] [/Q/P/E/O/N/2]"
		,"BOOT"			, PDCBootCmd,		0, 99,	0,	0,		"[PICO][PBM][APP]"
		,"CAPTURE"		, PDCCaptureCmd,	0, 10, 0,	16,		"[d:][p]fn [/Dx/B/N/E]"
		,"CCC"			, PDCCardChangeCmd, 0, 10, 0,	10,		"Card Change [delay secs]"
		,"CHDIR"		, PDCCHDirCmd,		0, 10, 0,	0,		"[drive:][path]"
		,"CHKDSK"		, PDCChkdskCmd,		0, 10, 0,	16,		"[d:][p][fn] [/F][/I]"
		,"COPY"			, PDCCopyCmd,		0, 10, 0,	0,		"source dest [/V]"
		,"DUMP"			, PDCDumpCmd,		0, 10, 0,	16,		"file[start[,end]]"
		,"DATE"			, BEDSDateCmd,		0,	0, 1,	0,		"print date/time"
		,"PDATE"		, PDCDateCmd,		0, 99, 1,	0,		"[mdy[hms[a|p]]] /IEUMCP]"
		,"DEL"			, PDCDelCmd,		0, 10, 0,	0,		"[drv:][pth][name] [/P]"
		,"DIR"			, PDCDirCmd,		0,	0, 0,	16,		"[d:][p][fn] [/PWBLV4A:a]"
		,"ERASE"		, PDCDelCmd,		0, 10, 0,	0,		"[drv:][pth][name] [/P]"
		,"FDISK"		, PDCFdiskCmd,		0, 99, 0,	16,		"[/Pnn/M/Sdev/@/F/Rnn/Q]"
		,"FORMAT"		, PDCFormatCmd,		0, 99, 0,	0,		"[drv:][/V[:label]][/Q/E]"
		,"GO"			, PDCGoCmd,			0, 99, 0,	16,		"args... | addr /A | /Fn"
		,"LO"			, PDCLoadSRecCmd,	0, 99, 0,	16,		"[ofs][;Bx[+]] [;G]"
		,"MKDIR"		, PDCMKDirCmd,		0, 10, 0,	0,		"[drive:][path]"
		,"MD"			, PDCMemDispCmd,	0, 10, 1,	16,		"display [range]"
		,"MM"			, PDCMemModCmd,		0, 99, 1,	16,		"modify [address]"
		,"ML"			, PDCMemListCmd,	0, 20, 1,	16,		"disassemble [range]"
		,"MON"			, PDCResetToPBMCmd, 0, 99, 0,	0,		"Reset to PBM"
		,"PATH"			, PDCPathCmd,		0, 10, 0,	0,		"[[d:]path[;...]] [/P]"
		,"PBM"			, PDCResetToPBMCmd, 0, 99, 0,	0,		"Reset to PBM"
		,"PROMPT"		, PDCPromptCmd,		0, 20, 0,	0,		"[text] [/P]"
		,"PR"			, PDCPortReadCmd,	1, 20, 1,	10,		"pin read	 <1..50>"
		,"PC"			, PDCPortClrCmd,	1, 20, 0,	10,		"pin clear	 <1..50>"
		,"PS"			, PDCPortSetCmd,	1, 20, 0,	10,		"pin set	 <1..50>"
		,"PT"			, PDCPortToggleCmd, 1, 20, 1,	10,		"pin toggle	 <1..50>"
		,"PM"			, PDCPortMirrorCmd, 1, 20, 1,	10,		"pin mirror	 <1..50>"
		,"TIME"			, BEDSTimeCmd,		0,	0, 1,	0,		"[hh:mm:ss [a|p]] [/M/C]"
		,"PTIME"		, PDCTimeCmd,		0, 99, 1,	0,		"[hh:mm:ss [a|p]] [/M/C]"
		,"TYPE"			, PDCTypeCmd,		0,	0, 0,	0,		"[drv:][pth][name]"
		,"REN"			, PDCRenCmd,		0, 10, 0,	0,		"[d:][p]oldname newname"
		,"RESET"		, BEDSResetCmd,		0, 100, 0,	0,		"(hard reset)"	
		,"RMDIR"		, PDCRMDirCmd,		0, 10, 0,	0,		"[drive:][path]"
		,"SAVE"			, PDCSaveCmd,		0, 10, 0,	16,		"file[start][end]"
		,"SD"			, PDCSectorDumpCmd, 0, 10, 1,	16,		"sect.dump[d:][range][/C]"
		,"SET"			, PDCSetCmd,		0, 10, 0,	0,		"[var=[str]] [/SLFE?]"
		,"XS"			, PDCXSCmd,			0, 0,  0,	0,		"[/X][/C][/Q]file"
		,"XR"			, PDCXRCmd,			0, 0,  0,	0,		"[/X][/C][/Q][file]"
		,"YS"			, PDCYSCmd,			0, 0,  0,	0,		"[/G][/Q]file[,file...]"
		,"YR"			, PDCYRCmd,			0, 0,  0,	0,		"[/G][/Q]"
#ifndef TEAPOT
		,"ZS"			, ZSCmd,			0, 0,  0,	0,		"ZModem send"
		,"SZ"			, ZSCmd,			0, 0,  0,	0,		""
#endif
		,"KS"			, KSCmd,			0, 0,  0,	0,		"Kermit send"
		,"VER"			, PDCVerCmd,		0, 0,  0,	0,		"Firmware versions"

//------------------------------------------------------------------------------------
// Future placeholders for PicoDOS

		,"BREAK"		, PDCBreakCmd,		0,	20, 0,	0,		""
		,"CLS"			, PDCCLSCmd,		0,	20, 0,	0,		""
		,"DEVICE"		, PDCDeviceCmd,		0,	20, 0,	0,		""
		,"EXIT"			, PDCExitCmd,		0,	20, 0,	0,		""
		,"INSTALL"		, PDCInstallCmd,	0,	20, 0,	0,		""
		,"LABEL"		, PDCLabelCmd,		0,	20, 0,	0,		""
		,"MEM"			, PDCMemCmd,		0,	20, 0,	0,		""
		,"MODE"			, PDCModeCmd,		0,	20, 0,	0,		""
		,"PATH"			, PDCPathCmd,		0,	20, 0,	0,		""
		,"VOL"			, PDCVolCmd,		0,	20, 0,	0,		""

//------------------------------------------------------------------------------------
		,"GSAVE"		, PDCSaveCmd,		0,	20, 0,	16,		""
		,"GS"			, PDCSaveCmd,		0,	20, 0,	16,		""
		,"CD"			, PDCCHDirCmd,		0,	10, 0,	0,		""
		,"CD."			, PDCCHDirCmd,		0,	10, 0,	0,		""
		,"CD.."			, PDCCHDirCmd,		0,	10, 0,	0,		""
		,"MKD"			, PDCMKDirCmd,		0,	10, 0,	0,		""
		,"RD"			, PDCRMDirCmd,		0,	10, 0,	0,		""
		,"HELP"			, PDCHelpCmd,		0,	0,	0,	0,		""
		,"HE"			, PDCHelpCmd,		0,	0,	0,	0,		""
		,"H"			, PDCHelpCmd,		0,	0,	0,	0,		""
		,"?"			, PDCHelpCmd,		0,	0,	0,	0,		""
		,"RES"			, PDCResetCmd,		0,	20, 0,	0,		""		
		,"G"			, PDCGoCmd,			0,	20, 0,	16,		""
		,"GO"			, PDCGoCmd,			0,	20, 0,	16,		""
		,"CRC"			, PDCCRCCmd,		0,	10, 0,	16,		""
		,"CMD10"		, PDCCmdStdCmdTest, 0,	20, 0,	10,		""
		,"CMD16"		, PDCCmdStdCmdTest, 0,	20, 0,	16,		""


		//TERMINATING ENTRY (!!!!This must be present at end of table !!!!)
		,""				, 0,				0,	0, 0,	0,		0
};

#endif

#endif	/* INCbedsCmdTblh */
