From: Michael Gernoth Date: Sun, 30 May 2010 20:54:06 +0000 (+0200) Subject: reindent files X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/rigol/commitdiff_plain/610d5b65ca67c740ee40fc044ce502ddf3cba27a reindent files --- diff --git a/raw2gp.c b/raw2gp.c index c6b965e..425eba0 100644 --- a/raw2gp.c +++ b/raw2gp.c @@ -4,12 +4,12 @@ int main (int argc, char **argv) { - unsigned char buf[1024]; - int i, n; - - while ((n = read (0, buf, 1024)) > 0) { - for (i=0;i 0) { + for (i=0;i #include @@ -22,150 +22,150 @@ rmmod uhci_hcd; modprobe uhci_hcd //This routine locates a scope by VID/PID and returns an opened handle to it. usb_dev_handle *find_scope() { - struct usb_bus *bus; - struct usb_device *dev=NULL; - usb_find_busses(); - usb_find_devices(); - for (bus=usb_busses; bus; bus=bus->next) { - for (dev=bus->devices; dev; dev=dev->next) { -// fprintf(stderr,"Prod/dev: %04X:%04X\n",dev->descriptor.idVendor,dev->descriptor.idProduct); - if (dev->descriptor.idVendor==0x400 && dev->descriptor.idProduct==0x5dc) { - return usb_open(dev); - } + struct usb_bus *bus; + struct usb_device *dev=NULL; + usb_find_busses(); + usb_find_devices(); + for (bus=usb_busses; bus; bus=bus->next) { + for (dev=bus->devices; dev; dev=dev->next) { + //fprintf(stderr,"Prod/dev: %04X:%04X\n",dev->descriptor.idVendor,dev->descriptor.idProduct); + if (dev->descriptor.idVendor==0x400 && dev->descriptor.idProduct==0x5dc) { + return usb_open(dev); + } + } } - } - return NULL; + return NULL; } //Helper-routine: Convert a little-endian 4-byte word to an int void int2chars(unsigned char *buff,unsigned int a) { - buff[3]=(a>>24)&0xff; - buff[2]=(a>>16)&0xff; - buff[1]=(a>>8)&0xff; - buff[0]=(a)&0xff; + buff[3]=(a>>24)&0xff; + buff[2]=(a>>16)&0xff; + buff[1]=(a>>8)&0xff; + buff[0]=(a)&0xff; } //Helper-routine: Convert an int to little-endian 4-byte word unsigned int chars2int(unsigned char *buff) { - unsigned int a; - a=buff[3]<<24; - a+=buff[2]<<16; - a+=buff[1]<<8; - a+=buff[0]; - return a; + unsigned int a; + a=buff[3]<<24; + a+=buff[2]<<16; + a+=buff[1]<<8; + a+=buff[0]; + return a; } #define MIN(a,b) (((a)<(b))?(a):(b)) inline char printable (char ch) { - if (ch < ' ') return '.'; - if (ch > '~') return '.'; - return ch; + if (ch < ' ') return '.'; + if (ch > '~') return '.'; + return ch; } //Debugging: Print a buffers contents in hex void printb (unsigned char *pkt, int len) { - int i, j; - - for (i=0;i 0x40-12) { + //fprintf(stderr," Reading response:\n"); + if (resplen 0x40-12) { -// fprintf(stderr," Reading response:\n"); - if (resplen 0) { - sscanf ((char*)buf, "%lf", &temp); - return temp; - } - return ERROR; + unsigned char buf[1024]; + double temp; + int l; + + l = sendscpi(sc, var, buf, 1024); + if (l > 0) { + sscanf ((char*)buf, "%lf", &temp); + return temp; + } + return ERROR; } void do_get_buf (struct usb_dev_handle *sc) { - FILE *fp; - int i, j, l, bp; - char buf[1024]; - unsigned char ch1[1024]; - unsigned char data[512*1024]; - double sampfreq; + FILE *fp; + int i, j, l, bp; + char buf[1024]; + unsigned char ch1[1024]; + unsigned char data[512*1024]; + double sampfreq; - sendscpi (sc, ":STOP", NULL, 0); + sendscpi (sc, ":STOP", NULL, 0); - sampfreq = get_float_from_scope (sc, ":ACQ:SAMP?"); + sampfreq = get_float_from_scope (sc, ":ACQ:SAMP?"); - printf ("Got sampling freq: %g\n", sampfreq); + printf ("Got sampling freq: %g\n", sampfreq); - sprintf (buf, ":TIM:SCAL %.15f", 50 / sampfreq); - printf ("sending scale cmd: %s\n", buf); - sendscpi (sc, buf, NULL, 0); + sprintf (buf, ":TIM:SCAL %.15f", 50 / sampfreq); + printf ("sending scale cmd: %s\n", buf); + sendscpi (sc, buf, NULL, 0); - sleep (1); + sleep (1); - bp=0; - for (i=-254*1024;i< 254*1024;i += 600) { - sprintf (buf, ":TIM:OFFSET %.15f", i / sampfreq); - printf ("Sending offset cmd: %s\n", buf); - sendscpi (sc, buf, NULL, 0); + bp=0; + for (i=-254*1024;i< 254*1024;i += 600) { + sprintf (buf, ":TIM:OFFSET %.15f", i / sampfreq); + printf ("Sending offset cmd: %s\n", buf); + sendscpi (sc, buf, NULL, 0); - l = sendscpi(sc, ":WAV:DATA? CHANEL1", ch1, 1024); + l = sendscpi(sc, ":WAV:DATA? CHANEL1", ch1, 1024); - if (l != 1024) { - printf ("hmm. didnt' get 1024 bytes. \n"); - } - - for (j=0;j<600;j++) - data[bp++] = ch1[j+0xd4]; - } - printf ("Got %d bytes of data. \n", bp); + if (l != 1024) { + printf ("hmm. didnt' get 1024 bytes. \n"); + } - fp = fopen ("ch1.dump", "w"); - fwrite (data, bp, 1, fp); - fclose (fp); + for (j=0;j<600;j++) + data[bp++] = ch1[j+0xd4]; + } + printf ("Got %d bytes of data. \n", bp); - sendscpi (sc, ":TIM:OFFSET 0", NULL, 0); + fp = fopen ("ch1.dump", "w"); + fwrite (data, bp, 1, fp); + fclose (fp); + + sendscpi (sc, ":TIM:OFFSET 0", NULL, 0); } int main(int argc, char **argv) { - struct usb_dev_handle *sc; - char *scpi; - unsigned char *buff; - int l; - //Init libusb - usb_init(); - //Locate and open the scope - sc=find_scope(); - if (!sc) { - printf("No scope found.\n"); - exit(1); - } else { - printf("Scope found.\n"); - } - //Initialize scope - initscope(sc); - buff = malloc (1024*1024); - while (1) { - scpi = readline ("> "); - - if (!scpi) break; - if (strlen (scpi) == 0) { - free (scpi); - continue; - } - - add_history (scpi); - - if (strncmp (scpi, "quit", 4) == 0) break; - if (strncmp (scpi, "plot", 4) == 0) { - do_plot (sc); - continue; - } - if (strncmp (scpi, "databuf", 4) == 0) { - do_get_buf (sc); - continue; - } - - l = strlen (scpi); - // printf ("got buf(%d): ", l); - // printb (scpi, l+2); - if (strchr (scpi, '?')) { - // printf ("Expecting reply\n"); - l = sendscpi(sc, scpi, buff, 1024*1024); - // printf ("Got replylen = %d.\n", l); - buff[l] = 0; //zero-terminate - printb (buff, l); - } else { - // printf ("No reply expected\n"); - l=sendscpi(sc,scpi,NULL,0); - } - free (scpi); - } - //Disable keylock, so the user doesn't have to press the 'force'-button - l=sendscpi(sc, ":KEY:LOCK DISABLE",NULL,0); - - //Free up and exit - usb_release_interface(sc,0); - usb_close(sc); - return 0; + struct usb_dev_handle *sc; + char *scpi; + unsigned char *buff; + int l; + //Init libusb + usb_init(); + //Locate and open the scope + sc=find_scope(); + if (!sc) { + printf("No scope found.\n"); + exit(1); + } else { + printf("Scope found.\n"); + } + //Initialize scope + initscope(sc); + buff = malloc (1024*1024); + while (1) { + scpi = readline ("> "); + + if (!scpi) break; + if (strlen (scpi) == 0) { + free (scpi); + continue; + } + + add_history (scpi); + + if (strncmp (scpi, "quit", 4) == 0) break; + if (strncmp (scpi, "plot", 4) == 0) { + do_plot (sc); + continue; + } + if (strncmp (scpi, "databuf", 4) == 0) { + do_get_buf (sc); + continue; + } + + l = strlen (scpi); + //printf ("got buf(%d): ", l); + //printb (scpi, l+2); + if (strchr (scpi, '?')) { + //printf ("Expecting reply\n"); + l = sendscpi(sc, scpi, buff, 1024*1024); + //printf ("Got replylen = %d.\n", l); + buff[l] = 0; //zero-terminate + printb (buff, l); + } else { + //printf ("No reply expected\n"); + l=sendscpi(sc,scpi,NULL,0); + } + free (scpi); + } + //Disable keylock, so the user doesn't have to press the 'force'-button + l=sendscpi(sc, ":KEY:LOCK DISABLE",NULL,0); + + //Free up and exit + usb_release_interface(sc,0); + usb_close(sc); + return 0; }