Ignore:
Timestamp:
01/20/10 15:51:11 (12 years ago)
Author:
rorothetroll
Message:

more support for the smartreader ... not yet finish so don't expect it to work right now

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/smartreader/csctapi/ifd_smartreader.c

    r1297 r1303  
    1 #ifdef HAVE_LIBUSB
    2 #ifdef USE_PTHREAD
     1#if defined(HAVE_LIBUSB) && defined(USE_PTHREAD)
    32/*
    43        ifd_smartreader.c
     
    2928    ftdic.out_ep = 0x82;
    3029
     30   
    3131    //open the first smartreader if found by find_smartreader
    3232    if ((ret = ftdi_usb_open(&ftdic, 0x0403, 0x6001)) < 0) {
    33         cs_log("unable to open ftdi device: %d (%s)\n", ret, ftdi_get_error_string(&ftdic));
     33        cs_log("unable to open ftdi device: %d (%s)", ret, ftdi_get_error_string(&ftdic));
    3434        return ERROR;
    3535    }
     
    4747    ftdi_setflowctrl(&ftdic, 0);
    4848
     49    // star the reading thread
     50    g_read_buffer_size = 0;
     51    pthread_mutex_init(&g_read_mutex,NULL);
     52    pthread_mutex_init(&g_usb_mutex,NULL);
    4953    ret = pthread_create(&rt, NULL, ReaderThread, (void *)&ftdic);
    5054    if (ret) {
    51         cs_log("ERROR; return code from pthread_create() is %d\n", ret);
     55        cs_log("ERROR; return code from pthread_create() is %d", ret);
    5256        return ERROR;
    5357    }
     
    133137
    134138    sr_config.fs=mhz*1000; //freq in KHz
    135     EnableSmartReader(&ftdic, sr_config.fs, sr_config.F, sr_config.D, sr_config.N, sr_config.inv);
     139    EnableSmartReader(&ftdic, sr_config.fs, sr_config.F, (BYTE)sr_config.D, sr_config.N, sr_config.inv);
    136140
    137141    return OK;
     
    147151   
    148152    if (ftdi_init(ftdic) < 0) {
    149         fprintf(stderr, "ftdi_init failed\n");
     153        cs_log("ftdi_init failed");
    150154        return ERROR;
    151155    }
     
    153157    if ((ret = ftdi_usb_find_all(ftdic, &devlist, 0x0403, 0x6001)) < 0)
    154158    {
    155         fprintf(stderr, "ftdi_usb_find_all failed: %d (%s)\n", ret, ftdi_get_error_string(ftdic));
    156         return ERROR;
    157     }
    158 
    159     printf("Number of FTDI devices found: %d\n", ret);
    160 
     159        cs_log( "ftdi_usb_find_all failed: %d (%s)", ret, ftdi_get_error_string(ftdic));
     160        return ERROR;
     161    }
     162#ifdef DEBUG_IO
     163    cs_log("Number of FTDI devices found: %d", ret);
     164#endif
    161165    i = 0;
    162166    dev_found=FALSE;
    163167    for (curdev = devlist; curdev != NULL; i++)
    164168    {
    165         printf("Checking device: %d\n", i);
    166         if ((ret = ftdi_usb_get_strings(ftdic, curdev->dev, manufacturer, 128, description, 128, NULL, 0)) < 0)
    167         {
    168             fprintf(stderr, "ftdi_usb_get_strings failed: %d (%s)\n", ret, ftdi_get_error_string(ftdic));
     169#ifdef DEBUG_IO
     170        cs_log("Checking device: %d", i);
     171        if ((ret = ftdi_usb_get_strings(ftdic, curdev->dev, manufacturer, 128, description, 128, NULL, 0)) < 0) {
     172            cs_log( "ftdi_usb_get_strings failed: %d (%s)", ret, ftdi_get_error_string(ftdic));
    169173            return ERROR;
    170174        }
    171         printf("Manufacturer: %s, Description: %s\n\n", manufacturer, description);
     175        cs_log("Manufacturer: %s, Description: %s", manufacturer, description);
     176#endif
    172177        if (i==index)
    173178            {
    174             printf("Found device index %d\n",i);
     179#ifdef DEBUG_IO
     180            cs_log("Found device index %d",i);
     181#endif
    175182            dev_found=TRUE;
    176183            break;
     
    183190    if(!dev_found)
    184191        {
    185         printf("Device not found\n");
     192        cs_log("Smartreader device number %d not found",index);
    186193       
    187194        ftdi_deinit(ftdic);
     
    238245    int ret = 0;
    239246    int idx;
    240     printf("write: ");
    241     hexdump(buff, size, 0);
    242 
     247
     248#ifdef DEBUG_IO
    243249    struct timeval start, stop, taken;
    244250    gettimeofday(&start, NULL);
     251#endif
    245252
    246253    if (udelay == 0) {
     
    261268    }
    262269
     270#ifdef DEBUG_IO
    263271    gettimeofday(&stop, NULL);
    264272    timersub(&stop, &start, &taken);
    265     printf(" took %u.000%u seconds\n", (unsigned int) taken.tv_sec, (unsigned int) taken.tv_usec);
     273    cs_log(" took %u.000%u seconds", (unsigned int) taken.tv_sec, (unsigned int) taken.tv_usec);
     274#endif
    266275    return ret;
    267276}
     
    316325
    317326    smart_flush(ftdic);
    318     EnableSmartReader(ftdic, 3571200, 372, 1, 0, 0);
     327
    319328    // set smartreader+ default values
    320329    sr_config.F=372;
     
    324333    sr_config.T=0;
    325334    sr_config.inv=0;
     335    EnableSmartReader(ftdic, sr_config.fs, sr_config.F, (BYTE)sr_config.D, sr_config.N, sr_config.inv);
    326336
    327337}
     
    333343    bool running = TRUE;
    334344    int ret;
     345    int copy_size;
    335346    unsigned char local_buffer[64];  //64 is max transfer size of FTDI bulk pipe
    336347
     
    350361        pthread_yield_np();
    351362
    352         if(ret>2){  //FTDI always sends modem status bytes as first 2 chars with the 232BM
     363        if(ret>2) {  //FTDI always sends modem status bytes as first 2 chars with the 232BM
    353364            pthread_mutex_lock(&g_read_mutex);
    354365
    355             int copy_size = sizeof(g_read_buffer) - g_read_buffer_size > ret-2 ?ret-2: sizeof(g_read_buffer) - g_read_buffer_size;
     366            copy_size = sizeof(g_read_buffer) - g_read_buffer_size > ret-2 ?ret-2: sizeof(g_read_buffer) - g_read_buffer_size;
    356367            memcpy(g_read_buffer+g_read_buffer_size,local_buffer+2,copy_size);
    357368            g_read_buffer_size += copy_size;           
    358             //printf("Transferred %u bytes to read buffer - current buffer = ",copy_size); hexdump(g_read_buffer,g_read_buffer_size); printf("\n");
    359369            pthread_mutex_unlock(&g_read_mutex);
    360         }else{
     370        }
     371        else {
    361372            //sleep for 50ms since there was nothing to read last time
    362373            usleep(50000);
     
    367378}
    368379
    369 #endif // USE_PTHREAD
    370 #endif //HAVE_LIBUSB
     380#endif // HAVE_LIBUSB && USE_PTHREAD
Note: See TracChangeset for help on using the changeset viewer.