1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2010 iZsh <izsh at fail0verflow.com>
4 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
5 // at your option, any later version. See the LICENSE.txt file for the text of
7 //-----------------------------------------------------------------------------
8 // Main command parser entry point
9 //-----------------------------------------------------------------------------
16 #include "cmdparser.h"
26 unsigned int current_command
= CMD_UNKNOWN
;
27 unsigned int received_command
= CMD_UNKNOWN
;
29 static int CmdHelp(const char *Cmd
);
30 static int CmdQuit(const char *Cmd
);
32 static command_t CommandTable
[] =
34 {"help", CmdHelp
, 1, "This help. Use '<command> help' for details of the following commands:\n"},
35 {"data", CmdData
, 1, "{ Plot window / data buffer manipulation... }"},
36 {"exit", CmdQuit
, 1, "Exit program"},
37 {"hf", CmdHF
, 1, "{ HF commands... }"},
38 {"hw", CmdHW
, 1, "{ Hardware commands... }"},
39 {"lf", CmdLF
, 1, "{ LF commands... }"},
40 {"quit", CmdQuit
, 1, "Quit program"},
44 int CmdHelp(const char *Cmd
)
46 CmdsHelp(CommandTable
);
50 int CmdQuit(const char *Cmd
)
56 void WaitForResponse(uint32_t response_type
)
58 while (received_command
!= response_type
) {
59 msleep(10); // XXX ugh
61 received_command
= CMD_UNKNOWN
;
64 //-----------------------------------------------------------------------------
65 // Entry point into our code: called whenever the user types a command and
66 // then presses Enter, which the full command line that they typed.
67 //-----------------------------------------------------------------------------
68 void CommandReceived(char *Cmd
)
70 CmdsParse(CommandTable
, Cmd
);
73 //-----------------------------------------------------------------------------
74 // Entry point into our code: called whenever we received a packet over USB
75 // that we weren't necessarily expecting, for example a debug print.
76 //-----------------------------------------------------------------------------
77 void UsbCommandReceived(UsbCommand
*UC
)
79 // printf("%s(%x) current cmd = %x\n", __FUNCTION__, c->cmd, current_command);
80 /* If we recognize a response, return to avoid further processing */
82 case CMD_DEBUG_PRINT_STRING
: {
84 if(UC
->arg
[0] > 70 || UC
->arg
[0] < 0) {
87 memcpy(s
, UC
->d
.asBytes
, UC
->arg
[0]);
89 PrintAndLog("#db# %s", s
);
93 case CMD_DEBUG_PRINT_INTEGERS
:
94 PrintAndLog("#db# %08x, %08x, %08x\r\n", UC
->arg
[0], UC
->arg
[1], UC
->arg
[2]);
97 case CMD_MEASURED_ANTENNA_TUNING
: {
99 int vLf125
, vLf134
, vHf
;
100 vLf125
= UC
->arg
[0] & 0xffff;
101 vLf134
= UC
->arg
[0] >> 16;
102 vHf
= UC
->arg
[1] & 0xffff;;
103 peakf
= UC
->arg
[2] & 0xffff;
104 peakv
= UC
->arg
[2] >> 16;
107 PrintAndLog("# LF antenna: %5.2f V @ 125.00 kHz", vLf125
/1000.0);
108 PrintAndLog("# LF antenna: %5.2f V @ 134.00 kHz", vLf134
/1000.0);
109 PrintAndLog("# LF optimal: %5.2f V @%9.2f kHz", peakv
/1000.0, 12000.0/(peakf
+1));
110 PrintAndLog("# HF antenna: %5.2f V @ 13.56 MHz", vHf
/1000.0);
112 PrintAndLog("# Your LF antenna is unusable.");
113 else if (peakv
<10000)
114 PrintAndLog("# Your LF antenna is marginal.");
116 PrintAndLog("# Your HF antenna is unusable.");
118 PrintAndLog("# Your HF antenna is marginal.");
124 /* Maybe it's a response: */
125 switch(current_command
) {
126 case CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K
:
127 if (UC
->cmd
!= CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K
) goto unexpected_response
;
129 for(i
=0; i
<48; i
++) sample_buf
[i
] = UC
->d
.asBytes
[i
];
130 received_command
= UC
->cmd
;
132 case CMD_ACQUIRE_RAW_ADC_SAMPLES_125K
:
133 case CMD_DOWNLOADED_SIM_SAMPLES_125K
:
134 if (UC
->cmd
!= CMD_ACK
) goto unexpected_response
;
136 received_command
= UC
->cmd
;
140 PrintAndLog("unrecognized command %08x\n", UC
->cmd
);