1 /*________________________________ epson-protocol.c _________________________________*/
\r
3 /* 1 2 3 4 5 6 7 8 */
\r
4 /*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
\r
5 /*******************************************|********************************************/
\r
7 * Copyright (c) 2009 Seiko Epson Corporation All rights reserved.
\r
9 * Copyright protection claimed includes all forms and matters of copyrightable
\r
10 * material and information now allowed by statutory or judicial law or hereinafter
\r
11 * granted, including without limitation, material generated from the software
\r
12 * programs which are displayed on the screen such as icons, screen display looks,
\r
15 /*******************************************|********************************************/
\r
17 /* Protocol Depend functions */
\r
19 /* Public Function Calls */
\r
20 /* -------------------------- */
\r
21 /* EPS_ERR_CODE prtFunctionCheck (commMode, usbFuncPtrs, netFuncPtrs, */
\r
22 /* cmnFuncPtrs ); */
\r
23 /* EPS_ERR_CODE prtFindPrinter (timeout ); */
\r
24 /* void prtCancelFindPrinter ( ); */
\r
25 /* EPS_ERR_CODE prtProbePrinterByID (probeParam ); */
\r
26 /* EPS_ERR_CODE prtProbePrinterByAddr (probeParam ); */
\r
27 /* EPS_ERR_CODE prtRecoverPE ( ); */
\r
28 /* EPS_ERR_CODE prtGetPMString (printer, pString, bufSize ); */
\r
29 /* EPS_ERR_CODE prtRegPrinter (printer, bNotify ); */
\r
30 /* EPS_ERR_CODE prtIsRegistered (Address, Protocol ); */
\r
31 /* EPS_ERR_CODE prtClearPrinterList (printer ); */
\r
32 /* EPS_ERR_CODE prtClearSupportedMedia (printer ); */
\r
33 /* EPS_ERR_CODE prtSetIdStr (printer, idString ); */
\r
35 /*******************************************|********************************************/
\r
37 /*------------------------------------ Includes -------------------------------------*/
\r
38 /*******************************************|********************************************/
\r
39 #include "epson-escpr-pvt.h"
\r
40 #include "epson-escpr-err.h"
\r
41 #include "epson-escpr-services.h"
\r
42 #include "epson-escpr-mem.h"
\r
43 #ifdef GCOMSW_CMD_ESCPAGE
\r
44 #include "epson-escpage.h"
\r
46 #ifdef GCOMSW_CMD_ESCPAGE_S
\r
47 #include "epson-escpage-s.h"
\r
50 #include "epson-protocol.h"
\r
52 #ifdef GCOMSW_PRT_USE_USB
\r
53 #include "epson-usb.h"
\r
56 #ifdef GCOMSW_PRT_USE_LPR
\r
57 #include "epson-net-lpr.h"
\r
60 #ifdef GCOMSW_PRT_USE_RAW
\r
61 #include "epson-net-raw.h"
\r
64 /*----------------------------- Local Macro Definitions -------------------------------*/
\r
65 /*******************************************|********************************************/
\r
66 #ifdef EPS_LOG_MODULE_PRTCOL
\r
67 #define EPS_LOG_MODULE EPS_LOG_MODULE_PRTCOL
\r
69 #define EPS_LOG_MODULE 0
\r
72 /*------------------------------------ Definition -----------------------------------*/
\r
73 /*******************************************|********************************************/
\r
74 /* Find Printer functions */
\r
75 typedef EPS_ERR_CODE (*NET_FindStart )(EPS_SOCKET*, const EPS_INT8*, EPS_BOOL );
\r
76 typedef EPS_ERR_CODE (*NET_FindCheck )(EPS_SOCKET, EPS_PRINTER_INN** );
\r
77 typedef EPS_ERR_CODE (*NET_FindEnd )(EPS_SOCKET );
\r
79 typedef struct tagEPS_FIND_FUNCS {
\r
80 NET_FindStart fncStart; /* Start function */
\r
81 NET_FindCheck fncCheck; /* Check function */
\r
82 NET_FindEnd fncEnd; /* End function */
\r
83 EPS_SOCKET sock; /* socekt */
\r
84 EPS_INT8 address[EPS_ADDR_BUFFSIZE];
\r
88 #define EPS_FINDNOTIFY_DELAY_COUNT (10)
\r
90 /*-------------------------- ESC/P-R Net Lib Global Variables ------------------------*/
\r
91 /*******************************************|********************************************/
\r
93 /*** Extern Function */
\r
94 /*** -------------------------------------------------------------------------------*/
\r
95 extern EPS_NET_FUNC epsNetFnc;
\r
96 extern EPS_CMN_FUNC epsCmnFnc;
\r
98 /*** Print Job Structure */
\r
99 /*** -------------------------------------------------------------------------------*/
\r
100 extern EPS_PRINT_JOB printJob;
\r
103 /*** -------------------------------------------------------------------------------*/
\r
104 EPS_BOOL g_FindBreak; /* Find printer end flag */
\r
105 EPS_INT32 g_FindProtocol;
\r
107 /*------------------------- Module "Local Global" Variables --------------------------*/
\r
108 /*******************************************|********************************************/
\r
110 /*** internal stock */
\r
111 /*** -------------------------------------------------------------------------------*/
\r
112 static EPS_PRINTER_LIST epsPrinterList; /* Printer List */
\r
116 /*-------------------------------- Local Functions ----------------------------------*/
\r
117 /*******************************************|********************************************/
\r
118 #ifdef GCOMSW_PRT_USE_NETWORK
\r
119 static EPS_ERR_CODE FindNetPrinter (EPS_INT32, EPS_UINT32, EPS_BOOL, const EPS_INT8* );
\r
121 static void MakePrinterStructure (EPS_PRINTER* dst, EPS_PRINTER_INN* src );
\r
122 static EPS_BOOL IsValidAddress (const EPS_INT8* );
\r
125 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
126 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
127 /*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
\r
128 /*-------------------- Public Functions ---------------------*/
\r
129 /*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
\r
130 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
131 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
133 /*******************************************|********************************************/
\r
135 /* Function name: prtFunctionCheck() */
\r
139 /* Name: Type: Description: */
\r
140 /* commMode EPS_INT8 I: Communication Mode */
\r
141 /* (Bi-Directional or Uni-Directional) */
\r
142 /* usbFuncPtrs EPS_USB_FUNC* I: Data structure containing function pointers to */
\r
143 /* USB I/O functions. */
\r
144 /* netFuncPtrs EPS_NET_FUNC* I: Data structure containing function pointers to */
\r
145 /* Socket I/O functions. */
\r
146 /* cmnFuncPtrs EPS_CMN_FUNC* I: Data structure containing function pointers to */
\r
147 /* external memory management functions. */
\r
148 /* Return value: */
\r
150 /* EPS_ERR_NONE - Success */
\r
152 /* EPS_ERR_INV_ARG_COMMMODE - Invalid argument "commMode" */
\r
153 /* EPS_ERR_INV_FNCP_NULL - Invalid function pointer structure */
\r
154 /* EPS_ERR_INV_FNCP_FINDCALLBACK - Invalid function pointer "findCallback" */
\r
155 /* EPS_ERR_INV_FNCP_MEMALLOC - Invalid function pointer "memAlloc" */
\r
156 /* EPS_ERR_INV_FNCP_MEMFREE - Invalid function pointer "memFree" */
\r
157 /* EPS_ERR_INV_FNCP_SLEEP - Invalid function pointer "sleep" */
\r
158 /* EPS_ERR_INV_FNCP_GETTIME - Invalid function pointer "GetTime" */
\r
159 /* EPS_ERR_INV_FNCP_OPENPORTAL - Invalid function pointer "openPortal" */
\r
160 /* EPS_ERR_INV_FNCP_CLOSEPORTAL - Invalid function pointer "closePortal" */
\r
161 /* EPS_ERR_INV_FNCP_READPORTAL - Invalid function pointer "readPortal" */
\r
162 /* EPS_ERR_INV_FNCP_WRITEPORTAL - Invalid function pointer "writePortal" */
\r
163 /* EPS_ERR_INV_FNCP_FINDFIRST - Invalid function pointer "findFirst" */
\r
164 /* EPS_ERR_INV_FNCP_FINDNEXT - Invalid function pointer "findNext" */
\r
165 /* EPS_ERR_INV_FNCP_FINDCLOSE - Invalid function pointer "findClose" */
\r
166 /* EPS_ERR_INV_FNCP_NETSOCKET - Invalid function pointer "socket" */
\r
167 /* EPS_ERR_INV_FNCP_NETCLOSE - Invalid function pointer "close" */
\r
168 /* EPS_ERR_INV_FNCP_NETCONNECT - Invalid function pointer "connect" */
\r
169 /* EPS_ERR_INV_FNCP_NETSHUTDOWN - Invalid function pointer "shutdown" */
\r
170 /* EPS_ERR_INV_FNCP_NETBIND - Invalid function pointer "bind" */
\r
171 /* EPS_ERR_INV_FNCP_NETLISTEN - Invalid function pointer "listen" */
\r
172 /* EPS_ERR_INV_FNCP_NETACCEPT - Invalid function pointer "accept" */
\r
173 /* EPS_ERR_INV_FNCP_NETSEND - Invalid function pointer "send" */
\r
174 /* EPS_ERR_INV_FNCP_NETSENDTO - Invalid function pointer "sendTo" */
\r
175 /* EPS_ERR_INV_FNCP_NETRECEIVE - Invalid function pointer "receive" */
\r
176 /* EPS_ERR_INV_FNCP_NETRECEIVEFROM - Invalid function pointer "receiveFrom" */
\r
177 /* EPS_ERR_INV_FNCP_NETGETSOCKNAME - Invalid function pointer "getsockname" */
\r
178 /* EPS_ERR_INV_FNCP_NETSETBROADCAST - Invalid function pointer "setBroadcast" */
\r
179 /* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
\r
182 /* Validate external functions. */
\r
184 /*******************************************|********************************************/
\r
185 EPS_ERR_CODE prtFunctionCheck (
\r
187 EPS_INT32 commMode,
\r
188 const EPS_USB_FUNC* usbFuncPtrs,
\r
189 const EPS_NET_FUNC* netFuncPtrs,
\r
190 const EPS_CMN_FUNC* cmnFuncPtrs
\r
193 EPS_UINT8* testptr; /* Test pointer to do memory test */
\r
194 EPS_UINT32 validProtocol;
\r
198 /*** Validate communication mode */
\r
199 if( (commMode & EPS_COMM_UNID) && (commMode & EPS_COMM_BID) ){
\r
200 EPS_RETURN( EPS_ERR_INV_ARG_COMMMODE )
\r
202 if( !(commMode & EPS_PROTOCOL_ALL) ){
\r
203 EPS_RETURN( EPS_ERR_INV_ARG_COMMMODE )
\r
206 validProtocol = EPS_PROTOCOL_INVALID;
\r
207 #ifdef GCOMSW_PRT_USE_USB
\r
208 validProtocol |= EPS_PROTOCOL_USB;
\r
210 #ifdef GCOMSW_PRT_USE_LPR
\r
211 validProtocol |= EPS_PROTOCOL_LPR;
\r
213 #ifdef GCOMSW_PRT_USE_RAW
\r
214 validProtocol |= EPS_PROTOCOL_RAW;
\r
216 if( EPS_PRT_PROTOCOL(commMode) & ~validProtocol ){
\r
217 EPS_RETURN( EPS_ERR_INV_ARG_COMMMODE )
\r
220 /*** Validate External Functions */
\r
221 if(cmnFuncPtrs == NULL){
\r
222 EPS_RETURN( EPS_ERR_INV_FNCP_NULL )
\r
225 if (cmnFuncPtrs->memAlloc == NULL){
\r
226 EPS_RETURN( EPS_ERR_INV_FNCP_MEMALLOC )
\r
229 if (cmnFuncPtrs->memFree == NULL){
\r
230 EPS_RETURN( EPS_ERR_INV_FNCP_MEMFREE )
\r
232 #ifdef GCOMSW_EPSON_SLEEP
\r
233 if (cmnFuncPtrs->sleep != NULL){
\r
235 if (cmnFuncPtrs->sleep == NULL){
\r
237 EPS_RETURN( EPS_ERR_INV_FNCP_SLEEP )
\r
240 if (cmnFuncPtrs->findCallback == NULL){
\r
241 EPS_RETURN( EPS_ERR_INV_FNCP_FINDCALLBACK )
\r
244 if (cmnFuncPtrs->getTime == NULL
\r
245 && ((cmnFuncPtrs->lockSync == NULL) || (cmnFuncPtrs->unlockSync == NULL)) ){
\r
246 EPS_RETURN( EPS_ERR_INV_FNCP_GETTIME )
\r
249 /*** Check Memory Functions */
\r
251 testptr = (EPS_UINT8 *)cmnFuncPtrs->memAlloc(10);
\r
252 if (testptr == NULL) {
\r
253 EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION )
\r
255 cmnFuncPtrs->memFree(testptr);
\r
258 /*** Validate USB Functions */
\r
259 #ifdef GCOMSW_PRT_USE_USB
\r
260 if (commMode & EPS_PROTOCOL_USB) {
\r
261 if (usbFuncPtrs == NULL){
\r
262 EPS_RETURN( EPS_ERR_INV_FNCP_NULL )
\r
265 if (usbFuncPtrs->openPortal == NULL){
\r
266 EPS_RETURN( EPS_ERR_INV_FNCP_OPENPORTAL )
\r
268 if (usbFuncPtrs->closePortal == NULL){
\r
269 EPS_RETURN( EPS_ERR_INV_FNCP_CLOSEPORTAL )
\r
271 if (usbFuncPtrs->writePortal == NULL){
\r
272 EPS_RETURN( EPS_ERR_INV_FNCP_WRITEPORTAL )
\r
275 if ( commMode & EPS_COMM_BID ) {
\r
276 if (usbFuncPtrs->readPortal == NULL){
\r
277 EPS_RETURN( EPS_ERR_INV_FNCP_READPORTAL )
\r
279 if (usbFuncPtrs->findFirst == NULL){
\r
280 EPS_RETURN( EPS_ERR_INV_FNCP_FINDFIRST )
\r
282 if (usbFuncPtrs->findNext == NULL){
\r
283 EPS_RETURN( EPS_ERR_INV_FNCP_FINDNEXT )
\r
285 if (usbFuncPtrs->findClose == NULL){
\r
286 EPS_RETURN( EPS_ERR_INV_FNCP_FINDCLOSE )
\r
288 #if 0 /* not necessary */
\r
289 if (cmnFuncPtrs->stateCallback == NULL)
\r
290 return (EPS_ERR_CODE)EPS_ERR_INV_FNCP_NOTIFYCALLBACK;
\r
299 /*** Validate Net Functions */
\r
300 #ifdef GCOMSW_PRT_USE_NETWORK
\r
301 if( (commMode & EPS_PROTOCOL_NET) ){
\r
302 if (netFuncPtrs == NULL){
\r
303 EPS_RETURN( EPS_ERR_INV_FNCP_NULL )
\r
306 if (netFuncPtrs->socket == NULL){
\r
307 EPS_RETURN( EPS_ERR_INV_FNCP_NETSOCKET )
\r
309 if (netFuncPtrs->close == NULL){
\r
310 EPS_RETURN( EPS_ERR_INV_FNCP_NETCLOSE )
\r
312 if (netFuncPtrs->connect == NULL){
\r
313 EPS_RETURN( EPS_ERR_INV_FNCP_NETCONNECT )
\r
315 if (netFuncPtrs->shutdown == NULL){
\r
316 EPS_RETURN( EPS_ERR_INV_FNCP_NETSHUTDOWN )
\r
318 if (netFuncPtrs->send == NULL){
\r
319 EPS_RETURN( EPS_ERR_INV_FNCP_NETSEND )
\r
321 if (netFuncPtrs->sendTo == NULL){
\r
322 EPS_RETURN( EPS_ERR_INV_FNCP_NETSENDTO )
\r
324 if (netFuncPtrs->receive == NULL){
\r
325 EPS_RETURN( EPS_ERR_INV_FNCP_NETRECEIVE )
\r
327 if (netFuncPtrs->receiveFrom == NULL){
\r
328 EPS_RETURN( EPS_ERR_INV_FNCP_NETRECEIVEFROM )
\r
331 #ifdef GCOMSW_PRT_USE_LPR
\r
332 if(commMode & EPS_PROTOCOL_LPR){
\r
333 if (netFuncPtrs->setBroadcast == NULL){
\r
334 EPS_RETURN( EPS_ERR_INV_FNCP_NETSETBROADCAST )
\r
342 #endif /* GCOMSW_PRT_USE_NETWORK */
\r
344 #ifdef GCOMSW_EPSON_SLEEP
\r
345 /*** Initial parameters for internal (simple) timing routine */
\r
346 /*** Used when system sleep routines are not available */
\r
347 if (epsCmnFnc.sleep == serSleep) {
\r
348 tdx = sleepTime = 0;
\r
350 while (!sleepTime) {
\r
352 sleepTime = 1000*(sleepE.time - sleepS.time) +
\r
353 (sleepE.millitm - sleepS.millitm);
\r
357 for (idx = 1; idx < tdx; idx++) {ftime(&sleepE); }
\r
358 sleepTime = 1000*(sleepE.time - sleepS.time) +
\r
359 (sleepE.millitm - sleepS.millitm);
\r
360 printJob.sleepSteps = tdx/sleepTime; /* Num steps for one msec */
\r
361 if (!printJob.sleepSteps)
\r
362 printJob.sleepSteps = -sleepTime/tdx; /* Num msec for each step */
\r
364 #endif /* GCOMSW_EPSON_SLEEP */
\r
366 EPS_RETURN( EPS_ERR_NONE )
\r
370 /*******************************************|********************************************/
\r
372 /* Function name: prtFindPrinter() */
\r
376 /* Name: Type: Description: */
\r
377 /* protocol EPS_INT32 I: traget protocol */
\r
378 /* timeout EPS_UINT32 I: find timeout */
\r
380 /* Return value: */
\r
381 /* EPS_ERR_NONE - Success (Opened Communication) */
\r
382 /* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
\r
383 /* EPS_ERR_PRINTER_NOT_FOUND - Printer not found (or error occur) */
\r
384 /* EPS_ERR_COMM_ERROR - Communication Error */
\r
386 /* EPS_FIND_CANCELED - user discontinued it */
\r
389 /* Find USB and network printers. */
\r
391 /*******************************************|********************************************/
\r
392 EPS_ERR_CODE prtFindPrinter (
\r
394 EPS_INT32 protocol,
\r
398 EPS_ERR_CODE ret = EPS_ERR_PRINTER_NOT_FOUND; /* Return status of internal calls */
\r
399 EPS_INT32 initProtocol = EPS_PRT_PROTOCOL(printJob.commMode);
\r
400 EPS_INT32 tgtProtocol = EPS_PRT_PROTOCOL(protocol);
\r
404 if( (tgtProtocol | initProtocol) != initProtocol){
\r
405 EPS_RETURN( EPS_ERR_INV_ARG_COMMMODE )
\r
407 g_FindProtocol = tgtProtocol;
\r
409 /* Reset break flag */
\r
410 if( epsCmnFnc.lockSync && epsCmnFnc.unlockSync ){
\r
411 epsCmnFnc.lockSync();
\r
412 g_FindBreak = FALSE;
\r
413 epsCmnFnc.unlockSync();
\r
416 /***------------------------------------------------------------------------------------*/
\r
418 /***------------------------------------------------------------------------------------*/
\r
419 #ifdef GCOMSW_PRT_USE_USB
\r
420 if( protocol & EPS_PROTOCOL_USB ){
\r
422 ret = usbFind( &timeout, printJob.commMode );
\r
424 if( !(EPS_ERR_NONE == ret || EPS_ERR_PRINTER_NOT_FOUND == ret
\r
425 || EPS_ERR_NOT_OPEN_IO == ret) ){
\r
431 /***------------------------------------------------------------------------------------*/
\r
433 /***------------------------------------------------------------------------------------*/
\r
434 #ifdef GCOMSW_PRT_USE_NETWORK
\r
435 if( protocol & EPS_PROTOCOL_NET ){
\r
437 ret = FindNetPrinter( protocol, timeout, TRUE, NULL );
\r
440 #endif /* GCOMSW_PRT_USE_NETWORK */
\r
442 if( epsPrinterList.num <= 0 ){
\r
443 if(EPS_ERR_NONE == ret ||
\r
444 EPS_ERR_PRINTER_NOT_USEFUL== ret ){
\r
445 ret = EPS_ERR_PRINTER_NOT_FOUND;
\r
448 if(EPS_ERR_PRINTER_NOT_FOUND == ret ||
\r
449 EPS_ERR_PRINTER_NOT_USEFUL== ret ){
\r
450 ret = EPS_ERR_NONE;
\r
458 /*******************************************|********************************************/
\r
460 /* Function name: prtCancelFindPrinter() */
\r
464 /* Name: Type: Description: */
\r
467 /* Return value: */
\r
468 /* EPS_ERR_NONE - Success */
\r
469 /* EPS_ERR_INVALID_CALL - invalid called */
\r
472 /* Cancel epsFindPrinter(), epsProbePrinter(). */
\r
474 /*******************************************|********************************************/
\r
475 EPS_ERR_CODE prtCancelFindPrinter(
\r
482 if( epsCmnFnc.lockSync && epsCmnFnc.unlockSync ){
\r
483 if( 0 == epsCmnFnc.lockSync() ){
\r
484 g_FindBreak = TRUE;
\r
485 epsCmnFnc.unlockSync();
\r
487 EPS_RETURN( EPS_ERR_NONE )
\r
489 EPS_RETURN( EPS_ERR_INVALID_CALL )
\r
494 /*******************************************|********************************************/
\r
496 /* Function name: prtProbePrinterByID() */
\r
500 /* Name: Type: Description: */
\r
501 /* probeParam EPS_PROBE* Pointer to a Prober parameter structure */
\r
503 /* Return value: */
\r
504 /* EPS_ERR_NONE - Success (Opened Communication) */
\r
505 /* EPS_ERR_PRINTER_NOT_FOUND - printer not found */
\r
506 /* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
\r
507 /* EPS_ERR_PROTOCOL_NOT_SUPPORTED - Unsupported function Error */
\r
510 /* Probe printer by ID string. */
\r
512 /*******************************************|********************************************/
\r
513 EPS_ERR_CODE prtProbePrinterByID (
\r
515 const EPS_PROBE* probeParam
\r
518 /*** Declare Variable Local to Routine */
\r
519 EPS_ERR_CODE ret = EPS_ERR_NONE; /* Return status of internal calls */
\r
520 EPS_PRINTER_INN* innerPrinter = NULL;
\r
521 EPS_UINT16 protocol = EPS_PROTOCOL_INVALID;
\r
522 EPS_INT8 sParse[EPS_PRNID_BUFFSIZE];
\r
523 EPS_INT8* pPos = NULL;
\r
524 EPS_INT32 nSegCnt = 0;
\r
525 EPS_UINT32 nTmp = 0;
\r
526 EPS_INT8 defStr[EPS_PRNID_BUFFSIZE];
\r
530 /*** Initialize Local Variables */
\r
531 ret = EPS_ERR_NONE;
\r
533 /*** Parse ID String */
\r
534 strcpy(sParse, probeParam->dsc.identify);
\r
536 pPos = strtok(sParse, EPS_PID_SEP);
\r
537 for(nSegCnt = 0; pPos != NULL && nSegCnt < EPS_PID_SEGNUM; nSegCnt++){
\r
540 if( 0 != strcmp(pPos, EPS_PID_PRT) ){
\r
541 EPS_RETURN( EPS_ERR_INV_ARG_PRINTER_ID )
\r
545 case 1: /* Get protocol number */
\r
546 sscanf(pPos, "%x", &nTmp);
\r
548 EPS_RETURN( EPS_ERR_INV_ARG_PRINTER_ID )
\r
550 protocol = (EPS_UINT16)nTmp;
\r
554 if( 0 != strcmp(pPos, EPS_PID_DEF) ){
\r
555 EPS_RETURN( EPS_ERR_INV_ARG_PRINTER_ID )
\r
559 case 3: /* Get description string */
\r
560 strcpy(defStr, pPos);
\r
564 pPos = strtok(NULL, EPS_PID_SEP);
\r
566 if(nSegCnt < EPS_PID_SEGNUM){
\r
567 EPS_RETURN( EPS_ERR_INV_ARG_PRINTER_ID )
\r
570 /* Reset break flag */
\r
571 if( epsCmnFnc.lockSync && epsCmnFnc.unlockSync ){
\r
572 epsCmnFnc.lockSync();
\r
573 g_FindBreak = FALSE;
\r
574 epsCmnFnc.unlockSync();
\r
577 /*** protocol depend probe */
\r
578 switch( EPS_PRT_PROTOCOL( protocol ) ){
\r
579 #ifdef GCOMSW_PRT_USE_USB
\r
580 case EPS_PROTOCOL_USB:
\r
581 if( printJob.commMode & EPS_PROTOCOL_USB ){
\r
582 ret = usbProbePrinterByID(defStr, probeParam->timeout, &innerPrinter);
\r
584 ret = EPS_ERR_PROTOCOL_NOT_SUPPORTED;
\r
589 #ifdef GCOMSW_PRT_USE_LPR
\r
590 case EPS_PROTOCOL_LPR:
\r
591 if( printJob.commMode & EPS_PROTOCOL_LPR ){
\r
592 ret = lprProbePrinterByID(defStr, probeParam->timeout, &innerPrinter);
\r
594 ret = EPS_ERR_PROTOCOL_NOT_SUPPORTED;
\r
599 #ifdef GCOMSW_PRT_USE_RAW
\r
600 case EPS_PROTOCOL_RAW:
\r
601 if( printJob.commMode & EPS_PROTOCOL_RAW ){
\r
602 ret = rawProbePrinterByID(defStr, probeParam->timeout, &innerPrinter);
\r
604 ret = EPS_ERR_PROTOCOL_NOT_SUPPORTED;
\r
610 ret = EPS_ERR_INV_ARG_PRINTER_ID;
\r
613 if(EPS_ERR_NONE == ret){
\r
614 innerPrinter->protocol = protocol | EPS_PRT_DIRECTION(printJob.commMode);
\r
615 ret = prtRegPrinter( innerPrinter, TRUE );
\r
616 if(EPS_FIND_CANCELED == ret){
\r
617 ret = EPS_ERR_NONE;
\r
625 /*******************************************|********************************************/
\r
627 /* Function name: prtProbePrinterByAddr() */
\r
631 /* Name: Type: Description: */
\r
632 /* probeParam EPS_PROBE* Pointer to a Prober parameter structure */
\r
634 /* Return value: */
\r
635 /* EPS_ERR_NONE - Success (Opened Communication) */
\r
636 /* EPS_ERR_PRINTER_NOT_FOUND - printer not found */
\r
637 /* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
\r
638 /* EPS_ERR_PROTOCOL_NOT_SUPPORTED - Unsupported function Error */
\r
639 /* EPS_ERR_PRINTER_NOT_USEFUL - received but not usefl */
\r
642 /* Probe network printer by IP Address. */
\r
644 /*******************************************|********************************************/
\r
645 EPS_ERR_CODE prtProbePrinterByAddr (
\r
647 const EPS_PROBE* probeParam
\r
650 /*** Declare Variable Local to Routine */
\r
651 EPS_ERR_CODE ret = EPS_ERR_PRINTER_NOT_FOUND; /* Return status of internal calls */
\r
652 EPS_INT32 initProtocol = EPS_PRT_PROTOCOL(printJob.commMode);
\r
653 EPS_INT32 tgtProtocol = EPS_PROTOCOL_INVALID;
\r
657 /*** Validate input parameters */
\r
658 if (NULL == probeParam) {
\r
659 EPS_RETURN( EPS_ERR_INV_ARG_PROBEINFO )
\r
661 tgtProtocol = EPS_PRT_PROTOCOL(probeParam->dsc.addr.protocol);
\r
662 if( (tgtProtocol | initProtocol) != initProtocol){
\r
663 EPS_RETURN( EPS_ERR_INV_ARG_COMMMODE )
\r
665 g_FindProtocol = tgtProtocol;
\r
667 /* Reset break flag */
\r
668 if( epsCmnFnc.lockSync && epsCmnFnc.unlockSync ){
\r
669 epsCmnFnc.lockSync();
\r
670 g_FindBreak = FALSE;
\r
671 epsCmnFnc.unlockSync();
\r
674 if( IsValidAddress(probeParam->dsc.addr.address) ){
\r
675 #if defined(GCOMSW_PRT_USE_NETWORK)
\r
676 /***--------------------------------------------------------------------------------*/
\r
677 /*** If IPAddress, Probe network printer */
\r
678 /***--------------------------------------------------------------------------------*/
\r
679 if( tgtProtocol & EPS_PROTOCOL_NET ){
\r
680 ret = FindNetPrinter(tgtProtocol, probeParam->timeout, FALSE, probeParam->dsc.addr.address);
\r
681 if(EPS_FIND_CANCELED == ret){
\r
682 ret = EPS_ERR_NONE;
\r
685 ret = EPS_ERR_PROTOCOL_NOT_SUPPORTED;
\r
688 ret = EPS_ERR_PROTOCOL_NOT_SUPPORTED;
\r
689 #endif /* GCOMSW_PRT_USE_NETWORK */
\r
691 ret = EPS_ERR_INV_ARG_PRINTER_ADDR;
\r
694 if( epsPrinterList.num <= 0 ){
\r
695 if(EPS_ERR_NONE == ret){
\r
696 ret = EPS_ERR_PRINTER_NOT_FOUND;
\r
699 if(EPS_ERR_PRINTER_NOT_FOUND == ret ||
\r
700 EPS_ERR_PRINTER_NOT_USEFUL== ret ){
\r
701 ret = EPS_ERR_NONE;
\r
709 /*******************************************|********************************************/
\r
711 /* Function name: prtSetupJobFunctions() */
\r
715 /* Name: Type: Description: */
\r
716 /* printer const EPS_PRINTER* I: Pointer to a target printer info. */
\r
718 /* Return value: */
\r
720 /* EPS_ERR_NONE - Success */
\r
721 /* EPS_ERR_OPR_FAIL - Internal Error */
\r
724 /* construct job function table. */
\r
726 /*******************************************|********************************************/
\r
727 EPS_ERR_CODE prtSetupJobFunctions (
\r
729 const EPS_PRINTER_INN* printer,
\r
730 EPS_JOB_FUNCS* pFuncs
\r
733 /*** Declare Variable Local to Routine */
\r
734 EPS_ERR_CODE ret = EPS_ERR_NONE; /* Return status of internal calls */
\r
738 switch( EPS_PRT_PROTOCOL( printer->protocol ) ){
\r
739 #ifdef GCOMSW_PRT_USE_USB
\r
740 case EPS_PROTOCOL_USB:
\r
741 pFuncs->StartJob = &usbStartJob;
\r
742 pFuncs->EndJob = &usbEndJob;
\r
743 pFuncs->RestartJob = &usbRestartJob;
\r
744 pFuncs->WriteData = &usbWritePrintData;
\r
745 pFuncs->ResetPrinter = &usbResetPrinter;
\r
746 pFuncs->MonitorStatus = &usbGetJobStatus;
\r
747 pFuncs->GetStatus = &usbGetStatus;
\r
751 #ifdef GCOMSW_PRT_USE_LPR
\r
752 case EPS_PROTOCOL_LPR:
\r
753 pFuncs->StartJob = &lprStartJob;
\r
754 pFuncs->EndJob = &lprEndJob;
\r
755 pFuncs->RestartJob = &lprRestartJob;
\r
756 pFuncs->WriteData = &lprWritePrintData;
\r
757 pFuncs->ResetPrinter = &lprResetPrinter;
\r
758 pFuncs->StartPage = &lprStartPage;
\r
759 pFuncs->EndPage = &lprEndPage;
\r
760 pFuncs->MonitorStatus = &lprGetJobStatus;
\r
761 pFuncs->GetStatus = &lprGetStatus;
\r
762 lprSetupSTFunctions(printer);
\r
766 #ifdef GCOMSW_PRT_USE_RAW
\r
767 case EPS_PROTOCOL_RAW:
\r
768 pFuncs->StartJob = &rawStartJob;
\r
769 pFuncs->EndJob = &rawEndJob;
\r
770 pFuncs->RestartJob = &rawRestartJob;
\r
771 pFuncs->WriteData = &rawWritePrintData;
\r
772 pFuncs->ResetPrinter = &rawResetPrinter;
\r
773 pFuncs->StartPage = &rawStartPage;
\r
774 pFuncs->EndPage = &rawEndPage;
\r
775 pFuncs->MonitorStatus = &rawGetJobStatus;
\r
776 pFuncs->GetStatus = &rawGetStatus;
\r
777 rawSetupSTFunctions(printer);
\r
782 ret = EPS_ERR_OPR_FAIL;
\r
789 /*******************************************|********************************************/
\r
791 /* Function name: prtGetInkStatus() */
\r
795 /* Name: Type: Description: */
\r
796 /* status EPS_STATUS* Pointer to the printer status. */
\r
798 /* Return value: */
\r
799 /* EPS_ERR_NONE - Success */
\r
800 /* EPS_ERR_NEED_BIDIRECT - Need Bi-Directional Communication */
\r
801 /* EPS_ERR_COMM_ERROR - Failed to send command */
\r
802 /* EPS_ERR_NOT_OPEN_IO - Cannot Open I/O Portal */
\r
803 /* EPS_ERR_NOT_CLOSE_IO - Cannot Close I/O Portal */
\r
804 /* EPS_ERR_PROTOCOL_NOT_SUPPORTED - Unsupported function Error */
\r
807 /* Gets the Ink Infomation. */
\r
809 /*******************************************|********************************************/
\r
810 EPS_ERR_CODE prtGetInkInfo (
\r
812 const EPS_PRINTER_INN* printer,
\r
816 /*** Declare Variable Local to Routine */
\r
817 EPS_ERR_CODE ret = EPS_ERR_NONE; /* Return status of internal calls */
\r
818 EPS_STATUS_INFO lclStatus;
\r
823 /*** Validate communication mode */
\r
824 if ( !EPS_IS_BI_PROTOCOL(printer->protocol) ){
\r
825 EPS_RETURN( EPS_ERR_NEED_BIDIRECT )
\r
828 memset(&lclStatus, 0, sizeof(lclStatus));
\r
829 /*** protocol GetStatus */
\r
830 switch( EPS_PRT_PROTOCOL( printer->protocol ) ){
\r
831 #ifdef GCOMSW_PRT_USE_USB
\r
832 case EPS_PROTOCOL_USB:
\r
833 ret = usbGetStatus(&lclStatus, NULL, NULL);
\r
837 #ifdef GCOMSW_PRT_USE_LPR
\r
838 case EPS_PROTOCOL_LPR:
\r
839 ret = lprGetInkInfo(&lclStatus);
\r
843 #ifdef GCOMSW_PRT_USE_RAW
\r
844 case EPS_PROTOCOL_RAW:
\r
845 ret = rawGetInkInfo(&lclStatus);
\r
850 ret = EPS_ERR_OPR_FAIL;
\r
853 if(EPS_ERR_NONE == ret
\r
854 && EPS_SUBPROTOCOL_PCDEV != EPS_PRT_SUBPROTOCOL(printer->protocol) ){
\r
855 info->number = lclStatus.nInkNo;
\r
856 for(idx=0; idx < EPS_INK_NUM; idx++) {
\r
857 info->colors[idx] = lclStatus.nColorType[idx];
\r
858 info->remaining[idx] = lclStatus.nColor[idx];
\r
866 /*******************************************|********************************************/
\r
868 /* Function name: prtGetPMString() */
\r
872 /* Name: Type: Description: */
\r
873 /* printer EPS_PRINTER_INN* I: Pointer to a PrinterInfo */
\r
874 /* type EPS_INT32 I: PM kind 1 or 2 */
\r
875 /* pString EPS_UINT8* O: Pointer to PM String */
\r
876 /* bufSize EPS_INT32 I: pString buffer size */
\r
878 /* Return value: */
\r
879 /* EPS_ERR_NONE - Success */
\r
880 /* EPS_ERR_OPR_FAIL - Internal Error */
\r
881 /* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
\r
882 /* EPS_ERR_COMM_ERROR - Communication Error */
\r
883 /* EPS_ERR_PROTOCOL_NOT_SUPPORTED - Unsupported function Error */
\r
887 /*******************************************|********************************************/
\r
888 EPS_ERR_CODE prtGetPMString (
\r
890 const EPS_PRINTER_INN* printer,
\r
892 EPS_UINT8* pString,
\r
896 /*** Declare Variable Local to Routine */
\r
897 EPS_ERR_CODE ret = EPS_ERR_NONE; /* Return status of internal calls */
\r
901 switch( EPS_PRT_PROTOCOL( printer->protocol ) ){
\r
902 #ifdef GCOMSW_PRT_USE_USB
\r
903 case EPS_PROTOCOL_USB:
\r
904 ret = usbGetPMString(printer, type, pString, bufSize);
\r
908 #ifdef GCOMSW_PRT_USE_LPR
\r
909 case EPS_PROTOCOL_LPR:
\r
910 ret = lprGetPMString(printer, type, pString, bufSize);
\r
914 #ifdef GCOMSW_PRT_USE_RAW
\r
915 case EPS_PROTOCOL_RAW:
\r
916 ret = rawGetPMString(printer, type, pString, bufSize);
\r
921 ret = EPS_ERR_OPR_FAIL;
\r
928 /*******************************************|********************************************/
\r
930 /* Function name: prtRegPrinter() */
\r
934 /* Name: Type: Description: */
\r
935 /* printer EPS_PRINTER* I:Data structure containing printer information. */
\r
936 /* bNotify EPS_BOOL I:This item need notify. */
\r
938 /* Return value: */
\r
939 /* EPS_ERR_NONE - Printer settled into one of the requested state(s)*/
\r
940 /* EPS_ERR_OPR_FAIL - Internal Error */
\r
941 /* EPS_ERR_MEMORY_ALLOCATION - Failed to allocate memory */
\r
942 /* EPS_FIND_CANCELED - cancel find by user */
\r
945 /* Registers a new printer with the global linked list managed by this module. */
\r
946 /* And Notify to user. */
\r
948 /*******************************************|********************************************/
\r
949 EPS_ERR_CODE prtRegPrinter(
\r
951 EPS_PRINTER_INN* printer,
\r
955 /*** Declare Variables Local to Routine */
\r
956 EPS_PRINTER usrPrinter; /* for user notify */
\r
957 EPS_PL_NODE* current = NULL;
\r
958 EPS_BOOL registered = FALSE;
\r
962 EPS_DBGPRINT( ("%X / %s\n", printer->protocol, printer->location) )
\r
964 if (printer->protocol == EPS_PROTOCOL_INVALID){
\r
965 EPS_RETURN( EPS_ERR_OPR_FAIL )
\r
968 if( NULL == epsPrinterList.root){
\r
969 /*** This is the first printer in the list. */
\r
970 epsPrinterList.root = (EPS_PL_NODE*)EPS_ALLOC(sizeof(EPS_PL_NODE));
\r
971 if(epsPrinterList.root == NULL) {
\r
972 EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION )
\r
974 epsPrinterList.num = 1;
\r
976 current = epsPrinterList.root;
\r
977 current->printer = printer;
\r
978 current->next = NULL;
\r
982 current = epsPrinterList.root;
\r
984 /* If we've found a printer in the list that matches the module's printer, */
\r
985 if( 0 == strcmp(printer->location, current->printer->location)){
\r
986 if(0 == strcmp(printer->modelName, current->printer->modelName)){
\r
993 /* And the new protocol has priority over the old one... */
\r
994 if (EPS_PRT_PROTOCOL(current->printer->protocol) > EPS_PRT_PROTOCOL(printer->protocol) ) {
\r
995 /* Prioritize the protocols. The lower-numbered protocol always */
\r
996 /* has precendence over the higher-numbered one (1 outranks 3). */
\r
997 current->printer->protocol = printer->protocol;
\r
999 /* Replase protocol */
\r
1000 EPS_DBGPRINT( ("Discover %d %s %s (Upgrade)\n", printer->protocol, printer->modelName, printer->printerID) )
\r
1001 EPS_SAFE_RELEASE( current->printer->protocolInfo );
\r
1002 EPS_SAFE_RELEASE( current->printer );
\r
1003 current->printer = printer;
\r
1006 /* In this case, the current protocol already has priority. Simply return. */
\r
1007 EPS_SAFE_RELEASE( printer->protocolInfo );
\r
1008 EPS_SAFE_RELEASE( printer );
\r
1009 EPS_RETURN( EPS_ERR_NONE )
\r
1013 if( NULL == current->next){
\r
1016 current = current->next;
\r
1019 /* If we've reached this part of the code, it means we haven't found the printer. */
\r
1020 /* Time to add a new node to the list. */
\r
1021 /* The variable "current" is right now pointing to the last member of the list. */
\r
1022 if( !registered ){
\r
1023 /* Allocate a new printer on the end of the linked list. */
\r
1024 current->next = (EPS_PL_NODE*)EPS_ALLOC(sizeof(EPS_PL_NODE));
\r
1025 if(current->next == NULL) {
\r
1026 EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION )
\r
1029 /* Fill in the list node. */
\r
1030 current->next->printer = printer;
\r
1031 current->next->next = NULL;
\r
1032 epsPrinterList.num++;
\r
1034 current = current->next;
\r
1038 EPS_DBGPRINT( ("Discover x%X (x%X) %s %s\n", printer->protocol, printer->supportFunc, printer->modelName, printer->printerID) )
\r
1040 if( TRUE == bNotify ){
\r
1041 MakePrinterStructure(&usrPrinter, printer);
\r
1043 if( EPS_USER_CANCEL == epsCmnFnc.findCallback(usrPrinter) ){
\r
1044 EPS_RETURN( EPS_FIND_CANCELED )
\r
1048 EPS_RETURN( EPS_ERR_NONE )
\r
1052 /*******************************************|********************************************/
\r
1054 /* Function name: prtIsRegistered() */
\r
1058 /* Name: Type: Description: */
\r
1059 /* Address EPS_INT8* IP Address. */
\r
1060 /* modelName EPS_INT8* Printer model name. */
\r
1061 /* Protocol EPS_INT32 Protocol ID. */
\r
1063 /* Return value: */
\r
1064 /* TRUE (registered), FALSE(not registered). */
\r
1066 /* Description: */
\r
1067 /* Whether the printer has registered is confirmed. */
\r
1069 /*******************************************|********************************************/
\r
1070 EPS_BOOL prtIsRegistered(
\r
1072 const EPS_INT8 *Address,
\r
1073 const EPS_INT8 *modelName,
\r
1074 EPS_INT32 Protocol
\r
1077 EPS_PL_NODE* current = epsPrinterList.root;
\r
1078 EPS_BOOL bMatch = FALSE;
\r
1082 while(NULL != current) {
\r
1083 /* If we've found a printer in the list that matches the module's printer, */
\r
1085 if( 0 == strcmp(current->printer->location, Address) ){
\r
1086 if(NULL != modelName){
\r
1087 if( 0 == strcmp(current->printer->modelName, modelName) ){
\r
1095 if(TRUE == bMatch){
\r
1096 /* And the new protocol has priority over the old one... */
\r
1097 if (EPS_PRT_PROTOCOL(current->printer->protocol) <= EPS_PRT_PROTOCOL(Protocol)) {
\r
1098 EPS_RETURN( TRUE )
\r
1100 /* already registered However it's low level protocol */
\r
1101 EPS_RETURN( FALSE )
\r
1105 current = current->next;
\r
1108 EPS_RETURN( FALSE )
\r
1112 /*******************************************|********************************************/
\r
1114 /* Function name: prtAddUsrPrinter() */
\r
1118 /* Name: Type: Description: */
\r
1119 /* usrPrinter EPS_PRINTER* I: User specified printer. */
\r
1120 /* printer EPS_PRINTER* O: Internal printer information. */
\r
1122 /* Return value: */
\r
1123 /* EPS_ERR_NONE - Success */
\r
1124 /* EPS_ERR_INV_ARG_COMMMODE - Invalid argument "usrPrinter.protocol" */
\r
1125 /* EPS_ERR_INV_ARG_PRINTER_ADDR - Invalid format " printer.location" */
\r
1126 /* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
\r
1127 /* EPS_ERR_INV_PRINT_LANGUAGE - Invalid argument "usrPrinter.language" */
\r
1129 /* Description: */
\r
1130 /* Register a user specified printer. */
\r
1132 /*******************************************|********************************************/
\r
1133 EPS_ERR_CODE prtAddUsrPrinter(
\r
1135 const EPS_PRINTER* usrPrinter,
\r
1136 EPS_PRINTER_INN** printer
\r
1139 EPS_ERR_CODE ret = EPS_ERR_NONE;
\r
1140 EPS_INT32 initProtocol = EPS_PRT_PROTOCOL(printJob.commMode);
\r
1141 EPS_INT32 tgtProtocol = EPS_PRT_PROTOCOL(usrPrinter->protocol);
\r
1142 EPS_INT8 address[EPS_ADDR_BUFFSIZE];
\r
1143 EPS_INT8* p = NULL;
\r
1144 EPS_INT32 nPort = 0;
\r
1145 EPS_PRINTER_INN* innerPrinter = NULL;
\r
1151 /*** Validate input parameters */
\r
1152 if( (tgtProtocol | initProtocol) != initProtocol){ /* Not Init protocol */
\r
1153 EPS_RETURN( EPS_ERR_INV_ARG_COMMMODE )
\r
1155 if( tgtProtocol & EPS_PROTOCOL_USB ){ /* USB */
\r
1157 EPS_RETURN( EPS_ERR_INV_ARG_COMMMODE )
\r
1159 if( memGetBitCount(tgtProtocol) > 1 ){ /* Multi protocol */
\r
1160 EPS_RETURN( EPS_ERR_INV_ARG_COMMMODE )
\r
1162 if( '\0' == usrPrinter->location[0] ){
\r
1163 EPS_RETURN( EPS_ERR_INV_ARG_PRINTER_ADDR )
\r
1165 if( EPS_ADDR_BUFFSIZE < strlen(usrPrinter->location) ){
\r
1166 EPS_RETURN( EPS_ERR_INV_ARG_PRINTER_ADDR )
\r
1169 if( !(EPS_LANG_ESCPR == usrPrinter->language ||
\r
1170 #ifdef GCOMSW_CMD_ESCPAGE_S
\r
1171 EPS_LANG_ESCPAGE_S == usrPrinter->language ||
\r
1173 EPS_LANG_ESCPAGE == usrPrinter->language ||
\r
1174 EPS_LANG_ESCPAGE_COLOR == usrPrinter->language ) ){
\r
1175 EPS_RETURN( EPS_ERR_INV_PRINT_LANGUAGE );
\r
1178 /*** pase location */
\r
1179 strcpy(address, usrPrinter->location);
\r
1180 p = strchr(address, ':');
\r
1183 p++; /* 1 = ':' */
\r
1184 sscanf(p, "%d", &nPort);
\r
1186 /* Default Port */
\r
1187 if( tgtProtocol & EPS_PROTOCOL_LPR ){
\r
1188 #ifdef GCOMSW_PRT_USE_LPR
\r
1189 nPort = lprGetDefautiPort();
\r
1191 EPS_RETURN( EPS_ERR_INV_ARG_COMMMODE )
\r
1193 } else if( tgtProtocol & EPS_PROTOCOL_RAW ){
\r
1194 #ifdef GCOMSW_PRT_USE_RAW
\r
1195 nPort = rawGetDefautiPort();
\r
1197 EPS_RETURN( EPS_ERR_INV_ARG_COMMMODE )
\r
1200 EPS_RETURN( EPS_ERR_INV_ARG_COMMMODE )
\r
1203 if( FALSE == IsValidAddress( address ) ){
\r
1204 EPS_RETURN( EPS_ERR_INV_ARG_PRINTER_ADDR )
\r
1207 /*** Create new printer */
\r
1208 innerPrinter = (EPS_PRINTER_INN*)EPS_ALLOC(sizeof(EPS_PRINTER_INN));
\r
1209 if( NULL == innerPrinter ){
\r
1210 EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION )
\r
1213 memset(innerPrinter, 0x00, sizeof(EPS_PRINTER_INN));
\r
1215 strcpy(innerPrinter->location, address);
\r
1216 innerPrinter->printPort = (EPS_UINT16)nPort;
\r
1217 innerPrinter->protocol = usrPrinter->protocol;
\r
1218 innerPrinter->supportFunc = EPS_SPF_RGBPRINT | EPS_SPF_JPGPRINT;
\r
1219 innerPrinter->JpgMax = EPS_JPEG_SIZE_UNLIMIT;
\r
1220 innerPrinter->language = usrPrinter->language;
\r
1221 strcpy(innerPrinter->modelName, usrPrinter->modelName);
\r
1222 /* innerPrinter->manufacturerName */
\r
1223 /* innerPrinter->friendlyName */
\r
1224 /* innerPrinter->printerID; */
\r
1225 /* innerPrinter->protocolInfo; */
\r
1227 /*** Append to printer lsit */
\r
1228 ret = prtRegPrinter(innerPrinter, FALSE);
\r
1229 if( EPS_ERR_NONE == ret ){
\r
1230 *printer = innerPrinter;
\r
1237 /*******************************************|********************************************/
\r
1239 /* Function name: prtGetInnerPrinter() */
\r
1243 /* Name: Type: Description: */
\r
1244 /* printer EPS_PRINTER Pointer to public infomation structure */
\r
1246 /* Return value: */
\r
1247 /* EPS_PRINTER_INN Pointer to private infomation structure */
\r
1249 /* Description: */
\r
1250 /* Get private infomation of printer. */
\r
1252 /*******************************************|********************************************/
\r
1253 EPS_PRINTER_INN* prtGetInnerPrinter(
\r
1255 const EPS_PRINTER* printer
\r
1258 EPS_PL_NODE* pCur = epsPrinterList.root;
\r
1259 EPS_PRINTER_INN* innerPrinter = NULL;
\r
1261 /* collates it with found printer */
\r
1262 while(NULL != pCur){
\r
1263 if(0 == strcmp(printer->modelName, pCur->printer->modelName)
\r
1264 && 0 == strcmp(printer->location, pCur->printer->location) ){
\r
1265 innerPrinter = pCur->printer;
\r
1268 pCur = pCur->next;
\r
1271 return innerPrinter;
\r
1275 /*******************************************|********************************************/
\r
1277 /* Function name: prtClearPrinterList() */
\r
1281 /* Name: Type: Description: */
\r
1284 /* Return value: */
\r
1287 /* Description: */
\r
1288 /* Crean up inside list of printer structure . */
\r
1290 /*******************************************|********************************************/
\r
1291 void prtClearPrinterList(
\r
1296 EPS_PL_NODE* pCur = epsPrinterList.root;
\r
1297 EPS_PL_NODE* pNext = NULL;
\r
1301 /* Clear stock printer list */
\r
1302 while(NULL != pCur){
\r
1303 pNext = pCur->next;
\r
1305 prtClearSupportedMedia(pCur->printer);
\r
1307 EPS_SAFE_RELEASE( pCur->printer->protocolInfo );
\r
1308 EPS_SAFE_RELEASE( pCur->printer );
\r
1309 EPS_SAFE_RELEASE( pCur );
\r
1314 epsPrinterList.num = 0;
\r
1315 epsPrinterList.root = NULL;
\r
1321 /*******************************************|********************************************/
\r
1323 /* Function name: prtClearSupportedMedia() */
\r
1327 /* Name: Type: Description: */
\r
1328 /* printer EPS_PRINTER_INN* I: Pointer to a printer info structure */
\r
1330 /* Return value: */
\r
1333 /* Description: */
\r
1334 /* Crean up inside list of supported media structure. */
\r
1336 /*******************************************|********************************************/
\r
1337 void prtClearSupportedMedia(
\r
1339 EPS_PRINTER_INN* printer
\r
1346 /* Clear "supportedMedia" */
\r
1347 if( NULL == printer ){
\r
1351 #ifdef GCOMSW_CMD_ESCPAGE
\r
1352 if(EPS_LANG_ESCPR == printer->language ){
\r
1355 if( NULL != printer->supportedMedia.sizeList ){
\r
1356 for(idx = 0; idx < printer->supportedMedia.numSizes; idx++) {
\r
1357 EPS_SAFE_RELEASE(printer->supportedMedia.sizeList[idx].typeList);
\r
1359 EPS_SAFE_RELEASE(printer->supportedMedia.sizeList);
\r
1361 #ifdef GCOMSW_CMD_ESCPAGE
\r
1363 /*** ESC/Page ***/
\r
1364 pageClearSupportedMedia(printer);
\r
1368 printer->supportedMedia.numSizes = 0;
\r
1369 printer->supportedMedia.JpegSizeLimit = EPS_JPEG_SIZE_MAX; /* lowest guarantee */
\r
1370 printer->supportedMedia.resolution = EPS_IR_360X360;
\r
1376 /*******************************************|********************************************/
\r
1378 /* Function name: prtSetIdStr() */
\r
1382 /* Name: Type: Description: */
\r
1383 /* printer EPS_PRINTER_INN* I/O: Pointer to a printer info structure */
\r
1384 /* idString EPS_INT8* I: protocol depended unique string */
\r
1386 /* Return value: */
\r
1389 /* Description: */
\r
1390 /* Set the Printer ID. */
\r
1392 /*******************************************|********************************************/
\r
1395 EPS_PRINTER_INN* printer,
\r
1396 const EPS_INT8* idString
\r
1399 sprintf(printer->printerID, EPS_PRINTER_ID_STR,
\r
1400 EPS_PRT_PROTOCOL_EX(printer->protocol), idString);
\r
1405 /*******************************************|********************************************/
\r
1407 /* Function name: prtRecoverPE() */
\r
1411 /* Name: Type: Description: */
\r
1414 /* Return value: */
\r
1415 /* EPS_ERR_NONE - Recovered successfully */
\r
1416 /* EPS_ERR_COMM_ERROR - Recovery failed */
\r
1418 /* Description: */
\r
1419 /* Tries to recover from the paper end error */
\r
1421 /*******************************************|********************************************/
\r
1422 EPS_ERR_CODE prtRecoverPE (
\r
1431 switch( EPS_PRT_PROTOCOL( printJob.printer->protocol ) ){
\r
1432 #ifdef GCOMSW_PRT_USE_USB
\r
1433 case EPS_PROTOCOL_USB:
\r
1434 ret = usbMechCommand(EPS_CBTCOM_PE);
\r
1438 #ifdef GCOMSW_PRT_USE_LPR
\r
1439 case EPS_PROTOCOL_LPR:
\r
1440 ret = lprMechCommand(printJob.printer, EPS_CBTCOM_PE);
\r
1444 #ifdef GCOMSW_PRT_USE_RAW
\r
1445 case EPS_PROTOCOL_RAW:
\r
1446 ret = rawMechCommand(printJob.printer, EPS_CBTCOM_PE);
\r
1450 EPS_RETURN( EPS_ERR_NONE ) /* Other protocol Not Support recover command */
\r
1456 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
1457 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
1458 /*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
\r
1459 /*-------------------- Local Functions ---------------------*/
\r
1460 /*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
\r
1461 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
1462 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
1463 #ifdef GCOMSW_PRT_USE_NETWORK
\r
1464 /*******************************************|********************************************/
\r
1466 /* Function name: FindNetPrinter() */
\r
1470 /* Name: Type: Description: */
\r
1471 /* protocol EPS_INT32 I: traget protocol */
\r
1472 /* timeout EPS_UINT32 I: find timeout */
\r
1473 /* plural EPS_BOOL I: TRUE= find plural printer / FALSE= one printer */
\r
1474 /* address EPS_INT8* I: send discover message address. */
\r
1475 /* (If plural=TRUE, this is NULL) */
\r
1477 /* Return value: */
\r
1478 /* EPS_ERR_NONE - Success (Opened Communication) */
\r
1479 /* EPS_ERR_MEMORY_ALLOCATION - Fail to memory allocation */
\r
1480 /* EPS_ERR_PRINTER_NOT_FOUND - Printer not found (or error occur) */
\r
1481 /* EPS_ERR_COMM_ERROR - socket error */
\r
1483 /* EPS_FIND_CANCELED - user discontinued it */
\r
1485 /* Description: */
\r
1486 /* Find network printers. */
\r
1488 /*******************************************|********************************************/
\r
1489 static EPS_ERR_CODE FindNetPrinter (
\r
1491 EPS_INT32 protocol,
\r
1492 EPS_UINT32 timeout,
\r
1494 const EPS_INT8* address
\r
1497 EPS_ERR_CODE ret = EPS_ERR_PRINTER_NOT_FOUND; /* Return status of internal calls */
\r
1498 EPS_PRINTER_INN* innerPrinter = NULL;
\r
1500 EPS_FIND_FUNCS* pProtocolFncs = NULL;
\r
1501 EPS_FIND_FUNCS* pFncs = NULL;
\r
1502 EPS_UINT32 tmStart, tmNow, tmSpan, tmReq;
\r
1503 EPS_INT32 nProtocolCnt = 0;
\r
1504 EPS_INT32 nCnt = 0;
\r
1505 EPS_BOOL bBreak = FALSE;
\r
1509 if(epsCmnFnc.getTime){
\r
1510 tmStart = epsCmnFnc.getTime();
\r
1511 tmNow = tmSpan = tmReq = 0;
\r
1513 timeout = tmStart = tmNow = tmSpan = tmReq = 0;
\r
1516 #ifdef GCOMSW_PRT_USE_LPR
\r
1517 if(protocol & EPS_PROTOCOL_LPR) nProtocolCnt++;
\r
1519 #ifdef GCOMSW_PRT_USE_RAW
\r
1520 if( (protocol & EPS_PROTOCOL_RAW) && !(protocol & EPS_PROTOCOL_LPR) ) nProtocolCnt++;
\r
1522 if(0 == nProtocolCnt){
\r
1523 EPS_RETURN( EPS_ERR_PRINTER_NOT_FOUND )
\r
1526 /* Setup net Find functions */
\r
1527 pProtocolFncs = (EPS_FIND_FUNCS*)EPS_ALLOC(sizeof(EPS_FIND_FUNCS)*nProtocolCnt);
\r
1528 if(NULL == pProtocolFncs){
\r
1529 EPS_RETURN( EPS_ERR_MEMORY_ALLOCATION )
\r
1532 pFncs = pProtocolFncs;
\r
1534 #ifdef GCOMSW_PRT_USE_LPR
\r
1535 if(protocol & EPS_PROTOCOL_LPR){
\r
1536 pFncs->fncStart = &lprFindStart;
\r
1537 pFncs->fncCheck = &lprFind;
\r
1538 pFncs->fncEnd = &lprFindEnd;
\r
1539 pFncs->sock = EPS_INVALID_SOCKET;
\r
1541 strcpy(pFncs->address, EPSNET_UDP_BROADCAST_ADDR);
\r
1543 strcpy(pFncs->address, address);
\r
1548 #ifdef GCOMSW_PRT_USE_RAW
\r
1549 if( (protocol & EPS_PROTOCOL_RAW) && !(protocol & EPS_PROTOCOL_LPR) ){
\r
1550 pFncs->fncStart = &rawFindStart;
\r
1551 pFncs->fncCheck = &rawFind;
\r
1552 pFncs->fncEnd = &rawFindEnd;
\r
1553 pFncs->sock = EPS_INVALID_SOCKET;
\r
1555 strcpy(pFncs->address, EPSNET_UDP_BROADCAST_ADDR);
\r
1557 strcpy(pFncs->address, address);
\r
1562 /* Start (send discover message) */
\r
1563 pFncs = pProtocolFncs;
\r
1564 ret = EPS_ERR_NONE;
\r
1565 for(nCnt = 0; (nCnt < nProtocolCnt) && (ret == EPS_ERR_NONE); nCnt++, pFncs++){
\r
1566 ret = pFncs->fncStart( &(pFncs->sock), pFncs->address, plural );
\r
1569 /* Check response */
\r
1570 if( EPS_ERR_NONE == ret){
\r
1571 ret = EPS_ERR_PRINTER_NOT_FOUND;
\r
1573 while( (EPS_ERR_PRINTER_NOT_FOUND == ret || EPS_ERR_PRINTER_NOT_USEFUL == ret) && !bBreak ){
\r
1574 pFncs = pProtocolFncs;
\r
1575 for(nCnt = 0; nCnt < nProtocolCnt; ){
\r
1576 innerPrinter = NULL;
\r
1577 ret = pFncs->fncCheck(pFncs->sock, &innerPrinter);
\r
1579 if( EPS_COM_NOT_RECEIVE == ret ){
\r
1580 ret = EPS_ERR_PRINTER_NOT_FOUND;
\r
1585 if( EPS_ERR_NONE == ret ){
\r
1586 innerPrinter->protocol |= EPS_PRT_DIRECTION(printJob.commMode);
\r
1588 ret = prtRegPrinter( innerPrinter, TRUE );
\r
1590 if(EPS_FIND_CANCELED == ret){
\r
1592 } else if(FALSE == plural){
\r
1593 /* find one printer */
\r
1598 } else if(EPS_ERR_PRINTER_NOT_FOUND == ret ){
\r
1599 /* next protocol */
\r
1602 } else if(EPS_ERR_PRINTER_NOT_USEFUL == ret ){
\r
1603 if(FALSE == plural){
\r
1604 /* find one printer */
\r
1608 /* next protocol */
\r
1618 /* epsCancelFindPriter() */
\r
1619 if( epsCmnFnc.lockSync && epsCmnFnc.unlockSync ){
\r
1620 if( 0 == epsCmnFnc.lockSync() ){
\r
1621 if( g_FindBreak ){
\r
1622 epsCmnFnc.unlockSync();
\r
1626 epsCmnFnc.unlockSync();
\r
1632 tmNow = epsCmnFnc.getTime();
\r
1633 tmSpan = (EPS_UINT32)(tmNow - tmStart);
\r
1634 /*EPS_DBGPRINT( ("TM %u - %u <> %u\n", tmNow, tmStart, tmSpan) )*/
\r
1635 if( tmSpan >= timeout ){
\r
1641 /* re isuue request */
\r
1642 /*EPS_DBGPRINT( ("TM %u - %u <> %u\n", tmNow, tmStart, tmSpan) )*/
\r
1643 if( (EPS_ERR_PRINTER_NOT_FOUND == ret ||
\r
1644 EPS_ERR_PRINTER_NOT_USEFUL == ret) && epsCmnFnc.getTime )
\r
1646 tmNow = epsCmnFnc.getTime();
\r
1651 if( EPSNET_FIND_REREQUEST_TIME <= (EPS_UINT32)(tmNow - tmReq) ){
\r
1652 EPS_DBGPRINT( ("beef up TM %u - %u <> %u\n", tmNow, tmReq, (EPS_UINT32)(tmNow - tmReq)) )
\r
1653 pFncs = pProtocolFncs;
\r
1654 ret = EPS_ERR_NONE;
\r
1655 for(nCnt = 0; (nCnt < nProtocolCnt) && (ret == EPS_ERR_NONE); nCnt++, pFncs++){
\r
1656 ret = pFncs->fncStart( &(pFncs->sock), pFncs->address, plural );
\r
1659 if( EPS_ERR_NONE == ret){
\r
1660 ret = EPS_ERR_PRINTER_NOT_FOUND;
\r
1669 pFncs = pProtocolFncs;
\r
1670 for(nCnt = 0; (nCnt < nProtocolCnt); nCnt++, pFncs++){
\r
1671 pFncs->fncEnd( pFncs->sock );
\r
1674 EPS_SAFE_RELEASE(pProtocolFncs);
\r
1679 #endif /* GCOMSW_PRT_USE_NETWORK */
\r
1682 /*******************************************|********************************************/
\r
1684 /* Function name: MakePrinterStructure() */
\r
1688 /* Name: Type: Description: */
\r
1689 /* dst EPS_PRINTER* O: Printer information */
\r
1690 /* src EPS_PRINTER_INN* I: Printer information internal */
\r
1692 /* Return value: */
\r
1695 /* Description: */
\r
1696 /* Copy printer information. */
\r
1698 /*******************************************|********************************************/
\r
1699 static void MakePrinterStructure(
\r
1702 EPS_PRINTER_INN* src
\r
1705 EPS_DBGPRINT(("%s : %d\n", src->modelName, src->protocol))
\r
1706 dst->protocol = EPS_PRT_PROTOCOL(src->protocol);
\r
1707 dst->supportFunc = src->supportFunc;
\r
1708 dst->language = src->language;
\r
1709 strcpy(dst->location, src->location);
\r
1710 strcpy(dst->macAddress, src->macAddress);
\r
1711 strcpy(dst->manufacturerName, src->manufacturerName);
\r
1712 strcpy(dst->modelName, src->modelName);
\r
1713 strcpy(dst->friendlyName, src->friendlyName);
\r
1714 strcpy(dst->printerID, src->printerID);
\r
1718 /*******************************************|********************************************/
\r
1720 /* Function name: IsValidAddress() */
\r
1724 /* Name: Type: Description: */
\r
1725 /* addr EPS_INT8* I: IP Address */
\r
1727 /* Return value: */
\r
1728 /* TRUE - valid */
\r
1729 /* FALSE - invalid */
\r
1731 /* Description: */
\r
1732 /* Validation of IP(v4) Address. */
\r
1734 /*******************************************|********************************************/
\r
1735 static EPS_BOOL IsValidAddress(
\r
1737 const EPS_INT8* addr
\r
1740 #define EPS_IPSEGNUM (4)
\r
1742 EPS_UINT32 nSeg[EPS_IPSEGNUM];
\r
1745 memset(nSeg, 0xFF, sizeof(EPS_UINT32)*EPS_IPSEGNUM);
\r
1747 sscanf(addr, "%d.%d.%d.%d", &nSeg[0], &nSeg[1], &nSeg[2], &nSeg[3]);
\r
1749 for(nCnt = 0; nCnt < EPS_IPSEGNUM; nCnt++){
\r
1750 if(nSeg[nCnt] > 255){
\r
1758 /*________________________________ epson-protocol.c _________________________________*/
\r
1760 /*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
\r
1761 /* 1 2 3 4 5 6 7 8 */
\r
1762 /*******************************************|********************************************/
\r
1763 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
1764 /***** End of File *** End of File *** End of File *** End of File *** End of File ******/
\r
1765 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r