Milinda Pathirage’s Blog

Computers are fascinating machines, but they’re mostly a reflection of the people using them

Maxing Out Your Love-Growth-Cash Triangle

November 29th, 2008 · No Comments · news, personal

Most people take on new jobs, projects and hobbies for three reasons:

  • To learn something new
  • To pay the bills
  • Because they love doing it

These three things fulfill some of our very basic needs—they give us stability, excitement, ways to contribute and opportunities to grow.

Read more.......

Sphere: Related Content

→ No CommentsTags:

GCC Compiler Extensions Used in Linux Kernel

November 21st, 2008 · No Comments · c programming, linux

GCC and Linux are a great pair. Although they are independent pieces of software, Linux is totally dependent on GCC to enable it on new architectures. Linux further exploits features in GCC, called extensions, for greater functionality and optimization.

Read this article from IBM Developer Works to find out more...

Sphere: Related Content

→ No CommentsTags:

Deadly Linux Commands

November 21st, 2008 · No Comments · linux tips, news

If you are new to Linux, chances are you will meet a stupid person perhaps in a forum or chat room that can trick you into using commands that will harm your files or even your entire operating system.

Read more....

Sphere: Related Content

→ No CommentsTags:

Don’t waste your afternoon drawing UML Sequence Diagrams

November 18th, 2008 · 1 Comment · news

websq

www.websequencediagrams.com

→ 1 CommentTags:

Five Things People Hate About Their Favorite Language

November 17th, 2008 · No Comments · programming

If they can't find five things to hate about their favorite tool, they don't know it well enough to either advoc ate it or pull in the big dollars using it.
Read more on stackoverflow.... Sphere: Related Content

→ No CommentsTags:

Linux Directory to an ISO

November 14th, 2008 · No Comments · linux, linux tips

If you want to backup any of your directories in Linux file system, you can use following command. Replace LABEL and directory to suit your needs.

mkisofs -V LABEL -r directory | gzip > cdrom.iso.gz

In Ubuntu 8.04 mkisofs command is just a symbolic link to genisoimage, the fork of mkisofs. It provides a mkisofs symlink to genisoimage for compatibility purposes. Ubuntu advice users to use genisoimage instead of mkisofs.

Sphere: Related Content

→ No CommentsTags:

PulseAudio Flooding LAN with Multicast Packets

November 14th, 2008 · No Comments · linux, linux tips

pulse

If you enable Multicast/RTP Sender and set the option 'send audio from local speakers' in above PulseAudio configuration window, it will flood the network with multicast packets when you play music in your computer. This problem has mentioned in this thread in ubuntuforums.org. Yesterday this has happened to me and it took 3 hours to find that PulseAudio has caused this.

Here is a another post by Justin Mason on the same problem with PulseAudio multicasting.

Sphere: Related Content

→ No CommentsTags:

Getting Started with libusb on Ubuntu

November 12th, 2008 · 4 Comments · Uncategorized, linux

What is libusb?

libusb is a library which user level applications can used to access USB devices without worrying about the underlying operating system. Or we can see it as a high-level API which wraps low-level kernel interactions with USB modules and provide developer with the facility to implement device driver for a USB device from the user space.

libusb is easy to use and libusb API provide high level abstraction to the Kernel structures and allows the developers to have access to these structures through the USBFS(USBfilesystem).

libusb supports Linux, FreeBSD, NetBSD, OpenBSD, Darwin, MacOS X and Windows through the libusb-win32 project.

Installing libusb on Ubuntu

libusb-0.1-4 and libusb-dev packages are available in Ubuntu 8.04 repositories. You can use follwing command to install them.

sudo apt-get install libusb-dev libusb-0.1-4

Simple Example

Here is a simple example application which gather all the possible technical/hardware details of a USB devices connected to the computer. Some devices will not contain some details. This example is based on the Developing Linux Device Drivers using Libusb API article. Inline comments will describe the code.

Make sure that you have at least one USB device plugged into your computer.

#include <stdio.h>
#include <usb.h>

void print_endpoint(struct usb_endpoint_descriptor *endpoint) {
    printf(" bEndpointAddress: %02xh\n", endpoint->bEndpointAddress);
    printf(" bmAttributes: %02xh\n", endpoint->bmAttributes);
    printf(" wMaxPacketSize: %d\n", endpoint->wMaxPacketSize);
    printf(" bInterval: %d\n", endpoint->bInterval);
    printf(" bRefresh: %d\n", endpoint->bRefresh);
    printf(" bSynchAddress: %d\n", endpoint->bSynchAddress);
}

void print_altsetting(struct usb_interface_descriptor *interface) {
    int i;

    printf(" bInterfaceNumber: %d\n", interface->bInterfaceNumber);
    printf(" bAlternateSetting: %d\n", interface->bAlternateSetting);
    printf(" bNumEndpoints: %d\n", interface->bNumEndpoints);
    printf(" bInterfaceClass: %d\n", interface->bInterfaceClass);
    printf(" bInterfaceSubClass: %d\n", interface->bInterfaceSubClass);
    printf(" bInterfaceProtocol: %d\n", interface->bInterfaceProtocol);
    printf(" iInterface: %d\n", interface->iInterface);

    for (i = 0; i < interface->bNumEndpoints; i++)
        print_endpoint(&interface->endpoint[i]);
}

void print_interface(struct usb_interface *interface) {
    int i;

    for (i = 0; i < interface->num_altsetting; i++)
        print_altsetting(&interface->altsetting[i]);
}

void print_configuration(struct usb_config_descriptor *config) {
    int i;

    printf(" wTotalLength: %d\n", config->wTotalLength);
    printf(" bNumInterfaces: %d\n", config->bNumInterfaces);
    printf(" bConfigurationValue: %d\n", config->bConfigurationValue);
    printf(" iConfiguration: %d\n", config->iConfiguration);
    printf(" bmAttributes: %02xh\n", config->bmAttributes);
    printf(" MaxPower: %d\n", config->MaxPower);

    for (i = 0; i < config->bNumInterfaces; i++)
        print_interface(&config->interface[i]);
}

int main(void) {

    struct usb_bus *bus;
    struct usb_device *dev;

    /* Initialize libusb */
    usb_init();

    /* Find all USB busses on system */
    usb_find_busses();

    /* Find all devices on all USB devices */
    usb_find_devices();

    printf("bus/device idVendor/idProduct\n");

    /* usb_busses is a global variable. */
    for (bus = usb_busses; bus; bus = bus->next) {
        for (dev = bus->devices; dev; dev = dev->next) {
            int ret, i;
            char string[256];
            usb_dev_handle *udev;

            printf("%s/%s %04X/%04X\n", bus->dirname, dev->filename,
                    dev->descriptor.idVendor, dev->descriptor.idProduct);
            
            /* Opens a USB device */            
            udev = usb_open(dev);
            if (udev) {
                if (dev->descriptor.iManufacturer) {
                    
                    /* Retrieves a string descriptor from a device using the first language */
                    ret = usb_get_string_simple(udev, dev->descriptor.iManufacturer, string, sizeof (string));
                    if (ret > 0)
                        printf("- Manufacturer : %s\n", string);
                    else
                        printf("- Unable to fetch manufacturer string\n");
                }

                if (dev->descriptor.iProduct) {
                    ret = usb_get_string_simple(udev, dev->descriptor.iProduct, string, sizeof (string));
                    if (ret > 0)
                        printf("- Product : %s\n", string);
                    else
                        printf("- Unable to fetch product string\n");
                }

                if (dev->descriptor.iSerialNumber) {
                    ret = usb_get_string_simple(udev, dev->descriptor.iSerialNumber, string, sizeof (string));
                    if (ret > 0)
                        printf("- Serial Number: %s\n", string);
                    else
                        printf("- Unable to fetch serial number string\n");
                }

                /* Closes a USB device */
                usb_close(udev);
            }

            if (!dev->config) {
                printf(" Couldn't retrieve descriptors\n");
                continue;
            }

            for (i = 0; i < dev->descriptor.bNumConfigurations; i++)
                print_configuration(&dev->config[i]);
        }
    }

    return 0;
}

For further details about the structures please look at the /usr/include/usb.h file.

Sphere: Related Content

→ 4 CommentsTags:

Linux boots in 2.97 seconds

November 12th, 2008 · No Comments · linux, news

Japanese embedded Linux house Lineo has announced a quick-start technology that it claims can boot Linux in 2.97 seconds on a low-powered system. The technology appears similar to but much faster than Linux's existing "suspend-to-disk" capability.

Read more from linuxdevices.com... Sphere: Related Content

→ No CommentsTags:

Linux vs. Mac vs. PC

November 11th, 2008 · No Comments · linux, personal

2007-09-10-mac-pc

→ No CommentsTags:

 Page 5 of 14  « First  ... « 3  4  5  6  7 » ...  Last »