Improvements
authorviric <viriketo@gmail.com>
Sun, 24 Oct 2010 04:05:22 +0200
changeset 4 5e6e113ebd92
parent 3 5925ce9887c2
child 5 8459d991779e
Improvements
pce.c
--- a/pce.c	Sun Oct 24 03:56:19 2010 +0200
+++ b/pce.c	Sun Oct 24 04:05:22 2010 +0200
@@ -26,6 +26,7 @@
 {
     int nsamples;
     int time_per_sample;
+    int immediate;
     char *download_file;
 } config;
 
@@ -115,7 +116,7 @@
     buf[36] = '0';
 
     // Immediate
-    buf[51] = 2;
+    buf[51] = config.immediate ? 2 : 1;
     // Minhum
     buf[52] = 0;
     buf[53] = 0;
@@ -165,10 +166,11 @@
     char data[100];
     res = usb_bulk_read(handle, ep_in, data, 3, 1000);
     assert(res == 3);
-    fprintf(stderr, "%02hhx%02hhx%02hhx\n", data[0], data[1], data[2]);
+    fprintf(stderr, "Debug: %02hhx%02hhx%02hhx\n", data[0], data[1], data[2]);
+    assert(data[0] == 2);
 
     int num = *((short int*) &data[1]);
-    fprintf(stderr, "Found %i bytes\n", num);
+    fprintf(stderr, "Found %i bytes = %i samples\n", num, num/4);
 
     if (num > 0)
     {
@@ -195,7 +197,8 @@
 
         res = usb_bulk_read(handle, ep_in, data, 3, 1000);
         assert(res == 3);
-        fprintf(stderr, "%02hhx%02hhx%02hhx\n", data[0], data[1], data[2]);
+        fprintf(stderr, "Debug: %02hhx%02hhx%02hhx\n", data[0], data[1], data[2]);
+        assert(data[0] == 2);
 
         int i;
         int sec = 0;
@@ -221,7 +224,7 @@
 void
 usage()
 {
-    fprintf(stderr, "usage: pce [-n nsamples] [-t timepersample] < -d downloadfile | -s >\n");
+    fprintf(stderr, "usage: pce [-n nsamples] [-t timepersample] [-i] <-d downloadfile | -s>\n");
 }
 
 int main(int argc, char **argv)
@@ -230,10 +233,11 @@
     int opt;
 
     config.nsamples = 16000;
+    config.immediate = 0;
     config.time_per_sample = 2;
     config.download_file = 0;
     action = HELP;
-    while  ((opt = getopt(argc, argv, "n:d:t:s")) != -1) {
+    while  ((opt = getopt(argc, argv, "n:d:t:si")) != -1) {
         switch (opt) {
             case 'n':
                 config.nsamples = atoi(optarg);
@@ -248,6 +252,9 @@
             case 's':
                 action = SET;
                 break;
+            case 'i':
+                config.immediate = 1;
+                break;
             default:
                 usage();
                 return 1;
@@ -276,8 +283,12 @@
         device->config->interface->altsetting->bInterfaceNumber);
     assert(res == 0 && "claim_interface");
 
-    if (config.download_file == 0)
+    if (action == SET)
     {
+        fprintf(stderr, "Settings: \n");
+        fprintf(stderr, " Max samples: %i\n", config.nsamples);
+        fprintf(stderr, " Time between samples: %i\n", config.time_per_sample);
+        fprintf(stderr, " Mode: %s\n", config.immediate ? "immediate" : "manual");
         send_program();
         send_config();
     }
@@ -287,6 +298,7 @@
         if (outfile != NULL)
         {
             start_download();
+            fprintf(stderr, "File \"%s\" written\n", config.download_file);
             fclose(outfile);
         }
         else