dnpds40: Decode sensor information as much as possible.

This commit is contained in:
Solomon Peachy 2015-06-30 20:51:30 -04:00
parent c3044c7fc7
commit 14af6acbb9
2 changed files with 77 additions and 24 deletions

1
README
View File

@ -445,6 +445,7 @@
Valid commands:
-i Query printer information (resolution, etc)
-I Query printer sensor information
-n Query printer counters
-N [ A | B | M ] Reset Counter A/B/M [2]
-p num Set 'P' counter to 'num'

View File

@ -983,6 +983,73 @@ top:
return CUPS_BACKEND_OK;
}
static int dnpds40_get_sensors(struct dnpds40_ctx *ctx)
{
struct dnpds40_cmd cmd;
uint8_t *resp;
int len = 0;
char *tok;
/* Get Sensor Info */
dnpds40_build_cmd(&cmd, "INFO", "SENSOR", 0);
resp = dnpds40_resp_cmd(ctx, &cmd, &len);
if (!resp)
return CUPS_BACKEND_FAILED;
dnpds40_cleanup_string((char*)resp, len);
tok = strtok((char*)resp, "; -");
do {
char *val = strtok(NULL, "; -");
if (!strcmp("HDT", tok)) {
INFO("Head Temperature : %s\n", val);
} else if (!strcmp("MDT", tok)) {
INFO("Media Temperature : %s\n", val);
} else if (!strcmp("PMK", tok)) {
INFO("Paper Mark : %s\n", val);
} else if (!strcmp("RML", tok)) {
INFO("Ribbon Mark Left : %s\n", val);
} else if (!strcmp("RMC", tok)) {
INFO("Ribbon Mark Right : %s\n", val);
} else if (!strcmp("RMR", tok)) {
INFO("Ribbon Mark Center : %s\n", val);
} else if (!strcmp("PSZ", tok)) {
INFO("Paper Size : %s\n", val);
} else if (!strcmp("PNT", tok)) {
INFO("Paper Notch : %s\n", val);
} else if (!strcmp("PJM", tok)) {
INFO("Paper Jam : %s\n", val);
} else if (!strcmp("PED", tok)) {
INFO("Paper End : %s\n", val);
} else if (!strcmp("PET", tok)) {
INFO("Paper Empty : %s\n", val);
} else if (!strcmp("HDV", tok)) {
INFO("Head Voltage : %s\n", val);
} else if (!strcmp("HMD", tok)) {
INFO("Humidity : %s\n", val);
} else if (!strcmp("RP1", tok)) {
INFO("Roll Paper End 1 : %s\n", val);
} else if (!strcmp("RP2", tok)) {
INFO("Roll Paper End 2 : %s\n", val);
} else if (!strcmp("GSR", tok)) {
INFO("Color Sensor Red : %s\n", val);
} else if (!strcmp("GSG", tok)) {
INFO("Color Sensor Green : %s\n", val);
} else if (!strcmp("GSB", tok)) {
INFO("Color Sensor Blue : %s\n", val);
} else {
INFO("Unknown Sensor: '%s' '%s'\n",
tok, val);
}
} while ((tok = strtok(NULL, "; -")) != NULL);
free(resp);
return CUPS_BACKEND_OK;
}
static int dnpds40_get_info(struct dnpds40_ctx *ctx)
{
struct dnpds40_cmd cmd;
@ -995,26 +1062,6 @@ static int dnpds40_get_info(struct dnpds40_ctx *ctx)
/* Firmware version already queried */
INFO("Firmware Version: '%s'\n", ctx->version);
/* Get Sensor Info */
dnpds40_build_cmd(&cmd, "INFO", "SENSOR", 0);
resp = dnpds40_resp_cmd(ctx, &cmd, &len);
if (!resp)
return CUPS_BACKEND_FAILED;
dnpds40_cleanup_string((char*)resp, len);
INFO("Sensor Info:\n");
{
char *tmp;
tmp = strtok((char*)resp, "; ");
do {
// XXX parse the components?
INFO(" %s\n", tmp);
} while ((tmp = strtok(NULL, "; ")) != NULL);
}
free(resp);
/* Get Horizonal resolution */
dnpds40_build_cmd(&cmd, "INFO", "RESOLUTION_H", 0);
@ -1024,7 +1071,7 @@ static int dnpds40_get_info(struct dnpds40_ctx *ctx)
dnpds40_cleanup_string((char*)resp, len);
INFO("Horizontal Resolution: '%s' dpi\n", (char*)resp + 3);
INFO("Horizontal Resolution : '%s' dpi\n", (char*)resp + 3);
free(resp);
@ -1037,7 +1084,7 @@ static int dnpds40_get_info(struct dnpds40_ctx *ctx)
dnpds40_cleanup_string((char*)resp, len);
INFO("Vertical Resolution: '%s' dpi\n", (char*)resp + 3);
INFO("Vertical Resolution : '%s' dpi\n", (char*)resp + 3);
free(resp);
@ -1496,7 +1543,7 @@ static int dnpds40_cmdline_arg(void *vctx, int argc, char **argv)
/* Reset arg parsing */
optind = 1;
opterr = 0;
while ((i = getopt(argc, argv, "inN:p:sS:")) >= 0) {
while ((i = getopt(argc, argv, "iInN:p:sS:")) >= 0) {
switch(i) {
case 'i':
if (ctx) {
@ -1504,6 +1551,11 @@ static int dnpds40_cmdline_arg(void *vctx, int argc, char **argv)
break;
}
return 1;
case 'I':
if (ctx) {
j = dnpds40_get_sensors(ctx);
break;
}
case 'n':
if (ctx) {
j = dnpds40_get_counters(ctx);
@ -1564,7 +1616,7 @@ static int dnpds40_cmdline_arg(void *vctx, int argc, char **argv)
/* Exported */
struct dyesub_backend dnpds40_backend = {
.name = "DNP DS40/DS80/DSRX1/DS620",
.version = "0.51",
.version = "0.52",
.uri_prefix = "dnpds40",
.cmdline_usage = dnpds40_cmdline,
.cmdline_arg = dnpds40_cmdline_arg,