Attached patch fixes the perl bindings... But it also fixes a bug in operationfile that couldn't handle firmware dump files we created.
-- 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 b3eca05711c934da542d44abf0f9cb7c831aada9 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 * Take a unint32_t for type instead of 'int' libconcord/operationfile.h libconcord/operationfile.cpp * Take a unint32_t for type instead of 'int' * Handle firmware files we created ourselves libconcord/web.cpp * Document GetTag() 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/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..ed1322c 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; @@ -269,12 +269,15 @@ int OperationFile::ReadAndParseOpFile(char *file_name, int *type) err = GetTag("INFORMATION", xml, xml_size, start_info_ptr); debug("err is %d", err); if (err == -1) { - return LC_ERROR; - } - - err = GetTag("/INFORMATION", xml, xml_size, end_info_ptr); - if (err == -1) { - return LC_ERROR; + debug("Unable to find INFORMATION tag, using whole file"); + start_info_ptr = xml; + end_info_ptr = xml + xml_size; + } else { + err = GetTag("/INFORMATION", xml, xml_size, end_info_ptr); + if (err == -1) { + debug("Unable to find /INFORMATION tag"); + return LC_ERROR; + } } } debug("start/end pointers populated"); @@ -310,12 +313,22 @@ int OperationFile::ReadAndParseOpFile(char *file_name, int *type) while (1) { uint8_t *tag_ptr; string tag_s; + debug("Looking for TYPE tag...\n"); err = GetTag("TYPE", tmp_data, tmp_size, tag_ptr, &tag_s); if (err == -1) { + debug("Looking for PATH tag...\n"); err = GetTag("PATH", tmp_data, tmp_size, tag_ptr, &tag_s); if (err == -1) { - debug("not a firmware file"); - break; + debug("Looking for DATA tag...\n"); + err = GetTag("DATA", tmp_data, tmp_size, tag_ptr, &tag_s); + if (err == -1) { + debug("not a firmware file"); + break; + } else { + debug("Looks like a firmware file we made"); + found_firmware = true; + break; + } } } if (!stricmp(tag_s.c_str(), "Firmware_Main")) { 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 */ diff --git a/libconcord/web.cpp b/libconcord/web.cpp index e64d131..12222b3 100644 --- a/libconcord/web.cpp +++ b/libconcord/web.cpp @@ -155,6 +155,13 @@ static int Zap(string &server, const char *s1, const char *s2) // If find_attributes is set to true, finds an XML tag with attributes and will // return the attributes. For example, if you have: <ELEMENT A="B" C="D"/> and // you search for a tag called "ELEMENT" the function will return A="B" C="D". +// +// find is the tag. +// data is the data to search through +// data_size is the size of data +// found is where we found it +// s, if passed, will hold the strong of the entire element, unless +// find_attributes is set, per abive. int GetTag(const char *find, uint8_t* data, uint32_t data_size, uint8_t *&found, string *s=NULL, bool find_attributes=false) {
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