Changeset 1236


Ignore:
Timestamp:
01/15/10 16:53:19 (11 years ago)
Author:
dingo35
Message:

New SetParity function in IO_Serial

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/csctapi/cardterminal.c

    r1220 r1236  
    714714    {
    715715        length = 2;
    716         IFD_Towitoko_SetParity(ct->slots[0]->ifd, IFD_TOWITOKO_PARITY_ODD);
     716        IO_Serial_SetParity (PARITY_ODD);   
    717717        buffer[0] = CTBCS_SW1_OK;
    718718        buffer[1] = CTBCS_SW2_OK;
     
    722722    {
    723723        length = 2;
    724         IFD_Towitoko_SetParity(ct->slots[0]->ifd, IFD_TOWITOKO_PARITY_EVEN);   
     724        IO_Serial_SetParity (PARITY_EVEN); 
    725725        buffer[0] = CTBCS_SW1_OK;
    726726        buffer[1] = CTBCS_SW2_OK;
     
    730730    {
    731731        length = 2;
    732         IFD_Towitoko_SetParity(ct->slots[0]->ifd, IFD_TOWITOKO_PARITY_NONE);   
     732        IO_Serial_SetParity (PARITY_NONE); 
    733733        buffer[0] = CTBCS_SW1_OK;
    734734        buffer[1] = CTBCS_SW2_OK;
  • trunk/csctapi/icc_async.c

    r1234 r1236  
    275275    if (icc->convention == ATR_CONVENTION_INVERSE)
    276276    {
    277         if (IFD_Towitoko_SetParity (icc->ifd, IFD_TOWITOKO_PARITY_ODD) != IFD_TOWITOKO_OK)
     277        if (!IO_Serial_SetParity (PARITY_ODD))
    278278            return ICC_ASYNC_IFD_ERROR;
    279279    }
    280280    else if(icc->protocol_type == ATR_PROTOCOL_TYPE_T14)
    281281    {
    282         if (IFD_Towitoko_SetParity (icc->ifd, IFD_TOWITOKO_PARITY_NONE) != IFD_TOWITOKO_OK)
     282        if (!IO_Serial_SetParity (PARITY_NONE))
    283283            return ICC_ASYNC_IFD_ERROR;     
    284284    }
    285285    else
    286286    {
    287         if (IFD_Towitoko_SetParity (icc->ifd, IFD_TOWITOKO_PARITY_EVEN) != IFD_TOWITOKO_OK)
     287        if (!IO_Serial_SetParity (PARITY_EVEN))
    288288            return ICC_ASYNC_IFD_ERROR;     
    289289    }
  • trunk/csctapi/ifd_towitoko.c

    r1235 r1236  
    185185    io->bits = 8;
    186186    io->stopbits = 2;
    187     io->parity = IO_SERIAL_PARITY_EVEN;
     187    io->parity = PARITY_EVEN;
    188188    io->dtr = IO_SERIAL_HIGH;
    189189//  io->dtr = IO_SERIAL_LOW;
     
    192192   
    193193       
    194     if (!IO_Serial_SetProperties (io))
     194    if (!IO_Serial_SetPropertiesOld (io))
    195195        return IFD_TOWITOKO_IO_ERROR;
    196196       
     
    209209    }
    210210   
    211     ret = IFD_Towitoko_SetParity (ifd, IFD_TOWITOKO_PARITY_EVEN);
     211    if (!IO_Serial_SetParity (PARITY_EVEN))
     212        return IFD_TOWITOKO_IO_ERROR;
    212213   
    213214    if (ret != IFD_TOWITOKO_OK)
     
    264265#endif
    265266    /* Get current settings */
    266     if (!IO_Serial_GetProperties (ifd->io))
     267    if (!IO_Serial_GetPropertiesOld (ifd->io))
    267268        return IFD_TOWITOKO_IO_ERROR;
    268269   
     
    275276    ifd->io->input_bitrate = baudrate;
    276277   
    277     if (!IO_Serial_SetProperties (ifd->io))
     278    if (!IO_Serial_SetPropertiesOld (ifd->io))
    278279        return IFD_TOWITOKO_IO_ERROR;
    279280   
     
    289290   
    290291    /* Get current settings */
    291     if (!IO_Serial_GetProperties (ifd->io))
     292    if (!IO_Serial_GetPropertiesOld (ifd->io))
    292293        return IFD_TOWITOKO_IO_ERROR;
    293294   
    294295    (*baudrate) = ifd->io->output_bitrate;
    295    
    296     return IFD_TOWITOKO_OK;
    297 }
    298 
    299 extern int IFD_Towitoko_SetParity (IFD * ifd, BYTE parity)
    300 {
    301     if(reader[ridx].typ == R_INTERNAL)
    302     {
    303         return IFD_TOWITOKO_OK;
    304     }
    305    
    306 #ifdef DEBUG_IFD
    307     printf ("IFD: Parity = %s\n",
    308     parity == IFD_TOWITOKO_PARITY_ODD ? "Odd" :
    309     parity == IFD_TOWITOKO_PARITY_EVEN ? "Even" : "Invalid");
    310 #endif
    311    
    312     if ((parity != IFD_TOWITOKO_PARITY_EVEN) && (parity != IFD_TOWITOKO_PARITY_ODD) && (parity != IFD_TOWITOKO_PARITY_NONE))
    313         return IFD_TOWITOKO_PARAM_ERROR;
    314    
    315     /* Get current settings */
    316     if (!IO_Serial_GetProperties (ifd->io))
    317         return IFD_TOWITOKO_IO_ERROR;
    318    
    319     if (ifd->io->parity !=parity)
    320     {
    321         ifd->io->parity = parity;
    322        
    323         if (!IO_Serial_SetProperties (ifd->io))
    324             return IFD_TOWITOKO_IO_ERROR;
    325     }
    326296   
    327297    return IFD_TOWITOKO_OK;
     
    408378        int parity;
    409379        int i;
    410         int par[3] = {IFD_TOWITOKO_PARITY_EVEN, IFD_TOWITOKO_PARITY_ODD, IFD_TOWITOKO_PARITY_NONE};
     380        int par[3] = {PARITY_EVEN, PARITY_ODD, PARITY_NONE};
    411381#ifdef HAVE_NANOSLEEP
    412382        struct timespec req_ts;
     
    421391            IO_Serial_Flush();
    422392
    423             ret = IFD_Towitoko_SetParity (ifd, parity);
    424             if (ret != IFD_TOWITOKO_OK)
    425                 return ret;
     393            if (!IO_Serial_SetParity (parity))
     394                return IFD_TOWITOKO_IO_ERROR;
    426395
    427396            ret = IFD_TOWITOKO_IO_ERROR;
  • trunk/csctapi/ifd_towitoko.h

    r1234 r1236  
    6767#define IFD_TOWITOKO_CHANGE(status)     (((status) & 0x80) == 0x80)
    6868
    69 /* Led Color */
    70 #define IFD_TOWITOKO_LED_OFF            0x00
    71 #define IFD_TOWITOKO_LED_RED            0x01
    72 #define IFD_TOWITOKO_LED_GREEN          0x02
    73 #define IFD_TOWITOKO_LED_YELLOW         0x03
    74 
    75 /* IFD parity */
    76 //#define IFD_TOWITOKO_PARITY_ODD         0x80
    77 //#define IFD_TOWITOKO_PARITY_EVEN        0x40
    78 #define IFD_TOWITOKO_PARITY_ODD         1
    79 #define IFD_TOWITOKO_PARITY_EVEN        2
    80 #define IFD_TOWITOKO_PARITY_NONE        3
    81 
    8269/* ICC types */
    8370#define IFD_TOWITOKO_I2C_SHORT          0
     
    130117extern int IFD_Towitoko_SetBaudrate (IFD * ifd, unsigned long baudrate);
    131118extern int IFD_Towitoko_GetBaudrate (IFD * ifd, unsigned long *baudrate);
    132 extern int IFD_Towitoko_SetParity (IFD * ifd, BYTE parity);
    133119
    134120/* General handling of ICC inserted in this IFD */
  • trunk/csctapi/io_serial.c

    r1235 r1236  
    180180}
    181181
    182 bool IO_Serial_GetProperties (IO_Serial * io)
     182bool IO_Serial_GetPropertiesOld (IO_Serial * io)
    183183{
    184184    struct termios currtio;
     
    424424    {
    425425        if (((currtio.c_cflag) & PARODD) == PARODD)
    426             io->parity = IO_SERIAL_PARITY_ODD;
     426            io->parity = PARITY_ODD;
    427427        else
    428             io->parity = IO_SERIAL_PARITY_EVEN;
     428            io->parity = PARITY_EVEN;
    429429    }
    430430    else
    431431    {
    432         io->parity = IO_SERIAL_PARITY_NONE;
     432        io->parity = PARITY_NONE;
    433433    }
    434434   
     
    445445   
    446446#ifdef DEBUG_IO
    447     printf("IO: Getting properties: %ld bps; %d bits/byte; %s parity; %d stopbits; dtr=%d; rts=%d\n", io->input_bitrate, io->bits, io->parity == IO_SERIAL_PARITY_EVEN ? "Even" : io->parity == IO_SERIAL_PARITY_ODD ? "Odd" : "None", io->stopbits, io->dtr, io->rts);
     447    printf("IO: Getting properties: %ld bps; %d bits/byte; %s parity; %d stopbits; dtr=%d; rts=%d\n", io->input_bitrate, io->bits, io->parity == PARITY_EVEN ? "Even" : io->parity == PARITY_ODD ? "Odd" : "None", io->stopbits, io->dtr, io->rts);
    448448#endif
    449449   
     
    451451}
    452452
    453 bool IO_Serial_SetProperties (IO_Serial * io)
     453bool IO_Serial_SetPropertiesOld (IO_Serial * io)
    454454{
    455455   struct termios newtio;
     
    460460#endif
    461461   
    462    //   printf("IO: Setting properties: reader_type%d, %ld bps; %d bits/byte; %s parity; %d stopbits; dtr=%d; rts=%d\n", reader[ridx].typ, io->input_bitrate, io->bits, io->parity == IO_SERIAL_PARITY_EVEN ? "Even" : io->parity == IO_SERIAL_PARITY_ODD ? "Odd" : "None", io->stopbits, io->dtr, io->rts);
     462   //   printf("IO: Setting properties: reader_type%d, %ld bps; %d bits/byte; %s parity; %d stopbits; dtr=%d; rts=%d\n", reader[ridx].typ, io->input_bitrate, io->bits, io->parity == PARITY_EVEN ? "Even" : io->parity == PARITY_ODD ? "Odd" : "None", io->stopbits, io->dtr, io->rts);
    463463   memset (&newtio, 0, sizeof (newtio));
    464464
     
    513513    switch (io->parity)
    514514    {
    515         case IO_SERIAL_PARITY_ODD:
     515        case PARITY_ODD:
    516516            newtio.c_cflag |= PARENB;
    517517            newtio.c_cflag |= PARODD;
    518518            break;
    519519       
    520         case IO_SERIAL_PARITY_EVEN:
     520        case PARITY_EVEN:   
    521521            newtio.c_cflag |= PARENB;
    522522            newtio.c_cflag &= ~PARODD;
    523523            break;
    524524       
    525         case IO_SERIAL_PARITY_NONE:
     525        case PARITY_NONE:
    526526            newtio.c_cflag &= ~PARENB;
    527527            break;
     
    566566   
    567567#ifdef DEBUG_IO
    568     printf("IO: Setting properties: reader_type%d, %ld bps; %d bits/byte; %s parity; %d stopbits; dtr=%d; rts=%d\n", reader[ridx].typ, io->input_bitrate, io->bits, io->parity == IO_SERIAL_PARITY_EVEN ? "Even" : io->parity == IO_SERIAL_PARITY_ODD ? "Odd" : "None", io->stopbits, io->dtr, io->rts);
    569 #endif
     568    printf("IO: Setting properties: reader_type%d, %ld bps; %d bits/byte; %s parity; %d stopbits; dtr=%d; rts=%d\n", reader[ridx].typ, io->input_bitrate, io->bits, io->parity == PARITY_EVEN ? "Even" : io->parity == PARITY_ODD ? "Odd" : "None", io->stopbits, io->dtr, io->rts);
     569#endif
     570    return TRUE;
     571}
     572
     573bool IO_Serial_SetProperties (struct termios newtio)
     574{
     575   if(reader[ridx].typ == R_INTERNAL)
     576      return FALSE;
     577
     578    if (tcsetattr (reader[ridx].handle, TCSANOW, &newtio) < 0)
     579        return FALSE;
     580//  tcflush(reader[ridx].handle, TCIOFLUSH);
     581//  if (tcsetattr (reader[ridx].handle, TCSAFLUSH, &newtio) < 0)
     582//      return FALSE;
     583
     584    unsigned int mctl;
     585    if (ioctl (reader[ridx].handle, TIOCMGET, &mctl) < 0)
     586        return FALSE;
     587   
     588    int dtr = ((mctl & TIOCM_DTR) ? IO_SERIAL_HIGH : IO_SERIAL_LOW);
     589    int rts = ((mctl & TIOCM_RTS) ? IO_SERIAL_HIGH : IO_SERIAL_LOW);
     590
     591    IO_Serial_Ioctl_Lock(1);
     592    IO_Serial_DTR_RTS(0, rts == IO_SERIAL_HIGH);
     593    IO_Serial_DTR_RTS(1, dtr == IO_SERIAL_HIGH);
     594    IO_Serial_Ioctl_Lock(0);
     595
     596#ifdef DEBUG_IO
     597    printf("IO: Setting properties\n");
     598#endif
     599
     600    return TRUE;
     601}
     602
     603int IO_Serial_SetParity (BYTE parity)
     604{
     605    if(reader[ridx].typ == R_INTERNAL)
     606        return TRUE;
     607
     608    if ((parity != PARITY_EVEN) && (parity != PARITY_ODD) && (parity != PARITY_NONE))
     609        return FALSE;
     610
     611    struct termios tio;
     612    int current_parity;
     613    // Get current parity
     614    if (tcgetattr (reader[ridx].handle, &tio) != 0)
     615      return FALSE;
     616
     617    if (((tio.c_cflag) & PARENB) == PARENB)
     618    {
     619        if (((tio.c_cflag) & PARODD) == PARODD)
     620            current_parity = PARITY_ODD;
     621        else
     622            current_parity = PARITY_EVEN;
     623    }
     624    else
     625    {
     626        current_parity = PARITY_NONE;
     627    }
     628
     629#ifdef DEBUG_IFD
     630    printf ("IFD: Setting parity from %s to %s\n",
     631    current_parity == PARITY_ODD ? "Odd" :
     632    current_parity == PARITY_NONE ? "None" :
     633    current_parity == PARITY_EVEN ? "Even" : "Invalid",
     634    parity == PARITY_ODD ? "Odd" :
     635    parity == PARITY_NONE ? "None" :
     636    parity == PARITY_EVEN ? "Even" : "Invalid");
     637#endif
     638   
     639    if (current_parity != parity)
     640    {
     641
     642        // Set the parity
     643        switch (parity)
     644        {
     645            case PARITY_ODD:
     646                tio.c_cflag |= PARENB;
     647                tio.c_cflag |= PARODD;
     648                break;
     649           
     650            case PARITY_EVEN:   
     651                tio.c_cflag |= PARENB;
     652                tio.c_cflag &= ~PARODD;
     653                break;
     654           
     655            case PARITY_NONE:
     656                tio.c_cflag &= ~PARENB;
     657                break;
     658        }
     659        if (!IO_Serial_SetProperties (tio))
     660            return FALSE;
     661    }
     662
    570663    return TRUE;
    571664}
     
    9591052    io->input_bitrate = 1200;
    9601053    io->output_bitrate = 1200;
    961     io->parity = IO_SERIAL_PARITY_NONE;
     1054    io->parity = PARITY_NONE;
    9621055    io->bits = 7;
    9631056    io->stopbits = 1;
    9641057    io->dtr = IO_SERIAL_HIGH;
    965 //  io->rts = IO_SERIAL_HIGH;
    9661058    io->rts = IO_SERIAL_LOW;
    9671059   
    968     if (!IO_Serial_SetProperties (io))
     1060    if (!IO_Serial_SetPropertiesOld (io))
    9691061        return FALSE;
    9701062
  • trunk/csctapi/io_serial.h

    r1235 r1236  
    3737
    3838/* Type of parity of the serial device */
    39 #define IO_SERIAL_PARITY_ODD        1
    40 #define IO_SERIAL_PARITY_EVEN       2
    41 #define IO_SERIAL_PARITY_NONE       3
     39#define PARITY_ODD      1
     40#define PARITY_EVEN     2
     41#define PARITY_NONE     3
    4242
    4343/* Values for the modem lines */
     
    8686
    8787/* Transmission properties */
    88 extern bool IO_Serial_SetProperties (IO_Serial * io);
    89 extern bool IO_Serial_GetProperties (IO_Serial * io);
     88extern bool IO_Serial_SetPropertiesOld (IO_Serial * io);
     89extern bool IO_Serial_GetPropertiesOld (IO_Serial * io);
    9090extern bool IO_Serial_DTR_RTS(int, int);
    9191#if defined(TUXBOX) && defined(PPC)
  • trunk/globals.h

    r1220 r1236  
    411411  int       card_status; //highlevel status
    412412  unsigned short status; //lowlevel status: states whether card inserted and/or change of status FIXME look at integration with pcsc_has_card/detect/card_status
     413    unsigned long baudrate; //we are storing baudrate to prevent unnecessary conversions from/to termios structure
    413414  struct    s_module ph;
    414415  uchar     ncd_key[16];
Note: See TracChangeset for help on using the changeset viewer.