Getting Your Palm to Talk to a Linux Box

Two students develop a solution to help get you in sync withyour palm device.

A Palm is such a neat portable device. You take notes on it, plan meetings or even write down anniversaries. It's a nice tool to have while on the road. Our intranet server, on the other hand, is also a great resource. We have our company's planning and agenda on it, and it has all those interesting notes, addresses and, in our case, a complete knowledge database. This server runs (of course) Linux, an Apache web server and MySQL database on top of it, glued together with a proprietary application engine.

Wouldn't it be great if the two environments could be synchronized? Of course! Now if we could only access the internal databases from the Palm on our Linux server, that would get us pointed toward the right direction. Documentation is sparse and the Internet is big. But then along came Kevin and Jeffrey, two students who, with some effort, put together a solution that allowed us to make changes on the Palm or on the corporate intranet server and have these modifications propagated to one another's counterpart databases.

All code below was tested on an Intel machine running a Red Hat 6.x release and a Palm Vx with serial cradle running Palm OS 3.5, but other combinations shouldn't cause any problems. The libraries used are unchanged since the first Palm appeared on the market, when they were still being produced by 3Com. I suppose (but haven't tested it) that Visor's won't cause any problem either, as they are running the same OS.

Let's start with the simple part: connecting the Palm to the server. First, we need to connect the cradle of the Palm with the serial port of the server. Then we create a device called pilot. This pilot is nothing more than a link to a serial port (in our case /dev/ttyS0):

ln /dev/ttyS0 /dev/pilot

Now, we're ready to open the connection to the Palm using a C program and a simple push on the HotSync button of the cradle. Once the connection is made, we can relax and read records from the Palm's databases.

Communicating and opening the connection to the Palm is easy with the pi library. This library simulates the BSD socket interface: create a socket, bind it to our device, listen for an incoming connection and accept it. The incoming connection is initiated by the Palm/cradle combination when a user hits the sync button on the cradle. Making a dæmon that waits for someone to come by and synchronize its Palm is illustrated in Listing 1. Loop this program forever.

Listing 1. Synchronizing the Palm

Once the connection is open, how do we interact with the Palm databases? Each database on the Palm has a name. We can open a database by name and get a specific record or cycle through the database. On a Macintosh or Windows platform these functions are performed by conduits. Palm itself provides a conduit on these platforms for every standard database included with the Palm OS bundle. The Palm database manager provides ways for us to cycle only through the modified records in a database. Modified since when? Well, since the last synchronization, the last time a server committed this database. So, we should do this in our programs when finished with the synchronization process. The lines in Listing 2 should be executed when the connection is open.

Listing 2. Cycling through Modified Records

Reading records from a Palm database doesn't qualify as synchronizing. We'll need to do more, such as write to the Palm, delete from it and read from our MySQL database. Since connecting to a MySQL database is outside the scope of this article, we won't discuss the further details of the synchronization problem (and the possible conflicts). However, Kevin Velghe has written an excellent document about it. You can read it at www.duo.be/palm/mysql_palm.html.

Records stored in a Palm database have unique numbers. Whenever you write a record to the device, it returns this number. You should store it on your desktop or central database, so that you can delete or update a specific record.

The dlp_WriteRecord accepts a Palm ID. If it is zero, the Palm OS will allocate a new one for you; if you pass an existing ID, the corresponding record will be updated. For most standard databases a pack function packs the structured record into a buffer. This process is shown in Listing 3.

Listing 3. Pack Function

Identifying the Palm

If, as in our case, you're serving multiple Palms on one server/cradle, you'll need to find out whose Palm is in the cradle. Once the connection is open, call the ReadUserInfo function:

{
  int db, len, I, attr;
  recordid_t id;
  struct PilotUser U;

...open the connection...

  sd = pi_accept(sd, 0, 0);
  dlp_ReadUserInfo(sd,&U);
  printf("Palm of: %s", U.username);
  pi_close(sd);
}

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

root

randy marsh's picture

i haven't had a chance to test this software .i'm just starting into linux with a copy of ubuntu but it would be smart to include the info that a few versions of linux don't let you log in as root. for those they will need to use "sudo" to get root access.

randy
lilwoffie

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState