Skip to content

Commit

Permalink
Improve debug messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
matlo committed Nov 5, 2016
1 parent dacc5f5 commit dc4cabe
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 18 deletions.
12 changes: 5 additions & 7 deletions core/adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,26 +267,24 @@ int adapter_get_controller(e_device_type device_type, int device_id)
return device_adapter[device_type-1][device_id];
}

static int debug = 0;

static void dump(unsigned char * packet, unsigned char length)
{
int i;
for (i = 0; i < length; ++i)
{
if(i && !(i%8))
{
gprintf("\n");
ncprintf("\n");
}
gprintf("0x%02x ", packet[i]);
ncprintf("0x%02x ", packet[i]);
}
gprintf("\n");
ncprintf("\n");
}

#define DEBUG_PACKET(PACKET, LENGTH) \
if(debug) \
if(gimx_params.debug.adapter) \
{ \
gprintf("%s\n", __func__); \
printf("%s\n", __func__); \
dump(data, length); \
}

Expand Down
9 changes: 8 additions & 1 deletion core/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ int args_read(int argc, char *argv[], s_gimx_params* params)
{"curses", no_argument, &params->curses, 1},
{"window-events", no_argument, &params->window_events, 1},
{"btstack", no_argument, &params->btstack, 1},
{"debug", no_argument, &params->debug, 1},
{"debug.ff_lg", no_argument, &params->debug.ff_lg, 1},
{"debug.ff_conv", no_argument, &params->debug.ff_conv, 1},
{"debug.adapter", no_argument, &params->debug.adapter, 1},
{"skip_leds", no_argument, &params->skip_leds, 1},
/* These options don't set a flag. We distinguish them by their indices. */
{"bdaddr", required_argument, 0, 'b'},
Expand Down Expand Up @@ -427,5 +429,10 @@ int args_read(int argc, char *argv[], s_gimx_params* params)
log_info();
}

if (params->debug.ff_conv != 0)
{
params->debug.ff_lg = 1;
}

return ret;
}
2 changes: 1 addition & 1 deletion core/gimx.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ s_gimx_params gimx_params =
.frequency_scale = 1,
.status = 0,
.curses = 0,
.debug = 0,
.debug = {},
.config_file = NULL,
.postpone_count = DEFAULT_POSTPONE_COUNT,
.subpositions = 0,
Expand Down
6 changes: 4 additions & 2 deletions core/haptic/ff_conv.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <gimx.h>
#include <string.h>

#define dprintf(...) if(gimx_params.debug.ff_conv) printf(__VA_ARGS__)

#define CLAMP(MIN,VALUE,MAX) (((VALUE) < MIN) ? (MIN) : (((VALUE) > MAX) ? (MAX) : (VALUE)))

static inline short u8_to_s16(unsigned char c) {
Expand Down Expand Up @@ -198,7 +200,7 @@ static int ff_conv_lg_force(int device, unsigned int index, GE_Event * event) {
break;
}

if(gimx_params.debug && ret != 0) {
if(gimx_params.debug.ff_conv && ret != 0) {
dump_event(event);
}

Expand All @@ -209,7 +211,7 @@ int ff_conv(int device, const unsigned char data[FF_LG_OUTPUT_REPORT_SIZE], GE_E

CHECK_DEVICE(device, -1)

if(gimx_params.debug) {
if(gimx_params.debug.ff_conv) {
dprintf("> ");
if(data[0] == FF_LG_CMD_EXTENDED_COMMAND) {
ff_lg_decode_extended(data);
Expand Down
10 changes: 6 additions & 4 deletions core/haptic/ff_lg.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <gimx.h>
#include <limits.h>

#define dprintf(...) if(gimx_params.debug.ff_lg) printf(__VA_ARGS__)

#define CLAMP(MIN,VALUE,MAX) (((VALUE) < MIN) ? (MIN) : (((VALUE) > MAX) ? (MAX) : (VALUE)))

static unsigned char fslot_nbits [] = {
Expand Down Expand Up @@ -410,7 +412,7 @@ void ff_lg_process_report(int device, const unsigned char data[FF_LG_OUTPUT_REPO
return;
}

if(gimx_params.debug) {
if(gimx_params.debug.ff_lg) {
dprintf("> ");
if(data[0] == FF_LG_CMD_EXTENDED_COMMAND) {
ff_lg_decode_extended(data);
Expand Down Expand Up @@ -753,7 +755,7 @@ int ff_lg_get_report(int device, s_ff_lg_report * report) {
{
// not a slot update
data[0] = cmd.cmd;
if(gimx_params.debug) {
if(gimx_params.debug.ff_lg) {
ff_lg_decode_command(data);
}
*report = ff_lg_device[device].last_report;
Expand All @@ -770,7 +772,7 @@ int ff_lg_get_report(int device, s_ff_lg_report * report) {
data[0] = cmd.cmd | FF_LG_CMD_STOP;
}
forces[index].updated = 0;
if(gimx_params.debug) {
if(gimx_params.debug.ff_lg) {
ff_lg_decode_command(data);
}
return convert_force(device, report);
Expand All @@ -782,7 +784,7 @@ int ff_lg_get_report(int device, s_ff_lg_report * report) {
s_ext_cmd * ext_cmd = ff_lg_device[device].ext_cmds + i;
if(ext_cmd->cmd[1] == cmd.ext) {
memcpy(data, ext_cmd->cmd, sizeof(ext_cmd->cmd));
if(gimx_params.debug) {
if(gimx_params.debug.ff_lg) {
ff_lg_decode_extended(data);
}
ext_cmd->updated = 0;
Expand Down
7 changes: 5 additions & 2 deletions core/include/gimx.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ typedef struct
double frequency_scale;
int status;
int curses;
int debug;
struct {
int ff_lg;
int ff_conv;
int adapter;
} debug;
char* config_file;
int postpone_count;
int subpositions;
Expand All @@ -48,7 +52,6 @@ typedef struct
extern s_gimx_params gimx_params;

#define gprintf(...) if(gimx_params.status) printf(__VA_ARGS__)
#define dprintf(...) if(gimx_params.debug) printf(__VA_ARGS__)
#define ncprintf(...) if(!gimx_params.curses) printf(__VA_ARGS__)
#define eprintf(msg) fprintf(stderr, "%s:%d %s: %s\n", __FILE__, __LINE__, __func__, msg)

Expand Down
54 changes: 53 additions & 1 deletion launcher/gimx-launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,7 @@ launcherFrame::launcherFrame(wxWindow* parent,wxWindowID id __attribute__((unuse
ProcessOutputChoice->Append(_("curses"));
ProcessOutputChoice->Append(_("text"));
ProcessOutputChoice->Append(_("log file"));
ProcessOutputChoice->Append(_("debug"));
FlexGridSizer3->Add(ProcessOutputChoice, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
FlexGridSizer8->Add(FlexGridSizer3, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
MouseSizer = new wxFlexGridSizer(1, 2, 0, 0);
Expand Down Expand Up @@ -1025,6 +1026,8 @@ launcherFrame::launcherFrame(wxWindow* parent,wxWindowID id __attribute__((unuse
}

refreshGui();

openLog = false;
}

launcherFrame::~launcherFrame()
Expand Down Expand Up @@ -1071,6 +1074,24 @@ void MyProcess::OnTerminate(int pid __attribute__((unused)), int status)
m_parent->OnProcessTerminated(this, status);
}

void launcherFrame::readDebugStrings(wxArrayString & values)
{
wxArrayString choices;
choices.Add(wxT("adapter"));
choices.Add(wxT("ff_conv"));
choices.Add(wxT("ff_lg"));
wxMultiChoiceDialog dialog(this, _("Select the files to debug:"), _(""), choices);

if (dialog.ShowModal() == wxID_OK)
{
wxArrayInt selections = dialog.GetSelections();
for (size_t n = 0; n < selections.GetCount(); n++)
{
values.Add(choices[selections[n]]);
}
}
}

void launcherFrame::OnButtonStartClick(wxCommandEvent& event __attribute__((unused)))
{
wxString command;
Expand Down Expand Up @@ -1200,6 +1221,36 @@ void launcherFrame::OnButtonStartClick(wxCommandEvent& event __attribute__((unus
{
command.Append(wxT(" --status --log "));
command.Append(wxT(LOG_FILE));
openLog = true;
}
else if(ProcessOutputChoice->GetStringSelection() == _("debug"))
{
wxArrayString destination;
destination.Add(_("text"));
destination.Add(_("log file"));
wxSingleChoiceDialog dialog(this, _("Select the destination:"), _(""), destination);
if (dialog.ShowModal() == wxID_OK)
{
wxString selection = dialog.GetStringSelection();
if(selection == _("text"))
{
command.Append(wxT(" --status"));
}
else if(selection == _("log file"))
{
command.Append(wxT(" --status --log "));
command.Append(wxT(LOG_FILE));
openLog = true;
}
}

wxArrayString values;
readDebugStrings(values);
for (size_t n = 0; n < values.GetCount(); n++)
{
command.Append(wxT(" --debug."));
command.Append(values[n]);
}
}

if(Input->GetStringSelection() == _("Network"))
Expand Down Expand Up @@ -1303,14 +1354,15 @@ void launcherFrame::OnProcessTerminated(wxProcess *process __attribute__((unused
OnMenuSave(event);
}

if(ProcessOutputChoice->GetStringSelection() == _("log file"))
if(openLog)
{
#ifdef WIN32
gimxLogDir.Replace(wxT("/"), wxT("\\"));
wxExecute(wxT("explorer ") + gimxLogDir + wxT(LOG_FILE), wxEXEC_ASYNC, NULL);
#else
wxExecute(wxT("xdg-open ") + gimxLogDir + wxT(LOG_FILE), wxEXEC_ASYNC, NULL);
#endif
openLog = false;
}
else
{
Expand Down
4 changes: 4 additions & 0 deletions launcher/gimx-launcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ class launcherFrame: public wxFrame
int readDonglePairings(vector<BluetoothPairing>& donglePairings);
BluetoothPairing selectBrokenPairing(vector<BluetoothPairing>& brokenDonglePairings);

void readDebugStrings(wxArrayString & values);

//(*Identifiers(launcherFrame)
static const long ID_STATICTEXT4;
static const long ID_CHOICE1;
Expand Down Expand Up @@ -194,6 +196,8 @@ class launcherFrame: public wxFrame

wxArrayString hids;

bool openLog;

DECLARE_EVENT_TABLE()
};

Expand Down
1 change: 1 addition & 0 deletions launcher/wxsmith/launcherframe.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
<item>curses</item>
<item>text</item>
<item>log file</item>
<item>debug</item>
</content>
<selection>0</selection>
</object>
Expand Down

0 comments on commit dc4cabe

Please sign in to comment.