#include <stdio.h>
#include <string.h>
+//#include <stdlib.h>
+//#include <ctype.h>
#include "cmdmain.h"
-#include "cmdparser.h"
#include "cmdcrc.h"
#include "reveng/reveng.h"
-//#include "reveng/cli.h"
-static int CmdHelp(const char *Cmd);
+#include "ui.h"
+#include "util.h"
-int CmdCrcCalc(const char *Cmd)
-{
- int argc = 0;
- char Cmd2[CMD_BUFFER_SIZE] = {0x00};
- char *argv[3];
+#define MAX_ARGS 20
- for (int i = 0; i < 50; i++)
- if (Cmd[i]==0x00) argc=i;
+int split(char *str, char *arr[MAX_ARGS]){
+ int beginIndex = 0;
+ int endIndex;
+ int maxWords = MAX_ARGS;
+ int wordCnt = 0;
- memcpy(Cmd2, Cmd, argc);
- argv[1]=Cmd2;
- reveng_main(argc, argv);
- return 0;
+ while(1){
+ while(isspace(str[beginIndex])){
+ ++beginIndex;
+ }
+ if(str[beginIndex] == '\0')
+ break;
+ endIndex = beginIndex;
+ while (str[endIndex] && !isspace(str[endIndex])){
+ ++endIndex;
+ }
+ int len = endIndex - beginIndex;
+ char *tmp = calloc(len + 1, sizeof(char));
+ memcpy(tmp, &str[beginIndex], len);
+ arr[wordCnt++] = tmp;
+ //PrintAndLog("cnt: %d, %s",wordCnt-1, arr[wordCnt-1]);
+ beginIndex = endIndex;
+ if (wordCnt == maxWords)
+ break;
+ }
+ return wordCnt;
}
-static command_t CommandTable[] =
-{
- {"help", CmdHelp, 1, "This help"},
- {"calc", CmdCrcCalc, 1, "{ Calculate CRC's }"},
- {NULL, NULL, 0, NULL}
-};
-
int CmdCrc(const char *Cmd)
{
- CmdsParse(CommandTable, Cmd);
- return 0;
-}
+ char name[] = {"reveng "};
+ char Cmd2[50 + 7];
+ memcpy(Cmd2, name, 7);
+ memcpy(Cmd2 + 7, Cmd, 50);
+ char *argv[MAX_ARGS];
+ int argc = split(Cmd2, argv);
+ //PrintAndLog("argc: %d, %s %s Cmd: %s",argc, argv[0], Cmd2, Cmd);
+ reveng_main(argc, argv);
+ for(int i = 0; i < argc; ++i){
+ //puts(arr[i]);
+ free(argv[i]);
+ }
-int CmdHelp(const char *Cmd)
-{
- CmdsHelp(CommandTable);
- return 0;
+ return 0;
}
+
#define CMDCRC_H__
int CmdCrc(const char *Cmd);
-int CmdCrcCalc(const char *Cmd);
#endif
static int CmdHelp(const char *Cmd);
static int CmdQuit(const char *Cmd);
+static int CmdRev(const char *Cmd);
//For storing command that are received from the device
static UsbCommand cmdBuffer[CMD_BUFFER_SIZE];
static command_t CommandTable[] =
{
{"help", CmdHelp, 1, "This help. Use '<command> help' for details of a particular command."},
- {"crc", CmdCrc, 1, "Crc calculations from the software reveng1-30"},
{"data", CmdData, 1, "{ Plot window / data buffer manipulation... }"},
{"hf", CmdHF, 1, "{ High Frequency commands... }"},
{"hw", CmdHW, 1, "{ Hardware commands... }"},
{"lf", CmdLF, 1, "{ Low Frequency commands... }"},
- {"script",CmdScript,1,"{ Scripting commands }"},
+ {"reveng",CmdRev, 1, "Crc calculations from the software reveng1-30"},
+ {"script",CmdScript,1, "{ Scripting commands }"},
{"quit", CmdQuit, 1, "Exit program"},
{"exit", CmdQuit, 1, "Exit program"},
{NULL, NULL, 0, NULL}
exit(0);
return 0;
}
+
+int CmdRev(const char *Cmd)
+{
+ CmdCrc(Cmd);
+ return 0;
+}
/**
* @brief This method should be called when sending a new command to the pm3. In case any old
* responses from previous commands are stored in the buffer, a call to this method should clear them.
model_t pset = model, *candmods, *mptr;
char *string;
- //myname = argv[0];
+ myname = argv[0];
/* stdin must be binary */
#ifdef _WIN32
#endif /* _WIN32 */
SETBMP();
-
+
+ pos=0;
+ optind=1;
do {
c=getopt(argc, argv, "?A:BDFLMP:SVXa:bcdefhi:k:lm:p:q:rstuvw:x:yz");
switch(c) {
uerror(const char *msg) {
/* Callback function to report fatal errors */
fprintf(stderr, "%s: %s\n", myname, msg);
- exit(EXIT_FAILURE);
+ return;
+ //exit(EXIT_FAILURE);
}
void
return(stdin);
if(!(handle = fopen(name, "rb"))) {
fprintf(stderr, "%s: cannot open '%s' for reading\n", myname, name);
- exit(EXIT_FAILURE);
+ return 0;
+ //exit(EXIT_FAILURE);
}
return(handle);
}
* specific.
*/
-/* #define PRESETS 1 */
+#ifdef _WIN32
+ #define PRESETS 1 //
+#endif
+
/* Macros defining the size of a bmp_t.
* Their values only matter if PRESETS and/or BMPMACRO are defined, in
char *optarg;
int optind = 1, opterr, optopt;
-
+int pos = 0;
int getopt(int argc, char *argv[], const char *optstring)
{
- static int pos = 0;
+ //static int pos = 0;
char *str;
if (pos == 0) {
*/
extern char *optarg;
-extern int optind, opterr, optopt;
+extern int optind, opterr, optopt, pos;
int getopt(int argc, char *argv[], const char *optstring);