/* * Biopod reader test program * Programmed by: Micah Villmow * Version: 1.0 * * Purpose: To test the image parsing capabilities of the biopod linux device * driver. * Copyright 2005 - Micah Villmow - all rights reserved */ #include #include #include #include #include #include #include #include #include #include #include "biopod.h" int array[16] = { 0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00}; unsigned char data[128 * 128]; int subarrays[8] = { 0,0,0,0,0,0,0,0}; int main(int argc, char *argv[]) { int x = 0; unsigned char buffer[32768]; int count = 0; int device; uint8_t row, col, pixel; uint8_t startrow, stoprow; uint8_t subarray; int header = 0; int byte = 0; int jbyte = 0; FILE *image = fopen(argv[1],"w"); device = open("/dev/biopod0",O_RDONLY); if(!device) { fprintf(stderr,"Device cannot be opened!\n"); exit(EXIT_FAILURE); } write(device,"1",1); ioctl(device,BIOPOD_IOCDEFAULT,1); fprintf(stderr,"%d\n",argc); loop: count = read(device,buffer,32768); fprintf(stderr,"count = %d\n",count); if(count > 500) { col = 128; pixel = 127; row = 128; for(x = 0; x < count; x++) { if(header == 0 && buffer[x] >= (unsigned char)0xE0 && buffer[x] <= (unsigned char)0xE7) { subarray = (uint8_t)buffer[x] - 0xE0; if(subarrays[subarray] > 0) { header = -1; jbyte = 0; } subarrays[subarray]++; startrow = 127 - (subarray * 16); stoprow = startrow - 15; row = startrow; pixel = 127; header = 1; } else if(header == 1) { data[row-- * col + pixel] = array[buffer[x] & 0xF]; data[row-- * col + pixel] = array[(buffer[x] >> 4) & 0xF]; if(row < stoprow || row > startrow) { if(pixel != 0) pixel--; row = startrow; } byte++; if(byte == 1024) { subarrays[subarray]++; header = 0; byte = 0; } }else { jbyte++; if(jbyte == 1024) { header = 0; jbyte = 0; } } } for(x = 0; x < 8; x++) if(subarrays[x] == 0){ fprintf(stderr,"subarray %d is missing\n",x); goto loop; } fprintf(image,"P2\n128 128\n256\n"); for(x = 0; x < 128*128; x++) { fprintf(image,"%d ",(unsigned char)data[x]); } } else { for(x = 0; x < count; x++) fprintf(stderr,"%d ",buffer[x]); } fclose(image); fprintf(stderr,"Starting ioctl based image retrieval"); { struct biopod_image bioimage; int r; bioimage.data = malloc(640*480 * sizeof(*bioimage.data)); if(!bioimage.data) { fprintf(stderr,"Malloc failed!\n"); exit(1); } image = fopen("ioctlimage","w"); r = ioctl(device,BIOPOD_IOCSTART,1); fprintf(stderr,"ioctl biopod_start called with retval %d\n",r); r = ioctl(device,BIOPOD_IOCGIMAGE,&bioimage); fprintf(stderr,"ioctl biopod_image called with retval %d\n",r); r = ioctl(device,BIOPOD_IOCSTOP,1); fprintf(stderr,"ioctl biopod_stop called with retval %d\n",r); fprintf(image,"P2\n128 128\n256\n"); for(x = 0; x < 128*128; x++) { fprintf(image,"%d ",(unsigned char)data[x]); } fclose(image); } close(device); exit(EXIT_SUCCESS); }