From 4a2d741b7eab9f4a9678deda80b935f436384b02 Mon Sep 17 00:00:00 2001 From: Peter Hurley Date: Wed, 1 Feb 2012 09:41:49 -0500 Subject: [PATCH 1/3] Fix supply level computation for 'percent' SupplyUnit Some printers report supply levels as percent already. This condition is indicated when the prtMarkerSuppliesSupplyUnit value is 19 (= 'percent'), as enumerated in Apple technical note TN2144. Signed-off-by: Peter Hurley --- backend/backend-private.h | 19 +++++++++++++++++++ backend/snmp-supplies.c | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletions(-) diff --git a/backend/backend-private.h b/backend/backend-private.h index 95dc2d8..a94b874 100644 --- a/backend/backend-private.h +++ b/backend/backend-private.h @@ -259,6 +259,25 @@ extern "C" { #define CUPS_TC_inserts 33 #define CUPS_TC_covers 34 +/* Values defined in RFC 1759 + * http://tools.ietf.org/html/rfc1759#page-61 + * Additional values from Apple technical note TN2144 + * http://developer.apple.com/library/mac/#technotes/tn2144/_index.html + */ +#define CUPS_TC_tenthousandthsofinches 3 +#define CUPS_TC_micrometers 4 +#define CUPS_TC_impressions 7 +#define CUPS_TC_sheets 8 +#define CUPS_TC_hours 11 +#define CUPS_TC_thousandthsofounces 12 +#define CUPS_TC_tenthsofgrams 13 +#define CUPS_TC_hundredsoffluidounces 14 +#define CUPS_TC_tenthsofmilliliters 15 +#define CUPS_TC_feet 16 +#define CUPS_TC_meters 17 +#define CUPS_TC_items 18 +#define CUPS_TC_percent 19 + /* These come from RFC 3808 to define character sets we support */ /* Also see http://www.iana.org/assignments/character-sets */ #define CUPS_TC_csASCII 3 diff --git a/backend/snmp-supplies.c b/backend/snmp-supplies.c index 4d8e52e..b3da3cb 100644 --- a/backend/snmp-supplies.c +++ b/backend/snmp-supplies.c @@ -56,6 +56,7 @@ typedef struct /**** Printer supply data ****/ color[8]; /* Color: "#RRGGBB" or "none" */ int colorant, /* Colorant index */ type, /* Supply type */ + units, /* Supply units (capacity & level)*/ max_capacity, /* Maximum capacity */ level; /* Current level value */ } backend_supplies_t; @@ -146,6 +147,13 @@ static const int prtMarkerSuppliesType[] = (sizeof(prtMarkerSuppliesType) / sizeof(prtMarkerSuppliesType[0])); /* Offset to supply index */ +static const int prtMarkerSuppliesSupplyUnit[] = + { CUPS_OID_prtMarkerSuppliesSupplyUnit, -1 }, + /* Type OID */ + prtMarkerSuppliesSupplyUnitOffset = + (sizeof(prtMarkerSuppliesSupplyUnit) / + sizeof(prtMarkerSuppliesSupplyUnit[0])); + /* Offset to supply index */ static const backend_state_t const printer_states[] = { @@ -230,7 +238,12 @@ backendSNMPSupplies( for (i = 0, ptr = value; i < num_supplies; i ++, ptr += strlen(ptr)) { if (supplies[i].max_capacity > 0) - percent = 100 * supplies[i].level / supplies[i].max_capacity; + { + if (supplies[i].units == CUPS_TC_percent) + percent = supplies[i].level; + else + percent = 100 * supplies[i].level / supplies[i].max_capacity; + } else percent = 50; @@ -916,6 +929,25 @@ backend_walk_cb(cups_snmp_t *packet, /* I - SNMP packet */ supplies[i - 1].type = packet->object_value.integer; } + else if (_cupsSNMPIsOIDPrefixed(packet, prtMarkerSuppliesSupplyUnit)) + { + /* + * Get marker supply units... + */ + + i = packet->object_name[prtMarkerSuppliesSupplyUnitOffset]; + if (i < 1 || i > CUPS_MAX_SUPPLIES || + packet->object_type != CUPS_ASN1_INTEGER) + return; + + fprintf(stderr, "DEBUG2: prtMarkerSuppliesSupplyUnit.1.%d = %d\n", i, + packet->object_value.integer); + + if (i > num_supplies) + num_supplies = i; + + supplies[i - 1].units = packet->object_value.integer; + } } -- 1.7.5.4