Monday, April 27, 2009

Sci-Tech Friendly President

Today, Obama announced the launch of a new agency, ARPA-E which stands for Advanced Research Projects Agency - Energy. The agency is modeled after DARPA (Defense - ARPA). The science-and-technology friendly US president is also planning to increase the allocated budget for science and technology to 3% of GDP, which is translated to about $240 billion.

Obama also said that he wants to make solar cells as cheap as paints, self-power buildings (smart building?) and some other interesting sci-tech researches. We will see breakthroughs in coming years produced by US national labs again, after deteriorated by wrong policies of Bush who is not-science-but-war friendly ex president.

Shall we start buying technology stocks once again? I am thinking that energy-related technologies will be booming, smart building system which can conserver more energy, which includes home automation that can control energy consumption to be more efficient, faster routers (we live in a connected world, don't we?), robotics will be more advanced, etc. Many new hi-tech jobs will be available.

I think 99% scientists and engineers should love this president.

Bravo to Obama!

Thursday, April 16, 2009

Mobile Platforms

  • Nokia’s Symbian OS-based S60 platform has something for everyone — C, C++, Java, Python, WRT widgets, and Flash — but the APIs require some getting used to. SymbianC++ and Open C/C++ (a C programming interface with runtime Posix libraries) programs are packaged as metadata files that must be digitally signed for security checks or the application won’t execute. IT can therefore use security certificates to monitor and control in-house mobile applications.
  • iPhone uses Objective-C — challenging even for experienced C, C++, and C# programmers. Developers coming from other languages face an even steeper learning curve. The Cocoa Touch programming interface and proprietary XCode integrated development environment (IDE) provide a powerful environment that includes a WYSIWYG interface builder. For Web-based apps, the SDK includes the HTML/JavaScript-based Dashcode framework. Everything in the iPhone runs at root level — and every process executing with root privileges can be a security threat. Additionally, the iPhone permits only one third-party app to run at a time. IPhone apps also must be digitally signed before they can execute.
  • Android applications are written in Java, but not Java ME. Instead, the Android SDK is a combination of standard Java SE and Java ME methods and classes, as well as nonstandard ones. This means that there’ s a learning curve, even for seasoned Java developers. The Android Development Tools plug-in lets developers use Eclipse to write and debug applications. Again, Android apps must be signed or they won’t run. The SDK does provide a developer key, but a private key is required for public distribution.
  • BlackBerry applications can be developed several ways: a Java-based IDE that provides access to RIM APIs and an Eclipse plug-in; a rapid application development approach that focuses on Web services using Visual Studio or Eclipse plug-ins and supports any .NET or Java language choice; or a Web-based app approach referred to as Browser Development, which lets developers create apps using existing BlackBerry browser software. The downside to writing apps using BlackBerry API extensions is that it ties the application to a particular device. Still, that’s no different than using the Android’s unique Java classes.
  • Windows Mobile uses the .NET Compact Framework, which makes development relatively straightforward for developers familiar with .NET languages such as C#, Visual Basic .NET, and (for native code) Visual C++. Because the .NET Compact Framework is a subset of the .Net Framework, components from .NET-based desktop clients, application servers, and Web servers are available. The upside is companies that have standardized on Microsoft platforms and developer tools can jump into mobile development. The downside is the the apps run on a single platform — Windows Mobile OS.

Monday, April 13, 2009

Sniper location system

By David F. Salisbury

Published: March 19, 2009

I magine a platoon of soldiers fighting in a hazardous urban environment who carry personal digital assistants that can display the location of enemy shooters in three dimensions and accurately identify the caliber and type of weapons they are firing.

Engineers at Vanderbilt University's Institute for Software Integrated Systems (ISIS) have developed a system that can give soldiers just such an edge by turning their combat helmets into "smart nodes” in a wireless sensor network.

ISIS developed this novel technology with the support of the Defense Advanced Research Project Agency and the university has patented the system's key elements.

Like several other shooter location systems developed in recent years, the ISIS system relies on the sound waves produced when a high-powered rifle is fired. These acoustic signals have distinctive characteristics that allow the systems to pick them out from other loud noises and track them back to their source. Current systems, however, rely on centralized or stand-alone sensor arrays. This limits their accuracy and restricts them to identifying shooters at line-of-sight locations.

By contrast, the ISIS system combines information from a number of nodes to triangulate on shooter positions and improve the accuracy of its location identification process. It also uses a patented technique to filter out the echoes that can throw off other acoustic detection systems, explains Akos Ledeczi, the senior research scientist at ISIS who heads up the development effort.

"When DARPA gave us the assignment of creating a shooter location system using nodes with very limited capabilities, they didn't think we could solve the technical problems,” Ledeczi admits. "At first, I didn't think we could do it either, but we figured out how to make it work!”

Retired U.S. Army Lieutenant Colonel Albert Sciarretta, who assesses new military technologies in urban environments for DARPA, is one of the experts who is impressed by the ISIS system: "It's strong points are that it isn't limited to locating shots fired in direct line-of-sight, it can pick up multiple shooters at the same time, and it can identify the caliber and type of weapon that is being fired.”

Sciarretta adds, "A leader can use the information that this system provides to react tactically to enemy shooters in ways that limit the number of friendly force and non-combatant casualties. The ISIS system could be easily developed into an operational war-fighting system.”

When a high-powered rifle is fired, it produces two different kinds of sound waves. One is the "muzzle blast” that expands outward in a spherical wave from the muzzle. The second is a conical shock wave that is produced by the bullet as it travels at supersonic speeds. Each node of the shooter location system contains an array of four sensitive microphones. If at least three of the microphones in a single node detect the muzzle blast, the information allows the nodes' microprocessor to calculate the direction that the sound came from. If the same array also detects the arrival time and angle of the bullet shockwave, a simple calculation gives the shooter's location.

"Because the microphones on the helmet are so close together, the precision is not very high,” Ledeczi says. "However, the nodes are continuously exchanging the times and angles of arrival for these acoustic signals, along with their own locations and orientations. When two or more nodes detect the shot, they can provide the bearing with better than one degree accuracy. The range is typically within a few meters even from as far as 300 meters. The more sensors that pick up the shot, the more accurate the localization.”

The ISIS system communicates its findings with the personal digital assistants that the soldiers carry. The PDAs are loaded with maps or overhead pictures of the area upon which the shooter locations are displayed.

In 2006, a team from the National Institute of Standards and Technology at the U.S. Army Aberdeen Test Center independently determined the accuracy of the system. Firing positions were located at distances of 50 to 300 meters from a 10-node sensor network. Six different weapons were used. The only shots that the system sometimes failed to track accurately were those that passed to one side of all of the nodes.

The field tests demonstrated that the system can pick out the location of high-powered sniper rifles even when they are firing at the same time as a submachine gun like the AK-47. They also proved that it can identify the window that a rifle is firing through even when the rifle is completely inside the building, the technique preferred by trained snipers.

These tests were performed with sensors in fixed locations. One of the problems with using a mobile network has been keeping track of the positions of the mobile nodes with sufficient precision. Standard GPS locations are inadequate for this purpose and satellite coverage can be spotty in urban environments. The ISIS team has recently solved this problem by adding an inexpensive radio chip that allows them to track the relative position of nodes using high-precision radio interferometry. The university has applied for a patent on the technique.

The ISIS shooter system uses wireless nodes invented at UC Berkeley and produced by Crossbow Technology Inc. of San Jose, Calif. These smart nodes, or motes, form self-organizing wireless-sensor networks and are the realization of the Pentagon's "smart-dust” concept of radically reducing the size and cost of sensor networks for military applications. Current commercial shooter location systems are extremely expensive, with prices ranging from $10,000 to $50,000 per unit. By contrast, an entire node for the ISIS system weighs only slightly more than the four AA batteries that power it and costs about $1,000 to construct using currently available commercial hardware.

Scientiest found The Edge of Space

Canadian technology on NASA mission is a prototype for future, longer mission

Where does space begin? Scientists at the University of Calgary have created a new instrument that is able to track the transition between the relatively gentle winds of Earth's atmosphere and the more violent flows of charged particles in space—flows that can reach speeds well over 1,000 km/hr. And they have accomplished this in unprecedented detail.

Data received from the U of C-designed instrument sent to space on a NASA launch from Alaska about two years ago was able to help pinpoint the so-called edge of space: the boundary between the Earth's atmosphere and outer space.

With that data, U of C scientists confirmed that space begins 118 km above Earth and the results were published this week in the Journal of Geophysical Research.

The instrument—called the Supra-Thermal Ion Imager—was carried by the JOULE-II rocket on Jan. 19, 2007. It travelled to an altitude of about 200 km above sea level and collected data for the five minutes it was moving through the "edge of space."

The Canadian Space Agency invested $422,000 in the development of the Supra-Thermal Ion Imager instrument on JOULE-II.

The ability to gather data in that area is significant because it's very difficult to make measurements in this region, which is too high for balloons and too low for satellites.

"It's only the second time that direct measurements of charged particle flows have been made in this region, and the first time all the ingredients—such as the upper atmospheric winds—have been included," says David Knudsen, associate professor in the Department of Physics and Astronomy at the University of Calgary.

Knudsen and his former PhD student Laureline Sangalli are the lead authors of the paper. Co-authors include: JOULE-II lead scientist Miguel Larsen of Clemson University, Robert Pfaff and Douglas Rowland of NASA Goddard Space Flight Center and T. Zhan of Conseco Inc.

"When you drag a heavy object over a surface, the interface becomes hot. In JOULE-II we were able to measure directly two regions being dragged past each other, one being the ionosphere—being driven by flows in space—and the other the earth's atmosphere," says Knudsen, who also is the head of the Space Physics Division of the Institute for Space Imaging Sciences (ISIS). The institute is a research partnership between the University of Calgary and University of Lethbridge.

The measurements confirmed what other scientists consider the boundary or edge of space.

"The results have given us a closer look at space, which is a benefit to pure research in space science," Knudsen says. "But it also allows us to calculate energy flows into the Earth's atmosphere that ultimately may be able to help us understand the interaction between space and our environment. That could mean a greater understanding of the link between sunspots and the warming and cooling of the Earth's climate as well as how space weather impacts satellites, communications, navigation, and power systems."

The U of C-designed instrument has been adopted by COM DEV, an Ontario-based global designer and manufacturer of space hardware, and is being used as a prototype for three instruments currently being readied to fly on the European Space Agency's "Swarm" satellite mission, set to launch late next year and to collect data for four years. The JOULE-II instrument is one in a long list of more than a dozen instruments designed by U of C scientists in the past forty years which have flown in space. There are at least five more being readied to go on missions in the next two years.

"Understanding the boundary between the Earth's atmosphere and outer space is fundamental to the bigger picture of the effects of space on the Earth's climate and environment," says Russ Taylor, the director of ISIS and head of the Department of Physics and Astronomy at the U of C. "This detection is part of a long history of success by ISIS researchers in designing and building innovative instruments flown on rockets and satellites to image the flow of matter and energy between the Earth and Space."

The paper "Rocket-based measurements of ion velocity, neutral wind, and electric field in the collisional transition region of the auroral ionosphere" was published this week in the Journal of Geophysical Research.

Move over, Newton: Scientifically ignorant computer derives natural laws from raw data

If Isaac Newton had had access to a supercomputer, he'd have had it watch apples fall and let it figure out what that meant. But the computer would have needed to run an algorithm developed by Cornell researchers that can derive natural laws from observed data.

Hod Lipson and Michael Schmidt with double pendulum
Lindsay France/Cornell University Photography
Professor Hod Lipson and graduate student Michael Schmidt adjust a double pendulum. Refectors on the pendulum enable motion-tracking software to record position and velocity as the pendulum swings. From this a new computer algorithm can derive equations of motion.

The researchers have taught a computer to find regularities in the natural world that represent natural laws -- without any prior scientific knowledge on the part of the computer. They have tested their method, or algorithm, on simple mechanical systems and believe it could be applied to more complex systems ranging from biology to cosmology and be useful in analyzing the mountains of data generated by modern experiments that use electronic data collection.

The research is described in the April 3 issue of the journal Science (Vol. 323, No. 5924) by Hod Lipson, associate professor of mechanical and aerospace engineering, and graduate student Michael Schmidt, a specialist in computational biology.

Their process begins by taking the derivatives of every variable observed with respect to every other -- a mathematical way of measuring how one quantity changes as another changes. Then the computer creates equations at random using various constants and variables from the data. It tests these against the known derivatives, keeps the equations that come closest to predicting correctly, modifies them at random and tests again, repeating until it literally evolves a set of equations that accurately describe the behavior of the real system.

Technically, the computer does not output equations, but finds "invariants" -- mathematical expressions that remain true all the time, from which human insights can derive equations.

"Even though it looks like it's changing erratically, there is always something deeper there that is always constant," Lipson explained. "That's the hint to the underlying physics. You want something that doesn't change, but the relationship between the variables in it changes in a way that's similar to [what we see in] the real system."

Once the invariants are found, potentially all equations describing the system are available: "All equations regarding a system must fit into and satisfy the invariants," Schmidt said. "But of course we still need a human interpreter to take this step."

The researchers tested the method with apparatus used in freshman physics courses: a spring-loaded linear oscillator, a single pendulum and a double pendulum. Given data on position and velocity over time, the computer found energy laws, and for the pendulum, the law of conservation of momentum. Given acceleration, it produced Newton's second law of motion.

The researchers point out that the computer evolves these laws without any prior knowledge of physics, kinematics or geometry. But evolution takes time. On a parallel computer with 32 processors, simple linear motion could be analyzed in a few minutes, but the complex double pendulum required 30 to 40 hours of computation. The researchers found that seeding the complex pendulum problem with terms from equations for the simple pendulum cut processing time to seven or eight hours. This "bootstrapping," they said, is similar to the way human scientists build on previous work.

Computers will not make scientists obsolete, the researchers conclude. Rather, they said, the computer can take over the grunt work, helping scientists focus quickly on the interesting phenomena and interpret their meaning.

The research was supported by the National Science Foundation.

Monday, March 30, 2009

Tuesday, March 24, 2009

To Find a Square-root with miniMIPS

###############################################################################
# To find a square-root of an integer
# (c) M. Lutfi, 2009
#
# Platform: miniMIPS
# tested on: MARS simulator
#
# Convention:
# $v0..$v1,$t0..$t9,$a0: destroyed during procedure calls
# $s0..$s9: saved during procedure calls
###############################################################################

.text
main:
la $a0, question
jal print_string # print(question)
addi $v0,$zero,5
syscall # read integer. v0 contains the integer read (x)
add $s0,$v0,$zero # s0 = x
bltu $s0,$zero,error # exit if x <>
beqz $s0,just_print # print "0" if x == 0
beq $s0,1,just_print # print "1" if x=1

addi $t1,$zero,0 # a = 0
add $t2,$s0,$zero # b = x

loop:
add $t3,$t1,$t2 # t3 = (a+b)
sra $t3,$t3,1 # mid = (a+b)/2
beq $t3,$t1,print_sqrt
beq $t3,$t2,print_sqrt # to prevent endless loop and give approx. result
multu $t3,$t3 #(hi,lo) = mid*mid
mflo $t4
mfhi $t5 # (t5,t4) = mid^2
beq $t4,$s0,print_sqrt # if (mid^2 == x) goto print_sqrt
bgtu $t4,$s0,set_b # if (mid^2 > x) goto set_b
bltu $t4,$s0,set_a # if (mid^2 <>

set_a:
add $t1,$t3,$zero # a = mid
j loop

set_b:
add $t2,$t3,$zero # b = mid
j loop

print_sqrt:
la $a0,answer
jal print_string # print "sqrt(x) = "
add $a0,$t3,$zero # mid is the sqrt(x)
jal print_integer # print the result
j main # do it again. To finish, just enter neg number
j exit

error:
la $a0, inv_num
addi $v0,$zero,4
syscall
j exit

just_print:
la $a0,answer
jal print_string # print "sqrt(x) = "
add $a0,$s0,$zero #print_integer(x)
jal print_integer

exit: # no param needed
addi $v0,$zero,10
syscall # exit


#---------------------------------subroutines----------------------------------
print_string: # string address in a0
addi $v0,$zero,4 # a0 and v0 are destroyed
syscall
jr $ra

print_integer: # integer value in a0
addi $v0,$zero,1
syscall
jr $ra



#-------------------data section-----------------

.data

question: .asciiz "\nEnter number to be square-rooted: "
inv_num: .asciiz "\nInvalid number (e.g, negative"
answer: .asciiz "Sqrt(x) = "

Monday, March 23, 2009

LED Blink on PICKit2 Demoboard

The following code will make LED 1 on PICKit2 demoboard (attached to PICKit2 programmer) to blink for about every 500 mSec. Tools needed are: gputils and sdcc (all of them are open sources), and pk2cmd freely available at Microchip website.

Source code:
__sfr __at (0x2007)  CONFIG = _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_OFF & _MCLRE_OFF &
   _CP_OFF & _IESO_OFF & _FCMEN_OFF & _BOR_OFF;



unsigned char delay1val;
unsigned char delay2val;

void delay()
{
    __asm
    CLRF        _delay1val
    CLRF        _delay2val
    loop:
    DECFSZ      _delay1val,f
    GOTO        loop
    DECFSZ      _delay2val,f
    GOTO        loop
    __endasm;
}

void main()
{
    // make C0 as output
    TRISC0 = 0;
    do {
       RC0 = 1;
       delay();
       RC0 = 0;
       delay();
    } while (1);
}


Makefile:

OBJS=demo1.o
PRJ=demo1
CHIP=690
ARCH=pic14
PLATFORM=16f$(CHIP)
LIBPATH=-I/usr/local/share/gputils/lkr -I/usr/local/share/sdcc/lib/pic
LINKSCRIPTPATH=/usr/local/share/gputils/lkr
LIBS=libsdcc.lib pic$(PLATFORM).lib libm.lib
CC=sdcc -V -m$(ARCH) -p$(PLATFORM)
LINKER=/usr/local/bin/gplink
CFLAGS=--opt-code-speed --stack-auto --main-return --profile --debug-xtra --no-pcode-opt --funsigned-char --Werror
CPPFLAGS=

.c.o:
  $(CC) $(CFLAGS) -D_16F$(CHIP) -c $<

$(PRJ).hex: $(OBJS)
        $(LINKER) -w -O1 -m -o $(PRJ).hex $(OBJS) $(LIBPATH) -f 0 $(LIBS) -s $(LINKSCRIPTPATH)/$(PLATFORM).lkr
   all: $(PRJ).hex
   clean:
        @echo "cleaning up all generated files..."
        @for obj in $(OBJS); do \             if [ -e $$obj ] ; then rm $$obj ; fi \         done
        @rm *.lst
        @if [ -e $(PRJ).cod ] ; then rm $(PRJ).cod ; fi
        @if [ -e $(PRJ).hex ] ; then rm $(PRJ).hex ; fi
        @echo "done."
install:
        pk2cmd -PPIC$(PLATFORM) -M -F$(PRJ).hex
        pk2cmd -PPIC$(PLATFORM) -T


To build:
make demo1.hex

To install:
make install

Sunday, March 22, 2009

PICKIT2 on OpenSUSE

First, create a new udev rules under /etc/udev/rules.d/, name it as "26-microchip.rules".
Add the following into the file:

# PicKit2
SUBSYSTEM=="usb_device", ACTION=="add", SYSFS{idVendor}=="04d8", SYSFS{idProduct}=="0033"
MODE="660", GROUP="microchip", RUN="/usr/local/bin/pk2cmd I /PPIC16F690", SYMLINK+="pickit2"

(do lsusb to verify the vendor and produc id)

Then, execute this on the shell:

sudo udevadm control --reload_rules

Then, download pk2cmd (search google. It should be linked to Microchip website. or try this: http://ww1.microchip.com/downloads/en/DeviceDoc/pk2cmdv1.20LinuxMacSource.tar.gz), compile and install.

When everything is complete with no error, plug in the PICkit2 USB to PC. Check that a new symbolic link was created under /dev as: pickit2. If it is there, you are good to go. Fire up the pk2cmd.

For example, assume the demo code has been there in the demo board and we just want to turn it on, we just need to type: pk2cmd -T /PPIC16F690. To get to know the attached chip on the demo board, try: pk2cmd -I -PPIC16F690

For example:
#> pk2cmd -I -PPIC16F690

Device ID = 1400
Revision = 0005
Device Name = PIC16F690

Operation Succeeded

Friday, March 20, 2009

SDCC Makefile for PIC14

OBJS=test.o
PRJ=test
PLATFORM=16f690
LIB=-I/usr/local/share/gputils/lkr -I/usr/local/share/sdcc/lib/pic

.c.o:
sdcc -V -mpic14 -p$(PLATFORM) --opt-code-speed --stack-auto --main-return -c $<

$(PRJ).hex: $(OBJS)
gplink -m -s $(PLATFORM).lkr -o $(PRJ).hex $(OBJS) $(LIB) -f 0 libsdcc.lib pic$(PLATFORM).lib libm.lib

clean:
rm $(OBJS)
rm $(PRJ).cod
rm $(PRJ).hex

Small Embedded Linux board

Beagleboard Site:
http://beagleboard.org/

BeagleBoard Shopping List
http://code.google.com/p/beagleboard/wiki/BeagleBoardShoppingList

Wednesday, January 28, 2009

New Wireless Standard Promises Ultra-Fast Media Applications

New Wireless Standard Promises Ultra-Fast Media Applications
Georgia Institute of Technology (01/22/09) Fernandez, Don

The Georgia Institute of Technology's Georgia Electronic Design Center (GEDC) has developed a complementary metal oxide semiconductor (CMOS) chip capable of transmitting 60 GHz digital radio-frequency signals. GEDC researchers say the technology could lead to the rapid transfer of high-definition movies and other large files from a PC to a cell phone, virtually wireless desktop computers and data centers, wireless home DVD systems, in-store kiosks that can download movies to mobile devices, and the ability to move gigabytes of photos or video files from a camera to a PC almost instantly. "We believe this new standard represents a major step forward," says GEDC director Joy Laskar. "Consumers could see products capable of ultra-fast short-range data transfer within two or three years." GEDC's chip provides multi-gigabit wireless transmissions by combining 60 GHz CMOS digital radio capabilities and multi-gigabit signal processing in an ultra-compact device. Laskar says the new technology represents the highest level of integration for 60 GHz wireless single-chip solutions. "Multi-gigabit technology definitely has major promise for new consumer and IT applications," says Microsoft Research's Darko Kirovski. GEDC researchers say they have already achieved high data transfer speeds that could lead to unprecedented short-range wireless speeds, including 15 Gbps at 1 meter, 10 Gbps at 2 meters, and 5 Gbps at 5 meters.

Tuesday, December 23, 2008

User Timer in Linux/Unix


#include <sys/time.h >
#include
<signal.h >
#include <stdlib.h >
#include <stdio.h >

#define MAX_COUNT 100

/* This flag controls termination of the main loop. */
volatile sig_atomic_t counter = 0;

/* The signal handler just clears the flag and re-enables itself. */
void
catch_alarm (int sig)
{
counter++;
signal (sig, catch_alarm);
// printf("\nCatch an alarm!\n");
}


void do_stuff (void)
{
static unsigned long c = 0;
printf ("Doing stuff while waiting for alarm (myCounter = %u, Counter=%u) \r", ++c, counter);
}

void set_timer_val(struct itimerval *t, const unsigned long ival_usec, const unsigned int val_usec)
{
//period between successive timer interrupts
t->it_interval.tv_usec = ival_usec % 1000000;
t->it_interval.tv_sec = ival_usec / 1000000;
//period between now and the first timer interrupt
t->it_value.tv_usec = val_usec % 1000000;
t->it_value.tv_sec = val_usec / 1000000;
}

int main (void)
{
struct itimerval ival, oval;

/* Establish a handler for SIGALRM signals. */
signal (SIGALRM, catch_alarm);

/* Set an alarm to go off in a little while. */
// one-shot timer
set_timer_val(&ival, 1000000, 500000);
setitimer (ITIMER_REAL, &ival, &oval);

/* Check the flag once in a while to see when to quit. */
while (counter < MAX_COUNT)
do_stuff ();

printf("\n");
return EXIT_SUCCESS;
}

Sunday, December 21, 2008

Creative XtremeGamer on Linux is Ready

The XFi driver is now available from Creative website. It's the first version (I think it is the first collaboration result between CreativeLabs and ALSA community). Although it supports very limited (very basic features: 2.0 speakers, no enhanced audio processing etc.) right now. At least, my OpenSUSE can spit out sound!

Get it from here.
extract it, but don't make it yet. Modify ctdrv.h. In my case, it shows like below:


#ifndef CTDRV_H
#define CTDRV_H

#define PCI_VENDOR_CREATIVE 0x1102
#define PCI_DEVICE_CREATIVE_20K1 0x0005
#define PCI_DEVICE_CREATIVE_20K2 0x000B
#define PCI_SUBVENDOR_CREATIVE 0x1102
#define PCI_SUBSYS_CREATIVE_SB0760 0x0024
//#define PCI_SUBSYS_CREATIVE_SB0880 0x0041
#define PCI_SUBSYS_CREATIVE_SB0880 0x6003

#define PCI_SUBSYS_CREATIVE_HENDRIX 0x6000
//#define PCI_SUBSYS_CREATIVE_HENDRIX 0x6003

#define CT_XFI_DMA_MASK 0xffffffffUL /* 32 bits */

That is because when I do:

Make a sound card as default in Linux

In the case that we have more than one sound-card, but to select one of them as the default sound-card, copy the following to ~/.asoundrc. In the example below, it makes the card 1 as the default (type "aplay -l" from shell to see all the cards installed and their associated card #).


pcm.!default {
type hw
card 1
}
ctl.!default {
type hw
card 1
}

Sunday, November 30, 2008

OS-X Bootcamp Missing or Corrupt Issue

I got my OS-X Leopard 10.5 a few days ago. After OSX installation, I went to Preference->Utilities->Boot Camp Assistant and then configured it. After reboot and installed the Windows XP, when my MacBook rebooted, it always failed and showed a message as below:

Windows could not start because the following file is missing or corrupt:
\system32\hal.dll
Please re-install a copy of the above file

I've tried various attempts with no success. I searched Google but nothing really helped solving the issue. Finally, I retried again by restoring the OSX into single partition and repartitioned it using The Bootcamp and chose 32 GB FAT32 partition for the Windows. During Windows Installation, I did not delete the partition created by the Bootcamp, but instead just chose NTFS Quick format. Out of my suprise, It worked.

So, the main issue before was that I should hadn't deleted the BOOTCAMP partition I shouldn't had used Windows' Partitioner) and just straightly reformat it and install the Windows.

It works now, except it couldn't find the audio driver (all the other devices were recognized and installed through the OSX CD).

Tuesday, November 25, 2008

AVI to MPEG mass conversion

Need a FFMPEG installed.

The following command will convert all *.AVI files into SVCD-format (with MP3 audio) files:


find . -iwholename *.avi -exec ffmpeg -target ntsc-svcd -acodec mp3 -y -i '{}' '{}.mpg' \;


To see all supported format on FFMPEG:


ffmpeg -formats

Wednesday, November 19, 2008

Using Vector template


#if defined(__cplusplus)
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#else
error "must be CPP-enabled compiler to compile this program"
#endif

using namespace std;


class CPoint {
public:
CPoint(double a, double b) { x = a; y = b; };
friend std::ostream& operator<< (std::ostream& os, const CPoint& val);
double getX() { return x; };
double getY() { return y; };
private:
double x;
double y;
};


std::ostream& operator<< (ostream& os, const CPoint& pt)
{
return os << "(" << pt.x << ", " << pt.y << ")" ;
}


int main()
{
vector<CPoint> points;
vector<CPoint>::iterator it;
int i;

it = points.begin();

for (i=0; i<10; i++) {
it = points.insert( it, CPoint(10.5+double(i)/11, 22.7 - double(i)/13) );
}


cout << "Vector Demo" << endl << "-------------" << endl;
cout << "Vector size = " << points.size() << endl;

for (it = points.begin(), i=0; it < points.end(); it++,i++)
{
// cout << "points[" <<>x;
cout << " " << *it;
cout << endl;
}

for (i=0; i< points.size(); i++)
{
cout << "points[" << i << "] = " << points[i] << endl;
}

return 0;
}

Friday, November 14, 2008

Making Linux running SUSE as a Bridge


  1. Make sure bridge module is installed in the Kernel

  2. Run the bridge module: sudo modprobe bridge

  3. Install bridge-utils (download it from http://bridge.sourceforge.net) and copy brctl into /sbin (the ifup script is hardcoded to call it from /sbin)

  4. create a new bridge instance (in this example, the bridge name is called br0): sudo brctl addbr br0

  5. Add the interface(s) to be members of this bridge: sudo brctl addif br0 ethx (where x = 0, 1, ...)
  6. To make it permanent, copy /etc/sysconfig/network/ifcfg-template to ifcfg-br0
  7. Modify the content and let have it as below (IPADDR is chosen here as 192.168.1.4):

  8. IPADDR=192.168.1.4
    NETMASK=255.255.255.0
    NETWORK=
    BROADCAST=
    STARTMODE=auto
    USERCONTROL=no
    BRIDGE='yes'
    BRIDGE_PORTS='eth0 eth1 eth2'
    BRIDGE_AGEINGTIME='300'
    BRIDGE_FORWARDDELAY='0'
    BRIDGE_HELLOTIME='2'
    BRIDGE_MAXAGE='20'
    BRIDGE_PATHCOSTS='19'
    BRIDGE_PORTPRIORITIES=
    BRIDGE_PRIORITY=
    BRIDGE_STP='on'

  9. restart network: sudo /etc/init.d/network restart


Sunday, October 26, 2008

How to figure out Linux Devices and Drivers

These are the steps to know if our devices have drivers installed and what they are.

$ less /proc/devices

Character devices:
1 mem
2 pty
3 ttyp
4 /dev/vc/0
4 tty
4 ttyS
5 /dev/tty
5 /dev/console
5 /dev/ptmx
6 lp
7 vcs
10 misc
13 input
14 sound
21 sg
29 fb
81 video4linux
116 alsa
128 ptm
136 pts
180 usb
189 usb_device
195 nvidia
253 usb_endpoint
254 rtc

Block devices:
1 ramdisk
2 fd
3 ide0
7 loop
8 sd
9 md
22 ide1
65 sd
66 sd
67 sd
68 sd
69 sd
70 sd
128 sd
129 sd
130 sd
131 sd
132 sd
133 sd
134 sd
135 sd
253 device-mapper
254 mdp

For example, to see what devices the video4linux driver has:

ls -artl /dev | grep 81
crw-rw---- 1 root root 253, 1 2008-10-26 17:17 usbdev1.1_ep81
crw-rw---- 1 root video 81, 1 2008-10-26 17:17 vbi0
crw-rw---- 1 root video 81, 0 2008-10-26 17:17 video0

To see what devices my NVidia driver has:

ls -artl /dev | grep 195
crw-rw---- 1 root video 195, 255 2008-10-26 17:18 nvidiactl
crw-rw---- 1 root video 195, 0 2008-10-26 17:18 nvidia

The major version is the one that we're interested. It's the first number showed when we do 'ls /dev' as well as the numbers showed in /proc/devices

Monday, October 6, 2008

Some useful socat commands

To link serial port ttyS0 to another serial port:

socat /dev/ttyS0,raw,echo=0,crnl /dev/ttyS1,raw,echo=0,crnl

To get time from time server:

socat TCP:time.nist.gov:13 -

To forward local http port to remote http port:

socat TCP-LISTEN:80,fork TCP:www.domain.org:80

To forward terminal to the serial port COM1:

socat READLINE,history=$HOME/.cmd_history /dev/ttyS0,raw,echo=0,crnl

Simple file-transfer:

On the server-side: socat TCP-LISTEN:port filename
To send file fro the server: socat TCP:hostname:port filename

socat - TCP4:www.domain.org:80

Transfers data between STDIO (-) and a TCP4 connection to port 80 of host www.domain.org. This example results in an interactive connection similar to telnet or netcat. The stdin terminal parameters are not changed, so you may close the relay with ^D or abort it with ^C.

socat -d -d READLINE,history=$HOME/.http_history \
TCP4:www.domain.org:www,crnl

This is similar to the previous example, but you can edit the current line in a bash like manner (READLINE) and use the history file .http_history; socat prints messages about progress (-d -d). The port is specified by service name (www), and correct network line termination characters (crnl) instead of NL are used.

socat TCP4-LISTEN:www TCP4:www.domain.org:www

Installs a simple TCP port forwarder. With TCP4-LISTEN it listens on local port "www" until a connection comes in, accepts it, then connects to the remote host (TCP4) and starts data transfer. It will not accept a second connection.


socat -d -d -lmlocal2 \
TCP4-LISTEN:80,bind=myaddr1,su=nobody,fork,range=10.0.0.0/8,reuseaddr \
TCP4:www.domain.org:80,bind=myaddr2

TCP port forwarder, each side bound to another local IP address (bind). This example handles an almost arbitrary number of parallel or consecutive connections by forking a new process after each accept(). It provides a little security by sudoing to user nobody after forking; it only permits connections from the private 10 network (range); due to reuseaddr, it allows immediate restart after master processes termination, even if some child sockets are not completely shut down. With -lmlocal2, socat logs to stderr until successfully reaching the accept loop. Further logging is directed to syslog with facility local2.


socat TCP4-LISTEN:5555,fork,tcpwrap=script \
EXEC:/bin/myscript,chroot=/home/sandbox,su-d=sandbox,pty,stderr

A simple server that accepts connections (TCP4-LISTEN) and forks a new child process for each connection; every child acts as single relay. The client must match the rules for daemon process name "script" in /etc/hosts.allow and /etc/hosts.deny, otherwise it is refused access (see "man 5 hosts_access"). For EXECuting the program, the child process chroots to /home/sandbox, sus to user sandbox, and then starts the program /home/sandbox/bin/myscript. Socat and myscript communicate via a pseudo tty (pty); myscripts stderr is redirected to stdout, so its error messages are transferred via socat to the connected client.

socat EXEC:"mail.sh target@domain.com",fdin=3,fdout=4 \
TCP4:mail.relay.org:25,crnl,bind=alias1.server.org,mss=512

mail.sh is a shell script, distributed with socat, that implements a simple SMTP client. It is programmed to "speak" SMTP on its FDs 3 (in) and 4 (out). The fdin and fdout options tell socat to use these FDs for communication with the program. Because mail.sh inherits stdin and stdout while socat does not use them, the script can read a mail body from stdin. Socat makes alias1 your local source address (bind), cares for correct network line termination (crnl) and sends at most 512 data bytes per packet (mss).


socat - /dev/ttyS0,raw,echo=0,crnl

Opens an interactive connection via the serial line, e.g. for talking with a modem. raw and echo set ttyS0's terminal parameters to practicable values, crnl converts to correct newline characters. Consider using READLINE instead of `-'.


socat UNIX-LISTEN:/tmp/.X11-unix/X1,fork \
SOCKS4:host.victim.org:127.0.0.1:6000,socksuser=nobody,sourceport=20

With UNIX-LISTEN, socat opens a listening UNIX domain socket /tmp/.X11-unix/X1. This path corresponds to local XWindow display :1 on your machine, so XWindow client connections to DISPLAY=:1 are accepted. Socat then speaks with the SOCKS4 server host.victim.org that might permit sourceport 20 based connections due to an FTP related weakness in its static IP filters. Socat pretends to be invoked by socksuser nobody, and requests to be connected to loopback port 6000 (only weak sockd configurations will allow this). So we get a connection to the victims XWindow server and, if it does not require MIT cookies or Kerberos authentication, we can start work. Please note that there can only be one connection at a time, because TCP can establish only one session with a given set of addresses and ports.


socat -u /tmp/readdata,seek-end=0,ignoreeof -


This is an example for unidirectional data transfer (-u). Socat transfers data from file /tmp/readdata (implicit address GOPEN), starting at its current end (seek-end=0 lets socat start reading at current end of file; use seek=0 or no seek option to first read the existing data) in a "tail -f" like mode (ignoreeof). The "file" might also be a listening UNIX domain socket (do not use a seek option then).

(sleep 5; echo PASSWORD; sleep 5; echo ls; sleep 1) |
socat - EXEC:'ssh -l user server',pty,setsid,ctty

EXECutes an ssh session to server. Uses a pty for communication between socat and ssh, makes it ssh's controlling tty (ctty), and makes this pty the owner of a new process group (setsid), so ssh accepts the password from socat.


socat -u TCP4-LISTEN:3334,reuseaddr,fork \
OPEN:/tmp/in.log,creat,append


Implements a simple network based message collector. For each client connecting to port 3334, a new child process is generated (option fork). All data sent by the clients are appended to the file /tmp/in.log. If the file does not exist, socat creats it. Option reuseaddr allows immediate restart of the server process.


socat READLINE,noecho='[Pp]assword:' EXEC:'ftp ftp.server.com',pty,setsid,ctty


Wraps a command line history (READLINE) around the EXECuted ftp client utility. This allows editing and reuse of FTP commands for relatively comfortable browsing through the ftp directory hierarchy. The password is echoed! pty is required to have ftp issue a prompt. Nevertheless, there may occur some confusion with the password and FTP prompts.


socat PTY,link=$HOME/dev/vmodem0,raw,echo=0,waitslave exec:'


Generates a pseudo terminal device (PTY) on the client that can be reached under the symbolic link $HOME/dev/vmodem0. An application that expects a serial line or modem can be configured to use $HOME/dev/vmodem0; its traffic will be directed to a modemserver via ssh where another socat instance links it with /dev/ttyS0.


socat TCP4-LISTEN:2022,reuseaddr,fork \
PROXY:proxy:www.domain.org:22,proxyport=3128,proxyauth=user:pass

starts a forwarder that accepts connections on port 2022, and directs them through the proxy daemon listening on port 3128 (proxyport) on host proxy, using the CONNECT method, where they are authenticated as "user" with "pass" (proxyauth). The proxy should establish connections to host www.domain.org on port 22 then.


echo |socat -u - file:/tmp/bigfile,create,largefile,seek=100000000000


creates a 100GB sparse file; this requires a file system type that supports this (ext2, ext3, reiserfs, jfs; not minix, vfat). The operation of writing 1 byte might take long (reiserfs: some minutes; ext2: "no" time), and the resulting file can consume some disk space with just its inodes (reiserfs: 2MB; ext2:16KB).


socat tcp-l:7777,reuseaddr,fork system:filan -i 0 -s >&2,nofork

listens for incoming TCP connections on port 7777. For each accepted connection, invokes a shell. This shell has its stdin and stdout directly connected to the TCP socket (nofork). The shell starts filan and lets it print the socket addresses to stderr (your terminal window).

echo -e

functions as primitive binary editor: it writes the 4 bytes 000 014 000 000 to the executable /usr/bin/squid at offset 0x00074420 (this is a real world patch to make the squid executable from Cygwin run under Windows, actual per May 2004).


socat - tcp:www.blackhat.org:31337,readbytes=1000

connect to an unknown service and prevent being flooded.

Piped Serial Port on VirtualBox

There is another very cool feature on Linux and VirtualBox which might solve compatibilities of old softwares that require serial connections. It's the host pipe serial-port. On VirtualBox, enable Serial port and select "Host Pipe", check "Create Pipe" and in "port path" textbox, type /tmp/com1_sock.

When my Windows XP is runnning, it recognizes the COM1 and is able to communicate. The byte-streams are actually piped to /tmp/com1_sock (if we don't do anything, it just acts as a dummy). If we want to forward it as a listening port (e.g, as a tcp server so remote systems are able to communicate with the COM1 via TCP/IP), on Linux host's shell type: socat UNIX-CONNECT:/tmp/com1_socket TCP-LISTEN:. We can pick any available tcp port, for example 8040.

Here's the example:

socat UNIX-CONNECT:/tmp/com1_socket TCP-LISTEN:8040

From another terminal (either local machine or remote machine) we can telnet to this port. For example, from our own Linux host, we can communicate to the Hyperterminal running under Windows-XP guest via this virtual serial port by telnetting to the port:

telnet localhost:8040

Voila! Our Linux machine will display anything we type on Hyperminal. This opens up a lot of experiments for us.

Sunday, October 5, 2008

Using Host-Interfacing and Bridging on VirtualBox

NAT interface on guest OS gives limitation so we may need to add a new virtual interface to it. This is called 'HIF' (Host Interface).

Steps:
  1. Install bridge-utils, if not yet installed:
    sudo yast -i bridge-utils

  2. edit /etc/sysconfig/network/ifcfg-br0 and write:


  3. BOOTPROTO='dhcp'
    NETMASK='255.255.255.0'
    STARTMODE='auto'
    USERCONTROL='no'
    DHCLIENT_TIMEOUT=30
    BRIDGE_PORTS='eth0'

  4. Edit /etc/sysconfig/network/ifcfg-eth0 and change the content to:
    BOOTPROTO='static'
    IPADDR='0.0.0.0'


  5. Create a new permanent interface:
    VBoxAddIF tap0  br0

  6. Configure the guest to have the second Virtual Network Interace and assign 'tap0' as its name

Friday, October 3, 2008

My BlackJack is dead!

Today my 3-months-old Samsung Blackjack II has died for no reason. I've charged the battery for hours but still no luck to turn it on. No sign of life on the cute gadget. Darn, seems I have to bring it to closest store for fix.

Using Xwindow client-server

Before starting, make sure both client and server (remote machine) have port 6000 open for Xserver (on SuSE, file /etc/sysconfig/displaymanager should contain DISPLAYMANAGER_XSERVER_TCP_PORT_6000_OPEN="yes"). Once you have changed it, restart Xwindow (or refresh it by pressing CTL-SHFT-BKSPACE).

  1. From local shell, type "xhost +". This will allow this client to connect to all hosts
  2. ssh to remote machine as: "ssh -Y -o ForwardX11Trusted=yes ". If after following steps it does not work, try "ssh -X -o ForwardX11=yes " (although this is less secure)
  3. Once we're in remote machine, type "xhost +" as well.
  4. if we just want to redirect a single X application, we can pass -display directly to the application. For example, to bring remote xterm window to our local screen, just type "xterm -display address:0", e.g.: xterm -display 192.168.1.4:0
  5. If we want to redirect all new X applications to our local screen, modify environment variable DISPLAY. For example: export DISPLAY=192.168.1.4:0 and then type any GUI applications.

Thursday, October 2, 2008

Google IMAP Settings

Incoming Mail (IMAP) Server - requires SSL: imap.gmail.com
Use SSL: Yes
Port: 993
Outgoing Mail (SMTP) Server - requires TLS: smtp.gmail.com (use authentication)
Use Authentication: Yes
Use STARTTLS: Yes (some clients call this SSL)
Port: 465 or 587
Account Name: your full email address (including @gmail.com) Google Apps users, please enter username@your_domain.com
Email Address: your full Gmail email address (username@gmail.com) Google Apps users, please enter username@your_domain.com
Password: your Gmail password

Sunday, August 17, 2008

Mount NTFS disk to Mac OS X

All portable/external had disks currently support legacy FAT (or VFAT as Linux so calls it) from DOS era. The file system is ugly in a sense that it is a 'greedy FS which consumes more space than many other file systems. We can easily use up all the space in our harddisk just by putting many video files into this FAT-formatted harddisk.

Started in NT, a new format was introduced: NTFS (Next-Technology File System). It is quite decent FS, except it seems doesn't fully support journaling (I heard it does, but not sure about that since it is a proprietary format from Microsoft).

Anyway, I don't want to talk too long about the FS, but I just want to talk more about how could the harddisk possibly be mounted to a OS-X based Mac machines? The answer is: use MacFUSE and NTFS-3g!
These opensources were originally targetting the development for Linux, but some folks have ported them to OS-X.

To install, first you need to install MacFUSE (search google to find the location), and after it is successfuly installed, install the OSX version of NTFS-3g. It may require you to reboot. After reboot, try to connect an NTFS-formatted external hard disk to Mac's available USB port. If the system can recognize and mount it, you're done.

I have a 2.5" "WD Passport" 250 GB external hard disk which was I reformatted in NTFS after I bought it. In the beginning, out of curiousity I attached it to my Linux machine running OpenSUSE 10.3. Out of my suprise, It could recognized and mounted it with no issues. I then found out that on my Linux has NTFS-3g in it installed by default. After googling, I found the ported Mac version. Now, all my machines (OSX, Linux, XP) are able to read/write files into this small-but-nice device.

Most influencing Technology

Sometimes, I ask myself about what is the most influencing breakthrough technology in human life? The criteria I ask first that it must be substantial, it must be ubiquotus and found in most every tool, device or anything people use.

My first answer is Transistor. Why? First, it is one of the tremendous invention in 21st century. Secondly, it can be found almost in any household's equipment. Don't believe me? Look at cellphones, TVs, radios, video consoles, computers, cars, airplanes, spacecrafts, security systems, weapons, medical equipments, kitchen appliances, network devices (router, switches, PSTN), satellites, even in our body (pacemaker), ..., and the list would go on and on. Currently, there is almost nobody can live without it.

The second place is taken by LASER. The invention is so great that it has advanced many other sciences and technologies and used in many applications. It is used in medical equipments (e.g, laser surgeries), in telecommunications, industries, military, mining and oil industries or energy in general, basic science research (Cyclotron, etc.), instruments, biotech industries, entertainment (in discotiques, in all cd/dvd players) and even toys!

The inventors should've got double nobel laurates (yes, I know, they all got nobel laurates in the past, but seems it is not enough considering how much their invention has changed our life forever).

The third one is for the invention of computer or the Internet.