]> cvs.zerfleddert.de Git - proxmark3-svn/blame - client/cmdmain.c
Removing windows specific code. Everything now compile and work the same for the...
[proxmark3-svn] / client / cmdmain.c
CommitLineData
7fe9b0b7 1#include <stdio.h>
2#include <stdlib.h>
3#include <unistd.h>
4#include <string.h>
91c38cf7 5#include "sleep.h"
7fe9b0b7 6#include "cmdparser.h"
7#include "data.h"
8#include "usb_cmd.h"
9#include "ui.h"
10#include "cmdhf.h"
11#include "cmddata.h"
12#include "cmdhw.h"
13#include "cmdlf.h"
14#include "cmdmain.h"
15
16unsigned int current_command = CMD_UNKNOWN;
17unsigned int received_command = CMD_UNKNOWN;
18
19static int CmdHelp(const char *Cmd);
20static int CmdQuit(const char *Cmd);
21
22static command_t CommandTable[] =
23{
c37d2e70 24 {"help", CmdHelp, 1, "This help. Use '<command> help' for details of the following commands:\n"},
37239a7c 25 {"data", CmdData, 1, "{ Plot window / data buffer manipulation... }"},
7fe9b0b7 26 {"exit", CmdQuit, 1, "Exit program"},
37239a7c 27 {"hf", CmdHF, 1, "{ HF commands... }"},
28 {"hw", CmdHW, 1, "{ Hardware commands... }"},
29 {"lf", CmdLF, 1, "{ LF commands... }"},
7fe9b0b7 30 {"quit", CmdQuit, 1, "Quit program"},
31 {NULL, NULL, 0, NULL}
32};
33
34int CmdHelp(const char *Cmd)
35{
36 CmdsHelp(CommandTable);
37 return 0;
38}
39
40int CmdQuit(const char *Cmd)
41{
42 exit(0);
43 return 0;
44}
45
46void WaitForResponse(uint32_t response_type)
47{
48 while (received_command != response_type) {
91c38cf7 49 msleep(10); // XXX ugh
7fe9b0b7 50 }
51 received_command = CMD_UNKNOWN;
52}
53
54//-----------------------------------------------------------------------------
55// Entry point into our code: called whenever the user types a command and
56// then presses Enter, which the full command line that they typed.
57//-----------------------------------------------------------------------------
58void CommandReceived(char *Cmd)
59{
60 CmdsParse(CommandTable, Cmd);
61}
62
63//-----------------------------------------------------------------------------
64// Entry point into our code: called whenever we received a packet over USB
65// that we weren't necessarily expecting, for example a debug print.
66//-----------------------------------------------------------------------------
67void UsbCommandReceived(UsbCommand *UC)
68{
69 // printf("%s(%x) current cmd = %x\n", __FUNCTION__, c->cmd, current_command);
70 /* If we recognize a response, return to avoid further processing */
71 switch(UC->cmd) {
72 case CMD_DEBUG_PRINT_STRING: {
73 char s[100];
74 if(UC->arg[0] > 70 || UC->arg[0] < 0) {
75 UC->arg[0] = 0;
76 }
77 memcpy(s, UC->d.asBytes, UC->arg[0]);
78 s[UC->arg[0]] = '\0';
79 PrintAndLog("#db# %s", s);
80 return;
81 }
82
83 case CMD_DEBUG_PRINT_INTEGERS:
84 PrintAndLog("#db# %08x, %08x, %08x\r\n", UC->arg[0], UC->arg[1], UC->arg[2]);
85 return;
86
87 case CMD_MEASURED_ANTENNA_TUNING: {
88 int peakv, peakf;
89 int vLf125, vLf134, vHf;
90 vLf125 = UC->arg[0] & 0xffff;
91 vLf134 = UC->arg[0] >> 16;
92 vHf = UC->arg[1] & 0xffff;;
93 peakf = UC->arg[2] & 0xffff;
94 peakv = UC->arg[2] >> 16;
95 PrintAndLog("");
96 PrintAndLog("");
97 PrintAndLog("# LF antenna: %5.2f V @ 125.00 kHz", vLf125/1000.0);
98 PrintAndLog("# LF antenna: %5.2f V @ 134.00 kHz", vLf134/1000.0);
99 PrintAndLog("# LF optimal: %5.2f V @%9.2f kHz", peakv/1000.0, 12000.0/(peakf+1));
100 PrintAndLog("# HF antenna: %5.2f V @ 13.56 MHz", vHf/1000.0);
101 if (peakv<2000)
102 PrintAndLog("# Your LF antenna is unusable.");
103 else if (peakv<10000)
104 PrintAndLog("# Your LF antenna is marginal.");
105 if (vHf<2000)
106 PrintAndLog("# Your HF antenna is unusable.");
107 else if (vHf<5000)
108 PrintAndLog("# Your HF antenna is marginal.");
109 return;
110 }
111 default:
112 break;
113 }
114 /* Maybe it's a response: */
115 switch(current_command) {
116 case CMD_DOWNLOAD_RAW_ADC_SAMPLES_125K:
117 if (UC->cmd != CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K) goto unexpected_response;
118 int i;
119 for(i=0; i<48; i++) sample_buf[i] = UC->d.asBytes[i];
120 received_command = UC->cmd;
121 return;
bdd1de1b 122 case CMD_ACQUIRE_RAW_ADC_SAMPLES_125K:
7fe9b0b7 123 case CMD_DOWNLOADED_SIM_SAMPLES_125K:
124 if (UC->cmd != CMD_ACK) goto unexpected_response;
125 // got ACK
126 received_command = UC->cmd;
127 return;
128 default:
129 unexpected_response:
130 PrintAndLog("unrecognized command %08x\n", UC->cmd);
131 break;
132 }
c37d2e70 133}
Impressum, Datenschutz