--- Begin Message ---
Author: thomas
Date: 2008-04-25 15:48:53 +0200 (Fri, 25 Apr 2008)
New Revision: 4398
Modified:
trunk/src/target/opkg/libopkg/opkg.c
trunk/src/target/opkg/libopkg/opkg.h
trunk/src/target/opkg/tests/libopkg_test.c
Log:
opkg: implement package listing in new libopkg
Modified: trunk/src/target/opkg/libopkg/opkg.c
===================================================================
--- trunk/src/target/opkg/libopkg/opkg.c 2008-04-24 11:05:21 UTC (rev
4397)
+++ trunk/src/target/opkg/libopkg/opkg.c 2008-04-25 13:48:53 UTC (rev
4398)
@@ -26,6 +26,7 @@
#include "opkg_configure.h"
#include "opkg_download.h"
#include "opkg_remove.h"
+#include "opkg_upgrade.h"
#include "sprintf_alloc.h"
#include "file_util.h"
@@ -124,6 +125,49 @@
/*** Public API ***/
+opkg_package_t *
+opkg_package_new ()
+{
+
+ opkg_package_t *p;
+
+ p = malloc (sizeof (opkg_package_t));
+ memset (p, 0, sizeof (opkg_package_t));
+
+ return p;
+}
+
+opkg_package_t *
+opkg_package_new_with_values (const char *name, const char *version,
+ const char *arch, const char *desc, const char *tags, int installed)
+{
+ opkg_package_t *package;
+ package = opkg_package_new ();
+
+#define sstrdup(x) (x) ? strdup (x) : NULL;
+
+ package->name = sstrdup (name);
+ package->version = sstrdup (version);
+ package->architecture = sstrdup (arch);
+ package->description = sstrdup (desc);
+ package->tags = sstrdup (tags);
+ package->installed = (installed != 0);
+
+ return package;
+}
+
+void
+opkg_package_free (opkg_package_t *p)
+{
+ free (p->name);
+ free (p->version);
+ free (p->architecture);
+ free (p->description);
+ free (p->tags);
+
+ free (p);
+}
+
opkg_t *
opkg_new ()
{
@@ -647,3 +691,39 @@
return 0;
}
+
+
+int
+opkg_list_packages (opkg_t *opkg, opkg_package_callback_t callback, void
*user_data)
+{
+ pkg_vec_t *all;
+ int i;
+
+ opkg_assert (opkg);
+ opkg_assert (callback);
+
+ all = pkg_vec_alloc ();
+ pkg_hash_fetch_available (&opkg->conf->pkg_hash, all);
+ for (i = 0; i < all->len; i++)
+ {
+ pkg_t *pkg;
+ opkg_package_t *package;
+
+ pkg = all->pkgs[i];
+
+ package = opkg_package_new_with_values (
+ pkg->name,
+ pkg->version,
+ pkg->architecture,
+ pkg->description,
+ pkg->tags,
+ (pkg->state_status == SS_INSTALLED));
+
+ callback (opkg, package, user_data);
+ }
+
+ pkg_vec_free (all);
+
+ return 0;
+}
+
Modified: trunk/src/target/opkg/libopkg/opkg.h
===================================================================
--- trunk/src/target/opkg/libopkg/opkg.h 2008-04-24 11:05:21 UTC (rev
4397)
+++ trunk/src/target/opkg/libopkg/opkg.h 2008-04-25 13:48:53 UTC (rev
4398)
@@ -16,8 +16,27 @@
*/
typedef struct _opkg_t opkg_t;
+typedef struct _opkg_package_t opkg_package_t;
+
typedef void (*opkg_progress_callback_t) (opkg_t *opkg, int percentage, void
*user_data);
+typedef void (*opkg_package_callback_t) (opkg_t *opkg, opkg_package_t
*package, void *user_data);
+
+struct _opkg_package_t
+{
+ char *name;
+ char *version;
+ char *architecture;
+ char *repository;
+ char *description;
+ char *tags;
+ int installed;
+};
+
+opkg_package_t* opkg_package_new ();
+opkg_package_t* opkg_package_new_with_values (const char *name, const char
*version, const char *arch, const char *desc, const char *tags, int installed);
+void opkg_package_free (opkg_package_t *package);
+
opkg_t* opkg_new ();
void opkg_free (opkg_t *opkg);
void opkg_get_option (opkg_t *opkg, char *option, void **value);
@@ -29,3 +48,5 @@
int opkg_upgrade_package (opkg_t *opkg, const char *package_name,
opkg_progress_callback_t callback, void *user_data);
int opkg_upgrade_all (opkg_t *opkg, opkg_progress_callback_t callback, void
*user_data);
int opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t
callback, void *user_data);
+
+int opkg_list_packages (opkg_t *opkg, opkg_package_callback_t callback, void
*user_data);
Modified: trunk/src/target/opkg/tests/libopkg_test.c
===================================================================
--- trunk/src/target/opkg/tests/libopkg_test.c 2008-04-24 11:05:21 UTC (rev
4397)
+++ trunk/src/target/opkg/tests/libopkg_test.c 2008-04-25 13:48:53 UTC (rev
4398)
@@ -9,7 +9,23 @@
fflush (stdout);
}
+void
+package_list_callback (opkg_t *opkg, opkg_package_t *pkg, void *data)
+{
+ static install_count = 0;
+ static total_count = 0;
+ if (pkg->installed)
+ install_count++;
+
+ total_count++;
+
+ printf ("\rPackage count: %d Installed, %d Total Available", install_count,
total_count);
+ fflush (stdout);
+
+ opkg_package_free (pkg);
+}
+
int
main (int argc, char **argv)
{
@@ -37,5 +53,8 @@
err = opkg_remove_package (opkg, "aspell", progress_callback, "Removing...");
printf ("\nopkg_remove_package returned %d\n", err);
+ opkg_list_packages (opkg, package_list_callback, NULL);
+ printf ("\n");
+
opkg_free (opkg);
}
--- End Message ---
--- Begin Message ---
Author: alphaone
Date: 2008-04-26 03:25:41 +0200 (Sat, 26 Apr 2008)
New Revision: 4400
Added:
developers/alphaone/u-blox/ubx-get.rb
developers/alphaone/u-blox/ubx-set.rb
Modified:
developers/alphaone/u-blox/ubx-config.rb
Log:
* Two tools now, ubx-get and ubx-set which will save/load almanac and ephemeris
data to/from a file
Modified: developers/alphaone/u-blox/ubx-config.rb
===================================================================
--- developers/alphaone/u-blox/ubx-config.rb 2008-04-26 01:06:29 UTC (rev
4399)
+++ developers/alphaone/u-blox/ubx-config.rb 2008-04-26 01:25:41 UTC (rev
4400)
@@ -18,8 +18,6 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-gem_original_require 'serialport'
-
UBX_CLASS = {
:NAV => 0x01,
:RXM => 0x02,
@@ -47,12 +45,24 @@
}
UBX_REVSTR = {
+ [:AID, :HUI, 72] =>
+ ["VEENnnnnnneeeeeeeeV", [:HEALTH, :UTC_A1, :UTC_A0, :UTC_TOT,
:UTC_WNT,
+ :UTC_LS, :UTC_WNF, :UTC_DN, :UTC_LSF, :UTC_SPARE, :KLOB_A0,
:KLOB_A1,
+ :KLOB_A2, :KLOB_A3, :KLOB_B0, :KLOB_B1, :KLOB_B2, :KLOB_B3,
:FLAGS]],
[:AID, :ALM, 1] =>
["C", [:SVID]],
[:AID, :ALM, 8] =>
["VV", [:SVID, :WEEK]],
[:AID, :ALM, 40] =>
- ["V"*10, [:SVID, :WEEK, :DWRD0, :DWRD1, :DWRD2, :DWRD3, :DWRD4,
:DWRD5, :DWRD6, :DWRD7]]
+ ["V"*10, [:SVID, :WEEK, :DWRD0, :DWRD1, :DWRD2, :DWRD3, :DWRD4,
:DWRD5, :DWRD6, :DWRD7]],
+ [:AID, :EPH, 1] =>
+ ["C", [:SVID]],
+ [:AID, :EPH, 8] =>
+ ["VV", [:SVID, :HOW]],
+ [:AID, :EPH, 104] =>
+ ["V"*26, [:SVID, :HOW, :SF1D0, :SF1D1, :SF1D2, :SF1D3, :SF1D4,
+ :SF1D5, :SF1D6, :SF1D7, :SF2D0, :SF2D1, :SF2D2, :SF2D3,
:SF2D4,
+ :SF2D5, :SF2D6, :SF1D7, :SF3D0, :SF3D1, :SF3D2, :SF3D3,
:SF3D4, :SF3D5, :SF3D6, :SF3D7]]
}
UBX_FWDSTR = {}
@@ -61,9 +71,10 @@
UBX_FWDSTR[newkey] = value
}
+SYNC1=0xb5
+SYNC2=0x62
+
class Message
- SYNC1=0xb5
- SYNC2=0x62
attr_accessor :data
def initialize(cl, id, data)
@cl = cl
@@ -84,7 +95,10 @@
end
def to_a()
- return [SYNC1, SYNC2, @cl, @id, @data]
+ field_names = [EMAIL PROTECTED], @id, @data.length]][1]
+ name_hash = {}
+ field_names.zip(@data).each{|name, value| name_hash[name] =
value}
+ return [SYNC1, SYNC2, @cl, @id, name_hash]
end
def to_s()
@@ -127,38 +141,3 @@
end
end
end
-
-device = SerialPort.new(ARGV[0], baudrate=9600, databits=8, stopbits=1,
parity=SerialPort::NONE)
-device.read_timeout=-1
-
-worker = Thread.new() {
- stream = []
- while true
- begin
- stream << device.getc
- (msg, len) = Message.parse(stream.map {|i| i.chr}.to_s)
- if msg
- puts msg.inspect
- end
- stream = stream[len..-1]
- rescue
- puts "An error occurred: #{$!}"
- stream = [ ]
- end
- end
-}
-
-sleep(2)
-
-foo = Message.new(:AID, :ALM, [])
-
-while true
- puts "Submitting Almanach request"
- device.write(foo.to_s)
- device.flush()
- sleep(3)
- bar = Message.new(:AID, :ALM, [1, 1234, 1, 2, 3, 4, 5, 6, 7, 8])
- device.write(bar.to_s)
- device.flush()
- sleep (2)
-end
Added: developers/alphaone/u-blox/ubx-get.rb
===================================================================
--- developers/alphaone/u-blox/ubx-get.rb (rev 0)
+++ developers/alphaone/u-blox/ubx-get.rb 2008-04-26 01:25:41 UTC (rev
4400)
@@ -0,0 +1,76 @@
+#!/usr/bin/ruby
+# ubx-get.rb - Utility to retrieve Almanac and Ephemeris data from u-blox GPS
+# receivers
+#
+# Copyright 2008 OpenMoko, Inc.
+# Authored by Daniel Willmann <[EMAIL PROTECTED]>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+gem_original_require 'serialport'
+
+require 'ubx-config'
+
+device = SerialPort.new(ARGV[0], baudrate=9600, databits=8, stopbits=1,
parity=SerialPort::NONE)
+device.read_timeout=-1
+if ARGV[1]
+ fd = File.open(ARGV[1], 'w')
+end
+
+worker = Thread.new() {
+ stream = []
+ while true
+ begin
+ stream << device.getc
+ (msg, len) = Message.parse(stream.map {|i| i.chr}.to_s)
+ if msg
+ puts msg.to_a.inspect
+ foo = Marshal.dump(msg)
+ if fd
+ fd.write([foo.length].pack("v"))
+ fd.write(foo)
+ end
+ end
+ stream = stream[len..-1]
+ rescue
+ puts "An error occurred: #{$!}"
+ stream = [ ]
+ end
+ end
+}
+
+sleep(1)
+
+foo = Message.new(:AID, :ALM, [])
+puts "Almanach request"
+device.write(foo.to_s)
+device.flush()
+sleep(2)
+
+foo = Message.new(:AID, :EPH, [])
+puts "Ephimeris request"
+device.write(foo.to_s)
+device.flush()
+sleep(2)
+
+#foo = Message.new(:AID, :HUI, [])
+#puts "Health info request"
+#device.write(foo.to_s)
+#device.flush()
+#sleep(2)
+
+if fd
+ fd.close
+end
Property changes on: developers/alphaone/u-blox/ubx-get.rb
___________________________________________________________________
Name: svn:executable
+ *
Added: developers/alphaone/u-blox/ubx-set.rb
===================================================================
--- developers/alphaone/u-blox/ubx-set.rb (rev 0)
+++ developers/alphaone/u-blox/ubx-set.rb 2008-04-26 01:25:41 UTC (rev
4400)
@@ -0,0 +1,59 @@
+#!/usr/bin/ruby
+# ubx-set.rb - Utility to set Almanac and Ephemeris data for u-blox GPS
+# receivers
+#
+# Copyright 2008 OpenMoko, Inc.
+# Authored by Daniel Willmann <[EMAIL PROTECTED]>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+gem_original_require 'serialport'
+
+require 'ubx-config'
+
+device = SerialPort.new(ARGV[0], baudrate=9600, databits=8, stopbits=1,
parity=SerialPort::NONE)
+device.read_timeout=-1
+fd = File.open(ARGV[1], 'r')
+
+worker = Thread.new() {
+ stream = []
+ while true
+ begin
+ stream << device.getc
+ (msg, len) = Message.parse(stream.map {|i| i.chr}.to_s)
+ if msg
+ puts msg.to_a.inspect
+ end
+ stream = stream[len..-1]
+ rescue
+ puts "An error occurred: #{$!}"
+ stream = [ ]
+ end
+ end
+}
+
+sleep(2)
+
+while !fd.eof?
+ len = fd.read(2).unpack("v")[0]
+ data = fd.read(len)
+ msg = Marshal.load(data)
+ puts msg.to_a.inspect
+ device.write(msg.to_s)
+ device.flush()
+end
+
+fd.close
+
Property changes on: developers/alphaone/u-blox/ubx-set.rb
___________________________________________________________________
Name: svn:executable
+ *
--- End Message ---