source: trunk/csctapi/ifd_phoenix.c@ 1224

Last change on this file since 1224 was 1224, checked in by dingo35, 13 years ago

Move phoenix/smartmouse transmit and receive to ifd_phoenix.c

  • Property svn:eol-style set to native
File size: 3.0 KB
Line 
1/*
2 ifd_phoenix.c
3 This module provides IFD handling functions for Smartmouse/Phoenix reader.
4*/
5
6#include <stdio.h>
7//#include <time.h>
8//#include <string.h>
9//#include "ioctls.h"
10#include "../globals.h"
11#include "atr.h"
12#include "ifd_towitoko.h" //FIXME
13
14#define OK 1
15#define ERROR 0
16
17#define IFD_TOWITOKO_MAX_TRANSMIT 255
18#define IFD_TOWITOKO_ATR_TIMEOUT 800
19
20int Phoenix_Init ()
21{
22 return OK;
23}
24
25int Phoenix_GetStatus (int * status)
26{
27 int in;
28 unsigned int modembits=0;
29 extern int oscam_card_detect; //FIXME kill global variable
30 if (ioctl(reader[ridx].handle, TIOCMGET,&modembits)<0)
31 return ERROR;
32 switch(oscam_card_detect&0x7f)
33 {
34 case 0: in=(modembits & TIOCM_CAR); break;
35 case 1: in=(modembits & TIOCM_DSR); break;
36 case 2: in=(modembits & TIOCM_CTS); break;
37 case 3: in=(modembits & TIOCM_RNG); break;
38 default: in=0; // dummy
39 }
40 if (!(oscam_card_detect&0x80))
41 in=!in;
42 *status = in;
43 return OK;
44}
45
46int Phoenix_Reset (ATR ** atr)
47{
48 return OK;
49}
50
51int Phoenix_Transmit (BYTE * buffer, unsigned size, IFD_Timings * timings)
52{
53 unsigned block_delay, char_delay, sent=0, to_send = 0;
54
55#ifdef DEBUG_IFD
56 printf ("IFD: Transmit: ");
57 for (sent = 0; sent < size; sent++)
58 printf ("%X ", buffer[sent]);
59 printf ("\n");
60#endif
61
62#define IFD_TOWITOKO_DELAY 0
63
64 /* Calculate delays */
65 char_delay = IFD_TOWITOKO_DELAY + timings->char_delay;
66 block_delay = IFD_TOWITOKO_DELAY + timings->block_delay;
67
68#ifdef USE_GPIO
69 if (gpio_detect) set_gpio1(0);
70#endif
71 for (sent = 0; sent < size; sent = sent + to_send)
72 {
73 /* Calculate number of bytes to send */
74 to_send = MIN(size, IFD_TOWITOKO_MAX_TRANSMIT);
75
76 /* Send data */
77 if ((sent == 0) && (block_delay != char_delay))
78 {
79 if (!IO_Serial_Write (block_delay, 1, buffer))
80 return ERROR;
81
82 if (!IO_Serial_Write (char_delay, to_send-1, buffer+1))
83 return ERROR;
84 }
85 else
86 {
87 if (!IO_Serial_Write (char_delay, to_send, buffer+sent))
88 return ERROR;
89 }
90 }
91#ifdef USE_GPIO
92 if (gpio_detect) set_gpio1(1);
93#endif
94 return OK;
95}
96
97int Phoenix_Receive (BYTE * buffer, unsigned size, IFD_Timings * timings)
98{
99 unsigned char_timeout, block_timeout;
100#ifdef DEBUG_IFD
101 int i;
102#endif
103
104#define IFD_TOWITOKO_TIMEOUT 1000
105
106 /* Calculate timeouts */
107 char_timeout = IFD_TOWITOKO_TIMEOUT + timings->char_timeout;
108 block_timeout = IFD_TOWITOKO_TIMEOUT + timings->block_timeout;
109#ifdef USE_GPIO
110 if (gpio_detect) set_gpio1(0);
111#endif
112 if (block_timeout != char_timeout)
113 {
114 /* Read first byte using block timeout */
115 if (!IO_Serial_Read (block_timeout, 1, buffer))
116 return ERROR;
117
118 if (size > 1)
119 {
120 /* Read remaining data bytes using char timeout */
121 if (!IO_Serial_Read (char_timeout, size - 1, buffer + 1))
122 return ERROR;
123 }
124 }
125 else
126 {
127 /* Read all data bytes with the same timeout */
128 if (!IO_Serial_Read (char_timeout, size, buffer))
129 return ERROR;
130 }
131#ifdef USE_GPIO
132 if (gpio_detect) set_gpio1(1);
133#endif
134
135#ifdef DEBUG_IFD
136 printf ("IFD: Receive: ");
137 for (i = 0; i < size; i++)
138 printf ("%X ", buffer[i]);
139 printf ("\n");
140#endif
141
142 return OK;
143}
144
145int Phoenix_SetBaudrate (int mhz)
146{
147 return OK;
148}
Note: See TracBrowser for help on using the repository browser.