/*****************************************************************************\
hpiom.c - HP I/O message handler
(c) 2003-2004 Copyright Hewlett-Packard Development Company, LP
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of Hewlett-Packard nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PATENT INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\*****************************************************************************/
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include "hpijs.h"
#include "hpiom.h"
static int hpiod_port_num = 50000;
static int hpiod_socket=-1;
static const int gnMaxDataSize = 2048;
static const int gnMaxCmdOptionSize = 4;
static const char gcFrameMarker = '$';
static const int gnPadding = 255;
static const int gnRequiredSize = 11;
static const int gnMinCommandSize = 16;
static const int gnMinDecodeSize = 10; // needed six bytes to determine command number,
// command length and data length
static const int gUV8FrameOffset = 0;
static const int gUV16CommandLengthOffset = 1;
static const int gUV8UnitNumberOffset = 3;
static const int gE8PacketTypeOffset = 4;
static const int gUV8CommandNumberOffset = 5;
static const int gUV16ReferenceNumberOffset = 6;
static const int gUV16DataLengthOffset = 8;
static const int gUV8CommandOptionsOffset = 10;
static const int gUV8RespFrameOffset = 0;
static const int gUV16RespCommandLengthOffset = 1;
static const int gUV8RespUnitNumberOffset = 3;
static const int gE8RespPacketTypeOffset = 4;
static const int gUV8RespCommandNumberOffset = 5;
static const int gUV16RespReferenceNumberOffset = 6;
static const int gUV16RespDataLengthOffset = 8;
static const int gE8RespCompleteOffset = 10;
// reserved reference number
//
static const int gnMinRefNum = 0xF000;
static const int gnMaxRefNum = 0xFFFD;
unsigned short gwSynchRefNum = 0xFFEC;
unsigned short gwSynchCompleteRefNum = 0xFFEB;
unsigned short gwResetRefNum = 0xFFEA;
unsigned short gwPrinterVersionQueryRefNum = 0xFFD0;
unsigned short gwPrinterStatusQueryRefNum = 0xFFD1;
unsigned short gwPrinterAttributesQueryRefNum = 0xFFD2;
unsigned short gwAlignmentQueryRefNum = 0xFFD3;
unsigned short gwDeviceIdQueryRefNum = 0xFFDD;
unsigned short gwHueCompensationQueryRefNum = 0xFFDE;
// command options
//
// printer query command options
//
static const int gnPrinterQueryOptionsSize = 4;
static unsigned char gpPrinterVersionQuery[] = { 0x00, 0x00, 0x00, 0x00 }; // 0 - return UV32 version data
//static unsigned char gpPrinterStatusQuery[] = { 0x01, 0x00, 0x00, 0x00 }; // 1 - return status string
//static unsigned char gpPrinterAttributesQuery[] = { 0x02, 0x00, 0x00, 0x00 }; // 2 - return printer attributes
static unsigned char gpAlignmentQuery[] = { 0x03, 0x00, 0x00, 0x00 }; // 3 - return primitive alignment value
//static unsigned char gpDeviceIdQuery[] = { 0x0D, 0x00, 0x00, 0x00 }; // 13 - return device id
//static unsigned char gpHueCompensationQuery[] = { 0x0E, 0x00, 0x00, 0x00 }; // 14 - return hue compensation
static unsigned char gpPenAlignmentQuery[] = { 0x0F, 0x00, 0x00, 0x00 }; // 15 - return pen alignment value
int GetPair(char *buf, char *key, char *value, char **tail)
{
int i=0, j;
key[0] = 0;
value[0] = 0;
if (buf[i] == '#')
{
for (; buf[i] != '\n' && i < HEADER_SIZE; i++); /* eat comment line */
i++;
}
if (strncasecmp(&buf[i], "data:", 5) == 0)
{
strcpy(key, "data:"); /* "data:" key has no value */
i+=5;
}
else
{
j = 0;
while ((buf[i] != '=') && (i < HEADER_SIZE) && (j < LINE_SIZE))
key[j++] = buf[i++];
for (j--; key[j] == ' ' && j > 0; j--); /* eat white space before = */
key[++j] = 0;
for (i++; buf[i] == ' ' && i < HEADER_SIZE; i++); /* eat white space after = */
j = 0;
while ((buf[i] != '\n') && (i < HEADER_SIZE) && (j < LINE_SIZE))
value[j++] = buf[i++];
for (j--; value[j] == ' ' && j > 0; j--); /* eat white space before \n */
value[++j] = 0;
}
i++; /* bump past '\n' */
if (tail != NULL)
*tail = buf + i; /* tail points to next line */
return i;
}
int ReadConfig()
{
char rcbuf[255];
FILE *inFile;
char *tail;
if((inFile = fopen(HPIODFILE, "r")) == NULL)
{
bug("unable to open %s: %m\n", HPIODFILE);
return 1;
}
if (fgets(rcbuf, sizeof(rcbuf), inFile) != NULL)
hpiod_port_num = strtol(rcbuf, &tail, 10);
fclose(inFile);
return 0;
}
//System::ParseMsg
//! Parse and convert all key value pairs in message. Do sanity check on values.
/*!
******************************************************************************/
int ParseMsg(char *buf, int len, MsgAttributes *ma)
{
char key[LINE_SIZE];
char value[LINE_SIZE];
char *tail, *tail2;
int i, ret=R_AOK;
ma->cmd[0] = 0;
ma->descriptor = -1;
ma->length = 0;
ma->channel = -1;
ma->data = NULL;
ma->result = -1;
ma->writelen = 0;
ma->readlen = 0;
ma->status = 0;
i = GetPair(buf, key, value, &tail);
if (strcasecmp(key, "msg") != 0)
{
bug("invalid message:%s\n", key);
return R_INVALID_MESSAGE;
}
strncpy(ma->cmd, value, sizeof(ma->cmd));
while (i < len)
{
i += GetPair(tail, key, value, &tail);
if (strcasecmp(key, "device-id") == 0)
{
ma->descriptor = strtol(value, &tail2, 10);
if (ma->descriptor < 0)
{
bug("invalid device descriptor:%d\n", ma->descriptor);
ret = R_INVALID_DESCRIPTOR;
break;
}
}
else if (strcasecmp(key, "channel-id") == 0)
{
ma->channel = strtol(value, &tail2, 10);
if (ma->channel < 0)
{
bug("invalid channel descriptor:%d\n", ma->channel);
ret = R_INVALID_CHANNEL_ID;
break;
}
}
else if (strcasecmp(key, "length") == 0)
{
ma->length = strtol(value, &tail2, 10);
if (ma->length > BUFFER_SIZE)
{
bug("invalid data length:%d\n", ma->length);
ret = R_INVALID_LENGTH;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
惠普打印机内部源代码
共466个文件
ppd:317个
h:65个
cpp:64个
4星 · 超过85%的资源 需积分: 34 56 下载量 16 浏览量
2012-06-09
11:27:17
上传
评论 2
收藏 1.85MB RAR 举报
温馨提示
惠普打印机
资源推荐
资源详情
资源评论
收起资源包目录
惠普打印机内部源代码 (466个子文件)
Makefile.am 4KB
hpiom.c 26KB
ijs_server.c 20KB
ijs.c 5KB
ijs_exec_unix.c 3KB
configure 183KB
dj3320.cpp 111KB
filterhpa.cpp 77KB
dj3600_cmap.cpp 63KB
dj3320_cmap.cpp 63KB
dj9xxvip.cpp 59KB
breaks_open.cpp 54KB
context.cpp 53KB
printer.cpp 36KB
phobos_cmaps.cpp 32KB
job.cpp 28KB
dj970_maps.cpp 27KB
dj895_maps2.cpp 24KB
dj690_maps.cpp 22KB
dj9xx.cpp 21KB
hpijs.cpp 19KB
compression.cpp 19KB
script.cpp 18KB
registry.cpp 18KB
dj600_maps.cpp 17KB
ljcolor.cpp 17KB
printerfactory.cpp 17KB
dj8xx.cpp 16KB
halftoner_open.cpp 14KB
systemservices.cpp 14KB
header.cpp 13KB
dj970_maps2.cpp 13KB
dj970_maps3.cpp 13KB
djgenericvip.cpp 13KB
dj850_maps.cpp 12KB
dj850.cpp 11KB
halftoner.cpp 11KB
dj895_maps.cpp 11KB
dj660_maps.cpp 11KB
services.cpp 10KB
ljmono.cpp 10KB
apollo2xxx.cpp 8KB
dj630.cpp 8KB
colormatch.cpp 8KB
dj690.cpp 8KB
htmtxhi.cpp 7KB
pmselect.cpp 7KB
globals.cpp 7KB
colormatcher_open.cpp 7KB
capture.cpp 7KB
scaler_open.cpp 7KB
dj8x5.cpp 6KB
dj660.cpp 6KB
psp100.cpp 6KB
dj600.cpp 6KB
printerproxy.cpp 5KB
dj3600.cpp 5KB
versioncode.cpp 5KB
dj540.cpp 5KB
scaler.cpp 5KB
dj350.cpp 4KB
apollo21xx.cpp 4KB
translator.cpp 3KB
creator.cpp 3KB
dj890.cpp 3KB
dj6xx.cpp 3KB
apollo2560.cpp 2KB
version.cpp 2KB
create_so.cpp 2KB
models.cpp 2KB
depcomp 14KB
foomatic-rip 193KB
config.guess 43KB
interp_data_50.h 35KB
internal.h 29KB
global_types.h 16KB
font.h 16KB
systemservices.h 13KB
context.h 12KB
config.h 12KB
printer.h 11KB
dj3320.h 10KB
dj9xxvip.h 9KB
hpprint_c_api.h 9KB
ldlencap.h 8KB
halftoner.h 7KB
printerfactory.h 7KB
filterhpa.h 6KB
dj9xx.h 6KB
djgenericvip.h 5KB
hpiom.h 5KB
colormatch.h 5KB
ernieplatform.h 5KB
job.h 5KB
psp100.h 5KB
script.h 5KB
ljcolor.h 4KB
compression.h 4KB
htfed.h 4KB
services.h 4KB
共 466 条
- 1
- 2
- 3
- 4
- 5
资源评论
- Neo_yyp2014-02-10没看懂里面的内容
- milo_xu2013-01-25之前下过一次,其实就是hpijs-1.7.1,名字没写清楚,重复下载了
- 泽蕴/kaillen/ziegler2020-04-12实用有帮助。
- jiangzhkaaaaa2012-12-31呵呵~~~~~还是有点用处的,感谢楼主啊
- heaven9182012-11-04暂时还没有使用,希望有用
RNCHXY
- 粉丝: 0
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功