dnp_ds40: Fix a bug in the new do_cmd() function.

Also move the debug output to be keyed off of DYESUB_DEBUG
This commit is contained in:
Solomon Peachy 2013-12-11 07:50:31 -05:00
parent 4715a088e3
commit 1ed58be6e3
1 changed files with 20 additions and 27 deletions

View File

@ -69,9 +69,6 @@ struct dnpds40_cmd {
static void dnpds40_build_cmd(struct dnpds40_cmd *cmd, char *arg1, char *arg2, uint32_t arg3_len) static void dnpds40_build_cmd(struct dnpds40_cmd *cmd, char *arg1, char *arg2, uint32_t arg3_len)
{ {
#if 0
uint i;
#endif
memset(cmd, 0x20, sizeof(*cmd)); memset(cmd, 0x20, sizeof(*cmd));
cmd->esc = 0x1b; cmd->esc = 0x1b;
cmd->p = 0x50; cmd->p = 0x50;
@ -80,13 +77,6 @@ static void dnpds40_build_cmd(struct dnpds40_cmd *cmd, char *arg1, char *arg2, u
if (arg3_len) if (arg3_len)
snprintf((char*)cmd->arg3, 8, "%08d", arg3_len); snprintf((char*)cmd->arg3, 8, "%08d", arg3_len);
#if 0
DEBUG("command: ");
for (i = 0 ; i < sizeof(*cmd); i++) {
DEBUG2("%02x ", *(((uint8_t*)cmd)+i));
}
DEBUG2("\n");
#endif
} }
static void dnpds40_cleanup_string(char *start, int len) static void dnpds40_cleanup_string(char *start, int len)
@ -165,8 +155,8 @@ static char *dnpds40_statuses(char *str)
} }
static int dnpds40_do_cmd(struct dnpds40_ctx *ctx, static int dnpds40_do_cmd(struct dnpds40_ctx *ctx,
struct dnpds40_cmd *cmd, struct dnpds40_cmd *cmd,
uint8_t *data, int len) uint8_t *data, int len)
{ {
int ret; int ret;
@ -174,7 +164,7 @@ static int dnpds40_do_cmd(struct dnpds40_ctx *ctx,
(uint8_t*)cmd, sizeof(*cmd)))) (uint8_t*)cmd, sizeof(*cmd))))
return ret; return ret;
if (*data && len) if (data && len)
if ((ret = send_data(ctx->dev, ctx->endp_down, if ((ret = send_data(ctx->dev, ctx->endp_down,
data, len))) data, len)))
return ret; return ret;
@ -208,11 +198,15 @@ static uint8_t * dnpds40_resp_cmd(struct dnpds40_ctx *ctx,
return NULL; return NULL;
} }
i = atoi(tmp); /* Length of payload in bytes, possibly padded */ if (getenv("DYESUB_DEBUG")) {
#if 0 DEBUG("<- ");
DEBUG("readback: '%s' len %d/%d\n", (char*) tmp, i, num); for (i = 0 ; i < num; i++) {
#endif DEBUG2("%02x ", tmp[i]);
}
DEBUG2("\n");
}
i = atoi(tmp); /* Length of payload in bytes, possibly padded */
respbuf = malloc(i); respbuf = malloc(i);
/* Read in the actual response */ /* Read in the actual response */
@ -223,6 +217,14 @@ static uint8_t * dnpds40_resp_cmd(struct dnpds40_ctx *ctx,
&num, &num,
5000); 5000);
if (getenv("DYESUB_DEBUG")) {
DEBUG("<- ");
for (i = 0 ; i < num; i++) {
DEBUG2("%02x ", respbuf[i]);
}
DEBUG2("\n");
}
if (ret < 0 || num != i) { if (ret < 0 || num != i) {
ERROR("Failure to receive data from printer (libusb error %d: (%d/%d from 0x%02x))\n", ret, num, i, ctx->endp_up); ERROR("Failure to receive data from printer (libusb error %d: (%d/%d from 0x%02x))\n", ret, num, i, ctx->endp_up);
@ -230,14 +232,6 @@ static uint8_t * dnpds40_resp_cmd(struct dnpds40_ctx *ctx,
return NULL; return NULL;
} }
#if 0
DEBUG("response: ");
for (i = 0 ; i < num; i++) {
DEBUG2("%02x ", respbuf[i]);
}
DEBUG2("\n");
#endif
*len = num; *len = num;
return respbuf; return respbuf;
} }
@ -379,7 +373,6 @@ top:
// XXX for now, dump the whole spool file over. Parse first? // XXX for now, dump the whole spool file over. Parse first?
DEBUG("Sending %d bytes to printer\n", ctx->datalen);
if ((ret = send_data(ctx->dev, ctx->endp_down, if ((ret = send_data(ctx->dev, ctx->endp_down,
ctx->databuf, ctx->datalen))) ctx->databuf, ctx->datalen)))
return ret; return ret;
@ -740,7 +733,7 @@ static int dnpds40_cmdline_arg(void *vctx, int run, char *arg1, char *arg2)
/* Exported */ /* Exported */
struct dyesub_backend dnpds40_backend = { struct dyesub_backend dnpds40_backend = {
.name = "DNP DS40/DS80", .name = "DNP DS40/DS80",
.version = "0.10", .version = "0.11",
.uri_prefix = "dnpds40", .uri_prefix = "dnpds40",
.cmdline_usage = dnpds40_cmdline, .cmdline_usage = dnpds40_cmdline,
.cmdline_arg = dnpds40_cmdline_arg, .cmdline_arg = dnpds40_cmdline_arg,