This patch fixes the perl bindings and the perl test script.

All extraneous stuff that made it into previous versions of this patch have
been pulled out into separate patches.

-- 
Phil Dibowitz                             p...@ipom.com
Open Source software and tech docs        Insanity Palace of Metallica
http://www.phildev.net/                   http://www.ipom.com/

"Be who you are and say what you feel, because those who mind don't matter
 and those who matter don't mind."
 - Dr. Seuss

commit f6935a719f503da6c47c34480a8ff3b0910dff20
Author: Phil Dibowitz <p...@ipom.com>
Date:   Sat Mar 15 21:22:22 2014 -0700

    Fix Perl Bindings
    
    libconcord/bindings/perl/concord.i
    * Fix for chnages in callback API
    * Fix for changes in read_and_parse_file
    
    libconcord/bindings/perl/test.pl
    * Port to new API
    
    libconcord/libconcord.h
    libconcord/libconcord.cpp
    libconcord/operationfile.h
    libconcord/operationfile.cpp
    * Take a uint32_t for type instead of 'int'
    
    libconcord/bindings/python/libconcord.py
    * Update bindings for int -> uint32_t change
    
    Signed-off-by: Phil Dibowitz <p...@ipom.com>

diff --git a/libconcord/bindings/perl/concord.i b/libconcord/bindings/perl/concord.i
index 6d183f2..fcbd5a6 100644
--- a/libconcord/bindings/perl/concord.i
+++ b/libconcord/bindings/perl/concord.i
@@ -25,7 +25,9 @@
  * This is the C callback that will wrap our perl callback and call
  * perl for us. SWIG can't handle this directly, we must do it.
  */
-void lc_cb_wrapper(uint32_t count, uint32_t curr, uint32_t total, void *arg)
+void lc_cb_wrapper(uint32_t stage_id, uint32_t count, uint32_t curr,
+    uint32_t total, uint32_t counter_type, void *arg,
+    const uint32_t *stages)
 {
     AV *args = (AV*)arg;
     SV *cb;
@@ -47,12 +49,14 @@ void lc_cb_wrapper(uint32_t count, uint32_t curr, uint32_t total, void *arg)
     PUSHMARK(SP);
 
     /*
-     * Push the first three variables into the stack and mortalize
+     * Push the first 5 variables into the stack and mortalize
      * them so that perl will clean them up after the call to cb.
      */
+    XPUSHs(sv_2mortal(newSViv(stage_id)));
     XPUSHs(sv_2mortal(newSViv(count)));
     XPUSHs(sv_2mortal(newSViv(curr)));
     XPUSHs(sv_2mortal(newSViv(total)));
+    XPUSHs(sv_2mortal(newSViv(counter_type)));
 
     /*
      * Next up, we recurse through the array in void *arg and pull
@@ -70,6 +74,8 @@ void lc_cb_wrapper(uint32_t count, uint32_t curr, uint32_t total, void *arg)
         XPUSHs(*av_fetch(args, i, 0));
     }
 
+    XPUSHs(sv_2mortal(newSViv(stages)));
+
     /*
      * Tell it we're done pushing things onto the stack, so it should
      * now know how big @_ is.
@@ -236,6 +242,7 @@ void lc_cb_wrapper(uint32_t count, uint32_t curr, uint32_t total, void *arg)
  * outputs, we have to list these individually... ignore only works in input.
  */
 %typemap(argout) uint32_t *size,
+         uint32_t *type,
          uint32_t *binary_size,
          uint32_t *key_names_length,
          uint32_t *ir_signal_length,
diff --git a/libconcord/bindings/perl/test.pl b/libconcord/bindings/perl/test.pl
index 1da009e..1c12ba3 100755
--- a/libconcord/bindings/perl/test.pl
+++ b/libconcord/bindings/perl/test.pl
@@ -35,12 +35,12 @@ use Getopt::Long qw(:config bundling);
 use concord;
 
 use constant FW_FILE => '/tmp/perl_fw';
-use constant CONFIG_FILE => '/tmp/perl_fw';
+use constant CONFIG_FILE => '/tmp/perl_cf';
 use constant IR_FILE => '/tmp/LearnIr.EZTut';
 
 sub cb
 {
-    my ($count, $curr, $total, $data) = @_;
+    my ($stage_id, $count, $curr, $total, $type, $data, $stages) = @_;
 
     print '*';
     #print "CALLBACK: count: $count, curr: $curr, total $total, data:"
@@ -72,7 +72,6 @@ sub dump_config
 
 sub dump_firmware
 {
-
     my ($blob, $size);
 
     my $err;
@@ -95,144 +94,61 @@ sub dump_firmware
 
 sub upload_config
 {
-    my ($blob, $size, $binblob, $binsize);
+    my ($err, $type);
 
-    my $err;
     print "Reading config ";
-    ($err, $blob, $size) = concord::read_file(CONFIG_FILE);
+    ($err, $type) = concord::read_and_parse_file(CONFIG_FILE);
     if ($err) {
         print "Failed to read config from file\n";
         exit(1);
     }
     print "done\n";
-    print "Finding binary ";
-    ($err, $binblob, $binsize) = concord::find_config_binary($blob, $size);
-    if ($err) {
-        print "Failed to find bin\n";
-        exit(1);
-    }
-    print "done\n";
-    print "Preparing for config update ";
-    concord::prep_config();
-    if ($err) {
-        print "Failed to prepare for config update";
-        exit(1);
-    }
-    print "done\n";
-    print "Invalidating flash ";
-    concord::invalidate_flash();
-    if ($err) {
-        print "Failed to invalidate flash";
-        exit(1);
-    }
-    print "done\n";
-    print "Erasing flash ";
-    concord::erase_config($binsize, \&cb, 1);
-    if ($err) {
-        print "Failed to erase flash";
-        exit(1);
-    }
-    print "done\n";
     print "Writing config ";
-    concord::write_config_to_remote($binblob, $binsize, \&cb, 1);
-    if ($err) {
-        print "Failed to write config to remote";
-        exit(1);
-    }
-    print "done\n";
-    print "Verifying config ";
-    concord::verify_remote_config($binblob, $binsize, \&cb, 1);
+    concord::update_configuration(\&cb, 1, 0);
     if ($err) {
         print "Failed to write config to remote";
         exit(1);
     }
-    print "Finalizing config update ";
-    concord::finish_config();
-    if ($err) {
-        print "Failed to finalize config update";
-        exit(1);
-    }
     print "done\n";
-
-    concord::delete_blob($blob);
-    print "done\n";
-
 }
 
 sub upload_firmware
 {
-    my ($err, $blob, $size, $binblob, $binsize);
+    my ($err, $type);
 
     $err = concord::is_fw_update_supported(0);
     if ($err) {
         print "Sorry, firmware is not supported on your device\n";
         exit(1);
     }
-    print "Reading fw\n";
-    ($err, $blob, $size) = concord::read_file(FW_FILE);
+    print "Reading config ";
+    ($err, $type) = concord::read_and_parse_file(FW_FILE);
     if ($err) {
         print "Failed to read config from file\n";
         exit(1);
     }
-    print "extracting fw ";
-    print "done\n";
-    ($err, $binblob, $binsize) = concord::extract_firmware_binary($blob, $size);
-    if ($err) {
-        print "Failed extract fw\n";
-        exit(1);
-    }
     print "done\n";
-    print "preping fw ";
-    $err = concord::prep_firmware();
-    if ($err) {
-        print "Failed prep fw\n";
-        exit(1);
-    }
-    print "done\n";
-    print "invalidating flash ";
-    $err = concord::invalidate_flash();
+    print "writing fw ";
+    $err = concord::update_firmware(\&cb, 0, 0, 0);
     if ($err) {
         print "Failed invalidate flash\n";
         exit(1);
     }
     print "done\n";
-    print "erasing flash ";
-    $err = concord::erase_firmware(0, \&cb, 0);
-    if ($err) {
-        print "Failed invalidate flash\n";
-        exit(1);
-    }
-    print "done\n";
-    print "erasing fw ";
-    $err = concord::write_firmware_to_remote($binblob, $binsize, 0, \&cb, 0);
-    if ($err) {
-        print "Failed invalidate flash\n";
-        exit(1);
-    }
-    print "done\n";
-    print "finishing fw ";
-    $err = concord::finish_firmware();
-    if ($err) {
-        print "Failed finish fw\n";
-        exit(1);
-    }
-    print "done\n";
-    concord::delete_blob($blob);
-    concord::delete_blob($binblob);
 }
 
 sub learn_ir_commands
 {
-    my ($err, $blob, $size, $binblob, $binsize);
+    my ($err, $type);
 
     print "Reading IR file ";
-    ($err, $blob, $size) = concord::read_file(IR_FILE);
+    my $type;
+    ($err, $type) = concord::read_and_parse_file(IR_FILE);
     print "done\n";
 
     print "Getting key names ";
     my $key_names;
-    ($err, $key_names) =
-        concord::get_key_names($blob, $size);
+    ($err, $key_names) = concord::get_key_names();
     print "done\n";
 
     my ($carrier_clock, $ir_signal, $ir_length); 
@@ -258,8 +174,7 @@ sub learn_ir_commands
 
         concord::delete_ir_signal($ir_signal);
 
-        $err = concord::post_new_code($blob, $size, $key_names->[$i],
-                $str);
+        $err = concord::post_new_code($key_names->[$i], $str, \&cb, 0);
 
         if ($err) {
             print "Failed to post\n";
@@ -278,26 +193,14 @@ sub learn_ir_commands
 select STDOUT;
 $| = 1;
 
-my $bar = 'val';
-
-my $ret = concord::init_concord();
-if ($ret != 0) {
-    print "Failed to init concord\n";
-    exit;
-}
-print "Get identity ";
-concord::get_identity(\&cb, $bar);
-print " done\n";
-
-print 'mfg: ' . concord::get_mfg() . "\n";
-print 'mfg: ' . concord::get_model() . "\n";
-
 my $opts = {};
 GetOptions($opts,
+    'get-identity|i',
     'dump-config|c',
     'upload-config|C',
     'dump-firmware|f',
     'upload-firmware|F',
+    'reset-remote|r',
     'learn-ir|l',
     ) || die();
 
@@ -306,19 +209,31 @@ if (keys(%$opts) != 1) {
     exit(1);
 }
 
-if (exists($opts->{'dump-config'})) {
+my $ret = concord::init_concord();
+if ($ret != 0) {
+    print "Failed to init concord\n";
+    exit;
+}
+print "Get identity ";
+concord::get_identity(\&cb, 0);
+print " done\n";
+
+print 'mfg: ' . concord::get_mfg() . "\n";
+print 'mfg: ' . concord::get_model() . "\n";
+
+
+if (exists($opts->{'get-identity'})) {
+    exit(0);
+} elsif (exists($opts->{'dump-config'})) {
     dump_config();
 } elsif (exists($opts->{'upload-config'})) {
     upload_config();
-    print "resetting...\n";
-    concord::reset_remote();
 } elsif (exists($opts->{'dump-firmware'})) {
     dump_firmware();
 } elsif (exists($opts->{'upload-firmware'})) {
     upload_firmware();
-    print "resetting...\n";
-    concord::reset_remote();
 } elsif (exists($opts->{'learn-ir'})) {
     learn_ir_commands();
+} elsif (exists($opts->{'reset-remote'})) {
+    concord::reset_remote(\&cb, 0);
 }
-
diff --git a/libconcord/bindings/python/libconcord.py b/libconcord/bindings/python/libconcord.py
index 718fc0e..a2dd4e6 100644
--- a/libconcord/bindings/python/libconcord.py
+++ b/libconcord/bindings/python/libconcord.py
@@ -558,12 +558,12 @@ delete_blob = _create_func(
     _in('ptr', POINTER(c_ubyte))
 );
 
-# int read_and_parse_file(char *filename, int *type);
+# int read_and_parse_file(char *filename, uint32_t *type);
 read_and_parse_file = _create_func(
     'read_and_parse_file',
     _ret_lc_concord(),
     _in('filename', c_char_p),
-    _out('type', c_int)
+    _out('type', c_uint)
 )
 
 # void delete_opfile_obj();
diff --git a/libconcord/libconcord.cpp b/libconcord/libconcord.cpp
index fc1ca7d..057d9b1 100644
--- a/libconcord/libconcord.cpp
+++ b/libconcord/libconcord.cpp
@@ -441,7 +441,7 @@ const char *lc_cb_stage_str(int stage)
 /*
  * Wrapper around the OperationFile class.
  */
-int read_and_parse_file(char *filename, int *type)
+int read_and_parse_file(char *filename, uint32_t *type)
 {
     of = new OperationFile;
     return of->ReadAndParseOpFile(filename, type);
@@ -712,6 +712,7 @@ int init_concord()
 #endif
 
     if (InitUSB()) {
+        debug("InitUSB failed");
         return LC_ERROR_OS;
     }
 
@@ -810,7 +811,7 @@ int reset_remote(lc_callback cb, void *cb_arg)
                     LC_CB_COUNTER_TYPE_STEPS, cb_arg, NULL);
             sleep(1);
             secs++;
-	}
+        }
         err = init_concord();
         if (err == 0) {
             err = _get_identity(NULL, NULL, 0);
diff --git a/libconcord/libconcord.h b/libconcord/libconcord.h
index 8e6f7ec..8dbd0bd 100644
--- a/libconcord/libconcord.h
+++ b/libconcord/libconcord.h
@@ -194,7 +194,7 @@ void delete_blob(uint8_t *ptr);
  * Read an operations file from the website, parse it, and return a mode
  * of operations.
  */
-int read_and_parse_file(char *filename, int *type);
+int read_and_parse_file(char *filename, uint32_t *type);
 /*
  * Free the memory used by the file as allocated in read_and_parse_file.
 */
diff --git a/libconcord/operationfile.cpp b/libconcord/operationfile.cpp
index f20ab72..0e21aec 100644
--- a/libconcord/operationfile.cpp
+++ b/libconcord/operationfile.cpp
@@ -229,7 +229,7 @@ int OperationFile::_ExtractFirmwareBinary()
     return 0;
 }
 
-int OperationFile::ReadAndParseOpFile(char *file_name, int *type)
+int OperationFile::ReadAndParseOpFile(char *file_name, uint32_t *type)
 {
     debug("In RAPOF");
     int err;
diff --git a/libconcord/operationfile.h b/libconcord/operationfile.h
index d6fc4e0..e534bbc 100644
--- a/libconcord/operationfile.h
+++ b/libconcord/operationfile.h
@@ -41,7 +41,7 @@ public:
     uint32_t GetXmlSize() {return xml_size;}
     uint8_t* GetData() {return data;}
     uint8_t* GetXml() {return xml;}
-    int ReadAndParseOpFile(char *file_name, int *type);
+    int ReadAndParseOpFile(char *file_name, uint32_t *type);
 };
 
 #endif /* OPERATIONFILE_H */

Attachment: signature.asc
Description: OpenPGP digital signature

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
concordance-devel mailing list
concordance-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/concordance-devel

Reply via email to