1 /*___________________________________ epson-cbt.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 /* Epson CBT Module */
\r
19 /* Public Function Calls */
\r
20 /* -------------------------- */
\r
21 /* EPS_ERR_CODE cbtCommOpen (void ); */
\r
22 /* EPS_INT32 cbtCommClose (void ); */
\r
23 /* EPS_ERR_CODE cbtCommChannelOpen (Channel, bRetry ); */
\r
24 /* EPS_INT32 cbtCommChannelClose (Channel ); */
\r
25 /* EPS_INT32 cbtCommReadData (Channel, Buffer, BuffLen, Size); */
\r
26 /* EPS_INT32 cbtCommWriteData (Channel, Buffer, BuffLen, Size); */
\r
28 /*******************************************|********************************************/
\r
30 /*------------------------------------ Includes -------------------------------------*/
\r
31 /*******************************************|********************************************/
\r
32 #include "epson-escpr-pvt.h"
\r
33 #include "epson-escpr-err.h"
\r
34 #include "epson-escpr-mem.h"
\r
35 #include "epson-escpr-services.h"
\r
36 #include "epson-cbt.h"
\r
38 /*------------------------------------ Definition -----------------------------------*/
\r
39 /*******************************************|********************************************/
\r
40 #define CBT_OPENCH_WAIT (50)
\r
41 #define CBT_OPENCH_RETRY (50)
\r
43 /*------------------------------- Local Compiler Switch --------------------------------*/
\r
44 /*******************************************|********************************************/
\r
45 #define LCOMSW_CBT_SOCKETFUNC_ON 1 /* the socket ID mode (0:OFF 1:ON(Default))*/
\r
47 #define LCOMSW_CBT_ALLOC_MEM 1 /* Use static memory */
\r
48 /* 0 -> Use static memory */
\r
49 /* 1 -> Use epsFnc.memAlloc() (Default) */
\r
51 #ifdef EPS_LOG_MODULE_CBT
\r
52 #define EPS_LOG_MODULE EPS_LOG_MODULE_CBT
\r
54 #define EPS_LOG_MODULE 0
\r
57 /*---------------------------- ESC/P-R Lib Global Variables --------------------------*/
\r
58 /*******************************************|********************************************/
\r
60 /*** Print Job/Page Struct */
\r
61 /*** -------------------------------------------------------------------------------*/
\r
62 extern EPS_PRINT_JOB printJob;
\r
64 /*** System Dependent Function (USB Communication) */
\r
65 /*** -------------------------------------------------------------------------------*/
\r
66 extern EPS_USB_FUNC epsUsbFnc;
\r
67 extern EPS_CMN_FUNC epsCmnFnc;
\r
70 /*** -------------------------------------------------------------------------------*/
\r
71 EPS_BOOL ioOpenState = EPS_IO_NOT_OPEN; /* Open state of I/O port (Bi-Directional) */
\r
72 EPS_BOOL ioDataChState = EPS_IO_NOT_OPEN; /* Open state of Data Channel */
\r
73 EPS_BOOL ioControlChState= EPS_IO_NOT_OPEN; /* Open state of Control Channel */
\r
74 EPS_BOOL ioOpenUniDirect = EPS_IO_NOT_OPEN; /* Open state of I/O port (Uni-Directional) */
\r
76 /*--------------------------- Data Structure Declarations ---------------------------*/
\r
77 /*******************************************|********************************************/
\r
79 /*------------------------ Epson CBT Module Global Variables -------------------------*/
\r
80 /*******************************************|********************************************/
\r
81 static CBTS_PRNINFO *gpCbtPrnInfo = NULL; /* Printer Information */
\r
83 /*-------------------------------- Local Definition ---------------------------------*/
\r
84 /*******************************************|********************************************/
\r
85 #define CBT_DUMYREAD_MAX (128) /* dummy read try max */
\r
87 /*--------------------- Memory allocation for Epson CBT Module ------------------------*/
\r
88 /*******************************************|********************************************/
\r
89 #if LCOMSW_CBT_ALLOC_MEM == 0
\r
90 static CBTS_PRNINFO sgcbtprninfo;
\r
91 static EPS_UINT8 sgreadbuff[CBT_MAX_CH][CBT_MAX_RTMP];
\r
92 static EPS_UINT8 sgrtmpbuff[CBT_MAX_CH][CBT_MAX_RTMP];
\r
93 static EPS_UINT8 sgwritebuff[CBT_TXPSIZE];
\r
94 static EPS_UINT8 sgcbtreadrtnbuff[CBT_MAX_RTMP];
\r
95 static EPS_UINT8 sgcbtdatareadbuff[CBT_MAX_RTMP];
\r
96 #endif /* LCOMSW_CBT_ALLOC_MEM */
\r
98 /*------------------------------------ Debug Dump -----------------------------------*/
\r
99 /*******************************************|********************************************/
\r
100 /*** ALL Debug Dump Switch for <epson-cbt.> */
\r
101 /*** -------------------------------------------------------------------------------*/
\r
102 #define _COMM_DEBUG 0 /* 0: OFF 1: ON */
\r
103 #define _CBTDEBUG_ 0 /* 0: OFF 1: ON */
\r
104 #define CBT_DBG_ERROR 0 /* 0: OFF 1: ON */
\r
106 /*** _COMM_DEBUG --- Communication Module Debug */
\r
107 /***--------------------------------------------------------------------------------*/
\r
109 #define COMM_DBG_ERROR
\r
110 #define CBTDebugPrintf(a) printf a
\r
111 #else /* def _COMM_DEBUG */
\r
112 #define CBTDebugPrintf(a)
\r
113 #endif /* def _COMM_DEBUG */
\r
115 /*** _CBTDEBUG_ --- CBT Debug */
\r
116 /***--------------------------------------------------------------------------------*/
\r
120 static EPS_INT8 debMsgWork[512];
\r
121 static void DebMsgOut(EPS_INT8 *buf)
\r
123 #ifdef _WINCE32_TEST_
\r
127 fh_Alloc = CreateFile(L"\\CBT_LOG.TXT",GENERIC_WRITE,FILE_SHARE_WRITE,NULL,
\r
128 OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
\r
129 SetFilePointer(fh_Alloc,0,NULL,FILE_END);
\r
130 WriteFile(fh_Alloc, buf, strlen(buf), &wb, NULL);
\r
131 CloseHandle(fh_Alloc);
\r
132 #else /* def _WINCE32_TEST_ */
\r
133 fprintf(stderr,buf);
\r
134 #endif /* def _WINCE32_TEST_ */
\r
136 #endif /* def _CBTDEBUG_ */
\r
138 /*-------------------------------- Local Functions ----------------------------------*/
\r
139 /*******************************************|********************************************/
\r
140 /*** Communication Module */
\r
141 /*** -------------------------------------------------------------------------------*/
\r
142 static EPS_INT32 commOpen (const EPS_USB_DEVICE*, EPS_FILEDSC* );
\r
143 static EPS_INT32 commClose (EPS_FILEDSC );
\r
144 static EPS_INT32 commOpenChannel (EPS_FILEDSC, EPS_INT32, EPS_BOOL );
\r
145 static EPS_INT32 commCloseChannel (EPS_FILEDSC, EPS_INT32 );
\r
146 static EPS_INT32 commChChange (EPS_INT32, EPS_UINT8* );
\r
148 /*** Mini CBT Engine */
\r
149 /*** -------------------------------------------------------------------------------*/
\r
150 static EPS_INT16 EPCBT_Open (EPS_FILEDSC, void*, EPS_WritePortal, EPS_ReadPortal);
\r
151 static EPS_INT16 EPCBT_Close (EPS_FILEDSC );
\r
152 static EPS_INT16 EPCBT_OpenChannel (EPS_FILEDSC, EPS_UINT8, EPS_BOOL );
\r
153 static EPS_INT16 EPCBT_CloseChannel (EPS_FILEDSC, EPS_UINT8 );
\r
154 static EPS_INT16 EPCBT_Write (EPS_FILEDSC, EPS_UINT8, const EPS_UINT8*, EPS_INT32*);
\r
155 static EPS_INT16 EPCBT_Read (EPS_FILEDSC, EPS_UINT8, EPS_UINT8*, EPS_INT32* );
\r
156 #if LCOMSW_CBT_SOCKETFUNC_ON
\r
157 static EPS_INT16 EPCBT_GetSocketID (EPS_FILEDSC, EPS_UINT8*, EPS_UINT8*, EPS_INT32 );
\r
159 static EPS_INT16 CbtWriteRtn (EPS_FILEDSC, CBTS_PRNINFO*, const EPS_UINT8*, EPS_INT32, EPS_INT32*);
\r
160 static EPS_INT16 CbtReadRtn (EPS_FILEDSC, CBTS_PRNINFO*, EPS_UINT8, EPS_UINT8*, EPS_INT32, EPS_INT32*, EPS_UINT8);
\r
161 static void CbtDummyRead (EPS_FILEDSC, CBTS_PRNINFO* );
\r
162 static void CbtChDummyRead (EPS_FILEDSC, CBTS_PRNINFO*, CBTS_CHINFO* );
\r
163 static EPS_INT16 CbtReplyCheck (EPS_UINT8*, EPS_INT32, EPS_UINT8 );
\r
164 static EPS_INT16 CbtEpsonPacking (EPS_FILEDSC, CBTS_PRNINFO* );
\r
165 static EPS_INT16 CbtInitCommand (EPS_FILEDSC, CBTS_PRNINFO* );
\r
166 static EPS_INT32 CbtOpenChannelCommand (EPS_FILEDSC, CBTS_PRNINFO*, EPS_UINT8, EPS_UINT32*, EPS_UINT32*, EPS_UINT32, EPS_UINT32);
\r
167 static EPS_INT16 CbtCloseChannelCommand (EPS_FILEDSC, CBTS_PRNINFO*, EPS_UINT8 );
\r
168 static EPS_INT32 CbtCreditReqCommand (EPS_FILEDSC, CBTS_PRNINFO*, EPS_UINT8, EPS_UINT32, EPS_UINT32);
\r
169 static EPS_INT16 CbtCreditCommand (EPS_FILEDSC, CBTS_PRNINFO*, EPS_UINT8, EPS_UINT32 );
\r
170 #if LCOMSW_CBT_SOCKETFUNC_ON
\r
171 static EPS_INT16 CbtGetSocketIDCommand (EPS_FILEDSC, CBTS_PRNINFO*, EPS_UINT8*, EPS_INT32, EPS_UINT8*);
\r
173 static EPS_INT32 CbtDataWrite (EPS_FILEDSC, CBTS_PRNINFO*, EPS_UINT8, const EPS_UINT8*, EPS_INT32);
\r
174 static EPS_INT16 CbtDataRead (EPS_FILEDSC, CBTS_PRNINFO*, EPS_UINT8, EPS_UINT8*, EPS_INT32*);
\r
175 static EPS_INT16 CbtMemAlloc (void );
\r
176 static void CbtMemFree (void );
\r
177 static void CbtPutBigEndianByte2 (EPS_UINT32, EPS_UINT8* );
\r
180 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
181 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
182 /*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
\r
183 /*-------------------- Public Functions ---------------------*/
\r
184 /*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
\r
185 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
186 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
188 /*******************************************|********************************************/
\r
190 /* Function name: cbtCommOpen() */
\r
194 /* Name: Type: Description: */
\r
195 /* devinfo EPS_USB_DEVICE I: Pointer to a usb device infomation */
\r
196 /* fd EPS_FILEDSC* O: file discripter */
\r
198 /* Return value: */
\r
199 /* EPS_ERR_NONE - Success (Opened Communication) */
\r
200 /* EPSCBT_ERR_2NDOPEN - CBT channels are already opened */
\r
201 /* EPS_ERR_NOT_OPEN_IO - Cannot Open I/O Portal */
\r
202 /* EPCBT_ERR_CBT2NDOPEN - CBT channels are already opened */
\r
203 /* EPCBT_ERR_MEMORY - Fail to memory allocation */
\r
204 /* EPCBT_ERR_CBTDISABLE - Fail to CBT communication */
\r
205 /* EPCBT_ERR_FATAL - Fatal communication error */
\r
206 /* EPCBT_ERR_INITDENIED - Printer cannot start CBT mode */
\r
207 /* EPCBT_ERR_VERSION - Incompatible version */
\r
208 /* EPCBT_ERR_INITFAILED - Not used by EPSON */
\r
209 /* EPCBT_ERR_UERESULT - Undefined result value */
\r
210 /* EPCBT_ERR_CBTNOTOPEN - Port is not open */
\r
211 /* EPCBT_ERR_PARAM - Parameter error */
\r
212 /* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
\r
213 /* EPCBT_ERR_NOSERVICE - The channel does not support the requested */
\r
217 /* Opens the communication on the specified. */
\r
219 /*******************************************|********************************************/
\r
220 EPS_INT32 cbtCommOpen (
\r
222 const EPS_USB_DEVICE* devinfo,
\r
226 EPS_INT32 Ret; /* Return status of internal calls */
\r
230 /*** Open Communication */
\r
231 if ((Ret = commOpen(devinfo, fd)) != EPCBT_ERR_NONE){
\r
232 CBTDebugPrintf(("EPS CBT: Open Failed [%d]\r\n",Ret));
\r
236 EPS_RETURN( EPS_ERR_NONE );
\r
239 /*******************************************|********************************************/
\r
241 /* Function name: cbtCommClose() */
\r
245 /* Name: Type: Description: */
\r
246 /* fd EPS_FILEDSC I: file discripter */
\r
248 /* Return value: */
\r
249 /* EPS_ERR_NONE - Closed Communication */
\r
250 /* EPSCBT_ERR_NOTOPEN - I/O port is not opened */
\r
251 /* EPCBT_ERR_CBTNOTOPEN - Port is not open */
\r
254 /* Closes the communication on the active printer. */
\r
256 /*******************************************|********************************************/
\r
257 EPS_INT32 cbtCommClose (
\r
266 CBTDebugPrintf(("EPS CBT:CLOSE --> Closing Communication on the device\r\n"));
\r
268 Ret = commClose(fd);
\r
270 if (Ret != EPCBT_ERR_NONE){
\r
271 CBTDebugPrintf(("EPS CBT: Close failed\r\n"));
\r
274 EPS_RETURN( EPS_ERR_NONE );
\r
277 /*******************************************|********************************************/
\r
279 /* Function name: cbtCommChannelOpen() */
\r
283 /* Name: Type: Description: */
\r
284 /* fd EPS_FILEDSC I: file discripter */
\r
285 /* Channel EPS_INT32 I: Communication Channel */
\r
286 /* bRetry EPS_BOOL I: If TRUE, retry open */
\r
288 /* Return value: */
\r
289 /* EPS_ERR_NONE - Success (Opened Communication) */
\r
290 /* EPSCBT_ERR_NOTOPEN - CBT channels are not opened */
\r
291 /* EPSCBT_ERR_PARAM - Parameter error */
\r
292 /* EPCBT_ERR_CBTNOTOPEN - Port is not open */
\r
293 /* EPCBT_ERR_PARAM - Parameter error */
\r
294 /* EPCBT_ERR_CH2NDOPEN - Channel is already open */
\r
295 /* EPCBT_ERR_RPLYPSIZE - Size of packet from OpenChannel is invalid */
\r
296 /* EPCBT_ERR_FATAL - Fatal communication error */
\r
297 /* EPCBT_ERR_UERESULT - Undefined result value */
\r
298 /* EPCBT_ERR_NOREPLY - No reply from printer */
\r
299 /* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
\r
300 /* EPCBT_ERR_UEREPLY - Received reply for a command not issued */
\r
301 /* EPCBT_ERR_RESOURCE - Insufficient printer resources for */
\r
303 /* EPCBT_ERR_OPENCHANNEL - Not used by EPSON */
\r
304 /* EPCBT_ERR_CHNOTSUPPORT - The channel is not supported */
\r
305 /* EPCBT_ERR_PACKETSIZE - Invalid packet size. */
\r
306 /* (0x0001 ? 0x0005 bytes) */
\r
307 /* EPCBT_ERR_NULLPACKETSZ - Packet size is 0x0000 in both directions. */
\r
308 /* No data can be transferred. Channel was */
\r
312 /* Open the communication channel. */
\r
314 /*******************************************|********************************************/
\r
315 EPS_INT32 cbtCommChannelOpen (
\r
326 if ((Ret = commOpenChannel(fd, Channel, bRetry)) != EPCBT_ERR_NONE){
\r
328 if (Channel == EPS_CBTCHANNEL_CTRL) {
\r
329 CBTDebugPrintf(("EPS CBT: Control Channel Open Failed\r\n"));
\r
331 } else if (Channel == EPS_CBTCHANNEL_DATA) {
\r
332 CBTDebugPrintf(("EPS CBT: Data Channel Open Failed\r\n"));
\r
338 EPS_RETURN( EPS_ERR_NONE );
\r
341 /*******************************************|********************************************/
\r
343 /* Function name: cbtCommChannelClose() */
\r
347 /* Name: Type: Description: */
\r
348 /* fd EPS_FILEDSC I: file discripter */
\r
349 /* Channel EPS_INT32 I: Communication Channel */
\r
351 /* Return value: */
\r
352 /* EPS_ERR_NONE - Success (Closed Communication) */
\r
353 /* EPSCBT_ERR_NOTOPEN - CBT channels are not opened */
\r
354 /* EPSCBT_ERR_PARAM - Parameter error */
\r
355 /* EPCBT_ERR_CBTNOTOPEN - Port is not open */
\r
356 /* EPCBT_ERR_CHNOTOPEN - Channel is not opened */
\r
357 /* EPCBT_ERR_FATAL - Fatal communication error */
\r
358 /* EPCBT_ERR_CLOSEDENIED - Close Channel is denied */
\r
359 /* EPCBT_ERR_CMDDENIED - Command is denied (Channel is not opened) */
\r
360 /* EPCBT_ERR_UERESULT - Undefined result value */
\r
361 /* EPCBT_ERR_NOREPLY - No reply from printer */
\r
362 /* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
\r
363 /* EPCBT_ERR_UEREPLY - Received reply for a command not issued */
\r
366 /* Close the communication channel. */
\r
368 /*******************************************|********************************************/
\r
369 EPS_INT32 cbtCommChannelClose (
\r
379 if ((Ret = commCloseChannel(fd, Channel)) != EPCBT_ERR_NONE){
\r
380 CBTDebugPrintf(("EPS CBT: Channel Close Failed\r\n"));
\r
384 EPS_RETURN( EPS_ERR_NONE );
\r
387 /*******************************************|********************************************/
\r
389 /* Function name: cbtCommReadData() */
\r
393 /* Name: Type: Description: */
\r
394 /* fd EPS_FILEDSC I: file discripter */
\r
395 /* Channel EPS_INT32 I: Channel-Select */
\r
396 /* 00: Data Channel */
\r
397 /* 01: Control Channel */
\r
398 /* Buffer EPS_UINT8* I: Buffer Pointer for Read Data */
\r
399 /* BuffLen EPS_INT32 I: Read Data Buffer Length (bytes) */
\r
400 /* Size EPS_INT32* O: Actuall Read Size */
\r
402 /* Return value: */
\r
403 /* EPCBT_ERR_NONE - Success */
\r
404 /* EPSCBT_ERR_NOTOPEN - I/O port is not opened */
\r
405 /* EPSCBT_ERR_PARAM - Parameter error */
\r
406 /* EPCBT_ERR_CBTNOTOPEN - CBT is not opened */
\r
407 /* EPCBT_ERR_PARAM - Parameter error */
\r
408 /* EPCBT_ERR_CHNOTOPEN - Channel is not opened */
\r
409 /* EPCBT_ERR_FATAL - Fatal communication error */
\r
410 /* EPCBT_ERR_CREDITOVF - Credit over flow */
\r
411 /* EPCBT_ERR_CMDDENIED - Command is denied (Channel is not opened) */
\r
412 /* EPCBT_ERR_UERESULT - Undefined result value */
\r
413 /* EPCBT_ERR_NOREPLY - No reply from printer */
\r
414 /* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
\r
415 /* EPCBT_ERR_UEREPLY - Received reply for a command not issued */
\r
416 /* EPCBT_ERR_READERROR - Data read error */
\r
419 /* Read the data from printer. */
\r
421 /*******************************************|********************************************/
\r
422 EPS_INT32 cbtCommReadData (
\r
431 EPS_INT32 Ret = EPCBT_ERR_NONE;
\r
432 EPS_INT32 InLen = 0;
\r
433 EPS_UINT8 CBTCh = 0;
\r
437 if ( ioOpenState == EPS_IO_NOT_OPEN ) /* Open check */
\r
438 Ret = EPSCBT_ERR_NOTOPEN;
\r
441 Ret = commChChange( Channel, &CBTCh ); /* channel change */
\r
442 if( Ret == EPCBT_ERR_NONE )
\r
444 *Size = 0; /* size clear */
\r
445 Ret = EPCBT_Read( fd, CBTCh, NULL, &InLen ); /* Size Get */
\r
446 if ( Ret == EPCBT_ERR_NONE )
\r
448 if ( InLen > BuffLen ) /* small buffer size ? */
\r
450 Ret = EPCBT_Read( fd, CBTCh, Buffer, &InLen ); /* Data Get */
\r
456 #ifdef COMM_DBG_ERROR
\r
457 if ( Ret != EPCBT_ERR_NONE )
\r
458 CBTDebugPrintf(("<< ReadData Ret[%d] Size[%d]\r\n", Ret, *Size));
\r
464 /*******************************************|********************************************/
\r
466 /* Function name: cbtCommWriteData() */
\r
470 /* Name: Type: Description: */
\r
471 /* fd EPS_FILEDSC I: file discripter */
\r
472 /* Channel EPS_INT32 I: Channel-Select */
\r
473 /* 00: Data Channel */
\r
474 /* 01: Control Channel */
\r
475 /* Buffer const EPS_UINT8* I: Buffer Pointer for Write Data */
\r
476 /* BuffLen EPS_INT32 I: Write Data Buffer Length (bytes) */
\r
477 /* Size EPS_INT32* O: Actuall Write Size */
\r
479 /* Return value: */
\r
480 /* EPCBT_ERR_NONE - Success */
\r
481 /* EPSCBT_ERR_NOTOPEN - I/O port is not opened */
\r
482 /* EPCBT_ERR_CBTNOTOPEN - CBT is not opened */
\r
483 /* EPSCBT_ERR_PARAM - Parameter error */
\r
484 /* EPCBT_ERR_CHNOTOPEN - Channel is not opened */
\r
485 /* EPCBT_ERR_FNCDISABLE - Function is disable to be completely finished */
\r
486 /* EPCBT_ERR_FATAL - Fatal communication error */
\r
487 /* EPCBT_ERR_CMDDENIED - Command is denied (Channel is not opened) */
\r
488 /* EPCBT_ERR_UERESULT - Undefined result value */
\r
489 /* EPCBT_ERR_WRITEERROR - Failed to write */
\r
492 /* Write the data to printer. */
\r
494 /*******************************************|********************************************/
\r
495 EPS_INT32 cbtCommWriteData (
\r
499 const EPS_UINT8* Buffer,
\r
504 EPS_INT32 Ret = EPCBT_ERR_NONE;
\r
506 EPS_INT32 RestSize;
\r
507 EPS_UINT8 CBTCh = 0;
\r
511 CBTDebugPrintf(("EPS CBT : cbtCommWriteData -> ioOpenState == %s\r\n", ioOpenState == EPS_IO_OPEN ? "ON" : "OFF"));
\r
513 if ( ioOpenState == EPS_IO_NOT_OPEN ) { /* Open check */
\r
514 Ret = EPSCBT_ERR_NOTOPEN;
\r
519 Ret = commChChange( Channel, &CBTCh ); /* channel change */
\r
520 if( Ret == EPCBT_ERR_NONE )
\r
522 *Size = 0; /* size clear */
\r
523 RestSize = BuffLen;
\r
525 while ( RestSize > 0 )
\r
527 Written = RestSize;
\r
528 Ret = EPCBT_Write(fd, CBTCh, &Buffer[*Size], &Written ); /* Write */
\r
529 *Size += Written; /* Set Write Length */
\r
530 RestSize -= Written;
\r
532 if( Ret != EPCBT_ERR_NONE )
\r
538 #ifdef COMM_DBG_ERROR
\r
539 if ( Ret != EPCBT_ERR_NONE )
\r
540 CBTDebugPrintf(("<< WriteData Ret[%d] Size[%d]\r\n", Ret, *Size));
\r
547 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
548 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
549 /*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
\r
550 /*-------------------- Local Functions ---------------------*/
\r
551 /*%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%*/
\r
552 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
553 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
555 /*******************************************|********************************************/
\r
557 /* Function name: commOpen() */
\r
561 /* Name: Type: Description: */
\r
562 /* devinfo EPS_USB_DEVICE I: Pointer to a usb device infomation */
\r
563 /* fd EPS_FILEDSC* O: file discripter */
\r
565 /* Return value: */
\r
566 /* EPCBT_ERR_NONE - Success */
\r
567 /* EPSCBT_ERR_2NDOPEN - CBT channels are already opened */
\r
568 /* EPS_ERR_NOT_OPEN_IO - Cannot Open I/O Portal */
\r
569 /* EPCBT_ERR_CBT2NDOPEN - CBT channels are already opened */
\r
570 /* EPCBT_ERR_MEMORY - Fail to memory allocation */
\r
571 /* EPCBT_ERR_CBTDISABLE - Fail to CBT communication */
\r
572 /* EPCBT_ERR_FATAL - Fatal communication error */
\r
573 /* EPCBT_ERR_INITDENIED - Printer cannot start CBT mode */
\r
574 /* EPCBT_ERR_VERSION - Incompatible version */
\r
575 /* EPCBT_ERR_INITFAILED - Not used by EPSON */
\r
576 /* EPCBT_ERR_UERESULT - Undefined result value */
\r
577 /* EPCBT_ERR_CBTNOTOPEN - Port is not open */
\r
578 /* EPCBT_ERR_PARAM - Parameter error */
\r
579 /* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
\r
580 /* EPCBT_ERR_NOSERVICE - The channel does not support the requested */
\r
584 /* Opens the communication. */
\r
586 /*******************************************|********************************************/
\r
587 static EPS_INT32 commOpen (
\r
589 const EPS_USB_DEVICE* devinfo,
\r
593 EPS_INT32 Ret = EPCBT_ERR_NONE;
\r
598 if ( ioOpenState == EPS_IO_OPEN ) { /* Open check */
\r
599 Ret = EPSCBT_ERR_2NDOPEN;
\r
601 if ( (*fd = epsUsbFnc.openPortal(devinfo)) == EPS_INVALID_FILEDSC)
\r
602 EPS_RETURN( EPS_ERR_NOT_OPEN_IO );
\r
605 Ret = EPCBT_Open(*fd, NULL, epsUsbFnc.writePortal, epsUsbFnc.readPortal); /* Open */
\r
607 if ( Ret == EPCBT_ERR_NONE ) {
\r
608 /* channel confirm */
\r
609 Ret = EPCBT_GetSocketID( *fd, &Sid, (EPS_UINT8*)"EPSON-DATA", 10 );
\r
610 if ( Ret == EPCBT_ERR_NONE )
\r
611 Ret = EPCBT_GetSocketID( *fd, &Sid, (EPS_UINT8*)"EPSON-CTRL", 10 );
\r
613 if(EPCBT_ERR_NONE != Ret ){
\r
616 } else if(EPS_INVALID_FILEDSC != *fd){
\r
617 epsUsbFnc.closePortal(*fd);
\r
618 *fd = EPS_INVALID_FILEDSC;
\r
622 if ( Ret == EPCBT_ERR_NONE )
\r
623 ioOpenState = EPS_IO_OPEN; /* Open flag On */
\r
625 CBTDebugPrintf(("EPS CBT : commOpen -> ioOpenState == %s\r\n", ioOpenState == EPS_IO_OPEN ? "ON" : "OFF"));
\r
630 /*******************************************|********************************************/
\r
632 /* Function name: commClose() */
\r
636 /* Name: Type: Description: */
\r
637 /* fd EPS_FILEDSC I: file discripter */
\r
639 /* Return value: */
\r
640 /* EPCBT_ERR_NONE - Success */
\r
641 /* EPSCBT_ERR_NOTOPEN - I/O port is not opened */
\r
642 /* EPCBT_ERR_CBTNOTOPEN - Port is not open */
\r
645 /* Close the communication. */
\r
647 /*******************************************|********************************************/
\r
648 static EPS_INT32 commClose (
\r
653 EPS_INT32 Ret = EPCBT_ERR_NONE;
\r
654 EPS_INT32 closePtlState = 0;
\r
658 if ( ioOpenState == EPS_IO_NOT_OPEN ) /* Open check */
\r
659 Ret = EPSCBT_ERR_NOTOPEN;
\r
662 Ret = EPCBT_Close(fd); /* Channel close & cbt exit */
\r
664 closePtlState = epsUsbFnc.closePortal(fd);
\r
666 ioOpenState = EPS_IO_NOT_OPEN; /* Open flag Off */
\r
669 #ifdef COMM_DBG_ERROR
\r
670 if ( Ret != EPCBT_ERR_NONE )
\r
671 CBTDebugPrintf(("<< Close Ret[%d] Close Portal[%d]\r\n", Ret, closePtlState));
\r
677 /*******************************************|********************************************/
\r
679 /* Function name: commOpenChannel() */
\r
683 /* Name: Type: Description: */
\r
684 /* fd EPS_FILEDSC I: file discripter */
\r
685 /* Channel EPS_INT32 I: channel number */
\r
686 /* bRetry EPS_BOOL I: If TRUE, retry open */
\r
688 /* Return value: */
\r
689 /* EPCBT_ERR_NONE - Success */
\r
690 /* EPSCBT_ERR_NOTOPEN - CBT channels are not opened */
\r
691 /* EPSCBT_ERR_PARAM - Parameter error */
\r
692 /* EPCBT_ERR_CBTNOTOPEN - Port is not open */
\r
693 /* EPCBT_ERR_PARAM - Parameter error */
\r
694 /* EPCBT_ERR_CH2NDOPEN - Channel is already open */
\r
695 /* EPCBT_ERR_RPLYPSIZE - Size of packet from OpenChannel is invalid */
\r
696 /* EPCBT_ERR_FATAL - Fatal communication error */
\r
697 /* EPCBT_ERR_UERESULT - Undefined result value */
\r
698 /* EPCBT_ERR_NOREPLY - No reply from printer */
\r
699 /* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
\r
700 /* EPCBT_ERR_UEREPLY - Received reply for a command not issued */
\r
701 /* EPCBT_ERR_RESOURCE - Insufficient printer resources for */
\r
703 /* EPCBT_ERR_OPENCHANNEL - Not used by EPSON */
\r
704 /* EPCBT_ERR_CHNOTSUPPORT - The channel is not supported */
\r
705 /* EPCBT_ERR_PACKETSIZE - Invalid packet size. */
\r
706 /* (0x0001 ? 0x0005 bytes) */
\r
707 /* EPCBT_ERR_NULLPACKETSZ - Packet size is 0x0000 in both directions. */
\r
708 /* No data can be transferred. Channel was */
\r
712 /* Opens the communication channel. */
\r
714 /*******************************************|********************************************/
\r
715 static EPS_INT32 commOpenChannel (
\r
722 EPS_INT32 Ret = EPCBT_ERR_NONE;
\r
723 EPS_UINT8 CBTCh = 0;
\r
727 if ( ioOpenState == EPS_IO_NOT_OPEN ) { /* Open check */
\r
728 Ret = EPSCBT_ERR_NOTOPEN;
\r
730 Ret = commChChange( Channel, &CBTCh ); /* Channel Change */
\r
732 if ( Ret == EPCBT_ERR_NONE ) {
\r
733 if ((CBTCh == CBT_CBTCH_DATA) && (ioDataChState == EPS_IO_NOT_OPEN)) {
\r
734 Ret = (EPS_INT16)EPCBT_OpenChannel(fd, CBTCh, bRetry); /* Open Data Channel */
\r
735 if (Ret == EPCBT_ERR_NONE)
\r
736 ioDataChState = EPS_IO_OPEN;
\r
739 if ((CBTCh == CBT_CBTCH_CTRL) && (ioControlChState == EPS_IO_NOT_OPEN)) {
\r
740 Ret = (EPS_INT16)EPCBT_OpenChannel(fd, CBTCh, bRetry); /* Open Control Channel */
\r
741 if (Ret == EPCBT_ERR_NONE)
\r
742 ioControlChState = EPS_IO_OPEN;
\r
747 #ifdef COMM_DBG_ERROR
\r
748 CBTDebugPrintf(("EPS CBT : commOpenChannel(%x)->%d\r\n", CBTCh, Ret));
\r
749 CBTDebugPrintf(("EPS CBT : commOpenChannel-> ioOpenState == %s\r\n", ioOpenState == EPS_IO_OPEN ? "ON" : "OFF"));
\r
750 if ( Ret != EPCBT_ERR_NONE )
\r
751 CBTDebugPrintf(("<< Close Channel Ret[%d]\r\n", Ret));
\r
757 /*******************************************|********************************************/
\r
759 /* Function name: commCloseChannel() */
\r
763 /* Name: Type: Description: */
\r
764 /* fd EPS_FILEDSC I: file discripter */
\r
765 /* Channel EPS_INT32 I: channel number */
\r
767 /* Return value: */
\r
768 /* EPCBT_ERR_NONE - Success */
\r
769 /* EPSCBT_ERR_NOTOPEN - CBT channels are not opened */
\r
770 /* EPSCBT_ERR_PARAM - Parameter error */
\r
771 /* EPCBT_ERR_CBTNOTOPEN - Port is not open */
\r
772 /* EPCBT_ERR_CHNOTOPEN - Channel is not opened */
\r
773 /* EPCBT_ERR_NONE - Success */
\r
774 /* EPCBT_ERR_FATAL - Fatal communication error */
\r
775 /* EPCBT_ERR_CLOSEDENIED - Close Channel is denied */
\r
776 /* EPCBT_ERR_CMDDENIED - Command is denied (Channel is not opened) */
\r
777 /* EPCBT_ERR_UERESULT - Undefined result value */
\r
778 /* EPCBT_ERR_NOREPLY - No reply from printer */
\r
779 /* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
\r
780 /* EPCBT_ERR_UEREPLY - Received reply for a command not issued */
\r
783 /* Close the communication channel. */
\r
785 /*******************************************|********************************************/
\r
786 static EPS_INT32 commCloseChannel (
\r
792 EPS_INT32 Ret = EPCBT_ERR_NONE;
\r
793 EPS_UINT8 CBTCh = 0;
\r
797 if ( ioOpenState == EPS_IO_NOT_OPEN ) /* Open check */
\r
798 Ret = EPSCBT_ERR_NOTOPEN;
\r
801 /* Channel close */
\r
802 Ret = commChChange( Channel, &CBTCh ); /* Channel Change */
\r
804 if ( Ret == EPCBT_ERR_NONE ) {
\r
805 if ((CBTCh == CBT_CBTCH_DATA) && (ioDataChState == EPS_IO_OPEN)) {
\r
806 Ret = (EPS_INT16)EPCBT_CloseChannel(fd, CBTCh); /* Close Data Channel */
\r
807 /*if (Ret == EPCBT_ERR_NONE) Force reset */
\r
808 ioDataChState = EPS_IO_NOT_OPEN;
\r
811 if ((CBTCh == CBT_CBTCH_CTRL) && (ioControlChState == EPS_IO_OPEN)) {
\r
812 Ret = (EPS_INT16)EPCBT_CloseChannel(fd, CBTCh); /* Close Control Channel */
\r
813 /*if (Ret == EPCBT_ERR_NONE) Force reset */
\r
814 ioControlChState = EPS_IO_NOT_OPEN;
\r
819 #ifdef COMM_DBG_ERROR
\r
820 if ( Ret != EPCBT_ERR_NONE )
\r
821 CBTDebugPrintf(("<< Close Channel Ret[%d]\r\n", Ret));
\r
827 /*******************************************|********************************************/
\r
829 /* Function name: commChChange() */
\r
833 /* Name: Type: Description: */
\r
834 /* Channel EPS_INT32 I: Channel number definition */
\r
835 /* 00: Data Channel */
\r
836 /* 01: Control Channel */
\r
837 /* CBTCh EPS_UINT8* O: Pointer to the channel number */
\r
838 /* 40: Data Channel */
\r
839 /* 02: Control Channel */
\r
841 /* Return value: */
\r
842 /* EPCBT_ERR_NONE - Success */
\r
843 /* EPSCBT_ERR_PARAM - Parameter error */
\r
846 /* Set the channel number. */
\r
848 /*******************************************|********************************************/
\r
849 static EPS_INT32 commChChange (
\r
855 EPS_INT32 Ret = EPCBT_ERR_NONE;
\r
861 case EPS_CBTCHANNEL_DATA: /* Data Channel */
\r
862 *CBTCh = CBT_CBTCH_DATA;
\r
864 case EPS_CBTCHANNEL_CTRL: /* Control Channel */
\r
865 *CBTCh = CBT_CBTCH_CTRL;
\r
867 default: /* Error */
\r
868 Ret = EPSCBT_ERR_PARAM;
\r
876 /*******************************************|********************************************/
\r
877 /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
\r
878 /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
\r
879 /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv Mini CBT Engine vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
\r
880 /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
\r
881 /*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
\r
882 /*******************************************|********************************************/
\r
884 /*******************************************|********************************************/
\r
886 /* Function name: EPCBT_Open */
\r
890 /* Name: Type: Description: */
\r
891 /* fd EPS_FILEDSC I: file discripter */
\r
892 /* pvPortInfo void * I: Port information */
\r
893 /* lpWriteFunc EPS_WritePortal I: Pointer to write function */
\r
894 /* lpReadFunc EPS_ReadPortal I: Pointer to read functiont information */
\r
896 /* Return value: */
\r
897 /* EPCBT_ERR_NONE - Success */
\r
898 /* EPCBT_ERR_CBT2NDOPEN - CBT channels are already opened */
\r
899 /* EPCBT_ERR_MEMORY - Fail to memory allocation */
\r
900 /* EPCBT_ERR_CBTDISABLE - Fail to CBT communication */
\r
901 /* EPCBT_ERR_FATAL - Fatal communication error */
\r
902 /* EPCBT_ERR_INITDENIED - Printer cannot start CBT mode */
\r
903 /* EPCBT_ERR_VERSION - Incompatible version */
\r
904 /* EPCBT_ERR_INITFAILED - Not used by EPSON */
\r
905 /* EPCBT_ERR_UERESULT - Undefined result value */
\r
908 /* Opens the CBT communication */
\r
910 /*******************************************|********************************************/
\r
911 static EPS_INT16 EPCBT_Open (
\r
915 EPS_WritePortal lpWriteFunc,
\r
916 EPS_ReadPortal lpReadFunc
\r
919 EPS_INT16 Ret = EPCBT_ERR_NONE;
\r
924 sprintf(debMsgWork,"EPCBT_Open (S)\r\n");
\r
925 DebMsgOut(debMsgWork);
\r
928 if( gpCbtPrnInfo != NULL) {
\r
929 Ret = EPCBT_ERR_CBT2NDOPEN;
\r
931 Ret = CbtMemAlloc( );
\r
934 if ( Ret == EPCBT_ERR_NONE ) {
\r
935 gpCbtPrnInfo->pPortInfo = pvPortInfo;
\r
936 gpCbtPrnInfo->pCbtWRtnFnc = lpWriteFunc;
\r
937 gpCbtPrnInfo->pCbtRRtnFnc = lpReadFunc;
\r
938 gpCbtPrnInfo->Mode = CBT_MODE_CBTOFF;
\r
940 CbtDummyRead( fd, gpCbtPrnInfo ); /* Dummy read */
\r
941 Ret = CbtEpsonPacking( fd, gpCbtPrnInfo ); /* send EpsonPackingCommand */
\r
942 if ( Ret == EPCBT_ERR_NONE )
\r
943 Ret = CbtInitCommand( fd, gpCbtPrnInfo ); /* send InitCommand */
\r
946 if ( Ret == EPCBT_ERR_NONE ) { /* OK ? */
\r
947 gpCbtPrnInfo->Mode = CBT_MODE_CBTON;
\r
949 if(Ret != EPCBT_ERR_CBT2NDOPEN)
\r
954 if( Ret != EPCBT_ERR_NONE ) {
\r
955 sprintf(debMsgWork," <- CBT_Open Ret[%d]\r\n",Ret);
\r
956 DebMsgOut(debMsgWork);
\r
961 sprintf(debMsgWork,"EPCBT_Open (E)\r\n");
\r
962 DebMsgOut(debMsgWork);
\r
968 /*******************************************|********************************************/
\r
970 /* Function name: EPCBT_Close() */
\r
974 /* Name: Type: Description: */
\r
975 /* fd EPS_FILEDSC I: file discripter */
\r
977 /* Return value: */
\r
978 /* EPCBT_ERR_NONE - Success */
\r
979 /* EPCBT_ERR_CBTNOTOPEN - Port is not open */
\r
980 /* EPCBT_ERR_FATAL - Fatal communication error */
\r
981 /* EPCBT_ERR_CLOSEDENIED - Close Channel is denied */
\r
982 /* EPCBT_ERR_CMDDENIED - Command is denied (Channel is not opened) */
\r
983 /* EPCBT_ERR_UERESULT - Undefined result value */
\r
984 /* EPCBT_ERR_NOREPLY - No reply from printer */
\r
985 /* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
\r
986 /* EPCBT_ERR_UEREPLY - Received reply for a command not issued */
\r
989 /* End CBT mode. */
\r
991 /*******************************************|********************************************/
\r
992 static EPS_INT16 EPCBT_Close (
\r
997 EPS_INT16 Ret = EPCBT_ERR_NONE;
\r
999 CBTS_CHINFO* ChPtr;
\r
1004 sprintf(debMsgWork,"EPCBT_Close (S)\r\n");
\r
1005 DebMsgOut(debMsgWork);
\r
1008 if( gpCbtPrnInfo == NULL) {
\r
1009 Ret = EPCBT_ERR_CBTNOTOPEN;
\r
1011 gpCbtPrnInfo->Mode = CBT_MODE_REQOFF;
\r
1013 for ( lp1 = 1; lp1 < CBT_MAX_CH ; lp1++ ) {
\r
1014 ChPtr = &gpCbtPrnInfo->Chinfo[lp1];
\r
1016 if ( ChPtr->No != 0 ) {
\r
1017 Ret = CbtCloseChannelCommand( fd, gpCbtPrnInfo, ChPtr->No ); /* Channel Close */
\r
1021 for ( lp1 = 0; lp1 < CBT_MAX_CH ; lp1++ ) {
\r
1022 ChPtr = &gpCbtPrnInfo->Chinfo[lp1];
\r
1024 ChPtr->PtSsize = 0;
\r
1025 ChPtr->StPsize = 0;
\r
1026 ChPtr->CreditP = 0;
\r
1027 ChPtr->CreditH = 0;
\r
1028 ChPtr->ReadSize = 0;
\r
1029 ChPtr->RTmpTop = 0;
\r
1030 ChPtr->RTmpEnd = 0;
\r
1031 ChPtr->RTmpCnt = 0;
\r
1034 gpCbtPrnInfo->Mode = CBT_MODE_CBTOFF;
\r
1039 if( Ret != EPCBT_ERR_NONE ) {
\r
1040 sprintf(debMsgWork, " <- CBT_Close Error! Ret[%d]\r\n",Ret);
\r
1041 DebMsgOut(debMsgWork);
\r
1046 sprintf(debMsgWork,"EPCBT_Close (E)\r\n");
\r
1047 DebMsgOut(debMsgWork);
\r
1050 EPS_RETURN( Ret );
\r
1053 /*******************************************|********************************************/
\r
1055 /* Function name: EPCBT_OpenChannel */
\r
1059 /* Name: Type: Description: */
\r
1060 /* fd EPS_FILEDSC I: file discripter */
\r
1061 /* SID EPS_UINT8 I: socket id */
\r
1062 /* bRetry EPS_BOOL I: If TRUE, retry open */
\r
1064 /* Return value: */
\r
1065 /* EPCBT_ERR_NONE - Port is not open */
\r
1066 /* EPCBT_ERR_CBTNOTOPEN - Port is not open */
\r
1067 /* EPCBT_ERR_PARAM - Parameter error */
\r
1068 /* EPCBT_ERR_CH2NDOPEN - Channel is already open */
\r
1069 /* EPCBT_ERR_RPLYPSIZE - Size of packet from OpenChannel is invalid */
\r
1070 /* EPCBT_ERR_FATAL - Fatal communication error */
\r
1071 /* EPCBT_ERR_UERESULT - Undefined result value */
\r
1072 /* EPCBT_ERR_NOREPLY - No reply from printer */
\r
1073 /* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
\r
1074 /* EPCBT_ERR_UEREPLY - Received reply for a command not issued */
\r
1075 /* EPCBT_ERR_RESOURCE - Insufficient printer resources for */
\r
1077 /* EPCBT_ERR_OPENCHANNEL - Not used by EPSON */
\r
1078 /* EPCBT_ERR_CHNOTSUPPORT - The channel is not supported */
\r
1079 /* EPCBT_ERR_PACKETSIZE - Invalid packet size. */
\r
1080 /* (0x0001 ? 0x0005 bytes) */
\r
1081 /* EPCBT_ERR_NULLPACKETSZ - Packet size is 0x0000 in both directions. */
\r
1082 /* No data can be transferred. Channel was */
\r
1085 /* Description: */
\r
1086 /* Opens the CBT communication. */
\r
1088 /*******************************************|********************************************/
\r
1089 static EPS_INT16 EPCBT_OpenChannel (
\r
1096 EPS_INT16 Ret = EPCBT_ERR_NONE;
\r
1097 EPS_UINT32 PtSsize = 0;
\r
1098 EPS_UINT32 StPsize = 0;
\r
1099 EPS_INT32 iCredit = 0;
\r
1100 EPS_INT32 nOpenRetry = 0;
\r
1102 CBTS_CHINFO *ChPtr;
\r
1107 sprintf(debMsgWork,"EPCBT_OpenChannel (S) 0x%02x\r\n", SID);
\r
1108 DebMsgOut(debMsgWork);
\r
1111 if( gpCbtPrnInfo == NULL) {
\r
1112 Ret = EPCBT_ERR_CBTNOTOPEN;
\r
1114 if ( gpCbtPrnInfo->Mode == CBT_MODE_CBTON ) {
\r
1115 if ( (SID == 0x00) || (SID == 0xff) )
\r
1116 Ret = EPCBT_ERR_PARAM;
\r
1118 for ( lp1 = 1; lp1 < CBT_MAX_CH ; lp1++ ) {
\r
1119 ChPtr = &gpCbtPrnInfo->Chinfo[lp1];
\r
1120 if ( ChPtr->No == SID ) { /* channel open ? */
\r
1121 Ret = EPCBT_ERR_CH2NDOPEN;
\r
1125 if ( Ret == EPCBT_ERR_NONE ) {
\r
1126 if ( gpCbtPrnInfo->Chinfo[lp1-1].No != 0 ) /* Over flow */
\r
1127 Ret = EPCBT_ERR_PARAM;
\r
1131 Ret = EPCBT_ERR_CBTNOTOPEN;
\r
1134 if ( Ret == EPCBT_ERR_NONE ) {
\r
1135 if ( SID == CBT_SID_DATA ) {
\r
1136 PtSsize = CBT_TXPSIZE;
\r
1137 StPsize = CBT_RXPSIZE;
\r
1139 PtSsize = CBT_RXPSIZE;
\r
1140 StPsize = CBT_RXPSIZE;
\r
1144 for( ; EPCBT_ERR_RESOURCE == (iCredit = CbtOpenChannelCommand(fd, gpCbtPrnInfo, SID, &PtSsize, &StPsize, 0, 0) )
\r
1145 && nOpenRetry < CBT_OPENCH_RETRY; nOpenRetry++){
\r
1147 serDelayThread(CBT_OPENCH_WAIT, &epsCmnFnc);
\r
1150 iCredit = CbtOpenChannelCommand(fd, gpCbtPrnInfo, SID, &PtSsize, &StPsize, 0, 0);
\r
1153 if ( iCredit < 0 )
\r
1154 Ret = (EPS_INT16)iCredit;
\r
1156 if ( Ret == EPCBT_ERR_NONE ) {
\r
1158 if ( ( PtSsize == 0 ) && ( StPsize == 0 ) )
\r
1159 Ret = EPCBT_ERR_RPLYPSIZE;
\r
1161 if ( (0 < PtSsize) && (PtSsize < 6) )
\r
1162 Ret = EPCBT_ERR_RPLYPSIZE;
\r
1164 if ( (0 < StPsize) && (StPsize < 6) )
\r
1165 Ret = EPCBT_ERR_RPLYPSIZE;
\r
1170 if ( Ret == EPCBT_ERR_NONE ) {
\r
1171 for ( lp1 = 1; ; lp1++ ) {
\r
1172 if ( lp1 >= CBT_MAX_CH ) {
\r
1173 Ret = EPCBT_ERR_PARAM;
\r
1177 ChPtr = &gpCbtPrnInfo->Chinfo[lp1];
\r
1179 if ( ChPtr->No == 0 ) {
\r
1181 ChPtr->PtSsize = (EPS_INT32)PtSsize;
\r
1182 ChPtr->StPsize = (EPS_INT32)StPsize;
\r
1183 ChPtr->CreditP = iCredit;
\r
1184 ChPtr->CreditH = 0;
\r
1185 ChPtr->ReadSize = 0;
\r
1186 ChPtr->RTmpTop = 0;
\r
1187 ChPtr->RTmpEnd = 0;
\r
1188 ChPtr->RTmpCnt = 0;
\r
1189 if ( SID == CBT_SID_CTRL ) {
\r
1190 CbtChDummyRead( fd, gpCbtPrnInfo, ChPtr ); /* Dummy Read */
\r
1198 if( Ret != EPCBT_ERR_NONE ) {
\r
1199 sprintf(debMsgWork, " <- EPCBT_OpenChannel Ret[%d] CH[%x]\r\n", Ret,SID);
\r
1200 DebMsgOut(debMsgWork);
\r
1205 sprintf(debMsgWork,"EPCBT_OpenChannel (E) 0x%02x\r\n", SID);
\r
1206 DebMsgOut(debMsgWork);
\r
1209 EPS_RETURN( Ret );
\r
1212 /*******************************************|********************************************/
\r
1214 /* Function name: EPCBT_CloseChannel() */
\r
1218 /* Name: Type: Description: */
\r
1219 /* fd EPS_FILEDSC I: file discripter */
\r
1220 /* SID EPS_UINT8 I: Socket ID */
\r
1222 /* Return value: */
\r
1223 /* EPCBT_ERR_NONE - Port is not open */
\r
1224 /* EPCBT_ERR_CBTNOTOPEN - Port is not open */
\r
1225 /* EPCBT_ERR_PARAM - Parameter error */
\r
1226 /* EPCBT_ERR_CHNOTOPEN - Channel is not opened */
\r
1227 /* EPCBT_ERR_NONE - Success */
\r
1228 /* EPCBT_ERR_FATAL - Fatal communication error */
\r
1229 /* EPCBT_ERR_CLOSEDENIED - Close Channel is denied */
\r
1230 /* EPCBT_ERR_CMDDENIED - Command is denied (Channel is not opened) */
\r
1231 /* EPCBT_ERR_UERESULT - Undefined result value */
\r
1232 /* EPCBT_ERR_NOREPLY - No reply from printer */
\r
1233 /* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
\r
1234 /* EPCBT_ERR_UEREPLY - Received reply for a command not issued */
\r
1236 /* Description: */
\r
1237 /* Close the communication channel. */
\r
1239 /*******************************************|********************************************/
\r
1240 static EPS_INT16 EPCBT_CloseChannel (
\r
1246 EPS_INT16 Ret = EPCBT_ERR_NONE;
\r
1248 CBTS_CHINFO* ChPtr = NULL;
\r
1253 sprintf(debMsgWork,"EPCBT_CloseChannel (S) 0x%02x\r\n", SID);
\r
1254 DebMsgOut(debMsgWork);
\r
1257 if( gpCbtPrnInfo == NULL) {
\r
1258 Ret = EPCBT_ERR_CBTNOTOPEN;
\r
1260 if ( gpCbtPrnInfo->Mode == CBT_MODE_CBTON ) {
\r
1261 if ( (SID == 0x00) || (SID == 0xff) )
\r
1262 Ret = EPCBT_ERR_PARAM;
\r
1264 for ( lp1 = 1; ; lp1++ ) {
\r
1265 if ( lp1 >= CBT_MAX_CH ) {
\r
1266 Ret = EPCBT_ERR_CHNOTOPEN;
\r
1269 ChPtr = &gpCbtPrnInfo->Chinfo[lp1];
\r
1270 if ( ChPtr->No == SID )
\r
1275 EPS_RETURN( Ret ); /* return normal end */
\r
1278 if ( Ret == EPCBT_ERR_NONE ) {
\r
1279 Ret = CbtCloseChannelCommand( fd, gpCbtPrnInfo, SID );
\r
1280 /*if ( Ret == EPCBT_ERR_NONE ) { Force reset */
\r
1282 ChPtr->PtSsize = 0;
\r
1283 ChPtr->StPsize = 0;
\r
1284 ChPtr->CreditP = 0;
\r
1285 ChPtr->CreditH = 0;
\r
1286 ChPtr->ReadSize = 0;
\r
1287 ChPtr->RTmpTop = 0;
\r
1288 ChPtr->RTmpEnd = 0;
\r
1289 ChPtr->RTmpCnt = 0;
\r
1290 /*} Force reset */
\r
1294 if( Ret != EPCBT_ERR_NONE ) {
\r
1295 sprintf(debMsgWork, " <- CBT_CloseChannel Ret[%d] CH[%x]\r\n",Ret,SID);
\r
1296 DebMsgOut(debMsgWork);
\r
1301 sprintf(debMsgWork,"EPCBT_CloseChannel (E) 0x%02x\r\n", SID);
\r
1302 DebMsgOut(debMsgWork);
\r
1305 EPS_RETURN( Ret );
\r
1308 /*******************************************|********************************************/
\r
1310 /* Function name: EPCBT_Write() */
\r
1314 /* Name: Type: Description: */
\r
1315 /* fd EPS_FILEDSC I: file discripter */
\r
1316 /* SID EPS_UINT8 I: Channel-Select */
\r
1317 /* lpBuffer const EPS_UINT8* I: Buffer Pointer for Write Data */
\r
1318 /* lpSize EPS_INT32* O: Write Data Buffer Length (bytes) */
\r
1320 /* Return value: */
\r
1321 /* EPCBT_ERR_NONE - Success */
\r
1322 /* EPCBT_ERR_CBTNOTOPEN - CBT is not opened */
\r
1323 /* EPSCBT_ERR_PARAM - Parameter error */
\r
1324 /* EPCBT_ERR_CHNOTOPEN - Channel is not opened */
\r
1325 /* EPCBT_ERR_FNCDISABLE - Function is disable to be completely finished */
\r
1326 /* EPCBT_ERR_FATAL - Fatal communication error */
\r
1327 /* EPCBT_ERR_CMDDENIED - Command is denied (Channel is not opened) */
\r
1328 /* EPCBT_ERR_UERESULT - Undefined result value */
\r
1329 /* EPCBT_ERR_WRITEERROR - Failed to write */
\r
1331 /* Description: */
\r
1332 /* Write the data to printer. */
\r
1334 /*******************************************|********************************************/
\r
1335 static EPS_INT16 EPCBT_Write (
\r
1339 const EPS_UINT8* lpBuffer,
\r
1343 EPS_INT16 Ret = EPCBT_ERR_NONE;
\r
1348 EPS_INT32 loopSize;
\r
1349 EPS_INT32 SendMaxSize;
\r
1350 CBTS_CHINFO* ChPtr = NULL;
\r
1355 sprintf(debMsgWork,"EPCBT_Write (S) 0x%02x(%04d)\r\n", SID, *lpSize);
\r
1356 DebMsgOut(debMsgWork);
\r
1359 if( gpCbtPrnInfo == NULL) {
\r
1360 Ret = EPCBT_ERR_CBTNOTOPEN;
\r
1362 if ( gpCbtPrnInfo->Mode == CBT_MODE_CBTON ) {
\r
1363 if ( (SID == 0x00) || (SID == 0xff) ) {
\r
1364 Ret = EPCBT_ERR_PARAM;
\r
1366 for ( lp1 = 1; ; lp1++ ) {
\r
1367 if ( lp1 >= CBT_MAX_CH ) {
\r
1368 Ret = EPCBT_ERR_CHNOTOPEN;
\r
1371 ChPtr = &gpCbtPrnInfo->Chinfo[lp1];
\r
1372 if ( ChPtr->No == SID )
\r
1377 Ret = EPCBT_ERR_CBTNOTOPEN;
\r
1380 if ( Ret == EPCBT_ERR_NONE ) {
\r
1381 if( (ChPtr->PtSsize - 6) < *lpSize)
\r
1382 SendMaxSize = ChPtr->PtSsize - 6;
\r
1384 SendMaxSize = *lpSize;
\r
1385 loopSize = *lpSize;
\r
1389 if ( ChPtr->CreditP == 0 ) {
\r
1390 Credit = CbtCreditReqCommand(fd, gpCbtPrnInfo, SID, CBT_CREDIT_LPT, 0xffff);
\r
1392 Ret = (EPS_INT16)Credit;
\r
1393 else if ( Credit == 0 )
\r
1394 Ret = EPCBT_ERR_FNCDISABLE;
\r
1396 ChPtr->CreditP = Credit;
\r
1399 if ( Ret != EPCBT_ERR_NONE )
\r
1402 if(SendMaxSize < loopSize)
\r
1403 Size = SendMaxSize;
\r
1406 Count = CbtDataWrite( fd, gpCbtPrnInfo, SID, &lpBuffer[*lpSize], Size );
\r
1407 ChPtr->CreditP -= 1;
\r
1408 if ( Count >= 0 ) {
\r
1410 loopSize -= Count;
\r
1412 Ret = (EPS_INT16)Count;
\r
1419 if( Ret != EPCBT_ERR_NONE ) {
\r
1420 sprintf(debMsgWork, " <- CBT_Write Ret[%d] CH[%x] Size[%d]\r\n",Ret,SID,*lpSize);
\r
1421 DebMsgOut(debMsgWork);
\r
1426 sprintf(debMsgWork,"EPCBT_Write (E) 0x%02x(%04d)\r\n", SID, *lpSize);
\r
1427 DebMsgOut(debMsgWork);
\r
1430 EPS_RETURN( Ret );
\r
1433 /*******************************************|********************************************/
\r
1435 /* Function name: EPCBT_Read */
\r
1439 /* Name: Type: Description: */
\r
1440 /* fd EPS_FILEDSC I: file discripter */
\r
1441 /* SID EPS_UINT8 I: Socket ID */
\r
1442 /* lpBuffer EPS_UINT8* O: Pointer to buffer for read data */
\r
1443 /* lpSize EPS_INT32* O: Pointer to variable for read data size */
\r
1445 /* Return value: */
\r
1446 /* EPCBT_ERR_NONE - Success */
\r
1447 /* EPCBT_ERR_CBTNOTOPEN - CBT is not opened */
\r
1448 /* EPCBT_ERR_PARAM - Parameter error */
\r
1449 /* EPCBT_ERR_CHNOTOPEN - Channel is not opened */
\r
1450 /* EPCBT_ERR_FATAL - Fatal communication error */
\r
1451 /* EPCBT_ERR_CREDITOVF - Credit over flow */
\r
1452 /* EPCBT_ERR_CMDDENIED - Command is denied (Channel is not opened) */
\r
1453 /* EPCBT_ERR_UERESULT - Undefined result value */
\r
1454 /* EPCBT_ERR_NOREPLY - No reply from printer */
\r
1455 /* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
\r
1456 /* EPCBT_ERR_UEREPLY - Received reply for a command not issued */
\r
1457 /* EPCBT_ERR_READERROR - Data read error */
\r
1459 /* Description: */
\r
1460 /* Receive the data from printer. */
\r
1462 /*******************************************|********************************************/
\r
1463 static EPS_INT16 EPCBT_Read (
\r
1467 EPS_UINT8* lpBuffer,
\r
1471 EPS_INT16 Ret = EPCBT_ERR_NONE;
\r
1472 EPS_INT32 Size = 0;
\r
1474 CBTS_CHINFO* ChPtr = NULL;
\r
1479 sprintf(debMsgWork,"EPCBT_Read (S) 0x%02x(%04d)\r\n", SID, *lpSize);
\r
1480 DebMsgOut(debMsgWork);
\r
1483 if( gpCbtPrnInfo == NULL) {
\r
1484 Ret = EPCBT_ERR_CBTNOTOPEN;
\r
1486 if ( gpCbtPrnInfo->Mode == CBT_MODE_CBTON ) {
\r
1487 if ( (SID == 0x00) || (SID == 0xff) ) {
\r
1488 Ret = EPCBT_ERR_PARAM;
\r
1490 for ( lp1 = 1; ; lp1++ ) {
\r
1491 if ( lp1 >= CBT_MAX_CH ) {
\r
1492 Ret = EPCBT_ERR_CHNOTOPEN;
\r
1495 ChPtr = &gpCbtPrnInfo->Chinfo[lp1];
\r
1496 if ( ChPtr->No == SID )
\r
1501 Ret = EPCBT_ERR_CBTNOTOPEN;
\r
1504 if ( Ret == EPCBT_ERR_NONE ) {
\r
1505 if ( lpBuffer == NULL ) {
\r
1506 if ( ChPtr->CreditH == 0 ) {
\r
1507 Ret = CbtCreditCommand( fd, gpCbtPrnInfo, SID, 1 );
\r
1508 if ( Ret == EPCBT_ERR_NONE )
\r
1509 ChPtr->CreditH += 1;
\r
1511 if ( Ret == EPCBT_ERR_NONE ) {
\r
1512 Ret = CbtDataRead( fd, gpCbtPrnInfo, SID, NULL, &Size );
\r
1517 Ret = CbtDataRead( fd, gpCbtPrnInfo, SID, lpBuffer, &Size );
\r
1523 if( Ret != EPCBT_ERR_NONE ) {
\r
1524 sprintf(debMsgWork, " <- CBT_Read Ret[%d] CH[%x] Size[%d]\r\n",Ret,SID,*lpSize);
\r
1525 DebMsgOut(debMsgWork);
\r
1530 sprintf(debMsgWork,"EPCBT_Read (E) 0x%02x(%04d)\r\n", SID, *lpSize);
\r
1531 DebMsgOut(debMsgWork);
\r
1534 EPS_RETURN( Ret );
\r
1537 /*******************************************|********************************************/
\r
1539 /* Function name: EPCBT_GetSocketID */
\r
1543 /* Name: Type: Description: */
\r
1544 /* fd EPS_FILEDSC I: file discripter */
\r
1545 /* pSID EPS_UINT8 * I: Socket ID */
\r
1546 /* pName EPS_UINT8 * I: Parameter Name */
\r
1547 /* Size EPS_INT32 I: Size of socket ID */
\r
1549 /* Return value: */
\r
1550 /* EPCBT_ERR_NONE - Success */
\r
1551 /* EPCBT_ERR_CBTNOTOPEN - Port is not open */
\r
1552 /* EPCBT_ERR_PARAM - Parameter error */
\r
1553 /* EPCBT_ERR_FATAL - Fatal communication error */
\r
1554 /* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
\r
1555 /* EPCBT_ERR_NOSERVICE - The channel does not support the requested */
\r
1557 /* EPCBT_ERR_UERESULT - Undefined result value */
\r
1559 /* Description: */
\r
1560 /* Gets the socket ID. */
\r
1562 /*******************************************|********************************************/
\r
1563 #if LCOMSW_CBT_SOCKETFUNC_ON
\r
1564 static EPS_INT16 EPCBT_GetSocketID (
\r
1572 EPS_INT16 Ret = EPCBT_ERR_NONE;
\r
1573 EPS_UINT8 SocketID = 0;
\r
1578 sprintf(debMsgWork,"EPCBT_GetSocketID (S)\r\n");
\r
1579 DebMsgOut(debMsgWork);
\r
1582 if( gpCbtPrnInfo == NULL) {
\r
1583 Ret = EPCBT_ERR_CBTNOTOPEN;
\r
1585 if ( gpCbtPrnInfo->Mode == CBT_MODE_CBTON ) {
\r
1586 if ( (pSID == NULL) || (pName == NULL) ) {
\r
1587 Ret = EPCBT_ERR_PARAM;
\r
1590 Ret = EPCBT_ERR_CBTNOTOPEN;
\r
1593 if ( Ret == EPCBT_ERR_NONE ) {
\r
1594 Ret = CbtGetSocketIDCommand( fd, gpCbtPrnInfo, pName, Size, &SocketID );
\r
1595 if ( Ret == EPCBT_ERR_NONE )
\r
1600 if( Ret != EPCBT_ERR_NONE ) {
\r
1601 sprintf(debMsgWork, " <- CBT_GetSocketID Ret[%d] SID[%02x]\r\n", Ret,*pSID);
\r
1602 DebMsgOut(debMsgWork);
\r
1607 sprintf(debMsgWork,"EPCBT_GetSocketID (E)\r\n");
\r
1608 DebMsgOut(debMsgWork);
\r
1611 EPS_RETURN( Ret );
\r
1613 #endif /* def LCOMSW_CBT_SOCKETFUNC_ON */
\r
1615 /*******************************************|********************************************/
\r
1617 /* Function name: CbtWriteRtn */
\r
1621 /* Name: Type: Description: */
\r
1622 /* fd EPS_FILEDSC I: file discripter */
\r
1623 /* pCbtPrnInfo CBTS_PRNINFO* I: Printer information */
\r
1624 /* Buff const EPS_UINT8* I: Pointer to the write data buffer */
\r
1625 /* BuffLen EPS_INT32 I: Size of the write data buffer */
\r
1626 /* Cnt EPS_INT32* O: Write data size */
\r
1628 /* Return value: */
\r
1629 /* EPCBT_ERR_NONE - Success */
\r
1630 /* EPCBT_ERR_WRITEERROR - Write error */
\r
1632 /* Description: */
\r
1633 /* Sends the data to the printer. */
\r
1635 /*******************************************|********************************************/
\r
1636 static EPS_INT16 CbtWriteRtn (
\r
1639 CBTS_PRNINFO* pCbtPrnInfo,
\r
1640 const EPS_UINT8* Buff,
\r
1641 EPS_INT32 BuffLen,
\r
1652 Ans = ( pCbtPrnInfo->pCbtWRtnFnc )( fd, (EPS_UINT8 *)Buff, BuffLen, Cnt );
\r
1655 sprintf(debMsgWork," * Write * Size=%4d(%4d) Data= ",BuffLen, *Cnt);
\r
1656 DebMsgOut(debMsgWork);
\r
1657 for (lp1 = 0; (lp1 < *Cnt); lp1++) {
\r
1658 sprintf(debMsgWork,"%02X ",Buff[lp1]);
\r
1659 DebMsgOut(debMsgWork);
\r
1661 DebMsgOut("\r\n");
\r
1665 EPS_RETURN( EPCBT_ERR_NONE );
\r
1667 EPS_RETURN( EPCBT_ERR_WRITEERROR );
\r
1671 /*******************************************|********************************************/
\r
1673 /* Function name: CbtReadRtn */
\r
1677 /* Name: Type: Description: */
\r
1678 /* fd EPS_FILEDSC I: file discripter */
\r
1679 /* pCbtPrnInfo CBTS_PRNINFO* I: Printer information */
\r
1680 /* SID EPS_UINT8 I: Socket ID */
\r
1681 /* lpBuffer EPS_UINT8* I: Pointer to the receive data buffer */
\r
1682 /* BuffSize EPS_INT32 I: Receive data buffer size */
\r
1683 /* Cnt EPS_INT32 * O: Receive data size */
\r
1684 /* DummyRead EPS_UINT8 I: Flag for the dummy read */
\r
1686 /* Return value: */
\r
1687 /* EPCBT_ERR_NONE - Success */
\r
1688 /* EPCBT_ERR_PARAM - Parameter error */
\r
1689 /* EPCBT_ERR_READERROR - Read data error */
\r
1690 /* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
\r
1691 /* EPCBT_ERR_UERESULT - Undefined result value */
\r
1693 /* Description: */
\r
1694 /* Recives the data from printer. */
\r
1696 /*******************************************|********************************************/
\r
1697 static EPS_INT16 CbtReadRtn (
\r
1700 CBTS_PRNINFO* pCbtPrnInfo,
\r
1702 EPS_UINT8* lpBuffer,
\r
1703 EPS_INT32 BuffSize,
\r
1705 EPS_UINT8 DummyRead
\r
1708 EPS_INT16 Ret = EPCBT_ERR_NONE;
\r
1710 EPS_INT32 Count = 0;
\r
1712 EPS_INT32 PSize = 0;
\r
1715 CBTS_CHINFO *ChSer = NULL;
\r
1716 CBTS_CHINFO *ChPtr = NULL;
\r
1717 EPS_UINT8 *wRBuff;
\r
1718 EPS_INT32 nDlySpan = 10; /* first 10 ms */
\r
1719 EPS_INT32 nDlyTotal = 2000; /* total 2000 ms */
\r
1723 wRBuff = pCbtPrnInfo->pCbtReadRtnBuff;
\r
1724 if ( DummyRead == CBT_READ_DMY ) {
\r
1725 Ans = ( pCbtPrnInfo->pCbtRRtnFnc )( fd, wRBuff, CBT_MAX_RTMP, &Count );
\r
1729 Ret = EPCBT_ERR_READERROR;
\r
1732 sprintf(debMsgWork," * Read * Size=%4d(%4d) Data= ",CBT_MAX_RTMP, Count);
\r
1733 DebMsgOut(debMsgWork);
\r
1734 for (lp1 = 0; (lp1 < Count); lp1++) {
\r
1735 sprintf(debMsgWork,"%02X ",wRBuff[lp1]);
\r
1736 DebMsgOut(debMsgWork);
\r
1738 DebMsgOut("\r\n");
\r
1741 #ifdef CBT_DBG_READ
\r
1742 sprintf(debMsgWork,"<CBT Dummy CbtReadRtn> Req-SID[%02x] Size[%d]\r\n",SID, *Cnt);
\r
1743 DebMsgOut(debMsgWork);
\r
1744 for (lp1 = 0; lp1 < *Cnt; lp1++) {
\r
1745 sprintf(debMsgWork,"%02X ",wRBuff[lp1]);
\r
1746 DebMsgOut(debMsgWork);
\r
1748 DebMsgOut("\r\n");
\r
1750 EPS_RETURN( Ret );
\r
1754 for ( lp1 = 0; ; lp1++ ) {
\r
1755 if ( lp1 >= CBT_MAX_CH ){
\r
1756 EPS_RETURN( EPCBT_ERR_PARAM );
\r
1759 ChSer = &pCbtPrnInfo->Chinfo[lp1];
\r
1760 if ( ChSer->No == SID )
\r
1764 while(nDlyTotal > 0){
\r
1765 if ( ChSer->RTmpCnt > 0 ) {
\r
1766 PSize = ChSer->RTmpBuff[(ChSer->RTmpTop+3) % CBT_MAX_RTMP]
\r
1767 + (ChSer->RTmpBuff[(ChSer->RTmpTop+2) % CBT_MAX_RTMP] << 8);
\r
1769 if ( BuffSize < PSize ) {
\r
1770 Ret = EPCBT_ERR_PARAM;
\r
1773 for ( lp1 = 0; lp1 < PSize; lp1++ ) {
\r
1774 lpBuffer[lp1] = ChSer->RTmpBuff[ChSer->RTmpTop];
\r
1775 ChSer->RTmpTop = (ChSer->RTmpTop+1) % CBT_MAX_RTMP;
\r
1776 ChSer->RTmpCnt = (ChSer->RTmpCnt-1);
\r
1783 Ans = ( pCbtPrnInfo->pCbtRRtnFnc )( fd, wRBuff, CBT_MAX_RTMP, &Count );
\r
1786 sprintf(debMsgWork," * Read * Size=%4d(%4d) Data= ",CBT_MAX_RTMP, Count);
\r
1787 DebMsgOut(debMsgWork);
\r
1788 for (lp1 = 0; (lp1 < Count); lp1++) {
\r
1789 sprintf(debMsgWork,"%02X ",wRBuff[lp1]);
\r
1790 DebMsgOut(debMsgWork);
\r
1792 DebMsgOut("\r\n");
\r
1795 if ( Count != 0 ) {
\r
1798 PSize = wRBuff[Top+3] + (wRBuff[Top+2] << 8);
\r
1799 if ( ( Count - Top < 4 ) || ( PSize == 0 ) || ( PSize > Count - Top ) ) {
\r
1800 Ret = EPCBT_ERR_MULFORMEDPACKET;
\r
1803 RxSID = wRBuff[Top];
\r
1805 for ( lp1 = 0; ; lp1++ ) {
\r
1806 if ( lp1 >= CBT_MAX_CH ) {
\r
1807 Ret = EPCBT_ERR_UEREPLY;
\r
1810 ChPtr = &pCbtPrnInfo->Chinfo[lp1];
\r
1812 /* Match channel ? */
\r
1813 if ( ChPtr->No == RxSID )
\r
1817 if ( Ret == EPCBT_ERR_NONE ) {
\r
1819 ChPtr->CreditH -= 1;
\r
1821 for ( lp1 = 0; lp1 < PSize; lp1++ ) {
\r
1822 ChPtr->RTmpBuff[ChPtr->RTmpEnd] = wRBuff[Top+lp1];
\r
1823 ChPtr->RTmpEnd = (ChPtr->RTmpEnd+1) % CBT_MAX_RTMP;
\r
1824 ChPtr->RTmpCnt = (ChPtr->RTmpCnt+1);
\r
1828 if ( Top >= Count )
\r
1837 Ret = EPCBT_ERR_READERROR;
\r
1843 serDelayThread(nDlySpan, &epsCmnFnc);
\r
1845 nDlyTotal -= nDlySpan;
\r
1846 if(nDlySpan < 200){
\r
1847 nDlySpan += nDlySpan/2;
\r
1848 if(nDlySpan > 200){
\r
1849 nDlySpan = 200; /* max 200ms */
\r
1854 if ( nDlyTotal < 0 )
\r
1855 Ret = EPCBT_ERR_READERROR;
\r
1857 #ifdef CBT_DBG_READ
\r
1858 sprintf(debMsgWork,"<CBT CbtReadRtn> Req-SID[%02x] Size[%d]\r\n",SID, *Cnt);
\r
1859 DebMsgOut(debMsgWork);
\r
1860 for (lp1 = 0; lp1 < *Cnt; lp1++) {
\r
1861 sprintf(debMsgWork,"%02X ",lpBuffer[lp1]);
\r
1862 DebMsgOut(debMsgWork);
\r
1864 DebMsgOut("\r\n");
\r
1867 EPS_RETURN( Ret );
\r
1870 /*******************************************|********************************************/
\r
1872 /* Function name: CbtDummyRead */
\r
1876 /* Name: Type: Description: */
\r
1877 /* fd EPS_FILEDSC I: file discripter */
\r
1878 /* pCbtPrnInfo CBTS_PRNINFO* I: Printer information */
\r
1880 /* Return value: */
\r
1883 /* Description: */
\r
1884 /* Try to read data from printer. */
\r
1886 /*******************************************|********************************************/
\r
1887 static void CbtDummyRead (
\r
1890 CBTS_PRNINFO* pCbtPrnInfo
\r
1894 EPS_INT32 Cnt = 0;
\r
1898 for ( i = 0; i < CBT_DUMYREAD_MAX ;i++ ) {
\r
1899 if ( CbtReadRtn( fd, pCbtPrnInfo, CBT_SID_MAIN, NULL, 0, &Cnt, CBT_READ_DMY ) == EPCBT_ERR_NONE ) {
\r
1910 /*******************************************|********************************************/
\r
1912 /* Function name: CbtChDummyRead */
\r
1916 /* Name: Type: Description: */
\r
1917 /* fd EPS_FILEDSC I: file discripter */
\r
1918 /* pCbtPrnInfo CBTS_PRNINFO* I: Printer information */
\r
1919 /* ChPtr CBTS_CHINFO* I: Channel */
\r
1921 /* Return value: */
\r
1924 /* Description: */
\r
1925 /* Try to read by using <ChPtr>. */
\r
1927 /*******************************************|********************************************/
\r
1928 static void CbtChDummyRead (
\r
1931 CBTS_PRNINFO* pCbtPrnInfo,
\r
1932 CBTS_CHINFO* ChPtr
\r
1942 if ( ChPtr->CreditH == 0 ) {
\r
1943 Ret = CbtCreditCommand( fd, pCbtPrnInfo, ChPtr->No, 1 );
\r
1944 if ( Ret == EPCBT_ERR_NONE )
\r
1945 ChPtr->CreditH += 1;
\r
1949 Ret = CbtReadRtn( fd, pCbtPrnInfo, ChPtr->No, NULL, 0, &Size, CBT_READ_DMY );
\r
1951 ChPtr->CreditH -= 1;
\r
1953 } while(Size > 0);
\r
1958 /*******************************************|********************************************/
\r
1960 /* Function name: CbtReplyCheck */
\r
1964 /* Name: Type: Description: */
\r
1965 /* Reply EPS_UINT8* I: Reply data */
\r
1966 /* ReplySz EPS_INT32 I: Reply data size */
\r
1967 /* RpyType EPS_UINT8 I: Reply data type */
\r
1969 /* Return value: */
\r
1970 /* EPCBT_ERR_NONE - Success */
\r
1971 /* EPCBT_ERR_NOREPLY - No reply from printer */
\r
1972 /* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
\r
1973 /* EPCBT_ERR_UEREPLY - Received reply for a command not issued */
\r
1975 /* Description: */
\r
1976 /* Checks the CBT command replys. */
\r
1978 /*******************************************|********************************************/
\r
1979 static EPS_INT16 CbtReplyCheck (
\r
1982 EPS_INT32 ReplySz,
\r
1986 EPS_INT16 Ret = EPCBT_ERR_NONE;
\r
1990 if ( ReplySz == 0 ){
\r
1991 EPS_RETURN( EPCBT_ERR_NOREPLY );
\r
1994 if( ( Reply[0] != 0x00 ) || ( Reply[1] != 0x00 ) || ( Reply[2] != 0x00 ) ){
\r
1995 EPS_RETURN( EPCBT_ERR_MULFORMEDPACKET );
\r
1998 switch ( Reply[6] ){
\r
1999 case CBT_RPY_INIT:
\r
2000 if (Reply[3] != CBT_RPY_SIZE_INIT)
\r
2001 Ret = EPCBT_ERR_MULFORMEDPACKET;
\r
2002 else if ( RpyType != CBT_CMD_INIT )
\r
2003 Ret = EPCBT_ERR_UEREPLY;
\r
2006 case CBT_RPY_OPENCHANNEL:
\r
2007 if (Reply[3] != CBT_RPY_SIZE_OPENCHANNEL)
\r
2008 Ret = EPCBT_ERR_MULFORMEDPACKET;
\r
2009 else if ( RpyType != CBT_CMD_OPENCHANNEL )
\r
2010 Ret = EPCBT_ERR_UEREPLY;
\r
2013 case CBT_RPY_CLOSECHANNEL:
\r
2014 if (Reply[3] != CBT_RPY_SIZE_CLOSECHANNEL)
\r
2015 Ret = EPCBT_ERR_MULFORMEDPACKET;
\r
2016 else if ( RpyType != CBT_CMD_CLOSECHANNEL )
\r
2017 Ret = EPCBT_ERR_UEREPLY;
\r
2020 case CBT_RPY_CREDIT:
\r
2021 if (Reply[3] != CBT_RPY_SIZE_CREDIT)
\r
2022 Ret = EPCBT_ERR_MULFORMEDPACKET;
\r
2023 else if ( RpyType != CBT_CMD_CREDIT )
\r
2024 Ret = EPCBT_ERR_UEREPLY;
\r
2027 case CBT_RPY_CREDITREQUEST:
\r
2028 if (Reply[3] != CBT_RPY_SIZE_CREDITREQUEST)
\r
2029 Ret = EPCBT_ERR_MULFORMEDPACKET;
\r
2030 else if ( RpyType != CBT_CMD_CREDITREQUEST )
\r
2031 Ret = EPCBT_ERR_UEREPLY;
\r
2034 case CBT_RPY_DEBIT:
\r
2035 case CBT_RPY_DEBITREQUEST:
\r
2036 case CBT_RPY_CONFIGSOCKET:
\r
2039 case CBT_RPY_EXIT:
\r
2040 if (Reply[3] != CBT_RPY_SIZE_EXIT)
\r
2041 Ret = EPCBT_ERR_MULFORMEDPACKET;
\r
2042 else if ( RpyType != CBT_CMD_EXIT )
\r
2043 Ret = EPCBT_ERR_UEREPLY;
\r
2046 case CBT_RPY_GETSOCKETID:
\r
2047 if ( RpyType != CBT_CMD_GETSOCKETID )
\r
2048 Ret = EPCBT_ERR_UEREPLY;
\r
2051 case CBT_RPY_GETSERVICENAME:
\r
2054 case CBT_RPY_EPSONPACKING:
\r
2055 if (Reply[3] != CBT_RPY_SIZE_EPSONPACKING)
\r
2056 Ret = EPCBT_ERR_MULFORMEDPACKET;
\r
2057 else if ( RpyType != CBT_CMD_EPSONPACKING )
\r
2058 Ret = EPCBT_ERR_UEREPLY;
\r
2062 Ret = EPCBT_ERR_MULFORMEDPACKET;
\r
2065 EPS_RETURN( Ret );
\r
2068 /*******************************************|********************************************/
\r
2070 /* Function name: CbtEpsonPacking */
\r
2074 /* Name: Type: Description: */
\r
2075 /* fd EPS_FILEDSC I: file discripter */
\r
2076 /* pCbtPrnInfo CBTS_PRNINFO* I: Printer information */
\r
2078 /* Return value: */
\r
2079 /* EPCBT_ERR_NONE - Success */
\r
2080 /* EPCBT_ERR_CBTDISABLE - Fail to CBT communication */
\r
2082 /* Description: */
\r
2083 /* Sends EpsonPackingCommand and receives reply. */
\r
2085 /*******************************************|********************************************/
\r
2086 static EPS_INT16 CbtEpsonPacking (
\r
2089 CBTS_PRNINFO* pCbtPrnInfo
\r
2092 EPS_INT16 Ret = EPCBT_ERR_NONE;
\r
2094 EPS_INT32 Cnt = 0;
\r
2095 EPS_INT32 BuffLen = CBT_CMD_SIZE_EPSONPACKING;
\r
2096 EPS_INT32 RSize = 0;
\r
2097 static const EPS_UINT8 Buff[] = {
\r
2098 0x00,0x00,0x00,0x1b,0x01,0x40,0x45,0x4a,0x4c,0x20,
\r
2099 0x31,0x32,0x38,0x34,0x2e,0x34,0x0a,0x40,0x45,0x4a,
\r
2100 0x4c,0x0a,0x40,0x45,0x4a,0x4c,0x0a
\r
2102 EPS_UINT8 RBuff[CBT_CMDREPLY_BUFFSZ];
\r
2106 memset(RBuff, 0, CBT_CMDREPLY_BUFFSZ);
\r
2108 Ans = CbtWriteRtn( fd, pCbtPrnInfo, Buff, BuffLen, &Cnt );
\r
2109 if ( Ans != EPCBT_ERR_NONE )
\r
2110 Ret = EPCBT_ERR_CBTDISABLE;
\r
2112 if ( Cnt != BuffLen )
\r
2113 Ret = EPCBT_ERR_CBTDISABLE;
\r
2116 if ( Ret != EPCBT_ERR_NONE ){
\r
2117 EPS_RETURN( Ret ); /* return error end */
\r
2120 Ans = CbtReadRtn( fd, pCbtPrnInfo, CBT_SID_MAIN, RBuff, CBT_CMDREPLY_BUFFSZ, &RSize, CBT_READ_NORMAL );
\r
2121 if ( Ans != EPCBT_ERR_NONE )
\r
2122 Ret = EPCBT_ERR_CBTDISABLE; /* no receive */
\r
2124 Ret = CbtReplyCheck( RBuff, RSize, CBT_CMD_EPSONPACKING );
\r
2125 if ( Ret == EPCBT_ERR_NONE ) {
\r
2126 if( ( RBuff[7] != 0x00 ) && ( RBuff[7] != 0x02 ) )
\r
2127 Ret = EPCBT_ERR_CBTDISABLE;
\r
2131 EPS_RETURN( Ret );
\r
2134 /*******************************************|********************************************/
\r
2136 /* Function name: CbtInitCommand */
\r
2140 /* Name: Type: Description: */
\r
2141 /* fd EPS_FILEDSC I: file discripter */
\r
2142 /* pCbtPrnInfo CBTS_PRNINFO* I: Printer information */
\r
2144 /* Return value: */
\r
2145 /* EPCBT_ERR_NONE - Success */
\r
2146 /* EPCBT_ERR_FATAL - Fatal communication error */
\r
2147 /* EPCBT_ERR_INITDENIED - Printer cannot start CBT mode */
\r
2148 /* EPCBT_ERR_VERSION - Incompatible version */
\r
2149 /* EPCBT_ERR_UERESULT - Undefined result value */
\r
2151 /* Description: */
\r
2152 /* Sends init command and receives reply. */
\r
2154 /*******************************************|********************************************/
\r
2155 static EPS_INT16 CbtInitCommand (
\r
2158 CBTS_PRNINFO* pCbtPrnInfo
\r
2161 EPS_INT16 Ret = EPCBT_ERR_NONE;
\r
2163 EPS_INT32 Cnt = 0;
\r
2164 EPS_INT32 BuffLen = CBT_CMD_SIZE_INIT;
\r
2165 EPS_INT32 RSize = 0;
\r
2166 static const EPS_UINT8 Buff[] = {0x00,0x00,0x00,CBT_CMD_SIZE_INIT,0x01,0x00,0x00,0x10};
\r
2167 EPS_UINT8 RBuff[CBT_CMDREPLY_BUFFSZ];
\r
2171 memset(RBuff, 0, CBT_CMDREPLY_BUFFSZ);
\r
2173 Ans = CbtWriteRtn( fd, pCbtPrnInfo, Buff, BuffLen, &Cnt );
\r
2174 if ( Ans != EPCBT_ERR_NONE )
\r
2175 Ret = EPCBT_ERR_FATAL;
\r
2177 if ( Cnt != BuffLen )
\r
2178 Ret = EPCBT_ERR_FATAL;
\r
2181 if ( Ret != EPCBT_ERR_NONE )
\r
2182 EPS_RETURN( Ret ); /* return error end */
\r
2184 Ans = CbtReadRtn( fd, pCbtPrnInfo, CBT_SID_MAIN, RBuff, CBT_CMDREPLY_BUFFSZ, &RSize, CBT_READ_NORMAL );
\r
2185 if ( Ans != EPCBT_ERR_NONE )
\r
2186 Ret = EPCBT_ERR_FATAL; /* No receive */
\r
2188 Ret = CbtReplyCheck( RBuff, RSize, CBT_CMD_INIT );
\r
2189 if ( Ret == EPCBT_ERR_NONE ) {
\r
2190 if ( RBuff[7] != 0x00 ) {
\r
2191 if ( RBuff[7] == 0x01 )
\r
2192 Ret = EPCBT_ERR_INITDENIED;
\r
2193 else if ( RBuff[7] == 0x02 )
\r
2194 Ret = EPCBT_ERR_VERSION;
\r
2195 else if ( RBuff[7] == 0x0b )
\r
2196 Ret = EPCBT_ERR_INITFAILED;
\r
2198 Ret = EPCBT_ERR_UERESULT;
\r
2203 EPS_RETURN( Ret );
\r
2207 /*******************************************|********************************************/
\r
2209 /* Function name: CbtOpenChannelCommand() */
\r
2213 /* Name: Type: Description: */
\r
2214 /* fd EPS_FILEDSC I: file discripter */
\r
2215 /* pCbtPrnInfo CBTS_PRNINFO* I: Port information */
\r
2216 /* SID EPS_UINT8 I: Socket ID */
\r
2217 /* pPtSsz EPS_INT32* O: Primary to secondary packet size */
\r
2218 /* pStPsz EPS_INT32* O: Secondary to primary packet size */
\r
2219 /* CreditReq EPS_INT32 I: Credit Requested */
\r
2220 /* CreditMax EPS_INT32 I: Maximum Outstanding Credit */
\r
2222 /* Return value: */
\r
2223 /* Credit number - Data packet number that is able to recieve */
\r
2224 /* by throughing <SID>. */
\r
2225 /* EPCBT_ERR_FATAL - Fatal communication error */
\r
2226 /* EPCBT_ERR_UERESULT - Undefined result value */
\r
2227 /* EPCBT_ERR_NOREPLY - No reply from printer */
\r
2228 /* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
\r
2229 /* EPCBT_ERR_UEREPLY - Received reply for a command not issued */
\r
2230 /* EPCBT_ERR_RESOURCE - Insufficient printer resources for OpenChannel*/
\r
2231 /* EPCBT_ERR_OPENCHANNEL - Not used by EPSON */
\r
2232 /* EPCBT_ERR_CHNOTSUPPORT - The channel is not supported */
\r
2233 /* EPCBT_ERR_PACKETSIZE - Invalid packet size. */
\r
2234 /* (0x0001 ? 0x0005 bytes) */
\r
2235 /* EPCBT_ERR_NULLPACKETSZ - Packet size is 0x0000 in both directions. */
\r
2236 /* No data can be transferred. Channel was */
\r
2239 /* Description: */
\r
2240 /* Sends the open channel command and receives the reply. */
\r
2242 /*******************************************|********************************************/
\r
2243 static EPS_INT32 CbtOpenChannelCommand (
\r
2246 CBTS_PRNINFO* pCbtPrnInfo,
\r
2248 EPS_UINT32* pPtSsz,
\r
2249 EPS_UINT32* pStPsz,
\r
2250 EPS_UINT32 CreditReq,
\r
2251 EPS_UINT32 CreditMax
\r
2254 EPS_INT32 Ret = EPCBT_ERR_NONE;
\r
2256 EPS_INT32 Cnt = 0;
\r
2257 EPS_INT32 BuffLen = CBT_CMD_SIZE_OPENCHANNEL;
\r
2258 EPS_INT32 RSize = 0;
\r
2259 static EPS_UINT8 Buff[] = {0x00,0x00,0x00,CBT_CMD_SIZE_OPENCHANNEL,0x01,0x00,0x01,0x00,0x00,0,0,0,0,0,0,0,0};
\r
2260 EPS_UINT8 RBuff[CBT_CMDREPLY_BUFFSZ];
\r
2264 memset(RBuff, 0, CBT_CMDREPLY_BUFFSZ);
\r
2269 CbtPutBigEndianByte2(*pPtSsz,&Buff[9]);
\r
2270 CbtPutBigEndianByte2(*pStPsz,&Buff[11]);
\r
2271 CbtPutBigEndianByte2(CreditReq,&Buff[13]);
\r
2272 CbtPutBigEndianByte2(CreditMax,&Buff[15]);
\r
2274 Ans = CbtWriteRtn( fd, pCbtPrnInfo, Buff, BuffLen, &Cnt );
\r
2275 if ( Ans != EPCBT_ERR_NONE )
\r
2276 Ret = EPCBT_ERR_FATAL;
\r
2278 if ( Cnt != BuffLen )
\r
2279 Ret = EPCBT_ERR_FATAL;
\r
2282 if ( Ret != EPCBT_ERR_NONE ){
\r
2283 EPS_RETURN( Ret ); /* return error end */
\r
2286 Ans = CbtReadRtn( fd, pCbtPrnInfo, CBT_SID_MAIN, RBuff, CBT_CMDREPLY_BUFFSZ, &RSize, CBT_READ_NORMAL );
\r
2287 if ( Ans != EPCBT_ERR_NONE )
\r
2288 Ret = EPCBT_ERR_FATAL; /* No receive */
\r
2290 Ret = CbtReplyCheck( RBuff, RSize, CBT_CMD_OPENCHANNEL );
\r
2291 if ( Ret == EPCBT_ERR_NONE ) {
\r
2292 if ( (RBuff[7] != 0x00) && (RBuff[7] != 0x06) ) {
\r
2293 if ( RBuff[7] == 0x04 )
\r
2294 Ret = EPCBT_ERR_RESOURCE;
\r
2295 else if ( RBuff[7] == 0x05 )
\r
2296 Ret = EPCBT_ERR_OPENCHANNEL;
\r
2297 else if ( RBuff[7] == 0x09 )
\r
2298 Ret = EPCBT_ERR_CHNOTSUPPORT;
\r
2299 else if ( RBuff[7] == 0x0C )
\r
2300 Ret = EPCBT_ERR_PACKETSIZE;
\r
2301 else if ( RBuff[7] == 0x0D )
\r
2302 Ret = EPCBT_ERR_NULLPACKETSZ;
\r
2304 Ret = EPCBT_ERR_UERESULT;
\r
2309 if ( Ret != EPCBT_ERR_NONE ){
\r
2310 EPS_RETURN( Ret ); /* error end */
\r
2313 *pPtSsz = (EPS_UINT32)((RBuff[10] << 8) + RBuff[11]);
\r
2314 *pStPsz = (EPS_UINT32)((RBuff[12] << 8) + RBuff[13]);
\r
2315 Ret = (RBuff[14] << 8) + RBuff[15];
\r
2317 EPS_RETURN( Ret );
\r
2320 /*******************************************|********************************************/
\r
2322 /* Function name: CbtCloseChannelCommand() */
\r
2326 /* Name: Type: Description: */
\r
2327 /* fd EPS_FILEDSC I: file discripter */
\r
2328 /* pCbtPrnInfo CBTS_PRNINFO* I: Port information */
\r
2329 /* SID EPS_UINT8 I: Socket ID */
\r
2331 /* Return value: */
\r
2332 /* EPCBT_ERR_NONE - Success */
\r
2333 /* EPCBT_ERR_FATAL - Fatal communication error */
\r
2334 /* EPCBT_ERR_CLOSEDENIED - Close Channel is denied */
\r
2335 /* EPCBT_ERR_CMDDENIED - Command is denied (Channel is not opened) */
\r
2336 /* EPCBT_ERR_UERESULT - Undefined result value */
\r
2337 /* EPCBT_ERR_NOREPLY - No reply from printer */
\r
2338 /* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
\r
2339 /* EPCBT_ERR_UEREPLY - Received reply for a command not issued */
\r
2341 /* Description: */
\r
2342 /* Send CloseChannel and receive reply. */
\r
2344 /*******************************************|********************************************/
\r
2345 static EPS_INT16 CbtCloseChannelCommand (
\r
2348 CBTS_PRNINFO* pCbtPrnInfo,
\r
2352 EPS_INT16 Ret = EPCBT_ERR_NONE;
\r
2354 EPS_INT32 Cnt = 0;
\r
2355 EPS_INT32 BuffLen = CBT_CMD_SIZE_CLOSECHANNEL;
\r
2356 EPS_INT32 RSize = 0;
\r
2357 static EPS_UINT8 Buff[] = {0x00,0x00,0x00,CBT_CMD_SIZE_CLOSECHANNEL,0x01,0x00,0x02,0x00,0x00,0x00};
\r
2358 EPS_UINT8 RBuff[CBT_CMDREPLY_BUFFSZ];
\r
2362 memset(RBuff, 0, CBT_CMDREPLY_BUFFSZ);
\r
2366 Ans = CbtWriteRtn( fd, pCbtPrnInfo, Buff, BuffLen, &Cnt );
\r
2367 if ( Ans != EPCBT_ERR_NONE )
\r
2368 Ret = EPCBT_ERR_FATAL;
\r
2370 if ( Cnt != BuffLen )
\r
2371 Ret = EPCBT_ERR_FATAL;
\r
2374 if ( Ret != EPCBT_ERR_NONE ){
\r
2375 EPS_RETURN( Ret ); /* return error end */
\r
2378 Ans = CbtReadRtn( fd, pCbtPrnInfo, CBT_SID_MAIN, RBuff, CBT_CMDREPLY_BUFFSZ, &RSize, CBT_READ_NORMAL );
\r
2379 if ( Ans != EPCBT_ERR_NONE )
\r
2380 Ret = EPCBT_ERR_FATAL; /* No receive */
\r
2382 Ret = CbtReplyCheck( RBuff, RSize, CBT_CMD_CLOSECHANNEL );
\r
2383 if ( Ret == EPCBT_ERR_NONE ) {
\r
2384 if ( RBuff[7] != 0x00 ) {
\r
2385 if ( RBuff[7] == 0x03 )
\r
2386 Ret = EPCBT_ERR_CLOSEDENIED;
\r
2387 else if ( RBuff[7] == 0x08 )
\r
2388 Ret = EPCBT_ERR_CMDDENIED;
\r
2390 Ret = EPCBT_ERR_UERESULT;
\r
2395 EPS_RETURN( Ret );
\r
2398 /*******************************************|********************************************/
\r
2400 /* Function name: CbtCreditReqCommand() */
\r
2404 /* Name: Type: Description: */
\r
2405 /* fd EPS_FILEDSC I: file discripter */
\r
2406 /* pCbtPrnInfo CBTS_PRNINFO* I: Printer information */
\r
2407 /* SID EPS_UINT8 I: SocketID */
\r
2408 /* CreditReq EPS_INT32 I: Credit Requested */
\r
2409 /* MaxCredit EPS_INT32 I: Maximum OutStanding Credit */
\r
2411 /* Return value: */
\r
2412 /* Credit - Success */
\r
2413 /* EPCBT_ERR_FATAL - Fatal communication error */
\r
2414 /* EPCBT_ERR_CMDDENIED - Command is denied (Channel is not opened) */
\r
2415 /* EPCBT_ERR_UERESULT - Undefined result value */
\r
2417 /* Description: */
\r
2418 /* Request credits and return credit number. */
\r
2420 /*******************************************|********************************************/
\r
2421 static EPS_INT32 CbtCreditReqCommand (
\r
2424 CBTS_PRNINFO* pCbtPrnInfo,
\r
2426 EPS_UINT32 CreditReq,
\r
2427 EPS_UINT32 MaxCredit
\r
2430 EPS_INT32 Ret = EPCBT_ERR_NONE;
\r
2432 EPS_INT32 Cnt = 0;
\r
2433 EPS_INT32 BuffLen = CBT_CMD_SIZE_CREDITREQUEST;
\r
2434 EPS_INT32 RSize = 0;
\r
2435 static EPS_UINT8 Buff[] = {0x00,0x00,0x00,CBT_CMD_SIZE_CREDITREQUEST,0x01,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00};
\r
2436 EPS_UINT8 RBuff[CBT_CMDREPLY_BUFFSZ];
\r
2440 memset(RBuff, 0, CBT_CMDREPLY_BUFFSZ);
\r
2445 CbtPutBigEndianByte2(CreditReq,&Buff[9]);
\r
2446 CbtPutBigEndianByte2(MaxCredit,&Buff[11]);
\r
2448 Ans = CbtWriteRtn( fd, pCbtPrnInfo, Buff, BuffLen, &Cnt );
\r
2449 if ( Ans != EPCBT_ERR_NONE )
\r
2450 Ret = EPCBT_ERR_FATAL;
\r
2452 if ( Cnt != BuffLen )
\r
2453 Ret = EPCBT_ERR_FATAL;
\r
2456 if ( Ret != EPCBT_ERR_NONE ){
\r
2457 EPS_RETURN( Ret ); /* return error end */
\r
2460 Ans = CbtReadRtn( fd, pCbtPrnInfo, CBT_SID_MAIN, RBuff, CBT_CMDREPLY_BUFFSZ, &RSize, CBT_READ_NORMAL );
\r
2461 if ( Ans != EPCBT_ERR_NONE )
\r
2462 Ret = EPCBT_ERR_FATAL; /* No receive */
\r
2464 Ret = CbtReplyCheck( RBuff, RSize, CBT_CMD_CREDITREQUEST );
\r
2465 if ( Ret == EPCBT_ERR_NONE ) {
\r
2466 if ( RBuff[7] != 0x00 ) {
\r
2467 if ( RBuff[7] == 0x08 )
\r
2468 Ret = EPCBT_ERR_CMDDENIED;
\r
2470 Ret = EPCBT_ERR_UERESULT;
\r
2475 if ( Ret != EPCBT_ERR_NONE ){
\r
2476 EPS_RETURN( Ret ); /* return error end */
\r
2479 Ret = ( RBuff[11] + (RBuff[10] << 8) );
\r
2481 EPS_RETURN( Ret );
\r
2484 /*******************************************|********************************************/
\r
2486 /* Function name: CbtCreditCommand() */
\r
2490 /* Name: Type: Description: */
\r
2491 /* fd EPS_FILEDSC I: file discripter */
\r
2492 /* pCbtPrnInfo CBTS_PRNINFO* I: Printer information */
\r
2493 /* SID EPS_UINT8 I: SocketID */
\r
2494 /* Credit EPS_INT32 I: Credit */
\r
2496 /* Return value: */
\r
2497 /* EPCBT_ERR_NONE - Success */
\r
2498 /* EPCBT_ERR_FATAL - Fatal communication error */
\r
2499 /* EPCBT_ERR_CREDITOVF - Credit over flow */
\r
2500 /* EPCBT_ERR_CMDDENIED - Command is denied (Channel is not opened) */
\r
2501 /* EPCBT_ERR_UERESULT - Undefined result value */
\r
2502 /* EPCBT_ERR_NOREPLY - No reply from printer */
\r
2503 /* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
\r
2504 /* EPCBT_ERR_UEREPLY - Received reply for a command not issued */
\r
2506 /* Description: */
\r
2507 /* Open the communication channel. */
\r
2509 /*******************************************|********************************************/
\r
2510 static EPS_INT16 CbtCreditCommand (
\r
2513 CBTS_PRNINFO* pCbtPrnInfo,
\r
2518 EPS_INT16 Ret = EPCBT_ERR_NONE;
\r
2520 EPS_INT32 Cnt = 0;
\r
2521 EPS_INT32 BuffLen = CBT_CMD_SIZE_CREDIT;
\r
2522 EPS_INT32 RSize = 0;
\r
2523 static EPS_UINT8 Buff[] = {0x00,0x00,0x00,CBT_CMD_SIZE_CREDIT,0x01,0x00,0x03,0x00,0x00,0x00,0x00};
\r
2524 EPS_UINT8 RBuff[CBT_CMDREPLY_BUFFSZ];
\r
2528 memset(RBuff, 0, CBT_CMDREPLY_BUFFSZ);
\r
2533 CbtPutBigEndianByte2(Credit,&Buff[9]);
\r
2535 Ans = CbtWriteRtn( fd, pCbtPrnInfo, Buff, BuffLen, &Cnt );
\r
2536 if ( Ans != EPCBT_ERR_NONE )
\r
2537 Ret = EPCBT_ERR_FATAL;
\r
2539 if ( Cnt != BuffLen )
\r
2540 Ret = EPCBT_ERR_FATAL;
\r
2543 if ( Ret != EPCBT_ERR_NONE ){
\r
2544 EPS_RETURN( Ret ); /* return error end */
\r
2547 Ans = CbtReadRtn( fd, pCbtPrnInfo, CBT_SID_MAIN, RBuff, CBT_CMDREPLY_BUFFSZ, &RSize, CBT_READ_NORMAL );
\r
2549 if ( Ans != EPCBT_ERR_NONE )
\r
2550 Ret = EPCBT_ERR_FATAL; /* No receive */
\r
2552 Ret = CbtReplyCheck( RBuff, RSize, CBT_CMD_CREDIT );
\r
2553 if ( Ret == EPCBT_ERR_NONE ) {
\r
2554 if ( RBuff[7] != 0x00 ) {
\r
2555 if ( RBuff[7] == 0x07 )
\r
2556 Ret = EPCBT_ERR_CREDITOVF;
\r
2557 else if ( RBuff[7] == 0x08 )
\r
2558 Ret = EPCBT_ERR_CMDDENIED;
\r
2560 Ret = EPCBT_ERR_UERESULT;
\r
2565 EPS_RETURN( Ret );
\r
2568 /*******************************************|********************************************/
\r
2570 /* Function name: CbtGetSocketIDCommand */
\r
2574 /* Name: Type: Description: */
\r
2575 /* fd EPS_FILEDSC I: file discripter */
\r
2576 /* pCbtPrnInfo CBTS_PRNINFO* I: Printer information */
\r
2577 /* lpNamepName EPS_UINT8 * I: Parameter Name */
\r
2578 /* Size EPS_INT32 I: Size of socket ID */
\r
2579 /* SocketID EPS_UINT8 * O: SocketID */
\r
2581 /* Return value: */
\r
2582 /* EPCBT_ERR_NONE - Success */
\r
2583 /* EPCBT_ERR_FATAL - Fatal communication error */
\r
2584 /* EPCBT_ERR_MULFORMEDPACKET - Received invalid packet */
\r
2585 /* EPCBT_ERR_NOSERVICE - The channel does not support the requested */
\r
2587 /* EPCBT_ERR_UERESULT - Undefined result value */
\r
2589 /* Description: */
\r
2590 /* Sends GetSocketID and receives reply. */
\r
2592 /*******************************************|********************************************/
\r
2593 #if LCOMSW_CBT_SOCKETFUNC_ON
\r
2594 static EPS_INT16 CbtGetSocketIDCommand (
\r
2597 CBTS_PRNINFO* pCbtPrnInfo,
\r
2598 EPS_UINT8* lpName,
\r
2600 EPS_UINT8* SocketID
\r
2603 /*** Declare Variable Local to Routine */
\r
2604 EPS_INT16 Ret = EPCBT_ERR_NONE;
\r
2606 EPS_INT32 Cnt = 0;
\r
2607 EPS_INT32 BuffLen;
\r
2609 EPS_INT32 RSize = 0;
\r
2610 EPS_UINT8 Buff[CBT_CMD_SIZE_GETSOCKETID + 40];
\r
2611 EPS_UINT8 RBuff[CBT_CMDREPLY_BUFFSZ];
\r
2615 /*** Initialize Local Variables */
\r
2616 memset(Buff, 0, CBT_CMD_SIZE_GETSOCKETID + 40);
\r
2617 memset(RBuff, 0, CBT_CMDREPLY_BUFFSZ);
\r
2619 BuffLen = CBT_CMD_SIZE_GETSOCKETID + Size;
\r
2624 Buff[3] = (EPS_UINT8)BuffLen;
\r
2629 /*** Sends GetSocketID and receives reply */
\r
2630 for ( lp1 = 0; lp1 < Size; lp1++ )
\r
2631 Buff[7+lp1] = lpName[lp1];
\r
2633 Ans = CbtWriteRtn( fd, pCbtPrnInfo, Buff, BuffLen, &Cnt );
\r
2635 if ( Ans != EPCBT_ERR_NONE )
\r
2636 Ret = EPCBT_ERR_FATAL;
\r
2638 if (Cnt != BuffLen)
\r
2639 Ret = EPCBT_ERR_FATAL;
\r
2642 if ( Ret != EPCBT_ERR_NONE ){
\r
2643 EPS_RETURN( Ret ); /* return error end */
\r
2646 Ans = CbtReadRtn( fd, pCbtPrnInfo, CBT_SID_MAIN, RBuff, CBT_CMDREPLY_BUFFSZ, &RSize, CBT_READ_NORMAL );
\r
2647 if ( Ans != EPCBT_ERR_NONE )
\r
2648 Ret = EPCBT_ERR_FATAL; /* No receive */
\r
2650 Ret = CbtReplyCheck( RBuff, RSize, CBT_CMD_GETSOCKETID );
\r
2651 if ( Ret == EPCBT_ERR_NONE ) {
\r
2652 if ( RBuff[3] != (Size + CBT_RPY_SIZE_GETSOCKETID) )
\r
2653 Ret = EPCBT_ERR_MULFORMEDPACKET;
\r
2654 else if ( RBuff[7] != 0x00 ) {
\r
2655 if ( RBuff[7] == 0x0A )
\r
2656 Ret = EPCBT_ERR_NOSERVICE;
\r
2658 Ret = EPCBT_ERR_UERESULT;
\r
2660 *SocketID = RBuff[8];
\r
2665 EPS_RETURN( Ret );
\r
2667 #endif /* def LCOMSW_CBT_SOCKETFUNC_ON */
\r
2669 /*******************************************|********************************************/
\r
2671 /* Function name: CbtDataWrite() */
\r
2675 /* Name: Type: Description: */
\r
2676 /* fd EPS_FILEDSC I: file discripter */
\r
2677 /* pCbtPrnInfo CBTS_PRNINFO* I: Printer information */
\r
2678 /* SID EPS_UINT8 I: SocketID */
\r
2679 /* lpBuffer const EPS_UINT8* I: Pointer to the write data buffer */
\r
2680 /* Size EPS_INT32 I: Size of the write data buffer */
\r
2682 /* Return value: */
\r
2683 /* Actually Write Size - Success */
\r
2684 /* EPCBT_ERR_WRITEERROR - Failed to write */
\r
2686 /* Description: */
\r
2687 /* Send data to printer. */
\r
2689 /*******************************************|********************************************/
\r
2690 static EPS_INT32 CbtDataWrite (
\r
2693 CBTS_PRNINFO* pCbtPrnInfo,
\r
2695 const EPS_UINT8* lpBuffer,
\r
2699 EPS_INT32 Ret = EPCBT_ERR_NONE;
\r
2701 EPS_INT32 Cnt = 0;
\r
2702 EPS_UINT32 BuffLen;
\r
2708 Buff = pCbtPrnInfo->pWriteBuff;
\r
2709 *(Buff + 0) = SID;
\r
2710 *(Buff + 1) = SID;
\r
2712 /* check packet size and Control */
\r
2713 if( (Size+6) > CBT_TXPSIZE)
\r
2714 BuffLen = CBT_TXPSIZE;
\r
2716 BuffLen = (EPS_UINT32)(Size + 6);
\r
2718 CbtPutBigEndianByte2(BuffLen, (Buff+2));
\r
2720 *(Buff + 5) = 0x01; /* end data */
\r
2723 for ( lp1=6; lp1<BuffLen; lp1++ )
\r
2724 *Buff++ = *lpBuffer++;
\r
2726 Ans = CbtWriteRtn( fd, pCbtPrnInfo, pCbtPrnInfo->pWriteBuff, (EPS_INT32)BuffLen, &Cnt );
\r
2730 Ret = EPCBT_ERR_WRITEERROR;
\r
2732 if ( Ans != EPCBT_ERR_NONE )
\r
2733 Ret = EPCBT_ERR_WRITEERROR;
\r
2735 EPS_RETURN( Ret );
\r
2738 /*******************************************|********************************************/
\r
2740 /* Function name: CbtDataRead */
\r
2744 /* Name: Type: Description: */
\r
2745 /* fd EPS_FILEDSC I: file discripter */
\r
2746 /* pCbtPrnInfo CBTS_PRNINFO* I: Printer information */
\r
2747 /* SID EPS_UINT8 I: Socket ID */
\r
2748 /* lpBuffer EPS_UINT8* O: Pointer to buffer for read data */
\r
2749 /* Size EPS_INT32* O: Pointer to variable for read data size */
\r
2751 /* Return value: */
\r
2752 /* EPCBT_ERR_NONE - Success */
\r
2753 /* EPCBT_ERR_CHNOTOPEN - Channel is not opened */
\r
2754 /* EPCBT_ERR_READERROR - Data read error */
\r
2756 /* Description: */
\r
2757 /* Read data from printer. */
\r
2759 /*******************************************|********************************************/
\r
2760 static EPS_INT16 CbtDataRead (
\r
2763 CBTS_PRNINFO* pCbtPrnInfo,
\r
2765 EPS_UINT8* lpBuffer,
\r
2769 EPS_INT16 Ret = EPCBT_ERR_NONE;
\r
2771 EPS_INT32 Cnt = 0;
\r
2773 CBTS_CHINFO* ChPtr = NULL;
\r
2779 for ( lp1 = 0; ; lp1++ ) {
\r
2780 if ( lp1 >= CBT_MAX_CH ){
\r
2781 EPS_RETURN( EPCBT_ERR_CHNOTOPEN );
\r
2784 ChPtr = &pCbtPrnInfo->Chinfo[lp1];
\r
2785 if ( ChPtr->No == SID ) /* channel open ? */
\r
2789 SBuff = ChPtr->ReadBuff;
\r
2790 if ( lpBuffer == NULL ) {
\r
2791 RBuff = pCbtPrnInfo->pCbtDataReadBuff;
\r
2792 Ans = CbtReadRtn( fd, pCbtPrnInfo, SID, RBuff, CBT_MAX_RTMP, &Cnt, CBT_READ_NORMAL );
\r
2796 SBuff += ChPtr->ReadSize;
\r
2797 for ( lp1 = 0; lp1 < Cnt; lp1++ )
\r
2798 *SBuff++ = *RBuff++;
\r
2800 ChPtr->ReadSize += Cnt;
\r
2802 if ( Ans != EPCBT_ERR_NONE )
\r
2803 Ret = EPCBT_ERR_READERROR;
\r
2805 *Size = ChPtr->ReadSize;
\r
2808 /* Buffer Size Check */
\r
2809 if ( *Size > ChPtr->ReadSize )
\r
2810 *Size = ChPtr->ReadSize;
\r
2811 for ( lp1 = 0; lp1 < *Size; lp1++ )
\r
2812 *RBuff++ = *SBuff++;
\r
2813 ChPtr->ReadSize = 0;
\r
2816 EPS_RETURN( Ret );
\r
2819 /*******************************************|********************************************/
\r
2821 /* Function name: CbtMemAlloc */
\r
2825 /* Name: Type: Description: */
\r
2828 /* Return value: */
\r
2829 /* EPCBT_ERR_NONE - Success */
\r
2830 /* EPCBT_ERR_MEMORY - Fail to memory allocation */
\r
2832 /* Description: */
\r
2833 /* Allocates the memory for CBT modules. */
\r
2835 /*******************************************|********************************************/
\r
2836 static EPS_INT16 CbtMemAlloc (
\r
2842 CBTS_CHINFO *ChPtr;
\r
2844 #if LCOMSW_CBT_ALLOC_MEM
\r
2845 gpCbtPrnInfo = (CBTS_PRNINFO*)EPS_ALLOC(sizeof(CBTS_PRNINFO));
\r
2847 return EPCBT_ERR_MEMORY;
\r
2848 memset(gpCbtPrnInfo, 0, sizeof(CBTS_PRNINFO));
\r
2849 #else /* LCOMSW_CBT_ALLOC_MEM */
\r
2850 gpCbtPrnInfo = &sgcbtprninfo;
\r
2851 #endif /* LCOMSW_CBT_ALLOC_MEM */
\r
2854 gpCbtPrnInfo->pPortInfo = NULL;
\r
2855 gpCbtPrnInfo->pWriteBuff = NULL;
\r
2856 gpCbtPrnInfo->pCbtReadRtnBuff = NULL;
\r
2857 gpCbtPrnInfo->pCbtDataReadBuff = NULL;
\r
2858 for ( lp1 = 0; lp1 < CBT_MAX_CH; lp1++ ) {
\r
2859 ChPtr = &gpCbtPrnInfo->Chinfo[lp1];
\r
2860 ChPtr->No = (EPS_UINT8)(lp1 == 0 ? CBT_SID_MAIN : 0);
\r
2861 ChPtr->PtSsize = 0;
\r
2862 ChPtr->StPsize = 0;
\r
2863 ChPtr->CreditP = 0;
\r
2864 ChPtr->CreditH = 0;
\r
2865 ChPtr->ReadSize = 0;
\r
2866 ChPtr->ReadBuff = NULL;
\r
2867 ChPtr->RTmpBuff = NULL;
\r
2868 ChPtr->RTmpTop = 0;
\r
2869 ChPtr->RTmpEnd = 0;
\r
2870 ChPtr->RTmpCnt = 0;
\r
2873 #if LCOMSW_CBT_ALLOC_MEM
\r
2874 gpCbtPrnInfo->pWriteBuff = (EPS_UINT8*)EPS_ALLOC(CBT_TXPSIZE);
\r
2875 if(!gpCbtPrnInfo->pWriteBuff)
\r
2876 return EPCBT_ERR_MEMORY;
\r
2877 gpCbtPrnInfo->pCbtReadRtnBuff = (EPS_UINT8*)EPS_ALLOC(CBT_MAX_RTMP);
\r
2878 if(!gpCbtPrnInfo->pCbtReadRtnBuff)
\r
2879 return EPCBT_ERR_MEMORY;
\r
2880 gpCbtPrnInfo->pCbtDataReadBuff = (EPS_UINT8*)EPS_ALLOC(CBT_MAX_RTMP);
\r
2881 if(!gpCbtPrnInfo->pCbtDataReadBuff)
\r
2882 return EPCBT_ERR_MEMORY;
\r
2883 #else /* LCOMSW_CBT_ALLOC_MEM */
\r
2884 gpCbtPrnInfo->pWriteBuff = (EPS_UINT8*)&sgwritebuff[0];
\r
2885 gpCbtPrnInfo->pCbtReadRtnBuff = (EPS_UINT8*)&sgcbtreadrtnbuff[0];
\r
2886 gpCbtPrnInfo->pCbtDataReadBuff = (EPS_UINT8*)&sgcbtdatareadbuff[0];
\r
2887 #endif /* LCOMSW_CBT_ALLOC_MEM */
\r
2889 for ( lp1 = 0; lp1 < CBT_MAX_CH; lp1++ ) {
\r
2890 ChPtr = &gpCbtPrnInfo->Chinfo[lp1];
\r
2892 #if LCOMSW_CBT_ALLOC_MEM
\r
2893 ChPtr->ReadBuff = (EPS_UINT8*)EPS_ALLOC(CBT_MAX_RTMP);
\r
2894 if(!ChPtr->ReadBuff)
\r
2895 return EPCBT_ERR_MEMORY;
\r
2896 ChPtr->RTmpBuff = (EPS_UINT8*)EPS_ALLOC(CBT_MAX_RTMP);
\r
2897 if(!ChPtr->RTmpBuff)
\r
2898 return EPCBT_ERR_MEMORY;
\r
2899 #else /* LCOMSW_CBT_ALLOC_MEM */
\r
2900 ChPtr->ReadBuff = (EPS_UINT8*)&sgreadbuff[lp1][0];
\r
2901 ChPtr->RTmpBuff = (EPS_UINT8*)&sgrtmpbuff[lp1][0];
\r
2902 #endif /* LCOMSW_CBT_ALLOC_MEM */
\r
2906 return EPCBT_ERR_NONE;
\r
2909 /*******************************************|********************************************/
\r
2911 /* Function name: CbtMemFree */
\r
2915 /* Name: Type: Description: */
\r
2918 /* Return value: */
\r
2921 /* Description: */
\r
2922 /* Frees the memory for CBT modules. */
\r
2924 /*******************************************|********************************************/
\r
2925 static void CbtMemFree (
\r
2931 CBTS_CHINFO *ChPtr;
\r
2933 if(!gpCbtPrnInfo) {
\r
2937 for ( lp1 = 0; lp1 < CBT_MAX_CH; lp1++ ) {
\r
2938 ChPtr = &gpCbtPrnInfo->Chinfo[lp1];
\r
2939 #if LCOMSW_CBT_ALLOC_MEM
\r
2940 EPS_SAFE_RELEASE(ChPtr->ReadBuff);
\r
2941 EPS_SAFE_RELEASE(ChPtr->RTmpBuff);
\r
2942 #else /* LCOMSW_CBT_ALLOC_MEM */
\r
2943 ChPtr->ReadBuff = NULL;
\r
2944 ChPtr->RTmpBuff = NULL;
\r
2945 #endif /* LCOMSW_CBT_ALLOC_MEM */
\r
2949 #if LCOMSW_CBT_ALLOC_MEM
\r
2950 EPS_SAFE_RELEASE(gpCbtPrnInfo->pWriteBuff);
\r
2951 EPS_SAFE_RELEASE(gpCbtPrnInfo->pCbtReadRtnBuff);
\r
2952 EPS_SAFE_RELEASE(gpCbtPrnInfo->pCbtDataReadBuff);
\r
2953 EPS_SAFE_RELEASE(gpCbtPrnInfo);
\r
2954 #else /* LCOMSW_CBT_ALLOC_MEM */
\r
2955 gpCbtPrnInfo->pWriteBuff = NULL;
\r
2956 gpCbtPrnInfo->pCbtReadRtnBuff = NULL;
\r
2957 gpCbtPrnInfo->pCbtDataReadBuff = NULL;
\r
2958 gpCbtPrnInfo = NULL;
\r
2959 #endif /* LCOMSW_CBT_ALLOC_MEM */
\r
2964 /*******************************************|********************************************/
\r
2966 /* Function name: CbtPutBigEndianByte2() */
\r
2970 /* Name: Type: Description: */
\r
2971 /* value EPS_INT32 I: same value */
\r
2972 /* buf[2] EPS_UINT8 I/O: Big endian value */
\r
2974 /* Return value: */
\r
2977 /* Description: */
\r
2978 /* Change input value to the big endian value. */
\r
2980 /*******************************************|********************************************/
\r
2981 static void CbtPutBigEndianByte2 (
\r
2988 /*** Change 2 bytes value to the big endianness */
\r
2989 EPS_UINT16 value2byte = (EPS_UINT16)value;
\r
2991 buf[0] = (EPS_UINT8)((value2byte >> 8) & 0x00ff);
\r
2992 buf[1] = (EPS_UINT8)((value2byte ) & 0x00ff);
\r
2996 /*___________________________________ epson-cbt.c ____________________________________*/
\r
2998 /*34567890123456789012345678901234567890123456789012345678901234567890123456789012345678*/
\r
2999 /* 1 2 3 4 5 6 7 8 */
\r
3000 /*******************************************|********************************************/
\r
3001 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r
3002 /***** End of File *** End of File *** End of File *** End of File *** End of File ******/
\r
3003 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%|%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
\r