Skip to content

Commit

Permalink
set debug log level
Browse files Browse the repository at this point in the history
  • Loading branch information
merlokk committed Dec 11, 2023
1 parent af0e25b commit ebe9d72
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 11 deletions.
3 changes: 2 additions & 1 deletion armsrc/appmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,8 @@ static void PacketReceived(PacketCommandNG *packet) {
// emulator
case CMD_SET_DBGMODE: {
g_dbglevel = packet->data.asBytes[0];
print_debug_level();
if (packet->length == 1 || packet->data.asBytes[1] != 0)
print_debug_level();
reply_ng(CMD_SET_DBGMODE, PM3_SUCCESS, NULL, 0);
break;
}
Expand Down
16 changes: 6 additions & 10 deletions client/src/cmdhw.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "cmdhw.h"
#include "cmddata.h"
#include "commonutil.h"
#include "preferences.h"
#include "pm3_cmd.h"
#include "pmflash.h" // rdv40validation_t
#include "cmdflashmem.h" // get_signature..
Expand Down Expand Up @@ -476,14 +477,9 @@ static int CmdDbg(const char *Cmd) {
return PM3_EINVARG;
}

clearCommandBuffer();
SendCommandNG(CMD_GET_DBGMODE, NULL, 0);
PacketResponseNG resp;
if (WaitForResponseTimeout(CMD_GET_DBGMODE, &resp, 2000) == false) {
PrintAndLogEx(WARNING, "Failed to get current device debug level");
return PM3_ETIMEOUT;
}
uint8_t curr = resp.data.asBytes[0];
uint8_t curr = DBG_NONE;
if (getDeviceDebugLevel(&curr) != PM3_SUCCESS)
return PM3_EFAILED;

const char *dbglvlstr;
switch (curr) {
Expand Down Expand Up @@ -522,8 +518,8 @@ static int CmdDbg(const char *Cmd) {
else if (lv4)
dbg = 4;

clearCommandBuffer();
SendCommandNG(CMD_SET_DBGMODE, &dbg, sizeof(dbg));
if (setDeviceDebugLevel(dbg, true) != PM3_SUCCESS)
return PM3_EFAILED;
}
return PM3_SUCCESS;
}
Expand Down
38 changes: 38 additions & 0 deletions client/src/preferences.c
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,44 @@ static int setCmdDeviceDebug (const char *Cmd)
}
*/

int getDeviceDebugLevel (uint8_t *debug_level) {
if (!g_session.pm3_present)
return PM3_EFAILED;

clearCommandBuffer();
SendCommandNG(CMD_GET_DBGMODE, NULL, 0);
PacketResponseNG resp;
if (WaitForResponseTimeout(CMD_GET_DBGMODE, &resp, 2000) == false) {
PrintAndLogEx(WARNING, "Failed to get current device debug level");
return PM3_ETIMEOUT;
}

if (debug_level)
*debug_level = resp.data.asBytes[0];

return PM3_SUCCESS;
}

int setDeviceDebugLevel (uint8_t debug_level, bool verbose) {
if (!g_session.pm3_present)
return PM3_EFAILED;

if (verbose)
PrintAndLogEx (INFO,"setting device debug loglevel to %u", debug_level);

uint8_t cdata[] = {debug_level, verbose};
clearCommandBuffer();
SendCommandNG(CMD_SET_DBGMODE, cdata, sizeof(cdata));
PacketResponseNG resp;
if (WaitForResponseTimeout(CMD_SET_DBGMODE, &resp, 2000) == false) {
PrintAndLogEx (WARNING,"failed to set device debug loglevel");
return PM3_EFAILED;
}

return PM3_SUCCESS;
}


static int setCmdOutput(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "prefs set output",
Expand Down
3 changes: 3 additions & 0 deletions client/src/preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@ int preferences_save(void);
void preferences_save_callback(json_t *root);
void preferences_load_callback(json_t *root);

int getDeviceDebugLevel (uint8_t *debug_level);
int setDeviceDebugLevel (uint8_t debug_level, bool verbose);

#endif

0 comments on commit ebe9d72

Please sign in to comment.