Synchronizing with a Polar HRM
One of my tasks during the development of Smart Zones Beta 2 is the HRM communication module, that allows users to import data about their training sessions to the application. Those cyclist or joggers who use HRM's know what it means. For the rest, let me briefly explain it.
“HRM” stands for “Heart Rate Monitor”. HRM's are small portable devices that measure and keep a log of your heart rate, i.e. the pace of your heart beats. Typically, you attach a strap to your chest and it detects the small electrical voltages that your heart produces when it's working. The other component is a radio receiver that usually has the appearance of a wrist watch. This device computes your current HR, shows that value on its small display, and records the whole sequence of values during your training session. It often polls the strap at intervals of five seconds. The information gathered may be shown in a heart rate graph.
Nowadays you don't need to be a pro to have one of these gadgets — they are sold with prices around £100 (~ €150) or even less. They are useful to keep your workouts at a high level without overtraining. Also, when you run or cycle, the messages that your body sends to you (about how tired you are, or how intense is the pain in your limbs) are pretty subjective, and highly influenced by psychological factors (e.g. you tolerance and perceptions are not quite the same if you train when you feel like shit). HRM's, on the other hand, always give you steel-cold measures that you can trust (damn) and let you know in which of your heart rate zones you are putting your heart.
An application like Smart Zones must integrate with HRM's to let users feed Trainsmart's database with accurate data about their training. The more accurate that feedback is, the better their suggested training programme will be.
Polar, a Finnish company, virtually invented HRM's. At this stage of Smart Zones, I have been working with their IrDA API to make some of their HRM's talk to Smart Zones via an infrared port (or an USB-to-IrDA device). I started working with the version 1.40 of their DLL and later upgraded to version 1.60. Everything worked fine, except that the progress bar that usually was shown during the whole synchronization process (see the image beside) was missing in the latest version. The sequence of commands that I was using was this one:
fnHRMCom_ResetIRCommunication (0)
fnHRMCom_StartIRCommunication (HRMCOM_PARAM_IRDA, "IR")
fnHRMCom_ReadMonitorInfo (&psg, &psmi)
fnHRMCom_ReadExercisesData (hWnd, FALSE)
for (int i = 0; i < psmi.iTotalFiles; i ++) {
fnHRMCom_GetExeFileInfo (i, &pef)
fnHRMCom_AnalyzeFile (i, 0)
fnHRMCom_SaveExerciseHRM (hDlg, szOutputFile, 0)
}
I knew that not having that progress bar would be a pain for users since infrared communication is infamous because of its low bandwidth. If a user tries to send data about all his 100 or 200 training sessions in the last year, it may take a few minutes to complete. So some feedback is vital to let them know that the synchronization is in progress. After spending far too long trying to find out why that dialog box was missing in the new version of the DLL, I did what software engineers sometimes do in such circumstances: undo the last changes and try to find out at what exact point things changed so badly. In that case, that meant reverting Polar's DLL to its previous version (1.40).
It worked, exactly as it should. There it was that nice dialog box with its progress bar.
Eventually I discovered that the parent window handle that I was passing
to the function fnHRMCom_ReadExercisesData
was NULL
, and this
function is supposed to receive a valid parent window. But even bearing
that in mind, I don't understand why it needs another window handle if
it works the same without it!
Never mind. Smart Zones is now accepting heart rate data from a wide range of Polar IrDA watches. And more Polar interfaces and other HRM brands are to come in the next weeks — we are pushing upgrades more or less once a week.